3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
12 LUSTRE=${LUSTRE:-$(dirname $0)/..}
13 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT "
19 # bug number for skipped tests: LU-9795
20 ALWAYS_EXCEPT+=" 402b "
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 # Skip tests for PPC that fail frequently
25 if [[ $(uname -m) = ppc64 ]]; then
26 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
27 ALWAYS_EXCEPT+=" 1a 1b 1d 1e 12c 12f "
28 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
29 ALWAYS_EXCEPT+=" 12g 12h 12m 12n 12o 12p "
30 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
31 ALWAYS_EXCEPT+=" 12q 21 22 23 24a 24b "
32 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
33 ALWAYS_EXCEPT+=" 24d 24e 24f 25b 30c 37 "
34 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
35 ALWAYS_EXCEPT+=" 57 58 90 110b 111b 113 "
36 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
37 ALWAYS_EXCEPT+=" 222b 222d 228 260a 260b 260c "
38 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
39 ALWAYS_EXCEPT+=" 220A 220a 221 222a 222c 223a "
40 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
41 ALWAYS_EXCEPT+=" 223b 224A 224a 226 227 600"
42 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
43 ALWAYS_EXCEPT+=" 601 602 603 604 605 "
48 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
50 OPENFILE=${OPENFILE:-openfile}
51 MOUNT_2=${MOUNT_2:-"yes"}
54 # script only handles up to 10 MDTs (because of MDT_PREFIX)
55 [ $MDSCOUNT -gt 9 ] &&
56 error "script cannot handle more than 9 MDTs, please fix"
58 check_and_setup_lustre
60 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
61 skip_env "Need MDS version at least 2.4.53"
64 # $RUNAS_ID may get set incorrectly somewhere else
65 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
66 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
68 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
69 if getent group nobody; then
71 elif getent group nogroup; then
74 error "No generic nobody group"
77 # if there is no CLIENT1 defined, some tests can be ran on localhost
78 CLIENT1=${CLIENT1:-$HOSTNAME}
79 # if CLIENT2 doesn't exist then use CLIENT1 instead
80 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
82 # Exception is the test which need two separate nodes
83 CLIENT2=${CLIENT2:-$CLIENT1}
86 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
87 do_nodesv $hosts "pgrep --pidfile=$HSMTOOL_PID_FILE hsmtool"
91 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
92 local wait_timeout=200
93 local wait_start=$SECONDS
94 local wait_end=$((wait_start + wait_timeout))
97 while ((SECONDS < wait_end)); do
98 if ! search_copytools $hosts; then
99 echo "copytools stopped in $((SECONDS - wait_start))s"
103 echo "copytools still running on $hosts"
105 [ $sleep_time -lt 5 ] && sleep_time=$((sleep_time + 1))
108 # try to dump Copytool's stack
109 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
110 "echo t >/proc/sysrq-trigger"
112 echo "copytools failed to stop in ${wait_timeout}s"
117 copytool_monitor_setup() {
118 local facet=${1:-$SINGLEAGT}
119 local agent=$(facet_active_host $facet)
121 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
122 local test_dir=$(do_node $agent "$cmd") ||
123 error "Failed to create tempdir on $agent"
124 export HSMTOOL_MONITOR_DIR=$test_dir
126 # Create the fifo and a monitor (cat dies when copytool dies)
127 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
128 error "failed to create copytool fifo on $agent"
129 cmd="cat $test_dir/fifo > $test_dir/events &"
130 cmd+=" echo \\\$! > $test_dir/monitor_pid"
132 # This background subshell nonsense is required when pdsh/ssh decides
133 # to wait for the cat process to exit on the remote client
134 (do_node $agent "$cmd") &
135 export HSMTOOL_MONITOR_PDSH=$!
137 # Slightly racy, but just making a best-effort to catch obvious
140 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
142 error "Failed to start copytool monitor on $agent"
150 case "$HSMTOOL_ARCHIVE_FORMAT" in
152 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
155 printf "%s" "$(hsm_root)/*/$fid"
160 get_copytool_event_log() {
161 local facet=${1:-$SINGLEAGT}
162 local agent=$(facet_active_host $facet)
164 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
165 error "Can't get event log: No monitor directory!"
167 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
168 error "Could not collect event log from $agent"
172 local agents=${1:-$(facet_active_host $SINGLEAGT)}
174 stack_trap "pkill_copytools $agents CONT || true" EXIT
175 pkill_copytools $agents STOP || return 0
176 echo "Copytool is suspended on $agents"
179 copytool_remove_backend() {
181 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
182 echo "Remove from backend: $fid = $be"
183 do_facet $SINGLEAGT rm -f $be
186 file_creation_failure() {
193 df $MOUNT $MOUNT2 >&2
194 error "Not enough space to create $file with $cmd"
197 error "cannot create $file with $cmd, status=$err"
202 # Creates a file using dd
208 local source=${5:-/dev/zero}
212 if [ -n "$conv" ]; then
216 # Create the directory in case it does not exist
217 mkdir -p "$(dirname "$file")"
218 # Delete the file in case it already exist
221 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
222 path2fid "$file" || error "cannot get FID of '$file'"
225 echo "cannot create file '$file'" >&2;
226 # Let the caller decide what to do on error
231 create_empty_file() {
232 create_file "${1/$DIR/$DIR2}" 1M 0 ||
233 file_creation_failure dd "${1/$DIR/$DIR2}" $?
236 create_small_file() {
237 local source_file=/dev/urandom
240 local conv=${2:-fsync}
242 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
243 file_creation_failure dd "${1/$DIR/$DIR2}" $?
246 create_small_sync_file() {
247 create_small_file "$1" sync
250 create_archive_file() {
251 local file="$(hsm_root)/$1"
253 local source=/dev/urandom
255 # Create the counterpart directory of the archive
256 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
257 error "cannot create archive directory '$(dirname "$file")'"
259 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
260 error "cannot create archive file '$file'"
264 local hsm_root="$(hsm_root)"
265 local file="$hsm_root/$2"
267 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
268 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
269 error "mkdir '$(dirname "$file")' failed"
270 do_facet $SINGLEAGT cp -p "$1" "$file" ||
271 error "cannot copy '$1' to '$file'"
276 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
283 mdts_set_param "" hsm_control "$cmd"
284 mdts_check_param hsm_control "$target" 10
289 mdts_set_param "" hsm.policy "+NRA"
290 CDT_POLICY_HAD_CHANGED=true
293 cdt_clear_no_retry() {
294 mdts_set_param "" hsm.policy "-NRA"
295 CDT_POLICY_HAD_CHANGED=true
298 cdt_set_non_blocking_restore() {
299 mdts_set_param "" hsm.policy "+NBR"
300 CDT_POLICY_HAD_CHANGED=true
303 cdt_clear_non_blocking_restore() {
304 mdts_set_param "" hsm.policy "-NBR"
305 CDT_POLICY_HAD_CHANGED=true
308 cdt_clear_mount_state() {
309 mdts_set_param "-P -d" hsm_control ""
313 set_test_state disabled disabled
317 set_test_state enabled enabled
321 set_test_state shutdown stopped
325 set_test_state purge enabled
331 cdt_set_sanity_policy
335 get_hsm_archive_id() {
338 st=$($LFS hsm_state $f)
339 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
341 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
345 check_hsm_flags_user() {
349 local st=$(get_hsm_flags $f user)
350 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
362 if [[ "$3" != 1 ]]; then
366 cp $1 $f || file_creation_failure cp $f $?
368 path2fid $f || error "cannot get fid on $f"
371 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
373 # Note that this might lead to surprising behaviours such as deleting an
374 # important file for the currently running test
375 delete_large_files() {
376 printf "Deleting large files...\n" >&2
377 find $MOUNT -size +10M -delete
378 wait_delete_completed
381 get_request_state() {
385 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
386 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
389 get_request_count() {
393 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
394 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
397 # Ensure the number of HSM request for a given FID is correct
398 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
399 assert_request_count() {
400 local request_count=$(get_request_count $1 $2)
401 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
403 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
410 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
411 [[ -n $fid ]] && cmd+=" | grep '$fid'"
412 cmd+=" | egrep 'WAITING|STARTED'"
414 wait_update_facet --verbose mds1 "$cmd" "" $timeout ||
415 error "requests did not complete"
418 wait_for_grace_delay() {
419 local val=$(get_hsm_param grace_delay)
423 wait_for_loop_period() {
424 local val=$(get_hsm_param loop_period)
431 # python2.6 in EL6 includes an internal json module
432 local json_parser='import json; import fileinput;'
433 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
434 json_parser+='json.loads([line for line in '
435 json_parser+='fileinput.input()][0]).items()])'
437 echo $raw_event | python -c "$json_parser"
440 get_agent_by_uuid_mdt() {
443 local mds=mds$(($mdtidx + 1))
444 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
448 check_agent_registered_by_mdt() {
451 local mds=mds$(($mdtidx + 1))
452 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
453 if [[ ! -z "$agent" ]]; then
454 echo "found agent $agent on $mds"
456 error "uuid $uuid not found in agent list on $mds"
460 check_agent_unregistered_by_mdt() {
463 local mds=mds$(($mdtidx + 1))
464 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
465 if [[ -z "$agent" ]]; then
466 echo "uuid not found in agent list on $mds"
468 error "uuid found in agent list on $mds: $agent"
472 check_agent_registered() {
475 for mdsno in $(seq 1 $MDSCOUNT); do
476 check_agent_registered_by_mdt $uuid $((mdsno - 1))
480 check_agent_unregistered() {
483 for mdsno in $(seq 1 $MDSCOUNT); do
484 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
489 local agent=${1:-$(facet_active_host $SINGLEAGT)}
491 # Lustre mount-point is mandatory and last parameter on
493 local mntpnt=$(do_rpc_nodes $agent \
494 pgrep --pidfile=$HSMTOOL_PID_FILE --list-full hsmtool |
496 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
498 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
504 # populate MDT device array
507 # cleanup from previous bad setup
510 # for recovery tests, coordinator needs to be started at mount
512 # the lustre conf must be without hsm on (like for sanity.sh)
513 echo "Set HSM on and start"
514 cdt_set_mount_state enabled
515 cdt_check_state enabled
517 echo "Set sanity-hsm HSM policy"
518 cdt_set_sanity_policy
520 # finished requests are quickly removed from list
521 set_hsm_param grace_delay 10
523 CLIENT_NIDS=( $($LCTL list_nids all) )
525 test_1A() { # was test_1
529 local f=$DIR/$tdir/$tfile
533 check_hsm_flags_user $f "0x00000000"
535 $RUNAS $LFS hsm_set --norelease $f ||
536 error "user could not change hsm flags"
537 check_hsm_flags_user $f "0x00000010"
539 $RUNAS $LFS hsm_clear --norelease $f ||
540 error "user could not clear hsm flags"
541 check_hsm_flags_user $f "0x00000000"
543 # User could not change those flags...
544 $RUNAS $LFS hsm_set --exists $f &&
545 error "user should not set this flag"
546 check_hsm_flags_user $f "0x00000000"
549 $LFS hsm_set --exists $f ||
550 error "root could not change hsm flags"
551 check_hsm_flags_user $f "0x00000001"
553 $LFS hsm_clear --exists $f ||
554 error "root could not clear hsm state"
555 check_hsm_flags_user $f "0x00000000"
558 run_test 1A "lfs hsm flags root/non-root access"
561 local f=$DIR/$tdir/$tfile
562 local fid=$(create_small_file $f)
566 $LFS hsm_archive $f || error "could not archive file"
567 wait_request_state $fid ARCHIVE SUCCEED
569 # Release and check states
570 $LFS hsm_release $f || error "could not release file"
571 echo -n "Verifying released state: "
572 check_hsm_flags $f "0x0000000d"
574 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
576 run_test 1a "mmap & cat a HSM released file"
582 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
583 error "failed to create file"
584 local fid=$(path2fid $f)
589 $LFS hsm_archive $f || error "could not archive file"
590 wait_request_state $fid ARCHIVE SUCCEED
593 $LFS hsm_release $f || error "could not release file"
594 echo "verify released state: "
595 check_hsm_flags $f "0x0000000d" && echo "pass"
598 $LFS hsm_restore $f || error "could not restore file"
599 wait_request_state $fid RESTORE SUCCEED
600 echo "verify restored state: "
601 check_hsm_flags $f "0x00000009" && echo "pass"
606 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
607 error "failed to set default stripe"
608 local f=$DIR/$tdir/$tfile
612 run_test 1b "Archive, Release and Restore composite file"
618 local f=$DIR/$tdir/$tfile
621 # Test whether we can set the maximum archive number.
622 local LOCAL_HSM_ARCHIVE_NUMBER=32
623 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
624 error "root could not change hsm flags"
625 check_hsm_flags_user $f "0x00000001"
626 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
627 local st=$(get_hsm_archive_id $f)
628 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
629 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
631 # Test whether setting archive number 0 results in no change.
632 $LFS hsm_set --exists --archive-id 0 $f ||
633 error "root could not change hsm flags"
634 check_hsm_flags_user $f "0x00000001"
635 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
636 st=$(get_hsm_archive_id $f)
637 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
638 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
640 LOCAL_HSM_ARCHIVE_NUMBER=33
641 if [ "$CLIENT_VERSION" -ge $(version_code 2.11.56) ] &&
642 [ "$MDS1_VERSION" -ge $(version_code 2.11.56) ]; then
643 # lustre in the new version supports unlimited archiveID.
644 # Test whether setting archive number > 32 is supported
645 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
646 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
647 check_hsm_flags_user $f "0x00000001"
649 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
650 st=$(get_hsm_archive_id $f)
651 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
652 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
654 # old client or old mds can only support at most 32 archiveID
655 # test whether setting archive number > 32 results in error.
656 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
657 error "bitmap archive number is larger than 32"
658 check_hsm_flags_user $f "0x00000001"
661 # Test whether setting archive number 16 and archived flag.
662 LOCAL_HSM_ARCHIVE_NUMBER=16
663 $LFS hsm_set --exists --archived \
664 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
665 error "root could not change hsm flags"
666 check_hsm_flags_user $f "0x00000009"
667 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
668 st=$(get_hsm_archive_id $f)
669 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
670 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
672 run_test 1c "Check setting archive-id in lfs hsm_set"
675 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
676 skip "need MDS version at least 2.10.59"
679 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
680 error "failed to set default stripe"
681 local f=$DIR/$tdir/$tfile
685 run_test 1d "Archive, Release and Restore DoM file"
688 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
689 skip "skipped for lustre < $SEL_VER"
692 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
693 error "failed to set default stripe"
694 local comp_file=$DIR/$tdir/$tfile
696 test_1bde_base $comp_file
698 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
699 local found=$($LFS find $flg_opts $comp_file | wc -l)
700 [ $found -eq 1 ] || error "1st component not found"
702 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
703 found=$($LFS find $flg_opts $comp_file | wc -l)
704 [ $found -eq 1 ] || error "2nd component not found"
706 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
707 found=$($LFS find $flg_opts $comp_file | wc -l)
708 [ $found -eq 1 ] || error "3rd component not found"
710 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
711 found=$($LFS find $flg_opts $comp_file | wc -l)
712 [ $found -eq 1 ] || error "4th component not found"
714 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
715 found=$($LFS find $flg_opts $comp_file | wc -l)
716 [ $found -eq 1 ] || error "5th component not found"
718 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
719 found=$($LFS find $flg_opts $comp_file | wc -l)
720 [ $found -eq 1 ] || error "6th component not found"
722 sel_layout_sanity $comp_file 6
724 run_test 1e "Archive, Release and Restore SEL file"
727 local f=$DIR/$tdir/$tfile
729 create_empty_file "$f"
730 # New files are not dirty
731 check_hsm_flags $f "0x00000000"
733 # For test, we simulate an archived file.
734 $LFS hsm_set --exists $f || error "user could not change hsm flags"
735 check_hsm_flags $f "0x00000001"
737 # chmod do not put the file dirty
738 chmod 600 $f || error "could not chmod test file"
739 check_hsm_flags $f "0x00000001"
741 # chown do not put the file dirty
742 chown $RUNAS_ID $f || error "could not chown test file"
743 check_hsm_flags $f "0x00000001"
745 # truncate put the file dirty
746 $TRUNCATE $f 1 || error "could not truncate test file"
747 check_hsm_flags $f "0x00000003"
749 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
750 check_hsm_flags $f "0x00000001"
752 run_test 2 "Check file dirtyness when doing setattr"
758 # New files are not dirty
760 check_hsm_flags $f "0x00000000"
762 # For test, we simulate an archived file.
763 $LFS hsm_set --exists $f ||
764 error "user could not change hsm flags"
765 check_hsm_flags $f "0x00000001"
767 # Reading a file, does not set dirty
768 cat $f > /dev/null || error "could not read file"
769 check_hsm_flags $f "0x00000001"
771 # Open for write without modifying data, does not set dirty
772 openfile -f O_WRONLY $f || error "could not open test file"
773 check_hsm_flags $f "0x00000001"
775 # Append to a file sets it dirty
776 cp -p /etc/passwd $f.append || error "could not create file"
777 $LFS hsm_set --exists $f.append ||
778 error "user could not change hsm flags"
779 dd if=/etc/passwd of=$f.append bs=1 count=3\
780 conv=notrunc oflag=append status=noxfer ||
781 file_creation_failure dd $f.append $?
782 check_hsm_flags $f.append "0x00000003"
784 # Modify a file sets it dirty
785 cp -p /etc/passwd $f.modify || error "could not create file"
786 $LFS hsm_set --exists $f.modify ||
787 error "user could not change hsm flags"
788 dd if=/dev/zero of=$f.modify bs=1 count=3\
789 conv=notrunc status=noxfer ||
790 file_creation_failure dd $f.modify $?
791 check_hsm_flags $f.modify "0x00000003"
793 # Open O_TRUNC sets dirty
794 cp -p /etc/passwd $f.trunc || error "could not create file"
795 $LFS hsm_set --exists $f.trunc ||
796 error "user could not change hsm flags"
797 cp /etc/group $f.trunc || error "could not override a file"
798 check_hsm_flags $f.trunc "0x00000003"
800 # Mmapped a file sets dirty
801 cp -p /etc/passwd $f.mmap || error "could not create file"
802 $LFS hsm_set --exists $f.mmap ||
803 error "user could not change hsm flags"
804 multiop $f.mmap OSMWUc || error "could not mmap a file"
805 check_hsm_flags $f.mmap "0x00000003"
807 run_test 3 "Check file dirtyness when opening for write"
810 local f=$DIR/$tdir/$tfile
811 local fid=$(create_small_file $f)
814 local st=$(get_request_state $fid CANCEL)
815 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
817 run_test 4 "Useless cancel must not be registered"
820 # test needs a running copytool
824 local f=$DIR/$tdir/$tfile
825 local fid=$(copy_file /etc/passwd $f)
827 wait_request_state $fid ARCHIVE SUCCEED
829 check_hsm_flags $f "0x00000009"
831 run_test 8 "Test default archive number"
833 test_9A() { # was test_9
834 # we do not use the default one to be sure
835 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
836 copytool setup --archive-id $archive_id
838 # give time for CT to register with MDTs
839 sleep $(($MDSCOUNT*2))
840 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
841 check_agent_registered $uuid
844 local f=$DIR/$tdir/$tfile
845 local fid=$(copy_file /etc/passwd $f)
846 $LFS hsm_archive --archive $archive_id $f
847 wait_request_state $fid ARCHIVE SUCCEED
849 check_hsm_flags $f "0x00000009"
851 run_test 9A "Use of explicit archive number, with dedicated copytool"
854 needclients 3 || return 0
860 # start all of the copytools
861 for n in $(seq $AGTCOUNT); do
862 copytool setup --facet agt$n
866 for n in $(seq $AGTCOUNT); do
867 file=$DIR/$tdir/$tfile.$n
868 fid=$(create_small_file $file)
870 $LFS hsm_archive $file || error "could not archive file $file"
871 wait_request_state $fid ARCHIVE SUCCEED
872 check_hsm_flags $file "0x00000009"
875 run_test 9a "Multiple remote agents"
878 # test needs a running copytool
881 mkdir -p $DIR/$tdir/d1
882 local f=$DIR/$tdir/$tfile
883 local fid=$(copy_file /etc/hosts $f)
884 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
885 error "hsm_archive failed"
886 wait_request_state $fid ARCHIVE SUCCEED
888 local hsm_root="$(copytool_device $SINGLEAGT)"
889 local archive="$(do_facet $SINGLEAGT \
890 find "$hsm_root" -name "$fid" -print0)"
891 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
893 echo "Verifying content"
894 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
895 echo "Verifying hsm state "
896 check_hsm_flags $f "0x00000009"
898 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
899 local st=$(get_hsm_archive_id $f)
900 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
901 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
903 run_test 10a "Archive a file"
906 # test needs a running copytool
910 local f=$DIR/$tdir/$tfile
911 local fid=$(copy_file /etc/hosts $f)
912 $LFS hsm_archive $f || error "archive request failed"
913 wait_request_state $fid ARCHIVE SUCCEED
915 $LFS hsm_archive $f || error "archive of non dirty file failed"
916 local cnt=$(get_request_count $fid ARCHIVE)
917 [[ "$cnt" == "1" ]] ||
918 error "archive of non dirty file must not make a request"
920 run_test 10b "Archive of non dirty file must work without doing request"
923 # test needs a running copytool
927 local f=$DIR/$tdir/$tfile
928 local fid=$(copy_file /etc/hosts $f)
929 $LFS hsm_set --noarchive $f
930 $LFS hsm_archive $f && error "archive a noarchive file must fail"
933 run_test 10c "Check forbidden archive"
936 # test needs a running copytool
940 local f=$DIR/$tdir/$tfile
941 local fid=$(copy_file /etc/hosts $f)
942 $LFS hsm_archive $f || error "cannot archive $f"
943 wait_request_state $fid ARCHIVE SUCCEED
945 local ar=$(get_hsm_archive_id $f)
946 local dflt=$(get_hsm_param default_archive_id)
947 [[ $ar == $dflt ]] ||
948 error "archived file is not on default archive: $ar != $dflt"
950 run_test 10d "Archive a file on the default archive id"
954 copy2archive /etc/hosts $tdir/$tfile
955 local f=$DIR/$tdir/$tfile
957 copytool import $tdir/$tfile $f
958 echo -n "Verifying released state: "
959 check_hsm_flags $f "0x0000000d"
961 local LSZ=$(stat -c "%s" $f)
962 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
964 echo "Verifying imported size $LSZ=$ASZ"
965 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
966 echo -n "Verifying released pattern: "
967 local PTRN=$($LFS getstripe -L $f)
969 [[ $PTRN == released ]] || error "Is not released"
970 local fid=$(path2fid $f)
971 echo "Verifying new fid $fid in archive"
973 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
974 error "No archive for fid $fid"
976 run_test 11a "Import a file"
979 # test needs a running copytool
983 local f=$DIR/$tdir/$tfile
984 local fid=$(copy_file /etc/hosts $f)
985 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
986 error "hsm_archive failed"
987 wait_request_state $fid ARCHIVE SUCCEED
989 local FILE_HASH=$(md5sum $f)
992 copytool import $fid $f
994 echo "$FILE_HASH" | md5sum -c
996 [[ $? -eq 0 ]] || error "Restored file differs"
998 run_test 11b "Import a deleted file using its FID"
1001 pool_add $TESTNAME || error "Pool creation failed"
1002 pool_add_targets $TESTNAME 1 1 || error "pool_add_targets failed"
1005 $LFS setstripe -p "$TESTNAME" $DIR/$tdir
1007 copy2archive /etc/hosts $tdir/$tfile
1008 copytool import $tdir/$tfile $DIR/$tdir/$tfile
1010 run_test 11c "Import a file to a directory with a pool"
1013 # test needs a running copytool
1017 copy2archive /etc/hosts $tdir/$tfile
1019 local f=$DIR/$tdir/$tfile
1020 copytool import $tdir/$tfile $f
1021 local f2=$DIR2/$tdir/$tfile
1022 echo "Verifying released state: "
1023 check_hsm_flags $f2 "0x0000000d"
1025 local fid=$(path2fid $f2)
1026 $LFS hsm_restore $f2
1027 wait_request_state $fid RESTORE SUCCEED
1029 echo "Verifying file state: "
1030 check_hsm_flags $f2 "0x00000009"
1032 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1034 [[ $? -eq 0 ]] || error "Restored file differs"
1036 run_test 12a "Restore an imported file explicitly"
1039 # test needs a running copytool
1043 copy2archive /etc/hosts $tdir/$tfile
1045 local f=$DIR/$tdir/$tfile
1046 copytool import $tdir/$tfile $f
1047 echo "Verifying released state: "
1048 check_hsm_flags $f "0x0000000d"
1050 cat $f > /dev/null || error "File read failed"
1052 echo "Verifying file state after restore: "
1053 check_hsm_flags $f "0x00000009"
1055 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1057 [[ $? -eq 0 ]] || error "Restored file differs"
1059 run_test 12b "Restore an imported file implicitly"
1062 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1064 # test needs a running copytool
1067 local f=$DIR/$tdir/$tfile
1069 $LFS setstripe -c 2 "$f"
1070 local fid=$(create_file "$f" 1M 5)
1072 local FILE_CRC=$(md5sum $f)
1074 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1075 wait_request_state $fid ARCHIVE SUCCEED
1076 $LFS hsm_release $f || error "release $f failed"
1078 echo "$FILE_CRC" | md5sum -c
1080 [[ $? -eq 0 ]] || error "Restored file differs"
1082 run_test 12c "Restore a file with stripe of 2"
1085 # test needs a running copytool
1090 local f=$DIR/$tdir/$tfile
1091 local fid=$(copy_file /etc/hosts $f)
1092 $LFS hsm_restore $f || error "restore of non archived file failed"
1093 local cnt=$(get_request_count $fid RESTORE)
1094 [[ "$cnt" == "0" ]] ||
1095 error "restore non archived must not make a request"
1096 $LFS hsm_archive $f ||
1097 error "archive request failed"
1098 wait_request_state $fid ARCHIVE SUCCEED
1099 $LFS hsm_restore $f ||
1100 error "restore of non released file failed"
1101 local cnt=$(get_request_count $fid RESTORE)
1102 [[ "$cnt" == "0" ]] ||
1103 error "restore a non dirty file must not make a request"
1105 run_test 12d "Restore of a non archived, non released file must work"\
1106 " without doing request"
1109 # test needs a running copytool
1113 local f=$DIR/$tdir/$tfile
1114 local fid=$(copy_file /etc/hosts $f)
1115 $LFS hsm_archive $f || error "archive request failed"
1116 wait_request_state $fid ARCHIVE SUCCEED
1119 cat /etc/hosts >> $f
1123 $LFS hsm_restore $f && error "restore a dirty file must fail"
1126 run_test 12e "Check forbidden restore"
1129 # test needs a running copytool
1133 local f=$DIR/$tdir/$tfile
1134 local fid=$(copy_file /etc/hosts $f)
1136 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1137 wait_request_state $fid ARCHIVE SUCCEED
1138 $LFS hsm_release $f || error "release of $f failed"
1140 wait_request_state $fid RESTORE SUCCEED
1142 echo -n "Verifying file state: "
1143 check_hsm_flags $f "0x00000009"
1145 diff -q /etc/hosts $f
1147 [[ $? -eq 0 ]] || error "Restored file differs"
1149 run_test 12f "Restore a released file explicitly"
1152 # test needs a running copytool
1156 local f=$DIR/$tdir/$tfile
1157 local fid=$(copy_file /etc/hosts $f)
1159 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1160 wait_request_state $fid ARCHIVE SUCCEED
1161 $LFS hsm_release $f || error "release of $f failed"
1163 diff -q /etc/hosts $f
1166 # we check we had a restore done
1167 wait_request_state $fid RESTORE SUCCEED
1169 [[ $st -eq 0 ]] || error "Restored file differs"
1171 run_test 12g "Restore a released file implicitly"
1174 needclients 2 || return 0
1176 # test needs a running copytool
1180 local f=$DIR/$tdir/$tfile
1181 local fid=$(copy_file /etc/hosts $f)
1183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1184 wait_request_state $fid ARCHIVE SUCCEED
1185 $LFS hsm_release $f || error "release of $f failed"
1187 do_node $CLIENT2 diff -q /etc/hosts $f
1190 # we check we had a restore done
1191 wait_request_state $fid RESTORE SUCCEED
1193 [[ $st -eq 0 ]] || error "Restored file differs"
1195 run_test 12h "Restore a released file implicitly from a second node"
1198 # test needs a running copytool
1202 local f=$DIR/$tdir/$tfile
1203 local fid=$(copy_file /etc/passwd $f)
1204 $LFS hsm_archive $f || error "archive of $f failed"
1205 wait_request_state $fid ARCHIVE SUCCEED
1207 $LFS hsm_release $f || error "release of $f failed"
1211 [[ $? -eq 0 ]] || error "Restored file differs"
1213 run_test 12m "Archive/release/implicit restore"
1216 # test needs a running copytool
1220 copy2archive /etc/hosts $tdir/$tfile
1222 local f=$DIR/$tdir/$tfile
1223 copytool import $tdir/$tfile $f
1225 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1226 error "Restored file differs"
1228 $LFS hsm_release $f || error "release of $f failed"
1230 run_test 12n "Import/implicit restore/release"
1233 # test needs a running copytool
1237 local f=$DIR/$tdir/$tfile
1238 local fid=$(copy_file /etc/hosts $f)
1240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1241 wait_request_state $fid ARCHIVE SUCCEED
1242 $LFS hsm_release $f || error "release of $f failed"
1244 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1245 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1247 # set no retry action mode
1250 diff -q /etc/hosts $f
1253 # we check we had a restore failure
1254 wait_request_state $fid RESTORE FAILED
1256 [[ $st -eq 0 ]] && error "Restore must fail"
1258 # remove no retry action mode
1261 # check file is still released
1262 check_hsm_flags $f "0x0000000d"
1264 # retry w/o failure injection
1265 do_facet $SINGLEMDS lctl set_param fail_loc=0
1267 # to be sure previous RESTORE result is gone
1269 wait_for_grace_delay
1271 diff -q /etc/hosts $f
1274 # we check we had a restore done
1275 wait_request_state $fid RESTORE SUCCEED
1277 [[ $st -eq 0 ]] || error "Restored file differs"
1279 run_test 12o "Layout-swap failure during Restore leaves file released"
1282 # test needs a running copytool
1286 local f=$DIR/$tdir/$tfile
1287 local fid=$(copy_file /etc/hosts $f)
1289 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1290 wait_request_state $fid ARCHIVE SUCCEED
1291 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1292 $LFS hsm_release $f || error "cannot release $f"
1293 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1294 $LFS hsm_release $f || error "cannot release $f"
1295 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1297 run_test 12p "implicit restore of a file on copytool mount point"
1300 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1301 skip "need MDS version at least 2.7.58"
1303 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1304 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1305 error "cannot mount $MOUNT3 on $SINGLEAGT"
1307 # test needs a running copytool
1308 copytool setup -m "$MOUNT3"
1310 local f=$DIR/$tdir/$tfile
1311 local f2=$DIR2/$tdir/$tfile
1312 local fid=$(create_small_file $f)
1313 local orig_size=$(stat -c "%s" $f)
1315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1316 wait_request_state $fid ARCHIVE SUCCEED
1318 $LFS hsm_release $f || error "could not release file"
1319 check_hsm_flags $f "0x0000000d"
1322 wait_copytools || error "copytool failed to stop"
1324 cat $f > /dev/null &
1326 # wait a bit to allow implicit restore request to be handled.
1327 # if not, next stat would also block on layout-lock.
1330 local size=$(stat -c "%s" $f2)
1331 [ $size -eq $orig_size ] ||
1332 error "$f2: wrong size after archive: $size != $orig_size"
1334 copytool setup -m "$MOUNT3"
1338 size=$(stat -c "%s" $f)
1339 [ $size -eq $orig_size ] ||
1340 error "$f: wrong size after restore: $size != $orig_size"
1342 size=$(stat -c "%s" $f2)
1343 [ $size -eq $orig_size ] ||
1344 error "$f2: wrong size after restore: $size != $orig_size"
1348 size=$(stat -c "%s" $f)
1350 error "$f: wrong size after overwrite: $size != 0"
1352 size=$(stat -c "%s" $f2)
1354 error "$f2: wrong size after overwrite: $size != 0"
1356 run_test 12q "file attributes are refreshed after restore"
1359 # test needs a running copytool
1363 local f=$DIR/$tdir/$tfile
1364 local fid=$(copy_file /etc/hosts $f)
1366 $LFS hsm_archive $f || error "archive of $f failed"
1367 wait_request_state $fid ARCHIVE SUCCEED
1368 $LFS hsm_release $f || error "release of $f failed"
1370 offset=$(lseek_test -d 7 $f)
1372 # we check we had a restore done
1373 wait_request_state $fid RESTORE SUCCEED
1374 [[ $offset == 7 ]] || error "offset $offset != 7"
1376 run_test 12r "lseek restores released file"
1380 for i in {1..10}; do
1381 local archive_dir="$(hsm_root)"/subdir/dir.$i
1383 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1384 for j in {1..10}; do
1385 local archive_file="$archive_dir"/file.$j
1387 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1393 copytool import "subdir" "$DIR/$tdir"
1395 # To check the import, the test uses diff with the -r flag
1396 # This is nice, but diff only checks files one by one, and triggering
1397 # an implicit restore for one file at a time will consume as many
1398 # seconds as there are files to compare. To speed this up, a restore
1399 # operation is triggered manually first.
1401 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1403 # Compare the imported data
1404 do_facet $SINGLEAGT \
1405 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1406 error "imported files differ from archived data"
1408 run_test 13 "Recursively import and restore a directory"
1411 # test needs a running copytool
1415 local f=$DIR/$tdir/$tfile
1416 local fid=$(create_small_file $f)
1417 local sum=$(md5sum $f | awk '{print $1}')
1418 $LFS hsm_archive $f || error "could not archive file"
1419 wait_request_state $fid ARCHIVE SUCCEED
1421 # create released file (simulate llapi_hsm_import call)
1422 local fid2=$(create_empty_file "$f")
1423 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1424 $LFS hsm_release $f || error "could not release file"
1426 # rebind the archive to the newly created file
1427 echo "rebind $fid to $fid2"
1429 copytool rebind $fid $fid2
1431 # restore file and compare md5sum
1432 local sum2=$(md5sum $f | awk '{print $1}')
1434 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1436 run_test 14 "Rebind archived file to a new fid"
1439 # test needs a running copytool
1443 local f=$DIR/$tdir/$tfile
1445 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1449 for i in $(seq 1 $count); do
1450 fids[$i]=$(create_small_file $f.$i)
1451 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1452 $LFS hsm_archive $f.$i || error "could not archive file"
1454 wait_all_done $(($count*60))
1456 stack_trap "rm -f $tmpfile" EXIT
1459 for i in $(seq 1 $count); do
1460 local fid2=$(create_empty_file "${f}.${i}")
1461 # add the rebind operation to the list
1462 echo ${fids[$i]} $fid2 >> $tmpfile
1464 # set it released (simulate llapi_hsm_import call)
1465 $LFS hsm_set --archived --exists $f.$i ||
1466 error "could not force hsm flags"
1467 $LFS hsm_release $f.$i || error "could not release file"
1469 nl=$(wc -l < $tmpfile)
1470 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1472 echo "rebind list of files"
1473 copytool rebind "$tmpfile"
1475 # restore files and compare md5sum
1476 for i in $(seq 1 $count); do
1477 local sum2=$(md5sum $f.$i | awk '{print $1}')
1478 [[ $sum2 == ${sums[$i]} ]] ||
1479 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1482 run_test 15 "Rebind a list of files"
1485 # test needs a running copytool
1489 # create a known size file so we can verify transfer speed
1492 dd if=/dev/zero of=$ref bs=1M count=20
1495 local f=$DIR/$tdir/$tfile
1496 local fid=$(copy_file $ref $f)
1498 local start=$(date +%s)
1500 wait_request_state $fid ARCHIVE SUCCEED
1501 local end=$(date +%s)
1502 # Add 1 to account for rounding errors between start and end (LU-8155)
1503 local duration=$((end - start + 1))
1505 [[ $duration -ge $((goal - 1)) ]] ||
1506 error "Transfer is too fast $duration < $goal"
1508 run_test 16 "Test CT bandwith control option"
1511 local f=$DIR/$tdir/$tfile
1512 create_empty_file "$f"
1514 # Could not release a non-archived file
1515 $LFS hsm_release $f && error "release should not succeed"
1517 # For following tests, we must test them with HS_ARCHIVED set
1518 $LFS hsm_set --exists --archived $f || error "could not add flag"
1520 # Could not release a file if no-release is set
1521 $LFS hsm_set --norelease $f || error "could not add flag"
1522 $LFS hsm_release $f && error "release should not succeed"
1523 $LFS hsm_clear --norelease $f || error "could not remove flag"
1525 # Could not release a file if lost
1526 $LFS hsm_set --lost $f || error "could not add flag"
1527 $LFS hsm_release $f && error "release should not succeed"
1528 $LFS hsm_clear --lost $f || error "could not remove flag"
1530 # Could not release a file if dirty
1531 $LFS hsm_set --dirty $f || error "could not add flag"
1532 $LFS hsm_release $f && error "release should not succeed"
1533 $LFS hsm_clear --dirty $f || error "could not remove flag"
1535 run_test 20 "Release is not permitted"
1538 # test needs a running copytool
1541 local f=$DIR/$tdir/test_release
1543 # Create a file and check its states
1544 local fid=$(create_small_file $f)
1545 check_hsm_flags $f "0x00000000"
1547 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1548 # used until file is flushed to disk
1549 if [ "$ost1_FSTYPE" == "zfs" ]; then
1550 # this causes an OST_SYNC rpc to be sent
1551 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1552 # clear locks to reread file data
1553 cancel_lru_locks osc
1556 local orig_size=$(stat -c "%s" $f)
1557 local orig_blocks=$(stat -c "%b" $f)
1559 start_full_debug_logging
1561 $LFS hsm_archive $f || error "could not archive file"
1562 wait_request_state $fid ARCHIVE SUCCEED
1564 local blocks=$(stat -c "%b" $f)
1565 [ $blocks -eq $orig_blocks ] ||
1566 error "$f: wrong block number after archive: " \
1567 "$blocks != $orig_blocks"
1568 local size=$(stat -c "%s" $f)
1569 [ $size -eq $orig_size ] ||
1570 error "$f: wrong size after archive: $size != $orig_size"
1572 # Release and check states
1573 $LFS hsm_release $f || error "could not release file"
1574 check_hsm_flags $f "0x0000000d"
1576 blocks=$(stat -c "%b" $f)
1577 [ $blocks -gt 5 ] &&
1578 error "$f: too many blocks after release: $blocks > 5"
1579 size=$(stat -c "%s" $f)
1580 [ $size -ne $orig_size ] &&
1581 error "$f: wrong size after release: $size != $orig_size"
1583 # Check we can release an file without stripe info
1587 check_hsm_flags $f "0x00000000"
1588 $LFS hsm_archive $f || error "could not archive file"
1589 wait_request_state $fid ARCHIVE SUCCEED
1591 # Release and check states
1592 $LFS hsm_release $f || error "could not release file"
1593 check_hsm_flags $f "0x0000000d"
1595 # Release again a file that is already released is OK
1596 $LFS hsm_release $f || fail "second release should succeed"
1597 check_hsm_flags $f "0x0000000d"
1599 stop_full_debug_logging
1601 run_test 21 "Simple release tests"
1604 # test needs a running copytool
1607 local f=$DIR/$tdir/test_release
1608 local swap=$DIR/$tdir/test_swap
1610 # Create a file and check its states
1611 local fid=$(create_small_file $f)
1612 check_hsm_flags $f "0x00000000"
1614 $LFS hsm_archive $f || error "could not archive file"
1615 wait_request_state $fid ARCHIVE SUCCEED
1617 # Release and check states
1618 $LFS hsm_release $f || error "could not release file"
1619 check_hsm_flags $f "0x0000000d"
1621 create_small_file $swap
1622 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1626 run_test 22 "Could not swap a release file"
1629 # test needs a running copytool
1632 local f=$DIR/$tdir/test_mtime
1634 # Create a file and check its states
1635 local fid=$(create_small_file $f)
1636 check_hsm_flags $f "0x00000000"
1638 $LFS hsm_archive $f || error "could not archive file"
1639 wait_request_state $fid ARCHIVE SUCCEED
1641 # Set modification time in the past
1642 touch -m -a -d @978261179 $f
1644 # Release and check states
1645 $LFS hsm_release $f || error "could not release file"
1646 check_hsm_flags $f "0x0000000d"
1648 local MTIME=$(stat -c "%Y" $f)
1649 local ATIME=$(stat -c "%X" $f)
1650 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1651 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1653 run_test 23 "Release does not change a/mtime (utime)"
1656 local file=$DIR/$tdir/$tfile
1665 # test needs a running copytool
1668 fid=$(create_small_file $file)
1670 # Create a file and check its states
1671 check_hsm_flags $file "0x00000000"
1673 # Ensure atime is less than mtime and ctime.
1677 atime0=$(stat -c "%X" $file)
1678 mtime0=$(stat -c "%Y" $file)
1679 ctime0=$(stat -c "%Z" $file)
1681 [ $atime0 -lt $mtime0 ] ||
1682 error "atime $atime0 is not less than mtime $mtime0"
1684 [ $atime0 -lt $ctime0 ] ||
1685 error "atime $atime0 is not less than ctime $ctime0"
1687 # Archive should not change any timestamps.
1688 $LFS hsm_archive $file || error "cannot archive '$file'"
1689 wait_request_state $fid ARCHIVE SUCCEED
1691 atime1=$(stat -c "%X" $file)
1692 mtime1=$(stat -c "%Y" $file)
1693 ctime1=$(stat -c "%Z" $file)
1695 [ $atime0 -eq $atime1 ] ||
1696 error "archive changed atime from $atime0 to $atime1"
1698 [ $mtime0 -eq $mtime1 ] ||
1699 error "archive changed mtime from $mtime0 to $mtime1"
1701 [ $ctime0 -eq $ctime1 ] ||
1702 error "archive changed ctime from $ctime0 to $ctime1"
1704 # Release should not change any timestamps.
1705 $LFS hsm_release $file || error "cannot release '$file'"
1706 check_hsm_flags $file "0x0000000d"
1708 atime1=$(stat -c "%X" $file)
1709 mtime1=$(stat -c "%Y" $file)
1710 ctime1=$(stat -c "%Z" $file)
1712 [ $atime0 -eq $atime1 ] ||
1713 error "release changed atime from $atime0 to $atime1"
1715 [ $mtime0 -eq $mtime1 ] ||
1716 error "release changed mtime from $mtime0 to $mtime1"
1718 [ $ctime0 -eq $ctime1 ] ||
1719 error "release changed ctime from $ctime0 to $ctime1"
1721 # Restore should not change any timestamps.
1722 $LFS hsm_restore $file
1723 wait_request_state $fid RESTORE SUCCEED
1725 atime1=$(stat -c "%X" $file)
1726 mtime1=$(stat -c "%Y" $file)
1727 ctime1=$(stat -c "%Z" $file)
1729 [ $atime0 -eq $atime1 ] ||
1730 error "restore changed atime from $atime0 to $atime1"
1732 [ $mtime0 -eq $mtime1 ] ||
1733 error "restore changed mtime from $mtime0 to $mtime1"
1735 [ $ctime0 -eq $ctime1 ] ||
1736 error "restore changed ctime from $ctime0 to $ctime1"
1739 wait_copytools || error "Copytools failed to stop"
1741 # Once more, after unmount and mount.
1742 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1743 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1745 atime1=$(stat -c "%X" $file)
1746 mtime1=$(stat -c "%Y" $file)
1747 ctime1=$(stat -c "%Z" $file)
1749 [ $atime0 -eq $atime1 ] ||
1750 error "remount changed atime from $atime0 to $atime1"
1752 [ $mtime0 -eq $mtime1 ] ||
1753 error "remount changed mtime from $mtime0 to $mtime1"
1755 [ $ctime0 -eq $ctime1 ] ||
1756 error "remount changed ctime from $ctime0 to $ctime1"
1758 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1761 local file=$DIR/$tdir/$tfile
1767 # Test needs a running copytool.
1770 # Check that root can do HSM actions on a regular user's file.
1771 fid=$(create_small_file $file)
1772 sum0=$(md5sum $file)
1774 chown $RUNAS_ID:$RUNAS_GID $file ||
1775 error "cannot chown '$file' to '$RUNAS_ID'"
1777 chmod ugo-w $DIR/$tdir ||
1778 error "cannot chmod '$DIR/$tdir'"
1780 $LFS hsm_archive $file
1781 wait_request_state $fid ARCHIVE SUCCEED
1783 $LFS hsm_release $file
1784 check_hsm_flags $file "0x0000000d"
1786 $LFS hsm_restore $file
1787 wait_request_state $fid RESTORE SUCCEED
1789 # Check that ordinary user can get HSM state.
1790 $RUNAS $LFS hsm_state $file ||
1791 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1793 $LFS hsm_release $file
1794 check_hsm_flags $file "0x0000000d"
1796 # Check that ordinary user can accessed released file.
1797 sum1=$($RUNAS md5sum $file) ||
1798 error "user '$RUNAS_ID' cannot read '$file'"
1800 [ "$sum0" == "$sum1" ] ||
1801 error "md5sum mismatch for '$file'"
1803 run_test 24b "root can archive, release, and restore user files"
1806 local file=$DIR/$tdir/$tfile
1807 local action=archive
1812 # test needs a running copytool
1817 # Save the default masks and check that cleanup_24c will
1818 # restore the request masks correctly.
1819 user_save=$(get_hsm_param user_request_mask)
1820 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1821 group_save=$(get_hsm_param group_request_mask)
1822 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1823 other_save=$(get_hsm_param other_request_mask)
1824 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1826 [ "$user_save" == RESTORE ] ||
1827 error "user_request_mask is '$user_save' expected 'RESTORE'"
1828 [ "$group_save" == RESTORE ] ||
1829 error "group_request_mask is '$group_save' expected 'RESTORE'"
1830 [ "$other_save" == RESTORE ] ||
1831 error "other_request_mask is '$other_save' expected 'RESTORE'"
1834 create_small_file $file
1835 chown $RUNAS_ID:$GROUP $file ||
1836 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1838 $RUNAS $LFS hsm_$action $file &&
1839 error "$action by user should fail"
1841 set_hsm_param user_request_mask $action
1842 $RUNAS $LFS hsm_$action $file ||
1843 error "$action by user should succeed"
1846 create_small_file $file
1847 chown nobody:$RUNAS_GID $file ||
1848 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1850 $RUNAS $LFS hsm_$action $file &&
1851 error "$action by group should fail"
1853 set_hsm_param group_request_mask $action
1854 $RUNAS $LFS hsm_$action $file ||
1855 error "$action by group should succeed"
1858 create_small_file $file
1859 chown nobody:$GROUP $file ||
1860 error "cannot chown '$file' to 'nobody:$GROUP'"
1862 $RUNAS $LFS hsm_$action $file &&
1863 error "$action by other should fail"
1865 set_hsm_param other_request_mask $action
1866 $RUNAS $LFS hsm_$action $file ||
1867 error "$action by other should succeed"
1869 run_test 24c "check that user,group,other request masks work"
1872 local file1=$DIR/$tdir/$tfile
1873 local file2=$DIR2/$tdir/$tfile
1877 fid1=$(create_small_file $file1)
1880 $LFS getstripe $file1
1882 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1883 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1884 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1886 copytool setup -m "$MOUNT3"
1888 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1889 mount -o remount,ro $MOUNT2
1891 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1893 fid2=$(path2fid $file2)
1894 [ "$fid1" == "$fid2" ] ||
1895 error "FID mismatch '$fid1' != '$fid2'"
1897 $LFS hsm_archive $file2 &&
1898 error "archive should fail on read-only mount"
1899 check_hsm_flags $file1 "0x00000000"
1901 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1902 wait_request_state $fid1 ARCHIVE SUCCEED
1904 $LFS hsm_release $file1
1905 $LFS hsm_restore $file2
1906 wait_request_state $fid1 RESTORE SUCCEED
1908 $LFS hsm_release $file1 || error "cannot release '$file1'"
1909 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1911 $LFS hsm_release $file2 &&
1912 error "release should fail on read-only mount"
1916 run_test 24d "check that read-only mounts are respected"
1921 local f=$DIR/$tdir/$tfile
1924 fid=$(create_small_file $f) || error "cannot create $f"
1925 $LFS hsm_archive $f || error "cannot archive $f"
1926 wait_request_state $fid ARCHIVE SUCCEED
1927 $LFS hsm_release $f || error "cannot release $f"
1928 while ! $LFS hsm_state $f | grep released; do
1932 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1934 run_test 24e "tar succeeds on HSM released files" # LU-6213
1937 # test needs a running copytool
1940 mkdir -p $DIR/$tdir/d1
1941 local f=$DIR/$tdir/$tfile
1942 local fid=$(copy_file /etc/hosts $f)
1945 $LFS hsm_archive $f ||
1946 error "hsm_archive failed"
1947 wait_request_state $fid ARCHIVE SUCCEED
1948 $LFS hsm_release $f || error "cannot release $f"
1949 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1952 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1953 error "Can not recover the tar contents"
1955 echo "Sum0 = $sum0, sum1 = $sum1"
1956 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1958 run_test 24f "root can archive, release, and restore tar files"
1961 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1962 skip "need MDS version 2.11.56 or later"
1964 local file=$DIR/$tdir/$tfile
1967 echo "RUNAS = '$RUNAS'"
1972 chmod ugo+rwx $DIR/$tdir
1974 echo "Please listen carefully as our options have changed." | tee $file
1975 fid=$(path2fid $file)
1978 $LFS hsm_archive $file
1979 wait_request_state $fid ARCHIVE SUCCEED
1980 check_hsm_flags $file 0x00000009 # exists archived
1982 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
1983 check_hsm_flags $file 0x0000000b # exists dirty archived
1985 run_test 24g "write by non-owner still sets dirty" # LU-11369
1988 # test needs a running copytool
1992 copy2archive /etc/hosts $tdir/$tfile
1994 local f=$DIR/$tdir/$tfile
1996 copytool import $tdir/$tfile $f
1998 $LFS hsm_set --lost $f
2003 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2005 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2006 " (Operation not permitted)"
2009 # test needs a running copytool
2014 local f=$DIR/$tdir/$tfile
2015 local fid=$(copy_file /etc/passwd $f)
2017 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2018 wait_request_state $fid ARCHIVE SUCCEED
2021 $LFS hsm_set --lost $f
2025 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2027 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2028 " (Operation not permitted)"
2030 test_26A() { # was test_26
2031 # test needs a running copytool
2034 local f=$DIR/$tdir/$tfile
2035 local fid=$(create_empty_file "$f")
2037 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2038 wait_request_state $fid ARCHIVE SUCCEED
2041 wait_request_state $fid REMOVE SUCCEED
2043 check_hsm_flags $f "0x00000000"
2045 run_test 26A "Remove the archive of a valid file"
2048 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2049 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2051 # test needs a running copytool
2055 local f=$DIR/$tdir/$tfile
2056 local fid=$(copy_file /etc/passwd $f)
2058 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2059 wait_request_state $fid ARCHIVE SUCCEED
2061 local f2=$DIR/$tdir/${tfile}_2
2062 local fid2=$(copy_file /etc/passwd $f2)
2064 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2065 wait_request_state $fid2 ARCHIVE SUCCEED
2067 local f3=$DIR/$tdir/${tfile}_3
2068 local fid3=$(copy_file /etc/passwd $f3)
2070 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2071 wait_request_state $fid3 ARCHIVE SUCCEED
2073 # set a long grace_delay vs short loop_period
2074 local orig_loop_period=$(get_hsm_param loop_period)
2075 local orig_grace_delay=$(get_hsm_param grace_delay)
2076 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2077 set_hsm_param loop_period 10
2078 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2079 set_hsm_param grace_delay 100
2083 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2084 set_hsm_param remove_archive_on_last_unlink 1
2086 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2091 wait_request_state $fid2 REMOVE SUCCEED
2093 assert_request_count $fid REMOVE 0 \
2094 "Unexpected archived data remove request for $f"
2095 assert_request_count $fid3 REMOVE 0 \
2096 "Unexpected archived data remove request for $f3"
2098 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2101 # test needs a running copytool
2105 local f=$DIR/$tdir/$tfile
2106 local fid=$(copy_file /etc/passwd $f)
2108 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2109 wait_request_state $fid ARCHIVE SUCCEED
2111 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2112 set_hsm_param remove_archive_on_last_unlink 1
2115 cdt_check_state stopped
2119 wait_request_state $fid REMOVE WAITING
2123 # copytool must re-register
2125 wait_copytools || error "copytool failed to stop"
2128 wait_request_state $fid REMOVE SUCCEED
2130 run_test 26b "RAoLU policy when CDT off"
2133 # test needs a running copytool
2137 local f=$DIR/$tdir/$tfile
2138 local fid=$(copy_file /etc/passwd $f)
2140 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2141 wait_request_state $fid ARCHIVE SUCCEED
2143 local f2=$DIR/$tdir/${tfile}_2
2144 local fid2=$(copy_file /etc/passwd $f2)
2146 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2147 wait_request_state $fid2 ARCHIVE SUCCEED
2149 # set a long grace_delay vs short loop_period
2150 local orig_loop_period=$(get_hsm_param loop_period)
2151 local orig_grace_delay=$(get_hsm_param grace_delay)
2152 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2153 set_hsm_param loop_period 10
2154 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2155 set_hsm_param grace_delay 100
2157 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2158 set_hsm_param remove_archive_on_last_unlink 1
2160 multiop_bg_pause $f O_c || error "open $f failed"
2166 wait_request_state $fid2 REMOVE SUCCEED
2167 assert_request_count $fid REMOVE 0 \
2168 "Unexpected archived data remove request for $f"
2170 kill -USR1 $pid || error "multiop early exit"
2171 # should reach autotest timeout if multiop fails to trap
2172 # signal, close file, and exit ...
2173 wait $pid || error "wait PID $PID failed"
2175 wait_request_state $fid REMOVE SUCCEED
2177 run_test 26c "RAoLU effective when file closed"
2180 # test needs a running copytool
2184 local f=$DIR/$tdir/$tfile
2185 local fid=$(create_small_file $f)
2187 $LFS hsm_archive $f || error "could not archive file"
2188 wait_request_state $fid ARCHIVE SUCCEED
2190 # set a long grace_delay vs short loop_period
2191 local orig_loop_period=$(get_hsm_param loop_period)
2192 local orig_grace_delay=$(get_hsm_param grace_delay)
2193 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2194 set_hsm_param loop_period 10
2195 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2196 set_hsm_param grace_delay 100
2198 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2199 set_hsm_param remove_archive_on_last_unlink 1
2201 multiop_bg_pause $f O_c || error "multiop failed"
2208 wait_request_state $fid REMOVE SUCCEED
2210 client_up || client_up || true
2212 kill -USR1 $MULTIPID
2213 wait $MULTIPID || error "multiop close failed"
2215 run_test 26d "RAoLU when Client eviction"
2218 # test needs a running copytool
2221 create_archive_file $tdir/$tfile
2222 local f=$DIR/$tdir/$tfile
2223 copytool import $tdir/$tfile $f
2224 local fid=$(path2fid $f)
2228 [[ $? != 0 ]] || error "Remove of a released file should fail"
2230 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2233 # test needs a running copytool
2236 local f=$DIR/$tdir/$tfile
2237 local fid=$(create_empty_file "$f")
2239 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2240 wait_request_state $fid ARCHIVE SUCCEED
2245 [[ $? != 0 ]] || error "Remove of a released file should fail"
2247 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2250 # test needs a running copytool
2253 local f=$DIR/$tdir/$tfile
2254 local fid=$(create_empty_file "$f")
2256 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2257 wait_request_state $fid ARCHIVE SUCCEED
2266 wait_request_state $fid REMOVE SUCCEED
2268 run_test 28 "Concurrent archive/file remove"
2271 # Tests --mntpath and --archive options
2274 copytool setup -m "$MOUNT" -a $archive_id
2276 # Bad archive number
2277 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2278 grep "Invalid argument" ||
2279 error "unexpected hsm_remove failure (1)"
2281 # mntpath is present but file is given
2282 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2283 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2284 error "unexpected hsm_remove failure (2)"
2286 run_test 29a "Tests --mntpath and --archive options"
2289 # test needs a running copytool
2292 local f=$DIR/$tdir/$tfile
2293 local fid=$(create_small_file $f)
2295 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2296 wait_request_state $fid ARCHIVE SUCCEED
2300 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2301 wait_request_state $fid REMOVE SUCCEED
2303 run_test 29b "Archive/delete/remove by FID from the archive."
2306 # test needs a running copytool
2309 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2310 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2311 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2313 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2314 wait_request_state $fid1 ARCHIVE SUCCEED
2315 wait_request_state $fid2 ARCHIVE SUCCEED
2316 wait_request_state $fid3 ARCHIVE SUCCEED
2318 rm -f $DIR/$tdir/$tfile-[1-3]
2320 echo $fid1 > $DIR/$tdir/list
2321 echo $fid2 >> $DIR/$tdir/list
2322 echo $fid3 >> $DIR/$tdir/list
2324 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2325 --filelist $DIR/$tdir/list
2326 wait_request_state $fid1 REMOVE SUCCEED
2327 wait_request_state $fid2 REMOVE SUCCEED
2328 wait_request_state $fid3 REMOVE SUCCEED
2330 run_test 29c "Archive/delete/remove by FID, using a file list."
2333 # test needs more than one CT
2334 needclients 3 || return 0
2340 # start all of the copytools
2341 for n in $(seq $AGTCOUNT); do
2342 copytool setup -f agt$n -a $n
2346 file=$DIR/$tdir/$tfile
2347 fid=$(create_small_file $file)
2349 $LFS hsm_archive $file
2350 wait_request_state $fid ARCHIVE SUCCEED
2351 check_hsm_flags $file "0x00000009"
2355 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2356 error "cannot hsm_remove '$fid'"
2358 # give time for CDT to handle remove request and create broadcasted
2361 # remove request has been broadcasted ?
2362 local cnt=$(get_request_count $fid REMOVE)
2363 # broadcasted requests + original
2364 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2365 error "remove not broadcasted to all CTs"
2367 # give time for CDT and CTs to handle broadcasted
2368 wait_for_loop_period
2370 # each agent serves one different archive_id, so broadcasted
2371 # hsm_remove request should only succeed once and fail at all others
2375 for n in $(seq $AGTCOUNT); do
2376 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2377 $HSM_PARAM.actions | awk \
2378 '/'$fid'.*action=REMOVE archive#='$n'/ \
2379 {print \\\$13}' | cut -f2 -d=")
2380 if [[ "$res" == "SUCCEED" ]]; then
2382 elif [[ "$res" == "FAILED" ]]; then
2387 [[ $scnt -eq 1 ]] ||
2388 error "one and only CT should have removed successfully"
2390 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2391 error "all but one CT should have failed to remove"
2393 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2394 "request to be sent once for each registered archive_id"
2397 # restore at exec cannot work on agent node (because of Linux kernel
2398 # protection of executables)
2399 needclients 2 || return 0
2401 # test needs a running copytool
2405 copy2archive /bin/true $tdir/$tfile
2407 local f=$DIR/$tdir/true
2408 copytool import $tdir/$tfile $f
2410 local fid=$(path2fid $f)
2412 stack_trap "cdt_clear_no_retry" EXIT
2413 # set no retry action mode
2420 [[ $st == 0 ]] || error "Failed to exec a released file"
2422 run_test 30a "Restore at exec (import case)"
2425 # restore at exec cannot work on agent node (because of Linux kernel
2426 # protection of executables)
2427 needclients 2 || return 0
2429 # test needs a running copytool
2433 local f=$DIR/$tdir/true
2434 local fid=$(copy_file /bin/true $f)
2436 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2437 wait_request_state $fid ARCHIVE SUCCEED
2441 stack_trap cdt_clear_no_retry EXIT
2442 # set no retry action mode
2450 [[ $st == 0 ]] || error "Failed to exec a released file"
2452 run_test 30b "Restore at exec (release case)"
2455 needclients 2 || return 0
2457 # test needs a running copytool
2461 local f=$DIR/$tdir/SLEEP
2462 local slp_sum1=$(md5sum /bin/sleep)
2463 local fid=$(copy_file /bin/sleep $f)
2465 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2466 wait_request_state $fid ARCHIVE SUCCEED
2468 check_hsm_flags $f "0x0000000d"
2470 stack_trap cdt_clear_no_retry EXIT
2471 # set no retry action mode
2474 do_node $CLIENT2 "$f 10" &
2478 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2480 [[ $? == 0 ]] || error "Execution failed during run"
2482 if [[ $? != 0 ]]; then
2483 local slp_sum2=$(md5sum /bin/sleep)
2484 # in case sleep file is modified during the test
2485 [[ $slp_sum1 == $slp_sum2 ]] &&
2486 error "Binary overwritten during exec"
2489 check_hsm_flags $f "0x00000009"
2491 run_test 30c "Update during exec of released file must fail"
2493 restore_and_check_size() {
2496 local s=$(stat -c "%s" $f)
2498 local st=$(get_hsm_flags $f)
2502 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2504 n=$(stat -c "%s" $f)
2505 # we echo in both cases to show stat is not hang
2506 if [[ $n != $s ]]; then
2507 echo "size seen is $n != $s"
2510 echo "size seen is right: $n == $s"
2514 st=$(get_hsm_flags $f)
2516 if [[ "$st" = "0x00000009" ]]; then
2519 echo " restore is too long"
2520 wait_request_state $fid RESTORE SUCCEED
2526 # test needs a running copytool
2529 create_archive_file $tdir/$tfile
2530 local f=$DIR/$tdir/$tfile
2531 copytool import $tdir/$tfile $f
2532 local fid=$($LFS path2fid $f)
2535 restore_and_check_size $f $fid
2538 [[ $err -eq 0 ]] || error "File size changed during restore"
2540 run_test 31a "Import a large file and check size during restore"
2544 # test needs a running copytool
2547 local f=$DIR/$tdir/$tfile
2548 local fid=$(create_file "$f" 1MB 39)
2550 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2551 wait_request_state $fid ARCHIVE SUCCEED
2554 restore_and_check_size $f $fid
2557 [[ $err -eq 0 ]] || error "File size changed during restore"
2559 run_test 31b "Restore a large unaligned file and check size during restore"
2562 # test needs a running copytool
2565 local f=$DIR/$tdir/$tfile
2566 local fid=$(create_file "$f" 1M 39)
2568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2569 wait_request_state $fid ARCHIVE SUCCEED
2572 restore_and_check_size $f $fid
2575 [[ $err -eq 0 ]] || error "File size changed during restore"
2577 run_test 31c "Restore a large aligned file and check size during restore"
2580 local f=$DIR/$tdir/$tfile
2581 local fid=$(create_empty_file "$f")
2585 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2586 wait_request_state $fid ARCHIVE SUCCEED
2589 # Prevent restore from completing
2593 md5sum $f >/dev/null &
2596 wait_request_state $fid RESTORE STARTED
2601 # Check restore trigger process was killed
2603 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2605 run_test 33 "Kill a restore waiting process"
2608 # test needs a running copytool
2611 local f=$DIR/$tdir/$tfile
2612 local fid=$(create_empty_file "$f")
2614 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2615 wait_request_state $fid ARCHIVE SUCCEED
2618 # Prevent restore from completing
2621 md5sum $f >/dev/null &
2624 wait_request_state $fid RESTORE STARTED
2626 # rm must not block during restore
2627 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2630 wait_request_state $fid RESTORE SUCCEED
2632 # Check md5sum pgm finished
2633 kill -0 $pid && error "Restore initiatior still running"
2634 wait $pid || error "Restore initiator failed with $?"
2636 # Check the file was actually deleted
2637 [ ! -f "$f" ] || error "$f was not deleted"
2639 run_test 34 "Remove file during restore"
2642 # test needs a running copytool
2645 local f=$DIR/$tdir/$tfile
2646 local f1=$DIR/$tdir/$tfile-1
2647 local fid=$(create_empty_file "$f")
2648 local fid1=$(copy_file /etc/passwd $f1)
2650 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2651 wait_request_state $fid ARCHIVE SUCCEED
2654 # Prevent restore from completing
2657 md5sum $f >/dev/null &
2660 wait_request_state $fid RESTORE STARTED
2662 # mv must not block during restore
2663 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2666 wait_request_state $fid RESTORE SUCCEED
2668 # Check md5sum pgm finished
2669 kill -0 $pid && error "Restore initiatior still running"
2670 wait $pid || error "Restore initiator failed with $?"
2672 local fid2=$(path2fid $f)
2673 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2675 run_test 35 "Overwrite file during restore"
2678 # test needs a running copytool
2681 local f=$DIR/$tdir/$tfile
2682 local fid=$(create_empty_file "$f")
2684 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2685 wait_request_state $fid ARCHIVE SUCCEED
2688 # Prevent restore from completing
2691 md5sum $f >/dev/null &
2694 wait_request_state $fid RESTORE STARTED
2696 # mv must not block during restore
2697 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2698 error "mv '$f' '$f.new' failed with rc=$?"
2701 wait_request_state $fid RESTORE SUCCEED
2703 # Check md5sum pgm finished
2704 kill -0 $pid && error "Restore initiator is still running"
2705 wait $pid || error "Restore initiator failed with $?"
2707 run_test 36 "Move file during restore"
2710 # LU-5683: check that an archived dirty file can be rearchived.
2713 local f=$DIR/$tdir/$tfile
2716 fid=$(create_small_file $f) || error "cannot create small file"
2718 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2719 wait_request_state $fid ARCHIVE SUCCEED
2720 $LFS hsm_release $f || error "cannot release $f"
2722 # Allow previous archive request to expire from the actions log.
2723 wait_for_grace_delay
2726 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2728 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2729 wait_request_state $fid ARCHIVE SUCCEED
2731 run_test 37 "re-archive a dirty file"
2738 for n in $(seq 1 $count); do
2739 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2741 echo "$count archive requests submitted"
2745 local stream_count=4
2746 local file_count=100
2748 local f=$DIR/$tdir/$tfile
2752 local max_requests=$(get_hsm_param max_requests)
2754 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2755 # Increase the number of HSM request that can be performed in
2756 # parallel. With the coordinator running once per second, this
2757 # also limits the number of requests per seconds that can be
2758 # performed, so we pick a decent number. But we also need to keep
2759 # that number low because the copytool has no rate limit and will
2760 # fail some requests if if gets too many at once.
2761 set_hsm_param max_requests 300
2763 for i in $(seq 1 $file_count); do
2764 for p in $(seq 1 $stream_count); do
2765 fid=$(copy_file /etc/hosts $f.$p.$i)
2771 # to be sure wait_all_done will not be mislead by previous tests
2773 wait_for_grace_delay
2775 # start archive streams in background (archive files in parallel)
2776 for p in $(seq 1 $stream_count); do
2777 multi_archive $f.$p $file_count &
2780 echo -n "Wait for all requests being enqueued..."
2785 run_test 40 "Parallel archive requests"
2788 # test needs a running copytool
2792 local f=$DIR/$tdir/$tfile
2793 local fid=$(create_small_file $f)
2795 $LFS hsm_archive $f || error "could not archive file"
2796 wait_request_state $fid ARCHIVE SUCCEED
2797 check_hsm_flags $f "0x00000009"
2799 multiop_bg_pause $f O_c || error "multiop failed"
2803 client_up || client_up || true
2805 kill -USR1 $MULTIPID
2806 wait $MULTIPID || error "multiop close failed"
2808 check_hsm_flags $f "0x0000000b"
2810 run_test 52 "Opened for write file on an evicted client should be set dirty"
2813 # test needs a running copytool
2817 local f=$DIR/$tdir/$tfile
2818 local fid=$(create_small_file $f)
2820 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2821 error "could not archive file"
2822 wait_request_state $fid ARCHIVE SUCCEED
2823 check_hsm_flags $f "0x00000009"
2825 multiop_bg_pause $f o_c || error "multiop failed"
2829 client_up || client_up || true
2831 kill -USR1 $MULTIPID
2832 wait $MULTIPID || error "multiop close failed"
2834 check_hsm_flags $f "0x00000009"
2836 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2839 local f=$DIR/$tdir/$tfile
2840 local fid=$(create_file "$f" 1MB 39)
2844 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2845 error "could not archive file"
2846 wait_request_state $fid ARCHIVE STARTED
2848 check_hsm_flags $f "0x00000001"
2850 stack_trap "cdt_clear_no_retry" EXIT
2851 # Avoid coordinator resending this request as soon it has failed.
2856 wait_request_state $fid ARCHIVE FAILED
2858 check_hsm_flags $f "0x00000003"
2860 run_test 54 "Write during an archive cancels it"
2863 local f=$DIR/$tdir/$tfile
2864 local fid=$(create_file "$f" 1MB 39)
2868 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2869 error "could not archive file"
2870 wait_request_state $fid ARCHIVE STARTED
2872 check_hsm_flags $f "0x00000001"
2874 stack_trap "cdt_clear_no_retry" EXIT
2875 # Avoid coordinator resending this request as soon it has failed.
2878 $TRUNCATE $f 1024 || error "truncate failed"
2880 wait_request_state $fid ARCHIVE FAILED
2882 check_hsm_flags $f "0x00000003"
2884 run_test 55 "Truncate during an archive cancels it"
2887 local f=$DIR/$tdir/$tfile
2888 local fid=$(create_file "$f" 1MB 39)
2892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2893 error "could not archive file"
2894 wait_request_state $fid ARCHIVE STARTED
2896 check_hsm_flags $f "0x00000001"
2898 # Change metadata and sync to be sure we are not changing only
2903 wait_request_state $fid ARCHIVE SUCCEED
2905 check_hsm_flags $f "0x00000009"
2907 run_test 56 "Setattr during an archive is ok"
2910 # Need one client for I/O, one for request
2911 needclients 2 || return 0
2913 # test needs a running copytool
2917 local f=$DIR/$tdir/test_archive_remote
2918 # Create a file on a remote node
2919 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2920 "count=2 conv=fsync"
2923 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2924 error "hsm_archive failed"
2925 local fid=$(path2fid $f)
2926 wait_request_state $fid ARCHIVE SUCCEED
2928 # Release and implicit restore it
2929 do_node $CLIENT2 "$LFS hsm_release $f" ||
2930 error "hsm_release failed"
2931 do_node $CLIENT2 "md5sum $f" ||
2932 error "hsm_restore failed"
2934 wait_request_state $fid RESTORE SUCCEED
2936 run_test 57 "Archive a file with dirty cache on another node"
2938 truncate_released_file() {
2942 local sz=$(stat -c %s $src_file)
2943 local f=$DIR/$tdir/$tfile
2944 local fid=$(copy_file $1 $f)
2948 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2949 error "could not archive file"
2950 wait_request_state $fid ARCHIVE SUCCEED
2952 $LFS hsm_release $f || error "could not release file"
2954 $TRUNCATE $f $trunc_to || error "truncate failed"
2957 local sz1=$(stat -c %s $f)
2958 [[ $sz1 == $trunc_to ]] ||
2959 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2962 check_hsm_flags $f "0x0000000b"
2964 local state=$(get_request_state $fid RESTORE)
2965 [[ "$state" == "SUCCEED" ]] ||
2966 error "truncate $sz does not trig restore, state = $state"
2968 $TRUNCATE $ref $trunc_to
2969 cmp $ref $f || error "file data wrong after truncate"
2975 # test needs a running copytool
2980 local sz=$(stat -c %s /etc/passwd)
2982 echo "truncate up from $sz to $((sz*2))"
2983 truncate_released_file /etc/passwd $((sz*2))
2985 echo "truncate down from $sz to $((sz/2))"
2986 truncate_released_file /etc/passwd $((sz/2))
2988 echo "truncate to 0"
2989 truncate_released_file /etc/passwd 0
2991 run_test 58 "Truncate a released file will trigger restore"
2995 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
2996 skip "Need MDS version at least 2.7.63"
2999 $MCREATE $DIR/$tfile || error "mcreate failed"
3000 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3001 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3002 fid=$(path2fid $DIR/$tfile)
3003 wait_request_state $fid ARCHIVE SUCCEED
3004 $LFS hsm_release $DIR/$tfile || error "release failed"
3006 run_test 59 "Release stripeless file with non-zero size"
3009 # This test validates the fix for LU-4512. Ensure that the -u
3010 # option changes the progress reporting interval from the
3011 # default (30 seconds) to the user-specified interval.
3012 local f=$DIR/$tdir/$tfile
3013 local fid=$(create_file "$f" 1M 10)
3016 local progress_timeout=$((interval * 4))
3017 copytool setup -b 1 --update-interval $interval
3020 local mdt=${MDT_PREFIX}${mdtidx}
3021 local mds=mds$((mdtidx + 1))
3023 # Wait for copytool to register
3024 wait_update_facet $mds \
3025 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3026 uuid 100 || error "coyptool failed to register with $mdt"
3028 local start_at=$(date +%s)
3029 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3030 error "could not archive file"
3032 local agent=$(facet_active_host $SINGLEAGT)
3033 local logfile=$(copytool_logfile $SINGLEAGT)
3035 wait_update $agent \
3036 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3037 error "copytool failed to start"
3039 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3040 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3046 echo -n "Expecting a progress update within $progress_timeout seconds... "
3048 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3049 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3050 echo "$RESULT bytes copied in $WAIT seconds."
3052 elif [ $WAIT -ge $progress_timeout ]; then
3053 error "Timed out waiting for progress update!"
3056 WAIT=$((WAIT + sleep))
3060 local finish_at=$(date +%s)
3061 local elapsed=$((finish_at - start_at))
3063 # Ensure that the progress update occurred within the expected window.
3064 if [ $elapsed -lt $((interval - 1)) ]; then
3065 error "Expected progress update after at least $interval seconds"
3068 echo "Wait for on going archive hsm action to complete"
3069 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3070 echo "File archiving not completed even after 10 secs"
3072 run_test 60 "Changing progress update interval from default"
3075 # test needs a running copytool
3079 local f=$DIR/$tdir/$tfile
3080 local fid=$(copy_file /etc/passwd $f)
3082 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3085 wait_request_state $fid ARCHIVE FAILED
3087 run_test 61 "Waiting archive of a removed file should fail"
3090 # test needs a new running copytool
3091 stack_trap copytool_monitor_cleanup EXIT
3092 copytool_monitor_setup
3093 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3095 # Wait for the copytool to register.
3096 wait_update --verbose $(facet_active_host mds1) \
3097 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3099 error "copytool failed to register with MDT0000"
3102 wait_copytools || error "Copytools failed to stop"
3104 local REGISTER_EVENT
3105 local UNREGISTER_EVENT
3106 while read event; do
3107 local parsed=$(parse_json_event "$event")
3108 if [ -z "$parsed" ]; then
3109 error "Copytool sent malformed event: $event"
3113 if [ $event_type == "REGISTER" ]; then
3114 REGISTER_EVENT=$event
3115 elif [ $event_type == "UNREGISTER" ]; then
3116 UNREGISTER_EVENT=$event
3118 done < <(echo $"$(get_copytool_event_log)")
3120 if [ -z "$REGISTER_EVENT" ]; then
3121 error "Copytool failed to send register event to FIFO"
3124 if [ -z "$UNREGISTER_EVENT" ]; then
3125 error "Copytool failed to send unregister event to FIFO"
3128 echo "Register/Unregister events look OK."
3130 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3133 # Bump progress interval for livelier events.
3136 # test needs a new running copytool
3137 stack_trap copytool_monitor_cleanup EXIT
3138 copytool_monitor_setup
3139 copytool setup --update-interval $interval --event-fifo \
3140 "$HSMTOOL_MONITOR_DIR/fifo"
3142 stack_trap "cdt_clear_no_retry" EXIT
3143 # Just start and stop the copytool to generate events.
3146 local f=$DIR/$tdir/$tfile
3147 local fid=$(create_small_file "$f")
3149 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3150 error "could not archive file"
3151 wait_request_state $fid ARCHIVE SUCCEED
3153 local expected_fields="event_time data_fid source_fid"
3154 expected_fields+=" total_bytes current_bytes"
3157 [ARCHIVE_START]=false
3158 [ARCHIVE_FINISH]=false
3159 [ARCHIVE_RUNNING]=false
3161 while read event; do
3162 # Make sure we're not getting anything from previous events.
3163 for field in $expected_fields; do
3167 local parsed=$(parse_json_event "$event")
3168 if [ -z "$parsed" ]; then
3169 error "Copytool sent malformed event: $event"
3173 events["$event_type"]=true
3175 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3177 # Do some simple checking of the progress update events.
3178 for expected_field in $expected_fields; do
3179 if [ -z ${!expected_field+x} ]; then
3180 error "Missing $expected_field field in event"
3184 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3186 # These should be identical throughout an archive operation
3187 [ $source_fid == $data_fid ] ||
3188 error "Expected source_fid to equal data_fid"
3189 done < <(echo $"$(get_copytool_event_log)")
3191 # Check we received every type of events we were expecting
3192 for event in "${!events[@]}"; do
3193 ${events["$event"]} ||
3194 error "Copytool failed to send '$event' event to FIFO"
3197 echo "Archive events look OK."
3199 run_test 71 "Copytool logs JSON archive events to FIFO"
3202 # Bump progress interval for livelier events.
3205 # test needs a new running copytool
3206 stack_trap copytool_monitor_cleanup EXIT
3207 copytool_monitor_setup
3208 copytool setup --update-interval $interval --event-fifo \
3209 "$HSMTOOL_MONITOR_DIR/fifo"
3210 local test_file=$HSMTOOL_MONITOR_DIR/file
3212 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3214 do_facet $SINGLEAGT "$cmd" ||
3215 error "cannot create $test_file on $SINGLEAGT"
3216 copy2archive $test_file $tdir/$tfile
3219 local f=$DIR/$tdir/$tfile
3220 copytool import $tdir/$tfile $f
3221 f=$DIR2/$tdir/$tfile
3222 echo "Verifying released state: "
3223 check_hsm_flags $f "0x0000000d"
3225 local fid=$(path2fid $f)
3227 wait_request_state $fid RESTORE SUCCEED
3229 local expected_fields="event_time data_fid source_fid"
3230 expected_fields+=" total_bytes current_bytes"
3234 while read event; do
3235 # Make sure we're not getting anything from previous events.
3236 for field in $expected_fields; do
3240 local parsed=$(parse_json_event "$event")
3241 if [ -z "$parsed" ]; then
3242 error "Copytool sent malformed event: $event"
3246 if [ $event_type == "RESTORE_START" ]; then
3248 if [ $source_fid != $data_fid ]; then
3249 error "source_fid should == data_fid at start"
3252 elif [ $event_type == "RESTORE_FINISH" ]; then
3254 if [ $source_fid != $data_fid ]; then
3255 error "source_fid should == data_fid at finish"
3258 elif [ $event_type != "RESTORE_RUNNING" ]; then
3262 # Do some simple checking of the progress update events.
3263 for expected_field in $expected_fields; do
3264 if [ -z ${!expected_field+x} ]; then
3265 error "Missing $expected_field field in event"
3269 if [ $total_bytes -eq 0 ]; then
3270 error "Expected total_bytes to be > 0"
3273 # When a restore starts out, the data fid is the same as the
3274 # source fid. After the restore has gotten going, we learn
3275 # the new data fid. Once the restore has finished, the source
3276 # fid is set to the new data fid.
3278 # We test this because some monitoring software may depend on
3279 # this behavior. If it changes, then the consumers of these
3280 # events may need to be modified.
3281 if [ $source_fid == $data_fid ]; then
3282 error "source_fid should != data_fid during restore"
3284 done < <(echo $"$(get_copytool_event_log)")
3286 if [ -z "$START_EVENT" ]; then
3287 error "Copytool failed to send restore start event to FIFO"
3290 if [ -z "$FINISH_EVENT" ]; then
3291 error "Copytool failed to send restore finish event to FIFO"
3294 echo "Restore events look OK."
3296 run_test 72 "Copytool logs JSON restore events to FIFO"
3299 file_count=51 # Max number of files constrained by LNET message size
3300 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3301 local f=$DIR/$tdir/$tfile
3302 local FILELIST=/tmp/filelist.txt
3306 for i in $(seq 1 $file_count); do
3307 fid=$(copy_file /etc/hosts $f.$i)
3308 echo $f.$i >> $FILELIST
3312 # to be sure wait_all_done will not be mislead by previous tests
3314 wait_for_grace_delay
3315 $LFS hsm_archive --filelist $FILELIST ||
3316 error "cannot archive a file list"
3318 $LFS hsm_release --filelist $FILELIST ||
3319 error "cannot release a file list"
3320 $LFS hsm_restore --filelist $FILELIST ||
3321 error "cannot restore a file list"
3324 run_test 90 "Archive/restore a file list"
3326 double_verify_reset_hsm_param() {
3328 echo "Testing $HSM_PARAM.$p"
3329 local val=$(get_hsm_param $p)
3331 local val2=$(($val * 2))
3332 set_hsm_param $p $val2
3333 val=$(get_hsm_param $p)
3334 [[ $val == $val2 ]] ||
3335 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3336 echo "Set $p to 0 must failed"
3340 set_hsm_param $p $save
3342 if [[ $rc == 0 ]]; then
3343 error "we must not be able to set $HSM_PARAM.$p to 0"
3348 double_verify_reset_hsm_param loop_period
3349 double_verify_reset_hsm_param grace_delay
3350 double_verify_reset_hsm_param active_request_timeout
3351 double_verify_reset_hsm_param max_requests
3352 double_verify_reset_hsm_param default_archive_id
3354 run_test 100 "Set coordinator /proc tunables"
3361 run_test 102 "Verify coordinator control"
3364 # test needs a running copytool
3371 for i in $(seq 1 20); do
3372 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3374 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3378 echo "Current requests"
3379 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3380 $HSM_PARAM.actions |\
3381 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3383 [[ -z "$res" ]] || error "Some request have not been canceled"
3385 run_test 103 "Purge all requests"
3390 local f=$DIR/$tdir/$tfile
3391 local fid=$(create_empty_file "$f")
3393 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3394 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3395 $HSM_PARAM.actions |\
3396 grep $fid | cut -f16 -d=")
3398 [[ "$data1" == "$DATAHEX" ]] ||
3399 error "Data field in records is ($data1) and not ($DATAHEX)"
3403 run_test 104 "Copy tool data field"
3406 local max_requests=$(get_hsm_param max_requests)
3410 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3411 set_hsm_param max_requests 300
3414 for i in $(seq -w 1 10); do
3415 cp /etc/passwd $DIR/$tdir/$i
3416 $LFS hsm_archive $DIR/$tdir/$i
3418 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3419 $HSM_PARAM.actions |\
3420 grep WAITING | wc -l")
3424 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3425 $HSM_PARAM.actions |\
3426 grep WAITING | wc -l")
3429 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3430 error "Requests count after shutdown $reqcnt2 != "\
3431 "before shutdown $reqcnt1"
3433 run_test 105 "Restart of coordinator"
3436 # test needs a running copytool
3439 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3441 check_agent_registered $uuid
3443 search_copytools || error "No copytool found"
3446 wait_copytools || error "Copytool failed to stop"
3448 check_agent_unregistered $uuid
3451 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3452 check_agent_registered $uuid
3454 run_test 106 "Copytool register/unregister"
3457 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3459 # test needs a running copytool
3461 # create and archive file
3463 local f1=$DIR/$tdir/$tfile
3464 local fid=$(copy_file /etc/passwd $f1)
3465 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3466 wait_request_state $fid ARCHIVE SUCCEED
3467 # shutdown and restart MDS
3469 # check the copytool still gets messages from MDT
3470 local f2=$DIR/$tdir/2
3471 local fid=$(copy_file /etc/passwd $f2)
3472 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3473 # main check of this sanity: this request MUST succeed
3474 wait_request_state $fid ARCHIVE SUCCEED
3476 run_test 107 "Copytool re-register after MDS restart"
3478 policy_set_and_test()
3482 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3483 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3484 [[ "$policy" == "$target" ]] ||
3485 error "Wrong policy after '$change': '$policy' != '$target'"
3489 # to force default policy setting if error
3490 CDT_POLICY_HAD_CHANGED=true
3492 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3493 local default="NonBlockingRestore [NoRetryAction]"
3494 [[ "$policy" == "$default" ]] ||
3495 error "default policy has changed,"\
3496 " '$policy' != '$default' update the test"
3497 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3498 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3499 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3500 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3501 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3502 # useless bacause we know but safer for futur changes to use real value
3503 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3504 echo "Next set_param must failed"
3505 policy_set_and_test "wrong" "$policy"
3508 echo "Back to default policy"
3509 cdt_set_sanity_policy
3511 run_test 109 "Policy display/change"
3514 # test needs a running copytool
3519 copy2archive /etc/passwd $tdir/$tfile
3521 local f=$DIR/$tdir/$tfile
3522 copytool import $tdir/$tfile $f
3523 local fid=$(path2fid $f)
3525 cdt_set_non_blocking_restore
3530 wait_request_state $fid RESTORE SUCCEED
3531 cdt_clear_non_blocking_restore
3535 error "md5sum returns $st != 1, "\
3536 "should also perror ENODATA (No data available)"
3538 run_test 110a "Non blocking restore policy (import case)"
3541 # test needs a running copytool
3545 local f=$DIR/$tdir/$tfile
3546 local fid=$(copy_file /etc/passwd $f)
3547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3548 wait_request_state $fid ARCHIVE SUCCEED
3551 cdt_set_non_blocking_restore
3556 wait_request_state $fid RESTORE SUCCEED
3557 cdt_clear_non_blocking_restore
3561 error "md5sum returns $st != 1, "\
3562 "should also perror ENODATA (No data available)"
3564 run_test 110b "Non blocking restore policy (release case)"
3567 # test needs a running copytool
3571 copy2archive /etc/passwd $tdir/$tfile
3573 local f=$DIR/$tdir/$tfile
3575 copytool import $tdir/$tfile $f
3576 local fid=$(path2fid $f)
3580 copytool_remove_backend $fid
3583 wait_request_state $fid RESTORE FAILED
3590 [[ $st == 0 ]] || error "Restore does not failed"
3592 run_test 111a "No retry policy (import case), restore will error"\
3593 " (No such file or directory)"
3596 # test needs a running copytool
3600 local f=$DIR/$tdir/$tfile
3601 local fid=$(copy_file /etc/passwd $f)
3602 stack_trap cdt_clear_no_retry EXIT
3604 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3605 wait_request_state $fid ARCHIVE SUCCEED
3608 copytool_remove_backend $fid
3611 wait_request_state $fid RESTORE FAILED
3615 [[ $st == 0 ]] || error "Restore does not failed"
3617 run_test 111b "No retry policy (release case), restore will error"\
3618 " (No such file or directory)"
3621 # test needs a running copytool
3625 local f=$DIR/$tdir/$tfile
3626 local fid=$(copy_file /etc/passwd $f)
3628 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3629 local l=$($LFS hsm_action $f)
3631 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3634 wait_request_state $fid ARCHIVE SUCCEED
3637 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3639 run_test 112 "State of recorded request"
3642 local file1=$DIR/$tdir/$tfile
3643 local file2=$DIR2/$tdir/$tfile
3645 local fid=$(create_small_sync_file $file1)
3647 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3648 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3649 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3651 copytool setup -m "$MOUNT3"
3653 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3655 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3656 wait_request_state $fid ARCHIVE SUCCEED
3658 $LFS hsm_release $file1
3659 echo "Verifying released state: "
3660 check_hsm_flags $file1 "0x0000000d"
3662 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3665 kill -USR1 $MULTIPID
3670 local size1=$(stat -c "%s" $file1)
3671 local size2=$(stat -c "%s" $file2)
3673 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3675 run_test 113 "wrong stat after restore"
3678 local f=$DIR/$tdir/$tfile
3679 local fid=$(create_empty_file "$f")
3683 # Prevent archive from completing
3686 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3687 # wait archive to register at CDT
3688 wait_request_state $fid ARCHIVE STARTED
3690 # Cancel the archive
3691 $LFS hsm_cancel "$f"
3693 wait_request_state $fid ARCHIVE CANCELED
3696 wait_request_state $fid CANCEL SUCCEED
3698 run_test 200 "Register/Cancel archive"
3701 # test needs a running copytool
3704 local f=$DIR/$tdir/$tfile
3705 create_archive_file $tdir/$tfile
3706 copytool import $tdir/$tfile $f
3707 local fid=$(path2fid $f)
3709 # test with cdt on is made in test_222
3712 # wait restore to register at CDT
3713 wait_request_state $fid RESTORE WAITING
3716 wait_request_state $fid RESTORE CANCELED
3717 wait_request_state $fid CANCEL SUCCEED
3719 run_test 201 "Register/Cancel restore"
3722 local f=$DIR/$tdir/$tfile
3723 local fid=$(create_empty_file "$f")
3725 # test needs a running copytool
3728 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3729 wait_request_state $fid ARCHIVE SUCCEED
3733 # wait remove to register at CDT
3734 wait_request_state $fid REMOVE STARTED
3737 wait_request_state $fid REMOVE CANCELED
3739 run_test 202 "Register/Cancel remove"
3741 test_220A() { # was test_220
3742 # test needs a running copytool
3747 local f=$DIR/$tdir/$tfile
3748 local fid=$(copy_file /etc/passwd $f)
3752 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3753 wait_request_state $fid ARCHIVE SUCCEED
3755 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3756 error "The expected changelog was not emitted"
3758 run_test 220A "Changelog for archive"
3761 # test needs a running copytool
3766 local f=$DIR/$tdir/$tfile
3767 local fid=$(copy_file /etc/passwd $f)
3771 # block copytool operations to allow for HSM request to be
3772 # submitted and file be unlinked (CDT will find object removed)
3775 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3777 # wait request to reach CT
3778 wait_request_state $fid ARCHIVE STARTED
3784 wait_request_state $fid ARCHIVE FAILED
3787 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3788 error "The expected changelog was not emitted"
3790 run_test 220a "Changelog for failed archive"
3793 local f=$DIR/$tdir/$tfile
3794 local fid=$(create_empty_file "$f")
3799 # Prevent archive from completing
3801 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3802 wait_request_state $fid ARCHIVE STARTED
3805 wait_request_state $fid ARCHIVE CANCELED
3808 wait_request_state $fid CANCEL SUCCEED
3810 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3811 error "The expected changelog was not emitted"
3813 run_test 221 "Changelog for archive canceled"
3816 # test needs a running copytool
3820 copy2archive /etc/passwd $tdir/$tfile
3822 local f=$DIR/$tdir/$tfile
3823 copytool import $tdir/$tfile $f
3824 local fid=$(path2fid $f)
3829 wait_request_state $fid RESTORE SUCCEED
3831 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3832 error "The expected changelog was not emitted"
3834 run_test 222a "Changelog for explicit restore"
3837 # test needs a running copytool
3841 local f=$DIR/$tdir/$tfile
3842 local fid=$(copy_file /etc/passwd $f)
3845 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3846 wait_request_state $fid ARCHIVE SUCCEED
3851 wait_request_state $fid RESTORE SUCCEED
3853 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3854 error "The expected changelog was not emitted"
3856 run_test 222b "Changelog for implicit restore"
3859 # test needs a running copytool
3863 copy2archive /etc/passwd $tdir/$tfile
3865 local f=$DIR/$tdir/$tfile
3866 copytool import $tdir/$tfile $f
3867 local fid=$(path2fid $f)
3871 # block copytool operations to allow for HSM request to be
3872 # submitted and file be unlinked (CDT will find object removed)
3877 # wait request to reach CT
3878 wait_request_state $fid RESTORE STARTED
3884 wait_request_state $fid RESTORE FAILED
3887 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3888 error "The expected changelog was not emitted"
3890 run_test 222c "Changelog for failed explicit restore"
3893 # test needs a running copytool
3897 local f=$DIR/$tdir/$tfile
3898 local fid=$(copy_file /etc/passwd $f)
3901 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3902 wait_request_state $fid ARCHIVE SUCCEED
3905 copytool_remove_backend $fid
3908 wait_request_state $fid RESTORE FAILED
3911 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3912 error "The expected changelog was not emitted"
3914 run_test 222d "Changelog for failed implicit restore"
3917 # test needs a running copytool
3920 local f=$DIR/$tdir/$tfile
3921 create_archive_file $tdir/$tfile
3925 copytool import $tdir/$tfile $f
3926 local fid=$(path2fid $f)
3929 wait_request_state $fid RESTORE STARTED
3931 wait_request_state $fid RESTORE CANCELED
3932 wait_request_state $fid CANCEL SUCCEED
3934 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3935 error "The expected changelog was not emitted"
3937 run_test 223a "Changelog for restore canceled (import case)"
3940 local f=$DIR/$tdir/$tfile
3941 local fid=$(create_empty_file "$f")
3946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3947 wait_request_state $fid ARCHIVE SUCCEED
3950 # Prevent restore from completing
3953 wait_request_state $fid RESTORE STARTED
3956 wait_request_state $fid RESTORE CANCELED
3959 wait_request_state $fid CANCEL SUCCEED
3961 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3962 error "The expected changelog was not emitted"
3964 run_test 223b "Changelog for restore canceled (release case)"
3966 test_224A() { # was test_224
3967 # test needs a running copytool
3972 local f=$DIR/$tdir/$tfile
3973 local fid=$(copy_file /etc/passwd $f)
3976 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3977 wait_request_state $fid ARCHIVE SUCCEED
3980 wait_request_state $fid REMOVE SUCCEED
3982 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
3983 error "The expected changelog was not emitted"
3985 run_test 224A "Changelog for remove"
3988 # test needs a running copytool
3993 local f=$DIR/$tdir/$tfile
3994 local fid=$(copy_file /etc/passwd $f)
3997 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3998 wait_request_state $fid ARCHIVE SUCCEED
4000 copytool_remove_backend $fid
4002 # block copytool operations to allow for HSM request to be
4003 # submitted and file be unlinked (CDT will find object removed)
4008 # wait for request to reach CT
4009 wait_request_state $fid REMOVE STARTED
4015 wait_request_state $fid REMOVE FAILED
4017 # HE_REMOVE|ENOENT=0x202
4018 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4019 error "The expected changelog was not emitted"
4021 run_test 224a "Changelog for failed remove"
4024 # test is not usable because remove request is too fast
4025 # so it is always finished before cancel can be done ...
4026 echo "Test disabled"
4029 # test needs a running copytool
4032 local f=$DIR/$tdir/$tfile
4033 local fid=$(create_empty_file "$f")
4036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4037 wait_request_state $fid ARCHIVE SUCCEED
4039 # Prevent restore from completing
4044 wait_request_state $fid REMOVE CANCELED
4047 wait_request_state $fid CANCEL SUCCEED
4049 changelog_find -type HSM -target-fid $fid -flags 0x27d
4050 error "The expected changelog was not emitted"
4052 run_test 225 "Changelog for remove canceled"
4055 # test needs a running copytool
4060 local f1=$DIR/$tdir/$tfile-1
4061 local f2=$DIR/$tdir/$tfile-2
4062 local f3=$DIR/$tdir/$tfile-3
4063 local fid1=$(copy_file /etc/passwd $f1)
4064 local fid2=$(copy_file /etc/passwd $f2)
4065 copy_file /etc/passwd $f3
4068 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4069 wait_request_state $fid1 ARCHIVE SUCCEED
4071 $LFS hsm_archive $f2
4072 wait_request_state $fid2 ARCHIVE SUCCEED
4074 rm $f1 || error "rm $f1 failed"
4077 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4078 error "The expected changelog was not emitted"
4080 mv $f3 $f2 || error "mv $f3 $f2 failed"
4082 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4083 error "The expected changelog was not emitted"
4085 run_test 226 "changelog for last rm/mv with exiting archive"
4087 # This is just a utility function to clarify what test_227 does
4092 "$LFS" "$action" --$flag "$file" ||
4093 error "Cannot ${action#hsm_} $flag on '$file'"
4095 # Only one changelog should be produced
4096 local entries="$(changelog_find -type HSM -target-fid $fid)"
4097 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4098 error "lfs $action --$flag '$file' produced more than one" \
4101 # Parse the last changelog record
4102 local entry="$(tail -n 1 <<< "$entries")"
4103 eval local -A changelog=$(changelog2array $entry)
4105 # Also check the flags match what is expected
4106 [[ ${changelog[flags]} == $target ]] ||
4107 error "Changelog flag is '${changelog[flags]}', not $target"
4111 local file="$DIR/$tdir/$tfile"
4112 local fid=$(create_empty_file "$file")
4117 for flag in norelease noarchive exists archived lost; do
4118 if [ "$flag" == lost ]; then
4119 # The flag "lost" only works on an archived file
4120 "$LFS" hsm_set --archived "$file"
4124 action="hsm_set" __test_227
4125 action="hsm_clear" __test_227
4128 run_test 227 "changelog when explicit setting of HSM flags"
4131 # test needs a running copytool
4134 local fid=$(create_small_sync_file $DIR/$tfile)
4135 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4136 wait_request_state $fid ARCHIVE SUCCEED
4138 $LFS hsm_release $DIR/$tfile
4139 check_hsm_flags $DIR/$tfile "0x0000000d"
4141 filefrag $DIR/$tfile | grep " 1 extent found" ||
4142 error "filefrag on released file must return only one extent"
4144 # only newer versions of cp detect sparse files by stat/FIEMAP
4146 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4147 error "copying $DIR/$tfile"
4148 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4150 $LFS hsm_release $DIR/$tfile
4151 check_hsm_flags $DIR/$tfile "0x0000000d"
4153 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4155 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4157 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4158 error "comparing untarred $DIR/$tfile"
4160 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4161 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4163 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4166 local file="$DIR/$tdir/$tfile"
4168 # set max_requests to allow one request of each type to be started (3)
4170 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4171 set_hsm_param max_requests 3
4174 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4175 set_hsm_param loop_period 1
4177 # send 1 requests of each kind twice
4180 for action in archive restore remove; do
4181 local filepath="$file"-to-$action
4182 local fid=$(create_empty_file "$filepath")
4183 local fid2=$(create_empty_file "$filepath".bis)
4185 if [ "$action" != archive ]; then
4186 "$LFS" hsm_archive "$filepath"
4187 wait_request_state $fid ARCHIVE SUCCEED
4188 "$LFS" hsm_archive "$filepath".bis
4189 wait_request_state $fid2 ARCHIVE SUCCEED
4191 if [ "$action" == restore ]; then
4192 "$LFS" hsm_release "$filepath"
4193 "$LFS" hsm_release "$filepath".bis
4197 # suspend the copytool to prevent requests from completing
4198 stack_trap "copytool_continue" EXIT
4201 # send `max_requests' requests (one of each kind)
4202 for action in archive restore remove; do
4203 filepath="$file"-to-$action
4204 "$LFS" hsm_${action} "$filepath"
4205 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4208 # send another batch of requests
4209 for action in archive restore remove; do
4210 "$LFS" hsm_${action} "$file-to-$action".bis
4212 # wait for `loop_period' seconds to make sure the coordinator has time
4213 # to register those, even though it should not
4216 # only the first batch of request should be started
4218 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4222 error "expected 3 STARTED requests, found $count"
4224 run_test 250 "Coordinator max request"
4227 local f=$DIR/$tdir/$tfile
4228 local fid=$(create_empty_file "$f")
4231 # to have a short test
4232 local old_to=$(get_hsm_param active_request_timeout)
4233 set_hsm_param active_request_timeout 1
4234 # to be sure the cdt will wake up frequently so
4235 # it will be able to cancel the "old" request
4236 local old_loop=$(get_hsm_param loop_period)
4237 set_hsm_param loop_period 1
4242 # Prevent archive from completing
4244 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4245 wait_request_state $fid ARCHIVE STARTED
4247 # Let the request timeout
4248 wait_request_state $fid ARCHIVE CANCELED
4250 set_hsm_param active_request_timeout $old_to
4251 set_hsm_param loop_period $old_loop
4253 run_test 251 "Coordinator request timeout"
4256 local f=$DIR/$tdir/$tfile
4257 local fid=$(create_empty_file "$f")
4259 # to have a short test
4260 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4261 set_hsm_param loop_period 1
4265 # Prevent archive from completing
4267 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4268 wait_request_state $fid ARCHIVE STARTED
4271 stack_trap "set_hsm_param active_request_timeout \
4272 $(get_hsm_param active_request_timeout)" EXIT
4273 set_hsm_param active_request_timeout 1
4275 wait_request_state $fid ARCHIVE CANCELED
4278 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4282 # test needs a running copytool
4286 local f=$DIR/$tdir/$tfile
4288 dd if=/dev/zero of=$f bs=1MB count=10
4289 local fid=$(path2fid $f)
4291 $LFS hsm_archive $f || error "could not archive file"
4292 wait_request_state $fid ARCHIVE SUCCEED
4294 # clear locks to discard inode data
4295 cancel_lru_locks osc
4297 #define OBD_FAIL_MDC_MERGE 0x807
4298 $LCTL set_param fail_loc=0x807
4300 #expect error here, instead of release with wrong size
4303 if ((rc == 0)); then
4304 file_size=$(stat -c '%s' $f)
4305 if ((file_size != 10485760)); then
4306 error "Wrong file size after hsm_release"
4309 echo "could not release file"
4312 run_test 253 "Check for wrong file size after release"
4316 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4317 skip "need MDS version at least 2.10.56"
4319 # Check that the counters are initialized to 0
4321 for request_type in archive restore remove; do
4322 count="$(get_hsm_param ${request_type}_count)" ||
4323 error "Reading ${request_type}_count failed with $?"
4325 [ "$count" -eq 0 ] ||
4326 error "Expected ${request_type}_count to be " \
4330 run_test 254a "Request counters are initialized to zero"
4334 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4335 skip "need MDS version at least 2.10.56"
4337 # The number of request to launch (at least 32)
4338 local request_count=$((RANDOM % 32 + 32))
4339 printf "Will launch %i requests of each type\n" "$request_count"
4341 # Launch a copytool to process requests
4344 # Set hsm.max_requests to allow starting all requests at the same time
4346 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4347 set_hsm_param max_requests "$request_count"
4351 for request_type in archive restore remove; do
4352 printf "Checking %s requests\n" "${request_type}"
4353 # Suspend the copytool to give us time to read the proc files
4356 for ((i = 0; i < $request_count; i++)); do
4357 case $request_type in
4359 create_empty_file "$DIR/$tdir/$tfile-$i" \
4363 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4366 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4369 # Give the coordinator 10 seconds to start every request
4371 while get_hsm_param actions | grep -q WAITING; do
4374 [ $timeout -gt 0 ] ||
4375 error "${request_type^} requests took too " \
4379 count="$(get_hsm_param ${request_type}_count)"
4380 [ "$count" -eq "$request_count" ] ||
4381 error "Expected '$request_count' (!= '$count') " \
4382 "active $request_type requests"
4384 # Let the copytool process the requests
4386 # Give it 10 seconds maximum
4388 while get_hsm_param actions | grep -q STARTED; do
4391 [ $timeout -gt 0 ] ||
4392 error "${request_type^} requests took too " \
4396 count="$(get_hsm_param ${request_type}_count)"
4397 [ "$count" -eq 0 ] ||
4398 error "Expected 0 (!= '$count') " \
4399 "active $request_type requests"
4402 run_test 254b "Request counters are correctly incremented and decremented"
4406 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4407 skip "Need MDS version at least 2.12.0"
4409 local file="$DIR/$tdir/$tfile"
4410 local fid=$(create_empty_file "$file")
4412 # How do you make sure the coordinator has consumed any outstanding
4413 # event, without triggering an event yourself?
4415 # You wait for a request to disappear from the coordinator's llog.
4417 # Warning: the setup represents 90% of this test
4419 # Create and process an HSM request
4421 "$LFS" hsm_archive "$file"
4422 wait_request_state $fid ARCHIVE SUCCEED
4425 wait_copytools || error "failed to stop copytools"
4427 # Launch a new HSM request
4429 create_empty_file "$file"
4430 "$LFS" hsm_archive "$file"
4434 # Have the completed request be removed as soon as the cdt wakes up
4435 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4436 set_hsm_param grace_delay 1
4437 # (Hopefully, time on the MDS will behave nicely)
4438 do_facet $SINGLEMDS sleep 2 &
4440 # Increase `loop_period' as a mean to prevent the coordinator from
4441 # waking itself up to do some housekeeping.
4442 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4443 set_hsm_param loop_period 1000
4445 wait $! || error "waiting failed"
4447 wait_request_state $fid ARCHIVE ""
4448 # The coordinator will not wake up on its own for ~`loop_period' secs...
4450 # ... Unless a copytool registers. Now the real test begins
4452 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4454 run_test 255 "Copytool registration wakes the coordinator up"
4456 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4457 # break in the future because of that.
4460 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4461 skip "need MDS version 2.11.56 or later"
4463 local -a files=("$DIR/$tdir/$tfile".{0..15})
4466 for file in "${files[@]}"; do
4467 create_small_file "$file"
4470 # Set a few hsm parameters
4472 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4473 set_hsm_param loop_period 1
4475 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4476 set_hsm_param max_requests 3
4480 "$LFS" hsm_archive "${files[0]}"
4481 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4482 "$LFS" hsm_release "${files[0]}"
4486 wait_copytools || error "copytools failed to stop"
4488 # Send several archive requests
4489 for file in "${files[@]:1}"; do
4490 "$LFS" hsm_archive "$file"
4493 # Send one restore request
4494 "$LFS" hsm_restore "${files[0]}"
4499 # Wait for all the requests to complete
4500 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4501 for file in "${files[@]:1}"; do
4502 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4505 # Collect the actions in the order in which the copytool processed them
4507 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4508 "$(copytool_logfile "$SINGLEAGT")")
4511 printf '%s\n' "${actions[@]}"
4514 for action in "${actions[@]:0:3}"; do
4515 [ "$action" == RESTORE ] && return
4518 error "Too many ARCHIVE requests were run before the RESTORE request"
4520 run_test 260a "Restore request have priority over other requests"
4522 # This test is very much tied to the implementation of the current priorisation
4523 # mechanism in the coordinator. It might not make sense to keep it in the future
4526 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4527 skip "need MDS version 2.11.56 or later"
4529 local -a files=("$DIR/$tdir/$tfile".{0..15})
4532 for file in "${files[@]}"; do
4533 create_small_file "$file"
4536 # Set a few hsm parameters
4538 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4539 set_hsm_param loop_period 1
4541 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4542 set_hsm_param max_requests 3
4545 copytool setup --archive-id 2
4546 "$LFS" hsm_archive --archive 2 "${files[0]}"
4547 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4548 "$LFS" hsm_release "${files[0]}"
4552 wait_copytools || error "copytools failed to stop"
4554 # Send several archive requests
4555 for file in "${files[@]:1}"; do
4556 "$LFS" hsm_archive "$file"
4559 # Send one restore request
4560 "$LFS" hsm_restore "${files[0]}"
4564 copytool setup --archive-id 2
4566 # Wait for all the requests to complete
4567 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4568 for file in "${files[@]:1}"; do
4569 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4572 # Collect the actions in the order in which the copytool processed them
4574 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4575 "$(copytool_logfile "$SINGLEAGT")")
4578 printf '%s\n' "${actions[@]}"
4581 for action in "${actions[@]:0:3}"; do
4582 [ "$action" == RESTORE ] && return
4585 error "Too many ARCHIVE requests were run before the RESTORE request"
4587 run_test 260b "Restore request have priority over other requests"
4589 # This test is very much tied to the implementation of the current priorisation
4590 # mechanism in the coordinator. It might not make sense to keep it in the future
4593 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4594 skip "Need MDS version at least 2.12.0"
4596 local -a files=("$DIR/$tdir/$tfile".{0..15})
4599 for file in "${files[@]}"; do
4600 create_small_file "$file"
4603 # Set a few hsm parameters
4605 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4606 set_hsm_param loop_period 1000
4608 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4609 set_hsm_param max_requests 3
4612 copytool setup --archive-id 2
4613 "$LFS" hsm_archive --archive 2 "${files[0]}"
4614 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4615 "$LFS" hsm_release "${files[0]}"
4619 wait_copytools || error "copytools failed to stop"
4621 # Force the next coordinator run to do housekeeping
4625 "$LFS" hsm_archive "${files[1]}"
4629 copytool setup --archive-id 2
4631 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4632 # The coordinator just did a housekeeping run it won't do another one
4633 # for around `loop_period' seconds => requests will not be reordered
4634 # if it costs too much (ie. when the coordinator has to discard a whole
4637 # Send several archive requests
4638 for file in "${files[@]:2}"; do
4639 "$LFS" hsm_archive "$file"
4642 # Send one restore request
4643 "$LFS" hsm_restore "${files[0]}"
4645 # Wait for all the requests to complete
4646 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4647 for file in "${files[@]:2}"; do
4648 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4651 # Collect the actions in the order in which the copytool processed them
4653 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4654 "$(copytool_logfile "$SINGLEAGT")")
4657 printf '%s\n' "${actions[@]}"
4660 for action in "${actions[@]:0:3}"; do
4661 [ "$action" == RESTORE ] &&
4662 error "Restore requests should not be prioritised" \
4663 "unless the coordinator is doing housekeeping"
4667 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4670 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4672 # the only way to test ondisk conf is to restart MDS ...
4673 echo "Stop coordinator and remove coordinator state at mount"
4676 # clean on disk conf set by default
4677 cdt_clear_mount_state
4678 cdt_check_state stopped
4680 # check cdt still off after umount/remount
4682 cdt_check_state stopped
4684 echo "Set coordinator start at mount, and start coordinator"
4685 cdt_set_mount_state enabled
4688 cdt_check_state enabled
4690 # check cdt still on after umount/remount
4692 cdt_check_state enabled
4694 # we are back to original state (cdt started at mount)
4696 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4699 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4701 local ai=$(get_hsm_param default_archive_id)
4702 local new=$((ai + 1))
4704 set_hsm_param default_archive_id $new -P
4706 local res=$(get_hsm_param default_archive_id)
4709 set_hsm_param default_archive_id "" "-P -d"
4711 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4713 run_test 301 "HSM tunnable are persistent"
4716 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4718 local ai=$(get_hsm_param default_archive_id)
4719 local new=$((ai + 1))
4724 set_hsm_param default_archive_id $new -P
4727 for mdtno in $(seq 1 $MDSCOUNT); do
4732 cdt_check_state enabled
4734 local res=$(get_hsm_param default_archive_id)
4737 set_hsm_param default_archive_id "" "-P -d"
4739 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4741 run_test 302 "HSM tunnable are persistent when CDT is off"
4744 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4750 local dir_mdt0=$DIR/$tdir/mdt0
4751 local dir_mdt1=$DIR/$tdir/mdt1
4753 # create 1 dir per MDT
4754 stack_trap "rm -rf $dir_mdt0" EXIT
4755 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4756 stack_trap "rm -rf $dir_mdt1" EXIT
4757 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4759 # create 1 file in each MDT
4760 local fid1=$(create_small_file $dir_mdt0/$tfile)
4761 local fid2=$(create_small_file $dir_mdt1/$tfile)
4763 # check that hsm request on mdt0 is sent to the right MDS
4764 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4765 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4766 echo "archive successful on mdt0"
4768 # check that hsm request on mdt1 is sent to the right MDS
4769 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4770 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4771 echo "archive successful on mdt1"
4773 run_test 400 "Single request is sent to the right MDT"
4776 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4782 local dir_mdt0=$DIR/$tdir/mdt0
4783 local dir_mdt1=$DIR/$tdir/mdt1
4785 # create 1 dir per MDT
4786 stack_trap "rm -rf $dir_mdt0" EXIT
4787 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4788 stack_trap "rm -rf $dir_mdt1" EXIT
4789 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4791 # create 1 file in each MDT
4792 local fid1=$(create_small_file $dir_mdt0/$tfile)
4793 local fid2=$(create_small_file $dir_mdt1/$tfile)
4795 # check that compound requests are shunt to the rights MDTs
4796 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4797 error "lfs hsm_archive"
4798 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4799 echo "archive successful on mdt0"
4800 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4801 echo "archive successful on mdt1"
4803 run_test 401 "Compound requests split and sent to their respective MDTs"
4805 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4810 local node=$(facet_active_host $facet)
4812 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4813 awk '{print $4}'); do
4814 echo "$3 $mdc on $node"
4815 do_facet $facet "$LCTL --device $mdc $state" || return 1
4820 # deactivate all mdc on agent1
4821 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4823 copytool setup --no-fail
4825 check_agent_unregistered "uuid" # match any agent
4827 # no expected running copytool
4828 search_copytools $agent && error "Copytool start should have failed"
4831 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4833 run_test 402a "Copytool start fails if all MDTs are inactive"
4840 local f=$DIR/$tdir/$tfile
4841 touch $f || error "touch $f failed"
4842 local fid=$(path2fid $f)
4844 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4845 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4848 # give time for CDT to send request and to keep it for retry
4849 wait_for_loop_period
4851 wait_request_state $fid ARCHIVE WAITING
4853 do_facet $SINGLEAGT lctl set_param fail_loc=0
4855 # request should succeed now
4856 wait_request_state $fid ARCHIVE SUCCEED
4858 run_test 402b "CDT must retry request upon slow start of CT"
4861 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4863 local agent=$(facet_active_host $SINGLEAGT)
4865 # deactivate all mdc for MDT0001
4866 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4869 local uuid=$(get_agent_uuid $agent)
4870 # check the agent is registered on MDT0000, and not on MDT0001
4871 check_agent_registered_by_mdt $uuid 0
4872 check_agent_unregistered_by_mdt $uuid 1
4874 # check running copytool process
4875 search_copytools $agent || error "No running copytools on $agent"
4877 # reactivate all mdc for MDT0001
4878 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4880 # make sure the copytool is now registered to all MDTs
4881 check_agent_registered $uuid
4883 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4886 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4890 # create files on both MDT0000 and MDT0001
4893 local dir_mdt0=$DIR/$tdir/mdt0
4894 stack_trap "rm -rf $dir_mdt0" EXIT
4895 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4897 # create 1 file on mdt0
4898 local fid1=$(create_small_file $dir_mdt0/$tfile)
4900 # deactivate all mdc for MDT0001
4901 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4903 # send an HSM request for files in MDT0000
4904 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4906 # check for completion of files in MDT0000
4907 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4908 echo "archive successful on mdt0"
4910 # reactivate all mdc for MDT0001
4911 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4913 run_test 404 "Inactive MDT does not block requests for active MDTs"
4916 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4922 local striped_dir=$DIR/$tdir/striped_dir
4924 # create striped dir on all of MDTs
4925 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4927 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4928 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4929 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4930 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4932 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4933 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4934 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4935 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4937 # check that compound requests are shunt to the rights MDTs
4938 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4939 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4940 error "lfs hsm_archive"
4942 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4943 echo "archive successful on $fid1"
4944 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4945 echo "archive successful on $fid2"
4946 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4947 echo "archive successful on $fid3"
4948 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4949 echo "archive successful on $fid4"
4951 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4952 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4953 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4954 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4956 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4957 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4958 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4959 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4961 run_test 405 "archive and release under striped directory"
4964 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4966 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
4967 skip "need MDS version at least 2.7.64"
4972 fid=$(create_small_file $DIR/$tdir/$tfile)
4977 $LFS hsm_archive $DIR/$tdir/$tfile
4978 wait_request_state "$fid" ARCHIVE SUCCEED
4979 $LFS hsm_release $DIR/$tdir/$tfile
4981 # Should migrate $tdir but not $tfile.
4982 $LFS migrate -m1 $DIR/$tdir &&
4983 error "migrating HSM an archived file should fail"
4985 $LFS hsm_restore $DIR/$tdir/$tfile
4986 wait_request_state "$fid" RESTORE SUCCEED
4988 $LFS hsm_remove $DIR/$tdir/$tfile
4989 wait_request_state "$fid" REMOVE SUCCEED
4991 cat $DIR/$tdir/$tfile > /dev/null ||
4992 error "cannot read $DIR/$tdir/$tfile"
4994 $LFS migrate -m1 $DIR/$tdir ||
4995 error "cannot complete migration after HSM remove"
4997 mdt_index=$($LFS getstripe -m $DIR/$tdir)
4998 if ((mdt_index != 1)); then
4999 error "expected MDT index 1, got $mdt_index"
5002 # Refresh fid after migration.
5003 fid=$(path2fid $DIR/$tdir/$tfile)
5006 $LFS hsm_archive $DIR/$tdir/$tfile
5007 wait_request_state "$fid" ARCHIVE SUCCEED 1
5009 lctl set_param debug=+trace
5010 $LFS hsm_release $DIR/$tdir/$tfile ||
5011 error "cannot release $DIR/$tdir/$tfile"
5013 $LFS hsm_restore $DIR/$tdir/$tfile
5014 wait_request_state "$fid" RESTORE SUCCEED 1
5016 cat $DIR/$tdir/$tfile > /dev/null ||
5017 error "cannot read $DIR/$tdir/$tfile"
5019 run_test 406 "attempting to migrate HSM archived files is safe"
5022 local f=$DIR/$tdir/$tfile
5023 local f2=$DIR2/$tdir/$tfile
5024 local fid=$(create_empty_file "$f")
5028 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5029 wait_request_state $fid ARCHIVE SUCCEED
5032 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5033 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5035 # Prevent restore from completing
5039 # 1st request holds layout lock while appropriate
5040 # RESTORE record is still not added to llog
5044 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5045 # after umount hsm_actions->O/x/x log shouldn't have
5046 # double RESTORE records like below
5047 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5048 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5050 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5052 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5054 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5057 wait_all_done 100 $fid
5059 run_test 407 "Check for double RESTORE records in llog"
5063 [ "$MDS1_VERSION" -lt $(version_code 2.6.92) ] &&
5064 skip "HSM migrate is not supported"
5066 test_mkdir -p $DIR/$tdir
5068 if [ "$CLIENT_VERSION" -lt $(version_code 2.11.56) ] ||
5069 [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ];
5071 llapi_hsm_test -d $DIR/$tdir -b ||
5072 error "One llapi HSM test failed"
5074 llapi_hsm_test -d $DIR/$tdir ||
5075 error "One llapi HSM test failed"
5078 run_test 500 "various LLAPI HSM tests"
5081 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
5082 skip "need MDS version at least 2.10.58"
5086 local f=$DIR/$tdir/$tfile
5089 # set changelog_mask to ALL
5090 changelog_chmask "ALL"
5092 chmod 777 $DIR/$tdir
5093 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5094 local fid=$(path2fid $f)
5097 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5098 -gid "$RUNAS_GID") ||
5099 error "No matching CREAT entry"
5101 # Parse the changelog
5102 eval local -A changelog=$(changelog2array $entry)
5103 local nid="${changelog[nid]}"
5106 echo "Got NID '$nid'"
5107 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5108 error "nid '$nid' does not match any client NID:" \
5111 run_test 600 "Changelog fields 'u=' and 'nid='"
5114 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5115 skip "need MDS version at least 2.10.58"
5119 local f=$DIR/$tdir/$tfile
5122 # set changelog_mask to ALL
5123 changelog_chmask "ALL"
5125 touch $f || error "touch $f failed"
5126 local fid=$(path2fid $f)
5129 cat $f || error "cat $f failed"
5131 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5132 error "No matching OPEN entry"
5134 run_test 601 "OPEN Changelog entry"
5137 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5138 skip "need MDS version at least 2.10.58"
5140 stack_trap "restore_opencache" EXIT
5145 local f=$DIR/$tdir/$tfile
5148 # set changelog_mask to ALL
5149 changelog_chmask "ALL"
5151 touch $f || error "touch $f failed"
5152 local fid=$(path2fid $f)
5155 cat $f || error "cat $f failed"
5157 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5161 echo f > $f || error "write $f failed"
5164 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5166 # remove OPEN from changelog_mask
5167 changelog_chmask "-OPEN"
5171 cat $f || error "cat $f failed"
5174 changelog_find -type CLOSE -target-fid $fid &&
5175 error "There should be no CLOSE entry"
5179 echo f > $f || error "write $f failed"
5182 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5184 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5187 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5188 skip "need MDS version at least 2.10.58"
5192 local f=$DIR/$tdir/$tfile
5195 # set changelog_mask to ALL
5196 changelog_chmask "ALL"
5198 touch $f || error "touch $f failed"
5199 local fid=$(path2fid $f)
5201 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5204 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5206 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5207 error "No matching GXATR entry"
5209 run_test 603 "GETXATTR Changelog entry"
5212 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5213 skip "need MDS version at least 2.10.58"
5217 local f=$DIR/$tdir/$tfile
5218 local f2=$DIR2/$tdir/$tfile
5219 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5221 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5222 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5223 do_facet mds1 lctl set_param "$procname=20"
5227 # set changelog_mask to ALL
5228 changelog_chmask "ALL"
5230 touch $f || error "touch $f failed"
5231 local fid=$(path2fid $f)
5237 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5241 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5242 -gid "$RUNAS_GID" -mode "r--") ||
5243 error "No matching NOPEN entry"
5245 # Parse the changelog
5246 eval local -A changelog=$(changelog2array $entry)
5247 local nid="${changelog[nid]}"
5250 echo "Got NID '$nid'"
5251 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5252 error "nid '$nid' does not match any client NID:" \
5257 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5260 changelog_find -type NOPEN -target-fid $fid &&
5261 error "There should be no NOPEN entry"
5263 # Sleep for `changelog_deniednext` seconds
5268 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5271 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5272 -gid "$RUNAS_GID" -mode "r--") ||
5273 error "No matching NOPEN entry"
5275 # Parse the changelog
5276 eval local -A changelog=$(changelog2array $entry)
5277 local nid="${changelog[nid]}"
5280 echo "Got NID '$nid'"
5281 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5282 error "nid '$nid' does not match any client NID:" \
5285 run_test 604 "NOPEN Changelog entry"
5288 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5289 skip "need MDS version at least 2.10.58"
5291 stack_trap "restore_opencache" EXIT
5296 local f=$DIR/$tdir/$tfile
5297 local f2=$DIR2/$tdir/$tfile
5300 # set changelog_mask to ALL
5301 changelog_chmask "ALL"
5303 touch $f || error "touch $f failed"
5304 local fid=$(path2fid $f)
5308 exec 3<> $f || error "open $f failed"
5312 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5316 exec 4<> $f || error "open $f failed"
5319 changelog_find -type OPEN -target-fid $fid &&
5320 error "There should be no OPEN entry"
5322 exec 4>&- || error "close $f failed"
5325 changelog_find -type CLOSE -target-fid $fid &&
5326 error "There should be no CLOSE entry"
5330 # access in rw, so different access mode should generate entries
5331 cat $f || error "cat $f failed"
5334 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5336 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5340 # same access as first one, should not generate new entries
5341 exec 4<> $f || error "open $f failed"
5344 changelog_find -type OPEN -target-fid $fid &&
5345 error "There should be no OPEN entry"
5347 exec 4>&- || error "close $f failed"
5350 changelog_find -type CLOSE -target-fid $fid &&
5351 error "There should be no CLOSE entry"
5355 # access by different user should generate new entries
5356 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5359 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5361 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5365 exec 3>&- || error "close $f failed"
5368 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5370 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5373 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5374 skip "need MDS version at least 2.10.58"
5376 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5377 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5378 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5379 skip_env "missing llog_reader"
5383 local f=$DIR/$tdir/$tfile
5386 # set changelog_mask to ALL
5387 changelog_chmask "ALL"
5389 chmod 777 $DIR/$tdir
5390 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5391 local fid=$(path2fid $f)
5392 rm $f || error "rm $f failed"
5394 local mntpt=$(facet_mntpt mds1)
5398 #remount mds1 as ldiskfs or zfs type
5399 stop mds1 || error "stop mds1 failed"
5400 stack_trap "unmount_fstype mds1; start mds1 $(mdsdevname 1)\
5401 $MDS_MOUNT_OPTS" EXIT
5402 mount_fstype mds1 || error "remount mds1 failed"
5404 for ((i = 0; i < 1; i++)); do
5405 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5406 local cat_file=$(do_facet mds1 $llog_reader \
5407 $mntpt/changelog_catalog | awk \
5408 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5409 [ -n "$cat_file" ] || error "no catalog file"
5411 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5412 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5413 [ -n "$entry" ] || error "no CREAT entry"
5416 local uidgid=$(echo $entry |
5417 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5418 [ -n "$uidgid" ] || error "uidgid is empty"
5419 echo "Got UID/GID $uidgid"
5420 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5421 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5422 local nid=$(echo $entry |
5423 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5424 [ -n "$nid" ] || error "nid is empty"
5426 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5427 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5429 run_test 606 "llog_reader groks changelog fields"
5432 check_and_cleanup_lustre