3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
12 LUSTRE=${LUSTRE:-$(dirname $0)/..}
13 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT "
19 # bug number for skipped tests: LU-9795 LU-9795
20 ALWAYS_EXCEPT+=" 13 402b"
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
26 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
28 OPENFILE=${OPENFILE:-openfile}
29 MMAP_CAT=${MMAP_CAT:-mmap_cat}
30 MOUNT_2=${MOUNT_2:-"yes"}
33 # script only handles up to 10 MDTs (because of MDT_PREFIX)
34 [ $MDSCOUNT -gt 9 ] &&
35 error "script cannot handle more than 9 MDTs, please fix"
37 check_and_setup_lustre
39 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
40 skip_env "Need MDS version at least 2.4.53"
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
48 if getent group nobody; then
50 elif getent group nogroup; then
53 error "No generic nobody group"
56 # if there is no CLIENT1 defined, some tests can be ran on localhost
57 CLIENT1=${CLIENT1:-$HOSTNAME}
58 # if CLIENT2 doesn't exist then use CLIENT1 instead
59 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
61 # Exception is the test which need two separate nodes
62 CLIENT2=${CLIENT2:-$CLIENT1}
65 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
66 # the following associated variables are added:
68 # AGTCOUNT: number of agents
69 # AGTDEV{N}: target HSM mount point (root path of the backend)
70 # agt{N}_HOST: hostname of the agent agt{N}
71 # SINGLEAGT: facet of the single agent
73 # The number of agents is initialized as the number of remote client nodes.
74 # By default, only single copytool is started on a remote client/agent. If there
75 # was no remote client, then the copytool will be started on the local client.
81 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
82 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
84 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
85 if [[ $CLIENTCOUNT -gt 1 ]] &&
86 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
87 skip_env "SHARED_DIRECTORY should be accessible"\
92 # We used to put the HSM archive in $SHARED_DIRECTORY but that
93 # meant NFS issues could hose sanity-hsm sessions. So now we
95 for n in $(seq $AGTCOUNT); do
96 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
97 agent=CLIENT$((n + 1))
98 if [[ -z "${!agent}" ]]; then
99 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
102 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
105 export SINGLEAGT=${SINGLEAGT:-agt1}
107 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
108 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
109 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
110 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
111 export HSMTOOL_TESTDIR
115 # The test only support up to 10 MDTs
116 MDT_PREFIX="mdt.$FSNAME-MDT000"
117 HSM_PARAM="${MDT_PREFIX}0.hsm"
119 # archive is purged at copytool setup
120 HSM_ARCHIVE_PURGE=true
122 # Don't allow copytool error upon start/setup
123 HSMTOOL_NOERROR=false
126 # Get the backend root path for the given agent facet.
129 local dev=AGTDEV$(facet_number $facet)
136 # get MDT device for each mdc
137 for mdtno in $(seq 1 $MDSCOUNT); do
138 local idx=$(($mdtno - 1))
139 MDT[$idx]=$($LCTL get_param -n \
140 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
141 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
146 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
147 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
151 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
153 echo "Killing existing copytools on $hosts"
154 do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
155 copytool_continue "$hosts"
159 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
160 local wait_timeout=200
161 local wait_start=$SECONDS
162 local wait_end=$((wait_start + wait_timeout))
163 local sleep_time=100000 # 0.1 second
165 while ((SECONDS < wait_end)); do
166 if ! search_copytools $hosts; then
167 echo "copytools stopped in $((SECONDS - wait_start))s"
171 echo "copytools still running on $hosts"
173 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
174 sleep_time=$(bc <<< "$sleep_time * 2")
177 # try to dump Copytool's stack
178 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
179 "echo t >/proc/sysrq-trigger"
181 echo "copytools failed to stop in ${wait_timeout}s"
186 copytool_monitor_setup() {
187 local facet=${1:-$SINGLEAGT}
188 local agent=$(facet_active_host $facet)
190 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
191 local test_dir=$(do_node $agent "$cmd") ||
192 error "Failed to create tempdir on $agent"
193 export HSMTOOL_MONITOR_DIR=$test_dir
195 # Create the fifo and a monitor (cat dies when copytool dies)
196 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
197 error "failed to create copytool fifo on $agent"
198 cmd="cat $test_dir/fifo > $test_dir/events &"
199 cmd+=" echo \\\$! > $test_dir/monitor_pid"
201 if [[ $PDSH == *Rmrsh* ]]; then
202 # This is required for pdsh -Rmrsh and its handling of remote
204 # Regular ssh and pdsh -Rssh work fine without this
205 # backgrounded subshell nonsense.
206 (do_node $agent "$cmd") &
207 export HSMTOOL_MONITOR_PDSH=$!
209 # Slightly racy, but just making a best-effort to catch obvious
212 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
213 error "Failed to start copytool monitor on $agent"
215 do_node $agent "$cmd"
217 error "Failed to start copytool monitor on $agent"
228 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
233 get_copytool_event_log() {
234 local facet=${1:-$SINGLEAGT}
235 local agent=$(facet_active_host $facet)
237 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
238 error "Can't get event log: No monitor directory!"
240 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
241 error "Could not collect event log from $agent"
245 local agents=${1:-$(facet_active_host $SINGLEAGT)}
248 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
249 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
250 echo "Copytool is suspended on $agents"
253 copytool_continue() {
254 local agents=${1:-$(facet_active_host $SINGLEAGT)}
256 do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
257 echo "Copytool is continued on $agents"
260 copytool_remove_backend() {
262 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
263 echo "Remove from backend: $fid = $be"
264 do_facet $SINGLEAGT rm -f $be
267 file_creation_failure() {
274 df $MOUNT $MOUNT2 >&2
275 error "Not enough space to create $file with $cmd"
278 error "cannot create $file with $cmd, status=$err"
283 # Creates a file using dd
289 local source=${5:-/dev/zero}
293 if [ -n "$conv" ]; then
297 # Create the directory in case it does not exist
298 mkdir -p "$(dirname "$file")"
299 # Delete the file in case it already exist
302 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
303 path2fid "$file" || error "cannot get FID of '$file'"
306 echo "cannot create file '$file'" >&2;
307 # Let the caller decide what to do on error
312 create_empty_file() {
313 create_file "${1/$DIR/$DIR2}" 1M 0 ||
314 file_creation_failure dd "${1/$DIR/$DIR2}" $?
317 create_small_file() {
318 local source_file=/dev/urandom
321 local conv=${2:-fsync}
323 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
324 file_creation_failure dd "${1/$DIR/$DIR2}" $?
327 create_small_sync_file() {
328 create_small_file "$1" sync
331 create_archive_file() {
332 local file="$(hsm_root)/$1"
334 local source=/dev/urandom
336 # Create the counterpart directory of the archive
337 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
338 error "cannot create archive directory '$(dirname "$file")'"
340 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
341 error "cannot create archive file '$file'"
345 local hsm_root="$(hsm_root)"
346 local file="$hsm_root/$2"
348 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
349 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
350 error "mkdir '$(dirname "$file")' failed"
351 do_facet $SINGLEAGT cp -p "$1" "$file" ||
352 error "cannot copy '$1' to '$file'"
357 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
364 mdts_set_param "" hsm_control "$cmd"
365 mdts_check_param hsm_control "$target" 10
370 mdts_set_param "" hsm.policy "+NRA"
371 CDT_POLICY_HAD_CHANGED=true
374 cdt_clear_no_retry() {
375 mdts_set_param "" hsm.policy "-NRA"
376 CDT_POLICY_HAD_CHANGED=true
379 cdt_set_non_blocking_restore() {
380 mdts_set_param "" hsm.policy "+NBR"
381 CDT_POLICY_HAD_CHANGED=true
384 cdt_clear_non_blocking_restore() {
385 mdts_set_param "" hsm.policy "-NBR"
386 CDT_POLICY_HAD_CHANGED=true
389 cdt_clear_mount_state() {
390 mdts_set_param "-P -d" hsm_control ""
394 set_test_state disabled disabled
398 set_test_state enabled enabled
402 set_test_state shutdown stopped
406 set_test_state purge enabled
412 cdt_set_sanity_policy
416 get_hsm_archive_id() {
419 st=$($LFS hsm_state $f)
420 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
422 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
426 check_hsm_flags_user() {
430 local st=$(get_hsm_flags $f user)
431 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
443 if [[ "$3" != 1 ]]; then
447 cp $1 $f || file_creation_failure cp $f $?
449 path2fid $f || error "cannot get fid on $f"
452 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
454 # Note that this might lead to surprising behaviours such as deleting an
455 # important file for the currently running test
456 delete_large_files() {
457 printf "Deleting large files...\n" >&2
458 find $MOUNT -size +10M -delete
459 wait_delete_completed
462 get_request_state() {
466 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
467 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
470 get_request_count() {
474 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
475 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
478 # Ensure the number of HSM request for a given FID is correct
479 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
480 assert_request_count() {
481 local request_count=$(get_request_count $1 $2)
482 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
484 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
491 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
492 [[ -n $fid ]] && cmd+=" | grep '$fid'"
493 cmd+=" | egrep 'WAITING|STARTED'"
495 wait_result $SINGLEMDS "$cmd" "" $timeout ||
496 error "requests did not complete"
499 wait_for_grace_delay() {
500 local val=$(get_hsm_param grace_delay)
504 wait_for_loop_period() {
505 local val=$(get_hsm_param loop_period)
512 # python2.6 in EL6 includes an internal json module
513 local json_parser='import json; import fileinput;'
514 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
515 json_parser+='json.loads([line for line in '
516 json_parser+='fileinput.input()][0]).items()])'
518 echo $raw_event | python -c "$json_parser"
521 get_agent_by_uuid_mdt() {
524 local mds=mds$(($mdtidx + 1))
525 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
529 check_agent_registered_by_mdt() {
532 local mds=mds$(($mdtidx + 1))
533 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
534 if [[ ! -z "$agent" ]]; then
535 echo "found agent $agent on $mds"
537 error "uuid $uuid not found in agent list on $mds"
541 check_agent_unregistered_by_mdt() {
544 local mds=mds$(($mdtidx + 1))
545 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
546 if [[ -z "$agent" ]]; then
547 echo "uuid not found in agent list on $mds"
549 error "uuid found in agent list on $mds: $agent"
553 check_agent_registered() {
556 for mdsno in $(seq 1 $MDSCOUNT); do
557 check_agent_registered_by_mdt $uuid $((mdsno - 1))
561 check_agent_unregistered() {
564 for mdsno in $(seq 1 $MDSCOUNT); do
565 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
570 local agent=${1:-$(facet_active_host $SINGLEAGT)}
572 # Lustre mount-point is mandatory and last parameter on
574 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
576 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
578 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
584 # populate MDT device array
587 # cleanup from previous bad setup
590 # for recovery tests, coordinator needs to be started at mount
592 # the lustre conf must be without hsm on (like for sanity.sh)
593 echo "Set HSM on and start"
594 cdt_set_mount_state enabled
595 cdt_check_state enabled
597 echo "Set sanity-hsm HSM policy"
598 cdt_set_sanity_policy
600 # finished requests are quickly removed from list
601 set_hsm_param grace_delay 10
603 CLIENT_NIDS=( $($LCTL list_nids all) )
605 test_1A() { # was test_1
609 local f=$DIR/$tdir/$tfile
613 check_hsm_flags_user $f "0x00000000"
615 $RUNAS $LFS hsm_set --norelease $f ||
616 error "user could not change hsm flags"
617 check_hsm_flags_user $f "0x00000010"
619 $RUNAS $LFS hsm_clear --norelease $f ||
620 error "user could not clear hsm flags"
621 check_hsm_flags_user $f "0x00000000"
623 # User could not change those flags...
624 $RUNAS $LFS hsm_set --exists $f &&
625 error "user should not set this flag"
626 check_hsm_flags_user $f "0x00000000"
629 $LFS hsm_set --exists $f ||
630 error "root could not change hsm flags"
631 check_hsm_flags_user $f "0x00000001"
633 $LFS hsm_clear --exists $f ||
634 error "root could not clear hsm state"
635 check_hsm_flags_user $f "0x00000000"
638 run_test 1A "lfs hsm flags root/non-root access"
641 local f=$DIR/$tdir/$tfile
642 local fid=$(create_small_file $f)
646 $LFS hsm_archive $f || error "could not archive file"
647 wait_request_state $fid ARCHIVE SUCCEED
649 # Release and check states
650 $LFS hsm_release $f || error "could not release file"
651 echo -n "Verifying released state: "
652 check_hsm_flags $f "0x0000000d"
654 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
656 run_test 1a "mmap & cat a HSM released file"
662 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
663 error "failed to create file"
664 local fid=$(path2fid $f)
669 $LFS hsm_archive $f || error "could not archive file"
670 wait_request_state $fid ARCHIVE SUCCEED
673 $LFS hsm_release $f || error "could not release file"
674 echo "verify released state: "
675 check_hsm_flags $f "0x0000000d" && echo "pass"
678 $LFS hsm_restore $f || error "could not restore file"
679 wait_request_state $fid RESTORE SUCCEED
680 echo "verify restored state: "
681 check_hsm_flags $f "0x00000009" && echo "pass"
686 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
687 error "failed to set default stripe"
688 local f=$DIR/$tdir/$tfile
692 run_test 1b "Archive, Release and Restore composite file"
698 local f=$DIR/$tdir/$tfile
701 # Test whether we can set the maximum archive number.
702 local LOCAL_HSM_ARCHIVE_NUMBER=32
703 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
704 error "root could not change hsm flags"
705 check_hsm_flags_user $f "0x00000001"
706 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
707 local st=$(get_hsm_archive_id $f)
708 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
709 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
711 # Test whether setting archive number 0 results in no change.
712 $LFS hsm_set --exists --archive-id 0 $f ||
713 error "root could not change hsm flags"
714 check_hsm_flags_user $f "0x00000001"
715 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
716 st=$(get_hsm_archive_id $f)
717 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
718 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
720 LOCAL_HSM_ARCHIVE_NUMBER=33
721 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
722 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
723 # lustre in the new version supports unlimited archiveID.
724 # Test whether setting archive number > 32 is supported
725 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
726 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
727 check_hsm_flags_user $f "0x00000001"
729 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
730 st=$(get_hsm_archive_id $f)
731 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
732 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
734 # old client or old mds can only support at most 32 archiveID
735 # test whether setting archive number > 32 results in error.
736 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
737 error "bitmap archive number is larger than 32"
738 check_hsm_flags_user $f "0x00000001"
741 # Test whether setting archive number 16 and archived flag.
742 LOCAL_HSM_ARCHIVE_NUMBER=16
743 $LFS hsm_set --exists --archived \
744 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
745 error "root could not change hsm flags"
746 check_hsm_flags_user $f "0x00000009"
747 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
748 st=$(get_hsm_archive_id $f)
749 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
750 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
752 run_test 1c "Check setting archive-id in lfs hsm_set"
755 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
756 skip "need MDS version at least 2.10.59"
759 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
760 error "failed to set default stripe"
761 local f=$DIR/$tdir/$tfile
765 run_test 1d "Archive, Release and Restore DoM file"
768 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
769 skip "skipped for lustre < $SEL_VER"
772 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
773 error "failed to set default stripe"
774 local comp_file=$DIR/$tdir/$tfile
776 test_1bde_base $comp_file
778 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
779 local found=$($LFS find $flg_opts $comp_file | wc -l)
780 [ $found -eq 1 ] || error "1st component not found"
782 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
783 found=$($LFS find $flg_opts $comp_file | wc -l)
784 [ $found -eq 1 ] || error "2nd component not found"
786 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
787 found=$($LFS find $flg_opts $comp_file | wc -l)
788 [ $found -eq 1 ] || error "3rd component not found"
790 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
791 found=$($LFS find $flg_opts $comp_file | wc -l)
792 [ $found -eq 1 ] || error "4th component not found"
794 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
795 found=$($LFS find $flg_opts $comp_file | wc -l)
796 [ $found -eq 1 ] || error "5th component not found"
798 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
799 found=$($LFS find $flg_opts $comp_file | wc -l)
800 [ $found -eq 1 ] || error "6th component not found"
802 sel_layout_sanity $comp_file 6
804 run_test 1e "Archive, Release and Restore SEL file"
807 local f=$DIR/$tdir/$tfile
809 create_empty_file "$f"
810 # New files are not dirty
811 check_hsm_flags $f "0x00000000"
813 # For test, we simulate an archived file.
814 $LFS hsm_set --exists $f || error "user could not change hsm flags"
815 check_hsm_flags $f "0x00000001"
817 # chmod do not put the file dirty
818 chmod 600 $f || error "could not chmod test file"
819 check_hsm_flags $f "0x00000001"
821 # chown do not put the file dirty
822 chown $RUNAS_ID $f || error "could not chown test file"
823 check_hsm_flags $f "0x00000001"
825 # truncate put the file dirty
826 $TRUNCATE $f 1 || error "could not truncate test file"
827 check_hsm_flags $f "0x00000003"
829 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
830 check_hsm_flags $f "0x00000001"
832 run_test 2 "Check file dirtyness when doing setattr"
838 # New files are not dirty
840 check_hsm_flags $f "0x00000000"
842 # For test, we simulate an archived file.
843 $LFS hsm_set --exists $f ||
844 error "user could not change hsm flags"
845 check_hsm_flags $f "0x00000001"
847 # Reading a file, does not set dirty
848 cat $f > /dev/null || error "could not read file"
849 check_hsm_flags $f "0x00000001"
851 # Open for write without modifying data, does not set dirty
852 openfile -f O_WRONLY $f || error "could not open test file"
853 check_hsm_flags $f "0x00000001"
855 # Append to a file sets it dirty
856 cp -p /etc/passwd $f.append || error "could not create file"
857 $LFS hsm_set --exists $f.append ||
858 error "user could not change hsm flags"
859 dd if=/etc/passwd of=$f.append bs=1 count=3\
860 conv=notrunc oflag=append status=noxfer ||
861 file_creation_failure dd $f.append $?
862 check_hsm_flags $f.append "0x00000003"
864 # Modify a file sets it dirty
865 cp -p /etc/passwd $f.modify || error "could not create file"
866 $LFS hsm_set --exists $f.modify ||
867 error "user could not change hsm flags"
868 dd if=/dev/zero of=$f.modify bs=1 count=3\
869 conv=notrunc status=noxfer ||
870 file_creation_failure dd $f.modify $?
871 check_hsm_flags $f.modify "0x00000003"
873 # Open O_TRUNC sets dirty
874 cp -p /etc/passwd $f.trunc || error "could not create file"
875 $LFS hsm_set --exists $f.trunc ||
876 error "user could not change hsm flags"
877 cp /etc/group $f.trunc || error "could not override a file"
878 check_hsm_flags $f.trunc "0x00000003"
880 # Mmapped a file sets dirty
881 cp -p /etc/passwd $f.mmap || error "could not create file"
882 $LFS hsm_set --exists $f.mmap ||
883 error "user could not change hsm flags"
884 multiop $f.mmap OSMWUc || error "could not mmap a file"
885 check_hsm_flags $f.mmap "0x00000003"
887 run_test 3 "Check file dirtyness when opening for write"
890 local f=$DIR/$tdir/$tfile
891 local fid=$(create_small_file $f)
894 local st=$(get_request_state $fid CANCEL)
895 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
897 run_test 4 "Useless cancel must not be registered"
900 # test needs a running copytool
904 local f=$DIR/$tdir/$tfile
905 local fid=$(copy_file /etc/passwd $f)
907 wait_request_state $fid ARCHIVE SUCCEED
909 check_hsm_flags $f "0x00000009"
911 run_test 8 "Test default archive number"
913 test_9A() { # was test_9
914 # we do not use the default one to be sure
915 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
916 copytool setup --archive-id $archive_id
918 # give time for CT to register with MDTs
919 sleep $(($MDSCOUNT*2))
920 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
921 check_agent_registered $uuid
924 local f=$DIR/$tdir/$tfile
925 local fid=$(copy_file /etc/passwd $f)
926 $LFS hsm_archive --archive $archive_id $f
927 wait_request_state $fid ARCHIVE SUCCEED
929 check_hsm_flags $f "0x00000009"
931 run_test 9A "Use of explicit archive number, with dedicated copytool"
934 needclients 3 || return 0
940 # start all of the copytools
941 for n in $(seq $AGTCOUNT); do
942 copytool setup --facet agt$n
946 for n in $(seq $AGTCOUNT); do
947 file=$DIR/$tdir/$tfile.$n
948 fid=$(create_small_file $file)
950 $LFS hsm_archive $file || error "could not archive file $file"
951 wait_request_state $fid ARCHIVE SUCCEED
952 check_hsm_flags $file "0x00000009"
955 run_test 9a "Multiple remote agents"
958 # test needs a running copytool
961 mkdir -p $DIR/$tdir/d1
962 local f=$DIR/$tdir/$tfile
963 local fid=$(copy_file /etc/hosts $f)
964 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
965 error "hsm_archive failed"
966 wait_request_state $fid ARCHIVE SUCCEED
968 local hsm_root="$(copytool_device $SINGLEAGT)"
969 local archive="$(do_facet $SINGLEAGT \
970 find "$hsm_root" -name "$fid" -print0)"
971 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
973 echo "Verifying content"
974 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
975 echo "Verifying hsm state "
976 check_hsm_flags $f "0x00000009"
978 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
979 local st=$(get_hsm_archive_id $f)
980 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
981 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
983 run_test 10a "Archive a file"
986 # test needs a running copytool
990 local f=$DIR/$tdir/$tfile
991 local fid=$(copy_file /etc/hosts $f)
992 $LFS hsm_archive $f || error "archive request failed"
993 wait_request_state $fid ARCHIVE SUCCEED
995 $LFS hsm_archive $f || error "archive of non dirty file failed"
996 local cnt=$(get_request_count $fid ARCHIVE)
997 [[ "$cnt" == "1" ]] ||
998 error "archive of non dirty file must not make a request"
1000 run_test 10b "Archive of non dirty file must work without doing request"
1003 # test needs a running copytool
1007 local f=$DIR/$tdir/$tfile
1008 local fid=$(copy_file /etc/hosts $f)
1009 $LFS hsm_set --noarchive $f
1010 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1013 run_test 10c "Check forbidden archive"
1016 # test needs a running copytool
1020 local f=$DIR/$tdir/$tfile
1021 local fid=$(copy_file /etc/hosts $f)
1022 $LFS hsm_archive $f || error "cannot archive $f"
1023 wait_request_state $fid ARCHIVE SUCCEED
1025 local ar=$(get_hsm_archive_id $f)
1026 local dflt=$(get_hsm_param default_archive_id)
1027 [[ $ar == $dflt ]] ||
1028 error "archived file is not on default archive: $ar != $dflt"
1030 run_test 10d "Archive a file on the default archive id"
1034 copy2archive /etc/hosts $tdir/$tfile
1035 local f=$DIR/$tdir/$tfile
1037 copytool import $tdir/$tfile $f
1038 echo -n "Verifying released state: "
1039 check_hsm_flags $f "0x0000000d"
1041 local LSZ=$(stat -c "%s" $f)
1042 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1044 echo "Verifying imported size $LSZ=$ASZ"
1045 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1046 echo -n "Verifying released pattern: "
1047 local PTRN=$($LFS getstripe -L $f)
1049 [[ $PTRN == released ]] || error "Is not released"
1050 local fid=$(path2fid $f)
1051 echo "Verifying new fid $fid in archive"
1053 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1054 error "No archive for fid $fid"
1056 run_test 11a "Import a file"
1059 # test needs a running copytool
1063 local f=$DIR/$tdir/$tfile
1064 local fid=$(copy_file /etc/hosts $f)
1065 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1066 error "hsm_archive failed"
1067 wait_request_state $fid ARCHIVE SUCCEED
1069 local FILE_HASH=$(md5sum $f)
1072 copytool import $fid $f
1074 echo "$FILE_HASH" | md5sum -c
1076 [[ $? -eq 0 ]] || error "Restored file differs"
1078 run_test 11b "Import a deleted file using its FID"
1081 # test needs a running copytool
1085 copy2archive /etc/hosts $tdir/$tfile
1087 local f=$DIR/$tdir/$tfile
1088 copytool import $tdir/$tfile $f
1089 local f2=$DIR2/$tdir/$tfile
1090 echo "Verifying released state: "
1091 check_hsm_flags $f2 "0x0000000d"
1093 local fid=$(path2fid $f2)
1094 $LFS hsm_restore $f2
1095 wait_request_state $fid RESTORE SUCCEED
1097 echo "Verifying file state: "
1098 check_hsm_flags $f2 "0x00000009"
1100 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1102 [[ $? -eq 0 ]] || error "Restored file differs"
1104 run_test 12a "Restore an imported file explicitly"
1107 # test needs a running copytool
1111 copy2archive /etc/hosts $tdir/$tfile
1113 local f=$DIR/$tdir/$tfile
1114 copytool import $tdir/$tfile $f
1115 echo "Verifying released state: "
1116 check_hsm_flags $f "0x0000000d"
1118 cat $f > /dev/null || error "File read failed"
1120 echo "Verifying file state after restore: "
1121 check_hsm_flags $f "0x00000009"
1123 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1125 [[ $? -eq 0 ]] || error "Restored file differs"
1127 run_test 12b "Restore an imported file implicitly"
1130 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1132 # test needs a running copytool
1135 local f=$DIR/$tdir/$tfile
1137 $LFS setstripe -c 2 "$f"
1138 local fid=$(create_file "$f" 1M 5)
1140 local FILE_CRC=$(md5sum $f)
1142 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1143 wait_request_state $fid ARCHIVE SUCCEED
1144 $LFS hsm_release $f || error "release $f failed"
1146 echo "$FILE_CRC" | md5sum -c
1148 [[ $? -eq 0 ]] || error "Restored file differs"
1150 run_test 12c "Restore a file with stripe of 2"
1153 # test needs a running copytool
1158 local f=$DIR/$tdir/$tfile
1159 local fid=$(copy_file /etc/hosts $f)
1160 $LFS hsm_restore $f || error "restore of non archived file failed"
1161 local cnt=$(get_request_count $fid RESTORE)
1162 [[ "$cnt" == "0" ]] ||
1163 error "restore non archived must not make a request"
1164 $LFS hsm_archive $f ||
1165 error "archive request failed"
1166 wait_request_state $fid ARCHIVE SUCCEED
1167 $LFS hsm_restore $f ||
1168 error "restore of non released file failed"
1169 local cnt=$(get_request_count $fid RESTORE)
1170 [[ "$cnt" == "0" ]] ||
1171 error "restore a non dirty file must not make a request"
1173 run_test 12d "Restore of a non archived, non released file must work"\
1174 " without doing request"
1177 # test needs a running copytool
1181 local f=$DIR/$tdir/$tfile
1182 local fid=$(copy_file /etc/hosts $f)
1183 $LFS hsm_archive $f || error "archive request failed"
1184 wait_request_state $fid ARCHIVE SUCCEED
1187 cat /etc/hosts >> $f
1191 $LFS hsm_restore $f && error "restore a dirty file must fail"
1194 run_test 12e "Check forbidden restore"
1197 # test needs a running copytool
1201 local f=$DIR/$tdir/$tfile
1202 local fid=$(copy_file /etc/hosts $f)
1204 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1205 wait_request_state $fid ARCHIVE SUCCEED
1206 $LFS hsm_release $f || error "release of $f failed"
1208 wait_request_state $fid RESTORE SUCCEED
1210 echo -n "Verifying file state: "
1211 check_hsm_flags $f "0x00000009"
1213 diff -q /etc/hosts $f
1215 [[ $? -eq 0 ]] || error "Restored file differs"
1217 run_test 12f "Restore a released file explicitly"
1220 # test needs a running copytool
1224 local f=$DIR/$tdir/$tfile
1225 local fid=$(copy_file /etc/hosts $f)
1227 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1228 wait_request_state $fid ARCHIVE SUCCEED
1229 $LFS hsm_release $f || error "release of $f failed"
1231 diff -q /etc/hosts $f
1234 # we check we had a restore done
1235 wait_request_state $fid RESTORE SUCCEED
1237 [[ $st -eq 0 ]] || error "Restored file differs"
1239 run_test 12g "Restore a released file implicitly"
1242 needclients 2 || return 0
1244 # test needs a running copytool
1248 local f=$DIR/$tdir/$tfile
1249 local fid=$(copy_file /etc/hosts $f)
1251 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1252 wait_request_state $fid ARCHIVE SUCCEED
1253 $LFS hsm_release $f || error "release of $f failed"
1255 do_node $CLIENT2 diff -q /etc/hosts $f
1258 # we check we had a restore done
1259 wait_request_state $fid RESTORE SUCCEED
1261 [[ $st -eq 0 ]] || error "Restored file differs"
1263 run_test 12h "Restore a released file implicitly from a second node"
1266 # test needs a running copytool
1270 local f=$DIR/$tdir/$tfile
1271 local fid=$(copy_file /etc/passwd $f)
1272 $LFS hsm_archive $f || error "archive of $f failed"
1273 wait_request_state $fid ARCHIVE SUCCEED
1275 $LFS hsm_release $f || error "release of $f failed"
1279 [[ $? -eq 0 ]] || error "Restored file differs"
1281 run_test 12m "Archive/release/implicit restore"
1284 # test needs a running copytool
1288 copy2archive /etc/hosts $tdir/$tfile
1290 local f=$DIR/$tdir/$tfile
1291 copytool import $tdir/$tfile $f
1293 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1294 error "Restored file differs"
1296 $LFS hsm_release $f || error "release of $f failed"
1298 run_test 12n "Import/implicit restore/release"
1301 # test needs a running copytool
1305 local f=$DIR/$tdir/$tfile
1306 local fid=$(copy_file /etc/hosts $f)
1308 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1309 wait_request_state $fid ARCHIVE SUCCEED
1310 $LFS hsm_release $f || error "release of $f failed"
1312 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1313 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1315 # set no retry action mode
1318 diff -q /etc/hosts $f
1321 # we check we had a restore failure
1322 wait_request_state $fid RESTORE FAILED
1324 [[ $st -eq 0 ]] && error "Restore must fail"
1326 # remove no retry action mode
1329 # check file is still released
1330 check_hsm_flags $f "0x0000000d"
1332 # retry w/o failure injection
1333 do_facet $SINGLEMDS lctl set_param fail_loc=0
1335 # to be sure previous RESTORE result is gone
1337 wait_for_grace_delay
1339 diff -q /etc/hosts $f
1342 # we check we had a restore done
1343 wait_request_state $fid RESTORE SUCCEED
1345 [[ $st -eq 0 ]] || error "Restored file differs"
1347 run_test 12o "Layout-swap failure during Restore leaves file released"
1350 # test needs a running copytool
1354 local f=$DIR/$tdir/$tfile
1355 local fid=$(copy_file /etc/hosts $f)
1357 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1358 wait_request_state $fid ARCHIVE SUCCEED
1359 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1360 $LFS hsm_release $f || error "cannot release $f"
1361 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1362 $LFS hsm_release $f || error "cannot release $f"
1363 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1365 run_test 12p "implicit restore of a file on copytool mount point"
1368 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1369 skip "need MDS version at least 2.7.58"
1371 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1372 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1373 error "cannot mount $MOUNT3 on $SINGLEAGT"
1375 # test needs a running copytool
1376 copytool setup -m "$MOUNT3"
1378 local f=$DIR/$tdir/$tfile
1379 local f2=$DIR2/$tdir/$tfile
1380 local fid=$(create_small_file $f)
1381 local orig_size=$(stat -c "%s" $f)
1383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1384 wait_request_state $fid ARCHIVE SUCCEED
1386 $LFS hsm_release $f || error "could not release file"
1387 check_hsm_flags $f "0x0000000d"
1390 wait_copytools || error "copytool failed to stop"
1392 cat $f > /dev/null &
1394 # wait a bit to allow implicit restore request to be handled.
1395 # if not, next stat would also block on layout-lock.
1398 local size=$(stat -c "%s" $f2)
1399 [ $size -eq $orig_size ] ||
1400 error "$f2: wrong size after archive: $size != $orig_size"
1402 copytool setup -m "$MOUNT3"
1406 size=$(stat -c "%s" $f)
1407 [ $size -eq $orig_size ] ||
1408 error "$f: wrong size after restore: $size != $orig_size"
1410 size=$(stat -c "%s" $f2)
1411 [ $size -eq $orig_size ] ||
1412 error "$f2: wrong size after restore: $size != $orig_size"
1416 size=$(stat -c "%s" $f)
1418 error "$f: wrong size after overwrite: $size != 0"
1420 size=$(stat -c "%s" $f2)
1422 error "$f2: wrong size after overwrite: $size != 0"
1424 run_test 12q "file attributes are refreshed after restore"
1428 for i in {1..10}; do
1429 local archive_dir="$(hsm_root)"/subdir/dir.$i
1431 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1432 for j in {1..10}; do
1433 local archive_file="$archive_dir"/file.$j
1435 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1441 copytool import "subdir" "$DIR/$tdir"
1443 # To check the import, the test uses diff with the -r flag
1444 # This is nice, but diff only checks files one by one, and triggering
1445 # an implicit restore for one file at a time will consume as many
1446 # seconds as there are files to compare. To speed this up, a restore
1447 # operation is triggered manually first.
1449 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1451 # Compare the imported data
1452 do_facet $SINGLEAGT \
1453 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1454 error "imported files differ from archived data"
1456 run_test 13 "Recursively import and restore a directory"
1459 # test needs a running copytool
1463 local f=$DIR/$tdir/$tfile
1464 local fid=$(create_small_file $f)
1465 local sum=$(md5sum $f | awk '{print $1}')
1466 $LFS hsm_archive $f || error "could not archive file"
1467 wait_request_state $fid ARCHIVE SUCCEED
1469 # create released file (simulate llapi_hsm_import call)
1470 local fid2=$(create_empty_file "$f")
1471 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1472 $LFS hsm_release $f || error "could not release file"
1474 # rebind the archive to the newly created file
1475 echo "rebind $fid to $fid2"
1477 copytool rebind $fid $fid2
1479 # restore file and compare md5sum
1480 local sum2=$(md5sum $f | awk '{print $1}')
1482 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1484 run_test 14 "Rebind archived file to a new fid"
1487 # test needs a running copytool
1491 local f=$DIR/$tdir/$tfile
1493 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1497 for i in $(seq 1 $count); do
1498 fids[$i]=$(create_small_file $f.$i)
1499 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1500 $LFS hsm_archive $f.$i || error "could not archive file"
1502 wait_all_done $(($count*60))
1504 stack_trap "rm -f $tmpfile" EXIT
1507 for i in $(seq 1 $count); do
1508 local fid2=$(create_empty_file "${f}.${i}")
1509 # add the rebind operation to the list
1510 echo ${fids[$i]} $fid2 >> $tmpfile
1512 # set it released (simulate llapi_hsm_import call)
1513 $LFS hsm_set --archived --exists $f.$i ||
1514 error "could not force hsm flags"
1515 $LFS hsm_release $f.$i || error "could not release file"
1517 nl=$(wc -l < $tmpfile)
1518 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1520 echo "rebind list of files"
1521 copytool rebind "$tmpfile"
1523 # restore files and compare md5sum
1524 for i in $(seq 1 $count); do
1525 local sum2=$(md5sum $f.$i | awk '{print $1}')
1526 [[ $sum2 == ${sums[$i]} ]] ||
1527 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1530 run_test 15 "Rebind a list of files"
1533 # test needs a running copytool
1537 # create a known size file so we can verify transfer speed
1540 dd if=/dev/zero of=$ref bs=1M count=20
1543 local f=$DIR/$tdir/$tfile
1544 local fid=$(copy_file $ref $f)
1546 local start=$(date +%s)
1548 wait_request_state $fid ARCHIVE SUCCEED
1549 local end=$(date +%s)
1550 # Add 1 to account for rounding errors between start and end (LU-8155)
1551 local duration=$((end - start + 1))
1553 [[ $duration -ge $((goal - 1)) ]] ||
1554 error "Transfer is too fast $duration < $goal"
1556 run_test 16 "Test CT bandwith control option"
1559 local f=$DIR/$tdir/$tfile
1560 create_empty_file "$f"
1562 # Could not release a non-archived file
1563 $LFS hsm_release $f && error "release should not succeed"
1565 # For following tests, we must test them with HS_ARCHIVED set
1566 $LFS hsm_set --exists --archived $f || error "could not add flag"
1568 # Could not release a file if no-release is set
1569 $LFS hsm_set --norelease $f || error "could not add flag"
1570 $LFS hsm_release $f && error "release should not succeed"
1571 $LFS hsm_clear --norelease $f || error "could not remove flag"
1573 # Could not release a file if lost
1574 $LFS hsm_set --lost $f || error "could not add flag"
1575 $LFS hsm_release $f && error "release should not succeed"
1576 $LFS hsm_clear --lost $f || error "could not remove flag"
1578 # Could not release a file if dirty
1579 $LFS hsm_set --dirty $f || error "could not add flag"
1580 $LFS hsm_release $f && error "release should not succeed"
1581 $LFS hsm_clear --dirty $f || error "could not remove flag"
1583 run_test 20 "Release is not permitted"
1586 # test needs a running copytool
1589 local f=$DIR/$tdir/test_release
1591 # Create a file and check its states
1592 local fid=$(create_small_file $f)
1593 check_hsm_flags $f "0x00000000"
1595 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1596 # used until file is flushed to disk
1597 if [ $(facet_fstype ost1) == "zfs" ]; then
1598 # this causes an OST_SYNC rpc to be sent
1599 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1600 # clear locks to reread file data
1601 cancel_lru_locks osc
1604 local orig_size=$(stat -c "%s" $f)
1605 local orig_blocks=$(stat -c "%b" $f)
1607 start_full_debug_logging
1609 $LFS hsm_archive $f || error "could not archive file"
1610 wait_request_state $fid ARCHIVE SUCCEED
1612 local blocks=$(stat -c "%b" $f)
1613 [ $blocks -eq $orig_blocks ] ||
1614 error "$f: wrong block number after archive: " \
1615 "$blocks != $orig_blocks"
1616 local size=$(stat -c "%s" $f)
1617 [ $size -eq $orig_size ] ||
1618 error "$f: wrong size after archive: $size != $orig_size"
1620 # Release and check states
1621 $LFS hsm_release $f || error "could not release file"
1622 check_hsm_flags $f "0x0000000d"
1624 blocks=$(stat -c "%b" $f)
1625 [ $blocks -gt 5 ] &&
1626 error "$f: too many blocks after release: $blocks > 5"
1627 size=$(stat -c "%s" $f)
1628 [ $size -ne $orig_size ] &&
1629 error "$f: wrong size after release: $size != $orig_size"
1631 # Check we can release an file without stripe info
1635 check_hsm_flags $f "0x00000000"
1636 $LFS hsm_archive $f || error "could not archive file"
1637 wait_request_state $fid ARCHIVE SUCCEED
1639 # Release and check states
1640 $LFS hsm_release $f || error "could not release file"
1641 check_hsm_flags $f "0x0000000d"
1643 # Release again a file that is already released is OK
1644 $LFS hsm_release $f || fail "second release should succeed"
1645 check_hsm_flags $f "0x0000000d"
1647 stop_full_debug_logging
1649 run_test 21 "Simple release tests"
1652 # test needs a running copytool
1655 local f=$DIR/$tdir/test_release
1656 local swap=$DIR/$tdir/test_swap
1658 # Create a file and check its states
1659 local fid=$(create_small_file $f)
1660 check_hsm_flags $f "0x00000000"
1662 $LFS hsm_archive $f || error "could not archive file"
1663 wait_request_state $fid ARCHIVE SUCCEED
1665 # Release and check states
1666 $LFS hsm_release $f || error "could not release file"
1667 check_hsm_flags $f "0x0000000d"
1669 create_small_file $swap
1670 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1674 run_test 22 "Could not swap a release file"
1677 # test needs a running copytool
1680 local f=$DIR/$tdir/test_mtime
1682 # Create a file and check its states
1683 local fid=$(create_small_file $f)
1684 check_hsm_flags $f "0x00000000"
1686 $LFS hsm_archive $f || error "could not archive file"
1687 wait_request_state $fid ARCHIVE SUCCEED
1689 # Set modification time in the past
1690 touch -m -a -d @978261179 $f
1692 # Release and check states
1693 $LFS hsm_release $f || error "could not release file"
1694 check_hsm_flags $f "0x0000000d"
1696 local MTIME=$(stat -c "%Y" $f)
1697 local ATIME=$(stat -c "%X" $f)
1698 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1699 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1701 run_test 23 "Release does not change a/mtime (utime)"
1704 local file=$DIR/$tdir/$tfile
1713 # test needs a running copytool
1716 fid=$(create_small_file $file)
1718 # Create a file and check its states
1719 check_hsm_flags $file "0x00000000"
1721 # Ensure atime is less than mtime and ctime.
1725 atime0=$(stat -c "%X" $file)
1726 mtime0=$(stat -c "%Y" $file)
1727 ctime0=$(stat -c "%Z" $file)
1729 [ $atime0 -lt $mtime0 ] ||
1730 error "atime $atime0 is not less than mtime $mtime0"
1732 [ $atime0 -lt $ctime0 ] ||
1733 error "atime $atime0 is not less than ctime $ctime0"
1735 # Archive should not change any timestamps.
1736 $LFS hsm_archive $file || error "cannot archive '$file'"
1737 wait_request_state $fid ARCHIVE SUCCEED
1739 atime1=$(stat -c "%X" $file)
1740 mtime1=$(stat -c "%Y" $file)
1741 ctime1=$(stat -c "%Z" $file)
1743 [ $atime0 -eq $atime1 ] ||
1744 error "archive changed atime from $atime0 to $atime1"
1746 [ $mtime0 -eq $mtime1 ] ||
1747 error "archive changed mtime from $mtime0 to $mtime1"
1749 [ $ctime0 -eq $ctime1 ] ||
1750 error "archive changed ctime from $ctime0 to $ctime1"
1752 # Release should not change any timestamps.
1753 $LFS hsm_release $file || error "cannot release '$file'"
1754 check_hsm_flags $file "0x0000000d"
1756 atime1=$(stat -c "%X" $file)
1757 mtime1=$(stat -c "%Y" $file)
1758 ctime1=$(stat -c "%Z" $file)
1760 [ $atime0 -eq $atime1 ] ||
1761 error "release changed atime from $atime0 to $atime1"
1763 [ $mtime0 -eq $mtime1 ] ||
1764 error "release changed mtime from $mtime0 to $mtime1"
1766 [ $ctime0 -eq $ctime1 ] ||
1767 error "release changed ctime from $ctime0 to $ctime1"
1769 # Restore should not change any timestamps.
1770 $LFS hsm_restore $file
1771 wait_request_state $fid RESTORE SUCCEED
1773 atime1=$(stat -c "%X" $file)
1774 mtime1=$(stat -c "%Y" $file)
1775 ctime1=$(stat -c "%Z" $file)
1777 [ $atime0 -eq $atime1 ] ||
1778 error "restore changed atime from $atime0 to $atime1"
1780 [ $mtime0 -eq $mtime1 ] ||
1781 error "restore changed mtime from $mtime0 to $mtime1"
1783 [ $ctime0 -eq $ctime1 ] ||
1784 error "restore changed ctime from $ctime0 to $ctime1"
1787 wait_copytools || error "Copytools failed to stop"
1789 # Once more, after unmount and mount.
1790 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1791 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1793 atime1=$(stat -c "%X" $file)
1794 mtime1=$(stat -c "%Y" $file)
1795 ctime1=$(stat -c "%Z" $file)
1797 [ $atime0 -eq $atime1 ] ||
1798 error "remount changed atime from $atime0 to $atime1"
1800 [ $mtime0 -eq $mtime1 ] ||
1801 error "remount changed mtime from $mtime0 to $mtime1"
1803 [ $ctime0 -eq $ctime1 ] ||
1804 error "remount changed ctime from $ctime0 to $ctime1"
1806 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1809 local file=$DIR/$tdir/$tfile
1815 # Test needs a running copytool.
1818 # Check that root can do HSM actions on a regular user's file.
1819 fid=$(create_small_file $file)
1820 sum0=$(md5sum $file)
1822 chown $RUNAS_ID:$RUNAS_GID $file ||
1823 error "cannot chown '$file' to '$RUNAS_ID'"
1825 chmod ugo-w $DIR/$tdir ||
1826 error "cannot chmod '$DIR/$tdir'"
1828 $LFS hsm_archive $file
1829 wait_request_state $fid ARCHIVE SUCCEED
1831 $LFS hsm_release $file
1832 check_hsm_flags $file "0x0000000d"
1834 $LFS hsm_restore $file
1835 wait_request_state $fid RESTORE SUCCEED
1837 # Check that ordinary user can get HSM state.
1838 $RUNAS $LFS hsm_state $file ||
1839 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1841 $LFS hsm_release $file
1842 check_hsm_flags $file "0x0000000d"
1844 # Check that ordinary user can accessed released file.
1845 sum1=$($RUNAS md5sum $file) ||
1846 error "user '$RUNAS_ID' cannot read '$file'"
1848 [ "$sum0" == "$sum1" ] ||
1849 error "md5sum mismatch for '$file'"
1851 run_test 24b "root can archive, release, and restore user files"
1854 local file=$DIR/$tdir/$tfile
1855 local action=archive
1860 # test needs a running copytool
1865 # Save the default masks and check that cleanup_24c will
1866 # restore the request masks correctly.
1867 user_save=$(get_hsm_param user_request_mask)
1868 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1869 group_save=$(get_hsm_param group_request_mask)
1870 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1871 other_save=$(get_hsm_param other_request_mask)
1872 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1874 [ "$user_save" == RESTORE ] ||
1875 error "user_request_mask is '$user_save' expected 'RESTORE'"
1876 [ "$group_save" == RESTORE ] ||
1877 error "group_request_mask is '$group_save' expected 'RESTORE'"
1878 [ "$other_save" == RESTORE ] ||
1879 error "other_request_mask is '$other_save' expected 'RESTORE'"
1882 create_small_file $file
1883 chown $RUNAS_ID:$GROUP $file ||
1884 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1886 $RUNAS $LFS hsm_$action $file &&
1887 error "$action by user should fail"
1889 set_hsm_param user_request_mask $action
1890 $RUNAS $LFS hsm_$action $file ||
1891 error "$action by user should succeed"
1894 create_small_file $file
1895 chown nobody:$RUNAS_GID $file ||
1896 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1898 $RUNAS $LFS hsm_$action $file &&
1899 error "$action by group should fail"
1901 set_hsm_param group_request_mask $action
1902 $RUNAS $LFS hsm_$action $file ||
1903 error "$action by group should succeed"
1906 create_small_file $file
1907 chown nobody:$GROUP $file ||
1908 error "cannot chown '$file' to 'nobody:$GROUP'"
1910 $RUNAS $LFS hsm_$action $file &&
1911 error "$action by other should fail"
1913 set_hsm_param other_request_mask $action
1914 $RUNAS $LFS hsm_$action $file ||
1915 error "$action by other should succeed"
1917 run_test 24c "check that user,group,other request masks work"
1920 local file1=$DIR/$tdir/$tfile
1921 local file2=$DIR2/$tdir/$tfile
1925 fid1=$(create_small_file $file1)
1928 $LFS getstripe $file1
1930 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1931 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1932 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1934 copytool setup -m "$MOUNT3"
1936 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1937 mount -o remount,ro $MOUNT2
1939 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1941 fid2=$(path2fid $file2)
1942 [ "$fid1" == "$fid2" ] ||
1943 error "FID mismatch '$fid1' != '$fid2'"
1945 $LFS hsm_archive $file2 &&
1946 error "archive should fail on read-only mount"
1947 check_hsm_flags $file1 "0x00000000"
1949 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1950 wait_request_state $fid1 ARCHIVE SUCCEED
1952 $LFS hsm_release $file1
1953 $LFS hsm_restore $file2
1954 wait_request_state $fid1 RESTORE SUCCEED
1956 $LFS hsm_release $file1 || error "cannot release '$file1'"
1957 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1959 $LFS hsm_release $file2 &&
1960 error "release should fail on read-only mount"
1964 run_test 24d "check that read-only mounts are respected"
1969 local f=$DIR/$tdir/$tfile
1972 fid=$(create_small_file $f) || error "cannot create $f"
1973 $LFS hsm_archive $f || error "cannot archive $f"
1974 wait_request_state $fid ARCHIVE SUCCEED
1975 $LFS hsm_release $f || error "cannot release $f"
1976 while ! $LFS hsm_state $f | grep released; do
1980 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1982 run_test 24e "tar succeeds on HSM released files" # LU-6213
1985 # test needs a running copytool
1988 mkdir -p $DIR/$tdir/d1
1989 local f=$DIR/$tdir/$tfile
1990 local fid=$(copy_file /etc/hosts $f)
1993 $LFS hsm_archive $f ||
1994 error "hsm_archive failed"
1995 wait_request_state $fid ARCHIVE SUCCEED
1996 $LFS hsm_release $f || error "cannot release $f"
1997 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2000 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2001 error "Can not recover the tar contents"
2003 echo "Sum0 = $sum0, sum1 = $sum1"
2004 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2006 run_test 24f "root can archive, release, and restore tar files"
2009 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2010 skip "need MDS version 2.11.56 or later"
2012 local file=$DIR/$tdir/$tfile
2015 echo "RUNAS = '$RUNAS'"
2020 chmod ugo+rwx $DIR/$tdir
2022 echo "Please listen carefully as our options have changed." | tee $file
2023 fid=$(path2fid $file)
2026 $LFS hsm_archive $file
2027 wait_request_state $fid ARCHIVE SUCCEED
2028 check_hsm_flags $file 0x00000009 # exists archived
2030 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2031 check_hsm_flags $file 0x0000000b # exists dirty archived
2033 run_test 24g "write by non-owner still sets dirty" # LU-11369
2036 # test needs a running copytool
2040 copy2archive /etc/hosts $tdir/$tfile
2042 local f=$DIR/$tdir/$tfile
2044 copytool import $tdir/$tfile $f
2046 $LFS hsm_set --lost $f
2051 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2053 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2054 " (Operation not permitted)"
2057 # test needs a running copytool
2062 local f=$DIR/$tdir/$tfile
2063 local fid=$(copy_file /etc/passwd $f)
2065 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2066 wait_request_state $fid ARCHIVE SUCCEED
2069 $LFS hsm_set --lost $f
2073 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2075 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2076 " (Operation not permitted)"
2078 test_26A() { # was test_26
2079 # test needs a running copytool
2082 local f=$DIR/$tdir/$tfile
2083 local fid=$(create_empty_file "$f")
2085 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2086 wait_request_state $fid ARCHIVE SUCCEED
2089 wait_request_state $fid REMOVE SUCCEED
2091 check_hsm_flags $f "0x00000000"
2093 run_test 26A "Remove the archive of a valid file"
2096 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2097 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2099 # test needs a running copytool
2103 local f=$DIR/$tdir/$tfile
2104 local fid=$(copy_file /etc/passwd $f)
2106 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2107 wait_request_state $fid ARCHIVE SUCCEED
2109 local f2=$DIR/$tdir/${tfile}_2
2110 local fid2=$(copy_file /etc/passwd $f2)
2112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2113 wait_request_state $fid2 ARCHIVE SUCCEED
2115 local f3=$DIR/$tdir/${tfile}_3
2116 local fid3=$(copy_file /etc/passwd $f3)
2118 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2119 wait_request_state $fid3 ARCHIVE SUCCEED
2121 # set a long grace_delay vs short loop_period
2122 local orig_loop_period=$(get_hsm_param loop_period)
2123 local orig_grace_delay=$(get_hsm_param grace_delay)
2124 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2125 set_hsm_param loop_period 10
2126 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2127 set_hsm_param grace_delay 100
2131 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2132 set_hsm_param remove_archive_on_last_unlink 1
2134 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2139 wait_request_state $fid2 REMOVE SUCCEED
2141 assert_request_count $fid REMOVE 0 \
2142 "Unexpected archived data remove request for $f"
2143 assert_request_count $fid3 REMOVE 0 \
2144 "Unexpected archived data remove request for $f3"
2146 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2149 # test needs a running copytool
2153 local f=$DIR/$tdir/$tfile
2154 local fid=$(copy_file /etc/passwd $f)
2156 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2157 wait_request_state $fid ARCHIVE SUCCEED
2159 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2160 set_hsm_param remove_archive_on_last_unlink 1
2163 cdt_check_state stopped
2167 wait_request_state $fid REMOVE WAITING
2171 # copytool must re-register
2173 wait_copytools || error "copytool failed to stop"
2176 wait_request_state $fid REMOVE SUCCEED
2178 run_test 26b "RAoLU policy when CDT off"
2181 # test needs a running copytool
2185 local f=$DIR/$tdir/$tfile
2186 local fid=$(copy_file /etc/passwd $f)
2188 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2189 wait_request_state $fid ARCHIVE SUCCEED
2191 local f2=$DIR/$tdir/${tfile}_2
2192 local fid2=$(copy_file /etc/passwd $f2)
2194 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2195 wait_request_state $fid2 ARCHIVE SUCCEED
2197 # set a long grace_delay vs short loop_period
2198 local orig_loop_period=$(get_hsm_param loop_period)
2199 local orig_grace_delay=$(get_hsm_param grace_delay)
2200 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2201 set_hsm_param loop_period 10
2202 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2203 set_hsm_param grace_delay 100
2205 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2206 set_hsm_param remove_archive_on_last_unlink 1
2208 multiop_bg_pause $f O_c || error "open $f failed"
2214 wait_request_state $fid2 REMOVE SUCCEED
2215 assert_request_count $fid REMOVE 0 \
2216 "Unexpected archived data remove request for $f"
2218 kill -USR1 $pid || error "multiop early exit"
2219 # should reach autotest timeout if multiop fails to trap
2220 # signal, close file, and exit ...
2221 wait $pid || error "wait PID $PID failed"
2223 wait_request_state $fid REMOVE SUCCEED
2225 run_test 26c "RAoLU effective when file closed"
2228 # test needs a running copytool
2232 local f=$DIR/$tdir/$tfile
2233 local fid=$(create_small_file $f)
2235 $LFS hsm_archive $f || error "could not archive file"
2236 wait_request_state $fid ARCHIVE SUCCEED
2238 # set a long grace_delay vs short loop_period
2239 local orig_loop_period=$(get_hsm_param loop_period)
2240 local orig_grace_delay=$(get_hsm_param grace_delay)
2241 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2242 set_hsm_param loop_period 10
2243 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2244 set_hsm_param grace_delay 100
2246 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2247 set_hsm_param remove_archive_on_last_unlink 1
2249 multiop_bg_pause $f O_c || error "multiop failed"
2256 wait_request_state $fid REMOVE SUCCEED
2258 client_up || client_up || true
2260 kill -USR1 $MULTIPID
2261 wait $MULTIPID || error "multiop close failed"
2263 run_test 26d "RAoLU when Client eviction"
2266 # test needs a running copytool
2269 create_archive_file $tdir/$tfile
2270 local f=$DIR/$tdir/$tfile
2271 copytool import $tdir/$tfile $f
2272 local fid=$(path2fid $f)
2276 [[ $? != 0 ]] || error "Remove of a released file should fail"
2278 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2281 # test needs a running copytool
2284 local f=$DIR/$tdir/$tfile
2285 local fid=$(create_empty_file "$f")
2287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2288 wait_request_state $fid ARCHIVE SUCCEED
2293 [[ $? != 0 ]] || error "Remove of a released file should fail"
2295 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2298 # test needs a running copytool
2301 local f=$DIR/$tdir/$tfile
2302 local fid=$(create_empty_file "$f")
2304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2305 wait_request_state $fid ARCHIVE SUCCEED
2314 wait_request_state $fid REMOVE SUCCEED
2316 run_test 28 "Concurrent archive/file remove"
2319 # Tests --mntpath and --archive options
2322 copytool setup -m "$MOUNT" -a $archive_id
2324 # Bad archive number
2325 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2326 grep "Invalid argument" ||
2327 error "unexpected hsm_remove failure (1)"
2329 # mntpath is present but file is given
2330 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2331 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2332 error "unexpected hsm_remove failure (2)"
2334 run_test 29a "Tests --mntpath and --archive options"
2337 # test needs a running copytool
2340 local f=$DIR/$tdir/$tfile
2341 local fid=$(create_small_file $f)
2343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2344 wait_request_state $fid ARCHIVE SUCCEED
2348 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2349 wait_request_state $fid REMOVE SUCCEED
2351 run_test 29b "Archive/delete/remove by FID from the archive."
2354 # test needs a running copytool
2357 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2358 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2359 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2361 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2362 wait_request_state $fid1 ARCHIVE SUCCEED
2363 wait_request_state $fid2 ARCHIVE SUCCEED
2364 wait_request_state $fid3 ARCHIVE SUCCEED
2366 rm -f $DIR/$tdir/$tfile-[1-3]
2368 echo $fid1 > $DIR/$tdir/list
2369 echo $fid2 >> $DIR/$tdir/list
2370 echo $fid3 >> $DIR/$tdir/list
2372 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2373 --filelist $DIR/$tdir/list
2374 wait_request_state $fid1 REMOVE SUCCEED
2375 wait_request_state $fid2 REMOVE SUCCEED
2376 wait_request_state $fid3 REMOVE SUCCEED
2378 run_test 29c "Archive/delete/remove by FID, using a file list."
2381 # test needs more than one CT
2382 needclients 3 || return 0
2388 # start all of the copytools
2389 for n in $(seq $AGTCOUNT); do
2390 copytool setup -f agt$n -a $n
2394 file=$DIR/$tdir/$tfile
2395 fid=$(create_small_file $file)
2397 $LFS hsm_archive $file
2398 wait_request_state $fid ARCHIVE SUCCEED
2399 check_hsm_flags $file "0x00000009"
2403 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2404 error "cannot hsm_remove '$fid'"
2406 # give time for CDT to handle remove request and create broadcasted
2409 # remove request has been broadcasted ?
2410 local cnt=$(get_request_count $fid REMOVE)
2411 # broadcasted requests + original
2412 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2413 error "remove not broadcasted to all CTs"
2415 # give time for CDT and CTs to handle broadcasted
2416 wait_for_loop_period
2418 # each agent serves one different archive_id, so broadcasted
2419 # hsm_remove request should only succeed once and fail at all others
2423 for n in $(seq $AGTCOUNT); do
2424 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2425 $HSM_PARAM.actions | awk \
2426 '/'$fid'.*action=REMOVE archive#='$n'/ \
2427 {print \\\$13}' | cut -f2 -d=")
2428 if [[ "$res" == "SUCCEED" ]]; then
2430 elif [[ "$res" == "FAILED" ]]; then
2435 [[ $scnt -eq 1 ]] ||
2436 error "one and only CT should have removed successfully"
2438 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2439 error "all but one CT should have failed to remove"
2441 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2442 "request to be sent once for each registered archive_id"
2445 # restore at exec cannot work on agent node (because of Linux kernel
2446 # protection of executables)
2447 needclients 2 || return 0
2449 # test needs a running copytool
2453 copy2archive /bin/true $tdir/$tfile
2455 local f=$DIR/$tdir/true
2456 copytool import $tdir/$tfile $f
2458 local fid=$(path2fid $f)
2460 stack_trap "cdt_clear_no_retry" EXIT
2461 # set no retry action mode
2468 [[ $st == 0 ]] || error "Failed to exec a released file"
2470 run_test 30a "Restore at exec (import case)"
2473 # restore at exec cannot work on agent node (because of Linux kernel
2474 # protection of executables)
2475 needclients 2 || return 0
2477 # test needs a running copytool
2481 local f=$DIR/$tdir/true
2482 local fid=$(copy_file /bin/true $f)
2484 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2485 wait_request_state $fid ARCHIVE SUCCEED
2489 stack_trap cdt_clear_no_retry EXIT
2490 # set no retry action mode
2498 [[ $st == 0 ]] || error "Failed to exec a released file"
2500 run_test 30b "Restore at exec (release case)"
2503 needclients 2 || return 0
2505 # test needs a running copytool
2509 local f=$DIR/$tdir/SLEEP
2510 local slp_sum1=$(md5sum /bin/sleep)
2511 local fid=$(copy_file /bin/sleep $f)
2513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2514 wait_request_state $fid ARCHIVE SUCCEED
2516 check_hsm_flags $f "0x0000000d"
2518 stack_trap cdt_clear_no_retry EXIT
2519 # set no retry action mode
2522 do_node $CLIENT2 "$f 10" &
2526 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2528 [[ $? == 0 ]] || error "Execution failed during run"
2530 if [[ $? != 0 ]]; then
2531 local slp_sum2=$(md5sum /bin/sleep)
2532 # in case sleep file is modified during the test
2533 [[ $slp_sum1 == $slp_sum2 ]] &&
2534 error "Binary overwritten during exec"
2537 check_hsm_flags $f "0x00000009"
2539 run_test 30c "Update during exec of released file must fail"
2541 restore_and_check_size() {
2544 local s=$(stat -c "%s" $f)
2546 local st=$(get_hsm_flags $f)
2550 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2552 n=$(stat -c "%s" $f)
2553 # we echo in both cases to show stat is not hang
2554 if [[ $n != $s ]]; then
2555 echo "size seen is $n != $s"
2558 echo "size seen is right: $n == $s"
2562 st=$(get_hsm_flags $f)
2564 if [[ "$st" = "0x00000009" ]]; then
2567 echo " restore is too long"
2568 wait_request_state $fid RESTORE SUCCEED
2574 # test needs a running copytool
2577 create_archive_file $tdir/$tfile
2578 local f=$DIR/$tdir/$tfile
2579 copytool import $tdir/$tfile $f
2580 local fid=$($LFS path2fid $f)
2583 restore_and_check_size $f $fid
2586 [[ $err -eq 0 ]] || error "File size changed during restore"
2588 run_test 31a "Import a large file and check size during restore"
2592 # test needs a running copytool
2595 local f=$DIR/$tdir/$tfile
2596 local fid=$(create_file "$f" 1MB 39)
2598 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2599 wait_request_state $fid ARCHIVE SUCCEED
2602 restore_and_check_size $f $fid
2605 [[ $err -eq 0 ]] || error "File size changed during restore"
2607 run_test 31b "Restore a large unaligned file and check size during restore"
2610 # test needs a running copytool
2613 local f=$DIR/$tdir/$tfile
2614 local fid=$(create_file "$f" 1M 39)
2616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2617 wait_request_state $fid ARCHIVE SUCCEED
2620 restore_and_check_size $f $fid
2623 [[ $err -eq 0 ]] || error "File size changed during restore"
2625 run_test 31c "Restore a large aligned file and check size during restore"
2628 local f=$DIR/$tdir/$tfile
2629 local fid=$(create_empty_file "$f")
2633 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2634 wait_request_state $fid ARCHIVE SUCCEED
2637 # Prevent restore from completing
2641 md5sum $f >/dev/null &
2644 wait_request_state $fid RESTORE STARTED
2649 # Check restore trigger process was killed
2651 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2653 run_test 33 "Kill a restore waiting process"
2656 # test needs a running copytool
2659 local f=$DIR/$tdir/$tfile
2660 local fid=$(create_empty_file "$f")
2662 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2663 wait_request_state $fid ARCHIVE SUCCEED
2666 # Prevent restore from completing
2669 md5sum $f >/dev/null &
2672 wait_request_state $fid RESTORE STARTED
2674 # rm must not block during restore
2675 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2678 wait_request_state $fid RESTORE SUCCEED
2680 # Check md5sum pgm finished
2681 kill -0 $pid && error "Restore initiatior still running"
2682 wait $pid || error "Restore initiator failed with $?"
2684 # Check the file was actually deleted
2685 [ ! -f "$f" ] || error "$f was not deleted"
2687 run_test 34 "Remove file during restore"
2690 # test needs a running copytool
2693 local f=$DIR/$tdir/$tfile
2694 local f1=$DIR/$tdir/$tfile-1
2695 local fid=$(create_empty_file "$f")
2696 local fid1=$(copy_file /etc/passwd $f1)
2698 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2699 wait_request_state $fid ARCHIVE SUCCEED
2702 # Prevent restore from completing
2705 md5sum $f >/dev/null &
2708 wait_request_state $fid RESTORE STARTED
2710 # mv must not block during restore
2711 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2714 wait_request_state $fid RESTORE SUCCEED
2716 # Check md5sum pgm finished
2717 kill -0 $pid && error "Restore initiatior still running"
2718 wait $pid || error "Restore initiator failed with $?"
2720 local fid2=$(path2fid $f)
2721 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2723 run_test 35 "Overwrite file during restore"
2726 # test needs a running copytool
2729 local f=$DIR/$tdir/$tfile
2730 local fid=$(create_empty_file "$f")
2732 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2733 wait_request_state $fid ARCHIVE SUCCEED
2736 # Prevent restore from completing
2739 md5sum $f >/dev/null &
2742 wait_request_state $fid RESTORE STARTED
2744 # mv must not block during restore
2745 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2746 error "mv '$f' '$f.new' failed with rc=$?"
2749 wait_request_state $fid RESTORE SUCCEED
2751 # Check md5sum pgm finished
2752 kill -0 $pid && error "Restore initiator is still running"
2753 wait $pid || error "Restore initiator failed with $?"
2755 run_test 36 "Move file during restore"
2758 # LU-5683: check that an archived dirty file can be rearchived.
2761 local f=$DIR/$tdir/$tfile
2764 fid=$(create_small_file $f) || error "cannot create small file"
2766 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2767 wait_request_state $fid ARCHIVE SUCCEED
2768 $LFS hsm_release $f || error "cannot release $f"
2770 # Allow previous archive request to expire from the actions log.
2771 wait_for_grace_delay
2774 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2776 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2777 wait_request_state $fid ARCHIVE SUCCEED
2779 run_test 37 "re-archive a dirty file"
2786 for n in $(seq 1 $count); do
2787 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2789 echo "$count archive requests submitted"
2793 local stream_count=4
2794 local file_count=100
2796 local f=$DIR/$tdir/$tfile
2800 local max_requests=$(get_hsm_param max_requests)
2802 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2803 # Increase the number of HSM request that can be performed in
2804 # parallel. With the coordinator running once per second, this
2805 # also limits the number of requests per seconds that can be
2806 # performed, so we pick a decent number. But we also need to keep
2807 # that number low because the copytool has no rate limit and will
2808 # fail some requests if if gets too many at once.
2809 set_hsm_param max_requests 300
2811 for i in $(seq 1 $file_count); do
2812 for p in $(seq 1 $stream_count); do
2813 fid=$(copy_file /etc/hosts $f.$p.$i)
2819 # to be sure wait_all_done will not be mislead by previous tests
2821 wait_for_grace_delay
2823 # start archive streams in background (archive files in parallel)
2824 for p in $(seq 1 $stream_count); do
2825 multi_archive $f.$p $file_count &
2828 echo -n "Wait for all requests being enqueued..."
2833 run_test 40 "Parallel archive requests"
2836 # test needs a running copytool
2840 local f=$DIR/$tdir/$tfile
2841 local fid=$(create_small_file $f)
2843 $LFS hsm_archive $f || error "could not archive file"
2844 wait_request_state $fid ARCHIVE SUCCEED
2845 check_hsm_flags $f "0x00000009"
2847 multiop_bg_pause $f O_c || error "multiop failed"
2851 client_up || client_up || true
2853 kill -USR1 $MULTIPID
2854 wait $MULTIPID || error "multiop close failed"
2856 check_hsm_flags $f "0x0000000b"
2858 run_test 52 "Opened for write file on an evicted client should be set dirty"
2861 # test needs a running copytool
2865 local f=$DIR/$tdir/$tfile
2866 local fid=$(create_small_file $f)
2868 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2869 error "could not archive file"
2870 wait_request_state $fid ARCHIVE SUCCEED
2871 check_hsm_flags $f "0x00000009"
2873 multiop_bg_pause $f o_c || error "multiop failed"
2877 client_up || client_up || true
2879 kill -USR1 $MULTIPID
2880 wait $MULTIPID || error "multiop close failed"
2882 check_hsm_flags $f "0x00000009"
2884 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2887 local f=$DIR/$tdir/$tfile
2888 local fid=$(create_file "$f" 1MB 39)
2892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2893 error "could not archive file"
2894 wait_request_state $fid ARCHIVE STARTED
2896 check_hsm_flags $f "0x00000001"
2898 stack_trap "cdt_clear_no_retry" EXIT
2899 # Avoid coordinator resending this request as soon it has failed.
2904 wait_request_state $fid ARCHIVE FAILED
2906 check_hsm_flags $f "0x00000003"
2908 run_test 54 "Write during an archive cancels it"
2911 local f=$DIR/$tdir/$tfile
2912 local fid=$(create_file "$f" 1MB 39)
2916 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2917 error "could not archive file"
2918 wait_request_state $fid ARCHIVE STARTED
2920 check_hsm_flags $f "0x00000001"
2922 stack_trap "cdt_clear_no_retry" EXIT
2923 # Avoid coordinator resending this request as soon it has failed.
2926 $TRUNCATE $f 1024 || error "truncate failed"
2928 wait_request_state $fid ARCHIVE FAILED
2930 check_hsm_flags $f "0x00000003"
2932 run_test 55 "Truncate during an archive cancels it"
2935 local f=$DIR/$tdir/$tfile
2936 local fid=$(create_file "$f" 1MB 39)
2940 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2941 error "could not archive file"
2942 wait_request_state $fid ARCHIVE STARTED
2944 check_hsm_flags $f "0x00000001"
2946 # Change metadata and sync to be sure we are not changing only
2951 wait_request_state $fid ARCHIVE SUCCEED
2953 check_hsm_flags $f "0x00000009"
2955 run_test 56 "Setattr during an archive is ok"
2958 # Need one client for I/O, one for request
2959 needclients 2 || return 0
2961 # test needs a running copytool
2965 local f=$DIR/$tdir/test_archive_remote
2966 # Create a file on a remote node
2967 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2968 "count=2 conv=fsync"
2971 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2972 error "hsm_archive failed"
2973 local fid=$(path2fid $f)
2974 wait_request_state $fid ARCHIVE SUCCEED
2976 # Release and implicit restore it
2977 do_node $CLIENT2 "$LFS hsm_release $f" ||
2978 error "hsm_release failed"
2979 do_node $CLIENT2 "md5sum $f" ||
2980 error "hsm_restore failed"
2982 wait_request_state $fid RESTORE SUCCEED
2984 run_test 57 "Archive a file with dirty cache on another node"
2986 truncate_released_file() {
2990 local sz=$(stat -c %s $src_file)
2991 local f=$DIR/$tdir/$tfile
2992 local fid=$(copy_file $1 $f)
2996 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2997 error "could not archive file"
2998 wait_request_state $fid ARCHIVE SUCCEED
3000 $LFS hsm_release $f || error "could not release file"
3002 $TRUNCATE $f $trunc_to || error "truncate failed"
3005 local sz1=$(stat -c %s $f)
3006 [[ $sz1 == $trunc_to ]] ||
3007 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3010 check_hsm_flags $f "0x0000000b"
3012 local state=$(get_request_state $fid RESTORE)
3013 [[ "$state" == "SUCCEED" ]] ||
3014 error "truncate $sz does not trig restore, state = $state"
3016 $TRUNCATE $ref $trunc_to
3017 cmp $ref $f || error "file data wrong after truncate"
3023 # test needs a running copytool
3028 local sz=$(stat -c %s /etc/passwd)
3030 echo "truncate up from $sz to $((sz*2))"
3031 truncate_released_file /etc/passwd $((sz*2))
3033 echo "truncate down from $sz to $((sz/2))"
3034 truncate_released_file /etc/passwd $((sz/2))
3036 echo "truncate to 0"
3037 truncate_released_file /etc/passwd 0
3039 run_test 58 "Truncate a released file will trigger restore"
3043 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3044 skip "Need MDS version at least 2.7.63"
3047 $MCREATE $DIR/$tfile || error "mcreate failed"
3048 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3049 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3050 fid=$(path2fid $DIR/$tfile)
3051 wait_request_state $fid ARCHIVE SUCCEED
3052 $LFS hsm_release $DIR/$tfile || error "release failed"
3054 run_test 59 "Release stripeless file with non-zero size"
3057 # This test validates the fix for LU-4512. Ensure that the -u
3058 # option changes the progress reporting interval from the
3059 # default (30 seconds) to the user-specified interval.
3060 local f=$DIR/$tdir/$tfile
3061 local fid=$(create_file "$f" 1M 10)
3064 local progress_timeout=$((interval * 4))
3065 copytool setup -b 1 --update-interval $interval
3068 local mdt=${MDT_PREFIX}${mdtidx}
3069 local mds=mds$((mdtidx + 1))
3071 # Wait for copytool to register
3072 wait_update_facet $mds \
3073 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3074 uuid 100 || error "coyptool failed to register with $mdt"
3076 local start_at=$(date +%s)
3077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3078 error "could not archive file"
3080 local agent=$(facet_active_host $SINGLEAGT)
3081 local logfile=$(copytool_logfile $SINGLEAGT)
3083 wait_update $agent \
3084 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3085 error "copytool failed to start"
3087 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3088 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3094 echo -n "Expecting a progress update within $progress_timeout seconds... "
3096 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3097 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3098 echo "$RESULT bytes copied in $WAIT seconds."
3100 elif [ $WAIT -ge $progress_timeout ]; then
3101 error "Timed out waiting for progress update!"
3104 WAIT=$((WAIT + sleep))
3108 local finish_at=$(date +%s)
3109 local elapsed=$((finish_at - start_at))
3111 # Ensure that the progress update occurred within the expected window.
3112 if [ $elapsed -lt $((interval - 1)) ]; then
3113 error "Expected progress update after at least $interval seconds"
3116 echo "Wait for on going archive hsm action to complete"
3117 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3118 echo "File archiving not completed even after 10 secs"
3120 run_test 60 "Changing progress update interval from default"
3123 # test needs a running copytool
3127 local f=$DIR/$tdir/$tfile
3128 local fid=$(copy_file /etc/passwd $f)
3130 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3133 wait_request_state $fid ARCHIVE FAILED
3135 run_test 61 "Waiting archive of a removed file should fail"
3138 # test needs a new running copytool
3139 stack_trap copytool_monitor_cleanup EXIT
3140 copytool_monitor_setup
3141 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3143 # Wait for the copytool to register.
3144 wait_update --verbose $(facet_active_host mds1) \
3145 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3147 error "copytool failed to register with MDT0000"
3150 wait_copytools || error "Copytools failed to stop"
3152 local REGISTER_EVENT
3153 local UNREGISTER_EVENT
3154 while read event; do
3155 local parsed=$(parse_json_event "$event")
3156 if [ -z "$parsed" ]; then
3157 error "Copytool sent malformed event: $event"
3161 if [ $event_type == "REGISTER" ]; then
3162 REGISTER_EVENT=$event
3163 elif [ $event_type == "UNREGISTER" ]; then
3164 UNREGISTER_EVENT=$event
3166 done < <(echo $"$(get_copytool_event_log)")
3168 if [ -z "$REGISTER_EVENT" ]; then
3169 error "Copytool failed to send register event to FIFO"
3172 if [ -z "$UNREGISTER_EVENT" ]; then
3173 error "Copytool failed to send unregister event to FIFO"
3176 echo "Register/Unregister events look OK."
3178 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3181 # Bump progress interval for livelier events.
3184 # test needs a new running copytool
3185 stack_trap copytool_monitor_cleanup EXIT
3186 copytool_monitor_setup
3187 copytool setup --update-interval $interval --event-fifo \
3188 "$HSMTOOL_MONITOR_DIR/fifo"
3190 stack_trap "cdt_clear_no_retry" EXIT
3191 # Just start and stop the copytool to generate events.
3194 local f=$DIR/$tdir/$tfile
3195 local fid=$(create_small_file "$f")
3197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3198 error "could not archive file"
3199 wait_request_state $fid ARCHIVE SUCCEED
3201 local expected_fields="event_time data_fid source_fid"
3202 expected_fields+=" total_bytes current_bytes"
3205 [ARCHIVE_START]=false
3206 [ARCHIVE_FINISH]=false
3207 [ARCHIVE_RUNNING]=false
3209 while read event; do
3210 # Make sure we're not getting anything from previous events.
3211 for field in $expected_fields; do
3215 local parsed=$(parse_json_event "$event")
3216 if [ -z "$parsed" ]; then
3217 error "Copytool sent malformed event: $event"
3221 events["$event_type"]=true
3223 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3225 # Do some simple checking of the progress update events.
3226 for expected_field in $expected_fields; do
3227 if [ -z ${!expected_field+x} ]; then
3228 error "Missing $expected_field field in event"
3232 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3234 # These should be identical throughout an archive operation
3235 [ $source_fid == $data_fid ] ||
3236 error "Expected source_fid to equal data_fid"
3237 done < <(echo $"$(get_copytool_event_log)")
3239 # Check we received every type of events we were expecting
3240 for event in "${!events[@]}"; do
3241 ${events["$event"]} ||
3242 error "Copytool failed to send '$event' event to FIFO"
3245 echo "Archive events look OK."
3247 run_test 71 "Copytool logs JSON archive events to FIFO"
3250 # Bump progress interval for livelier events.
3253 # test needs a new running copytool
3254 stack_trap copytool_monitor_cleanup EXIT
3255 copytool_monitor_setup
3256 copytool setup --update-interval $interval --event-fifo \
3257 "$HSMTOOL_MONITOR_DIR/fifo"
3258 local test_file=$HSMTOOL_MONITOR_DIR/file
3260 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3262 do_facet $SINGLEAGT "$cmd" ||
3263 error "cannot create $test_file on $SINGLEAGT"
3264 copy2archive $test_file $tdir/$tfile
3267 local f=$DIR/$tdir/$tfile
3268 copytool import $tdir/$tfile $f
3269 f=$DIR2/$tdir/$tfile
3270 echo "Verifying released state: "
3271 check_hsm_flags $f "0x0000000d"
3273 local fid=$(path2fid $f)
3275 wait_request_state $fid RESTORE SUCCEED
3277 local expected_fields="event_time data_fid source_fid"
3278 expected_fields+=" total_bytes current_bytes"
3282 while read event; do
3283 # Make sure we're not getting anything from previous events.
3284 for field in $expected_fields; do
3288 local parsed=$(parse_json_event "$event")
3289 if [ -z "$parsed" ]; then
3290 error "Copytool sent malformed event: $event"
3294 if [ $event_type == "RESTORE_START" ]; then
3296 if [ $source_fid != $data_fid ]; then
3297 error "source_fid should == data_fid at start"
3300 elif [ $event_type == "RESTORE_FINISH" ]; then
3302 if [ $source_fid != $data_fid ]; then
3303 error "source_fid should == data_fid at finish"
3306 elif [ $event_type != "RESTORE_RUNNING" ]; then
3310 # Do some simple checking of the progress update events.
3311 for expected_field in $expected_fields; do
3312 if [ -z ${!expected_field+x} ]; then
3313 error "Missing $expected_field field in event"
3317 if [ $total_bytes -eq 0 ]; then
3318 error "Expected total_bytes to be > 0"
3321 # When a restore starts out, the data fid is the same as the
3322 # source fid. After the restore has gotten going, we learn
3323 # the new data fid. Once the restore has finished, the source
3324 # fid is set to the new data fid.
3326 # We test this because some monitoring software may depend on
3327 # this behavior. If it changes, then the consumers of these
3328 # events may need to be modified.
3329 if [ $source_fid == $data_fid ]; then
3330 error "source_fid should != data_fid during restore"
3332 done < <(echo $"$(get_copytool_event_log)")
3334 if [ -z "$START_EVENT" ]; then
3335 error "Copytool failed to send restore start event to FIFO"
3338 if [ -z "$FINISH_EVENT" ]; then
3339 error "Copytool failed to send restore finish event to FIFO"
3342 echo "Restore events look OK."
3344 run_test 72 "Copytool logs JSON restore events to FIFO"
3347 file_count=51 # Max number of files constrained by LNET message size
3348 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3349 local f=$DIR/$tdir/$tfile
3350 local FILELIST=/tmp/filelist.txt
3354 for i in $(seq 1 $file_count); do
3355 fid=$(copy_file /etc/hosts $f.$i)
3356 echo $f.$i >> $FILELIST
3360 # to be sure wait_all_done will not be mislead by previous tests
3362 wait_for_grace_delay
3363 $LFS hsm_archive --filelist $FILELIST ||
3364 error "cannot archive a file list"
3366 $LFS hsm_release --filelist $FILELIST ||
3367 error "cannot release a file list"
3368 $LFS hsm_restore --filelist $FILELIST ||
3369 error "cannot restore a file list"
3372 run_test 90 "Archive/restore a file list"
3374 double_verify_reset_hsm_param() {
3376 echo "Testing $HSM_PARAM.$p"
3377 local val=$(get_hsm_param $p)
3379 local val2=$(($val * 2))
3380 set_hsm_param $p $val2
3381 val=$(get_hsm_param $p)
3382 [[ $val == $val2 ]] ||
3383 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3384 echo "Set $p to 0 must failed"
3388 set_hsm_param $p $save
3390 if [[ $rc == 0 ]]; then
3391 error "we must not be able to set $HSM_PARAM.$p to 0"
3396 double_verify_reset_hsm_param loop_period
3397 double_verify_reset_hsm_param grace_delay
3398 double_verify_reset_hsm_param active_request_timeout
3399 double_verify_reset_hsm_param max_requests
3400 double_verify_reset_hsm_param default_archive_id
3402 run_test 100 "Set coordinator /proc tunables"
3409 run_test 102 "Verify coordinator control"
3412 # test needs a running copytool
3419 for i in $(seq 1 20); do
3420 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3422 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3426 echo "Current requests"
3427 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3428 $HSM_PARAM.actions |\
3429 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3431 [[ -z "$res" ]] || error "Some request have not been canceled"
3433 run_test 103 "Purge all requests"
3438 local f=$DIR/$tdir/$tfile
3439 local fid=$(create_empty_file "$f")
3441 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3442 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3443 $HSM_PARAM.actions |\
3444 grep $fid | cut -f16 -d=")
3446 [[ "$data1" == "$DATAHEX" ]] ||
3447 error "Data field in records is ($data1) and not ($DATAHEX)"
3451 run_test 104 "Copy tool data field"
3454 local max_requests=$(get_hsm_param max_requests)
3458 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3459 set_hsm_param max_requests 300
3462 for i in $(seq -w 1 10); do
3463 cp /etc/passwd $DIR/$tdir/$i
3464 $LFS hsm_archive $DIR/$tdir/$i
3466 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3467 $HSM_PARAM.actions |\
3468 grep WAITING | wc -l")
3472 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3473 $HSM_PARAM.actions |\
3474 grep WAITING | wc -l")
3477 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3478 error "Requests count after shutdown $reqcnt2 != "\
3479 "before shutdown $reqcnt1"
3481 run_test 105 "Restart of coordinator"
3484 # test needs a running copytool
3487 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3489 check_agent_registered $uuid
3491 search_copytools || error "No copytool found"
3494 wait_copytools || error "Copytool failed to stop"
3496 check_agent_unregistered $uuid
3499 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3500 check_agent_registered $uuid
3502 run_test 106 "Copytool register/unregister"
3505 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3507 # test needs a running copytool
3509 # create and archive file
3511 local f1=$DIR/$tdir/$tfile
3512 local fid=$(copy_file /etc/passwd $f1)
3513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3514 wait_request_state $fid ARCHIVE SUCCEED
3515 # shutdown and restart MDS
3517 # check the copytool still gets messages from MDT
3518 local f2=$DIR/$tdir/2
3519 local fid=$(copy_file /etc/passwd $f2)
3520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3521 # main check of this sanity: this request MUST succeed
3522 wait_request_state $fid ARCHIVE SUCCEED
3524 run_test 107 "Copytool re-register after MDS restart"
3526 policy_set_and_test()
3530 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3531 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3532 [[ "$policy" == "$target" ]] ||
3533 error "Wrong policy after '$change': '$policy' != '$target'"
3537 # to force default policy setting if error
3538 CDT_POLICY_HAD_CHANGED=true
3540 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3541 local default="NonBlockingRestore [NoRetryAction]"
3542 [[ "$policy" == "$default" ]] ||
3543 error "default policy has changed,"\
3544 " '$policy' != '$default' update the test"
3545 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3546 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3547 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3548 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3549 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3550 # useless bacause we know but safer for futur changes to use real value
3551 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3552 echo "Next set_param must failed"
3553 policy_set_and_test "wrong" "$policy"
3556 echo "Back to default policy"
3557 cdt_set_sanity_policy
3559 run_test 109 "Policy display/change"
3562 # test needs a running copytool
3567 copy2archive /etc/passwd $tdir/$tfile
3569 local f=$DIR/$tdir/$tfile
3570 copytool import $tdir/$tfile $f
3571 local fid=$(path2fid $f)
3573 cdt_set_non_blocking_restore
3578 wait_request_state $fid RESTORE SUCCEED
3579 cdt_clear_non_blocking_restore
3583 error "md5sum returns $st != 1, "\
3584 "should also perror ENODATA (No data available)"
3586 run_test 110a "Non blocking restore policy (import case)"
3589 # test needs a running copytool
3593 local f=$DIR/$tdir/$tfile
3594 local fid=$(copy_file /etc/passwd $f)
3595 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3596 wait_request_state $fid ARCHIVE SUCCEED
3599 cdt_set_non_blocking_restore
3604 wait_request_state $fid RESTORE SUCCEED
3605 cdt_clear_non_blocking_restore
3609 error "md5sum returns $st != 1, "\
3610 "should also perror ENODATA (No data available)"
3612 run_test 110b "Non blocking restore policy (release case)"
3615 # test needs a running copytool
3619 copy2archive /etc/passwd $tdir/$tfile
3621 local f=$DIR/$tdir/$tfile
3623 copytool import $tdir/$tfile $f
3624 local fid=$(path2fid $f)
3628 copytool_remove_backend $fid
3631 wait_request_state $fid RESTORE FAILED
3638 [[ $st == 0 ]] || error "Restore does not failed"
3640 run_test 111a "No retry policy (import case), restore will error"\
3641 " (No such file or directory)"
3644 # test needs a running copytool
3648 local f=$DIR/$tdir/$tfile
3649 local fid=$(copy_file /etc/passwd $f)
3650 stack_trap cdt_clear_no_retry EXIT
3652 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3653 wait_request_state $fid ARCHIVE SUCCEED
3656 copytool_remove_backend $fid
3659 wait_request_state $fid RESTORE FAILED
3663 [[ $st == 0 ]] || error "Restore does not failed"
3665 run_test 111b "No retry policy (release case), restore will error"\
3666 " (No such file or directory)"
3669 # test needs a running copytool
3673 local f=$DIR/$tdir/$tfile
3674 local fid=$(copy_file /etc/passwd $f)
3676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3677 local l=$($LFS hsm_action $f)
3679 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3682 wait_request_state $fid ARCHIVE SUCCEED
3685 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3687 run_test 112 "State of recorded request"
3690 local file1=$DIR/$tdir/$tfile
3691 local file2=$DIR2/$tdir/$tfile
3693 local fid=$(create_small_sync_file $file1)
3695 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3696 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3697 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3699 copytool setup -m "$MOUNT3"
3701 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3703 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3704 wait_request_state $fid ARCHIVE SUCCEED
3706 $LFS hsm_release $file1
3707 echo "Verifying released state: "
3708 check_hsm_flags $file1 "0x0000000d"
3710 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3713 kill -USR1 $MULTIPID
3718 local size1=$(stat -c "%s" $file1)
3719 local size2=$(stat -c "%s" $file2)
3721 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3723 run_test 113 "wrong stat after restore"
3726 local f=$DIR/$tdir/$tfile
3727 local fid=$(create_empty_file "$f")
3731 # Prevent archive from completing
3734 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3735 # wait archive to register at CDT
3736 wait_request_state $fid ARCHIVE STARTED
3738 # Cancel the archive
3739 $LFS hsm_cancel "$f"
3741 wait_request_state $fid ARCHIVE CANCELED
3744 wait_request_state $fid CANCEL SUCCEED
3746 run_test 200 "Register/Cancel archive"
3749 # test needs a running copytool
3752 local f=$DIR/$tdir/$tfile
3753 create_archive_file $tdir/$tfile
3754 copytool import $tdir/$tfile $f
3755 local fid=$(path2fid $f)
3757 # test with cdt on is made in test_222
3760 # wait restore to register at CDT
3761 wait_request_state $fid RESTORE WAITING
3764 wait_request_state $fid RESTORE CANCELED
3765 wait_request_state $fid CANCEL SUCCEED
3767 run_test 201 "Register/Cancel restore"
3770 local f=$DIR/$tdir/$tfile
3771 local fid=$(create_empty_file "$f")
3773 # test needs a running copytool
3776 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3777 wait_request_state $fid ARCHIVE SUCCEED
3781 # wait remove to register at CDT
3782 wait_request_state $fid REMOVE STARTED
3785 wait_request_state $fid REMOVE CANCELED
3787 run_test 202 "Register/Cancel remove"
3789 test_220A() { # was test_220
3790 # test needs a running copytool
3795 local f=$DIR/$tdir/$tfile
3796 local fid=$(copy_file /etc/passwd $f)
3800 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3801 wait_request_state $fid ARCHIVE SUCCEED
3803 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3804 error "The expected changelog was not emitted"
3806 run_test 220A "Changelog for archive"
3809 # test needs a running copytool
3814 local f=$DIR/$tdir/$tfile
3815 local fid=$(copy_file /etc/passwd $f)
3819 # block copytool operations to allow for HSM request to be
3820 # submitted and file be unlinked (CDT will find object removed)
3823 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3825 # wait request to reach CT
3826 wait_request_state $fid ARCHIVE STARTED
3832 wait_request_state $fid ARCHIVE FAILED
3835 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3836 error "The expected changelog was not emitted"
3838 run_test 220a "Changelog for failed archive"
3841 local f=$DIR/$tdir/$tfile
3842 local fid=$(create_empty_file "$f")
3847 # Prevent archive from completing
3849 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3850 wait_request_state $fid ARCHIVE STARTED
3853 wait_request_state $fid ARCHIVE CANCELED
3856 wait_request_state $fid CANCEL SUCCEED
3858 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3859 error "The expected changelog was not emitted"
3861 run_test 221 "Changelog for archive canceled"
3864 # test needs a running copytool
3868 copy2archive /etc/passwd $tdir/$tfile
3870 local f=$DIR/$tdir/$tfile
3871 copytool import $tdir/$tfile $f
3872 local fid=$(path2fid $f)
3877 wait_request_state $fid RESTORE SUCCEED
3879 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3880 error "The expected changelog was not emitted"
3882 run_test 222a "Changelog for explicit restore"
3885 # test needs a running copytool
3889 local f=$DIR/$tdir/$tfile
3890 local fid=$(copy_file /etc/passwd $f)
3893 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3894 wait_request_state $fid ARCHIVE SUCCEED
3899 wait_request_state $fid RESTORE SUCCEED
3901 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3902 error "The expected changelog was not emitted"
3904 run_test 222b "Changelog for implicit restore"
3907 # test needs a running copytool
3911 copy2archive /etc/passwd $tdir/$tfile
3913 local f=$DIR/$tdir/$tfile
3914 copytool import $tdir/$tfile $f
3915 local fid=$(path2fid $f)
3919 # block copytool operations to allow for HSM request to be
3920 # submitted and file be unlinked (CDT will find object removed)
3925 # wait request to reach CT
3926 wait_request_state $fid RESTORE STARTED
3932 wait_request_state $fid RESTORE FAILED
3935 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3936 error "The expected changelog was not emitted"
3938 run_test 222c "Changelog for failed explicit restore"
3941 # test needs a running copytool
3945 local f=$DIR/$tdir/$tfile
3946 local fid=$(copy_file /etc/passwd $f)
3949 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3950 wait_request_state $fid ARCHIVE SUCCEED
3953 copytool_remove_backend $fid
3956 wait_request_state $fid RESTORE FAILED
3959 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3960 error "The expected changelog was not emitted"
3962 run_test 222d "Changelog for failed implicit restore"
3965 # test needs a running copytool
3968 local f=$DIR/$tdir/$tfile
3969 create_archive_file $tdir/$tfile
3973 copytool import $tdir/$tfile $f
3974 local fid=$(path2fid $f)
3977 wait_request_state $fid RESTORE STARTED
3979 wait_request_state $fid RESTORE CANCELED
3980 wait_request_state $fid CANCEL SUCCEED
3982 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3983 error "The expected changelog was not emitted"
3985 run_test 223a "Changelog for restore canceled (import case)"
3988 local f=$DIR/$tdir/$tfile
3989 local fid=$(create_empty_file "$f")
3994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3995 wait_request_state $fid ARCHIVE SUCCEED
3998 # Prevent restore from completing
4001 wait_request_state $fid RESTORE STARTED
4004 wait_request_state $fid RESTORE CANCELED
4007 wait_request_state $fid CANCEL SUCCEED
4009 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4010 error "The expected changelog was not emitted"
4012 run_test 223b "Changelog for restore canceled (release case)"
4014 test_224A() { # was test_224
4015 # test needs a running copytool
4020 local f=$DIR/$tdir/$tfile
4021 local fid=$(copy_file /etc/passwd $f)
4024 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4025 wait_request_state $fid ARCHIVE SUCCEED
4028 wait_request_state $fid REMOVE SUCCEED
4030 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4031 error "The expected changelog was not emitted"
4033 run_test 224A "Changelog for remove"
4036 # test needs a running copytool
4041 local f=$DIR/$tdir/$tfile
4042 local fid=$(copy_file /etc/passwd $f)
4045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4046 wait_request_state $fid ARCHIVE SUCCEED
4048 copytool_remove_backend $fid
4050 # block copytool operations to allow for HSM request to be
4051 # submitted and file be unlinked (CDT will find object removed)
4056 # wait for request to reach CT
4057 wait_request_state $fid REMOVE STARTED
4063 wait_request_state $fid REMOVE FAILED
4065 # HE_REMOVE|ENOENT=0x202
4066 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4067 error "The expected changelog was not emitted"
4069 run_test 224a "Changelog for failed remove"
4072 # test is not usable because remove request is too fast
4073 # so it is always finished before cancel can be done ...
4074 echo "Test disabled"
4077 # test needs a running copytool
4080 local f=$DIR/$tdir/$tfile
4081 local fid=$(create_empty_file "$f")
4084 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4085 wait_request_state $fid ARCHIVE SUCCEED
4087 # Prevent restore from completing
4092 wait_request_state $fid REMOVE CANCELED
4095 wait_request_state $fid CANCEL SUCCEED
4097 changelog_find -type HSM -target-fid $fid -flags 0x27d
4098 error "The expected changelog was not emitted"
4100 run_test 225 "Changelog for remove canceled"
4103 # test needs a running copytool
4108 local f1=$DIR/$tdir/$tfile-1
4109 local f2=$DIR/$tdir/$tfile-2
4110 local f3=$DIR/$tdir/$tfile-3
4111 local fid1=$(copy_file /etc/passwd $f1)
4112 local fid2=$(copy_file /etc/passwd $f2)
4113 copy_file /etc/passwd $f3
4116 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4117 wait_request_state $fid1 ARCHIVE SUCCEED
4119 $LFS hsm_archive $f2
4120 wait_request_state $fid2 ARCHIVE SUCCEED
4122 rm $f1 || error "rm $f1 failed"
4125 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4126 error "The expected changelog was not emitted"
4128 mv $f3 $f2 || error "mv $f3 $f2 failed"
4130 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4131 error "The expected changelog was not emitted"
4133 run_test 226 "changelog for last rm/mv with exiting archive"
4135 # This is just a utility function to clarify what test_227 does
4140 "$LFS" "$action" --$flag "$file" ||
4141 error "Cannot ${action#hsm_} $flag on '$file'"
4143 # Only one changelog should be produced
4144 local entries="$(changelog_find -type HSM -target-fid $fid)"
4145 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4146 error "lfs $action --$flag '$file' produced more than one" \
4149 # Parse the last changelog record
4150 local entry="$(tail -n 1 <<< "$entries")"
4151 eval local -A changelog=$(changelog2array $entry)
4153 # Also check the flags match what is expected
4154 [[ ${changelog[flags]} == $target ]] ||
4155 error "Changelog flag is '${changelog[flags]}', not $target"
4159 local file="$DIR/$tdir/$tfile"
4160 local fid=$(create_empty_file "$file")
4165 for flag in norelease noarchive exists archived lost; do
4166 if [ "$flag" == lost ]; then
4167 # The flag "lost" only works on an archived file
4168 "$LFS" hsm_set --archived "$file"
4172 action="hsm_set" __test_227
4173 action="hsm_clear" __test_227
4176 run_test 227 "changelog when explicit setting of HSM flags"
4179 # test needs a running copytool
4182 local fid=$(create_small_sync_file $DIR/$tfile)
4183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4184 wait_request_state $fid ARCHIVE SUCCEED
4186 $LFS hsm_release $DIR/$tfile
4187 check_hsm_flags $DIR/$tfile "0x0000000d"
4189 filefrag $DIR/$tfile | grep " 1 extent found" ||
4190 error "filefrag on released file must return only one extent"
4192 # only newer versions of cp detect sparse files by stat/FIEMAP
4194 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4195 error "copying $DIR/$tfile"
4196 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4198 $LFS hsm_release $DIR/$tfile
4199 check_hsm_flags $DIR/$tfile "0x0000000d"
4201 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4203 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4205 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4206 error "comparing untarred $DIR/$tfile"
4208 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4209 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4211 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4214 local file="$DIR/$tdir/$tfile"
4216 # set max_requests to allow one request of each type to be started (3)
4218 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4219 set_hsm_param max_requests 3
4222 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4223 set_hsm_param loop_period 1
4225 # send 1 requests of each kind twice
4228 for action in archive restore remove; do
4229 local filepath="$file"-to-$action
4230 local fid=$(create_empty_file "$filepath")
4231 local fid2=$(create_empty_file "$filepath".bis)
4233 if [ "$action" != archive ]; then
4234 "$LFS" hsm_archive "$filepath"
4235 wait_request_state $fid ARCHIVE SUCCEED
4236 "$LFS" hsm_archive "$filepath".bis
4237 wait_request_state $fid2 ARCHIVE SUCCEED
4239 if [ "$action" == restore ]; then
4240 "$LFS" hsm_release "$filepath"
4241 "$LFS" hsm_release "$filepath".bis
4245 # suspend the copytool to prevent requests from completing
4246 stack_trap "copytool_continue" EXIT
4249 # send `max_requests' requests (one of each kind)
4250 for action in archive restore remove; do
4251 filepath="$file"-to-$action
4252 "$LFS" hsm_${action} "$filepath"
4253 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4256 # send another batch of requests
4257 for action in archive restore remove; do
4258 "$LFS" hsm_${action} "$file-to-$action".bis
4260 # wait for `loop_period' seconds to make sure the coordinator has time
4261 # to register those, even though it should not
4264 # only the first batch of request should be started
4266 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4270 error "expected 3 STARTED requests, found $count"
4272 run_test 250 "Coordinator max request"
4275 local f=$DIR/$tdir/$tfile
4276 local fid=$(create_empty_file "$f")
4279 # to have a short test
4280 local old_to=$(get_hsm_param active_request_timeout)
4281 set_hsm_param active_request_timeout 1
4282 # to be sure the cdt will wake up frequently so
4283 # it will be able to cancel the "old" request
4284 local old_loop=$(get_hsm_param loop_period)
4285 set_hsm_param loop_period 1
4290 # Prevent archive from completing
4292 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4293 wait_request_state $fid ARCHIVE STARTED
4295 # Let the request timeout
4296 wait_request_state $fid ARCHIVE CANCELED
4298 set_hsm_param active_request_timeout $old_to
4299 set_hsm_param loop_period $old_loop
4301 run_test 251 "Coordinator request timeout"
4304 local f=$DIR/$tdir/$tfile
4305 local fid=$(create_empty_file "$f")
4307 # to have a short test
4308 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4309 set_hsm_param loop_period 1
4313 # Prevent archive from completing
4315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4316 wait_request_state $fid ARCHIVE STARTED
4319 stack_trap "set_hsm_param active_request_timeout \
4320 $(get_hsm_param active_request_timeout)" EXIT
4321 set_hsm_param active_request_timeout 1
4323 wait_request_state $fid ARCHIVE CANCELED
4326 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4330 # test needs a running copytool
4334 local f=$DIR/$tdir/$tfile
4336 dd if=/dev/zero of=$f bs=1MB count=10
4337 local fid=$(path2fid $f)
4339 $LFS hsm_archive $f || error "could not archive file"
4340 wait_request_state $fid ARCHIVE SUCCEED
4342 # clear locks to discard inode data
4343 cancel_lru_locks osc
4345 #define OBD_FAIL_MDC_MERGE 0x807
4346 $LCTL set_param fail_loc=0x807
4348 #expect error here, instead of release with wrong size
4351 if ((rc == 0)); then
4352 file_size=$(stat -c '%s' $f)
4353 if ((file_size != 10485760)); then
4354 error "Wrong file size after hsm_release"
4357 echo "could not release file"
4360 run_test 253 "Check for wrong file size after release"
4364 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4365 skip "need MDS version at least 2.10.56"
4367 # Check that the counters are initialized to 0
4369 for request_type in archive restore remove; do
4370 count="$(get_hsm_param ${request_type}_count)" ||
4371 error "Reading ${request_type}_count failed with $?"
4373 [ "$count" -eq 0 ] ||
4374 error "Expected ${request_type}_count to be " \
4378 run_test 254a "Request counters are initialized to zero"
4382 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4383 skip "need MDS version at least 2.10.56"
4385 # The number of request to launch (at least 32)
4386 local request_count=$((RANDOM % 32 + 32))
4387 printf "Will launch %i requests of each type\n" "$request_count"
4389 # Launch a copytool to process requests
4392 # Set hsm.max_requests to allow starting all requests at the same time
4394 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4395 set_hsm_param max_requests "$request_count"
4399 for request_type in archive restore remove; do
4400 printf "Checking %s requests\n" "${request_type}"
4401 # Suspend the copytool to give us time to read the proc files
4404 for ((i = 0; i < $request_count; i++)); do
4405 case $request_type in
4407 create_empty_file "$DIR/$tdir/$tfile-$i" \
4411 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4414 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4417 # Give the coordinator 10 seconds to start every request
4419 while get_hsm_param actions | grep -q WAITING; do
4422 [ $timeout -gt 0 ] ||
4423 error "${request_type^} requests took too " \
4427 count="$(get_hsm_param ${request_type}_count)"
4428 [ "$count" -eq "$request_count" ] ||
4429 error "Expected '$request_count' (!= '$count') " \
4430 "active $request_type requests"
4432 # Let the copytool process the requests
4434 # Give it 10 seconds maximum
4436 while get_hsm_param actions | grep -q STARTED; do
4439 [ $timeout -gt 0 ] ||
4440 error "${request_type^} requests took too " \
4444 count="$(get_hsm_param ${request_type}_count)"
4445 [ "$count" -eq 0 ] ||
4446 error "Expected 0 (!= '$count') " \
4447 "active $request_type requests"
4450 run_test 254b "Request counters are correctly incremented and decremented"
4454 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4455 skip "Need MDS version at least 2.12.0"
4457 local file="$DIR/$tdir/$tfile"
4458 local fid=$(create_empty_file "$file")
4460 # How do you make sure the coordinator has consumed any outstanding
4461 # event, without triggering an event yourself?
4463 # You wait for a request to disappear from the coordinator's llog.
4465 # Warning: the setup represents 90% of this test
4467 # Create and process an HSM request
4469 "$LFS" hsm_archive "$file"
4470 wait_request_state $fid ARCHIVE SUCCEED
4473 wait_copytools || error "failed to stop copytools"
4475 # Launch a new HSM request
4477 create_empty_file "$file"
4478 "$LFS" hsm_archive "$file"
4482 # Have the completed request be removed as soon as the cdt wakes up
4483 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4484 set_hsm_param grace_delay 1
4485 # (Hopefully, time on the MDS will behave nicely)
4486 do_facet $SINGLEMDS sleep 2 &
4488 # Increase `loop_period' as a mean to prevent the coordinator from
4489 # waking itself up to do some housekeeping.
4490 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4491 set_hsm_param loop_period 1000
4493 wait $! || error "waiting failed"
4495 wait_request_state $fid ARCHIVE ""
4496 # The coordinator will not wake up on its own for ~`loop_period' secs...
4498 # ... Unless a copytool registers. Now the real test begins
4500 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4502 run_test 255 "Copytool registration wakes the coordinator up"
4504 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4505 # break in the future because of that.
4508 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4509 skip "need MDS version 2.11.56 or later"
4511 local -a files=("$DIR/$tdir/$tfile".{0..15})
4514 for file in "${files[@]}"; do
4515 create_small_file "$file"
4518 # Set a few hsm parameters
4520 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4521 set_hsm_param loop_period 1
4523 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4524 set_hsm_param max_requests 3
4528 "$LFS" hsm_archive "${files[0]}"
4529 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4530 "$LFS" hsm_release "${files[0]}"
4534 wait_copytools || error "copytools failed to stop"
4536 # Send several archive requests
4537 for file in "${files[@]:1}"; do
4538 "$LFS" hsm_archive "$file"
4541 # Send one restore request
4542 "$LFS" hsm_restore "${files[0]}"
4547 # Wait for all the requests to complete
4548 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4549 for file in "${files[@]:1}"; do
4550 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4553 # Collect the actions in the order in which the copytool processed them
4555 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4556 "$(copytool_logfile "$SINGLEAGT")")
4559 printf '%s\n' "${actions[@]}"
4562 for action in "${actions[@]:0:3}"; do
4563 [ "$action" == RESTORE ] && return
4566 error "Too many ARCHIVE requests were run before the RESTORE request"
4568 run_test 260a "Restore request have priority over other requests"
4570 # This test is very much tied to the implementation of the current priorisation
4571 # mechanism in the coordinator. It might not make sense to keep it in the future
4574 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4575 skip "need MDS version 2.11.56 or later"
4577 local -a files=("$DIR/$tdir/$tfile".{0..15})
4580 for file in "${files[@]}"; do
4581 create_small_file "$file"
4584 # Set a few hsm parameters
4586 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4587 set_hsm_param loop_period 1
4589 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4590 set_hsm_param max_requests 3
4593 copytool setup --archive-id 2
4594 "$LFS" hsm_archive --archive 2 "${files[0]}"
4595 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4596 "$LFS" hsm_release "${files[0]}"
4600 wait_copytools || error "copytools failed to stop"
4602 # Send several archive requests
4603 for file in "${files[@]:1}"; do
4604 "$LFS" hsm_archive "$file"
4607 # Send one restore request
4608 "$LFS" hsm_restore "${files[0]}"
4612 copytool setup --archive-id 2
4614 # Wait for all the requests to complete
4615 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4616 for file in "${files[@]:1}"; do
4617 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4620 # Collect the actions in the order in which the copytool processed them
4622 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4623 "$(copytool_logfile "$SINGLEAGT")")
4626 printf '%s\n' "${actions[@]}"
4629 for action in "${actions[@]:0:3}"; do
4630 [ "$action" == RESTORE ] && return
4633 error "Too many ARCHIVE requests were run before the RESTORE request"
4635 run_test 260b "Restore request have priority over other requests"
4637 # This test is very much tied to the implementation of the current priorisation
4638 # mechanism in the coordinator. It might not make sense to keep it in the future
4641 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4642 skip "Need MDS version at least 2.12.0"
4644 local -a files=("$DIR/$tdir/$tfile".{0..15})
4647 for file in "${files[@]}"; do
4648 create_small_file "$file"
4651 # Set a few hsm parameters
4653 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4654 set_hsm_param loop_period 1000
4656 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4657 set_hsm_param max_requests 3
4660 copytool setup --archive-id 2
4661 "$LFS" hsm_archive --archive 2 "${files[0]}"
4662 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4663 "$LFS" hsm_release "${files[0]}"
4667 wait_copytools || error "copytools failed to stop"
4669 # Force the next coordinator run to do housekeeping
4673 "$LFS" hsm_archive "${files[1]}"
4677 copytool setup --archive-id 2
4679 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4680 # The coordinator just did a housekeeping run it won't do another one
4681 # for around `loop_period' seconds => requests will not be reordered
4682 # if it costs too much (ie. when the coordinator has to discard a whole
4685 # Send several archive requests
4686 for file in "${files[@]:2}"; do
4687 "$LFS" hsm_archive "$file"
4690 # Send one restore request
4691 "$LFS" hsm_restore "${files[0]}"
4693 # Wait for all the requests to complete
4694 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4695 for file in "${files[@]:2}"; do
4696 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4699 # Collect the actions in the order in which the copytool processed them
4701 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4702 "$(copytool_logfile "$SINGLEAGT")")
4705 printf '%s\n' "${actions[@]}"
4708 for action in "${actions[@]:0:3}"; do
4709 [ "$action" == RESTORE ] &&
4710 error "Restore requests should not be prioritised" \
4711 "unless the coordinator is doing housekeeping"
4715 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4718 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4720 # the only way to test ondisk conf is to restart MDS ...
4721 echo "Stop coordinator and remove coordinator state at mount"
4724 # clean on disk conf set by default
4725 cdt_clear_mount_state
4726 cdt_check_state stopped
4728 # check cdt still off after umount/remount
4730 cdt_check_state stopped
4732 echo "Set coordinator start at mount, and start coordinator"
4733 cdt_set_mount_state enabled
4736 cdt_check_state enabled
4738 # check cdt still on after umount/remount
4740 cdt_check_state enabled
4742 # we are back to original state (cdt started at mount)
4744 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4747 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4749 local ai=$(get_hsm_param default_archive_id)
4750 local new=$((ai + 1))
4752 set_hsm_param default_archive_id $new -P
4754 local res=$(get_hsm_param default_archive_id)
4757 set_hsm_param default_archive_id "" "-P -d"
4759 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4761 run_test 301 "HSM tunnable are persistent"
4764 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4766 local ai=$(get_hsm_param default_archive_id)
4767 local new=$((ai + 1))
4772 set_hsm_param default_archive_id $new -P
4775 for mdtno in $(seq 1 $MDSCOUNT); do
4780 cdt_check_state enabled
4782 local res=$(get_hsm_param default_archive_id)
4785 set_hsm_param default_archive_id "" "-P -d"
4787 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4789 run_test 302 "HSM tunnable are persistent when CDT is off"
4792 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4798 local dir_mdt0=$DIR/$tdir/mdt0
4799 local dir_mdt1=$DIR/$tdir/mdt1
4801 # create 1 dir per MDT
4802 stack_trap "rm -rf $dir_mdt0" EXIT
4803 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4804 stack_trap "rm -rf $dir_mdt1" EXIT
4805 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4807 # create 1 file in each MDT
4808 local fid1=$(create_small_file $dir_mdt0/$tfile)
4809 local fid2=$(create_small_file $dir_mdt1/$tfile)
4811 # check that hsm request on mdt0 is sent to the right MDS
4812 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4813 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4814 echo "archive successful on mdt0"
4816 # check that hsm request on mdt1 is sent to the right MDS
4817 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4818 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4819 echo "archive successful on mdt1"
4821 run_test 400 "Single request is sent to the right MDT"
4824 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4830 local dir_mdt0=$DIR/$tdir/mdt0
4831 local dir_mdt1=$DIR/$tdir/mdt1
4833 # create 1 dir per MDT
4834 stack_trap "rm -rf $dir_mdt0" EXIT
4835 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4836 stack_trap "rm -rf $dir_mdt1" EXIT
4837 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4839 # create 1 file in each MDT
4840 local fid1=$(create_small_file $dir_mdt0/$tfile)
4841 local fid2=$(create_small_file $dir_mdt1/$tfile)
4843 # check that compound requests are shunt to the rights MDTs
4844 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4845 error "lfs hsm_archive"
4846 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4847 echo "archive successful on mdt0"
4848 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4849 echo "archive successful on mdt1"
4851 run_test 401 "Compound requests split and sent to their respective MDTs"
4853 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4858 local node=$(facet_active_host $facet)
4860 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4861 awk '{print $4}'); do
4862 echo "$3 $mdc on $node"
4863 do_facet $facet "$LCTL --device $mdc $state" || return 1
4868 # deactivate all mdc on agent1
4869 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4871 copytool setup --no-fail
4873 check_agent_unregistered "uuid" # match any agent
4875 # no expected running copytool
4876 search_copytools $agent && error "Copytool start should have failed"
4879 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4881 run_test 402a "Copytool start fails if all MDTs are inactive"
4888 local f=$DIR/$tdir/$tfile
4889 touch $f || error "touch $f failed"
4890 local fid=$(path2fid $f)
4892 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4893 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4894 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4896 # give time for CDT to send request and to keep it for retry
4897 wait_for_loop_period
4899 wait_request_state $fid ARCHIVE WAITING
4901 do_facet $SINGLEAGT lctl set_param fail_loc=0
4903 # request should succeed now
4904 wait_request_state $fid ARCHIVE SUCCEED
4906 run_test 402b "CDT must retry request upon slow start of CT"
4909 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4911 local agent=$(facet_active_host $SINGLEAGT)
4913 # deactivate all mdc for MDT0001
4914 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4917 local uuid=$(get_agent_uuid $agent)
4918 # check the agent is registered on MDT0000, and not on MDT0001
4919 check_agent_registered_by_mdt $uuid 0
4920 check_agent_unregistered_by_mdt $uuid 1
4922 # check running copytool process
4923 search_copytools $agent || error "No running copytools on $agent"
4925 # reactivate all mdc for MDT0001
4926 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4928 # make sure the copytool is now registered to all MDTs
4929 check_agent_registered $uuid
4931 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4934 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4938 # create files on both MDT0000 and MDT0001
4941 local dir_mdt0=$DIR/$tdir/mdt0
4942 stack_trap "rm -rf $dir_mdt0" EXIT
4943 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4945 # create 1 file on mdt0
4946 local fid1=$(create_small_file $dir_mdt0/$tfile)
4948 # deactivate all mdc for MDT0001
4949 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4951 # send an HSM request for files in MDT0000
4952 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4954 # check for completion of files in MDT0000
4955 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4956 echo "archive successful on mdt0"
4958 # reactivate all mdc for MDT0001
4959 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4961 run_test 404 "Inactive MDT does not block requests for active MDTs"
4964 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4970 local striped_dir=$DIR/$tdir/striped_dir
4972 # create striped dir on all of MDTs
4973 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4975 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4976 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4977 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4978 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4980 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4981 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4982 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4983 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4985 # check that compound requests are shunt to the rights MDTs
4986 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4987 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4988 error "lfs hsm_archive"
4990 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4991 echo "archive successful on $fid1"
4992 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4993 echo "archive successful on $fid2"
4994 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4995 echo "archive successful on $fid3"
4996 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4997 echo "archive successful on $fid4"
4999 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5000 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5001 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5002 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5004 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5005 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5006 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5007 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5009 run_test 405 "archive and release under striped directory"
5012 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5014 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5015 skip "need MDS version at least 2.7.64"
5020 fid=$(create_small_file $DIR/$tdir/$tfile)
5025 $LFS hsm_archive $DIR/$tdir/$tfile
5026 wait_request_state "$fid" ARCHIVE SUCCEED
5027 $LFS hsm_release $DIR/$tdir/$tfile
5029 # Should migrate $tdir but not $tfile.
5030 $LFS migrate -m1 $DIR/$tdir &&
5031 error "migrating HSM an archived file should fail"
5033 $LFS hsm_restore $DIR/$tdir/$tfile
5034 wait_request_state "$fid" RESTORE SUCCEED
5036 $LFS hsm_remove $DIR/$tdir/$tfile
5037 wait_request_state "$fid" REMOVE SUCCEED
5039 cat $DIR/$tdir/$tfile > /dev/null ||
5040 error "cannot read $DIR/$tdir/$tfile"
5042 $LFS migrate -m1 $DIR/$tdir ||
5043 error "cannot complete migration after HSM remove"
5045 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5046 if ((mdt_index != 1)); then
5047 error "expected MDT index 1, got $mdt_index"
5050 # Refresh fid after migration.
5051 fid=$(path2fid $DIR/$tdir/$tfile)
5054 $LFS hsm_archive $DIR/$tdir/$tfile
5055 wait_request_state "$fid" ARCHIVE SUCCEED 1
5057 lctl set_param debug=+trace
5058 $LFS hsm_release $DIR/$tdir/$tfile ||
5059 error "cannot release $DIR/$tdir/$tfile"
5061 $LFS hsm_restore $DIR/$tdir/$tfile
5062 wait_request_state "$fid" RESTORE SUCCEED 1
5064 cat $DIR/$tdir/$tfile > /dev/null ||
5065 error "cannot read $DIR/$tdir/$tfile"
5067 run_test 406 "attempting to migrate HSM archived files is safe"
5070 local f=$DIR/$tdir/$tfile
5071 local f2=$DIR2/$tdir/$tfile
5072 local fid=$(create_empty_file "$f")
5076 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5077 wait_request_state $fid ARCHIVE SUCCEED
5080 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5081 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5083 # Prevent restore from completing
5087 # 1st request holds layout lock while appropriate
5088 # RESTORE record is still not added to llog
5092 # after umount hsm_actions->O/x/x log shouldn't have
5093 # double RESTORE records like below
5094 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5095 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5097 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5101 wait_request_state $fid RESTORE SUCCEED
5103 run_test 407 "Check for double RESTORE records in llog"
5107 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5108 skip "HSM migrate is not supported"
5110 test_mkdir -p $DIR/$tdir
5112 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5113 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5115 llapi_hsm_test -d $DIR/$tdir -b ||
5116 error "One llapi HSM test failed"
5118 llapi_hsm_test -d $DIR/$tdir ||
5119 error "One llapi HSM test failed"
5122 run_test 500 "various LLAPI HSM tests"
5125 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5126 skip "need MDS version at least 2.10.58"
5130 local f=$DIR/$tdir/$tfile
5133 # set changelog_mask to ALL
5134 changelog_chmask "ALL"
5136 chmod 777 $DIR/$tdir
5137 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5138 local fid=$(path2fid $f)
5141 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5142 -gid "$RUNAS_GID") ||
5143 error "No matching CREAT entry"
5145 # Parse the changelog
5146 eval local -A changelog=$(changelog2array $entry)
5147 local nid="${changelog[nid]}"
5150 echo "Got NID '$nid'"
5151 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5152 error "nid '$nid' does not match any client NID:" \
5155 run_test 600 "Changelog fields 'u=' and 'nid='"
5158 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5159 skip "need MDS version at least 2.10.58"
5163 local f=$DIR/$tdir/$tfile
5166 # set changelog_mask to ALL
5167 changelog_chmask "ALL"
5169 touch $f || error "touch $f failed"
5170 local fid=$(path2fid $f)
5173 cat $f || error "cat $f failed"
5175 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5176 error "No matching OPEN entry"
5178 run_test 601 "OPEN Changelog entry"
5181 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5182 skip "need MDS version at least 2.10.58"
5186 local f=$DIR/$tdir/$tfile
5189 # set changelog_mask to ALL
5190 changelog_chmask "ALL"
5192 touch $f || error "touch $f failed"
5193 local fid=$(path2fid $f)
5196 cat $f || error "cat $f failed"
5198 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5202 echo f > $f || error "write $f failed"
5205 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5207 # remove OPEN from changelog_mask
5208 changelog_chmask "-OPEN"
5212 cat $f || error "cat $f failed"
5215 changelog_find -type CLOSE -target-fid $fid &&
5216 error "There should be no CLOSE entry"
5220 echo f > $f || error "write $f failed"
5223 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5225 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5228 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5229 skip "need MDS version at least 2.10.58"
5233 local f=$DIR/$tdir/$tfile
5236 # set changelog_mask to ALL
5237 changelog_chmask "ALL"
5239 touch $f || error "touch $f failed"
5240 local fid=$(path2fid $f)
5242 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5245 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5247 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5248 error "No matching GXATR entry"
5250 run_test 603 "GETXATTR Changelog entry"
5253 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5254 skip "need MDS version at least 2.10.58"
5258 local f=$DIR/$tdir/$tfile
5259 local f2=$DIR2/$tdir/$tfile
5260 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5262 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5263 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5264 do_facet mds1 lctl set_param "$procname=20"
5268 # set changelog_mask to ALL
5269 changelog_chmask "ALL"
5271 touch $f || error "touch $f failed"
5272 local fid=$(path2fid $f)
5278 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5282 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5283 -gid "$RUNAS_GID" -mode "r--") ||
5284 error "No matching NOPEN entry"
5286 # Parse the changelog
5287 eval local -A changelog=$(changelog2array $entry)
5288 local nid="${changelog[nid]}"
5291 echo "Got NID '$nid'"
5292 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5293 error "nid '$nid' does not match any client NID:" \
5298 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5301 changelog_find -type NOPEN -target-fid $fid &&
5302 error "There should be no NOPEN entry"
5304 # Sleep for `changelog_deniednext` seconds
5309 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5312 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5313 -gid "$RUNAS_GID" -mode "r--") ||
5314 error "No matching NOPEN entry"
5316 # Parse the changelog
5317 eval local -A changelog=$(changelog2array $entry)
5318 local nid="${changelog[nid]}"
5321 echo "Got NID '$nid'"
5322 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5323 error "nid '$nid' does not match any client NID:" \
5326 run_test 604 "NOPEN Changelog entry"
5329 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5330 skip "need MDS version at least 2.10.58"
5334 local f=$DIR/$tdir/$tfile
5335 local f2=$DIR2/$tdir/$tfile
5338 # set changelog_mask to ALL
5339 changelog_chmask "ALL"
5341 touch $f || error "touch $f failed"
5342 local fid=$(path2fid $f)
5346 exec 3<> $f || error "open $f failed"
5350 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5354 exec 4<> $f || error "open $f failed"
5357 changelog_find -type OPEN -target-fid $fid &&
5358 error "There should be no OPEN entry"
5360 exec 4>&- || error "close $f failed"
5363 changelog_find -type CLOSE -target-fid $fid &&
5364 error "There should be no CLOSE entry"
5368 # access in rw, so different access mode should generate entries
5369 cat $f || error "cat $f failed"
5372 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5374 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5378 # same access as first one, should not generate new entries
5379 exec 4<> $f || error "open $f failed"
5382 changelog_find -type OPEN -target-fid $fid &&
5383 error "There should be no OPEN entry"
5385 exec 4>&- || error "close $f failed"
5388 changelog_find -type CLOSE -target-fid $fid &&
5389 error "There should be no CLOSE entry"
5393 # access by different user should generate new entries
5394 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5397 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5399 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5403 exec 3>&- || error "close $f failed"
5406 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5408 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5411 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5412 skip "need MDS version at least 2.10.58"
5414 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5415 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5416 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5417 skip_env "missing llog_reader" && return
5418 local fstype=$(facet_fstype mds1)
5422 local f=$DIR/$tdir/$tfile
5425 # set changelog_mask to ALL
5426 changelog_chmask "ALL"
5428 chmod 777 $DIR/$tdir
5429 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5430 local fid=$(path2fid $f)
5431 rm $f || error "rm $f failed"
5433 local mntpt=$(facet_mntpt mds1)
5437 #remount mds1 as ldiskfs or zfs type
5438 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5439 stop mds1 || error "stop mds1 failed"
5440 mount_fstype mds1 || error "remount mds1 failed"
5442 for ((i = 0; i < 1; i++)); do
5443 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5444 local cat_file=$(do_facet mds1 $llog_reader \
5445 $mntpt/changelog_catalog | awk \
5446 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5447 [ -n "$cat_file" ] || error "no catalog file"
5449 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5450 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5451 [ -n "$entry" ] || error "no CREAT entry"
5454 local uidgid=$(echo $entry |
5455 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5456 [ -n "$uidgid" ] || error "uidgid is empty"
5457 echo "Got UID/GID $uidgid"
5458 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5459 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5460 local nid=$(echo $entry |
5461 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5462 [ -n "$nid" ] || error "nid is empty"
5464 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5465 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5467 run_test 606 "llog_reader groks changelog fields"
5470 check_and_cleanup_lustre