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 mkdir_on_mdt0 $DIR/$tdir
563 local f=$DIR/$tdir/$tfile
564 local fid=$(create_small_file $f)
568 $LFS hsm_archive $f || error "could not archive file"
569 wait_request_state $fid ARCHIVE SUCCEED
571 # Release and check states
572 $LFS hsm_release $f || error "could not release file"
573 echo -n "Verifying released state: "
574 check_hsm_flags $f "0x0000000d"
576 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
578 run_test 1a "mmap & cat a HSM released file"
584 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
585 error "failed to create file"
586 local fid=$(path2fid $f)
591 $LFS hsm_archive $f || error "could not archive file"
592 wait_request_state $fid ARCHIVE SUCCEED
595 $LFS hsm_release $f || error "could not release file"
596 echo "verify released state: "
597 check_hsm_flags $f "0x0000000d" && echo "pass"
600 $LFS hsm_restore $f || error "could not restore file"
601 wait_request_state $fid RESTORE SUCCEED
602 echo "verify restored state: "
603 check_hsm_flags $f "0x00000009" && echo "pass"
607 mkdir_on_mdt0 $DIR/$tdir
608 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
609 error "failed to set default stripe"
610 local f=$DIR/$tdir/$tfile
614 run_test 1b "Archive, Release and Restore composite file"
620 local f=$DIR/$tdir/$tfile
623 # Test whether we can set the maximum archive number.
624 local LOCAL_HSM_ARCHIVE_NUMBER=32
625 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
626 error "root could not change hsm flags"
627 check_hsm_flags_user $f "0x00000001"
628 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
629 local st=$(get_hsm_archive_id $f)
630 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
631 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
633 # Test whether setting archive number 0 results in no change.
634 $LFS hsm_set --exists --archive-id 0 $f ||
635 error "root could not change hsm flags"
636 check_hsm_flags_user $f "0x00000001"
637 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
638 st=$(get_hsm_archive_id $f)
639 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
640 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
642 LOCAL_HSM_ARCHIVE_NUMBER=33
643 if [ "$CLIENT_VERSION" -ge $(version_code 2.11.56) ] &&
644 [ "$MDS1_VERSION" -ge $(version_code 2.11.56) ]; then
645 # lustre in the new version supports unlimited archiveID.
646 # Test whether setting archive number > 32 is supported
647 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
648 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
649 check_hsm_flags_user $f "0x00000001"
651 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
652 st=$(get_hsm_archive_id $f)
653 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
654 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
656 # old client or old mds can only support at most 32 archiveID
657 # test whether setting archive number > 32 results in error.
658 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
659 error "bitmap archive number is larger than 32"
660 check_hsm_flags_user $f "0x00000001"
663 # Test whether setting archive number 16 and archived flag.
664 LOCAL_HSM_ARCHIVE_NUMBER=16
665 $LFS hsm_set --exists --archived \
666 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
667 error "root could not change hsm flags"
668 check_hsm_flags_user $f "0x00000009"
669 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
670 st=$(get_hsm_archive_id $f)
671 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
672 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
674 run_test 1c "Check setting archive-id in lfs hsm_set"
677 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
678 skip "need MDS version at least 2.10.59"
680 mkdir_on_mdt0 $DIR/$tdir
681 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
682 error "failed to set default stripe"
683 local f=$DIR/$tdir/$tfile
687 run_test 1d "Archive, Release and Restore DoM file"
690 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
691 skip "skipped for lustre < $SEL_VER"
693 mkdir_on_mdt0 $DIR/$tdir
694 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
695 error "failed to set default stripe"
696 local comp_file=$DIR/$tdir/$tfile
698 test_1bde_base $comp_file
700 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
701 local found=$($LFS find $flg_opts $comp_file | wc -l)
702 [ $found -eq 1 ] || error "1st component not found"
704 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
705 found=$($LFS find $flg_opts $comp_file | wc -l)
706 [ $found -eq 1 ] || error "2nd component not found"
708 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
709 found=$($LFS find $flg_opts $comp_file | wc -l)
710 [ $found -eq 1 ] || error "3rd component not found"
712 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
713 found=$($LFS find $flg_opts $comp_file | wc -l)
714 [ $found -eq 1 ] || error "4th component not found"
716 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
717 found=$($LFS find $flg_opts $comp_file | wc -l)
718 [ $found -eq 1 ] || error "5th component not found"
720 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
721 found=$($LFS find $flg_opts $comp_file | wc -l)
722 [ $found -eq 1 ] || error "6th component not found"
724 sel_layout_sanity $comp_file 6
726 run_test 1e "Archive, Release and Restore SEL file"
729 local f=$DIR/$tdir/$tfile
731 mkdir_on_mdt0 $DIR/$tdir
732 create_empty_file "$f"
733 # New files are not dirty
734 check_hsm_flags $f "0x00000000"
736 # For test, we simulate an archived file.
737 $LFS hsm_set --exists $f || error "user could not change hsm flags"
738 check_hsm_flags $f "0x00000001"
740 # chmod do not put the file dirty
741 chmod 600 $f || error "could not chmod test file"
742 check_hsm_flags $f "0x00000001"
744 # chown do not put the file dirty
745 chown $RUNAS_ID $f || error "could not chown test file"
746 check_hsm_flags $f "0x00000001"
748 # truncate put the file dirty
749 $TRUNCATE $f 1 || error "could not truncate test file"
750 check_hsm_flags $f "0x00000003"
752 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
753 check_hsm_flags $f "0x00000001"
755 run_test 2 "Check file dirtyness when doing setattr"
758 mkdir_on_mdt0 $DIR/$tdir
761 # New files are not dirty
763 check_hsm_flags $f "0x00000000"
765 # For test, we simulate an archived file.
766 $LFS hsm_set --exists $f ||
767 error "user could not change hsm flags"
768 check_hsm_flags $f "0x00000001"
770 # Reading a file, does not set dirty
771 cat $f > /dev/null || error "could not read file"
772 check_hsm_flags $f "0x00000001"
774 # Open for write without modifying data, does not set dirty
775 openfile -f O_WRONLY $f || error "could not open test file"
776 check_hsm_flags $f "0x00000001"
778 # Append to a file sets it dirty
779 cp -p /etc/passwd $f.append || error "could not create file"
780 $LFS hsm_set --exists $f.append ||
781 error "user could not change hsm flags"
782 dd if=/etc/passwd of=$f.append bs=1 count=3\
783 conv=notrunc oflag=append status=noxfer ||
784 file_creation_failure dd $f.append $?
785 check_hsm_flags $f.append "0x00000003"
787 # Modify a file sets it dirty
788 cp -p /etc/passwd $f.modify || error "could not create file"
789 $LFS hsm_set --exists $f.modify ||
790 error "user could not change hsm flags"
791 dd if=/dev/zero of=$f.modify bs=1 count=3\
792 conv=notrunc status=noxfer ||
793 file_creation_failure dd $f.modify $?
794 check_hsm_flags $f.modify "0x00000003"
796 # Open O_TRUNC sets dirty
797 cp -p /etc/passwd $f.trunc || error "could not create file"
798 $LFS hsm_set --exists $f.trunc ||
799 error "user could not change hsm flags"
800 cp /etc/group $f.trunc || error "could not override a file"
801 check_hsm_flags $f.trunc "0x00000003"
803 # Mmapped a file sets dirty
804 cp -p /etc/passwd $f.mmap || error "could not create file"
805 $LFS hsm_set --exists $f.mmap ||
806 error "user could not change hsm flags"
807 multiop $f.mmap OSMWUc || error "could not mmap a file"
808 check_hsm_flags $f.mmap "0x00000003"
810 run_test 3 "Check file dirtyness when opening for write"
813 local f=$DIR/$tdir/$tfile
814 local fid=$(create_small_file $f)
817 local st=$(get_request_state $fid CANCEL)
818 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
820 run_test 4 "Useless cancel must not be registered"
823 # test needs a running copytool
826 mkdir_on_mdt0 $DIR/$tdir
827 local f=$DIR/$tdir/$tfile
828 local fid=$(copy_file /etc/passwd $f)
830 wait_request_state $fid ARCHIVE SUCCEED
832 check_hsm_flags $f "0x00000009"
834 run_test 8 "Test default archive number"
836 test_9A() { # was test_9
837 # we do not use the default one to be sure
838 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
839 copytool setup --archive-id $archive_id
841 # give time for CT to register with MDTs
842 sleep $(($MDSCOUNT*2))
843 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
844 check_agent_registered $uuid
846 mkdir_on_mdt0 $DIR/$tdir
848 local f=$DIR/$tdir/$tfile
849 local fid=$(copy_file /etc/passwd $f)
850 $LFS hsm_archive --archive $archive_id $f
851 wait_request_state $fid ARCHIVE SUCCEED
853 check_hsm_flags $f "0x00000009"
855 run_test 9A "Use of explicit archive number, with dedicated copytool"
858 needclients 3 || return 0
864 # start all of the copytools
865 for n in $(seq $AGTCOUNT); do
866 copytool setup --facet agt$n
869 mkdir_on_mdt0 $DIR/$tdir
872 for n in $(seq $AGTCOUNT); do
873 file=$DIR/$tdir/$tfile.$n
874 fid=$(create_small_file $file)
876 $LFS hsm_archive $file || error "could not archive file $file"
877 wait_request_state $fid ARCHIVE SUCCEED
878 check_hsm_flags $file "0x00000009"
881 run_test 9a "Multiple remote agents"
884 # test needs a running copytool
887 mkdir_on_mdt0 $DIR/$tdir
888 mkdir -p $DIR/$tdir/d1
889 local f=$DIR/$tdir/$tfile
890 local fid=$(copy_file /etc/hosts $f)
891 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
892 error "hsm_archive failed"
893 wait_request_state $fid ARCHIVE SUCCEED
895 local hsm_root="$(copytool_device $SINGLEAGT)"
896 local archive="$(do_facet $SINGLEAGT \
897 find "$hsm_root" -name "$fid" -print0)"
898 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
900 echo "Verifying content"
901 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
902 echo "Verifying hsm state "
903 check_hsm_flags $f "0x00000009"
905 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
906 local st=$(get_hsm_archive_id $f)
907 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
908 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
910 run_test 10a "Archive a file"
913 # test needs a running copytool
916 mkdir_on_mdt0 $DIR/$tdir
917 local f=$DIR/$tdir/$tfile
918 local fid=$(copy_file /etc/hosts $f)
919 $LFS hsm_archive $f || error "archive request failed"
920 wait_request_state $fid ARCHIVE SUCCEED
922 $LFS hsm_archive $f || error "archive of non dirty file failed"
923 local cnt=$(get_request_count $fid ARCHIVE)
924 [[ "$cnt" == "1" ]] ||
925 error "archive of non dirty file must not make a request"
927 run_test 10b "Archive of non dirty file must work without doing request"
930 # test needs a running copytool
934 local f=$DIR/$tdir/$tfile
935 local fid=$(copy_file /etc/hosts $f)
936 $LFS hsm_set --noarchive $f
937 $LFS hsm_archive $f && error "archive a noarchive file must fail"
940 run_test 10c "Check forbidden archive"
943 # test needs a running copytool
946 mkdir_on_mdt0 $DIR/$tdir
947 local f=$DIR/$tdir/$tfile
948 local fid=$(copy_file /etc/hosts $f)
949 $LFS hsm_archive $f || error "cannot archive $f"
950 wait_request_state $fid ARCHIVE SUCCEED
952 local ar=$(get_hsm_archive_id $f)
953 local dflt=$(get_hsm_param default_archive_id)
954 [[ $ar == $dflt ]] ||
955 error "archived file is not on default archive: $ar != $dflt"
957 run_test 10d "Archive a file on the default archive id"
960 mkdir_on_mdt0 $DIR/$tdir
961 copy2archive /etc/hosts $tdir/$tfile
962 local f=$DIR/$tdir/$tfile
964 copytool import $tdir/$tfile $f
965 echo -n "Verifying released state: "
966 check_hsm_flags $f "0x0000000d"
968 local LSZ=$(stat -c "%s" $f)
969 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
971 echo "Verifying imported size $LSZ=$ASZ"
972 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
973 echo -n "Verifying released pattern: "
974 local PTRN=$($LFS getstripe -L $f)
976 [[ $PTRN == released ]] || error "Is not released"
977 local fid=$(path2fid $f)
978 echo "Verifying new fid $fid in archive"
980 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
981 error "No archive for fid $fid"
983 run_test 11a "Import a file"
986 # test needs a running copytool
989 mkdir_on_mdt0 $DIR/$tdir
990 local f=$DIR/$tdir/$tfile
991 local fid=$(copy_file /etc/hosts $f)
992 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
993 error "hsm_archive failed"
994 wait_request_state $fid ARCHIVE SUCCEED
996 local FILE_HASH=$(md5sum $f)
999 copytool import $fid $f
1001 echo "$FILE_HASH" | md5sum -c
1003 [[ $? -eq 0 ]] || error "Restored file differs"
1005 run_test 11b "Import a deleted file using its FID"
1008 pool_add $TESTNAME || error "Pool creation failed"
1009 pool_add_targets $TESTNAME 1 1 || error "pool_add_targets failed"
1012 $LFS setstripe -p "$TESTNAME" $DIR/$tdir
1014 copy2archive /etc/hosts $tdir/$tfile
1015 copytool import $tdir/$tfile $DIR/$tdir/$tfile
1017 run_test 11c "Import a file to a directory with a pool"
1020 # test needs a running copytool
1023 mkdir_on_mdt0 $DIR/$tdir
1024 copy2archive /etc/hosts $tdir/$tfile
1026 local f=$DIR/$tdir/$tfile
1027 copytool import $tdir/$tfile $f
1028 local f2=$DIR2/$tdir/$tfile
1029 echo "Verifying released state: "
1030 check_hsm_flags $f2 "0x0000000d"
1032 local fid=$(path2fid $f2)
1033 $LFS hsm_restore $f2
1034 wait_request_state $fid RESTORE SUCCEED
1036 echo "Verifying file state: "
1037 check_hsm_flags $f2 "0x00000009"
1039 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1041 [[ $? -eq 0 ]] || error "Restored file differs"
1043 run_test 12a "Restore an imported file explicitly"
1046 # test needs a running copytool
1049 mkdir_on_mdt0 $DIR/$tdir
1050 copy2archive /etc/hosts $tdir/$tfile
1052 local f=$DIR/$tdir/$tfile
1053 copytool import $tdir/$tfile $f
1054 echo "Verifying released state: "
1055 check_hsm_flags $f "0x0000000d"
1057 cat $f > /dev/null || error "File read failed"
1059 echo "Verifying file state after restore: "
1060 check_hsm_flags $f "0x00000009"
1062 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1064 [[ $? -eq 0 ]] || error "Restored file differs"
1066 run_test 12b "Restore an imported file implicitly"
1069 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1071 # test needs a running copytool
1074 local f=$DIR/$tdir/$tfile
1075 mkdir_on_mdt0 $DIR/$tdir
1076 $LFS setstripe -c 2 "$f"
1077 local fid=$(create_file "$f" 1M 5)
1079 local FILE_CRC=$(md5sum $f)
1081 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1082 wait_request_state $fid ARCHIVE SUCCEED
1083 $LFS hsm_release $f || error "release $f failed"
1085 echo "$FILE_CRC" | md5sum -c
1087 [[ $? -eq 0 ]] || error "Restored file differs"
1089 run_test 12c "Restore a file with stripe of 2"
1092 # test needs a running copytool
1095 mkdir_on_mdt0 $DIR/$tdir
1097 local f=$DIR/$tdir/$tfile
1098 local fid=$(copy_file /etc/hosts $f)
1099 $LFS hsm_restore $f || error "restore of non archived file failed"
1100 local cnt=$(get_request_count $fid RESTORE)
1101 [[ "$cnt" == "0" ]] ||
1102 error "restore non archived must not make a request"
1103 $LFS hsm_archive $f ||
1104 error "archive request failed"
1105 wait_request_state $fid ARCHIVE SUCCEED
1106 $LFS hsm_restore $f ||
1107 error "restore of non released file failed"
1108 local cnt=$(get_request_count $fid RESTORE)
1109 [[ "$cnt" == "0" ]] ||
1110 error "restore a non dirty file must not make a request"
1112 run_test 12d "Restore of a non archived, non released file must work"\
1113 " without doing request"
1116 # test needs a running copytool
1119 mkdir_on_mdt0 $DIR/$tdir
1120 local f=$DIR/$tdir/$tfile
1121 local fid=$(copy_file /etc/hosts $f)
1122 $LFS hsm_archive $f || error "archive request failed"
1123 wait_request_state $fid ARCHIVE SUCCEED
1126 cat /etc/hosts >> $f
1130 $LFS hsm_restore $f && error "restore a dirty file must fail"
1133 run_test 12e "Check forbidden restore"
1136 # test needs a running copytool
1139 mkdir_on_mdt0 $DIR/$tdir
1140 local f=$DIR/$tdir/$tfile
1141 local fid=$(copy_file /etc/hosts $f)
1143 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1144 wait_request_state $fid ARCHIVE SUCCEED
1145 $LFS hsm_release $f || error "release of $f failed"
1147 wait_request_state $fid RESTORE SUCCEED
1149 echo -n "Verifying file state: "
1150 check_hsm_flags $f "0x00000009"
1152 diff -q /etc/hosts $f
1154 [[ $? -eq 0 ]] || error "Restored file differs"
1156 run_test 12f "Restore a released file explicitly"
1159 # test needs a running copytool
1162 mkdir_on_mdt0 $DIR/$tdir
1163 local f=$DIR/$tdir/$tfile
1164 local fid=$(copy_file /etc/hosts $f)
1166 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1167 wait_request_state $fid ARCHIVE SUCCEED
1168 $LFS hsm_release $f || error "release of $f failed"
1170 diff -q /etc/hosts $f
1173 # we check we had a restore done
1174 wait_request_state $fid RESTORE SUCCEED
1176 [[ $st -eq 0 ]] || error "Restored file differs"
1178 run_test 12g "Restore a released file implicitly"
1181 needclients 2 || return 0
1183 # test needs a running copytool
1186 mkdir_on_mdt0 $DIR/$tdir
1187 local f=$DIR/$tdir/$tfile
1188 local fid=$(copy_file /etc/hosts $f)
1190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1191 wait_request_state $fid ARCHIVE SUCCEED
1192 $LFS hsm_release $f || error "release of $f failed"
1194 do_node $CLIENT2 diff -q /etc/hosts $f
1197 # we check we had a restore done
1198 wait_request_state $fid RESTORE SUCCEED
1200 [[ $st -eq 0 ]] || error "Restored file differs"
1202 run_test 12h "Restore a released file implicitly from a second node"
1205 # test needs a running copytool
1208 mkdir_on_mdt0 $DIR/$tdir
1209 local f=$DIR/$tdir/$tfile
1210 local fid=$(copy_file /etc/passwd $f)
1211 $LFS hsm_archive $f || error "archive of $f failed"
1212 wait_request_state $fid ARCHIVE SUCCEED
1214 $LFS hsm_release $f || error "release of $f failed"
1218 [[ $? -eq 0 ]] || error "Restored file differs"
1220 run_test 12m "Archive/release/implicit restore"
1223 # test needs a running copytool
1227 copy2archive /etc/hosts $tdir/$tfile
1229 local f=$DIR/$tdir/$tfile
1230 copytool import $tdir/$tfile $f
1232 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1233 error "Restored file differs"
1235 $LFS hsm_release $f || error "release of $f failed"
1237 run_test 12n "Import/implicit restore/release"
1240 # test needs a running copytool
1243 mkdir_on_mdt0 $DIR/$tdir
1244 local f=$DIR/$tdir/$tfile
1245 local fid=$(copy_file /etc/hosts $f)
1247 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1248 wait_request_state $fid ARCHIVE SUCCEED
1249 $LFS hsm_release $f || error "release of $f failed"
1251 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1252 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1254 # set no retry action mode
1257 diff -q /etc/hosts $f
1260 # we check we had a restore failure
1261 wait_request_state $fid RESTORE FAILED
1263 [[ $st -eq 0 ]] && error "Restore must fail"
1265 # remove no retry action mode
1268 # check file is still released
1269 check_hsm_flags $f "0x0000000d"
1271 # retry w/o failure injection
1272 do_facet $SINGLEMDS lctl set_param fail_loc=0
1274 # to be sure previous RESTORE result is gone
1276 wait_for_grace_delay
1278 diff -q /etc/hosts $f
1281 # we check we had a restore done
1282 wait_request_state $fid RESTORE SUCCEED
1284 [[ $st -eq 0 ]] || error "Restored file differs"
1286 run_test 12o "Layout-swap failure during Restore leaves file released"
1289 # test needs a running copytool
1292 mkdir_on_mdt0 $DIR/$tdir
1293 local f=$DIR/$tdir/$tfile
1294 local fid=$(copy_file /etc/hosts $f)
1296 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1297 wait_request_state $fid ARCHIVE SUCCEED
1298 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1299 $LFS hsm_release $f || error "cannot release $f"
1300 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1301 $LFS hsm_release $f || error "cannot release $f"
1302 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1304 run_test 12p "implicit restore of a file on copytool mount point"
1307 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1308 skip "need MDS version at least 2.7.58"
1310 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1311 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1312 error "cannot mount $MOUNT3 on $SINGLEAGT"
1314 # test needs a running copytool
1315 copytool setup -m "$MOUNT3"
1317 mkdir_on_mdt0 $DIR/$tdir
1319 local f=$DIR/$tdir/$tfile
1320 local f2=$DIR2/$tdir/$tfile
1321 local fid=$(create_small_file $f)
1322 local orig_size=$(stat -c "%s" $f)
1324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1325 wait_request_state $fid ARCHIVE SUCCEED
1327 $LFS hsm_release $f || error "could not release file"
1328 check_hsm_flags $f "0x0000000d"
1331 wait_copytools || error "copytool failed to stop"
1333 cat $f > /dev/null &
1335 # wait a bit to allow implicit restore request to be handled.
1336 # if not, next stat would also block on layout-lock.
1339 local size=$(stat -c "%s" $f2)
1340 [ $size -eq $orig_size ] ||
1341 error "$f2: wrong size after archive: $size != $orig_size"
1343 copytool setup -m "$MOUNT3"
1347 size=$(stat -c "%s" $f)
1348 [ $size -eq $orig_size ] ||
1349 error "$f: wrong size after restore: $size != $orig_size"
1351 size=$(stat -c "%s" $f2)
1352 [ $size -eq $orig_size ] ||
1353 error "$f2: wrong size after restore: $size != $orig_size"
1357 size=$(stat -c "%s" $f)
1359 error "$f: wrong size after overwrite: $size != 0"
1361 size=$(stat -c "%s" $f2)
1363 error "$f2: wrong size after overwrite: $size != 0"
1365 run_test 12q "file attributes are refreshed after restore"
1368 # test needs a running copytool
1371 mkdir_on_mdt0 $DIR/$tdir
1372 local f=$DIR/$tdir/$tfile
1373 local fid=$(copy_file /etc/hosts $f)
1375 $LFS hsm_archive $f || error "archive of $f failed"
1376 wait_request_state $fid ARCHIVE SUCCEED
1377 $LFS hsm_release $f || error "release of $f failed"
1379 offset=$(lseek_test -d 7 $f)
1381 # we check we had a restore done
1382 wait_request_state $fid RESTORE SUCCEED
1383 [[ $offset == 7 ]] || error "offset $offset != 7"
1385 run_test 12r "lseek restores released file"
1388 local f=$DIR/$tdir/$tfile
1392 (( MDS1_VERSION >= $(version_code 2.15.50) )) ||
1393 skip "Need MDS version newer than 2.15.50"
1395 # test needs a running copytool
1398 mkdir_on_mdt0 $DIR/$tdir
1399 fid=$(copy_file /etc/hosts $f)
1401 $LFS hsm_archive $f || error "archive of $f failed"
1402 wait_request_state $fid ARCHIVE SUCCEED
1403 $LFS hsm_release $f || error "release of $f failed"
1405 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_HSM_RESTORE_RACE 0x8000018b
1406 do_facet mds1 $LCTL set_param fail_loc=0x8000018b
1407 cat $f > /dev/null & pid1=$!
1408 cat $f > /dev/null & pid2=$!
1410 wait $pid1 || error "cat process 1 fail (pid: $pid1)"
1411 wait $pid2 || error "cat process 2 fail (pid: $pid2)"
1413 # Race exists if more than 1 restore requests is registered
1414 assert_request_count $fid RESTORE 1
1416 run_test 12s "race between restore requests"
1420 for i in {1..10}; do
1421 local archive_dir="$(hsm_root)"/subdir/dir.$i
1423 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1424 for j in {1..10}; do
1425 local archive_file="$archive_dir"/file.$j
1427 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1433 copytool import "subdir" "$DIR/$tdir"
1435 # To check the import, the test uses diff with the -r flag
1436 # This is nice, but diff only checks files one by one, and triggering
1437 # an implicit restore for one file at a time will consume as many
1438 # seconds as there are files to compare. To speed this up, a restore
1439 # operation is triggered manually first.
1441 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1443 # Compare the imported data
1444 do_facet $SINGLEAGT \
1445 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1446 error "imported files differ from archived data"
1448 run_test 13 "Recursively import and restore a directory"
1451 # test needs a running copytool
1454 mkdir_on_mdt0 $DIR/$tdir
1457 local f=$DIR/$tdir/$tfile
1458 local fid=$(create_small_file $f)
1459 local sum=$(md5sum $f | awk '{print $1}')
1460 $LFS hsm_archive $f || error "could not archive file"
1461 wait_request_state $fid ARCHIVE SUCCEED
1463 # create released file (simulate llapi_hsm_import call)
1464 local fid2=$(create_empty_file "$f")
1465 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1466 $LFS hsm_release $f || error "could not release file"
1468 # rebind the archive to the newly created file
1469 echo "rebind $fid to $fid2"
1471 copytool rebind $fid $fid2
1473 # restore file and compare md5sum
1474 local sum2=$(md5sum $f | awk '{print $1}')
1476 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1478 run_test 14 "Rebind archived file to a new fid"
1481 # test needs a running copytool
1484 mkdir_on_mdt0 $DIR/$tdir
1487 local f=$DIR/$tdir/$tfile
1489 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1493 for i in $(seq 1 $count); do
1494 fids[$i]=$(create_small_file $f.$i)
1495 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1496 $LFS hsm_archive $f.$i || error "could not archive file"
1498 wait_all_done $(($count*60))
1500 stack_trap "rm -f $tmpfile" EXIT
1503 for i in $(seq 1 $count); do
1504 local fid2=$(create_empty_file "${f}.${i}")
1505 # add the rebind operation to the list
1506 echo ${fids[$i]} $fid2 >> $tmpfile
1508 # set it released (simulate llapi_hsm_import call)
1509 $LFS hsm_set --archived --exists $f.$i ||
1510 error "could not force hsm flags"
1511 $LFS hsm_release $f.$i || error "could not release file"
1513 nl=$(wc -l < $tmpfile)
1514 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1516 echo "rebind list of files"
1517 copytool rebind "$tmpfile"
1519 # restore files and compare md5sum
1520 for i in $(seq 1 $count); do
1521 local sum2=$(md5sum $f.$i | awk '{print $1}')
1522 [[ $sum2 == ${sums[$i]} ]] ||
1523 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1526 run_test 15 "Rebind a list of files"
1529 # test needs a running copytool
1533 # create a known size file so we can verify transfer speed
1536 dd if=/dev/zero of=$ref bs=1M count=20
1538 mkdir_on_mdt0 $DIR/$tdir
1539 local f=$DIR/$tdir/$tfile
1540 local fid=$(copy_file $ref $f)
1542 local start=$(date +%s)
1544 wait_request_state $fid ARCHIVE SUCCEED
1545 local end=$(date +%s)
1546 # Add 1 to account for rounding errors between start and end (LU-8155)
1547 local duration=$((end - start + 1))
1549 [[ $duration -ge $((goal - 1)) ]] ||
1550 error "Transfer is too fast $duration < $goal"
1552 run_test 16 "Test CT bandwith control option"
1555 local f=$DIR/$tdir/$tfile
1556 create_empty_file "$f"
1558 # Could not release a non-archived file
1559 $LFS hsm_release $f && error "release should not succeed"
1561 # For following tests, we must test them with HS_ARCHIVED set
1562 $LFS hsm_set --exists --archived $f || error "could not add flag"
1564 # Could not release a file if no-release is set
1565 $LFS hsm_set --norelease $f || error "could not add flag"
1566 $LFS hsm_release $f && error "release should not succeed"
1567 $LFS hsm_clear --norelease $f || error "could not remove flag"
1569 # Could not release a file if lost
1570 $LFS hsm_set --lost $f || error "could not add flag"
1571 $LFS hsm_release $f && error "release should not succeed"
1572 $LFS hsm_clear --lost $f || error "could not remove flag"
1574 # Could not release a file if dirty
1575 $LFS hsm_set --dirty $f || error "could not add flag"
1576 $LFS hsm_release $f && error "release should not succeed"
1577 $LFS hsm_clear --dirty $f || error "could not remove flag"
1579 run_test 20 "Release is not permitted"
1582 # test needs a running copytool
1584 mkdir_on_mdt0 $DIR/$tdir
1586 local f=$DIR/$tdir/test_release
1588 # Create a file and check its states
1589 local fid=$(create_small_file $f)
1590 check_hsm_flags $f "0x00000000"
1592 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1593 # used until file is flushed to disk
1594 if [ "$ost1_FSTYPE" == "zfs" ]; then
1595 # this causes an OST_SYNC rpc to be sent
1596 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1597 # clear locks to reread file data
1598 cancel_lru_locks osc
1601 local orig_size=$(stat -c "%s" $f)
1602 local orig_blocks=$(stat -c "%b" $f)
1604 start_full_debug_logging
1606 $LFS hsm_archive $f || error "could not archive file"
1607 wait_request_state $fid ARCHIVE SUCCEED
1609 local blocks=$(stat -c "%b" $f)
1610 [ $blocks -eq $orig_blocks ] ||
1611 error "$f: wrong block number after archive: " \
1612 "$blocks != $orig_blocks"
1613 local size=$(stat -c "%s" $f)
1614 [ $size -eq $orig_size ] ||
1615 error "$f: wrong size after archive: $size != $orig_size"
1617 # Release and check states
1618 $LFS hsm_release $f || error "could not release file"
1619 check_hsm_flags $f "0x0000000d"
1621 blocks=$(stat -c "%b" $f)
1622 [ $blocks -gt 5 ] &&
1623 error "$f: too many blocks after release: $blocks > 5"
1624 size=$(stat -c "%s" $f)
1625 [ $size -ne $orig_size ] &&
1626 error "$f: wrong size after release: $size != $orig_size"
1628 # Check we can release an file without stripe info
1632 check_hsm_flags $f "0x00000000"
1633 $LFS hsm_archive $f || error "could not archive file"
1634 wait_request_state $fid ARCHIVE SUCCEED
1636 # Release and check states
1637 $LFS hsm_release $f || error "could not release file"
1638 check_hsm_flags $f "0x0000000d"
1640 # Release again a file that is already released is OK
1641 $LFS hsm_release $f || fail "second release should succeed"
1642 check_hsm_flags $f "0x0000000d"
1644 stop_full_debug_logging
1646 run_test 21 "Simple release tests"
1649 # test needs a running copytool
1651 mkdir_on_mdt0 $DIR/$tdir
1653 local f=$DIR/$tdir/test_release
1654 local swap=$DIR/$tdir/test_swap
1656 # Create a file and check its states
1657 local fid=$(create_small_file $f)
1658 check_hsm_flags $f "0x00000000"
1660 $LFS hsm_archive $f || error "could not archive file"
1661 wait_request_state $fid ARCHIVE SUCCEED
1663 # Release and check states
1664 $LFS hsm_release $f || error "could not release file"
1665 check_hsm_flags $f "0x0000000d"
1667 create_small_file $swap
1668 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1672 run_test 22 "Could not swap a release file"
1675 # test needs a running copytool
1677 mkdir_on_mdt0 $DIR/$tdir
1679 local f=$DIR/$tdir/test_mtime
1681 # Create a file and check its states
1682 local fid=$(create_small_file $f)
1683 check_hsm_flags $f "0x00000000"
1685 $LFS hsm_archive $f || error "could not archive file"
1686 wait_request_state $fid ARCHIVE SUCCEED
1688 # Set modification time in the past
1689 touch -m -a -d @978261179 $f
1691 # Release and check states
1692 $LFS hsm_release $f || error "could not release file"
1693 check_hsm_flags $f "0x0000000d"
1695 local MTIME=$(stat -c "%Y" $f)
1696 local ATIME=$(stat -c "%X" $f)
1697 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1698 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1700 run_test 23 "Release does not change a/mtime (utime)"
1703 local file=$DIR/$tdir/$tfile
1712 # test needs a running copytool
1714 mkdir_on_mdt0 $DIR/$tdir
1716 fid=$(create_small_file $file)
1718 # Create a file and check its states
1719 check_hsm_flags $file "0x00000000"
1721 # Ensure atime is less than mtime and ctime.
1725 atime0=$(stat -c "%X" $file)
1726 mtime0=$(stat -c "%Y" $file)
1727 ctime0=$(stat -c "%Z" $file)
1729 [ $atime0 -lt $mtime0 ] ||
1730 error "atime $atime0 is not less than mtime $mtime0"
1732 [ $atime0 -lt $ctime0 ] ||
1733 error "atime $atime0 is not less than ctime $ctime0"
1735 # Archive should not change any timestamps.
1736 $LFS hsm_archive $file || error "cannot archive '$file'"
1737 wait_request_state $fid ARCHIVE SUCCEED
1739 atime1=$(stat -c "%X" $file)
1740 mtime1=$(stat -c "%Y" $file)
1741 ctime1=$(stat -c "%Z" $file)
1743 [ $atime0 -eq $atime1 ] ||
1744 error "archive changed atime from $atime0 to $atime1"
1746 [ $mtime0 -eq $mtime1 ] ||
1747 error "archive changed mtime from $mtime0 to $mtime1"
1749 [ $ctime0 -eq $ctime1 ] ||
1750 error "archive changed ctime from $ctime0 to $ctime1"
1752 # Release should not change any timestamps.
1753 $LFS hsm_release $file || error "cannot release '$file'"
1754 check_hsm_flags $file "0x0000000d"
1756 atime1=$(stat -c "%X" $file)
1757 mtime1=$(stat -c "%Y" $file)
1758 ctime1=$(stat -c "%Z" $file)
1760 [ $atime0 -eq $atime1 ] ||
1761 error "release changed atime from $atime0 to $atime1"
1763 [ $mtime0 -eq $mtime1 ] ||
1764 error "release changed mtime from $mtime0 to $mtime1"
1766 [ $ctime0 -eq $ctime1 ] ||
1767 error "release changed ctime from $ctime0 to $ctime1"
1769 # Restore should not change any timestamps.
1770 $LFS hsm_restore $file
1771 wait_request_state $fid RESTORE SUCCEED
1773 atime1=$(stat -c "%X" $file)
1774 mtime1=$(stat -c "%Y" $file)
1775 ctime1=$(stat -c "%Z" $file)
1777 [ $atime0 -eq $atime1 ] ||
1778 error "restore changed atime from $atime0 to $atime1"
1780 [ $mtime0 -eq $mtime1 ] ||
1781 error "restore changed mtime from $mtime0 to $mtime1"
1783 [ $ctime0 -eq $ctime1 ] ||
1784 error "restore changed ctime from $ctime0 to $ctime1"
1787 wait_copytools || error "Copytools failed to stop"
1789 # Once more, after unmount and mount.
1790 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1791 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1793 atime1=$(stat -c "%X" $file)
1794 mtime1=$(stat -c "%Y" $file)
1795 ctime1=$(stat -c "%Z" $file)
1797 [ $atime0 -eq $atime1 ] ||
1798 error "remount changed atime from $atime0 to $atime1"
1800 [ $mtime0 -eq $mtime1 ] ||
1801 error "remount changed mtime from $mtime0 to $mtime1"
1803 [ $ctime0 -eq $ctime1 ] ||
1804 error "remount changed ctime from $ctime0 to $ctime1"
1806 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1809 local file=$DIR/$tdir/$tfile
1815 # Test needs a running copytool.
1817 mkdir_on_mdt0 $DIR/$tdir
1819 # Check that root can do HSM actions on a regular user's file.
1820 fid=$(create_small_file $file)
1821 sum0=$(md5sum $file)
1823 chown $RUNAS_ID:$RUNAS_GID $file ||
1824 error "cannot chown '$file' to '$RUNAS_ID'"
1826 chmod ugo-w $DIR/$tdir ||
1827 error "cannot chmod '$DIR/$tdir'"
1829 $LFS hsm_archive $file
1830 wait_request_state $fid ARCHIVE SUCCEED
1832 $LFS hsm_release $file
1833 check_hsm_flags $file "0x0000000d"
1835 $LFS hsm_restore $file
1836 wait_request_state $fid RESTORE SUCCEED
1838 # Check that ordinary user can get HSM state.
1839 $RUNAS $LFS hsm_state $file ||
1840 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1842 $LFS hsm_release $file
1843 check_hsm_flags $file "0x0000000d"
1845 # Check that ordinary user can accessed released file.
1846 sum1=$($RUNAS md5sum $file) ||
1847 error "user '$RUNAS_ID' cannot read '$file'"
1849 [ "$sum0" == "$sum1" ] ||
1850 error "md5sum mismatch for '$file'"
1852 run_test 24b "root can archive, release, and restore user files"
1855 local file=$DIR/$tdir/$tfile
1856 local action=archive
1861 # test needs a running copytool
1863 mkdir_on_mdt0 $DIR/$tdir
1865 # Save the default masks and check that cleanup_24c will
1866 # restore the request masks correctly.
1867 user_save=$(get_hsm_param user_request_mask)
1868 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1869 group_save=$(get_hsm_param group_request_mask)
1870 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1871 other_save=$(get_hsm_param other_request_mask)
1872 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1874 [ "$user_save" == RESTORE ] ||
1875 error "user_request_mask is '$user_save' expected 'RESTORE'"
1876 [ "$group_save" == RESTORE ] ||
1877 error "group_request_mask is '$group_save' expected 'RESTORE'"
1878 [ "$other_save" == RESTORE ] ||
1879 error "other_request_mask is '$other_save' expected 'RESTORE'"
1882 create_small_file $file
1883 chown $RUNAS_ID:$GROUP $file ||
1884 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1886 $RUNAS $LFS hsm_$action $file &&
1887 error "$action by user should fail"
1889 set_hsm_param user_request_mask $action
1890 $RUNAS $LFS hsm_$action $file ||
1891 error "$action by user should succeed"
1894 create_small_file $file
1895 chown nobody:$RUNAS_GID $file ||
1896 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1898 $RUNAS $LFS hsm_$action $file &&
1899 error "$action by group should fail"
1901 set_hsm_param group_request_mask $action
1902 $RUNAS $LFS hsm_$action $file ||
1903 error "$action by group should succeed"
1906 create_small_file $file
1907 chown nobody:$GROUP $file ||
1908 error "cannot chown '$file' to 'nobody:$GROUP'"
1910 $RUNAS $LFS hsm_$action $file &&
1911 error "$action by other should fail"
1913 set_hsm_param other_request_mask $action
1914 $RUNAS $LFS hsm_$action $file ||
1915 error "$action by other should succeed"
1917 run_test 24c "check that user,group,other request masks work"
1920 local file1=$DIR/$tdir/$tfile
1921 local file2=$DIR2/$tdir/$tfile
1925 mkdir_on_mdt0 $DIR/$tdir
1927 fid1=$(create_small_file $file1)
1930 $LFS getstripe $file1
1932 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1933 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1934 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1936 copytool setup -m "$MOUNT3"
1938 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1939 mount -o remount,ro $MOUNT2
1941 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1943 fid2=$(path2fid $file2)
1944 [ "$fid1" == "$fid2" ] ||
1945 error "FID mismatch '$fid1' != '$fid2'"
1947 $LFS hsm_archive $file2 &&
1948 error "archive should fail on read-only mount"
1949 check_hsm_flags $file1 "0x00000000"
1951 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1952 wait_request_state $fid1 ARCHIVE SUCCEED
1954 $LFS hsm_release $file1
1955 $LFS hsm_restore $file2
1956 wait_request_state $fid1 RESTORE SUCCEED
1958 $LFS hsm_release $file1 || error "cannot release '$file1'"
1959 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1961 $LFS hsm_release $file2 &&
1962 error "release should fail on read-only mount"
1966 run_test 24d "check that read-only mounts are respected"
1970 mkdir_on_mdt0 $DIR/$tdir
1972 local f=$DIR/$tdir/$tfile
1975 fid=$(create_small_file $f) || error "cannot create $f"
1976 $LFS hsm_archive $f || error "cannot archive $f"
1977 wait_request_state $fid ARCHIVE SUCCEED
1978 $LFS hsm_release $f || error "cannot release $f"
1979 while ! $LFS hsm_state $f | grep released; do
1983 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1985 run_test 24e "tar succeeds on HSM released files" # LU-6213
1988 # test needs a running copytool
1990 mkdir_on_mdt0 $DIR/$tdir
1992 mkdir -p $DIR/$tdir/d1
1993 local f=$DIR/$tdir/$tfile
1994 local fid=$(copy_file /etc/hosts $f)
1997 $LFS hsm_archive $f ||
1998 error "hsm_archive failed"
1999 wait_request_state $fid ARCHIVE SUCCEED
2000 $LFS hsm_release $f || error "cannot release $f"
2001 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2004 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2005 error "Can not recover the tar contents"
2007 echo "Sum0 = $sum0, sum1 = $sum1"
2008 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2010 run_test 24f "root can archive, release, and restore tar files"
2013 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2014 skip "need MDS version 2.11.56 or later"
2016 local file=$DIR/$tdir/$tfile
2019 echo "RUNAS = '$RUNAS'"
2023 mkdir_on_mdt0 $DIR/$tdir
2024 chmod ugo+rwx $DIR/$tdir
2026 echo "Please listen carefully as our options have changed." | tee $file
2027 fid=$(path2fid $file)
2030 $LFS hsm_archive $file
2031 wait_request_state $fid ARCHIVE SUCCEED
2032 check_hsm_flags $file 0x00000009 # exists archived
2034 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2035 check_hsm_flags $file 0x0000000b # exists dirty archived
2037 run_test 24g "write by non-owner still sets dirty" # LU-11369
2040 # test needs a running copytool
2044 copy2archive /etc/hosts $tdir/$tfile
2046 local f=$DIR/$tdir/$tfile
2048 copytool import $tdir/$tfile $f
2050 $LFS hsm_set --lost $f
2055 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2057 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2058 " (Operation not permitted)"
2061 # test needs a running copytool
2064 mkdir_on_mdt0 $DIR/$tdir
2066 local f=$DIR/$tdir/$tfile
2067 local fid=$(copy_file /etc/passwd $f)
2069 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2070 wait_request_state $fid ARCHIVE SUCCEED
2073 $LFS hsm_set --lost $f
2077 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2079 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2080 " (Operation not permitted)"
2082 test_26A() { # was test_26
2083 # test needs a running copytool
2085 mkdir_on_mdt0 $DIR/$tdir
2087 local f=$DIR/$tdir/$tfile
2088 local fid=$(create_empty_file "$f")
2090 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2091 wait_request_state $fid ARCHIVE SUCCEED
2094 wait_request_state $fid REMOVE SUCCEED
2096 check_hsm_flags $f "0x00000000"
2098 run_test 26A "Remove the archive of a valid file"
2101 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2102 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2104 # test needs a running copytool
2106 mkdir_on_mdt0 $DIR/$tdir
2108 local f=$DIR/$tdir/$tfile
2109 local fid=$(copy_file /etc/passwd $f)
2111 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2112 wait_request_state $fid ARCHIVE SUCCEED
2114 local f2=$DIR/$tdir/${tfile}_2
2115 local fid2=$(copy_file /etc/passwd $f2)
2117 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2118 wait_request_state $fid2 ARCHIVE SUCCEED
2120 local f3=$DIR/$tdir/${tfile}_3
2121 local fid3=$(copy_file /etc/passwd $f3)
2123 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2124 wait_request_state $fid3 ARCHIVE SUCCEED
2126 # set a long grace_delay vs short loop_period
2127 local orig_loop_period=$(get_hsm_param loop_period)
2128 local orig_grace_delay=$(get_hsm_param grace_delay)
2129 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2130 set_hsm_param loop_period 10
2131 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2132 set_hsm_param grace_delay 100
2136 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2137 set_hsm_param remove_archive_on_last_unlink 1
2139 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2144 wait_request_state $fid2 REMOVE SUCCEED
2146 assert_request_count $fid REMOVE 0 \
2147 "Unexpected archived data remove request for $f"
2148 assert_request_count $fid3 REMOVE 0 \
2149 "Unexpected archived data remove request for $f3"
2151 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2154 # test needs a running copytool
2156 mkdir_on_mdt0 $DIR/$tdir
2158 local f=$DIR/$tdir/$tfile
2159 local fid=$(copy_file /etc/passwd $f)
2161 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2162 wait_request_state $fid ARCHIVE SUCCEED
2164 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2165 set_hsm_param remove_archive_on_last_unlink 1
2168 cdt_check_state stopped
2172 wait_request_state $fid REMOVE WAITING
2176 # copytool must re-register
2178 wait_copytools || error "copytool failed to stop"
2181 wait_request_state $fid REMOVE SUCCEED
2183 run_test 26b "RAoLU policy when CDT off"
2186 # test needs a running copytool
2188 mkdir_on_mdt0 $DIR/$tdir
2190 local f=$DIR/$tdir/$tfile
2191 local fid=$(copy_file /etc/passwd $f)
2193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2194 wait_request_state $fid ARCHIVE SUCCEED
2196 local f2=$DIR/$tdir/${tfile}_2
2197 local fid2=$(copy_file /etc/passwd $f2)
2199 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2200 wait_request_state $fid2 ARCHIVE SUCCEED
2202 # set a long grace_delay vs short loop_period
2203 local orig_loop_period=$(get_hsm_param loop_period)
2204 local orig_grace_delay=$(get_hsm_param grace_delay)
2205 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2206 set_hsm_param loop_period 10
2207 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2208 set_hsm_param grace_delay 100
2210 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2211 set_hsm_param remove_archive_on_last_unlink 1
2213 multiop_bg_pause $f O_c || error "open $f failed"
2219 wait_request_state $fid2 REMOVE SUCCEED
2220 assert_request_count $fid REMOVE 0 \
2221 "Unexpected archived data remove request for $f"
2223 kill -USR1 $pid || error "multiop early exit"
2224 # should reach autotest timeout if multiop fails to trap
2225 # signal, close file, and exit ...
2226 wait $pid || error "wait PID $PID failed"
2228 wait_request_state $fid REMOVE SUCCEED
2230 run_test 26c "RAoLU effective when file closed"
2233 # test needs a running copytool
2235 mkdir_on_mdt0 $DIR/$tdir
2237 local f=$DIR/$tdir/$tfile
2238 local fid=$(create_small_file $f)
2240 $LFS hsm_archive $f || error "could not archive file"
2241 wait_request_state $fid ARCHIVE SUCCEED
2243 # set a long grace_delay vs short loop_period
2244 local orig_loop_period=$(get_hsm_param loop_period)
2245 local orig_grace_delay=$(get_hsm_param grace_delay)
2246 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2247 set_hsm_param loop_period 10
2248 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2249 set_hsm_param grace_delay 100
2251 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2252 set_hsm_param remove_archive_on_last_unlink 1
2254 multiop_bg_pause $f O_c || error "multiop failed"
2261 wait_request_state $fid REMOVE SUCCEED
2263 client_up || client_up || true
2265 kill -USR1 $MULTIPID
2266 wait $MULTIPID || error "multiop close failed"
2268 run_test 26d "RAoLU when Client eviction"
2271 # test needs a running copytool
2274 create_archive_file $tdir/$tfile
2275 local f=$DIR/$tdir/$tfile
2276 copytool import $tdir/$tfile $f
2277 local fid=$(path2fid $f)
2281 [[ $? != 0 ]] || error "Remove of a released file should fail"
2283 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2286 # test needs a running copytool
2288 mkdir_on_mdt0 $DIR/$tdir
2290 local f=$DIR/$tdir/$tfile
2291 local fid=$(create_empty_file "$f")
2293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2294 wait_request_state $fid ARCHIVE SUCCEED
2299 [[ $? != 0 ]] || error "Remove of a released file should fail"
2301 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2304 # test needs a running copytool
2306 mkdir_on_mdt0 $DIR/$tdir
2308 local f=$DIR/$tdir/$tfile
2309 local fid=$(create_empty_file "$f")
2311 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2312 wait_request_state $fid ARCHIVE SUCCEED
2321 wait_request_state $fid REMOVE SUCCEED
2323 run_test 28 "Concurrent archive/file remove"
2326 # Tests --mntpath and --archive options
2329 copytool setup -m "$MOUNT" -a $archive_id
2331 # Bad archive number
2332 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2333 grep "Invalid argument" ||
2334 error "unexpected hsm_remove failure (1)"
2336 # mntpath is present but file is given
2337 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2338 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2339 error "unexpected hsm_remove failure (2)"
2341 run_test 29a "Tests --mntpath and --archive options"
2344 # test needs a running copytool
2346 mkdir_on_mdt0 $DIR/$tdir
2348 local f=$DIR/$tdir/$tfile
2349 local fid=$(create_small_file $f)
2351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2352 wait_request_state $fid ARCHIVE SUCCEED
2356 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2357 wait_request_state $fid REMOVE SUCCEED
2359 run_test 29b "Archive/delete/remove by FID from the archive."
2362 # test needs a running copytool
2364 mkdir_on_mdt0 $DIR/$tdir
2366 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2367 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2368 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2370 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2371 wait_request_state $fid1 ARCHIVE SUCCEED
2372 wait_request_state $fid2 ARCHIVE SUCCEED
2373 wait_request_state $fid3 ARCHIVE SUCCEED
2375 rm -f $DIR/$tdir/$tfile-[1-3]
2377 echo $fid1 > $DIR/$tdir/list
2378 echo $fid2 >> $DIR/$tdir/list
2379 echo $fid3 >> $DIR/$tdir/list
2381 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2382 --filelist $DIR/$tdir/list
2383 wait_request_state $fid1 REMOVE SUCCEED
2384 wait_request_state $fid2 REMOVE SUCCEED
2385 wait_request_state $fid3 REMOVE SUCCEED
2387 run_test 29c "Archive/delete/remove by FID, using a file list."
2390 # test needs more than one CT
2391 needclients 3 || return 0
2397 # start all of the copytools
2398 for n in $(seq $AGTCOUNT); do
2399 copytool setup -f agt$n -a $n
2402 mkdir_on_mdt0 $DIR/$tdir
2405 file=$DIR/$tdir/$tfile
2406 fid=$(create_small_file $file)
2408 $LFS hsm_archive $file
2409 wait_request_state $fid ARCHIVE SUCCEED
2410 check_hsm_flags $file "0x00000009"
2414 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2415 error "cannot hsm_remove '$fid'"
2417 # give time for CDT to handle remove request and create broadcasted
2420 # remove request has been broadcasted ?
2421 local cnt=$(get_request_count $fid REMOVE)
2422 # broadcasted requests + original
2423 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2424 error "remove not broadcasted to all CTs"
2426 # give time for CDT and CTs to handle broadcasted
2427 wait_for_loop_period
2429 # each agent serves one different archive_id, so broadcasted
2430 # hsm_remove request should only succeed once and fail at all others
2434 for n in $(seq $AGTCOUNT); do
2435 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2436 $HSM_PARAM.actions | awk \
2437 '/'$fid'.*action=REMOVE archive#='$n'/ \
2438 {print \\\$13}' | cut -f2 -d=")
2439 if [[ "$res" == "SUCCEED" ]]; then
2441 elif [[ "$res" == "FAILED" ]]; then
2446 [[ $scnt -eq 1 ]] ||
2447 error "one and only CT should have removed successfully"
2449 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2450 error "all but one CT should have failed to remove"
2452 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2453 "request to be sent once for each registered archive_id"
2456 # restore at exec cannot work on agent node (because of Linux kernel
2457 # protection of executables)
2458 needclients 2 || return 0
2460 # test needs a running copytool
2464 copy2archive /bin/true $tdir/$tfile
2466 local f=$DIR/$tdir/true
2467 copytool import $tdir/$tfile $f
2469 local fid=$(path2fid $f)
2471 stack_trap "cdt_clear_no_retry" EXIT
2472 # set no retry action mode
2479 [[ $st == 0 ]] || error "Failed to exec a released file"
2481 run_test 30a "Restore at exec (import case)"
2484 # restore at exec cannot work on agent node (because of Linux kernel
2485 # protection of executables)
2486 needclients 2 || return 0
2488 # test needs a running copytool
2491 mkdir_on_mdt0 $DIR/$tdir
2492 local f=$DIR/$tdir/true
2493 local fid=$(copy_file /bin/true $f)
2495 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2496 wait_request_state $fid ARCHIVE SUCCEED
2500 stack_trap cdt_clear_no_retry EXIT
2501 # set no retry action mode
2509 [[ $st == 0 ]] || error "Failed to exec a released file"
2511 run_test 30b "Restore at exec (release case)"
2514 needclients 2 || return 0
2516 # test needs a running copytool
2519 mkdir_on_mdt0 $DIR/$tdir
2520 local f=$DIR/$tdir/SLEEP
2521 local slp_sum1=$(md5sum /bin/sleep)
2522 local fid=$(copy_file /bin/sleep $f)
2524 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2525 wait_request_state $fid ARCHIVE SUCCEED
2527 check_hsm_flags $f "0x0000000d"
2529 stack_trap cdt_clear_no_retry EXIT
2530 # set no retry action mode
2533 do_node $CLIENT2 "$f 10" &
2537 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2539 [[ $? == 0 ]] || error "Execution failed during run"
2541 if [[ $? != 0 ]]; then
2542 local slp_sum2=$(md5sum /bin/sleep)
2543 # in case sleep file is modified during the test
2544 [[ $slp_sum1 == $slp_sum2 ]] &&
2545 error "Binary overwritten during exec"
2548 check_hsm_flags $f "0x00000009"
2550 run_test 30c "Update during exec of released file must fail"
2552 restore_and_check_size() {
2555 local s=$(stat -c "%s" $f)
2557 local st=$(get_hsm_flags $f)
2561 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2563 n=$(stat -c "%s" $f)
2564 # we echo in both cases to show stat is not hang
2565 if [[ $n != $s ]]; then
2566 echo "size seen is $n != $s"
2569 echo "size seen is right: $n == $s"
2573 st=$(get_hsm_flags $f)
2575 if [[ "$st" = "0x00000009" ]]; then
2578 echo " restore is too long"
2579 wait_request_state $fid RESTORE SUCCEED
2585 # test needs a running copytool
2587 mkdir_on_mdt0 $DIR/$tdir
2589 create_archive_file $tdir/$tfile
2590 local f=$DIR/$tdir/$tfile
2591 copytool import $tdir/$tfile $f
2592 local fid=$($LFS path2fid $f)
2595 restore_and_check_size $f $fid
2598 [[ $err -eq 0 ]] || error "File size changed during restore"
2600 run_test 31a "Import a large file and check size during restore"
2604 # test needs a running copytool
2606 mkdir_on_mdt0 $DIR/$tdir
2608 local f=$DIR/$tdir/$tfile
2609 local fid=$(create_file "$f" 1MB 39)
2611 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2612 wait_request_state $fid ARCHIVE SUCCEED
2615 restore_and_check_size $f $fid
2618 [[ $err -eq 0 ]] || error "File size changed during restore"
2620 run_test 31b "Restore a large unaligned file and check size during restore"
2623 # test needs a running copytool
2625 mkdir_on_mdt0 $DIR/$tdir
2627 local f=$DIR/$tdir/$tfile
2628 local fid=$(create_file "$f" 1M 39)
2630 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2631 wait_request_state $fid ARCHIVE SUCCEED
2634 restore_and_check_size $f $fid
2637 [[ $err -eq 0 ]] || error "File size changed during restore"
2639 run_test 31c "Restore a large aligned file and check size during restore"
2642 local f=$DIR/$tdir/$tfile
2644 mkdir_on_mdt0 $DIR/$tdir
2645 local fid=$(create_empty_file "$f")
2649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2650 wait_request_state $fid ARCHIVE SUCCEED
2653 # Prevent restore from completing
2657 md5sum $f >/dev/null &
2660 wait_request_state $fid RESTORE STARTED
2665 # Check restore trigger process was killed
2667 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2669 run_test 33 "Kill a restore waiting process"
2672 # test needs a running copytool
2674 mkdir_on_mdt0 $DIR/$tdir
2676 local f=$DIR/$tdir/$tfile
2677 local fid=$(create_empty_file "$f")
2679 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2680 wait_request_state $fid ARCHIVE SUCCEED
2683 # Prevent restore from completing
2686 md5sum $f >/dev/null &
2689 wait_request_state $fid RESTORE STARTED
2691 # rm must not block during restore
2692 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2695 wait_request_state $fid RESTORE SUCCEED
2697 # Check md5sum pgm finished
2698 kill -0 $pid && error "Restore initiatior still running"
2699 wait $pid || error "Restore initiator failed with $?"
2701 # Check the file was actually deleted
2702 [ ! -f "$f" ] || error "$f was not deleted"
2704 run_test 34 "Remove file during restore"
2707 # test needs a running copytool
2709 mkdir_on_mdt0 $DIR/$tdir
2711 local f=$DIR/$tdir/$tfile
2712 local f1=$DIR/$tdir/$tfile-1
2713 local fid=$(create_empty_file "$f")
2714 local fid1=$(copy_file /etc/passwd $f1)
2716 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2717 wait_request_state $fid ARCHIVE SUCCEED
2720 # Prevent restore from completing
2723 md5sum $f >/dev/null &
2726 wait_request_state $fid RESTORE STARTED
2728 # mv must not block during restore
2729 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2732 wait_request_state $fid RESTORE SUCCEED
2734 # Check md5sum pgm finished
2735 kill -0 $pid && error "Restore initiatior still running"
2736 wait $pid || error "Restore initiator failed with $?"
2738 local fid2=$(path2fid $f)
2739 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2741 run_test 35 "Overwrite file during restore"
2744 # test needs a running copytool
2746 mkdir_on_mdt0 $DIR/$tdir
2748 local f=$DIR/$tdir/$tfile
2749 local fid=$(create_empty_file "$f")
2751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2752 wait_request_state $fid ARCHIVE SUCCEED
2755 # Prevent restore from completing
2758 md5sum $f >/dev/null &
2761 wait_request_state $fid RESTORE STARTED
2763 # mv must not block during restore
2764 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2765 error "mv '$f' '$f.new' failed with rc=$?"
2768 wait_request_state $fid RESTORE SUCCEED
2770 # Check md5sum pgm finished
2771 kill -0 $pid && error "Restore initiator is still running"
2772 wait $pid || error "Restore initiator failed with $?"
2774 run_test 36 "Move file during restore"
2777 # LU-5683: check that an archived dirty file can be rearchived.
2779 mkdir_on_mdt0 $DIR/$tdir
2781 local f=$DIR/$tdir/$tfile
2784 fid=$(create_small_file $f) || error "cannot create small file"
2786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2787 wait_request_state $fid ARCHIVE SUCCEED
2788 $LFS hsm_release $f || error "cannot release $f"
2790 # Allow previous archive request to expire from the actions log.
2791 wait_for_grace_delay
2794 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2796 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2797 wait_request_state $fid ARCHIVE SUCCEED
2799 run_test 37 "re-archive a dirty file"
2806 for n in $(seq 1 $count); do
2807 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2809 echo "$count archive requests submitted"
2813 local stream_count=4
2814 local file_count=100
2816 local f=$DIR/$tdir/$tfile
2820 local max_requests=$(get_hsm_param max_requests)
2822 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2823 # Increase the number of HSM request that can be performed in
2824 # parallel. With the coordinator running once per second, this
2825 # also limits the number of requests per seconds that can be
2826 # performed, so we pick a decent number. But we also need to keep
2827 # that number low because the copytool has no rate limit and will
2828 # fail some requests if if gets too many at once.
2829 set_hsm_param max_requests 300
2831 for i in $(seq 1 $file_count); do
2832 for p in $(seq 1 $stream_count); do
2833 fid=$(copy_file /etc/hosts $f.$p.$i)
2839 # to be sure wait_all_done will not be mislead by previous tests
2841 wait_for_grace_delay
2843 # start archive streams in background (archive files in parallel)
2844 for p in $(seq 1 $stream_count); do
2845 multi_archive $f.$p $file_count &
2848 echo -n "Wait for all requests being enqueued..."
2853 run_test 40 "Parallel archive requests"
2855 hsm_archive_batch() {
2863 while [ $i -lt $files_num ]; do
2864 if [ $batch_num -eq $batch_max ]; then
2865 $LFS hsm_archive $fileset || error "HSM archive failed"
2866 # Reset the batch container.
2871 fileset+="${filebase}$i "
2872 batch_num=$(( batch_num + 1 ))
2876 if [ $batch_num -ne 0 ]; then
2877 $LFS hsm_archive $fileset || error "HSM archive failed"
2884 local dir=$DIR/$tdir
2887 set_hsm_param max_requests 1000000
2888 mkdir $dir || error "mkdir $dir failed"
2897 filebase="$dir/$tfile.start."
2898 createmany -m $filebase $files_num ||
2899 error "createmany -m $filebase failed: $?"
2902 hsm_archive_batch $files_num $batch_max "$filebase"
2903 elapsed=$((SECONDS - start))
2904 do_facet $SINGLEMDS "$LCTL get_param -n \
2905 $HSM_PARAM.actions | grep WAITING | wc -l"
2906 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2907 echo "Start Phase files_num: $files_num time: $elapsed"
2910 filebase="$dir/$tfile.in."
2911 createmany -m $filebase $files_num ||
2912 error "createmany -m $filebase failed: $?"
2914 hsm_archive_batch $files_num $batch_max "$filebase"
2915 elapsed=$((SECONDS - start))
2916 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2917 echo "Middle Phase files_num: $files_num time: $elapsed"
2920 filebase="$dir/$tfile.end."
2921 createmany -m $filebase $files_num ||
2922 error "createmany -m $filebase failed: $?"
2925 hsm_archive_batch $files_num $batch_max "$filebase"
2926 elapsed=$((SECONDS - start))
2927 do_facet $SINGLEMDS "$LCTL get_param -n \
2928 $HSM_PARAM.actions | grep WAITING | wc -l"
2930 unlinkmany $filebase $files_num || error "unlinkmany $filebase failed"
2931 echo "End Phase files_num: $files_num time: $elapsed"
2933 do_facet $SINGLEMDS "$LCTL get_param -n \
2934 $HSM_PARAM.actions | grep WAITING | wc -l"
2938 run_test 50 "Archive with large number of pending HSM actions"
2941 # test needs a running copytool
2944 mkdir_on_mdt0 $DIR/$tdir
2945 local f=$DIR/$tdir/$tfile
2946 local fid=$(create_small_file $f)
2948 $LFS hsm_archive $f || error "could not archive file"
2949 wait_request_state $fid ARCHIVE SUCCEED
2950 check_hsm_flags $f "0x00000009"
2952 multiop_bg_pause $f O_c || error "multiop failed"
2956 client_up || client_up || true
2958 kill -USR1 $MULTIPID
2959 wait $MULTIPID || error "multiop close failed"
2961 check_hsm_flags $f "0x0000000b"
2963 run_test 52 "Opened for write file on an evicted client should be set dirty"
2966 # test needs a running copytool
2969 mkdir_on_mdt0 $DIR/$tdir
2970 local f=$DIR/$tdir/$tfile
2971 local fid=$(create_small_file $f)
2973 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2974 error "could not archive file"
2975 wait_request_state $fid ARCHIVE SUCCEED
2976 check_hsm_flags $f "0x00000009"
2978 multiop_bg_pause $f o_c || error "multiop failed"
2982 client_up || client_up || true
2984 kill -USR1 $MULTIPID
2985 wait $MULTIPID || error "multiop close failed"
2987 check_hsm_flags $f "0x00000009"
2989 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2992 mkdir_on_mdt0 $DIR/$tdir
2994 local f=$DIR/$tdir/$tfile
2995 local fid=$(create_file "$f" 1MB 39)
2999 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3000 error "could not archive file"
3001 wait_request_state $fid ARCHIVE STARTED
3003 check_hsm_flags $f "0x00000001"
3005 stack_trap "cdt_clear_no_retry" EXIT
3006 # Avoid coordinator resending this request as soon it has failed.
3011 wait_request_state $fid ARCHIVE FAILED
3013 check_hsm_flags $f "0x00000003"
3015 run_test 54 "Write during an archive cancels it"
3018 mkdir_on_mdt0 $DIR/$tdir
3020 local f=$DIR/$tdir/$tfile
3021 local fid=$(create_file "$f" 1MB 39)
3025 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3026 error "could not archive file"
3027 wait_request_state $fid ARCHIVE STARTED
3029 check_hsm_flags $f "0x00000001"
3031 stack_trap "cdt_clear_no_retry" EXIT
3032 # Avoid coordinator resending this request as soon it has failed.
3035 $TRUNCATE $f 1024 || error "truncate failed"
3037 wait_request_state $fid ARCHIVE FAILED
3039 check_hsm_flags $f "0x00000003"
3041 run_test 55 "Truncate during an archive cancels it"
3044 mkdir_on_mdt0 $DIR/$tdir
3046 local f=$DIR/$tdir/$tfile
3047 local fid=$(create_file "$f" 1MB 39)
3051 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3052 error "could not archive file"
3053 wait_request_state $fid ARCHIVE STARTED
3055 check_hsm_flags $f "0x00000001"
3057 # Change metadata and sync to be sure we are not changing only
3062 wait_request_state $fid ARCHIVE SUCCEED
3064 check_hsm_flags $f "0x00000009"
3066 run_test 56 "Setattr during an archive is ok"
3069 # Need one client for I/O, one for request
3070 needclients 2 || return 0
3072 # test needs a running copytool
3075 mkdir_on_mdt0 $DIR/$tdir
3076 local f=$DIR/$tdir/test_archive_remote
3077 # Create a file on a remote node
3078 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3079 "count=2 conv=fsync"
3082 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3083 error "hsm_archive failed"
3084 local fid=$(path2fid $f)
3085 wait_request_state $fid ARCHIVE SUCCEED
3087 # Release and implicit restore it
3088 do_node $CLIENT2 "$LFS hsm_release $f" ||
3089 error "hsm_release failed"
3090 do_node $CLIENT2 "md5sum $f" ||
3091 error "hsm_restore failed"
3093 wait_request_state $fid RESTORE SUCCEED
3095 run_test 57 "Archive a file with dirty cache on another node"
3097 truncate_released_file() {
3101 local sz=$(stat -c %s $src_file)
3102 local f=$DIR/$tdir/$tfile
3103 local fid=$(copy_file $1 $f)
3107 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3108 error "could not archive file"
3109 wait_request_state $fid ARCHIVE SUCCEED
3111 $LFS hsm_release $f || error "could not release file"
3113 $TRUNCATE $f $trunc_to || error "truncate failed"
3116 local sz1=$(stat -c %s $f)
3117 [[ $sz1 == $trunc_to ]] ||
3118 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3121 check_hsm_flags $f "0x0000000b"
3123 local state=$(get_request_state $fid RESTORE)
3124 [[ "$state" == "SUCCEED" ]] ||
3125 error "truncate $sz does not trig restore, state = $state"
3127 $TRUNCATE $ref $trunc_to
3128 cmp $ref $f || error "file data wrong after truncate"
3134 # test needs a running copytool
3137 mkdir_on_mdt0 $DIR/$tdir
3139 local sz=$(stat -c %s /etc/passwd)
3141 echo "truncate up from $sz to $((sz*2))"
3142 truncate_released_file /etc/passwd $((sz*2))
3144 echo "truncate down from $sz to $((sz/2))"
3145 truncate_released_file /etc/passwd $((sz/2))
3147 echo "truncate to 0"
3148 truncate_released_file /etc/passwd 0
3150 run_test 58 "Truncate a released file will trigger restore"
3154 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3155 skip "Need MDS version at least 2.7.63"
3158 $MCREATE $DIR/$tfile || error "mcreate failed"
3159 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3160 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3161 fid=$(path2fid $DIR/$tfile)
3162 wait_request_state $fid ARCHIVE SUCCEED
3163 $LFS hsm_release $DIR/$tfile || error "release failed"
3165 run_test 59 "Release stripeless file with non-zero size"
3168 # This test validates the fix for LU-4512. Ensure that the -u
3169 # option changes the progress reporting interval from the
3170 # default (30 seconds) to the user-specified interval.
3171 mkdir_on_mdt0 $DIR/$tdir
3173 local f=$DIR/$tdir/$tfile
3174 local fid=$(create_file "$f" 1M 10)
3177 local progress_timeout=$((interval * 4))
3178 copytool setup -b 1 --update-interval $interval
3181 local mdt=${MDT_PREFIX}${mdtidx}
3182 local mds=mds$((mdtidx + 1))
3184 # Wait for copytool to register
3185 wait_update_facet $mds \
3186 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3187 uuid 100 || error "coyptool failed to register with $mdt"
3189 local start_at=$(date +%s)
3190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3191 error "could not archive file"
3193 local agent=$(facet_active_host $SINGLEAGT)
3194 local logfile=$(copytool_logfile $SINGLEAGT)
3196 wait_update $agent \
3197 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3198 error "copytool failed to start"
3200 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3201 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3207 echo -n "Expecting a progress update within $progress_timeout seconds... "
3209 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3210 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3211 echo "$RESULT bytes copied in $WAIT seconds."
3213 elif [ $WAIT -ge $progress_timeout ]; then
3214 error "Timed out waiting for progress update!"
3217 WAIT=$((WAIT + sleep))
3221 local finish_at=$(date +%s)
3222 local elapsed=$((finish_at - start_at))
3224 # Ensure that the progress update occurred within the expected window.
3225 if [ $elapsed -lt $((interval - 1)) ]; then
3226 error "Expected progress update after at least $interval seconds"
3229 echo "Wait for on going archive hsm action to complete"
3230 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3231 echo "File archiving not completed even after 10 secs"
3233 run_test 60 "Changing progress update interval from default"
3236 # test needs a running copytool
3239 mkdir_on_mdt0 $DIR/$tdir
3240 local f=$DIR/$tdir/$tfile
3241 local fid=$(copy_file /etc/passwd $f)
3243 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3246 wait_request_state $fid ARCHIVE FAILED
3248 run_test 61 "Waiting archive of a removed file should fail"
3251 # test needs a new running copytool
3252 stack_trap copytool_monitor_cleanup EXIT
3253 copytool_monitor_setup
3254 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3256 # Wait for the copytool to register.
3257 wait_update --verbose $(facet_active_host mds1) \
3258 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3260 error "copytool failed to register with MDT0000"
3263 wait_copytools || error "Copytools failed to stop"
3265 local REGISTER_EVENT
3266 local UNREGISTER_EVENT
3267 while read event; do
3268 local parsed=$(parse_json_event "$event")
3269 if [ -z "$parsed" ]; then
3270 error "Copytool sent malformed event: $event"
3274 if [ $event_type == "REGISTER" ]; then
3275 REGISTER_EVENT=$event
3276 elif [ $event_type == "UNREGISTER" ]; then
3277 UNREGISTER_EVENT=$event
3279 done < <(echo $"$(get_copytool_event_log)")
3281 if [ -z "$REGISTER_EVENT" ]; then
3282 error "Copytool failed to send register event to FIFO"
3285 if [ -z "$UNREGISTER_EVENT" ]; then
3286 error "Copytool failed to send unregister event to FIFO"
3289 echo "Register/Unregister events look OK."
3291 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3294 # Bump progress interval for livelier events.
3297 # test needs a new running copytool
3298 stack_trap copytool_monitor_cleanup EXIT
3299 copytool_monitor_setup
3300 copytool setup --update-interval $interval --event-fifo \
3301 "$HSMTOOL_MONITOR_DIR/fifo"
3303 stack_trap "cdt_clear_no_retry" EXIT
3304 # Just start and stop the copytool to generate events.
3307 mkdir_on_mdt0 $DIR/$tdir
3309 local f=$DIR/$tdir/$tfile
3310 local fid=$(create_small_file "$f")
3312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3313 error "could not archive file"
3314 wait_request_state $fid ARCHIVE SUCCEED
3316 local expected_fields="event_time data_fid source_fid"
3317 expected_fields+=" total_bytes current_bytes"
3320 [ARCHIVE_START]=false
3321 [ARCHIVE_FINISH]=false
3322 [ARCHIVE_RUNNING]=false
3324 while read event; do
3325 # Make sure we're not getting anything from previous events.
3326 for field in $expected_fields; do
3330 local parsed=$(parse_json_event "$event")
3331 if [ -z "$parsed" ]; then
3332 error "Copytool sent malformed event: $event"
3336 events["$event_type"]=true
3338 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3340 # Do some simple checking of the progress update events.
3341 for expected_field in $expected_fields; do
3342 if [ -z ${!expected_field+x} ]; then
3343 error "Missing $expected_field field in event"
3347 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3349 # These should be identical throughout an archive operation
3350 [ $source_fid == $data_fid ] ||
3351 error "Expected source_fid to equal data_fid"
3352 done < <(echo $"$(get_copytool_event_log)")
3354 # Check we received every type of events we were expecting
3355 for event in "${!events[@]}"; do
3356 ${events["$event"]} ||
3357 error "Copytool failed to send '$event' event to FIFO"
3360 echo "Archive events look OK."
3362 run_test 71 "Copytool logs JSON archive events to FIFO"
3365 # Bump progress interval for livelier events.
3368 # test needs a new running copytool
3369 stack_trap copytool_monitor_cleanup EXIT
3370 copytool_monitor_setup
3371 copytool setup --update-interval $interval --event-fifo \
3372 "$HSMTOOL_MONITOR_DIR/fifo"
3373 local test_file=$HSMTOOL_MONITOR_DIR/file
3375 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3377 do_facet $SINGLEAGT "$cmd" ||
3378 error "cannot create $test_file on $SINGLEAGT"
3379 copy2archive $test_file $tdir/$tfile
3381 mkdir_on_mdt0 $DIR/$tdir
3382 local f=$DIR/$tdir/$tfile
3383 copytool import $tdir/$tfile $f
3384 f=$DIR2/$tdir/$tfile
3385 echo "Verifying released state: "
3386 check_hsm_flags $f "0x0000000d"
3388 local fid=$(path2fid $f)
3390 wait_request_state $fid RESTORE SUCCEED
3392 local expected_fields="event_time data_fid source_fid"
3393 expected_fields+=" total_bytes current_bytes"
3397 while read event; do
3398 # Make sure we're not getting anything from previous events.
3399 for field in $expected_fields; do
3403 local parsed=$(parse_json_event "$event")
3404 if [ -z "$parsed" ]; then
3405 error "Copytool sent malformed event: $event"
3409 if [ $event_type == "RESTORE_START" ]; then
3411 if [ $source_fid != $data_fid ]; then
3412 error "source_fid should == data_fid at start"
3415 elif [ $event_type == "RESTORE_FINISH" ]; then
3417 if [ $source_fid != $data_fid ]; then
3418 error "source_fid should == data_fid at finish"
3421 elif [ $event_type != "RESTORE_RUNNING" ]; then
3425 # Do some simple checking of the progress update events.
3426 for expected_field in $expected_fields; do
3427 if [ -z ${!expected_field+x} ]; then
3428 error "Missing $expected_field field in event"
3432 if [ $total_bytes -eq 0 ]; then
3433 error "Expected total_bytes to be > 0"
3436 # When a restore starts out, the data fid is the same as the
3437 # source fid. After the restore has gotten going, we learn
3438 # the new data fid. Once the restore has finished, the source
3439 # fid is set to the new data fid.
3441 # We test this because some monitoring software may depend on
3442 # this behavior. If it changes, then the consumers of these
3443 # events may need to be modified.
3444 if [ $source_fid == $data_fid ]; then
3445 error "source_fid should != data_fid during restore"
3447 done < <(echo $"$(get_copytool_event_log)")
3449 if [ -z "$START_EVENT" ]; then
3450 error "Copytool failed to send restore start event to FIFO"
3453 if [ -z "$FINISH_EVENT" ]; then
3454 error "Copytool failed to send restore finish event to FIFO"
3457 echo "Restore events look OK."
3459 run_test 72 "Copytool logs JSON restore events to FIFO"
3462 file_count=51 # Max number of files constrained by LNET message size
3463 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3464 local f=$DIR/$tdir/$tfile
3465 local FILELIST=/tmp/filelist.txt
3469 for i in $(seq 1 $file_count); do
3470 fid=$(copy_file /etc/hosts $f.$i)
3471 echo $f.$i >> $FILELIST
3475 # to be sure wait_all_done will not be mislead by previous tests
3477 wait_for_grace_delay
3478 $LFS hsm_archive --filelist $FILELIST ||
3479 error "cannot archive a file list"
3481 $LFS hsm_release --filelist $FILELIST ||
3482 error "cannot release a file list"
3483 $LFS hsm_restore --filelist $FILELIST ||
3484 error "cannot restore a file list"
3487 run_test 90 "Archive/restore a file list"
3489 double_verify_reset_hsm_param() {
3491 echo "Testing $HSM_PARAM.$p"
3492 local val=$(get_hsm_param $p)
3494 local val2=$(($val * 2))
3495 set_hsm_param $p $val2
3496 val=$(get_hsm_param $p)
3497 [[ $val == $val2 ]] ||
3498 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3499 echo "Set $p to 0 must failed"
3503 set_hsm_param $p $save
3505 if [[ $rc == 0 ]]; then
3506 error "we must not be able to set $HSM_PARAM.$p to 0"
3511 double_verify_reset_hsm_param loop_period
3512 double_verify_reset_hsm_param grace_delay
3513 double_verify_reset_hsm_param active_request_timeout
3514 double_verify_reset_hsm_param max_requests
3515 double_verify_reset_hsm_param default_archive_id
3517 run_test 100 "Set coordinator /proc tunables"
3524 run_test 102 "Verify coordinator control"
3527 # test needs a running copytool
3534 for i in $(seq 1 20); do
3535 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3537 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3541 echo "Current requests"
3542 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3543 $HSM_PARAM.actions |\
3544 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3546 [[ -z "$res" ]] || error "Some request have not been canceled"
3548 run_test 103 "Purge all requests"
3551 (( MDS1_VERSION >= $(version_code 2.14.56) )) ||
3552 skip "Need MDS version at least 2.14.56"
3554 cdt_clear_non_blocking_restore
3556 # test needs a running copytool
3561 local rpcs_inflight=$($LCTL get_param -n \
3562 "mdc.$(facet_svc mds1)*.max_rpcs_in_flight" |
3565 mkdir_on_mdt0 $DIR/$tdir
3566 for ((i=0; i < rpcs_inflight; i++)); do
3567 fids+=( $(copy_file /etc/passwd $DIR/$tdir/${tfile}_$i) )
3569 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3573 local grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=ARCHIVE.*status=SUCCEED"
3575 while [[ $time -lt 5 ]] && [[ $cnt -ne ${#fids[@]} ]]; do
3576 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3577 grep -c -E '$grep_regex'")
3581 [[ $cnt -eq ${#fids[@]} ]] || error "Fail to archive files $cnt/${#fids[@]}"
3583 $LFS hsm_release $DIR/$tdir/*
3586 wait_copytools || error "Copytool failed to stop"
3589 for i in "${fids[@]}"; do
3590 cat $DIR/.lustre/fid/$i > /dev/null & pids+=($!)
3594 grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=RESTORE.*status=CANCELED"
3595 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3596 grep -cE '$grep_regex'")
3598 [[ "$cnt" -eq ${#fids[@]} ]] ||
3599 error "Some request have not been canceled ($cnt/${#fids[@]} canceled)"
3601 # cat cmds should not hang and should fail
3602 for i in "${!pids[@]}"; do
3604 error "Restore for ${tfile}_$i (${pids[$i]}) should fail" ||
3608 run_test 103a "Purge pending restore requests"
3613 mkdir_on_mdt0 $DIR/$tdir
3615 local f=$DIR/$tdir/$tfile
3616 local fid=$(create_empty_file "$f")
3618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3619 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3620 $HSM_PARAM.actions |\
3621 grep $fid | cut -f16 -d=")
3623 [[ "$data1" == "$DATAHEX" ]] ||
3624 error "Data field in records is ($data1) and not ($DATAHEX)"
3628 run_test 104 "Copy tool data field"
3631 local max_requests=$(get_hsm_param max_requests)
3632 mkdir_on_mdt0 $DIR/$tdir
3635 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3636 set_hsm_param max_requests 300
3639 for i in $(seq -w 1 10); do
3640 cp /etc/passwd $DIR/$tdir/$i
3641 $LFS hsm_archive $DIR/$tdir/$i
3643 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3644 $HSM_PARAM.actions |\
3645 grep WAITING | wc -l")
3649 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3650 $HSM_PARAM.actions |\
3651 grep WAITING | wc -l")
3654 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3655 error "Requests count after shutdown $reqcnt2 != "\
3656 "before shutdown $reqcnt1"
3658 run_test 105 "Restart of coordinator"
3661 # test needs a running copytool
3664 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3666 check_agent_registered $uuid
3668 search_copytools || error "No copytool found"
3671 wait_copytools || error "Copytool failed to stop"
3673 check_agent_unregistered $uuid
3676 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3677 check_agent_registered $uuid
3679 run_test 106 "Copytool register/unregister"
3682 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3684 # test needs a running copytool
3686 # create and archive file
3687 mkdir_on_mdt0 $DIR/$tdir
3688 local f1=$DIR/$tdir/$tfile
3689 local fid=$(copy_file /etc/passwd $f1)
3690 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3691 wait_request_state $fid ARCHIVE SUCCEED
3692 # shutdown and restart MDS
3694 # check the copytool still gets messages from MDT
3695 local f2=$DIR/$tdir/2
3696 local fid=$(copy_file /etc/passwd $f2)
3697 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3698 # main check of this sanity: this request MUST succeed
3699 wait_request_state $fid ARCHIVE SUCCEED
3701 run_test 107 "Copytool re-register after MDS restart"
3703 policy_set_and_test()
3707 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3708 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3709 [[ "$policy" == "$target" ]] ||
3710 error "Wrong policy after '$change': '$policy' != '$target'"
3714 # to force default policy setting if error
3715 CDT_POLICY_HAD_CHANGED=true
3717 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3718 local default="NonBlockingRestore [NoRetryAction]"
3719 [[ "$policy" == "$default" ]] ||
3720 error "default policy has changed,"\
3721 " '$policy' != '$default' update the test"
3722 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3723 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3724 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3725 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3726 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3727 # useless bacause we know but safer for futur changes to use real value
3728 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3729 echo "Next set_param must failed"
3730 policy_set_and_test "wrong" "$policy"
3733 echo "Back to default policy"
3734 cdt_set_sanity_policy
3736 run_test 109 "Policy display/change"
3739 # test needs a running copytool
3742 mkdir_on_mdt0 $DIR/$tdir
3744 copy2archive /etc/passwd $tdir/$tfile
3746 local f=$DIR/$tdir/$tfile
3747 copytool import $tdir/$tfile $f
3748 local fid=$(path2fid $f)
3750 cdt_set_non_blocking_restore
3755 wait_request_state $fid RESTORE SUCCEED
3756 cdt_clear_non_blocking_restore
3760 error "md5sum returns $st != 1, "\
3761 "should also perror ENODATA (No data available)"
3763 run_test 110a "Non blocking restore policy (import case)"
3766 # test needs a running copytool
3769 mkdir_on_mdt0 $DIR/$tdir
3770 local f=$DIR/$tdir/$tfile
3771 local fid=$(copy_file /etc/passwd $f)
3772 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3773 wait_request_state $fid ARCHIVE SUCCEED
3776 cdt_set_non_blocking_restore
3781 wait_request_state $fid RESTORE SUCCEED
3782 cdt_clear_non_blocking_restore
3786 error "md5sum returns $st != 1, "\
3787 "should also perror ENODATA (No data available)"
3789 run_test 110b "Non blocking restore policy (release case)"
3792 # test needs a running copytool
3795 mkdir_on_mdt0 $DIR/$tdir
3796 copy2archive /etc/passwd $tdir/$tfile
3798 local f=$DIR/$tdir/$tfile
3800 copytool import $tdir/$tfile $f
3801 local fid=$(path2fid $f)
3805 copytool_remove_backend $fid
3808 wait_request_state $fid RESTORE FAILED
3815 [[ $st == 0 ]] || error "Restore does not failed"
3817 run_test 111a "No retry policy (import case), restore will error"\
3818 " (No such file or directory)"
3821 # test needs a running copytool
3824 mkdir_on_mdt0 $DIR/$tdir
3825 local f=$DIR/$tdir/$tfile
3826 local fid=$(copy_file /etc/passwd $f)
3827 stack_trap cdt_clear_no_retry EXIT
3829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3830 wait_request_state $fid ARCHIVE SUCCEED
3833 copytool_remove_backend $fid
3836 wait_request_state $fid RESTORE FAILED
3840 [[ $st == 0 ]] || error "Restore does not failed"
3842 run_test 111b "No retry policy (release case), restore will error"\
3843 " (No such file or directory)"
3846 # test needs a running copytool
3849 mkdir_on_mdt0 $DIR/$tdir
3850 local f=$DIR/$tdir/$tfile
3851 local fid=$(copy_file /etc/passwd $f)
3853 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3854 local l=$($LFS hsm_action $f)
3856 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3859 wait_request_state $fid ARCHIVE SUCCEED
3862 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3864 run_test 112 "State of recorded request"
3867 mkdir_on_mdt0 $DIR/$tdir
3869 local file1=$DIR/$tdir/$tfile
3870 local file2=$DIR2/$tdir/$tfile
3872 local fid=$(create_small_sync_file $file1)
3874 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3875 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3876 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3878 copytool setup -m "$MOUNT3"
3880 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3882 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3883 wait_request_state $fid ARCHIVE SUCCEED
3885 $LFS hsm_release $file1
3886 echo "Verifying released state: "
3887 check_hsm_flags $file1 "0x0000000d"
3889 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3892 kill -USR1 $MULTIPID
3897 local size1=$(stat -c "%s" $file1)
3898 local size2=$(stat -c "%s" $file2)
3900 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3902 run_test 113 "wrong stat after restore"
3905 mkdir_on_mdt0 $DIR/$tdir
3907 local f=$DIR/$tdir/$tfile
3908 local fid=$(create_empty_file "$f")
3912 # Prevent archive from completing
3915 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3916 # wait archive to register at CDT
3917 wait_request_state $fid ARCHIVE STARTED
3919 # Cancel the archive
3920 $LFS hsm_cancel "$f"
3922 wait_request_state $fid ARCHIVE CANCELED
3925 wait_request_state $fid CANCEL SUCCEED
3927 run_test 200 "Register/Cancel archive"
3930 # test needs a running copytool
3932 mkdir_on_mdt0 $DIR/$tdir
3934 local f=$DIR/$tdir/$tfile
3935 create_archive_file $tdir/$tfile
3936 copytool import $tdir/$tfile $f
3937 local fid=$(path2fid $f)
3939 # test with cdt on is made in test_222
3942 # wait restore to register at CDT
3943 wait_request_state $fid RESTORE WAITING
3946 wait_request_state $fid RESTORE CANCELED
3947 wait_request_state $fid CANCEL SUCCEED
3949 run_test 201 "Register/Cancel restore"
3952 mkdir_on_mdt0 $DIR/$tdir
3954 local f=$DIR/$tdir/$tfile
3955 local fid=$(create_empty_file "$f")
3957 # test needs a running copytool
3960 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3961 wait_request_state $fid ARCHIVE SUCCEED
3965 # wait remove to register at CDT
3966 wait_request_state $fid REMOVE STARTED
3969 wait_request_state $fid REMOVE CANCELED
3971 run_test 202 "Register/Cancel remove"
3973 test_220A() { # was test_220
3974 # test needs a running copytool
3977 mkdir_on_mdt0 $DIR/$tdir
3979 local f=$DIR/$tdir/$tfile
3980 local fid=$(copy_file /etc/passwd $f)
3984 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3985 wait_request_state $fid ARCHIVE SUCCEED
3987 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3988 error "The expected changelog was not emitted"
3990 run_test 220A "Changelog for archive"
3993 # test needs a running copytool
3996 mkdir_on_mdt0 $DIR/$tdir
3998 local f=$DIR/$tdir/$tfile
3999 local fid=$(copy_file /etc/passwd $f)
4003 # block copytool operations to allow for HSM request to be
4004 # submitted and file be unlinked (CDT will find object removed)
4007 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4009 # wait request to reach CT
4010 wait_request_state $fid ARCHIVE STARTED
4016 wait_request_state $fid ARCHIVE FAILED
4019 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4020 error "The expected changelog was not emitted"
4022 run_test 220a "Changelog for failed archive"
4025 mkdir_on_mdt0 $DIR/$tdir
4027 local f=$DIR/$tdir/$tfile
4028 local fid=$(create_empty_file "$f")
4033 # Prevent archive from completing
4035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4036 wait_request_state $fid ARCHIVE STARTED
4039 wait_request_state $fid ARCHIVE CANCELED
4042 wait_request_state $fid CANCEL SUCCEED
4044 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4045 error "The expected changelog was not emitted"
4047 run_test 221 "Changelog for archive canceled"
4050 # test needs a running copytool
4053 mkdir_on_mdt0 $DIR/$tdir
4054 copy2archive /etc/passwd $tdir/$tfile
4056 local f=$DIR/$tdir/$tfile
4057 copytool import $tdir/$tfile $f
4058 local fid=$(path2fid $f)
4063 wait_request_state $fid RESTORE SUCCEED
4065 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4066 error "The expected changelog was not emitted"
4068 run_test 222a "Changelog for explicit restore"
4071 # test needs a running copytool
4074 mkdir_on_mdt0 $DIR/$tdir
4075 local f=$DIR/$tdir/$tfile
4076 local fid=$(copy_file /etc/passwd $f)
4079 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4080 wait_request_state $fid ARCHIVE SUCCEED
4085 wait_request_state $fid RESTORE SUCCEED
4087 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4088 error "The expected changelog was not emitted"
4090 run_test 222b "Changelog for implicit restore"
4093 # test needs a running copytool
4096 mkdir_on_mdt0 $DIR/$tdir
4097 copy2archive /etc/passwd $tdir/$tfile
4099 local f=$DIR/$tdir/$tfile
4100 copytool import $tdir/$tfile $f
4101 local fid=$(path2fid $f)
4105 # block copytool operations to allow for HSM request to be
4106 # submitted and file be unlinked (CDT will find object removed)
4111 # wait request to reach CT
4112 wait_request_state $fid RESTORE STARTED
4118 wait_request_state $fid RESTORE FAILED
4121 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4122 error "The expected changelog was not emitted"
4124 run_test 222c "Changelog for failed explicit restore"
4127 # test needs a running copytool
4130 mkdir_on_mdt0 $DIR/$tdir
4131 local f=$DIR/$tdir/$tfile
4132 local fid=$(copy_file /etc/passwd $f)
4135 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4136 wait_request_state $fid ARCHIVE SUCCEED
4139 copytool_remove_backend $fid
4142 wait_request_state $fid RESTORE FAILED
4145 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4146 error "The expected changelog was not emitted"
4148 run_test 222d "Changelog for failed implicit restore"
4151 # test needs a running copytool
4153 mkdir_on_mdt0 $DIR/$tdir
4155 local f=$DIR/$tdir/$tfile
4156 create_archive_file $tdir/$tfile
4160 copytool import $tdir/$tfile $f
4161 local fid=$(path2fid $f)
4164 wait_request_state $fid RESTORE STARTED
4166 wait_request_state $fid RESTORE CANCELED
4167 wait_request_state $fid CANCEL SUCCEED
4169 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4170 error "The expected changelog was not emitted"
4172 run_test 223a "Changelog for restore canceled (import case)"
4175 mkdir_on_mdt0 $DIR/$tdir
4177 local f=$DIR/$tdir/$tfile
4178 local fid=$(create_empty_file "$f")
4183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4184 wait_request_state $fid ARCHIVE SUCCEED
4187 # Prevent restore from completing
4190 wait_request_state $fid RESTORE STARTED
4193 wait_request_state $fid RESTORE CANCELED
4196 wait_request_state $fid CANCEL SUCCEED
4198 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4199 error "The expected changelog was not emitted"
4201 run_test 223b "Changelog for restore canceled (release case)"
4203 test_224A() { # was test_224
4204 # test needs a running copytool
4207 mkdir_on_mdt0 $DIR/$tdir
4209 local f=$DIR/$tdir/$tfile
4210 local fid=$(copy_file /etc/passwd $f)
4213 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4214 wait_request_state $fid ARCHIVE SUCCEED
4217 wait_request_state $fid REMOVE SUCCEED
4219 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4220 error "The expected changelog was not emitted"
4222 run_test 224A "Changelog for remove"
4225 # test needs a running copytool
4228 mkdir_on_mdt0 $DIR/$tdir
4230 local f=$DIR/$tdir/$tfile
4231 local fid=$(copy_file /etc/passwd $f)
4234 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4235 wait_request_state $fid ARCHIVE SUCCEED
4237 copytool_remove_backend $fid
4239 # block copytool operations to allow for HSM request to be
4240 # submitted and file be unlinked (CDT will find object removed)
4245 # wait for request to reach CT
4246 wait_request_state $fid REMOVE STARTED
4252 wait_request_state $fid REMOVE FAILED
4254 # HE_REMOVE|ENOENT=0x202
4255 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4256 error "The expected changelog was not emitted"
4258 run_test 224a "Changelog for failed remove"
4261 # test is not usable because remove request is too fast
4262 # so it is always finished before cancel can be done ...
4263 echo "Test disabled"
4266 # test needs a running copytool
4268 mkdir_on_mdt0 $DIR/$tdir
4270 local f=$DIR/$tdir/$tfile
4271 local fid=$(create_empty_file "$f")
4274 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4275 wait_request_state $fid ARCHIVE SUCCEED
4277 # Prevent restore from completing
4282 wait_request_state $fid REMOVE CANCELED
4285 wait_request_state $fid CANCEL SUCCEED
4287 changelog_find -type HSM -target-fid $fid -flags 0x27d
4288 error "The expected changelog was not emitted"
4290 run_test 225 "Changelog for remove canceled"
4293 # test needs a running copytool
4296 mkdir_on_mdt0 $DIR/$tdir
4298 local f1=$DIR/$tdir/$tfile-1
4299 local f2=$DIR/$tdir/$tfile-2
4300 local f3=$DIR/$tdir/$tfile-3
4301 local fid1=$(copy_file /etc/passwd $f1)
4302 local fid2=$(copy_file /etc/passwd $f2)
4303 copy_file /etc/passwd $f3
4306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4307 wait_request_state $fid1 ARCHIVE SUCCEED
4309 $LFS hsm_archive $f2
4310 wait_request_state $fid2 ARCHIVE SUCCEED
4312 rm $f1 || error "rm $f1 failed"
4315 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4316 error "The expected changelog was not emitted"
4318 mv $f3 $f2 || error "mv $f3 $f2 failed"
4320 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4321 error "The expected changelog was not emitted"
4323 run_test 226 "changelog for last rm/mv with exiting archive"
4325 # This is just a utility function to clarify what test_227 does
4330 "$LFS" "$action" --$flag "$file" ||
4331 error "Cannot ${action#hsm_} $flag on '$file'"
4333 # Only one changelog should be produced
4334 local entries="$(changelog_find -type HSM -target-fid $fid)"
4335 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4336 error "lfs $action --$flag '$file' produced more than one" \
4339 # Parse the last changelog record
4340 local entry="$(tail -n 1 <<< "$entries")"
4341 eval local -A changelog=$(changelog2array $entry)
4343 # Also check the flags match what is expected
4344 [[ ${changelog[flags]} == $target ]] ||
4345 error "Changelog flag is '${changelog[flags]}', not $target"
4349 local file="$DIR/$tdir/$tfile"
4350 local fid=$(create_empty_file "$file")
4355 for flag in norelease noarchive exists archived lost; do
4356 if [ "$flag" == lost ]; then
4357 # The flag "lost" only works on an archived file
4358 "$LFS" hsm_set --archived "$file"
4362 action="hsm_set" __test_227
4363 action="hsm_clear" __test_227
4366 run_test 227 "changelog when explicit setting of HSM flags"
4369 # test needs a running copytool
4371 mkdir_on_mdt0 $DIR/$tdir
4373 local fid=$(create_small_sync_file $DIR/$tfile)
4374 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4375 wait_request_state $fid ARCHIVE SUCCEED
4377 $LFS hsm_release $DIR/$tfile
4378 check_hsm_flags $DIR/$tfile "0x0000000d"
4380 filefrag $DIR/$tfile | grep " 1 extent found" ||
4381 error "filefrag on released file must return only one extent"
4383 # only newer versions of cp detect sparse files by stat/FIEMAP
4385 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4386 error "copying $DIR/$tfile"
4387 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4389 $LFS hsm_release $DIR/$tfile
4390 check_hsm_flags $DIR/$tfile "0x0000000d"
4392 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4394 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4396 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4397 error "comparing untarred $DIR/$tfile"
4399 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4400 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4402 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4405 local file="$DIR/$tdir/$tfile"
4407 # set max_requests to allow one request of each type to be started (3)
4409 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4410 set_hsm_param max_requests 3
4413 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4414 set_hsm_param loop_period 1
4416 # send 1 requests of each kind twice
4419 mkdir_on_mdt0 $DIR/$tdir
4422 for action in archive restore remove; do
4423 local filepath="$file"-to-$action
4424 local fid=$(create_empty_file "$filepath")
4425 local fid2=$(create_empty_file "$filepath".bis)
4427 if [ "$action" != archive ]; then
4428 "$LFS" hsm_archive "$filepath"
4429 wait_request_state $fid ARCHIVE SUCCEED
4430 "$LFS" hsm_archive "$filepath".bis
4431 wait_request_state $fid2 ARCHIVE SUCCEED
4433 if [ "$action" == restore ]; then
4434 "$LFS" hsm_release "$filepath"
4435 "$LFS" hsm_release "$filepath".bis
4439 # suspend the copytool to prevent requests from completing
4440 stack_trap "copytool_continue" EXIT
4443 # send `max_requests' requests (one of each kind)
4444 for action in archive restore remove; do
4445 filepath="$file"-to-$action
4446 "$LFS" hsm_${action} "$filepath"
4447 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4450 # send another batch of requests
4451 for action in archive restore remove; do
4452 "$LFS" hsm_${action} "$file-to-$action".bis
4454 # wait for `loop_period' seconds to make sure the coordinator has time
4455 # to register those, even though it should not
4458 # only the first batch of request should be started
4460 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4464 error "expected 3 STARTED requests, found $count"
4466 run_test 250 "Coordinator max request"
4469 mkdir_on_mdt0 $DIR/$tdir
4471 local f=$DIR/$tdir/$tfile
4472 local fid=$(create_empty_file "$f")
4475 # to have a short test
4476 local old_to=$(get_hsm_param active_request_timeout)
4477 set_hsm_param active_request_timeout 1
4478 # to be sure the cdt will wake up frequently so
4479 # it will be able to cancel the "old" request
4480 local old_loop=$(get_hsm_param loop_period)
4481 set_hsm_param loop_period 1
4486 # Prevent archive from completing
4488 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4489 wait_request_state $fid ARCHIVE STARTED
4491 # Let the request timeout
4492 wait_request_state $fid ARCHIVE CANCELED
4494 set_hsm_param active_request_timeout $old_to
4495 set_hsm_param loop_period $old_loop
4497 run_test 251 "Coordinator request timeout"
4500 mkdir_on_mdt0 $DIR/$tdir
4502 local f=$DIR/$tdir/$tfile
4503 local fid=$(create_empty_file "$f")
4505 # to have a short test
4506 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4507 set_hsm_param loop_period 1
4511 # Prevent archive from completing
4513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4514 wait_request_state $fid ARCHIVE STARTED
4517 stack_trap "set_hsm_param active_request_timeout \
4518 $(get_hsm_param active_request_timeout)" EXIT
4519 set_hsm_param active_request_timeout 1
4521 wait_request_state $fid ARCHIVE CANCELED
4524 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4528 # test needs a running copytool
4531 mkdir_on_mdt0 $DIR/$tdir
4532 local f=$DIR/$tdir/$tfile
4534 dd if=/dev/zero of=$f bs=1MB count=10
4535 local fid=$(path2fid $f)
4537 $LFS hsm_archive $f || error "could not archive file"
4538 wait_request_state $fid ARCHIVE SUCCEED
4540 # clear locks to discard inode data
4541 cancel_lru_locks osc
4543 #define OBD_FAIL_MDC_MERGE 0x807
4544 $LCTL set_param fail_loc=0x807
4546 #expect error here, instead of release with wrong size
4549 if ((rc == 0)); then
4550 file_size=$(stat -c '%s' $f)
4551 if ((file_size != 10485760)); then
4552 error "Wrong file size after hsm_release"
4555 echo "could not release file"
4558 run_test 253 "Check for wrong file size after release"
4562 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4563 skip "need MDS version at least 2.10.56"
4565 # Check that the counters are initialized to 0
4567 for request_type in archive restore remove; do
4568 count="$(get_hsm_param ${request_type}_count)" ||
4569 error "Reading ${request_type}_count failed with $?"
4571 [ "$count" -eq 0 ] ||
4572 error "Expected ${request_type}_count to be " \
4576 run_test 254a "Request counters are initialized to zero"
4580 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4581 skip "need MDS version at least 2.10.56"
4583 # The number of request to launch (at least 32)
4584 local request_count=$((RANDOM % 32 + 32))
4585 printf "Will launch %i requests of each type\n" "$request_count"
4587 # Launch a copytool to process requests
4590 # Set hsm.max_requests to allow starting all requests at the same time
4592 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4593 set_hsm_param max_requests "$request_count"
4595 mkdir_on_mdt0 $DIR/$tdir
4599 for request_type in archive restore remove; do
4600 printf "Checking %s requests\n" "${request_type}"
4601 # Suspend the copytool to give us time to read the proc files
4604 for ((i = 0; i < $request_count; i++)); do
4605 case $request_type in
4607 create_empty_file "$DIR/$tdir/$tfile-$i" \
4611 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4614 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4617 # Give the coordinator 10 seconds to start every request
4619 while get_hsm_param actions | grep -q WAITING; do
4622 [ $timeout -gt 0 ] ||
4623 error "${request_type^} requests took too " \
4627 count="$(get_hsm_param ${request_type}_count)"
4628 [ "$count" -eq "$request_count" ] ||
4629 error "Expected '$request_count' (!= '$count') " \
4630 "active $request_type requests"
4632 # Let the copytool process the requests
4634 # Give it 10 seconds maximum
4636 while get_hsm_param actions | grep -q STARTED; do
4639 [ $timeout -gt 0 ] ||
4640 error "${request_type^} requests took too " \
4644 count="$(get_hsm_param ${request_type}_count)"
4645 [ "$count" -eq 0 ] ||
4646 error "Expected 0 (!= '$count') " \
4647 "active $request_type requests"
4650 run_test 254b "Request counters are correctly incremented and decremented"
4654 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4655 skip "Need MDS version at least 2.12.0"
4657 mkdir_on_mdt0 $DIR/$tdir
4659 local file="$DIR/$tdir/$tfile"
4660 local fid=$(create_empty_file "$file")
4662 # How do you make sure the coordinator has consumed any outstanding
4663 # event, without triggering an event yourself?
4665 # You wait for a request to disappear from the coordinator's llog.
4667 # Warning: the setup represents 90% of this test
4669 # Create and process an HSM request
4671 "$LFS" hsm_archive "$file"
4672 wait_request_state $fid ARCHIVE SUCCEED
4675 wait_copytools || error "failed to stop copytools"
4677 # Launch a new HSM request
4679 create_empty_file "$file"
4680 "$LFS" hsm_archive "$file"
4684 # Have the completed request be removed as soon as the cdt wakes up
4685 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4686 set_hsm_param grace_delay 1
4687 # (Hopefully, time on the MDS will behave nicely)
4688 do_facet $SINGLEMDS sleep 2 &
4690 # Increase `loop_period' as a mean to prevent the coordinator from
4691 # waking itself up to do some housekeeping.
4692 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4693 set_hsm_param loop_period 1000
4695 wait $! || error "waiting failed"
4697 wait_request_state $fid ARCHIVE ""
4698 # The coordinator will not wake up on its own for ~`loop_period' secs...
4700 # ... Unless a copytool registers. Now the real test begins
4702 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4704 run_test 255 "Copytool registration wakes the coordinator up"
4706 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4707 # break in the future because of that.
4710 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4711 skip "need MDS version 2.11.56 or later"
4713 local -a files=("$DIR/$tdir/$tfile".{0..15})
4716 mkdir_on_mdt0 $DIR/$tdir
4718 for file in "${files[@]}"; do
4719 create_small_file "$file"
4722 # Set a few hsm parameters
4724 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4725 set_hsm_param loop_period 1
4727 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4728 set_hsm_param max_requests 3
4732 "$LFS" hsm_archive "${files[0]}"
4733 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4734 "$LFS" hsm_release "${files[0]}"
4738 wait_copytools || error "copytools failed to stop"
4740 # Send several archive requests
4741 for file in "${files[@]:1}"; do
4742 "$LFS" hsm_archive "$file"
4745 # Send one restore request
4746 "$LFS" hsm_restore "${files[0]}"
4751 # Wait for all the requests to complete
4752 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4753 for file in "${files[@]:1}"; do
4754 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4757 # Collect the actions in the order in which the copytool processed them
4759 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4760 "$(copytool_logfile "$SINGLEAGT")")
4763 printf '%s\n' "${actions[@]}"
4766 for action in "${actions[@]:0:3}"; do
4767 [ "$action" == RESTORE ] && return
4770 error "Too many ARCHIVE requests were run before the RESTORE request"
4772 run_test 260a "Restore request have priority over other requests"
4774 # This test is very much tied to the implementation of the current priorisation
4775 # mechanism in the coordinator. It might not make sense to keep it in the future
4778 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4779 skip "need MDS version 2.11.56 or later"
4781 local -a files=("$DIR/$tdir/$tfile".{0..15})
4784 mkdir_on_mdt0 $DIR/$tdir
4786 for file in "${files[@]}"; do
4787 create_small_file "$file"
4790 # Set a few hsm parameters
4792 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4793 set_hsm_param loop_period 1
4795 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4796 set_hsm_param max_requests 3
4799 copytool setup --archive-id 2
4800 "$LFS" hsm_archive --archive 2 "${files[0]}"
4801 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4802 "$LFS" hsm_release "${files[0]}"
4806 wait_copytools || error "copytools failed to stop"
4808 # Send several archive requests
4809 for file in "${files[@]:1}"; do
4810 "$LFS" hsm_archive "$file"
4813 # Send one restore request
4814 "$LFS" hsm_restore "${files[0]}"
4818 copytool setup --archive-id 2
4820 # Wait for all the requests to complete
4821 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4822 for file in "${files[@]:1}"; do
4823 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4826 # Collect the actions in the order in which the copytool processed them
4828 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4829 "$(copytool_logfile "$SINGLEAGT")")
4832 printf '%s\n' "${actions[@]}"
4835 for action in "${actions[@]:0:3}"; do
4836 [ "$action" == RESTORE ] && return
4839 error "Too many ARCHIVE requests were run before the RESTORE request"
4841 run_test 260b "Restore request have priority over other requests"
4843 # This test is very much tied to the implementation of the current priorisation
4844 # mechanism in the coordinator. It might not make sense to keep it in the future
4847 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4848 skip "Need MDS version at least 2.12.0"
4850 local -a files=("$DIR/$tdir/$tfile".{0..15})
4853 mkdir_on_mdt0 $DIR/$tdir
4855 for file in "${files[@]}"; do
4856 create_small_file "$file"
4859 # Set a few hsm parameters
4861 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4862 set_hsm_param loop_period 1000
4864 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4865 set_hsm_param max_requests 3
4868 copytool setup --archive-id 2
4869 "$LFS" hsm_archive --archive 2 "${files[0]}"
4870 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4871 "$LFS" hsm_release "${files[0]}"
4875 wait_copytools || error "copytools failed to stop"
4877 # Force the next coordinator run to do housekeeping
4881 "$LFS" hsm_archive "${files[1]}"
4885 copytool setup --archive-id 2
4887 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4888 # The coordinator just did a housekeeping run it won't do another one
4889 # for around `loop_period' seconds => requests will not be reordered
4890 # if it costs too much (ie. when the coordinator has to discard a whole
4893 # Send several archive requests
4894 for file in "${files[@]:2}"; do
4895 "$LFS" hsm_archive "$file"
4898 # Send one restore request
4899 "$LFS" hsm_restore "${files[0]}"
4901 # Wait for all the requests to complete
4902 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4903 for file in "${files[@]:2}"; do
4904 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4907 # Collect the actions in the order in which the copytool processed them
4909 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4910 "$(copytool_logfile "$SINGLEAGT")")
4913 printf '%s\n' "${actions[@]}"
4916 for action in "${actions[@]:0:3}"; do
4917 [ "$action" == RESTORE ] &&
4918 error "Restore requests should not be prioritised" \
4919 "unless the coordinator is doing housekeeping"
4923 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4926 local file=$DIR/$tdir/$tfile
4931 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4933 dd if=/dev/zero of=$file bs=4k count=2 || error "Write $file failed"
4934 fid=$(path2fid $file)
4935 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $file
4936 wait_request_state $fid ARCHIVE SUCCEED
4938 $LFS hsm_state $file
4939 $LFS hsm_release $file
4940 $LFS hsm_restore $file
4941 wait_request_state $fid RESTORE SUCCEED
4942 $LFS hsm_release $file
4943 size=$(stat -c %s $file)
4944 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4946 $LFS hsm_release $file
4947 $LFS hsm_restore $file
4948 $LFS hsm_release $file
4949 size=$(stat -c %s $file)
4950 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4951 $LFS hsm_state $file
4953 run_test 261 "Report 0 bytes size after HSM release"
4956 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4958 # the only way to test ondisk conf is to restart MDS ...
4959 echo "Stop coordinator and remove coordinator state at mount"
4962 # clean on disk conf set by default
4963 cdt_clear_mount_state
4964 cdt_check_state stopped
4966 # check cdt still off after umount/remount
4968 cdt_check_state stopped
4970 echo "Set coordinator start at mount, and start coordinator"
4971 cdt_set_mount_state enabled
4974 cdt_check_state enabled
4976 # check cdt still on after umount/remount
4978 cdt_check_state enabled
4980 # we are back to original state (cdt started at mount)
4982 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4985 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4987 local ai=$(get_hsm_param default_archive_id)
4988 local new=$((ai + 1))
4990 set_hsm_param default_archive_id $new -P
4992 local res=$(get_hsm_param default_archive_id)
4995 set_hsm_param default_archive_id "" "-P -d"
4997 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4999 run_test 301 "HSM tunnable are persistent"
5002 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
5004 local ai=$(get_hsm_param default_archive_id)
5005 local new=$((ai + 1))
5010 set_hsm_param default_archive_id $new -P
5013 for mdtno in $(seq 1 $MDSCOUNT); do
5018 cdt_check_state enabled
5020 local res=$(get_hsm_param default_archive_id)
5023 set_hsm_param default_archive_id "" "-P -d"
5025 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5027 run_test 302 "HSM tunnable are persistent when CDT is off"
5030 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5034 mkdir_on_mdt0 $DIR/$tdir
5036 local dir_mdt0=$DIR/$tdir/mdt0
5037 local dir_mdt1=$DIR/$tdir/mdt1
5039 # create 1 dir per MDT
5040 stack_trap "rm -rf $dir_mdt0" EXIT
5041 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5042 stack_trap "rm -rf $dir_mdt1" EXIT
5043 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5045 # create 1 file in each MDT
5046 local fid1=$(create_small_file $dir_mdt0/$tfile)
5047 local fid2=$(create_small_file $dir_mdt1/$tfile)
5049 # check that hsm request on mdt0 is sent to the right MDS
5050 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5051 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5052 echo "archive successful on mdt0"
5054 # check that hsm request on mdt1 is sent to the right MDS
5055 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5056 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5057 echo "archive successful on mdt1"
5059 run_test 400 "Single request is sent to the right MDT"
5062 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5066 mkdir_on_mdt0 $DIR/$tdir
5068 local dir_mdt0=$DIR/$tdir/mdt0
5069 local dir_mdt1=$DIR/$tdir/mdt1
5071 # create 1 dir per MDT
5072 stack_trap "rm -rf $dir_mdt0" EXIT
5073 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5074 stack_trap "rm -rf $dir_mdt1" EXIT
5075 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5077 # create 1 file in each MDT
5078 local fid1=$(create_small_file $dir_mdt0/$tfile)
5079 local fid2=$(create_small_file $dir_mdt1/$tfile)
5081 # check that compound requests are shunt to the rights MDTs
5082 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5083 error "lfs hsm_archive"
5084 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5085 echo "archive successful on mdt0"
5086 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5087 echo "archive successful on mdt1"
5089 run_test 401 "Compound requests split and sent to their respective MDTs"
5091 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5096 local node=$(facet_active_host $facet)
5098 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5099 awk '{print $4}'); do
5100 echo "$3 $mdc on $node"
5101 do_facet $facet "$LCTL --device $mdc $state" || return 1
5106 # deactivate all mdc on agent1
5107 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5109 copytool setup --no-fail
5111 check_agent_unregistered "uuid" # match any agent
5113 # no expected running copytool
5114 search_copytools $agent && error "Copytool start should have failed"
5117 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5119 run_test 402a "Copytool start fails if all MDTs are inactive"
5124 mkdir_on_mdt0 $DIR/$tdir
5126 local f=$DIR/$tdir/$tfile
5127 touch $f || error "touch $f failed"
5128 local fid=$(path2fid $f)
5130 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5131 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5134 # give time for CDT to send request and to keep it for retry
5135 wait_for_loop_period
5137 wait_request_state $fid ARCHIVE WAITING
5139 do_facet $SINGLEAGT lctl set_param fail_loc=0
5141 # request should succeed now
5142 wait_request_state $fid ARCHIVE SUCCEED
5144 run_test 402b "CDT must retry request upon slow start of CT"
5147 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5149 local agent=$(facet_active_host $SINGLEAGT)
5151 # deactivate all mdc for MDT0001
5152 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5155 local uuid=$(get_agent_uuid $agent)
5156 # check the agent is registered on MDT0000, and not on MDT0001
5157 check_agent_registered_by_mdt $uuid 0
5158 check_agent_unregistered_by_mdt $uuid 1
5160 # check running copytool process
5161 search_copytools $agent || error "No running copytools on $agent"
5163 # reactivate all mdc for MDT0001
5164 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5166 # make sure the copytool is now registered to all MDTs
5167 check_agent_registered $uuid
5169 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5172 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5176 # create files on both MDT0000 and MDT0001
5177 mkdir_on_mdt0 $DIR/$tdir
5179 local dir_mdt0=$DIR/$tdir/mdt0
5180 stack_trap "rm -rf $dir_mdt0" EXIT
5181 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5183 # create 1 file on mdt0
5184 local fid1=$(create_small_file $dir_mdt0/$tfile)
5186 # deactivate all mdc for MDT0001
5187 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5189 # send an HSM request for files in MDT0000
5190 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5192 # check for completion of files in MDT0000
5193 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5194 echo "archive successful on mdt0"
5196 # reactivate all mdc for MDT0001
5197 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5199 run_test 404 "Inactive MDT does not block requests for active MDTs"
5202 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5206 mkdir_on_mdt0 $DIR/$tdir
5208 local striped_dir=$DIR/$tdir/striped_dir
5210 # create striped dir on all of MDTs
5211 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5213 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5214 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5215 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5216 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5218 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5219 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5220 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5221 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5223 # check that compound requests are shunt to the rights MDTs
5224 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5225 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5226 error "lfs hsm_archive"
5228 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5229 echo "archive successful on $fid1"
5230 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5231 echo "archive successful on $fid2"
5232 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5233 echo "archive successful on $fid3"
5234 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5235 echo "archive successful on $fid4"
5237 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5238 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5239 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5240 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5242 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5243 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5244 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5245 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5247 run_test 405 "archive and release under striped directory"
5250 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5252 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5253 skip "need MDS version at least 2.7.64"
5258 mkdir_on_mdt0 $DIR/$tdir
5260 fid=$(create_small_file $DIR/$tdir/$tfile)
5265 $LFS hsm_archive $DIR/$tdir/$tfile
5266 wait_request_state "$fid" ARCHIVE SUCCEED
5267 $LFS hsm_release $DIR/$tdir/$tfile
5269 # Should migrate $tdir but not $tfile.
5270 $LFS migrate -m1 $DIR/$tdir &&
5271 error "migrating HSM an archived file should fail"
5273 $LFS hsm_restore $DIR/$tdir/$tfile
5274 wait_request_state "$fid" RESTORE SUCCEED
5276 $LFS hsm_remove $DIR/$tdir/$tfile
5277 wait_request_state "$fid" REMOVE SUCCEED
5279 cat $DIR/$tdir/$tfile > /dev/null ||
5280 error "cannot read $DIR/$tdir/$tfile"
5282 $LFS migrate -m1 $DIR/$tdir ||
5283 error "cannot complete migration after HSM remove"
5285 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5286 if ((mdt_index != 1)); then
5287 error "expected MDT index 1, got $mdt_index"
5290 # Refresh fid after migration.
5291 fid=$(path2fid $DIR/$tdir/$tfile)
5294 $LFS hsm_archive $DIR/$tdir/$tfile
5295 wait_request_state "$fid" ARCHIVE SUCCEED 1
5297 lctl set_param debug=+trace
5298 $LFS hsm_release $DIR/$tdir/$tfile ||
5299 error "cannot release $DIR/$tdir/$tfile"
5301 $LFS hsm_restore $DIR/$tdir/$tfile
5302 wait_request_state "$fid" RESTORE SUCCEED 1
5304 cat $DIR/$tdir/$tfile > /dev/null ||
5305 error "cannot read $DIR/$tdir/$tfile"
5307 run_test 406 "attempting to migrate HSM archived files is safe"
5310 mkdir_on_mdt0 $DIR/$tdir
5312 local f=$DIR/$tdir/$tfile
5313 local f2=$DIR2/$tdir/$tfile
5314 local fid=$(create_empty_file "$f")
5318 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5319 wait_request_state $fid ARCHIVE SUCCEED
5322 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5323 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5325 # Prevent restore from completing
5329 # 1st request holds layout lock while appropriate
5330 # RESTORE record is still not added to llog
5334 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5335 # after umount hsm_actions->O/x/x log shouldn't have
5336 # double RESTORE records like below
5337 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5338 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5340 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5342 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5344 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5347 wait_all_done 100 $fid
5349 run_test 407 "Check for double RESTORE records in llog"
5353 [ "$MDS1_VERSION" -lt $(version_code 2.6.92) ] &&
5354 skip "HSM migrate is not supported"
5356 test_mkdir -p $DIR/$tdir
5358 if [ "$CLIENT_VERSION" -lt $(version_code 2.11.56) ] ||
5359 [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ];
5361 llapi_hsm_test -d $DIR/$tdir -b ||
5362 error "One llapi HSM test failed"
5364 llapi_hsm_test -d $DIR/$tdir ||
5365 error "One llapi HSM test failed"
5368 run_test 500 "various LLAPI HSM tests"
5371 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
5372 skip "need MDS version at least 2.10.58"
5376 local f=$DIR/$tdir/$tfile
5379 # set changelog_mask to ALL
5380 changelog_chmask "ALL"
5382 chmod 777 $DIR/$tdir
5383 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5384 local fid=$(path2fid $f)
5387 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5388 -gid "$RUNAS_GID") ||
5389 error "No matching CREAT entry"
5391 # Parse the changelog
5392 eval local -A changelog=$(changelog2array $entry)
5393 local nid="${changelog[nid]}"
5396 echo "Got NID '$nid'"
5397 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5398 error "nid '$nid' does not match any client NID:" \
5401 run_test 600 "Changelog fields 'u=' and 'nid='"
5404 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5405 skip "need MDS version at least 2.10.58"
5409 local f=$DIR/$tdir/$tfile
5412 # set changelog_mask to ALL
5413 changelog_chmask "ALL"
5415 touch $f || error "touch $f failed"
5416 local fid=$(path2fid $f)
5419 cat $f || error "cat $f failed"
5421 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5422 error "No matching OPEN entry"
5424 run_test 601 "OPEN Changelog entry"
5427 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5428 skip "need MDS version at least 2.10.58"
5430 stack_trap "restore_opencache" EXIT
5435 local f=$DIR/$tdir/$tfile
5438 # set changelog_mask to ALL
5439 changelog_chmask "ALL"
5441 touch $f || error "touch $f failed"
5442 local fid=$(path2fid $f)
5445 cat $f || error "cat $f failed"
5447 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5451 echo f > $f || error "write $f failed"
5454 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5456 # remove OPEN from changelog_mask
5457 changelog_chmask "-OPEN"
5461 cat $f || error "cat $f failed"
5464 changelog_find -type CLOSE -target-fid $fid &&
5465 error "There should be no CLOSE entry"
5469 echo f > $f || error "write $f failed"
5472 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5474 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5477 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5478 skip "need MDS version at least 2.10.58"
5482 local f=$DIR/$tdir/$tfile
5485 # set changelog_mask to ALL
5486 changelog_chmask "ALL"
5488 touch $f || error "touch $f failed"
5489 local fid=$(path2fid $f)
5491 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5494 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5496 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5497 error "No matching GXATR entry"
5499 run_test 603 "GETXATTR Changelog entry"
5502 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5503 skip "need MDS version at least 2.10.58"
5505 mkdir_on_mdt0 $DIR/$tdir
5507 local f=$DIR/$tdir/$tfile
5508 local f2=$DIR2/$tdir/$tfile
5509 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5511 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5512 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5513 do_facet mds1 lctl set_param "$procname=20"
5517 # set changelog_mask to ALL
5518 changelog_chmask "ALL"
5520 touch $f || error "touch $f failed"
5521 local fid=$(path2fid $f)
5527 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5531 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5532 -gid "$RUNAS_GID" -mode "r--") ||
5533 error "No matching NOPEN entry"
5535 # Parse the changelog
5536 eval local -A changelog=$(changelog2array $entry)
5537 local nid="${changelog[nid]}"
5540 echo "Got NID '$nid'"
5541 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5542 error "nid '$nid' does not match any client NID:" \
5547 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5550 changelog_find -type NOPEN -target-fid $fid &&
5551 error "There should be no NOPEN entry"
5553 # Sleep for `changelog_deniednext` seconds
5558 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5561 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5562 -gid "$RUNAS_GID" -mode "r--") ||
5563 error "No matching NOPEN entry"
5565 # Parse the changelog
5566 eval local -A changelog=$(changelog2array $entry)
5567 local nid="${changelog[nid]}"
5570 echo "Got NID '$nid'"
5571 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5572 error "nid '$nid' does not match any client NID:" \
5575 run_test 604 "NOPEN Changelog entry"
5578 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5579 skip "need MDS version at least 2.10.58"
5581 stack_trap "restore_opencache" EXIT
5586 local f=$DIR/$tdir/$tfile
5587 local f2=$DIR2/$tdir/$tfile
5590 # set changelog_mask to ALL
5591 changelog_chmask "ALL"
5593 touch $f || error "touch $f failed"
5594 local fid=$(path2fid $f)
5598 exec 3<> $f || error "open $f failed"
5602 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5606 exec 4<> $f || error "open $f failed"
5609 changelog_find -type OPEN -target-fid $fid &&
5610 error "There should be no OPEN entry"
5612 exec 4>&- || error "close $f failed"
5615 changelog_find -type CLOSE -target-fid $fid &&
5616 error "There should be no CLOSE entry"
5620 # access in rw, so different access mode should generate entries
5621 cat $f || error "cat $f failed"
5624 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5626 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5630 # same access as first one, should not generate new entries
5631 exec 4<> $f || error "open $f failed"
5634 changelog_find -type OPEN -target-fid $fid &&
5635 error "There should be no OPEN entry"
5637 exec 4>&- || error "close $f failed"
5640 changelog_find -type CLOSE -target-fid $fid &&
5641 error "There should be no CLOSE entry"
5645 # access by different user should generate new entries
5646 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5649 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5651 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5655 exec 3>&- || error "close $f failed"
5658 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5660 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5663 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5664 skip "need MDS version at least 2.10.58"
5666 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5667 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5668 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5669 skip_env "missing llog_reader"
5671 mkdir_on_mdt0 $DIR/$tdir
5673 local f=$DIR/$tdir/$tfile
5676 # set changelog_mask to ALL
5677 changelog_chmask "ALL"
5679 chmod 777 $DIR/$tdir
5680 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5681 local fid=$(path2fid $f)
5682 rm $f || error "rm $f failed"
5684 local mntpt=$(facet_mntpt mds1)
5688 #remount mds1 as ldiskfs or zfs type
5689 stop mds1 || error "stop mds1 failed"
5690 stack_trap "unmount_fstype mds1; start mds1 $(mdsdevname 1)\
5691 $MDS_MOUNT_OPTS" EXIT
5692 mount_fstype mds1 || error "remount mds1 failed"
5694 for ((i = 0; i < 1; i++)); do
5695 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5696 local cat_file=$(do_facet mds1 $llog_reader \
5697 $mntpt/changelog_catalog | awk \
5698 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5699 [ -n "$cat_file" ] || error "no catalog file"
5701 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5702 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5703 [ -n "$entry" ] || error "no CREAT entry"
5706 local uidgid=$(echo $entry |
5707 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5708 [ -n "$uidgid" ] || error "uidgid is empty"
5709 echo "Got UID/GID $uidgid"
5710 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5711 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5712 local nid=$(echo $entry |
5713 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5714 [ -n "$nid" ] || error "nid is empty"
5716 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5717 error "nid '$nid' does not match any NID ${CLIENT_NIDS[*]}"
5719 run_test 606 "llog_reader groks changelog fields"
5722 check_and_cleanup_lustre