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"
1397 for i in {1..10}; do
1398 local archive_dir="$(hsm_root)"/subdir/dir.$i
1400 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1401 for j in {1..10}; do
1402 local archive_file="$archive_dir"/file.$j
1404 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1410 copytool import "subdir" "$DIR/$tdir"
1412 # To check the import, the test uses diff with the -r flag
1413 # This is nice, but diff only checks files one by one, and triggering
1414 # an implicit restore for one file at a time will consume as many
1415 # seconds as there are files to compare. To speed this up, a restore
1416 # operation is triggered manually first.
1418 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1420 # Compare the imported data
1421 do_facet $SINGLEAGT \
1422 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1423 error "imported files differ from archived data"
1425 run_test 13 "Recursively import and restore a directory"
1428 # test needs a running copytool
1431 mkdir_on_mdt0 $DIR/$tdir
1434 local f=$DIR/$tdir/$tfile
1435 local fid=$(create_small_file $f)
1436 local sum=$(md5sum $f | awk '{print $1}')
1437 $LFS hsm_archive $f || error "could not archive file"
1438 wait_request_state $fid ARCHIVE SUCCEED
1440 # create released file (simulate llapi_hsm_import call)
1441 local fid2=$(create_empty_file "$f")
1442 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1443 $LFS hsm_release $f || error "could not release file"
1445 # rebind the archive to the newly created file
1446 echo "rebind $fid to $fid2"
1448 copytool rebind $fid $fid2
1450 # restore file and compare md5sum
1451 local sum2=$(md5sum $f | awk '{print $1}')
1453 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1455 run_test 14 "Rebind archived file to a new fid"
1458 # test needs a running copytool
1461 mkdir_on_mdt0 $DIR/$tdir
1464 local f=$DIR/$tdir/$tfile
1466 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1470 for i in $(seq 1 $count); do
1471 fids[$i]=$(create_small_file $f.$i)
1472 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1473 $LFS hsm_archive $f.$i || error "could not archive file"
1475 wait_all_done $(($count*60))
1477 stack_trap "rm -f $tmpfile" EXIT
1480 for i in $(seq 1 $count); do
1481 local fid2=$(create_empty_file "${f}.${i}")
1482 # add the rebind operation to the list
1483 echo ${fids[$i]} $fid2 >> $tmpfile
1485 # set it released (simulate llapi_hsm_import call)
1486 $LFS hsm_set --archived --exists $f.$i ||
1487 error "could not force hsm flags"
1488 $LFS hsm_release $f.$i || error "could not release file"
1490 nl=$(wc -l < $tmpfile)
1491 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1493 echo "rebind list of files"
1494 copytool rebind "$tmpfile"
1496 # restore files and compare md5sum
1497 for i in $(seq 1 $count); do
1498 local sum2=$(md5sum $f.$i | awk '{print $1}')
1499 [[ $sum2 == ${sums[$i]} ]] ||
1500 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1503 run_test 15 "Rebind a list of files"
1506 # test needs a running copytool
1510 # create a known size file so we can verify transfer speed
1513 dd if=/dev/zero of=$ref bs=1M count=20
1515 mkdir_on_mdt0 $DIR/$tdir
1516 local f=$DIR/$tdir/$tfile
1517 local fid=$(copy_file $ref $f)
1519 local start=$(date +%s)
1521 wait_request_state $fid ARCHIVE SUCCEED
1522 local end=$(date +%s)
1523 # Add 1 to account for rounding errors between start and end (LU-8155)
1524 local duration=$((end - start + 1))
1526 [[ $duration -ge $((goal - 1)) ]] ||
1527 error "Transfer is too fast $duration < $goal"
1529 run_test 16 "Test CT bandwith control option"
1532 local f=$DIR/$tdir/$tfile
1533 create_empty_file "$f"
1535 # Could not release a non-archived file
1536 $LFS hsm_release $f && error "release should not succeed"
1538 # For following tests, we must test them with HS_ARCHIVED set
1539 $LFS hsm_set --exists --archived $f || error "could not add flag"
1541 # Could not release a file if no-release is set
1542 $LFS hsm_set --norelease $f || error "could not add flag"
1543 $LFS hsm_release $f && error "release should not succeed"
1544 $LFS hsm_clear --norelease $f || error "could not remove flag"
1546 # Could not release a file if lost
1547 $LFS hsm_set --lost $f || error "could not add flag"
1548 $LFS hsm_release $f && error "release should not succeed"
1549 $LFS hsm_clear --lost $f || error "could not remove flag"
1551 # Could not release a file if dirty
1552 $LFS hsm_set --dirty $f || error "could not add flag"
1553 $LFS hsm_release $f && error "release should not succeed"
1554 $LFS hsm_clear --dirty $f || error "could not remove flag"
1556 run_test 20 "Release is not permitted"
1559 # test needs a running copytool
1561 mkdir_on_mdt0 $DIR/$tdir
1563 local f=$DIR/$tdir/test_release
1565 # Create a file and check its states
1566 local fid=$(create_small_file $f)
1567 check_hsm_flags $f "0x00000000"
1569 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1570 # used until file is flushed to disk
1571 if [ "$ost1_FSTYPE" == "zfs" ]; then
1572 # this causes an OST_SYNC rpc to be sent
1573 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1574 # clear locks to reread file data
1575 cancel_lru_locks osc
1578 local orig_size=$(stat -c "%s" $f)
1579 local orig_blocks=$(stat -c "%b" $f)
1581 start_full_debug_logging
1583 $LFS hsm_archive $f || error "could not archive file"
1584 wait_request_state $fid ARCHIVE SUCCEED
1586 local blocks=$(stat -c "%b" $f)
1587 [ $blocks -eq $orig_blocks ] ||
1588 error "$f: wrong block number after archive: " \
1589 "$blocks != $orig_blocks"
1590 local size=$(stat -c "%s" $f)
1591 [ $size -eq $orig_size ] ||
1592 error "$f: wrong size after archive: $size != $orig_size"
1594 # Release and check states
1595 $LFS hsm_release $f || error "could not release file"
1596 check_hsm_flags $f "0x0000000d"
1598 blocks=$(stat -c "%b" $f)
1599 [ $blocks -gt 5 ] &&
1600 error "$f: too many blocks after release: $blocks > 5"
1601 size=$(stat -c "%s" $f)
1602 [ $size -ne $orig_size ] &&
1603 error "$f: wrong size after release: $size != $orig_size"
1605 # Check we can release an file without stripe info
1609 check_hsm_flags $f "0x00000000"
1610 $LFS hsm_archive $f || error "could not archive file"
1611 wait_request_state $fid ARCHIVE SUCCEED
1613 # Release and check states
1614 $LFS hsm_release $f || error "could not release file"
1615 check_hsm_flags $f "0x0000000d"
1617 # Release again a file that is already released is OK
1618 $LFS hsm_release $f || fail "second release should succeed"
1619 check_hsm_flags $f "0x0000000d"
1621 stop_full_debug_logging
1623 run_test 21 "Simple release tests"
1626 # test needs a running copytool
1628 mkdir_on_mdt0 $DIR/$tdir
1630 local f=$DIR/$tdir/test_release
1631 local swap=$DIR/$tdir/test_swap
1633 # Create a file and check its states
1634 local fid=$(create_small_file $f)
1635 check_hsm_flags $f "0x00000000"
1637 $LFS hsm_archive $f || error "could not archive file"
1638 wait_request_state $fid ARCHIVE SUCCEED
1640 # Release and check states
1641 $LFS hsm_release $f || error "could not release file"
1642 check_hsm_flags $f "0x0000000d"
1644 create_small_file $swap
1645 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1649 run_test 22 "Could not swap a release file"
1652 # test needs a running copytool
1654 mkdir_on_mdt0 $DIR/$tdir
1656 local f=$DIR/$tdir/test_mtime
1658 # Create a file and check its states
1659 local fid=$(create_small_file $f)
1660 check_hsm_flags $f "0x00000000"
1662 $LFS hsm_archive $f || error "could not archive file"
1663 wait_request_state $fid ARCHIVE SUCCEED
1665 # Set modification time in the past
1666 touch -m -a -d @978261179 $f
1668 # Release and check states
1669 $LFS hsm_release $f || error "could not release file"
1670 check_hsm_flags $f "0x0000000d"
1672 local MTIME=$(stat -c "%Y" $f)
1673 local ATIME=$(stat -c "%X" $f)
1674 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1675 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1677 run_test 23 "Release does not change a/mtime (utime)"
1680 local file=$DIR/$tdir/$tfile
1689 # test needs a running copytool
1691 mkdir_on_mdt0 $DIR/$tdir
1693 fid=$(create_small_file $file)
1695 # Create a file and check its states
1696 check_hsm_flags $file "0x00000000"
1698 # Ensure atime is less than mtime and ctime.
1702 atime0=$(stat -c "%X" $file)
1703 mtime0=$(stat -c "%Y" $file)
1704 ctime0=$(stat -c "%Z" $file)
1706 [ $atime0 -lt $mtime0 ] ||
1707 error "atime $atime0 is not less than mtime $mtime0"
1709 [ $atime0 -lt $ctime0 ] ||
1710 error "atime $atime0 is not less than ctime $ctime0"
1712 # Archive should not change any timestamps.
1713 $LFS hsm_archive $file || error "cannot archive '$file'"
1714 wait_request_state $fid ARCHIVE SUCCEED
1716 atime1=$(stat -c "%X" $file)
1717 mtime1=$(stat -c "%Y" $file)
1718 ctime1=$(stat -c "%Z" $file)
1720 [ $atime0 -eq $atime1 ] ||
1721 error "archive changed atime from $atime0 to $atime1"
1723 [ $mtime0 -eq $mtime1 ] ||
1724 error "archive changed mtime from $mtime0 to $mtime1"
1726 [ $ctime0 -eq $ctime1 ] ||
1727 error "archive changed ctime from $ctime0 to $ctime1"
1729 # Release should not change any timestamps.
1730 $LFS hsm_release $file || error "cannot release '$file'"
1731 check_hsm_flags $file "0x0000000d"
1733 atime1=$(stat -c "%X" $file)
1734 mtime1=$(stat -c "%Y" $file)
1735 ctime1=$(stat -c "%Z" $file)
1737 [ $atime0 -eq $atime1 ] ||
1738 error "release changed atime from $atime0 to $atime1"
1740 [ $mtime0 -eq $mtime1 ] ||
1741 error "release changed mtime from $mtime0 to $mtime1"
1743 [ $ctime0 -eq $ctime1 ] ||
1744 error "release changed ctime from $ctime0 to $ctime1"
1746 # Restore should not change any timestamps.
1747 $LFS hsm_restore $file
1748 wait_request_state $fid RESTORE SUCCEED
1750 atime1=$(stat -c "%X" $file)
1751 mtime1=$(stat -c "%Y" $file)
1752 ctime1=$(stat -c "%Z" $file)
1754 [ $atime0 -eq $atime1 ] ||
1755 error "restore changed atime from $atime0 to $atime1"
1757 [ $mtime0 -eq $mtime1 ] ||
1758 error "restore changed mtime from $mtime0 to $mtime1"
1760 [ $ctime0 -eq $ctime1 ] ||
1761 error "restore changed ctime from $ctime0 to $ctime1"
1764 wait_copytools || error "Copytools failed to stop"
1766 # Once more, after unmount and mount.
1767 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1768 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1770 atime1=$(stat -c "%X" $file)
1771 mtime1=$(stat -c "%Y" $file)
1772 ctime1=$(stat -c "%Z" $file)
1774 [ $atime0 -eq $atime1 ] ||
1775 error "remount changed atime from $atime0 to $atime1"
1777 [ $mtime0 -eq $mtime1 ] ||
1778 error "remount changed mtime from $mtime0 to $mtime1"
1780 [ $ctime0 -eq $ctime1 ] ||
1781 error "remount changed ctime from $ctime0 to $ctime1"
1783 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1786 local file=$DIR/$tdir/$tfile
1792 # Test needs a running copytool.
1794 mkdir_on_mdt0 $DIR/$tdir
1796 # Check that root can do HSM actions on a regular user's file.
1797 fid=$(create_small_file $file)
1798 sum0=$(md5sum $file)
1800 chown $RUNAS_ID:$RUNAS_GID $file ||
1801 error "cannot chown '$file' to '$RUNAS_ID'"
1803 chmod ugo-w $DIR/$tdir ||
1804 error "cannot chmod '$DIR/$tdir'"
1806 $LFS hsm_archive $file
1807 wait_request_state $fid ARCHIVE SUCCEED
1809 $LFS hsm_release $file
1810 check_hsm_flags $file "0x0000000d"
1812 $LFS hsm_restore $file
1813 wait_request_state $fid RESTORE SUCCEED
1815 # Check that ordinary user can get HSM state.
1816 $RUNAS $LFS hsm_state $file ||
1817 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1819 $LFS hsm_release $file
1820 check_hsm_flags $file "0x0000000d"
1822 # Check that ordinary user can accessed released file.
1823 sum1=$($RUNAS md5sum $file) ||
1824 error "user '$RUNAS_ID' cannot read '$file'"
1826 [ "$sum0" == "$sum1" ] ||
1827 error "md5sum mismatch for '$file'"
1829 run_test 24b "root can archive, release, and restore user files"
1832 local file=$DIR/$tdir/$tfile
1833 local action=archive
1838 # test needs a running copytool
1840 mkdir_on_mdt0 $DIR/$tdir
1842 # Save the default masks and check that cleanup_24c will
1843 # restore the request masks correctly.
1844 user_save=$(get_hsm_param user_request_mask)
1845 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1846 group_save=$(get_hsm_param group_request_mask)
1847 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1848 other_save=$(get_hsm_param other_request_mask)
1849 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1851 [ "$user_save" == RESTORE ] ||
1852 error "user_request_mask is '$user_save' expected 'RESTORE'"
1853 [ "$group_save" == RESTORE ] ||
1854 error "group_request_mask is '$group_save' expected 'RESTORE'"
1855 [ "$other_save" == RESTORE ] ||
1856 error "other_request_mask is '$other_save' expected 'RESTORE'"
1859 create_small_file $file
1860 chown $RUNAS_ID:$GROUP $file ||
1861 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1863 $RUNAS $LFS hsm_$action $file &&
1864 error "$action by user should fail"
1866 set_hsm_param user_request_mask $action
1867 $RUNAS $LFS hsm_$action $file ||
1868 error "$action by user should succeed"
1871 create_small_file $file
1872 chown nobody:$RUNAS_GID $file ||
1873 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1875 $RUNAS $LFS hsm_$action $file &&
1876 error "$action by group should fail"
1878 set_hsm_param group_request_mask $action
1879 $RUNAS $LFS hsm_$action $file ||
1880 error "$action by group should succeed"
1883 create_small_file $file
1884 chown nobody:$GROUP $file ||
1885 error "cannot chown '$file' to 'nobody:$GROUP'"
1887 $RUNAS $LFS hsm_$action $file &&
1888 error "$action by other should fail"
1890 set_hsm_param other_request_mask $action
1891 $RUNAS $LFS hsm_$action $file ||
1892 error "$action by other should succeed"
1894 run_test 24c "check that user,group,other request masks work"
1897 local file1=$DIR/$tdir/$tfile
1898 local file2=$DIR2/$tdir/$tfile
1902 mkdir_on_mdt0 $DIR/$tdir
1904 fid1=$(create_small_file $file1)
1907 $LFS getstripe $file1
1909 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1910 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1911 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1913 copytool setup -m "$MOUNT3"
1915 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1916 mount -o remount,ro $MOUNT2
1918 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1920 fid2=$(path2fid $file2)
1921 [ "$fid1" == "$fid2" ] ||
1922 error "FID mismatch '$fid1' != '$fid2'"
1924 $LFS hsm_archive $file2 &&
1925 error "archive should fail on read-only mount"
1926 check_hsm_flags $file1 "0x00000000"
1928 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1929 wait_request_state $fid1 ARCHIVE SUCCEED
1931 $LFS hsm_release $file1
1932 $LFS hsm_restore $file2
1933 wait_request_state $fid1 RESTORE SUCCEED
1935 $LFS hsm_release $file1 || error "cannot release '$file1'"
1936 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1938 $LFS hsm_release $file2 &&
1939 error "release should fail on read-only mount"
1943 run_test 24d "check that read-only mounts are respected"
1947 mkdir_on_mdt0 $DIR/$tdir
1949 local f=$DIR/$tdir/$tfile
1952 fid=$(create_small_file $f) || error "cannot create $f"
1953 $LFS hsm_archive $f || error "cannot archive $f"
1954 wait_request_state $fid ARCHIVE SUCCEED
1955 $LFS hsm_release $f || error "cannot release $f"
1956 while ! $LFS hsm_state $f | grep released; do
1960 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1962 run_test 24e "tar succeeds on HSM released files" # LU-6213
1965 # test needs a running copytool
1967 mkdir_on_mdt0 $DIR/$tdir
1969 mkdir -p $DIR/$tdir/d1
1970 local f=$DIR/$tdir/$tfile
1971 local fid=$(copy_file /etc/hosts $f)
1974 $LFS hsm_archive $f ||
1975 error "hsm_archive failed"
1976 wait_request_state $fid ARCHIVE SUCCEED
1977 $LFS hsm_release $f || error "cannot release $f"
1978 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1981 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1982 error "Can not recover the tar contents"
1984 echo "Sum0 = $sum0, sum1 = $sum1"
1985 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1987 run_test 24f "root can archive, release, and restore tar files"
1990 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1991 skip "need MDS version 2.11.56 or later"
1993 local file=$DIR/$tdir/$tfile
1996 echo "RUNAS = '$RUNAS'"
2000 mkdir_on_mdt0 $DIR/$tdir
2001 chmod ugo+rwx $DIR/$tdir
2003 echo "Please listen carefully as our options have changed." | tee $file
2004 fid=$(path2fid $file)
2007 $LFS hsm_archive $file
2008 wait_request_state $fid ARCHIVE SUCCEED
2009 check_hsm_flags $file 0x00000009 # exists archived
2011 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2012 check_hsm_flags $file 0x0000000b # exists dirty archived
2014 run_test 24g "write by non-owner still sets dirty" # LU-11369
2017 # test needs a running copytool
2021 copy2archive /etc/hosts $tdir/$tfile
2023 local f=$DIR/$tdir/$tfile
2025 copytool import $tdir/$tfile $f
2027 $LFS hsm_set --lost $f
2032 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2034 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2035 " (Operation not permitted)"
2038 # test needs a running copytool
2041 mkdir_on_mdt0 $DIR/$tdir
2043 local f=$DIR/$tdir/$tfile
2044 local fid=$(copy_file /etc/passwd $f)
2046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2047 wait_request_state $fid ARCHIVE SUCCEED
2050 $LFS hsm_set --lost $f
2054 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2056 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2057 " (Operation not permitted)"
2059 test_26A() { # was test_26
2060 # test needs a running copytool
2062 mkdir_on_mdt0 $DIR/$tdir
2064 local f=$DIR/$tdir/$tfile
2065 local fid=$(create_empty_file "$f")
2067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2068 wait_request_state $fid ARCHIVE SUCCEED
2071 wait_request_state $fid REMOVE SUCCEED
2073 check_hsm_flags $f "0x00000000"
2075 run_test 26A "Remove the archive of a valid file"
2078 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2079 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2081 # test needs a running copytool
2083 mkdir_on_mdt0 $DIR/$tdir
2085 local f=$DIR/$tdir/$tfile
2086 local fid=$(copy_file /etc/passwd $f)
2088 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2089 wait_request_state $fid ARCHIVE SUCCEED
2091 local f2=$DIR/$tdir/${tfile}_2
2092 local fid2=$(copy_file /etc/passwd $f2)
2094 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2095 wait_request_state $fid2 ARCHIVE SUCCEED
2097 local f3=$DIR/$tdir/${tfile}_3
2098 local fid3=$(copy_file /etc/passwd $f3)
2100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2101 wait_request_state $fid3 ARCHIVE SUCCEED
2103 # set a long grace_delay vs short loop_period
2104 local orig_loop_period=$(get_hsm_param loop_period)
2105 local orig_grace_delay=$(get_hsm_param grace_delay)
2106 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2107 set_hsm_param loop_period 10
2108 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2109 set_hsm_param grace_delay 100
2113 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2114 set_hsm_param remove_archive_on_last_unlink 1
2116 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2121 wait_request_state $fid2 REMOVE SUCCEED
2123 assert_request_count $fid REMOVE 0 \
2124 "Unexpected archived data remove request for $f"
2125 assert_request_count $fid3 REMOVE 0 \
2126 "Unexpected archived data remove request for $f3"
2128 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2131 # test needs a running copytool
2133 mkdir_on_mdt0 $DIR/$tdir
2135 local f=$DIR/$tdir/$tfile
2136 local fid=$(copy_file /etc/passwd $f)
2138 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2139 wait_request_state $fid ARCHIVE SUCCEED
2141 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2142 set_hsm_param remove_archive_on_last_unlink 1
2145 cdt_check_state stopped
2149 wait_request_state $fid REMOVE WAITING
2153 # copytool must re-register
2155 wait_copytools || error "copytool failed to stop"
2158 wait_request_state $fid REMOVE SUCCEED
2160 run_test 26b "RAoLU policy when CDT off"
2163 # test needs a running copytool
2165 mkdir_on_mdt0 $DIR/$tdir
2167 local f=$DIR/$tdir/$tfile
2168 local fid=$(copy_file /etc/passwd $f)
2170 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2171 wait_request_state $fid ARCHIVE SUCCEED
2173 local f2=$DIR/$tdir/${tfile}_2
2174 local fid2=$(copy_file /etc/passwd $f2)
2176 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2177 wait_request_state $fid2 ARCHIVE SUCCEED
2179 # set a long grace_delay vs short loop_period
2180 local orig_loop_period=$(get_hsm_param loop_period)
2181 local orig_grace_delay=$(get_hsm_param grace_delay)
2182 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2183 set_hsm_param loop_period 10
2184 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2185 set_hsm_param grace_delay 100
2187 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2188 set_hsm_param remove_archive_on_last_unlink 1
2190 multiop_bg_pause $f O_c || error "open $f failed"
2196 wait_request_state $fid2 REMOVE SUCCEED
2197 assert_request_count $fid REMOVE 0 \
2198 "Unexpected archived data remove request for $f"
2200 kill -USR1 $pid || error "multiop early exit"
2201 # should reach autotest timeout if multiop fails to trap
2202 # signal, close file, and exit ...
2203 wait $pid || error "wait PID $PID failed"
2205 wait_request_state $fid REMOVE SUCCEED
2207 run_test 26c "RAoLU effective when file closed"
2210 # test needs a running copytool
2212 mkdir_on_mdt0 $DIR/$tdir
2214 local f=$DIR/$tdir/$tfile
2215 local fid=$(create_small_file $f)
2217 $LFS hsm_archive $f || error "could not archive file"
2218 wait_request_state $fid ARCHIVE SUCCEED
2220 # set a long grace_delay vs short loop_period
2221 local orig_loop_period=$(get_hsm_param loop_period)
2222 local orig_grace_delay=$(get_hsm_param grace_delay)
2223 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2224 set_hsm_param loop_period 10
2225 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2226 set_hsm_param grace_delay 100
2228 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2229 set_hsm_param remove_archive_on_last_unlink 1
2231 multiop_bg_pause $f O_c || error "multiop failed"
2238 wait_request_state $fid REMOVE SUCCEED
2240 client_up || client_up || true
2242 kill -USR1 $MULTIPID
2243 wait $MULTIPID || error "multiop close failed"
2245 run_test 26d "RAoLU when Client eviction"
2248 # test needs a running copytool
2251 create_archive_file $tdir/$tfile
2252 local f=$DIR/$tdir/$tfile
2253 copytool import $tdir/$tfile $f
2254 local fid=$(path2fid $f)
2258 [[ $? != 0 ]] || error "Remove of a released file should fail"
2260 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2263 # test needs a running copytool
2265 mkdir_on_mdt0 $DIR/$tdir
2267 local f=$DIR/$tdir/$tfile
2268 local fid=$(create_empty_file "$f")
2270 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2271 wait_request_state $fid ARCHIVE SUCCEED
2276 [[ $? != 0 ]] || error "Remove of a released file should fail"
2278 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2281 # test needs a running copytool
2283 mkdir_on_mdt0 $DIR/$tdir
2285 local f=$DIR/$tdir/$tfile
2286 local fid=$(create_empty_file "$f")
2288 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2289 wait_request_state $fid ARCHIVE SUCCEED
2298 wait_request_state $fid REMOVE SUCCEED
2300 run_test 28 "Concurrent archive/file remove"
2303 # Tests --mntpath and --archive options
2306 copytool setup -m "$MOUNT" -a $archive_id
2308 # Bad archive number
2309 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2310 grep "Invalid argument" ||
2311 error "unexpected hsm_remove failure (1)"
2313 # mntpath is present but file is given
2314 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2315 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2316 error "unexpected hsm_remove failure (2)"
2318 run_test 29a "Tests --mntpath and --archive options"
2321 # test needs a running copytool
2323 mkdir_on_mdt0 $DIR/$tdir
2325 local f=$DIR/$tdir/$tfile
2326 local fid=$(create_small_file $f)
2328 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2329 wait_request_state $fid ARCHIVE SUCCEED
2333 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2334 wait_request_state $fid REMOVE SUCCEED
2336 run_test 29b "Archive/delete/remove by FID from the archive."
2339 # test needs a running copytool
2341 mkdir_on_mdt0 $DIR/$tdir
2343 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2344 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2345 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2347 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2348 wait_request_state $fid1 ARCHIVE SUCCEED
2349 wait_request_state $fid2 ARCHIVE SUCCEED
2350 wait_request_state $fid3 ARCHIVE SUCCEED
2352 rm -f $DIR/$tdir/$tfile-[1-3]
2354 echo $fid1 > $DIR/$tdir/list
2355 echo $fid2 >> $DIR/$tdir/list
2356 echo $fid3 >> $DIR/$tdir/list
2358 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2359 --filelist $DIR/$tdir/list
2360 wait_request_state $fid1 REMOVE SUCCEED
2361 wait_request_state $fid2 REMOVE SUCCEED
2362 wait_request_state $fid3 REMOVE SUCCEED
2364 run_test 29c "Archive/delete/remove by FID, using a file list."
2367 # test needs more than one CT
2368 needclients 3 || return 0
2374 # start all of the copytools
2375 for n in $(seq $AGTCOUNT); do
2376 copytool setup -f agt$n -a $n
2379 mkdir_on_mdt0 $DIR/$tdir
2382 file=$DIR/$tdir/$tfile
2383 fid=$(create_small_file $file)
2385 $LFS hsm_archive $file
2386 wait_request_state $fid ARCHIVE SUCCEED
2387 check_hsm_flags $file "0x00000009"
2391 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2392 error "cannot hsm_remove '$fid'"
2394 # give time for CDT to handle remove request and create broadcasted
2397 # remove request has been broadcasted ?
2398 local cnt=$(get_request_count $fid REMOVE)
2399 # broadcasted requests + original
2400 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2401 error "remove not broadcasted to all CTs"
2403 # give time for CDT and CTs to handle broadcasted
2404 wait_for_loop_period
2406 # each agent serves one different archive_id, so broadcasted
2407 # hsm_remove request should only succeed once and fail at all others
2411 for n in $(seq $AGTCOUNT); do
2412 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2413 $HSM_PARAM.actions | awk \
2414 '/'$fid'.*action=REMOVE archive#='$n'/ \
2415 {print \\\$13}' | cut -f2 -d=")
2416 if [[ "$res" == "SUCCEED" ]]; then
2418 elif [[ "$res" == "FAILED" ]]; then
2423 [[ $scnt -eq 1 ]] ||
2424 error "one and only CT should have removed successfully"
2426 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2427 error "all but one CT should have failed to remove"
2429 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2430 "request to be sent once for each registered archive_id"
2433 # restore at exec cannot work on agent node (because of Linux kernel
2434 # protection of executables)
2435 needclients 2 || return 0
2437 # test needs a running copytool
2441 copy2archive /bin/true $tdir/$tfile
2443 local f=$DIR/$tdir/true
2444 copytool import $tdir/$tfile $f
2446 local fid=$(path2fid $f)
2448 stack_trap "cdt_clear_no_retry" EXIT
2449 # set no retry action mode
2456 [[ $st == 0 ]] || error "Failed to exec a released file"
2458 run_test 30a "Restore at exec (import case)"
2461 # restore at exec cannot work on agent node (because of Linux kernel
2462 # protection of executables)
2463 needclients 2 || return 0
2465 # test needs a running copytool
2468 mkdir_on_mdt0 $DIR/$tdir
2469 local f=$DIR/$tdir/true
2470 local fid=$(copy_file /bin/true $f)
2472 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2473 wait_request_state $fid ARCHIVE SUCCEED
2477 stack_trap cdt_clear_no_retry EXIT
2478 # set no retry action mode
2486 [[ $st == 0 ]] || error "Failed to exec a released file"
2488 run_test 30b "Restore at exec (release case)"
2491 needclients 2 || return 0
2493 # test needs a running copytool
2496 mkdir_on_mdt0 $DIR/$tdir
2497 local f=$DIR/$tdir/SLEEP
2498 local slp_sum1=$(md5sum /bin/sleep)
2499 local fid=$(copy_file /bin/sleep $f)
2501 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2502 wait_request_state $fid ARCHIVE SUCCEED
2504 check_hsm_flags $f "0x0000000d"
2506 stack_trap cdt_clear_no_retry EXIT
2507 # set no retry action mode
2510 do_node $CLIENT2 "$f 10" &
2514 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2516 [[ $? == 0 ]] || error "Execution failed during run"
2518 if [[ $? != 0 ]]; then
2519 local slp_sum2=$(md5sum /bin/sleep)
2520 # in case sleep file is modified during the test
2521 [[ $slp_sum1 == $slp_sum2 ]] &&
2522 error "Binary overwritten during exec"
2525 check_hsm_flags $f "0x00000009"
2527 run_test 30c "Update during exec of released file must fail"
2529 restore_and_check_size() {
2532 local s=$(stat -c "%s" $f)
2534 local st=$(get_hsm_flags $f)
2538 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2540 n=$(stat -c "%s" $f)
2541 # we echo in both cases to show stat is not hang
2542 if [[ $n != $s ]]; then
2543 echo "size seen is $n != $s"
2546 echo "size seen is right: $n == $s"
2550 st=$(get_hsm_flags $f)
2552 if [[ "$st" = "0x00000009" ]]; then
2555 echo " restore is too long"
2556 wait_request_state $fid RESTORE SUCCEED
2562 # test needs a running copytool
2564 mkdir_on_mdt0 $DIR/$tdir
2566 create_archive_file $tdir/$tfile
2567 local f=$DIR/$tdir/$tfile
2568 copytool import $tdir/$tfile $f
2569 local fid=$($LFS path2fid $f)
2572 restore_and_check_size $f $fid
2575 [[ $err -eq 0 ]] || error "File size changed during restore"
2577 run_test 31a "Import a large file and check size during restore"
2581 # test needs a running copytool
2583 mkdir_on_mdt0 $DIR/$tdir
2585 local f=$DIR/$tdir/$tfile
2586 local fid=$(create_file "$f" 1MB 39)
2588 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2589 wait_request_state $fid ARCHIVE SUCCEED
2592 restore_and_check_size $f $fid
2595 [[ $err -eq 0 ]] || error "File size changed during restore"
2597 run_test 31b "Restore a large unaligned file and check size during restore"
2600 # test needs a running copytool
2602 mkdir_on_mdt0 $DIR/$tdir
2604 local f=$DIR/$tdir/$tfile
2605 local fid=$(create_file "$f" 1M 39)
2607 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2608 wait_request_state $fid ARCHIVE SUCCEED
2611 restore_and_check_size $f $fid
2614 [[ $err -eq 0 ]] || error "File size changed during restore"
2616 run_test 31c "Restore a large aligned file and check size during restore"
2619 local f=$DIR/$tdir/$tfile
2621 mkdir_on_mdt0 $DIR/$tdir
2622 local fid=$(create_empty_file "$f")
2626 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2627 wait_request_state $fid ARCHIVE SUCCEED
2630 # Prevent restore from completing
2634 md5sum $f >/dev/null &
2637 wait_request_state $fid RESTORE STARTED
2642 # Check restore trigger process was killed
2644 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2646 run_test 33 "Kill a restore waiting process"
2649 # test needs a running copytool
2651 mkdir_on_mdt0 $DIR/$tdir
2653 local f=$DIR/$tdir/$tfile
2654 local fid=$(create_empty_file "$f")
2656 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2657 wait_request_state $fid ARCHIVE SUCCEED
2660 # Prevent restore from completing
2663 md5sum $f >/dev/null &
2666 wait_request_state $fid RESTORE STARTED
2668 # rm must not block during restore
2669 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2672 wait_request_state $fid RESTORE SUCCEED
2674 # Check md5sum pgm finished
2675 kill -0 $pid && error "Restore initiatior still running"
2676 wait $pid || error "Restore initiator failed with $?"
2678 # Check the file was actually deleted
2679 [ ! -f "$f" ] || error "$f was not deleted"
2681 run_test 34 "Remove file during restore"
2684 # test needs a running copytool
2686 mkdir_on_mdt0 $DIR/$tdir
2688 local f=$DIR/$tdir/$tfile
2689 local f1=$DIR/$tdir/$tfile-1
2690 local fid=$(create_empty_file "$f")
2691 local fid1=$(copy_file /etc/passwd $f1)
2693 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2694 wait_request_state $fid ARCHIVE SUCCEED
2697 # Prevent restore from completing
2700 md5sum $f >/dev/null &
2703 wait_request_state $fid RESTORE STARTED
2705 # mv must not block during restore
2706 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2709 wait_request_state $fid RESTORE SUCCEED
2711 # Check md5sum pgm finished
2712 kill -0 $pid && error "Restore initiatior still running"
2713 wait $pid || error "Restore initiator failed with $?"
2715 local fid2=$(path2fid $f)
2716 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2718 run_test 35 "Overwrite file during restore"
2721 # test needs a running copytool
2723 mkdir_on_mdt0 $DIR/$tdir
2725 local f=$DIR/$tdir/$tfile
2726 local fid=$(create_empty_file "$f")
2728 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2729 wait_request_state $fid ARCHIVE SUCCEED
2732 # Prevent restore from completing
2735 md5sum $f >/dev/null &
2738 wait_request_state $fid RESTORE STARTED
2740 # mv must not block during restore
2741 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2742 error "mv '$f' '$f.new' failed with rc=$?"
2745 wait_request_state $fid RESTORE SUCCEED
2747 # Check md5sum pgm finished
2748 kill -0 $pid && error "Restore initiator is still running"
2749 wait $pid || error "Restore initiator failed with $?"
2751 run_test 36 "Move file during restore"
2754 # LU-5683: check that an archived dirty file can be rearchived.
2756 mkdir_on_mdt0 $DIR/$tdir
2758 local f=$DIR/$tdir/$tfile
2761 fid=$(create_small_file $f) || error "cannot create small file"
2763 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2764 wait_request_state $fid ARCHIVE SUCCEED
2765 $LFS hsm_release $f || error "cannot release $f"
2767 # Allow previous archive request to expire from the actions log.
2768 wait_for_grace_delay
2771 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2773 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2774 wait_request_state $fid ARCHIVE SUCCEED
2776 run_test 37 "re-archive a dirty file"
2783 for n in $(seq 1 $count); do
2784 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2786 echo "$count archive requests submitted"
2790 local stream_count=4
2791 local file_count=100
2793 local f=$DIR/$tdir/$tfile
2797 local max_requests=$(get_hsm_param max_requests)
2799 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2800 # Increase the number of HSM request that can be performed in
2801 # parallel. With the coordinator running once per second, this
2802 # also limits the number of requests per seconds that can be
2803 # performed, so we pick a decent number. But we also need to keep
2804 # that number low because the copytool has no rate limit and will
2805 # fail some requests if if gets too many at once.
2806 set_hsm_param max_requests 300
2808 for i in $(seq 1 $file_count); do
2809 for p in $(seq 1 $stream_count); do
2810 fid=$(copy_file /etc/hosts $f.$p.$i)
2816 # to be sure wait_all_done will not be mislead by previous tests
2818 wait_for_grace_delay
2820 # start archive streams in background (archive files in parallel)
2821 for p in $(seq 1 $stream_count); do
2822 multi_archive $f.$p $file_count &
2825 echo -n "Wait for all requests being enqueued..."
2830 run_test 40 "Parallel archive requests"
2832 hsm_archive_batch() {
2840 while [ $i -lt $files_num ]; do
2841 if [ $batch_num -eq $batch_max ]; then
2842 $LFS hsm_archive $fileset || error "HSM archive failed"
2843 # Reset the batch container.
2848 fileset+="${filebase}$i "
2849 batch_num=$(( batch_num + 1 ))
2853 if [ $batch_num -ne 0 ]; then
2854 $LFS hsm_archive $fileset || error "HSM archive failed"
2861 local dir=$DIR/$tdir
2864 set_hsm_param max_requests 1000000
2865 mkdir $dir || error "mkdir $dir failed"
2874 filebase="$dir/$tfile.start."
2875 createmany -m $filebase $files_num ||
2876 error "createmany -m $filebase failed: $?"
2879 hsm_archive_batch $files_num $batch_max "$filebase"
2880 elapsed=$((SECONDS - start))
2881 do_facet $SINGLEMDS "$LCTL get_param -n \
2882 $HSM_PARAM.actions | grep WAITING | wc -l"
2883 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2884 echo "Start Phase files_num: $files_num time: $elapsed"
2887 filebase="$dir/$tfile.in."
2888 createmany -m $filebase $files_num ||
2889 error "createmany -m $filebase failed: $?"
2891 hsm_archive_batch $files_num $batch_max "$filebase"
2892 elapsed=$((SECONDS - start))
2893 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2894 echo "Middle Phase files_num: $files_num time: $elapsed"
2897 filebase="$dir/$tfile.end."
2898 createmany -m $filebase $files_num ||
2899 error "createmany -m $filebase failed: $?"
2902 hsm_archive_batch $files_num $batch_max "$filebase"
2903 elapsed=$((SECONDS - start))
2904 do_facet $SINGLEMDS "$LCTL get_param -n \
2905 $HSM_PARAM.actions | grep WAITING | wc -l"
2907 unlinkmany $filebase $files_num || error "unlinkmany $filebase failed"
2908 echo "End Phase files_num: $files_num time: $elapsed"
2910 do_facet $SINGLEMDS "$LCTL get_param -n \
2911 $HSM_PARAM.actions | grep WAITING | wc -l"
2915 run_test 50 "Archive with large number of pending HSM actions"
2918 # test needs a running copytool
2921 mkdir_on_mdt0 $DIR/$tdir
2922 local f=$DIR/$tdir/$tfile
2923 local fid=$(create_small_file $f)
2925 $LFS hsm_archive $f || error "could not archive file"
2926 wait_request_state $fid ARCHIVE SUCCEED
2927 check_hsm_flags $f "0x00000009"
2929 multiop_bg_pause $f O_c || error "multiop failed"
2933 client_up || client_up || true
2935 kill -USR1 $MULTIPID
2936 wait $MULTIPID || error "multiop close failed"
2938 check_hsm_flags $f "0x0000000b"
2940 run_test 52 "Opened for write file on an evicted client should be set dirty"
2943 # test needs a running copytool
2946 mkdir_on_mdt0 $DIR/$tdir
2947 local f=$DIR/$tdir/$tfile
2948 local fid=$(create_small_file $f)
2950 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2951 error "could not archive file"
2952 wait_request_state $fid ARCHIVE SUCCEED
2953 check_hsm_flags $f "0x00000009"
2955 multiop_bg_pause $f o_c || error "multiop failed"
2959 client_up || client_up || true
2961 kill -USR1 $MULTIPID
2962 wait $MULTIPID || error "multiop close failed"
2964 check_hsm_flags $f "0x00000009"
2966 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2969 mkdir_on_mdt0 $DIR/$tdir
2971 local f=$DIR/$tdir/$tfile
2972 local fid=$(create_file "$f" 1MB 39)
2976 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2977 error "could not archive file"
2978 wait_request_state $fid ARCHIVE STARTED
2980 check_hsm_flags $f "0x00000001"
2982 stack_trap "cdt_clear_no_retry" EXIT
2983 # Avoid coordinator resending this request as soon it has failed.
2988 wait_request_state $fid ARCHIVE FAILED
2990 check_hsm_flags $f "0x00000003"
2992 run_test 54 "Write during an archive cancels it"
2995 mkdir_on_mdt0 $DIR/$tdir
2997 local f=$DIR/$tdir/$tfile
2998 local fid=$(create_file "$f" 1MB 39)
3002 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3003 error "could not archive file"
3004 wait_request_state $fid ARCHIVE STARTED
3006 check_hsm_flags $f "0x00000001"
3008 stack_trap "cdt_clear_no_retry" EXIT
3009 # Avoid coordinator resending this request as soon it has failed.
3012 $TRUNCATE $f 1024 || error "truncate failed"
3014 wait_request_state $fid ARCHIVE FAILED
3016 check_hsm_flags $f "0x00000003"
3018 run_test 55 "Truncate during an archive cancels it"
3021 mkdir_on_mdt0 $DIR/$tdir
3023 local f=$DIR/$tdir/$tfile
3024 local fid=$(create_file "$f" 1MB 39)
3028 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3029 error "could not archive file"
3030 wait_request_state $fid ARCHIVE STARTED
3032 check_hsm_flags $f "0x00000001"
3034 # Change metadata and sync to be sure we are not changing only
3039 wait_request_state $fid ARCHIVE SUCCEED
3041 check_hsm_flags $f "0x00000009"
3043 run_test 56 "Setattr during an archive is ok"
3046 # Need one client for I/O, one for request
3047 needclients 2 || return 0
3049 # test needs a running copytool
3052 mkdir_on_mdt0 $DIR/$tdir
3053 local f=$DIR/$tdir/test_archive_remote
3054 # Create a file on a remote node
3055 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3056 "count=2 conv=fsync"
3059 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3060 error "hsm_archive failed"
3061 local fid=$(path2fid $f)
3062 wait_request_state $fid ARCHIVE SUCCEED
3064 # Release and implicit restore it
3065 do_node $CLIENT2 "$LFS hsm_release $f" ||
3066 error "hsm_release failed"
3067 do_node $CLIENT2 "md5sum $f" ||
3068 error "hsm_restore failed"
3070 wait_request_state $fid RESTORE SUCCEED
3072 run_test 57 "Archive a file with dirty cache on another node"
3074 truncate_released_file() {
3078 local sz=$(stat -c %s $src_file)
3079 local f=$DIR/$tdir/$tfile
3080 local fid=$(copy_file $1 $f)
3084 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3085 error "could not archive file"
3086 wait_request_state $fid ARCHIVE SUCCEED
3088 $LFS hsm_release $f || error "could not release file"
3090 $TRUNCATE $f $trunc_to || error "truncate failed"
3093 local sz1=$(stat -c %s $f)
3094 [[ $sz1 == $trunc_to ]] ||
3095 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3098 check_hsm_flags $f "0x0000000b"
3100 local state=$(get_request_state $fid RESTORE)
3101 [[ "$state" == "SUCCEED" ]] ||
3102 error "truncate $sz does not trig restore, state = $state"
3104 $TRUNCATE $ref $trunc_to
3105 cmp $ref $f || error "file data wrong after truncate"
3111 # test needs a running copytool
3114 mkdir_on_mdt0 $DIR/$tdir
3116 local sz=$(stat -c %s /etc/passwd)
3118 echo "truncate up from $sz to $((sz*2))"
3119 truncate_released_file /etc/passwd $((sz*2))
3121 echo "truncate down from $sz to $((sz/2))"
3122 truncate_released_file /etc/passwd $((sz/2))
3124 echo "truncate to 0"
3125 truncate_released_file /etc/passwd 0
3127 run_test 58 "Truncate a released file will trigger restore"
3131 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3132 skip "Need MDS version at least 2.7.63"
3135 $MCREATE $DIR/$tfile || error "mcreate failed"
3136 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3137 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3138 fid=$(path2fid $DIR/$tfile)
3139 wait_request_state $fid ARCHIVE SUCCEED
3140 $LFS hsm_release $DIR/$tfile || error "release failed"
3142 run_test 59 "Release stripeless file with non-zero size"
3145 # This test validates the fix for LU-4512. Ensure that the -u
3146 # option changes the progress reporting interval from the
3147 # default (30 seconds) to the user-specified interval.
3148 mkdir_on_mdt0 $DIR/$tdir
3150 local f=$DIR/$tdir/$tfile
3151 local fid=$(create_file "$f" 1M 10)
3154 local progress_timeout=$((interval * 4))
3155 copytool setup -b 1 --update-interval $interval
3158 local mdt=${MDT_PREFIX}${mdtidx}
3159 local mds=mds$((mdtidx + 1))
3161 # Wait for copytool to register
3162 wait_update_facet $mds \
3163 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3164 uuid 100 || error "coyptool failed to register with $mdt"
3166 local start_at=$(date +%s)
3167 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3168 error "could not archive file"
3170 local agent=$(facet_active_host $SINGLEAGT)
3171 local logfile=$(copytool_logfile $SINGLEAGT)
3173 wait_update $agent \
3174 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3175 error "copytool failed to start"
3177 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3178 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3184 echo -n "Expecting a progress update within $progress_timeout seconds... "
3186 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3187 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3188 echo "$RESULT bytes copied in $WAIT seconds."
3190 elif [ $WAIT -ge $progress_timeout ]; then
3191 error "Timed out waiting for progress update!"
3194 WAIT=$((WAIT + sleep))
3198 local finish_at=$(date +%s)
3199 local elapsed=$((finish_at - start_at))
3201 # Ensure that the progress update occurred within the expected window.
3202 if [ $elapsed -lt $((interval - 1)) ]; then
3203 error "Expected progress update after at least $interval seconds"
3206 echo "Wait for on going archive hsm action to complete"
3207 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3208 echo "File archiving not completed even after 10 secs"
3210 run_test 60 "Changing progress update interval from default"
3213 # test needs a running copytool
3216 mkdir_on_mdt0 $DIR/$tdir
3217 local f=$DIR/$tdir/$tfile
3218 local fid=$(copy_file /etc/passwd $f)
3220 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3223 wait_request_state $fid ARCHIVE FAILED
3225 run_test 61 "Waiting archive of a removed file should fail"
3228 # test needs a new running copytool
3229 stack_trap copytool_monitor_cleanup EXIT
3230 copytool_monitor_setup
3231 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3233 # Wait for the copytool to register.
3234 wait_update --verbose $(facet_active_host mds1) \
3235 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3237 error "copytool failed to register with MDT0000"
3240 wait_copytools || error "Copytools failed to stop"
3242 local REGISTER_EVENT
3243 local UNREGISTER_EVENT
3244 while read event; do
3245 local parsed=$(parse_json_event "$event")
3246 if [ -z "$parsed" ]; then
3247 error "Copytool sent malformed event: $event"
3251 if [ $event_type == "REGISTER" ]; then
3252 REGISTER_EVENT=$event
3253 elif [ $event_type == "UNREGISTER" ]; then
3254 UNREGISTER_EVENT=$event
3256 done < <(echo $"$(get_copytool_event_log)")
3258 if [ -z "$REGISTER_EVENT" ]; then
3259 error "Copytool failed to send register event to FIFO"
3262 if [ -z "$UNREGISTER_EVENT" ]; then
3263 error "Copytool failed to send unregister event to FIFO"
3266 echo "Register/Unregister events look OK."
3268 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3271 # Bump progress interval for livelier events.
3274 # test needs a new running copytool
3275 stack_trap copytool_monitor_cleanup EXIT
3276 copytool_monitor_setup
3277 copytool setup --update-interval $interval --event-fifo \
3278 "$HSMTOOL_MONITOR_DIR/fifo"
3280 stack_trap "cdt_clear_no_retry" EXIT
3281 # Just start and stop the copytool to generate events.
3284 mkdir_on_mdt0 $DIR/$tdir
3286 local f=$DIR/$tdir/$tfile
3287 local fid=$(create_small_file "$f")
3289 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3290 error "could not archive file"
3291 wait_request_state $fid ARCHIVE SUCCEED
3293 local expected_fields="event_time data_fid source_fid"
3294 expected_fields+=" total_bytes current_bytes"
3297 [ARCHIVE_START]=false
3298 [ARCHIVE_FINISH]=false
3299 [ARCHIVE_RUNNING]=false
3301 while read event; do
3302 # Make sure we're not getting anything from previous events.
3303 for field in $expected_fields; do
3307 local parsed=$(parse_json_event "$event")
3308 if [ -z "$parsed" ]; then
3309 error "Copytool sent malformed event: $event"
3313 events["$event_type"]=true
3315 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3317 # Do some simple checking of the progress update events.
3318 for expected_field in $expected_fields; do
3319 if [ -z ${!expected_field+x} ]; then
3320 error "Missing $expected_field field in event"
3324 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3326 # These should be identical throughout an archive operation
3327 [ $source_fid == $data_fid ] ||
3328 error "Expected source_fid to equal data_fid"
3329 done < <(echo $"$(get_copytool_event_log)")
3331 # Check we received every type of events we were expecting
3332 for event in "${!events[@]}"; do
3333 ${events["$event"]} ||
3334 error "Copytool failed to send '$event' event to FIFO"
3337 echo "Archive events look OK."
3339 run_test 71 "Copytool logs JSON archive events to FIFO"
3342 # Bump progress interval for livelier events.
3345 # test needs a new running copytool
3346 stack_trap copytool_monitor_cleanup EXIT
3347 copytool_monitor_setup
3348 copytool setup --update-interval $interval --event-fifo \
3349 "$HSMTOOL_MONITOR_DIR/fifo"
3350 local test_file=$HSMTOOL_MONITOR_DIR/file
3352 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3354 do_facet $SINGLEAGT "$cmd" ||
3355 error "cannot create $test_file on $SINGLEAGT"
3356 copy2archive $test_file $tdir/$tfile
3358 mkdir_on_mdt0 $DIR/$tdir
3359 local f=$DIR/$tdir/$tfile
3360 copytool import $tdir/$tfile $f
3361 f=$DIR2/$tdir/$tfile
3362 echo "Verifying released state: "
3363 check_hsm_flags $f "0x0000000d"
3365 local fid=$(path2fid $f)
3367 wait_request_state $fid RESTORE SUCCEED
3369 local expected_fields="event_time data_fid source_fid"
3370 expected_fields+=" total_bytes current_bytes"
3374 while read event; do
3375 # Make sure we're not getting anything from previous events.
3376 for field in $expected_fields; do
3380 local parsed=$(parse_json_event "$event")
3381 if [ -z "$parsed" ]; then
3382 error "Copytool sent malformed event: $event"
3386 if [ $event_type == "RESTORE_START" ]; then
3388 if [ $source_fid != $data_fid ]; then
3389 error "source_fid should == data_fid at start"
3392 elif [ $event_type == "RESTORE_FINISH" ]; then
3394 if [ $source_fid != $data_fid ]; then
3395 error "source_fid should == data_fid at finish"
3398 elif [ $event_type != "RESTORE_RUNNING" ]; then
3402 # Do some simple checking of the progress update events.
3403 for expected_field in $expected_fields; do
3404 if [ -z ${!expected_field+x} ]; then
3405 error "Missing $expected_field field in event"
3409 if [ $total_bytes -eq 0 ]; then
3410 error "Expected total_bytes to be > 0"
3413 # When a restore starts out, the data fid is the same as the
3414 # source fid. After the restore has gotten going, we learn
3415 # the new data fid. Once the restore has finished, the source
3416 # fid is set to the new data fid.
3418 # We test this because some monitoring software may depend on
3419 # this behavior. If it changes, then the consumers of these
3420 # events may need to be modified.
3421 if [ $source_fid == $data_fid ]; then
3422 error "source_fid should != data_fid during restore"
3424 done < <(echo $"$(get_copytool_event_log)")
3426 if [ -z "$START_EVENT" ]; then
3427 error "Copytool failed to send restore start event to FIFO"
3430 if [ -z "$FINISH_EVENT" ]; then
3431 error "Copytool failed to send restore finish event to FIFO"
3434 echo "Restore events look OK."
3436 run_test 72 "Copytool logs JSON restore events to FIFO"
3439 file_count=51 # Max number of files constrained by LNET message size
3440 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3441 local f=$DIR/$tdir/$tfile
3442 local FILELIST=/tmp/filelist.txt
3446 for i in $(seq 1 $file_count); do
3447 fid=$(copy_file /etc/hosts $f.$i)
3448 echo $f.$i >> $FILELIST
3452 # to be sure wait_all_done will not be mislead by previous tests
3454 wait_for_grace_delay
3455 $LFS hsm_archive --filelist $FILELIST ||
3456 error "cannot archive a file list"
3458 $LFS hsm_release --filelist $FILELIST ||
3459 error "cannot release a file list"
3460 $LFS hsm_restore --filelist $FILELIST ||
3461 error "cannot restore a file list"
3464 run_test 90 "Archive/restore a file list"
3466 double_verify_reset_hsm_param() {
3468 echo "Testing $HSM_PARAM.$p"
3469 local val=$(get_hsm_param $p)
3471 local val2=$(($val * 2))
3472 set_hsm_param $p $val2
3473 val=$(get_hsm_param $p)
3474 [[ $val == $val2 ]] ||
3475 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3476 echo "Set $p to 0 must failed"
3480 set_hsm_param $p $save
3482 if [[ $rc == 0 ]]; then
3483 error "we must not be able to set $HSM_PARAM.$p to 0"
3488 double_verify_reset_hsm_param loop_period
3489 double_verify_reset_hsm_param grace_delay
3490 double_verify_reset_hsm_param active_request_timeout
3491 double_verify_reset_hsm_param max_requests
3492 double_verify_reset_hsm_param default_archive_id
3494 run_test 100 "Set coordinator /proc tunables"
3501 run_test 102 "Verify coordinator control"
3504 # test needs a running copytool
3511 for i in $(seq 1 20); do
3512 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3514 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3518 echo "Current requests"
3519 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3520 $HSM_PARAM.actions |\
3521 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3523 [[ -z "$res" ]] || error "Some request have not been canceled"
3525 run_test 103 "Purge all requests"
3528 (( MDS1_VERSION >= $(version_code 2.14.56) )) ||
3529 skip "Need MDS version at least 2.14.56"
3531 cdt_clear_non_blocking_restore
3533 # test needs a running copytool
3538 local rpcs_inflight=$($LCTL get_param -n \
3539 "mdc.$(facet_svc mds1)*.max_rpcs_in_flight" |
3542 mkdir_on_mdt0 $DIR/$tdir
3543 for ((i=0; i < rpcs_inflight; i++)); do
3544 fids+=( $(copy_file /etc/passwd $DIR/$tdir/${tfile}_$i) )
3546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3550 local grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=ARCHIVE.*status=SUCCEED"
3552 while [[ $time -lt 5 ]] && [[ $cnt -ne ${#fids[@]} ]]; do
3553 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3554 grep -c -E '$grep_regex'")
3558 [[ $cnt -eq ${#fids[@]} ]] || error "Fail to archive files $cnt/${#fids[@]}"
3560 $LFS hsm_release $DIR/$tdir/*
3563 wait_copytools || error "Copytool failed to stop"
3566 for i in "${fids[@]}"; do
3567 cat $DIR/.lustre/fid/$i > /dev/null & pids+=($!)
3571 grep_regex="($(tr ' ' '|' <<< "${fids[*]}")).*action=RESTORE.*status=CANCELED"
3572 cnt=$(do_facet mds1 "$LCTL get_param -n $HSM_PARAM.actions |
3573 grep -cE '$grep_regex'")
3575 [[ "$cnt" -eq ${#fids[@]} ]] ||
3576 error "Some request have not been canceled ($cnt/${#fids[@]} canceled)"
3578 # cat cmds should not hang and should fail
3579 for i in "${!pids[@]}"; do
3581 error "Restore for ${tfile}_$i (${pids[$i]}) should fail" ||
3585 run_test 103a "Purge pending restore requests"
3590 mkdir_on_mdt0 $DIR/$tdir
3592 local f=$DIR/$tdir/$tfile
3593 local fid=$(create_empty_file "$f")
3595 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3596 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3597 $HSM_PARAM.actions |\
3598 grep $fid | cut -f16 -d=")
3600 [[ "$data1" == "$DATAHEX" ]] ||
3601 error "Data field in records is ($data1) and not ($DATAHEX)"
3605 run_test 104 "Copy tool data field"
3608 local max_requests=$(get_hsm_param max_requests)
3609 mkdir_on_mdt0 $DIR/$tdir
3612 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3613 set_hsm_param max_requests 300
3616 for i in $(seq -w 1 10); do
3617 cp /etc/passwd $DIR/$tdir/$i
3618 $LFS hsm_archive $DIR/$tdir/$i
3620 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3621 $HSM_PARAM.actions |\
3622 grep WAITING | wc -l")
3626 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3627 $HSM_PARAM.actions |\
3628 grep WAITING | wc -l")
3631 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3632 error "Requests count after shutdown $reqcnt2 != "\
3633 "before shutdown $reqcnt1"
3635 run_test 105 "Restart of coordinator"
3638 # test needs a running copytool
3641 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3643 check_agent_registered $uuid
3645 search_copytools || error "No copytool found"
3648 wait_copytools || error "Copytool failed to stop"
3650 check_agent_unregistered $uuid
3653 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3654 check_agent_registered $uuid
3656 run_test 106 "Copytool register/unregister"
3659 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3661 # test needs a running copytool
3663 # create and archive file
3664 mkdir_on_mdt0 $DIR/$tdir
3665 local f1=$DIR/$tdir/$tfile
3666 local fid=$(copy_file /etc/passwd $f1)
3667 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3668 wait_request_state $fid ARCHIVE SUCCEED
3669 # shutdown and restart MDS
3671 # check the copytool still gets messages from MDT
3672 local f2=$DIR/$tdir/2
3673 local fid=$(copy_file /etc/passwd $f2)
3674 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3675 # main check of this sanity: this request MUST succeed
3676 wait_request_state $fid ARCHIVE SUCCEED
3678 run_test 107 "Copytool re-register after MDS restart"
3680 policy_set_and_test()
3684 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3685 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3686 [[ "$policy" == "$target" ]] ||
3687 error "Wrong policy after '$change': '$policy' != '$target'"
3691 # to force default policy setting if error
3692 CDT_POLICY_HAD_CHANGED=true
3694 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3695 local default="NonBlockingRestore [NoRetryAction]"
3696 [[ "$policy" == "$default" ]] ||
3697 error "default policy has changed,"\
3698 " '$policy' != '$default' update the test"
3699 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3700 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3701 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3702 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3703 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3704 # useless bacause we know but safer for futur changes to use real value
3705 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3706 echo "Next set_param must failed"
3707 policy_set_and_test "wrong" "$policy"
3710 echo "Back to default policy"
3711 cdt_set_sanity_policy
3713 run_test 109 "Policy display/change"
3716 # test needs a running copytool
3719 mkdir_on_mdt0 $DIR/$tdir
3721 copy2archive /etc/passwd $tdir/$tfile
3723 local f=$DIR/$tdir/$tfile
3724 copytool import $tdir/$tfile $f
3725 local fid=$(path2fid $f)
3727 cdt_set_non_blocking_restore
3732 wait_request_state $fid RESTORE SUCCEED
3733 cdt_clear_non_blocking_restore
3737 error "md5sum returns $st != 1, "\
3738 "should also perror ENODATA (No data available)"
3740 run_test 110a "Non blocking restore policy (import case)"
3743 # test needs a running copytool
3746 mkdir_on_mdt0 $DIR/$tdir
3747 local f=$DIR/$tdir/$tfile
3748 local fid=$(copy_file /etc/passwd $f)
3749 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3750 wait_request_state $fid ARCHIVE SUCCEED
3753 cdt_set_non_blocking_restore
3758 wait_request_state $fid RESTORE SUCCEED
3759 cdt_clear_non_blocking_restore
3763 error "md5sum returns $st != 1, "\
3764 "should also perror ENODATA (No data available)"
3766 run_test 110b "Non blocking restore policy (release case)"
3769 # test needs a running copytool
3772 mkdir_on_mdt0 $DIR/$tdir
3773 copy2archive /etc/passwd $tdir/$tfile
3775 local f=$DIR/$tdir/$tfile
3777 copytool import $tdir/$tfile $f
3778 local fid=$(path2fid $f)
3782 copytool_remove_backend $fid
3785 wait_request_state $fid RESTORE FAILED
3792 [[ $st == 0 ]] || error "Restore does not failed"
3794 run_test 111a "No retry policy (import case), restore will error"\
3795 " (No such file or directory)"
3798 # test needs a running copytool
3801 mkdir_on_mdt0 $DIR/$tdir
3802 local f=$DIR/$tdir/$tfile
3803 local fid=$(copy_file /etc/passwd $f)
3804 stack_trap cdt_clear_no_retry EXIT
3806 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3807 wait_request_state $fid ARCHIVE SUCCEED
3810 copytool_remove_backend $fid
3813 wait_request_state $fid RESTORE FAILED
3817 [[ $st == 0 ]] || error "Restore does not failed"
3819 run_test 111b "No retry policy (release case), restore will error"\
3820 " (No such file or directory)"
3823 # test needs a running copytool
3826 mkdir_on_mdt0 $DIR/$tdir
3827 local f=$DIR/$tdir/$tfile
3828 local fid=$(copy_file /etc/passwd $f)
3830 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3831 local l=$($LFS hsm_action $f)
3833 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3836 wait_request_state $fid ARCHIVE SUCCEED
3839 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3841 run_test 112 "State of recorded request"
3844 mkdir_on_mdt0 $DIR/$tdir
3846 local file1=$DIR/$tdir/$tfile
3847 local file2=$DIR2/$tdir/$tfile
3849 local fid=$(create_small_sync_file $file1)
3851 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3852 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3853 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3855 copytool setup -m "$MOUNT3"
3857 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3859 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3860 wait_request_state $fid ARCHIVE SUCCEED
3862 $LFS hsm_release $file1
3863 echo "Verifying released state: "
3864 check_hsm_flags $file1 "0x0000000d"
3866 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3869 kill -USR1 $MULTIPID
3874 local size1=$(stat -c "%s" $file1)
3875 local size2=$(stat -c "%s" $file2)
3877 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3879 run_test 113 "wrong stat after restore"
3882 mkdir_on_mdt0 $DIR/$tdir
3884 local f=$DIR/$tdir/$tfile
3885 local fid=$(create_empty_file "$f")
3889 # Prevent archive from completing
3892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3893 # wait archive to register at CDT
3894 wait_request_state $fid ARCHIVE STARTED
3896 # Cancel the archive
3897 $LFS hsm_cancel "$f"
3899 wait_request_state $fid ARCHIVE CANCELED
3902 wait_request_state $fid CANCEL SUCCEED
3904 run_test 200 "Register/Cancel archive"
3907 # test needs a running copytool
3909 mkdir_on_mdt0 $DIR/$tdir
3911 local f=$DIR/$tdir/$tfile
3912 create_archive_file $tdir/$tfile
3913 copytool import $tdir/$tfile $f
3914 local fid=$(path2fid $f)
3916 # test with cdt on is made in test_222
3919 # wait restore to register at CDT
3920 wait_request_state $fid RESTORE WAITING
3923 wait_request_state $fid RESTORE CANCELED
3924 wait_request_state $fid CANCEL SUCCEED
3926 run_test 201 "Register/Cancel restore"
3929 mkdir_on_mdt0 $DIR/$tdir
3931 local f=$DIR/$tdir/$tfile
3932 local fid=$(create_empty_file "$f")
3934 # test needs a running copytool
3937 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3938 wait_request_state $fid ARCHIVE SUCCEED
3942 # wait remove to register at CDT
3943 wait_request_state $fid REMOVE STARTED
3946 wait_request_state $fid REMOVE CANCELED
3948 run_test 202 "Register/Cancel remove"
3950 test_220A() { # was test_220
3951 # test needs a running copytool
3954 mkdir_on_mdt0 $DIR/$tdir
3956 local f=$DIR/$tdir/$tfile
3957 local fid=$(copy_file /etc/passwd $f)
3961 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3962 wait_request_state $fid ARCHIVE SUCCEED
3964 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3965 error "The expected changelog was not emitted"
3967 run_test 220A "Changelog for archive"
3970 # test needs a running copytool
3973 mkdir_on_mdt0 $DIR/$tdir
3975 local f=$DIR/$tdir/$tfile
3976 local fid=$(copy_file /etc/passwd $f)
3980 # block copytool operations to allow for HSM request to be
3981 # submitted and file be unlinked (CDT will find object removed)
3984 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3986 # wait request to reach CT
3987 wait_request_state $fid ARCHIVE STARTED
3993 wait_request_state $fid ARCHIVE FAILED
3996 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3997 error "The expected changelog was not emitted"
3999 run_test 220a "Changelog for failed archive"
4002 mkdir_on_mdt0 $DIR/$tdir
4004 local f=$DIR/$tdir/$tfile
4005 local fid=$(create_empty_file "$f")
4010 # Prevent archive from completing
4012 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4013 wait_request_state $fid ARCHIVE STARTED
4016 wait_request_state $fid ARCHIVE CANCELED
4019 wait_request_state $fid CANCEL SUCCEED
4021 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4022 error "The expected changelog was not emitted"
4024 run_test 221 "Changelog for archive canceled"
4027 # test needs a running copytool
4030 mkdir_on_mdt0 $DIR/$tdir
4031 copy2archive /etc/passwd $tdir/$tfile
4033 local f=$DIR/$tdir/$tfile
4034 copytool import $tdir/$tfile $f
4035 local fid=$(path2fid $f)
4040 wait_request_state $fid RESTORE SUCCEED
4042 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4043 error "The expected changelog was not emitted"
4045 run_test 222a "Changelog for explicit restore"
4048 # test needs a running copytool
4051 mkdir_on_mdt0 $DIR/$tdir
4052 local f=$DIR/$tdir/$tfile
4053 local fid=$(copy_file /etc/passwd $f)
4056 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4057 wait_request_state $fid ARCHIVE SUCCEED
4062 wait_request_state $fid RESTORE SUCCEED
4064 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4065 error "The expected changelog was not emitted"
4067 run_test 222b "Changelog for implicit restore"
4070 # test needs a running copytool
4073 mkdir_on_mdt0 $DIR/$tdir
4074 copy2archive /etc/passwd $tdir/$tfile
4076 local f=$DIR/$tdir/$tfile
4077 copytool import $tdir/$tfile $f
4078 local fid=$(path2fid $f)
4082 # block copytool operations to allow for HSM request to be
4083 # submitted and file be unlinked (CDT will find object removed)
4088 # wait request to reach CT
4089 wait_request_state $fid RESTORE STARTED
4095 wait_request_state $fid RESTORE FAILED
4098 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4099 error "The expected changelog was not emitted"
4101 run_test 222c "Changelog for failed explicit restore"
4104 # test needs a running copytool
4107 mkdir_on_mdt0 $DIR/$tdir
4108 local f=$DIR/$tdir/$tfile
4109 local fid=$(copy_file /etc/passwd $f)
4112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4113 wait_request_state $fid ARCHIVE SUCCEED
4116 copytool_remove_backend $fid
4119 wait_request_state $fid RESTORE FAILED
4122 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4123 error "The expected changelog was not emitted"
4125 run_test 222d "Changelog for failed implicit restore"
4128 # test needs a running copytool
4130 mkdir_on_mdt0 $DIR/$tdir
4132 local f=$DIR/$tdir/$tfile
4133 create_archive_file $tdir/$tfile
4137 copytool import $tdir/$tfile $f
4138 local fid=$(path2fid $f)
4141 wait_request_state $fid RESTORE STARTED
4143 wait_request_state $fid RESTORE CANCELED
4144 wait_request_state $fid CANCEL SUCCEED
4146 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4147 error "The expected changelog was not emitted"
4149 run_test 223a "Changelog for restore canceled (import case)"
4152 mkdir_on_mdt0 $DIR/$tdir
4154 local f=$DIR/$tdir/$tfile
4155 local fid=$(create_empty_file "$f")
4160 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4161 wait_request_state $fid ARCHIVE SUCCEED
4164 # Prevent restore from completing
4167 wait_request_state $fid RESTORE STARTED
4170 wait_request_state $fid RESTORE CANCELED
4173 wait_request_state $fid CANCEL SUCCEED
4175 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4176 error "The expected changelog was not emitted"
4178 run_test 223b "Changelog for restore canceled (release case)"
4180 test_224A() { # was test_224
4181 # test needs a running copytool
4184 mkdir_on_mdt0 $DIR/$tdir
4186 local f=$DIR/$tdir/$tfile
4187 local fid=$(copy_file /etc/passwd $f)
4190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4191 wait_request_state $fid ARCHIVE SUCCEED
4194 wait_request_state $fid REMOVE SUCCEED
4196 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4197 error "The expected changelog was not emitted"
4199 run_test 224A "Changelog for remove"
4202 # test needs a running copytool
4205 mkdir_on_mdt0 $DIR/$tdir
4207 local f=$DIR/$tdir/$tfile
4208 local fid=$(copy_file /etc/passwd $f)
4211 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4212 wait_request_state $fid ARCHIVE SUCCEED
4214 copytool_remove_backend $fid
4216 # block copytool operations to allow for HSM request to be
4217 # submitted and file be unlinked (CDT will find object removed)
4222 # wait for request to reach CT
4223 wait_request_state $fid REMOVE STARTED
4229 wait_request_state $fid REMOVE FAILED
4231 # HE_REMOVE|ENOENT=0x202
4232 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4233 error "The expected changelog was not emitted"
4235 run_test 224a "Changelog for failed remove"
4238 # test is not usable because remove request is too fast
4239 # so it is always finished before cancel can be done ...
4240 echo "Test disabled"
4243 # test needs a running copytool
4245 mkdir_on_mdt0 $DIR/$tdir
4247 local f=$DIR/$tdir/$tfile
4248 local fid=$(create_empty_file "$f")
4251 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4252 wait_request_state $fid ARCHIVE SUCCEED
4254 # Prevent restore from completing
4259 wait_request_state $fid REMOVE CANCELED
4262 wait_request_state $fid CANCEL SUCCEED
4264 changelog_find -type HSM -target-fid $fid -flags 0x27d
4265 error "The expected changelog was not emitted"
4267 run_test 225 "Changelog for remove canceled"
4270 # test needs a running copytool
4273 mkdir_on_mdt0 $DIR/$tdir
4275 local f1=$DIR/$tdir/$tfile-1
4276 local f2=$DIR/$tdir/$tfile-2
4277 local f3=$DIR/$tdir/$tfile-3
4278 local fid1=$(copy_file /etc/passwd $f1)
4279 local fid2=$(copy_file /etc/passwd $f2)
4280 copy_file /etc/passwd $f3
4283 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4284 wait_request_state $fid1 ARCHIVE SUCCEED
4286 $LFS hsm_archive $f2
4287 wait_request_state $fid2 ARCHIVE SUCCEED
4289 rm $f1 || error "rm $f1 failed"
4292 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4293 error "The expected changelog was not emitted"
4295 mv $f3 $f2 || error "mv $f3 $f2 failed"
4297 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4298 error "The expected changelog was not emitted"
4300 run_test 226 "changelog for last rm/mv with exiting archive"
4302 # This is just a utility function to clarify what test_227 does
4307 "$LFS" "$action" --$flag "$file" ||
4308 error "Cannot ${action#hsm_} $flag on '$file'"
4310 # Only one changelog should be produced
4311 local entries="$(changelog_find -type HSM -target-fid $fid)"
4312 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4313 error "lfs $action --$flag '$file' produced more than one" \
4316 # Parse the last changelog record
4317 local entry="$(tail -n 1 <<< "$entries")"
4318 eval local -A changelog=$(changelog2array $entry)
4320 # Also check the flags match what is expected
4321 [[ ${changelog[flags]} == $target ]] ||
4322 error "Changelog flag is '${changelog[flags]}', not $target"
4326 local file="$DIR/$tdir/$tfile"
4327 local fid=$(create_empty_file "$file")
4332 for flag in norelease noarchive exists archived lost; do
4333 if [ "$flag" == lost ]; then
4334 # The flag "lost" only works on an archived file
4335 "$LFS" hsm_set --archived "$file"
4339 action="hsm_set" __test_227
4340 action="hsm_clear" __test_227
4343 run_test 227 "changelog when explicit setting of HSM flags"
4346 # test needs a running copytool
4348 mkdir_on_mdt0 $DIR/$tdir
4350 local fid=$(create_small_sync_file $DIR/$tfile)
4351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4352 wait_request_state $fid ARCHIVE SUCCEED
4354 $LFS hsm_release $DIR/$tfile
4355 check_hsm_flags $DIR/$tfile "0x0000000d"
4357 filefrag $DIR/$tfile | grep " 1 extent found" ||
4358 error "filefrag on released file must return only one extent"
4360 # only newer versions of cp detect sparse files by stat/FIEMAP
4362 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4363 error "copying $DIR/$tfile"
4364 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4366 $LFS hsm_release $DIR/$tfile
4367 check_hsm_flags $DIR/$tfile "0x0000000d"
4369 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4371 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4373 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4374 error "comparing untarred $DIR/$tfile"
4376 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4377 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4379 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4382 local file="$DIR/$tdir/$tfile"
4384 # set max_requests to allow one request of each type to be started (3)
4386 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4387 set_hsm_param max_requests 3
4390 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4391 set_hsm_param loop_period 1
4393 # send 1 requests of each kind twice
4396 mkdir_on_mdt0 $DIR/$tdir
4399 for action in archive restore remove; do
4400 local filepath="$file"-to-$action
4401 local fid=$(create_empty_file "$filepath")
4402 local fid2=$(create_empty_file "$filepath".bis)
4404 if [ "$action" != archive ]; then
4405 "$LFS" hsm_archive "$filepath"
4406 wait_request_state $fid ARCHIVE SUCCEED
4407 "$LFS" hsm_archive "$filepath".bis
4408 wait_request_state $fid2 ARCHIVE SUCCEED
4410 if [ "$action" == restore ]; then
4411 "$LFS" hsm_release "$filepath"
4412 "$LFS" hsm_release "$filepath".bis
4416 # suspend the copytool to prevent requests from completing
4417 stack_trap "copytool_continue" EXIT
4420 # send `max_requests' requests (one of each kind)
4421 for action in archive restore remove; do
4422 filepath="$file"-to-$action
4423 "$LFS" hsm_${action} "$filepath"
4424 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4427 # send another batch of requests
4428 for action in archive restore remove; do
4429 "$LFS" hsm_${action} "$file-to-$action".bis
4431 # wait for `loop_period' seconds to make sure the coordinator has time
4432 # to register those, even though it should not
4435 # only the first batch of request should be started
4437 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4441 error "expected 3 STARTED requests, found $count"
4443 run_test 250 "Coordinator max request"
4446 mkdir_on_mdt0 $DIR/$tdir
4448 local f=$DIR/$tdir/$tfile
4449 local fid=$(create_empty_file "$f")
4452 # to have a short test
4453 local old_to=$(get_hsm_param active_request_timeout)
4454 set_hsm_param active_request_timeout 1
4455 # to be sure the cdt will wake up frequently so
4456 # it will be able to cancel the "old" request
4457 local old_loop=$(get_hsm_param loop_period)
4458 set_hsm_param loop_period 1
4463 # Prevent archive from completing
4465 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4466 wait_request_state $fid ARCHIVE STARTED
4468 # Let the request timeout
4469 wait_request_state $fid ARCHIVE CANCELED
4471 set_hsm_param active_request_timeout $old_to
4472 set_hsm_param loop_period $old_loop
4474 run_test 251 "Coordinator request timeout"
4477 mkdir_on_mdt0 $DIR/$tdir
4479 local f=$DIR/$tdir/$tfile
4480 local fid=$(create_empty_file "$f")
4482 # to have a short test
4483 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4484 set_hsm_param loop_period 1
4488 # Prevent archive from completing
4490 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4491 wait_request_state $fid ARCHIVE STARTED
4494 stack_trap "set_hsm_param active_request_timeout \
4495 $(get_hsm_param active_request_timeout)" EXIT
4496 set_hsm_param active_request_timeout 1
4498 wait_request_state $fid ARCHIVE CANCELED
4501 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4505 # test needs a running copytool
4508 mkdir_on_mdt0 $DIR/$tdir
4509 local f=$DIR/$tdir/$tfile
4511 dd if=/dev/zero of=$f bs=1MB count=10
4512 local fid=$(path2fid $f)
4514 $LFS hsm_archive $f || error "could not archive file"
4515 wait_request_state $fid ARCHIVE SUCCEED
4517 # clear locks to discard inode data
4518 cancel_lru_locks osc
4520 #define OBD_FAIL_MDC_MERGE 0x807
4521 $LCTL set_param fail_loc=0x807
4523 #expect error here, instead of release with wrong size
4526 if ((rc == 0)); then
4527 file_size=$(stat -c '%s' $f)
4528 if ((file_size != 10485760)); then
4529 error "Wrong file size after hsm_release"
4532 echo "could not release file"
4535 run_test 253 "Check for wrong file size after release"
4539 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4540 skip "need MDS version at least 2.10.56"
4542 # Check that the counters are initialized to 0
4544 for request_type in archive restore remove; do
4545 count="$(get_hsm_param ${request_type}_count)" ||
4546 error "Reading ${request_type}_count failed with $?"
4548 [ "$count" -eq 0 ] ||
4549 error "Expected ${request_type}_count to be " \
4553 run_test 254a "Request counters are initialized to zero"
4557 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4558 skip "need MDS version at least 2.10.56"
4560 # The number of request to launch (at least 32)
4561 local request_count=$((RANDOM % 32 + 32))
4562 printf "Will launch %i requests of each type\n" "$request_count"
4564 # Launch a copytool to process requests
4567 # Set hsm.max_requests to allow starting all requests at the same time
4569 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4570 set_hsm_param max_requests "$request_count"
4572 mkdir_on_mdt0 $DIR/$tdir
4576 for request_type in archive restore remove; do
4577 printf "Checking %s requests\n" "${request_type}"
4578 # Suspend the copytool to give us time to read the proc files
4581 for ((i = 0; i < $request_count; i++)); do
4582 case $request_type in
4584 create_empty_file "$DIR/$tdir/$tfile-$i" \
4588 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4591 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4594 # Give the coordinator 10 seconds to start every request
4596 while get_hsm_param actions | grep -q WAITING; do
4599 [ $timeout -gt 0 ] ||
4600 error "${request_type^} requests took too " \
4604 count="$(get_hsm_param ${request_type}_count)"
4605 [ "$count" -eq "$request_count" ] ||
4606 error "Expected '$request_count' (!= '$count') " \
4607 "active $request_type requests"
4609 # Let the copytool process the requests
4611 # Give it 10 seconds maximum
4613 while get_hsm_param actions | grep -q STARTED; do
4616 [ $timeout -gt 0 ] ||
4617 error "${request_type^} requests took too " \
4621 count="$(get_hsm_param ${request_type}_count)"
4622 [ "$count" -eq 0 ] ||
4623 error "Expected 0 (!= '$count') " \
4624 "active $request_type requests"
4627 run_test 254b "Request counters are correctly incremented and decremented"
4631 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4632 skip "Need MDS version at least 2.12.0"
4634 mkdir_on_mdt0 $DIR/$tdir
4636 local file="$DIR/$tdir/$tfile"
4637 local fid=$(create_empty_file "$file")
4639 # How do you make sure the coordinator has consumed any outstanding
4640 # event, without triggering an event yourself?
4642 # You wait for a request to disappear from the coordinator's llog.
4644 # Warning: the setup represents 90% of this test
4646 # Create and process an HSM request
4648 "$LFS" hsm_archive "$file"
4649 wait_request_state $fid ARCHIVE SUCCEED
4652 wait_copytools || error "failed to stop copytools"
4654 # Launch a new HSM request
4656 create_empty_file "$file"
4657 "$LFS" hsm_archive "$file"
4661 # Have the completed request be removed as soon as the cdt wakes up
4662 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4663 set_hsm_param grace_delay 1
4664 # (Hopefully, time on the MDS will behave nicely)
4665 do_facet $SINGLEMDS sleep 2 &
4667 # Increase `loop_period' as a mean to prevent the coordinator from
4668 # waking itself up to do some housekeeping.
4669 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4670 set_hsm_param loop_period 1000
4672 wait $! || error "waiting failed"
4674 wait_request_state $fid ARCHIVE ""
4675 # The coordinator will not wake up on its own for ~`loop_period' secs...
4677 # ... Unless a copytool registers. Now the real test begins
4679 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4681 run_test 255 "Copytool registration wakes the coordinator up"
4683 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4684 # break in the future because of that.
4687 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4688 skip "need MDS version 2.11.56 or later"
4690 local -a files=("$DIR/$tdir/$tfile".{0..15})
4693 mkdir_on_mdt0 $DIR/$tdir
4695 for file in "${files[@]}"; do
4696 create_small_file "$file"
4699 # Set a few hsm parameters
4701 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4702 set_hsm_param loop_period 1
4704 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4705 set_hsm_param max_requests 3
4709 "$LFS" hsm_archive "${files[0]}"
4710 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4711 "$LFS" hsm_release "${files[0]}"
4715 wait_copytools || error "copytools failed to stop"
4717 # Send several archive requests
4718 for file in "${files[@]:1}"; do
4719 "$LFS" hsm_archive "$file"
4722 # Send one restore request
4723 "$LFS" hsm_restore "${files[0]}"
4728 # Wait for all the requests to complete
4729 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4730 for file in "${files[@]:1}"; do
4731 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4734 # Collect the actions in the order in which the copytool processed them
4736 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4737 "$(copytool_logfile "$SINGLEAGT")")
4740 printf '%s\n' "${actions[@]}"
4743 for action in "${actions[@]:0:3}"; do
4744 [ "$action" == RESTORE ] && return
4747 error "Too many ARCHIVE requests were run before the RESTORE request"
4749 run_test 260a "Restore request have priority over other requests"
4751 # This test is very much tied to the implementation of the current priorisation
4752 # mechanism in the coordinator. It might not make sense to keep it in the future
4755 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4756 skip "need MDS version 2.11.56 or later"
4758 local -a files=("$DIR/$tdir/$tfile".{0..15})
4761 mkdir_on_mdt0 $DIR/$tdir
4763 for file in "${files[@]}"; do
4764 create_small_file "$file"
4767 # Set a few hsm parameters
4769 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4770 set_hsm_param loop_period 1
4772 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4773 set_hsm_param max_requests 3
4776 copytool setup --archive-id 2
4777 "$LFS" hsm_archive --archive 2 "${files[0]}"
4778 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4779 "$LFS" hsm_release "${files[0]}"
4783 wait_copytools || error "copytools failed to stop"
4785 # Send several archive requests
4786 for file in "${files[@]:1}"; do
4787 "$LFS" hsm_archive "$file"
4790 # Send one restore request
4791 "$LFS" hsm_restore "${files[0]}"
4795 copytool setup --archive-id 2
4797 # Wait for all the requests to complete
4798 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4799 for file in "${files[@]:1}"; do
4800 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4803 # Collect the actions in the order in which the copytool processed them
4805 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4806 "$(copytool_logfile "$SINGLEAGT")")
4809 printf '%s\n' "${actions[@]}"
4812 for action in "${actions[@]:0:3}"; do
4813 [ "$action" == RESTORE ] && return
4816 error "Too many ARCHIVE requests were run before the RESTORE request"
4818 run_test 260b "Restore request have priority over other requests"
4820 # This test is very much tied to the implementation of the current priorisation
4821 # mechanism in the coordinator. It might not make sense to keep it in the future
4824 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4825 skip "Need MDS version at least 2.12.0"
4827 local -a files=("$DIR/$tdir/$tfile".{0..15})
4830 mkdir_on_mdt0 $DIR/$tdir
4832 for file in "${files[@]}"; do
4833 create_small_file "$file"
4836 # Set a few hsm parameters
4838 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4839 set_hsm_param loop_period 1000
4841 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4842 set_hsm_param max_requests 3
4845 copytool setup --archive-id 2
4846 "$LFS" hsm_archive --archive 2 "${files[0]}"
4847 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4848 "$LFS" hsm_release "${files[0]}"
4852 wait_copytools || error "copytools failed to stop"
4854 # Force the next coordinator run to do housekeeping
4858 "$LFS" hsm_archive "${files[1]}"
4862 copytool setup --archive-id 2
4864 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4865 # The coordinator just did a housekeeping run it won't do another one
4866 # for around `loop_period' seconds => requests will not be reordered
4867 # if it costs too much (ie. when the coordinator has to discard a whole
4870 # Send several archive requests
4871 for file in "${files[@]:2}"; do
4872 "$LFS" hsm_archive "$file"
4875 # Send one restore request
4876 "$LFS" hsm_restore "${files[0]}"
4878 # Wait for all the requests to complete
4879 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4880 for file in "${files[@]:2}"; do
4881 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4884 # Collect the actions in the order in which the copytool processed them
4886 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4887 "$(copytool_logfile "$SINGLEAGT")")
4890 printf '%s\n' "${actions[@]}"
4893 for action in "${actions[@]:0:3}"; do
4894 [ "$action" == RESTORE ] &&
4895 error "Restore requests should not be prioritised" \
4896 "unless the coordinator is doing housekeeping"
4900 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4903 local file=$DIR/$tdir/$tfile
4908 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4910 dd if=/dev/zero of=$file bs=4k count=2 || error "Write $file failed"
4911 fid=$(path2fid $file)
4912 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $file
4913 wait_request_state $fid ARCHIVE SUCCEED
4915 $LFS hsm_state $file
4916 $LFS hsm_release $file
4917 $LFS hsm_restore $file
4918 wait_request_state $fid RESTORE SUCCEED
4919 $LFS hsm_release $file
4920 size=$(stat -c %s $file)
4921 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4923 $LFS hsm_release $file
4924 $LFS hsm_restore $file
4925 $LFS hsm_release $file
4926 size=$(stat -c %s $file)
4927 [[ $size == 8192 ]] || error "Size after HSM release: $size"
4928 $LFS hsm_state $file
4930 run_test 261 "Report 0 bytes size after HSM release"
4933 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4935 # the only way to test ondisk conf is to restart MDS ...
4936 echo "Stop coordinator and remove coordinator state at mount"
4939 # clean on disk conf set by default
4940 cdt_clear_mount_state
4941 cdt_check_state stopped
4943 # check cdt still off after umount/remount
4945 cdt_check_state stopped
4947 echo "Set coordinator start at mount, and start coordinator"
4948 cdt_set_mount_state enabled
4951 cdt_check_state enabled
4953 # check cdt still on after umount/remount
4955 cdt_check_state enabled
4957 # we are back to original state (cdt started at mount)
4959 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4962 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4964 local ai=$(get_hsm_param default_archive_id)
4965 local new=$((ai + 1))
4967 set_hsm_param default_archive_id $new -P
4969 local res=$(get_hsm_param default_archive_id)
4972 set_hsm_param default_archive_id "" "-P -d"
4974 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4976 run_test 301 "HSM tunnable are persistent"
4979 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4981 local ai=$(get_hsm_param default_archive_id)
4982 local new=$((ai + 1))
4987 set_hsm_param default_archive_id $new -P
4990 for mdtno in $(seq 1 $MDSCOUNT); do
4995 cdt_check_state enabled
4997 local res=$(get_hsm_param default_archive_id)
5000 set_hsm_param default_archive_id "" "-P -d"
5002 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5004 run_test 302 "HSM tunnable are persistent when CDT is off"
5007 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5011 mkdir_on_mdt0 $DIR/$tdir
5013 local dir_mdt0=$DIR/$tdir/mdt0
5014 local dir_mdt1=$DIR/$tdir/mdt1
5016 # create 1 dir per MDT
5017 stack_trap "rm -rf $dir_mdt0" EXIT
5018 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5019 stack_trap "rm -rf $dir_mdt1" EXIT
5020 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5022 # create 1 file in each MDT
5023 local fid1=$(create_small_file $dir_mdt0/$tfile)
5024 local fid2=$(create_small_file $dir_mdt1/$tfile)
5026 # check that hsm request on mdt0 is sent to the right MDS
5027 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5028 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5029 echo "archive successful on mdt0"
5031 # check that hsm request on mdt1 is sent to the right MDS
5032 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5033 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5034 echo "archive successful on mdt1"
5036 run_test 400 "Single request is sent to the right MDT"
5039 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5043 mkdir_on_mdt0 $DIR/$tdir
5045 local dir_mdt0=$DIR/$tdir/mdt0
5046 local dir_mdt1=$DIR/$tdir/mdt1
5048 # create 1 dir per MDT
5049 stack_trap "rm -rf $dir_mdt0" EXIT
5050 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5051 stack_trap "rm -rf $dir_mdt1" EXIT
5052 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5054 # create 1 file in each MDT
5055 local fid1=$(create_small_file $dir_mdt0/$tfile)
5056 local fid2=$(create_small_file $dir_mdt1/$tfile)
5058 # check that compound requests are shunt to the rights MDTs
5059 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5060 error "lfs hsm_archive"
5061 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5062 echo "archive successful on mdt0"
5063 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5064 echo "archive successful on mdt1"
5066 run_test 401 "Compound requests split and sent to their respective MDTs"
5068 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5073 local node=$(facet_active_host $facet)
5075 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5076 awk '{print $4}'); do
5077 echo "$3 $mdc on $node"
5078 do_facet $facet "$LCTL --device $mdc $state" || return 1
5083 # deactivate all mdc on agent1
5084 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5086 copytool setup --no-fail
5088 check_agent_unregistered "uuid" # match any agent
5090 # no expected running copytool
5091 search_copytools $agent && error "Copytool start should have failed"
5094 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5096 run_test 402a "Copytool start fails if all MDTs are inactive"
5101 mkdir_on_mdt0 $DIR/$tdir
5103 local f=$DIR/$tdir/$tfile
5104 touch $f || error "touch $f failed"
5105 local fid=$(path2fid $f)
5107 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5108 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5109 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5111 # give time for CDT to send request and to keep it for retry
5112 wait_for_loop_period
5114 wait_request_state $fid ARCHIVE WAITING
5116 do_facet $SINGLEAGT lctl set_param fail_loc=0
5118 # request should succeed now
5119 wait_request_state $fid ARCHIVE SUCCEED
5121 run_test 402b "CDT must retry request upon slow start of CT"
5124 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5126 local agent=$(facet_active_host $SINGLEAGT)
5128 # deactivate all mdc for MDT0001
5129 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5132 local uuid=$(get_agent_uuid $agent)
5133 # check the agent is registered on MDT0000, and not on MDT0001
5134 check_agent_registered_by_mdt $uuid 0
5135 check_agent_unregistered_by_mdt $uuid 1
5137 # check running copytool process
5138 search_copytools $agent || error "No running copytools on $agent"
5140 # reactivate all mdc for MDT0001
5141 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5143 # make sure the copytool is now registered to all MDTs
5144 check_agent_registered $uuid
5146 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5149 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5153 # create files on both MDT0000 and MDT0001
5154 mkdir_on_mdt0 $DIR/$tdir
5156 local dir_mdt0=$DIR/$tdir/mdt0
5157 stack_trap "rm -rf $dir_mdt0" EXIT
5158 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5160 # create 1 file on mdt0
5161 local fid1=$(create_small_file $dir_mdt0/$tfile)
5163 # deactivate all mdc for MDT0001
5164 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5166 # send an HSM request for files in MDT0000
5167 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5169 # check for completion of files in MDT0000
5170 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5171 echo "archive successful on mdt0"
5173 # reactivate all mdc for MDT0001
5174 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5176 run_test 404 "Inactive MDT does not block requests for active MDTs"
5179 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5183 mkdir_on_mdt0 $DIR/$tdir
5185 local striped_dir=$DIR/$tdir/striped_dir
5187 # create striped dir on all of MDTs
5188 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5190 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5191 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5192 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5193 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5195 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5196 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5197 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5198 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5200 # check that compound requests are shunt to the rights MDTs
5201 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5202 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5203 error "lfs hsm_archive"
5205 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5206 echo "archive successful on $fid1"
5207 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5208 echo "archive successful on $fid2"
5209 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5210 echo "archive successful on $fid3"
5211 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5212 echo "archive successful on $fid4"
5214 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5215 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5216 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5217 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5219 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5220 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5221 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5222 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5224 run_test 405 "archive and release under striped directory"
5227 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5229 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5230 skip "need MDS version at least 2.7.64"
5235 mkdir_on_mdt0 $DIR/$tdir
5237 fid=$(create_small_file $DIR/$tdir/$tfile)
5242 $LFS hsm_archive $DIR/$tdir/$tfile
5243 wait_request_state "$fid" ARCHIVE SUCCEED
5244 $LFS hsm_release $DIR/$tdir/$tfile
5246 # Should migrate $tdir but not $tfile.
5247 $LFS migrate -m1 $DIR/$tdir &&
5248 error "migrating HSM an archived file should fail"
5250 $LFS hsm_restore $DIR/$tdir/$tfile
5251 wait_request_state "$fid" RESTORE SUCCEED
5253 $LFS hsm_remove $DIR/$tdir/$tfile
5254 wait_request_state "$fid" REMOVE SUCCEED
5256 cat $DIR/$tdir/$tfile > /dev/null ||
5257 error "cannot read $DIR/$tdir/$tfile"
5259 $LFS migrate -m1 $DIR/$tdir ||
5260 error "cannot complete migration after HSM remove"
5262 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5263 if ((mdt_index != 1)); then
5264 error "expected MDT index 1, got $mdt_index"
5267 # Refresh fid after migration.
5268 fid=$(path2fid $DIR/$tdir/$tfile)
5271 $LFS hsm_archive $DIR/$tdir/$tfile
5272 wait_request_state "$fid" ARCHIVE SUCCEED 1
5274 lctl set_param debug=+trace
5275 $LFS hsm_release $DIR/$tdir/$tfile ||
5276 error "cannot release $DIR/$tdir/$tfile"
5278 $LFS hsm_restore $DIR/$tdir/$tfile
5279 wait_request_state "$fid" RESTORE SUCCEED 1
5281 cat $DIR/$tdir/$tfile > /dev/null ||
5282 error "cannot read $DIR/$tdir/$tfile"
5284 run_test 406 "attempting to migrate HSM archived files is safe"
5287 mkdir_on_mdt0 $DIR/$tdir
5289 local f=$DIR/$tdir/$tfile
5290 local f2=$DIR2/$tdir/$tfile
5291 local fid=$(create_empty_file "$f")
5295 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5296 wait_request_state $fid ARCHIVE SUCCEED
5299 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5300 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5302 # Prevent restore from completing
5306 # 1st request holds layout lock while appropriate
5307 # RESTORE record is still not added to llog
5311 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5312 # after umount hsm_actions->O/x/x log shouldn't have
5313 # double RESTORE records like below
5314 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5315 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5317 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5319 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5321 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"
5324 wait_all_done 100 $fid
5326 run_test 407 "Check for double RESTORE records in llog"
5330 [ "$MDS1_VERSION" -lt $(version_code 2.6.92) ] &&
5331 skip "HSM migrate is not supported"
5333 test_mkdir -p $DIR/$tdir
5335 if [ "$CLIENT_VERSION" -lt $(version_code 2.11.56) ] ||
5336 [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ];
5338 llapi_hsm_test -d $DIR/$tdir -b ||
5339 error "One llapi HSM test failed"
5341 llapi_hsm_test -d $DIR/$tdir ||
5342 error "One llapi HSM test failed"
5345 run_test 500 "various LLAPI HSM tests"
5348 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
5349 skip "need MDS version at least 2.10.58"
5353 local f=$DIR/$tdir/$tfile
5356 # set changelog_mask to ALL
5357 changelog_chmask "ALL"
5359 chmod 777 $DIR/$tdir
5360 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5361 local fid=$(path2fid $f)
5364 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5365 -gid "$RUNAS_GID") ||
5366 error "No matching CREAT entry"
5368 # Parse the changelog
5369 eval local -A changelog=$(changelog2array $entry)
5370 local nid="${changelog[nid]}"
5373 echo "Got NID '$nid'"
5374 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5375 error "nid '$nid' does not match any client NID:" \
5378 run_test 600 "Changelog fields 'u=' and 'nid='"
5381 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5382 skip "need MDS version at least 2.10.58"
5386 local f=$DIR/$tdir/$tfile
5389 # set changelog_mask to ALL
5390 changelog_chmask "ALL"
5392 touch $f || error "touch $f failed"
5393 local fid=$(path2fid $f)
5396 cat $f || error "cat $f failed"
5398 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5399 error "No matching OPEN entry"
5401 run_test 601 "OPEN Changelog entry"
5404 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5405 skip "need MDS version at least 2.10.58"
5407 stack_trap "restore_opencache" EXIT
5412 local f=$DIR/$tdir/$tfile
5415 # set changelog_mask to ALL
5416 changelog_chmask "ALL"
5418 touch $f || error "touch $f failed"
5419 local fid=$(path2fid $f)
5422 cat $f || error "cat $f failed"
5424 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5428 echo f > $f || error "write $f failed"
5431 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5433 # remove OPEN from changelog_mask
5434 changelog_chmask "-OPEN"
5438 cat $f || error "cat $f failed"
5441 changelog_find -type CLOSE -target-fid $fid &&
5442 error "There should be no CLOSE entry"
5446 echo f > $f || error "write $f failed"
5449 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5451 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5454 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5455 skip "need MDS version at least 2.10.58"
5459 local f=$DIR/$tdir/$tfile
5462 # set changelog_mask to ALL
5463 changelog_chmask "ALL"
5465 touch $f || error "touch $f failed"
5466 local fid=$(path2fid $f)
5468 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5471 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5473 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5474 error "No matching GXATR entry"
5476 run_test 603 "GETXATTR Changelog entry"
5479 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5480 skip "need MDS version at least 2.10.58"
5482 mkdir_on_mdt0 $DIR/$tdir
5484 local f=$DIR/$tdir/$tfile
5485 local f2=$DIR2/$tdir/$tfile
5486 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5488 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5489 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5490 do_facet mds1 lctl set_param "$procname=20"
5494 # set changelog_mask to ALL
5495 changelog_chmask "ALL"
5497 touch $f || error "touch $f failed"
5498 local fid=$(path2fid $f)
5504 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5508 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5509 -gid "$RUNAS_GID" -mode "r--") ||
5510 error "No matching NOPEN entry"
5512 # Parse the changelog
5513 eval local -A changelog=$(changelog2array $entry)
5514 local nid="${changelog[nid]}"
5517 echo "Got NID '$nid'"
5518 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5519 error "nid '$nid' does not match any client NID:" \
5524 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5527 changelog_find -type NOPEN -target-fid $fid &&
5528 error "There should be no NOPEN entry"
5530 # Sleep for `changelog_deniednext` seconds
5535 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5538 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5539 -gid "$RUNAS_GID" -mode "r--") ||
5540 error "No matching NOPEN entry"
5542 # Parse the changelog
5543 eval local -A changelog=$(changelog2array $entry)
5544 local nid="${changelog[nid]}"
5547 echo "Got NID '$nid'"
5548 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5549 error "nid '$nid' does not match any client NID:" \
5552 run_test 604 "NOPEN Changelog entry"
5555 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5556 skip "need MDS version at least 2.10.58"
5558 stack_trap "restore_opencache" EXIT
5563 local f=$DIR/$tdir/$tfile
5564 local f2=$DIR2/$tdir/$tfile
5567 # set changelog_mask to ALL
5568 changelog_chmask "ALL"
5570 touch $f || error "touch $f failed"
5571 local fid=$(path2fid $f)
5575 exec 3<> $f || error "open $f failed"
5579 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5583 exec 4<> $f || error "open $f failed"
5586 changelog_find -type OPEN -target-fid $fid &&
5587 error "There should be no OPEN entry"
5589 exec 4>&- || error "close $f failed"
5592 changelog_find -type CLOSE -target-fid $fid &&
5593 error "There should be no CLOSE entry"
5597 # access in rw, so different access mode should generate entries
5598 cat $f || error "cat $f failed"
5601 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5603 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5607 # same access as first one, should not generate new entries
5608 exec 4<> $f || error "open $f failed"
5611 changelog_find -type OPEN -target-fid $fid &&
5612 error "There should be no OPEN entry"
5614 exec 4>&- || error "close $f failed"
5617 changelog_find -type CLOSE -target-fid $fid &&
5618 error "There should be no CLOSE entry"
5622 # access by different user should generate new entries
5623 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5626 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5628 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5632 exec 3>&- || error "close $f failed"
5635 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5637 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5640 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5641 skip "need MDS version at least 2.10.58"
5643 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5644 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5645 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5646 skip_env "missing llog_reader"
5648 mkdir_on_mdt0 $DIR/$tdir
5650 local f=$DIR/$tdir/$tfile
5653 # set changelog_mask to ALL
5654 changelog_chmask "ALL"
5656 chmod 777 $DIR/$tdir
5657 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5658 local fid=$(path2fid $f)
5659 rm $f || error "rm $f failed"
5661 local mntpt=$(facet_mntpt mds1)
5665 #remount mds1 as ldiskfs or zfs type
5666 stop mds1 || error "stop mds1 failed"
5667 stack_trap "unmount_fstype mds1; start mds1 $(mdsdevname 1)\
5668 $MDS_MOUNT_OPTS" EXIT
5669 mount_fstype mds1 || error "remount mds1 failed"
5671 for ((i = 0; i < 1; i++)); do
5672 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5673 local cat_file=$(do_facet mds1 $llog_reader \
5674 $mntpt/changelog_catalog | awk \
5675 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5676 [ -n "$cat_file" ] || error "no catalog file"
5678 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5679 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5680 [ -n "$entry" ] || error "no CREAT entry"
5683 local uidgid=$(echo $entry |
5684 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5685 [ -n "$uidgid" ] || error "uidgid is empty"
5686 echo "Got UID/GID $uidgid"
5687 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5688 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5689 local nid=$(echo $entry |
5690 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5691 [ -n "$nid" ] || error "nid is empty"
5693 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5694 error "nid '$nid' does not match any NID ${CLIENT_NIDS[*]}"
5696 run_test 606 "llog_reader groks changelog fields"
5699 check_and_cleanup_lustre