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 MOUNT_2=${MOUNT_2:-"yes"}
54 # script only handles up to 10 MDTs (because of MDT_PREFIX)
55 [ $MDSCOUNT -gt 9 ] &&
56 error "script cannot handle more than 9 MDTs, please fix"
58 check_and_setup_lustre
60 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
61 skip_env "Need MDS version at least 2.4.53"
64 # $RUNAS_ID may get set incorrectly somewhere else
65 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
66 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
68 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
69 if getent group nobody; then
71 elif getent group nogroup; then
74 error "No generic nobody group"
77 # if there is no CLIENT1 defined, some tests can be ran on localhost
78 CLIENT1=${CLIENT1:-$HOSTNAME}
79 # if CLIENT2 doesn't exist then use CLIENT1 instead
80 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
82 # Exception is the test which need two separate nodes
83 CLIENT2=${CLIENT2:-$CLIENT1}
86 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
87 # the following associated variables are added:
89 # AGTCOUNT: number of agents
90 # AGTDEV{N}: target HSM mount point (root path of the backend)
91 # agt{N}_HOST: hostname of the agent agt{N}
92 # SINGLEAGT: facet of the single agent
94 # The number of agents is initialized as the number of remote client nodes.
95 # By default, only single copytool is started on a remote client/agent. If there
96 # was no remote client, then the copytool will be started on the local client.
102 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
103 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
105 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
106 if [[ $CLIENTCOUNT -gt 1 ]] &&
107 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
108 skip_env "SHARED_DIRECTORY should be accessible"\
109 "on all client nodes"
113 # We used to put the HSM archive in $SHARED_DIRECTORY but that
114 # meant NFS issues could hose sanity-hsm sessions. So now we
116 for n in $(seq $AGTCOUNT); do
117 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
118 agent=CLIENT$((n + 1))
119 if [[ -z "${!agent}" ]]; then
120 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
123 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
126 export SINGLEAGT=${SINGLEAGT:-agt1}
128 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
129 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
130 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
131 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
132 export HSMTOOL_TESTDIR
136 # The test only support up to 10 MDTs
137 MDT_PREFIX="mdt.$FSNAME-MDT000"
138 HSM_PARAM="${MDT_PREFIX}0.hsm"
140 # archive is purged at copytool setup
141 HSM_ARCHIVE_PURGE=true
143 # Don't allow copytool error upon start/setup
144 HSMTOOL_NOERROR=false
147 # Get the backend root path for the given agent facet.
150 local dev=AGTDEV$(facet_number $facet)
157 # get MDT device for each mdc
158 for mdtno in $(seq 1 $MDSCOUNT); do
159 local idx=$(($mdtno - 1))
160 MDT[$idx]=$($LCTL get_param -n \
161 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
162 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
167 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
168 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
172 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
174 echo "Killing existing copytools on $hosts"
175 do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
176 copytool_continue "$hosts"
180 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
181 local wait_timeout=200
182 local wait_start=$SECONDS
183 local wait_end=$((wait_start + wait_timeout))
184 local sleep_time=100000 # 0.1 second
186 while ((SECONDS < wait_end)); do
187 if ! search_copytools $hosts; then
188 echo "copytools stopped in $((SECONDS - wait_start))s"
192 echo "copytools still running on $hosts"
194 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
195 sleep_time=$(bc <<< "$sleep_time * 2")
198 # try to dump Copytool's stack
199 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
200 "echo t >/proc/sysrq-trigger"
202 echo "copytools failed to stop in ${wait_timeout}s"
207 copytool_monitor_setup() {
208 local facet=${1:-$SINGLEAGT}
209 local agent=$(facet_active_host $facet)
211 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
212 local test_dir=$(do_node $agent "$cmd") ||
213 error "Failed to create tempdir on $agent"
214 export HSMTOOL_MONITOR_DIR=$test_dir
216 # Create the fifo and a monitor (cat dies when copytool dies)
217 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
218 error "failed to create copytool fifo on $agent"
219 cmd="cat $test_dir/fifo > $test_dir/events &"
220 cmd+=" echo \\\$! > $test_dir/monitor_pid"
222 # This background subshell nonsense is required when pdsh/ssh decides
223 # to wait for the cat process to exit on the remote client
224 (do_node $agent "$cmd") &
225 export HSMTOOL_MONITOR_PDSH=$!
227 # Slightly racy, but just making a best-effort to catch obvious
230 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
232 error "Failed to start copytool monitor on $agent"
242 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
247 get_copytool_event_log() {
248 local facet=${1:-$SINGLEAGT}
249 local agent=$(facet_active_host $facet)
251 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
252 error "Can't get event log: No monitor directory!"
254 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
255 error "Could not collect event log from $agent"
259 local agents=${1:-$(facet_active_host $SINGLEAGT)}
262 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
263 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
264 echo "Copytool is suspended on $agents"
267 copytool_continue() {
268 local agents=${1:-$(facet_active_host $SINGLEAGT)}
270 do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
271 echo "Copytool is continued on $agents"
274 copytool_remove_backend() {
276 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
277 echo "Remove from backend: $fid = $be"
278 do_facet $SINGLEAGT rm -f $be
281 file_creation_failure() {
288 df $MOUNT $MOUNT2 >&2
289 error "Not enough space to create $file with $cmd"
292 error "cannot create $file with $cmd, status=$err"
297 # Creates a file using dd
303 local source=${5:-/dev/zero}
307 if [ -n "$conv" ]; then
311 # Create the directory in case it does not exist
312 mkdir -p "$(dirname "$file")"
313 # Delete the file in case it already exist
316 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
317 path2fid "$file" || error "cannot get FID of '$file'"
320 echo "cannot create file '$file'" >&2;
321 # Let the caller decide what to do on error
326 create_empty_file() {
327 create_file "${1/$DIR/$DIR2}" 1M 0 ||
328 file_creation_failure dd "${1/$DIR/$DIR2}" $?
331 create_small_file() {
332 local source_file=/dev/urandom
335 local conv=${2:-fsync}
337 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
338 file_creation_failure dd "${1/$DIR/$DIR2}" $?
341 create_small_sync_file() {
342 create_small_file "$1" sync
345 create_archive_file() {
346 local file="$(hsm_root)/$1"
348 local source=/dev/urandom
350 # Create the counterpart directory of the archive
351 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
352 error "cannot create archive directory '$(dirname "$file")'"
354 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
355 error "cannot create archive file '$file'"
359 local hsm_root="$(hsm_root)"
360 local file="$hsm_root/$2"
362 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
363 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
364 error "mkdir '$(dirname "$file")' failed"
365 do_facet $SINGLEAGT cp -p "$1" "$file" ||
366 error "cannot copy '$1' to '$file'"
371 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
378 mdts_set_param "" hsm_control "$cmd"
379 mdts_check_param hsm_control "$target" 10
384 mdts_set_param "" hsm.policy "+NRA"
385 CDT_POLICY_HAD_CHANGED=true
388 cdt_clear_no_retry() {
389 mdts_set_param "" hsm.policy "-NRA"
390 CDT_POLICY_HAD_CHANGED=true
393 cdt_set_non_blocking_restore() {
394 mdts_set_param "" hsm.policy "+NBR"
395 CDT_POLICY_HAD_CHANGED=true
398 cdt_clear_non_blocking_restore() {
399 mdts_set_param "" hsm.policy "-NBR"
400 CDT_POLICY_HAD_CHANGED=true
403 cdt_clear_mount_state() {
404 mdts_set_param "-P -d" hsm_control ""
408 set_test_state disabled disabled
412 set_test_state enabled enabled
416 set_test_state shutdown stopped
420 set_test_state purge enabled
426 cdt_set_sanity_policy
430 get_hsm_archive_id() {
433 st=$($LFS hsm_state $f)
434 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
436 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
440 check_hsm_flags_user() {
444 local st=$(get_hsm_flags $f user)
445 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
457 if [[ "$3" != 1 ]]; then
461 cp $1 $f || file_creation_failure cp $f $?
463 path2fid $f || error "cannot get fid on $f"
466 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
468 # Note that this might lead to surprising behaviours such as deleting an
469 # important file for the currently running test
470 delete_large_files() {
471 printf "Deleting large files...\n" >&2
472 find $MOUNT -size +10M -delete
473 wait_delete_completed
476 get_request_state() {
480 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
481 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
484 get_request_count() {
488 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
489 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
492 # Ensure the number of HSM request for a given FID is correct
493 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
494 assert_request_count() {
495 local request_count=$(get_request_count $1 $2)
496 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
498 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
505 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
506 [[ -n $fid ]] && cmd+=" | grep '$fid'"
507 cmd+=" | egrep 'WAITING|STARTED'"
509 wait_result $SINGLEMDS "$cmd" "" $timeout ||
510 error "requests did not complete"
513 wait_for_grace_delay() {
514 local val=$(get_hsm_param grace_delay)
518 wait_for_loop_period() {
519 local val=$(get_hsm_param loop_period)
526 # python2.6 in EL6 includes an internal json module
527 local json_parser='import json; import fileinput;'
528 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
529 json_parser+='json.loads([line for line in '
530 json_parser+='fileinput.input()][0]).items()])'
532 echo $raw_event | python -c "$json_parser"
535 get_agent_by_uuid_mdt() {
538 local mds=mds$(($mdtidx + 1))
539 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
543 check_agent_registered_by_mdt() {
546 local mds=mds$(($mdtidx + 1))
547 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
548 if [[ ! -z "$agent" ]]; then
549 echo "found agent $agent on $mds"
551 error "uuid $uuid not found in agent list on $mds"
555 check_agent_unregistered_by_mdt() {
558 local mds=mds$(($mdtidx + 1))
559 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
560 if [[ -z "$agent" ]]; then
561 echo "uuid not found in agent list on $mds"
563 error "uuid found in agent list on $mds: $agent"
567 check_agent_registered() {
570 for mdsno in $(seq 1 $MDSCOUNT); do
571 check_agent_registered_by_mdt $uuid $((mdsno - 1))
575 check_agent_unregistered() {
578 for mdsno in $(seq 1 $MDSCOUNT); do
579 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
584 local agent=${1:-$(facet_active_host $SINGLEAGT)}
586 # Lustre mount-point is mandatory and last parameter on
588 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
590 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
592 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
598 # populate MDT device array
601 # cleanup from previous bad setup
604 # for recovery tests, coordinator needs to be started at mount
606 # the lustre conf must be without hsm on (like for sanity.sh)
607 echo "Set HSM on and start"
608 cdt_set_mount_state enabled
609 cdt_check_state enabled
611 echo "Set sanity-hsm HSM policy"
612 cdt_set_sanity_policy
614 # finished requests are quickly removed from list
615 set_hsm_param grace_delay 10
617 CLIENT_NIDS=( $($LCTL list_nids all) )
619 test_1A() { # was test_1
623 local f=$DIR/$tdir/$tfile
627 check_hsm_flags_user $f "0x00000000"
629 $RUNAS $LFS hsm_set --norelease $f ||
630 error "user could not change hsm flags"
631 check_hsm_flags_user $f "0x00000010"
633 $RUNAS $LFS hsm_clear --norelease $f ||
634 error "user could not clear hsm flags"
635 check_hsm_flags_user $f "0x00000000"
637 # User could not change those flags...
638 $RUNAS $LFS hsm_set --exists $f &&
639 error "user should not set this flag"
640 check_hsm_flags_user $f "0x00000000"
643 $LFS hsm_set --exists $f ||
644 error "root could not change hsm flags"
645 check_hsm_flags_user $f "0x00000001"
647 $LFS hsm_clear --exists $f ||
648 error "root could not clear hsm state"
649 check_hsm_flags_user $f "0x00000000"
652 run_test 1A "lfs hsm flags root/non-root access"
655 local f=$DIR/$tdir/$tfile
656 local fid=$(create_small_file $f)
660 $LFS hsm_archive $f || error "could not archive file"
661 wait_request_state $fid ARCHIVE SUCCEED
663 # Release and check states
664 $LFS hsm_release $f || error "could not release file"
665 echo -n "Verifying released state: "
666 check_hsm_flags $f "0x0000000d"
668 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
670 run_test 1a "mmap & cat a HSM released file"
676 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
677 error "failed to create file"
678 local fid=$(path2fid $f)
683 $LFS hsm_archive $f || error "could not archive file"
684 wait_request_state $fid ARCHIVE SUCCEED
687 $LFS hsm_release $f || error "could not release file"
688 echo "verify released state: "
689 check_hsm_flags $f "0x0000000d" && echo "pass"
692 $LFS hsm_restore $f || error "could not restore file"
693 wait_request_state $fid RESTORE SUCCEED
694 echo "verify restored state: "
695 check_hsm_flags $f "0x00000009" && echo "pass"
700 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
701 error "failed to set default stripe"
702 local f=$DIR/$tdir/$tfile
706 run_test 1b "Archive, Release and Restore composite file"
712 local f=$DIR/$tdir/$tfile
715 # Test whether we can set the maximum archive number.
716 local LOCAL_HSM_ARCHIVE_NUMBER=32
717 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
718 error "root could not change hsm flags"
719 check_hsm_flags_user $f "0x00000001"
720 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
721 local st=$(get_hsm_archive_id $f)
722 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
723 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
725 # Test whether setting archive number 0 results in no change.
726 $LFS hsm_set --exists --archive-id 0 $f ||
727 error "root could not change hsm flags"
728 check_hsm_flags_user $f "0x00000001"
729 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
730 st=$(get_hsm_archive_id $f)
731 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
732 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
734 LOCAL_HSM_ARCHIVE_NUMBER=33
735 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
736 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
737 # lustre in the new version supports unlimited archiveID.
738 # Test whether setting archive number > 32 is supported
739 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
740 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
741 check_hsm_flags_user $f "0x00000001"
743 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
744 st=$(get_hsm_archive_id $f)
745 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
746 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
748 # old client or old mds can only support at most 32 archiveID
749 # test whether setting archive number > 32 results in error.
750 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
751 error "bitmap archive number is larger than 32"
752 check_hsm_flags_user $f "0x00000001"
755 # Test whether setting archive number 16 and archived flag.
756 LOCAL_HSM_ARCHIVE_NUMBER=16
757 $LFS hsm_set --exists --archived \
758 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
759 error "root could not change hsm flags"
760 check_hsm_flags_user $f "0x00000009"
761 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
762 st=$(get_hsm_archive_id $f)
763 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
764 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
766 run_test 1c "Check setting archive-id in lfs hsm_set"
769 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
770 skip "need MDS version at least 2.10.59"
773 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
774 error "failed to set default stripe"
775 local f=$DIR/$tdir/$tfile
779 run_test 1d "Archive, Release and Restore DoM file"
782 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
783 skip "skipped for lustre < $SEL_VER"
786 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
787 error "failed to set default stripe"
788 local comp_file=$DIR/$tdir/$tfile
790 test_1bde_base $comp_file
792 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
793 local found=$($LFS find $flg_opts $comp_file | wc -l)
794 [ $found -eq 1 ] || error "1st component not found"
796 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
797 found=$($LFS find $flg_opts $comp_file | wc -l)
798 [ $found -eq 1 ] || error "2nd component not found"
800 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
801 found=$($LFS find $flg_opts $comp_file | wc -l)
802 [ $found -eq 1 ] || error "3rd component not found"
804 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
805 found=$($LFS find $flg_opts $comp_file | wc -l)
806 [ $found -eq 1 ] || error "4th component not found"
808 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
809 found=$($LFS find $flg_opts $comp_file | wc -l)
810 [ $found -eq 1 ] || error "5th component not found"
812 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
813 found=$($LFS find $flg_opts $comp_file | wc -l)
814 [ $found -eq 1 ] || error "6th component not found"
816 sel_layout_sanity $comp_file 6
818 run_test 1e "Archive, Release and Restore SEL file"
821 local f=$DIR/$tdir/$tfile
823 create_empty_file "$f"
824 # New files are not dirty
825 check_hsm_flags $f "0x00000000"
827 # For test, we simulate an archived file.
828 $LFS hsm_set --exists $f || error "user could not change hsm flags"
829 check_hsm_flags $f "0x00000001"
831 # chmod do not put the file dirty
832 chmod 600 $f || error "could not chmod test file"
833 check_hsm_flags $f "0x00000001"
835 # chown do not put the file dirty
836 chown $RUNAS_ID $f || error "could not chown test file"
837 check_hsm_flags $f "0x00000001"
839 # truncate put the file dirty
840 $TRUNCATE $f 1 || error "could not truncate test file"
841 check_hsm_flags $f "0x00000003"
843 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
844 check_hsm_flags $f "0x00000001"
846 run_test 2 "Check file dirtyness when doing setattr"
852 # New files are not dirty
854 check_hsm_flags $f "0x00000000"
856 # For test, we simulate an archived file.
857 $LFS hsm_set --exists $f ||
858 error "user could not change hsm flags"
859 check_hsm_flags $f "0x00000001"
861 # Reading a file, does not set dirty
862 cat $f > /dev/null || error "could not read file"
863 check_hsm_flags $f "0x00000001"
865 # Open for write without modifying data, does not set dirty
866 openfile -f O_WRONLY $f || error "could not open test file"
867 check_hsm_flags $f "0x00000001"
869 # Append to a file sets it dirty
870 cp -p /etc/passwd $f.append || error "could not create file"
871 $LFS hsm_set --exists $f.append ||
872 error "user could not change hsm flags"
873 dd if=/etc/passwd of=$f.append bs=1 count=3\
874 conv=notrunc oflag=append status=noxfer ||
875 file_creation_failure dd $f.append $?
876 check_hsm_flags $f.append "0x00000003"
878 # Modify a file sets it dirty
879 cp -p /etc/passwd $f.modify || error "could not create file"
880 $LFS hsm_set --exists $f.modify ||
881 error "user could not change hsm flags"
882 dd if=/dev/zero of=$f.modify bs=1 count=3\
883 conv=notrunc status=noxfer ||
884 file_creation_failure dd $f.modify $?
885 check_hsm_flags $f.modify "0x00000003"
887 # Open O_TRUNC sets dirty
888 cp -p /etc/passwd $f.trunc || error "could not create file"
889 $LFS hsm_set --exists $f.trunc ||
890 error "user could not change hsm flags"
891 cp /etc/group $f.trunc || error "could not override a file"
892 check_hsm_flags $f.trunc "0x00000003"
894 # Mmapped a file sets dirty
895 cp -p /etc/passwd $f.mmap || error "could not create file"
896 $LFS hsm_set --exists $f.mmap ||
897 error "user could not change hsm flags"
898 multiop $f.mmap OSMWUc || error "could not mmap a file"
899 check_hsm_flags $f.mmap "0x00000003"
901 run_test 3 "Check file dirtyness when opening for write"
904 local f=$DIR/$tdir/$tfile
905 local fid=$(create_small_file $f)
908 local st=$(get_request_state $fid CANCEL)
909 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
911 run_test 4 "Useless cancel must not be registered"
914 # test needs a running copytool
918 local f=$DIR/$tdir/$tfile
919 local fid=$(copy_file /etc/passwd $f)
921 wait_request_state $fid ARCHIVE SUCCEED
923 check_hsm_flags $f "0x00000009"
925 run_test 8 "Test default archive number"
927 test_9A() { # was test_9
928 # we do not use the default one to be sure
929 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
930 copytool setup --archive-id $archive_id
932 # give time for CT to register with MDTs
933 sleep $(($MDSCOUNT*2))
934 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
935 check_agent_registered $uuid
938 local f=$DIR/$tdir/$tfile
939 local fid=$(copy_file /etc/passwd $f)
940 $LFS hsm_archive --archive $archive_id $f
941 wait_request_state $fid ARCHIVE SUCCEED
943 check_hsm_flags $f "0x00000009"
945 run_test 9A "Use of explicit archive number, with dedicated copytool"
948 needclients 3 || return 0
954 # start all of the copytools
955 for n in $(seq $AGTCOUNT); do
956 copytool setup --facet agt$n
960 for n in $(seq $AGTCOUNT); do
961 file=$DIR/$tdir/$tfile.$n
962 fid=$(create_small_file $file)
964 $LFS hsm_archive $file || error "could not archive file $file"
965 wait_request_state $fid ARCHIVE SUCCEED
966 check_hsm_flags $file "0x00000009"
969 run_test 9a "Multiple remote agents"
972 # test needs a running copytool
975 mkdir -p $DIR/$tdir/d1
976 local f=$DIR/$tdir/$tfile
977 local fid=$(copy_file /etc/hosts $f)
978 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
979 error "hsm_archive failed"
980 wait_request_state $fid ARCHIVE SUCCEED
982 local hsm_root="$(copytool_device $SINGLEAGT)"
983 local archive="$(do_facet $SINGLEAGT \
984 find "$hsm_root" -name "$fid" -print0)"
985 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
987 echo "Verifying content"
988 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
989 echo "Verifying hsm state "
990 check_hsm_flags $f "0x00000009"
992 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
993 local st=$(get_hsm_archive_id $f)
994 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
995 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
997 run_test 10a "Archive a file"
1000 # test needs a running copytool
1004 local f=$DIR/$tdir/$tfile
1005 local fid=$(copy_file /etc/hosts $f)
1006 $LFS hsm_archive $f || error "archive request failed"
1007 wait_request_state $fid ARCHIVE SUCCEED
1009 $LFS hsm_archive $f || error "archive of non dirty file failed"
1010 local cnt=$(get_request_count $fid ARCHIVE)
1011 [[ "$cnt" == "1" ]] ||
1012 error "archive of non dirty file must not make a request"
1014 run_test 10b "Archive of non dirty file must work without doing request"
1017 # test needs a running copytool
1021 local f=$DIR/$tdir/$tfile
1022 local fid=$(copy_file /etc/hosts $f)
1023 $LFS hsm_set --noarchive $f
1024 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1027 run_test 10c "Check forbidden archive"
1030 # test needs a running copytool
1034 local f=$DIR/$tdir/$tfile
1035 local fid=$(copy_file /etc/hosts $f)
1036 $LFS hsm_archive $f || error "cannot archive $f"
1037 wait_request_state $fid ARCHIVE SUCCEED
1039 local ar=$(get_hsm_archive_id $f)
1040 local dflt=$(get_hsm_param default_archive_id)
1041 [[ $ar == $dflt ]] ||
1042 error "archived file is not on default archive: $ar != $dflt"
1044 run_test 10d "Archive a file on the default archive id"
1048 copy2archive /etc/hosts $tdir/$tfile
1049 local f=$DIR/$tdir/$tfile
1051 copytool import $tdir/$tfile $f
1052 echo -n "Verifying released state: "
1053 check_hsm_flags $f "0x0000000d"
1055 local LSZ=$(stat -c "%s" $f)
1056 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1058 echo "Verifying imported size $LSZ=$ASZ"
1059 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1060 echo -n "Verifying released pattern: "
1061 local PTRN=$($LFS getstripe -L $f)
1063 [[ $PTRN == released ]] || error "Is not released"
1064 local fid=$(path2fid $f)
1065 echo "Verifying new fid $fid in archive"
1067 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1068 error "No archive for fid $fid"
1070 run_test 11a "Import a file"
1073 # test needs a running copytool
1077 local f=$DIR/$tdir/$tfile
1078 local fid=$(copy_file /etc/hosts $f)
1079 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1080 error "hsm_archive failed"
1081 wait_request_state $fid ARCHIVE SUCCEED
1083 local FILE_HASH=$(md5sum $f)
1086 copytool import $fid $f
1088 echo "$FILE_HASH" | md5sum -c
1090 [[ $? -eq 0 ]] || error "Restored file differs"
1092 run_test 11b "Import a deleted file using its FID"
1095 # test needs a running copytool
1099 copy2archive /etc/hosts $tdir/$tfile
1101 local f=$DIR/$tdir/$tfile
1102 copytool import $tdir/$tfile $f
1103 local f2=$DIR2/$tdir/$tfile
1104 echo "Verifying released state: "
1105 check_hsm_flags $f2 "0x0000000d"
1107 local fid=$(path2fid $f2)
1108 $LFS hsm_restore $f2
1109 wait_request_state $fid RESTORE SUCCEED
1111 echo "Verifying file state: "
1112 check_hsm_flags $f2 "0x00000009"
1114 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1116 [[ $? -eq 0 ]] || error "Restored file differs"
1118 run_test 12a "Restore an imported file explicitly"
1121 # test needs a running copytool
1125 copy2archive /etc/hosts $tdir/$tfile
1127 local f=$DIR/$tdir/$tfile
1128 copytool import $tdir/$tfile $f
1129 echo "Verifying released state: "
1130 check_hsm_flags $f "0x0000000d"
1132 cat $f > /dev/null || error "File read failed"
1134 echo "Verifying file state after restore: "
1135 check_hsm_flags $f "0x00000009"
1137 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1139 [[ $? -eq 0 ]] || error "Restored file differs"
1141 run_test 12b "Restore an imported file implicitly"
1144 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1146 # test needs a running copytool
1149 local f=$DIR/$tdir/$tfile
1151 $LFS setstripe -c 2 "$f"
1152 local fid=$(create_file "$f" 1M 5)
1154 local FILE_CRC=$(md5sum $f)
1156 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1157 wait_request_state $fid ARCHIVE SUCCEED
1158 $LFS hsm_release $f || error "release $f failed"
1160 echo "$FILE_CRC" | md5sum -c
1162 [[ $? -eq 0 ]] || error "Restored file differs"
1164 run_test 12c "Restore a file with stripe of 2"
1167 # test needs a running copytool
1172 local f=$DIR/$tdir/$tfile
1173 local fid=$(copy_file /etc/hosts $f)
1174 $LFS hsm_restore $f || error "restore of non archived file failed"
1175 local cnt=$(get_request_count $fid RESTORE)
1176 [[ "$cnt" == "0" ]] ||
1177 error "restore non archived must not make a request"
1178 $LFS hsm_archive $f ||
1179 error "archive request failed"
1180 wait_request_state $fid ARCHIVE SUCCEED
1181 $LFS hsm_restore $f ||
1182 error "restore of non released file failed"
1183 local cnt=$(get_request_count $fid RESTORE)
1184 [[ "$cnt" == "0" ]] ||
1185 error "restore a non dirty file must not make a request"
1187 run_test 12d "Restore of a non archived, non released file must work"\
1188 " without doing request"
1191 # test needs a running copytool
1195 local f=$DIR/$tdir/$tfile
1196 local fid=$(copy_file /etc/hosts $f)
1197 $LFS hsm_archive $f || error "archive request failed"
1198 wait_request_state $fid ARCHIVE SUCCEED
1201 cat /etc/hosts >> $f
1205 $LFS hsm_restore $f && error "restore a dirty file must fail"
1208 run_test 12e "Check forbidden restore"
1211 # test needs a running copytool
1215 local f=$DIR/$tdir/$tfile
1216 local fid=$(copy_file /etc/hosts $f)
1218 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1219 wait_request_state $fid ARCHIVE SUCCEED
1220 $LFS hsm_release $f || error "release of $f failed"
1222 wait_request_state $fid RESTORE SUCCEED
1224 echo -n "Verifying file state: "
1225 check_hsm_flags $f "0x00000009"
1227 diff -q /etc/hosts $f
1229 [[ $? -eq 0 ]] || error "Restored file differs"
1231 run_test 12f "Restore a released file explicitly"
1234 # test needs a running copytool
1238 local f=$DIR/$tdir/$tfile
1239 local fid=$(copy_file /etc/hosts $f)
1241 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1242 wait_request_state $fid ARCHIVE SUCCEED
1243 $LFS hsm_release $f || error "release of $f failed"
1245 diff -q /etc/hosts $f
1248 # we check we had a restore done
1249 wait_request_state $fid RESTORE SUCCEED
1251 [[ $st -eq 0 ]] || error "Restored file differs"
1253 run_test 12g "Restore a released file implicitly"
1256 needclients 2 || return 0
1258 # test needs a running copytool
1262 local f=$DIR/$tdir/$tfile
1263 local fid=$(copy_file /etc/hosts $f)
1265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1266 wait_request_state $fid ARCHIVE SUCCEED
1267 $LFS hsm_release $f || error "release of $f failed"
1269 do_node $CLIENT2 diff -q /etc/hosts $f
1272 # we check we had a restore done
1273 wait_request_state $fid RESTORE SUCCEED
1275 [[ $st -eq 0 ]] || error "Restored file differs"
1277 run_test 12h "Restore a released file implicitly from a second node"
1280 # test needs a running copytool
1284 local f=$DIR/$tdir/$tfile
1285 local fid=$(copy_file /etc/passwd $f)
1286 $LFS hsm_archive $f || error "archive of $f failed"
1287 wait_request_state $fid ARCHIVE SUCCEED
1289 $LFS hsm_release $f || error "release of $f failed"
1293 [[ $? -eq 0 ]] || error "Restored file differs"
1295 run_test 12m "Archive/release/implicit restore"
1298 # test needs a running copytool
1302 copy2archive /etc/hosts $tdir/$tfile
1304 local f=$DIR/$tdir/$tfile
1305 copytool import $tdir/$tfile $f
1307 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1308 error "Restored file differs"
1310 $LFS hsm_release $f || error "release of $f failed"
1312 run_test 12n "Import/implicit restore/release"
1315 # test needs a running copytool
1319 local f=$DIR/$tdir/$tfile
1320 local fid=$(copy_file /etc/hosts $f)
1322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1323 wait_request_state $fid ARCHIVE SUCCEED
1324 $LFS hsm_release $f || error "release of $f failed"
1326 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1327 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1329 # set no retry action mode
1332 diff -q /etc/hosts $f
1335 # we check we had a restore failure
1336 wait_request_state $fid RESTORE FAILED
1338 [[ $st -eq 0 ]] && error "Restore must fail"
1340 # remove no retry action mode
1343 # check file is still released
1344 check_hsm_flags $f "0x0000000d"
1346 # retry w/o failure injection
1347 do_facet $SINGLEMDS lctl set_param fail_loc=0
1349 # to be sure previous RESTORE result is gone
1351 wait_for_grace_delay
1353 diff -q /etc/hosts $f
1356 # we check we had a restore done
1357 wait_request_state $fid RESTORE SUCCEED
1359 [[ $st -eq 0 ]] || error "Restored file differs"
1361 run_test 12o "Layout-swap failure during Restore leaves file released"
1364 # test needs a running copytool
1368 local f=$DIR/$tdir/$tfile
1369 local fid=$(copy_file /etc/hosts $f)
1371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1372 wait_request_state $fid ARCHIVE SUCCEED
1373 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1374 $LFS hsm_release $f || error "cannot release $f"
1375 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1376 $LFS hsm_release $f || error "cannot release $f"
1377 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1379 run_test 12p "implicit restore of a file on copytool mount point"
1382 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1383 skip "need MDS version at least 2.7.58"
1385 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1386 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1387 error "cannot mount $MOUNT3 on $SINGLEAGT"
1389 # test needs a running copytool
1390 copytool setup -m "$MOUNT3"
1392 local f=$DIR/$tdir/$tfile
1393 local f2=$DIR2/$tdir/$tfile
1394 local fid=$(create_small_file $f)
1395 local orig_size=$(stat -c "%s" $f)
1397 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1398 wait_request_state $fid ARCHIVE SUCCEED
1400 $LFS hsm_release $f || error "could not release file"
1401 check_hsm_flags $f "0x0000000d"
1404 wait_copytools || error "copytool failed to stop"
1406 cat $f > /dev/null &
1408 # wait a bit to allow implicit restore request to be handled.
1409 # if not, next stat would also block on layout-lock.
1412 local size=$(stat -c "%s" $f2)
1413 [ $size -eq $orig_size ] ||
1414 error "$f2: wrong size after archive: $size != $orig_size"
1416 copytool setup -m "$MOUNT3"
1420 size=$(stat -c "%s" $f)
1421 [ $size -eq $orig_size ] ||
1422 error "$f: wrong size after restore: $size != $orig_size"
1424 size=$(stat -c "%s" $f2)
1425 [ $size -eq $orig_size ] ||
1426 error "$f2: wrong size after restore: $size != $orig_size"
1430 size=$(stat -c "%s" $f)
1432 error "$f: wrong size after overwrite: $size != 0"
1434 size=$(stat -c "%s" $f2)
1436 error "$f2: wrong size after overwrite: $size != 0"
1438 run_test 12q "file attributes are refreshed after restore"
1442 for i in {1..10}; do
1443 local archive_dir="$(hsm_root)"/subdir/dir.$i
1445 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1446 for j in {1..10}; do
1447 local archive_file="$archive_dir"/file.$j
1449 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1455 copytool import "subdir" "$DIR/$tdir"
1457 # To check the import, the test uses diff with the -r flag
1458 # This is nice, but diff only checks files one by one, and triggering
1459 # an implicit restore for one file at a time will consume as many
1460 # seconds as there are files to compare. To speed this up, a restore
1461 # operation is triggered manually first.
1463 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1465 # Compare the imported data
1466 do_facet $SINGLEAGT \
1467 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1468 error "imported files differ from archived data"
1470 run_test 13 "Recursively import and restore a directory"
1473 # test needs a running copytool
1477 local f=$DIR/$tdir/$tfile
1478 local fid=$(create_small_file $f)
1479 local sum=$(md5sum $f | awk '{print $1}')
1480 $LFS hsm_archive $f || error "could not archive file"
1481 wait_request_state $fid ARCHIVE SUCCEED
1483 # create released file (simulate llapi_hsm_import call)
1484 local fid2=$(create_empty_file "$f")
1485 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1486 $LFS hsm_release $f || error "could not release file"
1488 # rebind the archive to the newly created file
1489 echo "rebind $fid to $fid2"
1491 copytool rebind $fid $fid2
1493 # restore file and compare md5sum
1494 local sum2=$(md5sum $f | awk '{print $1}')
1496 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1498 run_test 14 "Rebind archived file to a new fid"
1501 # test needs a running copytool
1505 local f=$DIR/$tdir/$tfile
1507 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1511 for i in $(seq 1 $count); do
1512 fids[$i]=$(create_small_file $f.$i)
1513 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1514 $LFS hsm_archive $f.$i || error "could not archive file"
1516 wait_all_done $(($count*60))
1518 stack_trap "rm -f $tmpfile" EXIT
1521 for i in $(seq 1 $count); do
1522 local fid2=$(create_empty_file "${f}.${i}")
1523 # add the rebind operation to the list
1524 echo ${fids[$i]} $fid2 >> $tmpfile
1526 # set it released (simulate llapi_hsm_import call)
1527 $LFS hsm_set --archived --exists $f.$i ||
1528 error "could not force hsm flags"
1529 $LFS hsm_release $f.$i || error "could not release file"
1531 nl=$(wc -l < $tmpfile)
1532 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1534 echo "rebind list of files"
1535 copytool rebind "$tmpfile"
1537 # restore files and compare md5sum
1538 for i in $(seq 1 $count); do
1539 local sum2=$(md5sum $f.$i | awk '{print $1}')
1540 [[ $sum2 == ${sums[$i]} ]] ||
1541 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1544 run_test 15 "Rebind a list of files"
1547 # test needs a running copytool
1551 # create a known size file so we can verify transfer speed
1554 dd if=/dev/zero of=$ref bs=1M count=20
1557 local f=$DIR/$tdir/$tfile
1558 local fid=$(copy_file $ref $f)
1560 local start=$(date +%s)
1562 wait_request_state $fid ARCHIVE SUCCEED
1563 local end=$(date +%s)
1564 # Add 1 to account for rounding errors between start and end (LU-8155)
1565 local duration=$((end - start + 1))
1567 [[ $duration -ge $((goal - 1)) ]] ||
1568 error "Transfer is too fast $duration < $goal"
1570 run_test 16 "Test CT bandwith control option"
1573 local f=$DIR/$tdir/$tfile
1574 create_empty_file "$f"
1576 # Could not release a non-archived file
1577 $LFS hsm_release $f && error "release should not succeed"
1579 # For following tests, we must test them with HS_ARCHIVED set
1580 $LFS hsm_set --exists --archived $f || error "could not add flag"
1582 # Could not release a file if no-release is set
1583 $LFS hsm_set --norelease $f || error "could not add flag"
1584 $LFS hsm_release $f && error "release should not succeed"
1585 $LFS hsm_clear --norelease $f || error "could not remove flag"
1587 # Could not release a file if lost
1588 $LFS hsm_set --lost $f || error "could not add flag"
1589 $LFS hsm_release $f && error "release should not succeed"
1590 $LFS hsm_clear --lost $f || error "could not remove flag"
1592 # Could not release a file if dirty
1593 $LFS hsm_set --dirty $f || error "could not add flag"
1594 $LFS hsm_release $f && error "release should not succeed"
1595 $LFS hsm_clear --dirty $f || error "could not remove flag"
1597 run_test 20 "Release is not permitted"
1600 # test needs a running copytool
1603 local f=$DIR/$tdir/test_release
1605 # Create a file and check its states
1606 local fid=$(create_small_file $f)
1607 check_hsm_flags $f "0x00000000"
1609 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1610 # used until file is flushed to disk
1611 if [ $(facet_fstype ost1) == "zfs" ]; then
1612 # this causes an OST_SYNC rpc to be sent
1613 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1614 # clear locks to reread file data
1615 cancel_lru_locks osc
1618 local orig_size=$(stat -c "%s" $f)
1619 local orig_blocks=$(stat -c "%b" $f)
1621 start_full_debug_logging
1623 $LFS hsm_archive $f || error "could not archive file"
1624 wait_request_state $fid ARCHIVE SUCCEED
1626 local blocks=$(stat -c "%b" $f)
1627 [ $blocks -eq $orig_blocks ] ||
1628 error "$f: wrong block number after archive: " \
1629 "$blocks != $orig_blocks"
1630 local size=$(stat -c "%s" $f)
1631 [ $size -eq $orig_size ] ||
1632 error "$f: wrong size after archive: $size != $orig_size"
1634 # Release and check states
1635 $LFS hsm_release $f || error "could not release file"
1636 check_hsm_flags $f "0x0000000d"
1638 blocks=$(stat -c "%b" $f)
1639 [ $blocks -gt 5 ] &&
1640 error "$f: too many blocks after release: $blocks > 5"
1641 size=$(stat -c "%s" $f)
1642 [ $size -ne $orig_size ] &&
1643 error "$f: wrong size after release: $size != $orig_size"
1645 # Check we can release an file without stripe info
1649 check_hsm_flags $f "0x00000000"
1650 $LFS hsm_archive $f || error "could not archive file"
1651 wait_request_state $fid ARCHIVE SUCCEED
1653 # Release and check states
1654 $LFS hsm_release $f || error "could not release file"
1655 check_hsm_flags $f "0x0000000d"
1657 # Release again a file that is already released is OK
1658 $LFS hsm_release $f || fail "second release should succeed"
1659 check_hsm_flags $f "0x0000000d"
1661 stop_full_debug_logging
1663 run_test 21 "Simple release tests"
1666 # test needs a running copytool
1669 local f=$DIR/$tdir/test_release
1670 local swap=$DIR/$tdir/test_swap
1672 # Create a file and check its states
1673 local fid=$(create_small_file $f)
1674 check_hsm_flags $f "0x00000000"
1676 $LFS hsm_archive $f || error "could not archive file"
1677 wait_request_state $fid ARCHIVE SUCCEED
1679 # Release and check states
1680 $LFS hsm_release $f || error "could not release file"
1681 check_hsm_flags $f "0x0000000d"
1683 create_small_file $swap
1684 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1688 run_test 22 "Could not swap a release file"
1691 # test needs a running copytool
1694 local f=$DIR/$tdir/test_mtime
1696 # Create a file and check its states
1697 local fid=$(create_small_file $f)
1698 check_hsm_flags $f "0x00000000"
1700 $LFS hsm_archive $f || error "could not archive file"
1701 wait_request_state $fid ARCHIVE SUCCEED
1703 # Set modification time in the past
1704 touch -m -a -d @978261179 $f
1706 # Release and check states
1707 $LFS hsm_release $f || error "could not release file"
1708 check_hsm_flags $f "0x0000000d"
1710 local MTIME=$(stat -c "%Y" $f)
1711 local ATIME=$(stat -c "%X" $f)
1712 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1713 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1715 run_test 23 "Release does not change a/mtime (utime)"
1718 local file=$DIR/$tdir/$tfile
1727 # test needs a running copytool
1730 fid=$(create_small_file $file)
1732 # Create a file and check its states
1733 check_hsm_flags $file "0x00000000"
1735 # Ensure atime is less than mtime and ctime.
1739 atime0=$(stat -c "%X" $file)
1740 mtime0=$(stat -c "%Y" $file)
1741 ctime0=$(stat -c "%Z" $file)
1743 [ $atime0 -lt $mtime0 ] ||
1744 error "atime $atime0 is not less than mtime $mtime0"
1746 [ $atime0 -lt $ctime0 ] ||
1747 error "atime $atime0 is not less than ctime $ctime0"
1749 # Archive should not change any timestamps.
1750 $LFS hsm_archive $file || error "cannot archive '$file'"
1751 wait_request_state $fid ARCHIVE SUCCEED
1753 atime1=$(stat -c "%X" $file)
1754 mtime1=$(stat -c "%Y" $file)
1755 ctime1=$(stat -c "%Z" $file)
1757 [ $atime0 -eq $atime1 ] ||
1758 error "archive changed atime from $atime0 to $atime1"
1760 [ $mtime0 -eq $mtime1 ] ||
1761 error "archive changed mtime from $mtime0 to $mtime1"
1763 [ $ctime0 -eq $ctime1 ] ||
1764 error "archive changed ctime from $ctime0 to $ctime1"
1766 # Release should not change any timestamps.
1767 $LFS hsm_release $file || error "cannot release '$file'"
1768 check_hsm_flags $file "0x0000000d"
1770 atime1=$(stat -c "%X" $file)
1771 mtime1=$(stat -c "%Y" $file)
1772 ctime1=$(stat -c "%Z" $file)
1774 [ $atime0 -eq $atime1 ] ||
1775 error "release changed atime from $atime0 to $atime1"
1777 [ $mtime0 -eq $mtime1 ] ||
1778 error "release changed mtime from $mtime0 to $mtime1"
1780 [ $ctime0 -eq $ctime1 ] ||
1781 error "release changed ctime from $ctime0 to $ctime1"
1783 # Restore should not change any timestamps.
1784 $LFS hsm_restore $file
1785 wait_request_state $fid RESTORE SUCCEED
1787 atime1=$(stat -c "%X" $file)
1788 mtime1=$(stat -c "%Y" $file)
1789 ctime1=$(stat -c "%Z" $file)
1791 [ $atime0 -eq $atime1 ] ||
1792 error "restore changed atime from $atime0 to $atime1"
1794 [ $mtime0 -eq $mtime1 ] ||
1795 error "restore changed mtime from $mtime0 to $mtime1"
1797 [ $ctime0 -eq $ctime1 ] ||
1798 error "restore changed ctime from $ctime0 to $ctime1"
1801 wait_copytools || error "Copytools failed to stop"
1803 # Once more, after unmount and mount.
1804 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1805 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1807 atime1=$(stat -c "%X" $file)
1808 mtime1=$(stat -c "%Y" $file)
1809 ctime1=$(stat -c "%Z" $file)
1811 [ $atime0 -eq $atime1 ] ||
1812 error "remount changed atime from $atime0 to $atime1"
1814 [ $mtime0 -eq $mtime1 ] ||
1815 error "remount changed mtime from $mtime0 to $mtime1"
1817 [ $ctime0 -eq $ctime1 ] ||
1818 error "remount changed ctime from $ctime0 to $ctime1"
1820 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1823 local file=$DIR/$tdir/$tfile
1829 # Test needs a running copytool.
1832 # Check that root can do HSM actions on a regular user's file.
1833 fid=$(create_small_file $file)
1834 sum0=$(md5sum $file)
1836 chown $RUNAS_ID:$RUNAS_GID $file ||
1837 error "cannot chown '$file' to '$RUNAS_ID'"
1839 chmod ugo-w $DIR/$tdir ||
1840 error "cannot chmod '$DIR/$tdir'"
1842 $LFS hsm_archive $file
1843 wait_request_state $fid ARCHIVE SUCCEED
1845 $LFS hsm_release $file
1846 check_hsm_flags $file "0x0000000d"
1848 $LFS hsm_restore $file
1849 wait_request_state $fid RESTORE SUCCEED
1851 # Check that ordinary user can get HSM state.
1852 $RUNAS $LFS hsm_state $file ||
1853 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1855 $LFS hsm_release $file
1856 check_hsm_flags $file "0x0000000d"
1858 # Check that ordinary user can accessed released file.
1859 sum1=$($RUNAS md5sum $file) ||
1860 error "user '$RUNAS_ID' cannot read '$file'"
1862 [ "$sum0" == "$sum1" ] ||
1863 error "md5sum mismatch for '$file'"
1865 run_test 24b "root can archive, release, and restore user files"
1868 local file=$DIR/$tdir/$tfile
1869 local action=archive
1874 # test needs a running copytool
1879 # Save the default masks and check that cleanup_24c will
1880 # restore the request masks correctly.
1881 user_save=$(get_hsm_param user_request_mask)
1882 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1883 group_save=$(get_hsm_param group_request_mask)
1884 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1885 other_save=$(get_hsm_param other_request_mask)
1886 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1888 [ "$user_save" == RESTORE ] ||
1889 error "user_request_mask is '$user_save' expected 'RESTORE'"
1890 [ "$group_save" == RESTORE ] ||
1891 error "group_request_mask is '$group_save' expected 'RESTORE'"
1892 [ "$other_save" == RESTORE ] ||
1893 error "other_request_mask is '$other_save' expected 'RESTORE'"
1896 create_small_file $file
1897 chown $RUNAS_ID:$GROUP $file ||
1898 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1900 $RUNAS $LFS hsm_$action $file &&
1901 error "$action by user should fail"
1903 set_hsm_param user_request_mask $action
1904 $RUNAS $LFS hsm_$action $file ||
1905 error "$action by user should succeed"
1908 create_small_file $file
1909 chown nobody:$RUNAS_GID $file ||
1910 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1912 $RUNAS $LFS hsm_$action $file &&
1913 error "$action by group should fail"
1915 set_hsm_param group_request_mask $action
1916 $RUNAS $LFS hsm_$action $file ||
1917 error "$action by group should succeed"
1920 create_small_file $file
1921 chown nobody:$GROUP $file ||
1922 error "cannot chown '$file' to 'nobody:$GROUP'"
1924 $RUNAS $LFS hsm_$action $file &&
1925 error "$action by other should fail"
1927 set_hsm_param other_request_mask $action
1928 $RUNAS $LFS hsm_$action $file ||
1929 error "$action by other should succeed"
1931 run_test 24c "check that user,group,other request masks work"
1934 local file1=$DIR/$tdir/$tfile
1935 local file2=$DIR2/$tdir/$tfile
1939 fid1=$(create_small_file $file1)
1942 $LFS getstripe $file1
1944 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1945 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1946 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1948 copytool setup -m "$MOUNT3"
1950 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1951 mount -o remount,ro $MOUNT2
1953 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1955 fid2=$(path2fid $file2)
1956 [ "$fid1" == "$fid2" ] ||
1957 error "FID mismatch '$fid1' != '$fid2'"
1959 $LFS hsm_archive $file2 &&
1960 error "archive should fail on read-only mount"
1961 check_hsm_flags $file1 "0x00000000"
1963 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1964 wait_request_state $fid1 ARCHIVE SUCCEED
1966 $LFS hsm_release $file1
1967 $LFS hsm_restore $file2
1968 wait_request_state $fid1 RESTORE SUCCEED
1970 $LFS hsm_release $file1 || error "cannot release '$file1'"
1971 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1973 $LFS hsm_release $file2 &&
1974 error "release should fail on read-only mount"
1978 run_test 24d "check that read-only mounts are respected"
1983 local f=$DIR/$tdir/$tfile
1986 fid=$(create_small_file $f) || error "cannot create $f"
1987 $LFS hsm_archive $f || error "cannot archive $f"
1988 wait_request_state $fid ARCHIVE SUCCEED
1989 $LFS hsm_release $f || error "cannot release $f"
1990 while ! $LFS hsm_state $f | grep released; do
1994 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1996 run_test 24e "tar succeeds on HSM released files" # LU-6213
1999 # test needs a running copytool
2002 mkdir -p $DIR/$tdir/d1
2003 local f=$DIR/$tdir/$tfile
2004 local fid=$(copy_file /etc/hosts $f)
2007 $LFS hsm_archive $f ||
2008 error "hsm_archive failed"
2009 wait_request_state $fid ARCHIVE SUCCEED
2010 $LFS hsm_release $f || error "cannot release $f"
2011 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2014 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2015 error "Can not recover the tar contents"
2017 echo "Sum0 = $sum0, sum1 = $sum1"
2018 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2020 run_test 24f "root can archive, release, and restore tar files"
2023 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2024 skip "need MDS version 2.11.56 or later"
2026 local file=$DIR/$tdir/$tfile
2029 echo "RUNAS = '$RUNAS'"
2034 chmod ugo+rwx $DIR/$tdir
2036 echo "Please listen carefully as our options have changed." | tee $file
2037 fid=$(path2fid $file)
2040 $LFS hsm_archive $file
2041 wait_request_state $fid ARCHIVE SUCCEED
2042 check_hsm_flags $file 0x00000009 # exists archived
2044 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2045 check_hsm_flags $file 0x0000000b # exists dirty archived
2047 run_test 24g "write by non-owner still sets dirty" # LU-11369
2050 # test needs a running copytool
2054 copy2archive /etc/hosts $tdir/$tfile
2056 local f=$DIR/$tdir/$tfile
2058 copytool import $tdir/$tfile $f
2060 $LFS hsm_set --lost $f
2065 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2067 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2068 " (Operation not permitted)"
2071 # test needs a running copytool
2076 local f=$DIR/$tdir/$tfile
2077 local fid=$(copy_file /etc/passwd $f)
2079 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2080 wait_request_state $fid ARCHIVE SUCCEED
2083 $LFS hsm_set --lost $f
2087 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2089 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2090 " (Operation not permitted)"
2092 test_26A() { # was test_26
2093 # test needs a running copytool
2096 local f=$DIR/$tdir/$tfile
2097 local fid=$(create_empty_file "$f")
2099 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2100 wait_request_state $fid ARCHIVE SUCCEED
2103 wait_request_state $fid REMOVE SUCCEED
2105 check_hsm_flags $f "0x00000000"
2107 run_test 26A "Remove the archive of a valid file"
2110 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2111 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2113 # test needs a running copytool
2117 local f=$DIR/$tdir/$tfile
2118 local fid=$(copy_file /etc/passwd $f)
2120 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2121 wait_request_state $fid ARCHIVE SUCCEED
2123 local f2=$DIR/$tdir/${tfile}_2
2124 local fid2=$(copy_file /etc/passwd $f2)
2126 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2127 wait_request_state $fid2 ARCHIVE SUCCEED
2129 local f3=$DIR/$tdir/${tfile}_3
2130 local fid3=$(copy_file /etc/passwd $f3)
2132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2133 wait_request_state $fid3 ARCHIVE SUCCEED
2135 # set a long grace_delay vs short loop_period
2136 local orig_loop_period=$(get_hsm_param loop_period)
2137 local orig_grace_delay=$(get_hsm_param grace_delay)
2138 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2139 set_hsm_param loop_period 10
2140 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2141 set_hsm_param grace_delay 100
2145 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2146 set_hsm_param remove_archive_on_last_unlink 1
2148 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2153 wait_request_state $fid2 REMOVE SUCCEED
2155 assert_request_count $fid REMOVE 0 \
2156 "Unexpected archived data remove request for $f"
2157 assert_request_count $fid3 REMOVE 0 \
2158 "Unexpected archived data remove request for $f3"
2160 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2163 # test needs a running copytool
2167 local f=$DIR/$tdir/$tfile
2168 local fid=$(copy_file /etc/passwd $f)
2170 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2171 wait_request_state $fid ARCHIVE SUCCEED
2173 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2174 set_hsm_param remove_archive_on_last_unlink 1
2177 cdt_check_state stopped
2181 wait_request_state $fid REMOVE WAITING
2185 # copytool must re-register
2187 wait_copytools || error "copytool failed to stop"
2190 wait_request_state $fid REMOVE SUCCEED
2192 run_test 26b "RAoLU policy when CDT off"
2195 # test needs a running copytool
2199 local f=$DIR/$tdir/$tfile
2200 local fid=$(copy_file /etc/passwd $f)
2202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2203 wait_request_state $fid ARCHIVE SUCCEED
2205 local f2=$DIR/$tdir/${tfile}_2
2206 local fid2=$(copy_file /etc/passwd $f2)
2208 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2209 wait_request_state $fid2 ARCHIVE SUCCEED
2211 # set a long grace_delay vs short loop_period
2212 local orig_loop_period=$(get_hsm_param loop_period)
2213 local orig_grace_delay=$(get_hsm_param grace_delay)
2214 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2215 set_hsm_param loop_period 10
2216 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2217 set_hsm_param grace_delay 100
2219 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2220 set_hsm_param remove_archive_on_last_unlink 1
2222 multiop_bg_pause $f O_c || error "open $f failed"
2228 wait_request_state $fid2 REMOVE SUCCEED
2229 assert_request_count $fid REMOVE 0 \
2230 "Unexpected archived data remove request for $f"
2232 kill -USR1 $pid || error "multiop early exit"
2233 # should reach autotest timeout if multiop fails to trap
2234 # signal, close file, and exit ...
2235 wait $pid || error "wait PID $PID failed"
2237 wait_request_state $fid REMOVE SUCCEED
2239 run_test 26c "RAoLU effective when file closed"
2242 # test needs a running copytool
2246 local f=$DIR/$tdir/$tfile
2247 local fid=$(create_small_file $f)
2249 $LFS hsm_archive $f || error "could not archive file"
2250 wait_request_state $fid ARCHIVE SUCCEED
2252 # set a long grace_delay vs short loop_period
2253 local orig_loop_period=$(get_hsm_param loop_period)
2254 local orig_grace_delay=$(get_hsm_param grace_delay)
2255 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2256 set_hsm_param loop_period 10
2257 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2258 set_hsm_param grace_delay 100
2260 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2261 set_hsm_param remove_archive_on_last_unlink 1
2263 multiop_bg_pause $f O_c || error "multiop failed"
2270 wait_request_state $fid REMOVE SUCCEED
2272 client_up || client_up || true
2274 kill -USR1 $MULTIPID
2275 wait $MULTIPID || error "multiop close failed"
2277 run_test 26d "RAoLU when Client eviction"
2280 # test needs a running copytool
2283 create_archive_file $tdir/$tfile
2284 local f=$DIR/$tdir/$tfile
2285 copytool import $tdir/$tfile $f
2286 local fid=$(path2fid $f)
2290 [[ $? != 0 ]] || error "Remove of a released file should fail"
2292 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2295 # test needs a running copytool
2298 local f=$DIR/$tdir/$tfile
2299 local fid=$(create_empty_file "$f")
2301 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2302 wait_request_state $fid ARCHIVE SUCCEED
2307 [[ $? != 0 ]] || error "Remove of a released file should fail"
2309 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2312 # test needs a running copytool
2315 local f=$DIR/$tdir/$tfile
2316 local fid=$(create_empty_file "$f")
2318 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2319 wait_request_state $fid ARCHIVE SUCCEED
2328 wait_request_state $fid REMOVE SUCCEED
2330 run_test 28 "Concurrent archive/file remove"
2333 # Tests --mntpath and --archive options
2336 copytool setup -m "$MOUNT" -a $archive_id
2338 # Bad archive number
2339 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2340 grep "Invalid argument" ||
2341 error "unexpected hsm_remove failure (1)"
2343 # mntpath is present but file is given
2344 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2345 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2346 error "unexpected hsm_remove failure (2)"
2348 run_test 29a "Tests --mntpath and --archive options"
2351 # test needs a running copytool
2354 local f=$DIR/$tdir/$tfile
2355 local fid=$(create_small_file $f)
2357 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2358 wait_request_state $fid ARCHIVE SUCCEED
2362 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2363 wait_request_state $fid REMOVE SUCCEED
2365 run_test 29b "Archive/delete/remove by FID from the archive."
2368 # test needs a running copytool
2371 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2372 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2373 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2375 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2376 wait_request_state $fid1 ARCHIVE SUCCEED
2377 wait_request_state $fid2 ARCHIVE SUCCEED
2378 wait_request_state $fid3 ARCHIVE SUCCEED
2380 rm -f $DIR/$tdir/$tfile-[1-3]
2382 echo $fid1 > $DIR/$tdir/list
2383 echo $fid2 >> $DIR/$tdir/list
2384 echo $fid3 >> $DIR/$tdir/list
2386 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2387 --filelist $DIR/$tdir/list
2388 wait_request_state $fid1 REMOVE SUCCEED
2389 wait_request_state $fid2 REMOVE SUCCEED
2390 wait_request_state $fid3 REMOVE SUCCEED
2392 run_test 29c "Archive/delete/remove by FID, using a file list."
2395 # test needs more than one CT
2396 needclients 3 || return 0
2402 # start all of the copytools
2403 for n in $(seq $AGTCOUNT); do
2404 copytool setup -f agt$n -a $n
2408 file=$DIR/$tdir/$tfile
2409 fid=$(create_small_file $file)
2411 $LFS hsm_archive $file
2412 wait_request_state $fid ARCHIVE SUCCEED
2413 check_hsm_flags $file "0x00000009"
2417 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2418 error "cannot hsm_remove '$fid'"
2420 # give time for CDT to handle remove request and create broadcasted
2423 # remove request has been broadcasted ?
2424 local cnt=$(get_request_count $fid REMOVE)
2425 # broadcasted requests + original
2426 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2427 error "remove not broadcasted to all CTs"
2429 # give time for CDT and CTs to handle broadcasted
2430 wait_for_loop_period
2432 # each agent serves one different archive_id, so broadcasted
2433 # hsm_remove request should only succeed once and fail at all others
2437 for n in $(seq $AGTCOUNT); do
2438 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2439 $HSM_PARAM.actions | awk \
2440 '/'$fid'.*action=REMOVE archive#='$n'/ \
2441 {print \\\$13}' | cut -f2 -d=")
2442 if [[ "$res" == "SUCCEED" ]]; then
2444 elif [[ "$res" == "FAILED" ]]; then
2449 [[ $scnt -eq 1 ]] ||
2450 error "one and only CT should have removed successfully"
2452 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2453 error "all but one CT should have failed to remove"
2455 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2456 "request to be sent once for each registered archive_id"
2459 # restore at exec cannot work on agent node (because of Linux kernel
2460 # protection of executables)
2461 needclients 2 || return 0
2463 # test needs a running copytool
2467 copy2archive /bin/true $tdir/$tfile
2469 local f=$DIR/$tdir/true
2470 copytool import $tdir/$tfile $f
2472 local fid=$(path2fid $f)
2474 stack_trap "cdt_clear_no_retry" EXIT
2475 # set no retry action mode
2482 [[ $st == 0 ]] || error "Failed to exec a released file"
2484 run_test 30a "Restore at exec (import case)"
2487 # restore at exec cannot work on agent node (because of Linux kernel
2488 # protection of executables)
2489 needclients 2 || return 0
2491 # test needs a running copytool
2495 local f=$DIR/$tdir/true
2496 local fid=$(copy_file /bin/true $f)
2498 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2499 wait_request_state $fid ARCHIVE SUCCEED
2503 stack_trap cdt_clear_no_retry EXIT
2504 # set no retry action mode
2512 [[ $st == 0 ]] || error "Failed to exec a released file"
2514 run_test 30b "Restore at exec (release case)"
2517 needclients 2 || return 0
2519 # test needs a running copytool
2523 local f=$DIR/$tdir/SLEEP
2524 local slp_sum1=$(md5sum /bin/sleep)
2525 local fid=$(copy_file /bin/sleep $f)
2527 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2528 wait_request_state $fid ARCHIVE SUCCEED
2530 check_hsm_flags $f "0x0000000d"
2532 stack_trap cdt_clear_no_retry EXIT
2533 # set no retry action mode
2536 do_node $CLIENT2 "$f 10" &
2540 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2542 [[ $? == 0 ]] || error "Execution failed during run"
2544 if [[ $? != 0 ]]; then
2545 local slp_sum2=$(md5sum /bin/sleep)
2546 # in case sleep file is modified during the test
2547 [[ $slp_sum1 == $slp_sum2 ]] &&
2548 error "Binary overwritten during exec"
2551 check_hsm_flags $f "0x00000009"
2553 run_test 30c "Update during exec of released file must fail"
2555 restore_and_check_size() {
2558 local s=$(stat -c "%s" $f)
2560 local st=$(get_hsm_flags $f)
2564 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2566 n=$(stat -c "%s" $f)
2567 # we echo in both cases to show stat is not hang
2568 if [[ $n != $s ]]; then
2569 echo "size seen is $n != $s"
2572 echo "size seen is right: $n == $s"
2576 st=$(get_hsm_flags $f)
2578 if [[ "$st" = "0x00000009" ]]; then
2581 echo " restore is too long"
2582 wait_request_state $fid RESTORE SUCCEED
2588 # test needs a running copytool
2591 create_archive_file $tdir/$tfile
2592 local f=$DIR/$tdir/$tfile
2593 copytool import $tdir/$tfile $f
2594 local fid=$($LFS path2fid $f)
2597 restore_and_check_size $f $fid
2600 [[ $err -eq 0 ]] || error "File size changed during restore"
2602 run_test 31a "Import a large file and check size during restore"
2606 # test needs a running copytool
2609 local f=$DIR/$tdir/$tfile
2610 local fid=$(create_file "$f" 1MB 39)
2612 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2613 wait_request_state $fid ARCHIVE SUCCEED
2616 restore_and_check_size $f $fid
2619 [[ $err -eq 0 ]] || error "File size changed during restore"
2621 run_test 31b "Restore a large unaligned file and check size during restore"
2624 # test needs a running copytool
2627 local f=$DIR/$tdir/$tfile
2628 local fid=$(create_file "$f" 1M 39)
2630 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2631 wait_request_state $fid ARCHIVE SUCCEED
2634 restore_and_check_size $f $fid
2637 [[ $err -eq 0 ]] || error "File size changed during restore"
2639 run_test 31c "Restore a large aligned file and check size during restore"
2642 local f=$DIR/$tdir/$tfile
2643 local fid=$(create_empty_file "$f")
2647 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2648 wait_request_state $fid ARCHIVE SUCCEED
2651 # Prevent restore from completing
2655 md5sum $f >/dev/null &
2658 wait_request_state $fid RESTORE STARTED
2663 # Check restore trigger process was killed
2665 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2667 run_test 33 "Kill a restore waiting process"
2670 # test needs a running copytool
2673 local f=$DIR/$tdir/$tfile
2674 local fid=$(create_empty_file "$f")
2676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2677 wait_request_state $fid ARCHIVE SUCCEED
2680 # Prevent restore from completing
2683 md5sum $f >/dev/null &
2686 wait_request_state $fid RESTORE STARTED
2688 # rm must not block during restore
2689 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2692 wait_request_state $fid RESTORE SUCCEED
2694 # Check md5sum pgm finished
2695 kill -0 $pid && error "Restore initiatior still running"
2696 wait $pid || error "Restore initiator failed with $?"
2698 # Check the file was actually deleted
2699 [ ! -f "$f" ] || error "$f was not deleted"
2701 run_test 34 "Remove file during restore"
2704 # test needs a running copytool
2707 local f=$DIR/$tdir/$tfile
2708 local f1=$DIR/$tdir/$tfile-1
2709 local fid=$(create_empty_file "$f")
2710 local fid1=$(copy_file /etc/passwd $f1)
2712 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2713 wait_request_state $fid ARCHIVE SUCCEED
2716 # Prevent restore from completing
2719 md5sum $f >/dev/null &
2722 wait_request_state $fid RESTORE STARTED
2724 # mv must not block during restore
2725 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2728 wait_request_state $fid RESTORE SUCCEED
2730 # Check md5sum pgm finished
2731 kill -0 $pid && error "Restore initiatior still running"
2732 wait $pid || error "Restore initiator failed with $?"
2734 local fid2=$(path2fid $f)
2735 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2737 run_test 35 "Overwrite file during restore"
2740 # test needs a running copytool
2743 local f=$DIR/$tdir/$tfile
2744 local fid=$(create_empty_file "$f")
2746 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2747 wait_request_state $fid ARCHIVE SUCCEED
2750 # Prevent restore from completing
2753 md5sum $f >/dev/null &
2756 wait_request_state $fid RESTORE STARTED
2758 # mv must not block during restore
2759 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2760 error "mv '$f' '$f.new' failed with rc=$?"
2763 wait_request_state $fid RESTORE SUCCEED
2765 # Check md5sum pgm finished
2766 kill -0 $pid && error "Restore initiator is still running"
2767 wait $pid || error "Restore initiator failed with $?"
2769 run_test 36 "Move file during restore"
2772 # LU-5683: check that an archived dirty file can be rearchived.
2775 local f=$DIR/$tdir/$tfile
2778 fid=$(create_small_file $f) || error "cannot create small file"
2780 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2781 wait_request_state $fid ARCHIVE SUCCEED
2782 $LFS hsm_release $f || error "cannot release $f"
2784 # Allow previous archive request to expire from the actions log.
2785 wait_for_grace_delay
2788 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2790 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2791 wait_request_state $fid ARCHIVE SUCCEED
2793 run_test 37 "re-archive a dirty file"
2800 for n in $(seq 1 $count); do
2801 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2803 echo "$count archive requests submitted"
2807 local stream_count=4
2808 local file_count=100
2810 local f=$DIR/$tdir/$tfile
2814 local max_requests=$(get_hsm_param max_requests)
2816 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2817 # Increase the number of HSM request that can be performed in
2818 # parallel. With the coordinator running once per second, this
2819 # also limits the number of requests per seconds that can be
2820 # performed, so we pick a decent number. But we also need to keep
2821 # that number low because the copytool has no rate limit and will
2822 # fail some requests if if gets too many at once.
2823 set_hsm_param max_requests 300
2825 for i in $(seq 1 $file_count); do
2826 for p in $(seq 1 $stream_count); do
2827 fid=$(copy_file /etc/hosts $f.$p.$i)
2833 # to be sure wait_all_done will not be mislead by previous tests
2835 wait_for_grace_delay
2837 # start archive streams in background (archive files in parallel)
2838 for p in $(seq 1 $stream_count); do
2839 multi_archive $f.$p $file_count &
2842 echo -n "Wait for all requests being enqueued..."
2847 run_test 40 "Parallel archive requests"
2850 # test needs a running copytool
2854 local f=$DIR/$tdir/$tfile
2855 local fid=$(create_small_file $f)
2857 $LFS hsm_archive $f || error "could not archive file"
2858 wait_request_state $fid ARCHIVE SUCCEED
2859 check_hsm_flags $f "0x00000009"
2861 multiop_bg_pause $f O_c || error "multiop failed"
2865 client_up || client_up || true
2867 kill -USR1 $MULTIPID
2868 wait $MULTIPID || error "multiop close failed"
2870 check_hsm_flags $f "0x0000000b"
2872 run_test 52 "Opened for write file on an evicted client should be set dirty"
2875 # test needs a running copytool
2879 local f=$DIR/$tdir/$tfile
2880 local fid=$(create_small_file $f)
2882 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2883 error "could not archive file"
2884 wait_request_state $fid ARCHIVE SUCCEED
2885 check_hsm_flags $f "0x00000009"
2887 multiop_bg_pause $f o_c || error "multiop failed"
2891 client_up || client_up || true
2893 kill -USR1 $MULTIPID
2894 wait $MULTIPID || error "multiop close failed"
2896 check_hsm_flags $f "0x00000009"
2898 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2901 local f=$DIR/$tdir/$tfile
2902 local fid=$(create_file "$f" 1MB 39)
2906 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2907 error "could not archive file"
2908 wait_request_state $fid ARCHIVE STARTED
2910 check_hsm_flags $f "0x00000001"
2912 stack_trap "cdt_clear_no_retry" EXIT
2913 # Avoid coordinator resending this request as soon it has failed.
2918 wait_request_state $fid ARCHIVE FAILED
2920 check_hsm_flags $f "0x00000003"
2922 run_test 54 "Write during an archive cancels it"
2925 local f=$DIR/$tdir/$tfile
2926 local fid=$(create_file "$f" 1MB 39)
2930 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2931 error "could not archive file"
2932 wait_request_state $fid ARCHIVE STARTED
2934 check_hsm_flags $f "0x00000001"
2936 stack_trap "cdt_clear_no_retry" EXIT
2937 # Avoid coordinator resending this request as soon it has failed.
2940 $TRUNCATE $f 1024 || error "truncate failed"
2942 wait_request_state $fid ARCHIVE FAILED
2944 check_hsm_flags $f "0x00000003"
2946 run_test 55 "Truncate during an archive cancels it"
2949 local f=$DIR/$tdir/$tfile
2950 local fid=$(create_file "$f" 1MB 39)
2954 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2955 error "could not archive file"
2956 wait_request_state $fid ARCHIVE STARTED
2958 check_hsm_flags $f "0x00000001"
2960 # Change metadata and sync to be sure we are not changing only
2965 wait_request_state $fid ARCHIVE SUCCEED
2967 check_hsm_flags $f "0x00000009"
2969 run_test 56 "Setattr during an archive is ok"
2972 # Need one client for I/O, one for request
2973 needclients 2 || return 0
2975 # test needs a running copytool
2979 local f=$DIR/$tdir/test_archive_remote
2980 # Create a file on a remote node
2981 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2982 "count=2 conv=fsync"
2985 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2986 error "hsm_archive failed"
2987 local fid=$(path2fid $f)
2988 wait_request_state $fid ARCHIVE SUCCEED
2990 # Release and implicit restore it
2991 do_node $CLIENT2 "$LFS hsm_release $f" ||
2992 error "hsm_release failed"
2993 do_node $CLIENT2 "md5sum $f" ||
2994 error "hsm_restore failed"
2996 wait_request_state $fid RESTORE SUCCEED
2998 run_test 57 "Archive a file with dirty cache on another node"
3000 truncate_released_file() {
3004 local sz=$(stat -c %s $src_file)
3005 local f=$DIR/$tdir/$tfile
3006 local fid=$(copy_file $1 $f)
3010 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3011 error "could not archive file"
3012 wait_request_state $fid ARCHIVE SUCCEED
3014 $LFS hsm_release $f || error "could not release file"
3016 $TRUNCATE $f $trunc_to || error "truncate failed"
3019 local sz1=$(stat -c %s $f)
3020 [[ $sz1 == $trunc_to ]] ||
3021 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3024 check_hsm_flags $f "0x0000000b"
3026 local state=$(get_request_state $fid RESTORE)
3027 [[ "$state" == "SUCCEED" ]] ||
3028 error "truncate $sz does not trig restore, state = $state"
3030 $TRUNCATE $ref $trunc_to
3031 cmp $ref $f || error "file data wrong after truncate"
3037 # test needs a running copytool
3042 local sz=$(stat -c %s /etc/passwd)
3044 echo "truncate up from $sz to $((sz*2))"
3045 truncate_released_file /etc/passwd $((sz*2))
3047 echo "truncate down from $sz to $((sz/2))"
3048 truncate_released_file /etc/passwd $((sz/2))
3050 echo "truncate to 0"
3051 truncate_released_file /etc/passwd 0
3053 run_test 58 "Truncate a released file will trigger restore"
3057 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3058 skip "Need MDS version at least 2.7.63"
3061 $MCREATE $DIR/$tfile || error "mcreate failed"
3062 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3063 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3064 fid=$(path2fid $DIR/$tfile)
3065 wait_request_state $fid ARCHIVE SUCCEED
3066 $LFS hsm_release $DIR/$tfile || error "release failed"
3068 run_test 59 "Release stripeless file with non-zero size"
3071 # This test validates the fix for LU-4512. Ensure that the -u
3072 # option changes the progress reporting interval from the
3073 # default (30 seconds) to the user-specified interval.
3074 local f=$DIR/$tdir/$tfile
3075 local fid=$(create_file "$f" 1M 10)
3078 local progress_timeout=$((interval * 4))
3079 copytool setup -b 1 --update-interval $interval
3082 local mdt=${MDT_PREFIX}${mdtidx}
3083 local mds=mds$((mdtidx + 1))
3085 # Wait for copytool to register
3086 wait_update_facet $mds \
3087 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3088 uuid 100 || error "coyptool failed to register with $mdt"
3090 local start_at=$(date +%s)
3091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3092 error "could not archive file"
3094 local agent=$(facet_active_host $SINGLEAGT)
3095 local logfile=$(copytool_logfile $SINGLEAGT)
3097 wait_update $agent \
3098 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3099 error "copytool failed to start"
3101 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3102 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3108 echo -n "Expecting a progress update within $progress_timeout seconds... "
3110 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3111 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3112 echo "$RESULT bytes copied in $WAIT seconds."
3114 elif [ $WAIT -ge $progress_timeout ]; then
3115 error "Timed out waiting for progress update!"
3118 WAIT=$((WAIT + sleep))
3122 local finish_at=$(date +%s)
3123 local elapsed=$((finish_at - start_at))
3125 # Ensure that the progress update occurred within the expected window.
3126 if [ $elapsed -lt $((interval - 1)) ]; then
3127 error "Expected progress update after at least $interval seconds"
3130 echo "Wait for on going archive hsm action to complete"
3131 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3132 echo "File archiving not completed even after 10 secs"
3134 run_test 60 "Changing progress update interval from default"
3137 # test needs a running copytool
3141 local f=$DIR/$tdir/$tfile
3142 local fid=$(copy_file /etc/passwd $f)
3144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3147 wait_request_state $fid ARCHIVE FAILED
3149 run_test 61 "Waiting archive of a removed file should fail"
3152 # test needs a new running copytool
3153 stack_trap copytool_monitor_cleanup EXIT
3154 copytool_monitor_setup
3155 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3157 # Wait for the copytool to register.
3158 wait_update --verbose $(facet_active_host mds1) \
3159 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3161 error "copytool failed to register with MDT0000"
3164 wait_copytools || error "Copytools failed to stop"
3166 local REGISTER_EVENT
3167 local UNREGISTER_EVENT
3168 while read event; do
3169 local parsed=$(parse_json_event "$event")
3170 if [ -z "$parsed" ]; then
3171 error "Copytool sent malformed event: $event"
3175 if [ $event_type == "REGISTER" ]; then
3176 REGISTER_EVENT=$event
3177 elif [ $event_type == "UNREGISTER" ]; then
3178 UNREGISTER_EVENT=$event
3180 done < <(echo $"$(get_copytool_event_log)")
3182 if [ -z "$REGISTER_EVENT" ]; then
3183 error "Copytool failed to send register event to FIFO"
3186 if [ -z "$UNREGISTER_EVENT" ]; then
3187 error "Copytool failed to send unregister event to FIFO"
3190 echo "Register/Unregister events look OK."
3192 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3195 # Bump progress interval for livelier events.
3198 # test needs a new running copytool
3199 stack_trap copytool_monitor_cleanup EXIT
3200 copytool_monitor_setup
3201 copytool setup --update-interval $interval --event-fifo \
3202 "$HSMTOOL_MONITOR_DIR/fifo"
3204 stack_trap "cdt_clear_no_retry" EXIT
3205 # Just start and stop the copytool to generate events.
3208 local f=$DIR/$tdir/$tfile
3209 local fid=$(create_small_file "$f")
3211 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3212 error "could not archive file"
3213 wait_request_state $fid ARCHIVE SUCCEED
3215 local expected_fields="event_time data_fid source_fid"
3216 expected_fields+=" total_bytes current_bytes"
3219 [ARCHIVE_START]=false
3220 [ARCHIVE_FINISH]=false
3221 [ARCHIVE_RUNNING]=false
3223 while read event; do
3224 # Make sure we're not getting anything from previous events.
3225 for field in $expected_fields; do
3229 local parsed=$(parse_json_event "$event")
3230 if [ -z "$parsed" ]; then
3231 error "Copytool sent malformed event: $event"
3235 events["$event_type"]=true
3237 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3239 # Do some simple checking of the progress update events.
3240 for expected_field in $expected_fields; do
3241 if [ -z ${!expected_field+x} ]; then
3242 error "Missing $expected_field field in event"
3246 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3248 # These should be identical throughout an archive operation
3249 [ $source_fid == $data_fid ] ||
3250 error "Expected source_fid to equal data_fid"
3251 done < <(echo $"$(get_copytool_event_log)")
3253 # Check we received every type of events we were expecting
3254 for event in "${!events[@]}"; do
3255 ${events["$event"]} ||
3256 error "Copytool failed to send '$event' event to FIFO"
3259 echo "Archive events look OK."
3261 run_test 71 "Copytool logs JSON archive events to FIFO"
3264 # Bump progress interval for livelier events.
3267 # test needs a new running copytool
3268 stack_trap copytool_monitor_cleanup EXIT
3269 copytool_monitor_setup
3270 copytool setup --update-interval $interval --event-fifo \
3271 "$HSMTOOL_MONITOR_DIR/fifo"
3272 local test_file=$HSMTOOL_MONITOR_DIR/file
3274 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3276 do_facet $SINGLEAGT "$cmd" ||
3277 error "cannot create $test_file on $SINGLEAGT"
3278 copy2archive $test_file $tdir/$tfile
3281 local f=$DIR/$tdir/$tfile
3282 copytool import $tdir/$tfile $f
3283 f=$DIR2/$tdir/$tfile
3284 echo "Verifying released state: "
3285 check_hsm_flags $f "0x0000000d"
3287 local fid=$(path2fid $f)
3289 wait_request_state $fid RESTORE SUCCEED
3291 local expected_fields="event_time data_fid source_fid"
3292 expected_fields+=" total_bytes current_bytes"
3296 while read event; do
3297 # Make sure we're not getting anything from previous events.
3298 for field in $expected_fields; do
3302 local parsed=$(parse_json_event "$event")
3303 if [ -z "$parsed" ]; then
3304 error "Copytool sent malformed event: $event"
3308 if [ $event_type == "RESTORE_START" ]; then
3310 if [ $source_fid != $data_fid ]; then
3311 error "source_fid should == data_fid at start"
3314 elif [ $event_type == "RESTORE_FINISH" ]; then
3316 if [ $source_fid != $data_fid ]; then
3317 error "source_fid should == data_fid at finish"
3320 elif [ $event_type != "RESTORE_RUNNING" ]; then
3324 # Do some simple checking of the progress update events.
3325 for expected_field in $expected_fields; do
3326 if [ -z ${!expected_field+x} ]; then
3327 error "Missing $expected_field field in event"
3331 if [ $total_bytes -eq 0 ]; then
3332 error "Expected total_bytes to be > 0"
3335 # When a restore starts out, the data fid is the same as the
3336 # source fid. After the restore has gotten going, we learn
3337 # the new data fid. Once the restore has finished, the source
3338 # fid is set to the new data fid.
3340 # We test this because some monitoring software may depend on
3341 # this behavior. If it changes, then the consumers of these
3342 # events may need to be modified.
3343 if [ $source_fid == $data_fid ]; then
3344 error "source_fid should != data_fid during restore"
3346 done < <(echo $"$(get_copytool_event_log)")
3348 if [ -z "$START_EVENT" ]; then
3349 error "Copytool failed to send restore start event to FIFO"
3352 if [ -z "$FINISH_EVENT" ]; then
3353 error "Copytool failed to send restore finish event to FIFO"
3356 echo "Restore events look OK."
3358 run_test 72 "Copytool logs JSON restore events to FIFO"
3361 file_count=51 # Max number of files constrained by LNET message size
3362 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3363 local f=$DIR/$tdir/$tfile
3364 local FILELIST=/tmp/filelist.txt
3368 for i in $(seq 1 $file_count); do
3369 fid=$(copy_file /etc/hosts $f.$i)
3370 echo $f.$i >> $FILELIST
3374 # to be sure wait_all_done will not be mislead by previous tests
3376 wait_for_grace_delay
3377 $LFS hsm_archive --filelist $FILELIST ||
3378 error "cannot archive a file list"
3380 $LFS hsm_release --filelist $FILELIST ||
3381 error "cannot release a file list"
3382 $LFS hsm_restore --filelist $FILELIST ||
3383 error "cannot restore a file list"
3386 run_test 90 "Archive/restore a file list"
3388 double_verify_reset_hsm_param() {
3390 echo "Testing $HSM_PARAM.$p"
3391 local val=$(get_hsm_param $p)
3393 local val2=$(($val * 2))
3394 set_hsm_param $p $val2
3395 val=$(get_hsm_param $p)
3396 [[ $val == $val2 ]] ||
3397 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3398 echo "Set $p to 0 must failed"
3402 set_hsm_param $p $save
3404 if [[ $rc == 0 ]]; then
3405 error "we must not be able to set $HSM_PARAM.$p to 0"
3410 double_verify_reset_hsm_param loop_period
3411 double_verify_reset_hsm_param grace_delay
3412 double_verify_reset_hsm_param active_request_timeout
3413 double_verify_reset_hsm_param max_requests
3414 double_verify_reset_hsm_param default_archive_id
3416 run_test 100 "Set coordinator /proc tunables"
3423 run_test 102 "Verify coordinator control"
3426 # test needs a running copytool
3433 for i in $(seq 1 20); do
3434 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3436 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3440 echo "Current requests"
3441 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3442 $HSM_PARAM.actions |\
3443 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3445 [[ -z "$res" ]] || error "Some request have not been canceled"
3447 run_test 103 "Purge all requests"
3452 local f=$DIR/$tdir/$tfile
3453 local fid=$(create_empty_file "$f")
3455 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3456 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3457 $HSM_PARAM.actions |\
3458 grep $fid | cut -f16 -d=")
3460 [[ "$data1" == "$DATAHEX" ]] ||
3461 error "Data field in records is ($data1) and not ($DATAHEX)"
3465 run_test 104 "Copy tool data field"
3468 local max_requests=$(get_hsm_param max_requests)
3472 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3473 set_hsm_param max_requests 300
3476 for i in $(seq -w 1 10); do
3477 cp /etc/passwd $DIR/$tdir/$i
3478 $LFS hsm_archive $DIR/$tdir/$i
3480 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3481 $HSM_PARAM.actions |\
3482 grep WAITING | wc -l")
3486 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3487 $HSM_PARAM.actions |\
3488 grep WAITING | wc -l")
3491 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3492 error "Requests count after shutdown $reqcnt2 != "\
3493 "before shutdown $reqcnt1"
3495 run_test 105 "Restart of coordinator"
3498 # test needs a running copytool
3501 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3503 check_agent_registered $uuid
3505 search_copytools || error "No copytool found"
3508 wait_copytools || error "Copytool failed to stop"
3510 check_agent_unregistered $uuid
3513 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3514 check_agent_registered $uuid
3516 run_test 106 "Copytool register/unregister"
3519 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3521 # test needs a running copytool
3523 # create and archive file
3525 local f1=$DIR/$tdir/$tfile
3526 local fid=$(copy_file /etc/passwd $f1)
3527 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3528 wait_request_state $fid ARCHIVE SUCCEED
3529 # shutdown and restart MDS
3531 # check the copytool still gets messages from MDT
3532 local f2=$DIR/$tdir/2
3533 local fid=$(copy_file /etc/passwd $f2)
3534 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3535 # main check of this sanity: this request MUST succeed
3536 wait_request_state $fid ARCHIVE SUCCEED
3538 run_test 107 "Copytool re-register after MDS restart"
3540 policy_set_and_test()
3544 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3545 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3546 [[ "$policy" == "$target" ]] ||
3547 error "Wrong policy after '$change': '$policy' != '$target'"
3551 # to force default policy setting if error
3552 CDT_POLICY_HAD_CHANGED=true
3554 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3555 local default="NonBlockingRestore [NoRetryAction]"
3556 [[ "$policy" == "$default" ]] ||
3557 error "default policy has changed,"\
3558 " '$policy' != '$default' update the test"
3559 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3560 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3561 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3562 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3563 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3564 # useless bacause we know but safer for futur changes to use real value
3565 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3566 echo "Next set_param must failed"
3567 policy_set_and_test "wrong" "$policy"
3570 echo "Back to default policy"
3571 cdt_set_sanity_policy
3573 run_test 109 "Policy display/change"
3576 # test needs a running copytool
3581 copy2archive /etc/passwd $tdir/$tfile
3583 local f=$DIR/$tdir/$tfile
3584 copytool import $tdir/$tfile $f
3585 local fid=$(path2fid $f)
3587 cdt_set_non_blocking_restore
3592 wait_request_state $fid RESTORE SUCCEED
3593 cdt_clear_non_blocking_restore
3597 error "md5sum returns $st != 1, "\
3598 "should also perror ENODATA (No data available)"
3600 run_test 110a "Non blocking restore policy (import case)"
3603 # test needs a running copytool
3607 local f=$DIR/$tdir/$tfile
3608 local fid=$(copy_file /etc/passwd $f)
3609 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3610 wait_request_state $fid ARCHIVE SUCCEED
3613 cdt_set_non_blocking_restore
3618 wait_request_state $fid RESTORE SUCCEED
3619 cdt_clear_non_blocking_restore
3623 error "md5sum returns $st != 1, "\
3624 "should also perror ENODATA (No data available)"
3626 run_test 110b "Non blocking restore policy (release case)"
3629 # test needs a running copytool
3633 copy2archive /etc/passwd $tdir/$tfile
3635 local f=$DIR/$tdir/$tfile
3637 copytool import $tdir/$tfile $f
3638 local fid=$(path2fid $f)
3642 copytool_remove_backend $fid
3645 wait_request_state $fid RESTORE FAILED
3652 [[ $st == 0 ]] || error "Restore does not failed"
3654 run_test 111a "No retry policy (import case), restore will error"\
3655 " (No such file or directory)"
3658 # test needs a running copytool
3662 local f=$DIR/$tdir/$tfile
3663 local fid=$(copy_file /etc/passwd $f)
3664 stack_trap cdt_clear_no_retry EXIT
3666 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3667 wait_request_state $fid ARCHIVE SUCCEED
3670 copytool_remove_backend $fid
3673 wait_request_state $fid RESTORE FAILED
3677 [[ $st == 0 ]] || error "Restore does not failed"
3679 run_test 111b "No retry policy (release case), restore will error"\
3680 " (No such file or directory)"
3683 # test needs a running copytool
3687 local f=$DIR/$tdir/$tfile
3688 local fid=$(copy_file /etc/passwd $f)
3690 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3691 local l=$($LFS hsm_action $f)
3693 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3696 wait_request_state $fid ARCHIVE SUCCEED
3699 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3701 run_test 112 "State of recorded request"
3704 local file1=$DIR/$tdir/$tfile
3705 local file2=$DIR2/$tdir/$tfile
3707 local fid=$(create_small_sync_file $file1)
3709 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3710 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3711 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3713 copytool setup -m "$MOUNT3"
3715 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3717 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3718 wait_request_state $fid ARCHIVE SUCCEED
3720 $LFS hsm_release $file1
3721 echo "Verifying released state: "
3722 check_hsm_flags $file1 "0x0000000d"
3724 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3727 kill -USR1 $MULTIPID
3732 local size1=$(stat -c "%s" $file1)
3733 local size2=$(stat -c "%s" $file2)
3735 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3737 run_test 113 "wrong stat after restore"
3740 local f=$DIR/$tdir/$tfile
3741 local fid=$(create_empty_file "$f")
3745 # Prevent archive from completing
3748 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3749 # wait archive to register at CDT
3750 wait_request_state $fid ARCHIVE STARTED
3752 # Cancel the archive
3753 $LFS hsm_cancel "$f"
3755 wait_request_state $fid ARCHIVE CANCELED
3758 wait_request_state $fid CANCEL SUCCEED
3760 run_test 200 "Register/Cancel archive"
3763 # test needs a running copytool
3766 local f=$DIR/$tdir/$tfile
3767 create_archive_file $tdir/$tfile
3768 copytool import $tdir/$tfile $f
3769 local fid=$(path2fid $f)
3771 # test with cdt on is made in test_222
3774 # wait restore to register at CDT
3775 wait_request_state $fid RESTORE WAITING
3778 wait_request_state $fid RESTORE CANCELED
3779 wait_request_state $fid CANCEL SUCCEED
3781 run_test 201 "Register/Cancel restore"
3784 local f=$DIR/$tdir/$tfile
3785 local fid=$(create_empty_file "$f")
3787 # test needs a running copytool
3790 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3791 wait_request_state $fid ARCHIVE SUCCEED
3795 # wait remove to register at CDT
3796 wait_request_state $fid REMOVE STARTED
3799 wait_request_state $fid REMOVE CANCELED
3801 run_test 202 "Register/Cancel remove"
3803 test_220A() { # was test_220
3804 # test needs a running copytool
3809 local f=$DIR/$tdir/$tfile
3810 local fid=$(copy_file /etc/passwd $f)
3814 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3815 wait_request_state $fid ARCHIVE SUCCEED
3817 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3818 error "The expected changelog was not emitted"
3820 run_test 220A "Changelog for archive"
3823 # test needs a running copytool
3828 local f=$DIR/$tdir/$tfile
3829 local fid=$(copy_file /etc/passwd $f)
3833 # block copytool operations to allow for HSM request to be
3834 # submitted and file be unlinked (CDT will find object removed)
3837 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3839 # wait request to reach CT
3840 wait_request_state $fid ARCHIVE STARTED
3846 wait_request_state $fid ARCHIVE FAILED
3849 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3850 error "The expected changelog was not emitted"
3852 run_test 220a "Changelog for failed archive"
3855 local f=$DIR/$tdir/$tfile
3856 local fid=$(create_empty_file "$f")
3861 # Prevent archive from completing
3863 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3864 wait_request_state $fid ARCHIVE STARTED
3867 wait_request_state $fid ARCHIVE CANCELED
3870 wait_request_state $fid CANCEL SUCCEED
3872 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3873 error "The expected changelog was not emitted"
3875 run_test 221 "Changelog for archive canceled"
3878 # test needs a running copytool
3882 copy2archive /etc/passwd $tdir/$tfile
3884 local f=$DIR/$tdir/$tfile
3885 copytool import $tdir/$tfile $f
3886 local fid=$(path2fid $f)
3891 wait_request_state $fid RESTORE SUCCEED
3893 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3894 error "The expected changelog was not emitted"
3896 run_test 222a "Changelog for explicit restore"
3899 # test needs a running copytool
3903 local f=$DIR/$tdir/$tfile
3904 local fid=$(copy_file /etc/passwd $f)
3907 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3908 wait_request_state $fid ARCHIVE SUCCEED
3913 wait_request_state $fid RESTORE SUCCEED
3915 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3916 error "The expected changelog was not emitted"
3918 run_test 222b "Changelog for implicit restore"
3921 # test needs a running copytool
3925 copy2archive /etc/passwd $tdir/$tfile
3927 local f=$DIR/$tdir/$tfile
3928 copytool import $tdir/$tfile $f
3929 local fid=$(path2fid $f)
3933 # block copytool operations to allow for HSM request to be
3934 # submitted and file be unlinked (CDT will find object removed)
3939 # wait request to reach CT
3940 wait_request_state $fid RESTORE STARTED
3946 wait_request_state $fid RESTORE FAILED
3949 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3950 error "The expected changelog was not emitted"
3952 run_test 222c "Changelog for failed explicit restore"
3955 # test needs a running copytool
3959 local f=$DIR/$tdir/$tfile
3960 local fid=$(copy_file /etc/passwd $f)
3963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3964 wait_request_state $fid ARCHIVE SUCCEED
3967 copytool_remove_backend $fid
3970 wait_request_state $fid RESTORE FAILED
3973 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3974 error "The expected changelog was not emitted"
3976 run_test 222d "Changelog for failed implicit restore"
3979 # test needs a running copytool
3982 local f=$DIR/$tdir/$tfile
3983 create_archive_file $tdir/$tfile
3987 copytool import $tdir/$tfile $f
3988 local fid=$(path2fid $f)
3991 wait_request_state $fid RESTORE STARTED
3993 wait_request_state $fid RESTORE CANCELED
3994 wait_request_state $fid CANCEL SUCCEED
3996 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3997 error "The expected changelog was not emitted"
3999 run_test 223a "Changelog for restore canceled (import case)"
4002 local f=$DIR/$tdir/$tfile
4003 local fid=$(create_empty_file "$f")
4008 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4009 wait_request_state $fid ARCHIVE SUCCEED
4012 # Prevent restore from completing
4015 wait_request_state $fid RESTORE STARTED
4018 wait_request_state $fid RESTORE CANCELED
4021 wait_request_state $fid CANCEL SUCCEED
4023 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4024 error "The expected changelog was not emitted"
4026 run_test 223b "Changelog for restore canceled (release case)"
4028 test_224A() { # was test_224
4029 # test needs a running copytool
4034 local f=$DIR/$tdir/$tfile
4035 local fid=$(copy_file /etc/passwd $f)
4038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4039 wait_request_state $fid ARCHIVE SUCCEED
4042 wait_request_state $fid REMOVE SUCCEED
4044 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4045 error "The expected changelog was not emitted"
4047 run_test 224A "Changelog for remove"
4050 # test needs a running copytool
4055 local f=$DIR/$tdir/$tfile
4056 local fid=$(copy_file /etc/passwd $f)
4059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4060 wait_request_state $fid ARCHIVE SUCCEED
4062 copytool_remove_backend $fid
4064 # block copytool operations to allow for HSM request to be
4065 # submitted and file be unlinked (CDT will find object removed)
4070 # wait for request to reach CT
4071 wait_request_state $fid REMOVE STARTED
4077 wait_request_state $fid REMOVE FAILED
4079 # HE_REMOVE|ENOENT=0x202
4080 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4081 error "The expected changelog was not emitted"
4083 run_test 224a "Changelog for failed remove"
4086 # test is not usable because remove request is too fast
4087 # so it is always finished before cancel can be done ...
4088 echo "Test disabled"
4091 # test needs a running copytool
4094 local f=$DIR/$tdir/$tfile
4095 local fid=$(create_empty_file "$f")
4098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4099 wait_request_state $fid ARCHIVE SUCCEED
4101 # Prevent restore from completing
4106 wait_request_state $fid REMOVE CANCELED
4109 wait_request_state $fid CANCEL SUCCEED
4111 changelog_find -type HSM -target-fid $fid -flags 0x27d
4112 error "The expected changelog was not emitted"
4114 run_test 225 "Changelog for remove canceled"
4117 # test needs a running copytool
4122 local f1=$DIR/$tdir/$tfile-1
4123 local f2=$DIR/$tdir/$tfile-2
4124 local f3=$DIR/$tdir/$tfile-3
4125 local fid1=$(copy_file /etc/passwd $f1)
4126 local fid2=$(copy_file /etc/passwd $f2)
4127 copy_file /etc/passwd $f3
4130 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4131 wait_request_state $fid1 ARCHIVE SUCCEED
4133 $LFS hsm_archive $f2
4134 wait_request_state $fid2 ARCHIVE SUCCEED
4136 rm $f1 || error "rm $f1 failed"
4139 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4140 error "The expected changelog was not emitted"
4142 mv $f3 $f2 || error "mv $f3 $f2 failed"
4144 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4145 error "The expected changelog was not emitted"
4147 run_test 226 "changelog for last rm/mv with exiting archive"
4149 # This is just a utility function to clarify what test_227 does
4154 "$LFS" "$action" --$flag "$file" ||
4155 error "Cannot ${action#hsm_} $flag on '$file'"
4157 # Only one changelog should be produced
4158 local entries="$(changelog_find -type HSM -target-fid $fid)"
4159 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4160 error "lfs $action --$flag '$file' produced more than one" \
4163 # Parse the last changelog record
4164 local entry="$(tail -n 1 <<< "$entries")"
4165 eval local -A changelog=$(changelog2array $entry)
4167 # Also check the flags match what is expected
4168 [[ ${changelog[flags]} == $target ]] ||
4169 error "Changelog flag is '${changelog[flags]}', not $target"
4173 local file="$DIR/$tdir/$tfile"
4174 local fid=$(create_empty_file "$file")
4179 for flag in norelease noarchive exists archived lost; do
4180 if [ "$flag" == lost ]; then
4181 # The flag "lost" only works on an archived file
4182 "$LFS" hsm_set --archived "$file"
4186 action="hsm_set" __test_227
4187 action="hsm_clear" __test_227
4190 run_test 227 "changelog when explicit setting of HSM flags"
4193 # test needs a running copytool
4196 local fid=$(create_small_sync_file $DIR/$tfile)
4197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4198 wait_request_state $fid ARCHIVE SUCCEED
4200 $LFS hsm_release $DIR/$tfile
4201 check_hsm_flags $DIR/$tfile "0x0000000d"
4203 filefrag $DIR/$tfile | grep " 1 extent found" ||
4204 error "filefrag on released file must return only one extent"
4206 # only newer versions of cp detect sparse files by stat/FIEMAP
4208 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4209 error "copying $DIR/$tfile"
4210 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4212 $LFS hsm_release $DIR/$tfile
4213 check_hsm_flags $DIR/$tfile "0x0000000d"
4215 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4217 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4219 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4220 error "comparing untarred $DIR/$tfile"
4222 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4223 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4225 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4228 local file="$DIR/$tdir/$tfile"
4230 # set max_requests to allow one request of each type to be started (3)
4232 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4233 set_hsm_param max_requests 3
4236 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4237 set_hsm_param loop_period 1
4239 # send 1 requests of each kind twice
4242 for action in archive restore remove; do
4243 local filepath="$file"-to-$action
4244 local fid=$(create_empty_file "$filepath")
4245 local fid2=$(create_empty_file "$filepath".bis)
4247 if [ "$action" != archive ]; then
4248 "$LFS" hsm_archive "$filepath"
4249 wait_request_state $fid ARCHIVE SUCCEED
4250 "$LFS" hsm_archive "$filepath".bis
4251 wait_request_state $fid2 ARCHIVE SUCCEED
4253 if [ "$action" == restore ]; then
4254 "$LFS" hsm_release "$filepath"
4255 "$LFS" hsm_release "$filepath".bis
4259 # suspend the copytool to prevent requests from completing
4260 stack_trap "copytool_continue" EXIT
4263 # send `max_requests' requests (one of each kind)
4264 for action in archive restore remove; do
4265 filepath="$file"-to-$action
4266 "$LFS" hsm_${action} "$filepath"
4267 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4270 # send another batch of requests
4271 for action in archive restore remove; do
4272 "$LFS" hsm_${action} "$file-to-$action".bis
4274 # wait for `loop_period' seconds to make sure the coordinator has time
4275 # to register those, even though it should not
4278 # only the first batch of request should be started
4280 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4284 error "expected 3 STARTED requests, found $count"
4286 run_test 250 "Coordinator max request"
4289 local f=$DIR/$tdir/$tfile
4290 local fid=$(create_empty_file "$f")
4293 # to have a short test
4294 local old_to=$(get_hsm_param active_request_timeout)
4295 set_hsm_param active_request_timeout 1
4296 # to be sure the cdt will wake up frequently so
4297 # it will be able to cancel the "old" request
4298 local old_loop=$(get_hsm_param loop_period)
4299 set_hsm_param loop_period 1
4304 # Prevent archive from completing
4306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4307 wait_request_state $fid ARCHIVE STARTED
4309 # Let the request timeout
4310 wait_request_state $fid ARCHIVE CANCELED
4312 set_hsm_param active_request_timeout $old_to
4313 set_hsm_param loop_period $old_loop
4315 run_test 251 "Coordinator request timeout"
4318 local f=$DIR/$tdir/$tfile
4319 local fid=$(create_empty_file "$f")
4321 # to have a short test
4322 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4323 set_hsm_param loop_period 1
4327 # Prevent archive from completing
4329 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4330 wait_request_state $fid ARCHIVE STARTED
4333 stack_trap "set_hsm_param active_request_timeout \
4334 $(get_hsm_param active_request_timeout)" EXIT
4335 set_hsm_param active_request_timeout 1
4337 wait_request_state $fid ARCHIVE CANCELED
4340 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4344 # test needs a running copytool
4348 local f=$DIR/$tdir/$tfile
4350 dd if=/dev/zero of=$f bs=1MB count=10
4351 local fid=$(path2fid $f)
4353 $LFS hsm_archive $f || error "could not archive file"
4354 wait_request_state $fid ARCHIVE SUCCEED
4356 # clear locks to discard inode data
4357 cancel_lru_locks osc
4359 #define OBD_FAIL_MDC_MERGE 0x807
4360 $LCTL set_param fail_loc=0x807
4362 #expect error here, instead of release with wrong size
4365 if ((rc == 0)); then
4366 file_size=$(stat -c '%s' $f)
4367 if ((file_size != 10485760)); then
4368 error "Wrong file size after hsm_release"
4371 echo "could not release file"
4374 run_test 253 "Check for wrong file size after release"
4378 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4379 skip "need MDS version at least 2.10.56"
4381 # Check that the counters are initialized to 0
4383 for request_type in archive restore remove; do
4384 count="$(get_hsm_param ${request_type}_count)" ||
4385 error "Reading ${request_type}_count failed with $?"
4387 [ "$count" -eq 0 ] ||
4388 error "Expected ${request_type}_count to be " \
4392 run_test 254a "Request counters are initialized to zero"
4396 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4397 skip "need MDS version at least 2.10.56"
4399 # The number of request to launch (at least 32)
4400 local request_count=$((RANDOM % 32 + 32))
4401 printf "Will launch %i requests of each type\n" "$request_count"
4403 # Launch a copytool to process requests
4406 # Set hsm.max_requests to allow starting all requests at the same time
4408 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4409 set_hsm_param max_requests "$request_count"
4413 for request_type in archive restore remove; do
4414 printf "Checking %s requests\n" "${request_type}"
4415 # Suspend the copytool to give us time to read the proc files
4418 for ((i = 0; i < $request_count; i++)); do
4419 case $request_type in
4421 create_empty_file "$DIR/$tdir/$tfile-$i" \
4425 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4428 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4431 # Give the coordinator 10 seconds to start every request
4433 while get_hsm_param actions | grep -q WAITING; do
4436 [ $timeout -gt 0 ] ||
4437 error "${request_type^} requests took too " \
4441 count="$(get_hsm_param ${request_type}_count)"
4442 [ "$count" -eq "$request_count" ] ||
4443 error "Expected '$request_count' (!= '$count') " \
4444 "active $request_type requests"
4446 # Let the copytool process the requests
4448 # Give it 10 seconds maximum
4450 while get_hsm_param actions | grep -q STARTED; do
4453 [ $timeout -gt 0 ] ||
4454 error "${request_type^} requests took too " \
4458 count="$(get_hsm_param ${request_type}_count)"
4459 [ "$count" -eq 0 ] ||
4460 error "Expected 0 (!= '$count') " \
4461 "active $request_type requests"
4464 run_test 254b "Request counters are correctly incremented and decremented"
4468 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4469 skip "Need MDS version at least 2.12.0"
4471 local file="$DIR/$tdir/$tfile"
4472 local fid=$(create_empty_file "$file")
4474 # How do you make sure the coordinator has consumed any outstanding
4475 # event, without triggering an event yourself?
4477 # You wait for a request to disappear from the coordinator's llog.
4479 # Warning: the setup represents 90% of this test
4481 # Create and process an HSM request
4483 "$LFS" hsm_archive "$file"
4484 wait_request_state $fid ARCHIVE SUCCEED
4487 wait_copytools || error "failed to stop copytools"
4489 # Launch a new HSM request
4491 create_empty_file "$file"
4492 "$LFS" hsm_archive "$file"
4496 # Have the completed request be removed as soon as the cdt wakes up
4497 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4498 set_hsm_param grace_delay 1
4499 # (Hopefully, time on the MDS will behave nicely)
4500 do_facet $SINGLEMDS sleep 2 &
4502 # Increase `loop_period' as a mean to prevent the coordinator from
4503 # waking itself up to do some housekeeping.
4504 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4505 set_hsm_param loop_period 1000
4507 wait $! || error "waiting failed"
4509 wait_request_state $fid ARCHIVE ""
4510 # The coordinator will not wake up on its own for ~`loop_period' secs...
4512 # ... Unless a copytool registers. Now the real test begins
4514 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4516 run_test 255 "Copytool registration wakes the coordinator up"
4518 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4519 # break in the future because of that.
4522 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4523 skip "need MDS version 2.11.56 or later"
4525 local -a files=("$DIR/$tdir/$tfile".{0..15})
4528 for file in "${files[@]}"; do
4529 create_small_file "$file"
4532 # Set a few hsm parameters
4534 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4535 set_hsm_param loop_period 1
4537 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4538 set_hsm_param max_requests 3
4542 "$LFS" hsm_archive "${files[0]}"
4543 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4544 "$LFS" hsm_release "${files[0]}"
4548 wait_copytools || error "copytools failed to stop"
4550 # Send several archive requests
4551 for file in "${files[@]:1}"; do
4552 "$LFS" hsm_archive "$file"
4555 # Send one restore request
4556 "$LFS" hsm_restore "${files[0]}"
4561 # Wait for all the requests to complete
4562 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4563 for file in "${files[@]:1}"; do
4564 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4567 # Collect the actions in the order in which the copytool processed them
4569 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4570 "$(copytool_logfile "$SINGLEAGT")")
4573 printf '%s\n' "${actions[@]}"
4576 for action in "${actions[@]:0:3}"; do
4577 [ "$action" == RESTORE ] && return
4580 error "Too many ARCHIVE requests were run before the RESTORE request"
4582 run_test 260a "Restore request have priority over other requests"
4584 # This test is very much tied to the implementation of the current priorisation
4585 # mechanism in the coordinator. It might not make sense to keep it in the future
4588 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4589 skip "need MDS version 2.11.56 or later"
4591 local -a files=("$DIR/$tdir/$tfile".{0..15})
4594 for file in "${files[@]}"; do
4595 create_small_file "$file"
4598 # Set a few hsm parameters
4600 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4601 set_hsm_param loop_period 1
4603 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4604 set_hsm_param max_requests 3
4607 copytool setup --archive-id 2
4608 "$LFS" hsm_archive --archive 2 "${files[0]}"
4609 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4610 "$LFS" hsm_release "${files[0]}"
4614 wait_copytools || error "copytools failed to stop"
4616 # Send several archive requests
4617 for file in "${files[@]:1}"; do
4618 "$LFS" hsm_archive "$file"
4621 # Send one restore request
4622 "$LFS" hsm_restore "${files[0]}"
4626 copytool setup --archive-id 2
4628 # Wait for all the requests to complete
4629 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4630 for file in "${files[@]:1}"; do
4631 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4634 # Collect the actions in the order in which the copytool processed them
4636 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4637 "$(copytool_logfile "$SINGLEAGT")")
4640 printf '%s\n' "${actions[@]}"
4643 for action in "${actions[@]:0:3}"; do
4644 [ "$action" == RESTORE ] && return
4647 error "Too many ARCHIVE requests were run before the RESTORE request"
4649 run_test 260b "Restore request have priority over other requests"
4651 # This test is very much tied to the implementation of the current priorisation
4652 # mechanism in the coordinator. It might not make sense to keep it in the future
4655 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4656 skip "Need MDS version at least 2.12.0"
4658 local -a files=("$DIR/$tdir/$tfile".{0..15})
4661 for file in "${files[@]}"; do
4662 create_small_file "$file"
4665 # Set a few hsm parameters
4667 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4668 set_hsm_param loop_period 1000
4670 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4671 set_hsm_param max_requests 3
4674 copytool setup --archive-id 2
4675 "$LFS" hsm_archive --archive 2 "${files[0]}"
4676 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4677 "$LFS" hsm_release "${files[0]}"
4681 wait_copytools || error "copytools failed to stop"
4683 # Force the next coordinator run to do housekeeping
4687 "$LFS" hsm_archive "${files[1]}"
4691 copytool setup --archive-id 2
4693 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4694 # The coordinator just did a housekeeping run it won't do another one
4695 # for around `loop_period' seconds => requests will not be reordered
4696 # if it costs too much (ie. when the coordinator has to discard a whole
4699 # Send several archive requests
4700 for file in "${files[@]:2}"; do
4701 "$LFS" hsm_archive "$file"
4704 # Send one restore request
4705 "$LFS" hsm_restore "${files[0]}"
4707 # Wait for all the requests to complete
4708 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4709 for file in "${files[@]:2}"; do
4710 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4713 # Collect the actions in the order in which the copytool processed them
4715 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4716 "$(copytool_logfile "$SINGLEAGT")")
4719 printf '%s\n' "${actions[@]}"
4722 for action in "${actions[@]:0:3}"; do
4723 [ "$action" == RESTORE ] &&
4724 error "Restore requests should not be prioritised" \
4725 "unless the coordinator is doing housekeeping"
4729 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4732 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4734 # the only way to test ondisk conf is to restart MDS ...
4735 echo "Stop coordinator and remove coordinator state at mount"
4738 # clean on disk conf set by default
4739 cdt_clear_mount_state
4740 cdt_check_state stopped
4742 # check cdt still off after umount/remount
4744 cdt_check_state stopped
4746 echo "Set coordinator start at mount, and start coordinator"
4747 cdt_set_mount_state enabled
4750 cdt_check_state enabled
4752 # check cdt still on after umount/remount
4754 cdt_check_state enabled
4756 # we are back to original state (cdt started at mount)
4758 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4761 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4763 local ai=$(get_hsm_param default_archive_id)
4764 local new=$((ai + 1))
4766 set_hsm_param default_archive_id $new -P
4768 local res=$(get_hsm_param default_archive_id)
4771 set_hsm_param default_archive_id "" "-P -d"
4773 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4775 run_test 301 "HSM tunnable are persistent"
4778 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4780 local ai=$(get_hsm_param default_archive_id)
4781 local new=$((ai + 1))
4786 set_hsm_param default_archive_id $new -P
4789 for mdtno in $(seq 1 $MDSCOUNT); do
4794 cdt_check_state enabled
4796 local res=$(get_hsm_param default_archive_id)
4799 set_hsm_param default_archive_id "" "-P -d"
4801 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4803 run_test 302 "HSM tunnable are persistent when CDT is off"
4806 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4812 local dir_mdt0=$DIR/$tdir/mdt0
4813 local dir_mdt1=$DIR/$tdir/mdt1
4815 # create 1 dir per MDT
4816 stack_trap "rm -rf $dir_mdt0" EXIT
4817 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4818 stack_trap "rm -rf $dir_mdt1" EXIT
4819 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4821 # create 1 file in each MDT
4822 local fid1=$(create_small_file $dir_mdt0/$tfile)
4823 local fid2=$(create_small_file $dir_mdt1/$tfile)
4825 # check that hsm request on mdt0 is sent to the right MDS
4826 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4827 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4828 echo "archive successful on mdt0"
4830 # check that hsm request on mdt1 is sent to the right MDS
4831 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4832 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4833 echo "archive successful on mdt1"
4835 run_test 400 "Single request is sent to the right MDT"
4838 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4844 local dir_mdt0=$DIR/$tdir/mdt0
4845 local dir_mdt1=$DIR/$tdir/mdt1
4847 # create 1 dir per MDT
4848 stack_trap "rm -rf $dir_mdt0" EXIT
4849 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4850 stack_trap "rm -rf $dir_mdt1" EXIT
4851 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4853 # create 1 file in each MDT
4854 local fid1=$(create_small_file $dir_mdt0/$tfile)
4855 local fid2=$(create_small_file $dir_mdt1/$tfile)
4857 # check that compound requests are shunt to the rights MDTs
4858 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4859 error "lfs hsm_archive"
4860 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4861 echo "archive successful on mdt0"
4862 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4863 echo "archive successful on mdt1"
4865 run_test 401 "Compound requests split and sent to their respective MDTs"
4867 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4872 local node=$(facet_active_host $facet)
4874 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4875 awk '{print $4}'); do
4876 echo "$3 $mdc on $node"
4877 do_facet $facet "$LCTL --device $mdc $state" || return 1
4882 # deactivate all mdc on agent1
4883 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4885 copytool setup --no-fail
4887 check_agent_unregistered "uuid" # match any agent
4889 # no expected running copytool
4890 search_copytools $agent && error "Copytool start should have failed"
4893 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4895 run_test 402a "Copytool start fails if all MDTs are inactive"
4902 local f=$DIR/$tdir/$tfile
4903 touch $f || error "touch $f failed"
4904 local fid=$(path2fid $f)
4906 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4907 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4908 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4910 # give time for CDT to send request and to keep it for retry
4911 wait_for_loop_period
4913 wait_request_state $fid ARCHIVE WAITING
4915 do_facet $SINGLEAGT lctl set_param fail_loc=0
4917 # request should succeed now
4918 wait_request_state $fid ARCHIVE SUCCEED
4920 run_test 402b "CDT must retry request upon slow start of CT"
4923 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4925 local agent=$(facet_active_host $SINGLEAGT)
4927 # deactivate all mdc for MDT0001
4928 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4931 local uuid=$(get_agent_uuid $agent)
4932 # check the agent is registered on MDT0000, and not on MDT0001
4933 check_agent_registered_by_mdt $uuid 0
4934 check_agent_unregistered_by_mdt $uuid 1
4936 # check running copytool process
4937 search_copytools $agent || error "No running copytools on $agent"
4939 # reactivate all mdc for MDT0001
4940 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4942 # make sure the copytool is now registered to all MDTs
4943 check_agent_registered $uuid
4945 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4948 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4952 # create files on both MDT0000 and MDT0001
4955 local dir_mdt0=$DIR/$tdir/mdt0
4956 stack_trap "rm -rf $dir_mdt0" EXIT
4957 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4959 # create 1 file on mdt0
4960 local fid1=$(create_small_file $dir_mdt0/$tfile)
4962 # deactivate all mdc for MDT0001
4963 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4965 # send an HSM request for files in MDT0000
4966 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4968 # check for completion of files in MDT0000
4969 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4970 echo "archive successful on mdt0"
4972 # reactivate all mdc for MDT0001
4973 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4975 run_test 404 "Inactive MDT does not block requests for active MDTs"
4978 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4984 local striped_dir=$DIR/$tdir/striped_dir
4986 # create striped dir on all of MDTs
4987 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4989 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4990 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4991 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4992 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4994 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4995 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4996 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4997 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4999 # check that compound requests are shunt to the rights MDTs
5000 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5001 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5002 error "lfs hsm_archive"
5004 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5005 echo "archive successful on $fid1"
5006 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5007 echo "archive successful on $fid2"
5008 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5009 echo "archive successful on $fid3"
5010 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5011 echo "archive successful on $fid4"
5013 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5014 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5015 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5016 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5018 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5019 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5020 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5021 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5023 run_test 405 "archive and release under striped directory"
5026 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5028 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5029 skip "need MDS version at least 2.7.64"
5034 fid=$(create_small_file $DIR/$tdir/$tfile)
5039 $LFS hsm_archive $DIR/$tdir/$tfile
5040 wait_request_state "$fid" ARCHIVE SUCCEED
5041 $LFS hsm_release $DIR/$tdir/$tfile
5043 # Should migrate $tdir but not $tfile.
5044 $LFS migrate -m1 $DIR/$tdir &&
5045 error "migrating HSM an archived file should fail"
5047 $LFS hsm_restore $DIR/$tdir/$tfile
5048 wait_request_state "$fid" RESTORE SUCCEED
5050 $LFS hsm_remove $DIR/$tdir/$tfile
5051 wait_request_state "$fid" REMOVE SUCCEED
5053 cat $DIR/$tdir/$tfile > /dev/null ||
5054 error "cannot read $DIR/$tdir/$tfile"
5056 $LFS migrate -m1 $DIR/$tdir ||
5057 error "cannot complete migration after HSM remove"
5059 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5060 if ((mdt_index != 1)); then
5061 error "expected MDT index 1, got $mdt_index"
5064 # Refresh fid after migration.
5065 fid=$(path2fid $DIR/$tdir/$tfile)
5068 $LFS hsm_archive $DIR/$tdir/$tfile
5069 wait_request_state "$fid" ARCHIVE SUCCEED 1
5071 lctl set_param debug=+trace
5072 $LFS hsm_release $DIR/$tdir/$tfile ||
5073 error "cannot release $DIR/$tdir/$tfile"
5075 $LFS hsm_restore $DIR/$tdir/$tfile
5076 wait_request_state "$fid" RESTORE SUCCEED 1
5078 cat $DIR/$tdir/$tfile > /dev/null ||
5079 error "cannot read $DIR/$tdir/$tfile"
5081 run_test 406 "attempting to migrate HSM archived files is safe"
5084 local f=$DIR/$tdir/$tfile
5085 local f2=$DIR2/$tdir/$tfile
5086 local fid=$(create_empty_file "$f")
5090 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5091 wait_request_state $fid ARCHIVE SUCCEED
5094 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5095 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5097 # Prevent restore from completing
5101 # 1st request holds layout lock while appropriate
5102 # RESTORE record is still not added to llog
5106 # after umount hsm_actions->O/x/x log shouldn't have
5107 # double RESTORE records like below
5108 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5109 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5111 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5115 wait_request_state $fid RESTORE SUCCEED
5117 run_test 407 "Check for double RESTORE records in llog"
5121 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5122 skip "HSM migrate is not supported"
5124 test_mkdir -p $DIR/$tdir
5126 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5127 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5129 llapi_hsm_test -d $DIR/$tdir -b ||
5130 error "One llapi HSM test failed"
5132 llapi_hsm_test -d $DIR/$tdir ||
5133 error "One llapi HSM test failed"
5136 run_test 500 "various LLAPI HSM tests"
5139 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5140 skip "need MDS version at least 2.10.58"
5144 local f=$DIR/$tdir/$tfile
5147 # set changelog_mask to ALL
5148 changelog_chmask "ALL"
5150 chmod 777 $DIR/$tdir
5151 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5152 local fid=$(path2fid $f)
5155 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5156 -gid "$RUNAS_GID") ||
5157 error "No matching CREAT entry"
5159 # Parse the changelog
5160 eval local -A changelog=$(changelog2array $entry)
5161 local nid="${changelog[nid]}"
5164 echo "Got NID '$nid'"
5165 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5166 error "nid '$nid' does not match any client NID:" \
5169 run_test 600 "Changelog fields 'u=' and 'nid='"
5172 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5173 skip "need MDS version at least 2.10.58"
5177 local f=$DIR/$tdir/$tfile
5180 # set changelog_mask to ALL
5181 changelog_chmask "ALL"
5183 touch $f || error "touch $f failed"
5184 local fid=$(path2fid $f)
5187 cat $f || error "cat $f failed"
5189 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5190 error "No matching OPEN entry"
5192 run_test 601 "OPEN Changelog entry"
5195 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5196 skip "need MDS version at least 2.10.58"
5200 local f=$DIR/$tdir/$tfile
5203 # set changelog_mask to ALL
5204 changelog_chmask "ALL"
5206 touch $f || error "touch $f failed"
5207 local fid=$(path2fid $f)
5210 cat $f || error "cat $f failed"
5212 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5216 echo f > $f || error "write $f failed"
5219 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5221 # remove OPEN from changelog_mask
5222 changelog_chmask "-OPEN"
5226 cat $f || error "cat $f failed"
5229 changelog_find -type CLOSE -target-fid $fid &&
5230 error "There should be no CLOSE entry"
5234 echo f > $f || error "write $f failed"
5237 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5239 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5242 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5243 skip "need MDS version at least 2.10.58"
5247 local f=$DIR/$tdir/$tfile
5250 # set changelog_mask to ALL
5251 changelog_chmask "ALL"
5253 touch $f || error "touch $f failed"
5254 local fid=$(path2fid $f)
5256 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5259 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5261 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5262 error "No matching GXATR entry"
5264 run_test 603 "GETXATTR Changelog entry"
5267 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5268 skip "need MDS version at least 2.10.58"
5272 local f=$DIR/$tdir/$tfile
5273 local f2=$DIR2/$tdir/$tfile
5274 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5276 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5277 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5278 do_facet mds1 lctl set_param "$procname=20"
5282 # set changelog_mask to ALL
5283 changelog_chmask "ALL"
5285 touch $f || error "touch $f failed"
5286 local fid=$(path2fid $f)
5292 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5296 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5297 -gid "$RUNAS_GID" -mode "r--") ||
5298 error "No matching NOPEN entry"
5300 # Parse the changelog
5301 eval local -A changelog=$(changelog2array $entry)
5302 local nid="${changelog[nid]}"
5305 echo "Got NID '$nid'"
5306 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5307 error "nid '$nid' does not match any client NID:" \
5312 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5315 changelog_find -type NOPEN -target-fid $fid &&
5316 error "There should be no NOPEN entry"
5318 # Sleep for `changelog_deniednext` seconds
5323 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5326 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5327 -gid "$RUNAS_GID" -mode "r--") ||
5328 error "No matching NOPEN entry"
5330 # Parse the changelog
5331 eval local -A changelog=$(changelog2array $entry)
5332 local nid="${changelog[nid]}"
5335 echo "Got NID '$nid'"
5336 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5337 error "nid '$nid' does not match any client NID:" \
5340 run_test 604 "NOPEN Changelog entry"
5343 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5344 skip "need MDS version at least 2.10.58"
5348 local f=$DIR/$tdir/$tfile
5349 local f2=$DIR2/$tdir/$tfile
5352 # set changelog_mask to ALL
5353 changelog_chmask "ALL"
5355 touch $f || error "touch $f failed"
5356 local fid=$(path2fid $f)
5360 exec 3<> $f || error "open $f failed"
5364 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5368 exec 4<> $f || error "open $f failed"
5371 changelog_find -type OPEN -target-fid $fid &&
5372 error "There should be no OPEN entry"
5374 exec 4>&- || error "close $f failed"
5377 changelog_find -type CLOSE -target-fid $fid &&
5378 error "There should be no CLOSE entry"
5382 # access in rw, so different access mode should generate entries
5383 cat $f || error "cat $f failed"
5386 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5388 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5392 # same access as first one, should not generate new entries
5393 exec 4<> $f || error "open $f failed"
5396 changelog_find -type OPEN -target-fid $fid &&
5397 error "There should be no OPEN entry"
5399 exec 4>&- || error "close $f failed"
5402 changelog_find -type CLOSE -target-fid $fid &&
5403 error "There should be no CLOSE entry"
5407 # access by different user should generate new entries
5408 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5411 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5413 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5417 exec 3>&- || error "close $f failed"
5420 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5422 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5425 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5426 skip "need MDS version at least 2.10.58"
5428 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5429 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5430 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5431 skip_env "missing llog_reader" && return
5432 local fstype=$(facet_fstype mds1)
5436 local f=$DIR/$tdir/$tfile
5439 # set changelog_mask to ALL
5440 changelog_chmask "ALL"
5442 chmod 777 $DIR/$tdir
5443 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5444 local fid=$(path2fid $f)
5445 rm $f || error "rm $f failed"
5447 local mntpt=$(facet_mntpt mds1)
5451 #remount mds1 as ldiskfs or zfs type
5452 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5453 stop mds1 || error "stop mds1 failed"
5454 mount_fstype mds1 || error "remount mds1 failed"
5456 for ((i = 0; i < 1; i++)); do
5457 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5458 local cat_file=$(do_facet mds1 $llog_reader \
5459 $mntpt/changelog_catalog | awk \
5460 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5461 [ -n "$cat_file" ] || error "no catalog file"
5463 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5464 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5465 [ -n "$entry" ] || error "no CREAT entry"
5468 local uidgid=$(echo $entry |
5469 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5470 [ -n "$uidgid" ] || error "uidgid is empty"
5471 echo "Got UID/GID $uidgid"
5472 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5473 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5474 local nid=$(echo $entry |
5475 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5476 [ -n "$nid" ] || error "nid is empty"
5478 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5479 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5481 run_test 606 "llog_reader groks changelog fields"
5484 check_and_cleanup_lustre