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
20 ALWAYS_EXCEPT+=" 402b "
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 # Skip tests for PPC that fail frequently
25 if [[ $(uname -m) = ppc64 ]]; then
26 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
27 ALWAYS_EXCEPT+=" 1a 1b 1d 1e 12c 12f "
28 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
29 ALWAYS_EXCEPT+=" 12g 12h 12m 12n 12o 12p "
30 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
31 ALWAYS_EXCEPT+=" 12q 21 22 23 24a 24b "
32 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
33 ALWAYS_EXCEPT+=" 24d 24e 24f 25b 30c 37 "
34 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
35 ALWAYS_EXCEPT+=" 57 58 90 110b 111b 113 "
36 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
37 ALWAYS_EXCEPT+=" 222b 222d 228 260a 260b 260c "
38 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
39 ALWAYS_EXCEPT+=" 220A 220a 221 222a 222c 223a "
40 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
41 ALWAYS_EXCEPT+=" 223b 224A 224a 226 227 600"
42 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
43 ALWAYS_EXCEPT+=" 601 602 603 604 605 "
48 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
50 OPENFILE=${OPENFILE:-openfile}
51 MOUNT_2=${MOUNT_2:-"yes"}
54 # script only handles up to 10 MDTs (because of MDT_PREFIX)
55 [ $MDSCOUNT -gt 9 ] &&
56 error "script cannot handle more than 9 MDTs, please fix"
58 check_and_setup_lustre
60 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
61 skip_env "Need MDS version at least 2.4.53"
64 # $RUNAS_ID may get set incorrectly somewhere else
65 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
66 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
68 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
69 if getent group nobody; then
71 elif getent group nogroup; then
74 error "No generic nobody group"
77 # if there is no CLIENT1 defined, some tests can be ran on localhost
78 CLIENT1=${CLIENT1:-$HOSTNAME}
79 # if CLIENT2 doesn't exist then use CLIENT1 instead
80 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
82 # Exception is the test which need two separate nodes
83 CLIENT2=${CLIENT2:-$CLIENT1}
86 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
87 do_nodesv $hosts "pgrep --pidfile=$HSMTOOL_PID_FILE hsmtool"
91 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
92 local wait_timeout=200
93 local wait_start=$SECONDS
94 local wait_end=$((wait_start + wait_timeout))
97 while ((SECONDS < wait_end)); do
98 if ! search_copytools $hosts; then
99 echo "copytools stopped in $((SECONDS - wait_start))s"
103 echo "copytools still running on $hosts"
105 [ $sleep_time -lt 5 ] && sleep_time=$((sleep_time + 1))
108 # try to dump Copytool's stack
109 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
110 "echo t >/proc/sysrq-trigger"
112 echo "copytools failed to stop in ${wait_timeout}s"
117 copytool_monitor_setup() {
118 local facet=${1:-$SINGLEAGT}
119 local agent=$(facet_active_host $facet)
121 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
122 local test_dir=$(do_node $agent "$cmd") ||
123 error "Failed to create tempdir on $agent"
124 export HSMTOOL_MONITOR_DIR=$test_dir
126 # Create the fifo and a monitor (cat dies when copytool dies)
127 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
128 error "failed to create copytool fifo on $agent"
129 cmd="cat $test_dir/fifo > $test_dir/events &"
130 cmd+=" echo \\\$! > $test_dir/monitor_pid"
132 # This background subshell nonsense is required when pdsh/ssh decides
133 # to wait for the cat process to exit on the remote client
134 (do_node $agent "$cmd") &
135 export HSMTOOL_MONITOR_PDSH=$!
137 # Slightly racy, but just making a best-effort to catch obvious
140 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
142 error "Failed to start copytool monitor on $agent"
152 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
157 get_copytool_event_log() {
158 local facet=${1:-$SINGLEAGT}
159 local agent=$(facet_active_host $facet)
161 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
162 error "Can't get event log: No monitor directory!"
164 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
165 error "Could not collect event log from $agent"
169 local agents=${1:-$(facet_active_host $SINGLEAGT)}
171 stack_trap "pkill_copytools $agents CONT || true" EXIT
172 pkill_copytools $agents STOP || return 0
173 echo "Copytool is suspended on $agents"
176 copytool_remove_backend() {
178 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
179 echo "Remove from backend: $fid = $be"
180 do_facet $SINGLEAGT rm -f $be
183 file_creation_failure() {
190 df $MOUNT $MOUNT2 >&2
191 error "Not enough space to create $file with $cmd"
194 error "cannot create $file with $cmd, status=$err"
199 # Creates a file using dd
205 local source=${5:-/dev/zero}
209 if [ -n "$conv" ]; then
213 # Create the directory in case it does not exist
214 mkdir -p "$(dirname "$file")"
215 # Delete the file in case it already exist
218 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
219 path2fid "$file" || error "cannot get FID of '$file'"
222 echo "cannot create file '$file'" >&2;
223 # Let the caller decide what to do on error
228 create_empty_file() {
229 create_file "${1/$DIR/$DIR2}" 1M 0 ||
230 file_creation_failure dd "${1/$DIR/$DIR2}" $?
233 create_small_file() {
234 local source_file=/dev/urandom
237 local conv=${2:-fsync}
239 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
240 file_creation_failure dd "${1/$DIR/$DIR2}" $?
243 create_small_sync_file() {
244 create_small_file "$1" sync
247 create_archive_file() {
248 local file="$(hsm_root)/$1"
250 local source=/dev/urandom
252 # Create the counterpart directory of the archive
253 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
254 error "cannot create archive directory '$(dirname "$file")'"
256 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
257 error "cannot create archive file '$file'"
261 local hsm_root="$(hsm_root)"
262 local file="$hsm_root/$2"
264 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
265 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
266 error "mkdir '$(dirname "$file")' failed"
267 do_facet $SINGLEAGT cp -p "$1" "$file" ||
268 error "cannot copy '$1' to '$file'"
273 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
280 mdts_set_param "" hsm_control "$cmd"
281 mdts_check_param hsm_control "$target" 10
286 mdts_set_param "" hsm.policy "+NRA"
287 CDT_POLICY_HAD_CHANGED=true
290 cdt_clear_no_retry() {
291 mdts_set_param "" hsm.policy "-NRA"
292 CDT_POLICY_HAD_CHANGED=true
295 cdt_set_non_blocking_restore() {
296 mdts_set_param "" hsm.policy "+NBR"
297 CDT_POLICY_HAD_CHANGED=true
300 cdt_clear_non_blocking_restore() {
301 mdts_set_param "" hsm.policy "-NBR"
302 CDT_POLICY_HAD_CHANGED=true
305 cdt_clear_mount_state() {
306 mdts_set_param "-P -d" hsm_control ""
310 set_test_state disabled disabled
314 set_test_state enabled enabled
318 set_test_state shutdown stopped
322 set_test_state purge enabled
328 cdt_set_sanity_policy
332 get_hsm_archive_id() {
335 st=$($LFS hsm_state $f)
336 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
338 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
342 check_hsm_flags_user() {
346 local st=$(get_hsm_flags $f user)
347 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
359 if [[ "$3" != 1 ]]; then
363 cp $1 $f || file_creation_failure cp $f $?
365 path2fid $f || error "cannot get fid on $f"
368 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
370 # Note that this might lead to surprising behaviours such as deleting an
371 # important file for the currently running test
372 delete_large_files() {
373 printf "Deleting large files...\n" >&2
374 find $MOUNT -size +10M -delete
375 wait_delete_completed
378 get_request_state() {
382 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
383 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
386 get_request_count() {
390 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
391 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
394 # Ensure the number of HSM request for a given FID is correct
395 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
396 assert_request_count() {
397 local request_count=$(get_request_count $1 $2)
398 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
400 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
407 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
408 [[ -n $fid ]] && cmd+=" | grep '$fid'"
409 cmd+=" | egrep 'WAITING|STARTED'"
411 wait_update_facet --verbose mds1 "$cmd" "" $timeout ||
412 error "requests did not complete"
415 wait_for_grace_delay() {
416 local val=$(get_hsm_param grace_delay)
420 wait_for_loop_period() {
421 local val=$(get_hsm_param loop_period)
428 # python2.6 in EL6 includes an internal json module
429 local json_parser='import json; import fileinput;'
430 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
431 json_parser+='json.loads([line for line in '
432 json_parser+='fileinput.input()][0]).items()])'
434 echo $raw_event | python -c "$json_parser"
437 get_agent_by_uuid_mdt() {
440 local mds=mds$(($mdtidx + 1))
441 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
445 check_agent_registered_by_mdt() {
448 local mds=mds$(($mdtidx + 1))
449 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
450 if [[ ! -z "$agent" ]]; then
451 echo "found agent $agent on $mds"
453 error "uuid $uuid not found in agent list on $mds"
457 check_agent_unregistered_by_mdt() {
460 local mds=mds$(($mdtidx + 1))
461 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
462 if [[ -z "$agent" ]]; then
463 echo "uuid not found in agent list on $mds"
465 error "uuid found in agent list on $mds: $agent"
469 check_agent_registered() {
472 for mdsno in $(seq 1 $MDSCOUNT); do
473 check_agent_registered_by_mdt $uuid $((mdsno - 1))
477 check_agent_unregistered() {
480 for mdsno in $(seq 1 $MDSCOUNT); do
481 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
486 local agent=${1:-$(facet_active_host $SINGLEAGT)}
488 # Lustre mount-point is mandatory and last parameter on
490 local mntpnt=$(do_rpc_nodes $agent \
491 pgrep --pidfile=$HSMTOOL_PID_FILE --list-full hsmtool |
493 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
495 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
501 # populate MDT device array
504 # cleanup from previous bad setup
507 # for recovery tests, coordinator needs to be started at mount
509 # the lustre conf must be without hsm on (like for sanity.sh)
510 echo "Set HSM on and start"
511 cdt_set_mount_state enabled
512 cdt_check_state enabled
514 echo "Set sanity-hsm HSM policy"
515 cdt_set_sanity_policy
517 # finished requests are quickly removed from list
518 set_hsm_param grace_delay 10
520 CLIENT_NIDS=( $($LCTL list_nids all) )
522 test_1A() { # was test_1
526 local f=$DIR/$tdir/$tfile
530 check_hsm_flags_user $f "0x00000000"
532 $RUNAS $LFS hsm_set --norelease $f ||
533 error "user could not change hsm flags"
534 check_hsm_flags_user $f "0x00000010"
536 $RUNAS $LFS hsm_clear --norelease $f ||
537 error "user could not clear hsm flags"
538 check_hsm_flags_user $f "0x00000000"
540 # User could not change those flags...
541 $RUNAS $LFS hsm_set --exists $f &&
542 error "user should not set this flag"
543 check_hsm_flags_user $f "0x00000000"
546 $LFS hsm_set --exists $f ||
547 error "root could not change hsm flags"
548 check_hsm_flags_user $f "0x00000001"
550 $LFS hsm_clear --exists $f ||
551 error "root could not clear hsm state"
552 check_hsm_flags_user $f "0x00000000"
555 run_test 1A "lfs hsm flags root/non-root access"
558 local f=$DIR/$tdir/$tfile
559 local fid=$(create_small_file $f)
563 $LFS hsm_archive $f || error "could not archive file"
564 wait_request_state $fid ARCHIVE SUCCEED
566 # Release and check states
567 $LFS hsm_release $f || error "could not release file"
568 echo -n "Verifying released state: "
569 check_hsm_flags $f "0x0000000d"
571 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
573 run_test 1a "mmap & cat a HSM released file"
579 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
580 error "failed to create file"
581 local fid=$(path2fid $f)
586 $LFS hsm_archive $f || error "could not archive file"
587 wait_request_state $fid ARCHIVE SUCCEED
590 $LFS hsm_release $f || error "could not release file"
591 echo "verify released state: "
592 check_hsm_flags $f "0x0000000d" && echo "pass"
595 $LFS hsm_restore $f || error "could not restore file"
596 wait_request_state $fid RESTORE SUCCEED
597 echo "verify restored state: "
598 check_hsm_flags $f "0x00000009" && echo "pass"
603 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
604 error "failed to set default stripe"
605 local f=$DIR/$tdir/$tfile
609 run_test 1b "Archive, Release and Restore composite file"
615 local f=$DIR/$tdir/$tfile
618 # Test whether we can set the maximum archive number.
619 local LOCAL_HSM_ARCHIVE_NUMBER=32
620 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
621 error "root could not change hsm flags"
622 check_hsm_flags_user $f "0x00000001"
623 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
624 local st=$(get_hsm_archive_id $f)
625 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
626 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
628 # Test whether setting archive number 0 results in no change.
629 $LFS hsm_set --exists --archive-id 0 $f ||
630 error "root could not change hsm flags"
631 check_hsm_flags_user $f "0x00000001"
632 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
633 st=$(get_hsm_archive_id $f)
634 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
635 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
637 LOCAL_HSM_ARCHIVE_NUMBER=33
638 if [ "$CLIENT_VERSION" -ge $(version_code 2.11.56) ] &&
639 [ "$MDS1_VERSION" -ge $(version_code 2.11.56) ]; then
640 # lustre in the new version supports unlimited archiveID.
641 # Test whether setting archive number > 32 is supported
642 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
643 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
644 check_hsm_flags_user $f "0x00000001"
646 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
647 st=$(get_hsm_archive_id $f)
648 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
649 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
651 # old client or old mds can only support at most 32 archiveID
652 # test whether setting archive number > 32 results in error.
653 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
654 error "bitmap archive number is larger than 32"
655 check_hsm_flags_user $f "0x00000001"
658 # Test whether setting archive number 16 and archived flag.
659 LOCAL_HSM_ARCHIVE_NUMBER=16
660 $LFS hsm_set --exists --archived \
661 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
662 error "root could not change hsm flags"
663 check_hsm_flags_user $f "0x00000009"
664 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
665 st=$(get_hsm_archive_id $f)
666 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
667 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
669 run_test 1c "Check setting archive-id in lfs hsm_set"
672 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
673 skip "need MDS version at least 2.10.59"
676 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
677 error "failed to set default stripe"
678 local f=$DIR/$tdir/$tfile
682 run_test 1d "Archive, Release and Restore DoM file"
685 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
686 skip "skipped for lustre < $SEL_VER"
689 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
690 error "failed to set default stripe"
691 local comp_file=$DIR/$tdir/$tfile
693 test_1bde_base $comp_file
695 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
696 local found=$($LFS find $flg_opts $comp_file | wc -l)
697 [ $found -eq 1 ] || error "1st component not found"
699 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
700 found=$($LFS find $flg_opts $comp_file | wc -l)
701 [ $found -eq 1 ] || error "2nd component not found"
703 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
704 found=$($LFS find $flg_opts $comp_file | wc -l)
705 [ $found -eq 1 ] || error "3rd component not found"
707 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
708 found=$($LFS find $flg_opts $comp_file | wc -l)
709 [ $found -eq 1 ] || error "4th component not found"
711 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
712 found=$($LFS find $flg_opts $comp_file | wc -l)
713 [ $found -eq 1 ] || error "5th component not found"
715 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
716 found=$($LFS find $flg_opts $comp_file | wc -l)
717 [ $found -eq 1 ] || error "6th component not found"
719 sel_layout_sanity $comp_file 6
721 run_test 1e "Archive, Release and Restore SEL file"
724 local f=$DIR/$tdir/$tfile
726 create_empty_file "$f"
727 # New files are not dirty
728 check_hsm_flags $f "0x00000000"
730 # For test, we simulate an archived file.
731 $LFS hsm_set --exists $f || error "user could not change hsm flags"
732 check_hsm_flags $f "0x00000001"
734 # chmod do not put the file dirty
735 chmod 600 $f || error "could not chmod test file"
736 check_hsm_flags $f "0x00000001"
738 # chown do not put the file dirty
739 chown $RUNAS_ID $f || error "could not chown test file"
740 check_hsm_flags $f "0x00000001"
742 # truncate put the file dirty
743 $TRUNCATE $f 1 || error "could not truncate test file"
744 check_hsm_flags $f "0x00000003"
746 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
747 check_hsm_flags $f "0x00000001"
749 run_test 2 "Check file dirtyness when doing setattr"
755 # New files are not dirty
757 check_hsm_flags $f "0x00000000"
759 # For test, we simulate an archived file.
760 $LFS hsm_set --exists $f ||
761 error "user could not change hsm flags"
762 check_hsm_flags $f "0x00000001"
764 # Reading a file, does not set dirty
765 cat $f > /dev/null || error "could not read file"
766 check_hsm_flags $f "0x00000001"
768 # Open for write without modifying data, does not set dirty
769 openfile -f O_WRONLY $f || error "could not open test file"
770 check_hsm_flags $f "0x00000001"
772 # Append to a file sets it dirty
773 cp -p /etc/passwd $f.append || error "could not create file"
774 $LFS hsm_set --exists $f.append ||
775 error "user could not change hsm flags"
776 dd if=/etc/passwd of=$f.append bs=1 count=3\
777 conv=notrunc oflag=append status=noxfer ||
778 file_creation_failure dd $f.append $?
779 check_hsm_flags $f.append "0x00000003"
781 # Modify a file sets it dirty
782 cp -p /etc/passwd $f.modify || error "could not create file"
783 $LFS hsm_set --exists $f.modify ||
784 error "user could not change hsm flags"
785 dd if=/dev/zero of=$f.modify bs=1 count=3\
786 conv=notrunc status=noxfer ||
787 file_creation_failure dd $f.modify $?
788 check_hsm_flags $f.modify "0x00000003"
790 # Open O_TRUNC sets dirty
791 cp -p /etc/passwd $f.trunc || error "could not create file"
792 $LFS hsm_set --exists $f.trunc ||
793 error "user could not change hsm flags"
794 cp /etc/group $f.trunc || error "could not override a file"
795 check_hsm_flags $f.trunc "0x00000003"
797 # Mmapped a file sets dirty
798 cp -p /etc/passwd $f.mmap || error "could not create file"
799 $LFS hsm_set --exists $f.mmap ||
800 error "user could not change hsm flags"
801 multiop $f.mmap OSMWUc || error "could not mmap a file"
802 check_hsm_flags $f.mmap "0x00000003"
804 run_test 3 "Check file dirtyness when opening for write"
807 local f=$DIR/$tdir/$tfile
808 local fid=$(create_small_file $f)
811 local st=$(get_request_state $fid CANCEL)
812 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
814 run_test 4 "Useless cancel must not be registered"
817 # test needs a running copytool
821 local f=$DIR/$tdir/$tfile
822 local fid=$(copy_file /etc/passwd $f)
824 wait_request_state $fid ARCHIVE SUCCEED
826 check_hsm_flags $f "0x00000009"
828 run_test 8 "Test default archive number"
830 test_9A() { # was test_9
831 # we do not use the default one to be sure
832 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
833 copytool setup --archive-id $archive_id
835 # give time for CT to register with MDTs
836 sleep $(($MDSCOUNT*2))
837 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
838 check_agent_registered $uuid
841 local f=$DIR/$tdir/$tfile
842 local fid=$(copy_file /etc/passwd $f)
843 $LFS hsm_archive --archive $archive_id $f
844 wait_request_state $fid ARCHIVE SUCCEED
846 check_hsm_flags $f "0x00000009"
848 run_test 9A "Use of explicit archive number, with dedicated copytool"
851 needclients 3 || return 0
857 # start all of the copytools
858 for n in $(seq $AGTCOUNT); do
859 copytool setup --facet agt$n
863 for n in $(seq $AGTCOUNT); do
864 file=$DIR/$tdir/$tfile.$n
865 fid=$(create_small_file $file)
867 $LFS hsm_archive $file || error "could not archive file $file"
868 wait_request_state $fid ARCHIVE SUCCEED
869 check_hsm_flags $file "0x00000009"
872 run_test 9a "Multiple remote agents"
875 # test needs a running copytool
878 mkdir -p $DIR/$tdir/d1
879 local f=$DIR/$tdir/$tfile
880 local fid=$(copy_file /etc/hosts $f)
881 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
882 error "hsm_archive failed"
883 wait_request_state $fid ARCHIVE SUCCEED
885 local hsm_root="$(copytool_device $SINGLEAGT)"
886 local archive="$(do_facet $SINGLEAGT \
887 find "$hsm_root" -name "$fid" -print0)"
888 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
890 echo "Verifying content"
891 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
892 echo "Verifying hsm state "
893 check_hsm_flags $f "0x00000009"
895 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
896 local st=$(get_hsm_archive_id $f)
897 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
898 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
900 run_test 10a "Archive a file"
903 # test needs a running copytool
907 local f=$DIR/$tdir/$tfile
908 local fid=$(copy_file /etc/hosts $f)
909 $LFS hsm_archive $f || error "archive request failed"
910 wait_request_state $fid ARCHIVE SUCCEED
912 $LFS hsm_archive $f || error "archive of non dirty file failed"
913 local cnt=$(get_request_count $fid ARCHIVE)
914 [[ "$cnt" == "1" ]] ||
915 error "archive of non dirty file must not make a request"
917 run_test 10b "Archive of non dirty file must work without doing request"
920 # test needs a running copytool
924 local f=$DIR/$tdir/$tfile
925 local fid=$(copy_file /etc/hosts $f)
926 $LFS hsm_set --noarchive $f
927 $LFS hsm_archive $f && error "archive a noarchive file must fail"
930 run_test 10c "Check forbidden archive"
933 # test needs a running copytool
937 local f=$DIR/$tdir/$tfile
938 local fid=$(copy_file /etc/hosts $f)
939 $LFS hsm_archive $f || error "cannot archive $f"
940 wait_request_state $fid ARCHIVE SUCCEED
942 local ar=$(get_hsm_archive_id $f)
943 local dflt=$(get_hsm_param default_archive_id)
944 [[ $ar == $dflt ]] ||
945 error "archived file is not on default archive: $ar != $dflt"
947 run_test 10d "Archive a file on the default archive id"
951 copy2archive /etc/hosts $tdir/$tfile
952 local f=$DIR/$tdir/$tfile
954 copytool import $tdir/$tfile $f
955 echo -n "Verifying released state: "
956 check_hsm_flags $f "0x0000000d"
958 local LSZ=$(stat -c "%s" $f)
959 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
961 echo "Verifying imported size $LSZ=$ASZ"
962 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
963 echo -n "Verifying released pattern: "
964 local PTRN=$($LFS getstripe -L $f)
966 [[ $PTRN == released ]] || error "Is not released"
967 local fid=$(path2fid $f)
968 echo "Verifying new fid $fid in archive"
970 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
971 error "No archive for fid $fid"
973 run_test 11a "Import a file"
976 # test needs a running copytool
980 local f=$DIR/$tdir/$tfile
981 local fid=$(copy_file /etc/hosts $f)
982 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
983 error "hsm_archive failed"
984 wait_request_state $fid ARCHIVE SUCCEED
986 local FILE_HASH=$(md5sum $f)
989 copytool import $fid $f
991 echo "$FILE_HASH" | md5sum -c
993 [[ $? -eq 0 ]] || error "Restored file differs"
995 run_test 11b "Import a deleted file using its FID"
998 pool_add $TESTNAME || error "Pool creation failed"
999 pool_add_targets $TESTNAME 1 1 || error "pool_add_targets failed"
1002 $LFS setstripe -p "$TESTNAME" $DIR/$tdir
1004 copy2archive /etc/hosts $tdir/$tfile
1005 copytool import $tdir/$tfile $DIR/$tdir/$tfile
1007 run_test 11c "Import a file to a directory with a pool"
1010 # test needs a running copytool
1014 copy2archive /etc/hosts $tdir/$tfile
1016 local f=$DIR/$tdir/$tfile
1017 copytool import $tdir/$tfile $f
1018 local f2=$DIR2/$tdir/$tfile
1019 echo "Verifying released state: "
1020 check_hsm_flags $f2 "0x0000000d"
1022 local fid=$(path2fid $f2)
1023 $LFS hsm_restore $f2
1024 wait_request_state $fid RESTORE SUCCEED
1026 echo "Verifying file state: "
1027 check_hsm_flags $f2 "0x00000009"
1029 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1031 [[ $? -eq 0 ]] || error "Restored file differs"
1033 run_test 12a "Restore an imported file explicitly"
1036 # test needs a running copytool
1040 copy2archive /etc/hosts $tdir/$tfile
1042 local f=$DIR/$tdir/$tfile
1043 copytool import $tdir/$tfile $f
1044 echo "Verifying released state: "
1045 check_hsm_flags $f "0x0000000d"
1047 cat $f > /dev/null || error "File read failed"
1049 echo "Verifying file state after restore: "
1050 check_hsm_flags $f "0x00000009"
1052 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1054 [[ $? -eq 0 ]] || error "Restored file differs"
1056 run_test 12b "Restore an imported file implicitly"
1059 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1061 # test needs a running copytool
1064 local f=$DIR/$tdir/$tfile
1066 $LFS setstripe -c 2 "$f"
1067 local fid=$(create_file "$f" 1M 5)
1069 local FILE_CRC=$(md5sum $f)
1071 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1072 wait_request_state $fid ARCHIVE SUCCEED
1073 $LFS hsm_release $f || error "release $f failed"
1075 echo "$FILE_CRC" | md5sum -c
1077 [[ $? -eq 0 ]] || error "Restored file differs"
1079 run_test 12c "Restore a file with stripe of 2"
1082 # test needs a running copytool
1087 local f=$DIR/$tdir/$tfile
1088 local fid=$(copy_file /etc/hosts $f)
1089 $LFS hsm_restore $f || error "restore of non archived file failed"
1090 local cnt=$(get_request_count $fid RESTORE)
1091 [[ "$cnt" == "0" ]] ||
1092 error "restore non archived must not make a request"
1093 $LFS hsm_archive $f ||
1094 error "archive request failed"
1095 wait_request_state $fid ARCHIVE SUCCEED
1096 $LFS hsm_restore $f ||
1097 error "restore of non released file failed"
1098 local cnt=$(get_request_count $fid RESTORE)
1099 [[ "$cnt" == "0" ]] ||
1100 error "restore a non dirty file must not make a request"
1102 run_test 12d "Restore of a non archived, non released file must work"\
1103 " without doing request"
1106 # test needs a running copytool
1110 local f=$DIR/$tdir/$tfile
1111 local fid=$(copy_file /etc/hosts $f)
1112 $LFS hsm_archive $f || error "archive request failed"
1113 wait_request_state $fid ARCHIVE SUCCEED
1116 cat /etc/hosts >> $f
1120 $LFS hsm_restore $f && error "restore a dirty file must fail"
1123 run_test 12e "Check forbidden restore"
1126 # test needs a running copytool
1130 local f=$DIR/$tdir/$tfile
1131 local fid=$(copy_file /etc/hosts $f)
1133 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1134 wait_request_state $fid ARCHIVE SUCCEED
1135 $LFS hsm_release $f || error "release of $f failed"
1137 wait_request_state $fid RESTORE SUCCEED
1139 echo -n "Verifying file state: "
1140 check_hsm_flags $f "0x00000009"
1142 diff -q /etc/hosts $f
1144 [[ $? -eq 0 ]] || error "Restored file differs"
1146 run_test 12f "Restore a released file explicitly"
1149 # test needs a running copytool
1153 local f=$DIR/$tdir/$tfile
1154 local fid=$(copy_file /etc/hosts $f)
1156 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1157 wait_request_state $fid ARCHIVE SUCCEED
1158 $LFS hsm_release $f || error "release of $f failed"
1160 diff -q /etc/hosts $f
1163 # we check we had a restore done
1164 wait_request_state $fid RESTORE SUCCEED
1166 [[ $st -eq 0 ]] || error "Restored file differs"
1168 run_test 12g "Restore a released file implicitly"
1171 needclients 2 || return 0
1173 # test needs a running copytool
1177 local f=$DIR/$tdir/$tfile
1178 local fid=$(copy_file /etc/hosts $f)
1180 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1181 wait_request_state $fid ARCHIVE SUCCEED
1182 $LFS hsm_release $f || error "release of $f failed"
1184 do_node $CLIENT2 diff -q /etc/hosts $f
1187 # we check we had a restore done
1188 wait_request_state $fid RESTORE SUCCEED
1190 [[ $st -eq 0 ]] || error "Restored file differs"
1192 run_test 12h "Restore a released file implicitly from a second node"
1195 # test needs a running copytool
1199 local f=$DIR/$tdir/$tfile
1200 local fid=$(copy_file /etc/passwd $f)
1201 $LFS hsm_archive $f || error "archive of $f failed"
1202 wait_request_state $fid ARCHIVE SUCCEED
1204 $LFS hsm_release $f || error "release of $f failed"
1208 [[ $? -eq 0 ]] || error "Restored file differs"
1210 run_test 12m "Archive/release/implicit restore"
1213 # test needs a running copytool
1217 copy2archive /etc/hosts $tdir/$tfile
1219 local f=$DIR/$tdir/$tfile
1220 copytool import $tdir/$tfile $f
1222 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1223 error "Restored file differs"
1225 $LFS hsm_release $f || error "release of $f failed"
1227 run_test 12n "Import/implicit restore/release"
1230 # test needs a running copytool
1234 local f=$DIR/$tdir/$tfile
1235 local fid=$(copy_file /etc/hosts $f)
1237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1238 wait_request_state $fid ARCHIVE SUCCEED
1239 $LFS hsm_release $f || error "release of $f failed"
1241 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1242 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1244 # set no retry action mode
1247 diff -q /etc/hosts $f
1250 # we check we had a restore failure
1251 wait_request_state $fid RESTORE FAILED
1253 [[ $st -eq 0 ]] && error "Restore must fail"
1255 # remove no retry action mode
1258 # check file is still released
1259 check_hsm_flags $f "0x0000000d"
1261 # retry w/o failure injection
1262 do_facet $SINGLEMDS lctl set_param fail_loc=0
1264 # to be sure previous RESTORE result is gone
1266 wait_for_grace_delay
1268 diff -q /etc/hosts $f
1271 # we check we had a restore done
1272 wait_request_state $fid RESTORE SUCCEED
1274 [[ $st -eq 0 ]] || error "Restored file differs"
1276 run_test 12o "Layout-swap failure during Restore leaves file released"
1279 # test needs a running copytool
1283 local f=$DIR/$tdir/$tfile
1284 local fid=$(copy_file /etc/hosts $f)
1286 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1287 wait_request_state $fid ARCHIVE SUCCEED
1288 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1289 $LFS hsm_release $f || error "cannot release $f"
1290 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1291 $LFS hsm_release $f || error "cannot release $f"
1292 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1294 run_test 12p "implicit restore of a file on copytool mount point"
1297 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1298 skip "need MDS version at least 2.7.58"
1300 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1301 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1302 error "cannot mount $MOUNT3 on $SINGLEAGT"
1304 # test needs a running copytool
1305 copytool setup -m "$MOUNT3"
1307 local f=$DIR/$tdir/$tfile
1308 local f2=$DIR2/$tdir/$tfile
1309 local fid=$(create_small_file $f)
1310 local orig_size=$(stat -c "%s" $f)
1312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1313 wait_request_state $fid ARCHIVE SUCCEED
1315 $LFS hsm_release $f || error "could not release file"
1316 check_hsm_flags $f "0x0000000d"
1319 wait_copytools || error "copytool failed to stop"
1321 cat $f > /dev/null &
1323 # wait a bit to allow implicit restore request to be handled.
1324 # if not, next stat would also block on layout-lock.
1327 local size=$(stat -c "%s" $f2)
1328 [ $size -eq $orig_size ] ||
1329 error "$f2: wrong size after archive: $size != $orig_size"
1331 copytool setup -m "$MOUNT3"
1335 size=$(stat -c "%s" $f)
1336 [ $size -eq $orig_size ] ||
1337 error "$f: wrong size after restore: $size != $orig_size"
1339 size=$(stat -c "%s" $f2)
1340 [ $size -eq $orig_size ] ||
1341 error "$f2: wrong size after restore: $size != $orig_size"
1345 size=$(stat -c "%s" $f)
1347 error "$f: wrong size after overwrite: $size != 0"
1349 size=$(stat -c "%s" $f2)
1351 error "$f2: wrong size after overwrite: $size != 0"
1353 run_test 12q "file attributes are refreshed after restore"
1356 # test needs a running copytool
1360 local f=$DIR/$tdir/$tfile
1361 local fid=$(copy_file /etc/hosts $f)
1363 $LFS hsm_archive $f || error "archive of $f failed"
1364 wait_request_state $fid ARCHIVE SUCCEED
1365 $LFS hsm_release $f || error "release of $f failed"
1367 offset=$(lseek_test -d 7 $f)
1369 # we check we had a restore done
1370 wait_request_state $fid RESTORE SUCCEED
1371 [[ $offset == 7 ]] || error "offset $offset != 7"
1373 run_test 12r "lseek restores released file"
1377 for i in {1..10}; do
1378 local archive_dir="$(hsm_root)"/subdir/dir.$i
1380 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1381 for j in {1..10}; do
1382 local archive_file="$archive_dir"/file.$j
1384 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1390 copytool import "subdir" "$DIR/$tdir"
1392 # To check the import, the test uses diff with the -r flag
1393 # This is nice, but diff only checks files one by one, and triggering
1394 # an implicit restore for one file at a time will consume as many
1395 # seconds as there are files to compare. To speed this up, a restore
1396 # operation is triggered manually first.
1398 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1400 # Compare the imported data
1401 do_facet $SINGLEAGT \
1402 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1403 error "imported files differ from archived data"
1405 run_test 13 "Recursively import and restore a directory"
1408 # test needs a running copytool
1412 local f=$DIR/$tdir/$tfile
1413 local fid=$(create_small_file $f)
1414 local sum=$(md5sum $f | awk '{print $1}')
1415 $LFS hsm_archive $f || error "could not archive file"
1416 wait_request_state $fid ARCHIVE SUCCEED
1418 # create released file (simulate llapi_hsm_import call)
1419 local fid2=$(create_empty_file "$f")
1420 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1421 $LFS hsm_release $f || error "could not release file"
1423 # rebind the archive to the newly created file
1424 echo "rebind $fid to $fid2"
1426 copytool rebind $fid $fid2
1428 # restore file and compare md5sum
1429 local sum2=$(md5sum $f | awk '{print $1}')
1431 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1433 run_test 14 "Rebind archived file to a new fid"
1436 # test needs a running copytool
1440 local f=$DIR/$tdir/$tfile
1442 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1446 for i in $(seq 1 $count); do
1447 fids[$i]=$(create_small_file $f.$i)
1448 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1449 $LFS hsm_archive $f.$i || error "could not archive file"
1451 wait_all_done $(($count*60))
1453 stack_trap "rm -f $tmpfile" EXIT
1456 for i in $(seq 1 $count); do
1457 local fid2=$(create_empty_file "${f}.${i}")
1458 # add the rebind operation to the list
1459 echo ${fids[$i]} $fid2 >> $tmpfile
1461 # set it released (simulate llapi_hsm_import call)
1462 $LFS hsm_set --archived --exists $f.$i ||
1463 error "could not force hsm flags"
1464 $LFS hsm_release $f.$i || error "could not release file"
1466 nl=$(wc -l < $tmpfile)
1467 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1469 echo "rebind list of files"
1470 copytool rebind "$tmpfile"
1472 # restore files and compare md5sum
1473 for i in $(seq 1 $count); do
1474 local sum2=$(md5sum $f.$i | awk '{print $1}')
1475 [[ $sum2 == ${sums[$i]} ]] ||
1476 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1479 run_test 15 "Rebind a list of files"
1482 # test needs a running copytool
1486 # create a known size file so we can verify transfer speed
1489 dd if=/dev/zero of=$ref bs=1M count=20
1492 local f=$DIR/$tdir/$tfile
1493 local fid=$(copy_file $ref $f)
1495 local start=$(date +%s)
1497 wait_request_state $fid ARCHIVE SUCCEED
1498 local end=$(date +%s)
1499 # Add 1 to account for rounding errors between start and end (LU-8155)
1500 local duration=$((end - start + 1))
1502 [[ $duration -ge $((goal - 1)) ]] ||
1503 error "Transfer is too fast $duration < $goal"
1505 run_test 16 "Test CT bandwith control option"
1508 local f=$DIR/$tdir/$tfile
1509 create_empty_file "$f"
1511 # Could not release a non-archived file
1512 $LFS hsm_release $f && error "release should not succeed"
1514 # For following tests, we must test them with HS_ARCHIVED set
1515 $LFS hsm_set --exists --archived $f || error "could not add flag"
1517 # Could not release a file if no-release is set
1518 $LFS hsm_set --norelease $f || error "could not add flag"
1519 $LFS hsm_release $f && error "release should not succeed"
1520 $LFS hsm_clear --norelease $f || error "could not remove flag"
1522 # Could not release a file if lost
1523 $LFS hsm_set --lost $f || error "could not add flag"
1524 $LFS hsm_release $f && error "release should not succeed"
1525 $LFS hsm_clear --lost $f || error "could not remove flag"
1527 # Could not release a file if dirty
1528 $LFS hsm_set --dirty $f || error "could not add flag"
1529 $LFS hsm_release $f && error "release should not succeed"
1530 $LFS hsm_clear --dirty $f || error "could not remove flag"
1532 run_test 20 "Release is not permitted"
1535 # test needs a running copytool
1538 local f=$DIR/$tdir/test_release
1540 # Create a file and check its states
1541 local fid=$(create_small_file $f)
1542 check_hsm_flags $f "0x00000000"
1544 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1545 # used until file is flushed to disk
1546 if [ "$ost1_FSTYPE" == "zfs" ]; then
1547 # this causes an OST_SYNC rpc to be sent
1548 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1549 # clear locks to reread file data
1550 cancel_lru_locks osc
1553 local orig_size=$(stat -c "%s" $f)
1554 local orig_blocks=$(stat -c "%b" $f)
1556 start_full_debug_logging
1558 $LFS hsm_archive $f || error "could not archive file"
1559 wait_request_state $fid ARCHIVE SUCCEED
1561 local blocks=$(stat -c "%b" $f)
1562 [ $blocks -eq $orig_blocks ] ||
1563 error "$f: wrong block number after archive: " \
1564 "$blocks != $orig_blocks"
1565 local size=$(stat -c "%s" $f)
1566 [ $size -eq $orig_size ] ||
1567 error "$f: wrong size after archive: $size != $orig_size"
1569 # Release and check states
1570 $LFS hsm_release $f || error "could not release file"
1571 check_hsm_flags $f "0x0000000d"
1573 blocks=$(stat -c "%b" $f)
1574 [ $blocks -gt 5 ] &&
1575 error "$f: too many blocks after release: $blocks > 5"
1576 size=$(stat -c "%s" $f)
1577 [ $size -ne $orig_size ] &&
1578 error "$f: wrong size after release: $size != $orig_size"
1580 # Check we can release an file without stripe info
1584 check_hsm_flags $f "0x00000000"
1585 $LFS hsm_archive $f || error "could not archive file"
1586 wait_request_state $fid ARCHIVE SUCCEED
1588 # Release and check states
1589 $LFS hsm_release $f || error "could not release file"
1590 check_hsm_flags $f "0x0000000d"
1592 # Release again a file that is already released is OK
1593 $LFS hsm_release $f || fail "second release should succeed"
1594 check_hsm_flags $f "0x0000000d"
1596 stop_full_debug_logging
1598 run_test 21 "Simple release tests"
1601 # test needs a running copytool
1604 local f=$DIR/$tdir/test_release
1605 local swap=$DIR/$tdir/test_swap
1607 # Create a file and check its states
1608 local fid=$(create_small_file $f)
1609 check_hsm_flags $f "0x00000000"
1611 $LFS hsm_archive $f || error "could not archive file"
1612 wait_request_state $fid ARCHIVE SUCCEED
1614 # Release and check states
1615 $LFS hsm_release $f || error "could not release file"
1616 check_hsm_flags $f "0x0000000d"
1618 create_small_file $swap
1619 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1623 run_test 22 "Could not swap a release file"
1626 # test needs a running copytool
1629 local f=$DIR/$tdir/test_mtime
1631 # Create a file and check its states
1632 local fid=$(create_small_file $f)
1633 check_hsm_flags $f "0x00000000"
1635 $LFS hsm_archive $f || error "could not archive file"
1636 wait_request_state $fid ARCHIVE SUCCEED
1638 # Set modification time in the past
1639 touch -m -a -d @978261179 $f
1641 # Release and check states
1642 $LFS hsm_release $f || error "could not release file"
1643 check_hsm_flags $f "0x0000000d"
1645 local MTIME=$(stat -c "%Y" $f)
1646 local ATIME=$(stat -c "%X" $f)
1647 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1648 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1650 run_test 23 "Release does not change a/mtime (utime)"
1653 local file=$DIR/$tdir/$tfile
1662 # test needs a running copytool
1665 fid=$(create_small_file $file)
1667 # Create a file and check its states
1668 check_hsm_flags $file "0x00000000"
1670 # Ensure atime is less than mtime and ctime.
1674 atime0=$(stat -c "%X" $file)
1675 mtime0=$(stat -c "%Y" $file)
1676 ctime0=$(stat -c "%Z" $file)
1678 [ $atime0 -lt $mtime0 ] ||
1679 error "atime $atime0 is not less than mtime $mtime0"
1681 [ $atime0 -lt $ctime0 ] ||
1682 error "atime $atime0 is not less than ctime $ctime0"
1684 # Archive should not change any timestamps.
1685 $LFS hsm_archive $file || error "cannot archive '$file'"
1686 wait_request_state $fid ARCHIVE SUCCEED
1688 atime1=$(stat -c "%X" $file)
1689 mtime1=$(stat -c "%Y" $file)
1690 ctime1=$(stat -c "%Z" $file)
1692 [ $atime0 -eq $atime1 ] ||
1693 error "archive changed atime from $atime0 to $atime1"
1695 [ $mtime0 -eq $mtime1 ] ||
1696 error "archive changed mtime from $mtime0 to $mtime1"
1698 [ $ctime0 -eq $ctime1 ] ||
1699 error "archive changed ctime from $ctime0 to $ctime1"
1701 # Release should not change any timestamps.
1702 $LFS hsm_release $file || error "cannot release '$file'"
1703 check_hsm_flags $file "0x0000000d"
1705 atime1=$(stat -c "%X" $file)
1706 mtime1=$(stat -c "%Y" $file)
1707 ctime1=$(stat -c "%Z" $file)
1709 [ $atime0 -eq $atime1 ] ||
1710 error "release changed atime from $atime0 to $atime1"
1712 [ $mtime0 -eq $mtime1 ] ||
1713 error "release changed mtime from $mtime0 to $mtime1"
1715 [ $ctime0 -eq $ctime1 ] ||
1716 error "release changed ctime from $ctime0 to $ctime1"
1718 # Restore should not change any timestamps.
1719 $LFS hsm_restore $file
1720 wait_request_state $fid RESTORE SUCCEED
1722 atime1=$(stat -c "%X" $file)
1723 mtime1=$(stat -c "%Y" $file)
1724 ctime1=$(stat -c "%Z" $file)
1726 [ $atime0 -eq $atime1 ] ||
1727 error "restore changed atime from $atime0 to $atime1"
1729 [ $mtime0 -eq $mtime1 ] ||
1730 error "restore changed mtime from $mtime0 to $mtime1"
1732 [ $ctime0 -eq $ctime1 ] ||
1733 error "restore changed ctime from $ctime0 to $ctime1"
1736 wait_copytools || error "Copytools failed to stop"
1738 # Once more, after unmount and mount.
1739 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1740 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1742 atime1=$(stat -c "%X" $file)
1743 mtime1=$(stat -c "%Y" $file)
1744 ctime1=$(stat -c "%Z" $file)
1746 [ $atime0 -eq $atime1 ] ||
1747 error "remount changed atime from $atime0 to $atime1"
1749 [ $mtime0 -eq $mtime1 ] ||
1750 error "remount changed mtime from $mtime0 to $mtime1"
1752 [ $ctime0 -eq $ctime1 ] ||
1753 error "remount changed ctime from $ctime0 to $ctime1"
1755 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1758 local file=$DIR/$tdir/$tfile
1764 # Test needs a running copytool.
1767 # Check that root can do HSM actions on a regular user's file.
1768 fid=$(create_small_file $file)
1769 sum0=$(md5sum $file)
1771 chown $RUNAS_ID:$RUNAS_GID $file ||
1772 error "cannot chown '$file' to '$RUNAS_ID'"
1774 chmod ugo-w $DIR/$tdir ||
1775 error "cannot chmod '$DIR/$tdir'"
1777 $LFS hsm_archive $file
1778 wait_request_state $fid ARCHIVE SUCCEED
1780 $LFS hsm_release $file
1781 check_hsm_flags $file "0x0000000d"
1783 $LFS hsm_restore $file
1784 wait_request_state $fid RESTORE SUCCEED
1786 # Check that ordinary user can get HSM state.
1787 $RUNAS $LFS hsm_state $file ||
1788 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1790 $LFS hsm_release $file
1791 check_hsm_flags $file "0x0000000d"
1793 # Check that ordinary user can accessed released file.
1794 sum1=$($RUNAS md5sum $file) ||
1795 error "user '$RUNAS_ID' cannot read '$file'"
1797 [ "$sum0" == "$sum1" ] ||
1798 error "md5sum mismatch for '$file'"
1800 run_test 24b "root can archive, release, and restore user files"
1803 local file=$DIR/$tdir/$tfile
1804 local action=archive
1809 # test needs a running copytool
1814 # Save the default masks and check that cleanup_24c will
1815 # restore the request masks correctly.
1816 user_save=$(get_hsm_param user_request_mask)
1817 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1818 group_save=$(get_hsm_param group_request_mask)
1819 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1820 other_save=$(get_hsm_param other_request_mask)
1821 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1823 [ "$user_save" == RESTORE ] ||
1824 error "user_request_mask is '$user_save' expected 'RESTORE'"
1825 [ "$group_save" == RESTORE ] ||
1826 error "group_request_mask is '$group_save' expected 'RESTORE'"
1827 [ "$other_save" == RESTORE ] ||
1828 error "other_request_mask is '$other_save' expected 'RESTORE'"
1831 create_small_file $file
1832 chown $RUNAS_ID:$GROUP $file ||
1833 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1835 $RUNAS $LFS hsm_$action $file &&
1836 error "$action by user should fail"
1838 set_hsm_param user_request_mask $action
1839 $RUNAS $LFS hsm_$action $file ||
1840 error "$action by user should succeed"
1843 create_small_file $file
1844 chown nobody:$RUNAS_GID $file ||
1845 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1847 $RUNAS $LFS hsm_$action $file &&
1848 error "$action by group should fail"
1850 set_hsm_param group_request_mask $action
1851 $RUNAS $LFS hsm_$action $file ||
1852 error "$action by group should succeed"
1855 create_small_file $file
1856 chown nobody:$GROUP $file ||
1857 error "cannot chown '$file' to 'nobody:$GROUP'"
1859 $RUNAS $LFS hsm_$action $file &&
1860 error "$action by other should fail"
1862 set_hsm_param other_request_mask $action
1863 $RUNAS $LFS hsm_$action $file ||
1864 error "$action by other should succeed"
1866 run_test 24c "check that user,group,other request masks work"
1869 local file1=$DIR/$tdir/$tfile
1870 local file2=$DIR2/$tdir/$tfile
1874 fid1=$(create_small_file $file1)
1877 $LFS getstripe $file1
1879 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1880 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1881 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1883 copytool setup -m "$MOUNT3"
1885 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1886 mount -o remount,ro $MOUNT2
1888 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1890 fid2=$(path2fid $file2)
1891 [ "$fid1" == "$fid2" ] ||
1892 error "FID mismatch '$fid1' != '$fid2'"
1894 $LFS hsm_archive $file2 &&
1895 error "archive should fail on read-only mount"
1896 check_hsm_flags $file1 "0x00000000"
1898 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1899 wait_request_state $fid1 ARCHIVE SUCCEED
1901 $LFS hsm_release $file1
1902 $LFS hsm_restore $file2
1903 wait_request_state $fid1 RESTORE SUCCEED
1905 $LFS hsm_release $file1 || error "cannot release '$file1'"
1906 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1908 $LFS hsm_release $file2 &&
1909 error "release should fail on read-only mount"
1913 run_test 24d "check that read-only mounts are respected"
1918 local f=$DIR/$tdir/$tfile
1921 fid=$(create_small_file $f) || error "cannot create $f"
1922 $LFS hsm_archive $f || error "cannot archive $f"
1923 wait_request_state $fid ARCHIVE SUCCEED
1924 $LFS hsm_release $f || error "cannot release $f"
1925 while ! $LFS hsm_state $f | grep released; do
1929 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1931 run_test 24e "tar succeeds on HSM released files" # LU-6213
1934 # test needs a running copytool
1937 mkdir -p $DIR/$tdir/d1
1938 local f=$DIR/$tdir/$tfile
1939 local fid=$(copy_file /etc/hosts $f)
1942 $LFS hsm_archive $f ||
1943 error "hsm_archive failed"
1944 wait_request_state $fid ARCHIVE SUCCEED
1945 $LFS hsm_release $f || error "cannot release $f"
1946 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1949 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1950 error "Can not recover the tar contents"
1952 echo "Sum0 = $sum0, sum1 = $sum1"
1953 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1955 run_test 24f "root can archive, release, and restore tar files"
1958 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1959 skip "need MDS version 2.11.56 or later"
1961 local file=$DIR/$tdir/$tfile
1964 echo "RUNAS = '$RUNAS'"
1969 chmod ugo+rwx $DIR/$tdir
1971 echo "Please listen carefully as our options have changed." | tee $file
1972 fid=$(path2fid $file)
1975 $LFS hsm_archive $file
1976 wait_request_state $fid ARCHIVE SUCCEED
1977 check_hsm_flags $file 0x00000009 # exists archived
1979 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
1980 check_hsm_flags $file 0x0000000b # exists dirty archived
1982 run_test 24g "write by non-owner still sets dirty" # LU-11369
1985 # test needs a running copytool
1989 copy2archive /etc/hosts $tdir/$tfile
1991 local f=$DIR/$tdir/$tfile
1993 copytool import $tdir/$tfile $f
1995 $LFS hsm_set --lost $f
2000 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2002 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2003 " (Operation not permitted)"
2006 # test needs a running copytool
2011 local f=$DIR/$tdir/$tfile
2012 local fid=$(copy_file /etc/passwd $f)
2014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2015 wait_request_state $fid ARCHIVE SUCCEED
2018 $LFS hsm_set --lost $f
2022 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2024 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2025 " (Operation not permitted)"
2027 test_26A() { # was test_26
2028 # test needs a running copytool
2031 local f=$DIR/$tdir/$tfile
2032 local fid=$(create_empty_file "$f")
2034 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2035 wait_request_state $fid ARCHIVE SUCCEED
2038 wait_request_state $fid REMOVE SUCCEED
2040 check_hsm_flags $f "0x00000000"
2042 run_test 26A "Remove the archive of a valid file"
2045 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2046 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2048 # test needs a running copytool
2052 local f=$DIR/$tdir/$tfile
2053 local fid=$(copy_file /etc/passwd $f)
2055 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2056 wait_request_state $fid ARCHIVE SUCCEED
2058 local f2=$DIR/$tdir/${tfile}_2
2059 local fid2=$(copy_file /etc/passwd $f2)
2061 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2062 wait_request_state $fid2 ARCHIVE SUCCEED
2064 local f3=$DIR/$tdir/${tfile}_3
2065 local fid3=$(copy_file /etc/passwd $f3)
2067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2068 wait_request_state $fid3 ARCHIVE SUCCEED
2070 # set a long grace_delay vs short loop_period
2071 local orig_loop_period=$(get_hsm_param loop_period)
2072 local orig_grace_delay=$(get_hsm_param grace_delay)
2073 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2074 set_hsm_param loop_period 10
2075 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2076 set_hsm_param grace_delay 100
2080 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2081 set_hsm_param remove_archive_on_last_unlink 1
2083 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2088 wait_request_state $fid2 REMOVE SUCCEED
2090 assert_request_count $fid REMOVE 0 \
2091 "Unexpected archived data remove request for $f"
2092 assert_request_count $fid3 REMOVE 0 \
2093 "Unexpected archived data remove request for $f3"
2095 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2098 # test needs a running copytool
2102 local f=$DIR/$tdir/$tfile
2103 local fid=$(copy_file /etc/passwd $f)
2105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2106 wait_request_state $fid ARCHIVE SUCCEED
2108 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2109 set_hsm_param remove_archive_on_last_unlink 1
2112 cdt_check_state stopped
2116 wait_request_state $fid REMOVE WAITING
2120 # copytool must re-register
2122 wait_copytools || error "copytool failed to stop"
2125 wait_request_state $fid REMOVE SUCCEED
2127 run_test 26b "RAoLU policy when CDT off"
2130 # test needs a running copytool
2134 local f=$DIR/$tdir/$tfile
2135 local fid=$(copy_file /etc/passwd $f)
2137 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2138 wait_request_state $fid ARCHIVE SUCCEED
2140 local f2=$DIR/$tdir/${tfile}_2
2141 local fid2=$(copy_file /etc/passwd $f2)
2143 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2144 wait_request_state $fid2 ARCHIVE SUCCEED
2146 # set a long grace_delay vs short loop_period
2147 local orig_loop_period=$(get_hsm_param loop_period)
2148 local orig_grace_delay=$(get_hsm_param grace_delay)
2149 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2150 set_hsm_param loop_period 10
2151 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2152 set_hsm_param grace_delay 100
2154 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2155 set_hsm_param remove_archive_on_last_unlink 1
2157 multiop_bg_pause $f O_c || error "open $f failed"
2163 wait_request_state $fid2 REMOVE SUCCEED
2164 assert_request_count $fid REMOVE 0 \
2165 "Unexpected archived data remove request for $f"
2167 kill -USR1 $pid || error "multiop early exit"
2168 # should reach autotest timeout if multiop fails to trap
2169 # signal, close file, and exit ...
2170 wait $pid || error "wait PID $PID failed"
2172 wait_request_state $fid REMOVE SUCCEED
2174 run_test 26c "RAoLU effective when file closed"
2177 # test needs a running copytool
2181 local f=$DIR/$tdir/$tfile
2182 local fid=$(create_small_file $f)
2184 $LFS hsm_archive $f || error "could not archive file"
2185 wait_request_state $fid ARCHIVE SUCCEED
2187 # set a long grace_delay vs short loop_period
2188 local orig_loop_period=$(get_hsm_param loop_period)
2189 local orig_grace_delay=$(get_hsm_param grace_delay)
2190 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2191 set_hsm_param loop_period 10
2192 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2193 set_hsm_param grace_delay 100
2195 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2196 set_hsm_param remove_archive_on_last_unlink 1
2198 multiop_bg_pause $f O_c || error "multiop failed"
2205 wait_request_state $fid REMOVE SUCCEED
2207 client_up || client_up || true
2209 kill -USR1 $MULTIPID
2210 wait $MULTIPID || error "multiop close failed"
2212 run_test 26d "RAoLU when Client eviction"
2215 # test needs a running copytool
2218 create_archive_file $tdir/$tfile
2219 local f=$DIR/$tdir/$tfile
2220 copytool import $tdir/$tfile $f
2221 local fid=$(path2fid $f)
2225 [[ $? != 0 ]] || error "Remove of a released file should fail"
2227 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2230 # test needs a running copytool
2233 local f=$DIR/$tdir/$tfile
2234 local fid=$(create_empty_file "$f")
2236 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2237 wait_request_state $fid ARCHIVE SUCCEED
2242 [[ $? != 0 ]] || error "Remove of a released file should fail"
2244 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2247 # test needs a running copytool
2250 local f=$DIR/$tdir/$tfile
2251 local fid=$(create_empty_file "$f")
2253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2254 wait_request_state $fid ARCHIVE SUCCEED
2263 wait_request_state $fid REMOVE SUCCEED
2265 run_test 28 "Concurrent archive/file remove"
2268 # Tests --mntpath and --archive options
2271 copytool setup -m "$MOUNT" -a $archive_id
2273 # Bad archive number
2274 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2275 grep "Invalid argument" ||
2276 error "unexpected hsm_remove failure (1)"
2278 # mntpath is present but file is given
2279 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2280 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2281 error "unexpected hsm_remove failure (2)"
2283 run_test 29a "Tests --mntpath and --archive options"
2286 # test needs a running copytool
2289 local f=$DIR/$tdir/$tfile
2290 local fid=$(create_small_file $f)
2292 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2293 wait_request_state $fid ARCHIVE SUCCEED
2297 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2298 wait_request_state $fid REMOVE SUCCEED
2300 run_test 29b "Archive/delete/remove by FID from the archive."
2303 # test needs a running copytool
2306 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2307 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2308 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2310 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2311 wait_request_state $fid1 ARCHIVE SUCCEED
2312 wait_request_state $fid2 ARCHIVE SUCCEED
2313 wait_request_state $fid3 ARCHIVE SUCCEED
2315 rm -f $DIR/$tdir/$tfile-[1-3]
2317 echo $fid1 > $DIR/$tdir/list
2318 echo $fid2 >> $DIR/$tdir/list
2319 echo $fid3 >> $DIR/$tdir/list
2321 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2322 --filelist $DIR/$tdir/list
2323 wait_request_state $fid1 REMOVE SUCCEED
2324 wait_request_state $fid2 REMOVE SUCCEED
2325 wait_request_state $fid3 REMOVE SUCCEED
2327 run_test 29c "Archive/delete/remove by FID, using a file list."
2330 # test needs more than one CT
2331 needclients 3 || return 0
2337 # start all of the copytools
2338 for n in $(seq $AGTCOUNT); do
2339 copytool setup -f agt$n -a $n
2343 file=$DIR/$tdir/$tfile
2344 fid=$(create_small_file $file)
2346 $LFS hsm_archive $file
2347 wait_request_state $fid ARCHIVE SUCCEED
2348 check_hsm_flags $file "0x00000009"
2352 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2353 error "cannot hsm_remove '$fid'"
2355 # give time for CDT to handle remove request and create broadcasted
2358 # remove request has been broadcasted ?
2359 local cnt=$(get_request_count $fid REMOVE)
2360 # broadcasted requests + original
2361 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2362 error "remove not broadcasted to all CTs"
2364 # give time for CDT and CTs to handle broadcasted
2365 wait_for_loop_period
2367 # each agent serves one different archive_id, so broadcasted
2368 # hsm_remove request should only succeed once and fail at all others
2372 for n in $(seq $AGTCOUNT); do
2373 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2374 $HSM_PARAM.actions | awk \
2375 '/'$fid'.*action=REMOVE archive#='$n'/ \
2376 {print \\\$13}' | cut -f2 -d=")
2377 if [[ "$res" == "SUCCEED" ]]; then
2379 elif [[ "$res" == "FAILED" ]]; then
2384 [[ $scnt -eq 1 ]] ||
2385 error "one and only CT should have removed successfully"
2387 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2388 error "all but one CT should have failed to remove"
2390 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2391 "request to be sent once for each registered archive_id"
2394 # restore at exec cannot work on agent node (because of Linux kernel
2395 # protection of executables)
2396 needclients 2 || return 0
2398 # test needs a running copytool
2402 copy2archive /bin/true $tdir/$tfile
2404 local f=$DIR/$tdir/true
2405 copytool import $tdir/$tfile $f
2407 local fid=$(path2fid $f)
2409 stack_trap "cdt_clear_no_retry" EXIT
2410 # set no retry action mode
2417 [[ $st == 0 ]] || error "Failed to exec a released file"
2419 run_test 30a "Restore at exec (import case)"
2422 # restore at exec cannot work on agent node (because of Linux kernel
2423 # protection of executables)
2424 needclients 2 || return 0
2426 # test needs a running copytool
2430 local f=$DIR/$tdir/true
2431 local fid=$(copy_file /bin/true $f)
2433 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2434 wait_request_state $fid ARCHIVE SUCCEED
2438 stack_trap cdt_clear_no_retry EXIT
2439 # set no retry action mode
2447 [[ $st == 0 ]] || error "Failed to exec a released file"
2449 run_test 30b "Restore at exec (release case)"
2452 needclients 2 || return 0
2454 # test needs a running copytool
2458 local f=$DIR/$tdir/SLEEP
2459 local slp_sum1=$(md5sum /bin/sleep)
2460 local fid=$(copy_file /bin/sleep $f)
2462 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2463 wait_request_state $fid ARCHIVE SUCCEED
2465 check_hsm_flags $f "0x0000000d"
2467 stack_trap cdt_clear_no_retry EXIT
2468 # set no retry action mode
2471 do_node $CLIENT2 "$f 10" &
2475 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2477 [[ $? == 0 ]] || error "Execution failed during run"
2479 if [[ $? != 0 ]]; then
2480 local slp_sum2=$(md5sum /bin/sleep)
2481 # in case sleep file is modified during the test
2482 [[ $slp_sum1 == $slp_sum2 ]] &&
2483 error "Binary overwritten during exec"
2486 check_hsm_flags $f "0x00000009"
2488 run_test 30c "Update during exec of released file must fail"
2490 restore_and_check_size() {
2493 local s=$(stat -c "%s" $f)
2495 local st=$(get_hsm_flags $f)
2499 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2501 n=$(stat -c "%s" $f)
2502 # we echo in both cases to show stat is not hang
2503 if [[ $n != $s ]]; then
2504 echo "size seen is $n != $s"
2507 echo "size seen is right: $n == $s"
2511 st=$(get_hsm_flags $f)
2513 if [[ "$st" = "0x00000009" ]]; then
2516 echo " restore is too long"
2517 wait_request_state $fid RESTORE SUCCEED
2523 # test needs a running copytool
2526 create_archive_file $tdir/$tfile
2527 local f=$DIR/$tdir/$tfile
2528 copytool import $tdir/$tfile $f
2529 local fid=$($LFS path2fid $f)
2532 restore_and_check_size $f $fid
2535 [[ $err -eq 0 ]] || error "File size changed during restore"
2537 run_test 31a "Import a large file and check size during restore"
2541 # test needs a running copytool
2544 local f=$DIR/$tdir/$tfile
2545 local fid=$(create_file "$f" 1MB 39)
2547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2548 wait_request_state $fid ARCHIVE SUCCEED
2551 restore_and_check_size $f $fid
2554 [[ $err -eq 0 ]] || error "File size changed during restore"
2556 run_test 31b "Restore a large unaligned file and check size during restore"
2559 # test needs a running copytool
2562 local f=$DIR/$tdir/$tfile
2563 local fid=$(create_file "$f" 1M 39)
2565 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2566 wait_request_state $fid ARCHIVE SUCCEED
2569 restore_and_check_size $f $fid
2572 [[ $err -eq 0 ]] || error "File size changed during restore"
2574 run_test 31c "Restore a large aligned file and check size during restore"
2577 local f=$DIR/$tdir/$tfile
2578 local fid=$(create_empty_file "$f")
2582 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2583 wait_request_state $fid ARCHIVE SUCCEED
2586 # Prevent restore from completing
2590 md5sum $f >/dev/null &
2593 wait_request_state $fid RESTORE STARTED
2598 # Check restore trigger process was killed
2600 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2602 run_test 33 "Kill a restore waiting process"
2605 # test needs a running copytool
2608 local f=$DIR/$tdir/$tfile
2609 local fid=$(create_empty_file "$f")
2611 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2612 wait_request_state $fid ARCHIVE SUCCEED
2615 # Prevent restore from completing
2618 md5sum $f >/dev/null &
2621 wait_request_state $fid RESTORE STARTED
2623 # rm must not block during restore
2624 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2627 wait_request_state $fid RESTORE SUCCEED
2629 # Check md5sum pgm finished
2630 kill -0 $pid && error "Restore initiatior still running"
2631 wait $pid || error "Restore initiator failed with $?"
2633 # Check the file was actually deleted
2634 [ ! -f "$f" ] || error "$f was not deleted"
2636 run_test 34 "Remove file during restore"
2639 # test needs a running copytool
2642 local f=$DIR/$tdir/$tfile
2643 local f1=$DIR/$tdir/$tfile-1
2644 local fid=$(create_empty_file "$f")
2645 local fid1=$(copy_file /etc/passwd $f1)
2647 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2648 wait_request_state $fid ARCHIVE SUCCEED
2651 # Prevent restore from completing
2654 md5sum $f >/dev/null &
2657 wait_request_state $fid RESTORE STARTED
2659 # mv must not block during restore
2660 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2663 wait_request_state $fid RESTORE SUCCEED
2665 # Check md5sum pgm finished
2666 kill -0 $pid && error "Restore initiatior still running"
2667 wait $pid || error "Restore initiator failed with $?"
2669 local fid2=$(path2fid $f)
2670 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2672 run_test 35 "Overwrite file during restore"
2675 # test needs a running copytool
2678 local f=$DIR/$tdir/$tfile
2679 local fid=$(create_empty_file "$f")
2681 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2682 wait_request_state $fid ARCHIVE SUCCEED
2685 # Prevent restore from completing
2688 md5sum $f >/dev/null &
2691 wait_request_state $fid RESTORE STARTED
2693 # mv must not block during restore
2694 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2695 error "mv '$f' '$f.new' failed with rc=$?"
2698 wait_request_state $fid RESTORE SUCCEED
2700 # Check md5sum pgm finished
2701 kill -0 $pid && error "Restore initiator is still running"
2702 wait $pid || error "Restore initiator failed with $?"
2704 run_test 36 "Move file during restore"
2707 # LU-5683: check that an archived dirty file can be rearchived.
2710 local f=$DIR/$tdir/$tfile
2713 fid=$(create_small_file $f) || error "cannot create small file"
2715 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2716 wait_request_state $fid ARCHIVE SUCCEED
2717 $LFS hsm_release $f || error "cannot release $f"
2719 # Allow previous archive request to expire from the actions log.
2720 wait_for_grace_delay
2723 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2725 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2726 wait_request_state $fid ARCHIVE SUCCEED
2728 run_test 37 "re-archive a dirty file"
2735 for n in $(seq 1 $count); do
2736 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2738 echo "$count archive requests submitted"
2742 local stream_count=4
2743 local file_count=100
2745 local f=$DIR/$tdir/$tfile
2749 local max_requests=$(get_hsm_param max_requests)
2751 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2752 # Increase the number of HSM request that can be performed in
2753 # parallel. With the coordinator running once per second, this
2754 # also limits the number of requests per seconds that can be
2755 # performed, so we pick a decent number. But we also need to keep
2756 # that number low because the copytool has no rate limit and will
2757 # fail some requests if if gets too many at once.
2758 set_hsm_param max_requests 300
2760 for i in $(seq 1 $file_count); do
2761 for p in $(seq 1 $stream_count); do
2762 fid=$(copy_file /etc/hosts $f.$p.$i)
2768 # to be sure wait_all_done will not be mislead by previous tests
2770 wait_for_grace_delay
2772 # start archive streams in background (archive files in parallel)
2773 for p in $(seq 1 $stream_count); do
2774 multi_archive $f.$p $file_count &
2777 echo -n "Wait for all requests being enqueued..."
2782 run_test 40 "Parallel archive requests"
2785 # test needs a running copytool
2789 local f=$DIR/$tdir/$tfile
2790 local fid=$(create_small_file $f)
2792 $LFS hsm_archive $f || error "could not archive file"
2793 wait_request_state $fid ARCHIVE SUCCEED
2794 check_hsm_flags $f "0x00000009"
2796 multiop_bg_pause $f O_c || error "multiop failed"
2800 client_up || client_up || true
2802 kill -USR1 $MULTIPID
2803 wait $MULTIPID || error "multiop close failed"
2805 check_hsm_flags $f "0x0000000b"
2807 run_test 52 "Opened for write file on an evicted client should be set dirty"
2810 # test needs a running copytool
2814 local f=$DIR/$tdir/$tfile
2815 local fid=$(create_small_file $f)
2817 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2818 error "could not archive file"
2819 wait_request_state $fid ARCHIVE SUCCEED
2820 check_hsm_flags $f "0x00000009"
2822 multiop_bg_pause $f o_c || error "multiop failed"
2826 client_up || client_up || true
2828 kill -USR1 $MULTIPID
2829 wait $MULTIPID || error "multiop close failed"
2831 check_hsm_flags $f "0x00000009"
2833 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2836 local f=$DIR/$tdir/$tfile
2837 local fid=$(create_file "$f" 1MB 39)
2841 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2842 error "could not archive file"
2843 wait_request_state $fid ARCHIVE STARTED
2845 check_hsm_flags $f "0x00000001"
2847 stack_trap "cdt_clear_no_retry" EXIT
2848 # Avoid coordinator resending this request as soon it has failed.
2853 wait_request_state $fid ARCHIVE FAILED
2855 check_hsm_flags $f "0x00000003"
2857 run_test 54 "Write during an archive cancels it"
2860 local f=$DIR/$tdir/$tfile
2861 local fid=$(create_file "$f" 1MB 39)
2865 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2866 error "could not archive file"
2867 wait_request_state $fid ARCHIVE STARTED
2869 check_hsm_flags $f "0x00000001"
2871 stack_trap "cdt_clear_no_retry" EXIT
2872 # Avoid coordinator resending this request as soon it has failed.
2875 $TRUNCATE $f 1024 || error "truncate failed"
2877 wait_request_state $fid ARCHIVE FAILED
2879 check_hsm_flags $f "0x00000003"
2881 run_test 55 "Truncate during an archive cancels it"
2884 local f=$DIR/$tdir/$tfile
2885 local fid=$(create_file "$f" 1MB 39)
2889 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2890 error "could not archive file"
2891 wait_request_state $fid ARCHIVE STARTED
2893 check_hsm_flags $f "0x00000001"
2895 # Change metadata and sync to be sure we are not changing only
2900 wait_request_state $fid ARCHIVE SUCCEED
2902 check_hsm_flags $f "0x00000009"
2904 run_test 56 "Setattr during an archive is ok"
2907 # Need one client for I/O, one for request
2908 needclients 2 || return 0
2910 # test needs a running copytool
2914 local f=$DIR/$tdir/test_archive_remote
2915 # Create a file on a remote node
2916 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2917 "count=2 conv=fsync"
2920 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2921 error "hsm_archive failed"
2922 local fid=$(path2fid $f)
2923 wait_request_state $fid ARCHIVE SUCCEED
2925 # Release and implicit restore it
2926 do_node $CLIENT2 "$LFS hsm_release $f" ||
2927 error "hsm_release failed"
2928 do_node $CLIENT2 "md5sum $f" ||
2929 error "hsm_restore failed"
2931 wait_request_state $fid RESTORE SUCCEED
2933 run_test 57 "Archive a file with dirty cache on another node"
2935 truncate_released_file() {
2939 local sz=$(stat -c %s $src_file)
2940 local f=$DIR/$tdir/$tfile
2941 local fid=$(copy_file $1 $f)
2945 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2946 error "could not archive file"
2947 wait_request_state $fid ARCHIVE SUCCEED
2949 $LFS hsm_release $f || error "could not release file"
2951 $TRUNCATE $f $trunc_to || error "truncate failed"
2954 local sz1=$(stat -c %s $f)
2955 [[ $sz1 == $trunc_to ]] ||
2956 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2959 check_hsm_flags $f "0x0000000b"
2961 local state=$(get_request_state $fid RESTORE)
2962 [[ "$state" == "SUCCEED" ]] ||
2963 error "truncate $sz does not trig restore, state = $state"
2965 $TRUNCATE $ref $trunc_to
2966 cmp $ref $f || error "file data wrong after truncate"
2972 # test needs a running copytool
2977 local sz=$(stat -c %s /etc/passwd)
2979 echo "truncate up from $sz to $((sz*2))"
2980 truncate_released_file /etc/passwd $((sz*2))
2982 echo "truncate down from $sz to $((sz/2))"
2983 truncate_released_file /etc/passwd $((sz/2))
2985 echo "truncate to 0"
2986 truncate_released_file /etc/passwd 0
2988 run_test 58 "Truncate a released file will trigger restore"
2992 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
2993 skip "Need MDS version at least 2.7.63"
2996 $MCREATE $DIR/$tfile || error "mcreate failed"
2997 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
2998 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
2999 fid=$(path2fid $DIR/$tfile)
3000 wait_request_state $fid ARCHIVE SUCCEED
3001 $LFS hsm_release $DIR/$tfile || error "release failed"
3003 run_test 59 "Release stripeless file with non-zero size"
3006 # This test validates the fix for LU-4512. Ensure that the -u
3007 # option changes the progress reporting interval from the
3008 # default (30 seconds) to the user-specified interval.
3009 local f=$DIR/$tdir/$tfile
3010 local fid=$(create_file "$f" 1M 10)
3013 local progress_timeout=$((interval * 4))
3014 copytool setup -b 1 --update-interval $interval
3017 local mdt=${MDT_PREFIX}${mdtidx}
3018 local mds=mds$((mdtidx + 1))
3020 # Wait for copytool to register
3021 wait_update_facet $mds \
3022 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3023 uuid 100 || error "coyptool failed to register with $mdt"
3025 local start_at=$(date +%s)
3026 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3027 error "could not archive file"
3029 local agent=$(facet_active_host $SINGLEAGT)
3030 local logfile=$(copytool_logfile $SINGLEAGT)
3032 wait_update $agent \
3033 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3034 error "copytool failed to start"
3036 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3037 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3043 echo -n "Expecting a progress update within $progress_timeout seconds... "
3045 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3046 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3047 echo "$RESULT bytes copied in $WAIT seconds."
3049 elif [ $WAIT -ge $progress_timeout ]; then
3050 error "Timed out waiting for progress update!"
3053 WAIT=$((WAIT + sleep))
3057 local finish_at=$(date +%s)
3058 local elapsed=$((finish_at - start_at))
3060 # Ensure that the progress update occurred within the expected window.
3061 if [ $elapsed -lt $((interval - 1)) ]; then
3062 error "Expected progress update after at least $interval seconds"
3065 echo "Wait for on going archive hsm action to complete"
3066 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3067 echo "File archiving not completed even after 10 secs"
3069 run_test 60 "Changing progress update interval from default"
3072 # test needs a running copytool
3076 local f=$DIR/$tdir/$tfile
3077 local fid=$(copy_file /etc/passwd $f)
3079 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3082 wait_request_state $fid ARCHIVE FAILED
3084 run_test 61 "Waiting archive of a removed file should fail"
3087 # test needs a new running copytool
3088 stack_trap copytool_monitor_cleanup EXIT
3089 copytool_monitor_setup
3090 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3092 # Wait for the copytool to register.
3093 wait_update --verbose $(facet_active_host mds1) \
3094 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3096 error "copytool failed to register with MDT0000"
3099 wait_copytools || error "Copytools failed to stop"
3101 local REGISTER_EVENT
3102 local UNREGISTER_EVENT
3103 while read event; do
3104 local parsed=$(parse_json_event "$event")
3105 if [ -z "$parsed" ]; then
3106 error "Copytool sent malformed event: $event"
3110 if [ $event_type == "REGISTER" ]; then
3111 REGISTER_EVENT=$event
3112 elif [ $event_type == "UNREGISTER" ]; then
3113 UNREGISTER_EVENT=$event
3115 done < <(echo $"$(get_copytool_event_log)")
3117 if [ -z "$REGISTER_EVENT" ]; then
3118 error "Copytool failed to send register event to FIFO"
3121 if [ -z "$UNREGISTER_EVENT" ]; then
3122 error "Copytool failed to send unregister event to FIFO"
3125 echo "Register/Unregister events look OK."
3127 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3130 # Bump progress interval for livelier events.
3133 # test needs a new running copytool
3134 stack_trap copytool_monitor_cleanup EXIT
3135 copytool_monitor_setup
3136 copytool setup --update-interval $interval --event-fifo \
3137 "$HSMTOOL_MONITOR_DIR/fifo"
3139 stack_trap "cdt_clear_no_retry" EXIT
3140 # Just start and stop the copytool to generate events.
3143 local f=$DIR/$tdir/$tfile
3144 local fid=$(create_small_file "$f")
3146 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3147 error "could not archive file"
3148 wait_request_state $fid ARCHIVE SUCCEED
3150 local expected_fields="event_time data_fid source_fid"
3151 expected_fields+=" total_bytes current_bytes"
3154 [ARCHIVE_START]=false
3155 [ARCHIVE_FINISH]=false
3156 [ARCHIVE_RUNNING]=false
3158 while read event; do
3159 # Make sure we're not getting anything from previous events.
3160 for field in $expected_fields; do
3164 local parsed=$(parse_json_event "$event")
3165 if [ -z "$parsed" ]; then
3166 error "Copytool sent malformed event: $event"
3170 events["$event_type"]=true
3172 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3174 # Do some simple checking of the progress update events.
3175 for expected_field in $expected_fields; do
3176 if [ -z ${!expected_field+x} ]; then
3177 error "Missing $expected_field field in event"
3181 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3183 # These should be identical throughout an archive operation
3184 [ $source_fid == $data_fid ] ||
3185 error "Expected source_fid to equal data_fid"
3186 done < <(echo $"$(get_copytool_event_log)")
3188 # Check we received every type of events we were expecting
3189 for event in "${!events[@]}"; do
3190 ${events["$event"]} ||
3191 error "Copytool failed to send '$event' event to FIFO"
3194 echo "Archive events look OK."
3196 run_test 71 "Copytool logs JSON archive events to FIFO"
3199 # Bump progress interval for livelier events.
3202 # test needs a new running copytool
3203 stack_trap copytool_monitor_cleanup EXIT
3204 copytool_monitor_setup
3205 copytool setup --update-interval $interval --event-fifo \
3206 "$HSMTOOL_MONITOR_DIR/fifo"
3207 local test_file=$HSMTOOL_MONITOR_DIR/file
3209 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3211 do_facet $SINGLEAGT "$cmd" ||
3212 error "cannot create $test_file on $SINGLEAGT"
3213 copy2archive $test_file $tdir/$tfile
3216 local f=$DIR/$tdir/$tfile
3217 copytool import $tdir/$tfile $f
3218 f=$DIR2/$tdir/$tfile
3219 echo "Verifying released state: "
3220 check_hsm_flags $f "0x0000000d"
3222 local fid=$(path2fid $f)
3224 wait_request_state $fid RESTORE SUCCEED
3226 local expected_fields="event_time data_fid source_fid"
3227 expected_fields+=" total_bytes current_bytes"
3231 while read event; do
3232 # Make sure we're not getting anything from previous events.
3233 for field in $expected_fields; do
3237 local parsed=$(parse_json_event "$event")
3238 if [ -z "$parsed" ]; then
3239 error "Copytool sent malformed event: $event"
3243 if [ $event_type == "RESTORE_START" ]; then
3245 if [ $source_fid != $data_fid ]; then
3246 error "source_fid should == data_fid at start"
3249 elif [ $event_type == "RESTORE_FINISH" ]; then
3251 if [ $source_fid != $data_fid ]; then
3252 error "source_fid should == data_fid at finish"
3255 elif [ $event_type != "RESTORE_RUNNING" ]; then
3259 # Do some simple checking of the progress update events.
3260 for expected_field in $expected_fields; do
3261 if [ -z ${!expected_field+x} ]; then
3262 error "Missing $expected_field field in event"
3266 if [ $total_bytes -eq 0 ]; then
3267 error "Expected total_bytes to be > 0"
3270 # When a restore starts out, the data fid is the same as the
3271 # source fid. After the restore has gotten going, we learn
3272 # the new data fid. Once the restore has finished, the source
3273 # fid is set to the new data fid.
3275 # We test this because some monitoring software may depend on
3276 # this behavior. If it changes, then the consumers of these
3277 # events may need to be modified.
3278 if [ $source_fid == $data_fid ]; then
3279 error "source_fid should != data_fid during restore"
3281 done < <(echo $"$(get_copytool_event_log)")
3283 if [ -z "$START_EVENT" ]; then
3284 error "Copytool failed to send restore start event to FIFO"
3287 if [ -z "$FINISH_EVENT" ]; then
3288 error "Copytool failed to send restore finish event to FIFO"
3291 echo "Restore events look OK."
3293 run_test 72 "Copytool logs JSON restore events to FIFO"
3296 file_count=51 # Max number of files constrained by LNET message size
3297 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3298 local f=$DIR/$tdir/$tfile
3299 local FILELIST=/tmp/filelist.txt
3303 for i in $(seq 1 $file_count); do
3304 fid=$(copy_file /etc/hosts $f.$i)
3305 echo $f.$i >> $FILELIST
3309 # to be sure wait_all_done will not be mislead by previous tests
3311 wait_for_grace_delay
3312 $LFS hsm_archive --filelist $FILELIST ||
3313 error "cannot archive a file list"
3315 $LFS hsm_release --filelist $FILELIST ||
3316 error "cannot release a file list"
3317 $LFS hsm_restore --filelist $FILELIST ||
3318 error "cannot restore a file list"
3321 run_test 90 "Archive/restore a file list"
3323 double_verify_reset_hsm_param() {
3325 echo "Testing $HSM_PARAM.$p"
3326 local val=$(get_hsm_param $p)
3328 local val2=$(($val * 2))
3329 set_hsm_param $p $val2
3330 val=$(get_hsm_param $p)
3331 [[ $val == $val2 ]] ||
3332 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3333 echo "Set $p to 0 must failed"
3337 set_hsm_param $p $save
3339 if [[ $rc == 0 ]]; then
3340 error "we must not be able to set $HSM_PARAM.$p to 0"
3345 double_verify_reset_hsm_param loop_period
3346 double_verify_reset_hsm_param grace_delay
3347 double_verify_reset_hsm_param active_request_timeout
3348 double_verify_reset_hsm_param max_requests
3349 double_verify_reset_hsm_param default_archive_id
3351 run_test 100 "Set coordinator /proc tunables"
3358 run_test 102 "Verify coordinator control"
3361 # test needs a running copytool
3368 for i in $(seq 1 20); do
3369 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3375 echo "Current requests"
3376 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3377 $HSM_PARAM.actions |\
3378 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3380 [[ -z "$res" ]] || error "Some request have not been canceled"
3382 run_test 103 "Purge all requests"
3387 local f=$DIR/$tdir/$tfile
3388 local fid=$(create_empty_file "$f")
3390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3391 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3392 $HSM_PARAM.actions |\
3393 grep $fid | cut -f16 -d=")
3395 [[ "$data1" == "$DATAHEX" ]] ||
3396 error "Data field in records is ($data1) and not ($DATAHEX)"
3400 run_test 104 "Copy tool data field"
3403 local max_requests=$(get_hsm_param max_requests)
3407 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3408 set_hsm_param max_requests 300
3411 for i in $(seq -w 1 10); do
3412 cp /etc/passwd $DIR/$tdir/$i
3413 $LFS hsm_archive $DIR/$tdir/$i
3415 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3416 $HSM_PARAM.actions |\
3417 grep WAITING | wc -l")
3421 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3422 $HSM_PARAM.actions |\
3423 grep WAITING | wc -l")
3426 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3427 error "Requests count after shutdown $reqcnt2 != "\
3428 "before shutdown $reqcnt1"
3430 run_test 105 "Restart of coordinator"
3433 # test needs a running copytool
3436 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3438 check_agent_registered $uuid
3440 search_copytools || error "No copytool found"
3443 wait_copytools || error "Copytool failed to stop"
3445 check_agent_unregistered $uuid
3448 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3449 check_agent_registered $uuid
3451 run_test 106 "Copytool register/unregister"
3454 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3456 # test needs a running copytool
3458 # create and archive file
3460 local f1=$DIR/$tdir/$tfile
3461 local fid=$(copy_file /etc/passwd $f1)
3462 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3463 wait_request_state $fid ARCHIVE SUCCEED
3464 # shutdown and restart MDS
3466 # check the copytool still gets messages from MDT
3467 local f2=$DIR/$tdir/2
3468 local fid=$(copy_file /etc/passwd $f2)
3469 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3470 # main check of this sanity: this request MUST succeed
3471 wait_request_state $fid ARCHIVE SUCCEED
3473 run_test 107 "Copytool re-register after MDS restart"
3475 policy_set_and_test()
3479 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3480 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3481 [[ "$policy" == "$target" ]] ||
3482 error "Wrong policy after '$change': '$policy' != '$target'"
3486 # to force default policy setting if error
3487 CDT_POLICY_HAD_CHANGED=true
3489 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3490 local default="NonBlockingRestore [NoRetryAction]"
3491 [[ "$policy" == "$default" ]] ||
3492 error "default policy has changed,"\
3493 " '$policy' != '$default' update the test"
3494 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3495 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3496 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3497 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3498 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3499 # useless bacause we know but safer for futur changes to use real value
3500 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3501 echo "Next set_param must failed"
3502 policy_set_and_test "wrong" "$policy"
3505 echo "Back to default policy"
3506 cdt_set_sanity_policy
3508 run_test 109 "Policy display/change"
3511 # test needs a running copytool
3516 copy2archive /etc/passwd $tdir/$tfile
3518 local f=$DIR/$tdir/$tfile
3519 copytool import $tdir/$tfile $f
3520 local fid=$(path2fid $f)
3522 cdt_set_non_blocking_restore
3527 wait_request_state $fid RESTORE SUCCEED
3528 cdt_clear_non_blocking_restore
3532 error "md5sum returns $st != 1, "\
3533 "should also perror ENODATA (No data available)"
3535 run_test 110a "Non blocking restore policy (import case)"
3538 # test needs a running copytool
3542 local f=$DIR/$tdir/$tfile
3543 local fid=$(copy_file /etc/passwd $f)
3544 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3545 wait_request_state $fid ARCHIVE SUCCEED
3548 cdt_set_non_blocking_restore
3553 wait_request_state $fid RESTORE SUCCEED
3554 cdt_clear_non_blocking_restore
3558 error "md5sum returns $st != 1, "\
3559 "should also perror ENODATA (No data available)"
3561 run_test 110b "Non blocking restore policy (release case)"
3564 # test needs a running copytool
3568 copy2archive /etc/passwd $tdir/$tfile
3570 local f=$DIR/$tdir/$tfile
3572 copytool import $tdir/$tfile $f
3573 local fid=$(path2fid $f)
3577 copytool_remove_backend $fid
3580 wait_request_state $fid RESTORE FAILED
3587 [[ $st == 0 ]] || error "Restore does not failed"
3589 run_test 111a "No retry policy (import case), restore will error"\
3590 " (No such file or directory)"
3593 # test needs a running copytool
3597 local f=$DIR/$tdir/$tfile
3598 local fid=$(copy_file /etc/passwd $f)
3599 stack_trap cdt_clear_no_retry EXIT
3601 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3602 wait_request_state $fid ARCHIVE SUCCEED
3605 copytool_remove_backend $fid
3608 wait_request_state $fid RESTORE FAILED
3612 [[ $st == 0 ]] || error "Restore does not failed"
3614 run_test 111b "No retry policy (release case), restore will error"\
3615 " (No such file or directory)"
3618 # test needs a running copytool
3622 local f=$DIR/$tdir/$tfile
3623 local fid=$(copy_file /etc/passwd $f)
3625 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3626 local l=$($LFS hsm_action $f)
3628 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3631 wait_request_state $fid ARCHIVE SUCCEED
3634 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3636 run_test 112 "State of recorded request"
3639 local file1=$DIR/$tdir/$tfile
3640 local file2=$DIR2/$tdir/$tfile
3642 local fid=$(create_small_sync_file $file1)
3644 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3645 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3646 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3648 copytool setup -m "$MOUNT3"
3650 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3652 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3653 wait_request_state $fid ARCHIVE SUCCEED
3655 $LFS hsm_release $file1
3656 echo "Verifying released state: "
3657 check_hsm_flags $file1 "0x0000000d"
3659 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3662 kill -USR1 $MULTIPID
3667 local size1=$(stat -c "%s" $file1)
3668 local size2=$(stat -c "%s" $file2)
3670 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3672 run_test 113 "wrong stat after restore"
3675 local f=$DIR/$tdir/$tfile
3676 local fid=$(create_empty_file "$f")
3680 # Prevent archive from completing
3683 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3684 # wait archive to register at CDT
3685 wait_request_state $fid ARCHIVE STARTED
3687 # Cancel the archive
3688 $LFS hsm_cancel "$f"
3690 wait_request_state $fid ARCHIVE CANCELED
3693 wait_request_state $fid CANCEL SUCCEED
3695 run_test 200 "Register/Cancel archive"
3698 # test needs a running copytool
3701 local f=$DIR/$tdir/$tfile
3702 create_archive_file $tdir/$tfile
3703 copytool import $tdir/$tfile $f
3704 local fid=$(path2fid $f)
3706 # test with cdt on is made in test_222
3709 # wait restore to register at CDT
3710 wait_request_state $fid RESTORE WAITING
3713 wait_request_state $fid RESTORE CANCELED
3714 wait_request_state $fid CANCEL SUCCEED
3716 run_test 201 "Register/Cancel restore"
3719 local f=$DIR/$tdir/$tfile
3720 local fid=$(create_empty_file "$f")
3722 # test needs a running copytool
3725 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3726 wait_request_state $fid ARCHIVE SUCCEED
3730 # wait remove to register at CDT
3731 wait_request_state $fid REMOVE STARTED
3734 wait_request_state $fid REMOVE CANCELED
3736 run_test 202 "Register/Cancel remove"
3738 test_220A() { # was test_220
3739 # test needs a running copytool
3744 local f=$DIR/$tdir/$tfile
3745 local fid=$(copy_file /etc/passwd $f)
3749 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3750 wait_request_state $fid ARCHIVE SUCCEED
3752 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3753 error "The expected changelog was not emitted"
3755 run_test 220A "Changelog for archive"
3758 # test needs a running copytool
3763 local f=$DIR/$tdir/$tfile
3764 local fid=$(copy_file /etc/passwd $f)
3768 # block copytool operations to allow for HSM request to be
3769 # submitted and file be unlinked (CDT will find object removed)
3772 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3774 # wait request to reach CT
3775 wait_request_state $fid ARCHIVE STARTED
3781 wait_request_state $fid ARCHIVE FAILED
3784 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3785 error "The expected changelog was not emitted"
3787 run_test 220a "Changelog for failed archive"
3790 local f=$DIR/$tdir/$tfile
3791 local fid=$(create_empty_file "$f")
3796 # Prevent archive from completing
3798 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3799 wait_request_state $fid ARCHIVE STARTED
3802 wait_request_state $fid ARCHIVE CANCELED
3805 wait_request_state $fid CANCEL SUCCEED
3807 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3808 error "The expected changelog was not emitted"
3810 run_test 221 "Changelog for archive canceled"
3813 # test needs a running copytool
3817 copy2archive /etc/passwd $tdir/$tfile
3819 local f=$DIR/$tdir/$tfile
3820 copytool import $tdir/$tfile $f
3821 local fid=$(path2fid $f)
3826 wait_request_state $fid RESTORE SUCCEED
3828 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3829 error "The expected changelog was not emitted"
3831 run_test 222a "Changelog for explicit restore"
3834 # test needs a running copytool
3838 local f=$DIR/$tdir/$tfile
3839 local fid=$(copy_file /etc/passwd $f)
3842 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3843 wait_request_state $fid ARCHIVE SUCCEED
3848 wait_request_state $fid RESTORE SUCCEED
3850 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3851 error "The expected changelog was not emitted"
3853 run_test 222b "Changelog for implicit restore"
3856 # test needs a running copytool
3860 copy2archive /etc/passwd $tdir/$tfile
3862 local f=$DIR/$tdir/$tfile
3863 copytool import $tdir/$tfile $f
3864 local fid=$(path2fid $f)
3868 # block copytool operations to allow for HSM request to be
3869 # submitted and file be unlinked (CDT will find object removed)
3874 # wait request to reach CT
3875 wait_request_state $fid RESTORE STARTED
3881 wait_request_state $fid RESTORE FAILED
3884 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3885 error "The expected changelog was not emitted"
3887 run_test 222c "Changelog for failed explicit restore"
3890 # test needs a running copytool
3894 local f=$DIR/$tdir/$tfile
3895 local fid=$(copy_file /etc/passwd $f)
3898 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3899 wait_request_state $fid ARCHIVE SUCCEED
3902 copytool_remove_backend $fid
3905 wait_request_state $fid RESTORE FAILED
3908 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3909 error "The expected changelog was not emitted"
3911 run_test 222d "Changelog for failed implicit restore"
3914 # test needs a running copytool
3917 local f=$DIR/$tdir/$tfile
3918 create_archive_file $tdir/$tfile
3922 copytool import $tdir/$tfile $f
3923 local fid=$(path2fid $f)
3926 wait_request_state $fid RESTORE STARTED
3928 wait_request_state $fid RESTORE CANCELED
3929 wait_request_state $fid CANCEL SUCCEED
3931 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3932 error "The expected changelog was not emitted"
3934 run_test 223a "Changelog for restore canceled (import case)"
3937 local f=$DIR/$tdir/$tfile
3938 local fid=$(create_empty_file "$f")
3943 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3944 wait_request_state $fid ARCHIVE SUCCEED
3947 # Prevent restore from completing
3950 wait_request_state $fid RESTORE STARTED
3953 wait_request_state $fid RESTORE CANCELED
3956 wait_request_state $fid CANCEL SUCCEED
3958 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3959 error "The expected changelog was not emitted"
3961 run_test 223b "Changelog for restore canceled (release case)"
3963 test_224A() { # was test_224
3964 # test needs a running copytool
3969 local f=$DIR/$tdir/$tfile
3970 local fid=$(copy_file /etc/passwd $f)
3973 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3974 wait_request_state $fid ARCHIVE SUCCEED
3977 wait_request_state $fid REMOVE SUCCEED
3979 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
3980 error "The expected changelog was not emitted"
3982 run_test 224A "Changelog for remove"
3985 # test needs a running copytool
3990 local f=$DIR/$tdir/$tfile
3991 local fid=$(copy_file /etc/passwd $f)
3994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3995 wait_request_state $fid ARCHIVE SUCCEED
3997 copytool_remove_backend $fid
3999 # block copytool operations to allow for HSM request to be
4000 # submitted and file be unlinked (CDT will find object removed)
4005 # wait for request to reach CT
4006 wait_request_state $fid REMOVE STARTED
4012 wait_request_state $fid REMOVE FAILED
4014 # HE_REMOVE|ENOENT=0x202
4015 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4016 error "The expected changelog was not emitted"
4018 run_test 224a "Changelog for failed remove"
4021 # test is not usable because remove request is too fast
4022 # so it is always finished before cancel can be done ...
4023 echo "Test disabled"
4026 # test needs a running copytool
4029 local f=$DIR/$tdir/$tfile
4030 local fid=$(create_empty_file "$f")
4033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4034 wait_request_state $fid ARCHIVE SUCCEED
4036 # Prevent restore from completing
4041 wait_request_state $fid REMOVE CANCELED
4044 wait_request_state $fid CANCEL SUCCEED
4046 changelog_find -type HSM -target-fid $fid -flags 0x27d
4047 error "The expected changelog was not emitted"
4049 run_test 225 "Changelog for remove canceled"
4052 # test needs a running copytool
4057 local f1=$DIR/$tdir/$tfile-1
4058 local f2=$DIR/$tdir/$tfile-2
4059 local f3=$DIR/$tdir/$tfile-3
4060 local fid1=$(copy_file /etc/passwd $f1)
4061 local fid2=$(copy_file /etc/passwd $f2)
4062 copy_file /etc/passwd $f3
4065 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4066 wait_request_state $fid1 ARCHIVE SUCCEED
4068 $LFS hsm_archive $f2
4069 wait_request_state $fid2 ARCHIVE SUCCEED
4071 rm $f1 || error "rm $f1 failed"
4074 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4075 error "The expected changelog was not emitted"
4077 mv $f3 $f2 || error "mv $f3 $f2 failed"
4079 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4080 error "The expected changelog was not emitted"
4082 run_test 226 "changelog for last rm/mv with exiting archive"
4084 # This is just a utility function to clarify what test_227 does
4089 "$LFS" "$action" --$flag "$file" ||
4090 error "Cannot ${action#hsm_} $flag on '$file'"
4092 # Only one changelog should be produced
4093 local entries="$(changelog_find -type HSM -target-fid $fid)"
4094 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4095 error "lfs $action --$flag '$file' produced more than one" \
4098 # Parse the last changelog record
4099 local entry="$(tail -n 1 <<< "$entries")"
4100 eval local -A changelog=$(changelog2array $entry)
4102 # Also check the flags match what is expected
4103 [[ ${changelog[flags]} == $target ]] ||
4104 error "Changelog flag is '${changelog[flags]}', not $target"
4108 local file="$DIR/$tdir/$tfile"
4109 local fid=$(create_empty_file "$file")
4114 for flag in norelease noarchive exists archived lost; do
4115 if [ "$flag" == lost ]; then
4116 # The flag "lost" only works on an archived file
4117 "$LFS" hsm_set --archived "$file"
4121 action="hsm_set" __test_227
4122 action="hsm_clear" __test_227
4125 run_test 227 "changelog when explicit setting of HSM flags"
4128 # test needs a running copytool
4131 local fid=$(create_small_sync_file $DIR/$tfile)
4132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4133 wait_request_state $fid ARCHIVE SUCCEED
4135 $LFS hsm_release $DIR/$tfile
4136 check_hsm_flags $DIR/$tfile "0x0000000d"
4138 filefrag $DIR/$tfile | grep " 1 extent found" ||
4139 error "filefrag on released file must return only one extent"
4141 # only newer versions of cp detect sparse files by stat/FIEMAP
4143 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4144 error "copying $DIR/$tfile"
4145 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4147 $LFS hsm_release $DIR/$tfile
4148 check_hsm_flags $DIR/$tfile "0x0000000d"
4150 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4152 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4154 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4155 error "comparing untarred $DIR/$tfile"
4157 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4158 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4160 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4163 local file="$DIR/$tdir/$tfile"
4165 # set max_requests to allow one request of each type to be started (3)
4167 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4168 set_hsm_param max_requests 3
4171 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4172 set_hsm_param loop_period 1
4174 # send 1 requests of each kind twice
4177 for action in archive restore remove; do
4178 local filepath="$file"-to-$action
4179 local fid=$(create_empty_file "$filepath")
4180 local fid2=$(create_empty_file "$filepath".bis)
4182 if [ "$action" != archive ]; then
4183 "$LFS" hsm_archive "$filepath"
4184 wait_request_state $fid ARCHIVE SUCCEED
4185 "$LFS" hsm_archive "$filepath".bis
4186 wait_request_state $fid2 ARCHIVE SUCCEED
4188 if [ "$action" == restore ]; then
4189 "$LFS" hsm_release "$filepath"
4190 "$LFS" hsm_release "$filepath".bis
4194 # suspend the copytool to prevent requests from completing
4195 stack_trap "copytool_continue" EXIT
4198 # send `max_requests' requests (one of each kind)
4199 for action in archive restore remove; do
4200 filepath="$file"-to-$action
4201 "$LFS" hsm_${action} "$filepath"
4202 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4205 # send another batch of requests
4206 for action in archive restore remove; do
4207 "$LFS" hsm_${action} "$file-to-$action".bis
4209 # wait for `loop_period' seconds to make sure the coordinator has time
4210 # to register those, even though it should not
4213 # only the first batch of request should be started
4215 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4219 error "expected 3 STARTED requests, found $count"
4221 run_test 250 "Coordinator max request"
4224 local f=$DIR/$tdir/$tfile
4225 local fid=$(create_empty_file "$f")
4228 # to have a short test
4229 local old_to=$(get_hsm_param active_request_timeout)
4230 set_hsm_param active_request_timeout 1
4231 # to be sure the cdt will wake up frequently so
4232 # it will be able to cancel the "old" request
4233 local old_loop=$(get_hsm_param loop_period)
4234 set_hsm_param loop_period 1
4239 # Prevent archive from completing
4241 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4242 wait_request_state $fid ARCHIVE STARTED
4244 # Let the request timeout
4245 wait_request_state $fid ARCHIVE CANCELED
4247 set_hsm_param active_request_timeout $old_to
4248 set_hsm_param loop_period $old_loop
4250 run_test 251 "Coordinator request timeout"
4253 local f=$DIR/$tdir/$tfile
4254 local fid=$(create_empty_file "$f")
4256 # to have a short test
4257 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4258 set_hsm_param loop_period 1
4262 # Prevent archive from completing
4264 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4265 wait_request_state $fid ARCHIVE STARTED
4268 stack_trap "set_hsm_param active_request_timeout \
4269 $(get_hsm_param active_request_timeout)" EXIT
4270 set_hsm_param active_request_timeout 1
4272 wait_request_state $fid ARCHIVE CANCELED
4275 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4279 # test needs a running copytool
4283 local f=$DIR/$tdir/$tfile
4285 dd if=/dev/zero of=$f bs=1MB count=10
4286 local fid=$(path2fid $f)
4288 $LFS hsm_archive $f || error "could not archive file"
4289 wait_request_state $fid ARCHIVE SUCCEED
4291 # clear locks to discard inode data
4292 cancel_lru_locks osc
4294 #define OBD_FAIL_MDC_MERGE 0x807
4295 $LCTL set_param fail_loc=0x807
4297 #expect error here, instead of release with wrong size
4300 if ((rc == 0)); then
4301 file_size=$(stat -c '%s' $f)
4302 if ((file_size != 10485760)); then
4303 error "Wrong file size after hsm_release"
4306 echo "could not release file"
4309 run_test 253 "Check for wrong file size after release"
4313 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4314 skip "need MDS version at least 2.10.56"
4316 # Check that the counters are initialized to 0
4318 for request_type in archive restore remove; do
4319 count="$(get_hsm_param ${request_type}_count)" ||
4320 error "Reading ${request_type}_count failed with $?"
4322 [ "$count" -eq 0 ] ||
4323 error "Expected ${request_type}_count to be " \
4327 run_test 254a "Request counters are initialized to zero"
4331 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4332 skip "need MDS version at least 2.10.56"
4334 # The number of request to launch (at least 32)
4335 local request_count=$((RANDOM % 32 + 32))
4336 printf "Will launch %i requests of each type\n" "$request_count"
4338 # Launch a copytool to process requests
4341 # Set hsm.max_requests to allow starting all requests at the same time
4343 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4344 set_hsm_param max_requests "$request_count"
4348 for request_type in archive restore remove; do
4349 printf "Checking %s requests\n" "${request_type}"
4350 # Suspend the copytool to give us time to read the proc files
4353 for ((i = 0; i < $request_count; i++)); do
4354 case $request_type in
4356 create_empty_file "$DIR/$tdir/$tfile-$i" \
4360 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4363 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4366 # Give the coordinator 10 seconds to start every request
4368 while get_hsm_param actions | grep -q WAITING; do
4371 [ $timeout -gt 0 ] ||
4372 error "${request_type^} requests took too " \
4376 count="$(get_hsm_param ${request_type}_count)"
4377 [ "$count" -eq "$request_count" ] ||
4378 error "Expected '$request_count' (!= '$count') " \
4379 "active $request_type requests"
4381 # Let the copytool process the requests
4383 # Give it 10 seconds maximum
4385 while get_hsm_param actions | grep -q STARTED; do
4388 [ $timeout -gt 0 ] ||
4389 error "${request_type^} requests took too " \
4393 count="$(get_hsm_param ${request_type}_count)"
4394 [ "$count" -eq 0 ] ||
4395 error "Expected 0 (!= '$count') " \
4396 "active $request_type requests"
4399 run_test 254b "Request counters are correctly incremented and decremented"
4403 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4404 skip "Need MDS version at least 2.12.0"
4406 local file="$DIR/$tdir/$tfile"
4407 local fid=$(create_empty_file "$file")
4409 # How do you make sure the coordinator has consumed any outstanding
4410 # event, without triggering an event yourself?
4412 # You wait for a request to disappear from the coordinator's llog.
4414 # Warning: the setup represents 90% of this test
4416 # Create and process an HSM request
4418 "$LFS" hsm_archive "$file"
4419 wait_request_state $fid ARCHIVE SUCCEED
4422 wait_copytools || error "failed to stop copytools"
4424 # Launch a new HSM request
4426 create_empty_file "$file"
4427 "$LFS" hsm_archive "$file"
4431 # Have the completed request be removed as soon as the cdt wakes up
4432 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4433 set_hsm_param grace_delay 1
4434 # (Hopefully, time on the MDS will behave nicely)
4435 do_facet $SINGLEMDS sleep 2 &
4437 # Increase `loop_period' as a mean to prevent the coordinator from
4438 # waking itself up to do some housekeeping.
4439 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4440 set_hsm_param loop_period 1000
4442 wait $! || error "waiting failed"
4444 wait_request_state $fid ARCHIVE ""
4445 # The coordinator will not wake up on its own for ~`loop_period' secs...
4447 # ... Unless a copytool registers. Now the real test begins
4449 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4451 run_test 255 "Copytool registration wakes the coordinator up"
4453 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4454 # break in the future because of that.
4457 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4458 skip "need MDS version 2.11.56 or later"
4460 local -a files=("$DIR/$tdir/$tfile".{0..15})
4463 for file in "${files[@]}"; do
4464 create_small_file "$file"
4467 # Set a few hsm parameters
4469 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4470 set_hsm_param loop_period 1
4472 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4473 set_hsm_param max_requests 3
4477 "$LFS" hsm_archive "${files[0]}"
4478 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4479 "$LFS" hsm_release "${files[0]}"
4483 wait_copytools || error "copytools failed to stop"
4485 # Send several archive requests
4486 for file in "${files[@]:1}"; do
4487 "$LFS" hsm_archive "$file"
4490 # Send one restore request
4491 "$LFS" hsm_restore "${files[0]}"
4496 # Wait for all the requests to complete
4497 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4498 for file in "${files[@]:1}"; do
4499 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4502 # Collect the actions in the order in which the copytool processed them
4504 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4505 "$(copytool_logfile "$SINGLEAGT")")
4508 printf '%s\n' "${actions[@]}"
4511 for action in "${actions[@]:0:3}"; do
4512 [ "$action" == RESTORE ] && return
4515 error "Too many ARCHIVE requests were run before the RESTORE request"
4517 run_test 260a "Restore request have priority over other requests"
4519 # This test is very much tied to the implementation of the current priorisation
4520 # mechanism in the coordinator. It might not make sense to keep it in the future
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
4542 copytool setup --archive-id 2
4543 "$LFS" hsm_archive --archive 2 "${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]}"
4561 copytool setup --archive-id 2
4563 # Wait for all the requests to complete
4564 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4565 for file in "${files[@]:1}"; do
4566 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4569 # Collect the actions in the order in which the copytool processed them
4571 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4572 "$(copytool_logfile "$SINGLEAGT")")
4575 printf '%s\n' "${actions[@]}"
4578 for action in "${actions[@]:0:3}"; do
4579 [ "$action" == RESTORE ] && return
4582 error "Too many ARCHIVE requests were run before the RESTORE request"
4584 run_test 260b "Restore request have priority over other requests"
4586 # This test is very much tied to the implementation of the current priorisation
4587 # mechanism in the coordinator. It might not make sense to keep it in the future
4590 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4591 skip "Need MDS version at least 2.12.0"
4593 local -a files=("$DIR/$tdir/$tfile".{0..15})
4596 for file in "${files[@]}"; do
4597 create_small_file "$file"
4600 # Set a few hsm parameters
4602 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4603 set_hsm_param loop_period 1000
4605 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4606 set_hsm_param max_requests 3
4609 copytool setup --archive-id 2
4610 "$LFS" hsm_archive --archive 2 "${files[0]}"
4611 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4612 "$LFS" hsm_release "${files[0]}"
4616 wait_copytools || error "copytools failed to stop"
4618 # Force the next coordinator run to do housekeeping
4622 "$LFS" hsm_archive "${files[1]}"
4626 copytool setup --archive-id 2
4628 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4629 # The coordinator just did a housekeeping run it won't do another one
4630 # for around `loop_period' seconds => requests will not be reordered
4631 # if it costs too much (ie. when the coordinator has to discard a whole
4634 # Send several archive requests
4635 for file in "${files[@]:2}"; do
4636 "$LFS" hsm_archive "$file"
4639 # Send one restore request
4640 "$LFS" hsm_restore "${files[0]}"
4642 # Wait for all the requests to complete
4643 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4644 for file in "${files[@]:2}"; do
4645 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4648 # Collect the actions in the order in which the copytool processed them
4650 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4651 "$(copytool_logfile "$SINGLEAGT")")
4654 printf '%s\n' "${actions[@]}"
4657 for action in "${actions[@]:0:3}"; do
4658 [ "$action" == RESTORE ] &&
4659 error "Restore requests should not be prioritised" \
4660 "unless the coordinator is doing housekeeping"
4664 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4667 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4669 # the only way to test ondisk conf is to restart MDS ...
4670 echo "Stop coordinator and remove coordinator state at mount"
4673 # clean on disk conf set by default
4674 cdt_clear_mount_state
4675 cdt_check_state stopped
4677 # check cdt still off after umount/remount
4679 cdt_check_state stopped
4681 echo "Set coordinator start at mount, and start coordinator"
4682 cdt_set_mount_state enabled
4685 cdt_check_state enabled
4687 # check cdt still on after umount/remount
4689 cdt_check_state enabled
4691 # we are back to original state (cdt started at mount)
4693 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4696 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4698 local ai=$(get_hsm_param default_archive_id)
4699 local new=$((ai + 1))
4701 set_hsm_param default_archive_id $new -P
4703 local res=$(get_hsm_param default_archive_id)
4706 set_hsm_param default_archive_id "" "-P -d"
4708 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4710 run_test 301 "HSM tunnable are persistent"
4713 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4715 local ai=$(get_hsm_param default_archive_id)
4716 local new=$((ai + 1))
4721 set_hsm_param default_archive_id $new -P
4724 for mdtno in $(seq 1 $MDSCOUNT); do
4729 cdt_check_state enabled
4731 local res=$(get_hsm_param default_archive_id)
4734 set_hsm_param default_archive_id "" "-P -d"
4736 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4738 run_test 302 "HSM tunnable are persistent when CDT is off"
4741 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4747 local dir_mdt0=$DIR/$tdir/mdt0
4748 local dir_mdt1=$DIR/$tdir/mdt1
4750 # create 1 dir per MDT
4751 stack_trap "rm -rf $dir_mdt0" EXIT
4752 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4753 stack_trap "rm -rf $dir_mdt1" EXIT
4754 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4756 # create 1 file in each MDT
4757 local fid1=$(create_small_file $dir_mdt0/$tfile)
4758 local fid2=$(create_small_file $dir_mdt1/$tfile)
4760 # check that hsm request on mdt0 is sent to the right MDS
4761 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4762 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4763 echo "archive successful on mdt0"
4765 # check that hsm request on mdt1 is sent to the right MDS
4766 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4767 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4768 echo "archive successful on mdt1"
4770 run_test 400 "Single request is sent to the right MDT"
4773 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4779 local dir_mdt0=$DIR/$tdir/mdt0
4780 local dir_mdt1=$DIR/$tdir/mdt1
4782 # create 1 dir per MDT
4783 stack_trap "rm -rf $dir_mdt0" EXIT
4784 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4785 stack_trap "rm -rf $dir_mdt1" EXIT
4786 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4788 # create 1 file in each MDT
4789 local fid1=$(create_small_file $dir_mdt0/$tfile)
4790 local fid2=$(create_small_file $dir_mdt1/$tfile)
4792 # check that compound requests are shunt to the rights MDTs
4793 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4794 error "lfs hsm_archive"
4795 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4796 echo "archive successful on mdt0"
4797 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4798 echo "archive successful on mdt1"
4800 run_test 401 "Compound requests split and sent to their respective MDTs"
4802 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4807 local node=$(facet_active_host $facet)
4809 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4810 awk '{print $4}'); do
4811 echo "$3 $mdc on $node"
4812 do_facet $facet "$LCTL --device $mdc $state" || return 1
4817 # deactivate all mdc on agent1
4818 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4820 copytool setup --no-fail
4822 check_agent_unregistered "uuid" # match any agent
4824 # no expected running copytool
4825 search_copytools $agent && error "Copytool start should have failed"
4828 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4830 run_test 402a "Copytool start fails if all MDTs are inactive"
4837 local f=$DIR/$tdir/$tfile
4838 touch $f || error "touch $f failed"
4839 local fid=$(path2fid $f)
4841 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4842 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4843 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4845 # give time for CDT to send request and to keep it for retry
4846 wait_for_loop_period
4848 wait_request_state $fid ARCHIVE WAITING
4850 do_facet $SINGLEAGT lctl set_param fail_loc=0
4852 # request should succeed now
4853 wait_request_state $fid ARCHIVE SUCCEED
4855 run_test 402b "CDT must retry request upon slow start of CT"
4858 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4860 local agent=$(facet_active_host $SINGLEAGT)
4862 # deactivate all mdc for MDT0001
4863 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4866 local uuid=$(get_agent_uuid $agent)
4867 # check the agent is registered on MDT0000, and not on MDT0001
4868 check_agent_registered_by_mdt $uuid 0
4869 check_agent_unregistered_by_mdt $uuid 1
4871 # check running copytool process
4872 search_copytools $agent || error "No running copytools on $agent"
4874 # reactivate all mdc for MDT0001
4875 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4877 # make sure the copytool is now registered to all MDTs
4878 check_agent_registered $uuid
4880 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4883 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4887 # create files on both MDT0000 and MDT0001
4890 local dir_mdt0=$DIR/$tdir/mdt0
4891 stack_trap "rm -rf $dir_mdt0" EXIT
4892 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4894 # create 1 file on mdt0
4895 local fid1=$(create_small_file $dir_mdt0/$tfile)
4897 # deactivate all mdc for MDT0001
4898 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4900 # send an HSM request for files in MDT0000
4901 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4903 # check for completion of files in MDT0000
4904 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4905 echo "archive successful on mdt0"
4907 # reactivate all mdc for MDT0001
4908 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4910 run_test 404 "Inactive MDT does not block requests for active MDTs"
4913 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4919 local striped_dir=$DIR/$tdir/striped_dir
4921 # create striped dir on all of MDTs
4922 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4924 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4925 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4926 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4927 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4929 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4930 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4931 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4932 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4934 # check that compound requests are shunt to the rights MDTs
4935 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4936 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4937 error "lfs hsm_archive"
4939 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4940 echo "archive successful on $fid1"
4941 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4942 echo "archive successful on $fid2"
4943 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4944 echo "archive successful on $fid3"
4945 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4946 echo "archive successful on $fid4"
4948 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4949 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4950 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4951 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4953 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4954 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4955 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4956 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4958 run_test 405 "archive and release under striped directory"
4961 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4963 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
4964 skip "need MDS version at least 2.7.64"
4969 fid=$(create_small_file $DIR/$tdir/$tfile)
4974 $LFS hsm_archive $DIR/$tdir/$tfile
4975 wait_request_state "$fid" ARCHIVE SUCCEED
4976 $LFS hsm_release $DIR/$tdir/$tfile
4978 # Should migrate $tdir but not $tfile.
4979 $LFS migrate -m1 $DIR/$tdir &&
4980 error "migrating HSM an archived file should fail"
4982 $LFS hsm_restore $DIR/$tdir/$tfile
4983 wait_request_state "$fid" RESTORE SUCCEED
4985 $LFS hsm_remove $DIR/$tdir/$tfile
4986 wait_request_state "$fid" REMOVE SUCCEED
4988 cat $DIR/$tdir/$tfile > /dev/null ||
4989 error "cannot read $DIR/$tdir/$tfile"
4991 $LFS migrate -m1 $DIR/$tdir ||
4992 error "cannot complete migration after HSM remove"
4994 mdt_index=$($LFS getstripe -m $DIR/$tdir)
4995 if ((mdt_index != 1)); then
4996 error "expected MDT index 1, got $mdt_index"
4999 # Refresh fid after migration.
5000 fid=$(path2fid $DIR/$tdir/$tfile)
5003 $LFS hsm_archive $DIR/$tdir/$tfile
5004 wait_request_state "$fid" ARCHIVE SUCCEED 1
5006 lctl set_param debug=+trace
5007 $LFS hsm_release $DIR/$tdir/$tfile ||
5008 error "cannot release $DIR/$tdir/$tfile"
5010 $LFS hsm_restore $DIR/$tdir/$tfile
5011 wait_request_state "$fid" RESTORE SUCCEED 1
5013 cat $DIR/$tdir/$tfile > /dev/null ||
5014 error "cannot read $DIR/$tdir/$tfile"
5016 run_test 406 "attempting to migrate HSM archived files is safe"
5019 local f=$DIR/$tdir/$tfile
5020 local f2=$DIR2/$tdir/$tfile
5021 local fid=$(create_empty_file "$f")
5025 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5026 wait_request_state $fid ARCHIVE SUCCEED
5029 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5030 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5032 # Prevent restore from completing
5036 # 1st request holds layout lock while appropriate
5037 # RESTORE record is still not added to llog
5041 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5042 # after umount hsm_actions->O/x/x log shouldn't have
5043 # double RESTORE records like below
5044 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5045 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5047 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5049 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5051 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5054 wait_all_done 100 $fid
5056 run_test 407 "Check for double RESTORE records in llog"
5060 [ "$MDS1_VERSION" -lt $(version_code 2.6.92) ] &&
5061 skip "HSM migrate is not supported"
5063 test_mkdir -p $DIR/$tdir
5065 if [ "$CLIENT_VERSION" -lt $(version_code 2.11.56) ] ||
5066 [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ];
5068 llapi_hsm_test -d $DIR/$tdir -b ||
5069 error "One llapi HSM test failed"
5071 llapi_hsm_test -d $DIR/$tdir ||
5072 error "One llapi HSM test failed"
5075 run_test 500 "various LLAPI HSM tests"
5078 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
5079 skip "need MDS version at least 2.10.58"
5083 local f=$DIR/$tdir/$tfile
5086 # set changelog_mask to ALL
5087 changelog_chmask "ALL"
5089 chmod 777 $DIR/$tdir
5090 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5091 local fid=$(path2fid $f)
5094 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5095 -gid "$RUNAS_GID") ||
5096 error "No matching CREAT entry"
5098 # Parse the changelog
5099 eval local -A changelog=$(changelog2array $entry)
5100 local nid="${changelog[nid]}"
5103 echo "Got NID '$nid'"
5104 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5105 error "nid '$nid' does not match any client NID:" \
5108 run_test 600 "Changelog fields 'u=' and 'nid='"
5111 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5112 skip "need MDS version at least 2.10.58"
5116 local f=$DIR/$tdir/$tfile
5119 # set changelog_mask to ALL
5120 changelog_chmask "ALL"
5122 touch $f || error "touch $f failed"
5123 local fid=$(path2fid $f)
5126 cat $f || error "cat $f failed"
5128 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5129 error "No matching OPEN entry"
5131 run_test 601 "OPEN Changelog entry"
5134 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5135 skip "need MDS version at least 2.10.58"
5139 local f=$DIR/$tdir/$tfile
5142 # set changelog_mask to ALL
5143 changelog_chmask "ALL"
5145 touch $f || error "touch $f failed"
5146 local fid=$(path2fid $f)
5149 cat $f || error "cat $f failed"
5151 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5155 echo f > $f || error "write $f failed"
5158 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5160 # remove OPEN from changelog_mask
5161 changelog_chmask "-OPEN"
5165 cat $f || error "cat $f failed"
5168 changelog_find -type CLOSE -target-fid $fid &&
5169 error "There should be no CLOSE entry"
5173 echo f > $f || error "write $f failed"
5176 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5178 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5181 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5182 skip "need MDS version at least 2.10.58"
5186 local f=$DIR/$tdir/$tfile
5189 # set changelog_mask to ALL
5190 changelog_chmask "ALL"
5192 touch $f || error "touch $f failed"
5193 local fid=$(path2fid $f)
5195 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5198 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5200 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5201 error "No matching GXATR entry"
5203 run_test 603 "GETXATTR Changelog entry"
5206 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5207 skip "need MDS version at least 2.10.58"
5211 local f=$DIR/$tdir/$tfile
5212 local f2=$DIR2/$tdir/$tfile
5213 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5215 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5216 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5217 do_facet mds1 lctl set_param "$procname=20"
5221 # set changelog_mask to ALL
5222 changelog_chmask "ALL"
5224 touch $f || error "touch $f failed"
5225 local fid=$(path2fid $f)
5231 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5235 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5236 -gid "$RUNAS_GID" -mode "r--") ||
5237 error "No matching NOPEN entry"
5239 # Parse the changelog
5240 eval local -A changelog=$(changelog2array $entry)
5241 local nid="${changelog[nid]}"
5244 echo "Got NID '$nid'"
5245 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5246 error "nid '$nid' does not match any client NID:" \
5251 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5254 changelog_find -type NOPEN -target-fid $fid &&
5255 error "There should be no NOPEN entry"
5257 # Sleep for `changelog_deniednext` seconds
5262 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5265 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5266 -gid "$RUNAS_GID" -mode "r--") ||
5267 error "No matching NOPEN entry"
5269 # Parse the changelog
5270 eval local -A changelog=$(changelog2array $entry)
5271 local nid="${changelog[nid]}"
5274 echo "Got NID '$nid'"
5275 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5276 error "nid '$nid' does not match any client NID:" \
5279 run_test 604 "NOPEN Changelog entry"
5282 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5283 skip "need MDS version at least 2.10.58"
5287 local f=$DIR/$tdir/$tfile
5288 local f2=$DIR2/$tdir/$tfile
5291 # set changelog_mask to ALL
5292 changelog_chmask "ALL"
5294 touch $f || error "touch $f failed"
5295 local fid=$(path2fid $f)
5299 exec 3<> $f || error "open $f failed"
5303 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5307 exec 4<> $f || error "open $f failed"
5310 changelog_find -type OPEN -target-fid $fid &&
5311 error "There should be no OPEN entry"
5313 exec 4>&- || error "close $f failed"
5316 changelog_find -type CLOSE -target-fid $fid &&
5317 error "There should be no CLOSE entry"
5321 # access in rw, so different access mode should generate entries
5322 cat $f || error "cat $f failed"
5325 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5327 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5331 # same access as first one, should not generate new entries
5332 exec 4<> $f || error "open $f failed"
5335 changelog_find -type OPEN -target-fid $fid &&
5336 error "There should be no OPEN entry"
5338 exec 4>&- || error "close $f failed"
5341 changelog_find -type CLOSE -target-fid $fid &&
5342 error "There should be no CLOSE entry"
5346 # access by different user should generate new entries
5347 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5350 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5352 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5356 exec 3>&- || error "close $f failed"
5359 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5361 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5364 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5365 skip "need MDS version at least 2.10.58"
5367 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5368 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5369 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5370 skip_env "missing llog_reader"
5374 local f=$DIR/$tdir/$tfile
5377 # set changelog_mask to ALL
5378 changelog_chmask "ALL"
5380 chmod 777 $DIR/$tdir
5381 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5382 local fid=$(path2fid $f)
5383 rm $f || error "rm $f failed"
5385 local mntpt=$(facet_mntpt mds1)
5389 #remount mds1 as ldiskfs or zfs type
5390 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5391 stop mds1 || error "stop mds1 failed"
5392 mount_fstype mds1 || error "remount mds1 failed"
5394 for ((i = 0; i < 1; i++)); do
5395 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5396 local cat_file=$(do_facet mds1 $llog_reader \
5397 $mntpt/changelog_catalog | awk \
5398 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5399 [ -n "$cat_file" ] || error "no catalog file"
5401 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5402 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5403 [ -n "$entry" ] || error "no CREAT entry"
5406 local uidgid=$(echo $entry |
5407 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5408 [ -n "$uidgid" ] || error "uidgid is empty"
5409 echo "Got UID/GID $uidgid"
5410 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5411 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5412 local nid=$(echo $entry |
5413 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5414 [ -n "$nid" ] || error "nid is empty"
5416 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5417 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5419 run_test 606 "llog_reader groks changelog fields"
5422 check_and_cleanup_lustre