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 PYTHON='python'
433 local json_parser='import json; import fileinput;'
434 json_parser+=' print("\n".join(["local %s=\"%s\"" % tuple for tuple in '
435 json_parser+='json.loads([line for line in '
436 json_parser+='fileinput.input()][0]).items()]))'
438 # check if python/python2/python3 is available
439 if ! which $PYTHON > /dev/null 2>&1 ; then
441 if ! which $PYTHON > /dev/null 2>&1 ; then
445 echo $raw_event | $PYTHON -c "$json_parser"
448 get_agent_by_uuid_mdt() {
451 local mds=mds$(($mdtidx + 1))
452 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
456 check_agent_registered_by_mdt() {
459 local mds=mds$(($mdtidx + 1))
460 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
461 if [[ ! -z "$agent" ]]; then
462 echo "found agent $agent on $mds"
464 error "uuid $uuid not found in agent list on $mds"
468 check_agent_unregistered_by_mdt() {
471 local mds=mds$(($mdtidx + 1))
472 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
473 if [[ -z "$agent" ]]; then
474 echo "uuid not found in agent list on $mds"
476 error "uuid found in agent list on $mds: $agent"
480 check_agent_registered() {
483 for mdsno in $(seq 1 $MDSCOUNT); do
484 check_agent_registered_by_mdt $uuid $((mdsno - 1))
488 check_agent_unregistered() {
491 for mdsno in $(seq 1 $MDSCOUNT); do
492 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
497 local agent=${1:-$(facet_active_host $SINGLEAGT)}
499 # Lustre mount-point is mandatory and last parameter on
501 local mntpnt=$(do_rpc_nodes $agent \
502 pgrep --pidfile=$HSMTOOL_PID_FILE --list-full hsmtool |
504 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
506 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
512 # populate MDT device array
515 # cleanup from previous bad setup
518 # for recovery tests, coordinator needs to be started at mount
520 # the lustre conf must be without hsm on (like for sanity.sh)
521 echo "Set HSM on and start"
522 cdt_set_mount_state enabled
523 cdt_check_state enabled
525 echo "Set sanity-hsm HSM policy"
526 cdt_set_sanity_policy
528 # finished requests are quickly removed from list
529 set_hsm_param grace_delay 10
531 CLIENT_NIDS=( $($LCTL list_nids all) )
533 test_1A() { # was test_1
537 local f=$DIR/$tdir/$tfile
541 check_hsm_flags_user $f "0x00000000"
543 $RUNAS $LFS hsm_set --norelease $f ||
544 error "user could not change hsm flags"
545 check_hsm_flags_user $f "0x00000010"
547 $RUNAS $LFS hsm_clear --norelease $f ||
548 error "user could not clear hsm flags"
549 check_hsm_flags_user $f "0x00000000"
551 # User could not change those flags...
552 $RUNAS $LFS hsm_set --exists $f &&
553 error "user should not set this flag"
554 check_hsm_flags_user $f "0x00000000"
557 $LFS hsm_set --exists $f ||
558 error "root could not change hsm flags"
559 check_hsm_flags_user $f "0x00000001"
561 $LFS hsm_clear --exists $f ||
562 error "root could not clear hsm state"
563 check_hsm_flags_user $f "0x00000000"
566 run_test 1A "lfs hsm flags root/non-root access"
569 mkdir_on_mdt0 $DIR/$tdir
571 local f=$DIR/$tdir/$tfile
572 local fid=$(create_small_file $f)
576 $LFS hsm_archive $f || error "could not archive file"
577 wait_request_state $fid ARCHIVE SUCCEED
579 # Release and check states
580 $LFS hsm_release $f || error "could not release file"
581 echo -n "Verifying released state: "
582 check_hsm_flags $f "0x0000000d"
584 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
586 run_test 1a "mmap & cat a HSM released file"
592 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
593 error "failed to create file"
594 local fid=$(path2fid $f)
599 $LFS hsm_archive $f || error "could not archive file"
600 wait_request_state $fid ARCHIVE SUCCEED
603 $LFS hsm_release $f || error "could not release file"
604 echo "verify released state: "
605 check_hsm_flags $f "0x0000000d" && echo "pass"
608 $LFS hsm_restore $f || error "could not restore file"
609 wait_request_state $fid RESTORE SUCCEED
610 echo "verify restored state: "
611 check_hsm_flags $f "0x00000009" && echo "pass"
615 mkdir_on_mdt0 $DIR/$tdir
616 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
617 error "failed to set default stripe"
618 local f=$DIR/$tdir/$tfile
622 run_test 1b "Archive, Release and Restore composite file"
628 local f=$DIR/$tdir/$tfile
631 # Test whether we can set the maximum archive number.
632 local LOCAL_HSM_ARCHIVE_NUMBER=32
633 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
634 error "root could not change hsm flags"
635 check_hsm_flags_user $f "0x00000001"
636 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
637 local st=$(get_hsm_archive_id $f)
638 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
639 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
641 # Test whether setting archive number 0 results in no change.
642 $LFS hsm_set --exists --archive-id 0 $f ||
643 error "root could not change hsm flags"
644 check_hsm_flags_user $f "0x00000001"
645 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
646 st=$(get_hsm_archive_id $f)
647 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
648 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
650 LOCAL_HSM_ARCHIVE_NUMBER=33
651 if [ "$CLIENT_VERSION" -ge $(version_code 2.11.56) ] &&
652 [ "$MDS1_VERSION" -ge $(version_code 2.11.56) ]; then
653 # lustre in the new version supports unlimited archiveID.
654 # Test whether setting archive number > 32 is supported
655 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
656 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
657 check_hsm_flags_user $f "0x00000001"
659 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
660 st=$(get_hsm_archive_id $f)
661 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
662 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
664 # old client or old mds can only support at most 32 archiveID
665 # test whether setting archive number > 32 results in error.
666 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
667 error "bitmap archive number is larger than 32"
668 check_hsm_flags_user $f "0x00000001"
671 # Test whether setting archive number 16 and archived flag.
672 LOCAL_HSM_ARCHIVE_NUMBER=16
673 $LFS hsm_set --exists --archived \
674 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
675 error "root could not change hsm flags"
676 check_hsm_flags_user $f "0x00000009"
677 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
678 st=$(get_hsm_archive_id $f)
679 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
680 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
682 run_test 1c "Check setting archive-id in lfs hsm_set"
685 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
686 skip "need MDS version at least 2.10.59"
688 mkdir_on_mdt0 $DIR/$tdir
689 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
690 error "failed to set default stripe"
691 local f=$DIR/$tdir/$tfile
695 run_test 1d "Archive, Release and Restore DoM file"
698 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
699 skip "skipped for lustre < $SEL_VER"
701 mkdir_on_mdt0 $DIR/$tdir
702 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
703 error "failed to set default stripe"
704 local comp_file=$DIR/$tdir/$tfile
706 test_1bde_base $comp_file
708 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
709 local found=$($LFS find $flg_opts $comp_file | wc -l)
710 [ $found -eq 1 ] || error "1st component not found"
712 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
713 found=$($LFS find $flg_opts $comp_file | wc -l)
714 [ $found -eq 1 ] || error "2nd component not found"
716 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
717 found=$($LFS find $flg_opts $comp_file | wc -l)
718 [ $found -eq 1 ] || error "3rd component not found"
720 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
721 found=$($LFS find $flg_opts $comp_file | wc -l)
722 [ $found -eq 1 ] || error "4th component not found"
724 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
725 found=$($LFS find $flg_opts $comp_file | wc -l)
726 [ $found -eq 1 ] || error "5th component not found"
728 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
729 found=$($LFS find $flg_opts $comp_file | wc -l)
730 [ $found -eq 1 ] || error "6th component not found"
732 sel_layout_sanity $comp_file 6
734 run_test 1e "Archive, Release and Restore SEL file"
737 local f=$DIR/$tdir/$tfile
739 mkdir_on_mdt0 $DIR/$tdir
740 create_empty_file "$f"
741 # New files are not dirty
742 check_hsm_flags $f "0x00000000"
744 # For test, we simulate an archived file.
745 $LFS hsm_set --exists $f || error "user could not change hsm flags"
746 check_hsm_flags $f "0x00000001"
748 # chmod do not put the file dirty
749 chmod 600 $f || error "could not chmod test file"
750 check_hsm_flags $f "0x00000001"
752 # chown do not put the file dirty
753 chown $RUNAS_ID $f || error "could not chown test file"
754 check_hsm_flags $f "0x00000001"
756 # truncate put the file dirty
757 $TRUNCATE $f 1 || error "could not truncate test file"
758 check_hsm_flags $f "0x00000003"
760 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
761 check_hsm_flags $f "0x00000001"
763 run_test 2 "Check file dirtyness when doing setattr"
766 mkdir_on_mdt0 $DIR/$tdir
769 # New files are not dirty
771 check_hsm_flags $f "0x00000000"
773 # For test, we simulate an archived file.
774 $LFS hsm_set --exists $f ||
775 error "user could not change hsm flags"
776 check_hsm_flags $f "0x00000001"
778 # Reading a file, does not set dirty
779 cat $f > /dev/null || error "could not read file"
780 check_hsm_flags $f "0x00000001"
782 # Open for write without modifying data, does not set dirty
783 openfile -f O_WRONLY $f || error "could not open test file"
784 check_hsm_flags $f "0x00000001"
786 # Append to a file sets it dirty
787 cp -p /etc/passwd $f.append || error "could not create file"
788 $LFS hsm_set --exists $f.append ||
789 error "user could not change hsm flags"
790 dd if=/etc/passwd of=$f.append bs=1 count=3\
791 conv=notrunc oflag=append status=noxfer ||
792 file_creation_failure dd $f.append $?
793 check_hsm_flags $f.append "0x00000003"
795 # Modify a file sets it dirty
796 cp -p /etc/passwd $f.modify || error "could not create file"
797 $LFS hsm_set --exists $f.modify ||
798 error "user could not change hsm flags"
799 dd if=/dev/zero of=$f.modify bs=1 count=3\
800 conv=notrunc status=noxfer ||
801 file_creation_failure dd $f.modify $?
802 check_hsm_flags $f.modify "0x00000003"
804 # Open O_TRUNC sets dirty
805 cp -p /etc/passwd $f.trunc || error "could not create file"
806 $LFS hsm_set --exists $f.trunc ||
807 error "user could not change hsm flags"
808 cp /etc/group $f.trunc || error "could not override a file"
809 check_hsm_flags $f.trunc "0x00000003"
811 # Mmapped a file sets dirty
812 cp -p /etc/passwd $f.mmap || error "could not create file"
813 $LFS hsm_set --exists $f.mmap ||
814 error "user could not change hsm flags"
815 multiop $f.mmap OSMWUc || error "could not mmap a file"
816 check_hsm_flags $f.mmap "0x00000003"
818 run_test 3 "Check file dirtyness when opening for write"
821 local f=$DIR/$tdir/$tfile
822 local fid=$(create_small_file $f)
825 local st=$(get_request_state $fid CANCEL)
826 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
828 run_test 4 "Useless cancel must not be registered"
831 # test needs a running copytool
834 mkdir_on_mdt0 $DIR/$tdir
835 local f=$DIR/$tdir/$tfile
836 local fid=$(copy_file /etc/passwd $f)
838 wait_request_state $fid ARCHIVE SUCCEED
840 check_hsm_flags $f "0x00000009"
842 run_test 8 "Test default archive number"
844 test_9A() { # was test_9
845 # we do not use the default one to be sure
846 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
847 copytool setup --archive-id $archive_id
849 # give time for CT to register with MDTs
850 sleep $(($MDSCOUNT*2))
851 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
852 check_agent_registered $uuid
854 mkdir_on_mdt0 $DIR/$tdir
856 local f=$DIR/$tdir/$tfile
857 local fid=$(copy_file /etc/passwd $f)
858 $LFS hsm_archive --archive $archive_id $f
859 wait_request_state $fid ARCHIVE SUCCEED
861 check_hsm_flags $f "0x00000009"
863 run_test 9A "Use of explicit archive number, with dedicated copytool"
866 needclients 3 || return 0
872 # start all of the copytools
873 for n in $(seq $AGTCOUNT); do
874 copytool setup --facet agt$n
877 mkdir_on_mdt0 $DIR/$tdir
880 for n in $(seq $AGTCOUNT); do
881 file=$DIR/$tdir/$tfile.$n
882 fid=$(create_small_file $file)
884 $LFS hsm_archive $file || error "could not archive file $file"
885 wait_request_state $fid ARCHIVE SUCCEED
886 check_hsm_flags $file "0x00000009"
889 run_test 9a "Multiple remote agents"
892 # test needs a running copytool
895 mkdir_on_mdt0 $DIR/$tdir
896 mkdir -p $DIR/$tdir/d1
897 local f=$DIR/$tdir/$tfile
898 local fid=$(copy_file /etc/hosts $f)
899 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
900 error "hsm_archive failed"
901 wait_request_state $fid ARCHIVE SUCCEED
903 local hsm_root="$(copytool_device $SINGLEAGT)"
904 local archive="$(do_facet $SINGLEAGT \
905 find "$hsm_root" -name "$fid" -print0)"
906 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
908 echo "Verifying content"
909 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
910 echo "Verifying hsm state "
911 check_hsm_flags $f "0x00000009"
913 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
914 local st=$(get_hsm_archive_id $f)
915 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
916 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
918 run_test 10a "Archive a file"
921 # test needs a running copytool
924 mkdir_on_mdt0 $DIR/$tdir
925 local f=$DIR/$tdir/$tfile
926 local fid=$(copy_file /etc/hosts $f)
927 $LFS hsm_archive $f || error "archive request failed"
928 wait_request_state $fid ARCHIVE SUCCEED
930 $LFS hsm_archive $f || error "archive of non dirty file failed"
931 local cnt=$(get_request_count $fid ARCHIVE)
932 [[ "$cnt" == "1" ]] ||
933 error "archive of non dirty file must not make a request"
935 run_test 10b "Archive of non dirty file must work without doing request"
938 # test needs a running copytool
942 local f=$DIR/$tdir/$tfile
943 local fid=$(copy_file /etc/hosts $f)
944 $LFS hsm_set --noarchive $f
945 $LFS hsm_archive $f && error "archive a noarchive file must fail"
948 run_test 10c "Check forbidden archive"
951 # test needs a running copytool
954 mkdir_on_mdt0 $DIR/$tdir
955 local f=$DIR/$tdir/$tfile
956 local fid=$(copy_file /etc/hosts $f)
957 $LFS hsm_archive $f || error "cannot archive $f"
958 wait_request_state $fid ARCHIVE SUCCEED
960 local ar=$(get_hsm_archive_id $f)
961 local dflt=$(get_hsm_param default_archive_id)
962 [[ $ar == $dflt ]] ||
963 error "archived file is not on default archive: $ar != $dflt"
965 run_test 10d "Archive a file on the default archive id"
968 mkdir_on_mdt0 $DIR/$tdir
969 copy2archive /etc/hosts $tdir/$tfile
970 local f=$DIR/$tdir/$tfile
972 copytool import $tdir/$tfile $f
973 echo -n "Verifying released state: "
974 check_hsm_flags $f "0x0000000d"
976 local LSZ=$(stat -c "%s" $f)
977 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
979 echo "Verifying imported size $LSZ=$ASZ"
980 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
981 echo -n "Verifying released pattern: "
982 local PTRN=$($LFS getstripe -L $f)
984 [[ $PTRN == released ]] || error "Is not released"
985 local fid=$(path2fid $f)
986 echo "Verifying new fid $fid in archive"
988 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
989 error "No archive for fid $fid"
991 run_test 11a "Import a file"
994 # test needs a running copytool
997 mkdir_on_mdt0 $DIR/$tdir
998 local f=$DIR/$tdir/$tfile
999 local fid=$(copy_file /etc/hosts $f)
1000 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1001 error "hsm_archive failed"
1002 wait_request_state $fid ARCHIVE SUCCEED
1004 local FILE_HASH=$(md5sum $f)
1007 copytool import $fid $f
1009 echo "$FILE_HASH" | md5sum -c
1011 [[ $? -eq 0 ]] || error "Restored file differs"
1013 run_test 11b "Import a deleted file using its FID"
1016 pool_add $TESTNAME || error "Pool creation failed"
1017 pool_add_targets $TESTNAME 1 1 || error "pool_add_targets failed"
1020 $LFS setstripe -p "$TESTNAME" $DIR/$tdir
1022 copy2archive /etc/hosts $tdir/$tfile
1023 copytool import $tdir/$tfile $DIR/$tdir/$tfile
1025 run_test 11c "Import a file to a directory with a pool"
1028 # test needs a running copytool
1031 mkdir_on_mdt0 $DIR/$tdir
1032 copy2archive /etc/hosts $tdir/$tfile
1034 local f=$DIR/$tdir/$tfile
1035 copytool import $tdir/$tfile $f
1036 local f2=$DIR2/$tdir/$tfile
1037 echo "Verifying released state: "
1038 check_hsm_flags $f2 "0x0000000d"
1040 local fid=$(path2fid $f2)
1041 $LFS hsm_restore $f2
1042 wait_request_state $fid RESTORE SUCCEED
1044 echo "Verifying file state: "
1045 check_hsm_flags $f2 "0x00000009"
1047 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1049 [[ $? -eq 0 ]] || error "Restored file differs"
1051 run_test 12a "Restore an imported file explicitly"
1054 # test needs a running copytool
1057 mkdir_on_mdt0 $DIR/$tdir
1058 copy2archive /etc/hosts $tdir/$tfile
1060 local f=$DIR/$tdir/$tfile
1061 copytool import $tdir/$tfile $f
1062 echo "Verifying released state: "
1063 check_hsm_flags $f "0x0000000d"
1065 cat $f > /dev/null || error "File read failed"
1067 echo "Verifying file state after restore: "
1068 check_hsm_flags $f "0x00000009"
1070 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1072 [[ $? -eq 0 ]] || error "Restored file differs"
1074 run_test 12b "Restore an imported file implicitly"
1077 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1079 # test needs a running copytool
1082 local f=$DIR/$tdir/$tfile
1083 mkdir_on_mdt0 $DIR/$tdir
1084 $LFS setstripe -c 2 "$f"
1085 local fid=$(create_file "$f" 1M 5)
1087 local FILE_CRC=$(md5sum $f)
1089 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1090 wait_request_state $fid ARCHIVE SUCCEED
1091 $LFS hsm_release $f || error "release $f failed"
1093 echo "$FILE_CRC" | md5sum -c
1095 [[ $? -eq 0 ]] || error "Restored file differs"
1097 run_test 12c "Restore a file with stripe of 2"
1100 # test needs a running copytool
1103 mkdir_on_mdt0 $DIR/$tdir
1105 local f=$DIR/$tdir/$tfile
1106 local fid=$(copy_file /etc/hosts $f)
1107 $LFS hsm_restore $f || error "restore of non archived file failed"
1108 local cnt=$(get_request_count $fid RESTORE)
1109 [[ "$cnt" == "0" ]] ||
1110 error "restore non archived must not make a request"
1111 $LFS hsm_archive $f ||
1112 error "archive request failed"
1113 wait_request_state $fid ARCHIVE SUCCEED
1114 $LFS hsm_restore $f ||
1115 error "restore of non released file failed"
1116 local cnt=$(get_request_count $fid RESTORE)
1117 [[ "$cnt" == "0" ]] ||
1118 error "restore a non dirty file must not make a request"
1120 run_test 12d "Restore of a non archived, non released file must work"\
1121 " without doing request"
1124 # test needs a running copytool
1127 mkdir_on_mdt0 $DIR/$tdir
1128 local f=$DIR/$tdir/$tfile
1129 local fid=$(copy_file /etc/hosts $f)
1130 $LFS hsm_archive $f || error "archive request failed"
1131 wait_request_state $fid ARCHIVE SUCCEED
1134 cat /etc/hosts >> $f
1138 $LFS hsm_restore $f && error "restore a dirty file must fail"
1141 run_test 12e "Check forbidden restore"
1144 # test needs a running copytool
1147 mkdir_on_mdt0 $DIR/$tdir
1148 local f=$DIR/$tdir/$tfile
1149 local fid=$(copy_file /etc/hosts $f)
1151 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1152 wait_request_state $fid ARCHIVE SUCCEED
1153 $LFS hsm_release $f || error "release of $f failed"
1155 wait_request_state $fid RESTORE SUCCEED
1157 echo -n "Verifying file state: "
1158 check_hsm_flags $f "0x00000009"
1160 diff -q /etc/hosts $f
1162 [[ $? -eq 0 ]] || error "Restored file differs"
1164 run_test 12f "Restore a released file explicitly"
1167 # test needs a running copytool
1170 mkdir_on_mdt0 $DIR/$tdir
1171 local f=$DIR/$tdir/$tfile
1172 local fid=$(copy_file /etc/hosts $f)
1174 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1175 wait_request_state $fid ARCHIVE SUCCEED
1176 $LFS hsm_release $f || error "release of $f failed"
1178 diff -q /etc/hosts $f
1181 # we check we had a restore done
1182 wait_request_state $fid RESTORE SUCCEED
1184 [[ $st -eq 0 ]] || error "Restored file differs"
1186 run_test 12g "Restore a released file implicitly"
1189 needclients 2 || return 0
1191 # test needs a running copytool
1194 mkdir_on_mdt0 $DIR/$tdir
1195 local f=$DIR/$tdir/$tfile
1196 local fid=$(copy_file /etc/hosts $f)
1198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1199 wait_request_state $fid ARCHIVE SUCCEED
1200 $LFS hsm_release $f || error "release of $f failed"
1202 do_node $CLIENT2 diff -q /etc/hosts $f
1205 # we check we had a restore done
1206 wait_request_state $fid RESTORE SUCCEED
1208 [[ $st -eq 0 ]] || error "Restored file differs"
1210 run_test 12h "Restore a released file implicitly from a second node"
1213 # test needs a running copytool
1216 mkdir_on_mdt0 $DIR/$tdir
1217 local f=$DIR/$tdir/$tfile
1218 local fid=$(copy_file /etc/passwd $f)
1219 $LFS hsm_archive $f || error "archive of $f failed"
1220 wait_request_state $fid ARCHIVE SUCCEED
1222 $LFS hsm_release $f || error "release of $f failed"
1226 [[ $? -eq 0 ]] || error "Restored file differs"
1228 run_test 12m "Archive/release/implicit restore"
1231 # test needs a running copytool
1235 copy2archive /etc/hosts $tdir/$tfile
1237 local f=$DIR/$tdir/$tfile
1238 copytool import $tdir/$tfile $f
1240 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1241 error "Restored file differs"
1243 $LFS hsm_release $f || error "release of $f failed"
1245 run_test 12n "Import/implicit restore/release"
1248 # test needs a running copytool
1251 mkdir_on_mdt0 $DIR/$tdir
1252 local f=$DIR/$tdir/$tfile
1253 local fid=$(copy_file /etc/hosts $f)
1255 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1256 wait_request_state $fid ARCHIVE SUCCEED
1257 $LFS hsm_release $f || error "release of $f failed"
1259 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1260 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1262 # set no retry action mode
1265 diff -q /etc/hosts $f
1268 # we check we had a restore failure
1269 wait_request_state $fid RESTORE FAILED
1271 [[ $st -eq 0 ]] && error "Restore must fail"
1273 # remove no retry action mode
1276 # check file is still released
1277 check_hsm_flags $f "0x0000000d"
1279 # retry w/o failure injection
1280 do_facet $SINGLEMDS lctl set_param fail_loc=0
1282 # to be sure previous RESTORE result is gone
1284 wait_for_grace_delay
1286 diff -q /etc/hosts $f
1289 # we check we had a restore done
1290 wait_request_state $fid RESTORE SUCCEED
1292 [[ $st -eq 0 ]] || error "Restored file differs"
1294 run_test 12o "Layout-swap failure during Restore leaves file released"
1297 # test needs a running copytool
1300 mkdir_on_mdt0 $DIR/$tdir
1301 local f=$DIR/$tdir/$tfile
1302 local fid=$(copy_file /etc/hosts $f)
1304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1305 wait_request_state $fid ARCHIVE SUCCEED
1306 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1307 $LFS hsm_release $f || error "cannot release $f"
1308 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1309 $LFS hsm_release $f || error "cannot release $f"
1310 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1312 run_test 12p "implicit restore of a file on copytool mount point"
1315 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1316 skip "need MDS version at least 2.7.58"
1318 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1319 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1320 error "cannot mount $MOUNT3 on $SINGLEAGT"
1322 # test needs a running copytool
1323 copytool setup -m "$MOUNT3"
1325 mkdir_on_mdt0 $DIR/$tdir
1327 local f=$DIR/$tdir/$tfile
1328 local f2=$DIR2/$tdir/$tfile
1329 local fid=$(create_small_file $f)
1330 local orig_size=$(stat -c "%s" $f)
1332 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1333 wait_request_state $fid ARCHIVE SUCCEED
1335 $LFS hsm_release $f || error "could not release file"
1336 check_hsm_flags $f "0x0000000d"
1339 wait_copytools || error "copytool failed to stop"
1341 cat $f > /dev/null &
1343 # wait a bit to allow implicit restore request to be handled.
1344 # if not, next stat would also block on layout-lock.
1347 local size=$(stat -c "%s" $f2)
1348 [ $size -eq $orig_size ] ||
1349 error "$f2: wrong size after archive: $size != $orig_size"
1351 copytool setup -m "$MOUNT3"
1355 size=$(stat -c "%s" $f)
1356 [ $size -eq $orig_size ] ||
1357 error "$f: wrong size after restore: $size != $orig_size"
1359 size=$(stat -c "%s" $f2)
1360 [ $size -eq $orig_size ] ||
1361 error "$f2: wrong size after restore: $size != $orig_size"
1365 size=$(stat -c "%s" $f)
1367 error "$f: wrong size after overwrite: $size != 0"
1369 size=$(stat -c "%s" $f2)
1371 error "$f2: wrong size after overwrite: $size != 0"
1373 run_test 12q "file attributes are refreshed after restore"
1376 # test needs a running copytool
1379 mkdir_on_mdt0 $DIR/$tdir
1380 local f=$DIR/$tdir/$tfile
1381 local fid=$(copy_file /etc/hosts $f)
1383 $LFS hsm_archive $f || error "archive of $f failed"
1384 wait_request_state $fid ARCHIVE SUCCEED
1385 $LFS hsm_release $f || error "release of $f failed"
1387 offset=$(lseek_test -d 7 $f)
1389 # we check we had a restore done
1390 wait_request_state $fid RESTORE SUCCEED
1391 [[ $offset == 7 ]] || error "offset $offset != 7"
1393 run_test 12r "lseek restores released file"
1396 local f=$DIR/$tdir/$tfile
1400 (( MDS1_VERSION >= $(version_code 2.15.50) )) ||
1401 skip "Need MDS version newer than 2.15.50"
1403 # test needs a running copytool
1406 mkdir_on_mdt0 $DIR/$tdir
1407 fid=$(copy_file /etc/hosts $f)
1409 $LFS hsm_archive $f || error "archive of $f failed"
1410 wait_request_state $fid ARCHIVE SUCCEED
1411 $LFS hsm_release $f || error "release of $f failed"
1413 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_HSM_RESTORE_RACE 0x8000018b
1414 do_facet mds1 $LCTL set_param fail_loc=0x8000018b
1415 cat $f > /dev/null & pid1=$!
1416 cat $f > /dev/null & pid2=$!
1418 wait $pid1 || error "cat process 1 fail (pid: $pid1)"
1419 wait $pid2 || error "cat process 2 fail (pid: $pid2)"
1421 # Race exists if more than 1 restore requests is registered
1422 assert_request_count $fid RESTORE 1
1424 run_test 12s "race between restore requests"
1428 for i in {1..10}; do
1429 local archive_dir="$(hsm_root)"/subdir/dir.$i
1431 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1432 for j in {1..10}; do
1433 local archive_file="$archive_dir"/file.$j
1435 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1441 copytool import "subdir" "$DIR/$tdir"
1443 # To check the import, the test uses diff with the -r flag
1444 # This is nice, but diff only checks files one by one, and triggering
1445 # an implicit restore for one file at a time will consume as many
1446 # seconds as there are files to compare. To speed this up, a restore
1447 # operation is triggered manually first.
1449 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1451 # Compare the imported data
1452 do_facet $SINGLEAGT \
1453 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1454 error "imported files differ from archived data"
1456 run_test 13 "Recursively import and restore a directory"
1459 # test needs a running copytool
1462 mkdir_on_mdt0 $DIR/$tdir
1465 local f=$DIR/$tdir/$tfile
1466 local fid=$(create_small_file $f)
1467 local sum=$(md5sum $f | awk '{print $1}')
1468 $LFS hsm_archive $f || error "could not archive file"
1469 wait_request_state $fid ARCHIVE SUCCEED
1471 # create released file (simulate llapi_hsm_import call)
1472 local fid2=$(create_empty_file "$f")
1473 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1474 $LFS hsm_release $f || error "could not release file"
1476 # rebind the archive to the newly created file
1477 echo "rebind $fid to $fid2"
1479 copytool rebind $fid $fid2
1481 # restore file and compare md5sum
1482 local sum2=$(md5sum $f | awk '{print $1}')
1484 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1486 run_test 14 "Rebind archived file to a new fid"
1489 # test needs a running copytool
1492 mkdir_on_mdt0 $DIR/$tdir
1495 local f=$DIR/$tdir/$tfile
1497 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1501 for i in $(seq 1 $count); do
1502 fids[$i]=$(create_small_file $f.$i)
1503 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1504 $LFS hsm_archive $f.$i || error "could not archive file"
1506 wait_all_done $(($count*60))
1508 stack_trap "rm -f $tmpfile" EXIT
1511 for i in $(seq 1 $count); do
1512 local fid2=$(create_empty_file "${f}.${i}")
1513 # add the rebind operation to the list
1514 echo ${fids[$i]} $fid2 >> $tmpfile
1516 # set it released (simulate llapi_hsm_import call)
1517 $LFS hsm_set --archived --exists $f.$i ||
1518 error "could not force hsm flags"
1519 $LFS hsm_release $f.$i || error "could not release file"
1521 nl=$(wc -l < $tmpfile)
1522 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1524 echo "rebind list of files"
1525 copytool rebind "$tmpfile"
1527 # restore files and compare md5sum
1528 for i in $(seq 1 $count); do
1529 local sum2=$(md5sum $f.$i | awk '{print $1}')
1530 [[ $sum2 == ${sums[$i]} ]] ||
1531 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1534 run_test 15 "Rebind a list of files"
1537 # test needs a running copytool
1541 # create a known size file so we can verify transfer speed
1544 dd if=/dev/zero of=$ref bs=1M count=20
1546 mkdir_on_mdt0 $DIR/$tdir
1547 local f=$DIR/$tdir/$tfile
1548 local fid=$(copy_file $ref $f)
1550 local start=$(date +%s)
1552 wait_request_state $fid ARCHIVE SUCCEED
1553 local end=$(date +%s)
1554 # Add 1 to account for rounding errors between start and end (LU-8155)
1555 local duration=$((end - start + 1))
1557 [[ $duration -ge $((goal - 1)) ]] ||
1558 error "Transfer is too fast $duration < $goal"
1560 run_test 16 "Test CT bandwith control option"
1563 local f=$DIR/$tdir/$tfile
1564 create_empty_file "$f"
1566 # Could not release a non-archived file
1567 $LFS hsm_release $f && error "release should not succeed"
1569 # For following tests, we must test them with HS_ARCHIVED set
1570 $LFS hsm_set --exists --archived $f || error "could not add flag"
1572 # Could not release a file if no-release is set
1573 $LFS hsm_set --norelease $f || error "could not add flag"
1574 $LFS hsm_release $f && error "release should not succeed"
1575 $LFS hsm_clear --norelease $f || error "could not remove flag"
1577 # Could not release a file if lost
1578 $LFS hsm_set --lost $f || error "could not add flag"
1579 $LFS hsm_release $f && error "release should not succeed"
1580 $LFS hsm_clear --lost $f || error "could not remove flag"
1582 # Could not release a file if dirty
1583 $LFS hsm_set --dirty $f || error "could not add flag"
1584 $LFS hsm_release $f && error "release should not succeed"
1585 $LFS hsm_clear --dirty $f || error "could not remove flag"
1587 run_test 20 "Release is not permitted"
1590 # test needs a running copytool
1592 mkdir_on_mdt0 $DIR/$tdir
1594 local f=$DIR/$tdir/test_release
1596 # Create a file and check its states
1597 local fid=$(create_small_file $f)
1598 check_hsm_flags $f "0x00000000"
1600 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1601 # used until file is flushed to disk
1602 if [ "$ost1_FSTYPE" == "zfs" ]; then
1603 # this causes an OST_SYNC rpc to be sent
1604 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1605 # clear locks to reread file data
1606 cancel_lru_locks osc
1609 local orig_size=$(stat -c "%s" $f)
1610 local orig_blocks=$(stat -c "%b" $f)
1612 start_full_debug_logging
1614 $LFS hsm_archive $f || error "could not archive file"
1615 wait_request_state $fid ARCHIVE SUCCEED
1617 local blocks=$(stat -c "%b" $f)
1618 [ $blocks -eq $orig_blocks ] ||
1619 error "$f: wrong block number after archive: " \
1620 "$blocks != $orig_blocks"
1621 local size=$(stat -c "%s" $f)
1622 [ $size -eq $orig_size ] ||
1623 error "$f: wrong size after archive: $size != $orig_size"
1625 # Release and check states
1626 $LFS hsm_release $f || error "could not release file"
1627 check_hsm_flags $f "0x0000000d"
1629 blocks=$(stat -c "%b" $f)
1630 [ $blocks -gt 5 ] &&
1631 error "$f: too many blocks after release: $blocks > 5"
1632 size=$(stat -c "%s" $f)
1633 [ $size -ne $orig_size ] &&
1634 error "$f: wrong size after release: $size != $orig_size"
1636 # Check we can release an file without stripe info
1640 check_hsm_flags $f "0x00000000"
1641 $LFS hsm_archive $f || error "could not archive file"
1642 wait_request_state $fid ARCHIVE SUCCEED
1644 # Release and check states
1645 $LFS hsm_release $f || error "could not release file"
1646 check_hsm_flags $f "0x0000000d"
1648 # Release again a file that is already released is OK
1649 $LFS hsm_release $f || fail "second release should succeed"
1650 check_hsm_flags $f "0x0000000d"
1652 stop_full_debug_logging
1654 run_test 21 "Simple release tests"
1657 # test needs a running copytool
1659 mkdir_on_mdt0 $DIR/$tdir
1661 local f=$DIR/$tdir/test_release
1662 local swap=$DIR/$tdir/test_swap
1664 # Create a file and check its states
1665 local fid=$(create_small_file $f)
1666 check_hsm_flags $f "0x00000000"
1668 $LFS hsm_archive $f || error "could not archive file"
1669 wait_request_state $fid ARCHIVE SUCCEED
1671 # Release and check states
1672 $LFS hsm_release $f || error "could not release file"
1673 check_hsm_flags $f "0x0000000d"
1675 create_small_file $swap
1676 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1680 run_test 22 "Could not swap a release file"
1683 # test needs a running copytool
1685 mkdir_on_mdt0 $DIR/$tdir
1687 local f=$DIR/$tdir/test_mtime
1689 # Create a file and check its states
1690 local fid=$(create_small_file $f)
1691 check_hsm_flags $f "0x00000000"
1693 $LFS hsm_archive $f || error "could not archive file"
1694 wait_request_state $fid ARCHIVE SUCCEED
1696 # Set modification time in the past
1697 touch -m -a -d @978261179 $f
1699 # Release and check states
1700 $LFS hsm_release $f || error "could not release file"
1701 check_hsm_flags $f "0x0000000d"
1703 local MTIME=$(stat -c "%Y" $f)
1704 local ATIME=$(stat -c "%X" $f)
1705 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1706 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1708 run_test 23 "Release does not change a/mtime (utime)"
1711 local file=$DIR/$tdir/$tfile
1720 # test needs a running copytool
1722 mkdir_on_mdt0 $DIR/$tdir
1724 fid=$(create_small_file $file)
1726 # Create a file and check its states
1727 check_hsm_flags $file "0x00000000"
1729 # Ensure atime is less than mtime and ctime.
1733 atime0=$(stat -c "%X" $file)
1734 mtime0=$(stat -c "%Y" $file)
1735 ctime0=$(stat -c "%Z" $file)
1737 [ $atime0 -lt $mtime0 ] ||
1738 error "atime $atime0 is not less than mtime $mtime0"
1740 [ $atime0 -lt $ctime0 ] ||
1741 error "atime $atime0 is not less than ctime $ctime0"
1743 # Archive should not change any timestamps.
1744 $LFS hsm_archive $file || error "cannot archive '$file'"
1745 wait_request_state $fid ARCHIVE SUCCEED
1747 atime1=$(stat -c "%X" $file)
1748 mtime1=$(stat -c "%Y" $file)
1749 ctime1=$(stat -c "%Z" $file)
1751 [ $atime0 -eq $atime1 ] ||
1752 error "archive changed atime from $atime0 to $atime1"
1754 [ $mtime0 -eq $mtime1 ] ||
1755 error "archive changed mtime from $mtime0 to $mtime1"
1757 [ $ctime0 -eq $ctime1 ] ||
1758 error "archive changed ctime from $ctime0 to $ctime1"
1760 # Release should not change any timestamps.
1761 $LFS hsm_release $file || error "cannot release '$file'"
1762 check_hsm_flags $file "0x0000000d"
1764 atime1=$(stat -c "%X" $file)
1765 mtime1=$(stat -c "%Y" $file)
1766 ctime1=$(stat -c "%Z" $file)
1768 [ $atime0 -eq $atime1 ] ||
1769 error "release changed atime from $atime0 to $atime1"
1771 [ $mtime0 -eq $mtime1 ] ||
1772 error "release changed mtime from $mtime0 to $mtime1"
1774 [ $ctime0 -eq $ctime1 ] ||
1775 error "release changed ctime from $ctime0 to $ctime1"
1777 # Restore should not change any timestamps.
1778 $LFS hsm_restore $file
1779 wait_request_state $fid RESTORE SUCCEED
1781 atime1=$(stat -c "%X" $file)
1782 mtime1=$(stat -c "%Y" $file)
1783 ctime1=$(stat -c "%Z" $file)
1785 [ $atime0 -eq $atime1 ] ||
1786 error "restore changed atime from $atime0 to $atime1"
1788 [ $mtime0 -eq $mtime1 ] ||
1789 error "restore changed mtime from $mtime0 to $mtime1"
1791 [ $ctime0 -eq $ctime1 ] ||
1792 error "restore changed ctime from $ctime0 to $ctime1"
1795 wait_copytools || error "Copytools failed to stop"
1797 # Once more, after unmount and mount.
1798 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1799 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1801 atime1=$(stat -c "%X" $file)
1802 mtime1=$(stat -c "%Y" $file)
1803 ctime1=$(stat -c "%Z" $file)
1805 [ $atime0 -eq $atime1 ] ||
1806 error "remount changed atime from $atime0 to $atime1"
1808 [ $mtime0 -eq $mtime1 ] ||
1809 error "remount changed mtime from $mtime0 to $mtime1"
1811 [ $ctime0 -eq $ctime1 ] ||
1812 error "remount changed ctime from $ctime0 to $ctime1"
1814 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1817 local file=$DIR/$tdir/$tfile
1823 # Test needs a running copytool.
1825 mkdir_on_mdt0 $DIR/$tdir
1827 # Check that root can do HSM actions on a regular user's file.
1828 fid=$(create_small_file $file)
1829 sum0=$(md5sum $file)
1831 chown $RUNAS_ID:$RUNAS_GID $file ||
1832 error "cannot chown '$file' to '$RUNAS_ID'"
1834 chmod ugo-w $DIR/$tdir ||
1835 error "cannot chmod '$DIR/$tdir'"
1837 $LFS hsm_archive $file
1838 wait_request_state $fid ARCHIVE SUCCEED
1840 $LFS hsm_release $file
1841 check_hsm_flags $file "0x0000000d"
1843 $LFS hsm_restore $file
1844 wait_request_state $fid RESTORE SUCCEED
1846 # Check that ordinary user can get HSM state.
1847 $RUNAS $LFS hsm_state $file ||
1848 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1850 $LFS hsm_release $file
1851 check_hsm_flags $file "0x0000000d"
1853 # Check that ordinary user can accessed released file.
1854 sum1=$($RUNAS md5sum $file) ||
1855 error "user '$RUNAS_ID' cannot read '$file'"
1857 [ "$sum0" == "$sum1" ] ||
1858 error "md5sum mismatch for '$file'"
1860 run_test 24b "root can archive, release, and restore user files"
1863 local file=$DIR/$tdir/$tfile
1864 local action=archive
1869 # test needs a running copytool
1871 mkdir_on_mdt0 $DIR/$tdir
1873 # Save the default masks and check that cleanup_24c will
1874 # restore the request masks correctly.
1875 user_save=$(get_hsm_param user_request_mask)
1876 stack_trap "set_hsm_param user_request_mask '$user_save'" EXIT
1877 group_save=$(get_hsm_param group_request_mask)
1878 stack_trap "set_hsm_param group_request_mask '$group_save'" EXIT
1879 other_save=$(get_hsm_param other_request_mask)
1880 stack_trap "set_hsm_param other_request_mask '$other_save'" EXIT
1882 [ "$user_save" == RESTORE ] ||
1883 error "user_request_mask is '$user_save' expected 'RESTORE'"
1884 [ "$group_save" == RESTORE ] ||
1885 error "group_request_mask is '$group_save' expected 'RESTORE'"
1886 [ "$other_save" == RESTORE ] ||
1887 error "other_request_mask is '$other_save' expected 'RESTORE'"
1890 create_small_file $file
1891 chown $RUNAS_ID:$GROUP $file ||
1892 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1894 $RUNAS $LFS hsm_$action $file &&
1895 error "$action by user should fail"
1897 set_hsm_param user_request_mask $action
1898 $RUNAS $LFS hsm_$action $file ||
1899 error "$action by user should succeed"
1902 create_small_file $file
1903 chown nobody:$RUNAS_GID $file ||
1904 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1906 $RUNAS $LFS hsm_$action $file &&
1907 error "$action by group should fail"
1909 set_hsm_param group_request_mask $action
1910 $RUNAS $LFS hsm_$action $file ||
1911 error "$action by group should succeed"
1914 create_small_file $file
1915 chown nobody:$GROUP $file ||
1916 error "cannot chown '$file' to 'nobody:$GROUP'"
1918 $RUNAS $LFS hsm_$action $file &&
1919 error "$action by other should fail"
1921 set_hsm_param other_request_mask $action
1922 $RUNAS $LFS hsm_$action $file ||
1923 error "$action by other should succeed"
1925 run_test 24c "check that user,group,other request masks work"
1928 local file1=$DIR/$tdir/$tfile
1929 local file2=$DIR2/$tdir/$tfile
1933 mkdir_on_mdt0 $DIR/$tdir
1935 fid1=$(create_small_file $file1)
1938 $LFS getstripe $file1
1940 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1941 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1942 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1944 copytool setup -m "$MOUNT3"
1946 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1947 mount -o remount,ro $MOUNT2
1949 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1951 fid2=$(path2fid $file2)
1952 [ "$fid1" == "$fid2" ] ||
1953 error "FID mismatch '$fid1' != '$fid2'"
1955 $LFS hsm_archive $file2 &&
1956 error "archive should fail on read-only mount"
1957 check_hsm_flags $file1 "0x00000000"
1959 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1960 wait_request_state $fid1 ARCHIVE SUCCEED
1962 $LFS hsm_release $file1
1963 $LFS hsm_restore $file2
1964 wait_request_state $fid1 RESTORE SUCCEED
1966 $LFS hsm_release $file1 || error "cannot release '$file1'"
1967 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1969 $LFS hsm_release $file2 &&
1970 error "release should fail on read-only mount"
1974 run_test 24d "check that read-only mounts are respected"
1978 mkdir_on_mdt0 $DIR/$tdir
1980 local f=$DIR/$tdir/$tfile
1983 fid=$(create_small_file $f) || error "cannot create $f"
1984 $LFS hsm_archive $f || error "cannot archive $f"
1985 wait_request_state $fid ARCHIVE SUCCEED
1986 $LFS hsm_release $f || error "cannot release $f"
1987 while ! $LFS hsm_state $f | grep released; do
1991 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1993 run_test 24e "tar succeeds on HSM released files" # LU-6213
1996 # test needs a running copytool
1998 mkdir_on_mdt0 $DIR/$tdir
2000 mkdir -p $DIR/$tdir/d1
2001 local f=$DIR/$tdir/$tfile
2002 local fid=$(copy_file /etc/hosts $f)
2005 $LFS hsm_archive $f ||
2006 error "hsm_archive failed"
2007 wait_request_state $fid ARCHIVE SUCCEED
2008 $LFS hsm_release $f || error "cannot release $f"
2009 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2012 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2013 error "Can not recover the tar contents"
2015 echo "Sum0 = $sum0, sum1 = $sum1"
2016 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2018 run_test 24f "root can archive, release, and restore tar files"
2021 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2022 skip "need MDS version 2.11.56 or later"
2024 local file=$DIR/$tdir/$tfile
2027 echo "RUNAS = '$RUNAS'"
2031 mkdir_on_mdt0 $DIR/$tdir
2032 chmod ugo+rwx $DIR/$tdir
2034 echo "Please listen carefully as our options have changed." | tee $file
2035 fid=$(path2fid $file)
2038 $LFS hsm_archive $file
2039 wait_request_state $fid ARCHIVE SUCCEED
2040 check_hsm_flags $file 0x00000009 # exists archived
2042 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2043 check_hsm_flags $file 0x0000000b # exists dirty archived
2045 run_test 24g "write by non-owner still sets dirty" # LU-11369
2048 # test needs a running copytool
2052 copy2archive /etc/hosts $tdir/$tfile
2054 local f=$DIR/$tdir/$tfile
2056 copytool import $tdir/$tfile $f
2058 $LFS hsm_set --lost $f
2063 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2065 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2066 " (Operation not permitted)"
2069 # test needs a running copytool
2072 mkdir_on_mdt0 $DIR/$tdir
2074 local f=$DIR/$tdir/$tfile
2075 local fid=$(copy_file /etc/passwd $f)
2077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2078 wait_request_state $fid ARCHIVE SUCCEED
2081 $LFS hsm_set --lost $f
2085 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2087 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2088 " (Operation not permitted)"
2090 test_26A() { # was test_26
2091 # test needs a running copytool
2093 mkdir_on_mdt0 $DIR/$tdir
2095 local f=$DIR/$tdir/$tfile
2096 local fid=$(create_empty_file "$f")
2098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2099 wait_request_state $fid ARCHIVE SUCCEED
2102 wait_request_state $fid REMOVE SUCCEED
2104 check_hsm_flags $f "0x00000000"
2106 run_test 26A "Remove the archive of a valid file"
2109 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2110 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2112 # test needs a running copytool
2114 mkdir_on_mdt0 $DIR/$tdir
2116 local f=$DIR/$tdir/$tfile
2117 local fid=$(copy_file /etc/passwd $f)
2119 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2120 wait_request_state $fid ARCHIVE SUCCEED
2122 local f2=$DIR/$tdir/${tfile}_2
2123 local fid2=$(copy_file /etc/passwd $f2)
2125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2126 wait_request_state $fid2 ARCHIVE SUCCEED
2128 local f3=$DIR/$tdir/${tfile}_3
2129 local fid3=$(copy_file /etc/passwd $f3)
2131 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2132 wait_request_state $fid3 ARCHIVE SUCCEED
2134 # set a long grace_delay vs short loop_period
2135 local orig_loop_period=$(get_hsm_param loop_period)
2136 local orig_grace_delay=$(get_hsm_param grace_delay)
2137 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2138 set_hsm_param loop_period 10
2139 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2140 set_hsm_param grace_delay 100
2144 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2145 set_hsm_param remove_archive_on_last_unlink 1
2147 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2152 wait_request_state $fid2 REMOVE SUCCEED
2154 assert_request_count $fid REMOVE 0 \
2155 "Unexpected archived data remove request for $f"
2156 assert_request_count $fid3 REMOVE 0 \
2157 "Unexpected archived data remove request for $f3"
2159 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2162 # test needs a running copytool
2164 mkdir_on_mdt0 $DIR/$tdir
2166 local f=$DIR/$tdir/$tfile
2167 local fid=$(copy_file /etc/passwd $f)
2169 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2170 wait_request_state $fid ARCHIVE SUCCEED
2172 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2173 set_hsm_param remove_archive_on_last_unlink 1
2176 cdt_check_state stopped
2180 wait_request_state $fid REMOVE WAITING
2184 # copytool must re-register
2186 wait_copytools || error "copytool failed to stop"
2189 wait_request_state $fid REMOVE SUCCEED
2191 run_test 26b "RAoLU policy when CDT off"
2194 # test needs a running copytool
2196 mkdir_on_mdt0 $DIR/$tdir
2198 local f=$DIR/$tdir/$tfile
2199 local fid=$(copy_file /etc/passwd $f)
2201 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2202 wait_request_state $fid ARCHIVE SUCCEED
2204 local f2=$DIR/$tdir/${tfile}_2
2205 local fid2=$(copy_file /etc/passwd $f2)
2207 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2208 wait_request_state $fid2 ARCHIVE SUCCEED
2210 # set a long grace_delay vs short loop_period
2211 local orig_loop_period=$(get_hsm_param loop_period)
2212 local orig_grace_delay=$(get_hsm_param grace_delay)
2213 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2214 set_hsm_param loop_period 10
2215 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2216 set_hsm_param grace_delay 100
2218 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2219 set_hsm_param remove_archive_on_last_unlink 1
2221 multiop_bg_pause $f O_c || error "open $f failed"
2227 wait_request_state $fid2 REMOVE SUCCEED
2228 assert_request_count $fid REMOVE 0 \
2229 "Unexpected archived data remove request for $f"
2231 kill -USR1 $pid || error "multiop early exit"
2232 # should reach autotest timeout if multiop fails to trap
2233 # signal, close file, and exit ...
2234 wait $pid || error "wait PID $PID failed"
2236 wait_request_state $fid REMOVE SUCCEED
2238 run_test 26c "RAoLU effective when file closed"
2241 # test needs a running copytool
2243 mkdir_on_mdt0 $DIR/$tdir
2245 local f=$DIR/$tdir/$tfile
2246 local fid=$(create_small_file $f)
2248 $LFS hsm_archive $f || error "could not archive file"
2249 wait_request_state $fid ARCHIVE SUCCEED
2251 # set a long grace_delay vs short loop_period
2252 local orig_loop_period=$(get_hsm_param loop_period)
2253 local orig_grace_delay=$(get_hsm_param grace_delay)
2254 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2255 set_hsm_param loop_period 10
2256 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2257 set_hsm_param grace_delay 100
2259 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2260 set_hsm_param remove_archive_on_last_unlink 1
2262 multiop_bg_pause $f O_c || error "multiop failed"
2269 wait_request_state $fid REMOVE SUCCEED
2271 client_up || client_up || true
2273 kill -USR1 $MULTIPID
2274 wait $MULTIPID || error "multiop close failed"
2276 run_test 26d "RAoLU when Client eviction"
2279 # test needs a running copytool
2282 create_archive_file $tdir/$tfile
2283 local f=$DIR/$tdir/$tfile
2284 copytool import $tdir/$tfile $f
2285 local fid=$(path2fid $f)
2289 [[ $? != 0 ]] || error "Remove of a released file should fail"
2291 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2294 # test needs a running copytool
2296 mkdir_on_mdt0 $DIR/$tdir
2298 local f=$DIR/$tdir/$tfile
2299 local fid=$(create_empty_file "$f")
2301 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2302 wait_request_state $fid ARCHIVE SUCCEED
2307 [[ $? != 0 ]] || error "Remove of a released file should fail"
2309 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2312 # test needs a running copytool
2314 mkdir_on_mdt0 $DIR/$tdir
2316 local f=$DIR/$tdir/$tfile
2317 local fid=$(create_empty_file "$f")
2319 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2320 wait_request_state $fid ARCHIVE SUCCEED
2329 wait_request_state $fid REMOVE SUCCEED
2331 run_test 28 "Concurrent archive/file remove"
2334 # Tests --mntpath and --archive options
2337 copytool setup -m "$MOUNT" -a $archive_id
2339 # Bad archive number
2340 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2341 grep "Invalid argument" ||
2342 error "unexpected hsm_remove failure (1)"
2344 # mntpath is present but file is given
2345 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2346 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2347 error "unexpected hsm_remove failure (2)"
2349 run_test 29a "Tests --mntpath and --archive options"
2352 # test needs a running copytool
2354 mkdir_on_mdt0 $DIR/$tdir
2356 local f=$DIR/$tdir/$tfile
2357 local fid=$(create_small_file $f)
2359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2360 wait_request_state $fid ARCHIVE SUCCEED
2364 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2365 wait_request_state $fid REMOVE SUCCEED
2367 run_test 29b "Archive/delete/remove by FID from the archive."
2370 # test needs a running copytool
2372 mkdir_on_mdt0 $DIR/$tdir
2374 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2375 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2376 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2378 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2379 wait_request_state $fid1 ARCHIVE SUCCEED
2380 wait_request_state $fid2 ARCHIVE SUCCEED
2381 wait_request_state $fid3 ARCHIVE SUCCEED
2383 rm -f $DIR/$tdir/$tfile-[1-3]
2385 echo $fid1 > $DIR/$tdir/list
2386 echo $fid2 >> $DIR/$tdir/list
2387 echo $fid3 >> $DIR/$tdir/list
2389 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2390 --filelist $DIR/$tdir/list
2391 wait_request_state $fid1 REMOVE SUCCEED
2392 wait_request_state $fid2 REMOVE SUCCEED
2393 wait_request_state $fid3 REMOVE SUCCEED
2395 run_test 29c "Archive/delete/remove by FID, using a file list."
2398 # test needs more than one CT
2399 needclients 3 || return 0
2405 # start all of the copytools
2406 for n in $(seq $AGTCOUNT); do
2407 copytool setup -f agt$n -a $n
2410 mkdir_on_mdt0 $DIR/$tdir
2413 file=$DIR/$tdir/$tfile
2414 fid=$(create_small_file $file)
2416 $LFS hsm_archive $file
2417 wait_request_state $fid ARCHIVE SUCCEED
2418 check_hsm_flags $file "0x00000009"
2422 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2423 error "cannot hsm_remove '$fid'"
2425 # give time for CDT to handle remove request and create broadcasted
2428 # remove request has been broadcasted ?
2429 local cnt=$(get_request_count $fid REMOVE)
2430 # broadcasted requests + original
2431 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2432 error "remove not broadcasted to all CTs"
2434 # give time for CDT and CTs to handle broadcasted
2435 wait_for_loop_period
2437 # each agent serves one different archive_id, so broadcasted
2438 # hsm_remove request should only succeed once and fail at all others
2442 for n in $(seq $AGTCOUNT); do
2443 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2444 $HSM_PARAM.actions | awk \
2445 '/'$fid'.*action=REMOVE archive#='$n'/ \
2446 {print \\\$13}' | cut -f2 -d=")
2447 if [[ "$res" == "SUCCEED" ]]; then
2449 elif [[ "$res" == "FAILED" ]]; then
2454 [[ $scnt -eq 1 ]] ||
2455 error "one and only CT should have removed successfully"
2457 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2458 error "all but one CT should have failed to remove"
2460 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2461 "request to be sent once for each registered archive_id"
2464 # restore at exec cannot work on agent node (because of Linux kernel
2465 # protection of executables)
2466 needclients 2 || return 0
2468 # test needs a running copytool
2472 copy2archive /bin/true $tdir/$tfile
2474 local f=$DIR/$tdir/true
2475 copytool import $tdir/$tfile $f
2477 local fid=$(path2fid $f)
2479 stack_trap "cdt_clear_no_retry" EXIT
2480 # set no retry action mode
2487 [[ $st == 0 ]] || error "Failed to exec a released file"
2489 run_test 30a "Restore at exec (import case)"
2492 # restore at exec cannot work on agent node (because of Linux kernel
2493 # protection of executables)
2494 needclients 2 || return 0
2496 # test needs a running copytool
2499 mkdir_on_mdt0 $DIR/$tdir
2500 local f=$DIR/$tdir/true
2501 local fid=$(copy_file /bin/true $f)
2503 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2504 wait_request_state $fid ARCHIVE SUCCEED
2508 stack_trap cdt_clear_no_retry EXIT
2509 # set no retry action mode
2517 [[ $st == 0 ]] || error "Failed to exec a released file"
2519 run_test 30b "Restore at exec (release case)"
2522 needclients 2 || return 0
2524 # test needs a running copytool
2527 mkdir_on_mdt0 $DIR/$tdir
2528 local f=$DIR/$tdir/SLEEP
2529 local slp_sum1=$(md5sum /bin/sleep)
2530 local fid=$(copy_file /bin/sleep $f)
2532 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2533 wait_request_state $fid ARCHIVE SUCCEED
2535 check_hsm_flags $f "0x0000000d"
2537 stack_trap cdt_clear_no_retry EXIT
2538 # set no retry action mode
2541 do_node $CLIENT2 "$f 10" &
2545 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2547 [[ $? == 0 ]] || error "Execution failed during run"
2549 if [[ $? != 0 ]]; then
2550 local slp_sum2=$(md5sum /bin/sleep)
2551 # in case sleep file is modified during the test
2552 [[ $slp_sum1 == $slp_sum2 ]] &&
2553 error "Binary overwritten during exec"
2556 check_hsm_flags $f "0x00000009"
2558 run_test 30c "Update during exec of released file must fail"
2560 restore_and_check_size() {
2563 local s=$(stat -c "%s" $f)
2565 local st=$(get_hsm_flags $f)
2569 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2571 n=$(stat -c "%s" $f)
2572 # we echo in both cases to show stat is not hang
2573 if [[ $n != $s ]]; then
2574 echo "size seen is $n != $s"
2577 echo "size seen is right: $n == $s"
2581 st=$(get_hsm_flags $f)
2583 if [[ "$st" = "0x00000009" ]]; then
2586 echo " restore is too long"
2587 wait_request_state $fid RESTORE SUCCEED
2593 # test needs a running copytool
2595 mkdir_on_mdt0 $DIR/$tdir
2597 create_archive_file $tdir/$tfile
2598 local f=$DIR/$tdir/$tfile
2599 copytool import $tdir/$tfile $f
2600 local fid=$($LFS path2fid $f)
2603 restore_and_check_size $f $fid
2606 [[ $err -eq 0 ]] || error "File size changed during restore"
2608 run_test 31a "Import a large file and check size during restore"
2612 # test needs a running copytool
2614 mkdir_on_mdt0 $DIR/$tdir
2616 local f=$DIR/$tdir/$tfile
2617 local fid=$(create_file "$f" 1MB 39)
2619 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2620 wait_request_state $fid ARCHIVE SUCCEED
2623 restore_and_check_size $f $fid
2626 [[ $err -eq 0 ]] || error "File size changed during restore"
2628 run_test 31b "Restore a large unaligned file and check size during restore"
2631 # test needs a running copytool
2633 mkdir_on_mdt0 $DIR/$tdir
2635 local f=$DIR/$tdir/$tfile
2636 local fid=$(create_file "$f" 1M 39)
2638 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2639 wait_request_state $fid ARCHIVE SUCCEED
2642 restore_and_check_size $f $fid
2645 [[ $err -eq 0 ]] || error "File size changed during restore"
2647 run_test 31c "Restore a large aligned file and check size during restore"
2650 local f=$DIR/$tdir/$tfile
2652 mkdir_on_mdt0 $DIR/$tdir
2653 local fid=$(create_empty_file "$f")
2657 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2658 wait_request_state $fid ARCHIVE SUCCEED
2661 # Prevent restore from completing
2665 md5sum $f >/dev/null &
2668 wait_request_state $fid RESTORE STARTED
2673 # Check restore trigger process was killed
2675 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2677 run_test 33 "Kill a restore waiting process"
2680 # test needs a running copytool
2682 mkdir_on_mdt0 $DIR/$tdir
2684 local f=$DIR/$tdir/$tfile
2685 local fid=$(create_empty_file "$f")
2687 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2688 wait_request_state $fid ARCHIVE SUCCEED
2691 # Prevent restore from completing
2694 md5sum $f >/dev/null &
2697 wait_request_state $fid RESTORE STARTED
2699 # rm must not block during restore
2700 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2703 wait_request_state $fid RESTORE SUCCEED
2705 # Check md5sum pgm finished
2706 kill -0 $pid && error "Restore initiatior still running"
2707 wait $pid || error "Restore initiator failed with $?"
2709 # Check the file was actually deleted
2710 [ ! -f "$f" ] || error "$f was not deleted"
2712 run_test 34 "Remove file during restore"
2715 # test needs a running copytool
2717 mkdir_on_mdt0 $DIR/$tdir
2719 local f=$DIR/$tdir/$tfile
2720 local f1=$DIR/$tdir/$tfile-1
2721 local fid=$(create_empty_file "$f")
2722 local fid1=$(copy_file /etc/passwd $f1)
2724 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2725 wait_request_state $fid ARCHIVE SUCCEED
2728 # Prevent restore from completing
2731 md5sum $f >/dev/null &
2734 wait_request_state $fid RESTORE STARTED
2736 # mv must not block during restore
2737 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2740 wait_request_state $fid RESTORE SUCCEED
2742 # Check md5sum pgm finished
2743 kill -0 $pid && error "Restore initiatior still running"
2744 wait $pid || error "Restore initiator failed with $?"
2746 local fid2=$(path2fid $f)
2747 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2749 run_test 35 "Overwrite file during restore"
2752 # test needs a running copytool
2754 mkdir_on_mdt0 $DIR/$tdir
2756 local f=$DIR/$tdir/$tfile
2757 local fid=$(create_empty_file "$f")
2759 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2760 wait_request_state $fid ARCHIVE SUCCEED
2763 # Prevent restore from completing
2766 md5sum $f >/dev/null &
2769 wait_request_state $fid RESTORE STARTED
2771 # mv must not block during restore
2772 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2773 error "mv '$f' '$f.new' failed with rc=$?"
2776 wait_request_state $fid RESTORE SUCCEED
2778 # Check md5sum pgm finished
2779 kill -0 $pid && error "Restore initiator is still running"
2780 wait $pid || error "Restore initiator failed with $?"
2782 run_test 36 "Move file during restore"
2785 # LU-5683: check that an archived dirty file can be rearchived.
2787 mkdir_on_mdt0 $DIR/$tdir
2789 local f=$DIR/$tdir/$tfile
2792 fid=$(create_small_file $f) || error "cannot create small file"
2794 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2795 wait_request_state $fid ARCHIVE SUCCEED
2796 $LFS hsm_release $f || error "cannot release $f"
2798 # Allow previous archive request to expire from the actions log.
2799 wait_for_grace_delay
2802 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2804 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2805 wait_request_state $fid ARCHIVE SUCCEED
2807 run_test 37 "re-archive a dirty file"
2814 for n in $(seq 1 $count); do
2815 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2817 echo "$count archive requests submitted"
2821 local stream_count=4
2822 local file_count=100
2824 local f=$DIR/$tdir/$tfile
2828 local max_requests=$(get_hsm_param max_requests)
2830 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2831 # Increase the number of HSM request that can be performed in
2832 # parallel. With the coordinator running once per second, this
2833 # also limits the number of requests per seconds that can be
2834 # performed, so we pick a decent number. But we also need to keep
2835 # that number low because the copytool has no rate limit and will
2836 # fail some requests if if gets too many at once.
2837 set_hsm_param max_requests 300
2839 for i in $(seq 1 $file_count); do
2840 for p in $(seq 1 $stream_count); do
2841 fid=$(copy_file /etc/hosts $f.$p.$i)
2847 # to be sure wait_all_done will not be mislead by previous tests
2849 wait_for_grace_delay
2851 # start archive streams in background (archive files in parallel)
2852 for p in $(seq 1 $stream_count); do
2853 multi_archive $f.$p $file_count &
2856 echo -n "Wait for all requests being enqueued..."
2861 run_test 40 "Parallel archive requests"
2863 hsm_archive_batch() {
2871 while [ $i -lt $files_num ]; do
2872 if [ $batch_num -eq $batch_max ]; then
2873 $LFS hsm_archive $fileset || error "HSM archive failed"
2874 # Reset the batch container.
2879 fileset+="${filebase}$i "
2880 batch_num=$(( batch_num + 1 ))
2884 if [ $batch_num -ne 0 ]; then
2885 $LFS hsm_archive $fileset || error "HSM archive failed"
2892 local dir=$DIR/$tdir
2895 set_hsm_param max_requests 1000000
2896 mkdir $dir || error "mkdir $dir failed"
2905 filebase="$dir/$tfile.start."
2906 createmany -m $filebase $files_num ||
2907 error "createmany -m $filebase failed: $?"
2910 hsm_archive_batch $files_num $batch_max "$filebase"
2911 elapsed=$((SECONDS - start))
2912 do_facet $SINGLEMDS "$LCTL get_param -n \
2913 $HSM_PARAM.actions | grep WAITING | wc -l"
2914 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2915 echo "Start Phase files_num: $files_num time: $elapsed"
2918 filebase="$dir/$tfile.in."
2919 createmany -m $filebase $files_num ||
2920 error "createmany -m $filebase failed: $?"
2922 hsm_archive_batch $files_num $batch_max "$filebase"
2923 elapsed=$((SECONDS - start))
2924 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2925 echo "Middle Phase files_num: $files_num time: $elapsed"
2928 filebase="$dir/$tfile.end."
2929 createmany -m $filebase $files_num ||
2930 error "createmany -m $filebase failed: $?"
2933 hsm_archive_batch $files_num $batch_max "$filebase"
2934 elapsed=$((SECONDS - start))
2935 do_facet $SINGLEMDS "$LCTL get_param -n \
2936 $HSM_PARAM.actions | grep WAITING | wc -l"
2938 unlinkmany $filebase $files_num || error "unlinkmany $filebase failed"
2939 echo "End Phase files_num: $files_num time: $elapsed"
2941 do_facet $SINGLEMDS "$LCTL get_param -n \
2942 $HSM_PARAM.actions | grep WAITING | wc -l"
2946 run_test 50 "Archive with large number of pending HSM actions"
2949 # test needs a running copytool
2952 mkdir_on_mdt0 $DIR/$tdir
2953 local f=$DIR/$tdir/$tfile
2954 local fid=$(create_small_file $f)
2956 $LFS hsm_archive $f || error "could not archive file"
2957 wait_request_state $fid ARCHIVE SUCCEED
2958 check_hsm_flags $f "0x00000009"
2960 multiop_bg_pause $f O_c || error "multiop failed"
2964 client_up || client_up || true
2966 kill -USR1 $MULTIPID
2967 wait $MULTIPID || error "multiop close failed"
2969 check_hsm_flags $f "0x0000000b"
2971 run_test 52 "Opened for write file on an evicted client should be set dirty"
2974 # test needs a running copytool
2977 mkdir_on_mdt0 $DIR/$tdir
2978 local f=$DIR/$tdir/$tfile
2979 local fid=$(create_small_file $f)
2981 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2982 error "could not archive file"
2983 wait_request_state $fid ARCHIVE SUCCEED
2984 check_hsm_flags $f "0x00000009"
2986 multiop_bg_pause $f o_c || error "multiop failed"
2990 client_up || client_up || true
2992 kill -USR1 $MULTIPID
2993 wait $MULTIPID || error "multiop close failed"
2995 check_hsm_flags $f "0x00000009"
2997 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3000 mkdir_on_mdt0 $DIR/$tdir
3002 local f=$DIR/$tdir/$tfile
3003 local fid=$(create_file "$f" 1MB 39)
3007 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3008 error "could not archive file"
3009 wait_request_state $fid ARCHIVE STARTED
3011 check_hsm_flags $f "0x00000001"
3013 stack_trap "cdt_clear_no_retry" EXIT
3014 # Avoid coordinator resending this request as soon it has failed.
3019 wait_request_state $fid ARCHIVE FAILED
3021 check_hsm_flags $f "0x00000003"
3023 run_test 54 "Write during an archive cancels it"
3026 mkdir_on_mdt0 $DIR/$tdir
3028 local f=$DIR/$tdir/$tfile
3029 local fid=$(create_file "$f" 1MB 39)
3033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3034 error "could not archive file"
3035 wait_request_state $fid ARCHIVE STARTED
3037 check_hsm_flags $f "0x00000001"
3039 stack_trap "cdt_clear_no_retry" EXIT
3040 # Avoid coordinator resending this request as soon it has failed.
3043 $TRUNCATE $f 1024 || error "truncate failed"
3045 wait_request_state $fid ARCHIVE FAILED
3047 check_hsm_flags $f "0x00000003"
3049 run_test 55 "Truncate during an archive cancels it"
3052 mkdir_on_mdt0 $DIR/$tdir
3054 local f=$DIR/$tdir/$tfile
3055 local fid=$(create_file "$f" 1MB 39)
3059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3060 error "could not archive file"
3061 wait_request_state $fid ARCHIVE STARTED
3063 check_hsm_flags $f "0x00000001"
3065 # Change metadata and sync to be sure we are not changing only
3070 wait_request_state $fid ARCHIVE SUCCEED
3072 check_hsm_flags $f "0x00000009"
3074 run_test 56 "Setattr during an archive is ok"
3077 # Need one client for I/O, one for request
3078 needclients 2 || return 0
3080 # test needs a running copytool
3083 mkdir_on_mdt0 $DIR/$tdir
3084 local f=$DIR/$tdir/test_archive_remote
3085 # Create a file on a remote node
3086 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3087 "count=2 conv=fsync"
3090 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3091 error "hsm_archive failed"
3092 local fid=$(path2fid $f)
3093 wait_request_state $fid ARCHIVE SUCCEED
3095 # Release and implicit restore it
3096 do_node $CLIENT2 "$LFS hsm_release $f" ||
3097 error "hsm_release failed"
3098 do_node $CLIENT2 "md5sum $f" ||
3099 error "hsm_restore failed"
3101 wait_request_state $fid RESTORE SUCCEED
3103 run_test 57 "Archive a file with dirty cache on another node"
3105 truncate_released_file() {
3109 local sz=$(stat -c %s $src_file)
3110 local f=$DIR/$tdir/$tfile
3111 local fid=$(copy_file $1 $f)
3115 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3116 error "could not archive file"
3117 wait_request_state $fid ARCHIVE SUCCEED
3119 $LFS hsm_release $f || error "could not release file"
3121 $TRUNCATE $f $trunc_to || error "truncate failed"
3124 local sz1=$(stat -c %s $f)
3125 [[ $sz1 == $trunc_to ]] ||
3126 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3129 check_hsm_flags $f "0x0000000b"
3131 local state=$(get_request_state $fid RESTORE)
3132 [[ "$state" == "SUCCEED" ]] ||
3133 error "truncate $sz does not trig restore, state = $state"
3135 $TRUNCATE $ref $trunc_to
3136 cmp $ref $f || error "file data wrong after truncate"
3142 # test needs a running copytool
3145 mkdir_on_mdt0 $DIR/$tdir
3147 local sz=$(stat -c %s /etc/passwd)
3149 echo "truncate up from $sz to $((sz*2))"
3150 truncate_released_file /etc/passwd $((sz*2))
3152 echo "truncate down from $sz to $((sz/2))"
3153 truncate_released_file /etc/passwd $((sz/2))
3155 echo "truncate to 0"
3156 truncate_released_file /etc/passwd 0
3158 run_test 58 "Truncate a released file will trigger restore"
3162 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3163 skip "Need MDS version at least 2.7.63"
3166 $MCREATE $DIR/$tfile || error "mcreate failed"
3167 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3168 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3169 fid=$(path2fid $DIR/$tfile)
3170 wait_request_state $fid ARCHIVE SUCCEED
3171 $LFS hsm_release $DIR/$tfile || error "release failed"
3173 run_test 59 "Release stripeless file with non-zero size"
3176 # This test validates the fix for LU-4512. Ensure that the -u
3177 # option changes the progress reporting interval from the
3178 # default (30 seconds) to the user-specified interval.
3179 mkdir_on_mdt0 $DIR/$tdir
3181 local f=$DIR/$tdir/$tfile
3182 local fid=$(create_file "$f" 1M 10)
3185 local progress_timeout=$((interval * 4))
3186 copytool setup -b 1 --update-interval $interval
3189 local mdt=${MDT_PREFIX}${mdtidx}
3190 local mds=mds$((mdtidx + 1))
3192 # Wait for copytool to register
3193 wait_update_facet $mds \
3194 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3195 uuid 100 || error "coyptool failed to register with $mdt"
3197 local start_at=$(date +%s)
3198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3199 error "could not archive file"
3201 local agent=$(facet_active_host $SINGLEAGT)
3202 local logfile=$(copytool_logfile $SINGLEAGT)
3204 wait_update $agent \
3205 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3206 error "copytool failed to start"
3208 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3209 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3215 echo -n "Expecting a progress update within $progress_timeout seconds... "
3217 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3218 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3219 echo "$RESULT bytes copied in $WAIT seconds."
3221 elif [ $WAIT -ge $progress_timeout ]; then
3222 error "Timed out waiting for progress update!"
3225 WAIT=$((WAIT + sleep))
3229 local finish_at=$(date +%s)
3230 local elapsed=$((finish_at - start_at))
3232 # Ensure that the progress update occurred within the expected window.
3233 if [ $elapsed -lt $((interval - 1)) ]; then
3234 error "Expected progress update after at least $interval seconds"
3237 echo "Wait for on going archive hsm action to complete"
3238 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3239 echo "File archiving not completed even after 10 secs"
3241 run_test 60 "Changing progress update interval from default"
3244 # test needs a running copytool
3247 mkdir_on_mdt0 $DIR/$tdir
3248 local f=$DIR/$tdir/$tfile
3249 local fid=$(copy_file /etc/passwd $f)
3251 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3254 wait_request_state $fid ARCHIVE FAILED
3256 run_test 61 "Waiting archive of a removed file should fail"
3259 # test needs a new running copytool
3260 stack_trap copytool_monitor_cleanup EXIT
3261 copytool_monitor_setup
3262 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3264 # Wait for the copytool to register.
3265 wait_update --verbose $(facet_active_host mds1) \
3266 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3268 error "copytool failed to register with MDT0000"
3271 wait_copytools || error "Copytools failed to stop"
3273 local REGISTER_EVENT
3274 local UNREGISTER_EVENT
3275 while read event; do
3276 local parsed=$(parse_json_event "$event")
3277 if [ -z "$parsed" ]; then
3278 error "Copytool sent malformed event: $event"
3282 if [ $event_type == "REGISTER" ]; then
3283 REGISTER_EVENT=$event
3284 elif [ $event_type == "UNREGISTER" ]; then
3285 UNREGISTER_EVENT=$event
3287 done < <(echo $"$(get_copytool_event_log)")
3289 if [ -z "$REGISTER_EVENT" ]; then
3290 error "Copytool failed to send register event to FIFO"
3293 if [ -z "$UNREGISTER_EVENT" ]; then
3294 error "Copytool failed to send unregister event to FIFO"
3297 echo "Register/Unregister events look OK."
3299 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3302 # Bump progress interval for livelier events.
3305 # test needs a new running copytool
3306 stack_trap copytool_monitor_cleanup EXIT
3307 copytool_monitor_setup
3308 copytool setup --update-interval $interval --event-fifo \
3309 "$HSMTOOL_MONITOR_DIR/fifo"
3311 stack_trap "cdt_clear_no_retry" EXIT
3312 # Just start and stop the copytool to generate events.
3315 mkdir_on_mdt0 $DIR/$tdir
3317 local f=$DIR/$tdir/$tfile
3318 local fid=$(create_small_file "$f")
3320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3321 error "could not archive file"
3322 wait_request_state $fid ARCHIVE SUCCEED
3324 local expected_fields="event_time data_fid source_fid"
3325 expected_fields+=" total_bytes current_bytes"
3328 [ARCHIVE_START]=false
3329 [ARCHIVE_FINISH]=false
3330 [ARCHIVE_RUNNING]=false
3332 while read event; do
3333 # Make sure we're not getting anything from previous events.
3334 for field in $expected_fields; do
3338 local parsed=$(parse_json_event "$event")
3339 if [ -z "$parsed" ]; then
3340 error "Copytool sent malformed event: $event"
3344 events["$event_type"]=true
3346 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3348 # Do some simple checking of the progress update events.
3349 for expected_field in $expected_fields; do
3350 if [ -z ${!expected_field+x} ]; then
3351 error "Missing $expected_field field in event"
3355 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3357 # These should be identical throughout an archive operation
3358 [ $source_fid == $data_fid ] ||
3359 error "Expected source_fid to equal data_fid"
3360 done < <(echo $"$(get_copytool_event_log)")
3362 # Check we received every type of events we were expecting
3363 for event in "${!events[@]}"; do
3364 ${events["$event"]} ||
3365 error "Copytool failed to send '$event' event to FIFO"
3368 echo "Archive events look OK."
3370 run_test 71 "Copytool logs JSON archive events to FIFO"
3373 # Bump progress interval for livelier events.
3376 # test needs a new running copytool
3377 stack_trap copytool_monitor_cleanup EXIT
3378 copytool_monitor_setup
3379 copytool setup --update-interval $interval --event-fifo \
3380 "$HSMTOOL_MONITOR_DIR/fifo"
3381 local test_file=$HSMTOOL_MONITOR_DIR/file
3383 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3385 do_facet $SINGLEAGT "$cmd" ||
3386 error "cannot create $test_file on $SINGLEAGT"
3387 copy2archive $test_file $tdir/$tfile
3389 mkdir_on_mdt0 $DIR/$tdir
3390 local f=$DIR/$tdir/$tfile
3391 copytool import $tdir/$tfile $f
3392 f=$DIR2/$tdir/$tfile
3393 echo "Verifying released state: "
3394 check_hsm_flags $f "0x0000000d"
3396 local fid=$(path2fid $f)
3398 wait_request_state $fid RESTORE SUCCEED
3400 local expected_fields="event_time data_fid source_fid"
3401 expected_fields+=" total_bytes current_bytes"
3405 while read event; do
3406 # Make sure we're not getting anything from previous events.
3407 for field in $expected_fields; do
3411 local parsed=$(parse_json_event "$event")
3412 if [ -z "$parsed" ]; then
3413 error "Copytool sent malformed event: $event"
3417 if [ $event_type == "RESTORE_START" ]; then
3419 if [ $source_fid != $data_fid ]; then
3420 error "source_fid should == data_fid at start"
3423 elif [ $event_type == "RESTORE_FINISH" ]; then
3425 if [ $source_fid != $data_fid ]; then
3426 error "source_fid should == data_fid at finish"
3429 elif [ $event_type != "RESTORE_RUNNING" ]; then
3433 # Do some simple checking of the progress update events.
3434 for expected_field in $expected_fields; do
3435 if [ -z ${!expected_field+x} ]; then
3436 error "Missing $expected_field field in event"
3440 if [ $total_bytes -eq 0 ]; then
3441 error "Expected total_bytes to be > 0"
3444 # When a restore starts out, the data fid is the same as the
3445 # source fid. After the restore has gotten going, we learn
3446 # the new data fid. Once the restore has finished, the source
3447 # fid is set to the new data fid.
3449 # We test this because some monitoring software may depend on
3450 # this behavior. If it changes, then the consumers of these
3451 # events may need to be modified.
3452 if [ $source_fid == $data_fid ]; then
3453 error "source_fid should != data_fid during restore"
3455 done < <(echo $"$(get_copytool_event_log)")
3457 if [ -z "$START_EVENT" ]; then
3458 error "Copytool failed to send restore start event to FIFO"
3461 if [ -z "$FINISH_EVENT" ]; then
3462 error "Copytool failed to send restore finish event to FIFO"
3465 echo "Restore events look OK."
3467 run_test 72 "Copytool logs JSON restore events to FIFO"
3470 file_count=51 # Max number of files constrained by LNET message size
3471 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3472 local f=$DIR/$tdir/$tfile
3473 local FILELIST=/tmp/filelist.txt
3477 for i in $(seq 1 $file_count); do
3478 fid=$(copy_file /etc/hosts $f.$i)
3479 echo $f.$i >> $FILELIST
3483 # to be sure wait_all_done will not be mislead by previous tests
3485 wait_for_grace_delay
3486 $LFS hsm_archive --filelist $FILELIST ||
3487 error "cannot archive a file list"
3489 $LFS hsm_release --filelist $FILELIST ||
3490 error "cannot release a file list"
3491 $LFS hsm_restore --filelist $FILELIST ||
3492 error "cannot restore a file list"
3495 run_test 90 "Archive/restore a file list"
3497 double_verify_reset_hsm_param() {
3499 echo "Testing $HSM_PARAM.$p"
3500 local val=$(get_hsm_param $p)
3502 local val2=$(($val * 2))
3503 set_hsm_param $p $val2
3504 val=$(get_hsm_param $p)
3505 [[ $val == $val2 ]] ||
3506 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3507 echo "Set $p to 0 must failed"
3511 set_hsm_param $p $save
3513 if [[ $rc == 0 ]]; then
3514 error "we must not be able to set $HSM_PARAM.$p to 0"
3519 double_verify_reset_hsm_param loop_period
3520 double_verify_reset_hsm_param grace_delay
3521 double_verify_reset_hsm_param active_request_timeout
3522 double_verify_reset_hsm_param max_requests
3523 double_verify_reset_hsm_param default_archive_id
3525 run_test 100 "Set coordinator /proc tunables"
3532 run_test 102 "Verify coordinator control"
3535 # test needs a running copytool
3542 for i in $(seq 1 20); do
3543 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3549 echo "Current requests"
3550 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3551 $HSM_PARAM.actions |\
3552 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3554 [[ -z "$res" ]] || error "Some request have not been canceled"
3556 run_test 103 "Purge all requests"
3559 (( MDS1_VERSION >= $(version_code 2.14.56) )) ||
3560 skip "Need MDS version at least 2.14.56"
3562 cdt_clear_non_blocking_restore
3564 # test needs a running copytool
3569 local rpcs_inflight=$($LCTL get_param -n \
3570 "mdc.$(facet_svc mds1)*.max_rpcs_in_flight" |
3573 mkdir_on_mdt0 $DIR/$tdir
3574 for ((i=0; i < rpcs_inflight; i++)); do
3575 fids+=( $(copy_file /etc/passwd $DIR/$tdir/${tfile}_$i) )
3577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3581 local grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=ARCHIVE.*status=SUCCEED"
3583 while [[ $time -lt 5 ]] && [[ $cnt -ne ${#fids[@]} ]]; do
3584 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3585 grep -c -E '$grep_regex'")
3589 [[ $cnt -eq ${#fids[@]} ]] || error "Fail to archive files $cnt/${#fids[@]}"
3591 $LFS hsm_release $DIR/$tdir/*
3594 wait_copytools || error "Copytool failed to stop"
3597 for i in "${fids[@]}"; do
3598 cat $DIR/.lustre/fid/$i > /dev/null & pids+=($!)
3602 grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=RESTORE.*status=CANCELED"
3603 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3604 grep -cE '$grep_regex'")
3606 [[ "$cnt" -eq ${#fids[@]} ]] ||
3607 error "Some request have not been canceled ($cnt/${#fids[@]} canceled)"
3609 # cat cmds should not hang and should fail
3610 for i in "${!pids[@]}"; do
3612 error "Restore for ${tfile}_$i (${pids[$i]}) should fail" ||
3616 run_test 103a "Purge pending restore requests"
3621 mkdir_on_mdt0 $DIR/$tdir
3623 local f=$DIR/$tdir/$tfile
3624 local fid=$(create_empty_file "$f")
3626 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3627 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3628 $HSM_PARAM.actions |\
3629 grep $fid | cut -f16 -d=")
3631 [[ "$data1" == "$DATAHEX" ]] ||
3632 error "Data field in records is ($data1) and not ($DATAHEX)"
3636 run_test 104 "Copy tool data field"
3639 local max_requests=$(get_hsm_param max_requests)
3640 mkdir_on_mdt0 $DIR/$tdir
3643 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3644 set_hsm_param max_requests 300
3647 for i in $(seq -w 1 10); do
3648 cp /etc/passwd $DIR/$tdir/$i
3649 $LFS hsm_archive $DIR/$tdir/$i
3651 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3652 $HSM_PARAM.actions |\
3653 grep WAITING | wc -l")
3657 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3658 $HSM_PARAM.actions |\
3659 grep WAITING | wc -l")
3662 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3663 error "Requests count after shutdown $reqcnt2 != "\
3664 "before shutdown $reqcnt1"
3666 run_test 105 "Restart of coordinator"
3669 # test needs a running copytool
3672 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3674 check_agent_registered $uuid
3676 search_copytools || error "No copytool found"
3679 wait_copytools || error "Copytool failed to stop"
3681 check_agent_unregistered $uuid
3684 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3685 check_agent_registered $uuid
3687 run_test 106 "Copytool register/unregister"
3690 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3692 # test needs a running copytool
3694 # create and archive file
3695 mkdir_on_mdt0 $DIR/$tdir
3696 local f1=$DIR/$tdir/$tfile
3697 local fid=$(copy_file /etc/passwd $f1)
3698 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3699 wait_request_state $fid ARCHIVE SUCCEED
3700 # shutdown and restart MDS
3702 # check the copytool still gets messages from MDT
3703 local f2=$DIR/$tdir/2
3704 local fid=$(copy_file /etc/passwd $f2)
3705 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3706 # main check of this sanity: this request MUST succeed
3707 wait_request_state $fid ARCHIVE SUCCEED
3709 run_test 107 "Copytool re-register after MDS restart"
3711 policy_set_and_test()
3715 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3716 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3717 [[ "$policy" == "$target" ]] ||
3718 error "Wrong policy after '$change': '$policy' != '$target'"
3722 # to force default policy setting if error
3723 CDT_POLICY_HAD_CHANGED=true
3725 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3726 local default="NonBlockingRestore [NoRetryAction]"
3727 [[ "$policy" == "$default" ]] ||
3728 error "default policy has changed,"\
3729 " '$policy' != '$default' update the test"
3730 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3731 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3732 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3733 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3734 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3735 # useless bacause we know but safer for futur changes to use real value
3736 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3737 echo "Next set_param must failed"
3738 policy_set_and_test "wrong" "$policy"
3741 echo "Back to default policy"
3742 cdt_set_sanity_policy
3744 run_test 109 "Policy display/change"
3747 # test needs a running copytool
3750 mkdir_on_mdt0 $DIR/$tdir
3752 copy2archive /etc/passwd $tdir/$tfile
3754 local f=$DIR/$tdir/$tfile
3755 copytool import $tdir/$tfile $f
3756 local fid=$(path2fid $f)
3758 cdt_set_non_blocking_restore
3763 wait_request_state $fid RESTORE SUCCEED
3764 cdt_clear_non_blocking_restore
3768 error "md5sum returns $st != 1, "\
3769 "should also perror ENODATA (No data available)"
3771 run_test 110a "Non blocking restore policy (import case)"
3774 # test needs a running copytool
3777 mkdir_on_mdt0 $DIR/$tdir
3778 local f=$DIR/$tdir/$tfile
3779 local fid=$(copy_file /etc/passwd $f)
3780 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3781 wait_request_state $fid ARCHIVE SUCCEED
3784 cdt_set_non_blocking_restore
3789 wait_request_state $fid RESTORE SUCCEED
3790 cdt_clear_non_blocking_restore
3794 error "md5sum returns $st != 1, "\
3795 "should also perror ENODATA (No data available)"
3797 run_test 110b "Non blocking restore policy (release case)"
3800 # test needs a running copytool
3803 mkdir_on_mdt0 $DIR/$tdir
3804 copy2archive /etc/passwd $tdir/$tfile
3806 local f=$DIR/$tdir/$tfile
3808 copytool import $tdir/$tfile $f
3809 local fid=$(path2fid $f)
3813 copytool_remove_backend $fid
3816 wait_request_state $fid RESTORE FAILED
3823 [[ $st == 0 ]] || error "Restore does not failed"
3825 run_test 111a "No retry policy (import case), restore will error"\
3826 " (No such file or directory)"
3829 # test needs a running copytool
3832 mkdir_on_mdt0 $DIR/$tdir
3833 local f=$DIR/$tdir/$tfile
3834 local fid=$(copy_file /etc/passwd $f)
3835 stack_trap cdt_clear_no_retry EXIT
3837 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3838 wait_request_state $fid ARCHIVE SUCCEED
3841 copytool_remove_backend $fid
3844 wait_request_state $fid RESTORE FAILED
3848 [[ $st == 0 ]] || error "Restore does not failed"
3850 run_test 111b "No retry policy (release case), restore will error"\
3851 " (No such file or directory)"
3854 # test needs a running copytool
3857 mkdir_on_mdt0 $DIR/$tdir
3858 local f=$DIR/$tdir/$tfile
3859 local fid=$(copy_file /etc/passwd $f)
3861 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3862 local l=$($LFS hsm_action $f)
3864 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3867 wait_request_state $fid ARCHIVE SUCCEED
3870 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3872 run_test 112 "State of recorded request"
3875 mkdir_on_mdt0 $DIR/$tdir
3877 local file1=$DIR/$tdir/$tfile
3878 local file2=$DIR2/$tdir/$tfile
3880 local fid=$(create_small_sync_file $file1)
3882 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3883 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3884 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3886 copytool setup -m "$MOUNT3"
3888 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3890 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3891 wait_request_state $fid ARCHIVE SUCCEED
3893 $LFS hsm_release $file1
3894 echo "Verifying released state: "
3895 check_hsm_flags $file1 "0x0000000d"
3897 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3900 kill -USR1 $MULTIPID
3905 local size1=$(stat -c "%s" $file1)
3906 local size2=$(stat -c "%s" $file2)
3908 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3910 run_test 113 "wrong stat after restore"
3913 mkdir_on_mdt0 $DIR/$tdir
3915 local f1=$DIR/$tdir/${tfile}1
3916 local f2=$DIR/$tdir/${tfile}2
3917 local fid1=$(create_empty_file "$f1")
3918 local fid2=$(create_empty_file "$f2")
3922 # Prevent archive from completing
3925 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1 $f2
3926 # wait archive to register at CDT
3927 wait_request_state "$fid1" ARCHIVE WAITING
3929 # Set f2 in an incompatible state
3930 $LFS hsm_set --noarchive $f2
3934 wait_request_state "$fid1" ARCHIVE SUCCEED
3935 wait_request_state "$fid2" ARCHIVE FAILED
3937 run_test 114 "Incompatible request does not set other requests as STARTED"
3940 mkdir_on_mdt0 $DIR/$tdir
3942 local f=$DIR/$tdir/$tfile
3943 local fid=$(create_empty_file "$f")
3947 # Prevent archive from completing
3950 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3951 # wait archive to register at CDT
3952 wait_request_state $fid ARCHIVE STARTED
3954 # Cancel the archive
3955 $LFS hsm_cancel "$f"
3957 wait_request_state $fid ARCHIVE CANCELED
3960 wait_request_state $fid CANCEL SUCCEED
3962 run_test 200 "Register/Cancel archive"
3965 # test needs a running copytool
3967 mkdir_on_mdt0 $DIR/$tdir
3969 local f=$DIR/$tdir/$tfile
3970 create_archive_file $tdir/$tfile
3971 copytool import $tdir/$tfile $f
3972 local fid=$(path2fid $f)
3974 # test with cdt on is made in test_222
3977 # wait restore to register at CDT
3978 wait_request_state $fid RESTORE WAITING
3981 wait_request_state $fid RESTORE CANCELED
3982 wait_request_state $fid CANCEL SUCCEED
3984 run_test 201 "Register/Cancel restore"
3987 mkdir_on_mdt0 $DIR/$tdir
3989 local f=$DIR/$tdir/$tfile
3990 local fid=$(create_empty_file "$f")
3992 # test needs a running copytool
3995 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3996 wait_request_state $fid ARCHIVE SUCCEED
4000 # wait remove to register at CDT
4001 wait_request_state $fid REMOVE STARTED
4004 wait_request_state $fid REMOVE CANCELED
4006 run_test 202 "Register/Cancel remove"
4008 test_220A() { # was test_220
4009 # test needs a running copytool
4012 mkdir_on_mdt0 $DIR/$tdir
4014 local f=$DIR/$tdir/$tfile
4015 local fid=$(copy_file /etc/passwd $f)
4019 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4020 wait_request_state $fid ARCHIVE SUCCEED
4022 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4023 error "The expected changelog was not emitted"
4025 run_test 220A "Changelog for archive"
4028 # test needs a running copytool
4031 mkdir_on_mdt0 $DIR/$tdir
4033 local f=$DIR/$tdir/$tfile
4034 local fid=$(copy_file /etc/passwd $f)
4038 # block copytool operations to allow for HSM request to be
4039 # submitted and file be unlinked (CDT will find object removed)
4042 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4044 # wait request to reach CT
4045 wait_request_state $fid ARCHIVE STARTED
4051 wait_request_state $fid ARCHIVE FAILED
4054 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4055 error "The expected changelog was not emitted"
4057 run_test 220a "Changelog for failed archive"
4060 mkdir_on_mdt0 $DIR/$tdir
4062 local f=$DIR/$tdir/$tfile
4063 local fid=$(create_empty_file "$f")
4068 # Prevent archive from completing
4070 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4071 wait_request_state $fid ARCHIVE STARTED
4074 wait_request_state $fid ARCHIVE CANCELED
4077 wait_request_state $fid CANCEL SUCCEED
4079 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4080 error "The expected changelog was not emitted"
4082 run_test 221 "Changelog for archive canceled"
4085 # test needs a running copytool
4088 mkdir_on_mdt0 $DIR/$tdir
4089 copy2archive /etc/passwd $tdir/$tfile
4091 local f=$DIR/$tdir/$tfile
4092 copytool import $tdir/$tfile $f
4093 local fid=$(path2fid $f)
4098 wait_request_state $fid RESTORE SUCCEED
4100 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4101 error "The expected changelog was not emitted"
4103 run_test 222a "Changelog for explicit restore"
4106 # test needs a running copytool
4109 mkdir_on_mdt0 $DIR/$tdir
4110 local f=$DIR/$tdir/$tfile
4111 local fid=$(copy_file /etc/passwd $f)
4114 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4115 wait_request_state $fid ARCHIVE SUCCEED
4120 wait_request_state $fid RESTORE SUCCEED
4122 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4123 error "The expected changelog was not emitted"
4125 run_test 222b "Changelog for implicit restore"
4128 # test needs a running copytool
4131 mkdir_on_mdt0 $DIR/$tdir
4132 copy2archive /etc/passwd $tdir/$tfile
4134 local f=$DIR/$tdir/$tfile
4135 copytool import $tdir/$tfile $f
4136 local fid=$(path2fid $f)
4140 # block copytool operations to allow for HSM request to be
4141 # submitted and file be unlinked (CDT will find object removed)
4146 # wait request to reach CT
4147 wait_request_state $fid RESTORE STARTED
4153 wait_request_state $fid RESTORE FAILED
4156 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4157 error "The expected changelog was not emitted"
4159 run_test 222c "Changelog for failed explicit restore"
4162 # test needs a running copytool
4165 mkdir_on_mdt0 $DIR/$tdir
4166 local f=$DIR/$tdir/$tfile
4167 local fid=$(copy_file /etc/passwd $f)
4170 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4171 wait_request_state $fid ARCHIVE SUCCEED
4174 copytool_remove_backend $fid
4177 wait_request_state $fid RESTORE FAILED
4180 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4181 error "The expected changelog was not emitted"
4183 run_test 222d "Changelog for failed implicit restore"
4186 # test needs a running copytool
4188 mkdir_on_mdt0 $DIR/$tdir
4190 local f=$DIR/$tdir/$tfile
4191 create_archive_file $tdir/$tfile
4195 copytool import $tdir/$tfile $f
4196 local fid=$(path2fid $f)
4199 wait_request_state $fid RESTORE STARTED
4201 wait_request_state $fid RESTORE CANCELED
4202 wait_request_state $fid CANCEL SUCCEED
4204 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4205 error "The expected changelog was not emitted"
4207 run_test 223a "Changelog for restore canceled (import case)"
4210 mkdir_on_mdt0 $DIR/$tdir
4212 local f=$DIR/$tdir/$tfile
4213 local fid=$(create_empty_file "$f")
4218 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4219 wait_request_state $fid ARCHIVE SUCCEED
4222 # Prevent restore from completing
4225 wait_request_state $fid RESTORE STARTED
4228 wait_request_state $fid RESTORE CANCELED
4231 wait_request_state $fid CANCEL SUCCEED
4233 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4234 error "The expected changelog was not emitted"
4236 run_test 223b "Changelog for restore canceled (release case)"
4238 test_224A() { # was test_224
4239 # test needs a running copytool
4242 mkdir_on_mdt0 $DIR/$tdir
4244 local f=$DIR/$tdir/$tfile
4245 local fid=$(copy_file /etc/passwd $f)
4248 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4249 wait_request_state $fid ARCHIVE SUCCEED
4252 wait_request_state $fid REMOVE SUCCEED
4254 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4255 error "The expected changelog was not emitted"
4257 run_test 224A "Changelog for remove"
4260 # test needs a running copytool
4263 mkdir_on_mdt0 $DIR/$tdir
4265 local f=$DIR/$tdir/$tfile
4266 local fid=$(copy_file /etc/passwd $f)
4269 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4270 wait_request_state $fid ARCHIVE SUCCEED
4272 copytool_remove_backend $fid
4274 # block copytool operations to allow for HSM request to be
4275 # submitted and file be unlinked (CDT will find object removed)
4280 # wait for request to reach CT
4281 wait_request_state $fid REMOVE STARTED
4287 wait_request_state $fid REMOVE FAILED
4289 # HE_REMOVE|ENOENT=0x202
4290 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4291 error "The expected changelog was not emitted"
4293 run_test 224a "Changelog for failed remove"
4296 # test is not usable because remove request is too fast
4297 # so it is always finished before cancel can be done ...
4298 echo "Test disabled"
4301 # test needs a running copytool
4303 mkdir_on_mdt0 $DIR/$tdir
4305 local f=$DIR/$tdir/$tfile
4306 local fid=$(create_empty_file "$f")
4309 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4310 wait_request_state $fid ARCHIVE SUCCEED
4312 # Prevent restore from completing
4317 wait_request_state $fid REMOVE CANCELED
4320 wait_request_state $fid CANCEL SUCCEED
4322 changelog_find -type HSM -target-fid $fid -flags 0x27d
4323 error "The expected changelog was not emitted"
4325 run_test 225 "Changelog for remove canceled"
4328 # test needs a running copytool
4331 mkdir_on_mdt0 $DIR/$tdir
4333 local f1=$DIR/$tdir/$tfile-1
4334 local f2=$DIR/$tdir/$tfile-2
4335 local f3=$DIR/$tdir/$tfile-3
4336 local fid1=$(copy_file /etc/passwd $f1)
4337 local fid2=$(copy_file /etc/passwd $f2)
4338 copy_file /etc/passwd $f3
4341 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4342 wait_request_state $fid1 ARCHIVE SUCCEED
4344 $LFS hsm_archive $f2
4345 wait_request_state $fid2 ARCHIVE SUCCEED
4347 rm $f1 || error "rm $f1 failed"
4350 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4351 error "The expected changelog was not emitted"
4353 mv $f3 $f2 || error "mv $f3 $f2 failed"
4355 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4356 error "The expected changelog was not emitted"
4358 run_test 226 "changelog for last rm/mv with exiting archive"
4360 # This is just a utility function to clarify what test_227 does
4365 "$LFS" "$action" --$flag "$file" ||
4366 error "Cannot ${action#hsm_} $flag on '$file'"
4368 # Only one changelog should be produced
4369 local entries="$(changelog_find -type HSM -target-fid $fid)"
4370 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4371 error "lfs $action --$flag '$file' produced more than one" \
4374 # Parse the last changelog record
4375 local entry="$(tail -n 1 <<< "$entries")"
4376 eval local -A changelog=$(changelog2array $entry)
4378 # Also check the flags match what is expected
4379 [[ ${changelog[flags]} == $target ]] ||
4380 error "Changelog flag is '${changelog[flags]}', not $target"
4384 local file="$DIR/$tdir/$tfile"
4385 local fid=$(create_empty_file "$file")
4390 for flag in norelease noarchive exists archived lost; do
4391 if [ "$flag" == lost ]; then
4392 # The flag "lost" only works on an archived file
4393 "$LFS" hsm_set --archived "$file"
4397 action="hsm_set" __test_227
4398 action="hsm_clear" __test_227
4401 run_test 227 "changelog when explicit setting of HSM flags"
4404 # test needs a running copytool
4406 mkdir_on_mdt0 $DIR/$tdir
4408 local fid=$(create_small_sync_file $DIR/$tfile)
4409 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4410 wait_request_state $fid ARCHIVE SUCCEED
4412 $LFS hsm_release $DIR/$tfile
4413 check_hsm_flags $DIR/$tfile "0x0000000d"
4415 filefrag $DIR/$tfile | grep " 1 extent found" ||
4416 error "filefrag on released file must return only one extent"
4418 # only newer versions of cp detect sparse files by stat/FIEMAP
4420 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4421 error "copying $DIR/$tfile"
4422 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4424 $LFS hsm_release $DIR/$tfile
4425 check_hsm_flags $DIR/$tfile "0x0000000d"
4427 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4429 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4431 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4432 error "comparing untarred $DIR/$tfile"
4434 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4435 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4437 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4440 local file="$DIR/$tdir/$tfile"
4442 # set max_requests to allow one request of each type to be started (3)
4444 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4445 set_hsm_param max_requests 3
4448 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4449 set_hsm_param loop_period 1
4451 # send 1 requests of each kind twice
4454 mkdir_on_mdt0 $DIR/$tdir
4457 for action in archive restore remove; do
4458 local filepath="$file"-to-$action
4459 local fid=$(create_empty_file "$filepath")
4460 local fid2=$(create_empty_file "$filepath".bis)
4462 if [ "$action" != archive ]; then
4463 "$LFS" hsm_archive "$filepath"
4464 wait_request_state $fid ARCHIVE SUCCEED
4465 "$LFS" hsm_archive "$filepath".bis
4466 wait_request_state $fid2 ARCHIVE SUCCEED
4468 if [ "$action" == restore ]; then
4469 "$LFS" hsm_release "$filepath"
4470 "$LFS" hsm_release "$filepath".bis
4474 # suspend the copytool to prevent requests from completing
4475 stack_trap "copytool_continue" EXIT
4478 # send `max_requests' requests (one of each kind)
4479 for action in archive restore remove; do
4480 filepath="$file"-to-$action
4481 "$LFS" hsm_${action} "$filepath"
4482 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4485 # send another batch of requests
4486 for action in archive restore remove; do
4487 "$LFS" hsm_${action} "$file-to-$action".bis
4489 # wait for `loop_period' seconds to make sure the coordinator has time
4490 # to register those, even though it should not
4493 # only the first batch of request should be started
4495 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4499 error "expected 3 STARTED requests, found $count"
4501 run_test 250 "Coordinator max request"
4504 mkdir_on_mdt0 $DIR/$tdir
4506 local f=$DIR/$tdir/$tfile
4507 local fid=$(create_empty_file "$f")
4510 # to have a short test
4511 local old_to=$(get_hsm_param active_request_timeout)
4512 set_hsm_param active_request_timeout 1
4513 # to be sure the cdt will wake up frequently so
4514 # it will be able to cancel the "old" request
4515 local old_loop=$(get_hsm_param loop_period)
4516 set_hsm_param loop_period 1
4521 # Prevent archive from completing
4523 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4524 wait_request_state $fid ARCHIVE STARTED
4526 # Let the request timeout
4527 wait_request_state $fid ARCHIVE CANCELED
4529 set_hsm_param active_request_timeout $old_to
4530 set_hsm_param loop_period $old_loop
4532 run_test 251 "Coordinator request timeout"
4535 mkdir_on_mdt0 $DIR/$tdir
4537 local f=$DIR/$tdir/$tfile
4538 local fid=$(create_empty_file "$f")
4540 # to have a short test
4541 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4542 set_hsm_param loop_period 1
4546 # Prevent archive from completing
4548 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4549 wait_request_state $fid ARCHIVE STARTED
4552 stack_trap "set_hsm_param active_request_timeout \
4553 $(get_hsm_param active_request_timeout)" EXIT
4554 set_hsm_param active_request_timeout 1
4556 wait_request_state $fid ARCHIVE CANCELED
4559 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4563 # test needs a running copytool
4566 mkdir_on_mdt0 $DIR/$tdir
4567 local f=$DIR/$tdir/$tfile
4569 dd if=/dev/zero of=$f bs=1MB count=10
4570 local fid=$(path2fid $f)
4572 $LFS hsm_archive $f || error "could not archive file"
4573 wait_request_state $fid ARCHIVE SUCCEED
4575 # clear locks to discard inode data
4576 cancel_lru_locks osc
4578 #define OBD_FAIL_MDC_MERGE 0x807
4579 $LCTL set_param fail_loc=0x807
4581 #expect error here, instead of release with wrong size
4584 if ((rc == 0)); then
4585 file_size=$(stat -c '%s' $f)
4586 if ((file_size != 10485760)); then
4587 error "Wrong file size after hsm_release"
4590 echo "could not release file"
4593 run_test 253 "Check for wrong file size after release"
4597 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4598 skip "need MDS version at least 2.10.56"
4600 # Check that the counters are initialized to 0
4602 for request_type in archive restore remove; do
4603 count="$(get_hsm_param ${request_type}_count)" ||
4604 error "Reading ${request_type}_count failed with $?"
4606 [ "$count" -eq 0 ] ||
4607 error "Expected ${request_type}_count to be " \
4611 run_test 254a "Request counters are initialized to zero"
4615 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4616 skip "need MDS version at least 2.10.56"
4618 # The number of request to launch (at least 32)
4619 local request_count=$((RANDOM % 32 + 32))
4620 printf "Will launch %i requests of each type\n" "$request_count"
4622 # Launch a copytool to process requests
4625 # Set hsm.max_requests to allow starting all requests at the same time
4627 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4628 set_hsm_param max_requests "$request_count"
4630 mkdir_on_mdt0 $DIR/$tdir
4634 for request_type in archive restore remove; do
4635 printf "Checking %s requests\n" "${request_type}"
4636 # Suspend the copytool to give us time to read the proc files
4639 for ((i = 0; i < $request_count; i++)); do
4640 case $request_type in
4642 create_empty_file "$DIR/$tdir/$tfile-$i" \
4646 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4649 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4652 # Give the coordinator 10 seconds to start every request
4654 while get_hsm_param actions | grep -q WAITING; do
4657 [ $timeout -gt 0 ] ||
4658 error "${request_type^} requests took too " \
4662 count="$(get_hsm_param ${request_type}_count)"
4663 [ "$count" -eq "$request_count" ] ||
4664 error "Expected '$request_count' (!= '$count') " \
4665 "active $request_type requests"
4667 # Let the copytool process the requests
4669 # Give it 10 seconds maximum
4671 while get_hsm_param actions | grep -q STARTED; do
4674 [ $timeout -gt 0 ] ||
4675 error "${request_type^} requests took too " \
4679 count="$(get_hsm_param ${request_type}_count)"
4680 [ "$count" -eq 0 ] ||
4681 error "Expected 0 (!= '$count') " \
4682 "active $request_type requests"
4685 run_test 254b "Request counters are correctly incremented and decremented"
4689 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4690 skip "Need MDS version at least 2.12.0"
4692 mkdir_on_mdt0 $DIR/$tdir
4694 local file="$DIR/$tdir/$tfile"
4695 local fid=$(create_empty_file "$file")
4697 # How do you make sure the coordinator has consumed any outstanding
4698 # event, without triggering an event yourself?
4700 # You wait for a request to disappear from the coordinator's llog.
4702 # Warning: the setup represents 90% of this test
4704 # Create and process an HSM request
4706 "$LFS" hsm_archive "$file"
4707 wait_request_state $fid ARCHIVE SUCCEED
4710 wait_copytools || error "failed to stop copytools"
4712 # Launch a new HSM request
4714 create_empty_file "$file"
4715 "$LFS" hsm_archive "$file"
4719 # Have the completed request be removed as soon as the cdt wakes up
4720 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4721 set_hsm_param grace_delay 1
4722 # (Hopefully, time on the MDS will behave nicely)
4723 do_facet $SINGLEMDS sleep 2 &
4725 # Increase `loop_period' as a mean to prevent the coordinator from
4726 # waking itself up to do some housekeeping.
4727 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4728 set_hsm_param loop_period 1000
4730 wait $! || error "waiting failed"
4732 wait_request_state $fid ARCHIVE ""
4733 # The coordinator will not wake up on its own for ~`loop_period' secs...
4735 # ... Unless a copytool registers. Now the real test begins
4737 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4739 run_test 255 "Copytool registration wakes the coordinator up"
4741 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4742 # break in the future because of that.
4745 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4746 skip "need MDS version 2.11.56 or later"
4748 local -a files=("$DIR/$tdir/$tfile".{0..15})
4751 mkdir_on_mdt0 $DIR/$tdir
4753 for file in "${files[@]}"; do
4754 create_small_file "$file"
4757 # Set a few hsm parameters
4759 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4760 set_hsm_param loop_period 1
4762 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4763 set_hsm_param max_requests 3
4767 "$LFS" hsm_archive "${files[0]}"
4768 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4769 "$LFS" hsm_release "${files[0]}"
4773 wait_copytools || error "copytools failed to stop"
4775 # Send several archive requests
4776 for file in "${files[@]:1}"; do
4777 "$LFS" hsm_archive "$file"
4780 # Send one restore request
4781 "$LFS" hsm_restore "${files[0]}"
4786 # Wait for all the requests to complete
4787 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4788 for file in "${files[@]:1}"; do
4789 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4792 # Collect the actions in the order in which the copytool processed them
4794 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4795 "$(copytool_logfile "$SINGLEAGT")")
4798 printf '%s\n' "${actions[@]}"
4801 for action in "${actions[@]:0:3}"; do
4802 [ "$action" == RESTORE ] && return
4805 error "Too many ARCHIVE requests were run before the RESTORE request"
4807 run_test 260a "Restore request have priority over other requests"
4809 # This test is very much tied to the implementation of the current priorisation
4810 # mechanism in the coordinator. It might not make sense to keep it in the future
4813 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4814 skip "need MDS version 2.11.56 or later"
4816 local -a files=("$DIR/$tdir/$tfile".{0..15})
4819 mkdir_on_mdt0 $DIR/$tdir
4821 for file in "${files[@]}"; do
4822 create_small_file "$file"
4825 # Set a few hsm parameters
4827 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4828 set_hsm_param loop_period 1
4830 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4831 set_hsm_param max_requests 3
4834 copytool setup --archive-id 2
4835 "$LFS" hsm_archive --archive 2 "${files[0]}"
4836 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4837 "$LFS" hsm_release "${files[0]}"
4841 wait_copytools || error "copytools failed to stop"
4843 # Send several archive requests
4844 for file in "${files[@]:1}"; do
4845 "$LFS" hsm_archive "$file"
4848 # Send one restore request
4849 "$LFS" hsm_restore "${files[0]}"
4853 copytool setup --archive-id 2
4855 # Wait for all the requests to complete
4856 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4857 for file in "${files[@]:1}"; do
4858 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4861 # Collect the actions in the order in which the copytool processed them
4863 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4864 "$(copytool_logfile "$SINGLEAGT")")
4867 printf '%s\n' "${actions[@]}"
4870 for action in "${actions[@]:0:3}"; do
4871 [ "$action" == RESTORE ] && return
4874 error "Too many ARCHIVE requests were run before the RESTORE request"
4876 run_test 260b "Restore request have priority over other requests"
4878 # This test is very much tied to the implementation of the current priorisation
4879 # mechanism in the coordinator. It might not make sense to keep it in the future
4882 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4883 skip "Need MDS version at least 2.12.0"
4885 local -a files=("$DIR/$tdir/$tfile".{0..15})
4888 mkdir_on_mdt0 $DIR/$tdir
4890 for file in "${files[@]}"; do
4891 create_small_file "$file"
4894 # Set a few hsm parameters
4896 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4897 set_hsm_param loop_period 1000
4899 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4900 set_hsm_param max_requests 3
4903 copytool setup --archive-id 2
4904 "$LFS" hsm_archive --archive 2 "${files[0]}"
4905 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4906 "$LFS" hsm_release "${files[0]}"
4910 wait_copytools || error "copytools failed to stop"
4912 # Force the next coordinator run to do housekeeping
4916 "$LFS" hsm_archive "${files[1]}"
4920 copytool setup --archive-id 2
4922 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4923 # The coordinator just did a housekeeping run it won't do another one
4924 # for around `loop_period' seconds => requests will not be reordered
4925 # if it costs too much (ie. when the coordinator has to discard a whole
4928 # Send several archive requests
4929 for file in "${files[@]:2}"; do
4930 "$LFS" hsm_archive "$file"
4933 # Send one restore request
4934 "$LFS" hsm_restore "${files[0]}"
4936 # Wait for all the requests to complete
4937 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4938 for file in "${files[@]:2}"; do
4939 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4942 # Collect the actions in the order in which the copytool processed them
4944 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4945 "$(copytool_logfile "$SINGLEAGT")")
4948 printf '%s\n' "${actions[@]}"
4951 for action in "${actions[@]:0:3}"; do
4952 [ "$action" == RESTORE ] &&
4953 error "Restore requests should not be prioritised" \
4954 "unless the coordinator is doing housekeeping"
4958 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4961 local file=$DIR/$tdir/$tfile
4966 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4968 dd if=/dev/zero of=$file bs=4k count=2 || error "Write $file failed"
4969 fid=$(path2fid $file)
4970 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $file
4971 wait_request_state $fid ARCHIVE SUCCEED
4973 $LFS hsm_state $file
4974 $LFS hsm_release $file
4975 $LFS hsm_restore $file
4976 wait_request_state $fid RESTORE SUCCEED
4977 $LFS hsm_release $file
4978 size=$(stat -c %s $file)
4979 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4981 $LFS hsm_release $file
4982 $LFS hsm_restore $file
4983 $LFS hsm_release $file
4984 size=$(stat -c %s $file)
4985 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4986 $LFS hsm_state $file
4988 run_test 261 "Report 0 bytes size after HSM release"
4991 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4993 # the only way to test ondisk conf is to restart MDS ...
4994 echo "Stop coordinator and remove coordinator state at mount"
4997 # clean on disk conf set by default
4998 cdt_clear_mount_state
4999 cdt_check_state stopped
5001 # check cdt still off after umount/remount
5003 cdt_check_state stopped
5005 echo "Set coordinator start at mount, and start coordinator"
5006 cdt_set_mount_state enabled
5009 cdt_check_state enabled
5011 # check cdt still on after umount/remount
5013 cdt_check_state enabled
5015 # we are back to original state (cdt started at mount)
5017 run_test 300 "On disk coordinator state kept between MDT umount/mount"
5020 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
5022 local ai=$(get_hsm_param default_archive_id)
5023 local new=$((ai + 1))
5025 set_hsm_param default_archive_id $new -P
5027 local res=$(get_hsm_param default_archive_id)
5030 set_hsm_param default_archive_id "" "-P -d"
5032 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5034 run_test 301 "HSM tunnable are persistent"
5037 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
5039 local ai=$(get_hsm_param default_archive_id)
5040 local new=$((ai + 1))
5045 set_hsm_param default_archive_id $new -P
5048 for mdtno in $(seq 1 $MDSCOUNT); do
5053 cdt_check_state enabled
5055 local res=$(get_hsm_param default_archive_id)
5058 set_hsm_param default_archive_id "" "-P -d"
5060 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5062 run_test 302 "HSM tunnable are persistent when CDT is off"
5065 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5069 mkdir_on_mdt0 $DIR/$tdir
5071 local dir_mdt0=$DIR/$tdir/mdt0
5072 local dir_mdt1=$DIR/$tdir/mdt1
5074 # create 1 dir per MDT
5075 stack_trap "rm -rf $dir_mdt0" EXIT
5076 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5077 stack_trap "rm -rf $dir_mdt1" EXIT
5078 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5080 # create 1 file in each MDT
5081 local fid1=$(create_small_file $dir_mdt0/$tfile)
5082 local fid2=$(create_small_file $dir_mdt1/$tfile)
5084 # check that hsm request on mdt0 is sent to the right MDS
5085 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5086 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5087 echo "archive successful on mdt0"
5089 # check that hsm request on mdt1 is sent to the right MDS
5090 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5091 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5092 echo "archive successful on mdt1"
5094 run_test 400 "Single request is sent to the right MDT"
5097 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5101 mkdir_on_mdt0 $DIR/$tdir
5103 local dir_mdt0=$DIR/$tdir/mdt0
5104 local dir_mdt1=$DIR/$tdir/mdt1
5106 # create 1 dir per MDT
5107 stack_trap "rm -rf $dir_mdt0" EXIT
5108 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5109 stack_trap "rm -rf $dir_mdt1" EXIT
5110 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5112 # create 1 file in each MDT
5113 local fid1=$(create_small_file $dir_mdt0/$tfile)
5114 local fid2=$(create_small_file $dir_mdt1/$tfile)
5116 # check that compound requests are shunt to the rights MDTs
5117 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5118 error "lfs hsm_archive"
5119 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5120 echo "archive successful on mdt0"
5121 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5122 echo "archive successful on mdt1"
5124 run_test 401 "Compound requests split and sent to their respective MDTs"
5126 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5131 local node=$(facet_active_host $facet)
5133 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5134 awk '{print $4}'); do
5135 echo "$3 $mdc on $node"
5136 do_facet $facet "$LCTL --device $mdc $state" || return 1
5141 # deactivate all mdc on agent1
5142 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5144 copytool setup --no-fail
5146 check_agent_unregistered "uuid" # match any agent
5148 # no expected running copytool
5149 search_copytools $agent && error "Copytool start should have failed"
5152 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5154 run_test 402a "Copytool start fails if all MDTs are inactive"
5159 mkdir_on_mdt0 $DIR/$tdir
5161 local f=$DIR/$tdir/$tfile
5162 touch $f || error "touch $f failed"
5163 local fid=$(path2fid $f)
5165 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5166 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5167 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5169 # give time for CDT to send request and to keep it for retry
5170 wait_for_loop_period
5172 wait_request_state $fid ARCHIVE WAITING
5174 do_facet $SINGLEAGT lctl set_param fail_loc=0
5176 # request should succeed now
5177 wait_request_state $fid ARCHIVE SUCCEED
5179 run_test 402b "CDT must retry request upon slow start of CT"
5182 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5184 local agent=$(facet_active_host $SINGLEAGT)
5186 # deactivate all mdc for MDT0001
5187 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5190 local uuid=$(get_agent_uuid $agent)
5191 # check the agent is registered on MDT0000, and not on MDT0001
5192 check_agent_registered_by_mdt $uuid 0
5193 check_agent_unregistered_by_mdt $uuid 1
5195 # check running copytool process
5196 search_copytools $agent || error "No running copytools on $agent"
5198 # reactivate all mdc for MDT0001
5199 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5201 # make sure the copytool is now registered to all MDTs
5202 check_agent_registered $uuid
5204 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5207 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5211 # create files on both MDT0000 and MDT0001
5212 mkdir_on_mdt0 $DIR/$tdir
5214 local dir_mdt0=$DIR/$tdir/mdt0
5215 stack_trap "rm -rf $dir_mdt0" EXIT
5216 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5218 # create 1 file on mdt0
5219 local fid1=$(create_small_file $dir_mdt0/$tfile)
5221 # deactivate all mdc for MDT0001
5222 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5224 # send an HSM request for files in MDT0000
5225 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5227 # check for completion of files in MDT0000
5228 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5229 echo "archive successful on mdt0"
5231 # reactivate all mdc for MDT0001
5232 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5234 run_test 404 "Inactive MDT does not block requests for active MDTs"
5237 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5241 mkdir_on_mdt0 $DIR/$tdir
5243 local striped_dir=$DIR/$tdir/striped_dir
5245 # create striped dir on all of MDTs
5246 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5248 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5249 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5250 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5251 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5253 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5254 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5255 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5256 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5258 # check that compound requests are shunt to the rights MDTs
5259 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5260 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5261 error "lfs hsm_archive"
5263 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5264 echo "archive successful on $fid1"
5265 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5266 echo "archive successful on $fid2"
5267 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5268 echo "archive successful on $fid3"
5269 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5270 echo "archive successful on $fid4"
5272 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5273 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5274 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5275 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5277 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5278 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5279 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5280 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5282 run_test 405 "archive and release under striped directory"
5285 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5287 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5288 skip "need MDS version at least 2.7.64"
5293 mkdir_on_mdt0 $DIR/$tdir
5295 fid=$(create_small_file $DIR/$tdir/$tfile)
5300 $LFS hsm_archive $DIR/$tdir/$tfile
5301 wait_request_state "$fid" ARCHIVE SUCCEED
5302 $LFS hsm_release $DIR/$tdir/$tfile
5304 # Should migrate $tdir but not $tfile.
5305 $LFS migrate -m1 $DIR/$tdir &&
5306 error "migrating HSM an archived file should fail"
5308 $LFS hsm_restore $DIR/$tdir/$tfile
5309 wait_request_state "$fid" RESTORE SUCCEED
5311 $LFS hsm_remove $DIR/$tdir/$tfile
5312 wait_request_state "$fid" REMOVE SUCCEED
5314 cat $DIR/$tdir/$tfile > /dev/null ||
5315 error "cannot read $DIR/$tdir/$tfile"
5317 $LFS migrate -m1 $DIR/$tdir ||
5318 error "cannot complete migration after HSM remove"
5320 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5321 if ((mdt_index != 1)); then
5322 error "expected MDT index 1, got $mdt_index"
5325 # Refresh fid after migration.
5326 fid=$(path2fid $DIR/$tdir/$tfile)
5329 $LFS hsm_archive $DIR/$tdir/$tfile
5330 wait_request_state "$fid" ARCHIVE SUCCEED 1
5332 lctl set_param debug=+trace
5333 $LFS hsm_release $DIR/$tdir/$tfile ||
5334 error "cannot release $DIR/$tdir/$tfile"
5336 $LFS hsm_restore $DIR/$tdir/$tfile
5337 wait_request_state "$fid" RESTORE SUCCEED 1
5339 cat $DIR/$tdir/$tfile > /dev/null ||
5340 error "cannot read $DIR/$tdir/$tfile"
5342 run_test 406 "attempting to migrate HSM archived files is safe"
5345 mkdir_on_mdt0 $DIR/$tdir
5347 local f=$DIR/$tdir/$tfile
5348 local f2=$DIR2/$tdir/$tfile
5349 local fid=$(create_empty_file "$f")
5353 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5354 wait_request_state $fid ARCHIVE SUCCEED
5357 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5358 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5360 # Prevent restore from completing
5364 # 1st request holds layout lock while appropriate
5365 # RESTORE record is still not added to llog
5369 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5370 # after umount hsm_actions->O/x/x log shouldn't have
5371 # double RESTORE records like below
5372 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5373 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5375 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5377 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5379 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5382 wait_all_done 100 $fid
5384 run_test 407 "Check for double RESTORE records in llog"
5388 [ "$MDS1_VERSION" -lt $(version_code 2.6.92) ] &&
5389 skip "HSM migrate is not supported"
5391 test_mkdir -p $DIR/$tdir
5393 if [ "$CLIENT_VERSION" -lt $(version_code 2.11.56) ] ||
5394 [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ];
5396 llapi_hsm_test -d $DIR/$tdir -b ||
5397 error "One llapi HSM test failed"
5399 llapi_hsm_test -d $DIR/$tdir ||
5400 error "One llapi HSM test failed"
5403 run_test 500 "various LLAPI HSM tests"
5406 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
5407 skip "need MDS version at least 2.10.58"
5411 local f=$DIR/$tdir/$tfile
5414 # set changelog_mask to ALL
5415 changelog_chmask "ALL"
5417 chmod 777 $DIR/$tdir
5418 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5419 local fid=$(path2fid $f)
5422 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5423 -gid "$RUNAS_GID") ||
5424 error "No matching CREAT entry"
5426 # Parse the changelog
5427 eval local -A changelog=$(changelog2array $entry)
5428 local nid="${changelog[nid]}"
5431 echo "Got NID '$nid'"
5432 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5433 error "nid '$nid' does not match any client NID:" \
5436 run_test 600 "Changelog fields 'u=' and 'nid='"
5439 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5440 skip "need MDS version at least 2.10.58"
5444 local f=$DIR/$tdir/$tfile
5447 # set changelog_mask to ALL
5448 changelog_chmask "ALL"
5450 touch $f || error "touch $f failed"
5451 local fid=$(path2fid $f)
5454 cat $f || error "cat $f failed"
5456 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5457 error "No matching OPEN entry"
5459 run_test 601 "OPEN Changelog entry"
5462 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5463 skip "need MDS version at least 2.10.58"
5465 stack_trap "restore_opencache" EXIT
5470 local f=$DIR/$tdir/$tfile
5473 # set changelog_mask to ALL
5474 changelog_chmask "ALL"
5476 touch $f || error "touch $f failed"
5477 local fid=$(path2fid $f)
5480 cat $f || error "cat $f failed"
5482 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5486 echo f > $f || error "write $f failed"
5489 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5491 # remove OPEN from changelog_mask
5492 changelog_chmask "-OPEN"
5496 cat $f || error "cat $f failed"
5499 changelog_find -type CLOSE -target-fid $fid &&
5500 error "There should be no CLOSE entry"
5504 echo f > $f || error "write $f failed"
5507 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5509 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5512 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5513 skip "need MDS version at least 2.10.58"
5517 local f=$DIR/$tdir/$tfile
5520 # set changelog_mask to ALL
5521 changelog_chmask "ALL"
5523 touch $f || error "touch $f failed"
5524 local fid=$(path2fid $f)
5526 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5529 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5531 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5532 error "No matching GXATR entry"
5534 run_test 603 "GETXATTR Changelog entry"
5537 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5538 skip "need MDS version at least 2.10.58"
5540 mkdir_on_mdt0 $DIR/$tdir
5542 local f=$DIR/$tdir/$tfile
5543 local f2=$DIR2/$tdir/$tfile
5544 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5546 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5547 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5548 do_facet mds1 lctl set_param "$procname=20"
5552 # set changelog_mask to ALL
5553 changelog_chmask "ALL"
5555 touch $f || error "touch $f failed"
5556 local fid=$(path2fid $f)
5562 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5566 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5567 -gid "$RUNAS_GID" -mode "r--") ||
5568 error "No matching NOPEN entry"
5570 # Parse the changelog
5571 eval local -A changelog=$(changelog2array $entry)
5572 local nid="${changelog[nid]}"
5575 echo "Got NID '$nid'"
5576 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5577 error "nid '$nid' does not match any client NID:" \
5582 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5585 changelog_find -type NOPEN -target-fid $fid &&
5586 error "There should be no NOPEN entry"
5588 # Sleep for `changelog_deniednext` seconds
5593 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5596 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5597 -gid "$RUNAS_GID" -mode "r--") ||
5598 error "No matching NOPEN entry"
5600 # Parse the changelog
5601 eval local -A changelog=$(changelog2array $entry)
5602 local nid="${changelog[nid]}"
5605 echo "Got NID '$nid'"
5606 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5607 error "nid '$nid' does not match any client NID:" \
5610 run_test 604 "NOPEN Changelog entry"
5613 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5614 skip "need MDS version at least 2.10.58"
5616 stack_trap "restore_opencache" EXIT
5621 local f=$DIR/$tdir/$tfile
5622 local f2=$DIR2/$tdir/$tfile
5625 # set changelog_mask to ALL
5626 changelog_chmask "ALL"
5628 touch $f || error "touch $f failed"
5629 local fid=$(path2fid $f)
5633 exec 3<> $f || error "open $f failed"
5637 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5641 exec 4<> $f || error "open $f failed"
5644 changelog_find -type OPEN -target-fid $fid &&
5645 error "There should be no OPEN entry"
5647 exec 4>&- || error "close $f failed"
5650 changelog_find -type CLOSE -target-fid $fid &&
5651 error "There should be no CLOSE entry"
5655 # access in rw, so different access mode should generate entries
5656 cat $f || error "cat $f failed"
5659 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5661 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5665 # same access as first one, should not generate new entries
5666 exec 4<> $f || error "open $f failed"
5669 changelog_find -type OPEN -target-fid $fid &&
5670 error "There should be no OPEN entry"
5672 exec 4>&- || error "close $f failed"
5675 changelog_find -type CLOSE -target-fid $fid &&
5676 error "There should be no CLOSE entry"
5680 # access by different user should generate new entries
5681 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5684 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5686 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5690 exec 3>&- || error "close $f failed"
5693 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5695 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5698 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5699 skip "need MDS version at least 2.10.58"
5701 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5702 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5703 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5704 skip_env "missing llog_reader"
5706 mkdir_on_mdt0 $DIR/$tdir
5708 local f=$DIR/$tdir/$tfile
5711 # set changelog_mask to ALL
5712 changelog_chmask "ALL"
5714 chmod 777 $DIR/$tdir
5715 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5716 local fid=$(path2fid $f)
5717 rm $f || error "rm $f failed"
5719 local mntpt=$(facet_mntpt mds1)
5723 #remount mds1 as ldiskfs or zfs type
5724 stop mds1 || error "stop mds1 failed"
5725 stack_trap "unmount_fstype mds1; start mds1 $(mdsdevname 1)\
5726 $MDS_MOUNT_OPTS" EXIT
5727 mount_fstype mds1 || error "remount mds1 failed"
5729 for ((i = 0; i < 1; i++)); do
5730 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5731 local cat_file=$(do_facet mds1 $llog_reader \
5732 $mntpt/changelog_catalog | awk \
5733 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5734 [ -n "$cat_file" ] || error "no catalog file"
5736 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5737 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5738 [ -n "$entry" ] || error "no CREAT entry"
5741 local uidgid=$(echo $entry |
5742 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5743 [ -n "$uidgid" ] || error "uidgid is empty"
5744 echo "Got UID/GID $uidgid"
5745 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5746 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5747 local nid=$(echo $entry |
5748 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5749 [ -n "$nid" ] || error "nid is empty"
5751 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5752 error "nid '$nid' does not match any NID ${CLIENT_NIDS[*]}"
5754 run_test 606 "llog_reader groks changelog fields"
5757 check_and_cleanup_lustre