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 "libtool execute pgrep -x $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)}
172 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
173 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
174 echo "Copytool is suspended on $agents"
177 copytool_remove_backend() {
179 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
180 echo "Remove from backend: $fid = $be"
181 do_facet $SINGLEAGT rm -f $be
184 file_creation_failure() {
191 df $MOUNT $MOUNT2 >&2
192 error "Not enough space to create $file with $cmd"
195 error "cannot create $file with $cmd, status=$err"
200 # Creates a file using dd
206 local source=${5:-/dev/zero}
210 if [ -n "$conv" ]; then
214 # Create the directory in case it does not exist
215 mkdir -p "$(dirname "$file")"
216 # Delete the file in case it already exist
219 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
220 path2fid "$file" || error "cannot get FID of '$file'"
223 echo "cannot create file '$file'" >&2;
224 # Let the caller decide what to do on error
229 create_empty_file() {
230 create_file "${1/$DIR/$DIR2}" 1M 0 ||
231 file_creation_failure dd "${1/$DIR/$DIR2}" $?
234 create_small_file() {
235 local source_file=/dev/urandom
238 local conv=${2:-fsync}
240 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
241 file_creation_failure dd "${1/$DIR/$DIR2}" $?
244 create_small_sync_file() {
245 create_small_file "$1" sync
248 create_archive_file() {
249 local file="$(hsm_root)/$1"
251 local source=/dev/urandom
253 # Create the counterpart directory of the archive
254 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
255 error "cannot create archive directory '$(dirname "$file")'"
257 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
258 error "cannot create archive file '$file'"
262 local hsm_root="$(hsm_root)"
263 local file="$hsm_root/$2"
265 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
266 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
267 error "mkdir '$(dirname "$file")' failed"
268 do_facet $SINGLEAGT cp -p "$1" "$file" ||
269 error "cannot copy '$1' to '$file'"
274 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
281 mdts_set_param "" hsm_control "$cmd"
282 mdts_check_param hsm_control "$target" 10
287 mdts_set_param "" hsm.policy "+NRA"
288 CDT_POLICY_HAD_CHANGED=true
291 cdt_clear_no_retry() {
292 mdts_set_param "" hsm.policy "-NRA"
293 CDT_POLICY_HAD_CHANGED=true
296 cdt_set_non_blocking_restore() {
297 mdts_set_param "" hsm.policy "+NBR"
298 CDT_POLICY_HAD_CHANGED=true
301 cdt_clear_non_blocking_restore() {
302 mdts_set_param "" hsm.policy "-NBR"
303 CDT_POLICY_HAD_CHANGED=true
306 cdt_clear_mount_state() {
307 mdts_set_param "-P -d" hsm_control ""
311 set_test_state disabled disabled
315 set_test_state enabled enabled
319 set_test_state shutdown stopped
323 set_test_state purge enabled
329 cdt_set_sanity_policy
333 get_hsm_archive_id() {
336 st=$($LFS hsm_state $f)
337 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
339 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
343 check_hsm_flags_user() {
347 local st=$(get_hsm_flags $f user)
348 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
360 if [[ "$3" != 1 ]]; then
364 cp $1 $f || file_creation_failure cp $f $?
366 path2fid $f || error "cannot get fid on $f"
369 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
371 # Note that this might lead to surprising behaviours such as deleting an
372 # important file for the currently running test
373 delete_large_files() {
374 printf "Deleting large files...\n" >&2
375 find $MOUNT -size +10M -delete
376 wait_delete_completed
379 get_request_state() {
383 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
384 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
387 get_request_count() {
391 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
392 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
395 # Ensure the number of HSM request for a given FID is correct
396 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
397 assert_request_count() {
398 local request_count=$(get_request_count $1 $2)
399 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
401 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
408 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
409 [[ -n $fid ]] && cmd+=" | grep '$fid'"
410 cmd+=" | egrep 'WAITING|STARTED'"
412 wait_update_facet --verbose mds1 "$cmd" "" $timeout ||
413 error "requests did not complete"
416 wait_for_grace_delay() {
417 local val=$(get_hsm_param grace_delay)
421 wait_for_loop_period() {
422 local val=$(get_hsm_param loop_period)
429 # python2.6 in EL6 includes an internal json module
430 local json_parser='import json; import fileinput;'
431 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
432 json_parser+='json.loads([line for line in '
433 json_parser+='fileinput.input()][0]).items()])'
435 echo $raw_event | python -c "$json_parser"
438 get_agent_by_uuid_mdt() {
441 local mds=mds$(($mdtidx + 1))
442 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
446 check_agent_registered_by_mdt() {
449 local mds=mds$(($mdtidx + 1))
450 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
451 if [[ ! -z "$agent" ]]; then
452 echo "found agent $agent on $mds"
454 error "uuid $uuid not found in agent list on $mds"
458 check_agent_unregistered_by_mdt() {
461 local mds=mds$(($mdtidx + 1))
462 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
463 if [[ -z "$agent" ]]; then
464 echo "uuid not found in agent list on $mds"
466 error "uuid found in agent list on $mds: $agent"
470 check_agent_registered() {
473 for mdsno in $(seq 1 $MDSCOUNT); do
474 check_agent_registered_by_mdt $uuid $((mdsno - 1))
478 check_agent_unregistered() {
481 for mdsno in $(seq 1 $MDSCOUNT); do
482 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
487 local agent=${1:-$(facet_active_host $SINGLEAGT)}
489 # Lustre mount-point is mandatory and last parameter on
491 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
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 [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
639 [ $(lustre_version_code $SINGLEMDS) -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 [ $(lustre_version_code $SINGLEMDS) -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 # test needs a running copytool
1002 copy2archive /etc/hosts $tdir/$tfile
1004 local f=$DIR/$tdir/$tfile
1005 copytool import $tdir/$tfile $f
1006 local f2=$DIR2/$tdir/$tfile
1007 echo "Verifying released state: "
1008 check_hsm_flags $f2 "0x0000000d"
1010 local fid=$(path2fid $f2)
1011 $LFS hsm_restore $f2
1012 wait_request_state $fid RESTORE SUCCEED
1014 echo "Verifying file state: "
1015 check_hsm_flags $f2 "0x00000009"
1017 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1019 [[ $? -eq 0 ]] || error "Restored file differs"
1021 run_test 12a "Restore an imported file explicitly"
1024 # test needs a running copytool
1028 copy2archive /etc/hosts $tdir/$tfile
1030 local f=$DIR/$tdir/$tfile
1031 copytool import $tdir/$tfile $f
1032 echo "Verifying released state: "
1033 check_hsm_flags $f "0x0000000d"
1035 cat $f > /dev/null || error "File read failed"
1037 echo "Verifying file state after restore: "
1038 check_hsm_flags $f "0x00000009"
1040 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1042 [[ $? -eq 0 ]] || error "Restored file differs"
1044 run_test 12b "Restore an imported file implicitly"
1047 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1049 # test needs a running copytool
1052 local f=$DIR/$tdir/$tfile
1054 $LFS setstripe -c 2 "$f"
1055 local fid=$(create_file "$f" 1M 5)
1057 local FILE_CRC=$(md5sum $f)
1059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1060 wait_request_state $fid ARCHIVE SUCCEED
1061 $LFS hsm_release $f || error "release $f failed"
1063 echo "$FILE_CRC" | md5sum -c
1065 [[ $? -eq 0 ]] || error "Restored file differs"
1067 run_test 12c "Restore a file with stripe of 2"
1070 # test needs a running copytool
1075 local f=$DIR/$tdir/$tfile
1076 local fid=$(copy_file /etc/hosts $f)
1077 $LFS hsm_restore $f || error "restore of non archived file failed"
1078 local cnt=$(get_request_count $fid RESTORE)
1079 [[ "$cnt" == "0" ]] ||
1080 error "restore non archived must not make a request"
1081 $LFS hsm_archive $f ||
1082 error "archive request failed"
1083 wait_request_state $fid ARCHIVE SUCCEED
1084 $LFS hsm_restore $f ||
1085 error "restore of non released file failed"
1086 local cnt=$(get_request_count $fid RESTORE)
1087 [[ "$cnt" == "0" ]] ||
1088 error "restore a non dirty file must not make a request"
1090 run_test 12d "Restore of a non archived, non released file must work"\
1091 " without doing request"
1094 # test needs a running copytool
1098 local f=$DIR/$tdir/$tfile
1099 local fid=$(copy_file /etc/hosts $f)
1100 $LFS hsm_archive $f || error "archive request failed"
1101 wait_request_state $fid ARCHIVE SUCCEED
1104 cat /etc/hosts >> $f
1108 $LFS hsm_restore $f && error "restore a dirty file must fail"
1111 run_test 12e "Check forbidden restore"
1114 # test needs a running copytool
1118 local f=$DIR/$tdir/$tfile
1119 local fid=$(copy_file /etc/hosts $f)
1121 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1122 wait_request_state $fid ARCHIVE SUCCEED
1123 $LFS hsm_release $f || error "release of $f failed"
1125 wait_request_state $fid RESTORE SUCCEED
1127 echo -n "Verifying file state: "
1128 check_hsm_flags $f "0x00000009"
1130 diff -q /etc/hosts $f
1132 [[ $? -eq 0 ]] || error "Restored file differs"
1134 run_test 12f "Restore a released file explicitly"
1137 # test needs a running copytool
1141 local f=$DIR/$tdir/$tfile
1142 local fid=$(copy_file /etc/hosts $f)
1144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1145 wait_request_state $fid ARCHIVE SUCCEED
1146 $LFS hsm_release $f || error "release of $f failed"
1148 diff -q /etc/hosts $f
1151 # we check we had a restore done
1152 wait_request_state $fid RESTORE SUCCEED
1154 [[ $st -eq 0 ]] || error "Restored file differs"
1156 run_test 12g "Restore a released file implicitly"
1159 needclients 2 || return 0
1161 # test needs a running copytool
1165 local f=$DIR/$tdir/$tfile
1166 local fid=$(copy_file /etc/hosts $f)
1168 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1169 wait_request_state $fid ARCHIVE SUCCEED
1170 $LFS hsm_release $f || error "release of $f failed"
1172 do_node $CLIENT2 diff -q /etc/hosts $f
1175 # we check we had a restore done
1176 wait_request_state $fid RESTORE SUCCEED
1178 [[ $st -eq 0 ]] || error "Restored file differs"
1180 run_test 12h "Restore a released file implicitly from a second node"
1183 # test needs a running copytool
1187 local f=$DIR/$tdir/$tfile
1188 local fid=$(copy_file /etc/passwd $f)
1189 $LFS hsm_archive $f || error "archive of $f failed"
1190 wait_request_state $fid ARCHIVE SUCCEED
1192 $LFS hsm_release $f || error "release of $f failed"
1196 [[ $? -eq 0 ]] || error "Restored file differs"
1198 run_test 12m "Archive/release/implicit restore"
1201 # test needs a running copytool
1205 copy2archive /etc/hosts $tdir/$tfile
1207 local f=$DIR/$tdir/$tfile
1208 copytool import $tdir/$tfile $f
1210 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1211 error "Restored file differs"
1213 $LFS hsm_release $f || error "release of $f failed"
1215 run_test 12n "Import/implicit restore/release"
1218 # test needs a running copytool
1222 local f=$DIR/$tdir/$tfile
1223 local fid=$(copy_file /etc/hosts $f)
1225 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1226 wait_request_state $fid ARCHIVE SUCCEED
1227 $LFS hsm_release $f || error "release of $f failed"
1229 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1230 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1232 # set no retry action mode
1235 diff -q /etc/hosts $f
1238 # we check we had a restore failure
1239 wait_request_state $fid RESTORE FAILED
1241 [[ $st -eq 0 ]] && error "Restore must fail"
1243 # remove no retry action mode
1246 # check file is still released
1247 check_hsm_flags $f "0x0000000d"
1249 # retry w/o failure injection
1250 do_facet $SINGLEMDS lctl set_param fail_loc=0
1252 # to be sure previous RESTORE result is gone
1254 wait_for_grace_delay
1256 diff -q /etc/hosts $f
1259 # we check we had a restore done
1260 wait_request_state $fid RESTORE SUCCEED
1262 [[ $st -eq 0 ]] || error "Restored file differs"
1264 run_test 12o "Layout-swap failure during Restore leaves file released"
1267 # test needs a running copytool
1271 local f=$DIR/$tdir/$tfile
1272 local fid=$(copy_file /etc/hosts $f)
1274 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1275 wait_request_state $fid ARCHIVE SUCCEED
1276 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1277 $LFS hsm_release $f || error "cannot release $f"
1278 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1279 $LFS hsm_release $f || error "cannot release $f"
1280 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1282 run_test 12p "implicit restore of a file on copytool mount point"
1285 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1286 skip "need MDS version at least 2.7.58"
1288 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1289 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1290 error "cannot mount $MOUNT3 on $SINGLEAGT"
1292 # test needs a running copytool
1293 copytool setup -m "$MOUNT3"
1295 local f=$DIR/$tdir/$tfile
1296 local f2=$DIR2/$tdir/$tfile
1297 local fid=$(create_small_file $f)
1298 local orig_size=$(stat -c "%s" $f)
1300 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1301 wait_request_state $fid ARCHIVE SUCCEED
1303 $LFS hsm_release $f || error "could not release file"
1304 check_hsm_flags $f "0x0000000d"
1307 wait_copytools || error "copytool failed to stop"
1309 cat $f > /dev/null &
1311 # wait a bit to allow implicit restore request to be handled.
1312 # if not, next stat would also block on layout-lock.
1315 local size=$(stat -c "%s" $f2)
1316 [ $size -eq $orig_size ] ||
1317 error "$f2: wrong size after archive: $size != $orig_size"
1319 copytool setup -m "$MOUNT3"
1323 size=$(stat -c "%s" $f)
1324 [ $size -eq $orig_size ] ||
1325 error "$f: wrong size after restore: $size != $orig_size"
1327 size=$(stat -c "%s" $f2)
1328 [ $size -eq $orig_size ] ||
1329 error "$f2: wrong size after restore: $size != $orig_size"
1333 size=$(stat -c "%s" $f)
1335 error "$f: wrong size after overwrite: $size != 0"
1337 size=$(stat -c "%s" $f2)
1339 error "$f2: wrong size after overwrite: $size != 0"
1341 run_test 12q "file attributes are refreshed after restore"
1344 # test needs a running copytool
1348 local f=$DIR/$tdir/$tfile
1349 local fid=$(copy_file /etc/hosts $f)
1351 $LFS hsm_archive $f || error "archive of $f failed"
1352 wait_request_state $fid ARCHIVE SUCCEED
1353 $LFS hsm_release $f || error "release of $f failed"
1355 offset=$(lseek_test -d 7 $f)
1357 # we check we had a restore done
1358 wait_request_state $fid RESTORE SUCCEED
1359 [[ $offset == 7 ]] || error "offset $offset != 7"
1361 run_test 12r "lseek restores released file"
1365 for i in {1..10}; do
1366 local archive_dir="$(hsm_root)"/subdir/dir.$i
1368 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1369 for j in {1..10}; do
1370 local archive_file="$archive_dir"/file.$j
1372 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1378 copytool import "subdir" "$DIR/$tdir"
1380 # To check the import, the test uses diff with the -r flag
1381 # This is nice, but diff only checks files one by one, and triggering
1382 # an implicit restore for one file at a time will consume as many
1383 # seconds as there are files to compare. To speed this up, a restore
1384 # operation is triggered manually first.
1386 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1388 # Compare the imported data
1389 do_facet $SINGLEAGT \
1390 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1391 error "imported files differ from archived data"
1393 run_test 13 "Recursively import and restore a directory"
1396 # test needs a running copytool
1400 local f=$DIR/$tdir/$tfile
1401 local fid=$(create_small_file $f)
1402 local sum=$(md5sum $f | awk '{print $1}')
1403 $LFS hsm_archive $f || error "could not archive file"
1404 wait_request_state $fid ARCHIVE SUCCEED
1406 # create released file (simulate llapi_hsm_import call)
1407 local fid2=$(create_empty_file "$f")
1408 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1409 $LFS hsm_release $f || error "could not release file"
1411 # rebind the archive to the newly created file
1412 echo "rebind $fid to $fid2"
1414 copytool rebind $fid $fid2
1416 # restore file and compare md5sum
1417 local sum2=$(md5sum $f | awk '{print $1}')
1419 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1421 run_test 14 "Rebind archived file to a new fid"
1424 # test needs a running copytool
1428 local f=$DIR/$tdir/$tfile
1430 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1434 for i in $(seq 1 $count); do
1435 fids[$i]=$(create_small_file $f.$i)
1436 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1437 $LFS hsm_archive $f.$i || error "could not archive file"
1439 wait_all_done $(($count*60))
1441 stack_trap "rm -f $tmpfile" EXIT
1444 for i in $(seq 1 $count); do
1445 local fid2=$(create_empty_file "${f}.${i}")
1446 # add the rebind operation to the list
1447 echo ${fids[$i]} $fid2 >> $tmpfile
1449 # set it released (simulate llapi_hsm_import call)
1450 $LFS hsm_set --archived --exists $f.$i ||
1451 error "could not force hsm flags"
1452 $LFS hsm_release $f.$i || error "could not release file"
1454 nl=$(wc -l < $tmpfile)
1455 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1457 echo "rebind list of files"
1458 copytool rebind "$tmpfile"
1460 # restore files and compare md5sum
1461 for i in $(seq 1 $count); do
1462 local sum2=$(md5sum $f.$i | awk '{print $1}')
1463 [[ $sum2 == ${sums[$i]} ]] ||
1464 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1467 run_test 15 "Rebind a list of files"
1470 # test needs a running copytool
1474 # create a known size file so we can verify transfer speed
1477 dd if=/dev/zero of=$ref bs=1M count=20
1480 local f=$DIR/$tdir/$tfile
1481 local fid=$(copy_file $ref $f)
1483 local start=$(date +%s)
1485 wait_request_state $fid ARCHIVE SUCCEED
1486 local end=$(date +%s)
1487 # Add 1 to account for rounding errors between start and end (LU-8155)
1488 local duration=$((end - start + 1))
1490 [[ $duration -ge $((goal - 1)) ]] ||
1491 error "Transfer is too fast $duration < $goal"
1493 run_test 16 "Test CT bandwith control option"
1496 local f=$DIR/$tdir/$tfile
1497 create_empty_file "$f"
1499 # Could not release a non-archived file
1500 $LFS hsm_release $f && error "release should not succeed"
1502 # For following tests, we must test them with HS_ARCHIVED set
1503 $LFS hsm_set --exists --archived $f || error "could not add flag"
1505 # Could not release a file if no-release is set
1506 $LFS hsm_set --norelease $f || error "could not add flag"
1507 $LFS hsm_release $f && error "release should not succeed"
1508 $LFS hsm_clear --norelease $f || error "could not remove flag"
1510 # Could not release a file if lost
1511 $LFS hsm_set --lost $f || error "could not add flag"
1512 $LFS hsm_release $f && error "release should not succeed"
1513 $LFS hsm_clear --lost $f || error "could not remove flag"
1515 # Could not release a file if dirty
1516 $LFS hsm_set --dirty $f || error "could not add flag"
1517 $LFS hsm_release $f && error "release should not succeed"
1518 $LFS hsm_clear --dirty $f || error "could not remove flag"
1520 run_test 20 "Release is not permitted"
1523 # test needs a running copytool
1526 local f=$DIR/$tdir/test_release
1528 # Create a file and check its states
1529 local fid=$(create_small_file $f)
1530 check_hsm_flags $f "0x00000000"
1532 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1533 # used until file is flushed to disk
1534 if [ $(facet_fstype ost1) == "zfs" ]; then
1535 # this causes an OST_SYNC rpc to be sent
1536 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1537 # clear locks to reread file data
1538 cancel_lru_locks osc
1541 local orig_size=$(stat -c "%s" $f)
1542 local orig_blocks=$(stat -c "%b" $f)
1544 start_full_debug_logging
1546 $LFS hsm_archive $f || error "could not archive file"
1547 wait_request_state $fid ARCHIVE SUCCEED
1549 local blocks=$(stat -c "%b" $f)
1550 [ $blocks -eq $orig_blocks ] ||
1551 error "$f: wrong block number after archive: " \
1552 "$blocks != $orig_blocks"
1553 local size=$(stat -c "%s" $f)
1554 [ $size -eq $orig_size ] ||
1555 error "$f: wrong size after archive: $size != $orig_size"
1557 # Release and check states
1558 $LFS hsm_release $f || error "could not release file"
1559 check_hsm_flags $f "0x0000000d"
1561 blocks=$(stat -c "%b" $f)
1562 [ $blocks -gt 5 ] &&
1563 error "$f: too many blocks after release: $blocks > 5"
1564 size=$(stat -c "%s" $f)
1565 [ $size -ne $orig_size ] &&
1566 error "$f: wrong size after release: $size != $orig_size"
1568 # Check we can release an file without stripe info
1572 check_hsm_flags $f "0x00000000"
1573 $LFS hsm_archive $f || error "could not archive file"
1574 wait_request_state $fid ARCHIVE SUCCEED
1576 # Release and check states
1577 $LFS hsm_release $f || error "could not release file"
1578 check_hsm_flags $f "0x0000000d"
1580 # Release again a file that is already released is OK
1581 $LFS hsm_release $f || fail "second release should succeed"
1582 check_hsm_flags $f "0x0000000d"
1584 stop_full_debug_logging
1586 run_test 21 "Simple release tests"
1589 # test needs a running copytool
1592 local f=$DIR/$tdir/test_release
1593 local swap=$DIR/$tdir/test_swap
1595 # Create a file and check its states
1596 local fid=$(create_small_file $f)
1597 check_hsm_flags $f "0x00000000"
1599 $LFS hsm_archive $f || error "could not archive file"
1600 wait_request_state $fid ARCHIVE SUCCEED
1602 # Release and check states
1603 $LFS hsm_release $f || error "could not release file"
1604 check_hsm_flags $f "0x0000000d"
1606 create_small_file $swap
1607 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1611 run_test 22 "Could not swap a release file"
1614 # test needs a running copytool
1617 local f=$DIR/$tdir/test_mtime
1619 # Create a file and check its states
1620 local fid=$(create_small_file $f)
1621 check_hsm_flags $f "0x00000000"
1623 $LFS hsm_archive $f || error "could not archive file"
1624 wait_request_state $fid ARCHIVE SUCCEED
1626 # Set modification time in the past
1627 touch -m -a -d @978261179 $f
1629 # Release and check states
1630 $LFS hsm_release $f || error "could not release file"
1631 check_hsm_flags $f "0x0000000d"
1633 local MTIME=$(stat -c "%Y" $f)
1634 local ATIME=$(stat -c "%X" $f)
1635 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1636 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1638 run_test 23 "Release does not change a/mtime (utime)"
1641 local file=$DIR/$tdir/$tfile
1650 # test needs a running copytool
1653 fid=$(create_small_file $file)
1655 # Create a file and check its states
1656 check_hsm_flags $file "0x00000000"
1658 # Ensure atime is less than mtime and ctime.
1662 atime0=$(stat -c "%X" $file)
1663 mtime0=$(stat -c "%Y" $file)
1664 ctime0=$(stat -c "%Z" $file)
1666 [ $atime0 -lt $mtime0 ] ||
1667 error "atime $atime0 is not less than mtime $mtime0"
1669 [ $atime0 -lt $ctime0 ] ||
1670 error "atime $atime0 is not less than ctime $ctime0"
1672 # Archive should not change any timestamps.
1673 $LFS hsm_archive $file || error "cannot archive '$file'"
1674 wait_request_state $fid ARCHIVE SUCCEED
1676 atime1=$(stat -c "%X" $file)
1677 mtime1=$(stat -c "%Y" $file)
1678 ctime1=$(stat -c "%Z" $file)
1680 [ $atime0 -eq $atime1 ] ||
1681 error "archive changed atime from $atime0 to $atime1"
1683 [ $mtime0 -eq $mtime1 ] ||
1684 error "archive changed mtime from $mtime0 to $mtime1"
1686 [ $ctime0 -eq $ctime1 ] ||
1687 error "archive changed ctime from $ctime0 to $ctime1"
1689 # Release should not change any timestamps.
1690 $LFS hsm_release $file || error "cannot release '$file'"
1691 check_hsm_flags $file "0x0000000d"
1693 atime1=$(stat -c "%X" $file)
1694 mtime1=$(stat -c "%Y" $file)
1695 ctime1=$(stat -c "%Z" $file)
1697 [ $atime0 -eq $atime1 ] ||
1698 error "release changed atime from $atime0 to $atime1"
1700 [ $mtime0 -eq $mtime1 ] ||
1701 error "release changed mtime from $mtime0 to $mtime1"
1703 [ $ctime0 -eq $ctime1 ] ||
1704 error "release changed ctime from $ctime0 to $ctime1"
1706 # Restore should not change any timestamps.
1707 $LFS hsm_restore $file
1708 wait_request_state $fid RESTORE SUCCEED
1710 atime1=$(stat -c "%X" $file)
1711 mtime1=$(stat -c "%Y" $file)
1712 ctime1=$(stat -c "%Z" $file)
1714 [ $atime0 -eq $atime1 ] ||
1715 error "restore changed atime from $atime0 to $atime1"
1717 [ $mtime0 -eq $mtime1 ] ||
1718 error "restore changed mtime from $mtime0 to $mtime1"
1720 [ $ctime0 -eq $ctime1 ] ||
1721 error "restore changed ctime from $ctime0 to $ctime1"
1724 wait_copytools || error "Copytools failed to stop"
1726 # Once more, after unmount and mount.
1727 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1728 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1730 atime1=$(stat -c "%X" $file)
1731 mtime1=$(stat -c "%Y" $file)
1732 ctime1=$(stat -c "%Z" $file)
1734 [ $atime0 -eq $atime1 ] ||
1735 error "remount changed atime from $atime0 to $atime1"
1737 [ $mtime0 -eq $mtime1 ] ||
1738 error "remount changed mtime from $mtime0 to $mtime1"
1740 [ $ctime0 -eq $ctime1 ] ||
1741 error "remount changed ctime from $ctime0 to $ctime1"
1743 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1746 local file=$DIR/$tdir/$tfile
1752 # Test needs a running copytool.
1755 # Check that root can do HSM actions on a regular user's file.
1756 fid=$(create_small_file $file)
1757 sum0=$(md5sum $file)
1759 chown $RUNAS_ID:$RUNAS_GID $file ||
1760 error "cannot chown '$file' to '$RUNAS_ID'"
1762 chmod ugo-w $DIR/$tdir ||
1763 error "cannot chmod '$DIR/$tdir'"
1765 $LFS hsm_archive $file
1766 wait_request_state $fid ARCHIVE SUCCEED
1768 $LFS hsm_release $file
1769 check_hsm_flags $file "0x0000000d"
1771 $LFS hsm_restore $file
1772 wait_request_state $fid RESTORE SUCCEED
1774 # Check that ordinary user can get HSM state.
1775 $RUNAS $LFS hsm_state $file ||
1776 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1778 $LFS hsm_release $file
1779 check_hsm_flags $file "0x0000000d"
1781 # Check that ordinary user can accessed released file.
1782 sum1=$($RUNAS md5sum $file) ||
1783 error "user '$RUNAS_ID' cannot read '$file'"
1785 [ "$sum0" == "$sum1" ] ||
1786 error "md5sum mismatch for '$file'"
1788 run_test 24b "root can archive, release, and restore user files"
1791 local file=$DIR/$tdir/$tfile
1792 local action=archive
1797 # test needs a running copytool
1802 # Save the default masks and check that cleanup_24c will
1803 # restore the request masks correctly.
1804 user_save=$(get_hsm_param user_request_mask)
1805 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1806 group_save=$(get_hsm_param group_request_mask)
1807 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1808 other_save=$(get_hsm_param other_request_mask)
1809 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1811 [ "$user_save" == RESTORE ] ||
1812 error "user_request_mask is '$user_save' expected 'RESTORE'"
1813 [ "$group_save" == RESTORE ] ||
1814 error "group_request_mask is '$group_save' expected 'RESTORE'"
1815 [ "$other_save" == RESTORE ] ||
1816 error "other_request_mask is '$other_save' expected 'RESTORE'"
1819 create_small_file $file
1820 chown $RUNAS_ID:$GROUP $file ||
1821 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1823 $RUNAS $LFS hsm_$action $file &&
1824 error "$action by user should fail"
1826 set_hsm_param user_request_mask $action
1827 $RUNAS $LFS hsm_$action $file ||
1828 error "$action by user should succeed"
1831 create_small_file $file
1832 chown nobody:$RUNAS_GID $file ||
1833 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1835 $RUNAS $LFS hsm_$action $file &&
1836 error "$action by group should fail"
1838 set_hsm_param group_request_mask $action
1839 $RUNAS $LFS hsm_$action $file ||
1840 error "$action by group should succeed"
1843 create_small_file $file
1844 chown nobody:$GROUP $file ||
1845 error "cannot chown '$file' to 'nobody:$GROUP'"
1847 $RUNAS $LFS hsm_$action $file &&
1848 error "$action by other should fail"
1850 set_hsm_param other_request_mask $action
1851 $RUNAS $LFS hsm_$action $file ||
1852 error "$action by other should succeed"
1854 run_test 24c "check that user,group,other request masks work"
1857 local file1=$DIR/$tdir/$tfile
1858 local file2=$DIR2/$tdir/$tfile
1862 fid1=$(create_small_file $file1)
1865 $LFS getstripe $file1
1867 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1868 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1869 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1871 copytool setup -m "$MOUNT3"
1873 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1874 mount -o remount,ro $MOUNT2
1876 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1878 fid2=$(path2fid $file2)
1879 [ "$fid1" == "$fid2" ] ||
1880 error "FID mismatch '$fid1' != '$fid2'"
1882 $LFS hsm_archive $file2 &&
1883 error "archive should fail on read-only mount"
1884 check_hsm_flags $file1 "0x00000000"
1886 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1887 wait_request_state $fid1 ARCHIVE SUCCEED
1889 $LFS hsm_release $file1
1890 $LFS hsm_restore $file2
1891 wait_request_state $fid1 RESTORE SUCCEED
1893 $LFS hsm_release $file1 || error "cannot release '$file1'"
1894 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1896 $LFS hsm_release $file2 &&
1897 error "release should fail on read-only mount"
1901 run_test 24d "check that read-only mounts are respected"
1906 local f=$DIR/$tdir/$tfile
1909 fid=$(create_small_file $f) || error "cannot create $f"
1910 $LFS hsm_archive $f || error "cannot archive $f"
1911 wait_request_state $fid ARCHIVE SUCCEED
1912 $LFS hsm_release $f || error "cannot release $f"
1913 while ! $LFS hsm_state $f | grep released; do
1917 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1919 run_test 24e "tar succeeds on HSM released files" # LU-6213
1922 # test needs a running copytool
1925 mkdir -p $DIR/$tdir/d1
1926 local f=$DIR/$tdir/$tfile
1927 local fid=$(copy_file /etc/hosts $f)
1930 $LFS hsm_archive $f ||
1931 error "hsm_archive failed"
1932 wait_request_state $fid ARCHIVE SUCCEED
1933 $LFS hsm_release $f || error "cannot release $f"
1934 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1937 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1938 error "Can not recover the tar contents"
1940 echo "Sum0 = $sum0, sum1 = $sum1"
1941 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1943 run_test 24f "root can archive, release, and restore tar files"
1946 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1947 skip "need MDS version 2.11.56 or later"
1949 local file=$DIR/$tdir/$tfile
1952 echo "RUNAS = '$RUNAS'"
1957 chmod ugo+rwx $DIR/$tdir
1959 echo "Please listen carefully as our options have changed." | tee $file
1960 fid=$(path2fid $file)
1963 $LFS hsm_archive $file
1964 wait_request_state $fid ARCHIVE SUCCEED
1965 check_hsm_flags $file 0x00000009 # exists archived
1967 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
1968 check_hsm_flags $file 0x0000000b # exists dirty archived
1970 run_test 24g "write by non-owner still sets dirty" # LU-11369
1973 # test needs a running copytool
1977 copy2archive /etc/hosts $tdir/$tfile
1979 local f=$DIR/$tdir/$tfile
1981 copytool import $tdir/$tfile $f
1983 $LFS hsm_set --lost $f
1988 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1990 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1991 " (Operation not permitted)"
1994 # test needs a running copytool
1999 local f=$DIR/$tdir/$tfile
2000 local fid=$(copy_file /etc/passwd $f)
2002 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2003 wait_request_state $fid ARCHIVE SUCCEED
2006 $LFS hsm_set --lost $f
2010 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2012 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2013 " (Operation not permitted)"
2015 test_26A() { # was test_26
2016 # test needs a running copytool
2019 local f=$DIR/$tdir/$tfile
2020 local fid=$(create_empty_file "$f")
2022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2023 wait_request_state $fid ARCHIVE SUCCEED
2026 wait_request_state $fid REMOVE SUCCEED
2028 check_hsm_flags $f "0x00000000"
2030 run_test 26A "Remove the archive of a valid file"
2033 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2034 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2036 # test needs a running copytool
2040 local f=$DIR/$tdir/$tfile
2041 local fid=$(copy_file /etc/passwd $f)
2043 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2044 wait_request_state $fid ARCHIVE SUCCEED
2046 local f2=$DIR/$tdir/${tfile}_2
2047 local fid2=$(copy_file /etc/passwd $f2)
2049 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2050 wait_request_state $fid2 ARCHIVE SUCCEED
2052 local f3=$DIR/$tdir/${tfile}_3
2053 local fid3=$(copy_file /etc/passwd $f3)
2055 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2056 wait_request_state $fid3 ARCHIVE SUCCEED
2058 # set a long grace_delay vs short loop_period
2059 local orig_loop_period=$(get_hsm_param loop_period)
2060 local orig_grace_delay=$(get_hsm_param grace_delay)
2061 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2062 set_hsm_param loop_period 10
2063 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2064 set_hsm_param grace_delay 100
2068 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2069 set_hsm_param remove_archive_on_last_unlink 1
2071 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2076 wait_request_state $fid2 REMOVE SUCCEED
2078 assert_request_count $fid REMOVE 0 \
2079 "Unexpected archived data remove request for $f"
2080 assert_request_count $fid3 REMOVE 0 \
2081 "Unexpected archived data remove request for $f3"
2083 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2086 # test needs a running copytool
2090 local f=$DIR/$tdir/$tfile
2091 local fid=$(copy_file /etc/passwd $f)
2093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2094 wait_request_state $fid ARCHIVE SUCCEED
2096 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2097 set_hsm_param remove_archive_on_last_unlink 1
2100 cdt_check_state stopped
2104 wait_request_state $fid REMOVE WAITING
2108 # copytool must re-register
2110 wait_copytools || error "copytool failed to stop"
2113 wait_request_state $fid REMOVE SUCCEED
2115 run_test 26b "RAoLU policy when CDT off"
2118 # test needs a running copytool
2122 local f=$DIR/$tdir/$tfile
2123 local fid=$(copy_file /etc/passwd $f)
2125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2126 wait_request_state $fid ARCHIVE SUCCEED
2128 local f2=$DIR/$tdir/${tfile}_2
2129 local fid2=$(copy_file /etc/passwd $f2)
2131 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2132 wait_request_state $fid2 ARCHIVE SUCCEED
2134 # set a long grace_delay vs short loop_period
2135 local orig_loop_period=$(get_hsm_param loop_period)
2136 local orig_grace_delay=$(get_hsm_param grace_delay)
2137 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2138 set_hsm_param loop_period 10
2139 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2140 set_hsm_param grace_delay 100
2142 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2143 set_hsm_param remove_archive_on_last_unlink 1
2145 multiop_bg_pause $f O_c || error "open $f failed"
2151 wait_request_state $fid2 REMOVE SUCCEED
2152 assert_request_count $fid REMOVE 0 \
2153 "Unexpected archived data remove request for $f"
2155 kill -USR1 $pid || error "multiop early exit"
2156 # should reach autotest timeout if multiop fails to trap
2157 # signal, close file, and exit ...
2158 wait $pid || error "wait PID $PID failed"
2160 wait_request_state $fid REMOVE SUCCEED
2162 run_test 26c "RAoLU effective when file closed"
2165 # test needs a running copytool
2169 local f=$DIR/$tdir/$tfile
2170 local fid=$(create_small_file $f)
2172 $LFS hsm_archive $f || error "could not archive file"
2173 wait_request_state $fid ARCHIVE SUCCEED
2175 # set a long grace_delay vs short loop_period
2176 local orig_loop_period=$(get_hsm_param loop_period)
2177 local orig_grace_delay=$(get_hsm_param grace_delay)
2178 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2179 set_hsm_param loop_period 10
2180 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2181 set_hsm_param grace_delay 100
2183 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2184 set_hsm_param remove_archive_on_last_unlink 1
2186 multiop_bg_pause $f O_c || error "multiop failed"
2193 wait_request_state $fid REMOVE SUCCEED
2195 client_up || client_up || true
2197 kill -USR1 $MULTIPID
2198 wait $MULTIPID || error "multiop close failed"
2200 run_test 26d "RAoLU when Client eviction"
2203 # test needs a running copytool
2206 create_archive_file $tdir/$tfile
2207 local f=$DIR/$tdir/$tfile
2208 copytool import $tdir/$tfile $f
2209 local fid=$(path2fid $f)
2213 [[ $? != 0 ]] || error "Remove of a released file should fail"
2215 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2218 # test needs a running copytool
2221 local f=$DIR/$tdir/$tfile
2222 local fid=$(create_empty_file "$f")
2224 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2225 wait_request_state $fid ARCHIVE SUCCEED
2230 [[ $? != 0 ]] || error "Remove of a released file should fail"
2232 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2235 # test needs a running copytool
2238 local f=$DIR/$tdir/$tfile
2239 local fid=$(create_empty_file "$f")
2241 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2242 wait_request_state $fid ARCHIVE SUCCEED
2251 wait_request_state $fid REMOVE SUCCEED
2253 run_test 28 "Concurrent archive/file remove"
2256 # Tests --mntpath and --archive options
2259 copytool setup -m "$MOUNT" -a $archive_id
2261 # Bad archive number
2262 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2263 grep "Invalid argument" ||
2264 error "unexpected hsm_remove failure (1)"
2266 # mntpath is present but file is given
2267 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2268 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2269 error "unexpected hsm_remove failure (2)"
2271 run_test 29a "Tests --mntpath and --archive options"
2274 # test needs a running copytool
2277 local f=$DIR/$tdir/$tfile
2278 local fid=$(create_small_file $f)
2280 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2281 wait_request_state $fid ARCHIVE SUCCEED
2285 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2286 wait_request_state $fid REMOVE SUCCEED
2288 run_test 29b "Archive/delete/remove by FID from the archive."
2291 # test needs a running copytool
2294 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2295 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2296 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2298 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2299 wait_request_state $fid1 ARCHIVE SUCCEED
2300 wait_request_state $fid2 ARCHIVE SUCCEED
2301 wait_request_state $fid3 ARCHIVE SUCCEED
2303 rm -f $DIR/$tdir/$tfile-[1-3]
2305 echo $fid1 > $DIR/$tdir/list
2306 echo $fid2 >> $DIR/$tdir/list
2307 echo $fid3 >> $DIR/$tdir/list
2309 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2310 --filelist $DIR/$tdir/list
2311 wait_request_state $fid1 REMOVE SUCCEED
2312 wait_request_state $fid2 REMOVE SUCCEED
2313 wait_request_state $fid3 REMOVE SUCCEED
2315 run_test 29c "Archive/delete/remove by FID, using a file list."
2318 # test needs more than one CT
2319 needclients 3 || return 0
2325 # start all of the copytools
2326 for n in $(seq $AGTCOUNT); do
2327 copytool setup -f agt$n -a $n
2331 file=$DIR/$tdir/$tfile
2332 fid=$(create_small_file $file)
2334 $LFS hsm_archive $file
2335 wait_request_state $fid ARCHIVE SUCCEED
2336 check_hsm_flags $file "0x00000009"
2340 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2341 error "cannot hsm_remove '$fid'"
2343 # give time for CDT to handle remove request and create broadcasted
2346 # remove request has been broadcasted ?
2347 local cnt=$(get_request_count $fid REMOVE)
2348 # broadcasted requests + original
2349 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2350 error "remove not broadcasted to all CTs"
2352 # give time for CDT and CTs to handle broadcasted
2353 wait_for_loop_period
2355 # each agent serves one different archive_id, so broadcasted
2356 # hsm_remove request should only succeed once and fail at all others
2360 for n in $(seq $AGTCOUNT); do
2361 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2362 $HSM_PARAM.actions | awk \
2363 '/'$fid'.*action=REMOVE archive#='$n'/ \
2364 {print \\\$13}' | cut -f2 -d=")
2365 if [[ "$res" == "SUCCEED" ]]; then
2367 elif [[ "$res" == "FAILED" ]]; then
2372 [[ $scnt -eq 1 ]] ||
2373 error "one and only CT should have removed successfully"
2375 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2376 error "all but one CT should have failed to remove"
2378 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2379 "request to be sent once for each registered archive_id"
2382 # restore at exec cannot work on agent node (because of Linux kernel
2383 # protection of executables)
2384 needclients 2 || return 0
2386 # test needs a running copytool
2390 copy2archive /bin/true $tdir/$tfile
2392 local f=$DIR/$tdir/true
2393 copytool import $tdir/$tfile $f
2395 local fid=$(path2fid $f)
2397 stack_trap "cdt_clear_no_retry" EXIT
2398 # set no retry action mode
2405 [[ $st == 0 ]] || error "Failed to exec a released file"
2407 run_test 30a "Restore at exec (import case)"
2410 # restore at exec cannot work on agent node (because of Linux kernel
2411 # protection of executables)
2412 needclients 2 || return 0
2414 # test needs a running copytool
2418 local f=$DIR/$tdir/true
2419 local fid=$(copy_file /bin/true $f)
2421 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2422 wait_request_state $fid ARCHIVE SUCCEED
2426 stack_trap cdt_clear_no_retry EXIT
2427 # set no retry action mode
2435 [[ $st == 0 ]] || error "Failed to exec a released file"
2437 run_test 30b "Restore at exec (release case)"
2440 needclients 2 || return 0
2442 # test needs a running copytool
2446 local f=$DIR/$tdir/SLEEP
2447 local slp_sum1=$(md5sum /bin/sleep)
2448 local fid=$(copy_file /bin/sleep $f)
2450 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2451 wait_request_state $fid ARCHIVE SUCCEED
2453 check_hsm_flags $f "0x0000000d"
2455 stack_trap cdt_clear_no_retry EXIT
2456 # set no retry action mode
2459 do_node $CLIENT2 "$f 10" &
2463 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2465 [[ $? == 0 ]] || error "Execution failed during run"
2467 if [[ $? != 0 ]]; then
2468 local slp_sum2=$(md5sum /bin/sleep)
2469 # in case sleep file is modified during the test
2470 [[ $slp_sum1 == $slp_sum2 ]] &&
2471 error "Binary overwritten during exec"
2474 check_hsm_flags $f "0x00000009"
2476 run_test 30c "Update during exec of released file must fail"
2478 restore_and_check_size() {
2481 local s=$(stat -c "%s" $f)
2483 local st=$(get_hsm_flags $f)
2487 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2489 n=$(stat -c "%s" $f)
2490 # we echo in both cases to show stat is not hang
2491 if [[ $n != $s ]]; then
2492 echo "size seen is $n != $s"
2495 echo "size seen is right: $n == $s"
2499 st=$(get_hsm_flags $f)
2501 if [[ "$st" = "0x00000009" ]]; then
2504 echo " restore is too long"
2505 wait_request_state $fid RESTORE SUCCEED
2511 # test needs a running copytool
2514 create_archive_file $tdir/$tfile
2515 local f=$DIR/$tdir/$tfile
2516 copytool import $tdir/$tfile $f
2517 local fid=$($LFS path2fid $f)
2520 restore_and_check_size $f $fid
2523 [[ $err -eq 0 ]] || error "File size changed during restore"
2525 run_test 31a "Import a large file and check size during restore"
2529 # test needs a running copytool
2532 local f=$DIR/$tdir/$tfile
2533 local fid=$(create_file "$f" 1MB 39)
2535 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2536 wait_request_state $fid ARCHIVE SUCCEED
2539 restore_and_check_size $f $fid
2542 [[ $err -eq 0 ]] || error "File size changed during restore"
2544 run_test 31b "Restore a large unaligned file and check size during restore"
2547 # test needs a running copytool
2550 local f=$DIR/$tdir/$tfile
2551 local fid=$(create_file "$f" 1M 39)
2553 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2554 wait_request_state $fid ARCHIVE SUCCEED
2557 restore_and_check_size $f $fid
2560 [[ $err -eq 0 ]] || error "File size changed during restore"
2562 run_test 31c "Restore a large aligned file and check size during restore"
2565 local f=$DIR/$tdir/$tfile
2566 local fid=$(create_empty_file "$f")
2570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2571 wait_request_state $fid ARCHIVE SUCCEED
2574 # Prevent restore from completing
2578 md5sum $f >/dev/null &
2581 wait_request_state $fid RESTORE STARTED
2586 # Check restore trigger process was killed
2588 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2590 run_test 33 "Kill a restore waiting process"
2593 # test needs a running copytool
2596 local f=$DIR/$tdir/$tfile
2597 local fid=$(create_empty_file "$f")
2599 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2600 wait_request_state $fid ARCHIVE SUCCEED
2603 # Prevent restore from completing
2606 md5sum $f >/dev/null &
2609 wait_request_state $fid RESTORE STARTED
2611 # rm must not block during restore
2612 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2615 wait_request_state $fid RESTORE SUCCEED
2617 # Check md5sum pgm finished
2618 kill -0 $pid && error "Restore initiatior still running"
2619 wait $pid || error "Restore initiator failed with $?"
2621 # Check the file was actually deleted
2622 [ ! -f "$f" ] || error "$f was not deleted"
2624 run_test 34 "Remove file during restore"
2627 # test needs a running copytool
2630 local f=$DIR/$tdir/$tfile
2631 local f1=$DIR/$tdir/$tfile-1
2632 local fid=$(create_empty_file "$f")
2633 local fid1=$(copy_file /etc/passwd $f1)
2635 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2636 wait_request_state $fid ARCHIVE SUCCEED
2639 # Prevent restore from completing
2642 md5sum $f >/dev/null &
2645 wait_request_state $fid RESTORE STARTED
2647 # mv must not block during restore
2648 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2651 wait_request_state $fid RESTORE SUCCEED
2653 # Check md5sum pgm finished
2654 kill -0 $pid && error "Restore initiatior still running"
2655 wait $pid || error "Restore initiator failed with $?"
2657 local fid2=$(path2fid $f)
2658 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2660 run_test 35 "Overwrite file during restore"
2663 # test needs a running copytool
2666 local f=$DIR/$tdir/$tfile
2667 local fid=$(create_empty_file "$f")
2669 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2670 wait_request_state $fid ARCHIVE SUCCEED
2673 # Prevent restore from completing
2676 md5sum $f >/dev/null &
2679 wait_request_state $fid RESTORE STARTED
2681 # mv must not block during restore
2682 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2683 error "mv '$f' '$f.new' failed with rc=$?"
2686 wait_request_state $fid RESTORE SUCCEED
2688 # Check md5sum pgm finished
2689 kill -0 $pid && error "Restore initiator is still running"
2690 wait $pid || error "Restore initiator failed with $?"
2692 run_test 36 "Move file during restore"
2695 # LU-5683: check that an archived dirty file can be rearchived.
2698 local f=$DIR/$tdir/$tfile
2701 fid=$(create_small_file $f) || error "cannot create small file"
2703 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2704 wait_request_state $fid ARCHIVE SUCCEED
2705 $LFS hsm_release $f || error "cannot release $f"
2707 # Allow previous archive request to expire from the actions log.
2708 wait_for_grace_delay
2711 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2714 wait_request_state $fid ARCHIVE SUCCEED
2716 run_test 37 "re-archive a dirty file"
2723 for n in $(seq 1 $count); do
2724 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2726 echo "$count archive requests submitted"
2730 local stream_count=4
2731 local file_count=100
2733 local f=$DIR/$tdir/$tfile
2737 local max_requests=$(get_hsm_param max_requests)
2739 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2740 # Increase the number of HSM request that can be performed in
2741 # parallel. With the coordinator running once per second, this
2742 # also limits the number of requests per seconds that can be
2743 # performed, so we pick a decent number. But we also need to keep
2744 # that number low because the copytool has no rate limit and will
2745 # fail some requests if if gets too many at once.
2746 set_hsm_param max_requests 300
2748 for i in $(seq 1 $file_count); do
2749 for p in $(seq 1 $stream_count); do
2750 fid=$(copy_file /etc/hosts $f.$p.$i)
2756 # to be sure wait_all_done will not be mislead by previous tests
2758 wait_for_grace_delay
2760 # start archive streams in background (archive files in parallel)
2761 for p in $(seq 1 $stream_count); do
2762 multi_archive $f.$p $file_count &
2765 echo -n "Wait for all requests being enqueued..."
2770 run_test 40 "Parallel archive requests"
2773 # test needs a running copytool
2777 local f=$DIR/$tdir/$tfile
2778 local fid=$(create_small_file $f)
2780 $LFS hsm_archive $f || error "could not archive file"
2781 wait_request_state $fid ARCHIVE SUCCEED
2782 check_hsm_flags $f "0x00000009"
2784 multiop_bg_pause $f O_c || error "multiop failed"
2788 client_up || client_up || true
2790 kill -USR1 $MULTIPID
2791 wait $MULTIPID || error "multiop close failed"
2793 check_hsm_flags $f "0x0000000b"
2795 run_test 52 "Opened for write file on an evicted client should be set dirty"
2798 # test needs a running copytool
2802 local f=$DIR/$tdir/$tfile
2803 local fid=$(create_small_file $f)
2805 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2806 error "could not archive file"
2807 wait_request_state $fid ARCHIVE SUCCEED
2808 check_hsm_flags $f "0x00000009"
2810 multiop_bg_pause $f o_c || error "multiop failed"
2814 client_up || client_up || true
2816 kill -USR1 $MULTIPID
2817 wait $MULTIPID || error "multiop close failed"
2819 check_hsm_flags $f "0x00000009"
2821 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2824 local f=$DIR/$tdir/$tfile
2825 local fid=$(create_file "$f" 1MB 39)
2829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2830 error "could not archive file"
2831 wait_request_state $fid ARCHIVE STARTED
2833 check_hsm_flags $f "0x00000001"
2835 stack_trap "cdt_clear_no_retry" EXIT
2836 # Avoid coordinator resending this request as soon it has failed.
2841 wait_request_state $fid ARCHIVE FAILED
2843 check_hsm_flags $f "0x00000003"
2845 run_test 54 "Write during an archive cancels it"
2848 local f=$DIR/$tdir/$tfile
2849 local fid=$(create_file "$f" 1MB 39)
2853 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2854 error "could not archive file"
2855 wait_request_state $fid ARCHIVE STARTED
2857 check_hsm_flags $f "0x00000001"
2859 stack_trap "cdt_clear_no_retry" EXIT
2860 # Avoid coordinator resending this request as soon it has failed.
2863 $TRUNCATE $f 1024 || error "truncate failed"
2865 wait_request_state $fid ARCHIVE FAILED
2867 check_hsm_flags $f "0x00000003"
2869 run_test 55 "Truncate during an archive cancels it"
2872 local f=$DIR/$tdir/$tfile
2873 local fid=$(create_file "$f" 1MB 39)
2877 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2878 error "could not archive file"
2879 wait_request_state $fid ARCHIVE STARTED
2881 check_hsm_flags $f "0x00000001"
2883 # Change metadata and sync to be sure we are not changing only
2888 wait_request_state $fid ARCHIVE SUCCEED
2890 check_hsm_flags $f "0x00000009"
2892 run_test 56 "Setattr during an archive is ok"
2895 # Need one client for I/O, one for request
2896 needclients 2 || return 0
2898 # test needs a running copytool
2902 local f=$DIR/$tdir/test_archive_remote
2903 # Create a file on a remote node
2904 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2905 "count=2 conv=fsync"
2908 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2909 error "hsm_archive failed"
2910 local fid=$(path2fid $f)
2911 wait_request_state $fid ARCHIVE SUCCEED
2913 # Release and implicit restore it
2914 do_node $CLIENT2 "$LFS hsm_release $f" ||
2915 error "hsm_release failed"
2916 do_node $CLIENT2 "md5sum $f" ||
2917 error "hsm_restore failed"
2919 wait_request_state $fid RESTORE SUCCEED
2921 run_test 57 "Archive a file with dirty cache on another node"
2923 truncate_released_file() {
2927 local sz=$(stat -c %s $src_file)
2928 local f=$DIR/$tdir/$tfile
2929 local fid=$(copy_file $1 $f)
2933 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2934 error "could not archive file"
2935 wait_request_state $fid ARCHIVE SUCCEED
2937 $LFS hsm_release $f || error "could not release file"
2939 $TRUNCATE $f $trunc_to || error "truncate failed"
2942 local sz1=$(stat -c %s $f)
2943 [[ $sz1 == $trunc_to ]] ||
2944 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2947 check_hsm_flags $f "0x0000000b"
2949 local state=$(get_request_state $fid RESTORE)
2950 [[ "$state" == "SUCCEED" ]] ||
2951 error "truncate $sz does not trig restore, state = $state"
2953 $TRUNCATE $ref $trunc_to
2954 cmp $ref $f || error "file data wrong after truncate"
2960 # test needs a running copytool
2965 local sz=$(stat -c %s /etc/passwd)
2967 echo "truncate up from $sz to $((sz*2))"
2968 truncate_released_file /etc/passwd $((sz*2))
2970 echo "truncate down from $sz to $((sz/2))"
2971 truncate_released_file /etc/passwd $((sz/2))
2973 echo "truncate to 0"
2974 truncate_released_file /etc/passwd 0
2976 run_test 58 "Truncate a released file will trigger restore"
2980 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
2981 skip "Need MDS version at least 2.7.63"
2984 $MCREATE $DIR/$tfile || error "mcreate failed"
2985 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
2986 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
2987 fid=$(path2fid $DIR/$tfile)
2988 wait_request_state $fid ARCHIVE SUCCEED
2989 $LFS hsm_release $DIR/$tfile || error "release failed"
2991 run_test 59 "Release stripeless file with non-zero size"
2994 # This test validates the fix for LU-4512. Ensure that the -u
2995 # option changes the progress reporting interval from the
2996 # default (30 seconds) to the user-specified interval.
2997 local f=$DIR/$tdir/$tfile
2998 local fid=$(create_file "$f" 1M 10)
3001 local progress_timeout=$((interval * 4))
3002 copytool setup -b 1 --update-interval $interval
3005 local mdt=${MDT_PREFIX}${mdtidx}
3006 local mds=mds$((mdtidx + 1))
3008 # Wait for copytool to register
3009 wait_update_facet $mds \
3010 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3011 uuid 100 || error "coyptool failed to register with $mdt"
3013 local start_at=$(date +%s)
3014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3015 error "could not archive file"
3017 local agent=$(facet_active_host $SINGLEAGT)
3018 local logfile=$(copytool_logfile $SINGLEAGT)
3020 wait_update $agent \
3021 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3022 error "copytool failed to start"
3024 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3025 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3031 echo -n "Expecting a progress update within $progress_timeout seconds... "
3033 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3034 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3035 echo "$RESULT bytes copied in $WAIT seconds."
3037 elif [ $WAIT -ge $progress_timeout ]; then
3038 error "Timed out waiting for progress update!"
3041 WAIT=$((WAIT + sleep))
3045 local finish_at=$(date +%s)
3046 local elapsed=$((finish_at - start_at))
3048 # Ensure that the progress update occurred within the expected window.
3049 if [ $elapsed -lt $((interval - 1)) ]; then
3050 error "Expected progress update after at least $interval seconds"
3053 echo "Wait for on going archive hsm action to complete"
3054 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3055 echo "File archiving not completed even after 10 secs"
3057 run_test 60 "Changing progress update interval from default"
3060 # test needs a running copytool
3064 local f=$DIR/$tdir/$tfile
3065 local fid=$(copy_file /etc/passwd $f)
3067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3070 wait_request_state $fid ARCHIVE FAILED
3072 run_test 61 "Waiting archive of a removed file should fail"
3075 # test needs a new running copytool
3076 stack_trap copytool_monitor_cleanup EXIT
3077 copytool_monitor_setup
3078 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3080 # Wait for the copytool to register.
3081 wait_update --verbose $(facet_active_host mds1) \
3082 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3084 error "copytool failed to register with MDT0000"
3087 wait_copytools || error "Copytools failed to stop"
3089 local REGISTER_EVENT
3090 local UNREGISTER_EVENT
3091 while read event; do
3092 local parsed=$(parse_json_event "$event")
3093 if [ -z "$parsed" ]; then
3094 error "Copytool sent malformed event: $event"
3098 if [ $event_type == "REGISTER" ]; then
3099 REGISTER_EVENT=$event
3100 elif [ $event_type == "UNREGISTER" ]; then
3101 UNREGISTER_EVENT=$event
3103 done < <(echo $"$(get_copytool_event_log)")
3105 if [ -z "$REGISTER_EVENT" ]; then
3106 error "Copytool failed to send register event to FIFO"
3109 if [ -z "$UNREGISTER_EVENT" ]; then
3110 error "Copytool failed to send unregister event to FIFO"
3113 echo "Register/Unregister events look OK."
3115 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3118 # Bump progress interval for livelier events.
3121 # test needs a new running copytool
3122 stack_trap copytool_monitor_cleanup EXIT
3123 copytool_monitor_setup
3124 copytool setup --update-interval $interval --event-fifo \
3125 "$HSMTOOL_MONITOR_DIR/fifo"
3127 stack_trap "cdt_clear_no_retry" EXIT
3128 # Just start and stop the copytool to generate events.
3131 local f=$DIR/$tdir/$tfile
3132 local fid=$(create_small_file "$f")
3134 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3135 error "could not archive file"
3136 wait_request_state $fid ARCHIVE SUCCEED
3138 local expected_fields="event_time data_fid source_fid"
3139 expected_fields+=" total_bytes current_bytes"
3142 [ARCHIVE_START]=false
3143 [ARCHIVE_FINISH]=false
3144 [ARCHIVE_RUNNING]=false
3146 while read event; do
3147 # Make sure we're not getting anything from previous events.
3148 for field in $expected_fields; do
3152 local parsed=$(parse_json_event "$event")
3153 if [ -z "$parsed" ]; then
3154 error "Copytool sent malformed event: $event"
3158 events["$event_type"]=true
3160 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3162 # Do some simple checking of the progress update events.
3163 for expected_field in $expected_fields; do
3164 if [ -z ${!expected_field+x} ]; then
3165 error "Missing $expected_field field in event"
3169 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3171 # These should be identical throughout an archive operation
3172 [ $source_fid == $data_fid ] ||
3173 error "Expected source_fid to equal data_fid"
3174 done < <(echo $"$(get_copytool_event_log)")
3176 # Check we received every type of events we were expecting
3177 for event in "${!events[@]}"; do
3178 ${events["$event"]} ||
3179 error "Copytool failed to send '$event' event to FIFO"
3182 echo "Archive events look OK."
3184 run_test 71 "Copytool logs JSON archive events to FIFO"
3187 # Bump progress interval for livelier events.
3190 # test needs a new running copytool
3191 stack_trap copytool_monitor_cleanup EXIT
3192 copytool_monitor_setup
3193 copytool setup --update-interval $interval --event-fifo \
3194 "$HSMTOOL_MONITOR_DIR/fifo"
3195 local test_file=$HSMTOOL_MONITOR_DIR/file
3197 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3199 do_facet $SINGLEAGT "$cmd" ||
3200 error "cannot create $test_file on $SINGLEAGT"
3201 copy2archive $test_file $tdir/$tfile
3204 local f=$DIR/$tdir/$tfile
3205 copytool import $tdir/$tfile $f
3206 f=$DIR2/$tdir/$tfile
3207 echo "Verifying released state: "
3208 check_hsm_flags $f "0x0000000d"
3210 local fid=$(path2fid $f)
3212 wait_request_state $fid RESTORE SUCCEED
3214 local expected_fields="event_time data_fid source_fid"
3215 expected_fields+=" total_bytes current_bytes"
3219 while read event; do
3220 # Make sure we're not getting anything from previous events.
3221 for field in $expected_fields; do
3225 local parsed=$(parse_json_event "$event")
3226 if [ -z "$parsed" ]; then
3227 error "Copytool sent malformed event: $event"
3231 if [ $event_type == "RESTORE_START" ]; then
3233 if [ $source_fid != $data_fid ]; then
3234 error "source_fid should == data_fid at start"
3237 elif [ $event_type == "RESTORE_FINISH" ]; then
3239 if [ $source_fid != $data_fid ]; then
3240 error "source_fid should == data_fid at finish"
3243 elif [ $event_type != "RESTORE_RUNNING" ]; then
3247 # Do some simple checking of the progress update events.
3248 for expected_field in $expected_fields; do
3249 if [ -z ${!expected_field+x} ]; then
3250 error "Missing $expected_field field in event"
3254 if [ $total_bytes -eq 0 ]; then
3255 error "Expected total_bytes to be > 0"
3258 # When a restore starts out, the data fid is the same as the
3259 # source fid. After the restore has gotten going, we learn
3260 # the new data fid. Once the restore has finished, the source
3261 # fid is set to the new data fid.
3263 # We test this because some monitoring software may depend on
3264 # this behavior. If it changes, then the consumers of these
3265 # events may need to be modified.
3266 if [ $source_fid == $data_fid ]; then
3267 error "source_fid should != data_fid during restore"
3269 done < <(echo $"$(get_copytool_event_log)")
3271 if [ -z "$START_EVENT" ]; then
3272 error "Copytool failed to send restore start event to FIFO"
3275 if [ -z "$FINISH_EVENT" ]; then
3276 error "Copytool failed to send restore finish event to FIFO"
3279 echo "Restore events look OK."
3281 run_test 72 "Copytool logs JSON restore events to FIFO"
3284 file_count=51 # Max number of files constrained by LNET message size
3285 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3286 local f=$DIR/$tdir/$tfile
3287 local FILELIST=/tmp/filelist.txt
3291 for i in $(seq 1 $file_count); do
3292 fid=$(copy_file /etc/hosts $f.$i)
3293 echo $f.$i >> $FILELIST
3297 # to be sure wait_all_done will not be mislead by previous tests
3299 wait_for_grace_delay
3300 $LFS hsm_archive --filelist $FILELIST ||
3301 error "cannot archive a file list"
3303 $LFS hsm_release --filelist $FILELIST ||
3304 error "cannot release a file list"
3305 $LFS hsm_restore --filelist $FILELIST ||
3306 error "cannot restore a file list"
3309 run_test 90 "Archive/restore a file list"
3311 double_verify_reset_hsm_param() {
3313 echo "Testing $HSM_PARAM.$p"
3314 local val=$(get_hsm_param $p)
3316 local val2=$(($val * 2))
3317 set_hsm_param $p $val2
3318 val=$(get_hsm_param $p)
3319 [[ $val == $val2 ]] ||
3320 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3321 echo "Set $p to 0 must failed"
3325 set_hsm_param $p $save
3327 if [[ $rc == 0 ]]; then
3328 error "we must not be able to set $HSM_PARAM.$p to 0"
3333 double_verify_reset_hsm_param loop_period
3334 double_verify_reset_hsm_param grace_delay
3335 double_verify_reset_hsm_param active_request_timeout
3336 double_verify_reset_hsm_param max_requests
3337 double_verify_reset_hsm_param default_archive_id
3339 run_test 100 "Set coordinator /proc tunables"
3346 run_test 102 "Verify coordinator control"
3349 # test needs a running copytool
3356 for i in $(seq 1 20); do
3357 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3363 echo "Current requests"
3364 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3365 $HSM_PARAM.actions |\
3366 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3368 [[ -z "$res" ]] || error "Some request have not been canceled"
3370 run_test 103 "Purge all requests"
3375 local f=$DIR/$tdir/$tfile
3376 local fid=$(create_empty_file "$f")
3378 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3379 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3380 $HSM_PARAM.actions |\
3381 grep $fid | cut -f16 -d=")
3383 [[ "$data1" == "$DATAHEX" ]] ||
3384 error "Data field in records is ($data1) and not ($DATAHEX)"
3388 run_test 104 "Copy tool data field"
3391 local max_requests=$(get_hsm_param max_requests)
3395 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3396 set_hsm_param max_requests 300
3399 for i in $(seq -w 1 10); do
3400 cp /etc/passwd $DIR/$tdir/$i
3401 $LFS hsm_archive $DIR/$tdir/$i
3403 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3404 $HSM_PARAM.actions |\
3405 grep WAITING | wc -l")
3409 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3410 $HSM_PARAM.actions |\
3411 grep WAITING | wc -l")
3414 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3415 error "Requests count after shutdown $reqcnt2 != "\
3416 "before shutdown $reqcnt1"
3418 run_test 105 "Restart of coordinator"
3421 # test needs a running copytool
3424 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3426 check_agent_registered $uuid
3428 search_copytools || error "No copytool found"
3431 wait_copytools || error "Copytool failed to stop"
3433 check_agent_unregistered $uuid
3436 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3437 check_agent_registered $uuid
3439 run_test 106 "Copytool register/unregister"
3442 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3444 # test needs a running copytool
3446 # create and archive file
3448 local f1=$DIR/$tdir/$tfile
3449 local fid=$(copy_file /etc/passwd $f1)
3450 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3451 wait_request_state $fid ARCHIVE SUCCEED
3452 # shutdown and restart MDS
3454 # check the copytool still gets messages from MDT
3455 local f2=$DIR/$tdir/2
3456 local fid=$(copy_file /etc/passwd $f2)
3457 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3458 # main check of this sanity: this request MUST succeed
3459 wait_request_state $fid ARCHIVE SUCCEED
3461 run_test 107 "Copytool re-register after MDS restart"
3463 policy_set_and_test()
3467 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3468 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3469 [[ "$policy" == "$target" ]] ||
3470 error "Wrong policy after '$change': '$policy' != '$target'"
3474 # to force default policy setting if error
3475 CDT_POLICY_HAD_CHANGED=true
3477 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3478 local default="NonBlockingRestore [NoRetryAction]"
3479 [[ "$policy" == "$default" ]] ||
3480 error "default policy has changed,"\
3481 " '$policy' != '$default' update the test"
3482 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3483 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3484 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3485 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3486 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3487 # useless bacause we know but safer for futur changes to use real value
3488 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3489 echo "Next set_param must failed"
3490 policy_set_and_test "wrong" "$policy"
3493 echo "Back to default policy"
3494 cdt_set_sanity_policy
3496 run_test 109 "Policy display/change"
3499 # test needs a running copytool
3504 copy2archive /etc/passwd $tdir/$tfile
3506 local f=$DIR/$tdir/$tfile
3507 copytool import $tdir/$tfile $f
3508 local fid=$(path2fid $f)
3510 cdt_set_non_blocking_restore
3515 wait_request_state $fid RESTORE SUCCEED
3516 cdt_clear_non_blocking_restore
3520 error "md5sum returns $st != 1, "\
3521 "should also perror ENODATA (No data available)"
3523 run_test 110a "Non blocking restore policy (import case)"
3526 # test needs a running copytool
3530 local f=$DIR/$tdir/$tfile
3531 local fid=$(copy_file /etc/passwd $f)
3532 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3533 wait_request_state $fid ARCHIVE SUCCEED
3536 cdt_set_non_blocking_restore
3541 wait_request_state $fid RESTORE SUCCEED
3542 cdt_clear_non_blocking_restore
3546 error "md5sum returns $st != 1, "\
3547 "should also perror ENODATA (No data available)"
3549 run_test 110b "Non blocking restore policy (release case)"
3552 # test needs a running copytool
3556 copy2archive /etc/passwd $tdir/$tfile
3558 local f=$DIR/$tdir/$tfile
3560 copytool import $tdir/$tfile $f
3561 local fid=$(path2fid $f)
3565 copytool_remove_backend $fid
3568 wait_request_state $fid RESTORE FAILED
3575 [[ $st == 0 ]] || error "Restore does not failed"
3577 run_test 111a "No retry policy (import case), restore will error"\
3578 " (No such file or directory)"
3581 # test needs a running copytool
3585 local f=$DIR/$tdir/$tfile
3586 local fid=$(copy_file /etc/passwd $f)
3587 stack_trap cdt_clear_no_retry EXIT
3589 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3590 wait_request_state $fid ARCHIVE SUCCEED
3593 copytool_remove_backend $fid
3596 wait_request_state $fid RESTORE FAILED
3600 [[ $st == 0 ]] || error "Restore does not failed"
3602 run_test 111b "No retry policy (release case), restore will error"\
3603 " (No such file or directory)"
3606 # test needs a running copytool
3610 local f=$DIR/$tdir/$tfile
3611 local fid=$(copy_file /etc/passwd $f)
3613 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3614 local l=$($LFS hsm_action $f)
3616 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3619 wait_request_state $fid ARCHIVE SUCCEED
3622 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3624 run_test 112 "State of recorded request"
3627 local file1=$DIR/$tdir/$tfile
3628 local file2=$DIR2/$tdir/$tfile
3630 local fid=$(create_small_sync_file $file1)
3632 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3633 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3634 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3636 copytool setup -m "$MOUNT3"
3638 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3640 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3641 wait_request_state $fid ARCHIVE SUCCEED
3643 $LFS hsm_release $file1
3644 echo "Verifying released state: "
3645 check_hsm_flags $file1 "0x0000000d"
3647 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3650 kill -USR1 $MULTIPID
3655 local size1=$(stat -c "%s" $file1)
3656 local size2=$(stat -c "%s" $file2)
3658 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3660 run_test 113 "wrong stat after restore"
3663 local f=$DIR/$tdir/$tfile
3664 local fid=$(create_empty_file "$f")
3668 # Prevent archive from completing
3671 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3672 # wait archive to register at CDT
3673 wait_request_state $fid ARCHIVE STARTED
3675 # Cancel the archive
3676 $LFS hsm_cancel "$f"
3678 wait_request_state $fid ARCHIVE CANCELED
3681 wait_request_state $fid CANCEL SUCCEED
3683 run_test 200 "Register/Cancel archive"
3686 # test needs a running copytool
3689 local f=$DIR/$tdir/$tfile
3690 create_archive_file $tdir/$tfile
3691 copytool import $tdir/$tfile $f
3692 local fid=$(path2fid $f)
3694 # test with cdt on is made in test_222
3697 # wait restore to register at CDT
3698 wait_request_state $fid RESTORE WAITING
3701 wait_request_state $fid RESTORE CANCELED
3702 wait_request_state $fid CANCEL SUCCEED
3704 run_test 201 "Register/Cancel restore"
3707 local f=$DIR/$tdir/$tfile
3708 local fid=$(create_empty_file "$f")
3710 # test needs a running copytool
3713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3714 wait_request_state $fid ARCHIVE SUCCEED
3718 # wait remove to register at CDT
3719 wait_request_state $fid REMOVE STARTED
3722 wait_request_state $fid REMOVE CANCELED
3724 run_test 202 "Register/Cancel remove"
3726 test_220A() { # was test_220
3727 # test needs a running copytool
3732 local f=$DIR/$tdir/$tfile
3733 local fid=$(copy_file /etc/passwd $f)
3737 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3738 wait_request_state $fid ARCHIVE SUCCEED
3740 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3741 error "The expected changelog was not emitted"
3743 run_test 220A "Changelog for archive"
3746 # test needs a running copytool
3751 local f=$DIR/$tdir/$tfile
3752 local fid=$(copy_file /etc/passwd $f)
3756 # block copytool operations to allow for HSM request to be
3757 # submitted and file be unlinked (CDT will find object removed)
3760 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3762 # wait request to reach CT
3763 wait_request_state $fid ARCHIVE STARTED
3769 wait_request_state $fid ARCHIVE FAILED
3772 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3773 error "The expected changelog was not emitted"
3775 run_test 220a "Changelog for failed archive"
3778 local f=$DIR/$tdir/$tfile
3779 local fid=$(create_empty_file "$f")
3784 # Prevent archive from completing
3786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3787 wait_request_state $fid ARCHIVE STARTED
3790 wait_request_state $fid ARCHIVE CANCELED
3793 wait_request_state $fid CANCEL SUCCEED
3795 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3796 error "The expected changelog was not emitted"
3798 run_test 221 "Changelog for archive canceled"
3801 # test needs a running copytool
3805 copy2archive /etc/passwd $tdir/$tfile
3807 local f=$DIR/$tdir/$tfile
3808 copytool import $tdir/$tfile $f
3809 local fid=$(path2fid $f)
3814 wait_request_state $fid RESTORE SUCCEED
3816 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3817 error "The expected changelog was not emitted"
3819 run_test 222a "Changelog for explicit restore"
3822 # test needs a running copytool
3826 local f=$DIR/$tdir/$tfile
3827 local fid=$(copy_file /etc/passwd $f)
3830 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3831 wait_request_state $fid ARCHIVE SUCCEED
3836 wait_request_state $fid RESTORE SUCCEED
3838 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3839 error "The expected changelog was not emitted"
3841 run_test 222b "Changelog for implicit restore"
3844 # test needs a running copytool
3848 copy2archive /etc/passwd $tdir/$tfile
3850 local f=$DIR/$tdir/$tfile
3851 copytool import $tdir/$tfile $f
3852 local fid=$(path2fid $f)
3856 # block copytool operations to allow for HSM request to be
3857 # submitted and file be unlinked (CDT will find object removed)
3862 # wait request to reach CT
3863 wait_request_state $fid RESTORE STARTED
3869 wait_request_state $fid RESTORE FAILED
3872 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3873 error "The expected changelog was not emitted"
3875 run_test 222c "Changelog for failed explicit restore"
3878 # test needs a running copytool
3882 local f=$DIR/$tdir/$tfile
3883 local fid=$(copy_file /etc/passwd $f)
3886 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3887 wait_request_state $fid ARCHIVE SUCCEED
3890 copytool_remove_backend $fid
3893 wait_request_state $fid RESTORE FAILED
3896 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3897 error "The expected changelog was not emitted"
3899 run_test 222d "Changelog for failed implicit restore"
3902 # test needs a running copytool
3905 local f=$DIR/$tdir/$tfile
3906 create_archive_file $tdir/$tfile
3910 copytool import $tdir/$tfile $f
3911 local fid=$(path2fid $f)
3914 wait_request_state $fid RESTORE STARTED
3916 wait_request_state $fid RESTORE CANCELED
3917 wait_request_state $fid CANCEL SUCCEED
3919 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3920 error "The expected changelog was not emitted"
3922 run_test 223a "Changelog for restore canceled (import case)"
3925 local f=$DIR/$tdir/$tfile
3926 local fid=$(create_empty_file "$f")
3931 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3932 wait_request_state $fid ARCHIVE SUCCEED
3935 # Prevent restore from completing
3938 wait_request_state $fid RESTORE STARTED
3941 wait_request_state $fid RESTORE CANCELED
3944 wait_request_state $fid CANCEL SUCCEED
3946 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3947 error "The expected changelog was not emitted"
3949 run_test 223b "Changelog for restore canceled (release case)"
3951 test_224A() { # was test_224
3952 # test needs a running copytool
3957 local f=$DIR/$tdir/$tfile
3958 local fid=$(copy_file /etc/passwd $f)
3961 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3962 wait_request_state $fid ARCHIVE SUCCEED
3965 wait_request_state $fid REMOVE SUCCEED
3967 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
3968 error "The expected changelog was not emitted"
3970 run_test 224A "Changelog for remove"
3973 # test needs a running copytool
3978 local f=$DIR/$tdir/$tfile
3979 local fid=$(copy_file /etc/passwd $f)
3982 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3983 wait_request_state $fid ARCHIVE SUCCEED
3985 copytool_remove_backend $fid
3987 # block copytool operations to allow for HSM request to be
3988 # submitted and file be unlinked (CDT will find object removed)
3993 # wait for request to reach CT
3994 wait_request_state $fid REMOVE STARTED
4000 wait_request_state $fid REMOVE FAILED
4002 # HE_REMOVE|ENOENT=0x202
4003 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4004 error "The expected changelog was not emitted"
4006 run_test 224a "Changelog for failed remove"
4009 # test is not usable because remove request is too fast
4010 # so it is always finished before cancel can be done ...
4011 echo "Test disabled"
4014 # test needs a running copytool
4017 local f=$DIR/$tdir/$tfile
4018 local fid=$(create_empty_file "$f")
4021 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4022 wait_request_state $fid ARCHIVE SUCCEED
4024 # Prevent restore from completing
4029 wait_request_state $fid REMOVE CANCELED
4032 wait_request_state $fid CANCEL SUCCEED
4034 changelog_find -type HSM -target-fid $fid -flags 0x27d
4035 error "The expected changelog was not emitted"
4037 run_test 225 "Changelog for remove canceled"
4040 # test needs a running copytool
4045 local f1=$DIR/$tdir/$tfile-1
4046 local f2=$DIR/$tdir/$tfile-2
4047 local f3=$DIR/$tdir/$tfile-3
4048 local fid1=$(copy_file /etc/passwd $f1)
4049 local fid2=$(copy_file /etc/passwd $f2)
4050 copy_file /etc/passwd $f3
4053 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4054 wait_request_state $fid1 ARCHIVE SUCCEED
4056 $LFS hsm_archive $f2
4057 wait_request_state $fid2 ARCHIVE SUCCEED
4059 rm $f1 || error "rm $f1 failed"
4062 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4063 error "The expected changelog was not emitted"
4065 mv $f3 $f2 || error "mv $f3 $f2 failed"
4067 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4068 error "The expected changelog was not emitted"
4070 run_test 226 "changelog for last rm/mv with exiting archive"
4072 # This is just a utility function to clarify what test_227 does
4077 "$LFS" "$action" --$flag "$file" ||
4078 error "Cannot ${action#hsm_} $flag on '$file'"
4080 # Only one changelog should be produced
4081 local entries="$(changelog_find -type HSM -target-fid $fid)"
4082 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4083 error "lfs $action --$flag '$file' produced more than one" \
4086 # Parse the last changelog record
4087 local entry="$(tail -n 1 <<< "$entries")"
4088 eval local -A changelog=$(changelog2array $entry)
4090 # Also check the flags match what is expected
4091 [[ ${changelog[flags]} == $target ]] ||
4092 error "Changelog flag is '${changelog[flags]}', not $target"
4096 local file="$DIR/$tdir/$tfile"
4097 local fid=$(create_empty_file "$file")
4102 for flag in norelease noarchive exists archived lost; do
4103 if [ "$flag" == lost ]; then
4104 # The flag "lost" only works on an archived file
4105 "$LFS" hsm_set --archived "$file"
4109 action="hsm_set" __test_227
4110 action="hsm_clear" __test_227
4113 run_test 227 "changelog when explicit setting of HSM flags"
4116 # test needs a running copytool
4119 local fid=$(create_small_sync_file $DIR/$tfile)
4120 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4121 wait_request_state $fid ARCHIVE SUCCEED
4123 $LFS hsm_release $DIR/$tfile
4124 check_hsm_flags $DIR/$tfile "0x0000000d"
4126 filefrag $DIR/$tfile | grep " 1 extent found" ||
4127 error "filefrag on released file must return only one extent"
4129 # only newer versions of cp detect sparse files by stat/FIEMAP
4131 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4132 error "copying $DIR/$tfile"
4133 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4135 $LFS hsm_release $DIR/$tfile
4136 check_hsm_flags $DIR/$tfile "0x0000000d"
4138 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4140 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4142 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4143 error "comparing untarred $DIR/$tfile"
4145 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4146 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4148 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4151 local file="$DIR/$tdir/$tfile"
4153 # set max_requests to allow one request of each type to be started (3)
4155 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4156 set_hsm_param max_requests 3
4159 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4160 set_hsm_param loop_period 1
4162 # send 1 requests of each kind twice
4165 for action in archive restore remove; do
4166 local filepath="$file"-to-$action
4167 local fid=$(create_empty_file "$filepath")
4168 local fid2=$(create_empty_file "$filepath".bis)
4170 if [ "$action" != archive ]; then
4171 "$LFS" hsm_archive "$filepath"
4172 wait_request_state $fid ARCHIVE SUCCEED
4173 "$LFS" hsm_archive "$filepath".bis
4174 wait_request_state $fid2 ARCHIVE SUCCEED
4176 if [ "$action" == restore ]; then
4177 "$LFS" hsm_release "$filepath"
4178 "$LFS" hsm_release "$filepath".bis
4182 # suspend the copytool to prevent requests from completing
4183 stack_trap "copytool_continue" EXIT
4186 # send `max_requests' requests (one of each kind)
4187 for action in archive restore remove; do
4188 filepath="$file"-to-$action
4189 "$LFS" hsm_${action} "$filepath"
4190 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4193 # send another batch of requests
4194 for action in archive restore remove; do
4195 "$LFS" hsm_${action} "$file-to-$action".bis
4197 # wait for `loop_period' seconds to make sure the coordinator has time
4198 # to register those, even though it should not
4201 # only the first batch of request should be started
4203 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4207 error "expected 3 STARTED requests, found $count"
4209 run_test 250 "Coordinator max request"
4212 local f=$DIR/$tdir/$tfile
4213 local fid=$(create_empty_file "$f")
4216 # to have a short test
4217 local old_to=$(get_hsm_param active_request_timeout)
4218 set_hsm_param active_request_timeout 1
4219 # to be sure the cdt will wake up frequently so
4220 # it will be able to cancel the "old" request
4221 local old_loop=$(get_hsm_param loop_period)
4222 set_hsm_param loop_period 1
4227 # Prevent archive from completing
4229 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4230 wait_request_state $fid ARCHIVE STARTED
4232 # Let the request timeout
4233 wait_request_state $fid ARCHIVE CANCELED
4235 set_hsm_param active_request_timeout $old_to
4236 set_hsm_param loop_period $old_loop
4238 run_test 251 "Coordinator request timeout"
4241 local f=$DIR/$tdir/$tfile
4242 local fid=$(create_empty_file "$f")
4244 # to have a short test
4245 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4246 set_hsm_param loop_period 1
4250 # Prevent archive from completing
4252 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4253 wait_request_state $fid ARCHIVE STARTED
4256 stack_trap "set_hsm_param active_request_timeout \
4257 $(get_hsm_param active_request_timeout)" EXIT
4258 set_hsm_param active_request_timeout 1
4260 wait_request_state $fid ARCHIVE CANCELED
4263 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4267 # test needs a running copytool
4271 local f=$DIR/$tdir/$tfile
4273 dd if=/dev/zero of=$f bs=1MB count=10
4274 local fid=$(path2fid $f)
4276 $LFS hsm_archive $f || error "could not archive file"
4277 wait_request_state $fid ARCHIVE SUCCEED
4279 # clear locks to discard inode data
4280 cancel_lru_locks osc
4282 #define OBD_FAIL_MDC_MERGE 0x807
4283 $LCTL set_param fail_loc=0x807
4285 #expect error here, instead of release with wrong size
4288 if ((rc == 0)); then
4289 file_size=$(stat -c '%s' $f)
4290 if ((file_size != 10485760)); then
4291 error "Wrong file size after hsm_release"
4294 echo "could not release file"
4297 run_test 253 "Check for wrong file size after release"
4301 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4302 skip "need MDS version at least 2.10.56"
4304 # Check that the counters are initialized to 0
4306 for request_type in archive restore remove; do
4307 count="$(get_hsm_param ${request_type}_count)" ||
4308 error "Reading ${request_type}_count failed with $?"
4310 [ "$count" -eq 0 ] ||
4311 error "Expected ${request_type}_count to be " \
4315 run_test 254a "Request counters are initialized to zero"
4319 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4320 skip "need MDS version at least 2.10.56"
4322 # The number of request to launch (at least 32)
4323 local request_count=$((RANDOM % 32 + 32))
4324 printf "Will launch %i requests of each type\n" "$request_count"
4326 # Launch a copytool to process requests
4329 # Set hsm.max_requests to allow starting all requests at the same time
4331 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4332 set_hsm_param max_requests "$request_count"
4336 for request_type in archive restore remove; do
4337 printf "Checking %s requests\n" "${request_type}"
4338 # Suspend the copytool to give us time to read the proc files
4341 for ((i = 0; i < $request_count; i++)); do
4342 case $request_type in
4344 create_empty_file "$DIR/$tdir/$tfile-$i" \
4348 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4351 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4354 # Give the coordinator 10 seconds to start every request
4356 while get_hsm_param actions | grep -q WAITING; do
4359 [ $timeout -gt 0 ] ||
4360 error "${request_type^} requests took too " \
4364 count="$(get_hsm_param ${request_type}_count)"
4365 [ "$count" -eq "$request_count" ] ||
4366 error "Expected '$request_count' (!= '$count') " \
4367 "active $request_type requests"
4369 # Let the copytool process the requests
4371 # Give it 10 seconds maximum
4373 while get_hsm_param actions | grep -q STARTED; do
4376 [ $timeout -gt 0 ] ||
4377 error "${request_type^} requests took too " \
4381 count="$(get_hsm_param ${request_type}_count)"
4382 [ "$count" -eq 0 ] ||
4383 error "Expected 0 (!= '$count') " \
4384 "active $request_type requests"
4387 run_test 254b "Request counters are correctly incremented and decremented"
4391 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4392 skip "Need MDS version at least 2.12.0"
4394 local file="$DIR/$tdir/$tfile"
4395 local fid=$(create_empty_file "$file")
4397 # How do you make sure the coordinator has consumed any outstanding
4398 # event, without triggering an event yourself?
4400 # You wait for a request to disappear from the coordinator's llog.
4402 # Warning: the setup represents 90% of this test
4404 # Create and process an HSM request
4406 "$LFS" hsm_archive "$file"
4407 wait_request_state $fid ARCHIVE SUCCEED
4410 wait_copytools || error "failed to stop copytools"
4412 # Launch a new HSM request
4414 create_empty_file "$file"
4415 "$LFS" hsm_archive "$file"
4419 # Have the completed request be removed as soon as the cdt wakes up
4420 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4421 set_hsm_param grace_delay 1
4422 # (Hopefully, time on the MDS will behave nicely)
4423 do_facet $SINGLEMDS sleep 2 &
4425 # Increase `loop_period' as a mean to prevent the coordinator from
4426 # waking itself up to do some housekeeping.
4427 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4428 set_hsm_param loop_period 1000
4430 wait $! || error "waiting failed"
4432 wait_request_state $fid ARCHIVE ""
4433 # The coordinator will not wake up on its own for ~`loop_period' secs...
4435 # ... Unless a copytool registers. Now the real test begins
4437 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4439 run_test 255 "Copytool registration wakes the coordinator up"
4441 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4442 # break in the future because of that.
4445 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4446 skip "need MDS version 2.11.56 or later"
4448 local -a files=("$DIR/$tdir/$tfile".{0..15})
4451 for file in "${files[@]}"; do
4452 create_small_file "$file"
4455 # Set a few hsm parameters
4457 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4458 set_hsm_param loop_period 1
4460 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4461 set_hsm_param max_requests 3
4465 "$LFS" hsm_archive "${files[0]}"
4466 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4467 "$LFS" hsm_release "${files[0]}"
4471 wait_copytools || error "copytools failed to stop"
4473 # Send several archive requests
4474 for file in "${files[@]:1}"; do
4475 "$LFS" hsm_archive "$file"
4478 # Send one restore request
4479 "$LFS" hsm_restore "${files[0]}"
4484 # Wait for all the requests to complete
4485 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4486 for file in "${files[@]:1}"; do
4487 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4490 # Collect the actions in the order in which the copytool processed them
4492 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4493 "$(copytool_logfile "$SINGLEAGT")")
4496 printf '%s\n' "${actions[@]}"
4499 for action in "${actions[@]:0:3}"; do
4500 [ "$action" == RESTORE ] && return
4503 error "Too many ARCHIVE requests were run before the RESTORE request"
4505 run_test 260a "Restore request have priority over other requests"
4507 # This test is very much tied to the implementation of the current priorisation
4508 # mechanism in the coordinator. It might not make sense to keep it in the future
4511 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4512 skip "need MDS version 2.11.56 or later"
4514 local -a files=("$DIR/$tdir/$tfile".{0..15})
4517 for file in "${files[@]}"; do
4518 create_small_file "$file"
4521 # Set a few hsm parameters
4523 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4524 set_hsm_param loop_period 1
4526 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4527 set_hsm_param max_requests 3
4530 copytool setup --archive-id 2
4531 "$LFS" hsm_archive --archive 2 "${files[0]}"
4532 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4533 "$LFS" hsm_release "${files[0]}"
4537 wait_copytools || error "copytools failed to stop"
4539 # Send several archive requests
4540 for file in "${files[@]:1}"; do
4541 "$LFS" hsm_archive "$file"
4544 # Send one restore request
4545 "$LFS" hsm_restore "${files[0]}"
4549 copytool setup --archive-id 2
4551 # Wait for all the requests to complete
4552 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4553 for file in "${files[@]:1}"; do
4554 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4557 # Collect the actions in the order in which the copytool processed them
4559 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4560 "$(copytool_logfile "$SINGLEAGT")")
4563 printf '%s\n' "${actions[@]}"
4566 for action in "${actions[@]:0:3}"; do
4567 [ "$action" == RESTORE ] && return
4570 error "Too many ARCHIVE requests were run before the RESTORE request"
4572 run_test 260b "Restore request have priority over other requests"
4574 # This test is very much tied to the implementation of the current priorisation
4575 # mechanism in the coordinator. It might not make sense to keep it in the future
4578 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4579 skip "Need MDS version at least 2.12.0"
4581 local -a files=("$DIR/$tdir/$tfile".{0..15})
4584 for file in "${files[@]}"; do
4585 create_small_file "$file"
4588 # Set a few hsm parameters
4590 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4591 set_hsm_param loop_period 1000
4593 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4594 set_hsm_param max_requests 3
4597 copytool setup --archive-id 2
4598 "$LFS" hsm_archive --archive 2 "${files[0]}"
4599 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4600 "$LFS" hsm_release "${files[0]}"
4604 wait_copytools || error "copytools failed to stop"
4606 # Force the next coordinator run to do housekeeping
4610 "$LFS" hsm_archive "${files[1]}"
4614 copytool setup --archive-id 2
4616 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4617 # The coordinator just did a housekeeping run it won't do another one
4618 # for around `loop_period' seconds => requests will not be reordered
4619 # if it costs too much (ie. when the coordinator has to discard a whole
4622 # Send several archive requests
4623 for file in "${files[@]:2}"; do
4624 "$LFS" hsm_archive "$file"
4627 # Send one restore request
4628 "$LFS" hsm_restore "${files[0]}"
4630 # Wait for all the requests to complete
4631 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4632 for file in "${files[@]:2}"; do
4633 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4636 # Collect the actions in the order in which the copytool processed them
4638 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4639 "$(copytool_logfile "$SINGLEAGT")")
4642 printf '%s\n' "${actions[@]}"
4645 for action in "${actions[@]:0:3}"; do
4646 [ "$action" == RESTORE ] &&
4647 error "Restore requests should not be prioritised" \
4648 "unless the coordinator is doing housekeeping"
4652 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4655 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4657 # the only way to test ondisk conf is to restart MDS ...
4658 echo "Stop coordinator and remove coordinator state at mount"
4661 # clean on disk conf set by default
4662 cdt_clear_mount_state
4663 cdt_check_state stopped
4665 # check cdt still off after umount/remount
4667 cdt_check_state stopped
4669 echo "Set coordinator start at mount, and start coordinator"
4670 cdt_set_mount_state enabled
4673 cdt_check_state enabled
4675 # check cdt still on after umount/remount
4677 cdt_check_state enabled
4679 # we are back to original state (cdt started at mount)
4681 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4684 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4686 local ai=$(get_hsm_param default_archive_id)
4687 local new=$((ai + 1))
4689 set_hsm_param default_archive_id $new -P
4691 local res=$(get_hsm_param default_archive_id)
4694 set_hsm_param default_archive_id "" "-P -d"
4696 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4698 run_test 301 "HSM tunnable are persistent"
4701 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4703 local ai=$(get_hsm_param default_archive_id)
4704 local new=$((ai + 1))
4709 set_hsm_param default_archive_id $new -P
4712 for mdtno in $(seq 1 $MDSCOUNT); do
4717 cdt_check_state enabled
4719 local res=$(get_hsm_param default_archive_id)
4722 set_hsm_param default_archive_id "" "-P -d"
4724 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4726 run_test 302 "HSM tunnable are persistent when CDT is off"
4729 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4735 local dir_mdt0=$DIR/$tdir/mdt0
4736 local dir_mdt1=$DIR/$tdir/mdt1
4738 # create 1 dir per MDT
4739 stack_trap "rm -rf $dir_mdt0" EXIT
4740 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4741 stack_trap "rm -rf $dir_mdt1" EXIT
4742 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4744 # create 1 file in each MDT
4745 local fid1=$(create_small_file $dir_mdt0/$tfile)
4746 local fid2=$(create_small_file $dir_mdt1/$tfile)
4748 # check that hsm request on mdt0 is sent to the right MDS
4749 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4750 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4751 echo "archive successful on mdt0"
4753 # check that hsm request on mdt1 is sent to the right MDS
4754 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4755 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4756 echo "archive successful on mdt1"
4758 run_test 400 "Single request is sent to the right MDT"
4761 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4767 local dir_mdt0=$DIR/$tdir/mdt0
4768 local dir_mdt1=$DIR/$tdir/mdt1
4770 # create 1 dir per MDT
4771 stack_trap "rm -rf $dir_mdt0" EXIT
4772 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4773 stack_trap "rm -rf $dir_mdt1" EXIT
4774 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4776 # create 1 file in each MDT
4777 local fid1=$(create_small_file $dir_mdt0/$tfile)
4778 local fid2=$(create_small_file $dir_mdt1/$tfile)
4780 # check that compound requests are shunt to the rights MDTs
4781 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4782 error "lfs hsm_archive"
4783 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4784 echo "archive successful on mdt0"
4785 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4786 echo "archive successful on mdt1"
4788 run_test 401 "Compound requests split and sent to their respective MDTs"
4790 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4795 local node=$(facet_active_host $facet)
4797 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4798 awk '{print $4}'); do
4799 echo "$3 $mdc on $node"
4800 do_facet $facet "$LCTL --device $mdc $state" || return 1
4805 # deactivate all mdc on agent1
4806 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4808 copytool setup --no-fail
4810 check_agent_unregistered "uuid" # match any agent
4812 # no expected running copytool
4813 search_copytools $agent && error "Copytool start should have failed"
4816 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4818 run_test 402a "Copytool start fails if all MDTs are inactive"
4825 local f=$DIR/$tdir/$tfile
4826 touch $f || error "touch $f failed"
4827 local fid=$(path2fid $f)
4829 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4830 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4831 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4833 # give time for CDT to send request and to keep it for retry
4834 wait_for_loop_period
4836 wait_request_state $fid ARCHIVE WAITING
4838 do_facet $SINGLEAGT lctl set_param fail_loc=0
4840 # request should succeed now
4841 wait_request_state $fid ARCHIVE SUCCEED
4843 run_test 402b "CDT must retry request upon slow start of CT"
4846 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4848 local agent=$(facet_active_host $SINGLEAGT)
4850 # deactivate all mdc for MDT0001
4851 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4854 local uuid=$(get_agent_uuid $agent)
4855 # check the agent is registered on MDT0000, and not on MDT0001
4856 check_agent_registered_by_mdt $uuid 0
4857 check_agent_unregistered_by_mdt $uuid 1
4859 # check running copytool process
4860 search_copytools $agent || error "No running copytools on $agent"
4862 # reactivate all mdc for MDT0001
4863 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4865 # make sure the copytool is now registered to all MDTs
4866 check_agent_registered $uuid
4868 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4871 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4875 # create files on both MDT0000 and MDT0001
4878 local dir_mdt0=$DIR/$tdir/mdt0
4879 stack_trap "rm -rf $dir_mdt0" EXIT
4880 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4882 # create 1 file on mdt0
4883 local fid1=$(create_small_file $dir_mdt0/$tfile)
4885 # deactivate all mdc for MDT0001
4886 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4888 # send an HSM request for files in MDT0000
4889 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4891 # check for completion of files in MDT0000
4892 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4893 echo "archive successful on mdt0"
4895 # reactivate all mdc for MDT0001
4896 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4898 run_test 404 "Inactive MDT does not block requests for active MDTs"
4901 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4907 local striped_dir=$DIR/$tdir/striped_dir
4909 # create striped dir on all of MDTs
4910 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4912 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4913 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4914 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4915 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4917 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4918 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4919 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4920 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4922 # check that compound requests are shunt to the rights MDTs
4923 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4924 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4925 error "lfs hsm_archive"
4927 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4928 echo "archive successful on $fid1"
4929 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4930 echo "archive successful on $fid2"
4931 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4932 echo "archive successful on $fid3"
4933 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4934 echo "archive successful on $fid4"
4936 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4937 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4938 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4939 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4941 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4942 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4943 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4944 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4946 run_test 405 "archive and release under striped directory"
4949 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4951 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
4952 skip "need MDS version at least 2.7.64"
4957 fid=$(create_small_file $DIR/$tdir/$tfile)
4962 $LFS hsm_archive $DIR/$tdir/$tfile
4963 wait_request_state "$fid" ARCHIVE SUCCEED
4964 $LFS hsm_release $DIR/$tdir/$tfile
4966 # Should migrate $tdir but not $tfile.
4967 $LFS migrate -m1 $DIR/$tdir &&
4968 error "migrating HSM an archived file should fail"
4970 $LFS hsm_restore $DIR/$tdir/$tfile
4971 wait_request_state "$fid" RESTORE SUCCEED
4973 $LFS hsm_remove $DIR/$tdir/$tfile
4974 wait_request_state "$fid" REMOVE SUCCEED
4976 cat $DIR/$tdir/$tfile > /dev/null ||
4977 error "cannot read $DIR/$tdir/$tfile"
4979 $LFS migrate -m1 $DIR/$tdir ||
4980 error "cannot complete migration after HSM remove"
4982 mdt_index=$($LFS getstripe -m $DIR/$tdir)
4983 if ((mdt_index != 1)); then
4984 error "expected MDT index 1, got $mdt_index"
4987 # Refresh fid after migration.
4988 fid=$(path2fid $DIR/$tdir/$tfile)
4991 $LFS hsm_archive $DIR/$tdir/$tfile
4992 wait_request_state "$fid" ARCHIVE SUCCEED 1
4994 lctl set_param debug=+trace
4995 $LFS hsm_release $DIR/$tdir/$tfile ||
4996 error "cannot release $DIR/$tdir/$tfile"
4998 $LFS hsm_restore $DIR/$tdir/$tfile
4999 wait_request_state "$fid" RESTORE SUCCEED 1
5001 cat $DIR/$tdir/$tfile > /dev/null ||
5002 error "cannot read $DIR/$tdir/$tfile"
5004 run_test 406 "attempting to migrate HSM archived files is safe"
5007 local f=$DIR/$tdir/$tfile
5008 local f2=$DIR2/$tdir/$tfile
5009 local fid=$(create_empty_file "$f")
5013 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5014 wait_request_state $fid ARCHIVE SUCCEED
5017 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5018 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5020 # Prevent restore from completing
5024 # 1st request holds layout lock while appropriate
5025 # RESTORE record is still not added to llog
5029 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5030 # after umount hsm_actions->O/x/x log shouldn't have
5031 # double RESTORE records like below
5032 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5033 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5035 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5037 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5039 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5042 wait_all_done 100 $fid
5044 run_test 407 "Check for double RESTORE records in llog"
5048 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5049 skip "HSM migrate is not supported"
5051 test_mkdir -p $DIR/$tdir
5053 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5054 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5056 llapi_hsm_test -d $DIR/$tdir -b ||
5057 error "One llapi HSM test failed"
5059 llapi_hsm_test -d $DIR/$tdir ||
5060 error "One llapi HSM test failed"
5063 run_test 500 "various LLAPI HSM tests"
5066 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5067 skip "need MDS version at least 2.10.58"
5071 local f=$DIR/$tdir/$tfile
5074 # set changelog_mask to ALL
5075 changelog_chmask "ALL"
5077 chmod 777 $DIR/$tdir
5078 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5079 local fid=$(path2fid $f)
5082 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5083 -gid "$RUNAS_GID") ||
5084 error "No matching CREAT entry"
5086 # Parse the changelog
5087 eval local -A changelog=$(changelog2array $entry)
5088 local nid="${changelog[nid]}"
5091 echo "Got NID '$nid'"
5092 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5093 error "nid '$nid' does not match any client NID:" \
5096 run_test 600 "Changelog fields 'u=' and 'nid='"
5099 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5100 skip "need MDS version at least 2.10.58"
5104 local f=$DIR/$tdir/$tfile
5107 # set changelog_mask to ALL
5108 changelog_chmask "ALL"
5110 touch $f || error "touch $f failed"
5111 local fid=$(path2fid $f)
5114 cat $f || error "cat $f failed"
5116 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5117 error "No matching OPEN entry"
5119 run_test 601 "OPEN Changelog entry"
5122 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5123 skip "need MDS version at least 2.10.58"
5127 local f=$DIR/$tdir/$tfile
5130 # set changelog_mask to ALL
5131 changelog_chmask "ALL"
5133 touch $f || error "touch $f failed"
5134 local fid=$(path2fid $f)
5137 cat $f || error "cat $f failed"
5139 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5143 echo f > $f || error "write $f failed"
5146 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5148 # remove OPEN from changelog_mask
5149 changelog_chmask "-OPEN"
5153 cat $f || error "cat $f failed"
5156 changelog_find -type CLOSE -target-fid $fid &&
5157 error "There should be no CLOSE entry"
5161 echo f > $f || error "write $f failed"
5164 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5166 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5169 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5170 skip "need MDS version at least 2.10.58"
5174 local f=$DIR/$tdir/$tfile
5177 # set changelog_mask to ALL
5178 changelog_chmask "ALL"
5180 touch $f || error "touch $f failed"
5181 local fid=$(path2fid $f)
5183 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5186 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5188 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5189 error "No matching GXATR entry"
5191 run_test 603 "GETXATTR Changelog entry"
5194 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5195 skip "need MDS version at least 2.10.58"
5199 local f=$DIR/$tdir/$tfile
5200 local f2=$DIR2/$tdir/$tfile
5201 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5203 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5204 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5205 do_facet mds1 lctl set_param "$procname=20"
5209 # set changelog_mask to ALL
5210 changelog_chmask "ALL"
5212 touch $f || error "touch $f failed"
5213 local fid=$(path2fid $f)
5219 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5223 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5224 -gid "$RUNAS_GID" -mode "r--") ||
5225 error "No matching NOPEN entry"
5227 # Parse the changelog
5228 eval local -A changelog=$(changelog2array $entry)
5229 local nid="${changelog[nid]}"
5232 echo "Got NID '$nid'"
5233 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5234 error "nid '$nid' does not match any client NID:" \
5239 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5242 changelog_find -type NOPEN -target-fid $fid &&
5243 error "There should be no NOPEN entry"
5245 # Sleep for `changelog_deniednext` seconds
5250 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5253 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5254 -gid "$RUNAS_GID" -mode "r--") ||
5255 error "No matching NOPEN entry"
5257 # Parse the changelog
5258 eval local -A changelog=$(changelog2array $entry)
5259 local nid="${changelog[nid]}"
5262 echo "Got NID '$nid'"
5263 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5264 error "nid '$nid' does not match any client NID:" \
5267 run_test 604 "NOPEN Changelog entry"
5270 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5271 skip "need MDS version at least 2.10.58"
5275 local f=$DIR/$tdir/$tfile
5276 local f2=$DIR2/$tdir/$tfile
5279 # set changelog_mask to ALL
5280 changelog_chmask "ALL"
5282 touch $f || error "touch $f failed"
5283 local fid=$(path2fid $f)
5287 exec 3<> $f || error "open $f failed"
5291 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5295 exec 4<> $f || error "open $f failed"
5298 changelog_find -type OPEN -target-fid $fid &&
5299 error "There should be no OPEN entry"
5301 exec 4>&- || error "close $f failed"
5304 changelog_find -type CLOSE -target-fid $fid &&
5305 error "There should be no CLOSE entry"
5309 # access in rw, so different access mode should generate entries
5310 cat $f || error "cat $f failed"
5313 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5315 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5319 # same access as first one, should not generate new entries
5320 exec 4<> $f || error "open $f failed"
5323 changelog_find -type OPEN -target-fid $fid &&
5324 error "There should be no OPEN entry"
5326 exec 4>&- || error "close $f failed"
5329 changelog_find -type CLOSE -target-fid $fid &&
5330 error "There should be no CLOSE entry"
5334 # access by different user should generate new entries
5335 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5338 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5340 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5344 exec 3>&- || error "close $f failed"
5347 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5349 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5352 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5353 skip "need MDS version at least 2.10.58"
5355 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5356 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5357 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5358 skip_env "missing llog_reader" && return
5359 local fstype=$(facet_fstype mds1)
5363 local f=$DIR/$tdir/$tfile
5366 # set changelog_mask to ALL
5367 changelog_chmask "ALL"
5369 chmod 777 $DIR/$tdir
5370 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5371 local fid=$(path2fid $f)
5372 rm $f || error "rm $f failed"
5374 local mntpt=$(facet_mntpt mds1)
5378 #remount mds1 as ldiskfs or zfs type
5379 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5380 stop mds1 || error "stop mds1 failed"
5381 mount_fstype mds1 || error "remount mds1 failed"
5383 for ((i = 0; i < 1; i++)); do
5384 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5385 local cat_file=$(do_facet mds1 $llog_reader \
5386 $mntpt/changelog_catalog | awk \
5387 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5388 [ -n "$cat_file" ] || error "no catalog file"
5390 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5391 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5392 [ -n "$entry" ] || error "no CREAT entry"
5395 local uidgid=$(echo $entry |
5396 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5397 [ -n "$uidgid" ] || error "uidgid is empty"
5398 echo "Got UID/GID $uidgid"
5399 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5400 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5401 local nid=$(echo $entry |
5402 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5403 [ -n "$nid" ] || error "nid is empty"
5405 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5406 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5408 run_test 606 "llog_reader groks changelog fields"
5411 check_and_cleanup_lustre