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"
669 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
670 error "failed to create file"
671 local fid=$(path2fid $f)
676 $LFS hsm_archive $f || error "could not archive file"
677 wait_request_state $fid ARCHIVE SUCCEED
680 $LFS hsm_release $f || error "could not release file"
681 echo "verify released state: "
682 check_hsm_flags $f "0x0000000d" && echo "pass"
685 $LFS hsm_restore $f || error "could not restore file"
686 wait_request_state $fid RESTORE SUCCEED
687 echo "verify restored state: "
688 check_hsm_flags $f "0x00000009" && echo "pass"
693 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
694 error "failed to set default stripe"
695 local f=$DIR/$tdir/$tfile
699 run_test 1b "Archive, Release and Restore composite file"
705 local f=$DIR/$tdir/$tfile
708 # Test whether we can set the maximum archive number.
709 local LOCAL_HSM_ARCHIVE_NUMBER=32
710 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
711 error "root could not change hsm flags"
712 check_hsm_flags_user $f "0x00000001"
713 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
714 local st=$(get_hsm_archive_id $f)
715 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
716 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
718 # Test whether setting archive number 0 results in no change.
719 $LFS hsm_set --exists --archive-id 0 $f ||
720 error "root could not change hsm flags"
721 check_hsm_flags_user $f "0x00000001"
722 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
723 st=$(get_hsm_archive_id $f)
724 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
725 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
727 LOCAL_HSM_ARCHIVE_NUMBER=33
728 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
729 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
730 # lustre in the new version supports unlimited archiveID.
731 # Test whether setting archive number > 32 is supported
732 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
733 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
734 check_hsm_flags_user $f "0x00000001"
736 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
737 st=$(get_hsm_archive_id $f)
738 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
739 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
741 # old client or old mds can only support at most 32 archiveID
742 # test whether setting archive number > 32 results in error.
743 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
744 error "bitmap archive number is larger than 32"
745 check_hsm_flags_user $f "0x00000001"
748 # Test whether setting archive number 16 and archived flag.
749 LOCAL_HSM_ARCHIVE_NUMBER=16
750 $LFS hsm_set --exists --archived \
751 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
752 error "root could not change hsm flags"
753 check_hsm_flags_user $f "0x00000009"
754 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
755 st=$(get_hsm_archive_id $f)
756 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
757 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
759 run_test 1c "Check setting archive-id in lfs hsm_set"
762 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
763 skip "need MDS version at least 2.10.59"
766 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
767 error "failed to set default stripe"
768 local f=$DIR/$tdir/$tfile
772 run_test 1d "Archive, Release and Restore DoM file"
775 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
776 skip "skipped for lustre < $SEL_VER"
779 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
780 error "failed to set default stripe"
781 local comp_file=$DIR/$tdir/$tfile
783 test_1bde_base $comp_file
785 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
786 local found=$($LFS find $flg_opts $comp_file | wc -l)
787 [ $found -eq 1 ] || error "1st component not found"
789 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
790 found=$($LFS find $flg_opts $comp_file | wc -l)
791 [ $found -eq 1 ] || error "2nd component not found"
793 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
794 found=$($LFS find $flg_opts $comp_file | wc -l)
795 [ $found -eq 1 ] || error "3rd component not found"
797 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
798 found=$($LFS find $flg_opts $comp_file | wc -l)
799 [ $found -eq 1 ] || error "4th component not found"
801 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
802 found=$($LFS find $flg_opts $comp_file | wc -l)
803 [ $found -eq 1 ] || error "5th component not found"
805 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
806 found=$($LFS find $flg_opts $comp_file | wc -l)
807 [ $found -eq 1 ] || error "6th component not found"
809 sel_layout_sanity $comp_file 6
811 run_test 1e "Archive, Release and Restore SEL file"
814 local f=$DIR/$tdir/$tfile
816 create_empty_file "$f"
817 # New files are not dirty
818 check_hsm_flags $f "0x00000000"
820 # For test, we simulate an archived file.
821 $LFS hsm_set --exists $f || error "user could not change hsm flags"
822 check_hsm_flags $f "0x00000001"
824 # chmod do not put the file dirty
825 chmod 600 $f || error "could not chmod test file"
826 check_hsm_flags $f "0x00000001"
828 # chown do not put the file dirty
829 chown $RUNAS_ID $f || error "could not chown test file"
830 check_hsm_flags $f "0x00000001"
832 # truncate put the file dirty
833 $TRUNCATE $f 1 || error "could not truncate test file"
834 check_hsm_flags $f "0x00000003"
836 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
837 check_hsm_flags $f "0x00000001"
839 run_test 2 "Check file dirtyness when doing setattr"
845 # New files are not dirty
847 check_hsm_flags $f "0x00000000"
849 # For test, we simulate an archived file.
850 $LFS hsm_set --exists $f ||
851 error "user could not change hsm flags"
852 check_hsm_flags $f "0x00000001"
854 # Reading a file, does not set dirty
855 cat $f > /dev/null || error "could not read file"
856 check_hsm_flags $f "0x00000001"
858 # Open for write without modifying data, does not set dirty
859 openfile -f O_WRONLY $f || error "could not open test file"
860 check_hsm_flags $f "0x00000001"
862 # Append to a file sets it dirty
863 cp -p /etc/passwd $f.append || error "could not create file"
864 $LFS hsm_set --exists $f.append ||
865 error "user could not change hsm flags"
866 dd if=/etc/passwd of=$f.append bs=1 count=3\
867 conv=notrunc oflag=append status=noxfer ||
868 file_creation_failure dd $f.append $?
869 check_hsm_flags $f.append "0x00000003"
871 # Modify a file sets it dirty
872 cp -p /etc/passwd $f.modify || error "could not create file"
873 $LFS hsm_set --exists $f.modify ||
874 error "user could not change hsm flags"
875 dd if=/dev/zero of=$f.modify bs=1 count=3\
876 conv=notrunc status=noxfer ||
877 file_creation_failure dd $f.modify $?
878 check_hsm_flags $f.modify "0x00000003"
880 # Open O_TRUNC sets dirty
881 cp -p /etc/passwd $f.trunc || error "could not create file"
882 $LFS hsm_set --exists $f.trunc ||
883 error "user could not change hsm flags"
884 cp /etc/group $f.trunc || error "could not override a file"
885 check_hsm_flags $f.trunc "0x00000003"
887 # Mmapped a file sets dirty
888 cp -p /etc/passwd $f.mmap || error "could not create file"
889 $LFS hsm_set --exists $f.mmap ||
890 error "user could not change hsm flags"
891 multiop $f.mmap OSMWUc || error "could not mmap a file"
892 check_hsm_flags $f.mmap "0x00000003"
894 run_test 3 "Check file dirtyness when opening for write"
897 local f=$DIR/$tdir/$tfile
898 local fid=$(create_small_file $f)
901 local st=$(get_request_state $fid CANCEL)
902 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
904 run_test 4 "Useless cancel must not be registered"
907 # test needs a running copytool
911 local f=$DIR/$tdir/$tfile
912 local fid=$(copy_file /etc/passwd $f)
914 wait_request_state $fid ARCHIVE SUCCEED
916 check_hsm_flags $f "0x00000009"
918 run_test 8 "Test default archive number"
920 test_9A() { # was test_9
921 # we do not use the default one to be sure
922 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
923 copytool setup --archive-id $archive_id
925 # give time for CT to register with MDTs
926 sleep $(($MDSCOUNT*2))
927 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
928 check_agent_registered $uuid
931 local f=$DIR/$tdir/$tfile
932 local fid=$(copy_file /etc/passwd $f)
933 $LFS hsm_archive --archive $archive_id $f
934 wait_request_state $fid ARCHIVE SUCCEED
936 check_hsm_flags $f "0x00000009"
938 run_test 9A "Use of explicit archive number, with dedicated copytool"
941 needclients 3 || return 0
947 # start all of the copytools
948 for n in $(seq $AGTCOUNT); do
949 copytool setup --facet agt$n
953 for n in $(seq $AGTCOUNT); do
954 file=$DIR/$tdir/$tfile.$n
955 fid=$(create_small_file $file)
957 $LFS hsm_archive $file || error "could not archive file $file"
958 wait_request_state $fid ARCHIVE SUCCEED
959 check_hsm_flags $file "0x00000009"
962 run_test 9a "Multiple remote agents"
965 # test needs a running copytool
968 mkdir -p $DIR/$tdir/d1
969 local f=$DIR/$tdir/$tfile
970 local fid=$(copy_file /etc/hosts $f)
971 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
972 error "hsm_archive failed"
973 wait_request_state $fid ARCHIVE SUCCEED
975 local hsm_root="$(copytool_device $SINGLEAGT)"
976 local archive="$(do_facet $SINGLEAGT \
977 find "$hsm_root" -name "$fid" -print0)"
978 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
980 echo "Verifying content"
981 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
982 echo "Verifying hsm state "
983 check_hsm_flags $f "0x00000009"
985 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
986 local st=$(get_hsm_archive_id $f)
987 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
988 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
990 run_test 10a "Archive a file"
993 # test needs a running copytool
997 local f=$DIR/$tdir/$tfile
998 local fid=$(copy_file /etc/hosts $f)
999 $LFS hsm_archive $f || error "archive request failed"
1000 wait_request_state $fid ARCHIVE SUCCEED
1002 $LFS hsm_archive $f || error "archive of non dirty file failed"
1003 local cnt=$(get_request_count $fid ARCHIVE)
1004 [[ "$cnt" == "1" ]] ||
1005 error "archive of non dirty file must not make a request"
1007 run_test 10b "Archive of non dirty file must work without doing request"
1010 # test needs a running copytool
1014 local f=$DIR/$tdir/$tfile
1015 local fid=$(copy_file /etc/hosts $f)
1016 $LFS hsm_set --noarchive $f
1017 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1020 run_test 10c "Check forbidden archive"
1023 # test needs a running copytool
1027 local f=$DIR/$tdir/$tfile
1028 local fid=$(copy_file /etc/hosts $f)
1029 $LFS hsm_archive $f || error "cannot archive $f"
1030 wait_request_state $fid ARCHIVE SUCCEED
1032 local ar=$(get_hsm_archive_id $f)
1033 local dflt=$(get_hsm_param default_archive_id)
1034 [[ $ar == $dflt ]] ||
1035 error "archived file is not on default archive: $ar != $dflt"
1037 run_test 10d "Archive a file on the default archive id"
1041 copy2archive /etc/hosts $tdir/$tfile
1042 local f=$DIR/$tdir/$tfile
1044 copytool import $tdir/$tfile $f
1045 echo -n "Verifying released state: "
1046 check_hsm_flags $f "0x0000000d"
1048 local LSZ=$(stat -c "%s" $f)
1049 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1051 echo "Verifying imported size $LSZ=$ASZ"
1052 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1053 echo -n "Verifying released pattern: "
1054 local PTRN=$($GETSTRIPE -L $f)
1056 [[ $PTRN == released ]] || error "Is not released"
1057 local fid=$(path2fid $f)
1058 echo "Verifying new fid $fid in archive"
1060 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1061 error "No archive for fid $fid"
1063 run_test 11a "Import a file"
1066 # test needs a running copytool
1070 local f=$DIR/$tdir/$tfile
1071 local fid=$(copy_file /etc/hosts $f)
1072 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1073 error "hsm_archive failed"
1074 wait_request_state $fid ARCHIVE SUCCEED
1076 local FILE_HASH=$(md5sum $f)
1079 copytool import $fid $f
1081 echo "$FILE_HASH" | md5sum -c
1083 [[ $? -eq 0 ]] || error "Restored file differs"
1085 run_test 11b "Import a deleted file using its FID"
1088 # test needs a running copytool
1092 copy2archive /etc/hosts $tdir/$tfile
1094 local f=$DIR/$tdir/$tfile
1095 copytool import $tdir/$tfile $f
1096 local f2=$DIR2/$tdir/$tfile
1097 echo "Verifying released state: "
1098 check_hsm_flags $f2 "0x0000000d"
1100 local fid=$(path2fid $f2)
1101 $LFS hsm_restore $f2
1102 wait_request_state $fid RESTORE SUCCEED
1104 echo "Verifying file state: "
1105 check_hsm_flags $f2 "0x00000009"
1107 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1109 [[ $? -eq 0 ]] || error "Restored file differs"
1111 run_test 12a "Restore an imported file explicitly"
1114 # test needs a running copytool
1118 copy2archive /etc/hosts $tdir/$tfile
1120 local f=$DIR/$tdir/$tfile
1121 copytool import $tdir/$tfile $f
1122 echo "Verifying released state: "
1123 check_hsm_flags $f "0x0000000d"
1125 cat $f > /dev/null || error "File read failed"
1127 echo "Verifying file state after restore: "
1128 check_hsm_flags $f "0x00000009"
1130 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1132 [[ $? -eq 0 ]] || error "Restored file differs"
1134 run_test 12b "Restore an imported file implicitly"
1137 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1139 # test needs a running copytool
1142 local f=$DIR/$tdir/$tfile
1144 $LFS setstripe -c 2 "$f"
1145 local fid=$(create_file "$f" 1M 5)
1147 local FILE_CRC=$(md5sum $f)
1149 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1150 wait_request_state $fid ARCHIVE SUCCEED
1151 $LFS hsm_release $f || error "release $f failed"
1153 echo "$FILE_CRC" | md5sum -c
1155 [[ $? -eq 0 ]] || error "Restored file differs"
1157 run_test 12c "Restore a file with stripe of 2"
1160 # test needs a running copytool
1165 local f=$DIR/$tdir/$tfile
1166 local fid=$(copy_file /etc/hosts $f)
1167 $LFS hsm_restore $f || error "restore of non archived file failed"
1168 local cnt=$(get_request_count $fid RESTORE)
1169 [[ "$cnt" == "0" ]] ||
1170 error "restore non archived must not make a request"
1171 $LFS hsm_archive $f ||
1172 error "archive request failed"
1173 wait_request_state $fid ARCHIVE SUCCEED
1174 $LFS hsm_restore $f ||
1175 error "restore of non released file failed"
1176 local cnt=$(get_request_count $fid RESTORE)
1177 [[ "$cnt" == "0" ]] ||
1178 error "restore a non dirty file must not make a request"
1180 run_test 12d "Restore of a non archived, non released file must work"\
1181 " without doing request"
1184 # test needs a running copytool
1188 local f=$DIR/$tdir/$tfile
1189 local fid=$(copy_file /etc/hosts $f)
1190 $LFS hsm_archive $f || error "archive request failed"
1191 wait_request_state $fid ARCHIVE SUCCEED
1194 cat /etc/hosts >> $f
1198 $LFS hsm_restore $f && error "restore a dirty file must fail"
1201 run_test 12e "Check forbidden restore"
1204 # test needs a running copytool
1208 local f=$DIR/$tdir/$tfile
1209 local fid=$(copy_file /etc/hosts $f)
1211 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1212 wait_request_state $fid ARCHIVE SUCCEED
1213 $LFS hsm_release $f || error "release of $f failed"
1215 wait_request_state $fid RESTORE SUCCEED
1217 echo -n "Verifying file state: "
1218 check_hsm_flags $f "0x00000009"
1220 diff -q /etc/hosts $f
1222 [[ $? -eq 0 ]] || error "Restored file differs"
1224 run_test 12f "Restore a released file explicitly"
1227 # test needs a running copytool
1231 local f=$DIR/$tdir/$tfile
1232 local fid=$(copy_file /etc/hosts $f)
1234 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1235 wait_request_state $fid ARCHIVE SUCCEED
1236 $LFS hsm_release $f || error "release of $f failed"
1238 diff -q /etc/hosts $f
1241 # we check we had a restore done
1242 wait_request_state $fid RESTORE SUCCEED
1244 [[ $st -eq 0 ]] || error "Restored file differs"
1246 run_test 12g "Restore a released file implicitly"
1249 needclients 2 || return 0
1251 # test needs a running copytool
1255 local f=$DIR/$tdir/$tfile
1256 local fid=$(copy_file /etc/hosts $f)
1258 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1259 wait_request_state $fid ARCHIVE SUCCEED
1260 $LFS hsm_release $f || error "release of $f failed"
1262 do_node $CLIENT2 diff -q /etc/hosts $f
1265 # we check we had a restore done
1266 wait_request_state $fid RESTORE SUCCEED
1268 [[ $st -eq 0 ]] || error "Restored file differs"
1270 run_test 12h "Restore a released file implicitly from a second node"
1273 # test needs a running copytool
1277 local f=$DIR/$tdir/$tfile
1278 local fid=$(copy_file /etc/passwd $f)
1279 $LFS hsm_archive $f || error "archive of $f failed"
1280 wait_request_state $fid ARCHIVE SUCCEED
1282 $LFS hsm_release $f || error "release of $f failed"
1286 [[ $? -eq 0 ]] || error "Restored file differs"
1288 run_test 12m "Archive/release/implicit restore"
1291 # test needs a running copytool
1295 copy2archive /etc/hosts $tdir/$tfile
1297 local f=$DIR/$tdir/$tfile
1298 copytool import $tdir/$tfile $f
1300 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1301 error "Restored file differs"
1303 $LFS hsm_release $f || error "release of $f failed"
1305 run_test 12n "Import/implicit restore/release"
1308 # test needs a running copytool
1312 local f=$DIR/$tdir/$tfile
1313 local fid=$(copy_file /etc/hosts $f)
1315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1316 wait_request_state $fid ARCHIVE SUCCEED
1317 $LFS hsm_release $f || error "release of $f failed"
1319 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1320 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1322 # set no retry action mode
1325 diff -q /etc/hosts $f
1328 # we check we had a restore failure
1329 wait_request_state $fid RESTORE FAILED
1331 [[ $st -eq 0 ]] && error "Restore must fail"
1333 # remove no retry action mode
1336 # check file is still released
1337 check_hsm_flags $f "0x0000000d"
1339 # retry w/o failure injection
1340 do_facet $SINGLEMDS lctl set_param fail_loc=0
1342 # to be sure previous RESTORE result is gone
1344 wait_for_grace_delay
1346 diff -q /etc/hosts $f
1349 # we check we had a restore done
1350 wait_request_state $fid RESTORE SUCCEED
1352 [[ $st -eq 0 ]] || error "Restored file differs"
1354 run_test 12o "Layout-swap failure during Restore leaves file released"
1357 # test needs a running copytool
1361 local f=$DIR/$tdir/$tfile
1362 local fid=$(copy_file /etc/hosts $f)
1364 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1365 wait_request_state $fid ARCHIVE SUCCEED
1366 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1367 $LFS hsm_release $f || error "cannot release $f"
1368 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1369 $LFS hsm_release $f || error "cannot release $f"
1370 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1372 run_test 12p "implicit restore of a file on copytool mount point"
1375 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1376 skip "need MDS version at least 2.7.58"
1378 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1379 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1380 error "cannot mount $MOUNT3 on $SINGLEAGT"
1382 # test needs a running copytool
1383 copytool setup -m "$MOUNT3"
1385 local f=$DIR/$tdir/$tfile
1386 local f2=$DIR2/$tdir/$tfile
1387 local fid=$(create_small_file $f)
1388 local orig_size=$(stat -c "%s" $f)
1390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1391 wait_request_state $fid ARCHIVE SUCCEED
1393 $LFS hsm_release $f || error "could not release file"
1394 check_hsm_flags $f "0x0000000d"
1397 wait_copytools || error "copytool failed to stop"
1399 cat $f > /dev/null &
1401 # wait a bit to allow implicit restore request to be handled.
1402 # if not, next stat would also block on layout-lock.
1405 local size=$(stat -c "%s" $f2)
1406 [ $size -eq $orig_size ] ||
1407 error "$f2: wrong size after archive: $size != $orig_size"
1409 copytool setup -m "$MOUNT3"
1413 size=$(stat -c "%s" $f)
1414 [ $size -eq $orig_size ] ||
1415 error "$f: wrong size after restore: $size != $orig_size"
1417 size=$(stat -c "%s" $f2)
1418 [ $size -eq $orig_size ] ||
1419 error "$f2: wrong size after restore: $size != $orig_size"
1423 size=$(stat -c "%s" $f)
1425 error "$f: wrong size after overwrite: $size != 0"
1427 size=$(stat -c "%s" $f2)
1429 error "$f2: wrong size after overwrite: $size != 0"
1431 run_test 12q "file attributes are refreshed after restore"
1435 for i in {1..10}; do
1436 local archive_dir="$(hsm_root)"/subdir/dir.$i
1438 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1439 for j in {1..10}; do
1440 local archive_file="$archive_dir"/file.$j
1442 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1448 copytool import "subdir" "$DIR/$tdir"
1450 # To check the import, the test uses diff with the -r flag
1451 # This is nice, but diff only checks files one by one, and triggering
1452 # an implicit restore for one file at a time will consume as many
1453 # seconds as there are files to compare. To speed this up, a restore
1454 # operation is triggered manually first.
1456 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1458 # Compare the imported data
1459 do_facet $SINGLEAGT \
1460 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1461 error "imported files differ from archived data"
1463 run_test 13 "Recursively import and restore a directory"
1466 # test needs a running copytool
1470 local f=$DIR/$tdir/$tfile
1471 local fid=$(create_small_file $f)
1472 local sum=$(md5sum $f | awk '{print $1}')
1473 $LFS hsm_archive $f || error "could not archive file"
1474 wait_request_state $fid ARCHIVE SUCCEED
1476 # create released file (simulate llapi_hsm_import call)
1477 local fid2=$(create_empty_file "$f")
1478 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1479 $LFS hsm_release $f || error "could not release file"
1481 # rebind the archive to the newly created file
1482 echo "rebind $fid to $fid2"
1484 copytool rebind $fid $fid2
1486 # restore file and compare md5sum
1487 local sum2=$(md5sum $f | awk '{print $1}')
1489 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1491 run_test 14 "Rebind archived file to a new fid"
1494 # test needs a running copytool
1498 local f=$DIR/$tdir/$tfile
1500 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1504 for i in $(seq 1 $count); do
1505 fids[$i]=$(create_small_file $f.$i)
1506 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1507 $LFS hsm_archive $f.$i || error "could not archive file"
1509 wait_all_done $(($count*60))
1511 stack_trap "rm -f $tmpfile" EXIT
1514 for i in $(seq 1 $count); do
1515 local fid2=$(create_empty_file "${f}.${i}")
1516 # add the rebind operation to the list
1517 echo ${fids[$i]} $fid2 >> $tmpfile
1519 # set it released (simulate llapi_hsm_import call)
1520 $LFS hsm_set --archived --exists $f.$i ||
1521 error "could not force hsm flags"
1522 $LFS hsm_release $f.$i || error "could not release file"
1524 nl=$(wc -l < $tmpfile)
1525 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1527 echo "rebind list of files"
1528 copytool rebind "$tmpfile"
1530 # restore files and compare md5sum
1531 for i in $(seq 1 $count); do
1532 local sum2=$(md5sum $f.$i | awk '{print $1}')
1533 [[ $sum2 == ${sums[$i]} ]] ||
1534 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1537 run_test 15 "Rebind a list of files"
1540 # test needs a running copytool
1544 # create a known size file so we can verify transfer speed
1547 dd if=/dev/zero of=$ref bs=1M count=20
1550 local f=$DIR/$tdir/$tfile
1551 local fid=$(copy_file $ref $f)
1553 local start=$(date +%s)
1555 wait_request_state $fid ARCHIVE SUCCEED
1556 local end=$(date +%s)
1557 # Add 1 to account for rounding errors between start and end (LU-8155)
1558 local duration=$((end - start + 1))
1560 [[ $duration -ge $((goal - 1)) ]] ||
1561 error "Transfer is too fast $duration < $goal"
1563 run_test 16 "Test CT bandwith control option"
1566 local f=$DIR/$tdir/$tfile
1567 create_empty_file "$f"
1569 # Could not release a non-archived file
1570 $LFS hsm_release $f && error "release should not succeed"
1572 # For following tests, we must test them with HS_ARCHIVED set
1573 $LFS hsm_set --exists --archived $f || error "could not add flag"
1575 # Could not release a file if no-release is set
1576 $LFS hsm_set --norelease $f || error "could not add flag"
1577 $LFS hsm_release $f && error "release should not succeed"
1578 $LFS hsm_clear --norelease $f || error "could not remove flag"
1580 # Could not release a file if lost
1581 $LFS hsm_set --lost $f || error "could not add flag"
1582 $LFS hsm_release $f && error "release should not succeed"
1583 $LFS hsm_clear --lost $f || error "could not remove flag"
1585 # Could not release a file if dirty
1586 $LFS hsm_set --dirty $f || error "could not add flag"
1587 $LFS hsm_release $f && error "release should not succeed"
1588 $LFS hsm_clear --dirty $f || error "could not remove flag"
1590 run_test 20 "Release is not permitted"
1593 # test needs a running copytool
1596 local f=$DIR/$tdir/test_release
1598 # Create a file and check its states
1599 local fid=$(create_small_file $f)
1600 check_hsm_flags $f "0x00000000"
1602 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1603 # used until file is flushed to disk
1604 if [ $(facet_fstype ost1) == "zfs" ]; then
1605 # this causes an OST_SYNC rpc to be sent
1606 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1607 # clear locks to reread file data
1608 cancel_lru_locks osc
1611 local orig_size=$(stat -c "%s" $f)
1612 local orig_blocks=$(stat -c "%b" $f)
1614 start_full_debug_logging
1616 $LFS hsm_archive $f || error "could not archive file"
1617 wait_request_state $fid ARCHIVE SUCCEED
1619 local blocks=$(stat -c "%b" $f)
1620 [ $blocks -eq $orig_blocks ] ||
1621 error "$f: wrong block number after archive: " \
1622 "$blocks != $orig_blocks"
1623 local size=$(stat -c "%s" $f)
1624 [ $size -eq $orig_size ] ||
1625 error "$f: wrong size after archive: $size != $orig_size"
1627 # Release and check states
1628 $LFS hsm_release $f || error "could not release file"
1629 check_hsm_flags $f "0x0000000d"
1631 blocks=$(stat -c "%b" $f)
1632 [ $blocks -gt 5 ] &&
1633 error "$f: too many blocks after release: $blocks > 5"
1634 size=$(stat -c "%s" $f)
1635 [ $size -ne $orig_size ] &&
1636 error "$f: wrong size after release: $size != $orig_size"
1638 # Check we can release an file without stripe info
1642 check_hsm_flags $f "0x00000000"
1643 $LFS hsm_archive $f || error "could not archive file"
1644 wait_request_state $fid ARCHIVE SUCCEED
1646 # Release and check states
1647 $LFS hsm_release $f || error "could not release file"
1648 check_hsm_flags $f "0x0000000d"
1650 # Release again a file that is already released is OK
1651 $LFS hsm_release $f || fail "second release should succeed"
1652 check_hsm_flags $f "0x0000000d"
1654 stop_full_debug_logging
1656 run_test 21 "Simple release tests"
1659 # test needs a running copytool
1662 local f=$DIR/$tdir/test_release
1663 local swap=$DIR/$tdir/test_swap
1665 # Create a file and check its states
1666 local fid=$(create_small_file $f)
1667 check_hsm_flags $f "0x00000000"
1669 $LFS hsm_archive $f || error "could not archive file"
1670 wait_request_state $fid ARCHIVE SUCCEED
1672 # Release and check states
1673 $LFS hsm_release $f || error "could not release file"
1674 check_hsm_flags $f "0x0000000d"
1676 create_small_file $swap
1677 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1681 run_test 22 "Could not swap a release file"
1684 # test needs a running copytool
1687 local f=$DIR/$tdir/test_mtime
1689 # Create a file and check its states
1690 local fid=$(create_small_file $f)
1691 check_hsm_flags $f "0x00000000"
1693 $LFS hsm_archive $f || error "could not archive file"
1694 wait_request_state $fid ARCHIVE SUCCEED
1696 # Set modification time in the past
1697 touch -m -a -d @978261179 $f
1699 # Release and check states
1700 $LFS hsm_release $f || error "could not release file"
1701 check_hsm_flags $f "0x0000000d"
1703 local MTIME=$(stat -c "%Y" $f)
1704 local ATIME=$(stat -c "%X" $f)
1705 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1706 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1708 run_test 23 "Release does not change a/mtime (utime)"
1711 local file=$DIR/$tdir/$tfile
1720 # test needs a running copytool
1723 fid=$(create_small_file $file)
1725 # Create a file and check its states
1726 check_hsm_flags $file "0x00000000"
1728 # Ensure atime is less than mtime and ctime.
1732 atime0=$(stat -c "%X" $file)
1733 mtime0=$(stat -c "%Y" $file)
1734 ctime0=$(stat -c "%Z" $file)
1736 [ $atime0 -lt $mtime0 ] ||
1737 error "atime $atime0 is not less than mtime $mtime0"
1739 [ $atime0 -lt $ctime0 ] ||
1740 error "atime $atime0 is not less than ctime $ctime0"
1742 # Archive should not change any timestamps.
1743 $LFS hsm_archive $file || error "cannot archive '$file'"
1744 wait_request_state $fid ARCHIVE SUCCEED
1746 atime1=$(stat -c "%X" $file)
1747 mtime1=$(stat -c "%Y" $file)
1748 ctime1=$(stat -c "%Z" $file)
1750 [ $atime0 -eq $atime1 ] ||
1751 error "archive changed atime from $atime0 to $atime1"
1753 [ $mtime0 -eq $mtime1 ] ||
1754 error "archive changed mtime from $mtime0 to $mtime1"
1756 [ $ctime0 -eq $ctime1 ] ||
1757 error "archive changed ctime from $ctime0 to $ctime1"
1759 # Release should not change any timestamps.
1760 $LFS hsm_release $file || error "cannot release '$file'"
1761 check_hsm_flags $file "0x0000000d"
1763 atime1=$(stat -c "%X" $file)
1764 mtime1=$(stat -c "%Y" $file)
1765 ctime1=$(stat -c "%Z" $file)
1767 [ $atime0 -eq $atime1 ] ||
1768 error "release changed atime from $atime0 to $atime1"
1770 [ $mtime0 -eq $mtime1 ] ||
1771 error "release changed mtime from $mtime0 to $mtime1"
1773 [ $ctime0 -eq $ctime1 ] ||
1774 error "release changed ctime from $ctime0 to $ctime1"
1776 # Restore should not change any timestamps.
1777 $LFS hsm_restore $file
1778 wait_request_state $fid RESTORE SUCCEED
1780 atime1=$(stat -c "%X" $file)
1781 mtime1=$(stat -c "%Y" $file)
1782 ctime1=$(stat -c "%Z" $file)
1784 [ $atime0 -eq $atime1 ] ||
1785 error "restore changed atime from $atime0 to $atime1"
1787 [ $mtime0 -eq $mtime1 ] ||
1788 error "restore changed mtime from $mtime0 to $mtime1"
1790 [ $ctime0 -eq $ctime1 ] ||
1791 error "restore changed ctime from $ctime0 to $ctime1"
1794 wait_copytools || error "Copytools failed to stop"
1796 # Once more, after unmount and mount.
1797 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1798 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1800 atime1=$(stat -c "%X" $file)
1801 mtime1=$(stat -c "%Y" $file)
1802 ctime1=$(stat -c "%Z" $file)
1804 [ $atime0 -eq $atime1 ] ||
1805 error "remount changed atime from $atime0 to $atime1"
1807 [ $mtime0 -eq $mtime1 ] ||
1808 error "remount changed mtime from $mtime0 to $mtime1"
1810 [ $ctime0 -eq $ctime1 ] ||
1811 error "remount changed ctime from $ctime0 to $ctime1"
1813 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1816 local file=$DIR/$tdir/$tfile
1822 # Test needs a running copytool.
1825 # Check that root can do HSM actions on a regular user's file.
1826 fid=$(create_small_file $file)
1827 sum0=$(md5sum $file)
1829 chown $RUNAS_ID:$RUNAS_GID $file ||
1830 error "cannot chown '$file' to '$RUNAS_ID'"
1832 chmod ugo-w $DIR/$tdir ||
1833 error "cannot chmod '$DIR/$tdir'"
1835 $LFS hsm_archive $file
1836 wait_request_state $fid ARCHIVE SUCCEED
1838 $LFS hsm_release $file
1839 check_hsm_flags $file "0x0000000d"
1841 $LFS hsm_restore $file
1842 wait_request_state $fid RESTORE SUCCEED
1844 # Check that ordinary user can get HSM state.
1845 $RUNAS $LFS hsm_state $file ||
1846 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1848 $LFS hsm_release $file
1849 check_hsm_flags $file "0x0000000d"
1851 # Check that ordinary user can accessed released file.
1852 sum1=$($RUNAS md5sum $file) ||
1853 error "user '$RUNAS_ID' cannot read '$file'"
1855 [ "$sum0" == "$sum1" ] ||
1856 error "md5sum mismatch for '$file'"
1858 run_test 24b "root can archive, release, and restore user files"
1861 local file=$DIR/$tdir/$tfile
1862 local action=archive
1867 # test needs a running copytool
1872 # Save the default masks and check that cleanup_24c will
1873 # restore the request masks correctly.
1874 user_save=$(get_hsm_param user_request_mask)
1875 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1876 group_save=$(get_hsm_param group_request_mask)
1877 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1878 other_save=$(get_hsm_param other_request_mask)
1879 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1881 [ "$user_save" == RESTORE ] ||
1882 error "user_request_mask is '$user_save' expected 'RESTORE'"
1883 [ "$group_save" == RESTORE ] ||
1884 error "group_request_mask is '$group_save' expected 'RESTORE'"
1885 [ "$other_save" == RESTORE ] ||
1886 error "other_request_mask is '$other_save' expected 'RESTORE'"
1889 create_small_file $file
1890 chown $RUNAS_ID:$GROUP $file ||
1891 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1893 $RUNAS $LFS hsm_$action $file &&
1894 error "$action by user should fail"
1896 set_hsm_param user_request_mask $action
1897 $RUNAS $LFS hsm_$action $file ||
1898 error "$action by user should succeed"
1901 create_small_file $file
1902 chown nobody:$RUNAS_GID $file ||
1903 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1905 $RUNAS $LFS hsm_$action $file &&
1906 error "$action by group should fail"
1908 set_hsm_param group_request_mask $action
1909 $RUNAS $LFS hsm_$action $file ||
1910 error "$action by group should succeed"
1913 create_small_file $file
1914 chown nobody:$GROUP $file ||
1915 error "cannot chown '$file' to 'nobody:$GROUP'"
1917 $RUNAS $LFS hsm_$action $file &&
1918 error "$action by other should fail"
1920 set_hsm_param other_request_mask $action
1921 $RUNAS $LFS hsm_$action $file ||
1922 error "$action by other should succeed"
1924 run_test 24c "check that user,group,other request masks work"
1927 local file1=$DIR/$tdir/$tfile
1928 local file2=$DIR2/$tdir/$tfile
1932 fid1=$(create_small_file $file1)
1935 $LFS getstripe $file1
1937 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1938 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1939 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1941 copytool setup -m "$MOUNT3"
1943 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1944 mount -o remount,ro $MOUNT2
1946 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1948 fid2=$(path2fid $file2)
1949 [ "$fid1" == "$fid2" ] ||
1950 error "FID mismatch '$fid1' != '$fid2'"
1952 $LFS hsm_archive $file2 &&
1953 error "archive should fail on read-only mount"
1954 check_hsm_flags $file1 "0x00000000"
1956 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1957 wait_request_state $fid1 ARCHIVE SUCCEED
1959 $LFS hsm_release $file1
1960 $LFS hsm_restore $file2
1961 wait_request_state $fid1 RESTORE SUCCEED
1963 $LFS hsm_release $file1 || error "cannot release '$file1'"
1964 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1966 $LFS hsm_release $file2 &&
1967 error "release should fail on read-only mount"
1971 run_test 24d "check that read-only mounts are respected"
1976 local f=$DIR/$tdir/$tfile
1979 fid=$(create_small_file $f) || error "cannot create $f"
1980 $LFS hsm_archive $f || error "cannot archive $f"
1981 wait_request_state $fid ARCHIVE SUCCEED
1982 $LFS hsm_release $f || error "cannot release $f"
1983 while ! $LFS hsm_state $f | grep released; do
1987 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1989 run_test 24e "tar succeeds on HSM released files" # LU-6213
1992 # test needs a running copytool
1995 mkdir -p $DIR/$tdir/d1
1996 local f=$DIR/$tdir/$tfile
1997 local fid=$(copy_file /etc/hosts $f)
2000 $LFS hsm_archive $f ||
2001 error "hsm_archive failed"
2002 wait_request_state $fid ARCHIVE SUCCEED
2003 $LFS hsm_release $f || error "cannot release $f"
2004 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2007 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2008 error "Can not recover the tar contents"
2010 echo "Sum0 = $sum0, sum1 = $sum1"
2011 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2013 run_test 24f "root can archive, release, and restore tar files"
2016 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2017 skip "need MDS version 2.11.56 or later"
2019 local file=$DIR/$tdir/$tfile
2022 echo "RUNAS = '$RUNAS'"
2027 chmod ugo+rwx $DIR/$tdir
2029 echo "Please listen carefully as our options have changed." | tee $file
2030 fid=$(path2fid $file)
2033 $LFS hsm_archive $file
2034 wait_request_state $fid ARCHIVE SUCCEED
2035 check_hsm_flags $file 0x00000009 # exists archived
2037 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2038 check_hsm_flags $file 0x0000000b # exists dirty archived
2040 run_test 24g "write by non-owner still sets dirty" # LU-11369
2043 # test needs a running copytool
2047 copy2archive /etc/hosts $tdir/$tfile
2049 local f=$DIR/$tdir/$tfile
2051 copytool import $tdir/$tfile $f
2053 $LFS hsm_set --lost $f
2058 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2060 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2061 " (Operation not permitted)"
2064 # test needs a running copytool
2069 local f=$DIR/$tdir/$tfile
2070 local fid=$(copy_file /etc/passwd $f)
2072 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2073 wait_request_state $fid ARCHIVE SUCCEED
2076 $LFS hsm_set --lost $f
2080 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2082 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2083 " (Operation not permitted)"
2085 test_26A() { # was test_26
2086 # test needs a running copytool
2089 local f=$DIR/$tdir/$tfile
2090 local fid=$(create_empty_file "$f")
2092 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2093 wait_request_state $fid ARCHIVE SUCCEED
2096 wait_request_state $fid REMOVE SUCCEED
2098 check_hsm_flags $f "0x00000000"
2100 run_test 26A "Remove the archive of a valid file"
2103 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2104 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2106 # test needs a running copytool
2110 local f=$DIR/$tdir/$tfile
2111 local fid=$(copy_file /etc/passwd $f)
2113 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2114 wait_request_state $fid ARCHIVE SUCCEED
2116 local f2=$DIR/$tdir/${tfile}_2
2117 local fid2=$(copy_file /etc/passwd $f2)
2119 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2120 wait_request_state $fid2 ARCHIVE SUCCEED
2122 local f3=$DIR/$tdir/${tfile}_3
2123 local fid3=$(copy_file /etc/passwd $f3)
2125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2126 wait_request_state $fid3 ARCHIVE SUCCEED
2128 # set a long grace_delay vs short loop_period
2129 local orig_loop_period=$(get_hsm_param loop_period)
2130 local orig_grace_delay=$(get_hsm_param grace_delay)
2131 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2132 set_hsm_param loop_period 10
2133 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2134 set_hsm_param grace_delay 100
2138 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2139 set_hsm_param remove_archive_on_last_unlink 1
2141 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2146 wait_request_state $fid2 REMOVE SUCCEED
2148 assert_request_count $fid REMOVE 0 \
2149 "Unexpected archived data remove request for $f"
2150 assert_request_count $fid3 REMOVE 0 \
2151 "Unexpected archived data remove request for $f3"
2153 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2156 # test needs a running copytool
2160 local f=$DIR/$tdir/$tfile
2161 local fid=$(copy_file /etc/passwd $f)
2163 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2164 wait_request_state $fid ARCHIVE SUCCEED
2166 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2167 set_hsm_param remove_archive_on_last_unlink 1
2170 cdt_check_state stopped
2174 wait_request_state $fid REMOVE WAITING
2178 # copytool must re-register
2180 wait_copytools || error "copytool failed to stop"
2183 wait_request_state $fid REMOVE SUCCEED
2185 run_test 26b "RAoLU policy when CDT off"
2188 # test needs a running copytool
2192 local f=$DIR/$tdir/$tfile
2193 local fid=$(copy_file /etc/passwd $f)
2195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2196 wait_request_state $fid ARCHIVE SUCCEED
2198 local f2=$DIR/$tdir/${tfile}_2
2199 local fid2=$(copy_file /etc/passwd $f2)
2201 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2202 wait_request_state $fid2 ARCHIVE SUCCEED
2204 # set a long grace_delay vs short loop_period
2205 local orig_loop_period=$(get_hsm_param loop_period)
2206 local orig_grace_delay=$(get_hsm_param grace_delay)
2207 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2208 set_hsm_param loop_period 10
2209 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2210 set_hsm_param grace_delay 100
2212 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2213 set_hsm_param remove_archive_on_last_unlink 1
2215 multiop_bg_pause $f O_c || error "open $f failed"
2221 wait_request_state $fid2 REMOVE SUCCEED
2222 assert_request_count $fid REMOVE 0 \
2223 "Unexpected archived data remove request for $f"
2225 kill -USR1 $pid || error "multiop early exit"
2226 # should reach autotest timeout if multiop fails to trap
2227 # signal, close file, and exit ...
2228 wait $pid || error "wait PID $PID failed"
2230 wait_request_state $fid REMOVE SUCCEED
2232 run_test 26c "RAoLU effective when file closed"
2235 # test needs a running copytool
2239 local f=$DIR/$tdir/$tfile
2240 local fid=$(create_small_file $f)
2242 $LFS hsm_archive $f || error "could not archive file"
2243 wait_request_state $fid ARCHIVE SUCCEED
2245 # set a long grace_delay vs short loop_period
2246 local orig_loop_period=$(get_hsm_param loop_period)
2247 local orig_grace_delay=$(get_hsm_param grace_delay)
2248 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2249 set_hsm_param loop_period 10
2250 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2251 set_hsm_param grace_delay 100
2253 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2254 set_hsm_param remove_archive_on_last_unlink 1
2256 multiop_bg_pause $f O_c || error "multiop failed"
2263 wait_request_state $fid REMOVE SUCCEED
2265 client_up || client_up || true
2267 kill -USR1 $MULTIPID
2268 wait $MULTIPID || error "multiop close failed"
2270 run_test 26d "RAoLU when Client eviction"
2273 # test needs a running copytool
2276 create_archive_file $tdir/$tfile
2277 local f=$DIR/$tdir/$tfile
2278 copytool import $tdir/$tfile $f
2279 local fid=$(path2fid $f)
2283 [[ $? != 0 ]] || error "Remove of a released file should fail"
2285 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2288 # test needs a running copytool
2291 local f=$DIR/$tdir/$tfile
2292 local fid=$(create_empty_file "$f")
2294 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2295 wait_request_state $fid ARCHIVE SUCCEED
2300 [[ $? != 0 ]] || error "Remove of a released file should fail"
2302 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2305 # test needs a running copytool
2308 local f=$DIR/$tdir/$tfile
2309 local fid=$(create_empty_file "$f")
2311 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2312 wait_request_state $fid ARCHIVE SUCCEED
2321 wait_request_state $fid REMOVE SUCCEED
2323 run_test 28 "Concurrent archive/file remove"
2326 # Tests --mntpath and --archive options
2329 copytool setup -m "$MOUNT" -a $archive_id
2331 # Bad archive number
2332 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2333 grep "Invalid argument" ||
2334 error "unexpected hsm_remove failure (1)"
2336 # mntpath is present but file is given
2337 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2338 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2339 error "unexpected hsm_remove failure (2)"
2341 run_test 29a "Tests --mntpath and --archive options"
2344 # test needs a running copytool
2347 local f=$DIR/$tdir/$tfile
2348 local fid=$(create_small_file $f)
2350 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2351 wait_request_state $fid ARCHIVE SUCCEED
2355 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2356 wait_request_state $fid REMOVE SUCCEED
2358 run_test 29b "Archive/delete/remove by FID from the archive."
2361 # test needs a running copytool
2364 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2365 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2366 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2368 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2369 wait_request_state $fid1 ARCHIVE SUCCEED
2370 wait_request_state $fid2 ARCHIVE SUCCEED
2371 wait_request_state $fid3 ARCHIVE SUCCEED
2373 rm -f $DIR/$tdir/$tfile-[1-3]
2375 echo $fid1 > $DIR/$tdir/list
2376 echo $fid2 >> $DIR/$tdir/list
2377 echo $fid3 >> $DIR/$tdir/list
2379 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2380 --filelist $DIR/$tdir/list
2381 wait_request_state $fid1 REMOVE SUCCEED
2382 wait_request_state $fid2 REMOVE SUCCEED
2383 wait_request_state $fid3 REMOVE SUCCEED
2385 run_test 29c "Archive/delete/remove by FID, using a file list."
2388 # test needs more than one CT
2389 needclients 3 || return 0
2395 # start all of the copytools
2396 for n in $(seq $AGTCOUNT); do
2397 copytool setup -f agt$n -a $n
2401 file=$DIR/$tdir/$tfile
2402 fid=$(create_small_file $file)
2404 $LFS hsm_archive $file
2405 wait_request_state $fid ARCHIVE SUCCEED
2406 check_hsm_flags $file "0x00000009"
2410 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2411 error "cannot hsm_remove '$fid'"
2413 # give time for CDT to handle remove request and create broadcasted
2416 # remove request has been broadcasted ?
2417 local cnt=$(get_request_count $fid REMOVE)
2418 # broadcasted requests + original
2419 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2420 error "remove not broadcasted to all CTs"
2422 # give time for CDT and CTs to handle broadcasted
2423 wait_for_loop_period
2425 # each agent serves one different archive_id, so broadcasted
2426 # hsm_remove request should only succeed once and fail at all others
2430 for n in $(seq $AGTCOUNT); do
2431 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2432 $HSM_PARAM.actions | awk \
2433 '/'$fid'.*action=REMOVE archive#='$n'/ \
2434 {print \\\$13}' | cut -f2 -d=")
2435 if [[ "$res" == "SUCCEED" ]]; then
2437 elif [[ "$res" == "FAILED" ]]; then
2442 [[ $scnt -eq 1 ]] ||
2443 error "one and only CT should have removed successfully"
2445 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2446 error "all but one CT should have failed to remove"
2448 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2449 "request to be sent once for each registered archive_id"
2452 # restore at exec cannot work on agent node (because of Linux kernel
2453 # protection of executables)
2454 needclients 2 || return 0
2456 # test needs a running copytool
2460 copy2archive /bin/true $tdir/$tfile
2462 local f=$DIR/$tdir/true
2463 copytool import $tdir/$tfile $f
2465 local fid=$(path2fid $f)
2467 stack_trap "cdt_clear_no_retry" EXIT
2468 # set no retry action mode
2475 [[ $st == 0 ]] || error "Failed to exec a released file"
2477 run_test 30a "Restore at exec (import case)"
2480 # restore at exec cannot work on agent node (because of Linux kernel
2481 # protection of executables)
2482 needclients 2 || return 0
2484 # test needs a running copytool
2488 local f=$DIR/$tdir/true
2489 local fid=$(copy_file /bin/true $f)
2491 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2492 wait_request_state $fid ARCHIVE SUCCEED
2496 stack_trap cdt_clear_no_retry EXIT
2497 # set no retry action mode
2505 [[ $st == 0 ]] || error "Failed to exec a released file"
2507 run_test 30b "Restore at exec (release case)"
2510 needclients 2 || return 0
2512 # test needs a running copytool
2516 local f=$DIR/$tdir/SLEEP
2517 local slp_sum1=$(md5sum /bin/sleep)
2518 local fid=$(copy_file /bin/sleep $f)
2520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2521 wait_request_state $fid ARCHIVE SUCCEED
2523 check_hsm_flags $f "0x0000000d"
2525 stack_trap cdt_clear_no_retry EXIT
2526 # set no retry action mode
2529 do_node $CLIENT2 "$f 10" &
2533 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2535 [[ $? == 0 ]] || error "Execution failed during run"
2537 if [[ $? != 0 ]]; then
2538 local slp_sum2=$(md5sum /bin/sleep)
2539 # in case sleep file is modified during the test
2540 [[ $slp_sum1 == $slp_sum2 ]] &&
2541 error "Binary overwritten during exec"
2544 check_hsm_flags $f "0x00000009"
2546 run_test 30c "Update during exec of released file must fail"
2548 restore_and_check_size() {
2551 local s=$(stat -c "%s" $f)
2553 local st=$(get_hsm_flags $f)
2557 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2559 n=$(stat -c "%s" $f)
2560 # we echo in both cases to show stat is not hang
2561 if [[ $n != $s ]]; then
2562 echo "size seen is $n != $s"
2565 echo "size seen is right: $n == $s"
2569 st=$(get_hsm_flags $f)
2571 if [[ "$st" = "0x00000009" ]]; then
2574 echo " restore is too long"
2575 wait_request_state $fid RESTORE SUCCEED
2581 # test needs a running copytool
2584 create_archive_file $tdir/$tfile
2585 local f=$DIR/$tdir/$tfile
2586 copytool import $tdir/$tfile $f
2587 local fid=$($LFS path2fid $f)
2590 restore_and_check_size $f $fid
2593 [[ $err -eq 0 ]] || error "File size changed during restore"
2595 run_test 31a "Import a large file and check size during restore"
2599 # test needs a running copytool
2602 local f=$DIR/$tdir/$tfile
2603 local fid=$(create_file "$f" 1MB 39)
2605 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2606 wait_request_state $fid ARCHIVE SUCCEED
2609 restore_and_check_size $f $fid
2612 [[ $err -eq 0 ]] || error "File size changed during restore"
2614 run_test 31b "Restore a large unaligned file and check size during restore"
2617 # test needs a running copytool
2620 local f=$DIR/$tdir/$tfile
2621 local fid=$(create_file "$f" 1M 39)
2623 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2624 wait_request_state $fid ARCHIVE SUCCEED
2627 restore_and_check_size $f $fid
2630 [[ $err -eq 0 ]] || error "File size changed during restore"
2632 run_test 31c "Restore a large aligned file and check size during restore"
2635 local f=$DIR/$tdir/$tfile
2636 local fid=$(create_empty_file "$f")
2640 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2641 wait_request_state $fid ARCHIVE SUCCEED
2644 # Prevent restore from completing
2648 md5sum $f >/dev/null &
2651 wait_request_state $fid RESTORE STARTED
2656 # Check restore trigger process was killed
2658 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2660 run_test 33 "Kill a restore waiting process"
2663 # test needs a running copytool
2666 local f=$DIR/$tdir/$tfile
2667 local fid=$(create_empty_file "$f")
2669 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2670 wait_request_state $fid ARCHIVE SUCCEED
2673 # Prevent restore from completing
2676 md5sum $f >/dev/null &
2679 wait_request_state $fid RESTORE STARTED
2681 # rm must not block during restore
2682 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2685 wait_request_state $fid RESTORE SUCCEED
2687 # Check md5sum pgm finished
2688 kill -0 $pid && error "Restore initiatior still running"
2689 wait $pid || error "Restore initiator failed with $?"
2691 # Check the file was actually deleted
2692 [ ! -f "$f" ] || error "$f was not deleted"
2694 run_test 34 "Remove file during restore"
2697 # test needs a running copytool
2700 local f=$DIR/$tdir/$tfile
2701 local f1=$DIR/$tdir/$tfile-1
2702 local fid=$(create_empty_file "$f")
2703 local fid1=$(copy_file /etc/passwd $f1)
2705 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2706 wait_request_state $fid ARCHIVE SUCCEED
2709 # Prevent restore from completing
2712 md5sum $f >/dev/null &
2715 wait_request_state $fid RESTORE STARTED
2717 # mv must not block during restore
2718 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2721 wait_request_state $fid RESTORE SUCCEED
2723 # Check md5sum pgm finished
2724 kill -0 $pid && error "Restore initiatior still running"
2725 wait $pid || error "Restore initiator failed with $?"
2727 local fid2=$(path2fid $f)
2728 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2730 run_test 35 "Overwrite file during restore"
2733 # test needs a running copytool
2736 local f=$DIR/$tdir/$tfile
2737 local fid=$(create_empty_file "$f")
2739 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2740 wait_request_state $fid ARCHIVE SUCCEED
2743 # Prevent restore from completing
2746 md5sum $f >/dev/null &
2749 wait_request_state $fid RESTORE STARTED
2751 # mv must not block during restore
2752 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2753 error "mv '$f' '$f.new' failed with rc=$?"
2756 wait_request_state $fid RESTORE SUCCEED
2758 # Check md5sum pgm finished
2759 kill -0 $pid && error "Restore initiator is still running"
2760 wait $pid || error "Restore initiator failed with $?"
2762 run_test 36 "Move file during restore"
2765 # LU-5683: check that an archived dirty file can be rearchived.
2768 local f=$DIR/$tdir/$tfile
2771 fid=$(create_small_file $f) || error "cannot create small file"
2773 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2774 wait_request_state $fid ARCHIVE SUCCEED
2775 $LFS hsm_release $f || error "cannot release $f"
2777 # Allow previous archive request to expire from the actions log.
2778 wait_for_grace_delay
2781 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2783 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2784 wait_request_state $fid ARCHIVE SUCCEED
2786 run_test 37 "re-archive a dirty file"
2793 for n in $(seq 1 $count); do
2794 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2796 echo "$count archive requests submitted"
2800 local stream_count=4
2801 local file_count=100
2803 local f=$DIR/$tdir/$tfile
2807 local max_requests=$(get_hsm_param max_requests)
2809 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2810 # Increase the number of HSM request that can be performed in
2811 # parallel. With the coordinator running once per second, this
2812 # also limits the number of requests per seconds that can be
2813 # performed, so we pick a decent number. But we also need to keep
2814 # that number low because the copytool has no rate limit and will
2815 # fail some requests if if gets too many at once.
2816 set_hsm_param max_requests 300
2818 for i in $(seq 1 $file_count); do
2819 for p in $(seq 1 $stream_count); do
2820 fid=$(copy_file /etc/hosts $f.$p.$i)
2826 # to be sure wait_all_done will not be mislead by previous tests
2828 wait_for_grace_delay
2830 # start archive streams in background (archive files in parallel)
2831 for p in $(seq 1 $stream_count); do
2832 multi_archive $f.$p $file_count &
2835 echo -n "Wait for all requests being enqueued..."
2840 run_test 40 "Parallel archive requests"
2843 # test needs a running copytool
2847 local f=$DIR/$tdir/$tfile
2848 local fid=$(create_small_file $f)
2850 $LFS hsm_archive $f || error "could not archive file"
2851 wait_request_state $fid ARCHIVE SUCCEED
2852 check_hsm_flags $f "0x00000009"
2854 multiop_bg_pause $f O_c || error "multiop failed"
2858 client_up || client_up || true
2860 kill -USR1 $MULTIPID
2861 wait $MULTIPID || error "multiop close failed"
2863 check_hsm_flags $f "0x0000000b"
2865 run_test 52 "Opened for write file on an evicted client should be set dirty"
2868 # test needs a running copytool
2872 local f=$DIR/$tdir/$tfile
2873 local fid=$(create_small_file $f)
2875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2876 error "could not archive file"
2877 wait_request_state $fid ARCHIVE SUCCEED
2878 check_hsm_flags $f "0x00000009"
2880 multiop_bg_pause $f o_c || error "multiop failed"
2884 client_up || client_up || true
2886 kill -USR1 $MULTIPID
2887 wait $MULTIPID || error "multiop close failed"
2889 check_hsm_flags $f "0x00000009"
2891 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2894 local f=$DIR/$tdir/$tfile
2895 local fid=$(create_file "$f" 1MB 39)
2899 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2900 error "could not archive file"
2901 wait_request_state $fid ARCHIVE STARTED
2903 check_hsm_flags $f "0x00000001"
2905 stack_trap "cdt_clear_no_retry" EXIT
2906 # Avoid coordinator resending this request as soon it has failed.
2911 wait_request_state $fid ARCHIVE FAILED
2913 check_hsm_flags $f "0x00000003"
2915 run_test 54 "Write during an archive cancels it"
2918 local f=$DIR/$tdir/$tfile
2919 local fid=$(create_file "$f" 1MB 39)
2923 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2924 error "could not archive file"
2925 wait_request_state $fid ARCHIVE STARTED
2927 check_hsm_flags $f "0x00000001"
2929 stack_trap "cdt_clear_no_retry" EXIT
2930 # Avoid coordinator resending this request as soon it has failed.
2933 $TRUNCATE $f 1024 || error "truncate failed"
2935 wait_request_state $fid ARCHIVE FAILED
2937 check_hsm_flags $f "0x00000003"
2939 run_test 55 "Truncate during an archive cancels it"
2942 local f=$DIR/$tdir/$tfile
2943 local fid=$(create_file "$f" 1MB 39)
2947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2948 error "could not archive file"
2949 wait_request_state $fid ARCHIVE STARTED
2951 check_hsm_flags $f "0x00000001"
2953 # Change metadata and sync to be sure we are not changing only
2958 wait_request_state $fid ARCHIVE SUCCEED
2960 check_hsm_flags $f "0x00000009"
2962 run_test 56 "Setattr during an archive is ok"
2965 # Need one client for I/O, one for request
2966 needclients 2 || return 0
2968 # test needs a running copytool
2972 local f=$DIR/$tdir/test_archive_remote
2973 # Create a file on a remote node
2974 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2975 "count=2 conv=fsync"
2978 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2979 error "hsm_archive failed"
2980 local fid=$(path2fid $f)
2981 wait_request_state $fid ARCHIVE SUCCEED
2983 # Release and implicit restore it
2984 do_node $CLIENT2 "$LFS hsm_release $f" ||
2985 error "hsm_release failed"
2986 do_node $CLIENT2 "md5sum $f" ||
2987 error "hsm_restore failed"
2989 wait_request_state $fid RESTORE SUCCEED
2991 run_test 57 "Archive a file with dirty cache on another node"
2993 truncate_released_file() {
2997 local sz=$(stat -c %s $src_file)
2998 local f=$DIR/$tdir/$tfile
2999 local fid=$(copy_file $1 $f)
3003 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3004 error "could not archive file"
3005 wait_request_state $fid ARCHIVE SUCCEED
3007 $LFS hsm_release $f || error "could not release file"
3009 $TRUNCATE $f $trunc_to || error "truncate failed"
3012 local sz1=$(stat -c %s $f)
3013 [[ $sz1 == $trunc_to ]] ||
3014 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3017 check_hsm_flags $f "0x0000000b"
3019 local state=$(get_request_state $fid RESTORE)
3020 [[ "$state" == "SUCCEED" ]] ||
3021 error "truncate $sz does not trig restore, state = $state"
3023 $TRUNCATE $ref $trunc_to
3024 cmp $ref $f || error "file data wrong after truncate"
3030 # test needs a running copytool
3035 local sz=$(stat -c %s /etc/passwd)
3037 echo "truncate up from $sz to $((sz*2))"
3038 truncate_released_file /etc/passwd $((sz*2))
3040 echo "truncate down from $sz to $((sz/2))"
3041 truncate_released_file /etc/passwd $((sz/2))
3043 echo "truncate to 0"
3044 truncate_released_file /etc/passwd 0
3046 run_test 58 "Truncate a released file will trigger restore"
3050 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3051 skip "Need MDS version at least 2.7.63"
3054 $MCREATE $DIR/$tfile || error "mcreate failed"
3055 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3056 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3057 fid=$(path2fid $DIR/$tfile)
3058 wait_request_state $fid ARCHIVE SUCCEED
3059 $LFS hsm_release $DIR/$tfile || error "release failed"
3061 run_test 59 "Release stripeless file with non-zero size"
3064 # This test validates the fix for LU-4512. Ensure that the -u
3065 # option changes the progress reporting interval from the
3066 # default (30 seconds) to the user-specified interval.
3067 local f=$DIR/$tdir/$tfile
3068 local fid=$(create_file "$f" 1M 10)
3071 local progress_timeout=$((interval * 4))
3072 copytool setup -b 1 --update-interval $interval
3075 local mdt=${MDT_PREFIX}${mdtidx}
3076 local mds=mds$((mdtidx + 1))
3078 # Wait for copytool to register
3079 wait_update_facet $mds \
3080 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3081 uuid 100 || error "coyptool failed to register with $mdt"
3083 local start_at=$(date +%s)
3084 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3085 error "could not archive file"
3087 local agent=$(facet_active_host $SINGLEAGT)
3088 local logfile=$(copytool_logfile $SINGLEAGT)
3090 wait_update $agent \
3091 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3092 error "copytool failed to start"
3094 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3095 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3101 echo -n "Expecting a progress update within $progress_timeout seconds... "
3103 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3104 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3105 echo "$RESULT bytes copied in $WAIT seconds."
3107 elif [ $WAIT -ge $progress_timeout ]; then
3108 error "Timed out waiting for progress update!"
3111 WAIT=$((WAIT + sleep))
3115 local finish_at=$(date +%s)
3116 local elapsed=$((finish_at - start_at))
3118 # Ensure that the progress update occurred within the expected window.
3119 if [ $elapsed -lt $((interval - 1)) ]; then
3120 error "Expected progress update after at least $interval seconds"
3123 echo "Wait for on going archive hsm action to complete"
3124 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3125 echo "File archiving not completed even after 10 secs"
3127 run_test 60 "Changing progress update interval from default"
3130 # test needs a running copytool
3134 local f=$DIR/$tdir/$tfile
3135 local fid=$(copy_file /etc/passwd $f)
3137 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3140 wait_request_state $fid ARCHIVE FAILED
3142 run_test 61 "Waiting archive of a removed file should fail"
3145 # test needs a new running copytool
3146 stack_trap copytool_monitor_cleanup EXIT
3147 copytool_monitor_setup
3148 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3150 # Wait for the copytool to register.
3151 wait_update --verbose $(facet_active_host mds1) \
3152 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3154 error "copytool failed to register with MDT0000"
3157 wait_copytools || error "Copytools failed to stop"
3159 local REGISTER_EVENT
3160 local UNREGISTER_EVENT
3161 while read event; do
3162 local parsed=$(parse_json_event "$event")
3163 if [ -z "$parsed" ]; then
3164 error "Copytool sent malformed event: $event"
3168 if [ $event_type == "REGISTER" ]; then
3169 REGISTER_EVENT=$event
3170 elif [ $event_type == "UNREGISTER" ]; then
3171 UNREGISTER_EVENT=$event
3173 done < <(echo $"$(get_copytool_event_log)")
3175 if [ -z "$REGISTER_EVENT" ]; then
3176 error "Copytool failed to send register event to FIFO"
3179 if [ -z "$UNREGISTER_EVENT" ]; then
3180 error "Copytool failed to send unregister event to FIFO"
3183 echo "Register/Unregister events look OK."
3185 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3188 # Bump progress interval for livelier events.
3191 # test needs a new running copytool
3192 stack_trap copytool_monitor_cleanup EXIT
3193 copytool_monitor_setup
3194 copytool setup --update-interval $interval --event-fifo \
3195 "$HSMTOOL_MONITOR_DIR/fifo"
3197 stack_trap "cdt_clear_no_retry" EXIT
3198 # Just start and stop the copytool to generate events.
3201 local f=$DIR/$tdir/$tfile
3202 local fid=$(create_small_file "$f")
3204 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3205 error "could not archive file"
3206 wait_request_state $fid ARCHIVE SUCCEED
3208 local expected_fields="event_time data_fid source_fid"
3209 expected_fields+=" total_bytes current_bytes"
3212 [ARCHIVE_START]=false
3213 [ARCHIVE_FINISH]=false
3214 [ARCHIVE_RUNNING]=false
3216 while read event; do
3217 # Make sure we're not getting anything from previous events.
3218 for field in $expected_fields; do
3222 local parsed=$(parse_json_event "$event")
3223 if [ -z "$parsed" ]; then
3224 error "Copytool sent malformed event: $event"
3228 events["$event_type"]=true
3230 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3232 # Do some simple checking of the progress update events.
3233 for expected_field in $expected_fields; do
3234 if [ -z ${!expected_field+x} ]; then
3235 error "Missing $expected_field field in event"
3239 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3241 # These should be identical throughout an archive operation
3242 [ $source_fid == $data_fid ] ||
3243 error "Expected source_fid to equal data_fid"
3244 done < <(echo $"$(get_copytool_event_log)")
3246 # Check we received every type of events we were expecting
3247 for event in "${!events[@]}"; do
3248 ${events["$event"]} ||
3249 error "Copytool failed to send '$event' event to FIFO"
3252 echo "Archive events look OK."
3254 run_test 71 "Copytool logs JSON archive events to FIFO"
3257 # Bump progress interval for livelier events.
3260 # test needs a new running copytool
3261 stack_trap copytool_monitor_cleanup EXIT
3262 copytool_monitor_setup
3263 copytool setup --update-interval $interval --event-fifo \
3264 "$HSMTOOL_MONITOR_DIR/fifo"
3265 local test_file=$HSMTOOL_MONITOR_DIR/file
3267 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3269 do_facet $SINGLEAGT "$cmd" ||
3270 error "cannot create $test_file on $SINGLEAGT"
3271 copy2archive $test_file $tdir/$tfile
3274 local f=$DIR/$tdir/$tfile
3275 copytool import $tdir/$tfile $f
3276 f=$DIR2/$tdir/$tfile
3277 echo "Verifying released state: "
3278 check_hsm_flags $f "0x0000000d"
3280 local fid=$(path2fid $f)
3282 wait_request_state $fid RESTORE SUCCEED
3284 local expected_fields="event_time data_fid source_fid"
3285 expected_fields+=" total_bytes current_bytes"
3289 while read event; do
3290 # Make sure we're not getting anything from previous events.
3291 for field in $expected_fields; do
3295 local parsed=$(parse_json_event "$event")
3296 if [ -z "$parsed" ]; then
3297 error "Copytool sent malformed event: $event"
3301 if [ $event_type == "RESTORE_START" ]; then
3303 if [ $source_fid != $data_fid ]; then
3304 error "source_fid should == data_fid at start"
3307 elif [ $event_type == "RESTORE_FINISH" ]; then
3309 if [ $source_fid != $data_fid ]; then
3310 error "source_fid should == data_fid at finish"
3313 elif [ $event_type != "RESTORE_RUNNING" ]; then
3317 # Do some simple checking of the progress update events.
3318 for expected_field in $expected_fields; do
3319 if [ -z ${!expected_field+x} ]; then
3320 error "Missing $expected_field field in event"
3324 if [ $total_bytes -eq 0 ]; then
3325 error "Expected total_bytes to be > 0"
3328 # When a restore starts out, the data fid is the same as the
3329 # source fid. After the restore has gotten going, we learn
3330 # the new data fid. Once the restore has finished, the source
3331 # fid is set to the new data fid.
3333 # We test this because some monitoring software may depend on
3334 # this behavior. If it changes, then the consumers of these
3335 # events may need to be modified.
3336 if [ $source_fid == $data_fid ]; then
3337 error "source_fid should != data_fid during restore"
3339 done < <(echo $"$(get_copytool_event_log)")
3341 if [ -z "$START_EVENT" ]; then
3342 error "Copytool failed to send restore start event to FIFO"
3345 if [ -z "$FINISH_EVENT" ]; then
3346 error "Copytool failed to send restore finish event to FIFO"
3349 echo "Restore events look OK."
3351 run_test 72 "Copytool logs JSON restore events to FIFO"
3354 file_count=51 # Max number of files constrained by LNET message size
3355 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3356 local f=$DIR/$tdir/$tfile
3357 local FILELIST=/tmp/filelist.txt
3361 for i in $(seq 1 $file_count); do
3362 fid=$(copy_file /etc/hosts $f.$i)
3363 echo $f.$i >> $FILELIST
3367 # to be sure wait_all_done will not be mislead by previous tests
3369 wait_for_grace_delay
3370 $LFS hsm_archive --filelist $FILELIST ||
3371 error "cannot archive a file list"
3373 $LFS hsm_release --filelist $FILELIST ||
3374 error "cannot release a file list"
3375 $LFS hsm_restore --filelist $FILELIST ||
3376 error "cannot restore a file list"
3379 run_test 90 "Archive/restore a file list"
3381 double_verify_reset_hsm_param() {
3383 echo "Testing $HSM_PARAM.$p"
3384 local val=$(get_hsm_param $p)
3386 local val2=$(($val * 2))
3387 set_hsm_param $p $val2
3388 val=$(get_hsm_param $p)
3389 [[ $val == $val2 ]] ||
3390 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3391 echo "Set $p to 0 must failed"
3395 set_hsm_param $p $save
3397 if [[ $rc == 0 ]]; then
3398 error "we must not be able to set $HSM_PARAM.$p to 0"
3403 double_verify_reset_hsm_param loop_period
3404 double_verify_reset_hsm_param grace_delay
3405 double_verify_reset_hsm_param active_request_timeout
3406 double_verify_reset_hsm_param max_requests
3407 double_verify_reset_hsm_param default_archive_id
3409 run_test 100 "Set coordinator /proc tunables"
3416 run_test 102 "Verify coordinator control"
3419 # test needs a running copytool
3426 for i in $(seq 1 20); do
3427 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3429 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3433 echo "Current requests"
3434 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3435 $HSM_PARAM.actions |\
3436 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3438 [[ -z "$res" ]] || error "Some request have not been canceled"
3440 run_test 103 "Purge all requests"
3445 local f=$DIR/$tdir/$tfile
3446 local fid=$(create_empty_file "$f")
3448 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3449 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3450 $HSM_PARAM.actions |\
3451 grep $fid | cut -f16 -d=")
3453 [[ "$data1" == "$DATAHEX" ]] ||
3454 error "Data field in records is ($data1) and not ($DATAHEX)"
3458 run_test 104 "Copy tool data field"
3461 local max_requests=$(get_hsm_param max_requests)
3465 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3466 set_hsm_param max_requests 300
3469 for i in $(seq -w 1 10); do
3470 cp /etc/passwd $DIR/$tdir/$i
3471 $LFS hsm_archive $DIR/$tdir/$i
3473 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3474 $HSM_PARAM.actions |\
3475 grep WAITING | wc -l")
3479 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3480 $HSM_PARAM.actions |\
3481 grep WAITING | wc -l")
3484 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3485 error "Requests count after shutdown $reqcnt2 != "\
3486 "before shutdown $reqcnt1"
3488 run_test 105 "Restart of coordinator"
3491 # test needs a running copytool
3494 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3496 check_agent_registered $uuid
3498 search_copytools || error "No copytool found"
3501 wait_copytools || error "Copytool failed to stop"
3503 check_agent_unregistered $uuid
3506 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3507 check_agent_registered $uuid
3509 run_test 106 "Copytool register/unregister"
3512 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3514 # test needs a running copytool
3516 # create and archive file
3518 local f1=$DIR/$tdir/$tfile
3519 local fid=$(copy_file /etc/passwd $f1)
3520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3521 wait_request_state $fid ARCHIVE SUCCEED
3522 # shutdown and restart MDS
3524 # check the copytool still gets messages from MDT
3525 local f2=$DIR/$tdir/2
3526 local fid=$(copy_file /etc/passwd $f2)
3527 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3528 # main check of this sanity: this request MUST succeed
3529 wait_request_state $fid ARCHIVE SUCCEED
3531 run_test 107 "Copytool re-register after MDS restart"
3533 policy_set_and_test()
3537 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3538 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3539 [[ "$policy" == "$target" ]] ||
3540 error "Wrong policy after '$change': '$policy' != '$target'"
3544 # to force default policy setting if error
3545 CDT_POLICY_HAD_CHANGED=true
3547 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3548 local default="NonBlockingRestore [NoRetryAction]"
3549 [[ "$policy" == "$default" ]] ||
3550 error "default policy has changed,"\
3551 " '$policy' != '$default' update the test"
3552 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3553 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3554 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3555 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3556 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3557 # useless bacause we know but safer for futur changes to use real value
3558 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3559 echo "Next set_param must failed"
3560 policy_set_and_test "wrong" "$policy"
3563 echo "Back to default policy"
3564 cdt_set_sanity_policy
3566 run_test 109 "Policy display/change"
3569 # test needs a running copytool
3574 copy2archive /etc/passwd $tdir/$tfile
3576 local f=$DIR/$tdir/$tfile
3577 copytool import $tdir/$tfile $f
3578 local fid=$(path2fid $f)
3580 cdt_set_non_blocking_restore
3585 wait_request_state $fid RESTORE SUCCEED
3586 cdt_clear_non_blocking_restore
3590 error "md5sum returns $st != 1, "\
3591 "should also perror ENODATA (No data available)"
3593 run_test 110a "Non blocking restore policy (import case)"
3596 # test needs a running copytool
3600 local f=$DIR/$tdir/$tfile
3601 local fid=$(copy_file /etc/passwd $f)
3602 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3603 wait_request_state $fid ARCHIVE SUCCEED
3606 cdt_set_non_blocking_restore
3611 wait_request_state $fid RESTORE SUCCEED
3612 cdt_clear_non_blocking_restore
3616 error "md5sum returns $st != 1, "\
3617 "should also perror ENODATA (No data available)"
3619 run_test 110b "Non blocking restore policy (release case)"
3622 # test needs a running copytool
3626 copy2archive /etc/passwd $tdir/$tfile
3628 local f=$DIR/$tdir/$tfile
3630 copytool import $tdir/$tfile $f
3631 local fid=$(path2fid $f)
3635 copytool_remove_backend $fid
3638 wait_request_state $fid RESTORE FAILED
3645 [[ $st == 0 ]] || error "Restore does not failed"
3647 run_test 111a "No retry policy (import 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)
3657 stack_trap cdt_clear_no_retry EXIT
3659 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3660 wait_request_state $fid ARCHIVE SUCCEED
3663 copytool_remove_backend $fid
3666 wait_request_state $fid RESTORE FAILED
3670 [[ $st == 0 ]] || error "Restore does not failed"
3672 run_test 111b "No retry policy (release case), restore will error"\
3673 " (No such file or directory)"
3676 # test needs a running copytool
3680 local f=$DIR/$tdir/$tfile
3681 local fid=$(copy_file /etc/passwd $f)
3683 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3684 local l=$($LFS hsm_action $f)
3686 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3689 wait_request_state $fid ARCHIVE SUCCEED
3692 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3694 run_test 112 "State of recorded request"
3697 local file1=$DIR/$tdir/$tfile
3698 local file2=$DIR2/$tdir/$tfile
3700 local fid=$(create_small_sync_file $file1)
3702 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3703 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3704 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3706 copytool setup -m "$MOUNT3"
3708 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3710 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3711 wait_request_state $fid ARCHIVE SUCCEED
3713 $LFS hsm_release $file1
3714 echo "Verifying released state: "
3715 check_hsm_flags $file1 "0x0000000d"
3717 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3720 kill -USR1 $MULTIPID
3725 local size1=$(stat -c "%s" $file1)
3726 local size2=$(stat -c "%s" $file2)
3728 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3730 run_test 113 "wrong stat after restore"
3733 local f=$DIR/$tdir/$tfile
3734 local fid=$(create_empty_file "$f")
3738 # Prevent archive from completing
3741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3742 # wait archive to register at CDT
3743 wait_request_state $fid ARCHIVE STARTED
3745 # Cancel the archive
3746 $LFS hsm_cancel "$f"
3748 wait_request_state $fid ARCHIVE CANCELED
3751 wait_request_state $fid CANCEL SUCCEED
3753 run_test 200 "Register/Cancel archive"
3756 # test needs a running copytool
3759 local f=$DIR/$tdir/$tfile
3760 create_archive_file $tdir/$tfile
3761 copytool import $tdir/$tfile $f
3762 local fid=$(path2fid $f)
3764 # test with cdt on is made in test_222
3767 # wait restore to register at CDT
3768 wait_request_state $fid RESTORE WAITING
3771 wait_request_state $fid RESTORE CANCELED
3772 wait_request_state $fid CANCEL SUCCEED
3774 run_test 201 "Register/Cancel restore"
3777 local f=$DIR/$tdir/$tfile
3778 local fid=$(create_empty_file "$f")
3780 # test needs a running copytool
3783 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3784 wait_request_state $fid ARCHIVE SUCCEED
3788 # wait remove to register at CDT
3789 wait_request_state $fid REMOVE STARTED
3792 wait_request_state $fid REMOVE CANCELED
3794 run_test 202 "Register/Cancel remove"
3796 test_220A() { # was test_220
3797 # test needs a running copytool
3802 local f=$DIR/$tdir/$tfile
3803 local fid=$(copy_file /etc/passwd $f)
3807 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3808 wait_request_state $fid ARCHIVE SUCCEED
3810 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3811 error "The expected changelog was not emitted"
3813 run_test 220A "Changelog for archive"
3816 # test needs a running copytool
3821 local f=$DIR/$tdir/$tfile
3822 local fid=$(copy_file /etc/passwd $f)
3826 # block copytool operations to allow for HSM request to be
3827 # submitted and file be unlinked (CDT will find object removed)
3830 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3832 # wait request to reach CT
3833 wait_request_state $fid ARCHIVE STARTED
3839 wait_request_state $fid ARCHIVE FAILED
3842 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3843 error "The expected changelog was not emitted"
3845 run_test 220a "Changelog for failed archive"
3848 local f=$DIR/$tdir/$tfile
3849 local fid=$(create_empty_file "$f")
3854 # Prevent archive from completing
3856 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3857 wait_request_state $fid ARCHIVE STARTED
3860 wait_request_state $fid ARCHIVE CANCELED
3863 wait_request_state $fid CANCEL SUCCEED
3865 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3866 error "The expected changelog was not emitted"
3868 run_test 221 "Changelog for archive canceled"
3871 # test needs a running copytool
3875 copy2archive /etc/passwd $tdir/$tfile
3877 local f=$DIR/$tdir/$tfile
3878 copytool import $tdir/$tfile $f
3879 local fid=$(path2fid $f)
3884 wait_request_state $fid RESTORE SUCCEED
3886 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3887 error "The expected changelog was not emitted"
3889 run_test 222a "Changelog for explicit restore"
3892 # test needs a running copytool
3896 local f=$DIR/$tdir/$tfile
3897 local fid=$(copy_file /etc/passwd $f)
3900 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3901 wait_request_state $fid ARCHIVE SUCCEED
3906 wait_request_state $fid RESTORE SUCCEED
3908 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3909 error "The expected changelog was not emitted"
3911 run_test 222b "Changelog for implicit restore"
3914 # test needs a running copytool
3918 copy2archive /etc/passwd $tdir/$tfile
3920 local f=$DIR/$tdir/$tfile
3921 copytool import $tdir/$tfile $f
3922 local fid=$(path2fid $f)
3926 # block copytool operations to allow for HSM request to be
3927 # submitted and file be unlinked (CDT will find object removed)
3932 # wait request to reach CT
3933 wait_request_state $fid RESTORE STARTED
3939 wait_request_state $fid RESTORE FAILED
3942 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3943 error "The expected changelog was not emitted"
3945 run_test 222c "Changelog for failed explicit restore"
3948 # test needs a running copytool
3952 local f=$DIR/$tdir/$tfile
3953 local fid=$(copy_file /etc/passwd $f)
3956 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3957 wait_request_state $fid ARCHIVE SUCCEED
3960 copytool_remove_backend $fid
3963 wait_request_state $fid RESTORE FAILED
3966 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3967 error "The expected changelog was not emitted"
3969 run_test 222d "Changelog for failed implicit restore"
3972 # test needs a running copytool
3975 local f=$DIR/$tdir/$tfile
3976 create_archive_file $tdir/$tfile
3980 copytool import $tdir/$tfile $f
3981 local fid=$(path2fid $f)
3984 wait_request_state $fid RESTORE STARTED
3986 wait_request_state $fid RESTORE CANCELED
3987 wait_request_state $fid CANCEL SUCCEED
3989 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3990 error "The expected changelog was not emitted"
3992 run_test 223a "Changelog for restore canceled (import case)"
3995 local f=$DIR/$tdir/$tfile
3996 local fid=$(create_empty_file "$f")
4001 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4002 wait_request_state $fid ARCHIVE SUCCEED
4005 # Prevent restore from completing
4008 wait_request_state $fid RESTORE STARTED
4011 wait_request_state $fid RESTORE CANCELED
4014 wait_request_state $fid CANCEL SUCCEED
4016 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4017 error "The expected changelog was not emitted"
4019 run_test 223b "Changelog for restore canceled (release case)"
4021 test_224A() { # was test_224
4022 # test needs a running copytool
4027 local f=$DIR/$tdir/$tfile
4028 local fid=$(copy_file /etc/passwd $f)
4031 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4032 wait_request_state $fid ARCHIVE SUCCEED
4035 wait_request_state $fid REMOVE SUCCEED
4037 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4038 error "The expected changelog was not emitted"
4040 run_test 224A "Changelog for remove"
4043 # test needs a running copytool
4048 local f=$DIR/$tdir/$tfile
4049 local fid=$(copy_file /etc/passwd $f)
4052 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4053 wait_request_state $fid ARCHIVE SUCCEED
4055 copytool_remove_backend $fid
4057 # block copytool operations to allow for HSM request to be
4058 # submitted and file be unlinked (CDT will find object removed)
4063 # wait for request to reach CT
4064 wait_request_state $fid REMOVE STARTED
4070 wait_request_state $fid REMOVE FAILED
4072 # HE_REMOVE|ENOENT=0x202
4073 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4074 error "The expected changelog was not emitted"
4076 run_test 224a "Changelog for failed remove"
4079 # test is not usable because remove request is too fast
4080 # so it is always finished before cancel can be done ...
4081 echo "Test disabled"
4084 # test needs a running copytool
4087 local f=$DIR/$tdir/$tfile
4088 local fid=$(create_empty_file "$f")
4091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4092 wait_request_state $fid ARCHIVE SUCCEED
4094 # Prevent restore from completing
4099 wait_request_state $fid REMOVE CANCELED
4102 wait_request_state $fid CANCEL SUCCEED
4104 changelog_find -type HSM -target-fid $fid -flags 0x27d
4105 error "The expected changelog was not emitted"
4107 run_test 225 "Changelog for remove canceled"
4110 # test needs a running copytool
4115 local f1=$DIR/$tdir/$tfile-1
4116 local f2=$DIR/$tdir/$tfile-2
4117 local f3=$DIR/$tdir/$tfile-3
4118 local fid1=$(copy_file /etc/passwd $f1)
4119 local fid2=$(copy_file /etc/passwd $f2)
4120 copy_file /etc/passwd $f3
4123 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4124 wait_request_state $fid1 ARCHIVE SUCCEED
4126 $LFS hsm_archive $f2
4127 wait_request_state $fid2 ARCHIVE SUCCEED
4129 rm $f1 || error "rm $f1 failed"
4132 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4133 error "The expected changelog was not emitted"
4135 mv $f3 $f2 || error "mv $f3 $f2 failed"
4137 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4138 error "The expected changelog was not emitted"
4140 run_test 226 "changelog for last rm/mv with exiting archive"
4142 # This is just a utility function to clarify what test_227 does
4147 "$LFS" "$action" --$flag "$file" ||
4148 error "Cannot ${action#hsm_} $flag on '$file'"
4150 # Only one changelog should be produced
4151 local entries="$(changelog_find -type HSM -target-fid $fid)"
4152 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4153 error "lfs $action --$flag '$file' produced more than one" \
4156 # Parse the last changelog record
4157 local entry="$(tail -n 1 <<< "$entries")"
4158 eval local -A changelog=$(changelog2array $entry)
4160 # Also check the flags match what is expected
4161 [[ ${changelog[flags]} == $target ]] ||
4162 error "Changelog flag is '${changelog[flags]}', not $target"
4166 local file="$DIR/$tdir/$tfile"
4167 local fid=$(create_empty_file "$file")
4172 for flag in norelease noarchive exists archived lost; do
4173 if [ "$flag" == lost ]; then
4174 # The flag "lost" only works on an archived file
4175 "$LFS" hsm_set --archived "$file"
4179 action="hsm_set" __test_227
4180 action="hsm_clear" __test_227
4183 run_test 227 "changelog when explicit setting of HSM flags"
4186 # test needs a running copytool
4189 local fid=$(create_small_sync_file $DIR/$tfile)
4190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4191 wait_request_state $fid ARCHIVE SUCCEED
4193 $LFS hsm_release $DIR/$tfile
4194 check_hsm_flags $DIR/$tfile "0x0000000d"
4196 filefrag $DIR/$tfile | grep " 1 extent found" ||
4197 error "filefrag on released file must return only one extent"
4199 # only newer versions of cp detect sparse files by stat/FIEMAP
4201 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4202 error "copying $DIR/$tfile"
4203 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4205 $LFS hsm_release $DIR/$tfile
4206 check_hsm_flags $DIR/$tfile "0x0000000d"
4208 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4210 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4212 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4213 error "comparing untarred $DIR/$tfile"
4215 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4216 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4218 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4221 local file="$DIR/$tdir/$tfile"
4223 # set max_requests to allow one request of each type to be started (3)
4225 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4226 set_hsm_param max_requests 3
4229 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4230 set_hsm_param loop_period 1
4232 # send 1 requests of each kind twice
4235 for action in archive restore remove; do
4236 local filepath="$file"-to-$action
4237 local fid=$(create_empty_file "$filepath")
4238 local fid2=$(create_empty_file "$filepath".bis)
4240 if [ "$action" != archive ]; then
4241 "$LFS" hsm_archive "$filepath"
4242 wait_request_state $fid ARCHIVE SUCCEED
4243 "$LFS" hsm_archive "$filepath".bis
4244 wait_request_state $fid2 ARCHIVE SUCCEED
4246 if [ "$action" == restore ]; then
4247 "$LFS" hsm_release "$filepath"
4248 "$LFS" hsm_release "$filepath".bis
4252 # suspend the copytool to prevent requests from completing
4253 stack_trap "copytool_continue" EXIT
4256 # send `max_requests' requests (one of each kind)
4257 for action in archive restore remove; do
4258 filepath="$file"-to-$action
4259 "$LFS" hsm_${action} "$filepath"
4260 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4263 # send another batch of requests
4264 for action in archive restore remove; do
4265 "$LFS" hsm_${action} "$file-to-$action".bis
4267 # wait for `loop_period' seconds to make sure the coordinator has time
4268 # to register those, even though it should not
4271 # only the first batch of request should be started
4273 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4277 error "expected 3 STARTED requests, found $count"
4279 run_test 250 "Coordinator max request"
4282 local f=$DIR/$tdir/$tfile
4283 local fid=$(create_empty_file "$f")
4286 # to have a short test
4287 local old_to=$(get_hsm_param active_request_timeout)
4288 set_hsm_param active_request_timeout 1
4289 # to be sure the cdt will wake up frequently so
4290 # it will be able to cancel the "old" request
4291 local old_loop=$(get_hsm_param loop_period)
4292 set_hsm_param loop_period 1
4297 # Prevent archive from completing
4299 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4300 wait_request_state $fid ARCHIVE STARTED
4302 # Let the request timeout
4303 wait_request_state $fid ARCHIVE CANCELED
4305 set_hsm_param active_request_timeout $old_to
4306 set_hsm_param loop_period $old_loop
4308 run_test 251 "Coordinator request timeout"
4311 local f=$DIR/$tdir/$tfile
4312 local fid=$(create_empty_file "$f")
4314 # to have a short test
4315 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4316 set_hsm_param loop_period 1
4320 # Prevent archive from completing
4322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4323 wait_request_state $fid ARCHIVE STARTED
4326 stack_trap "set_hsm_param active_request_timeout \
4327 $(get_hsm_param active_request_timeout)" EXIT
4328 set_hsm_param active_request_timeout 1
4330 wait_request_state $fid ARCHIVE CANCELED
4333 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4337 # test needs a running copytool
4341 local f=$DIR/$tdir/$tfile
4343 dd if=/dev/zero of=$f bs=1MB count=10
4344 local fid=$(path2fid $f)
4346 $LFS hsm_archive $f || error "could not archive file"
4347 wait_request_state $fid ARCHIVE SUCCEED
4349 # clear locks to discard inode data
4350 cancel_lru_locks osc
4352 #define OBD_FAIL_MDC_MERGE 0x807
4353 $LCTL set_param fail_loc=0x807
4355 #expect error here, instead of release with wrong size
4358 if ((rc == 0)); then
4359 file_size=$(stat -c '%s' $f)
4360 if ((file_size != 10485760)); then
4361 error "Wrong file size after hsm_release"
4364 echo "could not release file"
4367 run_test 253 "Check for wrong file size after release"
4371 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4372 skip "need MDS version at least 2.10.56"
4374 # Check that the counters are initialized to 0
4376 for request_type in archive restore remove; do
4377 count="$(get_hsm_param ${request_type}_count)" ||
4378 error "Reading ${request_type}_count failed with $?"
4380 [ "$count" -eq 0 ] ||
4381 error "Expected ${request_type}_count to be " \
4385 run_test 254a "Request counters are initialized to zero"
4389 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4390 skip "need MDS version at least 2.10.56"
4392 # The number of request to launch (at least 32)
4393 local request_count=$((RANDOM % 32 + 32))
4394 printf "Will launch %i requests of each type\n" "$request_count"
4396 # Launch a copytool to process requests
4399 # Set hsm.max_requests to allow starting all requests at the same time
4401 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4402 set_hsm_param max_requests "$request_count"
4406 for request_type in archive restore remove; do
4407 printf "Checking %s requests\n" "${request_type}"
4408 # Suspend the copytool to give us time to read the proc files
4411 for ((i = 0; i < $request_count; i++)); do
4412 case $request_type in
4414 create_empty_file "$DIR/$tdir/$tfile-$i" \
4418 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4421 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4424 # Give the coordinator 10 seconds to start every request
4426 while get_hsm_param actions | grep -q WAITING; do
4429 [ $timeout -gt 0 ] ||
4430 error "${request_type^} requests took too " \
4434 count="$(get_hsm_param ${request_type}_count)"
4435 [ "$count" -eq "$request_count" ] ||
4436 error "Expected '$request_count' (!= '$count') " \
4437 "active $request_type requests"
4439 # Let the copytool process the requests
4441 # Give it 10 seconds maximum
4443 while get_hsm_param actions | grep -q STARTED; do
4446 [ $timeout -gt 0 ] ||
4447 error "${request_type^} requests took too " \
4451 count="$(get_hsm_param ${request_type}_count)"
4452 [ "$count" -eq 0 ] ||
4453 error "Expected 0 (!= '$count') " \
4454 "active $request_type requests"
4457 run_test 254b "Request counters are correctly incremented and decremented"
4461 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4462 skip "Need MDS version at least 2.12.0"
4464 local file="$DIR/$tdir/$tfile"
4465 local fid=$(create_empty_file "$file")
4467 # How do you make sure the coordinator has consumed any outstanding
4468 # event, without triggering an event yourself?
4470 # You wait for a request to disappear from the coordinator's llog.
4472 # Warning: the setup represents 90% of this test
4474 # Create and process an HSM request
4476 "$LFS" hsm_archive "$file"
4477 wait_request_state $fid ARCHIVE SUCCEED
4480 wait_copytools || error "failed to stop copytools"
4482 # Launch a new HSM request
4484 create_empty_file "$file"
4485 "$LFS" hsm_archive "$file"
4489 # Have the completed request be removed as soon as the cdt wakes up
4490 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4491 set_hsm_param grace_delay 1
4492 # (Hopefully, time on the MDS will behave nicely)
4493 do_facet $SINGLEMDS sleep 2 &
4495 # Increase `loop_period' as a mean to prevent the coordinator from
4496 # waking itself up to do some housekeeping.
4497 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4498 set_hsm_param loop_period 1000
4500 wait $! || error "waiting failed"
4502 wait_request_state $fid ARCHIVE ""
4503 # The coordinator will not wake up on its own for ~`loop_period' secs...
4505 # ... Unless a copytool registers. Now the real test begins
4507 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4509 run_test 255 "Copytool registration wakes the coordinator up"
4511 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4512 # break in the future because of that.
4515 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4516 skip "need MDS version 2.11.56 or later"
4518 local -a files=("$DIR/$tdir/$tfile".{0..15})
4521 for file in "${files[@]}"; do
4522 create_small_file "$file"
4525 # Set a few hsm parameters
4527 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4528 set_hsm_param loop_period 1
4530 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4531 set_hsm_param max_requests 3
4535 "$LFS" hsm_archive "${files[0]}"
4536 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4537 "$LFS" hsm_release "${files[0]}"
4541 wait_copytools || error "copytools failed to stop"
4543 # Send several archive requests
4544 for file in "${files[@]:1}"; do
4545 "$LFS" hsm_archive "$file"
4548 # Send one restore request
4549 "$LFS" hsm_restore "${files[0]}"
4554 # Wait for all the requests to complete
4555 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4556 for file in "${files[@]:1}"; do
4557 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4560 # Collect the actions in the order in which the copytool processed them
4562 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4563 "$(copytool_logfile "$SINGLEAGT")")
4566 printf '%s\n' "${actions[@]}"
4569 for action in "${actions[@]:0:3}"; do
4570 [ "$action" == RESTORE ] && return
4573 error "Too many ARCHIVE requests were run before the RESTORE request"
4575 run_test 260a "Restore request have priority over other requests"
4577 # This test is very much tied to the implementation of the current priorisation
4578 # mechanism in the coordinator. It might not make sense to keep it in the future
4581 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4582 skip "need MDS version 2.11.56 or later"
4584 local -a files=("$DIR/$tdir/$tfile".{0..15})
4587 for file in "${files[@]}"; do
4588 create_small_file "$file"
4591 # Set a few hsm parameters
4593 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4594 set_hsm_param loop_period 1
4596 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4597 set_hsm_param max_requests 3
4600 copytool setup --archive-id 2
4601 "$LFS" hsm_archive --archive 2 "${files[0]}"
4602 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4603 "$LFS" hsm_release "${files[0]}"
4607 wait_copytools || error "copytools failed to stop"
4609 # Send several archive requests
4610 for file in "${files[@]:1}"; do
4611 "$LFS" hsm_archive "$file"
4614 # Send one restore request
4615 "$LFS" hsm_restore "${files[0]}"
4619 copytool setup --archive-id 2
4621 # Wait for all the requests to complete
4622 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4623 for file in "${files[@]:1}"; do
4624 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4627 # Collect the actions in the order in which the copytool processed them
4629 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4630 "$(copytool_logfile "$SINGLEAGT")")
4633 printf '%s\n' "${actions[@]}"
4636 for action in "${actions[@]:0:3}"; do
4637 [ "$action" == RESTORE ] && return
4640 error "Too many ARCHIVE requests were run before the RESTORE request"
4642 run_test 260b "Restore request have priority over other requests"
4644 # This test is very much tied to the implementation of the current priorisation
4645 # mechanism in the coordinator. It might not make sense to keep it in the future
4648 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4649 skip "Need MDS version at least 2.12.0"
4651 local -a files=("$DIR/$tdir/$tfile".{0..15})
4654 for file in "${files[@]}"; do
4655 create_small_file "$file"
4658 # Set a few hsm parameters
4660 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4661 set_hsm_param loop_period 1000
4663 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4664 set_hsm_param max_requests 3
4667 copytool setup --archive-id 2
4668 "$LFS" hsm_archive --archive 2 "${files[0]}"
4669 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4670 "$LFS" hsm_release "${files[0]}"
4674 wait_copytools || error "copytools failed to stop"
4676 # Force the next coordinator run to do housekeeping
4680 "$LFS" hsm_archive "${files[1]}"
4684 copytool setup --archive-id 2
4686 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4687 # The coordinator just did a housekeeping run it won't do another one
4688 # for around `loop_period' seconds => requests will not be reordered
4689 # if it costs too much (ie. when the coordinator has to discard a whole
4692 # Send several archive requests
4693 for file in "${files[@]:2}"; do
4694 "$LFS" hsm_archive "$file"
4697 # Send one restore request
4698 "$LFS" hsm_restore "${files[0]}"
4700 # Wait for all the requests to complete
4701 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4702 for file in "${files[@]:2}"; do
4703 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4706 # Collect the actions in the order in which the copytool processed them
4708 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4709 "$(copytool_logfile "$SINGLEAGT")")
4712 printf '%s\n' "${actions[@]}"
4715 for action in "${actions[@]:0:3}"; do
4716 [ "$action" == RESTORE ] &&
4717 error "Restore requests should not be prioritised" \
4718 "unless the coordinator is doing housekeeping"
4722 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4725 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4727 # the only way to test ondisk conf is to restart MDS ...
4728 echo "Stop coordinator and remove coordinator state at mount"
4731 # clean on disk conf set by default
4732 cdt_clear_mount_state
4733 cdt_check_state stopped
4735 # check cdt still off after umount/remount
4737 cdt_check_state stopped
4739 echo "Set coordinator start at mount, and start coordinator"
4740 cdt_set_mount_state enabled
4743 cdt_check_state enabled
4745 # check cdt still on after umount/remount
4747 cdt_check_state enabled
4749 # we are back to original state (cdt started at mount)
4751 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4754 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4756 local ai=$(get_hsm_param default_archive_id)
4757 local new=$((ai + 1))
4759 set_hsm_param default_archive_id $new -P
4761 local res=$(get_hsm_param default_archive_id)
4764 set_hsm_param default_archive_id "" "-P -d"
4766 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4768 run_test 301 "HSM tunnable are persistent"
4771 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4773 local ai=$(get_hsm_param default_archive_id)
4774 local new=$((ai + 1))
4779 set_hsm_param default_archive_id $new -P
4782 for mdtno in $(seq 1 $MDSCOUNT); do
4787 cdt_check_state enabled
4789 local res=$(get_hsm_param default_archive_id)
4792 set_hsm_param default_archive_id "" "-P -d"
4794 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4796 run_test 302 "HSM tunnable are persistent when CDT is off"
4799 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4805 local dir_mdt0=$DIR/$tdir/mdt0
4806 local dir_mdt1=$DIR/$tdir/mdt1
4808 # create 1 dir per MDT
4809 stack_trap "rm -rf $dir_mdt0" EXIT
4810 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4811 stack_trap "rm -rf $dir_mdt1" EXIT
4812 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4814 # create 1 file in each MDT
4815 local fid1=$(create_small_file $dir_mdt0/$tfile)
4816 local fid2=$(create_small_file $dir_mdt1/$tfile)
4818 # check that hsm request on mdt0 is sent to the right MDS
4819 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4820 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4821 echo "archive successful on mdt0"
4823 # check that hsm request on mdt1 is sent to the right MDS
4824 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4825 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4826 echo "archive successful on mdt1"
4828 run_test 400 "Single request is sent to the right MDT"
4831 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4837 local dir_mdt0=$DIR/$tdir/mdt0
4838 local dir_mdt1=$DIR/$tdir/mdt1
4840 # create 1 dir per MDT
4841 stack_trap "rm -rf $dir_mdt0" EXIT
4842 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4843 stack_trap "rm -rf $dir_mdt1" EXIT
4844 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4846 # create 1 file in each MDT
4847 local fid1=$(create_small_file $dir_mdt0/$tfile)
4848 local fid2=$(create_small_file $dir_mdt1/$tfile)
4850 # check that compound requests are shunt to the rights MDTs
4851 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4852 error "lfs hsm_archive"
4853 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4854 echo "archive successful on mdt0"
4855 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4856 echo "archive successful on mdt1"
4858 run_test 401 "Compound requests split and sent to their respective MDTs"
4860 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4865 local node=$(facet_active_host $facet)
4867 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4868 awk '{print $4}'); do
4869 echo "$3 $mdc on $node"
4870 do_facet $facet "$LCTL --device $mdc $state" || return 1
4875 # deactivate all mdc on agent1
4876 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4878 copytool setup --no-fail
4880 check_agent_unregistered "uuid" # match any agent
4882 # no expected running copytool
4883 search_copytools $agent && error "Copytool start should have failed"
4886 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4888 run_test 402a "Copytool start fails if all MDTs are inactive"
4895 local f=$DIR/$tdir/$tfile
4896 touch $f || error "touch $f failed"
4897 local fid=$(path2fid $f)
4899 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4900 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4901 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4903 # give time for CDT to send request and to keep it for retry
4904 wait_for_loop_period
4906 wait_request_state $fid ARCHIVE WAITING
4908 do_facet $SINGLEAGT lctl set_param fail_loc=0
4910 # request should succeed now
4911 wait_request_state $fid ARCHIVE SUCCEED
4913 run_test 402b "CDT must retry request upon slow start of CT"
4916 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4918 local agent=$(facet_active_host $SINGLEAGT)
4920 # deactivate all mdc for MDT0001
4921 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4924 local uuid=$(get_agent_uuid $agent)
4925 # check the agent is registered on MDT0000, and not on MDT0001
4926 check_agent_registered_by_mdt $uuid 0
4927 check_agent_unregistered_by_mdt $uuid 1
4929 # check running copytool process
4930 search_copytools $agent || error "No running copytools on $agent"
4932 # reactivate all mdc for MDT0001
4933 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4935 # make sure the copytool is now registered to all MDTs
4936 check_agent_registered $uuid
4938 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4941 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4945 # create files on both MDT0000 and MDT0001
4948 local dir_mdt0=$DIR/$tdir/mdt0
4949 stack_trap "rm -rf $dir_mdt0" EXIT
4950 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4952 # create 1 file on mdt0
4953 local fid1=$(create_small_file $dir_mdt0/$tfile)
4955 # deactivate all mdc for MDT0001
4956 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4958 # send an HSM request for files in MDT0000
4959 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4961 # check for completion of files in MDT0000
4962 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4963 echo "archive successful on mdt0"
4965 # reactivate all mdc for MDT0001
4966 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4968 run_test 404 "Inactive MDT does not block requests for active MDTs"
4971 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4977 local striped_dir=$DIR/$tdir/striped_dir
4979 # create striped dir on all of MDTs
4980 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4982 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4983 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4984 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4985 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4987 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4988 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4989 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4990 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4992 # check that compound requests are shunt to the rights MDTs
4993 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4994 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4995 error "lfs hsm_archive"
4997 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4998 echo "archive successful on $fid1"
4999 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5000 echo "archive successful on $fid2"
5001 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5002 echo "archive successful on $fid3"
5003 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5004 echo "archive successful on $fid4"
5006 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5007 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5008 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5009 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5011 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5012 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5013 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5014 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5016 run_test 405 "archive and release under striped directory"
5019 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5021 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5022 skip "need MDS version at least 2.7.64"
5027 fid=$(create_small_file $DIR/$tdir/$tfile)
5032 $LFS hsm_archive $DIR/$tdir/$tfile
5033 wait_request_state "$fid" ARCHIVE SUCCEED
5034 $LFS hsm_release $DIR/$tdir/$tfile
5036 # Should migrate $tdir but not $tfile.
5037 $LFS migrate -m1 $DIR/$tdir &&
5038 error "migrating HSM an archived file should fail"
5040 $LFS hsm_restore $DIR/$tdir/$tfile
5041 wait_request_state "$fid" RESTORE SUCCEED
5043 $LFS hsm_remove $DIR/$tdir/$tfile
5044 wait_request_state "$fid" REMOVE SUCCEED
5046 cat $DIR/$tdir/$tfile > /dev/null ||
5047 error "cannot read $DIR/$tdir/$tfile"
5049 $LFS migrate -m1 $DIR/$tdir ||
5050 error "cannot complete migration after HSM remove"
5052 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5053 if ((mdt_index != 1)); then
5054 error "expected MDT index 1, got $mdt_index"
5057 # Refresh fid after migration.
5058 fid=$(path2fid $DIR/$tdir/$tfile)
5061 $LFS hsm_archive $DIR/$tdir/$tfile
5062 wait_request_state "$fid" ARCHIVE SUCCEED 1
5064 lctl set_param debug=+trace
5065 $LFS hsm_release $DIR/$tdir/$tfile ||
5066 error "cannot release $DIR/$tdir/$tfile"
5068 $LFS hsm_restore $DIR/$tdir/$tfile
5069 wait_request_state "$fid" RESTORE SUCCEED 1
5071 cat $DIR/$tdir/$tfile > /dev/null ||
5072 error "cannot read $DIR/$tdir/$tfile"
5074 run_test 406 "attempting to migrate HSM archived files is safe"
5077 local f=$DIR/$tdir/$tfile
5078 local f2=$DIR2/$tdir/$tfile
5079 local fid=$(create_empty_file "$f")
5083 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5084 wait_request_state $fid ARCHIVE SUCCEED
5087 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5088 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5090 # Prevent restore from completing
5094 # 1st request holds layout lock while appropriate
5095 # RESTORE record is still not added to llog
5099 # after umount hsm_actions->O/x/x log shouldn't have
5100 # double RESTORE records like below
5101 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5102 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5104 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5108 wait_request_state $fid RESTORE SUCCEED
5110 run_test 407 "Check for double RESTORE records in llog"
5114 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5115 skip "HSM migrate is not supported"
5117 test_mkdir -p $DIR/$tdir
5119 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5120 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5122 llapi_hsm_test -d $DIR/$tdir -b ||
5123 error "One llapi HSM test failed"
5125 llapi_hsm_test -d $DIR/$tdir ||
5126 error "One llapi HSM test failed"
5129 run_test 500 "various LLAPI HSM tests"
5132 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5133 skip "need MDS version at least 2.10.58"
5137 local f=$DIR/$tdir/$tfile
5140 # set changelog_mask to ALL
5141 changelog_chmask "ALL"
5143 chmod 777 $DIR/$tdir
5144 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5145 local fid=$(path2fid $f)
5148 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5149 -gid "$RUNAS_GID") ||
5150 error "No matching CREAT entry"
5152 # Parse the changelog
5153 eval local -A changelog=$(changelog2array $entry)
5154 local nid="${changelog[nid]}"
5157 echo "Got NID '$nid'"
5158 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5159 error "nid '$nid' does not match any client NID:" \
5162 run_test 600 "Changelog fields 'u=' and 'nid='"
5165 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5166 skip "need MDS version at least 2.10.58"
5170 local f=$DIR/$tdir/$tfile
5173 # set changelog_mask to ALL
5174 changelog_chmask "ALL"
5176 touch $f || error "touch $f failed"
5177 local fid=$(path2fid $f)
5180 cat $f || error "cat $f failed"
5182 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5183 error "No matching OPEN entry"
5185 run_test 601 "OPEN Changelog entry"
5188 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5189 skip "need MDS version at least 2.10.58"
5193 local f=$DIR/$tdir/$tfile
5196 # set changelog_mask to ALL
5197 changelog_chmask "ALL"
5199 touch $f || error "touch $f failed"
5200 local fid=$(path2fid $f)
5203 cat $f || error "cat $f failed"
5205 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5209 echo f > $f || error "write $f failed"
5212 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5214 # remove OPEN from changelog_mask
5215 changelog_chmask "-OPEN"
5219 cat $f || error "cat $f failed"
5222 changelog_find -type CLOSE -target-fid $fid &&
5223 error "There should be no CLOSE entry"
5227 echo f > $f || error "write $f failed"
5230 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5232 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5235 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5236 skip "need MDS version at least 2.10.58"
5240 local f=$DIR/$tdir/$tfile
5243 # set changelog_mask to ALL
5244 changelog_chmask "ALL"
5246 touch $f || error "touch $f failed"
5247 local fid=$(path2fid $f)
5249 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5252 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5254 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5255 error "No matching GXATR entry"
5257 run_test 603 "GETXATTR Changelog entry"
5260 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5261 skip "need MDS version at least 2.10.58"
5265 local f=$DIR/$tdir/$tfile
5266 local f2=$DIR2/$tdir/$tfile
5267 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5269 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5270 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5271 do_facet mds1 lctl set_param "$procname=20"
5275 # set changelog_mask to ALL
5276 changelog_chmask "ALL"
5278 touch $f || error "touch $f failed"
5279 local fid=$(path2fid $f)
5285 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5289 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5290 -gid "$RUNAS_GID" -mode "r--") ||
5291 error "No matching NOPEN entry"
5293 # Parse the changelog
5294 eval local -A changelog=$(changelog2array $entry)
5295 local nid="${changelog[nid]}"
5298 echo "Got NID '$nid'"
5299 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5300 error "nid '$nid' does not match any client NID:" \
5305 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5308 changelog_find -type NOPEN -target-fid $fid &&
5309 error "There should be no NOPEN entry"
5311 # Sleep for `changelog_deniednext` seconds
5316 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5319 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5320 -gid "$RUNAS_GID" -mode "r--") ||
5321 error "No matching NOPEN entry"
5323 # Parse the changelog
5324 eval local -A changelog=$(changelog2array $entry)
5325 local nid="${changelog[nid]}"
5328 echo "Got NID '$nid'"
5329 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5330 error "nid '$nid' does not match any client NID:" \
5333 run_test 604 "NOPEN Changelog entry"
5336 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5337 skip "need MDS version at least 2.10.58"
5341 local f=$DIR/$tdir/$tfile
5342 local f2=$DIR2/$tdir/$tfile
5345 # set changelog_mask to ALL
5346 changelog_chmask "ALL"
5348 touch $f || error "touch $f failed"
5349 local fid=$(path2fid $f)
5353 exec 3<> $f || error "open $f failed"
5357 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
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 in rw, so different access mode should generate entries
5376 cat $f || error "cat $f 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 # same access as first one, should not generate new entries
5386 exec 4<> $f || error "open $f failed"
5389 changelog_find -type OPEN -target-fid $fid &&
5390 error "There should be no OPEN entry"
5392 exec 4>&- || error "close $f failed"
5395 changelog_find -type CLOSE -target-fid $fid &&
5396 error "There should be no CLOSE entry"
5400 # access by different user should generate new entries
5401 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5404 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5406 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5410 exec 3>&- || error "close $f failed"
5413 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5415 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5418 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5419 skip "need MDS version at least 2.10.58"
5421 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5422 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5423 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5424 skip_env "missing llog_reader" && return
5425 local fstype=$(facet_fstype mds1)
5429 local f=$DIR/$tdir/$tfile
5432 # set changelog_mask to ALL
5433 changelog_chmask "ALL"
5435 chmod 777 $DIR/$tdir
5436 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5437 local fid=$(path2fid $f)
5438 rm $f || error "rm $f failed"
5440 local mntpt=$(facet_mntpt mds1)
5444 #remount mds1 as ldiskfs or zfs type
5445 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5446 stop mds1 || error "stop mds1 failed"
5447 mount_fstype mds1 || error "remount mds1 failed"
5449 for ((i = 0; i < 1; i++)); do
5450 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5451 local cat_file=$(do_facet mds1 $llog_reader \
5452 $mntpt/changelog_catalog | awk \
5453 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5454 [ -n "$cat_file" ] || error "no catalog file"
5456 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5457 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5458 [ -n "$entry" ] || error "no CREAT entry"
5461 local uidgid=$(echo $entry |
5462 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5463 [ -n "$uidgid" ] || error "uidgid is empty"
5464 echo "Got UID/GID $uidgid"
5465 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5466 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5467 local nid=$(echo $entry |
5468 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5469 [ -n "$nid" ] || error "nid is empty"
5471 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5472 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5474 run_test 606 "llog_reader groks changelog fields"
5477 check_and_cleanup_lustre