3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 # bug number for skipped tests: LU-9795 LU-9795
19 ALWAYS_EXCEPT=" 13 402b $ALWAYS_EXCEPT"
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
32 MULTIOP=${MULTIOP:-multiop}
33 OPENFILE=${OPENFILE:-openfile}
34 MMAP_CAT=${MMAP_CAT:-mmap_cat}
35 MOUNT_2=${MOUNT_2:-"yes"}
38 # script only handles up to 10 MDTs (because of MDT_PREFIX)
39 [ $MDSCOUNT -gt 9 ] &&
40 error "script cannot handle more than 9 MDTs, please fix" && exit
42 check_and_setup_lustre
44 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
45 skip_env "Need MDS version at least 2.4.53"
48 # $RUNAS_ID may get set incorrectly somewhere else
49 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
50 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
52 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
53 if getent group nobody; then
55 elif getent group nogroup; then
58 error "No generic nobody group"
63 # if there is no CLIENT1 defined, some tests can be ran on localhost
64 CLIENT1=${CLIENT1:-$HOSTNAME}
65 # if CLIENT2 doesn't exist then use CLIENT1 instead
66 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
68 # Exception is the test which need two separate nodes
69 CLIENT2=${CLIENT2:-$CLIENT1}
72 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
73 # the following associated variables are added:
75 # AGTCOUNT: number of agents
76 # AGTDEV{N}: target HSM mount point (root path of the backend)
77 # agt{N}_HOST: hostname of the agent agt{N}
78 # SINGLEAGT: facet of the single agent
80 # The number of agents is initialized as the number of remote client nodes.
81 # By default, only single copytool is started on a remote client/agent. If there
82 # was no remote client, then the copytool will be started on the local client.
88 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
89 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
91 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
92 if [[ $CLIENTCOUNT -gt 1 ]] &&
93 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
94 skip_env "SHARED_DIRECTORY should be accessible"\
99 # We used to put the HSM archive in $SHARED_DIRECTORY but that
100 # meant NFS issues could hose sanity-hsm sessions. So now we
102 for n in $(seq $AGTCOUNT); do
103 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
104 agent=CLIENT$((n + 1))
105 if [[ -z "${!agent}" ]]; then
106 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
109 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
112 export SINGLEAGT=${SINGLEAGT:-agt1}
114 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
115 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
116 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
117 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
118 export HSMTOOL_TESTDIR
122 # The test only support up to 10 MDTs
123 MDT_PREFIX="mdt.$FSNAME-MDT000"
124 HSM_PARAM="${MDT_PREFIX}0.hsm"
126 # archive is purged at copytool setup
127 HSM_ARCHIVE_PURGE=true
129 # Don't allow copytool error upon start/setup
130 HSMTOOL_NOERROR=false
133 # Get the backend root path for the given agent facet.
136 local dev=AGTDEV$(facet_number $facet)
143 # get MDT device for each mdc
144 for mdtno in $(seq 1 $MDSCOUNT); do
145 local idx=$(($mdtno - 1))
146 MDT[$idx]=$($LCTL get_param -n \
147 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
148 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
153 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
154 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
158 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
160 echo "Killing existing copytools on $hosts"
161 do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
162 copytool_continue "$hosts"
166 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
167 local wait_timeout=200
168 local wait_start=$SECONDS
169 local wait_end=$((wait_start + wait_timeout))
170 local sleep_time=100000 # 0.1 second
172 while ((SECONDS < wait_end)); do
173 if ! search_copytools $hosts; then
174 echo "copytools stopped in $((SECONDS - wait_start))s"
178 echo "copytools still running on $hosts"
180 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
181 sleep_time=$(bc <<< "$sleep_time * 2")
184 # try to dump Copytool's stack
185 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
186 "echo t >/proc/sysrq-trigger"
188 echo "copytools failed to stop in ${wait_timeout}s"
193 copytool_monitor_setup() {
194 local facet=${1:-$SINGLEAGT}
195 local agent=$(facet_active_host $facet)
197 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
198 local test_dir=$(do_node $agent "$cmd") ||
199 error "Failed to create tempdir on $agent"
200 export HSMTOOL_MONITOR_DIR=$test_dir
202 # Create the fifo and a monitor (cat dies when copytool dies)
203 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
204 error "failed to create copytool fifo on $agent"
205 cmd="cat $test_dir/fifo > $test_dir/events &"
206 cmd+=" echo \\\$! > $test_dir/monitor_pid"
208 if [[ $PDSH == *Rmrsh* ]]; then
209 # This is required for pdsh -Rmrsh and its handling of remote
211 # Regular ssh and pdsh -Rssh work fine without this
212 # backgrounded subshell nonsense.
213 (do_node $agent "$cmd") &
214 export HSMTOOL_MONITOR_PDSH=$!
216 # Slightly racy, but just making a best-effort to catch obvious
219 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
220 error "Failed to start copytool monitor on $agent"
222 do_node $agent "$cmd"
224 error "Failed to start copytool monitor on $agent"
235 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
240 get_copytool_event_log() {
241 local facet=${1:-$SINGLEAGT}
242 local agent=$(facet_active_host $facet)
244 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
245 error "Can't get event log: No monitor directory!"
247 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
248 error "Could not collect event log from $agent"
252 local agents=${1:-$(facet_active_host $SINGLEAGT)}
255 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
256 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
257 echo "Copytool is suspended on $agents"
260 copytool_continue() {
261 local agents=${1:-$(facet_active_host $SINGLEAGT)}
263 do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
264 echo "Copytool is continued on $agents"
267 copytool_remove_backend() {
269 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
270 echo "Remove from backend: $fid = $be"
271 do_facet $SINGLEAGT rm -f $be
274 file_creation_failure() {
281 df $MOUNT $MOUNT2 >&2
282 error "Not enough space to create $file with $cmd"
285 error "cannot create $file with $cmd, status=$err"
290 # Creates a file using dd
296 local source=${5:-/dev/zero}
300 if [ -n "$conv" ]; then
304 # Create the directory in case it does not exist
305 mkdir -p "$(dirname "$file")"
306 # Delete the file in case it already exist
309 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
310 path2fid "$file" || error "cannot get FID of '$file'"
313 echo "cannot create file '$file'" >&2;
314 # Let the caller decide what to do on error
319 create_empty_file() {
320 create_file "${1/$DIR/$DIR2}" 1M 0 ||
321 file_creation_failure dd "${1/$DIR/$DIR2}" $?
324 create_small_file() {
325 local source_file=/dev/urandom
328 local conv=${2:-fsync}
330 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
331 file_creation_failure dd "${1/$DIR/$DIR2}" $?
334 create_small_sync_file() {
335 create_small_file "$1" sync
338 create_archive_file() {
339 local file="$(hsm_root)/$1"
341 local source=/dev/urandom
343 # Create the counterpart directory of the archive
344 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
345 error "cannot create archive directory '$(dirname "$file")'"
347 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
348 error "cannot create archive file '$file'"
352 local hsm_root="$(hsm_root)"
353 local file="$hsm_root/$2"
355 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
356 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
357 error "mkdir '$(dirname "$file")' failed"
358 do_facet $SINGLEAGT cp -p "$1" "$file" ||
359 error "cannot copy '$1' to '$file'"
364 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
371 mdts_set_param "" hsm_control "$cmd"
372 mdts_check_param hsm_control "$target" 10
377 mdts_set_param "" hsm.policy "+NRA"
378 CDT_POLICY_HAD_CHANGED=true
381 cdt_clear_no_retry() {
382 mdts_set_param "" hsm.policy "-NRA"
383 CDT_POLICY_HAD_CHANGED=true
386 cdt_set_non_blocking_restore() {
387 mdts_set_param "" hsm.policy "+NBR"
388 CDT_POLICY_HAD_CHANGED=true
391 cdt_clear_non_blocking_restore() {
392 mdts_set_param "" hsm.policy "-NBR"
393 CDT_POLICY_HAD_CHANGED=true
396 cdt_clear_mount_state() {
397 mdts_set_param "-P -d" hsm_control ""
401 set_test_state disabled disabled
405 set_test_state enabled enabled
409 set_test_state shutdown stopped
413 set_test_state purge enabled
419 cdt_set_sanity_policy
423 get_hsm_archive_id() {
426 st=$($LFS hsm_state $f)
427 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
429 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
433 check_hsm_flags_user() {
437 local st=$(get_hsm_flags $f user)
438 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
450 if [[ "$3" != 1 ]]; then
454 cp $1 $f || file_creation_failure cp $f $?
456 path2fid $f || error "cannot get fid on $f"
459 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
461 # Note that this might lead to surprising behaviours such as deleting an
462 # important file for the currently running test
463 delete_large_files() {
464 printf "Deleting large files...\n" >&2
465 find $MOUNT -size +10M -delete
466 wait_delete_completed
469 get_request_state() {
473 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
474 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
477 get_request_count() {
481 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
482 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
485 # Ensure the number of HSM request for a given FID is correct
486 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
487 assert_request_count() {
488 local request_count=$(get_request_count $1 $2)
489 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
491 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
498 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
499 [[ -n $fid ]] && cmd+=" | grep '$fid'"
500 cmd+=" | egrep 'WAITING|STARTED'"
502 wait_result $SINGLEMDS "$cmd" "" $timeout ||
503 error "requests did not complete"
506 wait_for_grace_delay() {
507 local val=$(get_hsm_param grace_delay)
511 wait_for_loop_period() {
512 local val=$(get_hsm_param loop_period)
519 # python2.6 in EL6 includes an internal json module
520 local json_parser='import json; import fileinput;'
521 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
522 json_parser+='json.loads([line for line in '
523 json_parser+='fileinput.input()][0]).items()])'
525 echo $raw_event | python -c "$json_parser"
528 get_agent_by_uuid_mdt() {
531 local mds=mds$(($mdtidx + 1))
532 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
536 check_agent_registered_by_mdt() {
539 local mds=mds$(($mdtidx + 1))
540 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
541 if [[ ! -z "$agent" ]]; then
542 echo "found agent $agent on $mds"
544 error "uuid $uuid not found in agent list on $mds"
548 check_agent_unregistered_by_mdt() {
551 local mds=mds$(($mdtidx + 1))
552 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
553 if [[ -z "$agent" ]]; then
554 echo "uuid not found in agent list on $mds"
556 error "uuid found in agent list on $mds: $agent"
560 check_agent_registered() {
563 for mdsno in $(seq 1 $MDSCOUNT); do
564 check_agent_registered_by_mdt $uuid $((mdsno - 1))
568 check_agent_unregistered() {
571 for mdsno in $(seq 1 $MDSCOUNT); do
572 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
577 local agent=${1:-$(facet_active_host $SINGLEAGT)}
579 # Lustre mount-point is mandatory and last parameter on
581 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
583 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
585 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
591 # populate MDT device array
594 # cleanup from previous bad setup
597 # for recovery tests, coordinator needs to be started at mount
599 # the lustre conf must be without hsm on (like for sanity.sh)
600 echo "Set HSM on and start"
601 cdt_set_mount_state enabled
602 cdt_check_state enabled
604 echo "Set sanity-hsm HSM policy"
605 cdt_set_sanity_policy
607 # finished requests are quickly removed from list
608 set_hsm_param grace_delay 10
610 CLIENT_NIDS=( $($LCTL list_nids all) )
612 test_1A() { # was test_1
616 local f=$DIR/$tdir/$tfile
620 check_hsm_flags_user $f "0x00000000"
622 $RUNAS $LFS hsm_set --norelease $f ||
623 error "user could not change hsm flags"
624 check_hsm_flags_user $f "0x00000010"
626 $RUNAS $LFS hsm_clear --norelease $f ||
627 error "user could not clear hsm flags"
628 check_hsm_flags_user $f "0x00000000"
630 # User could not change those flags...
631 $RUNAS $LFS hsm_set --exists $f &&
632 error "user should not set this flag"
633 check_hsm_flags_user $f "0x00000000"
636 $LFS hsm_set --exists $f ||
637 error "root could not change hsm flags"
638 check_hsm_flags_user $f "0x00000001"
640 $LFS hsm_clear --exists $f ||
641 error "root could not clear hsm state"
642 check_hsm_flags_user $f "0x00000000"
645 run_test 1A "lfs hsm flags root/non-root access"
648 local f=$DIR/$tdir/$tfile
649 local fid=$(create_small_file $f)
653 $LFS hsm_archive $f || error "could not archive file"
654 wait_request_state $fid ARCHIVE SUCCEED
656 # Release and check states
657 $LFS hsm_release $f || error "could not release file"
658 echo -n "Verifying released state: "
659 check_hsm_flags $f "0x0000000d"
661 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
663 run_test 1a "mmap & cat a HSM released file"
667 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
668 error "failed to set default stripe"
669 local f=$DIR/$tdir/$tfile
672 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
673 error "failed to create file"
674 local fid=$(path2fid $f)
679 $LFS hsm_archive $f || error "could not archive file"
680 wait_request_state $fid ARCHIVE SUCCEED
683 $LFS hsm_release $f || error "could not release file"
684 echo "verify released state: "
685 check_hsm_flags $f "0x0000000d" && echo "pass"
688 $LFS hsm_restore $f || error "could not restore file"
689 wait_request_state $fid RESTORE SUCCEED
690 echo "verify restored state: "
691 check_hsm_flags $f "0x00000009" && echo "pass"
693 run_test 1b "Archive, Release and Restore composite file"
699 local f=$DIR/$tdir/$tfile
702 # Test whether we can set the maximum archive number.
703 local LOCAL_HSM_ARCHIVE_NUMBER=32
704 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
705 error "root could not change hsm flags"
706 check_hsm_flags_user $f "0x00000001"
707 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
708 local st=$(get_hsm_archive_id $f)
709 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
710 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
712 # Test whether setting archive number 0 results in no change.
713 $LFS hsm_set --exists --archive-id 0 $f ||
714 error "root could not change hsm flags"
715 check_hsm_flags_user $f "0x00000001"
716 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
717 st=$(get_hsm_archive_id $f)
718 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
719 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
721 LOCAL_HSM_ARCHIVE_NUMBER=33
722 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
723 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
724 # lustre in the new version supports unlimited archiveID.
725 # Test whether setting archive number > 32 is supported
726 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
727 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
728 check_hsm_flags_user $f "0x00000001"
730 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
731 st=$(get_hsm_archive_id $f)
732 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
733 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
735 # old client or old mds can only support at most 32 archiveID
736 # test whether setting archive number > 32 results in error.
737 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
738 error "bitmap archive number is larger than 32"
739 check_hsm_flags_user $f "0x00000001"
742 # Test whether setting archive number 16 and archived flag.
743 LOCAL_HSM_ARCHIVE_NUMBER=16
744 $LFS hsm_set --exists --archived \
745 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
746 error "root could not change hsm flags"
747 check_hsm_flags_user $f "0x00000009"
748 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
749 st=$(get_hsm_archive_id $f)
750 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
751 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
753 run_test 1c "Check setting archive-id in lfs hsm_set"
756 [ $MDS_VERSION_CODE -lt $(version_code 2.10.59) ] &&
757 skip "need MDS version at least 2.10.59"
760 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
761 error "failed to set default stripe"
762 local f=$DIR/$tdir/$tfile
765 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
766 error "failed to create file"
767 local fid=$(path2fid $f)
772 $LFS hsm_archive $f || error "could not archive file"
773 wait_request_state $fid ARCHIVE SUCCEED
776 $LFS hsm_release $f || error "could not release file"
777 echo "verify released state: "
778 check_hsm_flags $f "0x0000000d" && echo "pass"
781 $LFS hsm_restore $f || error "could not restore file"
782 wait_request_state $fid RESTORE SUCCEED
783 echo "verify restored state: "
784 check_hsm_flags $f "0x00000009" && echo "pass"
786 run_test 1d "Archive, Release and Restore DoM file"
789 local f=$DIR/$tdir/$tfile
791 create_empty_file "$f"
792 # New files are not dirty
793 check_hsm_flags $f "0x00000000"
795 # For test, we simulate an archived file.
796 $LFS hsm_set --exists $f || error "user could not change hsm flags"
797 check_hsm_flags $f "0x00000001"
799 # chmod do not put the file dirty
800 chmod 600 $f || error "could not chmod test file"
801 check_hsm_flags $f "0x00000001"
803 # chown do not put the file dirty
804 chown $RUNAS_ID $f || error "could not chown test file"
805 check_hsm_flags $f "0x00000001"
807 # truncate put the file dirty
808 $TRUNCATE $f 1 || error "could not truncate test file"
809 check_hsm_flags $f "0x00000003"
811 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
812 check_hsm_flags $f "0x00000001"
814 run_test 2 "Check file dirtyness when doing setattr"
820 # New files are not dirty
822 check_hsm_flags $f "0x00000000"
824 # For test, we simulate an archived file.
825 $LFS hsm_set --exists $f ||
826 error "user could not change hsm flags"
827 check_hsm_flags $f "0x00000001"
829 # Reading a file, does not set dirty
830 cat $f > /dev/null || error "could not read file"
831 check_hsm_flags $f "0x00000001"
833 # Open for write without modifying data, does not set dirty
834 openfile -f O_WRONLY $f || error "could not open test file"
835 check_hsm_flags $f "0x00000001"
837 # Append to a file sets it dirty
838 cp -p /etc/passwd $f.append || error "could not create file"
839 $LFS hsm_set --exists $f.append ||
840 error "user could not change hsm flags"
841 dd if=/etc/passwd of=$f.append bs=1 count=3\
842 conv=notrunc oflag=append status=noxfer ||
843 file_creation_failure dd $f.append $?
844 check_hsm_flags $f.append "0x00000003"
846 # Modify a file sets it dirty
847 cp -p /etc/passwd $f.modify || error "could not create file"
848 $LFS hsm_set --exists $f.modify ||
849 error "user could not change hsm flags"
850 dd if=/dev/zero of=$f.modify bs=1 count=3\
851 conv=notrunc status=noxfer ||
852 file_creation_failure dd $f.modify $?
853 check_hsm_flags $f.modify "0x00000003"
855 # Open O_TRUNC sets dirty
856 cp -p /etc/passwd $f.trunc || error "could not create file"
857 $LFS hsm_set --exists $f.trunc ||
858 error "user could not change hsm flags"
859 cp /etc/group $f.trunc || error "could not override a file"
860 check_hsm_flags $f.trunc "0x00000003"
862 # Mmapped a file sets dirty
863 cp -p /etc/passwd $f.mmap || error "could not create file"
864 $LFS hsm_set --exists $f.mmap ||
865 error "user could not change hsm flags"
866 multiop $f.mmap OSMWUc || error "could not mmap a file"
867 check_hsm_flags $f.mmap "0x00000003"
869 run_test 3 "Check file dirtyness when opening for write"
872 local f=$DIR/$tdir/$tfile
873 local fid=$(create_small_file $f)
876 local st=$(get_request_state $fid CANCEL)
877 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
879 run_test 4 "Useless cancel must not be registered"
882 # test needs a running copytool
886 local f=$DIR/$tdir/$tfile
887 local fid=$(copy_file /etc/passwd $f)
889 wait_request_state $fid ARCHIVE SUCCEED
891 check_hsm_flags $f "0x00000009"
893 run_test 8 "Test default archive number"
895 test_9A() { # was test_9
896 # we do not use the default one to be sure
897 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
898 copytool setup --archive-id $archive_id
900 # give time for CT to register with MDTs
901 sleep $(($MDSCOUNT*2))
902 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
903 check_agent_registered $uuid
906 local f=$DIR/$tdir/$tfile
907 local fid=$(copy_file /etc/passwd $f)
908 $LFS hsm_archive --archive $archive_id $f
909 wait_request_state $fid ARCHIVE SUCCEED
911 check_hsm_flags $f "0x00000009"
913 run_test 9A "Use of explicit archive number, with dedicated copytool"
916 needclients 3 || return 0
922 # start all of the copytools
923 for n in $(seq $AGTCOUNT); do
924 copytool setup --facet agt$n
928 for n in $(seq $AGTCOUNT); do
929 file=$DIR/$tdir/$tfile.$n
930 fid=$(create_small_file $file)
932 $LFS hsm_archive $file || error "could not archive file $file"
933 wait_request_state $fid ARCHIVE SUCCEED
934 check_hsm_flags $file "0x00000009"
937 run_test 9a "Multiple remote agents"
940 # test needs a running copytool
943 mkdir -p $DIR/$tdir/d1
944 local f=$DIR/$tdir/$tfile
945 local fid=$(copy_file /etc/hosts $f)
946 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
947 error "hsm_archive failed"
948 wait_request_state $fid ARCHIVE SUCCEED
950 local hsm_root="$(copytool_device $SINGLEAGT)"
951 local archive="$(do_facet $SINGLEAGT \
952 find "$hsm_root" -name "$fid" -print0)"
953 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
955 echo "Verifying content"
956 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
957 echo "Verifying hsm state "
958 check_hsm_flags $f "0x00000009"
960 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
961 local st=$(get_hsm_archive_id $f)
962 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
963 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
965 run_test 10a "Archive a file"
968 # test needs a running copytool
972 local f=$DIR/$tdir/$tfile
973 local fid=$(copy_file /etc/hosts $f)
974 $LFS hsm_archive $f || error "archive request failed"
975 wait_request_state $fid ARCHIVE SUCCEED
977 $LFS hsm_archive $f || error "archive of non dirty file failed"
978 local cnt=$(get_request_count $fid ARCHIVE)
979 [[ "$cnt" == "1" ]] ||
980 error "archive of non dirty file must not make a request"
982 run_test 10b "Archive of non dirty file must work without doing request"
985 # test needs a running copytool
989 local f=$DIR/$tdir/$tfile
990 local fid=$(copy_file /etc/hosts $f)
991 $LFS hsm_set --noarchive $f
992 $LFS hsm_archive $f && error "archive a noarchive file must fail"
995 run_test 10c "Check forbidden archive"
998 # test needs a running copytool
1002 local f=$DIR/$tdir/$tfile
1003 local fid=$(copy_file /etc/hosts $f)
1004 $LFS hsm_archive $f || error "cannot archive $f"
1005 wait_request_state $fid ARCHIVE SUCCEED
1007 local ar=$(get_hsm_archive_id $f)
1008 local dflt=$(get_hsm_param default_archive_id)
1009 [[ $ar == $dflt ]] ||
1010 error "archived file is not on default archive: $ar != $dflt"
1012 run_test 10d "Archive a file on the default archive id"
1016 copy2archive /etc/hosts $tdir/$tfile
1017 local f=$DIR/$tdir/$tfile
1019 copytool import $tdir/$tfile $f
1020 echo -n "Verifying released state: "
1021 check_hsm_flags $f "0x0000000d"
1023 local LSZ=$(stat -c "%s" $f)
1024 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1026 echo "Verifying imported size $LSZ=$ASZ"
1027 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1028 echo -n "Verifying released pattern: "
1029 local PTRN=$($GETSTRIPE -L $f)
1031 [[ $PTRN == released ]] || error "Is not released"
1032 local fid=$(path2fid $f)
1033 echo "Verifying new fid $fid in archive"
1035 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1036 error "No archive for fid $fid"
1038 run_test 11a "Import a file"
1041 # test needs a running copytool
1045 local f=$DIR/$tdir/$tfile
1046 local fid=$(copy_file /etc/hosts $f)
1047 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1048 error "hsm_archive failed"
1049 wait_request_state $fid ARCHIVE SUCCEED
1051 local FILE_HASH=$(md5sum $f)
1054 copytool import $fid $f
1056 echo "$FILE_HASH" | md5sum -c
1058 [[ $? -eq 0 ]] || error "Restored file differs"
1060 run_test 11b "Import a deleted file using its FID"
1063 # test needs a running copytool
1067 copy2archive /etc/hosts $tdir/$tfile
1069 local f=$DIR/$tdir/$tfile
1070 copytool import $tdir/$tfile $f
1071 local f2=$DIR2/$tdir/$tfile
1072 echo "Verifying released state: "
1073 check_hsm_flags $f2 "0x0000000d"
1075 local fid=$(path2fid $f2)
1076 $LFS hsm_restore $f2
1077 wait_request_state $fid RESTORE SUCCEED
1079 echo "Verifying file state: "
1080 check_hsm_flags $f2 "0x00000009"
1082 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1084 [[ $? -eq 0 ]] || error "Restored file differs"
1086 run_test 12a "Restore an imported file explicitly"
1089 # test needs a running copytool
1093 copy2archive /etc/hosts $tdir/$tfile
1095 local f=$DIR/$tdir/$tfile
1096 copytool import $tdir/$tfile $f
1097 echo "Verifying released state: "
1098 check_hsm_flags $f "0x0000000d"
1100 cat $f > /dev/null || error "File read failed"
1102 echo "Verifying file state after restore: "
1103 check_hsm_flags $f "0x00000009"
1105 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1107 [[ $? -eq 0 ]] || error "Restored file differs"
1109 run_test 12b "Restore an imported file implicitly"
1112 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1114 # test needs a running copytool
1117 local f=$DIR/$tdir/$tfile
1119 $LFS setstripe -c 2 "$f"
1120 local fid=$(create_file "$f" 1M 5)
1122 local FILE_CRC=$(md5sum $f)
1124 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1125 wait_request_state $fid ARCHIVE SUCCEED
1126 $LFS hsm_release $f || error "release $f failed"
1128 echo "$FILE_CRC" | md5sum -c
1130 [[ $? -eq 0 ]] || error "Restored file differs"
1132 run_test 12c "Restore a file with stripe of 2"
1135 # test needs a running copytool
1140 local f=$DIR/$tdir/$tfile
1141 local fid=$(copy_file /etc/hosts $f)
1142 $LFS hsm_restore $f || error "restore of non archived file failed"
1143 local cnt=$(get_request_count $fid RESTORE)
1144 [[ "$cnt" == "0" ]] ||
1145 error "restore non archived must not make a request"
1146 $LFS hsm_archive $f ||
1147 error "archive request failed"
1148 wait_request_state $fid ARCHIVE SUCCEED
1149 $LFS hsm_restore $f ||
1150 error "restore of non released file failed"
1151 local cnt=$(get_request_count $fid RESTORE)
1152 [[ "$cnt" == "0" ]] ||
1153 error "restore a non dirty file must not make a request"
1155 run_test 12d "Restore of a non archived, non released file must work"\
1156 " without doing request"
1159 # test needs a running copytool
1163 local f=$DIR/$tdir/$tfile
1164 local fid=$(copy_file /etc/hosts $f)
1165 $LFS hsm_archive $f || error "archive request failed"
1166 wait_request_state $fid ARCHIVE SUCCEED
1169 cat /etc/hosts >> $f
1173 $LFS hsm_restore $f && error "restore a dirty file must fail"
1176 run_test 12e "Check forbidden restore"
1179 # test needs a running copytool
1183 local f=$DIR/$tdir/$tfile
1184 local fid=$(copy_file /etc/hosts $f)
1186 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1187 wait_request_state $fid ARCHIVE SUCCEED
1188 $LFS hsm_release $f || error "release of $f failed"
1190 wait_request_state $fid RESTORE SUCCEED
1192 echo -n "Verifying file state: "
1193 check_hsm_flags $f "0x00000009"
1195 diff -q /etc/hosts $f
1197 [[ $? -eq 0 ]] || error "Restored file differs"
1199 run_test 12f "Restore a released file explicitly"
1202 # test needs a running copytool
1206 local f=$DIR/$tdir/$tfile
1207 local fid=$(copy_file /etc/hosts $f)
1209 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1210 wait_request_state $fid ARCHIVE SUCCEED
1211 $LFS hsm_release $f || error "release of $f failed"
1213 diff -q /etc/hosts $f
1216 # we check we had a restore done
1217 wait_request_state $fid RESTORE SUCCEED
1219 [[ $st -eq 0 ]] || error "Restored file differs"
1221 run_test 12g "Restore a released file implicitly"
1224 needclients 2 || return 0
1226 # test needs a running copytool
1230 local f=$DIR/$tdir/$tfile
1231 local fid=$(copy_file /etc/hosts $f)
1233 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1234 wait_request_state $fid ARCHIVE SUCCEED
1235 $LFS hsm_release $f || error "release of $f failed"
1237 do_node $CLIENT2 diff -q /etc/hosts $f
1240 # we check we had a restore done
1241 wait_request_state $fid RESTORE SUCCEED
1243 [[ $st -eq 0 ]] || error "Restored file differs"
1245 run_test 12h "Restore a released file implicitly from a second node"
1248 # test needs a running copytool
1252 local f=$DIR/$tdir/$tfile
1253 local fid=$(copy_file /etc/passwd $f)
1254 $LFS hsm_archive $f || error "archive of $f failed"
1255 wait_request_state $fid ARCHIVE SUCCEED
1257 $LFS hsm_release $f || error "release of $f failed"
1261 [[ $? -eq 0 ]] || error "Restored file differs"
1263 run_test 12m "Archive/release/implicit restore"
1266 # test needs a running copytool
1270 copy2archive /etc/hosts $tdir/$tfile
1272 local f=$DIR/$tdir/$tfile
1273 copytool import $tdir/$tfile $f
1275 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1276 error "Restored file differs"
1278 $LFS hsm_release $f || error "release of $f failed"
1280 run_test 12n "Import/implicit restore/release"
1283 # test needs a running copytool
1287 local f=$DIR/$tdir/$tfile
1288 local fid=$(copy_file /etc/hosts $f)
1290 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1291 wait_request_state $fid ARCHIVE SUCCEED
1292 $LFS hsm_release $f || error "release of $f failed"
1294 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1295 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1297 # set no retry action mode
1300 diff -q /etc/hosts $f
1303 # we check we had a restore failure
1304 wait_request_state $fid RESTORE FAILED
1306 [[ $st -eq 0 ]] && error "Restore must fail"
1308 # remove no retry action mode
1311 # check file is still released
1312 check_hsm_flags $f "0x0000000d"
1314 # retry w/o failure injection
1315 do_facet $SINGLEMDS lctl set_param fail_loc=0
1317 # to be sure previous RESTORE result is gone
1319 wait_for_grace_delay
1321 diff -q /etc/hosts $f
1324 # we check we had a restore done
1325 wait_request_state $fid RESTORE SUCCEED
1327 [[ $st -eq 0 ]] || error "Restored file differs"
1329 run_test 12o "Layout-swap failure during Restore leaves file released"
1332 # test needs a running copytool
1336 local f=$DIR/$tdir/$tfile
1337 local fid=$(copy_file /etc/hosts $f)
1339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1340 wait_request_state $fid ARCHIVE SUCCEED
1341 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1342 $LFS hsm_release $f || error "cannot release $f"
1343 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1344 $LFS hsm_release $f || error "cannot release $f"
1345 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1347 run_test 12p "implicit restore of a file on copytool mount point"
1350 [ $MDS_VERSION_CODE -lt $(version_code 2.7.58) ] &&
1351 skip "need MDS version at least 2.7.58"
1353 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1354 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1355 error "cannot mount $MOUNT3 on $SINGLEAGT"
1357 # test needs a running copytool
1358 copytool setup -m "$MOUNT3"
1360 local f=$DIR/$tdir/$tfile
1361 local f2=$DIR2/$tdir/$tfile
1362 local fid=$(create_small_file $f)
1363 local orig_size=$(stat -c "%s" $f)
1365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1366 wait_request_state $fid ARCHIVE SUCCEED
1368 $LFS hsm_release $f || error "could not release file"
1369 check_hsm_flags $f "0x0000000d"
1372 wait_copytools || error "copytool failed to stop"
1374 cat $f > /dev/null &
1376 # wait a bit to allow implicit restore request to be handled.
1377 # if not, next stat would also block on layout-lock.
1380 local size=$(stat -c "%s" $f2)
1381 [ $size -eq $orig_size ] ||
1382 error "$f2: wrong size after archive: $size != $orig_size"
1384 copytool setup -m "$MOUNT3"
1388 size=$(stat -c "%s" $f)
1389 [ $size -eq $orig_size ] ||
1390 error "$f: wrong size after restore: $size != $orig_size"
1392 size=$(stat -c "%s" $f2)
1393 [ $size -eq $orig_size ] ||
1394 error "$f2: wrong size after restore: $size != $orig_size"
1398 size=$(stat -c "%s" $f)
1400 error "$f: wrong size after overwrite: $size != 0"
1402 size=$(stat -c "%s" $f2)
1404 error "$f2: wrong size after overwrite: $size != 0"
1406 run_test 12q "file attributes are refreshed after restore"
1410 for i in {1..10}; do
1411 local archive_dir="$(hsm_root)"/subdir/dir.$i
1413 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1414 for j in {1..10}; do
1415 local archive_file="$archive_dir"/file.$j
1417 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1423 copytool import "subdir" "$DIR/$tdir"
1425 # To check the import, the test uses diff with the -r flag
1426 # This is nice, but diff only checks files one by one, and triggering
1427 # an implicit restore for one file at a time will consume as many
1428 # seconds as there are files to compare. To speed this up, a restore
1429 # operation is triggered manually first.
1431 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1433 # Compare the imported data
1434 do_facet $SINGLEAGT \
1435 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1436 error "imported files differ from archived data"
1438 run_test 13 "Recursively import and restore a directory"
1441 # test needs a running copytool
1445 local f=$DIR/$tdir/$tfile
1446 local fid=$(create_small_file $f)
1447 local sum=$(md5sum $f | awk '{print $1}')
1448 $LFS hsm_archive $f || error "could not archive file"
1449 wait_request_state $fid ARCHIVE SUCCEED
1451 # create released file (simulate llapi_hsm_import call)
1452 local fid2=$(create_empty_file "$f")
1453 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1454 $LFS hsm_release $f || error "could not release file"
1456 # rebind the archive to the newly created file
1457 echo "rebind $fid to $fid2"
1459 copytool rebind $fid $fid2
1461 # restore file and compare md5sum
1462 local sum2=$(md5sum $f | awk '{print $1}')
1464 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1466 run_test 14 "Rebind archived file to a new fid"
1469 # test needs a running copytool
1473 local f=$DIR/$tdir/$tfile
1475 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1479 for i in $(seq 1 $count); do
1480 fids[$i]=$(create_small_file $f.$i)
1481 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1482 $LFS hsm_archive $f.$i || error "could not archive file"
1484 wait_all_done $(($count*60))
1486 stack_trap "rm -f $tmpfile" EXIT
1489 for i in $(seq 1 $count); do
1490 local fid2=$(create_empty_file "${f}.${i}")
1491 # add the rebind operation to the list
1492 echo ${fids[$i]} $fid2 >> $tmpfile
1494 # set it released (simulate llapi_hsm_import call)
1495 $LFS hsm_set --archived --exists $f.$i ||
1496 error "could not force hsm flags"
1497 $LFS hsm_release $f.$i || error "could not release file"
1499 nl=$(wc -l < $tmpfile)
1500 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1502 echo "rebind list of files"
1503 copytool rebind "$tmpfile"
1505 # restore files and compare md5sum
1506 for i in $(seq 1 $count); do
1507 local sum2=$(md5sum $f.$i | awk '{print $1}')
1508 [[ $sum2 == ${sums[$i]} ]] ||
1509 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1512 run_test 15 "Rebind a list of files"
1515 # test needs a running copytool
1519 # create a known size file so we can verify transfer speed
1522 dd if=/dev/zero of=$ref bs=1M count=20
1525 local f=$DIR/$tdir/$tfile
1526 local fid=$(copy_file $ref $f)
1528 local start=$(date +%s)
1530 wait_request_state $fid ARCHIVE SUCCEED
1531 local end=$(date +%s)
1532 # Add 1 to account for rounding errors between start and end (LU-8155)
1533 local duration=$((end - start + 1))
1535 [[ $duration -ge $((goal - 1)) ]] ||
1536 error "Transfer is too fast $duration < $goal"
1538 run_test 16 "Test CT bandwith control option"
1541 local f=$DIR/$tdir/$tfile
1542 create_empty_file "$f"
1544 # Could not release a non-archived file
1545 $LFS hsm_release $f && error "release should not succeed"
1547 # For following tests, we must test them with HS_ARCHIVED set
1548 $LFS hsm_set --exists --archived $f || error "could not add flag"
1550 # Could not release a file if no-release is set
1551 $LFS hsm_set --norelease $f || error "could not add flag"
1552 $LFS hsm_release $f && error "release should not succeed"
1553 $LFS hsm_clear --norelease $f || error "could not remove flag"
1555 # Could not release a file if lost
1556 $LFS hsm_set --lost $f || error "could not add flag"
1557 $LFS hsm_release $f && error "release should not succeed"
1558 $LFS hsm_clear --lost $f || error "could not remove flag"
1560 # Could not release a file if dirty
1561 $LFS hsm_set --dirty $f || error "could not add flag"
1562 $LFS hsm_release $f && error "release should not succeed"
1563 $LFS hsm_clear --dirty $f || error "could not remove flag"
1565 run_test 20 "Release is not permitted"
1568 # test needs a running copytool
1571 local f=$DIR/$tdir/test_release
1573 # Create a file and check its states
1574 local fid=$(create_small_file $f)
1575 check_hsm_flags $f "0x00000000"
1577 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1578 # used until file is flushed to disk
1579 if [ $(facet_fstype ost1) == "zfs" ]; then
1580 # this causes an OST_SYNC rpc to be sent
1581 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1582 # clear locks to reread file data
1583 cancel_lru_locks osc
1586 local orig_size=$(stat -c "%s" $f)
1587 local orig_blocks=$(stat -c "%b" $f)
1589 start_full_debug_logging
1591 $LFS hsm_archive $f || error "could not archive file"
1592 wait_request_state $fid ARCHIVE SUCCEED
1594 local blocks=$(stat -c "%b" $f)
1595 [ $blocks -eq $orig_blocks ] ||
1596 error "$f: wrong block number after archive: " \
1597 "$blocks != $orig_blocks"
1598 local size=$(stat -c "%s" $f)
1599 [ $size -eq $orig_size ] ||
1600 error "$f: wrong size after archive: $size != $orig_size"
1602 # Release and check states
1603 $LFS hsm_release $f || error "could not release file"
1604 check_hsm_flags $f "0x0000000d"
1606 blocks=$(stat -c "%b" $f)
1607 [ $blocks -gt 5 ] &&
1608 error "$f: too many blocks after release: $blocks > 5"
1609 size=$(stat -c "%s" $f)
1610 [ $size -ne $orig_size ] &&
1611 error "$f: wrong size after release: $size != $orig_size"
1613 # Check we can release an file without stripe info
1617 check_hsm_flags $f "0x00000000"
1618 $LFS hsm_archive $f || error "could not archive file"
1619 wait_request_state $fid ARCHIVE SUCCEED
1621 # Release and check states
1622 $LFS hsm_release $f || error "could not release file"
1623 check_hsm_flags $f "0x0000000d"
1625 # Release again a file that is already released is OK
1626 $LFS hsm_release $f || fail "second release should succeed"
1627 check_hsm_flags $f "0x0000000d"
1629 stop_full_debug_logging
1631 run_test 21 "Simple release tests"
1634 # test needs a running copytool
1637 local f=$DIR/$tdir/test_release
1638 local swap=$DIR/$tdir/test_swap
1640 # Create a file and check its states
1641 local fid=$(create_small_file $f)
1642 check_hsm_flags $f "0x00000000"
1644 $LFS hsm_archive $f || error "could not archive file"
1645 wait_request_state $fid ARCHIVE SUCCEED
1647 # Release and check states
1648 $LFS hsm_release $f || error "could not release file"
1649 check_hsm_flags $f "0x0000000d"
1651 create_small_file $swap
1652 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1656 run_test 22 "Could not swap a release file"
1659 # test needs a running copytool
1662 local f=$DIR/$tdir/test_mtime
1664 # Create a file and check its states
1665 local fid=$(create_small_file $f)
1666 check_hsm_flags $f "0x00000000"
1668 $LFS hsm_archive $f || error "could not archive file"
1669 wait_request_state $fid ARCHIVE SUCCEED
1671 # Set modification time in the past
1672 touch -m -a -d @978261179 $f
1674 # Release and check states
1675 $LFS hsm_release $f || error "could not release file"
1676 check_hsm_flags $f "0x0000000d"
1678 local MTIME=$(stat -c "%Y" $f)
1679 local ATIME=$(stat -c "%X" $f)
1680 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1681 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1683 run_test 23 "Release does not change a/mtime (utime)"
1686 local file=$DIR/$tdir/$tfile
1695 # test needs a running copytool
1698 fid=$(create_small_file $file)
1700 # Create a file and check its states
1701 check_hsm_flags $file "0x00000000"
1703 # Ensure atime is less than mtime and ctime.
1707 atime0=$(stat -c "%X" $file)
1708 mtime0=$(stat -c "%Y" $file)
1709 ctime0=$(stat -c "%Z" $file)
1711 [ $atime0 -lt $mtime0 ] ||
1712 error "atime $atime0 is not less than mtime $mtime0"
1714 [ $atime0 -lt $ctime0 ] ||
1715 error "atime $atime0 is not less than ctime $ctime0"
1717 # Archive should not change any timestamps.
1718 $LFS hsm_archive $file || error "cannot archive '$file'"
1719 wait_request_state $fid ARCHIVE SUCCEED
1721 atime1=$(stat -c "%X" $file)
1722 mtime1=$(stat -c "%Y" $file)
1723 ctime1=$(stat -c "%Z" $file)
1725 [ $atime0 -eq $atime1 ] ||
1726 error "archive changed atime from $atime0 to $atime1"
1728 [ $mtime0 -eq $mtime1 ] ||
1729 error "archive changed mtime from $mtime0 to $mtime1"
1731 [ $ctime0 -eq $ctime1 ] ||
1732 error "archive changed ctime from $ctime0 to $ctime1"
1734 # Release should not change any timestamps.
1735 $LFS hsm_release $file || error "cannot release '$file'"
1736 check_hsm_flags $file "0x0000000d"
1738 atime1=$(stat -c "%X" $file)
1739 mtime1=$(stat -c "%Y" $file)
1740 ctime1=$(stat -c "%Z" $file)
1742 [ $atime0 -eq $atime1 ] ||
1743 error "release changed atime from $atime0 to $atime1"
1745 [ $mtime0 -eq $mtime1 ] ||
1746 error "release changed mtime from $mtime0 to $mtime1"
1748 [ $ctime0 -eq $ctime1 ] ||
1749 error "release changed ctime from $ctime0 to $ctime1"
1751 # Restore should not change any timestamps.
1752 $LFS hsm_restore $file
1753 wait_request_state $fid RESTORE SUCCEED
1755 atime1=$(stat -c "%X" $file)
1756 mtime1=$(stat -c "%Y" $file)
1757 ctime1=$(stat -c "%Z" $file)
1759 [ $atime0 -eq $atime1 ] ||
1760 error "restore changed atime from $atime0 to $atime1"
1762 [ $mtime0 -eq $mtime1 ] ||
1763 error "restore changed mtime from $mtime0 to $mtime1"
1765 [ $ctime0 -eq $ctime1 ] ||
1766 error "restore changed ctime from $ctime0 to $ctime1"
1769 wait_copytools || error "Copytools failed to stop"
1771 # Once more, after unmount and mount.
1772 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1773 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1775 atime1=$(stat -c "%X" $file)
1776 mtime1=$(stat -c "%Y" $file)
1777 ctime1=$(stat -c "%Z" $file)
1779 [ $atime0 -eq $atime1 ] ||
1780 error "remount changed atime from $atime0 to $atime1"
1782 [ $mtime0 -eq $mtime1 ] ||
1783 error "remount changed mtime from $mtime0 to $mtime1"
1785 [ $ctime0 -eq $ctime1 ] ||
1786 error "remount changed ctime from $ctime0 to $ctime1"
1788 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1791 local file=$DIR/$tdir/$tfile
1797 # Test needs a running copytool.
1800 # Check that root can do HSM actions on a regular user's file.
1801 fid=$(create_small_file $file)
1802 sum0=$(md5sum $file)
1804 chown $RUNAS_ID:$RUNAS_GID $file ||
1805 error "cannot chown '$file' to '$RUNAS_ID'"
1807 chmod ugo-w $DIR/$tdir ||
1808 error "cannot chmod '$DIR/$tdir'"
1810 $LFS hsm_archive $file
1811 wait_request_state $fid ARCHIVE SUCCEED
1813 $LFS hsm_release $file
1814 check_hsm_flags $file "0x0000000d"
1816 $LFS hsm_restore $file
1817 wait_request_state $fid RESTORE SUCCEED
1819 # Check that ordinary user can get HSM state.
1820 $RUNAS $LFS hsm_state $file ||
1821 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1823 $LFS hsm_release $file
1824 check_hsm_flags $file "0x0000000d"
1826 # Check that ordinary user can accessed released file.
1827 sum1=$($RUNAS md5sum $file) ||
1828 error "user '$RUNAS_ID' cannot read '$file'"
1830 [ "$sum0" == "$sum1" ] ||
1831 error "md5sum mismatch for '$file'"
1833 run_test 24b "root can archive, release, and restore user files"
1836 local file=$DIR/$tdir/$tfile
1837 local action=archive
1842 # test needs a running copytool
1847 # Save the default masks and check that cleanup_24c will
1848 # restore the request masks correctly.
1849 user_save=$(get_hsm_param user_request_mask)
1850 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1851 group_save=$(get_hsm_param group_request_mask)
1852 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1853 other_save=$(get_hsm_param other_request_mask)
1854 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1856 [ "$user_save" == RESTORE ] ||
1857 error "user_request_mask is '$user_save' expected 'RESTORE'"
1858 [ "$group_save" == RESTORE ] ||
1859 error "group_request_mask is '$group_save' expected 'RESTORE'"
1860 [ "$other_save" == RESTORE ] ||
1861 error "other_request_mask is '$other_save' expected 'RESTORE'"
1864 create_small_file $file
1865 chown $RUNAS_ID:$GROUP $file ||
1866 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1868 $RUNAS $LFS hsm_$action $file &&
1869 error "$action by user should fail"
1871 set_hsm_param user_request_mask $action
1872 $RUNAS $LFS hsm_$action $file ||
1873 error "$action by user should succeed"
1876 create_small_file $file
1877 chown nobody:$RUNAS_GID $file ||
1878 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1880 $RUNAS $LFS hsm_$action $file &&
1881 error "$action by group should fail"
1883 set_hsm_param group_request_mask $action
1884 $RUNAS $LFS hsm_$action $file ||
1885 error "$action by group should succeed"
1888 create_small_file $file
1889 chown nobody:$GROUP $file ||
1890 error "cannot chown '$file' to 'nobody:$GROUP'"
1892 $RUNAS $LFS hsm_$action $file &&
1893 error "$action by other should fail"
1895 set_hsm_param other_request_mask $action
1896 $RUNAS $LFS hsm_$action $file ||
1897 error "$action by other should succeed"
1899 run_test 24c "check that user,group,other request masks work"
1902 local file1=$DIR/$tdir/$tfile
1903 local file2=$DIR2/$tdir/$tfile
1907 fid1=$(create_small_file $file1)
1910 $LFS getstripe $file1
1912 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1913 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1914 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1916 copytool setup -m "$MOUNT3"
1918 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1919 mount -o remount,ro $MOUNT2
1921 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1923 fid2=$(path2fid $file2)
1924 [ "$fid1" == "$fid2" ] ||
1925 error "FID mismatch '$fid1' != '$fid2'"
1927 $LFS hsm_archive $file2 &&
1928 error "archive should fail on read-only mount"
1929 check_hsm_flags $file1 "0x00000000"
1931 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1932 wait_request_state $fid1 ARCHIVE SUCCEED
1934 $LFS hsm_release $file1
1935 $LFS hsm_restore $file2
1936 wait_request_state $fid1 RESTORE SUCCEED
1938 $LFS hsm_release $file1 || error "cannot release '$file1'"
1939 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1941 $LFS hsm_release $file2 &&
1942 error "release should fail on read-only mount"
1946 run_test 24d "check that read-only mounts are respected"
1951 local f=$DIR/$tdir/$tfile
1954 fid=$(create_small_file $f) || error "cannot create $f"
1955 $LFS hsm_archive $f || error "cannot archive $f"
1956 wait_request_state $fid ARCHIVE SUCCEED
1957 $LFS hsm_release $f || error "cannot release $f"
1958 while ! $LFS hsm_state $f | grep released; do
1962 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1964 run_test 24e "tar succeeds on HSM released files" # LU-6213
1967 # test needs a running copytool
1970 mkdir -p $DIR/$tdir/d1
1971 local f=$DIR/$tdir/$tfile
1972 local fid=$(copy_file /etc/hosts $f)
1975 $LFS hsm_archive $f ||
1976 error "hsm_archive failed"
1977 wait_request_state $fid ARCHIVE SUCCEED
1978 $LFS hsm_release $f || error "cannot release $f"
1979 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1982 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1983 error "Can not recover the tar contents"
1985 echo "Sum0 = $sum0, sum1 = $sum1"
1986 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1988 run_test 24f "root can archive, release, and restore tar files"
1991 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
1992 skip "need MDS version 2.11.56 or later"
1994 local file=$DIR/$tdir/$tfile
1997 echo "RUNAS = '$RUNAS'"
2002 chmod ugo+rwx $DIR/$tdir
2004 echo "Please listen carefully as our options have changed." | tee $file
2005 fid=$(path2fid $file)
2008 $LFS hsm_archive $file
2009 wait_request_state $fid ARCHIVE SUCCEED
2010 check_hsm_flags $file 0x00000009 # exists archived
2012 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2013 check_hsm_flags $file 0x0000000b # exists dirty archived
2015 run_test 24g "write by non-owner still sets dirty" # LU-11369
2018 # test needs a running copytool
2022 copy2archive /etc/hosts $tdir/$tfile
2024 local f=$DIR/$tdir/$tfile
2026 copytool import $tdir/$tfile $f
2028 $LFS hsm_set --lost $f
2033 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2035 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2036 " (Operation not permitted)"
2039 # test needs a running copytool
2044 local f=$DIR/$tdir/$tfile
2045 local fid=$(copy_file /etc/passwd $f)
2047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2048 wait_request_state $fid ARCHIVE SUCCEED
2051 $LFS hsm_set --lost $f
2055 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2057 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2058 " (Operation not permitted)"
2060 test_26A() { # was test_26
2061 # test needs a running copytool
2064 local f=$DIR/$tdir/$tfile
2065 local fid=$(create_empty_file "$f")
2067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2068 wait_request_state $fid ARCHIVE SUCCEED
2071 wait_request_state $fid REMOVE SUCCEED
2073 check_hsm_flags $f "0x00000000"
2075 run_test 26A "Remove the archive of a valid file"
2078 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2079 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2081 # test needs a running copytool
2085 local f=$DIR/$tdir/$tfile
2086 local fid=$(copy_file /etc/passwd $f)
2088 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2089 wait_request_state $fid ARCHIVE SUCCEED
2091 local f2=$DIR/$tdir/${tfile}_2
2092 local fid2=$(copy_file /etc/passwd $f2)
2094 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2095 wait_request_state $fid2 ARCHIVE SUCCEED
2097 local f3=$DIR/$tdir/${tfile}_3
2098 local fid3=$(copy_file /etc/passwd $f3)
2100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2101 wait_request_state $fid3 ARCHIVE SUCCEED
2103 # set a long grace_delay vs short loop_period
2104 local orig_loop_period=$(get_hsm_param loop_period)
2105 local orig_grace_delay=$(get_hsm_param grace_delay)
2106 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2107 set_hsm_param loop_period 10
2108 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2109 set_hsm_param grace_delay 100
2113 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2114 set_hsm_param remove_archive_on_last_unlink 1
2116 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2121 wait_request_state $fid2 REMOVE SUCCEED
2123 assert_request_count $fid REMOVE 0 \
2124 "Unexpected archived data remove request for $f"
2125 assert_request_count $fid3 REMOVE 0 \
2126 "Unexpected archived data remove request for $f3"
2128 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2131 # test needs a running copytool
2135 local f=$DIR/$tdir/$tfile
2136 local fid=$(copy_file /etc/passwd $f)
2138 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2139 wait_request_state $fid ARCHIVE SUCCEED
2141 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2142 set_hsm_param remove_archive_on_last_unlink 1
2145 cdt_check_state stopped
2149 wait_request_state $fid REMOVE WAITING
2153 # copytool must re-register
2155 wait_copytools || error "copytool failed to stop"
2158 wait_request_state $fid REMOVE SUCCEED
2160 run_test 26b "RAoLU policy when CDT off"
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 local f2=$DIR/$tdir/${tfile}_2
2174 local fid2=$(copy_file /etc/passwd $f2)
2176 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2177 wait_request_state $fid2 ARCHIVE SUCCEED
2179 # set a long grace_delay vs short loop_period
2180 local orig_loop_period=$(get_hsm_param loop_period)
2181 local orig_grace_delay=$(get_hsm_param grace_delay)
2182 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2183 set_hsm_param loop_period 10
2184 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2185 set_hsm_param grace_delay 100
2187 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2188 set_hsm_param remove_archive_on_last_unlink 1
2190 multiop_bg_pause $f O_c || error "open $f failed"
2196 wait_request_state $fid2 REMOVE SUCCEED
2197 assert_request_count $fid REMOVE 0 \
2198 "Unexpected archived data remove request for $f"
2200 kill -USR1 $pid || error "multiop early exit"
2201 # should reach autotest timeout if multiop fails to trap
2202 # signal, close file, and exit ...
2203 wait $pid || error "wait PID $PID failed"
2205 wait_request_state $fid REMOVE SUCCEED
2207 run_test 26c "RAoLU effective when file closed"
2210 # test needs a running copytool
2214 local f=$DIR/$tdir/$tfile
2215 local fid=$(create_small_file $f)
2217 $LFS hsm_archive $f || error "could not archive file"
2218 wait_request_state $fid ARCHIVE SUCCEED
2220 # set a long grace_delay vs short loop_period
2221 local orig_loop_period=$(get_hsm_param loop_period)
2222 local orig_grace_delay=$(get_hsm_param grace_delay)
2223 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2224 set_hsm_param loop_period 10
2225 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2226 set_hsm_param grace_delay 100
2228 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2229 set_hsm_param remove_archive_on_last_unlink 1
2231 multiop_bg_pause $f O_c || error "multiop failed"
2238 wait_request_state $fid REMOVE SUCCEED
2240 client_up || client_up || true
2242 kill -USR1 $MULTIPID
2243 wait $MULTIPID || error "multiop close failed"
2245 run_test 26d "RAoLU when Client eviction"
2248 # test needs a running copytool
2251 create_archive_file $tdir/$tfile
2252 local f=$DIR/$tdir/$tfile
2253 copytool import $tdir/$tfile $f
2254 local fid=$(path2fid $f)
2258 [[ $? != 0 ]] || error "Remove of a released file should fail"
2260 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2263 # test needs a running copytool
2266 local f=$DIR/$tdir/$tfile
2267 local fid=$(create_empty_file "$f")
2269 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2270 wait_request_state $fid ARCHIVE SUCCEED
2275 [[ $? != 0 ]] || error "Remove of a released file should fail"
2277 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2280 # test needs a running copytool
2283 local f=$DIR/$tdir/$tfile
2284 local fid=$(create_empty_file "$f")
2286 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2287 wait_request_state $fid ARCHIVE SUCCEED
2296 wait_request_state $fid REMOVE SUCCEED
2298 run_test 28 "Concurrent archive/file remove"
2301 # Tests --mntpath and --archive options
2304 copytool setup -m "$MOUNT" -a $archive_id
2306 # Bad archive number
2307 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2308 grep "Invalid argument" ||
2309 error "unexpected hsm_remove failure (1)"
2311 # mntpath is present but file is given
2312 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2313 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2314 error "unexpected hsm_remove failure (2)"
2316 run_test 29a "Tests --mntpath and --archive options"
2319 # test needs a running copytool
2322 local f=$DIR/$tdir/$tfile
2323 local fid=$(create_small_file $f)
2325 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2326 wait_request_state $fid ARCHIVE SUCCEED
2330 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2331 wait_request_state $fid REMOVE SUCCEED
2333 run_test 29b "Archive/delete/remove by FID from the archive."
2336 # test needs a running copytool
2339 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2340 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2341 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2344 wait_request_state $fid1 ARCHIVE SUCCEED
2345 wait_request_state $fid2 ARCHIVE SUCCEED
2346 wait_request_state $fid3 ARCHIVE SUCCEED
2348 rm -f $DIR/$tdir/$tfile-[1-3]
2350 echo $fid1 > $DIR/$tdir/list
2351 echo $fid2 >> $DIR/$tdir/list
2352 echo $fid3 >> $DIR/$tdir/list
2354 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2355 --filelist $DIR/$tdir/list
2356 wait_request_state $fid1 REMOVE SUCCEED
2357 wait_request_state $fid2 REMOVE SUCCEED
2358 wait_request_state $fid3 REMOVE SUCCEED
2360 run_test 29c "Archive/delete/remove by FID, using a file list."
2363 # test needs more than one CT
2364 needclients 3 || return 0
2370 # start all of the copytools
2371 for n in $(seq $AGTCOUNT); do
2372 copytool setup -f agt$n -a $n
2376 file=$DIR/$tdir/$tfile
2377 fid=$(create_small_file $file)
2379 $LFS hsm_archive $file
2380 wait_request_state $fid ARCHIVE SUCCEED
2381 check_hsm_flags $file "0x00000009"
2385 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2386 error "cannot hsm_remove '$fid'"
2388 # give time for CDT to handle remove request and create broadcasted
2391 # remove request has been broadcasted ?
2392 local cnt=$(get_request_count $fid REMOVE)
2393 # broadcasted requests + original
2394 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2395 error "remove not broadcasted to all CTs"
2397 # give time for CDT and CTs to handle broadcasted
2398 wait_for_loop_period
2400 # each agent serves one different archive_id, so broadcasted
2401 # hsm_remove request should only succeed once and fail at all others
2405 for n in $(seq $AGTCOUNT); do
2406 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2407 $HSM_PARAM.actions | awk \
2408 '/'$fid'.*action=REMOVE archive#='$n'/ \
2409 {print \\\$13}' | cut -f2 -d=")
2410 if [[ "$res" == "SUCCEED" ]]; then
2412 elif [[ "$res" == "FAILED" ]]; then
2417 [[ $scnt -eq 1 ]] ||
2418 error "one and only CT should have removed successfully"
2420 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2421 error "all but one CT should have failed to remove"
2423 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2424 "request to be sent once for each registered archive_id"
2427 # restore at exec cannot work on agent node (because of Linux kernel
2428 # protection of executables)
2429 needclients 2 || return 0
2431 # test needs a running copytool
2435 copy2archive /bin/true $tdir/$tfile
2437 local f=$DIR/$tdir/true
2438 copytool import $tdir/$tfile $f
2440 local fid=$(path2fid $f)
2442 stack_trap "cdt_clear_no_retry" EXIT
2443 # set no retry action mode
2450 [[ $st == 0 ]] || error "Failed to exec a released file"
2452 run_test 30a "Restore at exec (import case)"
2455 # restore at exec cannot work on agent node (because of Linux kernel
2456 # protection of executables)
2457 needclients 2 || return 0
2459 # test needs a running copytool
2463 local f=$DIR/$tdir/true
2464 local fid=$(copy_file /bin/true $f)
2466 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2467 wait_request_state $fid ARCHIVE SUCCEED
2471 stack_trap cdt_clear_no_retry EXIT
2472 # set no retry action mode
2480 [[ $st == 0 ]] || error "Failed to exec a released file"
2482 run_test 30b "Restore at exec (release case)"
2485 needclients 2 || return 0
2487 # test needs a running copytool
2491 local f=$DIR/$tdir/SLEEP
2492 local slp_sum1=$(md5sum /bin/sleep)
2493 local fid=$(copy_file /bin/sleep $f)
2495 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2496 wait_request_state $fid ARCHIVE SUCCEED
2498 check_hsm_flags $f "0x0000000d"
2500 stack_trap cdt_clear_no_retry EXIT
2501 # set no retry action mode
2504 do_node $CLIENT2 "$f 10" &
2508 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2510 [[ $? == 0 ]] || error "Execution failed during run"
2512 if [[ $? != 0 ]]; then
2513 local slp_sum2=$(md5sum /bin/sleep)
2514 # in case sleep file is modified during the test
2515 [[ $slp_sum1 == $slp_sum2 ]] &&
2516 error "Binary overwritten during exec"
2519 check_hsm_flags $f "0x00000009"
2521 run_test 30c "Update during exec of released file must fail"
2523 restore_and_check_size() {
2526 local s=$(stat -c "%s" $f)
2528 local st=$(get_hsm_flags $f)
2532 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2534 n=$(stat -c "%s" $f)
2535 # we echo in both cases to show stat is not hang
2536 if [[ $n != $s ]]; then
2537 echo "size seen is $n != $s"
2540 echo "size seen is right: $n == $s"
2544 st=$(get_hsm_flags $f)
2546 if [[ "$st" = "0x00000009" ]]; then
2549 echo " restore is too long"
2550 wait_request_state $fid RESTORE SUCCEED
2556 # test needs a running copytool
2559 create_archive_file $tdir/$tfile
2560 local f=$DIR/$tdir/$tfile
2561 copytool import $tdir/$tfile $f
2562 local fid=$($LFS path2fid $f)
2565 restore_and_check_size $f $fid
2568 [[ $err -eq 0 ]] || error "File size changed during restore"
2570 run_test 31a "Import a large file and check size during restore"
2574 # test needs a running copytool
2577 local f=$DIR/$tdir/$tfile
2578 local fid=$(create_file "$f" 1MB 39)
2580 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2581 wait_request_state $fid ARCHIVE SUCCEED
2584 restore_and_check_size $f $fid
2587 [[ $err -eq 0 ]] || error "File size changed during restore"
2589 run_test 31b "Restore a large unaligned file and check size during restore"
2592 # test needs a running copytool
2595 local f=$DIR/$tdir/$tfile
2596 local fid=$(create_file "$f" 1M 39)
2598 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2599 wait_request_state $fid ARCHIVE SUCCEED
2602 restore_and_check_size $f $fid
2605 [[ $err -eq 0 ]] || error "File size changed during restore"
2607 run_test 31c "Restore a large aligned file and check size during restore"
2610 local f=$DIR/$tdir/$tfile
2611 local fid=$(create_empty_file "$f")
2615 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2616 wait_request_state $fid ARCHIVE SUCCEED
2619 # Prevent restore from completing
2623 md5sum $f >/dev/null &
2626 wait_request_state $fid RESTORE STARTED
2631 # Check restore trigger process was killed
2633 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2635 run_test 33 "Kill a restore waiting process"
2638 # test needs a running copytool
2641 local f=$DIR/$tdir/$tfile
2642 local fid=$(create_empty_file "$f")
2644 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2645 wait_request_state $fid ARCHIVE SUCCEED
2648 # Prevent restore from completing
2651 md5sum $f >/dev/null &
2654 wait_request_state $fid RESTORE STARTED
2656 # rm must not block during restore
2657 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2660 wait_request_state $fid RESTORE SUCCEED
2662 # Check md5sum pgm finished
2663 kill -0 $pid && error "Restore initiatior still running"
2664 wait $pid || error "Restore initiator failed with $?"
2666 # Check the file was actually deleted
2667 [ ! -f "$f" ] || error "$f was not deleted"
2669 run_test 34 "Remove file during restore"
2672 # test needs a running copytool
2675 local f=$DIR/$tdir/$tfile
2676 local f1=$DIR/$tdir/$tfile-1
2677 local fid=$(create_empty_file "$f")
2678 local fid1=$(copy_file /etc/passwd $f1)
2680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2681 wait_request_state $fid ARCHIVE SUCCEED
2684 # Prevent restore from completing
2687 md5sum $f >/dev/null &
2690 wait_request_state $fid RESTORE STARTED
2692 # mv must not block during restore
2693 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2696 wait_request_state $fid RESTORE SUCCEED
2698 # Check md5sum pgm finished
2699 kill -0 $pid && error "Restore initiatior still running"
2700 wait $pid || error "Restore initiator failed with $?"
2702 local fid2=$(path2fid $f)
2703 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2705 run_test 35 "Overwrite file during restore"
2708 # test needs a running copytool
2711 local f=$DIR/$tdir/$tfile
2712 local fid=$(create_empty_file "$f")
2714 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2715 wait_request_state $fid ARCHIVE SUCCEED
2718 # Prevent restore from completing
2721 md5sum $f >/dev/null &
2724 wait_request_state $fid RESTORE STARTED
2726 # mv must not block during restore
2727 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2728 error "mv '$f' '$f.new' failed with rc=$?"
2731 wait_request_state $fid RESTORE SUCCEED
2733 # Check md5sum pgm finished
2734 kill -0 $pid && error "Restore initiator is still running"
2735 wait $pid || error "Restore initiator failed with $?"
2737 run_test 36 "Move file during restore"
2740 # LU-5683: check that an archived dirty file can be rearchived.
2743 local f=$DIR/$tdir/$tfile
2746 fid=$(create_small_file $f) || error "cannot create small file"
2748 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2749 wait_request_state $fid ARCHIVE SUCCEED
2750 $LFS hsm_release $f || error "cannot release $f"
2752 # Allow previous archive request to expire from the actions log.
2753 wait_for_grace_delay
2756 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2758 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2759 wait_request_state $fid ARCHIVE SUCCEED
2761 run_test 37 "re-archive a dirty file"
2768 for n in $(seq 1 $count); do
2769 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2771 echo "$count archive requests submitted"
2775 local stream_count=4
2776 local file_count=100
2778 local f=$DIR/$tdir/$tfile
2782 local max_requests=$(get_hsm_param max_requests)
2784 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2785 # Increase the number of HSM request that can be performed in
2786 # parallel. With the coordinator running once per second, this
2787 # also limits the number of requests per seconds that can be
2788 # performed, so we pick a decent number. But we also need to keep
2789 # that number low because the copytool has no rate limit and will
2790 # fail some requests if if gets too many at once.
2791 set_hsm_param max_requests 300
2793 for i in $(seq 1 $file_count); do
2794 for p in $(seq 1 $stream_count); do
2795 fid=$(copy_file /etc/hosts $f.$p.$i)
2801 # to be sure wait_all_done will not be mislead by previous tests
2803 wait_for_grace_delay
2805 # start archive streams in background (archive files in parallel)
2806 for p in $(seq 1 $stream_count); do
2807 multi_archive $f.$p $file_count &
2810 echo -n "Wait for all requests being enqueued..."
2815 run_test 40 "Parallel archive requests"
2818 # test needs a running copytool
2822 local f=$DIR/$tdir/$tfile
2823 local fid=$(create_small_file $f)
2825 $LFS hsm_archive $f || error "could not archive file"
2826 wait_request_state $fid ARCHIVE SUCCEED
2827 check_hsm_flags $f "0x00000009"
2829 multiop_bg_pause $f O_c || error "multiop failed"
2833 client_up || client_up || true
2835 kill -USR1 $MULTIPID
2836 wait $MULTIPID || error "multiop close failed"
2838 check_hsm_flags $f "0x0000000b"
2840 run_test 52 "Opened for write file on an evicted client should be set dirty"
2843 # test needs a running copytool
2847 local f=$DIR/$tdir/$tfile
2848 local fid=$(create_small_file $f)
2850 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2851 error "could not archive file"
2852 wait_request_state $fid ARCHIVE SUCCEED
2853 check_hsm_flags $f "0x00000009"
2855 multiop_bg_pause $f o_c || error "multiop failed"
2859 client_up || client_up || true
2861 kill -USR1 $MULTIPID
2862 wait $MULTIPID || error "multiop close failed"
2864 check_hsm_flags $f "0x00000009"
2866 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2869 local f=$DIR/$tdir/$tfile
2870 local fid=$(create_file "$f" 1MB 39)
2874 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2875 error "could not archive file"
2876 wait_request_state $fid ARCHIVE STARTED
2878 check_hsm_flags $f "0x00000001"
2880 stack_trap "cdt_clear_no_retry" EXIT
2881 # Avoid coordinator resending this request as soon it has failed.
2886 wait_request_state $fid ARCHIVE FAILED
2888 check_hsm_flags $f "0x00000003"
2890 run_test 54 "Write during an archive cancels it"
2893 local f=$DIR/$tdir/$tfile
2894 local fid=$(create_file "$f" 1MB 39)
2898 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2899 error "could not archive file"
2900 wait_request_state $fid ARCHIVE STARTED
2902 check_hsm_flags $f "0x00000001"
2904 stack_trap "cdt_clear_no_retry" EXIT
2905 # Avoid coordinator resending this request as soon it has failed.
2908 $TRUNCATE $f 1024 || error "truncate failed"
2910 wait_request_state $fid ARCHIVE FAILED
2912 check_hsm_flags $f "0x00000003"
2914 run_test 55 "Truncate during an archive cancels it"
2917 local f=$DIR/$tdir/$tfile
2918 local fid=$(create_file "$f" 1MB 39)
2922 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2923 error "could not archive file"
2924 wait_request_state $fid ARCHIVE STARTED
2926 check_hsm_flags $f "0x00000001"
2928 # Change metadata and sync to be sure we are not changing only
2933 wait_request_state $fid ARCHIVE SUCCEED
2935 check_hsm_flags $f "0x00000009"
2937 run_test 56 "Setattr during an archive is ok"
2940 # Need one client for I/O, one for request
2941 needclients 2 || return 0
2943 # test needs a running copytool
2947 local f=$DIR/$tdir/test_archive_remote
2948 # Create a file on a remote node
2949 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2950 "count=2 conv=fsync"
2953 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2954 error "hsm_archive failed"
2955 local fid=$(path2fid $f)
2956 wait_request_state $fid ARCHIVE SUCCEED
2958 # Release and implicit restore it
2959 do_node $CLIENT2 "$LFS hsm_release $f" ||
2960 error "hsm_release failed"
2961 do_node $CLIENT2 "md5sum $f" ||
2962 error "hsm_restore failed"
2964 wait_request_state $fid RESTORE SUCCEED
2966 run_test 57 "Archive a file with dirty cache on another node"
2968 truncate_released_file() {
2972 local sz=$(stat -c %s $src_file)
2973 local f=$DIR/$tdir/$tfile
2974 local fid=$(copy_file $1 $f)
2978 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2979 error "could not archive file"
2980 wait_request_state $fid ARCHIVE SUCCEED
2982 $LFS hsm_release $f || error "could not release file"
2984 $TRUNCATE $f $trunc_to || error "truncate failed"
2987 local sz1=$(stat -c %s $f)
2988 [[ $sz1 == $trunc_to ]] ||
2989 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2992 check_hsm_flags $f "0x0000000b"
2994 local state=$(get_request_state $fid RESTORE)
2995 [[ "$state" == "SUCCEED" ]] ||
2996 error "truncate $sz does not trig restore, state = $state"
2998 $TRUNCATE $ref $trunc_to
2999 cmp $ref $f || error "file data wrong after truncate"
3005 # test needs a running copytool
3010 local sz=$(stat -c %s /etc/passwd)
3012 echo "truncate up from $sz to $((sz*2))"
3013 truncate_released_file /etc/passwd $((sz*2))
3015 echo "truncate down from $sz to $((sz/2))"
3016 truncate_released_file /etc/passwd $((sz/2))
3018 echo "truncate to 0"
3019 truncate_released_file /etc/passwd 0
3021 run_test 58 "Truncate a released file will trigger restore"
3025 [[ $MDS_VERSION_CODE -lt $(version_code 2.7.63) ]] &&
3026 skip "Need MDS version at least 2.7.63"
3029 $MCREATE $DIR/$tfile || error "mcreate failed"
3030 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3031 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3032 fid=$(path2fid $DIR/$tfile)
3033 wait_request_state $fid ARCHIVE SUCCEED
3034 $LFS hsm_release $DIR/$tfile || error "release failed"
3036 run_test 59 "Release stripeless file with non-zero size"
3039 # This test validates the fix for LU-4512. Ensure that the -u
3040 # option changes the progress reporting interval from the
3041 # default (30 seconds) to the user-specified interval.
3042 local f=$DIR/$tdir/$tfile
3043 local fid=$(create_file "$f" 1M 10)
3046 local progress_timeout=$((interval * 4))
3047 copytool setup -b 1 --update-interval $interval
3050 local mdt=${MDT_PREFIX}${mdtidx}
3051 local mds=mds$((mdtidx + 1))
3053 # Wait for copytool to register
3054 wait_update_facet $mds \
3055 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3056 uuid 100 || error "coyptool failed to register with $mdt"
3058 local start_at=$(date +%s)
3059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3060 error "could not archive file"
3062 local agent=$(facet_active_host $SINGLEAGT)
3063 local logfile=$(copytool_logfile $SINGLEAGT)
3065 wait_update $agent \
3066 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3067 error "copytool failed to start"
3069 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3070 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3076 echo -n "Expecting a progress update within $progress_timeout seconds... "
3078 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3079 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3080 echo "$RESULT bytes copied in $WAIT seconds."
3082 elif [ $WAIT -ge $progress_timeout ]; then
3083 error "Timed out waiting for progress update!"
3086 WAIT=$((WAIT + sleep))
3090 local finish_at=$(date +%s)
3091 local elapsed=$((finish_at - start_at))
3093 # Ensure that the progress update occurred within the expected window.
3094 if [ $elapsed -lt $((interval - 1)) ]; then
3095 error "Expected progress update after at least $interval seconds"
3098 echo "Wait for on going archive hsm action to complete"
3099 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3100 echo "File archiving not completed even after 10 secs"
3102 run_test 60 "Changing progress update interval from default"
3105 # test needs a running copytool
3109 local f=$DIR/$tdir/$tfile
3110 local fid=$(copy_file /etc/passwd $f)
3112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3115 wait_request_state $fid ARCHIVE FAILED
3117 run_test 61 "Waiting archive of a removed file should fail"
3120 # test needs a new running copytool
3121 stack_trap copytool_monitor_cleanup EXIT
3122 copytool_monitor_setup
3123 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3125 # Wait for the copytool to register.
3126 wait_update --verbose $(facet_active_host mds1) \
3127 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3129 error "copytool failed to register with MDT0000"
3132 wait_copytools || error "Copytools failed to stop"
3134 local REGISTER_EVENT
3135 local UNREGISTER_EVENT
3136 while read event; do
3137 local parsed=$(parse_json_event "$event")
3138 if [ -z "$parsed" ]; then
3139 error "Copytool sent malformed event: $event"
3143 if [ $event_type == "REGISTER" ]; then
3144 REGISTER_EVENT=$event
3145 elif [ $event_type == "UNREGISTER" ]; then
3146 UNREGISTER_EVENT=$event
3148 done < <(echo $"$(get_copytool_event_log)")
3150 if [ -z "$REGISTER_EVENT" ]; then
3151 error "Copytool failed to send register event to FIFO"
3154 if [ -z "$UNREGISTER_EVENT" ]; then
3155 error "Copytool failed to send unregister event to FIFO"
3158 echo "Register/Unregister events look OK."
3160 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3163 # Bump progress interval for livelier events.
3166 # test needs a new running copytool
3167 stack_trap copytool_monitor_cleanup EXIT
3168 copytool_monitor_setup
3169 copytool setup --update-interval $interval --event-fifo \
3170 "$HSMTOOL_MONITOR_DIR/fifo"
3172 stack_trap "cdt_clear_no_retry" EXIT
3173 # Just start and stop the copytool to generate events.
3176 local f=$DIR/$tdir/$tfile
3177 local fid=$(create_small_file "$f")
3179 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3180 error "could not archive file"
3181 wait_request_state $fid ARCHIVE SUCCEED
3183 local expected_fields="event_time data_fid source_fid"
3184 expected_fields+=" total_bytes current_bytes"
3187 [ARCHIVE_START]=false
3188 [ARCHIVE_FINISH]=false
3189 [ARCHIVE_RUNNING]=false
3191 while read event; do
3192 # Make sure we're not getting anything from previous events.
3193 for field in $expected_fields; do
3197 local parsed=$(parse_json_event "$event")
3198 if [ -z "$parsed" ]; then
3199 error "Copytool sent malformed event: $event"
3203 events["$event_type"]=true
3205 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3207 # Do some simple checking of the progress update events.
3208 for expected_field in $expected_fields; do
3209 if [ -z ${!expected_field+x} ]; then
3210 error "Missing $expected_field field in event"
3214 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3216 # These should be identical throughout an archive operation
3217 [ $source_fid == $data_fid ] ||
3218 error "Expected source_fid to equal data_fid"
3219 done < <(echo $"$(get_copytool_event_log)")
3221 # Check we received every type of events we were expecting
3222 for event in "${!events[@]}"; do
3223 ${events["$event"]} ||
3224 error "Copytool failed to send '$event' event to FIFO"
3227 echo "Archive events look OK."
3229 run_test 71 "Copytool logs JSON archive events to FIFO"
3232 # Bump progress interval for livelier events.
3235 # test needs a new running copytool
3236 stack_trap copytool_monitor_cleanup EXIT
3237 copytool_monitor_setup
3238 copytool setup --update-interval $interval --event-fifo \
3239 "$HSMTOOL_MONITOR_DIR/fifo"
3240 local test_file=$HSMTOOL_MONITOR_DIR/file
3242 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3244 do_facet $SINGLEAGT "$cmd" ||
3245 error "cannot create $test_file on $SINGLEAGT"
3246 copy2archive $test_file $tdir/$tfile
3249 local f=$DIR/$tdir/$tfile
3250 copytool import $tdir/$tfile $f
3251 f=$DIR2/$tdir/$tfile
3252 echo "Verifying released state: "
3253 check_hsm_flags $f "0x0000000d"
3255 local fid=$(path2fid $f)
3257 wait_request_state $fid RESTORE SUCCEED
3259 local expected_fields="event_time data_fid source_fid"
3260 expected_fields+=" total_bytes current_bytes"
3264 while read event; do
3265 # Make sure we're not getting anything from previous events.
3266 for field in $expected_fields; do
3270 local parsed=$(parse_json_event "$event")
3271 if [ -z "$parsed" ]; then
3272 error "Copytool sent malformed event: $event"
3276 if [ $event_type == "RESTORE_START" ]; then
3278 if [ $source_fid != $data_fid ]; then
3279 error "source_fid should == data_fid at start"
3282 elif [ $event_type == "RESTORE_FINISH" ]; then
3284 if [ $source_fid != $data_fid ]; then
3285 error "source_fid should == data_fid at finish"
3288 elif [ $event_type != "RESTORE_RUNNING" ]; then
3292 # Do some simple checking of the progress update events.
3293 for expected_field in $expected_fields; do
3294 if [ -z ${!expected_field+x} ]; then
3295 error "Missing $expected_field field in event"
3299 if [ $total_bytes -eq 0 ]; then
3300 error "Expected total_bytes to be > 0"
3303 # When a restore starts out, the data fid is the same as the
3304 # source fid. After the restore has gotten going, we learn
3305 # the new data fid. Once the restore has finished, the source
3306 # fid is set to the new data fid.
3308 # We test this because some monitoring software may depend on
3309 # this behavior. If it changes, then the consumers of these
3310 # events may need to be modified.
3311 if [ $source_fid == $data_fid ]; then
3312 error "source_fid should != data_fid during restore"
3314 done < <(echo $"$(get_copytool_event_log)")
3316 if [ -z "$START_EVENT" ]; then
3317 error "Copytool failed to send restore start event to FIFO"
3320 if [ -z "$FINISH_EVENT" ]; then
3321 error "Copytool failed to send restore finish event to FIFO"
3324 echo "Restore events look OK."
3326 run_test 72 "Copytool logs JSON restore events to FIFO"
3329 file_count=51 # Max number of files constrained by LNET message size
3330 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3331 local f=$DIR/$tdir/$tfile
3332 local FILELIST=/tmp/filelist.txt
3336 for i in $(seq 1 $file_count); do
3337 fid=$(copy_file /etc/hosts $f.$i)
3338 echo $f.$i >> $FILELIST
3342 # to be sure wait_all_done will not be mislead by previous tests
3344 wait_for_grace_delay
3345 $LFS hsm_archive --filelist $FILELIST ||
3346 error "cannot archive a file list"
3348 $LFS hsm_release --filelist $FILELIST ||
3349 error "cannot release a file list"
3350 $LFS hsm_restore --filelist $FILELIST ||
3351 error "cannot restore a file list"
3354 run_test 90 "Archive/restore a file list"
3356 double_verify_reset_hsm_param() {
3358 echo "Testing $HSM_PARAM.$p"
3359 local val=$(get_hsm_param $p)
3361 local val2=$(($val * 2))
3362 set_hsm_param $p $val2
3363 val=$(get_hsm_param $p)
3364 [[ $val == $val2 ]] ||
3365 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3366 echo "Set $p to 0 must failed"
3370 set_hsm_param $p $save
3372 if [[ $rc == 0 ]]; then
3373 error "we must not be able to set $HSM_PARAM.$p to 0"
3378 double_verify_reset_hsm_param loop_period
3379 double_verify_reset_hsm_param grace_delay
3380 double_verify_reset_hsm_param active_request_timeout
3381 double_verify_reset_hsm_param max_requests
3382 double_verify_reset_hsm_param default_archive_id
3384 run_test 100 "Set coordinator /proc tunables"
3391 run_test 102 "Verify coordinator control"
3394 # test needs a running copytool
3401 for i in $(seq 1 20); do
3402 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3404 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3408 echo "Current requests"
3409 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3410 $HSM_PARAM.actions |\
3411 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3413 [[ -z "$res" ]] || error "Some request have not been canceled"
3415 run_test 103 "Purge all requests"
3420 local f=$DIR/$tdir/$tfile
3421 local fid=$(create_empty_file "$f")
3423 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3424 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3425 $HSM_PARAM.actions |\
3426 grep $fid | cut -f16 -d=")
3428 [[ "$data1" == "$DATAHEX" ]] ||
3429 error "Data field in records is ($data1) and not ($DATAHEX)"
3433 run_test 104 "Copy tool data field"
3436 local max_requests=$(get_hsm_param max_requests)
3440 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3441 set_hsm_param max_requests 300
3444 for i in $(seq -w 1 10); do
3445 cp /etc/passwd $DIR/$tdir/$i
3446 $LFS hsm_archive $DIR/$tdir/$i
3448 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3449 $HSM_PARAM.actions |\
3450 grep WAITING | wc -l")
3454 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3455 $HSM_PARAM.actions |\
3456 grep WAITING | wc -l")
3459 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3460 error "Requests count after shutdown $reqcnt2 != "\
3461 "before shutdown $reqcnt1"
3463 run_test 105 "Restart of coordinator"
3466 # test needs a running copytool
3469 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3471 check_agent_registered $uuid
3473 search_copytools || error "No copytool found"
3476 wait_copytools || error "Copytool failed to stop"
3478 check_agent_unregistered $uuid
3481 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3482 check_agent_registered $uuid
3484 run_test 106 "Copytool register/unregister"
3487 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3489 # test needs a running copytool
3491 # create and archive file
3493 local f1=$DIR/$tdir/$tfile
3494 local fid=$(copy_file /etc/passwd $f1)
3495 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3496 wait_request_state $fid ARCHIVE SUCCEED
3497 # shutdown and restart MDS
3499 # check the copytool still gets messages from MDT
3500 local f2=$DIR/$tdir/2
3501 local fid=$(copy_file /etc/passwd $f2)
3502 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3503 # main check of this sanity: this request MUST succeed
3504 wait_request_state $fid ARCHIVE SUCCEED
3506 run_test 107 "Copytool re-register after MDS restart"
3508 policy_set_and_test()
3512 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3513 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3514 [[ "$policy" == "$target" ]] ||
3515 error "Wrong policy after '$change': '$policy' != '$target'"
3519 # to force default policy setting if error
3520 CDT_POLICY_HAD_CHANGED=true
3522 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3523 local default="NonBlockingRestore [NoRetryAction]"
3524 [[ "$policy" == "$default" ]] ||
3525 error "default policy has changed,"\
3526 " '$policy' != '$default' update the test"
3527 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3528 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3529 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3530 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3531 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3532 # useless bacause we know but safer for futur changes to use real value
3533 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3534 echo "Next set_param must failed"
3535 policy_set_and_test "wrong" "$policy"
3538 echo "Back to default policy"
3539 cdt_set_sanity_policy
3541 run_test 109 "Policy display/change"
3544 # test needs a running copytool
3549 copy2archive /etc/passwd $tdir/$tfile
3551 local f=$DIR/$tdir/$tfile
3552 copytool import $tdir/$tfile $f
3553 local fid=$(path2fid $f)
3555 cdt_set_non_blocking_restore
3560 wait_request_state $fid RESTORE SUCCEED
3561 cdt_clear_non_blocking_restore
3565 error "md5sum returns $st != 1, "\
3566 "should also perror ENODATA (No data available)"
3568 run_test 110a "Non blocking restore policy (import case)"
3571 # test needs a running copytool
3575 local f=$DIR/$tdir/$tfile
3576 local fid=$(copy_file /etc/passwd $f)
3577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3578 wait_request_state $fid ARCHIVE SUCCEED
3581 cdt_set_non_blocking_restore
3586 wait_request_state $fid RESTORE SUCCEED
3587 cdt_clear_non_blocking_restore
3591 error "md5sum returns $st != 1, "\
3592 "should also perror ENODATA (No data available)"
3594 run_test 110b "Non blocking restore policy (release case)"
3597 # test needs a running copytool
3601 copy2archive /etc/passwd $tdir/$tfile
3603 local f=$DIR/$tdir/$tfile
3605 copytool import $tdir/$tfile $f
3606 local fid=$(path2fid $f)
3610 copytool_remove_backend $fid
3613 wait_request_state $fid RESTORE FAILED
3620 [[ $st == 0 ]] || error "Restore does not failed"
3622 run_test 111a "No retry policy (import case), restore will error"\
3623 " (No such file or directory)"
3626 # test needs a running copytool
3630 local f=$DIR/$tdir/$tfile
3631 local fid=$(copy_file /etc/passwd $f)
3632 stack_trap cdt_clear_no_retry EXIT
3634 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3635 wait_request_state $fid ARCHIVE SUCCEED
3638 copytool_remove_backend $fid
3641 wait_request_state $fid RESTORE FAILED
3645 [[ $st == 0 ]] || error "Restore does not failed"
3647 run_test 111b "No retry policy (release case), restore will error"\
3648 " (No such file or directory)"
3651 # test needs a running copytool
3655 local f=$DIR/$tdir/$tfile
3656 local fid=$(copy_file /etc/passwd $f)
3658 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3659 local l=$($LFS hsm_action $f)
3661 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3664 wait_request_state $fid ARCHIVE SUCCEED
3667 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3669 run_test 112 "State of recorded request"
3672 local file1=$DIR/$tdir/$tfile
3673 local file2=$DIR2/$tdir/$tfile
3675 local fid=$(create_small_sync_file $file1)
3677 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3678 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3679 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3681 copytool setup -m "$MOUNT3"
3683 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3685 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3686 wait_request_state $fid ARCHIVE SUCCEED
3688 $LFS hsm_release $file1
3689 echo "Verifying released state: "
3690 check_hsm_flags $file1 "0x0000000d"
3692 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3695 kill -USR1 $MULTIPID
3700 local size1=$(stat -c "%s" $file1)
3701 local size2=$(stat -c "%s" $file2)
3703 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3705 run_test 113 "wrong stat after restore"
3708 local f=$DIR/$tdir/$tfile
3709 local fid=$(create_empty_file "$f")
3713 # Prevent archive from completing
3716 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3717 # wait archive to register at CDT
3718 wait_request_state $fid ARCHIVE STARTED
3720 # Cancel the archive
3721 $LFS hsm_cancel "$f"
3723 wait_request_state $fid ARCHIVE CANCELED
3726 wait_request_state $fid CANCEL SUCCEED
3728 run_test 200 "Register/Cancel archive"
3731 # test needs a running copytool
3734 local f=$DIR/$tdir/$tfile
3735 create_archive_file $tdir/$tfile
3736 copytool import $tdir/$tfile $f
3737 local fid=$(path2fid $f)
3739 # test with cdt on is made in test_222
3742 # wait restore to register at CDT
3743 wait_request_state $fid RESTORE WAITING
3746 wait_request_state $fid RESTORE CANCELED
3747 wait_request_state $fid CANCEL SUCCEED
3749 run_test 201 "Register/Cancel restore"
3752 local f=$DIR/$tdir/$tfile
3753 local fid=$(create_empty_file "$f")
3755 # test needs a running copytool
3758 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3759 wait_request_state $fid ARCHIVE SUCCEED
3763 # wait remove to register at CDT
3764 wait_request_state $fid REMOVE STARTED
3767 wait_request_state $fid REMOVE CANCELED
3769 run_test 202 "Register/Cancel remove"
3771 test_220A() { # was test_220
3772 # test needs a running copytool
3777 local f=$DIR/$tdir/$tfile
3778 local fid=$(copy_file /etc/passwd $f)
3782 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3783 wait_request_state $fid ARCHIVE SUCCEED
3785 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3786 error "The expected changelog was not emitted"
3788 run_test 220A "Changelog for archive"
3791 # test needs a running copytool
3796 local f=$DIR/$tdir/$tfile
3797 local fid=$(copy_file /etc/passwd $f)
3801 # block copytool operations to allow for HSM request to be
3802 # submitted and file be unlinked (CDT will find object removed)
3805 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3807 # wait request to reach CT
3808 wait_request_state $fid ARCHIVE STARTED
3814 wait_request_state $fid ARCHIVE FAILED
3817 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3818 error "The expected changelog was not emitted"
3820 run_test 220a "Changelog for failed archive"
3823 local f=$DIR/$tdir/$tfile
3824 local fid=$(create_empty_file "$f")
3829 # Prevent archive from completing
3831 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3832 wait_request_state $fid ARCHIVE STARTED
3835 wait_request_state $fid ARCHIVE CANCELED
3838 wait_request_state $fid CANCEL SUCCEED
3840 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3841 error "The expected changelog was not emitted"
3843 run_test 221 "Changelog for archive canceled"
3846 # test needs a running copytool
3850 copy2archive /etc/passwd $tdir/$tfile
3852 local f=$DIR/$tdir/$tfile
3853 copytool import $tdir/$tfile $f
3854 local fid=$(path2fid $f)
3859 wait_request_state $fid RESTORE SUCCEED
3861 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3862 error "The expected changelog was not emitted"
3864 run_test 222a "Changelog for explicit restore"
3867 # test needs a running copytool
3871 local f=$DIR/$tdir/$tfile
3872 local fid=$(copy_file /etc/passwd $f)
3875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3876 wait_request_state $fid ARCHIVE SUCCEED
3881 wait_request_state $fid RESTORE SUCCEED
3883 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3884 error "The expected changelog was not emitted"
3886 run_test 222b "Changelog for implicit restore"
3889 # test needs a running copytool
3893 copy2archive /etc/passwd $tdir/$tfile
3895 local f=$DIR/$tdir/$tfile
3896 copytool import $tdir/$tfile $f
3897 local fid=$(path2fid $f)
3901 # block copytool operations to allow for HSM request to be
3902 # submitted and file be unlinked (CDT will find object removed)
3907 # wait request to reach CT
3908 wait_request_state $fid RESTORE STARTED
3914 wait_request_state $fid RESTORE FAILED
3917 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3918 error "The expected changelog was not emitted"
3920 run_test 222c "Changelog for failed explicit restore"
3923 # test needs a running copytool
3927 local f=$DIR/$tdir/$tfile
3928 local fid=$(copy_file /etc/passwd $f)
3931 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3932 wait_request_state $fid ARCHIVE SUCCEED
3935 copytool_remove_backend $fid
3938 wait_request_state $fid RESTORE FAILED
3941 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3942 error "The expected changelog was not emitted"
3944 run_test 222d "Changelog for failed implicit restore"
3947 # test needs a running copytool
3950 local f=$DIR/$tdir/$tfile
3951 create_archive_file $tdir/$tfile
3955 copytool import $tdir/$tfile $f
3956 local fid=$(path2fid $f)
3959 wait_request_state $fid RESTORE STARTED
3961 wait_request_state $fid RESTORE CANCELED
3962 wait_request_state $fid CANCEL SUCCEED
3964 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3965 error "The expected changelog was not emitted"
3967 run_test 223a "Changelog for restore canceled (import case)"
3970 local f=$DIR/$tdir/$tfile
3971 local fid=$(create_empty_file "$f")
3976 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3977 wait_request_state $fid ARCHIVE SUCCEED
3980 # Prevent restore from completing
3983 wait_request_state $fid RESTORE STARTED
3986 wait_request_state $fid RESTORE CANCELED
3989 wait_request_state $fid CANCEL SUCCEED
3991 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3992 error "The expected changelog was not emitted"
3994 run_test 223b "Changelog for restore canceled (release case)"
3996 test_224A() { # was test_224
3997 # test needs a running copytool
4002 local f=$DIR/$tdir/$tfile
4003 local fid=$(copy_file /etc/passwd $f)
4006 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4007 wait_request_state $fid ARCHIVE SUCCEED
4010 wait_request_state $fid REMOVE SUCCEED
4012 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4013 error "The expected changelog was not emitted"
4015 run_test 224A "Changelog for remove"
4018 # test needs a running copytool
4023 local f=$DIR/$tdir/$tfile
4024 local fid=$(copy_file /etc/passwd $f)
4027 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4028 wait_request_state $fid ARCHIVE SUCCEED
4030 copytool_remove_backend $fid
4032 # block copytool operations to allow for HSM request to be
4033 # submitted and file be unlinked (CDT will find object removed)
4038 # wait for request to reach CT
4039 wait_request_state $fid REMOVE STARTED
4045 wait_request_state $fid REMOVE FAILED
4047 # HE_REMOVE|ENOENT=0x202
4048 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4049 error "The expected changelog was not emitted"
4051 run_test 224a "Changelog for failed remove"
4054 # test is not usable because remove request is too fast
4055 # so it is always finished before cancel can be done ...
4056 echo "Test disabled"
4059 # test needs a running copytool
4062 local f=$DIR/$tdir/$tfile
4063 local fid=$(create_empty_file "$f")
4066 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4067 wait_request_state $fid ARCHIVE SUCCEED
4069 # Prevent restore from completing
4074 wait_request_state $fid REMOVE CANCELED
4077 wait_request_state $fid CANCEL SUCCEED
4079 changelog_find -type HSM -target-fid $fid -flags 0x27d
4080 error "The expected changelog was not emitted"
4082 run_test 225 "Changelog for remove canceled"
4085 # test needs a running copytool
4090 local f1=$DIR/$tdir/$tfile-1
4091 local f2=$DIR/$tdir/$tfile-2
4092 local f3=$DIR/$tdir/$tfile-3
4093 local fid1=$(copy_file /etc/passwd $f1)
4094 local fid2=$(copy_file /etc/passwd $f2)
4095 copy_file /etc/passwd $f3
4098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4099 wait_request_state $fid1 ARCHIVE SUCCEED
4101 $LFS hsm_archive $f2
4102 wait_request_state $fid2 ARCHIVE SUCCEED
4104 rm $f1 || error "rm $f1 failed"
4107 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4108 error "The expected changelog was not emitted"
4110 mv $f3 $f2 || error "mv $f3 $f2 failed"
4112 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4113 error "The expected changelog was not emitted"
4115 run_test 226 "changelog for last rm/mv with exiting archive"
4117 # This is just a utility function to clarify what test_227 does
4122 "$LFS" "$action" --$flag "$file" ||
4123 error "Cannot ${action#hsm_} $flag on '$file'"
4125 # Only one changelog should be produced
4126 local entries="$(changelog_find -type HSM -target-fid $fid)"
4127 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4128 error "lfs $action --$flag '$file' produced more than one" \
4131 # Parse the last changelog record
4132 local entry="$(tail -n 1 <<< "$entries")"
4133 eval local -A changelog=$(changelog2array $entry)
4135 # Also check the flags match what is expected
4136 [[ ${changelog[flags]} == $target ]] ||
4137 error "Changelog flag is '${changelog[flags]}', not $target"
4141 local file="$DIR/$tdir/$tfile"
4142 local fid=$(create_empty_file "$file")
4147 for flag in norelease noarchive exists archived lost; do
4148 if [ "$flag" == lost ]; then
4149 # The flag "lost" only works on an archived file
4150 "$LFS" hsm_set --archived "$file"
4154 action="hsm_set" __test_227
4155 action="hsm_clear" __test_227
4158 run_test 227 "changelog when explicit setting of HSM flags"
4161 # test needs a running copytool
4164 local fid=$(create_small_sync_file $DIR/$tfile)
4165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4166 wait_request_state $fid ARCHIVE SUCCEED
4168 $LFS hsm_release $DIR/$tfile
4169 check_hsm_flags $DIR/$tfile "0x0000000d"
4171 filefrag $DIR/$tfile | grep " 1 extent found" ||
4172 error "filefrag on released file must return only one extent"
4174 # only newer versions of cp detect sparse files by stat/FIEMAP
4176 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4177 error "copying $DIR/$tfile"
4178 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4180 $LFS hsm_release $DIR/$tfile
4181 check_hsm_flags $DIR/$tfile "0x0000000d"
4183 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4185 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4187 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4188 error "comparing untarred $DIR/$tfile"
4190 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4191 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4193 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4196 local file="$DIR/$tdir/$tfile"
4198 # set max_requests to allow one request of each type to be started (3)
4200 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4201 set_hsm_param max_requests 3
4204 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4205 set_hsm_param loop_period 1
4207 # send 1 requests of each kind twice
4210 for action in archive restore remove; do
4211 local filepath="$file"-to-$action
4212 local fid=$(create_empty_file "$filepath")
4213 local fid2=$(create_empty_file "$filepath".bis)
4215 if [ "$action" != archive ]; then
4216 "$LFS" hsm_archive "$filepath"
4217 wait_request_state $fid ARCHIVE SUCCEED
4218 "$LFS" hsm_archive "$filepath".bis
4219 wait_request_state $fid2 ARCHIVE SUCCEED
4221 if [ "$action" == restore ]; then
4222 "$LFS" hsm_release "$filepath"
4223 "$LFS" hsm_release "$filepath".bis
4227 # suspend the copytool to prevent requests from completing
4228 stack_trap "copytool_continue" EXIT
4231 # send `max_requests' requests (one of each kind)
4232 for action in archive restore remove; do
4233 filepath="$file"-to-$action
4234 "$LFS" hsm_${action} "$filepath"
4235 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4238 # send another batch of requests
4239 for action in archive restore remove; do
4240 "$LFS" hsm_${action} "$file-to-$action".bis
4242 # wait for `loop_period' seconds to make sure the coordinator has time
4243 # to register those, even though it should not
4246 # only the first batch of request should be started
4248 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4252 error "expected 3 STARTED requests, found $count"
4254 run_test 250 "Coordinator max request"
4257 local f=$DIR/$tdir/$tfile
4258 local fid=$(create_empty_file "$f")
4261 # to have a short test
4262 local old_to=$(get_hsm_param active_request_timeout)
4263 set_hsm_param active_request_timeout 1
4264 # to be sure the cdt will wake up frequently so
4265 # it will be able to cancel the "old" request
4266 local old_loop=$(get_hsm_param loop_period)
4267 set_hsm_param loop_period 1
4272 # Prevent archive from completing
4274 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4275 wait_request_state $fid ARCHIVE STARTED
4277 # Let the request timeout
4278 wait_request_state $fid ARCHIVE CANCELED
4280 set_hsm_param active_request_timeout $old_to
4281 set_hsm_param loop_period $old_loop
4283 run_test 251 "Coordinator request timeout"
4286 local f=$DIR/$tdir/$tfile
4287 local fid=$(create_empty_file "$f")
4289 # to have a short test
4290 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4291 set_hsm_param loop_period 1
4295 # Prevent archive from completing
4297 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4298 wait_request_state $fid ARCHIVE STARTED
4301 stack_trap "set_hsm_param active_request_timeout \
4302 $(get_hsm_param active_request_timeout)" EXIT
4303 set_hsm_param active_request_timeout 1
4305 wait_request_state $fid ARCHIVE CANCELED
4308 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4312 # test needs a running copytool
4316 local f=$DIR/$tdir/$tfile
4318 dd if=/dev/zero of=$f bs=1MB count=10
4319 local fid=$(path2fid $f)
4321 $LFS hsm_archive $f || error "could not archive file"
4322 wait_request_state $fid ARCHIVE SUCCEED
4324 # clear locks to discard inode data
4325 cancel_lru_locks osc
4327 #define OBD_FAIL_MDC_MERGE 0x807
4328 $LCTL set_param fail_loc=0x807
4330 #expect error here, instead of release with wrong size
4333 if ((rc == 0)); then
4334 file_size=$(stat -c '%s' $f)
4335 if ((file_size != 10485760)); then
4336 error "Wrong file size after hsm_release"
4339 echo "could not release file"
4342 run_test 253 "Check for wrong file size after release"
4346 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4347 skip "need MDS version at least 2.10.56"
4349 # Check that the counters are initialized to 0
4351 for request_type in archive restore remove; do
4352 count="$(get_hsm_param ${request_type}_count)" ||
4353 error "Reading ${request_type}_count failed with $?"
4355 [ "$count" -eq 0 ] ||
4356 error "Expected ${request_type}_count to be " \
4360 run_test 254a "Request counters are initialized to zero"
4364 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4365 skip "need MDS version at least 2.10.56"
4367 # The number of request to launch (at least 32)
4368 local request_count=$((RANDOM % 32 + 32))
4369 printf "Will launch %i requests of each type\n" "$request_count"
4371 # Launch a copytool to process requests
4374 # Set hsm.max_requests to allow starting all requests at the same time
4376 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4377 set_hsm_param max_requests "$request_count"
4381 for request_type in archive restore remove; do
4382 printf "Checking %s requests\n" "${request_type}"
4383 # Suspend the copytool to give us time to read the proc files
4386 for ((i = 0; i < $request_count; i++)); do
4387 case $request_type in
4389 create_empty_file "$DIR/$tdir/$tfile-$i" \
4393 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4396 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4399 # Give the coordinator 10 seconds to start every request
4401 while get_hsm_param actions | grep -q WAITING; do
4404 [ $timeout -gt 0 ] ||
4405 error "${request_type^} requests took too " \
4409 count="$(get_hsm_param ${request_type}_count)"
4410 [ "$count" -eq "$request_count" ] ||
4411 error "Expected '$request_count' (!= '$count') " \
4412 "active $request_type requests"
4414 # Let the copytool process the requests
4416 # Give it 10 seconds maximum
4418 while get_hsm_param actions | grep -q STARTED; do
4421 [ $timeout -gt 0 ] ||
4422 error "${request_type^} requests took too " \
4426 count="$(get_hsm_param ${request_type}_count)"
4427 [ "$count" -eq 0 ] ||
4428 error "Expected 0 (!= '$count') " \
4429 "active $request_type requests"
4432 run_test 254b "Request counters are correctly incremented and decremented"
4436 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4437 skip "Need MDS version at least 2.12.0"
4439 local file="$DIR/$tdir/$tfile"
4440 local fid=$(create_empty_file "$file")
4442 # How do you make sure the coordinator has consumed any outstanding
4443 # event, without triggering an event yourself?
4445 # You wait for a request to disappear from the coordinator's llog.
4447 # Warning: the setup represents 90% of this test
4449 # Create and process an HSM request
4451 "$LFS" hsm_archive "$file"
4452 wait_request_state $fid ARCHIVE SUCCEED
4455 wait_copytools || error "failed to stop copytools"
4457 # Launch a new HSM request
4459 create_empty_file "$file"
4460 "$LFS" hsm_archive "$file"
4464 # Have the completed request be removed as soon as the cdt wakes up
4465 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4466 set_hsm_param grace_delay 1
4467 # (Hopefully, time on the MDS will behave nicely)
4468 do_facet $SINGLEMDS sleep 2 &
4470 # Increase `loop_period' as a mean to prevent the coordinator from
4471 # waking itself up to do some housekeeping.
4472 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4473 set_hsm_param loop_period 1000
4475 wait $! || error "waiting failed"
4477 wait_request_state $fid ARCHIVE ""
4478 # The coordinator will not wake up on its own for ~`loop_period' secs...
4480 # ... Unless a copytool registers. Now the real test begins
4482 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4484 run_test 255 "Copytool registration wakes the coordinator up"
4486 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4487 # break in the future because of that.
4490 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4491 skip "need MDS version 2.11.56 or later"
4493 local -a files=("$DIR/$tdir/$tfile".{0..15})
4496 for file in "${files[@]}"; do
4497 create_small_file "$file"
4500 # Set a few hsm parameters
4502 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4503 set_hsm_param loop_period 1
4505 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4506 set_hsm_param max_requests 3
4510 "$LFS" hsm_archive "${files[0]}"
4511 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4512 "$LFS" hsm_release "${files[0]}"
4516 wait_copytools || error "copytools failed to stop"
4518 # Send several archive requests
4519 for file in "${files[@]:1}"; do
4520 "$LFS" hsm_archive "$file"
4523 # Send one restore request
4524 "$LFS" hsm_restore "${files[0]}"
4529 # Wait for all the requests to complete
4530 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4531 for file in "${files[@]:1}"; do
4532 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4535 # Collect the actions in the order in which the copytool processed them
4537 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4538 "$(copytool_logfile "$SINGLEAGT")")
4541 printf '%s\n' "${actions[@]}"
4544 for action in "${actions[@]:0:3}"; do
4545 [ "$action" == RESTORE ] && return
4548 error "Too many ARCHIVE requests were run before the RESTORE request"
4550 run_test 260a "Restore request have priority over other requests"
4552 # This test is very much tied to the implementation of the current priorisation
4553 # mechanism in the coordinator. It might not make sense to keep it in the future
4556 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4557 skip "need MDS version 2.11.56 or later"
4559 local -a files=("$DIR/$tdir/$tfile".{0..15})
4562 for file in "${files[@]}"; do
4563 create_small_file "$file"
4566 # Set a few hsm parameters
4568 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4569 set_hsm_param loop_period 1
4571 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4572 set_hsm_param max_requests 3
4575 copytool setup --archive-id 2
4576 "$LFS" hsm_archive --archive 2 "${files[0]}"
4577 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4578 "$LFS" hsm_release "${files[0]}"
4582 wait_copytools || error "copytools failed to stop"
4584 # Send several archive requests
4585 for file in "${files[@]:1}"; do
4586 "$LFS" hsm_archive "$file"
4589 # Send one restore request
4590 "$LFS" hsm_restore "${files[0]}"
4594 copytool setup --archive-id 2
4596 # Wait for all the requests to complete
4597 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4598 for file in "${files[@]:1}"; do
4599 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4602 # Collect the actions in the order in which the copytool processed them
4604 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4605 "$(copytool_logfile "$SINGLEAGT")")
4608 printf '%s\n' "${actions[@]}"
4611 for action in "${actions[@]:0:3}"; do
4612 [ "$action" == RESTORE ] && return
4615 error "Too many ARCHIVE requests were run before the RESTORE request"
4617 run_test 260b "Restore request have priority over other requests"
4619 # This test is very much tied to the implementation of the current priorisation
4620 # mechanism in the coordinator. It might not make sense to keep it in the future
4623 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4624 skip "Need MDS version at least 2.12.0"
4626 local -a files=("$DIR/$tdir/$tfile".{0..15})
4629 for file in "${files[@]}"; do
4630 create_small_file "$file"
4633 # Set a few hsm parameters
4635 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4636 set_hsm_param loop_period 1000
4638 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4639 set_hsm_param max_requests 3
4642 copytool setup --archive-id 2
4643 "$LFS" hsm_archive --archive 2 "${files[0]}"
4644 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4645 "$LFS" hsm_release "${files[0]}"
4649 wait_copytools || error "copytools failed to stop"
4651 # Force the next coordinator run to do housekeeping
4655 "$LFS" hsm_archive "${files[1]}"
4659 copytool setup --archive-id 2
4661 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4662 # The coordinator just did a housekeeping run it won't do another one
4663 # for around `loop_period' seconds => requests will not be reordered
4664 # if it costs too much (ie. when the coordinator has to discard a whole
4667 # Send several archive requests
4668 for file in "${files[@]:2}"; do
4669 "$LFS" hsm_archive "$file"
4672 # Send one restore request
4673 "$LFS" hsm_restore "${files[0]}"
4675 # Wait for all the requests to complete
4676 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4677 for file in "${files[@]:2}"; do
4678 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4681 # Collect the actions in the order in which the copytool processed them
4683 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4684 "$(copytool_logfile "$SINGLEAGT")")
4687 printf '%s\n' "${actions[@]}"
4690 for action in "${actions[@]:0:3}"; do
4691 [ "$action" == RESTORE ] &&
4692 error "Restore requests should not be prioritised" \
4693 "unless the coordinator is doing housekeeping"
4697 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4700 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4702 # the only way to test ondisk conf is to restart MDS ...
4703 echo "Stop coordinator and remove coordinator state at mount"
4706 # clean on disk conf set by default
4707 cdt_clear_mount_state
4708 cdt_check_state stopped
4710 # check cdt still off after umount/remount
4712 cdt_check_state stopped
4714 echo "Set coordinator start at mount, and start coordinator"
4715 cdt_set_mount_state enabled
4718 cdt_check_state enabled
4720 # check cdt still on after umount/remount
4722 cdt_check_state enabled
4724 # we are back to original state (cdt started at mount)
4726 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4729 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4731 local ai=$(get_hsm_param default_archive_id)
4732 local new=$((ai + 1))
4734 set_hsm_param default_archive_id $new -P
4736 local res=$(get_hsm_param default_archive_id)
4739 set_hsm_param default_archive_id "" "-P -d"
4741 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4743 run_test 301 "HSM tunnable are persistent"
4746 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4748 local ai=$(get_hsm_param default_archive_id)
4749 local new=$((ai + 1))
4754 set_hsm_param default_archive_id $new -P
4757 for mdtno in $(seq 1 $MDSCOUNT); do
4762 cdt_check_state enabled
4764 local res=$(get_hsm_param default_archive_id)
4767 set_hsm_param default_archive_id "" "-P -d"
4769 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4771 run_test 302 "HSM tunnable are persistent when CDT is off"
4774 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4780 local dir_mdt0=$DIR/$tdir/mdt0
4781 local dir_mdt1=$DIR/$tdir/mdt1
4783 # create 1 dir per MDT
4784 stack_trap "rm -rf $dir_mdt0" EXIT
4785 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4786 stack_trap "rm -rf $dir_mdt1" EXIT
4787 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4789 # create 1 file in each MDT
4790 local fid1=$(create_small_file $dir_mdt0/$tfile)
4791 local fid2=$(create_small_file $dir_mdt1/$tfile)
4793 # check that hsm request on mdt0 is sent to the right MDS
4794 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4795 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4796 echo "archive successful on mdt0"
4798 # check that hsm request on mdt1 is sent to the right MDS
4799 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4800 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4801 echo "archive successful on mdt1"
4803 run_test 400 "Single request is sent to the right MDT"
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 compound requests are shunt to the rights MDTs
4826 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4827 error "lfs hsm_archive"
4828 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4829 echo "archive successful on mdt0"
4830 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4831 echo "archive successful on mdt1"
4833 run_test 401 "Compound requests split and sent to their respective MDTs"
4835 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4840 local node=$(facet_active_host $facet)
4842 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4843 awk '{print $4}'); do
4844 echo "$3 $mdc on $node"
4845 do_facet $facet "$LCTL --device $mdc $state" || return 1
4850 # deactivate all mdc on agent1
4851 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4853 copytool setup --no-fail
4855 check_agent_unregistered "uuid" # match any agent
4857 # no expected running copytool
4858 search_copytools $agent && error "Copytool start should have failed"
4861 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4863 run_test 402a "Copytool start fails if all MDTs are inactive"
4870 local f=$DIR/$tdir/$tfile
4871 touch $f || error "touch $f failed"
4872 local fid=$(path2fid $f)
4874 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4875 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4876 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4878 # give time for CDT to send request and to keep it for retry
4879 wait_for_loop_period
4881 wait_request_state $fid ARCHIVE WAITING
4883 do_facet $SINGLEAGT lctl set_param fail_loc=0
4885 # request should succeed now
4886 wait_request_state $fid ARCHIVE SUCCEED
4888 run_test 402b "CDT must retry request upon slow start of CT"
4891 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4893 local agent=$(facet_active_host $SINGLEAGT)
4895 # deactivate all mdc for MDT0001
4896 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4899 local uuid=$(get_agent_uuid $agent)
4900 # check the agent is registered on MDT0000, and not on MDT0001
4901 check_agent_registered_by_mdt $uuid 0
4902 check_agent_unregistered_by_mdt $uuid 1
4904 # check running copytool process
4905 search_copytools $agent || error "No running copytools on $agent"
4907 # reactivate all mdc for MDT0001
4908 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4910 # make sure the copytool is now registered to all MDTs
4911 check_agent_registered $uuid
4913 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4916 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4920 # create files on both MDT0000 and MDT0001
4923 local dir_mdt0=$DIR/$tdir/mdt0
4924 stack_trap "rm -rf $dir_mdt0" EXIT
4925 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4927 # create 1 file on mdt0
4928 local fid1=$(create_small_file $dir_mdt0/$tfile)
4930 # deactivate all mdc for MDT0001
4931 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4933 # send an HSM request for files in MDT0000
4934 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4936 # check for completion of files in MDT0000
4937 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4938 echo "archive successful on mdt0"
4940 # reactivate all mdc for MDT0001
4941 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4943 run_test 404 "Inactive MDT does not block requests for active MDTs"
4946 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4952 local striped_dir=$DIR/$tdir/striped_dir
4954 # create striped dir on all of MDTs
4955 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4957 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4958 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4959 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4960 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4962 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4963 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4964 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4965 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4967 # check that compound requests are shunt to the rights MDTs
4968 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4969 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4970 error "lfs hsm_archive"
4972 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4973 echo "archive successful on $fid1"
4974 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4975 echo "archive successful on $fid2"
4976 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4977 echo "archive successful on $fid3"
4978 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4979 echo "archive successful on $fid4"
4981 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4982 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4983 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4984 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4986 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4987 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4988 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4989 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4991 run_test 405 "archive and release under striped directory"
4994 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4996 [ $MDS_VERSION_CODE -lt $(version_code 2.7.64) ] &&
4997 skip "need MDS version at least 2.7.64"
5002 fid=$(create_small_file $DIR/$tdir/$tfile)
5007 $LFS hsm_archive $DIR/$tdir/$tfile
5008 wait_request_state "$fid" ARCHIVE SUCCEED
5009 $LFS hsm_release $DIR/$tdir/$tfile
5011 # Should migrate $tdir but not $tfile.
5012 $LFS migrate -m1 $DIR/$tdir &&
5013 error "migrating HSM an archived file should fail"
5015 $LFS hsm_restore $DIR/$tdir/$tfile
5016 wait_request_state "$fid" RESTORE SUCCEED
5018 $LFS hsm_remove $DIR/$tdir/$tfile
5019 wait_request_state "$fid" REMOVE SUCCEED
5021 cat $DIR/$tdir/$tfile > /dev/null ||
5022 error "cannot read $DIR/$tdir/$tfile"
5024 $LFS migrate -m1 $DIR/$tdir ||
5025 error "cannot complete migration after HSM remove"
5027 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5028 if ((mdt_index != 1)); then
5029 error "expected MDT index 1, got $mdt_index"
5032 # Refresh fid after migration.
5033 fid=$(path2fid $DIR/$tdir/$tfile)
5036 $LFS hsm_archive $DIR/$tdir/$tfile
5037 wait_request_state "$fid" ARCHIVE SUCCEED 1
5039 lctl set_param debug=+trace
5040 $LFS hsm_release $DIR/$tdir/$tfile ||
5041 error "cannot release $DIR/$tdir/$tfile"
5043 $LFS hsm_restore $DIR/$tdir/$tfile
5044 wait_request_state "$fid" RESTORE SUCCEED 1
5046 cat $DIR/$tdir/$tfile > /dev/null ||
5047 error "cannot read $DIR/$tdir/$tfile"
5049 run_test 406 "attempting to migrate HSM archived files is safe"
5052 local f=$DIR/$tdir/$tfile
5053 local f2=$DIR2/$tdir/$tfile
5054 local fid=$(create_empty_file "$f")
5058 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5059 wait_request_state $fid ARCHIVE SUCCEED
5062 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5063 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5065 # Prevent restore from completing
5069 # 1st request holds layout lock while appropriate
5070 # RESTORE record is still not added to llog
5074 # after umount hsm_actions->O/x/x log shouldn't have
5075 # double RESTORE records like below
5076 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5077 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5079 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5083 wait_request_state $fid RESTORE SUCCEED
5085 run_test 407 "Check for double RESTORE records in llog"
5089 [ $MDS_VERSION_CODE -lt $(version_code 2.6.92) ] &&
5090 skip "HSM migrate is not supported"
5092 test_mkdir -p $DIR/$tdir
5094 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5095 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5097 llapi_hsm_test -d $DIR/$tdir -b ||
5098 error "One llapi HSM test failed"
5100 llapi_hsm_test -d $DIR/$tdir ||
5101 error "One llapi HSM test failed"
5104 run_test 500 "various LLAPI HSM tests"
5107 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5108 skip "need MDS version at least 2.10.58"
5112 local f=$DIR/$tdir/$tfile
5115 # set changelog_mask to ALL
5116 changelog_chmask "ALL"
5118 chmod 777 $DIR/$tdir
5119 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5120 local fid=$(path2fid $f)
5123 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5124 -gid "$RUNAS_GID") ||
5125 error "No matching CREAT entry"
5127 # Parse the changelog
5128 eval local -A changelog=$(changelog2array $entry)
5129 local nid="${changelog[nid]}"
5132 echo "Got NID '$nid'"
5133 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5134 error "nid '$nid' does not match any client NID:" \
5137 run_test 600 "Changelog fields 'u=' and 'nid='"
5140 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5141 skip "need MDS version at least 2.10.58"
5145 local f=$DIR/$tdir/$tfile
5148 # set changelog_mask to ALL
5149 changelog_chmask "ALL"
5151 touch $f || error "touch $f failed"
5152 local fid=$(path2fid $f)
5155 cat $f || error "cat $f failed"
5157 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5158 error "No matching OPEN entry"
5160 run_test 601 "OPEN Changelog entry"
5163 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5164 skip "need MDS version at least 2.10.58"
5168 local f=$DIR/$tdir/$tfile
5171 # set changelog_mask to ALL
5172 changelog_chmask "ALL"
5174 touch $f || error "touch $f failed"
5175 local fid=$(path2fid $f)
5178 cat $f || error "cat $f failed"
5180 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5184 echo f > $f || error "write $f failed"
5187 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5189 # remove OPEN from changelog_mask
5190 changelog_chmask "-OPEN"
5194 cat $f || error "cat $f failed"
5197 changelog_find -type CLOSE -target-fid $fid &&
5198 error "There should be no CLOSE entry"
5202 echo f > $f || error "write $f failed"
5205 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5207 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5210 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5211 skip "need MDS version at least 2.10.58"
5215 local f=$DIR/$tdir/$tfile
5218 # set changelog_mask to ALL
5219 changelog_chmask "ALL"
5221 touch $f || error "touch $f failed"
5222 local fid=$(path2fid $f)
5224 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5227 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5229 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5230 error "No matching GXATR entry"
5232 run_test 603 "GETXATTR Changelog entry"
5235 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5236 skip "need MDS version at least 2.10.58"
5240 local f=$DIR/$tdir/$tfile
5241 local f2=$DIR2/$tdir/$tfile
5242 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5244 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5245 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5246 do_facet mds1 lctl set_param "$procname=20"
5250 # set changelog_mask to ALL
5251 changelog_chmask "ALL"
5253 touch $f || error "touch $f failed"
5254 local fid=$(path2fid $f)
5260 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5264 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5265 -gid "$RUNAS_GID" -mode "r--") ||
5266 error "No matching NOPEN entry"
5268 # Parse the changelog
5269 eval local -A changelog=$(changelog2array $entry)
5270 local nid="${changelog[nid]}"
5273 echo "Got NID '$nid'"
5274 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5275 error "nid '$nid' does not match any client NID:" \
5280 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5283 changelog_find -type NOPEN -target-fid $fid &&
5284 error "There should be no NOPEN entry"
5286 # Sleep for `changelog_deniednext` seconds
5291 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5294 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5295 -gid "$RUNAS_GID" -mode "r--") ||
5296 error "No matching NOPEN entry"
5298 # Parse the changelog
5299 eval local -A changelog=$(changelog2array $entry)
5300 local nid="${changelog[nid]}"
5303 echo "Got NID '$nid'"
5304 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5305 error "nid '$nid' does not match any client NID:" \
5308 run_test 604 "NOPEN Changelog entry"
5311 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5312 skip "need MDS version at least 2.10.58"
5316 local f=$DIR/$tdir/$tfile
5317 local f2=$DIR2/$tdir/$tfile
5320 # set changelog_mask to ALL
5321 changelog_chmask "ALL"
5323 touch $f || error "touch $f failed"
5324 local fid=$(path2fid $f)
5328 exec 3<> $f || error "open $f failed"
5332 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5336 exec 4<> $f || error "open $f failed"
5339 changelog_find -type OPEN -target-fid $fid &&
5340 error "There should be no OPEN entry"
5342 exec 4>&- || error "close $f failed"
5345 changelog_find -type CLOSE -target-fid $fid &&
5346 error "There should be no CLOSE entry"
5350 # access in rw, so different access mode should generate entries
5351 cat $f || error "cat $f failed"
5354 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5356 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5360 # same access as first one, should not generate new entries
5361 exec 4<> $f || error "open $f failed"
5364 changelog_find -type OPEN -target-fid $fid &&
5365 error "There should be no OPEN entry"
5367 exec 4>&- || error "close $f failed"
5370 changelog_find -type CLOSE -target-fid $fid &&
5371 error "There should be no CLOSE entry"
5375 # access by different user should generate new entries
5376 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5379 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5381 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5385 exec 3>&- || error "close $f failed"
5388 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5390 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5393 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5394 skip "need MDS version at least 2.10.58"
5396 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5397 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5398 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5399 skip_env "missing llog_reader" && return
5400 local fstype=$(facet_fstype mds1)
5404 local f=$DIR/$tdir/$tfile
5407 # set changelog_mask to ALL
5408 changelog_chmask "ALL"
5410 chmod 777 $DIR/$tdir
5411 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5412 local fid=$(path2fid $f)
5413 rm $f || error "rm $f failed"
5415 local mntpt=$(facet_mntpt mds1)
5419 #remount mds1 as ldiskfs or zfs type
5420 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5421 stop mds1 || error "stop mds1 failed"
5422 mount_fstype mds1 || error "remount mds1 failed"
5424 for ((i = 0; i < 1; i++)); do
5425 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5426 local cat_file=$(do_facet mds1 $llog_reader \
5427 $mntpt/changelog_catalog | awk \
5428 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5429 [ -n "$cat_file" ] || error "no catalog file"
5431 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5432 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5433 [ -n "$entry" ] || error "no CREAT entry"
5436 local uidgid=$(echo $entry |
5437 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5438 [ -n "$uidgid" ] || error "uidgid is empty"
5439 echo "Got UID/GID $uidgid"
5440 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5441 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5442 local nid=$(echo $entry |
5443 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5444 [ -n "$nid" ] || error "nid is empty"
5446 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5447 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5449 run_test 606 "llog_reader groks changelog fields"
5452 check_and_cleanup_lustre