3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
12 LUSTRE=${LUSTRE:-$(dirname $0)/..}
13 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT "
19 # bug number for skipped tests: LU-9795 LU-9795
20 ALWAYS_EXCEPT+=" 13 402b "
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 # Skip tests for PPC that fail frequently
25 if [[ $(uname -m) = ppc64 ]]; then
26 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
27 ALWAYS_EXCEPT+=" 1a 1b 1d 1e 12c 12f "
28 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
29 ALWAYS_EXCEPT+=" 12g 12h 12m 12n 12o 12p "
30 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
31 ALWAYS_EXCEPT+=" 12q 21 22 23 24a 24b "
32 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
33 ALWAYS_EXCEPT+=" 24d 24e 24f 25b 30c 37 "
34 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
35 ALWAYS_EXCEPT+=" 57 58 90 110b 111b 113 "
36 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
37 ALWAYS_EXCEPT+=" 222b 222d 228 260a 260b 260c "
38 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
39 ALWAYS_EXCEPT+=" 220A 220a 221 222a 222c 223a "
40 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
41 ALWAYS_EXCEPT+=" 223b 224A 224a 226 227 600"
42 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
43 ALWAYS_EXCEPT+=" 601 602 603 604 605 "
48 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
50 OPENFILE=${OPENFILE:-openfile}
51 MMAP_CAT=${MMAP_CAT:-mmap_cat}
52 MOUNT_2=${MOUNT_2:-"yes"}
55 # script only handles up to 10 MDTs (because of MDT_PREFIX)
56 [ $MDSCOUNT -gt 9 ] &&
57 error "script cannot handle more than 9 MDTs, please fix"
59 check_and_setup_lustre
61 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
62 skip_env "Need MDS version at least 2.4.53"
65 # $RUNAS_ID may get set incorrectly somewhere else
66 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
67 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
69 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
70 if getent group nobody; then
72 elif getent group nogroup; then
75 error "No generic nobody group"
78 # if there is no CLIENT1 defined, some tests can be ran on localhost
79 CLIENT1=${CLIENT1:-$HOSTNAME}
80 # if CLIENT2 doesn't exist then use CLIENT1 instead
81 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
83 # Exception is the test which need two separate nodes
84 CLIENT2=${CLIENT2:-$CLIENT1}
87 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
88 # the following associated variables are added:
90 # AGTCOUNT: number of agents
91 # AGTDEV{N}: target HSM mount point (root path of the backend)
92 # agt{N}_HOST: hostname of the agent agt{N}
93 # SINGLEAGT: facet of the single agent
95 # The number of agents is initialized as the number of remote client nodes.
96 # By default, only single copytool is started on a remote client/agent. If there
97 # was no remote client, then the copytool will be started on the local client.
103 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
104 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
106 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
107 if [[ $CLIENTCOUNT -gt 1 ]] &&
108 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
109 skip_env "SHARED_DIRECTORY should be accessible"\
110 "on all client nodes"
114 # We used to put the HSM archive in $SHARED_DIRECTORY but that
115 # meant NFS issues could hose sanity-hsm sessions. So now we
117 for n in $(seq $AGTCOUNT); do
118 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
119 agent=CLIENT$((n + 1))
120 if [[ -z "${!agent}" ]]; then
121 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
124 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
127 export SINGLEAGT=${SINGLEAGT:-agt1}
129 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
130 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
131 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
132 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
133 export HSMTOOL_TESTDIR
137 # The test only support up to 10 MDTs
138 MDT_PREFIX="mdt.$FSNAME-MDT000"
139 HSM_PARAM="${MDT_PREFIX}0.hsm"
141 # archive is purged at copytool setup
142 HSM_ARCHIVE_PURGE=true
144 # Don't allow copytool error upon start/setup
145 HSMTOOL_NOERROR=false
148 # Get the backend root path for the given agent facet.
151 local dev=AGTDEV$(facet_number $facet)
158 # get MDT device for each mdc
159 for mdtno in $(seq 1 $MDSCOUNT); do
160 local idx=$(($mdtno - 1))
161 MDT[$idx]=$($LCTL get_param -n \
162 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
163 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
168 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
169 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
173 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
175 echo "Killing existing copytools on $hosts"
176 do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
177 copytool_continue "$hosts"
181 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
182 local wait_timeout=200
183 local wait_start=$SECONDS
184 local wait_end=$((wait_start + wait_timeout))
185 local sleep_time=100000 # 0.1 second
187 while ((SECONDS < wait_end)); do
188 if ! search_copytools $hosts; then
189 echo "copytools stopped in $((SECONDS - wait_start))s"
193 echo "copytools still running on $hosts"
195 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
196 sleep_time=$(bc <<< "$sleep_time * 2")
199 # try to dump Copytool's stack
200 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
201 "echo t >/proc/sysrq-trigger"
203 echo "copytools failed to stop in ${wait_timeout}s"
208 copytool_monitor_setup() {
209 local facet=${1:-$SINGLEAGT}
210 local agent=$(facet_active_host $facet)
212 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
213 local test_dir=$(do_node $agent "$cmd") ||
214 error "Failed to create tempdir on $agent"
215 export HSMTOOL_MONITOR_DIR=$test_dir
217 # Create the fifo and a monitor (cat dies when copytool dies)
218 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
219 error "failed to create copytool fifo on $agent"
220 cmd="cat $test_dir/fifo > $test_dir/events &"
221 cmd+=" echo \\\$! > $test_dir/monitor_pid"
223 # This background subshell nonsense is required when pdsh/ssh decides
224 # to wait for the cat process to exit on the remote client
225 (do_node $agent "$cmd") &
226 export HSMTOOL_MONITOR_PDSH=$!
228 # Slightly racy, but just making a best-effort to catch obvious
231 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
233 error "Failed to start copytool monitor on $agent"
243 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
248 get_copytool_event_log() {
249 local facet=${1:-$SINGLEAGT}
250 local agent=$(facet_active_host $facet)
252 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
253 error "Can't get event log: No monitor directory!"
255 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
256 error "Could not collect event log from $agent"
260 local agents=${1:-$(facet_active_host $SINGLEAGT)}
263 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
264 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
265 echo "Copytool is suspended on $agents"
268 copytool_continue() {
269 local agents=${1:-$(facet_active_host $SINGLEAGT)}
271 do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
272 echo "Copytool is continued on $agents"
275 copytool_remove_backend() {
277 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
278 echo "Remove from backend: $fid = $be"
279 do_facet $SINGLEAGT rm -f $be
282 file_creation_failure() {
289 df $MOUNT $MOUNT2 >&2
290 error "Not enough space to create $file with $cmd"
293 error "cannot create $file with $cmd, status=$err"
298 # Creates a file using dd
304 local source=${5:-/dev/zero}
308 if [ -n "$conv" ]; then
312 # Create the directory in case it does not exist
313 mkdir -p "$(dirname "$file")"
314 # Delete the file in case it already exist
317 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
318 path2fid "$file" || error "cannot get FID of '$file'"
321 echo "cannot create file '$file'" >&2;
322 # Let the caller decide what to do on error
327 create_empty_file() {
328 create_file "${1/$DIR/$DIR2}" 1M 0 ||
329 file_creation_failure dd "${1/$DIR/$DIR2}" $?
332 create_small_file() {
333 local source_file=/dev/urandom
336 local conv=${2:-fsync}
338 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
339 file_creation_failure dd "${1/$DIR/$DIR2}" $?
342 create_small_sync_file() {
343 create_small_file "$1" sync
346 create_archive_file() {
347 local file="$(hsm_root)/$1"
349 local source=/dev/urandom
351 # Create the counterpart directory of the archive
352 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
353 error "cannot create archive directory '$(dirname "$file")'"
355 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
356 error "cannot create archive file '$file'"
360 local hsm_root="$(hsm_root)"
361 local file="$hsm_root/$2"
363 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
364 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
365 error "mkdir '$(dirname "$file")' failed"
366 do_facet $SINGLEAGT cp -p "$1" "$file" ||
367 error "cannot copy '$1' to '$file'"
372 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
379 mdts_set_param "" hsm_control "$cmd"
380 mdts_check_param hsm_control "$target" 10
385 mdts_set_param "" hsm.policy "+NRA"
386 CDT_POLICY_HAD_CHANGED=true
389 cdt_clear_no_retry() {
390 mdts_set_param "" hsm.policy "-NRA"
391 CDT_POLICY_HAD_CHANGED=true
394 cdt_set_non_blocking_restore() {
395 mdts_set_param "" hsm.policy "+NBR"
396 CDT_POLICY_HAD_CHANGED=true
399 cdt_clear_non_blocking_restore() {
400 mdts_set_param "" hsm.policy "-NBR"
401 CDT_POLICY_HAD_CHANGED=true
404 cdt_clear_mount_state() {
405 mdts_set_param "-P -d" hsm_control ""
409 set_test_state disabled disabled
413 set_test_state enabled enabled
417 set_test_state shutdown stopped
421 set_test_state purge enabled
427 cdt_set_sanity_policy
431 get_hsm_archive_id() {
434 st=$($LFS hsm_state $f)
435 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
437 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
441 check_hsm_flags_user() {
445 local st=$(get_hsm_flags $f user)
446 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
458 if [[ "$3" != 1 ]]; then
462 cp $1 $f || file_creation_failure cp $f $?
464 path2fid $f || error "cannot get fid on $f"
467 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
469 # Note that this might lead to surprising behaviours such as deleting an
470 # important file for the currently running test
471 delete_large_files() {
472 printf "Deleting large files...\n" >&2
473 find $MOUNT -size +10M -delete
474 wait_delete_completed
477 get_request_state() {
481 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
482 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
485 get_request_count() {
489 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
490 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
493 # Ensure the number of HSM request for a given FID is correct
494 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
495 assert_request_count() {
496 local request_count=$(get_request_count $1 $2)
497 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
499 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
506 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
507 [[ -n $fid ]] && cmd+=" | grep '$fid'"
508 cmd+=" | egrep 'WAITING|STARTED'"
510 wait_result $SINGLEMDS "$cmd" "" $timeout ||
511 error "requests did not complete"
514 wait_for_grace_delay() {
515 local val=$(get_hsm_param grace_delay)
519 wait_for_loop_period() {
520 local val=$(get_hsm_param loop_period)
527 # python2.6 in EL6 includes an internal json module
528 local json_parser='import json; import fileinput;'
529 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
530 json_parser+='json.loads([line for line in '
531 json_parser+='fileinput.input()][0]).items()])'
533 echo $raw_event | python -c "$json_parser"
536 get_agent_by_uuid_mdt() {
539 local mds=mds$(($mdtidx + 1))
540 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
544 check_agent_registered_by_mdt() {
547 local mds=mds$(($mdtidx + 1))
548 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
549 if [[ ! -z "$agent" ]]; then
550 echo "found agent $agent on $mds"
552 error "uuid $uuid not found in agent list on $mds"
556 check_agent_unregistered_by_mdt() {
559 local mds=mds$(($mdtidx + 1))
560 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
561 if [[ -z "$agent" ]]; then
562 echo "uuid not found in agent list on $mds"
564 error "uuid found in agent list on $mds: $agent"
568 check_agent_registered() {
571 for mdsno in $(seq 1 $MDSCOUNT); do
572 check_agent_registered_by_mdt $uuid $((mdsno - 1))
576 check_agent_unregistered() {
579 for mdsno in $(seq 1 $MDSCOUNT); do
580 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
585 local agent=${1:-$(facet_active_host $SINGLEAGT)}
587 # Lustre mount-point is mandatory and last parameter on
589 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
591 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
593 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
599 # populate MDT device array
602 # cleanup from previous bad setup
605 # for recovery tests, coordinator needs to be started at mount
607 # the lustre conf must be without hsm on (like for sanity.sh)
608 echo "Set HSM on and start"
609 cdt_set_mount_state enabled
610 cdt_check_state enabled
612 echo "Set sanity-hsm HSM policy"
613 cdt_set_sanity_policy
615 # finished requests are quickly removed from list
616 set_hsm_param grace_delay 10
618 CLIENT_NIDS=( $($LCTL list_nids all) )
620 test_1A() { # was test_1
624 local f=$DIR/$tdir/$tfile
628 check_hsm_flags_user $f "0x00000000"
630 $RUNAS $LFS hsm_set --norelease $f ||
631 error "user could not change hsm flags"
632 check_hsm_flags_user $f "0x00000010"
634 $RUNAS $LFS hsm_clear --norelease $f ||
635 error "user could not clear hsm flags"
636 check_hsm_flags_user $f "0x00000000"
638 # User could not change those flags...
639 $RUNAS $LFS hsm_set --exists $f &&
640 error "user should not set this flag"
641 check_hsm_flags_user $f "0x00000000"
644 $LFS hsm_set --exists $f ||
645 error "root could not change hsm flags"
646 check_hsm_flags_user $f "0x00000001"
648 $LFS hsm_clear --exists $f ||
649 error "root could not clear hsm state"
650 check_hsm_flags_user $f "0x00000000"
653 run_test 1A "lfs hsm flags root/non-root access"
656 local f=$DIR/$tdir/$tfile
657 local fid=$(create_small_file $f)
661 $LFS hsm_archive $f || error "could not archive file"
662 wait_request_state $fid ARCHIVE SUCCEED
664 # Release and check states
665 $LFS hsm_release $f || error "could not release file"
666 echo -n "Verifying released state: "
667 check_hsm_flags $f "0x0000000d"
669 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
671 run_test 1a "mmap & cat a HSM released file"
677 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
678 error "failed to create file"
679 local fid=$(path2fid $f)
684 $LFS hsm_archive $f || error "could not archive file"
685 wait_request_state $fid ARCHIVE SUCCEED
688 $LFS hsm_release $f || error "could not release file"
689 echo "verify released state: "
690 check_hsm_flags $f "0x0000000d" && echo "pass"
693 $LFS hsm_restore $f || error "could not restore file"
694 wait_request_state $fid RESTORE SUCCEED
695 echo "verify restored state: "
696 check_hsm_flags $f "0x00000009" && echo "pass"
701 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
702 error "failed to set default stripe"
703 local f=$DIR/$tdir/$tfile
707 run_test 1b "Archive, Release and Restore composite file"
713 local f=$DIR/$tdir/$tfile
716 # Test whether we can set the maximum archive number.
717 local LOCAL_HSM_ARCHIVE_NUMBER=32
718 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
719 error "root could not change hsm flags"
720 check_hsm_flags_user $f "0x00000001"
721 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
722 local st=$(get_hsm_archive_id $f)
723 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
724 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
726 # Test whether setting archive number 0 results in no change.
727 $LFS hsm_set --exists --archive-id 0 $f ||
728 error "root could not change hsm flags"
729 check_hsm_flags_user $f "0x00000001"
730 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
731 st=$(get_hsm_archive_id $f)
732 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
733 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
735 LOCAL_HSM_ARCHIVE_NUMBER=33
736 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
737 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
738 # lustre in the new version supports unlimited archiveID.
739 # Test whether setting archive number > 32 is supported
740 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
741 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
742 check_hsm_flags_user $f "0x00000001"
744 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
745 st=$(get_hsm_archive_id $f)
746 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
747 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
749 # old client or old mds can only support at most 32 archiveID
750 # test whether setting archive number > 32 results in error.
751 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
752 error "bitmap archive number is larger than 32"
753 check_hsm_flags_user $f "0x00000001"
756 # Test whether setting archive number 16 and archived flag.
757 LOCAL_HSM_ARCHIVE_NUMBER=16
758 $LFS hsm_set --exists --archived \
759 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
760 error "root could not change hsm flags"
761 check_hsm_flags_user $f "0x00000009"
762 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
763 st=$(get_hsm_archive_id $f)
764 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
765 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
767 run_test 1c "Check setting archive-id in lfs hsm_set"
770 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
771 skip "need MDS version at least 2.10.59"
774 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
775 error "failed to set default stripe"
776 local f=$DIR/$tdir/$tfile
780 run_test 1d "Archive, Release and Restore DoM file"
783 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
784 skip "skipped for lustre < $SEL_VER"
787 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
788 error "failed to set default stripe"
789 local comp_file=$DIR/$tdir/$tfile
791 test_1bde_base $comp_file
793 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
794 local found=$($LFS find $flg_opts $comp_file | wc -l)
795 [ $found -eq 1 ] || error "1st component not found"
797 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
798 found=$($LFS find $flg_opts $comp_file | wc -l)
799 [ $found -eq 1 ] || error "2nd component not found"
801 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
802 found=$($LFS find $flg_opts $comp_file | wc -l)
803 [ $found -eq 1 ] || error "3rd component not found"
805 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
806 found=$($LFS find $flg_opts $comp_file | wc -l)
807 [ $found -eq 1 ] || error "4th component not found"
809 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
810 found=$($LFS find $flg_opts $comp_file | wc -l)
811 [ $found -eq 1 ] || error "5th component not found"
813 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
814 found=$($LFS find $flg_opts $comp_file | wc -l)
815 [ $found -eq 1 ] || error "6th component not found"
817 sel_layout_sanity $comp_file 6
819 run_test 1e "Archive, Release and Restore SEL file"
822 local f=$DIR/$tdir/$tfile
824 create_empty_file "$f"
825 # New files are not dirty
826 check_hsm_flags $f "0x00000000"
828 # For test, we simulate an archived file.
829 $LFS hsm_set --exists $f || error "user could not change hsm flags"
830 check_hsm_flags $f "0x00000001"
832 # chmod do not put the file dirty
833 chmod 600 $f || error "could not chmod test file"
834 check_hsm_flags $f "0x00000001"
836 # chown do not put the file dirty
837 chown $RUNAS_ID $f || error "could not chown test file"
838 check_hsm_flags $f "0x00000001"
840 # truncate put the file dirty
841 $TRUNCATE $f 1 || error "could not truncate test file"
842 check_hsm_flags $f "0x00000003"
844 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
845 check_hsm_flags $f "0x00000001"
847 run_test 2 "Check file dirtyness when doing setattr"
853 # New files are not dirty
855 check_hsm_flags $f "0x00000000"
857 # For test, we simulate an archived file.
858 $LFS hsm_set --exists $f ||
859 error "user could not change hsm flags"
860 check_hsm_flags $f "0x00000001"
862 # Reading a file, does not set dirty
863 cat $f > /dev/null || error "could not read file"
864 check_hsm_flags $f "0x00000001"
866 # Open for write without modifying data, does not set dirty
867 openfile -f O_WRONLY $f || error "could not open test file"
868 check_hsm_flags $f "0x00000001"
870 # Append to a file sets it dirty
871 cp -p /etc/passwd $f.append || error "could not create file"
872 $LFS hsm_set --exists $f.append ||
873 error "user could not change hsm flags"
874 dd if=/etc/passwd of=$f.append bs=1 count=3\
875 conv=notrunc oflag=append status=noxfer ||
876 file_creation_failure dd $f.append $?
877 check_hsm_flags $f.append "0x00000003"
879 # Modify a file sets it dirty
880 cp -p /etc/passwd $f.modify || error "could not create file"
881 $LFS hsm_set --exists $f.modify ||
882 error "user could not change hsm flags"
883 dd if=/dev/zero of=$f.modify bs=1 count=3\
884 conv=notrunc status=noxfer ||
885 file_creation_failure dd $f.modify $?
886 check_hsm_flags $f.modify "0x00000003"
888 # Open O_TRUNC sets dirty
889 cp -p /etc/passwd $f.trunc || error "could not create file"
890 $LFS hsm_set --exists $f.trunc ||
891 error "user could not change hsm flags"
892 cp /etc/group $f.trunc || error "could not override a file"
893 check_hsm_flags $f.trunc "0x00000003"
895 # Mmapped a file sets dirty
896 cp -p /etc/passwd $f.mmap || error "could not create file"
897 $LFS hsm_set --exists $f.mmap ||
898 error "user could not change hsm flags"
899 multiop $f.mmap OSMWUc || error "could not mmap a file"
900 check_hsm_flags $f.mmap "0x00000003"
902 run_test 3 "Check file dirtyness when opening for write"
905 local f=$DIR/$tdir/$tfile
906 local fid=$(create_small_file $f)
909 local st=$(get_request_state $fid CANCEL)
910 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
912 run_test 4 "Useless cancel must not be registered"
915 # test needs a running copytool
919 local f=$DIR/$tdir/$tfile
920 local fid=$(copy_file /etc/passwd $f)
922 wait_request_state $fid ARCHIVE SUCCEED
924 check_hsm_flags $f "0x00000009"
926 run_test 8 "Test default archive number"
928 test_9A() { # was test_9
929 # we do not use the default one to be sure
930 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
931 copytool setup --archive-id $archive_id
933 # give time for CT to register with MDTs
934 sleep $(($MDSCOUNT*2))
935 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
936 check_agent_registered $uuid
939 local f=$DIR/$tdir/$tfile
940 local fid=$(copy_file /etc/passwd $f)
941 $LFS hsm_archive --archive $archive_id $f
942 wait_request_state $fid ARCHIVE SUCCEED
944 check_hsm_flags $f "0x00000009"
946 run_test 9A "Use of explicit archive number, with dedicated copytool"
949 needclients 3 || return 0
955 # start all of the copytools
956 for n in $(seq $AGTCOUNT); do
957 copytool setup --facet agt$n
961 for n in $(seq $AGTCOUNT); do
962 file=$DIR/$tdir/$tfile.$n
963 fid=$(create_small_file $file)
965 $LFS hsm_archive $file || error "could not archive file $file"
966 wait_request_state $fid ARCHIVE SUCCEED
967 check_hsm_flags $file "0x00000009"
970 run_test 9a "Multiple remote agents"
973 # test needs a running copytool
976 mkdir -p $DIR/$tdir/d1
977 local f=$DIR/$tdir/$tfile
978 local fid=$(copy_file /etc/hosts $f)
979 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
980 error "hsm_archive failed"
981 wait_request_state $fid ARCHIVE SUCCEED
983 local hsm_root="$(copytool_device $SINGLEAGT)"
984 local archive="$(do_facet $SINGLEAGT \
985 find "$hsm_root" -name "$fid" -print0)"
986 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
988 echo "Verifying content"
989 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
990 echo "Verifying hsm state "
991 check_hsm_flags $f "0x00000009"
993 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
994 local st=$(get_hsm_archive_id $f)
995 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
996 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
998 run_test 10a "Archive a file"
1001 # test needs a running copytool
1005 local f=$DIR/$tdir/$tfile
1006 local fid=$(copy_file /etc/hosts $f)
1007 $LFS hsm_archive $f || error "archive request failed"
1008 wait_request_state $fid ARCHIVE SUCCEED
1010 $LFS hsm_archive $f || error "archive of non dirty file failed"
1011 local cnt=$(get_request_count $fid ARCHIVE)
1012 [[ "$cnt" == "1" ]] ||
1013 error "archive of non dirty file must not make a request"
1015 run_test 10b "Archive of non dirty file must work without doing request"
1018 # test needs a running copytool
1022 local f=$DIR/$tdir/$tfile
1023 local fid=$(copy_file /etc/hosts $f)
1024 $LFS hsm_set --noarchive $f
1025 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1028 run_test 10c "Check forbidden archive"
1031 # test needs a running copytool
1035 local f=$DIR/$tdir/$tfile
1036 local fid=$(copy_file /etc/hosts $f)
1037 $LFS hsm_archive $f || error "cannot archive $f"
1038 wait_request_state $fid ARCHIVE SUCCEED
1040 local ar=$(get_hsm_archive_id $f)
1041 local dflt=$(get_hsm_param default_archive_id)
1042 [[ $ar == $dflt ]] ||
1043 error "archived file is not on default archive: $ar != $dflt"
1045 run_test 10d "Archive a file on the default archive id"
1049 copy2archive /etc/hosts $tdir/$tfile
1050 local f=$DIR/$tdir/$tfile
1052 copytool import $tdir/$tfile $f
1053 echo -n "Verifying released state: "
1054 check_hsm_flags $f "0x0000000d"
1056 local LSZ=$(stat -c "%s" $f)
1057 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1059 echo "Verifying imported size $LSZ=$ASZ"
1060 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1061 echo -n "Verifying released pattern: "
1062 local PTRN=$($LFS getstripe -L $f)
1064 [[ $PTRN == released ]] || error "Is not released"
1065 local fid=$(path2fid $f)
1066 echo "Verifying new fid $fid in archive"
1068 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1069 error "No archive for fid $fid"
1071 run_test 11a "Import a file"
1074 # test needs a running copytool
1078 local f=$DIR/$tdir/$tfile
1079 local fid=$(copy_file /etc/hosts $f)
1080 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1081 error "hsm_archive failed"
1082 wait_request_state $fid ARCHIVE SUCCEED
1084 local FILE_HASH=$(md5sum $f)
1087 copytool import $fid $f
1089 echo "$FILE_HASH" | md5sum -c
1091 [[ $? -eq 0 ]] || error "Restored file differs"
1093 run_test 11b "Import a deleted file using its FID"
1096 # test needs a running copytool
1100 copy2archive /etc/hosts $tdir/$tfile
1102 local f=$DIR/$tdir/$tfile
1103 copytool import $tdir/$tfile $f
1104 local f2=$DIR2/$tdir/$tfile
1105 echo "Verifying released state: "
1106 check_hsm_flags $f2 "0x0000000d"
1108 local fid=$(path2fid $f2)
1109 $LFS hsm_restore $f2
1110 wait_request_state $fid RESTORE SUCCEED
1112 echo "Verifying file state: "
1113 check_hsm_flags $f2 "0x00000009"
1115 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1117 [[ $? -eq 0 ]] || error "Restored file differs"
1119 run_test 12a "Restore an imported file explicitly"
1122 # test needs a running copytool
1126 copy2archive /etc/hosts $tdir/$tfile
1128 local f=$DIR/$tdir/$tfile
1129 copytool import $tdir/$tfile $f
1130 echo "Verifying released state: "
1131 check_hsm_flags $f "0x0000000d"
1133 cat $f > /dev/null || error "File read failed"
1135 echo "Verifying file state after restore: "
1136 check_hsm_flags $f "0x00000009"
1138 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1140 [[ $? -eq 0 ]] || error "Restored file differs"
1142 run_test 12b "Restore an imported file implicitly"
1145 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1147 # test needs a running copytool
1150 local f=$DIR/$tdir/$tfile
1152 $LFS setstripe -c 2 "$f"
1153 local fid=$(create_file "$f" 1M 5)
1155 local FILE_CRC=$(md5sum $f)
1157 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1158 wait_request_state $fid ARCHIVE SUCCEED
1159 $LFS hsm_release $f || error "release $f failed"
1161 echo "$FILE_CRC" | md5sum -c
1163 [[ $? -eq 0 ]] || error "Restored file differs"
1165 run_test 12c "Restore a file with stripe of 2"
1168 # test needs a running copytool
1173 local f=$DIR/$tdir/$tfile
1174 local fid=$(copy_file /etc/hosts $f)
1175 $LFS hsm_restore $f || error "restore of non archived file failed"
1176 local cnt=$(get_request_count $fid RESTORE)
1177 [[ "$cnt" == "0" ]] ||
1178 error "restore non archived must not make a request"
1179 $LFS hsm_archive $f ||
1180 error "archive request failed"
1181 wait_request_state $fid ARCHIVE SUCCEED
1182 $LFS hsm_restore $f ||
1183 error "restore of non released file failed"
1184 local cnt=$(get_request_count $fid RESTORE)
1185 [[ "$cnt" == "0" ]] ||
1186 error "restore a non dirty file must not make a request"
1188 run_test 12d "Restore of a non archived, non released file must work"\
1189 " without doing request"
1192 # test needs a running copytool
1196 local f=$DIR/$tdir/$tfile
1197 local fid=$(copy_file /etc/hosts $f)
1198 $LFS hsm_archive $f || error "archive request failed"
1199 wait_request_state $fid ARCHIVE SUCCEED
1202 cat /etc/hosts >> $f
1206 $LFS hsm_restore $f && error "restore a dirty file must fail"
1209 run_test 12e "Check forbidden restore"
1212 # test needs a running copytool
1216 local f=$DIR/$tdir/$tfile
1217 local fid=$(copy_file /etc/hosts $f)
1219 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1220 wait_request_state $fid ARCHIVE SUCCEED
1221 $LFS hsm_release $f || error "release of $f failed"
1223 wait_request_state $fid RESTORE SUCCEED
1225 echo -n "Verifying file state: "
1226 check_hsm_flags $f "0x00000009"
1228 diff -q /etc/hosts $f
1230 [[ $? -eq 0 ]] || error "Restored file differs"
1232 run_test 12f "Restore a released file explicitly"
1235 # test needs a running copytool
1239 local f=$DIR/$tdir/$tfile
1240 local fid=$(copy_file /etc/hosts $f)
1242 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1243 wait_request_state $fid ARCHIVE SUCCEED
1244 $LFS hsm_release $f || error "release of $f failed"
1246 diff -q /etc/hosts $f
1249 # we check we had a restore done
1250 wait_request_state $fid RESTORE SUCCEED
1252 [[ $st -eq 0 ]] || error "Restored file differs"
1254 run_test 12g "Restore a released file implicitly"
1257 needclients 2 || return 0
1259 # test needs a running copytool
1263 local f=$DIR/$tdir/$tfile
1264 local fid=$(copy_file /etc/hosts $f)
1266 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1267 wait_request_state $fid ARCHIVE SUCCEED
1268 $LFS hsm_release $f || error "release of $f failed"
1270 do_node $CLIENT2 diff -q /etc/hosts $f
1273 # we check we had a restore done
1274 wait_request_state $fid RESTORE SUCCEED
1276 [[ $st -eq 0 ]] || error "Restored file differs"
1278 run_test 12h "Restore a released file implicitly from a second node"
1281 # test needs a running copytool
1285 local f=$DIR/$tdir/$tfile
1286 local fid=$(copy_file /etc/passwd $f)
1287 $LFS hsm_archive $f || error "archive of $f failed"
1288 wait_request_state $fid ARCHIVE SUCCEED
1290 $LFS hsm_release $f || error "release of $f failed"
1294 [[ $? -eq 0 ]] || error "Restored file differs"
1296 run_test 12m "Archive/release/implicit restore"
1299 # test needs a running copytool
1303 copy2archive /etc/hosts $tdir/$tfile
1305 local f=$DIR/$tdir/$tfile
1306 copytool import $tdir/$tfile $f
1308 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1309 error "Restored file differs"
1311 $LFS hsm_release $f || error "release of $f failed"
1313 run_test 12n "Import/implicit restore/release"
1316 # test needs a running copytool
1320 local f=$DIR/$tdir/$tfile
1321 local fid=$(copy_file /etc/hosts $f)
1323 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1324 wait_request_state $fid ARCHIVE SUCCEED
1325 $LFS hsm_release $f || error "release of $f failed"
1327 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1328 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1330 # set no retry action mode
1333 diff -q /etc/hosts $f
1336 # we check we had a restore failure
1337 wait_request_state $fid RESTORE FAILED
1339 [[ $st -eq 0 ]] && error "Restore must fail"
1341 # remove no retry action mode
1344 # check file is still released
1345 check_hsm_flags $f "0x0000000d"
1347 # retry w/o failure injection
1348 do_facet $SINGLEMDS lctl set_param fail_loc=0
1350 # to be sure previous RESTORE result is gone
1352 wait_for_grace_delay
1354 diff -q /etc/hosts $f
1357 # we check we had a restore done
1358 wait_request_state $fid RESTORE SUCCEED
1360 [[ $st -eq 0 ]] || error "Restored file differs"
1362 run_test 12o "Layout-swap failure during Restore leaves file released"
1365 # test needs a running copytool
1369 local f=$DIR/$tdir/$tfile
1370 local fid=$(copy_file /etc/hosts $f)
1372 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1373 wait_request_state $fid ARCHIVE SUCCEED
1374 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1375 $LFS hsm_release $f || error "cannot release $f"
1376 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1377 $LFS hsm_release $f || error "cannot release $f"
1378 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1380 run_test 12p "implicit restore of a file on copytool mount point"
1383 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1384 skip "need MDS version at least 2.7.58"
1386 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1387 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1388 error "cannot mount $MOUNT3 on $SINGLEAGT"
1390 # test needs a running copytool
1391 copytool setup -m "$MOUNT3"
1393 local f=$DIR/$tdir/$tfile
1394 local f2=$DIR2/$tdir/$tfile
1395 local fid=$(create_small_file $f)
1396 local orig_size=$(stat -c "%s" $f)
1398 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1399 wait_request_state $fid ARCHIVE SUCCEED
1401 $LFS hsm_release $f || error "could not release file"
1402 check_hsm_flags $f "0x0000000d"
1405 wait_copytools || error "copytool failed to stop"
1407 cat $f > /dev/null &
1409 # wait a bit to allow implicit restore request to be handled.
1410 # if not, next stat would also block on layout-lock.
1413 local size=$(stat -c "%s" $f2)
1414 [ $size -eq $orig_size ] ||
1415 error "$f2: wrong size after archive: $size != $orig_size"
1417 copytool setup -m "$MOUNT3"
1421 size=$(stat -c "%s" $f)
1422 [ $size -eq $orig_size ] ||
1423 error "$f: wrong size after restore: $size != $orig_size"
1425 size=$(stat -c "%s" $f2)
1426 [ $size -eq $orig_size ] ||
1427 error "$f2: wrong size after restore: $size != $orig_size"
1431 size=$(stat -c "%s" $f)
1433 error "$f: wrong size after overwrite: $size != 0"
1435 size=$(stat -c "%s" $f2)
1437 error "$f2: wrong size after overwrite: $size != 0"
1439 run_test 12q "file attributes are refreshed after restore"
1443 for i in {1..10}; do
1444 local archive_dir="$(hsm_root)"/subdir/dir.$i
1446 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1447 for j in {1..10}; do
1448 local archive_file="$archive_dir"/file.$j
1450 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1456 copytool import "subdir" "$DIR/$tdir"
1458 # To check the import, the test uses diff with the -r flag
1459 # This is nice, but diff only checks files one by one, and triggering
1460 # an implicit restore for one file at a time will consume as many
1461 # seconds as there are files to compare. To speed this up, a restore
1462 # operation is triggered manually first.
1464 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1466 # Compare the imported data
1467 do_facet $SINGLEAGT \
1468 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1469 error "imported files differ from archived data"
1471 run_test 13 "Recursively import and restore a directory"
1474 # test needs a running copytool
1478 local f=$DIR/$tdir/$tfile
1479 local fid=$(create_small_file $f)
1480 local sum=$(md5sum $f | awk '{print $1}')
1481 $LFS hsm_archive $f || error "could not archive file"
1482 wait_request_state $fid ARCHIVE SUCCEED
1484 # create released file (simulate llapi_hsm_import call)
1485 local fid2=$(create_empty_file "$f")
1486 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1487 $LFS hsm_release $f || error "could not release file"
1489 # rebind the archive to the newly created file
1490 echo "rebind $fid to $fid2"
1492 copytool rebind $fid $fid2
1494 # restore file and compare md5sum
1495 local sum2=$(md5sum $f | awk '{print $1}')
1497 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1499 run_test 14 "Rebind archived file to a new fid"
1502 # test needs a running copytool
1506 local f=$DIR/$tdir/$tfile
1508 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1512 for i in $(seq 1 $count); do
1513 fids[$i]=$(create_small_file $f.$i)
1514 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1515 $LFS hsm_archive $f.$i || error "could not archive file"
1517 wait_all_done $(($count*60))
1519 stack_trap "rm -f $tmpfile" EXIT
1522 for i in $(seq 1 $count); do
1523 local fid2=$(create_empty_file "${f}.${i}")
1524 # add the rebind operation to the list
1525 echo ${fids[$i]} $fid2 >> $tmpfile
1527 # set it released (simulate llapi_hsm_import call)
1528 $LFS hsm_set --archived --exists $f.$i ||
1529 error "could not force hsm flags"
1530 $LFS hsm_release $f.$i || error "could not release file"
1532 nl=$(wc -l < $tmpfile)
1533 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1535 echo "rebind list of files"
1536 copytool rebind "$tmpfile"
1538 # restore files and compare md5sum
1539 for i in $(seq 1 $count); do
1540 local sum2=$(md5sum $f.$i | awk '{print $1}')
1541 [[ $sum2 == ${sums[$i]} ]] ||
1542 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1545 run_test 15 "Rebind a list of files"
1548 # test needs a running copytool
1552 # create a known size file so we can verify transfer speed
1555 dd if=/dev/zero of=$ref bs=1M count=20
1558 local f=$DIR/$tdir/$tfile
1559 local fid=$(copy_file $ref $f)
1561 local start=$(date +%s)
1563 wait_request_state $fid ARCHIVE SUCCEED
1564 local end=$(date +%s)
1565 # Add 1 to account for rounding errors between start and end (LU-8155)
1566 local duration=$((end - start + 1))
1568 [[ $duration -ge $((goal - 1)) ]] ||
1569 error "Transfer is too fast $duration < $goal"
1571 run_test 16 "Test CT bandwith control option"
1574 local f=$DIR/$tdir/$tfile
1575 create_empty_file "$f"
1577 # Could not release a non-archived file
1578 $LFS hsm_release $f && error "release should not succeed"
1580 # For following tests, we must test them with HS_ARCHIVED set
1581 $LFS hsm_set --exists --archived $f || error "could not add flag"
1583 # Could not release a file if no-release is set
1584 $LFS hsm_set --norelease $f || error "could not add flag"
1585 $LFS hsm_release $f && error "release should not succeed"
1586 $LFS hsm_clear --norelease $f || error "could not remove flag"
1588 # Could not release a file if lost
1589 $LFS hsm_set --lost $f || error "could not add flag"
1590 $LFS hsm_release $f && error "release should not succeed"
1591 $LFS hsm_clear --lost $f || error "could not remove flag"
1593 # Could not release a file if dirty
1594 $LFS hsm_set --dirty $f || error "could not add flag"
1595 $LFS hsm_release $f && error "release should not succeed"
1596 $LFS hsm_clear --dirty $f || error "could not remove flag"
1598 run_test 20 "Release is not permitted"
1601 # test needs a running copytool
1604 local f=$DIR/$tdir/test_release
1606 # Create a file and check its states
1607 local fid=$(create_small_file $f)
1608 check_hsm_flags $f "0x00000000"
1610 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1611 # used until file is flushed to disk
1612 if [ $(facet_fstype ost1) == "zfs" ]; then
1613 # this causes an OST_SYNC rpc to be sent
1614 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1615 # clear locks to reread file data
1616 cancel_lru_locks osc
1619 local orig_size=$(stat -c "%s" $f)
1620 local orig_blocks=$(stat -c "%b" $f)
1622 start_full_debug_logging
1624 $LFS hsm_archive $f || error "could not archive file"
1625 wait_request_state $fid ARCHIVE SUCCEED
1627 local blocks=$(stat -c "%b" $f)
1628 [ $blocks -eq $orig_blocks ] ||
1629 error "$f: wrong block number after archive: " \
1630 "$blocks != $orig_blocks"
1631 local size=$(stat -c "%s" $f)
1632 [ $size -eq $orig_size ] ||
1633 error "$f: wrong size after archive: $size != $orig_size"
1635 # Release and check states
1636 $LFS hsm_release $f || error "could not release file"
1637 check_hsm_flags $f "0x0000000d"
1639 blocks=$(stat -c "%b" $f)
1640 [ $blocks -gt 5 ] &&
1641 error "$f: too many blocks after release: $blocks > 5"
1642 size=$(stat -c "%s" $f)
1643 [ $size -ne $orig_size ] &&
1644 error "$f: wrong size after release: $size != $orig_size"
1646 # Check we can release an file without stripe info
1650 check_hsm_flags $f "0x00000000"
1651 $LFS hsm_archive $f || error "could not archive file"
1652 wait_request_state $fid ARCHIVE SUCCEED
1654 # Release and check states
1655 $LFS hsm_release $f || error "could not release file"
1656 check_hsm_flags $f "0x0000000d"
1658 # Release again a file that is already released is OK
1659 $LFS hsm_release $f || fail "second release should succeed"
1660 check_hsm_flags $f "0x0000000d"
1662 stop_full_debug_logging
1664 run_test 21 "Simple release tests"
1667 # test needs a running copytool
1670 local f=$DIR/$tdir/test_release
1671 local swap=$DIR/$tdir/test_swap
1673 # Create a file and check its states
1674 local fid=$(create_small_file $f)
1675 check_hsm_flags $f "0x00000000"
1677 $LFS hsm_archive $f || error "could not archive file"
1678 wait_request_state $fid ARCHIVE SUCCEED
1680 # Release and check states
1681 $LFS hsm_release $f || error "could not release file"
1682 check_hsm_flags $f "0x0000000d"
1684 create_small_file $swap
1685 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1689 run_test 22 "Could not swap a release file"
1692 # test needs a running copytool
1695 local f=$DIR/$tdir/test_mtime
1697 # Create a file and check its states
1698 local fid=$(create_small_file $f)
1699 check_hsm_flags $f "0x00000000"
1701 $LFS hsm_archive $f || error "could not archive file"
1702 wait_request_state $fid ARCHIVE SUCCEED
1704 # Set modification time in the past
1705 touch -m -a -d @978261179 $f
1707 # Release and check states
1708 $LFS hsm_release $f || error "could not release file"
1709 check_hsm_flags $f "0x0000000d"
1711 local MTIME=$(stat -c "%Y" $f)
1712 local ATIME=$(stat -c "%X" $f)
1713 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1714 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1716 run_test 23 "Release does not change a/mtime (utime)"
1719 local file=$DIR/$tdir/$tfile
1728 # test needs a running copytool
1731 fid=$(create_small_file $file)
1733 # Create a file and check its states
1734 check_hsm_flags $file "0x00000000"
1736 # Ensure atime is less than mtime and ctime.
1740 atime0=$(stat -c "%X" $file)
1741 mtime0=$(stat -c "%Y" $file)
1742 ctime0=$(stat -c "%Z" $file)
1744 [ $atime0 -lt $mtime0 ] ||
1745 error "atime $atime0 is not less than mtime $mtime0"
1747 [ $atime0 -lt $ctime0 ] ||
1748 error "atime $atime0 is not less than ctime $ctime0"
1750 # Archive should not change any timestamps.
1751 $LFS hsm_archive $file || error "cannot archive '$file'"
1752 wait_request_state $fid ARCHIVE SUCCEED
1754 atime1=$(stat -c "%X" $file)
1755 mtime1=$(stat -c "%Y" $file)
1756 ctime1=$(stat -c "%Z" $file)
1758 [ $atime0 -eq $atime1 ] ||
1759 error "archive changed atime from $atime0 to $atime1"
1761 [ $mtime0 -eq $mtime1 ] ||
1762 error "archive changed mtime from $mtime0 to $mtime1"
1764 [ $ctime0 -eq $ctime1 ] ||
1765 error "archive changed ctime from $ctime0 to $ctime1"
1767 # Release should not change any timestamps.
1768 $LFS hsm_release $file || error "cannot release '$file'"
1769 check_hsm_flags $file "0x0000000d"
1771 atime1=$(stat -c "%X" $file)
1772 mtime1=$(stat -c "%Y" $file)
1773 ctime1=$(stat -c "%Z" $file)
1775 [ $atime0 -eq $atime1 ] ||
1776 error "release changed atime from $atime0 to $atime1"
1778 [ $mtime0 -eq $mtime1 ] ||
1779 error "release changed mtime from $mtime0 to $mtime1"
1781 [ $ctime0 -eq $ctime1 ] ||
1782 error "release changed ctime from $ctime0 to $ctime1"
1784 # Restore should not change any timestamps.
1785 $LFS hsm_restore $file
1786 wait_request_state $fid RESTORE SUCCEED
1788 atime1=$(stat -c "%X" $file)
1789 mtime1=$(stat -c "%Y" $file)
1790 ctime1=$(stat -c "%Z" $file)
1792 [ $atime0 -eq $atime1 ] ||
1793 error "restore changed atime from $atime0 to $atime1"
1795 [ $mtime0 -eq $mtime1 ] ||
1796 error "restore changed mtime from $mtime0 to $mtime1"
1798 [ $ctime0 -eq $ctime1 ] ||
1799 error "restore changed ctime from $ctime0 to $ctime1"
1802 wait_copytools || error "Copytools failed to stop"
1804 # Once more, after unmount and mount.
1805 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1806 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1808 atime1=$(stat -c "%X" $file)
1809 mtime1=$(stat -c "%Y" $file)
1810 ctime1=$(stat -c "%Z" $file)
1812 [ $atime0 -eq $atime1 ] ||
1813 error "remount changed atime from $atime0 to $atime1"
1815 [ $mtime0 -eq $mtime1 ] ||
1816 error "remount changed mtime from $mtime0 to $mtime1"
1818 [ $ctime0 -eq $ctime1 ] ||
1819 error "remount changed ctime from $ctime0 to $ctime1"
1821 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1824 local file=$DIR/$tdir/$tfile
1830 # Test needs a running copytool.
1833 # Check that root can do HSM actions on a regular user's file.
1834 fid=$(create_small_file $file)
1835 sum0=$(md5sum $file)
1837 chown $RUNAS_ID:$RUNAS_GID $file ||
1838 error "cannot chown '$file' to '$RUNAS_ID'"
1840 chmod ugo-w $DIR/$tdir ||
1841 error "cannot chmod '$DIR/$tdir'"
1843 $LFS hsm_archive $file
1844 wait_request_state $fid ARCHIVE SUCCEED
1846 $LFS hsm_release $file
1847 check_hsm_flags $file "0x0000000d"
1849 $LFS hsm_restore $file
1850 wait_request_state $fid RESTORE SUCCEED
1852 # Check that ordinary user can get HSM state.
1853 $RUNAS $LFS hsm_state $file ||
1854 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1856 $LFS hsm_release $file
1857 check_hsm_flags $file "0x0000000d"
1859 # Check that ordinary user can accessed released file.
1860 sum1=$($RUNAS md5sum $file) ||
1861 error "user '$RUNAS_ID' cannot read '$file'"
1863 [ "$sum0" == "$sum1" ] ||
1864 error "md5sum mismatch for '$file'"
1866 run_test 24b "root can archive, release, and restore user files"
1869 local file=$DIR/$tdir/$tfile
1870 local action=archive
1875 # test needs a running copytool
1880 # Save the default masks and check that cleanup_24c will
1881 # restore the request masks correctly.
1882 user_save=$(get_hsm_param user_request_mask)
1883 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1884 group_save=$(get_hsm_param group_request_mask)
1885 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1886 other_save=$(get_hsm_param other_request_mask)
1887 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1889 [ "$user_save" == RESTORE ] ||
1890 error "user_request_mask is '$user_save' expected 'RESTORE'"
1891 [ "$group_save" == RESTORE ] ||
1892 error "group_request_mask is '$group_save' expected 'RESTORE'"
1893 [ "$other_save" == RESTORE ] ||
1894 error "other_request_mask is '$other_save' expected 'RESTORE'"
1897 create_small_file $file
1898 chown $RUNAS_ID:$GROUP $file ||
1899 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1901 $RUNAS $LFS hsm_$action $file &&
1902 error "$action by user should fail"
1904 set_hsm_param user_request_mask $action
1905 $RUNAS $LFS hsm_$action $file ||
1906 error "$action by user should succeed"
1909 create_small_file $file
1910 chown nobody:$RUNAS_GID $file ||
1911 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1913 $RUNAS $LFS hsm_$action $file &&
1914 error "$action by group should fail"
1916 set_hsm_param group_request_mask $action
1917 $RUNAS $LFS hsm_$action $file ||
1918 error "$action by group should succeed"
1921 create_small_file $file
1922 chown nobody:$GROUP $file ||
1923 error "cannot chown '$file' to 'nobody:$GROUP'"
1925 $RUNAS $LFS hsm_$action $file &&
1926 error "$action by other should fail"
1928 set_hsm_param other_request_mask $action
1929 $RUNAS $LFS hsm_$action $file ||
1930 error "$action by other should succeed"
1932 run_test 24c "check that user,group,other request masks work"
1935 local file1=$DIR/$tdir/$tfile
1936 local file2=$DIR2/$tdir/$tfile
1940 fid1=$(create_small_file $file1)
1943 $LFS getstripe $file1
1945 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1946 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1947 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1949 copytool setup -m "$MOUNT3"
1951 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1952 mount -o remount,ro $MOUNT2
1954 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1956 fid2=$(path2fid $file2)
1957 [ "$fid1" == "$fid2" ] ||
1958 error "FID mismatch '$fid1' != '$fid2'"
1960 $LFS hsm_archive $file2 &&
1961 error "archive should fail on read-only mount"
1962 check_hsm_flags $file1 "0x00000000"
1964 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1965 wait_request_state $fid1 ARCHIVE SUCCEED
1967 $LFS hsm_release $file1
1968 $LFS hsm_restore $file2
1969 wait_request_state $fid1 RESTORE SUCCEED
1971 $LFS hsm_release $file1 || error "cannot release '$file1'"
1972 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1974 $LFS hsm_release $file2 &&
1975 error "release should fail on read-only mount"
1979 run_test 24d "check that read-only mounts are respected"
1984 local f=$DIR/$tdir/$tfile
1987 fid=$(create_small_file $f) || error "cannot create $f"
1988 $LFS hsm_archive $f || error "cannot archive $f"
1989 wait_request_state $fid ARCHIVE SUCCEED
1990 $LFS hsm_release $f || error "cannot release $f"
1991 while ! $LFS hsm_state $f | grep released; do
1995 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1997 run_test 24e "tar succeeds on HSM released files" # LU-6213
2000 # test needs a running copytool
2003 mkdir -p $DIR/$tdir/d1
2004 local f=$DIR/$tdir/$tfile
2005 local fid=$(copy_file /etc/hosts $f)
2008 $LFS hsm_archive $f ||
2009 error "hsm_archive failed"
2010 wait_request_state $fid ARCHIVE SUCCEED
2011 $LFS hsm_release $f || error "cannot release $f"
2012 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2015 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2016 error "Can not recover the tar contents"
2018 echo "Sum0 = $sum0, sum1 = $sum1"
2019 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2021 run_test 24f "root can archive, release, and restore tar files"
2024 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2025 skip "need MDS version 2.11.56 or later"
2027 local file=$DIR/$tdir/$tfile
2030 echo "RUNAS = '$RUNAS'"
2035 chmod ugo+rwx $DIR/$tdir
2037 echo "Please listen carefully as our options have changed." | tee $file
2038 fid=$(path2fid $file)
2041 $LFS hsm_archive $file
2042 wait_request_state $fid ARCHIVE SUCCEED
2043 check_hsm_flags $file 0x00000009 # exists archived
2045 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2046 check_hsm_flags $file 0x0000000b # exists dirty archived
2048 run_test 24g "write by non-owner still sets dirty" # LU-11369
2051 # test needs a running copytool
2055 copy2archive /etc/hosts $tdir/$tfile
2057 local f=$DIR/$tdir/$tfile
2059 copytool import $tdir/$tfile $f
2061 $LFS hsm_set --lost $f
2066 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2068 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2069 " (Operation not permitted)"
2072 # test needs a running copytool
2077 local f=$DIR/$tdir/$tfile
2078 local fid=$(copy_file /etc/passwd $f)
2080 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2081 wait_request_state $fid ARCHIVE SUCCEED
2084 $LFS hsm_set --lost $f
2088 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2090 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2091 " (Operation not permitted)"
2093 test_26A() { # was test_26
2094 # test needs a running copytool
2097 local f=$DIR/$tdir/$tfile
2098 local fid=$(create_empty_file "$f")
2100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2101 wait_request_state $fid ARCHIVE SUCCEED
2104 wait_request_state $fid REMOVE SUCCEED
2106 check_hsm_flags $f "0x00000000"
2108 run_test 26A "Remove the archive of a valid file"
2111 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2112 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2114 # test needs a running copytool
2118 local f=$DIR/$tdir/$tfile
2119 local fid=$(copy_file /etc/passwd $f)
2121 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2122 wait_request_state $fid ARCHIVE SUCCEED
2124 local f2=$DIR/$tdir/${tfile}_2
2125 local fid2=$(copy_file /etc/passwd $f2)
2127 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2128 wait_request_state $fid2 ARCHIVE SUCCEED
2130 local f3=$DIR/$tdir/${tfile}_3
2131 local fid3=$(copy_file /etc/passwd $f3)
2133 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2134 wait_request_state $fid3 ARCHIVE SUCCEED
2136 # set a long grace_delay vs short loop_period
2137 local orig_loop_period=$(get_hsm_param loop_period)
2138 local orig_grace_delay=$(get_hsm_param grace_delay)
2139 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2140 set_hsm_param loop_period 10
2141 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2142 set_hsm_param grace_delay 100
2146 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2147 set_hsm_param remove_archive_on_last_unlink 1
2149 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2154 wait_request_state $fid2 REMOVE SUCCEED
2156 assert_request_count $fid REMOVE 0 \
2157 "Unexpected archived data remove request for $f"
2158 assert_request_count $fid3 REMOVE 0 \
2159 "Unexpected archived data remove request for $f3"
2161 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2164 # test needs a running copytool
2168 local f=$DIR/$tdir/$tfile
2169 local fid=$(copy_file /etc/passwd $f)
2171 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2172 wait_request_state $fid ARCHIVE SUCCEED
2174 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2175 set_hsm_param remove_archive_on_last_unlink 1
2178 cdt_check_state stopped
2182 wait_request_state $fid REMOVE WAITING
2186 # copytool must re-register
2188 wait_copytools || error "copytool failed to stop"
2191 wait_request_state $fid REMOVE SUCCEED
2193 run_test 26b "RAoLU policy when CDT off"
2196 # test needs a running copytool
2200 local f=$DIR/$tdir/$tfile
2201 local fid=$(copy_file /etc/passwd $f)
2203 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2204 wait_request_state $fid ARCHIVE SUCCEED
2206 local f2=$DIR/$tdir/${tfile}_2
2207 local fid2=$(copy_file /etc/passwd $f2)
2209 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2210 wait_request_state $fid2 ARCHIVE SUCCEED
2212 # set a long grace_delay vs short loop_period
2213 local orig_loop_period=$(get_hsm_param loop_period)
2214 local orig_grace_delay=$(get_hsm_param grace_delay)
2215 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2216 set_hsm_param loop_period 10
2217 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2218 set_hsm_param grace_delay 100
2220 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2221 set_hsm_param remove_archive_on_last_unlink 1
2223 multiop_bg_pause $f O_c || error "open $f failed"
2229 wait_request_state $fid2 REMOVE SUCCEED
2230 assert_request_count $fid REMOVE 0 \
2231 "Unexpected archived data remove request for $f"
2233 kill -USR1 $pid || error "multiop early exit"
2234 # should reach autotest timeout if multiop fails to trap
2235 # signal, close file, and exit ...
2236 wait $pid || error "wait PID $PID failed"
2238 wait_request_state $fid REMOVE SUCCEED
2240 run_test 26c "RAoLU effective when file closed"
2243 # test needs a running copytool
2247 local f=$DIR/$tdir/$tfile
2248 local fid=$(create_small_file $f)
2250 $LFS hsm_archive $f || error "could not archive file"
2251 wait_request_state $fid ARCHIVE SUCCEED
2253 # set a long grace_delay vs short loop_period
2254 local orig_loop_period=$(get_hsm_param loop_period)
2255 local orig_grace_delay=$(get_hsm_param grace_delay)
2256 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2257 set_hsm_param loop_period 10
2258 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2259 set_hsm_param grace_delay 100
2261 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2262 set_hsm_param remove_archive_on_last_unlink 1
2264 multiop_bg_pause $f O_c || error "multiop failed"
2271 wait_request_state $fid REMOVE SUCCEED
2273 client_up || client_up || true
2275 kill -USR1 $MULTIPID
2276 wait $MULTIPID || error "multiop close failed"
2278 run_test 26d "RAoLU when Client eviction"
2281 # test needs a running copytool
2284 create_archive_file $tdir/$tfile
2285 local f=$DIR/$tdir/$tfile
2286 copytool import $tdir/$tfile $f
2287 local fid=$(path2fid $f)
2291 [[ $? != 0 ]] || error "Remove of a released file should fail"
2293 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2296 # test needs a running copytool
2299 local f=$DIR/$tdir/$tfile
2300 local fid=$(create_empty_file "$f")
2302 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2303 wait_request_state $fid ARCHIVE SUCCEED
2308 [[ $? != 0 ]] || error "Remove of a released file should fail"
2310 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2313 # test needs a running copytool
2316 local f=$DIR/$tdir/$tfile
2317 local fid=$(create_empty_file "$f")
2319 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2320 wait_request_state $fid ARCHIVE SUCCEED
2329 wait_request_state $fid REMOVE SUCCEED
2331 run_test 28 "Concurrent archive/file remove"
2334 # Tests --mntpath and --archive options
2337 copytool setup -m "$MOUNT" -a $archive_id
2339 # Bad archive number
2340 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2341 grep "Invalid argument" ||
2342 error "unexpected hsm_remove failure (1)"
2344 # mntpath is present but file is given
2345 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2346 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2347 error "unexpected hsm_remove failure (2)"
2349 run_test 29a "Tests --mntpath and --archive options"
2352 # test needs a running copytool
2355 local f=$DIR/$tdir/$tfile
2356 local fid=$(create_small_file $f)
2358 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2359 wait_request_state $fid ARCHIVE SUCCEED
2363 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2364 wait_request_state $fid REMOVE SUCCEED
2366 run_test 29b "Archive/delete/remove by FID from the archive."
2369 # test needs a running copytool
2372 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2373 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2374 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2376 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2377 wait_request_state $fid1 ARCHIVE SUCCEED
2378 wait_request_state $fid2 ARCHIVE SUCCEED
2379 wait_request_state $fid3 ARCHIVE SUCCEED
2381 rm -f $DIR/$tdir/$tfile-[1-3]
2383 echo $fid1 > $DIR/$tdir/list
2384 echo $fid2 >> $DIR/$tdir/list
2385 echo $fid3 >> $DIR/$tdir/list
2387 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2388 --filelist $DIR/$tdir/list
2389 wait_request_state $fid1 REMOVE SUCCEED
2390 wait_request_state $fid2 REMOVE SUCCEED
2391 wait_request_state $fid3 REMOVE SUCCEED
2393 run_test 29c "Archive/delete/remove by FID, using a file list."
2396 # test needs more than one CT
2397 needclients 3 || return 0
2403 # start all of the copytools
2404 for n in $(seq $AGTCOUNT); do
2405 copytool setup -f agt$n -a $n
2409 file=$DIR/$tdir/$tfile
2410 fid=$(create_small_file $file)
2412 $LFS hsm_archive $file
2413 wait_request_state $fid ARCHIVE SUCCEED
2414 check_hsm_flags $file "0x00000009"
2418 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2419 error "cannot hsm_remove '$fid'"
2421 # give time for CDT to handle remove request and create broadcasted
2424 # remove request has been broadcasted ?
2425 local cnt=$(get_request_count $fid REMOVE)
2426 # broadcasted requests + original
2427 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2428 error "remove not broadcasted to all CTs"
2430 # give time for CDT and CTs to handle broadcasted
2431 wait_for_loop_period
2433 # each agent serves one different archive_id, so broadcasted
2434 # hsm_remove request should only succeed once and fail at all others
2438 for n in $(seq $AGTCOUNT); do
2439 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2440 $HSM_PARAM.actions | awk \
2441 '/'$fid'.*action=REMOVE archive#='$n'/ \
2442 {print \\\$13}' | cut -f2 -d=")
2443 if [[ "$res" == "SUCCEED" ]]; then
2445 elif [[ "$res" == "FAILED" ]]; then
2450 [[ $scnt -eq 1 ]] ||
2451 error "one and only CT should have removed successfully"
2453 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2454 error "all but one CT should have failed to remove"
2456 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2457 "request to be sent once for each registered archive_id"
2460 # restore at exec cannot work on agent node (because of Linux kernel
2461 # protection of executables)
2462 needclients 2 || return 0
2464 # test needs a running copytool
2468 copy2archive /bin/true $tdir/$tfile
2470 local f=$DIR/$tdir/true
2471 copytool import $tdir/$tfile $f
2473 local fid=$(path2fid $f)
2475 stack_trap "cdt_clear_no_retry" EXIT
2476 # set no retry action mode
2483 [[ $st == 0 ]] || error "Failed to exec a released file"
2485 run_test 30a "Restore at exec (import case)"
2488 # restore at exec cannot work on agent node (because of Linux kernel
2489 # protection of executables)
2490 needclients 2 || return 0
2492 # test needs a running copytool
2496 local f=$DIR/$tdir/true
2497 local fid=$(copy_file /bin/true $f)
2499 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2500 wait_request_state $fid ARCHIVE SUCCEED
2504 stack_trap cdt_clear_no_retry EXIT
2505 # set no retry action mode
2513 [[ $st == 0 ]] || error "Failed to exec a released file"
2515 run_test 30b "Restore at exec (release case)"
2518 needclients 2 || return 0
2520 # test needs a running copytool
2524 local f=$DIR/$tdir/SLEEP
2525 local slp_sum1=$(md5sum /bin/sleep)
2526 local fid=$(copy_file /bin/sleep $f)
2528 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2529 wait_request_state $fid ARCHIVE SUCCEED
2531 check_hsm_flags $f "0x0000000d"
2533 stack_trap cdt_clear_no_retry EXIT
2534 # set no retry action mode
2537 do_node $CLIENT2 "$f 10" &
2541 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2543 [[ $? == 0 ]] || error "Execution failed during run"
2545 if [[ $? != 0 ]]; then
2546 local slp_sum2=$(md5sum /bin/sleep)
2547 # in case sleep file is modified during the test
2548 [[ $slp_sum1 == $slp_sum2 ]] &&
2549 error "Binary overwritten during exec"
2552 check_hsm_flags $f "0x00000009"
2554 run_test 30c "Update during exec of released file must fail"
2556 restore_and_check_size() {
2559 local s=$(stat -c "%s" $f)
2561 local st=$(get_hsm_flags $f)
2565 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2567 n=$(stat -c "%s" $f)
2568 # we echo in both cases to show stat is not hang
2569 if [[ $n != $s ]]; then
2570 echo "size seen is $n != $s"
2573 echo "size seen is right: $n == $s"
2577 st=$(get_hsm_flags $f)
2579 if [[ "$st" = "0x00000009" ]]; then
2582 echo " restore is too long"
2583 wait_request_state $fid RESTORE SUCCEED
2589 # test needs a running copytool
2592 create_archive_file $tdir/$tfile
2593 local f=$DIR/$tdir/$tfile
2594 copytool import $tdir/$tfile $f
2595 local fid=$($LFS path2fid $f)
2598 restore_and_check_size $f $fid
2601 [[ $err -eq 0 ]] || error "File size changed during restore"
2603 run_test 31a "Import a large file and check size during restore"
2607 # test needs a running copytool
2610 local f=$DIR/$tdir/$tfile
2611 local fid=$(create_file "$f" 1MB 39)
2613 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2614 wait_request_state $fid ARCHIVE SUCCEED
2617 restore_and_check_size $f $fid
2620 [[ $err -eq 0 ]] || error "File size changed during restore"
2622 run_test 31b "Restore a large unaligned file and check size during restore"
2625 # test needs a running copytool
2628 local f=$DIR/$tdir/$tfile
2629 local fid=$(create_file "$f" 1M 39)
2631 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2632 wait_request_state $fid ARCHIVE SUCCEED
2635 restore_and_check_size $f $fid
2638 [[ $err -eq 0 ]] || error "File size changed during restore"
2640 run_test 31c "Restore a large aligned file and check size during restore"
2643 local f=$DIR/$tdir/$tfile
2644 local fid=$(create_empty_file "$f")
2648 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2649 wait_request_state $fid ARCHIVE SUCCEED
2652 # Prevent restore from completing
2656 md5sum $f >/dev/null &
2659 wait_request_state $fid RESTORE STARTED
2664 # Check restore trigger process was killed
2666 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2668 run_test 33 "Kill a restore waiting process"
2671 # test needs a running copytool
2674 local f=$DIR/$tdir/$tfile
2675 local fid=$(create_empty_file "$f")
2677 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2678 wait_request_state $fid ARCHIVE SUCCEED
2681 # Prevent restore from completing
2684 md5sum $f >/dev/null &
2687 wait_request_state $fid RESTORE STARTED
2689 # rm must not block during restore
2690 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2693 wait_request_state $fid RESTORE SUCCEED
2695 # Check md5sum pgm finished
2696 kill -0 $pid && error "Restore initiatior still running"
2697 wait $pid || error "Restore initiator failed with $?"
2699 # Check the file was actually deleted
2700 [ ! -f "$f" ] || error "$f was not deleted"
2702 run_test 34 "Remove file during restore"
2705 # test needs a running copytool
2708 local f=$DIR/$tdir/$tfile
2709 local f1=$DIR/$tdir/$tfile-1
2710 local fid=$(create_empty_file "$f")
2711 local fid1=$(copy_file /etc/passwd $f1)
2713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2714 wait_request_state $fid ARCHIVE SUCCEED
2717 # Prevent restore from completing
2720 md5sum $f >/dev/null &
2723 wait_request_state $fid RESTORE STARTED
2725 # mv must not block during restore
2726 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2729 wait_request_state $fid RESTORE SUCCEED
2731 # Check md5sum pgm finished
2732 kill -0 $pid && error "Restore initiatior still running"
2733 wait $pid || error "Restore initiator failed with $?"
2735 local fid2=$(path2fid $f)
2736 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2738 run_test 35 "Overwrite file during restore"
2741 # test needs a running copytool
2744 local f=$DIR/$tdir/$tfile
2745 local fid=$(create_empty_file "$f")
2747 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2748 wait_request_state $fid ARCHIVE SUCCEED
2751 # Prevent restore from completing
2754 md5sum $f >/dev/null &
2757 wait_request_state $fid RESTORE STARTED
2759 # mv must not block during restore
2760 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2761 error "mv '$f' '$f.new' failed with rc=$?"
2764 wait_request_state $fid RESTORE SUCCEED
2766 # Check md5sum pgm finished
2767 kill -0 $pid && error "Restore initiator is still running"
2768 wait $pid || error "Restore initiator failed with $?"
2770 run_test 36 "Move file during restore"
2773 # LU-5683: check that an archived dirty file can be rearchived.
2776 local f=$DIR/$tdir/$tfile
2779 fid=$(create_small_file $f) || error "cannot create small file"
2781 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2782 wait_request_state $fid ARCHIVE SUCCEED
2783 $LFS hsm_release $f || error "cannot release $f"
2785 # Allow previous archive request to expire from the actions log.
2786 wait_for_grace_delay
2789 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2791 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2792 wait_request_state $fid ARCHIVE SUCCEED
2794 run_test 37 "re-archive a dirty file"
2801 for n in $(seq 1 $count); do
2802 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2804 echo "$count archive requests submitted"
2808 local stream_count=4
2809 local file_count=100
2811 local f=$DIR/$tdir/$tfile
2815 local max_requests=$(get_hsm_param max_requests)
2817 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2818 # Increase the number of HSM request that can be performed in
2819 # parallel. With the coordinator running once per second, this
2820 # also limits the number of requests per seconds that can be
2821 # performed, so we pick a decent number. But we also need to keep
2822 # that number low because the copytool has no rate limit and will
2823 # fail some requests if if gets too many at once.
2824 set_hsm_param max_requests 300
2826 for i in $(seq 1 $file_count); do
2827 for p in $(seq 1 $stream_count); do
2828 fid=$(copy_file /etc/hosts $f.$p.$i)
2834 # to be sure wait_all_done will not be mislead by previous tests
2836 wait_for_grace_delay
2838 # start archive streams in background (archive files in parallel)
2839 for p in $(seq 1 $stream_count); do
2840 multi_archive $f.$p $file_count &
2843 echo -n "Wait for all requests being enqueued..."
2848 run_test 40 "Parallel archive requests"
2851 # test needs a running copytool
2855 local f=$DIR/$tdir/$tfile
2856 local fid=$(create_small_file $f)
2858 $LFS hsm_archive $f || error "could not archive file"
2859 wait_request_state $fid ARCHIVE SUCCEED
2860 check_hsm_flags $f "0x00000009"
2862 multiop_bg_pause $f O_c || error "multiop failed"
2866 client_up || client_up || true
2868 kill -USR1 $MULTIPID
2869 wait $MULTIPID || error "multiop close failed"
2871 check_hsm_flags $f "0x0000000b"
2873 run_test 52 "Opened for write file on an evicted client should be set dirty"
2876 # test needs a running copytool
2880 local f=$DIR/$tdir/$tfile
2881 local fid=$(create_small_file $f)
2883 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2884 error "could not archive file"
2885 wait_request_state $fid ARCHIVE SUCCEED
2886 check_hsm_flags $f "0x00000009"
2888 multiop_bg_pause $f o_c || error "multiop failed"
2892 client_up || client_up || true
2894 kill -USR1 $MULTIPID
2895 wait $MULTIPID || error "multiop close failed"
2897 check_hsm_flags $f "0x00000009"
2899 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2902 local f=$DIR/$tdir/$tfile
2903 local fid=$(create_file "$f" 1MB 39)
2907 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2908 error "could not archive file"
2909 wait_request_state $fid ARCHIVE STARTED
2911 check_hsm_flags $f "0x00000001"
2913 stack_trap "cdt_clear_no_retry" EXIT
2914 # Avoid coordinator resending this request as soon it has failed.
2919 wait_request_state $fid ARCHIVE FAILED
2921 check_hsm_flags $f "0x00000003"
2923 run_test 54 "Write during an archive cancels it"
2926 local f=$DIR/$tdir/$tfile
2927 local fid=$(create_file "$f" 1MB 39)
2931 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2932 error "could not archive file"
2933 wait_request_state $fid ARCHIVE STARTED
2935 check_hsm_flags $f "0x00000001"
2937 stack_trap "cdt_clear_no_retry" EXIT
2938 # Avoid coordinator resending this request as soon it has failed.
2941 $TRUNCATE $f 1024 || error "truncate failed"
2943 wait_request_state $fid ARCHIVE FAILED
2945 check_hsm_flags $f "0x00000003"
2947 run_test 55 "Truncate during an archive cancels it"
2950 local f=$DIR/$tdir/$tfile
2951 local fid=$(create_file "$f" 1MB 39)
2955 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2956 error "could not archive file"
2957 wait_request_state $fid ARCHIVE STARTED
2959 check_hsm_flags $f "0x00000001"
2961 # Change metadata and sync to be sure we are not changing only
2966 wait_request_state $fid ARCHIVE SUCCEED
2968 check_hsm_flags $f "0x00000009"
2970 run_test 56 "Setattr during an archive is ok"
2973 # Need one client for I/O, one for request
2974 needclients 2 || return 0
2976 # test needs a running copytool
2980 local f=$DIR/$tdir/test_archive_remote
2981 # Create a file on a remote node
2982 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2983 "count=2 conv=fsync"
2986 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2987 error "hsm_archive failed"
2988 local fid=$(path2fid $f)
2989 wait_request_state $fid ARCHIVE SUCCEED
2991 # Release and implicit restore it
2992 do_node $CLIENT2 "$LFS hsm_release $f" ||
2993 error "hsm_release failed"
2994 do_node $CLIENT2 "md5sum $f" ||
2995 error "hsm_restore failed"
2997 wait_request_state $fid RESTORE SUCCEED
2999 run_test 57 "Archive a file with dirty cache on another node"
3001 truncate_released_file() {
3005 local sz=$(stat -c %s $src_file)
3006 local f=$DIR/$tdir/$tfile
3007 local fid=$(copy_file $1 $f)
3011 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3012 error "could not archive file"
3013 wait_request_state $fid ARCHIVE SUCCEED
3015 $LFS hsm_release $f || error "could not release file"
3017 $TRUNCATE $f $trunc_to || error "truncate failed"
3020 local sz1=$(stat -c %s $f)
3021 [[ $sz1 == $trunc_to ]] ||
3022 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3025 check_hsm_flags $f "0x0000000b"
3027 local state=$(get_request_state $fid RESTORE)
3028 [[ "$state" == "SUCCEED" ]] ||
3029 error "truncate $sz does not trig restore, state = $state"
3031 $TRUNCATE $ref $trunc_to
3032 cmp $ref $f || error "file data wrong after truncate"
3038 # test needs a running copytool
3043 local sz=$(stat -c %s /etc/passwd)
3045 echo "truncate up from $sz to $((sz*2))"
3046 truncate_released_file /etc/passwd $((sz*2))
3048 echo "truncate down from $sz to $((sz/2))"
3049 truncate_released_file /etc/passwd $((sz/2))
3051 echo "truncate to 0"
3052 truncate_released_file /etc/passwd 0
3054 run_test 58 "Truncate a released file will trigger restore"
3058 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3059 skip "Need MDS version at least 2.7.63"
3062 $MCREATE $DIR/$tfile || error "mcreate failed"
3063 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3064 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3065 fid=$(path2fid $DIR/$tfile)
3066 wait_request_state $fid ARCHIVE SUCCEED
3067 $LFS hsm_release $DIR/$tfile || error "release failed"
3069 run_test 59 "Release stripeless file with non-zero size"
3072 # This test validates the fix for LU-4512. Ensure that the -u
3073 # option changes the progress reporting interval from the
3074 # default (30 seconds) to the user-specified interval.
3075 local f=$DIR/$tdir/$tfile
3076 local fid=$(create_file "$f" 1M 10)
3079 local progress_timeout=$((interval * 4))
3080 copytool setup -b 1 --update-interval $interval
3083 local mdt=${MDT_PREFIX}${mdtidx}
3084 local mds=mds$((mdtidx + 1))
3086 # Wait for copytool to register
3087 wait_update_facet $mds \
3088 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3089 uuid 100 || error "coyptool failed to register with $mdt"
3091 local start_at=$(date +%s)
3092 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3093 error "could not archive file"
3095 local agent=$(facet_active_host $SINGLEAGT)
3096 local logfile=$(copytool_logfile $SINGLEAGT)
3098 wait_update $agent \
3099 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3100 error "copytool failed to start"
3102 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3103 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3109 echo -n "Expecting a progress update within $progress_timeout seconds... "
3111 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3112 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3113 echo "$RESULT bytes copied in $WAIT seconds."
3115 elif [ $WAIT -ge $progress_timeout ]; then
3116 error "Timed out waiting for progress update!"
3119 WAIT=$((WAIT + sleep))
3123 local finish_at=$(date +%s)
3124 local elapsed=$((finish_at - start_at))
3126 # Ensure that the progress update occurred within the expected window.
3127 if [ $elapsed -lt $((interval - 1)) ]; then
3128 error "Expected progress update after at least $interval seconds"
3131 echo "Wait for on going archive hsm action to complete"
3132 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3133 echo "File archiving not completed even after 10 secs"
3135 run_test 60 "Changing progress update interval from default"
3138 # test needs a running copytool
3142 local f=$DIR/$tdir/$tfile
3143 local fid=$(copy_file /etc/passwd $f)
3145 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3148 wait_request_state $fid ARCHIVE FAILED
3150 run_test 61 "Waiting archive of a removed file should fail"
3153 # test needs a new running copytool
3154 stack_trap copytool_monitor_cleanup EXIT
3155 copytool_monitor_setup
3156 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3158 # Wait for the copytool to register.
3159 wait_update --verbose $(facet_active_host mds1) \
3160 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3162 error "copytool failed to register with MDT0000"
3165 wait_copytools || error "Copytools failed to stop"
3167 local REGISTER_EVENT
3168 local UNREGISTER_EVENT
3169 while read event; do
3170 local parsed=$(parse_json_event "$event")
3171 if [ -z "$parsed" ]; then
3172 error "Copytool sent malformed event: $event"
3176 if [ $event_type == "REGISTER" ]; then
3177 REGISTER_EVENT=$event
3178 elif [ $event_type == "UNREGISTER" ]; then
3179 UNREGISTER_EVENT=$event
3181 done < <(echo $"$(get_copytool_event_log)")
3183 if [ -z "$REGISTER_EVENT" ]; then
3184 error "Copytool failed to send register event to FIFO"
3187 if [ -z "$UNREGISTER_EVENT" ]; then
3188 error "Copytool failed to send unregister event to FIFO"
3191 echo "Register/Unregister events look OK."
3193 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3196 # Bump progress interval for livelier events.
3199 # test needs a new running copytool
3200 stack_trap copytool_monitor_cleanup EXIT
3201 copytool_monitor_setup
3202 copytool setup --update-interval $interval --event-fifo \
3203 "$HSMTOOL_MONITOR_DIR/fifo"
3205 stack_trap "cdt_clear_no_retry" EXIT
3206 # Just start and stop the copytool to generate events.
3209 local f=$DIR/$tdir/$tfile
3210 local fid=$(create_small_file "$f")
3212 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3213 error "could not archive file"
3214 wait_request_state $fid ARCHIVE SUCCEED
3216 local expected_fields="event_time data_fid source_fid"
3217 expected_fields+=" total_bytes current_bytes"
3220 [ARCHIVE_START]=false
3221 [ARCHIVE_FINISH]=false
3222 [ARCHIVE_RUNNING]=false
3224 while read event; do
3225 # Make sure we're not getting anything from previous events.
3226 for field in $expected_fields; do
3230 local parsed=$(parse_json_event "$event")
3231 if [ -z "$parsed" ]; then
3232 error "Copytool sent malformed event: $event"
3236 events["$event_type"]=true
3238 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3240 # Do some simple checking of the progress update events.
3241 for expected_field in $expected_fields; do
3242 if [ -z ${!expected_field+x} ]; then
3243 error "Missing $expected_field field in event"
3247 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3249 # These should be identical throughout an archive operation
3250 [ $source_fid == $data_fid ] ||
3251 error "Expected source_fid to equal data_fid"
3252 done < <(echo $"$(get_copytool_event_log)")
3254 # Check we received every type of events we were expecting
3255 for event in "${!events[@]}"; do
3256 ${events["$event"]} ||
3257 error "Copytool failed to send '$event' event to FIFO"
3260 echo "Archive events look OK."
3262 run_test 71 "Copytool logs JSON archive events to FIFO"
3265 # Bump progress interval for livelier events.
3268 # test needs a new running copytool
3269 stack_trap copytool_monitor_cleanup EXIT
3270 copytool_monitor_setup
3271 copytool setup --update-interval $interval --event-fifo \
3272 "$HSMTOOL_MONITOR_DIR/fifo"
3273 local test_file=$HSMTOOL_MONITOR_DIR/file
3275 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3277 do_facet $SINGLEAGT "$cmd" ||
3278 error "cannot create $test_file on $SINGLEAGT"
3279 copy2archive $test_file $tdir/$tfile
3282 local f=$DIR/$tdir/$tfile
3283 copytool import $tdir/$tfile $f
3284 f=$DIR2/$tdir/$tfile
3285 echo "Verifying released state: "
3286 check_hsm_flags $f "0x0000000d"
3288 local fid=$(path2fid $f)
3290 wait_request_state $fid RESTORE SUCCEED
3292 local expected_fields="event_time data_fid source_fid"
3293 expected_fields+=" total_bytes current_bytes"
3297 while read event; do
3298 # Make sure we're not getting anything from previous events.
3299 for field in $expected_fields; do
3303 local parsed=$(parse_json_event "$event")
3304 if [ -z "$parsed" ]; then
3305 error "Copytool sent malformed event: $event"
3309 if [ $event_type == "RESTORE_START" ]; then
3311 if [ $source_fid != $data_fid ]; then
3312 error "source_fid should == data_fid at start"
3315 elif [ $event_type == "RESTORE_FINISH" ]; then
3317 if [ $source_fid != $data_fid ]; then
3318 error "source_fid should == data_fid at finish"
3321 elif [ $event_type != "RESTORE_RUNNING" ]; then
3325 # Do some simple checking of the progress update events.
3326 for expected_field in $expected_fields; do
3327 if [ -z ${!expected_field+x} ]; then
3328 error "Missing $expected_field field in event"
3332 if [ $total_bytes -eq 0 ]; then
3333 error "Expected total_bytes to be > 0"
3336 # When a restore starts out, the data fid is the same as the
3337 # source fid. After the restore has gotten going, we learn
3338 # the new data fid. Once the restore has finished, the source
3339 # fid is set to the new data fid.
3341 # We test this because some monitoring software may depend on
3342 # this behavior. If it changes, then the consumers of these
3343 # events may need to be modified.
3344 if [ $source_fid == $data_fid ]; then
3345 error "source_fid should != data_fid during restore"
3347 done < <(echo $"$(get_copytool_event_log)")
3349 if [ -z "$START_EVENT" ]; then
3350 error "Copytool failed to send restore start event to FIFO"
3353 if [ -z "$FINISH_EVENT" ]; then
3354 error "Copytool failed to send restore finish event to FIFO"
3357 echo "Restore events look OK."
3359 run_test 72 "Copytool logs JSON restore events to FIFO"
3362 file_count=51 # Max number of files constrained by LNET message size
3363 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3364 local f=$DIR/$tdir/$tfile
3365 local FILELIST=/tmp/filelist.txt
3369 for i in $(seq 1 $file_count); do
3370 fid=$(copy_file /etc/hosts $f.$i)
3371 echo $f.$i >> $FILELIST
3375 # to be sure wait_all_done will not be mislead by previous tests
3377 wait_for_grace_delay
3378 $LFS hsm_archive --filelist $FILELIST ||
3379 error "cannot archive a file list"
3381 $LFS hsm_release --filelist $FILELIST ||
3382 error "cannot release a file list"
3383 $LFS hsm_restore --filelist $FILELIST ||
3384 error "cannot restore a file list"
3387 run_test 90 "Archive/restore a file list"
3389 double_verify_reset_hsm_param() {
3391 echo "Testing $HSM_PARAM.$p"
3392 local val=$(get_hsm_param $p)
3394 local val2=$(($val * 2))
3395 set_hsm_param $p $val2
3396 val=$(get_hsm_param $p)
3397 [[ $val == $val2 ]] ||
3398 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3399 echo "Set $p to 0 must failed"
3403 set_hsm_param $p $save
3405 if [[ $rc == 0 ]]; then
3406 error "we must not be able to set $HSM_PARAM.$p to 0"
3411 double_verify_reset_hsm_param loop_period
3412 double_verify_reset_hsm_param grace_delay
3413 double_verify_reset_hsm_param active_request_timeout
3414 double_verify_reset_hsm_param max_requests
3415 double_verify_reset_hsm_param default_archive_id
3417 run_test 100 "Set coordinator /proc tunables"
3424 run_test 102 "Verify coordinator control"
3427 # test needs a running copytool
3434 for i in $(seq 1 20); do
3435 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3441 echo "Current requests"
3442 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3443 $HSM_PARAM.actions |\
3444 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3446 [[ -z "$res" ]] || error "Some request have not been canceled"
3448 run_test 103 "Purge all requests"
3453 local f=$DIR/$tdir/$tfile
3454 local fid=$(create_empty_file "$f")
3456 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3457 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3458 $HSM_PARAM.actions |\
3459 grep $fid | cut -f16 -d=")
3461 [[ "$data1" == "$DATAHEX" ]] ||
3462 error "Data field in records is ($data1) and not ($DATAHEX)"
3466 run_test 104 "Copy tool data field"
3469 local max_requests=$(get_hsm_param max_requests)
3473 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3474 set_hsm_param max_requests 300
3477 for i in $(seq -w 1 10); do
3478 cp /etc/passwd $DIR/$tdir/$i
3479 $LFS hsm_archive $DIR/$tdir/$i
3481 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3482 $HSM_PARAM.actions |\
3483 grep WAITING | wc -l")
3487 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3488 $HSM_PARAM.actions |\
3489 grep WAITING | wc -l")
3492 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3493 error "Requests count after shutdown $reqcnt2 != "\
3494 "before shutdown $reqcnt1"
3496 run_test 105 "Restart of coordinator"
3499 # test needs a running copytool
3502 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3504 check_agent_registered $uuid
3506 search_copytools || error "No copytool found"
3509 wait_copytools || error "Copytool failed to stop"
3511 check_agent_unregistered $uuid
3514 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3515 check_agent_registered $uuid
3517 run_test 106 "Copytool register/unregister"
3520 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3522 # test needs a running copytool
3524 # create and archive file
3526 local f1=$DIR/$tdir/$tfile
3527 local fid=$(copy_file /etc/passwd $f1)
3528 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3529 wait_request_state $fid ARCHIVE SUCCEED
3530 # shutdown and restart MDS
3532 # check the copytool still gets messages from MDT
3533 local f2=$DIR/$tdir/2
3534 local fid=$(copy_file /etc/passwd $f2)
3535 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3536 # main check of this sanity: this request MUST succeed
3537 wait_request_state $fid ARCHIVE SUCCEED
3539 run_test 107 "Copytool re-register after MDS restart"
3541 policy_set_and_test()
3545 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3546 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3547 [[ "$policy" == "$target" ]] ||
3548 error "Wrong policy after '$change': '$policy' != '$target'"
3552 # to force default policy setting if error
3553 CDT_POLICY_HAD_CHANGED=true
3555 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3556 local default="NonBlockingRestore [NoRetryAction]"
3557 [[ "$policy" == "$default" ]] ||
3558 error "default policy has changed,"\
3559 " '$policy' != '$default' update the test"
3560 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3561 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3562 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3563 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3564 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3565 # useless bacause we know but safer for futur changes to use real value
3566 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3567 echo "Next set_param must failed"
3568 policy_set_and_test "wrong" "$policy"
3571 echo "Back to default policy"
3572 cdt_set_sanity_policy
3574 run_test 109 "Policy display/change"
3577 # test needs a running copytool
3582 copy2archive /etc/passwd $tdir/$tfile
3584 local f=$DIR/$tdir/$tfile
3585 copytool import $tdir/$tfile $f
3586 local fid=$(path2fid $f)
3588 cdt_set_non_blocking_restore
3593 wait_request_state $fid RESTORE SUCCEED
3594 cdt_clear_non_blocking_restore
3598 error "md5sum returns $st != 1, "\
3599 "should also perror ENODATA (No data available)"
3601 run_test 110a "Non blocking restore policy (import case)"
3604 # test needs a running copytool
3608 local f=$DIR/$tdir/$tfile
3609 local fid=$(copy_file /etc/passwd $f)
3610 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3611 wait_request_state $fid ARCHIVE SUCCEED
3614 cdt_set_non_blocking_restore
3619 wait_request_state $fid RESTORE SUCCEED
3620 cdt_clear_non_blocking_restore
3624 error "md5sum returns $st != 1, "\
3625 "should also perror ENODATA (No data available)"
3627 run_test 110b "Non blocking restore policy (release case)"
3630 # test needs a running copytool
3634 copy2archive /etc/passwd $tdir/$tfile
3636 local f=$DIR/$tdir/$tfile
3638 copytool import $tdir/$tfile $f
3639 local fid=$(path2fid $f)
3643 copytool_remove_backend $fid
3646 wait_request_state $fid RESTORE FAILED
3653 [[ $st == 0 ]] || error "Restore does not failed"
3655 run_test 111a "No retry policy (import case), restore will error"\
3656 " (No such file or directory)"
3659 # test needs a running copytool
3663 local f=$DIR/$tdir/$tfile
3664 local fid=$(copy_file /etc/passwd $f)
3665 stack_trap cdt_clear_no_retry EXIT
3667 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3668 wait_request_state $fid ARCHIVE SUCCEED
3671 copytool_remove_backend $fid
3674 wait_request_state $fid RESTORE FAILED
3678 [[ $st == 0 ]] || error "Restore does not failed"
3680 run_test 111b "No retry policy (release case), restore will error"\
3681 " (No such file or directory)"
3684 # test needs a running copytool
3688 local f=$DIR/$tdir/$tfile
3689 local fid=$(copy_file /etc/passwd $f)
3691 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3692 local l=$($LFS hsm_action $f)
3694 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3697 wait_request_state $fid ARCHIVE SUCCEED
3700 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3702 run_test 112 "State of recorded request"
3705 local file1=$DIR/$tdir/$tfile
3706 local file2=$DIR2/$tdir/$tfile
3708 local fid=$(create_small_sync_file $file1)
3710 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3711 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3712 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3714 copytool setup -m "$MOUNT3"
3716 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3718 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3719 wait_request_state $fid ARCHIVE SUCCEED
3721 $LFS hsm_release $file1
3722 echo "Verifying released state: "
3723 check_hsm_flags $file1 "0x0000000d"
3725 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3728 kill -USR1 $MULTIPID
3733 local size1=$(stat -c "%s" $file1)
3734 local size2=$(stat -c "%s" $file2)
3736 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3738 run_test 113 "wrong stat after restore"
3741 local f=$DIR/$tdir/$tfile
3742 local fid=$(create_empty_file "$f")
3746 # Prevent archive from completing
3749 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3750 # wait archive to register at CDT
3751 wait_request_state $fid ARCHIVE STARTED
3753 # Cancel the archive
3754 $LFS hsm_cancel "$f"
3756 wait_request_state $fid ARCHIVE CANCELED
3759 wait_request_state $fid CANCEL SUCCEED
3761 run_test 200 "Register/Cancel archive"
3764 # test needs a running copytool
3767 local f=$DIR/$tdir/$tfile
3768 create_archive_file $tdir/$tfile
3769 copytool import $tdir/$tfile $f
3770 local fid=$(path2fid $f)
3772 # test with cdt on is made in test_222
3775 # wait restore to register at CDT
3776 wait_request_state $fid RESTORE WAITING
3779 wait_request_state $fid RESTORE CANCELED
3780 wait_request_state $fid CANCEL SUCCEED
3782 run_test 201 "Register/Cancel restore"
3785 local f=$DIR/$tdir/$tfile
3786 local fid=$(create_empty_file "$f")
3788 # test needs a running copytool
3791 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3792 wait_request_state $fid ARCHIVE SUCCEED
3796 # wait remove to register at CDT
3797 wait_request_state $fid REMOVE STARTED
3800 wait_request_state $fid REMOVE CANCELED
3802 run_test 202 "Register/Cancel remove"
3804 test_220A() { # was test_220
3805 # test needs a running copytool
3810 local f=$DIR/$tdir/$tfile
3811 local fid=$(copy_file /etc/passwd $f)
3815 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3816 wait_request_state $fid ARCHIVE SUCCEED
3818 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3819 error "The expected changelog was not emitted"
3821 run_test 220A "Changelog for archive"
3824 # test needs a running copytool
3829 local f=$DIR/$tdir/$tfile
3830 local fid=$(copy_file /etc/passwd $f)
3834 # block copytool operations to allow for HSM request to be
3835 # submitted and file be unlinked (CDT will find object removed)
3838 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3840 # wait request to reach CT
3841 wait_request_state $fid ARCHIVE STARTED
3847 wait_request_state $fid ARCHIVE FAILED
3850 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3851 error "The expected changelog was not emitted"
3853 run_test 220a "Changelog for failed archive"
3856 local f=$DIR/$tdir/$tfile
3857 local fid=$(create_empty_file "$f")
3862 # Prevent archive from completing
3864 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3865 wait_request_state $fid ARCHIVE STARTED
3868 wait_request_state $fid ARCHIVE CANCELED
3871 wait_request_state $fid CANCEL SUCCEED
3873 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3874 error "The expected changelog was not emitted"
3876 run_test 221 "Changelog for archive canceled"
3879 # test needs a running copytool
3883 copy2archive /etc/passwd $tdir/$tfile
3885 local f=$DIR/$tdir/$tfile
3886 copytool import $tdir/$tfile $f
3887 local fid=$(path2fid $f)
3892 wait_request_state $fid RESTORE SUCCEED
3894 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3895 error "The expected changelog was not emitted"
3897 run_test 222a "Changelog for explicit restore"
3900 # test needs a running copytool
3904 local f=$DIR/$tdir/$tfile
3905 local fid=$(copy_file /etc/passwd $f)
3908 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3909 wait_request_state $fid ARCHIVE SUCCEED
3914 wait_request_state $fid RESTORE SUCCEED
3916 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3917 error "The expected changelog was not emitted"
3919 run_test 222b "Changelog for implicit restore"
3922 # test needs a running copytool
3926 copy2archive /etc/passwd $tdir/$tfile
3928 local f=$DIR/$tdir/$tfile
3929 copytool import $tdir/$tfile $f
3930 local fid=$(path2fid $f)
3934 # block copytool operations to allow for HSM request to be
3935 # submitted and file be unlinked (CDT will find object removed)
3940 # wait request to reach CT
3941 wait_request_state $fid RESTORE STARTED
3947 wait_request_state $fid RESTORE FAILED
3950 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3951 error "The expected changelog was not emitted"
3953 run_test 222c "Changelog for failed explicit restore"
3956 # test needs a running copytool
3960 local f=$DIR/$tdir/$tfile
3961 local fid=$(copy_file /etc/passwd $f)
3964 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3965 wait_request_state $fid ARCHIVE SUCCEED
3968 copytool_remove_backend $fid
3971 wait_request_state $fid RESTORE FAILED
3974 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3975 error "The expected changelog was not emitted"
3977 run_test 222d "Changelog for failed implicit restore"
3980 # test needs a running copytool
3983 local f=$DIR/$tdir/$tfile
3984 create_archive_file $tdir/$tfile
3988 copytool import $tdir/$tfile $f
3989 local fid=$(path2fid $f)
3992 wait_request_state $fid RESTORE STARTED
3994 wait_request_state $fid RESTORE CANCELED
3995 wait_request_state $fid CANCEL SUCCEED
3997 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3998 error "The expected changelog was not emitted"
4000 run_test 223a "Changelog for restore canceled (import case)"
4003 local f=$DIR/$tdir/$tfile
4004 local fid=$(create_empty_file "$f")
4009 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4010 wait_request_state $fid ARCHIVE SUCCEED
4013 # Prevent restore from completing
4016 wait_request_state $fid RESTORE STARTED
4019 wait_request_state $fid RESTORE CANCELED
4022 wait_request_state $fid CANCEL SUCCEED
4024 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4025 error "The expected changelog was not emitted"
4027 run_test 223b "Changelog for restore canceled (release case)"
4029 test_224A() { # was test_224
4030 # test needs a running copytool
4035 local f=$DIR/$tdir/$tfile
4036 local fid=$(copy_file /etc/passwd $f)
4039 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4040 wait_request_state $fid ARCHIVE SUCCEED
4043 wait_request_state $fid REMOVE SUCCEED
4045 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4046 error "The expected changelog was not emitted"
4048 run_test 224A "Changelog for remove"
4051 # test needs a running copytool
4056 local f=$DIR/$tdir/$tfile
4057 local fid=$(copy_file /etc/passwd $f)
4060 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4061 wait_request_state $fid ARCHIVE SUCCEED
4063 copytool_remove_backend $fid
4065 # block copytool operations to allow for HSM request to be
4066 # submitted and file be unlinked (CDT will find object removed)
4071 # wait for request to reach CT
4072 wait_request_state $fid REMOVE STARTED
4078 wait_request_state $fid REMOVE FAILED
4080 # HE_REMOVE|ENOENT=0x202
4081 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4082 error "The expected changelog was not emitted"
4084 run_test 224a "Changelog for failed remove"
4087 # test is not usable because remove request is too fast
4088 # so it is always finished before cancel can be done ...
4089 echo "Test disabled"
4092 # test needs a running copytool
4095 local f=$DIR/$tdir/$tfile
4096 local fid=$(create_empty_file "$f")
4099 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4100 wait_request_state $fid ARCHIVE SUCCEED
4102 # Prevent restore from completing
4107 wait_request_state $fid REMOVE CANCELED
4110 wait_request_state $fid CANCEL SUCCEED
4112 changelog_find -type HSM -target-fid $fid -flags 0x27d
4113 error "The expected changelog was not emitted"
4115 run_test 225 "Changelog for remove canceled"
4118 # test needs a running copytool
4123 local f1=$DIR/$tdir/$tfile-1
4124 local f2=$DIR/$tdir/$tfile-2
4125 local f3=$DIR/$tdir/$tfile-3
4126 local fid1=$(copy_file /etc/passwd $f1)
4127 local fid2=$(copy_file /etc/passwd $f2)
4128 copy_file /etc/passwd $f3
4131 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4132 wait_request_state $fid1 ARCHIVE SUCCEED
4134 $LFS hsm_archive $f2
4135 wait_request_state $fid2 ARCHIVE SUCCEED
4137 rm $f1 || error "rm $f1 failed"
4140 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4141 error "The expected changelog was not emitted"
4143 mv $f3 $f2 || error "mv $f3 $f2 failed"
4145 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4146 error "The expected changelog was not emitted"
4148 run_test 226 "changelog for last rm/mv with exiting archive"
4150 # This is just a utility function to clarify what test_227 does
4155 "$LFS" "$action" --$flag "$file" ||
4156 error "Cannot ${action#hsm_} $flag on '$file'"
4158 # Only one changelog should be produced
4159 local entries="$(changelog_find -type HSM -target-fid $fid)"
4160 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4161 error "lfs $action --$flag '$file' produced more than one" \
4164 # Parse the last changelog record
4165 local entry="$(tail -n 1 <<< "$entries")"
4166 eval local -A changelog=$(changelog2array $entry)
4168 # Also check the flags match what is expected
4169 [[ ${changelog[flags]} == $target ]] ||
4170 error "Changelog flag is '${changelog[flags]}', not $target"
4174 local file="$DIR/$tdir/$tfile"
4175 local fid=$(create_empty_file "$file")
4180 for flag in norelease noarchive exists archived lost; do
4181 if [ "$flag" == lost ]; then
4182 # The flag "lost" only works on an archived file
4183 "$LFS" hsm_set --archived "$file"
4187 action="hsm_set" __test_227
4188 action="hsm_clear" __test_227
4191 run_test 227 "changelog when explicit setting of HSM flags"
4194 # test needs a running copytool
4197 local fid=$(create_small_sync_file $DIR/$tfile)
4198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4199 wait_request_state $fid ARCHIVE SUCCEED
4201 $LFS hsm_release $DIR/$tfile
4202 check_hsm_flags $DIR/$tfile "0x0000000d"
4204 filefrag $DIR/$tfile | grep " 1 extent found" ||
4205 error "filefrag on released file must return only one extent"
4207 # only newer versions of cp detect sparse files by stat/FIEMAP
4209 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4210 error "copying $DIR/$tfile"
4211 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4213 $LFS hsm_release $DIR/$tfile
4214 check_hsm_flags $DIR/$tfile "0x0000000d"
4216 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4218 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4220 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4221 error "comparing untarred $DIR/$tfile"
4223 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4224 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4226 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4229 local file="$DIR/$tdir/$tfile"
4231 # set max_requests to allow one request of each type to be started (3)
4233 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4234 set_hsm_param max_requests 3
4237 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4238 set_hsm_param loop_period 1
4240 # send 1 requests of each kind twice
4243 for action in archive restore remove; do
4244 local filepath="$file"-to-$action
4245 local fid=$(create_empty_file "$filepath")
4246 local fid2=$(create_empty_file "$filepath".bis)
4248 if [ "$action" != archive ]; then
4249 "$LFS" hsm_archive "$filepath"
4250 wait_request_state $fid ARCHIVE SUCCEED
4251 "$LFS" hsm_archive "$filepath".bis
4252 wait_request_state $fid2 ARCHIVE SUCCEED
4254 if [ "$action" == restore ]; then
4255 "$LFS" hsm_release "$filepath"
4256 "$LFS" hsm_release "$filepath".bis
4260 # suspend the copytool to prevent requests from completing
4261 stack_trap "copytool_continue" EXIT
4264 # send `max_requests' requests (one of each kind)
4265 for action in archive restore remove; do
4266 filepath="$file"-to-$action
4267 "$LFS" hsm_${action} "$filepath"
4268 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4271 # send another batch of requests
4272 for action in archive restore remove; do
4273 "$LFS" hsm_${action} "$file-to-$action".bis
4275 # wait for `loop_period' seconds to make sure the coordinator has time
4276 # to register those, even though it should not
4279 # only the first batch of request should be started
4281 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4285 error "expected 3 STARTED requests, found $count"
4287 run_test 250 "Coordinator max request"
4290 local f=$DIR/$tdir/$tfile
4291 local fid=$(create_empty_file "$f")
4294 # to have a short test
4295 local old_to=$(get_hsm_param active_request_timeout)
4296 set_hsm_param active_request_timeout 1
4297 # to be sure the cdt will wake up frequently so
4298 # it will be able to cancel the "old" request
4299 local old_loop=$(get_hsm_param loop_period)
4300 set_hsm_param loop_period 1
4305 # Prevent archive from completing
4307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4308 wait_request_state $fid ARCHIVE STARTED
4310 # Let the request timeout
4311 wait_request_state $fid ARCHIVE CANCELED
4313 set_hsm_param active_request_timeout $old_to
4314 set_hsm_param loop_period $old_loop
4316 run_test 251 "Coordinator request timeout"
4319 local f=$DIR/$tdir/$tfile
4320 local fid=$(create_empty_file "$f")
4322 # to have a short test
4323 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4324 set_hsm_param loop_period 1
4328 # Prevent archive from completing
4330 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4331 wait_request_state $fid ARCHIVE STARTED
4334 stack_trap "set_hsm_param active_request_timeout \
4335 $(get_hsm_param active_request_timeout)" EXIT
4336 set_hsm_param active_request_timeout 1
4338 wait_request_state $fid ARCHIVE CANCELED
4341 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4345 # test needs a running copytool
4349 local f=$DIR/$tdir/$tfile
4351 dd if=/dev/zero of=$f bs=1MB count=10
4352 local fid=$(path2fid $f)
4354 $LFS hsm_archive $f || error "could not archive file"
4355 wait_request_state $fid ARCHIVE SUCCEED
4357 # clear locks to discard inode data
4358 cancel_lru_locks osc
4360 #define OBD_FAIL_MDC_MERGE 0x807
4361 $LCTL set_param fail_loc=0x807
4363 #expect error here, instead of release with wrong size
4366 if ((rc == 0)); then
4367 file_size=$(stat -c '%s' $f)
4368 if ((file_size != 10485760)); then
4369 error "Wrong file size after hsm_release"
4372 echo "could not release file"
4375 run_test 253 "Check for wrong file size after release"
4379 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4380 skip "need MDS version at least 2.10.56"
4382 # Check that the counters are initialized to 0
4384 for request_type in archive restore remove; do
4385 count="$(get_hsm_param ${request_type}_count)" ||
4386 error "Reading ${request_type}_count failed with $?"
4388 [ "$count" -eq 0 ] ||
4389 error "Expected ${request_type}_count to be " \
4393 run_test 254a "Request counters are initialized to zero"
4397 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4398 skip "need MDS version at least 2.10.56"
4400 # The number of request to launch (at least 32)
4401 local request_count=$((RANDOM % 32 + 32))
4402 printf "Will launch %i requests of each type\n" "$request_count"
4404 # Launch a copytool to process requests
4407 # Set hsm.max_requests to allow starting all requests at the same time
4409 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4410 set_hsm_param max_requests "$request_count"
4414 for request_type in archive restore remove; do
4415 printf "Checking %s requests\n" "${request_type}"
4416 # Suspend the copytool to give us time to read the proc files
4419 for ((i = 0; i < $request_count; i++)); do
4420 case $request_type in
4422 create_empty_file "$DIR/$tdir/$tfile-$i" \
4426 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4429 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4432 # Give the coordinator 10 seconds to start every request
4434 while get_hsm_param actions | grep -q WAITING; do
4437 [ $timeout -gt 0 ] ||
4438 error "${request_type^} requests took too " \
4442 count="$(get_hsm_param ${request_type}_count)"
4443 [ "$count" -eq "$request_count" ] ||
4444 error "Expected '$request_count' (!= '$count') " \
4445 "active $request_type requests"
4447 # Let the copytool process the requests
4449 # Give it 10 seconds maximum
4451 while get_hsm_param actions | grep -q STARTED; do
4454 [ $timeout -gt 0 ] ||
4455 error "${request_type^} requests took too " \
4459 count="$(get_hsm_param ${request_type}_count)"
4460 [ "$count" -eq 0 ] ||
4461 error "Expected 0 (!= '$count') " \
4462 "active $request_type requests"
4465 run_test 254b "Request counters are correctly incremented and decremented"
4469 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4470 skip "Need MDS version at least 2.12.0"
4472 local file="$DIR/$tdir/$tfile"
4473 local fid=$(create_empty_file "$file")
4475 # How do you make sure the coordinator has consumed any outstanding
4476 # event, without triggering an event yourself?
4478 # You wait for a request to disappear from the coordinator's llog.
4480 # Warning: the setup represents 90% of this test
4482 # Create and process an HSM request
4484 "$LFS" hsm_archive "$file"
4485 wait_request_state $fid ARCHIVE SUCCEED
4488 wait_copytools || error "failed to stop copytools"
4490 # Launch a new HSM request
4492 create_empty_file "$file"
4493 "$LFS" hsm_archive "$file"
4497 # Have the completed request be removed as soon as the cdt wakes up
4498 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4499 set_hsm_param grace_delay 1
4500 # (Hopefully, time on the MDS will behave nicely)
4501 do_facet $SINGLEMDS sleep 2 &
4503 # Increase `loop_period' as a mean to prevent the coordinator from
4504 # waking itself up to do some housekeeping.
4505 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4506 set_hsm_param loop_period 1000
4508 wait $! || error "waiting failed"
4510 wait_request_state $fid ARCHIVE ""
4511 # The coordinator will not wake up on its own for ~`loop_period' secs...
4513 # ... Unless a copytool registers. Now the real test begins
4515 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4517 run_test 255 "Copytool registration wakes the coordinator up"
4519 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4520 # break in the future because of that.
4523 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4524 skip "need MDS version 2.11.56 or later"
4526 local -a files=("$DIR/$tdir/$tfile".{0..15})
4529 for file in "${files[@]}"; do
4530 create_small_file "$file"
4533 # Set a few hsm parameters
4535 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4536 set_hsm_param loop_period 1
4538 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4539 set_hsm_param max_requests 3
4543 "$LFS" hsm_archive "${files[0]}"
4544 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4545 "$LFS" hsm_release "${files[0]}"
4549 wait_copytools || error "copytools failed to stop"
4551 # Send several archive requests
4552 for file in "${files[@]:1}"; do
4553 "$LFS" hsm_archive "$file"
4556 # Send one restore request
4557 "$LFS" hsm_restore "${files[0]}"
4562 # Wait for all the requests to complete
4563 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4564 for file in "${files[@]:1}"; do
4565 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4568 # Collect the actions in the order in which the copytool processed them
4570 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4571 "$(copytool_logfile "$SINGLEAGT")")
4574 printf '%s\n' "${actions[@]}"
4577 for action in "${actions[@]:0:3}"; do
4578 [ "$action" == RESTORE ] && return
4581 error "Too many ARCHIVE requests were run before the RESTORE request"
4583 run_test 260a "Restore request have priority over other requests"
4585 # This test is very much tied to the implementation of the current priorisation
4586 # mechanism in the coordinator. It might not make sense to keep it in the future
4589 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4590 skip "need MDS version 2.11.56 or later"
4592 local -a files=("$DIR/$tdir/$tfile".{0..15})
4595 for file in "${files[@]}"; do
4596 create_small_file "$file"
4599 # Set a few hsm parameters
4601 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4602 set_hsm_param loop_period 1
4604 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4605 set_hsm_param max_requests 3
4608 copytool setup --archive-id 2
4609 "$LFS" hsm_archive --archive 2 "${files[0]}"
4610 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4611 "$LFS" hsm_release "${files[0]}"
4615 wait_copytools || error "copytools failed to stop"
4617 # Send several archive requests
4618 for file in "${files[@]:1}"; do
4619 "$LFS" hsm_archive "$file"
4622 # Send one restore request
4623 "$LFS" hsm_restore "${files[0]}"
4627 copytool setup --archive-id 2
4629 # Wait for all the requests to complete
4630 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4631 for file in "${files[@]:1}"; do
4632 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4635 # Collect the actions in the order in which the copytool processed them
4637 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4638 "$(copytool_logfile "$SINGLEAGT")")
4641 printf '%s\n' "${actions[@]}"
4644 for action in "${actions[@]:0:3}"; do
4645 [ "$action" == RESTORE ] && return
4648 error "Too many ARCHIVE requests were run before the RESTORE request"
4650 run_test 260b "Restore request have priority over other requests"
4652 # This test is very much tied to the implementation of the current priorisation
4653 # mechanism in the coordinator. It might not make sense to keep it in the future
4656 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4657 skip "Need MDS version at least 2.12.0"
4659 local -a files=("$DIR/$tdir/$tfile".{0..15})
4662 for file in "${files[@]}"; do
4663 create_small_file "$file"
4666 # Set a few hsm parameters
4668 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4669 set_hsm_param loop_period 1000
4671 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4672 set_hsm_param max_requests 3
4675 copytool setup --archive-id 2
4676 "$LFS" hsm_archive --archive 2 "${files[0]}"
4677 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4678 "$LFS" hsm_release "${files[0]}"
4682 wait_copytools || error "copytools failed to stop"
4684 # Force the next coordinator run to do housekeeping
4688 "$LFS" hsm_archive "${files[1]}"
4692 copytool setup --archive-id 2
4694 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4695 # The coordinator just did a housekeeping run it won't do another one
4696 # for around `loop_period' seconds => requests will not be reordered
4697 # if it costs too much (ie. when the coordinator has to discard a whole
4700 # Send several archive requests
4701 for file in "${files[@]:2}"; do
4702 "$LFS" hsm_archive "$file"
4705 # Send one restore request
4706 "$LFS" hsm_restore "${files[0]}"
4708 # Wait for all the requests to complete
4709 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4710 for file in "${files[@]:2}"; do
4711 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4714 # Collect the actions in the order in which the copytool processed them
4716 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4717 "$(copytool_logfile "$SINGLEAGT")")
4720 printf '%s\n' "${actions[@]}"
4723 for action in "${actions[@]:0:3}"; do
4724 [ "$action" == RESTORE ] &&
4725 error "Restore requests should not be prioritised" \
4726 "unless the coordinator is doing housekeeping"
4730 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4733 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4735 # the only way to test ondisk conf is to restart MDS ...
4736 echo "Stop coordinator and remove coordinator state at mount"
4739 # clean on disk conf set by default
4740 cdt_clear_mount_state
4741 cdt_check_state stopped
4743 # check cdt still off after umount/remount
4745 cdt_check_state stopped
4747 echo "Set coordinator start at mount, and start coordinator"
4748 cdt_set_mount_state enabled
4751 cdt_check_state enabled
4753 # check cdt still on after umount/remount
4755 cdt_check_state enabled
4757 # we are back to original state (cdt started at mount)
4759 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4762 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4764 local ai=$(get_hsm_param default_archive_id)
4765 local new=$((ai + 1))
4767 set_hsm_param default_archive_id $new -P
4769 local res=$(get_hsm_param default_archive_id)
4772 set_hsm_param default_archive_id "" "-P -d"
4774 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4776 run_test 301 "HSM tunnable are persistent"
4779 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4781 local ai=$(get_hsm_param default_archive_id)
4782 local new=$((ai + 1))
4787 set_hsm_param default_archive_id $new -P
4790 for mdtno in $(seq 1 $MDSCOUNT); do
4795 cdt_check_state enabled
4797 local res=$(get_hsm_param default_archive_id)
4800 set_hsm_param default_archive_id "" "-P -d"
4802 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4804 run_test 302 "HSM tunnable are persistent when CDT is off"
4807 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4813 local dir_mdt0=$DIR/$tdir/mdt0
4814 local dir_mdt1=$DIR/$tdir/mdt1
4816 # create 1 dir per MDT
4817 stack_trap "rm -rf $dir_mdt0" EXIT
4818 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4819 stack_trap "rm -rf $dir_mdt1" EXIT
4820 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4822 # create 1 file in each MDT
4823 local fid1=$(create_small_file $dir_mdt0/$tfile)
4824 local fid2=$(create_small_file $dir_mdt1/$tfile)
4826 # check that hsm request on mdt0 is sent to the right MDS
4827 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4828 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4829 echo "archive successful on mdt0"
4831 # check that hsm request on mdt1 is sent to the right MDS
4832 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4833 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4834 echo "archive successful on mdt1"
4836 run_test 400 "Single request is sent to the right MDT"
4839 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4845 local dir_mdt0=$DIR/$tdir/mdt0
4846 local dir_mdt1=$DIR/$tdir/mdt1
4848 # create 1 dir per MDT
4849 stack_trap "rm -rf $dir_mdt0" EXIT
4850 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4851 stack_trap "rm -rf $dir_mdt1" EXIT
4852 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4854 # create 1 file in each MDT
4855 local fid1=$(create_small_file $dir_mdt0/$tfile)
4856 local fid2=$(create_small_file $dir_mdt1/$tfile)
4858 # check that compound requests are shunt to the rights MDTs
4859 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4860 error "lfs hsm_archive"
4861 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4862 echo "archive successful on mdt0"
4863 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4864 echo "archive successful on mdt1"
4866 run_test 401 "Compound requests split and sent to their respective MDTs"
4868 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4873 local node=$(facet_active_host $facet)
4875 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4876 awk '{print $4}'); do
4877 echo "$3 $mdc on $node"
4878 do_facet $facet "$LCTL --device $mdc $state" || return 1
4883 # deactivate all mdc on agent1
4884 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4886 copytool setup --no-fail
4888 check_agent_unregistered "uuid" # match any agent
4890 # no expected running copytool
4891 search_copytools $agent && error "Copytool start should have failed"
4894 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4896 run_test 402a "Copytool start fails if all MDTs are inactive"
4903 local f=$DIR/$tdir/$tfile
4904 touch $f || error "touch $f failed"
4905 local fid=$(path2fid $f)
4907 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4908 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4909 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4911 # give time for CDT to send request and to keep it for retry
4912 wait_for_loop_period
4914 wait_request_state $fid ARCHIVE WAITING
4916 do_facet $SINGLEAGT lctl set_param fail_loc=0
4918 # request should succeed now
4919 wait_request_state $fid ARCHIVE SUCCEED
4921 run_test 402b "CDT must retry request upon slow start of CT"
4924 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4926 local agent=$(facet_active_host $SINGLEAGT)
4928 # deactivate all mdc for MDT0001
4929 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4932 local uuid=$(get_agent_uuid $agent)
4933 # check the agent is registered on MDT0000, and not on MDT0001
4934 check_agent_registered_by_mdt $uuid 0
4935 check_agent_unregistered_by_mdt $uuid 1
4937 # check running copytool process
4938 search_copytools $agent || error "No running copytools on $agent"
4940 # reactivate all mdc for MDT0001
4941 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4943 # make sure the copytool is now registered to all MDTs
4944 check_agent_registered $uuid
4946 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4949 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4953 # create files on both MDT0000 and MDT0001
4956 local dir_mdt0=$DIR/$tdir/mdt0
4957 stack_trap "rm -rf $dir_mdt0" EXIT
4958 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4960 # create 1 file on mdt0
4961 local fid1=$(create_small_file $dir_mdt0/$tfile)
4963 # deactivate all mdc for MDT0001
4964 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4966 # send an HSM request for files in MDT0000
4967 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4969 # check for completion of files in MDT0000
4970 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4971 echo "archive successful on mdt0"
4973 # reactivate all mdc for MDT0001
4974 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4976 run_test 404 "Inactive MDT does not block requests for active MDTs"
4979 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4985 local striped_dir=$DIR/$tdir/striped_dir
4987 # create striped dir on all of MDTs
4988 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4990 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4991 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4992 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4993 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4995 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4996 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4997 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4998 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5000 # check that compound requests are shunt to the rights MDTs
5001 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5002 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5003 error "lfs hsm_archive"
5005 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5006 echo "archive successful on $fid1"
5007 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5008 echo "archive successful on $fid2"
5009 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5010 echo "archive successful on $fid3"
5011 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5012 echo "archive successful on $fid4"
5014 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5015 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5016 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5017 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5019 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5020 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5021 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5022 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5024 run_test 405 "archive and release under striped directory"
5027 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5029 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5030 skip "need MDS version at least 2.7.64"
5035 fid=$(create_small_file $DIR/$tdir/$tfile)
5040 $LFS hsm_archive $DIR/$tdir/$tfile
5041 wait_request_state "$fid" ARCHIVE SUCCEED
5042 $LFS hsm_release $DIR/$tdir/$tfile
5044 # Should migrate $tdir but not $tfile.
5045 $LFS migrate -m1 $DIR/$tdir &&
5046 error "migrating HSM an archived file should fail"
5048 $LFS hsm_restore $DIR/$tdir/$tfile
5049 wait_request_state "$fid" RESTORE SUCCEED
5051 $LFS hsm_remove $DIR/$tdir/$tfile
5052 wait_request_state "$fid" REMOVE SUCCEED
5054 cat $DIR/$tdir/$tfile > /dev/null ||
5055 error "cannot read $DIR/$tdir/$tfile"
5057 $LFS migrate -m1 $DIR/$tdir ||
5058 error "cannot complete migration after HSM remove"
5060 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5061 if ((mdt_index != 1)); then
5062 error "expected MDT index 1, got $mdt_index"
5065 # Refresh fid after migration.
5066 fid=$(path2fid $DIR/$tdir/$tfile)
5069 $LFS hsm_archive $DIR/$tdir/$tfile
5070 wait_request_state "$fid" ARCHIVE SUCCEED 1
5072 lctl set_param debug=+trace
5073 $LFS hsm_release $DIR/$tdir/$tfile ||
5074 error "cannot release $DIR/$tdir/$tfile"
5076 $LFS hsm_restore $DIR/$tdir/$tfile
5077 wait_request_state "$fid" RESTORE SUCCEED 1
5079 cat $DIR/$tdir/$tfile > /dev/null ||
5080 error "cannot read $DIR/$tdir/$tfile"
5082 run_test 406 "attempting to migrate HSM archived files is safe"
5085 local f=$DIR/$tdir/$tfile
5086 local f2=$DIR2/$tdir/$tfile
5087 local fid=$(create_empty_file "$f")
5091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5092 wait_request_state $fid ARCHIVE SUCCEED
5095 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5096 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5098 # Prevent restore from completing
5102 # 1st request holds layout lock while appropriate
5103 # RESTORE record is still not added to llog
5107 # after umount hsm_actions->O/x/x log shouldn't have
5108 # double RESTORE records like below
5109 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5110 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5112 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5116 wait_request_state $fid RESTORE SUCCEED
5118 run_test 407 "Check for double RESTORE records in llog"
5122 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5123 skip "HSM migrate is not supported"
5125 test_mkdir -p $DIR/$tdir
5127 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5128 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5130 llapi_hsm_test -d $DIR/$tdir -b ||
5131 error "One llapi HSM test failed"
5133 llapi_hsm_test -d $DIR/$tdir ||
5134 error "One llapi HSM test failed"
5137 run_test 500 "various LLAPI HSM tests"
5140 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5141 skip "need MDS version at least 2.10.58"
5145 local f=$DIR/$tdir/$tfile
5148 # set changelog_mask to ALL
5149 changelog_chmask "ALL"
5151 chmod 777 $DIR/$tdir
5152 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5153 local fid=$(path2fid $f)
5156 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5157 -gid "$RUNAS_GID") ||
5158 error "No matching CREAT entry"
5160 # Parse the changelog
5161 eval local -A changelog=$(changelog2array $entry)
5162 local nid="${changelog[nid]}"
5165 echo "Got NID '$nid'"
5166 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5167 error "nid '$nid' does not match any client NID:" \
5170 run_test 600 "Changelog fields 'u=' and 'nid='"
5173 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5174 skip "need MDS version at least 2.10.58"
5178 local f=$DIR/$tdir/$tfile
5181 # set changelog_mask to ALL
5182 changelog_chmask "ALL"
5184 touch $f || error "touch $f failed"
5185 local fid=$(path2fid $f)
5188 cat $f || error "cat $f failed"
5190 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5191 error "No matching OPEN entry"
5193 run_test 601 "OPEN Changelog entry"
5196 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5197 skip "need MDS version at least 2.10.58"
5201 local f=$DIR/$tdir/$tfile
5204 # set changelog_mask to ALL
5205 changelog_chmask "ALL"
5207 touch $f || error "touch $f failed"
5208 local fid=$(path2fid $f)
5211 cat $f || error "cat $f failed"
5213 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5217 echo f > $f || error "write $f failed"
5220 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5222 # remove OPEN from changelog_mask
5223 changelog_chmask "-OPEN"
5227 cat $f || error "cat $f failed"
5230 changelog_find -type CLOSE -target-fid $fid &&
5231 error "There should be no CLOSE entry"
5235 echo f > $f || error "write $f failed"
5238 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5240 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5243 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5244 skip "need MDS version at least 2.10.58"
5248 local f=$DIR/$tdir/$tfile
5251 # set changelog_mask to ALL
5252 changelog_chmask "ALL"
5254 touch $f || error "touch $f failed"
5255 local fid=$(path2fid $f)
5257 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5260 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5262 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5263 error "No matching GXATR entry"
5265 run_test 603 "GETXATTR Changelog entry"
5268 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5269 skip "need MDS version at least 2.10.58"
5273 local f=$DIR/$tdir/$tfile
5274 local f2=$DIR2/$tdir/$tfile
5275 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5277 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5278 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5279 do_facet mds1 lctl set_param "$procname=20"
5283 # set changelog_mask to ALL
5284 changelog_chmask "ALL"
5286 touch $f || error "touch $f failed"
5287 local fid=$(path2fid $f)
5293 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5297 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5298 -gid "$RUNAS_GID" -mode "r--") ||
5299 error "No matching NOPEN entry"
5301 # Parse the changelog
5302 eval local -A changelog=$(changelog2array $entry)
5303 local nid="${changelog[nid]}"
5306 echo "Got NID '$nid'"
5307 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5308 error "nid '$nid' does not match any client NID:" \
5313 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5316 changelog_find -type NOPEN -target-fid $fid &&
5317 error "There should be no NOPEN entry"
5319 # Sleep for `changelog_deniednext` seconds
5324 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5327 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5328 -gid "$RUNAS_GID" -mode "r--") ||
5329 error "No matching NOPEN entry"
5331 # Parse the changelog
5332 eval local -A changelog=$(changelog2array $entry)
5333 local nid="${changelog[nid]}"
5336 echo "Got NID '$nid'"
5337 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5338 error "nid '$nid' does not match any client NID:" \
5341 run_test 604 "NOPEN Changelog entry"
5344 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5345 skip "need MDS version at least 2.10.58"
5349 local f=$DIR/$tdir/$tfile
5350 local f2=$DIR2/$tdir/$tfile
5353 # set changelog_mask to ALL
5354 changelog_chmask "ALL"
5356 touch $f || error "touch $f failed"
5357 local fid=$(path2fid $f)
5361 exec 3<> $f || error "open $f failed"
5365 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5369 exec 4<> $f || error "open $f failed"
5372 changelog_find -type OPEN -target-fid $fid &&
5373 error "There should be no OPEN entry"
5375 exec 4>&- || error "close $f failed"
5378 changelog_find -type CLOSE -target-fid $fid &&
5379 error "There should be no CLOSE entry"
5383 # access in rw, so different access mode should generate entries
5384 cat $f || error "cat $f failed"
5387 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5389 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5393 # same access as first one, should not generate new entries
5394 exec 4<> $f || error "open $f failed"
5397 changelog_find -type OPEN -target-fid $fid &&
5398 error "There should be no OPEN entry"
5400 exec 4>&- || error "close $f failed"
5403 changelog_find -type CLOSE -target-fid $fid &&
5404 error "There should be no CLOSE entry"
5408 # access by different user should generate new entries
5409 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5412 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5414 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5418 exec 3>&- || error "close $f failed"
5421 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5423 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5426 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5427 skip "need MDS version at least 2.10.58"
5429 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5430 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5431 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5432 skip_env "missing llog_reader" && return
5433 local fstype=$(facet_fstype mds1)
5437 local f=$DIR/$tdir/$tfile
5440 # set changelog_mask to ALL
5441 changelog_chmask "ALL"
5443 chmod 777 $DIR/$tdir
5444 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5445 local fid=$(path2fid $f)
5446 rm $f || error "rm $f failed"
5448 local mntpt=$(facet_mntpt mds1)
5452 #remount mds1 as ldiskfs or zfs type
5453 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5454 stop mds1 || error "stop mds1 failed"
5455 mount_fstype mds1 || error "remount mds1 failed"
5457 for ((i = 0; i < 1; i++)); do
5458 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5459 local cat_file=$(do_facet mds1 $llog_reader \
5460 $mntpt/changelog_catalog | awk \
5461 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5462 [ -n "$cat_file" ] || error "no catalog file"
5464 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5465 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5466 [ -n "$entry" ] || error "no CREAT entry"
5469 local uidgid=$(echo $entry |
5470 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5471 [ -n "$uidgid" ] || error "uidgid is empty"
5472 echo "Got UID/GID $uidgid"
5473 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5474 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5475 local nid=$(echo $entry |
5476 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5477 [ -n "$nid" ] || error "nid is empty"
5479 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5480 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5482 run_test 606 "llog_reader groks changelog fields"
5485 check_and_cleanup_lustre