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"
1389 for i in {1..10}; do
1390 local archive_dir="$(hsm_root)"/subdir/dir.$i
1392 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1393 for j in {1..10}; do
1394 local archive_file="$archive_dir"/file.$j
1396 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1402 copytool import "subdir" "$DIR/$tdir"
1404 # To check the import, the test uses diff with the -r flag
1405 # This is nice, but diff only checks files one by one, and triggering
1406 # an implicit restore for one file at a time will consume as many
1407 # seconds as there are files to compare. To speed this up, a restore
1408 # operation is triggered manually first.
1410 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1412 # Compare the imported data
1413 do_facet $SINGLEAGT \
1414 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1415 error "imported files differ from archived data"
1417 run_test 13 "Recursively import and restore a directory"
1420 # test needs a running copytool
1423 mkdir_on_mdt0 $DIR/$tdir
1426 local f=$DIR/$tdir/$tfile
1427 local fid=$(create_small_file $f)
1428 local sum=$(md5sum $f | awk '{print $1}')
1429 $LFS hsm_archive $f || error "could not archive file"
1430 wait_request_state $fid ARCHIVE SUCCEED
1432 # create released file (simulate llapi_hsm_import call)
1433 local fid2=$(create_empty_file "$f")
1434 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1435 $LFS hsm_release $f || error "could not release file"
1437 # rebind the archive to the newly created file
1438 echo "rebind $fid to $fid2"
1440 copytool rebind $fid $fid2
1442 # restore file and compare md5sum
1443 local sum2=$(md5sum $f | awk '{print $1}')
1445 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1447 run_test 14 "Rebind archived file to a new fid"
1450 # test needs a running copytool
1453 mkdir_on_mdt0 $DIR/$tdir
1456 local f=$DIR/$tdir/$tfile
1458 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1462 for i in $(seq 1 $count); do
1463 fids[$i]=$(create_small_file $f.$i)
1464 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1465 $LFS hsm_archive $f.$i || error "could not archive file"
1467 wait_all_done $(($count*60))
1469 stack_trap "rm -f $tmpfile" EXIT
1472 for i in $(seq 1 $count); do
1473 local fid2=$(create_empty_file "${f}.${i}")
1474 # add the rebind operation to the list
1475 echo ${fids[$i]} $fid2 >> $tmpfile
1477 # set it released (simulate llapi_hsm_import call)
1478 $LFS hsm_set --archived --exists $f.$i ||
1479 error "could not force hsm flags"
1480 $LFS hsm_release $f.$i || error "could not release file"
1482 nl=$(wc -l < $tmpfile)
1483 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1485 echo "rebind list of files"
1486 copytool rebind "$tmpfile"
1488 # restore files and compare md5sum
1489 for i in $(seq 1 $count); do
1490 local sum2=$(md5sum $f.$i | awk '{print $1}')
1491 [[ $sum2 == ${sums[$i]} ]] ||
1492 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1495 run_test 15 "Rebind a list of files"
1498 # test needs a running copytool
1502 # create a known size file so we can verify transfer speed
1505 dd if=/dev/zero of=$ref bs=1M count=20
1507 mkdir_on_mdt0 $DIR/$tdir
1508 local f=$DIR/$tdir/$tfile
1509 local fid=$(copy_file $ref $f)
1511 local start=$(date +%s)
1513 wait_request_state $fid ARCHIVE SUCCEED
1514 local end=$(date +%s)
1515 # Add 1 to account for rounding errors between start and end (LU-8155)
1516 local duration=$((end - start + 1))
1518 [[ $duration -ge $((goal - 1)) ]] ||
1519 error "Transfer is too fast $duration < $goal"
1521 run_test 16 "Test CT bandwith control option"
1524 local f=$DIR/$tdir/$tfile
1525 create_empty_file "$f"
1527 # Could not release a non-archived file
1528 $LFS hsm_release $f && error "release should not succeed"
1530 # For following tests, we must test them with HS_ARCHIVED set
1531 $LFS hsm_set --exists --archived $f || error "could not add flag"
1533 # Could not release a file if no-release is set
1534 $LFS hsm_set --norelease $f || error "could not add flag"
1535 $LFS hsm_release $f && error "release should not succeed"
1536 $LFS hsm_clear --norelease $f || error "could not remove flag"
1538 # Could not release a file if lost
1539 $LFS hsm_set --lost $f || error "could not add flag"
1540 $LFS hsm_release $f && error "release should not succeed"
1541 $LFS hsm_clear --lost $f || error "could not remove flag"
1543 # Could not release a file if dirty
1544 $LFS hsm_set --dirty $f || error "could not add flag"
1545 $LFS hsm_release $f && error "release should not succeed"
1546 $LFS hsm_clear --dirty $f || error "could not remove flag"
1548 run_test 20 "Release is not permitted"
1551 # test needs a running copytool
1553 mkdir_on_mdt0 $DIR/$tdir
1555 local f=$DIR/$tdir/test_release
1557 # Create a file and check its states
1558 local fid=$(create_small_file $f)
1559 check_hsm_flags $f "0x00000000"
1561 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1562 # used until file is flushed to disk
1563 if [ "$ost1_FSTYPE" == "zfs" ]; then
1564 # this causes an OST_SYNC rpc to be sent
1565 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1566 # clear locks to reread file data
1567 cancel_lru_locks osc
1570 local orig_size=$(stat -c "%s" $f)
1571 local orig_blocks=$(stat -c "%b" $f)
1573 start_full_debug_logging
1575 $LFS hsm_archive $f || error "could not archive file"
1576 wait_request_state $fid ARCHIVE SUCCEED
1578 local blocks=$(stat -c "%b" $f)
1579 [ $blocks -eq $orig_blocks ] ||
1580 error "$f: wrong block number after archive: " \
1581 "$blocks != $orig_blocks"
1582 local size=$(stat -c "%s" $f)
1583 [ $size -eq $orig_size ] ||
1584 error "$f: wrong size after archive: $size != $orig_size"
1586 # Release and check states
1587 $LFS hsm_release $f || error "could not release file"
1588 check_hsm_flags $f "0x0000000d"
1590 blocks=$(stat -c "%b" $f)
1591 [ $blocks -gt 5 ] &&
1592 error "$f: too many blocks after release: $blocks > 5"
1593 size=$(stat -c "%s" $f)
1594 [ $size -ne $orig_size ] &&
1595 error "$f: wrong size after release: $size != $orig_size"
1597 # Check we can release an file without stripe info
1601 check_hsm_flags $f "0x00000000"
1602 $LFS hsm_archive $f || error "could not archive file"
1603 wait_request_state $fid ARCHIVE SUCCEED
1605 # Release and check states
1606 $LFS hsm_release $f || error "could not release file"
1607 check_hsm_flags $f "0x0000000d"
1609 # Release again a file that is already released is OK
1610 $LFS hsm_release $f || fail "second release should succeed"
1611 check_hsm_flags $f "0x0000000d"
1613 stop_full_debug_logging
1615 run_test 21 "Simple release tests"
1618 # test needs a running copytool
1620 mkdir_on_mdt0 $DIR/$tdir
1622 local f=$DIR/$tdir/test_release
1623 local swap=$DIR/$tdir/test_swap
1625 # Create a file and check its states
1626 local fid=$(create_small_file $f)
1627 check_hsm_flags $f "0x00000000"
1629 $LFS hsm_archive $f || error "could not archive file"
1630 wait_request_state $fid ARCHIVE SUCCEED
1632 # Release and check states
1633 $LFS hsm_release $f || error "could not release file"
1634 check_hsm_flags $f "0x0000000d"
1636 create_small_file $swap
1637 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1641 run_test 22 "Could not swap a release file"
1644 # test needs a running copytool
1646 mkdir_on_mdt0 $DIR/$tdir
1648 local f=$DIR/$tdir/test_mtime
1650 # Create a file and check its states
1651 local fid=$(create_small_file $f)
1652 check_hsm_flags $f "0x00000000"
1654 $LFS hsm_archive $f || error "could not archive file"
1655 wait_request_state $fid ARCHIVE SUCCEED
1657 # Set modification time in the past
1658 touch -m -a -d @978261179 $f
1660 # Release and check states
1661 $LFS hsm_release $f || error "could not release file"
1662 check_hsm_flags $f "0x0000000d"
1664 local MTIME=$(stat -c "%Y" $f)
1665 local ATIME=$(stat -c "%X" $f)
1666 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1667 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1669 run_test 23 "Release does not change a/mtime (utime)"
1672 local file=$DIR/$tdir/$tfile
1681 # test needs a running copytool
1683 mkdir_on_mdt0 $DIR/$tdir
1685 fid=$(create_small_file $file)
1687 # Create a file and check its states
1688 check_hsm_flags $file "0x00000000"
1690 # Ensure atime is less than mtime and ctime.
1694 atime0=$(stat -c "%X" $file)
1695 mtime0=$(stat -c "%Y" $file)
1696 ctime0=$(stat -c "%Z" $file)
1698 [ $atime0 -lt $mtime0 ] ||
1699 error "atime $atime0 is not less than mtime $mtime0"
1701 [ $atime0 -lt $ctime0 ] ||
1702 error "atime $atime0 is not less than ctime $ctime0"
1704 # Archive should not change any timestamps.
1705 $LFS hsm_archive $file || error "cannot archive '$file'"
1706 wait_request_state $fid ARCHIVE SUCCEED
1708 atime1=$(stat -c "%X" $file)
1709 mtime1=$(stat -c "%Y" $file)
1710 ctime1=$(stat -c "%Z" $file)
1712 [ $atime0 -eq $atime1 ] ||
1713 error "archive changed atime from $atime0 to $atime1"
1715 [ $mtime0 -eq $mtime1 ] ||
1716 error "archive changed mtime from $mtime0 to $mtime1"
1718 [ $ctime0 -eq $ctime1 ] ||
1719 error "archive changed ctime from $ctime0 to $ctime1"
1721 # Release should not change any timestamps.
1722 $LFS hsm_release $file || error "cannot release '$file'"
1723 check_hsm_flags $file "0x0000000d"
1725 atime1=$(stat -c "%X" $file)
1726 mtime1=$(stat -c "%Y" $file)
1727 ctime1=$(stat -c "%Z" $file)
1729 [ $atime0 -eq $atime1 ] ||
1730 error "release changed atime from $atime0 to $atime1"
1732 [ $mtime0 -eq $mtime1 ] ||
1733 error "release changed mtime from $mtime0 to $mtime1"
1735 [ $ctime0 -eq $ctime1 ] ||
1736 error "release changed ctime from $ctime0 to $ctime1"
1738 # Restore should not change any timestamps.
1739 $LFS hsm_restore $file
1740 wait_request_state $fid RESTORE SUCCEED
1742 atime1=$(stat -c "%X" $file)
1743 mtime1=$(stat -c "%Y" $file)
1744 ctime1=$(stat -c "%Z" $file)
1746 [ $atime0 -eq $atime1 ] ||
1747 error "restore changed atime from $atime0 to $atime1"
1749 [ $mtime0 -eq $mtime1 ] ||
1750 error "restore changed mtime from $mtime0 to $mtime1"
1752 [ $ctime0 -eq $ctime1 ] ||
1753 error "restore changed ctime from $ctime0 to $ctime1"
1756 wait_copytools || error "Copytools failed to stop"
1758 # Once more, after unmount and mount.
1759 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1760 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1762 atime1=$(stat -c "%X" $file)
1763 mtime1=$(stat -c "%Y" $file)
1764 ctime1=$(stat -c "%Z" $file)
1766 [ $atime0 -eq $atime1 ] ||
1767 error "remount changed atime from $atime0 to $atime1"
1769 [ $mtime0 -eq $mtime1 ] ||
1770 error "remount changed mtime from $mtime0 to $mtime1"
1772 [ $ctime0 -eq $ctime1 ] ||
1773 error "remount changed ctime from $ctime0 to $ctime1"
1775 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1778 local file=$DIR/$tdir/$tfile
1784 # Test needs a running copytool.
1786 mkdir_on_mdt0 $DIR/$tdir
1788 # Check that root can do HSM actions on a regular user's file.
1789 fid=$(create_small_file $file)
1790 sum0=$(md5sum $file)
1792 chown $RUNAS_ID:$RUNAS_GID $file ||
1793 error "cannot chown '$file' to '$RUNAS_ID'"
1795 chmod ugo-w $DIR/$tdir ||
1796 error "cannot chmod '$DIR/$tdir'"
1798 $LFS hsm_archive $file
1799 wait_request_state $fid ARCHIVE SUCCEED
1801 $LFS hsm_release $file
1802 check_hsm_flags $file "0x0000000d"
1804 $LFS hsm_restore $file
1805 wait_request_state $fid RESTORE SUCCEED
1807 # Check that ordinary user can get HSM state.
1808 $RUNAS $LFS hsm_state $file ||
1809 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1811 $LFS hsm_release $file
1812 check_hsm_flags $file "0x0000000d"
1814 # Check that ordinary user can accessed released file.
1815 sum1=$($RUNAS md5sum $file) ||
1816 error "user '$RUNAS_ID' cannot read '$file'"
1818 [ "$sum0" == "$sum1" ] ||
1819 error "md5sum mismatch for '$file'"
1821 run_test 24b "root can archive, release, and restore user files"
1824 local file=$DIR/$tdir/$tfile
1825 local action=archive
1830 # test needs a running copytool
1832 mkdir_on_mdt0 $DIR/$tdir
1834 # Save the default masks and check that cleanup_24c will
1835 # restore the request masks correctly.
1836 user_save=$(get_hsm_param user_request_mask)
1837 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1838 group_save=$(get_hsm_param group_request_mask)
1839 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1840 other_save=$(get_hsm_param other_request_mask)
1841 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1843 [ "$user_save" == RESTORE ] ||
1844 error "user_request_mask is '$user_save' expected 'RESTORE'"
1845 [ "$group_save" == RESTORE ] ||
1846 error "group_request_mask is '$group_save' expected 'RESTORE'"
1847 [ "$other_save" == RESTORE ] ||
1848 error "other_request_mask is '$other_save' expected 'RESTORE'"
1851 create_small_file $file
1852 chown $RUNAS_ID:$GROUP $file ||
1853 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1855 $RUNAS $LFS hsm_$action $file &&
1856 error "$action by user should fail"
1858 set_hsm_param user_request_mask $action
1859 $RUNAS $LFS hsm_$action $file ||
1860 error "$action by user should succeed"
1863 create_small_file $file
1864 chown nobody:$RUNAS_GID $file ||
1865 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1867 $RUNAS $LFS hsm_$action $file &&
1868 error "$action by group should fail"
1870 set_hsm_param group_request_mask $action
1871 $RUNAS $LFS hsm_$action $file ||
1872 error "$action by group should succeed"
1875 create_small_file $file
1876 chown nobody:$GROUP $file ||
1877 error "cannot chown '$file' to 'nobody:$GROUP'"
1879 $RUNAS $LFS hsm_$action $file &&
1880 error "$action by other should fail"
1882 set_hsm_param other_request_mask $action
1883 $RUNAS $LFS hsm_$action $file ||
1884 error "$action by other should succeed"
1886 run_test 24c "check that user,group,other request masks work"
1889 local file1=$DIR/$tdir/$tfile
1890 local file2=$DIR2/$tdir/$tfile
1894 mkdir_on_mdt0 $DIR/$tdir
1896 fid1=$(create_small_file $file1)
1899 $LFS getstripe $file1
1901 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1902 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1903 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1905 copytool setup -m "$MOUNT3"
1907 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1908 mount -o remount,ro $MOUNT2
1910 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1912 fid2=$(path2fid $file2)
1913 [ "$fid1" == "$fid2" ] ||
1914 error "FID mismatch '$fid1' != '$fid2'"
1916 $LFS hsm_archive $file2 &&
1917 error "archive should fail on read-only mount"
1918 check_hsm_flags $file1 "0x00000000"
1920 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1921 wait_request_state $fid1 ARCHIVE SUCCEED
1923 $LFS hsm_release $file1
1924 $LFS hsm_restore $file2
1925 wait_request_state $fid1 RESTORE SUCCEED
1927 $LFS hsm_release $file1 || error "cannot release '$file1'"
1928 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1930 $LFS hsm_release $file2 &&
1931 error "release should fail on read-only mount"
1935 run_test 24d "check that read-only mounts are respected"
1939 mkdir_on_mdt0 $DIR/$tdir
1941 local f=$DIR/$tdir/$tfile
1944 fid=$(create_small_file $f) || error "cannot create $f"
1945 $LFS hsm_archive $f || error "cannot archive $f"
1946 wait_request_state $fid ARCHIVE SUCCEED
1947 $LFS hsm_release $f || error "cannot release $f"
1948 while ! $LFS hsm_state $f | grep released; do
1952 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1954 run_test 24e "tar succeeds on HSM released files" # LU-6213
1957 # test needs a running copytool
1959 mkdir_on_mdt0 $DIR/$tdir
1961 mkdir -p $DIR/$tdir/d1
1962 local f=$DIR/$tdir/$tfile
1963 local fid=$(copy_file /etc/hosts $f)
1966 $LFS hsm_archive $f ||
1967 error "hsm_archive failed"
1968 wait_request_state $fid ARCHIVE SUCCEED
1969 $LFS hsm_release $f || error "cannot release $f"
1970 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1973 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1974 error "Can not recover the tar contents"
1976 echo "Sum0 = $sum0, sum1 = $sum1"
1977 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1979 run_test 24f "root can archive, release, and restore tar files"
1982 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1983 skip "need MDS version 2.11.56 or later"
1985 local file=$DIR/$tdir/$tfile
1988 echo "RUNAS = '$RUNAS'"
1992 mkdir_on_mdt0 $DIR/$tdir
1993 chmod ugo+rwx $DIR/$tdir
1995 echo "Please listen carefully as our options have changed." | tee $file
1996 fid=$(path2fid $file)
1999 $LFS hsm_archive $file
2000 wait_request_state $fid ARCHIVE SUCCEED
2001 check_hsm_flags $file 0x00000009 # exists archived
2003 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2004 check_hsm_flags $file 0x0000000b # exists dirty archived
2006 run_test 24g "write by non-owner still sets dirty" # LU-11369
2009 # test needs a running copytool
2013 copy2archive /etc/hosts $tdir/$tfile
2015 local f=$DIR/$tdir/$tfile
2017 copytool import $tdir/$tfile $f
2019 $LFS hsm_set --lost $f
2024 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2026 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2027 " (Operation not permitted)"
2030 # test needs a running copytool
2033 mkdir_on_mdt0 $DIR/$tdir
2035 local f=$DIR/$tdir/$tfile
2036 local fid=$(copy_file /etc/passwd $f)
2038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2039 wait_request_state $fid ARCHIVE SUCCEED
2042 $LFS hsm_set --lost $f
2046 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2048 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2049 " (Operation not permitted)"
2051 test_26A() { # was test_26
2052 # test needs a running copytool
2054 mkdir_on_mdt0 $DIR/$tdir
2056 local f=$DIR/$tdir/$tfile
2057 local fid=$(create_empty_file "$f")
2059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2060 wait_request_state $fid ARCHIVE SUCCEED
2063 wait_request_state $fid REMOVE SUCCEED
2065 check_hsm_flags $f "0x00000000"
2067 run_test 26A "Remove the archive of a valid file"
2070 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2071 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2073 # test needs a running copytool
2075 mkdir_on_mdt0 $DIR/$tdir
2077 local f=$DIR/$tdir/$tfile
2078 local fid=$(copy_file /etc/passwd $f)
2080 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2081 wait_request_state $fid ARCHIVE SUCCEED
2083 local f2=$DIR/$tdir/${tfile}_2
2084 local fid2=$(copy_file /etc/passwd $f2)
2086 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2087 wait_request_state $fid2 ARCHIVE SUCCEED
2089 local f3=$DIR/$tdir/${tfile}_3
2090 local fid3=$(copy_file /etc/passwd $f3)
2092 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2093 wait_request_state $fid3 ARCHIVE SUCCEED
2095 # set a long grace_delay vs short loop_period
2096 local orig_loop_period=$(get_hsm_param loop_period)
2097 local orig_grace_delay=$(get_hsm_param grace_delay)
2098 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2099 set_hsm_param loop_period 10
2100 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2101 set_hsm_param grace_delay 100
2105 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2106 set_hsm_param remove_archive_on_last_unlink 1
2108 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2113 wait_request_state $fid2 REMOVE SUCCEED
2115 assert_request_count $fid REMOVE 0 \
2116 "Unexpected archived data remove request for $f"
2117 assert_request_count $fid3 REMOVE 0 \
2118 "Unexpected archived data remove request for $f3"
2120 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2123 # test needs a running copytool
2125 mkdir_on_mdt0 $DIR/$tdir
2127 local f=$DIR/$tdir/$tfile
2128 local fid=$(copy_file /etc/passwd $f)
2130 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2131 wait_request_state $fid ARCHIVE SUCCEED
2133 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2134 set_hsm_param remove_archive_on_last_unlink 1
2137 cdt_check_state stopped
2141 wait_request_state $fid REMOVE WAITING
2145 # copytool must re-register
2147 wait_copytools || error "copytool failed to stop"
2150 wait_request_state $fid REMOVE SUCCEED
2152 run_test 26b "RAoLU policy when CDT off"
2155 # test needs a running copytool
2157 mkdir_on_mdt0 $DIR/$tdir
2159 local f=$DIR/$tdir/$tfile
2160 local fid=$(copy_file /etc/passwd $f)
2162 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2163 wait_request_state $fid ARCHIVE SUCCEED
2165 local f2=$DIR/$tdir/${tfile}_2
2166 local fid2=$(copy_file /etc/passwd $f2)
2168 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2169 wait_request_state $fid2 ARCHIVE SUCCEED
2171 # set a long grace_delay vs short loop_period
2172 local orig_loop_period=$(get_hsm_param loop_period)
2173 local orig_grace_delay=$(get_hsm_param grace_delay)
2174 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2175 set_hsm_param loop_period 10
2176 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2177 set_hsm_param grace_delay 100
2179 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2180 set_hsm_param remove_archive_on_last_unlink 1
2182 multiop_bg_pause $f O_c || error "open $f failed"
2188 wait_request_state $fid2 REMOVE SUCCEED
2189 assert_request_count $fid REMOVE 0 \
2190 "Unexpected archived data remove request for $f"
2192 kill -USR1 $pid || error "multiop early exit"
2193 # should reach autotest timeout if multiop fails to trap
2194 # signal, close file, and exit ...
2195 wait $pid || error "wait PID $PID failed"
2197 wait_request_state $fid REMOVE SUCCEED
2199 run_test 26c "RAoLU effective when file closed"
2202 # test needs a running copytool
2204 mkdir_on_mdt0 $DIR/$tdir
2206 local f=$DIR/$tdir/$tfile
2207 local fid=$(create_small_file $f)
2209 $LFS hsm_archive $f || error "could not archive file"
2210 wait_request_state $fid ARCHIVE SUCCEED
2212 # set a long grace_delay vs short loop_period
2213 local orig_loop_period=$(get_hsm_param loop_period)
2214 local orig_grace_delay=$(get_hsm_param grace_delay)
2215 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2216 set_hsm_param loop_period 10
2217 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2218 set_hsm_param grace_delay 100
2220 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2221 set_hsm_param remove_archive_on_last_unlink 1
2223 multiop_bg_pause $f O_c || error "multiop failed"
2230 wait_request_state $fid REMOVE SUCCEED
2232 client_up || client_up || true
2234 kill -USR1 $MULTIPID
2235 wait $MULTIPID || error "multiop close failed"
2237 run_test 26d "RAoLU when Client eviction"
2240 # test needs a running copytool
2243 create_archive_file $tdir/$tfile
2244 local f=$DIR/$tdir/$tfile
2245 copytool import $tdir/$tfile $f
2246 local fid=$(path2fid $f)
2250 [[ $? != 0 ]] || error "Remove of a released file should fail"
2252 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2255 # test needs a running copytool
2257 mkdir_on_mdt0 $DIR/$tdir
2259 local f=$DIR/$tdir/$tfile
2260 local fid=$(create_empty_file "$f")
2262 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2263 wait_request_state $fid ARCHIVE SUCCEED
2268 [[ $? != 0 ]] || error "Remove of a released file should fail"
2270 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2273 # test needs a running copytool
2275 mkdir_on_mdt0 $DIR/$tdir
2277 local f=$DIR/$tdir/$tfile
2278 local fid=$(create_empty_file "$f")
2280 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2281 wait_request_state $fid ARCHIVE SUCCEED
2290 wait_request_state $fid REMOVE SUCCEED
2292 run_test 28 "Concurrent archive/file remove"
2295 # Tests --mntpath and --archive options
2298 copytool setup -m "$MOUNT" -a $archive_id
2300 # Bad archive number
2301 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2302 grep "Invalid argument" ||
2303 error "unexpected hsm_remove failure (1)"
2305 # mntpath is present but file is given
2306 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2307 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2308 error "unexpected hsm_remove failure (2)"
2310 run_test 29a "Tests --mntpath and --archive options"
2313 # test needs a running copytool
2315 mkdir_on_mdt0 $DIR/$tdir
2317 local f=$DIR/$tdir/$tfile
2318 local fid=$(create_small_file $f)
2320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2321 wait_request_state $fid ARCHIVE SUCCEED
2325 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2326 wait_request_state $fid REMOVE SUCCEED
2328 run_test 29b "Archive/delete/remove by FID from the archive."
2331 # test needs a running copytool
2333 mkdir_on_mdt0 $DIR/$tdir
2335 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2336 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2337 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2340 wait_request_state $fid1 ARCHIVE SUCCEED
2341 wait_request_state $fid2 ARCHIVE SUCCEED
2342 wait_request_state $fid3 ARCHIVE SUCCEED
2344 rm -f $DIR/$tdir/$tfile-[1-3]
2346 echo $fid1 > $DIR/$tdir/list
2347 echo $fid2 >> $DIR/$tdir/list
2348 echo $fid3 >> $DIR/$tdir/list
2350 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2351 --filelist $DIR/$tdir/list
2352 wait_request_state $fid1 REMOVE SUCCEED
2353 wait_request_state $fid2 REMOVE SUCCEED
2354 wait_request_state $fid3 REMOVE SUCCEED
2356 run_test 29c "Archive/delete/remove by FID, using a file list."
2359 # test needs more than one CT
2360 needclients 3 || return 0
2366 # start all of the copytools
2367 for n in $(seq $AGTCOUNT); do
2368 copytool setup -f agt$n -a $n
2371 mkdir_on_mdt0 $DIR/$tdir
2374 file=$DIR/$tdir/$tfile
2375 fid=$(create_small_file $file)
2377 $LFS hsm_archive $file
2378 wait_request_state $fid ARCHIVE SUCCEED
2379 check_hsm_flags $file "0x00000009"
2383 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2384 error "cannot hsm_remove '$fid'"
2386 # give time for CDT to handle remove request and create broadcasted
2389 # remove request has been broadcasted ?
2390 local cnt=$(get_request_count $fid REMOVE)
2391 # broadcasted requests + original
2392 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2393 error "remove not broadcasted to all CTs"
2395 # give time for CDT and CTs to handle broadcasted
2396 wait_for_loop_period
2398 # each agent serves one different archive_id, so broadcasted
2399 # hsm_remove request should only succeed once and fail at all others
2403 for n in $(seq $AGTCOUNT); do
2404 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2405 $HSM_PARAM.actions | awk \
2406 '/'$fid'.*action=REMOVE archive#='$n'/ \
2407 {print \\\$13}' | cut -f2 -d=")
2408 if [[ "$res" == "SUCCEED" ]]; then
2410 elif [[ "$res" == "FAILED" ]]; then
2415 [[ $scnt -eq 1 ]] ||
2416 error "one and only CT should have removed successfully"
2418 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2419 error "all but one CT should have failed to remove"
2421 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2422 "request to be sent once for each registered archive_id"
2425 # restore at exec cannot work on agent node (because of Linux kernel
2426 # protection of executables)
2427 needclients 2 || return 0
2429 # test needs a running copytool
2433 copy2archive /bin/true $tdir/$tfile
2435 local f=$DIR/$tdir/true
2436 copytool import $tdir/$tfile $f
2438 local fid=$(path2fid $f)
2440 stack_trap "cdt_clear_no_retry" EXIT
2441 # set no retry action mode
2448 [[ $st == 0 ]] || error "Failed to exec a released file"
2450 run_test 30a "Restore at exec (import case)"
2453 # restore at exec cannot work on agent node (because of Linux kernel
2454 # protection of executables)
2455 needclients 2 || return 0
2457 # test needs a running copytool
2460 mkdir_on_mdt0 $DIR/$tdir
2461 local f=$DIR/$tdir/true
2462 local fid=$(copy_file /bin/true $f)
2464 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2465 wait_request_state $fid ARCHIVE SUCCEED
2469 stack_trap cdt_clear_no_retry EXIT
2470 # set no retry action mode
2478 [[ $st == 0 ]] || error "Failed to exec a released file"
2480 run_test 30b "Restore at exec (release case)"
2483 needclients 2 || return 0
2485 # test needs a running copytool
2488 mkdir_on_mdt0 $DIR/$tdir
2489 local f=$DIR/$tdir/SLEEP
2490 local slp_sum1=$(md5sum /bin/sleep)
2491 local fid=$(copy_file /bin/sleep $f)
2493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2494 wait_request_state $fid ARCHIVE SUCCEED
2496 check_hsm_flags $f "0x0000000d"
2498 stack_trap cdt_clear_no_retry EXIT
2499 # set no retry action mode
2502 do_node $CLIENT2 "$f 10" &
2506 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2508 [[ $? == 0 ]] || error "Execution failed during run"
2510 if [[ $? != 0 ]]; then
2511 local slp_sum2=$(md5sum /bin/sleep)
2512 # in case sleep file is modified during the test
2513 [[ $slp_sum1 == $slp_sum2 ]] &&
2514 error "Binary overwritten during exec"
2517 check_hsm_flags $f "0x00000009"
2519 run_test 30c "Update during exec of released file must fail"
2521 restore_and_check_size() {
2524 local s=$(stat -c "%s" $f)
2526 local st=$(get_hsm_flags $f)
2530 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2532 n=$(stat -c "%s" $f)
2533 # we echo in both cases to show stat is not hang
2534 if [[ $n != $s ]]; then
2535 echo "size seen is $n != $s"
2538 echo "size seen is right: $n == $s"
2542 st=$(get_hsm_flags $f)
2544 if [[ "$st" = "0x00000009" ]]; then
2547 echo " restore is too long"
2548 wait_request_state $fid RESTORE SUCCEED
2554 # test needs a running copytool
2556 mkdir_on_mdt0 $DIR/$tdir
2558 create_archive_file $tdir/$tfile
2559 local f=$DIR/$tdir/$tfile
2560 copytool import $tdir/$tfile $f
2561 local fid=$($LFS path2fid $f)
2564 restore_and_check_size $f $fid
2567 [[ $err -eq 0 ]] || error "File size changed during restore"
2569 run_test 31a "Import a large file and check size during restore"
2573 # test needs a running copytool
2575 mkdir_on_mdt0 $DIR/$tdir
2577 local f=$DIR/$tdir/$tfile
2578 local fid=$(create_file "$f" 1MB 39)
2580 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2581 wait_request_state $fid ARCHIVE SUCCEED
2584 restore_and_check_size $f $fid
2587 [[ $err -eq 0 ]] || error "File size changed during restore"
2589 run_test 31b "Restore a large unaligned file and check size during restore"
2592 # test needs a running copytool
2594 mkdir_on_mdt0 $DIR/$tdir
2596 local f=$DIR/$tdir/$tfile
2597 local fid=$(create_file "$f" 1M 39)
2599 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2600 wait_request_state $fid ARCHIVE SUCCEED
2603 restore_and_check_size $f $fid
2606 [[ $err -eq 0 ]] || error "File size changed during restore"
2608 run_test 31c "Restore a large aligned file and check size during restore"
2611 local f=$DIR/$tdir/$tfile
2613 mkdir_on_mdt0 $DIR/$tdir
2614 local fid=$(create_empty_file "$f")
2618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2619 wait_request_state $fid ARCHIVE SUCCEED
2622 # Prevent restore from completing
2626 md5sum $f >/dev/null &
2629 wait_request_state $fid RESTORE STARTED
2634 # Check restore trigger process was killed
2636 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2638 run_test 33 "Kill a restore waiting process"
2641 # test needs a running copytool
2643 mkdir_on_mdt0 $DIR/$tdir
2645 local f=$DIR/$tdir/$tfile
2646 local fid=$(create_empty_file "$f")
2648 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2649 wait_request_state $fid ARCHIVE SUCCEED
2652 # Prevent restore from completing
2655 md5sum $f >/dev/null &
2658 wait_request_state $fid RESTORE STARTED
2660 # rm must not block during restore
2661 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2664 wait_request_state $fid RESTORE SUCCEED
2666 # Check md5sum pgm finished
2667 kill -0 $pid && error "Restore initiatior still running"
2668 wait $pid || error "Restore initiator failed with $?"
2670 # Check the file was actually deleted
2671 [ ! -f "$f" ] || error "$f was not deleted"
2673 run_test 34 "Remove file during restore"
2676 # test needs a running copytool
2678 mkdir_on_mdt0 $DIR/$tdir
2680 local f=$DIR/$tdir/$tfile
2681 local f1=$DIR/$tdir/$tfile-1
2682 local fid=$(create_empty_file "$f")
2683 local fid1=$(copy_file /etc/passwd $f1)
2685 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2686 wait_request_state $fid ARCHIVE SUCCEED
2689 # Prevent restore from completing
2692 md5sum $f >/dev/null &
2695 wait_request_state $fid RESTORE STARTED
2697 # mv must not block during restore
2698 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2701 wait_request_state $fid RESTORE SUCCEED
2703 # Check md5sum pgm finished
2704 kill -0 $pid && error "Restore initiatior still running"
2705 wait $pid || error "Restore initiator failed with $?"
2707 local fid2=$(path2fid $f)
2708 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2710 run_test 35 "Overwrite file during restore"
2713 # test needs a running copytool
2715 mkdir_on_mdt0 $DIR/$tdir
2717 local f=$DIR/$tdir/$tfile
2718 local fid=$(create_empty_file "$f")
2720 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2721 wait_request_state $fid ARCHIVE SUCCEED
2724 # Prevent restore from completing
2727 md5sum $f >/dev/null &
2730 wait_request_state $fid RESTORE STARTED
2732 # mv must not block during restore
2733 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2734 error "mv '$f' '$f.new' failed with rc=$?"
2737 wait_request_state $fid RESTORE SUCCEED
2739 # Check md5sum pgm finished
2740 kill -0 $pid && error "Restore initiator is still running"
2741 wait $pid || error "Restore initiator failed with $?"
2743 run_test 36 "Move file during restore"
2746 # LU-5683: check that an archived dirty file can be rearchived.
2748 mkdir_on_mdt0 $DIR/$tdir
2750 local f=$DIR/$tdir/$tfile
2753 fid=$(create_small_file $f) || error "cannot create small file"
2755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2756 wait_request_state $fid ARCHIVE SUCCEED
2757 $LFS hsm_release $f || error "cannot release $f"
2759 # Allow previous archive request to expire from the actions log.
2760 wait_for_grace_delay
2763 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2765 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2766 wait_request_state $fid ARCHIVE SUCCEED
2768 run_test 37 "re-archive a dirty file"
2775 for n in $(seq 1 $count); do
2776 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2778 echo "$count archive requests submitted"
2782 local stream_count=4
2783 local file_count=100
2785 local f=$DIR/$tdir/$tfile
2789 local max_requests=$(get_hsm_param max_requests)
2791 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2792 # Increase the number of HSM request that can be performed in
2793 # parallel. With the coordinator running once per second, this
2794 # also limits the number of requests per seconds that can be
2795 # performed, so we pick a decent number. But we also need to keep
2796 # that number low because the copytool has no rate limit and will
2797 # fail some requests if if gets too many at once.
2798 set_hsm_param max_requests 300
2800 for i in $(seq 1 $file_count); do
2801 for p in $(seq 1 $stream_count); do
2802 fid=$(copy_file /etc/hosts $f.$p.$i)
2808 # to be sure wait_all_done will not be mislead by previous tests
2810 wait_for_grace_delay
2812 # start archive streams in background (archive files in parallel)
2813 for p in $(seq 1 $stream_count); do
2814 multi_archive $f.$p $file_count &
2817 echo -n "Wait for all requests being enqueued..."
2822 run_test 40 "Parallel archive requests"
2824 hsm_archive_batch() {
2832 while [ $i -lt $files_num ]; do
2833 if [ $batch_num -eq $batch_max ]; then
2834 $LFS hsm_archive $fileset || error "HSM archive failed"
2835 # Reset the batch container.
2840 fileset+="${filebase}$i "
2841 batch_num=$(( batch_num + 1 ))
2845 if [ $batch_num -ne 0 ]; then
2846 $LFS hsm_archive $fileset || error "HSM archive failed"
2853 local dir=$DIR/$tdir
2856 set_hsm_param max_requests 1000000
2857 mkdir $dir || error "mkdir $dir failed"
2866 filebase="$dir/$tfile.start."
2867 createmany -m $filebase $files_num ||
2868 error "createmany -m $filebase failed: $?"
2871 hsm_archive_batch $files_num $batch_max "$filebase"
2872 elapsed=$((SECONDS - start))
2873 do_facet $SINGLEMDS "$LCTL get_param -n \
2874 $HSM_PARAM.actions | grep WAITING | wc -l"
2875 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2876 echo "Start Phase files_num: $files_num time: $elapsed"
2879 filebase="$dir/$tfile.in."
2880 createmany -m $filebase $files_num ||
2881 error "createmany -m $filebase failed: $?"
2883 hsm_archive_batch $files_num $batch_max "$filebase"
2884 elapsed=$((SECONDS - start))
2885 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2886 echo "Middle Phase files_num: $files_num time: $elapsed"
2889 filebase="$dir/$tfile.end."
2890 createmany -m $filebase $files_num ||
2891 error "createmany -m $filebase failed: $?"
2894 hsm_archive_batch $files_num $batch_max "$filebase"
2895 elapsed=$((SECONDS - start))
2896 do_facet $SINGLEMDS "$LCTL get_param -n \
2897 $HSM_PARAM.actions | grep WAITING | wc -l"
2899 unlinkmany $filebase $files_num || error "unlinkmany $filebase failed"
2900 echo "End Phase files_num: $files_num time: $elapsed"
2902 do_facet $SINGLEMDS "$LCTL get_param -n \
2903 $HSM_PARAM.actions | grep WAITING | wc -l"
2907 run_test 50 "Archive with large number of pending HSM actions"
2910 # test needs a running copytool
2913 mkdir_on_mdt0 $DIR/$tdir
2914 local f=$DIR/$tdir/$tfile
2915 local fid=$(create_small_file $f)
2917 $LFS hsm_archive $f || error "could not archive file"
2918 wait_request_state $fid ARCHIVE SUCCEED
2919 check_hsm_flags $f "0x00000009"
2921 multiop_bg_pause $f O_c || error "multiop failed"
2925 client_up || client_up || true
2927 kill -USR1 $MULTIPID
2928 wait $MULTIPID || error "multiop close failed"
2930 check_hsm_flags $f "0x0000000b"
2932 run_test 52 "Opened for write file on an evicted client should be set dirty"
2935 # test needs a running copytool
2938 mkdir_on_mdt0 $DIR/$tdir
2939 local f=$DIR/$tdir/$tfile
2940 local fid=$(create_small_file $f)
2942 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2943 error "could not archive file"
2944 wait_request_state $fid ARCHIVE SUCCEED
2945 check_hsm_flags $f "0x00000009"
2947 multiop_bg_pause $f o_c || error "multiop failed"
2951 client_up || client_up || true
2953 kill -USR1 $MULTIPID
2954 wait $MULTIPID || error "multiop close failed"
2956 check_hsm_flags $f "0x00000009"
2958 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2961 mkdir_on_mdt0 $DIR/$tdir
2963 local f=$DIR/$tdir/$tfile
2964 local fid=$(create_file "$f" 1MB 39)
2968 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2969 error "could not archive file"
2970 wait_request_state $fid ARCHIVE STARTED
2972 check_hsm_flags $f "0x00000001"
2974 stack_trap "cdt_clear_no_retry" EXIT
2975 # Avoid coordinator resending this request as soon it has failed.
2980 wait_request_state $fid ARCHIVE FAILED
2982 check_hsm_flags $f "0x00000003"
2984 run_test 54 "Write during an archive cancels it"
2987 mkdir_on_mdt0 $DIR/$tdir
2989 local f=$DIR/$tdir/$tfile
2990 local fid=$(create_file "$f" 1MB 39)
2994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2995 error "could not archive file"
2996 wait_request_state $fid ARCHIVE STARTED
2998 check_hsm_flags $f "0x00000001"
3000 stack_trap "cdt_clear_no_retry" EXIT
3001 # Avoid coordinator resending this request as soon it has failed.
3004 $TRUNCATE $f 1024 || error "truncate failed"
3006 wait_request_state $fid ARCHIVE FAILED
3008 check_hsm_flags $f "0x00000003"
3010 run_test 55 "Truncate during an archive cancels it"
3013 mkdir_on_mdt0 $DIR/$tdir
3015 local f=$DIR/$tdir/$tfile
3016 local fid=$(create_file "$f" 1MB 39)
3020 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3021 error "could not archive file"
3022 wait_request_state $fid ARCHIVE STARTED
3024 check_hsm_flags $f "0x00000001"
3026 # Change metadata and sync to be sure we are not changing only
3031 wait_request_state $fid ARCHIVE SUCCEED
3033 check_hsm_flags $f "0x00000009"
3035 run_test 56 "Setattr during an archive is ok"
3038 # Need one client for I/O, one for request
3039 needclients 2 || return 0
3041 # test needs a running copytool
3044 mkdir_on_mdt0 $DIR/$tdir
3045 local f=$DIR/$tdir/test_archive_remote
3046 # Create a file on a remote node
3047 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3048 "count=2 conv=fsync"
3051 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3052 error "hsm_archive failed"
3053 local fid=$(path2fid $f)
3054 wait_request_state $fid ARCHIVE SUCCEED
3056 # Release and implicit restore it
3057 do_node $CLIENT2 "$LFS hsm_release $f" ||
3058 error "hsm_release failed"
3059 do_node $CLIENT2 "md5sum $f" ||
3060 error "hsm_restore failed"
3062 wait_request_state $fid RESTORE SUCCEED
3064 run_test 57 "Archive a file with dirty cache on another node"
3066 truncate_released_file() {
3070 local sz=$(stat -c %s $src_file)
3071 local f=$DIR/$tdir/$tfile
3072 local fid=$(copy_file $1 $f)
3076 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3077 error "could not archive file"
3078 wait_request_state $fid ARCHIVE SUCCEED
3080 $LFS hsm_release $f || error "could not release file"
3082 $TRUNCATE $f $trunc_to || error "truncate failed"
3085 local sz1=$(stat -c %s $f)
3086 [[ $sz1 == $trunc_to ]] ||
3087 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3090 check_hsm_flags $f "0x0000000b"
3092 local state=$(get_request_state $fid RESTORE)
3093 [[ "$state" == "SUCCEED" ]] ||
3094 error "truncate $sz does not trig restore, state = $state"
3096 $TRUNCATE $ref $trunc_to
3097 cmp $ref $f || error "file data wrong after truncate"
3103 # test needs a running copytool
3106 mkdir_on_mdt0 $DIR/$tdir
3108 local sz=$(stat -c %s /etc/passwd)
3110 echo "truncate up from $sz to $((sz*2))"
3111 truncate_released_file /etc/passwd $((sz*2))
3113 echo "truncate down from $sz to $((sz/2))"
3114 truncate_released_file /etc/passwd $((sz/2))
3116 echo "truncate to 0"
3117 truncate_released_file /etc/passwd 0
3119 run_test 58 "Truncate a released file will trigger restore"
3123 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3124 skip "Need MDS version at least 2.7.63"
3127 $MCREATE $DIR/$tfile || error "mcreate failed"
3128 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3129 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3130 fid=$(path2fid $DIR/$tfile)
3131 wait_request_state $fid ARCHIVE SUCCEED
3132 $LFS hsm_release $DIR/$tfile || error "release failed"
3134 run_test 59 "Release stripeless file with non-zero size"
3137 # This test validates the fix for LU-4512. Ensure that the -u
3138 # option changes the progress reporting interval from the
3139 # default (30 seconds) to the user-specified interval.
3140 mkdir_on_mdt0 $DIR/$tdir
3142 local f=$DIR/$tdir/$tfile
3143 local fid=$(create_file "$f" 1M 10)
3146 local progress_timeout=$((interval * 4))
3147 copytool setup -b 1 --update-interval $interval
3150 local mdt=${MDT_PREFIX}${mdtidx}
3151 local mds=mds$((mdtidx + 1))
3153 # Wait for copytool to register
3154 wait_update_facet $mds \
3155 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3156 uuid 100 || error "coyptool failed to register with $mdt"
3158 local start_at=$(date +%s)
3159 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3160 error "could not archive file"
3162 local agent=$(facet_active_host $SINGLEAGT)
3163 local logfile=$(copytool_logfile $SINGLEAGT)
3165 wait_update $agent \
3166 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3167 error "copytool failed to start"
3169 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3170 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3176 echo -n "Expecting a progress update within $progress_timeout seconds... "
3178 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3179 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3180 echo "$RESULT bytes copied in $WAIT seconds."
3182 elif [ $WAIT -ge $progress_timeout ]; then
3183 error "Timed out waiting for progress update!"
3186 WAIT=$((WAIT + sleep))
3190 local finish_at=$(date +%s)
3191 local elapsed=$((finish_at - start_at))
3193 # Ensure that the progress update occurred within the expected window.
3194 if [ $elapsed -lt $((interval - 1)) ]; then
3195 error "Expected progress update after at least $interval seconds"
3198 echo "Wait for on going archive hsm action to complete"
3199 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3200 echo "File archiving not completed even after 10 secs"
3202 run_test 60 "Changing progress update interval from default"
3205 # test needs a running copytool
3208 mkdir_on_mdt0 $DIR/$tdir
3209 local f=$DIR/$tdir/$tfile
3210 local fid=$(copy_file /etc/passwd $f)
3212 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3215 wait_request_state $fid ARCHIVE FAILED
3217 run_test 61 "Waiting archive of a removed file should fail"
3220 # test needs a new running copytool
3221 stack_trap copytool_monitor_cleanup EXIT
3222 copytool_monitor_setup
3223 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3225 # Wait for the copytool to register.
3226 wait_update --verbose $(facet_active_host mds1) \
3227 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3229 error "copytool failed to register with MDT0000"
3232 wait_copytools || error "Copytools failed to stop"
3234 local REGISTER_EVENT
3235 local UNREGISTER_EVENT
3236 while read event; do
3237 local parsed=$(parse_json_event "$event")
3238 if [ -z "$parsed" ]; then
3239 error "Copytool sent malformed event: $event"
3243 if [ $event_type == "REGISTER" ]; then
3244 REGISTER_EVENT=$event
3245 elif [ $event_type == "UNREGISTER" ]; then
3246 UNREGISTER_EVENT=$event
3248 done < <(echo $"$(get_copytool_event_log)")
3250 if [ -z "$REGISTER_EVENT" ]; then
3251 error "Copytool failed to send register event to FIFO"
3254 if [ -z "$UNREGISTER_EVENT" ]; then
3255 error "Copytool failed to send unregister event to FIFO"
3258 echo "Register/Unregister events look OK."
3260 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3263 # Bump progress interval for livelier events.
3266 # test needs a new running copytool
3267 stack_trap copytool_monitor_cleanup EXIT
3268 copytool_monitor_setup
3269 copytool setup --update-interval $interval --event-fifo \
3270 "$HSMTOOL_MONITOR_DIR/fifo"
3272 stack_trap "cdt_clear_no_retry" EXIT
3273 # Just start and stop the copytool to generate events.
3276 mkdir_on_mdt0 $DIR/$tdir
3278 local f=$DIR/$tdir/$tfile
3279 local fid=$(create_small_file "$f")
3281 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3282 error "could not archive file"
3283 wait_request_state $fid ARCHIVE SUCCEED
3285 local expected_fields="event_time data_fid source_fid"
3286 expected_fields+=" total_bytes current_bytes"
3289 [ARCHIVE_START]=false
3290 [ARCHIVE_FINISH]=false
3291 [ARCHIVE_RUNNING]=false
3293 while read event; do
3294 # Make sure we're not getting anything from previous events.
3295 for field in $expected_fields; do
3299 local parsed=$(parse_json_event "$event")
3300 if [ -z "$parsed" ]; then
3301 error "Copytool sent malformed event: $event"
3305 events["$event_type"]=true
3307 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3309 # Do some simple checking of the progress update events.
3310 for expected_field in $expected_fields; do
3311 if [ -z ${!expected_field+x} ]; then
3312 error "Missing $expected_field field in event"
3316 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3318 # These should be identical throughout an archive operation
3319 [ $source_fid == $data_fid ] ||
3320 error "Expected source_fid to equal data_fid"
3321 done < <(echo $"$(get_copytool_event_log)")
3323 # Check we received every type of events we were expecting
3324 for event in "${!events[@]}"; do
3325 ${events["$event"]} ||
3326 error "Copytool failed to send '$event' event to FIFO"
3329 echo "Archive events look OK."
3331 run_test 71 "Copytool logs JSON archive events to FIFO"
3334 # Bump progress interval for livelier events.
3337 # test needs a new running copytool
3338 stack_trap copytool_monitor_cleanup EXIT
3339 copytool_monitor_setup
3340 copytool setup --update-interval $interval --event-fifo \
3341 "$HSMTOOL_MONITOR_DIR/fifo"
3342 local test_file=$HSMTOOL_MONITOR_DIR/file
3344 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3346 do_facet $SINGLEAGT "$cmd" ||
3347 error "cannot create $test_file on $SINGLEAGT"
3348 copy2archive $test_file $tdir/$tfile
3350 mkdir_on_mdt0 $DIR/$tdir
3351 local f=$DIR/$tdir/$tfile
3352 copytool import $tdir/$tfile $f
3353 f=$DIR2/$tdir/$tfile
3354 echo "Verifying released state: "
3355 check_hsm_flags $f "0x0000000d"
3357 local fid=$(path2fid $f)
3359 wait_request_state $fid RESTORE SUCCEED
3361 local expected_fields="event_time data_fid source_fid"
3362 expected_fields+=" total_bytes current_bytes"
3366 while read event; do
3367 # Make sure we're not getting anything from previous events.
3368 for field in $expected_fields; do
3372 local parsed=$(parse_json_event "$event")
3373 if [ -z "$parsed" ]; then
3374 error "Copytool sent malformed event: $event"
3378 if [ $event_type == "RESTORE_START" ]; then
3380 if [ $source_fid != $data_fid ]; then
3381 error "source_fid should == data_fid at start"
3384 elif [ $event_type == "RESTORE_FINISH" ]; then
3386 if [ $source_fid != $data_fid ]; then
3387 error "source_fid should == data_fid at finish"
3390 elif [ $event_type != "RESTORE_RUNNING" ]; then
3394 # Do some simple checking of the progress update events.
3395 for expected_field in $expected_fields; do
3396 if [ -z ${!expected_field+x} ]; then
3397 error "Missing $expected_field field in event"
3401 if [ $total_bytes -eq 0 ]; then
3402 error "Expected total_bytes to be > 0"
3405 # When a restore starts out, the data fid is the same as the
3406 # source fid. After the restore has gotten going, we learn
3407 # the new data fid. Once the restore has finished, the source
3408 # fid is set to the new data fid.
3410 # We test this because some monitoring software may depend on
3411 # this behavior. If it changes, then the consumers of these
3412 # events may need to be modified.
3413 if [ $source_fid == $data_fid ]; then
3414 error "source_fid should != data_fid during restore"
3416 done < <(echo $"$(get_copytool_event_log)")
3418 if [ -z "$START_EVENT" ]; then
3419 error "Copytool failed to send restore start event to FIFO"
3422 if [ -z "$FINISH_EVENT" ]; then
3423 error "Copytool failed to send restore finish event to FIFO"
3426 echo "Restore events look OK."
3428 run_test 72 "Copytool logs JSON restore events to FIFO"
3431 file_count=51 # Max number of files constrained by LNET message size
3432 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3433 local f=$DIR/$tdir/$tfile
3434 local FILELIST=/tmp/filelist.txt
3438 for i in $(seq 1 $file_count); do
3439 fid=$(copy_file /etc/hosts $f.$i)
3440 echo $f.$i >> $FILELIST
3444 # to be sure wait_all_done will not be mislead by previous tests
3446 wait_for_grace_delay
3447 $LFS hsm_archive --filelist $FILELIST ||
3448 error "cannot archive a file list"
3450 $LFS hsm_release --filelist $FILELIST ||
3451 error "cannot release a file list"
3452 $LFS hsm_restore --filelist $FILELIST ||
3453 error "cannot restore a file list"
3456 run_test 90 "Archive/restore a file list"
3458 double_verify_reset_hsm_param() {
3460 echo "Testing $HSM_PARAM.$p"
3461 local val=$(get_hsm_param $p)
3463 local val2=$(($val * 2))
3464 set_hsm_param $p $val2
3465 val=$(get_hsm_param $p)
3466 [[ $val == $val2 ]] ||
3467 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3468 echo "Set $p to 0 must failed"
3472 set_hsm_param $p $save
3474 if [[ $rc == 0 ]]; then
3475 error "we must not be able to set $HSM_PARAM.$p to 0"
3480 double_verify_reset_hsm_param loop_period
3481 double_verify_reset_hsm_param grace_delay
3482 double_verify_reset_hsm_param active_request_timeout
3483 double_verify_reset_hsm_param max_requests
3484 double_verify_reset_hsm_param default_archive_id
3486 run_test 100 "Set coordinator /proc tunables"
3493 run_test 102 "Verify coordinator control"
3496 # test needs a running copytool
3503 for i in $(seq 1 20); do
3504 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3506 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3510 echo "Current requests"
3511 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3512 $HSM_PARAM.actions |\
3513 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3515 [[ -z "$res" ]] || error "Some request have not been canceled"
3517 run_test 103 "Purge all requests"
3520 (( MDS1_VERSION >= $(version_code 2.14.56) )) ||
3521 skip "Need MDS version at least 2.14.56"
3523 cdt_clear_non_blocking_restore
3525 # test needs a running copytool
3530 local rpcs_inflight=$($LCTL get_param -n \
3531 "mdc.$(facet_svc mds1)*.max_rpcs_in_flight" |
3534 mkdir_on_mdt0 $DIR/$tdir
3535 for ((i=0; i < rpcs_inflight; i++)); do
3536 fids+=( $(copy_file /etc/passwd $DIR/$tdir/${tfile}_$i) )
3538 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3542 local grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=ARCHIVE.*status=SUCCEED"
3544 while [[ $time -lt 5 ]] && [[ $cnt -ne ${#fids[@]} ]]; do
3545 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3546 grep -c -E '$grep_regex'")
3550 [[ $cnt -eq ${#fids[@]} ]] || error "Fail to archive files $cnt/${#fids[@]}"
3552 $LFS hsm_release $DIR/$tdir/*
3555 wait_copytools || error "Copytool failed to stop"
3558 for i in "${fids[@]}"; do
3559 cat $DIR/.lustre/fid/$i > /dev/null & pids+=($!)
3563 grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=RESTORE.*status=CANCELED"
3564 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3565 grep -cE '$grep_regex'")
3567 [[ "$cnt" -eq ${#fids[@]} ]] ||
3568 error "Some request have not been canceled ($cnt/${#fids[@]} canceled)"
3570 # cat cmds should not hang and should fail
3571 for i in "${!pids[@]}"; do
3573 error "Restore for ${tfile}_$i (${pids[$i]}) should fail" ||
3577 run_test 103a "Purge pending restore requests"
3582 mkdir_on_mdt0 $DIR/$tdir
3584 local f=$DIR/$tdir/$tfile
3585 local fid=$(create_empty_file "$f")
3587 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3588 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3589 $HSM_PARAM.actions |\
3590 grep $fid | cut -f16 -d=")
3592 [[ "$data1" == "$DATAHEX" ]] ||
3593 error "Data field in records is ($data1) and not ($DATAHEX)"
3597 run_test 104 "Copy tool data field"
3600 local max_requests=$(get_hsm_param max_requests)
3601 mkdir_on_mdt0 $DIR/$tdir
3604 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3605 set_hsm_param max_requests 300
3608 for i in $(seq -w 1 10); do
3609 cp /etc/passwd $DIR/$tdir/$i
3610 $LFS hsm_archive $DIR/$tdir/$i
3612 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3613 $HSM_PARAM.actions |\
3614 grep WAITING | wc -l")
3618 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3619 $HSM_PARAM.actions |\
3620 grep WAITING | wc -l")
3623 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3624 error "Requests count after shutdown $reqcnt2 != "\
3625 "before shutdown $reqcnt1"
3627 run_test 105 "Restart of coordinator"
3630 # test needs a running copytool
3633 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3635 check_agent_registered $uuid
3637 search_copytools || error "No copytool found"
3640 wait_copytools || error "Copytool failed to stop"
3642 check_agent_unregistered $uuid
3645 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3646 check_agent_registered $uuid
3648 run_test 106 "Copytool register/unregister"
3651 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3653 # test needs a running copytool
3655 # create and archive file
3656 mkdir_on_mdt0 $DIR/$tdir
3657 local f1=$DIR/$tdir/$tfile
3658 local fid=$(copy_file /etc/passwd $f1)
3659 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3660 wait_request_state $fid ARCHIVE SUCCEED
3661 # shutdown and restart MDS
3663 # check the copytool still gets messages from MDT
3664 local f2=$DIR/$tdir/2
3665 local fid=$(copy_file /etc/passwd $f2)
3666 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3667 # main check of this sanity: this request MUST succeed
3668 wait_request_state $fid ARCHIVE SUCCEED
3670 run_test 107 "Copytool re-register after MDS restart"
3672 policy_set_and_test()
3676 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3677 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3678 [[ "$policy" == "$target" ]] ||
3679 error "Wrong policy after '$change': '$policy' != '$target'"
3683 # to force default policy setting if error
3684 CDT_POLICY_HAD_CHANGED=true
3686 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3687 local default="NonBlockingRestore [NoRetryAction]"
3688 [[ "$policy" == "$default" ]] ||
3689 error "default policy has changed,"\
3690 " '$policy' != '$default' update the test"
3691 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3692 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3693 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3694 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3695 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3696 # useless bacause we know but safer for futur changes to use real value
3697 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3698 echo "Next set_param must failed"
3699 policy_set_and_test "wrong" "$policy"
3702 echo "Back to default policy"
3703 cdt_set_sanity_policy
3705 run_test 109 "Policy display/change"
3708 # test needs a running copytool
3711 mkdir_on_mdt0 $DIR/$tdir
3713 copy2archive /etc/passwd $tdir/$tfile
3715 local f=$DIR/$tdir/$tfile
3716 copytool import $tdir/$tfile $f
3717 local fid=$(path2fid $f)
3719 cdt_set_non_blocking_restore
3724 wait_request_state $fid RESTORE SUCCEED
3725 cdt_clear_non_blocking_restore
3729 error "md5sum returns $st != 1, "\
3730 "should also perror ENODATA (No data available)"
3732 run_test 110a "Non blocking restore policy (import case)"
3735 # test needs a running copytool
3738 mkdir_on_mdt0 $DIR/$tdir
3739 local f=$DIR/$tdir/$tfile
3740 local fid=$(copy_file /etc/passwd $f)
3741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3742 wait_request_state $fid ARCHIVE SUCCEED
3745 cdt_set_non_blocking_restore
3750 wait_request_state $fid RESTORE SUCCEED
3751 cdt_clear_non_blocking_restore
3755 error "md5sum returns $st != 1, "\
3756 "should also perror ENODATA (No data available)"
3758 run_test 110b "Non blocking restore policy (release case)"
3761 # test needs a running copytool
3764 mkdir_on_mdt0 $DIR/$tdir
3765 copy2archive /etc/passwd $tdir/$tfile
3767 local f=$DIR/$tdir/$tfile
3769 copytool import $tdir/$tfile $f
3770 local fid=$(path2fid $f)
3774 copytool_remove_backend $fid
3777 wait_request_state $fid RESTORE FAILED
3784 [[ $st == 0 ]] || error "Restore does not failed"
3786 run_test 111a "No retry policy (import case), restore will error"\
3787 " (No such file or directory)"
3790 # test needs a running copytool
3793 mkdir_on_mdt0 $DIR/$tdir
3794 local f=$DIR/$tdir/$tfile
3795 local fid=$(copy_file /etc/passwd $f)
3796 stack_trap cdt_clear_no_retry EXIT
3798 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3799 wait_request_state $fid ARCHIVE SUCCEED
3802 copytool_remove_backend $fid
3805 wait_request_state $fid RESTORE FAILED
3809 [[ $st == 0 ]] || error "Restore does not failed"
3811 run_test 111b "No retry policy (release case), restore will error"\
3812 " (No such file or directory)"
3815 # test needs a running copytool
3818 mkdir_on_mdt0 $DIR/$tdir
3819 local f=$DIR/$tdir/$tfile
3820 local fid=$(copy_file /etc/passwd $f)
3822 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3823 local l=$($LFS hsm_action $f)
3825 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3828 wait_request_state $fid ARCHIVE SUCCEED
3831 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3833 run_test 112 "State of recorded request"
3836 mkdir_on_mdt0 $DIR/$tdir
3838 local file1=$DIR/$tdir/$tfile
3839 local file2=$DIR2/$tdir/$tfile
3841 local fid=$(create_small_sync_file $file1)
3843 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3844 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3845 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3847 copytool setup -m "$MOUNT3"
3849 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3851 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3852 wait_request_state $fid ARCHIVE SUCCEED
3854 $LFS hsm_release $file1
3855 echo "Verifying released state: "
3856 check_hsm_flags $file1 "0x0000000d"
3858 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3861 kill -USR1 $MULTIPID
3866 local size1=$(stat -c "%s" $file1)
3867 local size2=$(stat -c "%s" $file2)
3869 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3871 run_test 113 "wrong stat after restore"
3874 mkdir_on_mdt0 $DIR/$tdir
3876 local f=$DIR/$tdir/$tfile
3877 local fid=$(create_empty_file "$f")
3881 # Prevent archive from completing
3884 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3885 # wait archive to register at CDT
3886 wait_request_state $fid ARCHIVE STARTED
3888 # Cancel the archive
3889 $LFS hsm_cancel "$f"
3891 wait_request_state $fid ARCHIVE CANCELED
3894 wait_request_state $fid CANCEL SUCCEED
3896 run_test 200 "Register/Cancel archive"
3899 # test needs a running copytool
3901 mkdir_on_mdt0 $DIR/$tdir
3903 local f=$DIR/$tdir/$tfile
3904 create_archive_file $tdir/$tfile
3905 copytool import $tdir/$tfile $f
3906 local fid=$(path2fid $f)
3908 # test with cdt on is made in test_222
3911 # wait restore to register at CDT
3912 wait_request_state $fid RESTORE WAITING
3915 wait_request_state $fid RESTORE CANCELED
3916 wait_request_state $fid CANCEL SUCCEED
3918 run_test 201 "Register/Cancel restore"
3921 mkdir_on_mdt0 $DIR/$tdir
3923 local f=$DIR/$tdir/$tfile
3924 local fid=$(create_empty_file "$f")
3926 # test needs a running copytool
3929 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3930 wait_request_state $fid ARCHIVE SUCCEED
3934 # wait remove to register at CDT
3935 wait_request_state $fid REMOVE STARTED
3938 wait_request_state $fid REMOVE CANCELED
3940 run_test 202 "Register/Cancel remove"
3942 test_220A() { # was test_220
3943 # test needs a running copytool
3946 mkdir_on_mdt0 $DIR/$tdir
3948 local f=$DIR/$tdir/$tfile
3949 local fid=$(copy_file /etc/passwd $f)
3953 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3954 wait_request_state $fid ARCHIVE SUCCEED
3956 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3957 error "The expected changelog was not emitted"
3959 run_test 220A "Changelog for archive"
3962 # test needs a running copytool
3965 mkdir_on_mdt0 $DIR/$tdir
3967 local f=$DIR/$tdir/$tfile
3968 local fid=$(copy_file /etc/passwd $f)
3972 # block copytool operations to allow for HSM request to be
3973 # submitted and file be unlinked (CDT will find object removed)
3976 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3978 # wait request to reach CT
3979 wait_request_state $fid ARCHIVE STARTED
3985 wait_request_state $fid ARCHIVE FAILED
3988 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3989 error "The expected changelog was not emitted"
3991 run_test 220a "Changelog for failed archive"
3994 mkdir_on_mdt0 $DIR/$tdir
3996 local f=$DIR/$tdir/$tfile
3997 local fid=$(create_empty_file "$f")
4002 # Prevent archive from completing
4004 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4005 wait_request_state $fid ARCHIVE STARTED
4008 wait_request_state $fid ARCHIVE CANCELED
4011 wait_request_state $fid CANCEL SUCCEED
4013 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4014 error "The expected changelog was not emitted"
4016 run_test 221 "Changelog for archive canceled"
4019 # test needs a running copytool
4022 mkdir_on_mdt0 $DIR/$tdir
4023 copy2archive /etc/passwd $tdir/$tfile
4025 local f=$DIR/$tdir/$tfile
4026 copytool import $tdir/$tfile $f
4027 local fid=$(path2fid $f)
4032 wait_request_state $fid RESTORE SUCCEED
4034 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4035 error "The expected changelog was not emitted"
4037 run_test 222a "Changelog for explicit restore"
4040 # test needs a running copytool
4043 mkdir_on_mdt0 $DIR/$tdir
4044 local f=$DIR/$tdir/$tfile
4045 local fid=$(copy_file /etc/passwd $f)
4048 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4049 wait_request_state $fid ARCHIVE SUCCEED
4054 wait_request_state $fid RESTORE SUCCEED
4056 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4057 error "The expected changelog was not emitted"
4059 run_test 222b "Changelog for implicit restore"
4062 # test needs a running copytool
4065 mkdir_on_mdt0 $DIR/$tdir
4066 copy2archive /etc/passwd $tdir/$tfile
4068 local f=$DIR/$tdir/$tfile
4069 copytool import $tdir/$tfile $f
4070 local fid=$(path2fid $f)
4074 # block copytool operations to allow for HSM request to be
4075 # submitted and file be unlinked (CDT will find object removed)
4080 # wait request to reach CT
4081 wait_request_state $fid RESTORE STARTED
4087 wait_request_state $fid RESTORE FAILED
4090 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4091 error "The expected changelog was not emitted"
4093 run_test 222c "Changelog for failed explicit restore"
4096 # test needs a running copytool
4099 mkdir_on_mdt0 $DIR/$tdir
4100 local f=$DIR/$tdir/$tfile
4101 local fid=$(copy_file /etc/passwd $f)
4104 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4105 wait_request_state $fid ARCHIVE SUCCEED
4108 copytool_remove_backend $fid
4111 wait_request_state $fid RESTORE FAILED
4114 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4115 error "The expected changelog was not emitted"
4117 run_test 222d "Changelog for failed implicit restore"
4120 # test needs a running copytool
4122 mkdir_on_mdt0 $DIR/$tdir
4124 local f=$DIR/$tdir/$tfile
4125 create_archive_file $tdir/$tfile
4129 copytool import $tdir/$tfile $f
4130 local fid=$(path2fid $f)
4133 wait_request_state $fid RESTORE STARTED
4135 wait_request_state $fid RESTORE CANCELED
4136 wait_request_state $fid CANCEL SUCCEED
4138 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4139 error "The expected changelog was not emitted"
4141 run_test 223a "Changelog for restore canceled (import case)"
4144 mkdir_on_mdt0 $DIR/$tdir
4146 local f=$DIR/$tdir/$tfile
4147 local fid=$(create_empty_file "$f")
4152 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4153 wait_request_state $fid ARCHIVE SUCCEED
4156 # Prevent restore from completing
4159 wait_request_state $fid RESTORE STARTED
4162 wait_request_state $fid RESTORE CANCELED
4165 wait_request_state $fid CANCEL SUCCEED
4167 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4168 error "The expected changelog was not emitted"
4170 run_test 223b "Changelog for restore canceled (release case)"
4172 test_224A() { # was test_224
4173 # test needs a running copytool
4176 mkdir_on_mdt0 $DIR/$tdir
4178 local f=$DIR/$tdir/$tfile
4179 local fid=$(copy_file /etc/passwd $f)
4182 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4183 wait_request_state $fid ARCHIVE SUCCEED
4186 wait_request_state $fid REMOVE SUCCEED
4188 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4189 error "The expected changelog was not emitted"
4191 run_test 224A "Changelog for remove"
4194 # test needs a running copytool
4197 mkdir_on_mdt0 $DIR/$tdir
4199 local f=$DIR/$tdir/$tfile
4200 local fid=$(copy_file /etc/passwd $f)
4203 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4204 wait_request_state $fid ARCHIVE SUCCEED
4206 copytool_remove_backend $fid
4208 # block copytool operations to allow for HSM request to be
4209 # submitted and file be unlinked (CDT will find object removed)
4214 # wait for request to reach CT
4215 wait_request_state $fid REMOVE STARTED
4221 wait_request_state $fid REMOVE FAILED
4223 # HE_REMOVE|ENOENT=0x202
4224 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4225 error "The expected changelog was not emitted"
4227 run_test 224a "Changelog for failed remove"
4230 # test is not usable because remove request is too fast
4231 # so it is always finished before cancel can be done ...
4232 echo "Test disabled"
4235 # test needs a running copytool
4237 mkdir_on_mdt0 $DIR/$tdir
4239 local f=$DIR/$tdir/$tfile
4240 local fid=$(create_empty_file "$f")
4243 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4244 wait_request_state $fid ARCHIVE SUCCEED
4246 # Prevent restore from completing
4251 wait_request_state $fid REMOVE CANCELED
4254 wait_request_state $fid CANCEL SUCCEED
4256 changelog_find -type HSM -target-fid $fid -flags 0x27d
4257 error "The expected changelog was not emitted"
4259 run_test 225 "Changelog for remove canceled"
4262 # test needs a running copytool
4265 mkdir_on_mdt0 $DIR/$tdir
4267 local f1=$DIR/$tdir/$tfile-1
4268 local f2=$DIR/$tdir/$tfile-2
4269 local f3=$DIR/$tdir/$tfile-3
4270 local fid1=$(copy_file /etc/passwd $f1)
4271 local fid2=$(copy_file /etc/passwd $f2)
4272 copy_file /etc/passwd $f3
4275 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4276 wait_request_state $fid1 ARCHIVE SUCCEED
4278 $LFS hsm_archive $f2
4279 wait_request_state $fid2 ARCHIVE SUCCEED
4281 rm $f1 || error "rm $f1 failed"
4284 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4285 error "The expected changelog was not emitted"
4287 mv $f3 $f2 || error "mv $f3 $f2 failed"
4289 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4290 error "The expected changelog was not emitted"
4292 run_test 226 "changelog for last rm/mv with exiting archive"
4294 # This is just a utility function to clarify what test_227 does
4299 "$LFS" "$action" --$flag "$file" ||
4300 error "Cannot ${action#hsm_} $flag on '$file'"
4302 # Only one changelog should be produced
4303 local entries="$(changelog_find -type HSM -target-fid $fid)"
4304 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4305 error "lfs $action --$flag '$file' produced more than one" \
4308 # Parse the last changelog record
4309 local entry="$(tail -n 1 <<< "$entries")"
4310 eval local -A changelog=$(changelog2array $entry)
4312 # Also check the flags match what is expected
4313 [[ ${changelog[flags]} == $target ]] ||
4314 error "Changelog flag is '${changelog[flags]}', not $target"
4318 local file="$DIR/$tdir/$tfile"
4319 local fid=$(create_empty_file "$file")
4324 for flag in norelease noarchive exists archived lost; do
4325 if [ "$flag" == lost ]; then
4326 # The flag "lost" only works on an archived file
4327 "$LFS" hsm_set --archived "$file"
4331 action="hsm_set" __test_227
4332 action="hsm_clear" __test_227
4335 run_test 227 "changelog when explicit setting of HSM flags"
4338 # test needs a running copytool
4340 mkdir_on_mdt0 $DIR/$tdir
4342 local fid=$(create_small_sync_file $DIR/$tfile)
4343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4344 wait_request_state $fid ARCHIVE SUCCEED
4346 $LFS hsm_release $DIR/$tfile
4347 check_hsm_flags $DIR/$tfile "0x0000000d"
4349 filefrag $DIR/$tfile | grep " 1 extent found" ||
4350 error "filefrag on released file must return only one extent"
4352 # only newer versions of cp detect sparse files by stat/FIEMAP
4354 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4355 error "copying $DIR/$tfile"
4356 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4358 $LFS hsm_release $DIR/$tfile
4359 check_hsm_flags $DIR/$tfile "0x0000000d"
4361 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4363 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4365 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4366 error "comparing untarred $DIR/$tfile"
4368 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4369 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4371 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4374 local file="$DIR/$tdir/$tfile"
4376 # set max_requests to allow one request of each type to be started (3)
4378 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4379 set_hsm_param max_requests 3
4382 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4383 set_hsm_param loop_period 1
4385 # send 1 requests of each kind twice
4388 mkdir_on_mdt0 $DIR/$tdir
4391 for action in archive restore remove; do
4392 local filepath="$file"-to-$action
4393 local fid=$(create_empty_file "$filepath")
4394 local fid2=$(create_empty_file "$filepath".bis)
4396 if [ "$action" != archive ]; then
4397 "$LFS" hsm_archive "$filepath"
4398 wait_request_state $fid ARCHIVE SUCCEED
4399 "$LFS" hsm_archive "$filepath".bis
4400 wait_request_state $fid2 ARCHIVE SUCCEED
4402 if [ "$action" == restore ]; then
4403 "$LFS" hsm_release "$filepath"
4404 "$LFS" hsm_release "$filepath".bis
4408 # suspend the copytool to prevent requests from completing
4409 stack_trap "copytool_continue" EXIT
4412 # send `max_requests' requests (one of each kind)
4413 for action in archive restore remove; do
4414 filepath="$file"-to-$action
4415 "$LFS" hsm_${action} "$filepath"
4416 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4419 # send another batch of requests
4420 for action in archive restore remove; do
4421 "$LFS" hsm_${action} "$file-to-$action".bis
4423 # wait for `loop_period' seconds to make sure the coordinator has time
4424 # to register those, even though it should not
4427 # only the first batch of request should be started
4429 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4433 error "expected 3 STARTED requests, found $count"
4435 run_test 250 "Coordinator max request"
4438 mkdir_on_mdt0 $DIR/$tdir
4440 local f=$DIR/$tdir/$tfile
4441 local fid=$(create_empty_file "$f")
4444 # to have a short test
4445 local old_to=$(get_hsm_param active_request_timeout)
4446 set_hsm_param active_request_timeout 1
4447 # to be sure the cdt will wake up frequently so
4448 # it will be able to cancel the "old" request
4449 local old_loop=$(get_hsm_param loop_period)
4450 set_hsm_param loop_period 1
4455 # Prevent archive from completing
4457 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4458 wait_request_state $fid ARCHIVE STARTED
4460 # Let the request timeout
4461 wait_request_state $fid ARCHIVE CANCELED
4463 set_hsm_param active_request_timeout $old_to
4464 set_hsm_param loop_period $old_loop
4466 run_test 251 "Coordinator request timeout"
4469 mkdir_on_mdt0 $DIR/$tdir
4471 local f=$DIR/$tdir/$tfile
4472 local fid=$(create_empty_file "$f")
4474 # to have a short test
4475 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4476 set_hsm_param loop_period 1
4480 # Prevent archive from completing
4482 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4483 wait_request_state $fid ARCHIVE STARTED
4486 stack_trap "set_hsm_param active_request_timeout \
4487 $(get_hsm_param active_request_timeout)" EXIT
4488 set_hsm_param active_request_timeout 1
4490 wait_request_state $fid ARCHIVE CANCELED
4493 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4497 # test needs a running copytool
4500 mkdir_on_mdt0 $DIR/$tdir
4501 local f=$DIR/$tdir/$tfile
4503 dd if=/dev/zero of=$f bs=1MB count=10
4504 local fid=$(path2fid $f)
4506 $LFS hsm_archive $f || error "could not archive file"
4507 wait_request_state $fid ARCHIVE SUCCEED
4509 # clear locks to discard inode data
4510 cancel_lru_locks osc
4512 #define OBD_FAIL_MDC_MERGE 0x807
4513 $LCTL set_param fail_loc=0x807
4515 #expect error here, instead of release with wrong size
4518 if ((rc == 0)); then
4519 file_size=$(stat -c '%s' $f)
4520 if ((file_size != 10485760)); then
4521 error "Wrong file size after hsm_release"
4524 echo "could not release file"
4527 run_test 253 "Check for wrong file size after release"
4531 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4532 skip "need MDS version at least 2.10.56"
4534 # Check that the counters are initialized to 0
4536 for request_type in archive restore remove; do
4537 count="$(get_hsm_param ${request_type}_count)" ||
4538 error "Reading ${request_type}_count failed with $?"
4540 [ "$count" -eq 0 ] ||
4541 error "Expected ${request_type}_count to be " \
4545 run_test 254a "Request counters are initialized to zero"
4549 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4550 skip "need MDS version at least 2.10.56"
4552 # The number of request to launch (at least 32)
4553 local request_count=$((RANDOM % 32 + 32))
4554 printf "Will launch %i requests of each type\n" "$request_count"
4556 # Launch a copytool to process requests
4559 # Set hsm.max_requests to allow starting all requests at the same time
4561 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4562 set_hsm_param max_requests "$request_count"
4564 mkdir_on_mdt0 $DIR/$tdir
4568 for request_type in archive restore remove; do
4569 printf "Checking %s requests\n" "${request_type}"
4570 # Suspend the copytool to give us time to read the proc files
4573 for ((i = 0; i < $request_count; i++)); do
4574 case $request_type in
4576 create_empty_file "$DIR/$tdir/$tfile-$i" \
4580 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4583 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4586 # Give the coordinator 10 seconds to start every request
4588 while get_hsm_param actions | grep -q WAITING; do
4591 [ $timeout -gt 0 ] ||
4592 error "${request_type^} requests took too " \
4596 count="$(get_hsm_param ${request_type}_count)"
4597 [ "$count" -eq "$request_count" ] ||
4598 error "Expected '$request_count' (!= '$count') " \
4599 "active $request_type requests"
4601 # Let the copytool process the requests
4603 # Give it 10 seconds maximum
4605 while get_hsm_param actions | grep -q STARTED; do
4608 [ $timeout -gt 0 ] ||
4609 error "${request_type^} requests took too " \
4613 count="$(get_hsm_param ${request_type}_count)"
4614 [ "$count" -eq 0 ] ||
4615 error "Expected 0 (!= '$count') " \
4616 "active $request_type requests"
4619 run_test 254b "Request counters are correctly incremented and decremented"
4623 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4624 skip "Need MDS version at least 2.12.0"
4626 mkdir_on_mdt0 $DIR/$tdir
4628 local file="$DIR/$tdir/$tfile"
4629 local fid=$(create_empty_file "$file")
4631 # How do you make sure the coordinator has consumed any outstanding
4632 # event, without triggering an event yourself?
4634 # You wait for a request to disappear from the coordinator's llog.
4636 # Warning: the setup represents 90% of this test
4638 # Create and process an HSM request
4640 "$LFS" hsm_archive "$file"
4641 wait_request_state $fid ARCHIVE SUCCEED
4644 wait_copytools || error "failed to stop copytools"
4646 # Launch a new HSM request
4648 create_empty_file "$file"
4649 "$LFS" hsm_archive "$file"
4653 # Have the completed request be removed as soon as the cdt wakes up
4654 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4655 set_hsm_param grace_delay 1
4656 # (Hopefully, time on the MDS will behave nicely)
4657 do_facet $SINGLEMDS sleep 2 &
4659 # Increase `loop_period' as a mean to prevent the coordinator from
4660 # waking itself up to do some housekeeping.
4661 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4662 set_hsm_param loop_period 1000
4664 wait $! || error "waiting failed"
4666 wait_request_state $fid ARCHIVE ""
4667 # The coordinator will not wake up on its own for ~`loop_period' secs...
4669 # ... Unless a copytool registers. Now the real test begins
4671 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4673 run_test 255 "Copytool registration wakes the coordinator up"
4675 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4676 # break in the future because of that.
4679 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4680 skip "need MDS version 2.11.56 or later"
4682 local -a files=("$DIR/$tdir/$tfile".{0..15})
4685 mkdir_on_mdt0 $DIR/$tdir
4687 for file in "${files[@]}"; do
4688 create_small_file "$file"
4691 # Set a few hsm parameters
4693 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4694 set_hsm_param loop_period 1
4696 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4697 set_hsm_param max_requests 3
4701 "$LFS" hsm_archive "${files[0]}"
4702 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4703 "$LFS" hsm_release "${files[0]}"
4707 wait_copytools || error "copytools failed to stop"
4709 # Send several archive requests
4710 for file in "${files[@]:1}"; do
4711 "$LFS" hsm_archive "$file"
4714 # Send one restore request
4715 "$LFS" hsm_restore "${files[0]}"
4720 # Wait for all the requests to complete
4721 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4722 for file in "${files[@]:1}"; do
4723 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4726 # Collect the actions in the order in which the copytool processed them
4728 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4729 "$(copytool_logfile "$SINGLEAGT")")
4732 printf '%s\n' "${actions[@]}"
4735 for action in "${actions[@]:0:3}"; do
4736 [ "$action" == RESTORE ] && return
4739 error "Too many ARCHIVE requests were run before the RESTORE request"
4741 run_test 260a "Restore request have priority over other requests"
4743 # This test is very much tied to the implementation of the current priorisation
4744 # mechanism in the coordinator. It might not make sense to keep it in the future
4747 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4748 skip "need MDS version 2.11.56 or later"
4750 local -a files=("$DIR/$tdir/$tfile".{0..15})
4753 mkdir_on_mdt0 $DIR/$tdir
4755 for file in "${files[@]}"; do
4756 create_small_file "$file"
4759 # Set a few hsm parameters
4761 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4762 set_hsm_param loop_period 1
4764 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4765 set_hsm_param max_requests 3
4768 copytool setup --archive-id 2
4769 "$LFS" hsm_archive --archive 2 "${files[0]}"
4770 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4771 "$LFS" hsm_release "${files[0]}"
4775 wait_copytools || error "copytools failed to stop"
4777 # Send several archive requests
4778 for file in "${files[@]:1}"; do
4779 "$LFS" hsm_archive "$file"
4782 # Send one restore request
4783 "$LFS" hsm_restore "${files[0]}"
4787 copytool setup --archive-id 2
4789 # Wait for all the requests to complete
4790 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4791 for file in "${files[@]:1}"; do
4792 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4795 # Collect the actions in the order in which the copytool processed them
4797 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4798 "$(copytool_logfile "$SINGLEAGT")")
4801 printf '%s\n' "${actions[@]}"
4804 for action in "${actions[@]:0:3}"; do
4805 [ "$action" == RESTORE ] && return
4808 error "Too many ARCHIVE requests were run before the RESTORE request"
4810 run_test 260b "Restore request have priority over other requests"
4812 # This test is very much tied to the implementation of the current priorisation
4813 # mechanism in the coordinator. It might not make sense to keep it in the future
4816 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4817 skip "Need MDS version at least 2.12.0"
4819 local -a files=("$DIR/$tdir/$tfile".{0..15})
4822 mkdir_on_mdt0 $DIR/$tdir
4824 for file in "${files[@]}"; do
4825 create_small_file "$file"
4828 # Set a few hsm parameters
4830 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4831 set_hsm_param loop_period 1000
4833 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4834 set_hsm_param max_requests 3
4837 copytool setup --archive-id 2
4838 "$LFS" hsm_archive --archive 2 "${files[0]}"
4839 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4840 "$LFS" hsm_release "${files[0]}"
4844 wait_copytools || error "copytools failed to stop"
4846 # Force the next coordinator run to do housekeeping
4850 "$LFS" hsm_archive "${files[1]}"
4854 copytool setup --archive-id 2
4856 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4857 # The coordinator just did a housekeeping run it won't do another one
4858 # for around `loop_period' seconds => requests will not be reordered
4859 # if it costs too much (ie. when the coordinator has to discard a whole
4862 # Send several archive requests
4863 for file in "${files[@]:2}"; do
4864 "$LFS" hsm_archive "$file"
4867 # Send one restore request
4868 "$LFS" hsm_restore "${files[0]}"
4870 # Wait for all the requests to complete
4871 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4872 for file in "${files[@]:2}"; do
4873 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4876 # Collect the actions in the order in which the copytool processed them
4878 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4879 "$(copytool_logfile "$SINGLEAGT")")
4882 printf '%s\n' "${actions[@]}"
4885 for action in "${actions[@]:0:3}"; do
4886 [ "$action" == RESTORE ] &&
4887 error "Restore requests should not be prioritised" \
4888 "unless the coordinator is doing housekeeping"
4892 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4895 local file=$DIR/$tdir/$tfile
4900 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4902 dd if=/dev/zero of=$file bs=4k count=2 || error "Write $file failed"
4903 fid=$(path2fid $file)
4904 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $file
4905 wait_request_state $fid ARCHIVE SUCCEED
4907 $LFS hsm_state $file
4908 $LFS hsm_release $file
4909 $LFS hsm_restore $file
4910 wait_request_state $fid RESTORE SUCCEED
4911 $LFS hsm_release $file
4912 size=$(stat -c %s $file)
4913 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4915 $LFS hsm_release $file
4916 $LFS hsm_restore $file
4917 $LFS hsm_release $file
4918 size=$(stat -c %s $file)
4919 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4920 $LFS hsm_state $file
4922 run_test 261 "Report 0 bytes size after HSM release"
4925 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4927 # the only way to test ondisk conf is to restart MDS ...
4928 echo "Stop coordinator and remove coordinator state at mount"
4931 # clean on disk conf set by default
4932 cdt_clear_mount_state
4933 cdt_check_state stopped
4935 # check cdt still off after umount/remount
4937 cdt_check_state stopped
4939 echo "Set coordinator start at mount, and start coordinator"
4940 cdt_set_mount_state enabled
4943 cdt_check_state enabled
4945 # check cdt still on after umount/remount
4947 cdt_check_state enabled
4949 # we are back to original state (cdt started at mount)
4951 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4954 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4956 local ai=$(get_hsm_param default_archive_id)
4957 local new=$((ai + 1))
4959 set_hsm_param default_archive_id $new -P
4961 local res=$(get_hsm_param default_archive_id)
4964 set_hsm_param default_archive_id "" "-P -d"
4966 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4968 run_test 301 "HSM tunnable are persistent"
4971 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4973 local ai=$(get_hsm_param default_archive_id)
4974 local new=$((ai + 1))
4979 set_hsm_param default_archive_id $new -P
4982 for mdtno in $(seq 1 $MDSCOUNT); do
4987 cdt_check_state enabled
4989 local res=$(get_hsm_param default_archive_id)
4992 set_hsm_param default_archive_id "" "-P -d"
4994 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4996 run_test 302 "HSM tunnable are persistent when CDT is off"
4999 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5003 mkdir_on_mdt0 $DIR/$tdir
5005 local dir_mdt0=$DIR/$tdir/mdt0
5006 local dir_mdt1=$DIR/$tdir/mdt1
5008 # create 1 dir per MDT
5009 stack_trap "rm -rf $dir_mdt0" EXIT
5010 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5011 stack_trap "rm -rf $dir_mdt1" EXIT
5012 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5014 # create 1 file in each MDT
5015 local fid1=$(create_small_file $dir_mdt0/$tfile)
5016 local fid2=$(create_small_file $dir_mdt1/$tfile)
5018 # check that hsm request on mdt0 is sent to the right MDS
5019 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5020 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5021 echo "archive successful on mdt0"
5023 # check that hsm request on mdt1 is sent to the right MDS
5024 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5025 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5026 echo "archive successful on mdt1"
5028 run_test 400 "Single request is sent to the right MDT"
5031 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5035 mkdir_on_mdt0 $DIR/$tdir
5037 local dir_mdt0=$DIR/$tdir/mdt0
5038 local dir_mdt1=$DIR/$tdir/mdt1
5040 # create 1 dir per MDT
5041 stack_trap "rm -rf $dir_mdt0" EXIT
5042 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5043 stack_trap "rm -rf $dir_mdt1" EXIT
5044 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5046 # create 1 file in each MDT
5047 local fid1=$(create_small_file $dir_mdt0/$tfile)
5048 local fid2=$(create_small_file $dir_mdt1/$tfile)
5050 # check that compound requests are shunt to the rights MDTs
5051 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5052 error "lfs hsm_archive"
5053 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5054 echo "archive successful on mdt0"
5055 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5056 echo "archive successful on mdt1"
5058 run_test 401 "Compound requests split and sent to their respective MDTs"
5060 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5065 local node=$(facet_active_host $facet)
5067 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5068 awk '{print $4}'); do
5069 echo "$3 $mdc on $node"
5070 do_facet $facet "$LCTL --device $mdc $state" || return 1
5075 # deactivate all mdc on agent1
5076 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5078 copytool setup --no-fail
5080 check_agent_unregistered "uuid" # match any agent
5082 # no expected running copytool
5083 search_copytools $agent && error "Copytool start should have failed"
5086 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5088 run_test 402a "Copytool start fails if all MDTs are inactive"
5093 mkdir_on_mdt0 $DIR/$tdir
5095 local f=$DIR/$tdir/$tfile
5096 touch $f || error "touch $f failed"
5097 local fid=$(path2fid $f)
5099 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5100 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5101 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5103 # give time for CDT to send request and to keep it for retry
5104 wait_for_loop_period
5106 wait_request_state $fid ARCHIVE WAITING
5108 do_facet $SINGLEAGT lctl set_param fail_loc=0
5110 # request should succeed now
5111 wait_request_state $fid ARCHIVE SUCCEED
5113 run_test 402b "CDT must retry request upon slow start of CT"
5116 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5118 local agent=$(facet_active_host $SINGLEAGT)
5120 # deactivate all mdc for MDT0001
5121 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5124 local uuid=$(get_agent_uuid $agent)
5125 # check the agent is registered on MDT0000, and not on MDT0001
5126 check_agent_registered_by_mdt $uuid 0
5127 check_agent_unregistered_by_mdt $uuid 1
5129 # check running copytool process
5130 search_copytools $agent || error "No running copytools on $agent"
5132 # reactivate all mdc for MDT0001
5133 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5135 # make sure the copytool is now registered to all MDTs
5136 check_agent_registered $uuid
5138 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5141 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5145 # create files on both MDT0000 and MDT0001
5146 mkdir_on_mdt0 $DIR/$tdir
5148 local dir_mdt0=$DIR/$tdir/mdt0
5149 stack_trap "rm -rf $dir_mdt0" EXIT
5150 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5152 # create 1 file on mdt0
5153 local fid1=$(create_small_file $dir_mdt0/$tfile)
5155 # deactivate all mdc for MDT0001
5156 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5158 # send an HSM request for files in MDT0000
5159 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5161 # check for completion of files in MDT0000
5162 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5163 echo "archive successful on mdt0"
5165 # reactivate all mdc for MDT0001
5166 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5168 run_test 404 "Inactive MDT does not block requests for active MDTs"
5171 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5175 mkdir_on_mdt0 $DIR/$tdir
5177 local striped_dir=$DIR/$tdir/striped_dir
5179 # create striped dir on all of MDTs
5180 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5182 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5183 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5184 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5185 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5187 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5188 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5189 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5190 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5192 # check that compound requests are shunt to the rights MDTs
5193 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5194 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5195 error "lfs hsm_archive"
5197 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5198 echo "archive successful on $fid1"
5199 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5200 echo "archive successful on $fid2"
5201 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5202 echo "archive successful on $fid3"
5203 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5204 echo "archive successful on $fid4"
5206 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5207 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5208 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5209 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5211 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5212 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5213 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5214 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5216 run_test 405 "archive and release under striped directory"
5219 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5221 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5222 skip "need MDS version at least 2.7.64"
5227 mkdir_on_mdt0 $DIR/$tdir
5229 fid=$(create_small_file $DIR/$tdir/$tfile)
5234 $LFS hsm_archive $DIR/$tdir/$tfile
5235 wait_request_state "$fid" ARCHIVE SUCCEED
5236 $LFS hsm_release $DIR/$tdir/$tfile
5238 # Should migrate $tdir but not $tfile.
5239 $LFS migrate -m1 $DIR/$tdir &&
5240 error "migrating HSM an archived file should fail"
5242 $LFS hsm_restore $DIR/$tdir/$tfile
5243 wait_request_state "$fid" RESTORE SUCCEED
5245 $LFS hsm_remove $DIR/$tdir/$tfile
5246 wait_request_state "$fid" REMOVE SUCCEED
5248 cat $DIR/$tdir/$tfile > /dev/null ||
5249 error "cannot read $DIR/$tdir/$tfile"
5251 $LFS migrate -m1 $DIR/$tdir ||
5252 error "cannot complete migration after HSM remove"
5254 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5255 if ((mdt_index != 1)); then
5256 error "expected MDT index 1, got $mdt_index"
5259 # Refresh fid after migration.
5260 fid=$(path2fid $DIR/$tdir/$tfile)
5263 $LFS hsm_archive $DIR/$tdir/$tfile
5264 wait_request_state "$fid" ARCHIVE SUCCEED 1
5266 lctl set_param debug=+trace
5267 $LFS hsm_release $DIR/$tdir/$tfile ||
5268 error "cannot release $DIR/$tdir/$tfile"
5270 $LFS hsm_restore $DIR/$tdir/$tfile
5271 wait_request_state "$fid" RESTORE SUCCEED 1
5273 cat $DIR/$tdir/$tfile > /dev/null ||
5274 error "cannot read $DIR/$tdir/$tfile"
5276 run_test 406 "attempting to migrate HSM archived files is safe"
5279 mkdir_on_mdt0 $DIR/$tdir
5281 local f=$DIR/$tdir/$tfile
5282 local f2=$DIR2/$tdir/$tfile
5283 local fid=$(create_empty_file "$f")
5287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5288 wait_request_state $fid ARCHIVE SUCCEED
5291 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5292 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5294 # Prevent restore from completing
5298 # 1st request holds layout lock while appropriate
5299 # RESTORE record is still not added to llog
5303 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5304 # after umount hsm_actions->O/x/x log shouldn't have
5305 # double RESTORE records like below
5306 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5307 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5309 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5311 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5313 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5316 wait_all_done 100 $fid
5318 run_test 407 "Check for double RESTORE records in llog"
5322 [ "$MDS1_VERSION" -lt $(version_code 2.6.92) ] &&
5323 skip "HSM migrate is not supported"
5325 test_mkdir -p $DIR/$tdir
5327 if [ "$CLIENT_VERSION" -lt $(version_code 2.11.56) ] ||
5328 [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ];
5330 llapi_hsm_test -d $DIR/$tdir -b ||
5331 error "One llapi HSM test failed"
5333 llapi_hsm_test -d $DIR/$tdir ||
5334 error "One llapi HSM test failed"
5337 run_test 500 "various LLAPI HSM tests"
5340 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
5341 skip "need MDS version at least 2.10.58"
5345 local f=$DIR/$tdir/$tfile
5348 # set changelog_mask to ALL
5349 changelog_chmask "ALL"
5351 chmod 777 $DIR/$tdir
5352 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5353 local fid=$(path2fid $f)
5356 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5357 -gid "$RUNAS_GID") ||
5358 error "No matching CREAT entry"
5360 # Parse the changelog
5361 eval local -A changelog=$(changelog2array $entry)
5362 local nid="${changelog[nid]}"
5365 echo "Got NID '$nid'"
5366 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5367 error "nid '$nid' does not match any client NID:" \
5370 run_test 600 "Changelog fields 'u=' and 'nid='"
5373 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5374 skip "need MDS version at least 2.10.58"
5378 local f=$DIR/$tdir/$tfile
5381 # set changelog_mask to ALL
5382 changelog_chmask "ALL"
5384 touch $f || error "touch $f failed"
5385 local fid=$(path2fid $f)
5388 cat $f || error "cat $f failed"
5390 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5391 error "No matching OPEN entry"
5393 run_test 601 "OPEN Changelog entry"
5396 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5397 skip "need MDS version at least 2.10.58"
5399 stack_trap "restore_opencache" EXIT
5404 local f=$DIR/$tdir/$tfile
5407 # set changelog_mask to ALL
5408 changelog_chmask "ALL"
5410 touch $f || error "touch $f failed"
5411 local fid=$(path2fid $f)
5414 cat $f || error "cat $f failed"
5416 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5420 echo f > $f || error "write $f failed"
5423 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5425 # remove OPEN from changelog_mask
5426 changelog_chmask "-OPEN"
5430 cat $f || error "cat $f failed"
5433 changelog_find -type CLOSE -target-fid $fid &&
5434 error "There should be no CLOSE entry"
5438 echo f > $f || error "write $f failed"
5441 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5443 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5446 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5447 skip "need MDS version at least 2.10.58"
5451 local f=$DIR/$tdir/$tfile
5454 # set changelog_mask to ALL
5455 changelog_chmask "ALL"
5457 touch $f || error "touch $f failed"
5458 local fid=$(path2fid $f)
5460 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5463 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5465 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5466 error "No matching GXATR entry"
5468 run_test 603 "GETXATTR Changelog entry"
5471 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5472 skip "need MDS version at least 2.10.58"
5474 mkdir_on_mdt0 $DIR/$tdir
5476 local f=$DIR/$tdir/$tfile
5477 local f2=$DIR2/$tdir/$tfile
5478 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5480 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5481 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5482 do_facet mds1 lctl set_param "$procname=20"
5486 # set changelog_mask to ALL
5487 changelog_chmask "ALL"
5489 touch $f || error "touch $f failed"
5490 local fid=$(path2fid $f)
5496 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5500 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5501 -gid "$RUNAS_GID" -mode "r--") ||
5502 error "No matching NOPEN entry"
5504 # Parse the changelog
5505 eval local -A changelog=$(changelog2array $entry)
5506 local nid="${changelog[nid]}"
5509 echo "Got NID '$nid'"
5510 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5511 error "nid '$nid' does not match any client NID:" \
5516 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5519 changelog_find -type NOPEN -target-fid $fid &&
5520 error "There should be no NOPEN entry"
5522 # Sleep for `changelog_deniednext` seconds
5527 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5530 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5531 -gid "$RUNAS_GID" -mode "r--") ||
5532 error "No matching NOPEN entry"
5534 # Parse the changelog
5535 eval local -A changelog=$(changelog2array $entry)
5536 local nid="${changelog[nid]}"
5539 echo "Got NID '$nid'"
5540 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5541 error "nid '$nid' does not match any client NID:" \
5544 run_test 604 "NOPEN Changelog entry"
5547 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5548 skip "need MDS version at least 2.10.58"
5550 stack_trap "restore_opencache" EXIT
5555 local f=$DIR/$tdir/$tfile
5556 local f2=$DIR2/$tdir/$tfile
5559 # set changelog_mask to ALL
5560 changelog_chmask "ALL"
5562 touch $f || error "touch $f failed"
5563 local fid=$(path2fid $f)
5567 exec 3<> $f || error "open $f failed"
5571 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5575 exec 4<> $f || error "open $f failed"
5578 changelog_find -type OPEN -target-fid $fid &&
5579 error "There should be no OPEN entry"
5581 exec 4>&- || error "close $f failed"
5584 changelog_find -type CLOSE -target-fid $fid &&
5585 error "There should be no CLOSE entry"
5589 # access in rw, so different access mode should generate entries
5590 cat $f || error "cat $f failed"
5593 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5595 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5599 # same access as first one, should not generate new entries
5600 exec 4<> $f || error "open $f failed"
5603 changelog_find -type OPEN -target-fid $fid &&
5604 error "There should be no OPEN entry"
5606 exec 4>&- || error "close $f failed"
5609 changelog_find -type CLOSE -target-fid $fid &&
5610 error "There should be no CLOSE entry"
5614 # access by different user should generate new entries
5615 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5618 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5620 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5624 exec 3>&- || error "close $f failed"
5627 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5629 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5632 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5633 skip "need MDS version at least 2.10.58"
5635 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5636 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5637 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5638 skip_env "missing llog_reader"
5640 mkdir_on_mdt0 $DIR/$tdir
5642 local f=$DIR/$tdir/$tfile
5645 # set changelog_mask to ALL
5646 changelog_chmask "ALL"
5648 chmod 777 $DIR/$tdir
5649 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5650 local fid=$(path2fid $f)
5651 rm $f || error "rm $f failed"
5653 local mntpt=$(facet_mntpt mds1)
5657 #remount mds1 as ldiskfs or zfs type
5658 stop mds1 || error "stop mds1 failed"
5659 stack_trap "unmount_fstype mds1; start mds1 $(mdsdevname 1)\
5660 $MDS_MOUNT_OPTS" EXIT
5661 mount_fstype mds1 || error "remount mds1 failed"
5663 for ((i = 0; i < 1; i++)); do
5664 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5665 local cat_file=$(do_facet mds1 $llog_reader \
5666 $mntpt/changelog_catalog | awk \
5667 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5668 [ -n "$cat_file" ] || error "no catalog file"
5670 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5671 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5672 [ -n "$entry" ] || error "no CREAT entry"
5675 local uidgid=$(echo $entry |
5676 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5677 [ -n "$uidgid" ] || error "uidgid is empty"
5678 echo "Got UID/GID $uidgid"
5679 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5680 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5681 local nid=$(echo $entry |
5682 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5683 [ -n "$nid" ] || error "nid is empty"
5685 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5686 error "nid '$nid' does not match any NID ${CLIENT_NIDS[*]}"
5688 run_test 606 "llog_reader groks changelog fields"
5691 check_and_cleanup_lustre