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 LU-9795
20 ALWAYS_EXCEPT+=" 13 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 "libtool execute pgrep -x $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))
95 local sleep_time=100000 # 0.1 second
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 32000000 ] && # 3.2 seconds
106 sleep_time=$(bc <<< "$sleep_time * 2")
109 # try to dump Copytool's stack
110 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
111 "echo t >/proc/sysrq-trigger"
113 echo "copytools failed to stop in ${wait_timeout}s"
118 copytool_monitor_setup() {
119 local facet=${1:-$SINGLEAGT}
120 local agent=$(facet_active_host $facet)
122 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
123 local test_dir=$(do_node $agent "$cmd") ||
124 error "Failed to create tempdir on $agent"
125 export HSMTOOL_MONITOR_DIR=$test_dir
127 # Create the fifo and a monitor (cat dies when copytool dies)
128 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
129 error "failed to create copytool fifo on $agent"
130 cmd="cat $test_dir/fifo > $test_dir/events &"
131 cmd+=" echo \\\$! > $test_dir/monitor_pid"
133 # This background subshell nonsense is required when pdsh/ssh decides
134 # to wait for the cat process to exit on the remote client
135 (do_node $agent "$cmd") &
136 export HSMTOOL_MONITOR_PDSH=$!
138 # Slightly racy, but just making a best-effort to catch obvious
141 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
143 error "Failed to start copytool monitor on $agent"
153 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
158 get_copytool_event_log() {
159 local facet=${1:-$SINGLEAGT}
160 local agent=$(facet_active_host $facet)
162 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
163 error "Can't get event log: No monitor directory!"
165 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
166 error "Could not collect event log from $agent"
170 local agents=${1:-$(facet_active_host $SINGLEAGT)}
173 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
174 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
175 echo "Copytool is suspended on $agents"
178 copytool_remove_backend() {
180 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
181 echo "Remove from backend: $fid = $be"
182 do_facet $SINGLEAGT rm -f $be
185 file_creation_failure() {
192 df $MOUNT $MOUNT2 >&2
193 error "Not enough space to create $file with $cmd"
196 error "cannot create $file with $cmd, status=$err"
201 # Creates a file using dd
207 local source=${5:-/dev/zero}
211 if [ -n "$conv" ]; then
215 # Create the directory in case it does not exist
216 mkdir -p "$(dirname "$file")"
217 # Delete the file in case it already exist
220 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
221 path2fid "$file" || error "cannot get FID of '$file'"
224 echo "cannot create file '$file'" >&2;
225 # Let the caller decide what to do on error
230 create_empty_file() {
231 create_file "${1/$DIR/$DIR2}" 1M 0 ||
232 file_creation_failure dd "${1/$DIR/$DIR2}" $?
235 create_small_file() {
236 local source_file=/dev/urandom
239 local conv=${2:-fsync}
241 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
242 file_creation_failure dd "${1/$DIR/$DIR2}" $?
245 create_small_sync_file() {
246 create_small_file "$1" sync
249 create_archive_file() {
250 local file="$(hsm_root)/$1"
252 local source=/dev/urandom
254 # Create the counterpart directory of the archive
255 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
256 error "cannot create archive directory '$(dirname "$file")'"
258 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
259 error "cannot create archive file '$file'"
263 local hsm_root="$(hsm_root)"
264 local file="$hsm_root/$2"
266 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
267 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
268 error "mkdir '$(dirname "$file")' failed"
269 do_facet $SINGLEAGT cp -p "$1" "$file" ||
270 error "cannot copy '$1' to '$file'"
275 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
282 mdts_set_param "" hsm_control "$cmd"
283 mdts_check_param hsm_control "$target" 10
288 mdts_set_param "" hsm.policy "+NRA"
289 CDT_POLICY_HAD_CHANGED=true
292 cdt_clear_no_retry() {
293 mdts_set_param "" hsm.policy "-NRA"
294 CDT_POLICY_HAD_CHANGED=true
297 cdt_set_non_blocking_restore() {
298 mdts_set_param "" hsm.policy "+NBR"
299 CDT_POLICY_HAD_CHANGED=true
302 cdt_clear_non_blocking_restore() {
303 mdts_set_param "" hsm.policy "-NBR"
304 CDT_POLICY_HAD_CHANGED=true
307 cdt_clear_mount_state() {
308 mdts_set_param "-P -d" hsm_control ""
312 set_test_state disabled disabled
316 set_test_state enabled enabled
320 set_test_state shutdown stopped
324 set_test_state purge enabled
330 cdt_set_sanity_policy
334 get_hsm_archive_id() {
337 st=$($LFS hsm_state $f)
338 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
340 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
344 check_hsm_flags_user() {
348 local st=$(get_hsm_flags $f user)
349 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
361 if [[ "$3" != 1 ]]; then
365 cp $1 $f || file_creation_failure cp $f $?
367 path2fid $f || error "cannot get fid on $f"
370 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
372 # Note that this might lead to surprising behaviours such as deleting an
373 # important file for the currently running test
374 delete_large_files() {
375 printf "Deleting large files...\n" >&2
376 find $MOUNT -size +10M -delete
377 wait_delete_completed
380 get_request_state() {
384 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
385 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
388 get_request_count() {
392 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
393 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
396 # Ensure the number of HSM request for a given FID is correct
397 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
398 assert_request_count() {
399 local request_count=$(get_request_count $1 $2)
400 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
402 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
409 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
410 [[ -n $fid ]] && cmd+=" | grep '$fid'"
411 cmd+=" | egrep 'WAITING|STARTED'"
413 wait_update_facet --verbose mds1 "$cmd" "" $timeout ||
414 error "requests did not complete"
417 wait_for_grace_delay() {
418 local val=$(get_hsm_param grace_delay)
422 wait_for_loop_period() {
423 local val=$(get_hsm_param loop_period)
430 # python2.6 in EL6 includes an internal json module
431 local json_parser='import json; import fileinput;'
432 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
433 json_parser+='json.loads([line for line in '
434 json_parser+='fileinput.input()][0]).items()])'
436 echo $raw_event | python -c "$json_parser"
439 get_agent_by_uuid_mdt() {
442 local mds=mds$(($mdtidx + 1))
443 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
447 check_agent_registered_by_mdt() {
450 local mds=mds$(($mdtidx + 1))
451 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
452 if [[ ! -z "$agent" ]]; then
453 echo "found agent $agent on $mds"
455 error "uuid $uuid not found in agent list on $mds"
459 check_agent_unregistered_by_mdt() {
462 local mds=mds$(($mdtidx + 1))
463 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
464 if [[ -z "$agent" ]]; then
465 echo "uuid not found in agent list on $mds"
467 error "uuid found in agent list on $mds: $agent"
471 check_agent_registered() {
474 for mdsno in $(seq 1 $MDSCOUNT); do
475 check_agent_registered_by_mdt $uuid $((mdsno - 1))
479 check_agent_unregistered() {
482 for mdsno in $(seq 1 $MDSCOUNT); do
483 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
488 local agent=${1:-$(facet_active_host $SINGLEAGT)}
490 # Lustre mount-point is mandatory and last parameter on
492 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
494 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
496 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
502 # populate MDT device array
505 # cleanup from previous bad setup
508 # for recovery tests, coordinator needs to be started at mount
510 # the lustre conf must be without hsm on (like for sanity.sh)
511 echo "Set HSM on and start"
512 cdt_set_mount_state enabled
513 cdt_check_state enabled
515 echo "Set sanity-hsm HSM policy"
516 cdt_set_sanity_policy
518 # finished requests are quickly removed from list
519 set_hsm_param grace_delay 10
521 CLIENT_NIDS=( $($LCTL list_nids all) )
523 test_1A() { # was test_1
527 local f=$DIR/$tdir/$tfile
531 check_hsm_flags_user $f "0x00000000"
533 $RUNAS $LFS hsm_set --norelease $f ||
534 error "user could not change hsm flags"
535 check_hsm_flags_user $f "0x00000010"
537 $RUNAS $LFS hsm_clear --norelease $f ||
538 error "user could not clear hsm flags"
539 check_hsm_flags_user $f "0x00000000"
541 # User could not change those flags...
542 $RUNAS $LFS hsm_set --exists $f &&
543 error "user should not set this flag"
544 check_hsm_flags_user $f "0x00000000"
547 $LFS hsm_set --exists $f ||
548 error "root could not change hsm flags"
549 check_hsm_flags_user $f "0x00000001"
551 $LFS hsm_clear --exists $f ||
552 error "root could not clear hsm state"
553 check_hsm_flags_user $f "0x00000000"
556 run_test 1A "lfs hsm flags root/non-root access"
559 local f=$DIR/$tdir/$tfile
560 local fid=$(create_small_file $f)
564 $LFS hsm_archive $f || error "could not archive file"
565 wait_request_state $fid ARCHIVE SUCCEED
567 # Release and check states
568 $LFS hsm_release $f || error "could not release file"
569 echo -n "Verifying released state: "
570 check_hsm_flags $f "0x0000000d"
572 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
574 run_test 1a "mmap & cat a HSM released file"
580 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
581 error "failed to create file"
582 local fid=$(path2fid $f)
587 $LFS hsm_archive $f || error "could not archive file"
588 wait_request_state $fid ARCHIVE SUCCEED
591 $LFS hsm_release $f || error "could not release file"
592 echo "verify released state: "
593 check_hsm_flags $f "0x0000000d" && echo "pass"
596 $LFS hsm_restore $f || error "could not restore file"
597 wait_request_state $fid RESTORE SUCCEED
598 echo "verify restored state: "
599 check_hsm_flags $f "0x00000009" && echo "pass"
604 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
605 error "failed to set default stripe"
606 local f=$DIR/$tdir/$tfile
610 run_test 1b "Archive, Release and Restore composite file"
616 local f=$DIR/$tdir/$tfile
619 # Test whether we can set the maximum archive number.
620 local LOCAL_HSM_ARCHIVE_NUMBER=32
621 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
622 error "root could not change hsm flags"
623 check_hsm_flags_user $f "0x00000001"
624 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
625 local st=$(get_hsm_archive_id $f)
626 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
627 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
629 # Test whether setting archive number 0 results in no change.
630 $LFS hsm_set --exists --archive-id 0 $f ||
631 error "root could not change hsm flags"
632 check_hsm_flags_user $f "0x00000001"
633 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
634 st=$(get_hsm_archive_id $f)
635 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
636 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
638 LOCAL_HSM_ARCHIVE_NUMBER=33
639 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
640 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
641 # lustre in the new version supports unlimited archiveID.
642 # Test whether setting archive number > 32 is supported
643 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
644 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
645 check_hsm_flags_user $f "0x00000001"
647 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
648 st=$(get_hsm_archive_id $f)
649 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
650 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
652 # old client or old mds can only support at most 32 archiveID
653 # test whether setting archive number > 32 results in error.
654 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
655 error "bitmap archive number is larger than 32"
656 check_hsm_flags_user $f "0x00000001"
659 # Test whether setting archive number 16 and archived flag.
660 LOCAL_HSM_ARCHIVE_NUMBER=16
661 $LFS hsm_set --exists --archived \
662 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
663 error "root could not change hsm flags"
664 check_hsm_flags_user $f "0x00000009"
665 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
666 st=$(get_hsm_archive_id $f)
667 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
668 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
670 run_test 1c "Check setting archive-id in lfs hsm_set"
673 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
674 skip "need MDS version at least 2.10.59"
677 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
678 error "failed to set default stripe"
679 local f=$DIR/$tdir/$tfile
683 run_test 1d "Archive, Release and Restore DoM file"
686 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
687 skip "skipped for lustre < $SEL_VER"
690 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
691 error "failed to set default stripe"
692 local comp_file=$DIR/$tdir/$tfile
694 test_1bde_base $comp_file
696 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
697 local found=$($LFS find $flg_opts $comp_file | wc -l)
698 [ $found -eq 1 ] || error "1st component not found"
700 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
701 found=$($LFS find $flg_opts $comp_file | wc -l)
702 [ $found -eq 1 ] || error "2nd component not found"
704 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
705 found=$($LFS find $flg_opts $comp_file | wc -l)
706 [ $found -eq 1 ] || error "3rd component not found"
708 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
709 found=$($LFS find $flg_opts $comp_file | wc -l)
710 [ $found -eq 1 ] || error "4th component not found"
712 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
713 found=$($LFS find $flg_opts $comp_file | wc -l)
714 [ $found -eq 1 ] || error "5th component not found"
716 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
717 found=$($LFS find $flg_opts $comp_file | wc -l)
718 [ $found -eq 1 ] || error "6th component not found"
720 sel_layout_sanity $comp_file 6
722 run_test 1e "Archive, Release and Restore SEL file"
725 local f=$DIR/$tdir/$tfile
727 create_empty_file "$f"
728 # New files are not dirty
729 check_hsm_flags $f "0x00000000"
731 # For test, we simulate an archived file.
732 $LFS hsm_set --exists $f || error "user could not change hsm flags"
733 check_hsm_flags $f "0x00000001"
735 # chmod do not put the file dirty
736 chmod 600 $f || error "could not chmod test file"
737 check_hsm_flags $f "0x00000001"
739 # chown do not put the file dirty
740 chown $RUNAS_ID $f || error "could not chown test file"
741 check_hsm_flags $f "0x00000001"
743 # truncate put the file dirty
744 $TRUNCATE $f 1 || error "could not truncate test file"
745 check_hsm_flags $f "0x00000003"
747 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
748 check_hsm_flags $f "0x00000001"
750 run_test 2 "Check file dirtyness when doing setattr"
756 # New files are not dirty
758 check_hsm_flags $f "0x00000000"
760 # For test, we simulate an archived file.
761 $LFS hsm_set --exists $f ||
762 error "user could not change hsm flags"
763 check_hsm_flags $f "0x00000001"
765 # Reading a file, does not set dirty
766 cat $f > /dev/null || error "could not read file"
767 check_hsm_flags $f "0x00000001"
769 # Open for write without modifying data, does not set dirty
770 openfile -f O_WRONLY $f || error "could not open test file"
771 check_hsm_flags $f "0x00000001"
773 # Append to a file sets it dirty
774 cp -p /etc/passwd $f.append || error "could not create file"
775 $LFS hsm_set --exists $f.append ||
776 error "user could not change hsm flags"
777 dd if=/etc/passwd of=$f.append bs=1 count=3\
778 conv=notrunc oflag=append status=noxfer ||
779 file_creation_failure dd $f.append $?
780 check_hsm_flags $f.append "0x00000003"
782 # Modify a file sets it dirty
783 cp -p /etc/passwd $f.modify || error "could not create file"
784 $LFS hsm_set --exists $f.modify ||
785 error "user could not change hsm flags"
786 dd if=/dev/zero of=$f.modify bs=1 count=3\
787 conv=notrunc status=noxfer ||
788 file_creation_failure dd $f.modify $?
789 check_hsm_flags $f.modify "0x00000003"
791 # Open O_TRUNC sets dirty
792 cp -p /etc/passwd $f.trunc || error "could not create file"
793 $LFS hsm_set --exists $f.trunc ||
794 error "user could not change hsm flags"
795 cp /etc/group $f.trunc || error "could not override a file"
796 check_hsm_flags $f.trunc "0x00000003"
798 # Mmapped a file sets dirty
799 cp -p /etc/passwd $f.mmap || error "could not create file"
800 $LFS hsm_set --exists $f.mmap ||
801 error "user could not change hsm flags"
802 multiop $f.mmap OSMWUc || error "could not mmap a file"
803 check_hsm_flags $f.mmap "0x00000003"
805 run_test 3 "Check file dirtyness when opening for write"
808 local f=$DIR/$tdir/$tfile
809 local fid=$(create_small_file $f)
812 local st=$(get_request_state $fid CANCEL)
813 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
815 run_test 4 "Useless cancel must not be registered"
818 # test needs a running copytool
822 local f=$DIR/$tdir/$tfile
823 local fid=$(copy_file /etc/passwd $f)
825 wait_request_state $fid ARCHIVE SUCCEED
827 check_hsm_flags $f "0x00000009"
829 run_test 8 "Test default archive number"
831 test_9A() { # was test_9
832 # we do not use the default one to be sure
833 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
834 copytool setup --archive-id $archive_id
836 # give time for CT to register with MDTs
837 sleep $(($MDSCOUNT*2))
838 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
839 check_agent_registered $uuid
842 local f=$DIR/$tdir/$tfile
843 local fid=$(copy_file /etc/passwd $f)
844 $LFS hsm_archive --archive $archive_id $f
845 wait_request_state $fid ARCHIVE SUCCEED
847 check_hsm_flags $f "0x00000009"
849 run_test 9A "Use of explicit archive number, with dedicated copytool"
852 needclients 3 || return 0
858 # start all of the copytools
859 for n in $(seq $AGTCOUNT); do
860 copytool setup --facet agt$n
864 for n in $(seq $AGTCOUNT); do
865 file=$DIR/$tdir/$tfile.$n
866 fid=$(create_small_file $file)
868 $LFS hsm_archive $file || error "could not archive file $file"
869 wait_request_state $fid ARCHIVE SUCCEED
870 check_hsm_flags $file "0x00000009"
873 run_test 9a "Multiple remote agents"
876 # test needs a running copytool
879 mkdir -p $DIR/$tdir/d1
880 local f=$DIR/$tdir/$tfile
881 local fid=$(copy_file /etc/hosts $f)
882 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
883 error "hsm_archive failed"
884 wait_request_state $fid ARCHIVE SUCCEED
886 local hsm_root="$(copytool_device $SINGLEAGT)"
887 local archive="$(do_facet $SINGLEAGT \
888 find "$hsm_root" -name "$fid" -print0)"
889 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
891 echo "Verifying content"
892 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
893 echo "Verifying hsm state "
894 check_hsm_flags $f "0x00000009"
896 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
897 local st=$(get_hsm_archive_id $f)
898 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
899 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
901 run_test 10a "Archive a file"
904 # test needs a running copytool
908 local f=$DIR/$tdir/$tfile
909 local fid=$(copy_file /etc/hosts $f)
910 $LFS hsm_archive $f || error "archive request failed"
911 wait_request_state $fid ARCHIVE SUCCEED
913 $LFS hsm_archive $f || error "archive of non dirty file failed"
914 local cnt=$(get_request_count $fid ARCHIVE)
915 [[ "$cnt" == "1" ]] ||
916 error "archive of non dirty file must not make a request"
918 run_test 10b "Archive of non dirty file must work without doing request"
921 # test needs a running copytool
925 local f=$DIR/$tdir/$tfile
926 local fid=$(copy_file /etc/hosts $f)
927 $LFS hsm_set --noarchive $f
928 $LFS hsm_archive $f && error "archive a noarchive file must fail"
931 run_test 10c "Check forbidden archive"
934 # test needs a running copytool
938 local f=$DIR/$tdir/$tfile
939 local fid=$(copy_file /etc/hosts $f)
940 $LFS hsm_archive $f || error "cannot archive $f"
941 wait_request_state $fid ARCHIVE SUCCEED
943 local ar=$(get_hsm_archive_id $f)
944 local dflt=$(get_hsm_param default_archive_id)
945 [[ $ar == $dflt ]] ||
946 error "archived file is not on default archive: $ar != $dflt"
948 run_test 10d "Archive a file on the default archive id"
952 copy2archive /etc/hosts $tdir/$tfile
953 local f=$DIR/$tdir/$tfile
955 copytool import $tdir/$tfile $f
956 echo -n "Verifying released state: "
957 check_hsm_flags $f "0x0000000d"
959 local LSZ=$(stat -c "%s" $f)
960 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
962 echo "Verifying imported size $LSZ=$ASZ"
963 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
964 echo -n "Verifying released pattern: "
965 local PTRN=$($LFS getstripe -L $f)
967 [[ $PTRN == released ]] || error "Is not released"
968 local fid=$(path2fid $f)
969 echo "Verifying new fid $fid in archive"
971 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
972 error "No archive for fid $fid"
974 run_test 11a "Import a file"
977 # test needs a running copytool
981 local f=$DIR/$tdir/$tfile
982 local fid=$(copy_file /etc/hosts $f)
983 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
984 error "hsm_archive failed"
985 wait_request_state $fid ARCHIVE SUCCEED
987 local FILE_HASH=$(md5sum $f)
990 copytool import $fid $f
992 echo "$FILE_HASH" | md5sum -c
994 [[ $? -eq 0 ]] || error "Restored file differs"
996 run_test 11b "Import a deleted file using its FID"
999 # test needs a running copytool
1003 copy2archive /etc/hosts $tdir/$tfile
1005 local f=$DIR/$tdir/$tfile
1006 copytool import $tdir/$tfile $f
1007 local f2=$DIR2/$tdir/$tfile
1008 echo "Verifying released state: "
1009 check_hsm_flags $f2 "0x0000000d"
1011 local fid=$(path2fid $f2)
1012 $LFS hsm_restore $f2
1013 wait_request_state $fid RESTORE SUCCEED
1015 echo "Verifying file state: "
1016 check_hsm_flags $f2 "0x00000009"
1018 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1020 [[ $? -eq 0 ]] || error "Restored file differs"
1022 run_test 12a "Restore an imported file explicitly"
1025 # test needs a running copytool
1029 copy2archive /etc/hosts $tdir/$tfile
1031 local f=$DIR/$tdir/$tfile
1032 copytool import $tdir/$tfile $f
1033 echo "Verifying released state: "
1034 check_hsm_flags $f "0x0000000d"
1036 cat $f > /dev/null || error "File read failed"
1038 echo "Verifying file state after restore: "
1039 check_hsm_flags $f "0x00000009"
1041 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1043 [[ $? -eq 0 ]] || error "Restored file differs"
1045 run_test 12b "Restore an imported file implicitly"
1048 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1050 # test needs a running copytool
1053 local f=$DIR/$tdir/$tfile
1055 $LFS setstripe -c 2 "$f"
1056 local fid=$(create_file "$f" 1M 5)
1058 local FILE_CRC=$(md5sum $f)
1060 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1061 wait_request_state $fid ARCHIVE SUCCEED
1062 $LFS hsm_release $f || error "release $f failed"
1064 echo "$FILE_CRC" | md5sum -c
1066 [[ $? -eq 0 ]] || error "Restored file differs"
1068 run_test 12c "Restore a file with stripe of 2"
1071 # test needs a running copytool
1076 local f=$DIR/$tdir/$tfile
1077 local fid=$(copy_file /etc/hosts $f)
1078 $LFS hsm_restore $f || error "restore of non archived file failed"
1079 local cnt=$(get_request_count $fid RESTORE)
1080 [[ "$cnt" == "0" ]] ||
1081 error "restore non archived must not make a request"
1082 $LFS hsm_archive $f ||
1083 error "archive request failed"
1084 wait_request_state $fid ARCHIVE SUCCEED
1085 $LFS hsm_restore $f ||
1086 error "restore of non released file failed"
1087 local cnt=$(get_request_count $fid RESTORE)
1088 [[ "$cnt" == "0" ]] ||
1089 error "restore a non dirty file must not make a request"
1091 run_test 12d "Restore of a non archived, non released file must work"\
1092 " without doing request"
1095 # test needs a running copytool
1099 local f=$DIR/$tdir/$tfile
1100 local fid=$(copy_file /etc/hosts $f)
1101 $LFS hsm_archive $f || error "archive request failed"
1102 wait_request_state $fid ARCHIVE SUCCEED
1105 cat /etc/hosts >> $f
1109 $LFS hsm_restore $f && error "restore a dirty file must fail"
1112 run_test 12e "Check forbidden restore"
1115 # test needs a running copytool
1119 local f=$DIR/$tdir/$tfile
1120 local fid=$(copy_file /etc/hosts $f)
1122 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1123 wait_request_state $fid ARCHIVE SUCCEED
1124 $LFS hsm_release $f || error "release of $f failed"
1126 wait_request_state $fid RESTORE SUCCEED
1128 echo -n "Verifying file state: "
1129 check_hsm_flags $f "0x00000009"
1131 diff -q /etc/hosts $f
1133 [[ $? -eq 0 ]] || error "Restored file differs"
1135 run_test 12f "Restore a released file explicitly"
1138 # test needs a running copytool
1142 local f=$DIR/$tdir/$tfile
1143 local fid=$(copy_file /etc/hosts $f)
1145 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1146 wait_request_state $fid ARCHIVE SUCCEED
1147 $LFS hsm_release $f || error "release of $f failed"
1149 diff -q /etc/hosts $f
1152 # we check we had a restore done
1153 wait_request_state $fid RESTORE SUCCEED
1155 [[ $st -eq 0 ]] || error "Restored file differs"
1157 run_test 12g "Restore a released file implicitly"
1160 needclients 2 || return 0
1162 # test needs a running copytool
1166 local f=$DIR/$tdir/$tfile
1167 local fid=$(copy_file /etc/hosts $f)
1169 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1170 wait_request_state $fid ARCHIVE SUCCEED
1171 $LFS hsm_release $f || error "release of $f failed"
1173 do_node $CLIENT2 diff -q /etc/hosts $f
1176 # we check we had a restore done
1177 wait_request_state $fid RESTORE SUCCEED
1179 [[ $st -eq 0 ]] || error "Restored file differs"
1181 run_test 12h "Restore a released file implicitly from a second node"
1184 # test needs a running copytool
1188 local f=$DIR/$tdir/$tfile
1189 local fid=$(copy_file /etc/passwd $f)
1190 $LFS hsm_archive $f || error "archive of $f failed"
1191 wait_request_state $fid ARCHIVE SUCCEED
1193 $LFS hsm_release $f || error "release of $f failed"
1197 [[ $? -eq 0 ]] || error "Restored file differs"
1199 run_test 12m "Archive/release/implicit restore"
1202 # test needs a running copytool
1206 copy2archive /etc/hosts $tdir/$tfile
1208 local f=$DIR/$tdir/$tfile
1209 copytool import $tdir/$tfile $f
1211 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1212 error "Restored file differs"
1214 $LFS hsm_release $f || error "release of $f failed"
1216 run_test 12n "Import/implicit restore/release"
1219 # test needs a running copytool
1223 local f=$DIR/$tdir/$tfile
1224 local fid=$(copy_file /etc/hosts $f)
1226 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1227 wait_request_state $fid ARCHIVE SUCCEED
1228 $LFS hsm_release $f || error "release of $f failed"
1230 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1231 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1233 # set no retry action mode
1236 diff -q /etc/hosts $f
1239 # we check we had a restore failure
1240 wait_request_state $fid RESTORE FAILED
1242 [[ $st -eq 0 ]] && error "Restore must fail"
1244 # remove no retry action mode
1247 # check file is still released
1248 check_hsm_flags $f "0x0000000d"
1250 # retry w/o failure injection
1251 do_facet $SINGLEMDS lctl set_param fail_loc=0
1253 # to be sure previous RESTORE result is gone
1255 wait_for_grace_delay
1257 diff -q /etc/hosts $f
1260 # we check we had a restore done
1261 wait_request_state $fid RESTORE SUCCEED
1263 [[ $st -eq 0 ]] || error "Restored file differs"
1265 run_test 12o "Layout-swap failure during Restore leaves file released"
1268 # test needs a running copytool
1272 local f=$DIR/$tdir/$tfile
1273 local fid=$(copy_file /etc/hosts $f)
1275 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1276 wait_request_state $fid ARCHIVE SUCCEED
1277 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1278 $LFS hsm_release $f || error "cannot release $f"
1279 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1280 $LFS hsm_release $f || error "cannot release $f"
1281 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1283 run_test 12p "implicit restore of a file on copytool mount point"
1286 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1287 skip "need MDS version at least 2.7.58"
1289 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1290 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1291 error "cannot mount $MOUNT3 on $SINGLEAGT"
1293 # test needs a running copytool
1294 copytool setup -m "$MOUNT3"
1296 local f=$DIR/$tdir/$tfile
1297 local f2=$DIR2/$tdir/$tfile
1298 local fid=$(create_small_file $f)
1299 local orig_size=$(stat -c "%s" $f)
1301 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1302 wait_request_state $fid ARCHIVE SUCCEED
1304 $LFS hsm_release $f || error "could not release file"
1305 check_hsm_flags $f "0x0000000d"
1308 wait_copytools || error "copytool failed to stop"
1310 cat $f > /dev/null &
1312 # wait a bit to allow implicit restore request to be handled.
1313 # if not, next stat would also block on layout-lock.
1316 local size=$(stat -c "%s" $f2)
1317 [ $size -eq $orig_size ] ||
1318 error "$f2: wrong size after archive: $size != $orig_size"
1320 copytool setup -m "$MOUNT3"
1324 size=$(stat -c "%s" $f)
1325 [ $size -eq $orig_size ] ||
1326 error "$f: wrong size after restore: $size != $orig_size"
1328 size=$(stat -c "%s" $f2)
1329 [ $size -eq $orig_size ] ||
1330 error "$f2: wrong size after restore: $size != $orig_size"
1334 size=$(stat -c "%s" $f)
1336 error "$f: wrong size after overwrite: $size != 0"
1338 size=$(stat -c "%s" $f2)
1340 error "$f2: wrong size after overwrite: $size != 0"
1342 run_test 12q "file attributes are refreshed after restore"
1346 for i in {1..10}; do
1347 local archive_dir="$(hsm_root)"/subdir/dir.$i
1349 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1350 for j in {1..10}; do
1351 local archive_file="$archive_dir"/file.$j
1353 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1359 copytool import "subdir" "$DIR/$tdir"
1361 # To check the import, the test uses diff with the -r flag
1362 # This is nice, but diff only checks files one by one, and triggering
1363 # an implicit restore for one file at a time will consume as many
1364 # seconds as there are files to compare. To speed this up, a restore
1365 # operation is triggered manually first.
1367 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1369 # Compare the imported data
1370 do_facet $SINGLEAGT \
1371 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1372 error "imported files differ from archived data"
1374 run_test 13 "Recursively import and restore a directory"
1377 # test needs a running copytool
1381 local f=$DIR/$tdir/$tfile
1382 local fid=$(create_small_file $f)
1383 local sum=$(md5sum $f | awk '{print $1}')
1384 $LFS hsm_archive $f || error "could not archive file"
1385 wait_request_state $fid ARCHIVE SUCCEED
1387 # create released file (simulate llapi_hsm_import call)
1388 local fid2=$(create_empty_file "$f")
1389 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1390 $LFS hsm_release $f || error "could not release file"
1392 # rebind the archive to the newly created file
1393 echo "rebind $fid to $fid2"
1395 copytool rebind $fid $fid2
1397 # restore file and compare md5sum
1398 local sum2=$(md5sum $f | awk '{print $1}')
1400 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1402 run_test 14 "Rebind archived file to a new fid"
1405 # test needs a running copytool
1409 local f=$DIR/$tdir/$tfile
1411 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1415 for i in $(seq 1 $count); do
1416 fids[$i]=$(create_small_file $f.$i)
1417 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1418 $LFS hsm_archive $f.$i || error "could not archive file"
1420 wait_all_done $(($count*60))
1422 stack_trap "rm -f $tmpfile" EXIT
1425 for i in $(seq 1 $count); do
1426 local fid2=$(create_empty_file "${f}.${i}")
1427 # add the rebind operation to the list
1428 echo ${fids[$i]} $fid2 >> $tmpfile
1430 # set it released (simulate llapi_hsm_import call)
1431 $LFS hsm_set --archived --exists $f.$i ||
1432 error "could not force hsm flags"
1433 $LFS hsm_release $f.$i || error "could not release file"
1435 nl=$(wc -l < $tmpfile)
1436 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1438 echo "rebind list of files"
1439 copytool rebind "$tmpfile"
1441 # restore files and compare md5sum
1442 for i in $(seq 1 $count); do
1443 local sum2=$(md5sum $f.$i | awk '{print $1}')
1444 [[ $sum2 == ${sums[$i]} ]] ||
1445 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1448 run_test 15 "Rebind a list of files"
1451 # test needs a running copytool
1455 # create a known size file so we can verify transfer speed
1458 dd if=/dev/zero of=$ref bs=1M count=20
1461 local f=$DIR/$tdir/$tfile
1462 local fid=$(copy_file $ref $f)
1464 local start=$(date +%s)
1466 wait_request_state $fid ARCHIVE SUCCEED
1467 local end=$(date +%s)
1468 # Add 1 to account for rounding errors between start and end (LU-8155)
1469 local duration=$((end - start + 1))
1471 [[ $duration -ge $((goal - 1)) ]] ||
1472 error "Transfer is too fast $duration < $goal"
1474 run_test 16 "Test CT bandwith control option"
1477 local f=$DIR/$tdir/$tfile
1478 create_empty_file "$f"
1480 # Could not release a non-archived file
1481 $LFS hsm_release $f && error "release should not succeed"
1483 # For following tests, we must test them with HS_ARCHIVED set
1484 $LFS hsm_set --exists --archived $f || error "could not add flag"
1486 # Could not release a file if no-release is set
1487 $LFS hsm_set --norelease $f || error "could not add flag"
1488 $LFS hsm_release $f && error "release should not succeed"
1489 $LFS hsm_clear --norelease $f || error "could not remove flag"
1491 # Could not release a file if lost
1492 $LFS hsm_set --lost $f || error "could not add flag"
1493 $LFS hsm_release $f && error "release should not succeed"
1494 $LFS hsm_clear --lost $f || error "could not remove flag"
1496 # Could not release a file if dirty
1497 $LFS hsm_set --dirty $f || error "could not add flag"
1498 $LFS hsm_release $f && error "release should not succeed"
1499 $LFS hsm_clear --dirty $f || error "could not remove flag"
1501 run_test 20 "Release is not permitted"
1504 # test needs a running copytool
1507 local f=$DIR/$tdir/test_release
1509 # Create a file and check its states
1510 local fid=$(create_small_file $f)
1511 check_hsm_flags $f "0x00000000"
1513 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1514 # used until file is flushed to disk
1515 if [ $(facet_fstype ost1) == "zfs" ]; then
1516 # this causes an OST_SYNC rpc to be sent
1517 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1518 # clear locks to reread file data
1519 cancel_lru_locks osc
1522 local orig_size=$(stat -c "%s" $f)
1523 local orig_blocks=$(stat -c "%b" $f)
1525 start_full_debug_logging
1527 $LFS hsm_archive $f || error "could not archive file"
1528 wait_request_state $fid ARCHIVE SUCCEED
1530 local blocks=$(stat -c "%b" $f)
1531 [ $blocks -eq $orig_blocks ] ||
1532 error "$f: wrong block number after archive: " \
1533 "$blocks != $orig_blocks"
1534 local size=$(stat -c "%s" $f)
1535 [ $size -eq $orig_size ] ||
1536 error "$f: wrong size after archive: $size != $orig_size"
1538 # Release and check states
1539 $LFS hsm_release $f || error "could not release file"
1540 check_hsm_flags $f "0x0000000d"
1542 blocks=$(stat -c "%b" $f)
1543 [ $blocks -gt 5 ] &&
1544 error "$f: too many blocks after release: $blocks > 5"
1545 size=$(stat -c "%s" $f)
1546 [ $size -ne $orig_size ] &&
1547 error "$f: wrong size after release: $size != $orig_size"
1549 # Check we can release an file without stripe info
1553 check_hsm_flags $f "0x00000000"
1554 $LFS hsm_archive $f || error "could not archive file"
1555 wait_request_state $fid ARCHIVE SUCCEED
1557 # Release and check states
1558 $LFS hsm_release $f || error "could not release file"
1559 check_hsm_flags $f "0x0000000d"
1561 # Release again a file that is already released is OK
1562 $LFS hsm_release $f || fail "second release should succeed"
1563 check_hsm_flags $f "0x0000000d"
1565 stop_full_debug_logging
1567 run_test 21 "Simple release tests"
1570 # test needs a running copytool
1573 local f=$DIR/$tdir/test_release
1574 local swap=$DIR/$tdir/test_swap
1576 # Create a file and check its states
1577 local fid=$(create_small_file $f)
1578 check_hsm_flags $f "0x00000000"
1580 $LFS hsm_archive $f || error "could not archive file"
1581 wait_request_state $fid ARCHIVE SUCCEED
1583 # Release and check states
1584 $LFS hsm_release $f || error "could not release file"
1585 check_hsm_flags $f "0x0000000d"
1587 create_small_file $swap
1588 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1592 run_test 22 "Could not swap a release file"
1595 # test needs a running copytool
1598 local f=$DIR/$tdir/test_mtime
1600 # Create a file and check its states
1601 local fid=$(create_small_file $f)
1602 check_hsm_flags $f "0x00000000"
1604 $LFS hsm_archive $f || error "could not archive file"
1605 wait_request_state $fid ARCHIVE SUCCEED
1607 # Set modification time in the past
1608 touch -m -a -d @978261179 $f
1610 # Release and check states
1611 $LFS hsm_release $f || error "could not release file"
1612 check_hsm_flags $f "0x0000000d"
1614 local MTIME=$(stat -c "%Y" $f)
1615 local ATIME=$(stat -c "%X" $f)
1616 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1617 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1619 run_test 23 "Release does not change a/mtime (utime)"
1622 local file=$DIR/$tdir/$tfile
1631 # test needs a running copytool
1634 fid=$(create_small_file $file)
1636 # Create a file and check its states
1637 check_hsm_flags $file "0x00000000"
1639 # Ensure atime is less than mtime and ctime.
1643 atime0=$(stat -c "%X" $file)
1644 mtime0=$(stat -c "%Y" $file)
1645 ctime0=$(stat -c "%Z" $file)
1647 [ $atime0 -lt $mtime0 ] ||
1648 error "atime $atime0 is not less than mtime $mtime0"
1650 [ $atime0 -lt $ctime0 ] ||
1651 error "atime $atime0 is not less than ctime $ctime0"
1653 # Archive should not change any timestamps.
1654 $LFS hsm_archive $file || error "cannot archive '$file'"
1655 wait_request_state $fid ARCHIVE SUCCEED
1657 atime1=$(stat -c "%X" $file)
1658 mtime1=$(stat -c "%Y" $file)
1659 ctime1=$(stat -c "%Z" $file)
1661 [ $atime0 -eq $atime1 ] ||
1662 error "archive changed atime from $atime0 to $atime1"
1664 [ $mtime0 -eq $mtime1 ] ||
1665 error "archive changed mtime from $mtime0 to $mtime1"
1667 [ $ctime0 -eq $ctime1 ] ||
1668 error "archive changed ctime from $ctime0 to $ctime1"
1670 # Release should not change any timestamps.
1671 $LFS hsm_release $file || error "cannot release '$file'"
1672 check_hsm_flags $file "0x0000000d"
1674 atime1=$(stat -c "%X" $file)
1675 mtime1=$(stat -c "%Y" $file)
1676 ctime1=$(stat -c "%Z" $file)
1678 [ $atime0 -eq $atime1 ] ||
1679 error "release changed atime from $atime0 to $atime1"
1681 [ $mtime0 -eq $mtime1 ] ||
1682 error "release changed mtime from $mtime0 to $mtime1"
1684 [ $ctime0 -eq $ctime1 ] ||
1685 error "release changed ctime from $ctime0 to $ctime1"
1687 # Restore should not change any timestamps.
1688 $LFS hsm_restore $file
1689 wait_request_state $fid RESTORE SUCCEED
1691 atime1=$(stat -c "%X" $file)
1692 mtime1=$(stat -c "%Y" $file)
1693 ctime1=$(stat -c "%Z" $file)
1695 [ $atime0 -eq $atime1 ] ||
1696 error "restore changed atime from $atime0 to $atime1"
1698 [ $mtime0 -eq $mtime1 ] ||
1699 error "restore changed mtime from $mtime0 to $mtime1"
1701 [ $ctime0 -eq $ctime1 ] ||
1702 error "restore changed ctime from $ctime0 to $ctime1"
1705 wait_copytools || error "Copytools failed to stop"
1707 # Once more, after unmount and mount.
1708 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1709 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1711 atime1=$(stat -c "%X" $file)
1712 mtime1=$(stat -c "%Y" $file)
1713 ctime1=$(stat -c "%Z" $file)
1715 [ $atime0 -eq $atime1 ] ||
1716 error "remount changed atime from $atime0 to $atime1"
1718 [ $mtime0 -eq $mtime1 ] ||
1719 error "remount changed mtime from $mtime0 to $mtime1"
1721 [ $ctime0 -eq $ctime1 ] ||
1722 error "remount changed ctime from $ctime0 to $ctime1"
1724 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1727 local file=$DIR/$tdir/$tfile
1733 # Test needs a running copytool.
1736 # Check that root can do HSM actions on a regular user's file.
1737 fid=$(create_small_file $file)
1738 sum0=$(md5sum $file)
1740 chown $RUNAS_ID:$RUNAS_GID $file ||
1741 error "cannot chown '$file' to '$RUNAS_ID'"
1743 chmod ugo-w $DIR/$tdir ||
1744 error "cannot chmod '$DIR/$tdir'"
1746 $LFS hsm_archive $file
1747 wait_request_state $fid ARCHIVE SUCCEED
1749 $LFS hsm_release $file
1750 check_hsm_flags $file "0x0000000d"
1752 $LFS hsm_restore $file
1753 wait_request_state $fid RESTORE SUCCEED
1755 # Check that ordinary user can get HSM state.
1756 $RUNAS $LFS hsm_state $file ||
1757 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1759 $LFS hsm_release $file
1760 check_hsm_flags $file "0x0000000d"
1762 # Check that ordinary user can accessed released file.
1763 sum1=$($RUNAS md5sum $file) ||
1764 error "user '$RUNAS_ID' cannot read '$file'"
1766 [ "$sum0" == "$sum1" ] ||
1767 error "md5sum mismatch for '$file'"
1769 run_test 24b "root can archive, release, and restore user files"
1772 local file=$DIR/$tdir/$tfile
1773 local action=archive
1778 # test needs a running copytool
1783 # Save the default masks and check that cleanup_24c will
1784 # restore the request masks correctly.
1785 user_save=$(get_hsm_param user_request_mask)
1786 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1787 group_save=$(get_hsm_param group_request_mask)
1788 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1789 other_save=$(get_hsm_param other_request_mask)
1790 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1792 [ "$user_save" == RESTORE ] ||
1793 error "user_request_mask is '$user_save' expected 'RESTORE'"
1794 [ "$group_save" == RESTORE ] ||
1795 error "group_request_mask is '$group_save' expected 'RESTORE'"
1796 [ "$other_save" == RESTORE ] ||
1797 error "other_request_mask is '$other_save' expected 'RESTORE'"
1800 create_small_file $file
1801 chown $RUNAS_ID:$GROUP $file ||
1802 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1804 $RUNAS $LFS hsm_$action $file &&
1805 error "$action by user should fail"
1807 set_hsm_param user_request_mask $action
1808 $RUNAS $LFS hsm_$action $file ||
1809 error "$action by user should succeed"
1812 create_small_file $file
1813 chown nobody:$RUNAS_GID $file ||
1814 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1816 $RUNAS $LFS hsm_$action $file &&
1817 error "$action by group should fail"
1819 set_hsm_param group_request_mask $action
1820 $RUNAS $LFS hsm_$action $file ||
1821 error "$action by group should succeed"
1824 create_small_file $file
1825 chown nobody:$GROUP $file ||
1826 error "cannot chown '$file' to 'nobody:$GROUP'"
1828 $RUNAS $LFS hsm_$action $file &&
1829 error "$action by other should fail"
1831 set_hsm_param other_request_mask $action
1832 $RUNAS $LFS hsm_$action $file ||
1833 error "$action by other should succeed"
1835 run_test 24c "check that user,group,other request masks work"
1838 local file1=$DIR/$tdir/$tfile
1839 local file2=$DIR2/$tdir/$tfile
1843 fid1=$(create_small_file $file1)
1846 $LFS getstripe $file1
1848 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1849 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1850 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1852 copytool setup -m "$MOUNT3"
1854 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1855 mount -o remount,ro $MOUNT2
1857 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1859 fid2=$(path2fid $file2)
1860 [ "$fid1" == "$fid2" ] ||
1861 error "FID mismatch '$fid1' != '$fid2'"
1863 $LFS hsm_archive $file2 &&
1864 error "archive should fail on read-only mount"
1865 check_hsm_flags $file1 "0x00000000"
1867 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1868 wait_request_state $fid1 ARCHIVE SUCCEED
1870 $LFS hsm_release $file1
1871 $LFS hsm_restore $file2
1872 wait_request_state $fid1 RESTORE SUCCEED
1874 $LFS hsm_release $file1 || error "cannot release '$file1'"
1875 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1877 $LFS hsm_release $file2 &&
1878 error "release should fail on read-only mount"
1882 run_test 24d "check that read-only mounts are respected"
1887 local f=$DIR/$tdir/$tfile
1890 fid=$(create_small_file $f) || error "cannot create $f"
1891 $LFS hsm_archive $f || error "cannot archive $f"
1892 wait_request_state $fid ARCHIVE SUCCEED
1893 $LFS hsm_release $f || error "cannot release $f"
1894 while ! $LFS hsm_state $f | grep released; do
1898 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1900 run_test 24e "tar succeeds on HSM released files" # LU-6213
1903 # test needs a running copytool
1906 mkdir -p $DIR/$tdir/d1
1907 local f=$DIR/$tdir/$tfile
1908 local fid=$(copy_file /etc/hosts $f)
1911 $LFS hsm_archive $f ||
1912 error "hsm_archive failed"
1913 wait_request_state $fid ARCHIVE SUCCEED
1914 $LFS hsm_release $f || error "cannot release $f"
1915 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1918 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1919 error "Can not recover the tar contents"
1921 echo "Sum0 = $sum0, sum1 = $sum1"
1922 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1924 run_test 24f "root can archive, release, and restore tar files"
1927 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1928 skip "need MDS version 2.11.56 or later"
1930 local file=$DIR/$tdir/$tfile
1933 echo "RUNAS = '$RUNAS'"
1938 chmod ugo+rwx $DIR/$tdir
1940 echo "Please listen carefully as our options have changed." | tee $file
1941 fid=$(path2fid $file)
1944 $LFS hsm_archive $file
1945 wait_request_state $fid ARCHIVE SUCCEED
1946 check_hsm_flags $file 0x00000009 # exists archived
1948 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
1949 check_hsm_flags $file 0x0000000b # exists dirty archived
1951 run_test 24g "write by non-owner still sets dirty" # LU-11369
1954 # test needs a running copytool
1958 copy2archive /etc/hosts $tdir/$tfile
1960 local f=$DIR/$tdir/$tfile
1962 copytool import $tdir/$tfile $f
1964 $LFS hsm_set --lost $f
1969 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1971 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1972 " (Operation not permitted)"
1975 # test needs a running copytool
1980 local f=$DIR/$tdir/$tfile
1981 local fid=$(copy_file /etc/passwd $f)
1983 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1984 wait_request_state $fid ARCHIVE SUCCEED
1987 $LFS hsm_set --lost $f
1991 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1993 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1994 " (Operation not permitted)"
1996 test_26A() { # was test_26
1997 # test needs a running copytool
2000 local f=$DIR/$tdir/$tfile
2001 local fid=$(create_empty_file "$f")
2003 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2004 wait_request_state $fid ARCHIVE SUCCEED
2007 wait_request_state $fid REMOVE SUCCEED
2009 check_hsm_flags $f "0x00000000"
2011 run_test 26A "Remove the archive of a valid file"
2014 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2015 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2017 # test needs a running copytool
2021 local f=$DIR/$tdir/$tfile
2022 local fid=$(copy_file /etc/passwd $f)
2024 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2025 wait_request_state $fid ARCHIVE SUCCEED
2027 local f2=$DIR/$tdir/${tfile}_2
2028 local fid2=$(copy_file /etc/passwd $f2)
2030 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2031 wait_request_state $fid2 ARCHIVE SUCCEED
2033 local f3=$DIR/$tdir/${tfile}_3
2034 local fid3=$(copy_file /etc/passwd $f3)
2036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2037 wait_request_state $fid3 ARCHIVE SUCCEED
2039 # set a long grace_delay vs short loop_period
2040 local orig_loop_period=$(get_hsm_param loop_period)
2041 local orig_grace_delay=$(get_hsm_param grace_delay)
2042 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2043 set_hsm_param loop_period 10
2044 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2045 set_hsm_param grace_delay 100
2049 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2050 set_hsm_param remove_archive_on_last_unlink 1
2052 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2057 wait_request_state $fid2 REMOVE SUCCEED
2059 assert_request_count $fid REMOVE 0 \
2060 "Unexpected archived data remove request for $f"
2061 assert_request_count $fid3 REMOVE 0 \
2062 "Unexpected archived data remove request for $f3"
2064 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2067 # test needs a running copytool
2071 local f=$DIR/$tdir/$tfile
2072 local fid=$(copy_file /etc/passwd $f)
2074 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2075 wait_request_state $fid ARCHIVE SUCCEED
2077 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2078 set_hsm_param remove_archive_on_last_unlink 1
2081 cdt_check_state stopped
2085 wait_request_state $fid REMOVE WAITING
2089 # copytool must re-register
2091 wait_copytools || error "copytool failed to stop"
2094 wait_request_state $fid REMOVE SUCCEED
2096 run_test 26b "RAoLU policy when CDT off"
2099 # test needs a running copytool
2103 local f=$DIR/$tdir/$tfile
2104 local fid=$(copy_file /etc/passwd $f)
2106 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2107 wait_request_state $fid ARCHIVE SUCCEED
2109 local f2=$DIR/$tdir/${tfile}_2
2110 local fid2=$(copy_file /etc/passwd $f2)
2112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2113 wait_request_state $fid2 ARCHIVE SUCCEED
2115 # set a long grace_delay vs short loop_period
2116 local orig_loop_period=$(get_hsm_param loop_period)
2117 local orig_grace_delay=$(get_hsm_param grace_delay)
2118 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2119 set_hsm_param loop_period 10
2120 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2121 set_hsm_param grace_delay 100
2123 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2124 set_hsm_param remove_archive_on_last_unlink 1
2126 multiop_bg_pause $f O_c || error "open $f failed"
2132 wait_request_state $fid2 REMOVE SUCCEED
2133 assert_request_count $fid REMOVE 0 \
2134 "Unexpected archived data remove request for $f"
2136 kill -USR1 $pid || error "multiop early exit"
2137 # should reach autotest timeout if multiop fails to trap
2138 # signal, close file, and exit ...
2139 wait $pid || error "wait PID $PID failed"
2141 wait_request_state $fid REMOVE SUCCEED
2143 run_test 26c "RAoLU effective when file closed"
2146 # test needs a running copytool
2150 local f=$DIR/$tdir/$tfile
2151 local fid=$(create_small_file $f)
2153 $LFS hsm_archive $f || error "could not archive file"
2154 wait_request_state $fid ARCHIVE SUCCEED
2156 # set a long grace_delay vs short loop_period
2157 local orig_loop_period=$(get_hsm_param loop_period)
2158 local orig_grace_delay=$(get_hsm_param grace_delay)
2159 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2160 set_hsm_param loop_period 10
2161 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2162 set_hsm_param grace_delay 100
2164 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2165 set_hsm_param remove_archive_on_last_unlink 1
2167 multiop_bg_pause $f O_c || error "multiop failed"
2174 wait_request_state $fid REMOVE SUCCEED
2176 client_up || client_up || true
2178 kill -USR1 $MULTIPID
2179 wait $MULTIPID || error "multiop close failed"
2181 run_test 26d "RAoLU when Client eviction"
2184 # test needs a running copytool
2187 create_archive_file $tdir/$tfile
2188 local f=$DIR/$tdir/$tfile
2189 copytool import $tdir/$tfile $f
2190 local fid=$(path2fid $f)
2194 [[ $? != 0 ]] || error "Remove of a released file should fail"
2196 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2199 # test needs a running copytool
2202 local f=$DIR/$tdir/$tfile
2203 local fid=$(create_empty_file "$f")
2205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2206 wait_request_state $fid ARCHIVE SUCCEED
2211 [[ $? != 0 ]] || error "Remove of a released file should fail"
2213 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2216 # test needs a running copytool
2219 local f=$DIR/$tdir/$tfile
2220 local fid=$(create_empty_file "$f")
2222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2223 wait_request_state $fid ARCHIVE SUCCEED
2232 wait_request_state $fid REMOVE SUCCEED
2234 run_test 28 "Concurrent archive/file remove"
2237 # Tests --mntpath and --archive options
2240 copytool setup -m "$MOUNT" -a $archive_id
2242 # Bad archive number
2243 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2244 grep "Invalid argument" ||
2245 error "unexpected hsm_remove failure (1)"
2247 # mntpath is present but file is given
2248 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2249 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2250 error "unexpected hsm_remove failure (2)"
2252 run_test 29a "Tests --mntpath and --archive options"
2255 # test needs a running copytool
2258 local f=$DIR/$tdir/$tfile
2259 local fid=$(create_small_file $f)
2261 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2262 wait_request_state $fid ARCHIVE SUCCEED
2266 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2267 wait_request_state $fid REMOVE SUCCEED
2269 run_test 29b "Archive/delete/remove by FID from the archive."
2272 # test needs a running copytool
2275 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2276 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2277 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2280 wait_request_state $fid1 ARCHIVE SUCCEED
2281 wait_request_state $fid2 ARCHIVE SUCCEED
2282 wait_request_state $fid3 ARCHIVE SUCCEED
2284 rm -f $DIR/$tdir/$tfile-[1-3]
2286 echo $fid1 > $DIR/$tdir/list
2287 echo $fid2 >> $DIR/$tdir/list
2288 echo $fid3 >> $DIR/$tdir/list
2290 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2291 --filelist $DIR/$tdir/list
2292 wait_request_state $fid1 REMOVE SUCCEED
2293 wait_request_state $fid2 REMOVE SUCCEED
2294 wait_request_state $fid3 REMOVE SUCCEED
2296 run_test 29c "Archive/delete/remove by FID, using a file list."
2299 # test needs more than one CT
2300 needclients 3 || return 0
2306 # start all of the copytools
2307 for n in $(seq $AGTCOUNT); do
2308 copytool setup -f agt$n -a $n
2312 file=$DIR/$tdir/$tfile
2313 fid=$(create_small_file $file)
2315 $LFS hsm_archive $file
2316 wait_request_state $fid ARCHIVE SUCCEED
2317 check_hsm_flags $file "0x00000009"
2321 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2322 error "cannot hsm_remove '$fid'"
2324 # give time for CDT to handle remove request and create broadcasted
2327 # remove request has been broadcasted ?
2328 local cnt=$(get_request_count $fid REMOVE)
2329 # broadcasted requests + original
2330 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2331 error "remove not broadcasted to all CTs"
2333 # give time for CDT and CTs to handle broadcasted
2334 wait_for_loop_period
2336 # each agent serves one different archive_id, so broadcasted
2337 # hsm_remove request should only succeed once and fail at all others
2341 for n in $(seq $AGTCOUNT); do
2342 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2343 $HSM_PARAM.actions | awk \
2344 '/'$fid'.*action=REMOVE archive#='$n'/ \
2345 {print \\\$13}' | cut -f2 -d=")
2346 if [[ "$res" == "SUCCEED" ]]; then
2348 elif [[ "$res" == "FAILED" ]]; then
2353 [[ $scnt -eq 1 ]] ||
2354 error "one and only CT should have removed successfully"
2356 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2357 error "all but one CT should have failed to remove"
2359 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2360 "request to be sent once for each registered archive_id"
2363 # restore at exec cannot work on agent node (because of Linux kernel
2364 # protection of executables)
2365 needclients 2 || return 0
2367 # test needs a running copytool
2371 copy2archive /bin/true $tdir/$tfile
2373 local f=$DIR/$tdir/true
2374 copytool import $tdir/$tfile $f
2376 local fid=$(path2fid $f)
2378 stack_trap "cdt_clear_no_retry" EXIT
2379 # set no retry action mode
2386 [[ $st == 0 ]] || error "Failed to exec a released file"
2388 run_test 30a "Restore at exec (import case)"
2391 # restore at exec cannot work on agent node (because of Linux kernel
2392 # protection of executables)
2393 needclients 2 || return 0
2395 # test needs a running copytool
2399 local f=$DIR/$tdir/true
2400 local fid=$(copy_file /bin/true $f)
2402 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2403 wait_request_state $fid ARCHIVE SUCCEED
2407 stack_trap cdt_clear_no_retry EXIT
2408 # set no retry action mode
2416 [[ $st == 0 ]] || error "Failed to exec a released file"
2418 run_test 30b "Restore at exec (release case)"
2421 needclients 2 || return 0
2423 # test needs a running copytool
2427 local f=$DIR/$tdir/SLEEP
2428 local slp_sum1=$(md5sum /bin/sleep)
2429 local fid=$(copy_file /bin/sleep $f)
2431 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2432 wait_request_state $fid ARCHIVE SUCCEED
2434 check_hsm_flags $f "0x0000000d"
2436 stack_trap cdt_clear_no_retry EXIT
2437 # set no retry action mode
2440 do_node $CLIENT2 "$f 10" &
2444 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2446 [[ $? == 0 ]] || error "Execution failed during run"
2448 if [[ $? != 0 ]]; then
2449 local slp_sum2=$(md5sum /bin/sleep)
2450 # in case sleep file is modified during the test
2451 [[ $slp_sum1 == $slp_sum2 ]] &&
2452 error "Binary overwritten during exec"
2455 check_hsm_flags $f "0x00000009"
2457 run_test 30c "Update during exec of released file must fail"
2459 restore_and_check_size() {
2462 local s=$(stat -c "%s" $f)
2464 local st=$(get_hsm_flags $f)
2468 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2470 n=$(stat -c "%s" $f)
2471 # we echo in both cases to show stat is not hang
2472 if [[ $n != $s ]]; then
2473 echo "size seen is $n != $s"
2476 echo "size seen is right: $n == $s"
2480 st=$(get_hsm_flags $f)
2482 if [[ "$st" = "0x00000009" ]]; then
2485 echo " restore is too long"
2486 wait_request_state $fid RESTORE SUCCEED
2492 # test needs a running copytool
2495 create_archive_file $tdir/$tfile
2496 local f=$DIR/$tdir/$tfile
2497 copytool import $tdir/$tfile $f
2498 local fid=$($LFS path2fid $f)
2501 restore_and_check_size $f $fid
2504 [[ $err -eq 0 ]] || error "File size changed during restore"
2506 run_test 31a "Import a large file and check size during restore"
2510 # test needs a running copytool
2513 local f=$DIR/$tdir/$tfile
2514 local fid=$(create_file "$f" 1MB 39)
2516 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2517 wait_request_state $fid ARCHIVE SUCCEED
2520 restore_and_check_size $f $fid
2523 [[ $err -eq 0 ]] || error "File size changed during restore"
2525 run_test 31b "Restore a large unaligned file and check size during restore"
2528 # test needs a running copytool
2531 local f=$DIR/$tdir/$tfile
2532 local fid=$(create_file "$f" 1M 39)
2534 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2535 wait_request_state $fid ARCHIVE SUCCEED
2538 restore_and_check_size $f $fid
2541 [[ $err -eq 0 ]] || error "File size changed during restore"
2543 run_test 31c "Restore a large aligned file and check size during restore"
2546 local f=$DIR/$tdir/$tfile
2547 local fid=$(create_empty_file "$f")
2551 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2552 wait_request_state $fid ARCHIVE SUCCEED
2555 # Prevent restore from completing
2559 md5sum $f >/dev/null &
2562 wait_request_state $fid RESTORE STARTED
2567 # Check restore trigger process was killed
2569 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2571 run_test 33 "Kill a restore waiting process"
2574 # test needs a running copytool
2577 local f=$DIR/$tdir/$tfile
2578 local fid=$(create_empty_file "$f")
2580 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2581 wait_request_state $fid ARCHIVE SUCCEED
2584 # Prevent restore from completing
2587 md5sum $f >/dev/null &
2590 wait_request_state $fid RESTORE STARTED
2592 # rm must not block during restore
2593 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2596 wait_request_state $fid RESTORE SUCCEED
2598 # Check md5sum pgm finished
2599 kill -0 $pid && error "Restore initiatior still running"
2600 wait $pid || error "Restore initiator failed with $?"
2602 # Check the file was actually deleted
2603 [ ! -f "$f" ] || error "$f was not deleted"
2605 run_test 34 "Remove file during restore"
2608 # test needs a running copytool
2611 local f=$DIR/$tdir/$tfile
2612 local f1=$DIR/$tdir/$tfile-1
2613 local fid=$(create_empty_file "$f")
2614 local fid1=$(copy_file /etc/passwd $f1)
2616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2617 wait_request_state $fid ARCHIVE SUCCEED
2620 # Prevent restore from completing
2623 md5sum $f >/dev/null &
2626 wait_request_state $fid RESTORE STARTED
2628 # mv must not block during restore
2629 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2632 wait_request_state $fid RESTORE SUCCEED
2634 # Check md5sum pgm finished
2635 kill -0 $pid && error "Restore initiatior still running"
2636 wait $pid || error "Restore initiator failed with $?"
2638 local fid2=$(path2fid $f)
2639 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2641 run_test 35 "Overwrite file during restore"
2644 # test needs a running copytool
2647 local f=$DIR/$tdir/$tfile
2648 local fid=$(create_empty_file "$f")
2650 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2651 wait_request_state $fid ARCHIVE SUCCEED
2654 # Prevent restore from completing
2657 md5sum $f >/dev/null &
2660 wait_request_state $fid RESTORE STARTED
2662 # mv must not block during restore
2663 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2664 error "mv '$f' '$f.new' failed with rc=$?"
2667 wait_request_state $fid RESTORE SUCCEED
2669 # Check md5sum pgm finished
2670 kill -0 $pid && error "Restore initiator is still running"
2671 wait $pid || error "Restore initiator failed with $?"
2673 run_test 36 "Move file during restore"
2676 # LU-5683: check that an archived dirty file can be rearchived.
2679 local f=$DIR/$tdir/$tfile
2682 fid=$(create_small_file $f) || error "cannot create small file"
2684 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2685 wait_request_state $fid ARCHIVE SUCCEED
2686 $LFS hsm_release $f || error "cannot release $f"
2688 # Allow previous archive request to expire from the actions log.
2689 wait_for_grace_delay
2692 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2694 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2695 wait_request_state $fid ARCHIVE SUCCEED
2697 run_test 37 "re-archive a dirty file"
2704 for n in $(seq 1 $count); do
2705 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2707 echo "$count archive requests submitted"
2711 local stream_count=4
2712 local file_count=100
2714 local f=$DIR/$tdir/$tfile
2718 local max_requests=$(get_hsm_param max_requests)
2720 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2721 # Increase the number of HSM request that can be performed in
2722 # parallel. With the coordinator running once per second, this
2723 # also limits the number of requests per seconds that can be
2724 # performed, so we pick a decent number. But we also need to keep
2725 # that number low because the copytool has no rate limit and will
2726 # fail some requests if if gets too many at once.
2727 set_hsm_param max_requests 300
2729 for i in $(seq 1 $file_count); do
2730 for p in $(seq 1 $stream_count); do
2731 fid=$(copy_file /etc/hosts $f.$p.$i)
2737 # to be sure wait_all_done will not be mislead by previous tests
2739 wait_for_grace_delay
2741 # start archive streams in background (archive files in parallel)
2742 for p in $(seq 1 $stream_count); do
2743 multi_archive $f.$p $file_count &
2746 echo -n "Wait for all requests being enqueued..."
2751 run_test 40 "Parallel archive requests"
2754 # test needs a running copytool
2758 local f=$DIR/$tdir/$tfile
2759 local fid=$(create_small_file $f)
2761 $LFS hsm_archive $f || error "could not archive file"
2762 wait_request_state $fid ARCHIVE SUCCEED
2763 check_hsm_flags $f "0x00000009"
2765 multiop_bg_pause $f O_c || error "multiop failed"
2769 client_up || client_up || true
2771 kill -USR1 $MULTIPID
2772 wait $MULTIPID || error "multiop close failed"
2774 check_hsm_flags $f "0x0000000b"
2776 run_test 52 "Opened for write file on an evicted client should be set dirty"
2779 # test needs a running copytool
2783 local f=$DIR/$tdir/$tfile
2784 local fid=$(create_small_file $f)
2786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2787 error "could not archive file"
2788 wait_request_state $fid ARCHIVE SUCCEED
2789 check_hsm_flags $f "0x00000009"
2791 multiop_bg_pause $f o_c || error "multiop failed"
2795 client_up || client_up || true
2797 kill -USR1 $MULTIPID
2798 wait $MULTIPID || error "multiop close failed"
2800 check_hsm_flags $f "0x00000009"
2802 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2805 local f=$DIR/$tdir/$tfile
2806 local fid=$(create_file "$f" 1MB 39)
2810 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2811 error "could not archive file"
2812 wait_request_state $fid ARCHIVE STARTED
2814 check_hsm_flags $f "0x00000001"
2816 stack_trap "cdt_clear_no_retry" EXIT
2817 # Avoid coordinator resending this request as soon it has failed.
2822 wait_request_state $fid ARCHIVE FAILED
2824 check_hsm_flags $f "0x00000003"
2826 run_test 54 "Write during an archive cancels it"
2829 local f=$DIR/$tdir/$tfile
2830 local fid=$(create_file "$f" 1MB 39)
2834 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2835 error "could not archive file"
2836 wait_request_state $fid ARCHIVE STARTED
2838 check_hsm_flags $f "0x00000001"
2840 stack_trap "cdt_clear_no_retry" EXIT
2841 # Avoid coordinator resending this request as soon it has failed.
2844 $TRUNCATE $f 1024 || error "truncate failed"
2846 wait_request_state $fid ARCHIVE FAILED
2848 check_hsm_flags $f "0x00000003"
2850 run_test 55 "Truncate during an archive cancels it"
2853 local f=$DIR/$tdir/$tfile
2854 local fid=$(create_file "$f" 1MB 39)
2858 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2859 error "could not archive file"
2860 wait_request_state $fid ARCHIVE STARTED
2862 check_hsm_flags $f "0x00000001"
2864 # Change metadata and sync to be sure we are not changing only
2869 wait_request_state $fid ARCHIVE SUCCEED
2871 check_hsm_flags $f "0x00000009"
2873 run_test 56 "Setattr during an archive is ok"
2876 # Need one client for I/O, one for request
2877 needclients 2 || return 0
2879 # test needs a running copytool
2883 local f=$DIR/$tdir/test_archive_remote
2884 # Create a file on a remote node
2885 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2886 "count=2 conv=fsync"
2889 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2890 error "hsm_archive failed"
2891 local fid=$(path2fid $f)
2892 wait_request_state $fid ARCHIVE SUCCEED
2894 # Release and implicit restore it
2895 do_node $CLIENT2 "$LFS hsm_release $f" ||
2896 error "hsm_release failed"
2897 do_node $CLIENT2 "md5sum $f" ||
2898 error "hsm_restore failed"
2900 wait_request_state $fid RESTORE SUCCEED
2902 run_test 57 "Archive a file with dirty cache on another node"
2904 truncate_released_file() {
2908 local sz=$(stat -c %s $src_file)
2909 local f=$DIR/$tdir/$tfile
2910 local fid=$(copy_file $1 $f)
2914 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2915 error "could not archive file"
2916 wait_request_state $fid ARCHIVE SUCCEED
2918 $LFS hsm_release $f || error "could not release file"
2920 $TRUNCATE $f $trunc_to || error "truncate failed"
2923 local sz1=$(stat -c %s $f)
2924 [[ $sz1 == $trunc_to ]] ||
2925 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2928 check_hsm_flags $f "0x0000000b"
2930 local state=$(get_request_state $fid RESTORE)
2931 [[ "$state" == "SUCCEED" ]] ||
2932 error "truncate $sz does not trig restore, state = $state"
2934 $TRUNCATE $ref $trunc_to
2935 cmp $ref $f || error "file data wrong after truncate"
2941 # test needs a running copytool
2946 local sz=$(stat -c %s /etc/passwd)
2948 echo "truncate up from $sz to $((sz*2))"
2949 truncate_released_file /etc/passwd $((sz*2))
2951 echo "truncate down from $sz to $((sz/2))"
2952 truncate_released_file /etc/passwd $((sz/2))
2954 echo "truncate to 0"
2955 truncate_released_file /etc/passwd 0
2957 run_test 58 "Truncate a released file will trigger restore"
2961 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
2962 skip "Need MDS version at least 2.7.63"
2965 $MCREATE $DIR/$tfile || error "mcreate failed"
2966 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
2967 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
2968 fid=$(path2fid $DIR/$tfile)
2969 wait_request_state $fid ARCHIVE SUCCEED
2970 $LFS hsm_release $DIR/$tfile || error "release failed"
2972 run_test 59 "Release stripeless file with non-zero size"
2975 # This test validates the fix for LU-4512. Ensure that the -u
2976 # option changes the progress reporting interval from the
2977 # default (30 seconds) to the user-specified interval.
2978 local f=$DIR/$tdir/$tfile
2979 local fid=$(create_file "$f" 1M 10)
2982 local progress_timeout=$((interval * 4))
2983 copytool setup -b 1 --update-interval $interval
2986 local mdt=${MDT_PREFIX}${mdtidx}
2987 local mds=mds$((mdtidx + 1))
2989 # Wait for copytool to register
2990 wait_update_facet $mds \
2991 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2992 uuid 100 || error "coyptool failed to register with $mdt"
2994 local start_at=$(date +%s)
2995 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2996 error "could not archive file"
2998 local agent=$(facet_active_host $SINGLEAGT)
2999 local logfile=$(copytool_logfile $SINGLEAGT)
3001 wait_update $agent \
3002 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3003 error "copytool failed to start"
3005 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3006 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3012 echo -n "Expecting a progress update within $progress_timeout seconds... "
3014 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3015 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3016 echo "$RESULT bytes copied in $WAIT seconds."
3018 elif [ $WAIT -ge $progress_timeout ]; then
3019 error "Timed out waiting for progress update!"
3022 WAIT=$((WAIT + sleep))
3026 local finish_at=$(date +%s)
3027 local elapsed=$((finish_at - start_at))
3029 # Ensure that the progress update occurred within the expected window.
3030 if [ $elapsed -lt $((interval - 1)) ]; then
3031 error "Expected progress update after at least $interval seconds"
3034 echo "Wait for on going archive hsm action to complete"
3035 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3036 echo "File archiving not completed even after 10 secs"
3038 run_test 60 "Changing progress update interval from default"
3041 # test needs a running copytool
3045 local f=$DIR/$tdir/$tfile
3046 local fid=$(copy_file /etc/passwd $f)
3048 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3051 wait_request_state $fid ARCHIVE FAILED
3053 run_test 61 "Waiting archive of a removed file should fail"
3056 # test needs a new running copytool
3057 stack_trap copytool_monitor_cleanup EXIT
3058 copytool_monitor_setup
3059 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3061 # Wait for the copytool to register.
3062 wait_update --verbose $(facet_active_host mds1) \
3063 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3065 error "copytool failed to register with MDT0000"
3068 wait_copytools || error "Copytools failed to stop"
3070 local REGISTER_EVENT
3071 local UNREGISTER_EVENT
3072 while read event; do
3073 local parsed=$(parse_json_event "$event")
3074 if [ -z "$parsed" ]; then
3075 error "Copytool sent malformed event: $event"
3079 if [ $event_type == "REGISTER" ]; then
3080 REGISTER_EVENT=$event
3081 elif [ $event_type == "UNREGISTER" ]; then
3082 UNREGISTER_EVENT=$event
3084 done < <(echo $"$(get_copytool_event_log)")
3086 if [ -z "$REGISTER_EVENT" ]; then
3087 error "Copytool failed to send register event to FIFO"
3090 if [ -z "$UNREGISTER_EVENT" ]; then
3091 error "Copytool failed to send unregister event to FIFO"
3094 echo "Register/Unregister events look OK."
3096 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3099 # Bump progress interval for livelier events.
3102 # test needs a new running copytool
3103 stack_trap copytool_monitor_cleanup EXIT
3104 copytool_monitor_setup
3105 copytool setup --update-interval $interval --event-fifo \
3106 "$HSMTOOL_MONITOR_DIR/fifo"
3108 stack_trap "cdt_clear_no_retry" EXIT
3109 # Just start and stop the copytool to generate events.
3112 local f=$DIR/$tdir/$tfile
3113 local fid=$(create_small_file "$f")
3115 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3116 error "could not archive file"
3117 wait_request_state $fid ARCHIVE SUCCEED
3119 local expected_fields="event_time data_fid source_fid"
3120 expected_fields+=" total_bytes current_bytes"
3123 [ARCHIVE_START]=false
3124 [ARCHIVE_FINISH]=false
3125 [ARCHIVE_RUNNING]=false
3127 while read event; do
3128 # Make sure we're not getting anything from previous events.
3129 for field in $expected_fields; do
3133 local parsed=$(parse_json_event "$event")
3134 if [ -z "$parsed" ]; then
3135 error "Copytool sent malformed event: $event"
3139 events["$event_type"]=true
3141 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3143 # Do some simple checking of the progress update events.
3144 for expected_field in $expected_fields; do
3145 if [ -z ${!expected_field+x} ]; then
3146 error "Missing $expected_field field in event"
3150 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3152 # These should be identical throughout an archive operation
3153 [ $source_fid == $data_fid ] ||
3154 error "Expected source_fid to equal data_fid"
3155 done < <(echo $"$(get_copytool_event_log)")
3157 # Check we received every type of events we were expecting
3158 for event in "${!events[@]}"; do
3159 ${events["$event"]} ||
3160 error "Copytool failed to send '$event' event to FIFO"
3163 echo "Archive events look OK."
3165 run_test 71 "Copytool logs JSON archive events to FIFO"
3168 # Bump progress interval for livelier events.
3171 # test needs a new running copytool
3172 stack_trap copytool_monitor_cleanup EXIT
3173 copytool_monitor_setup
3174 copytool setup --update-interval $interval --event-fifo \
3175 "$HSMTOOL_MONITOR_DIR/fifo"
3176 local test_file=$HSMTOOL_MONITOR_DIR/file
3178 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3180 do_facet $SINGLEAGT "$cmd" ||
3181 error "cannot create $test_file on $SINGLEAGT"
3182 copy2archive $test_file $tdir/$tfile
3185 local f=$DIR/$tdir/$tfile
3186 copytool import $tdir/$tfile $f
3187 f=$DIR2/$tdir/$tfile
3188 echo "Verifying released state: "
3189 check_hsm_flags $f "0x0000000d"
3191 local fid=$(path2fid $f)
3193 wait_request_state $fid RESTORE SUCCEED
3195 local expected_fields="event_time data_fid source_fid"
3196 expected_fields+=" total_bytes current_bytes"
3200 while read event; do
3201 # Make sure we're not getting anything from previous events.
3202 for field in $expected_fields; do
3206 local parsed=$(parse_json_event "$event")
3207 if [ -z "$parsed" ]; then
3208 error "Copytool sent malformed event: $event"
3212 if [ $event_type == "RESTORE_START" ]; then
3214 if [ $source_fid != $data_fid ]; then
3215 error "source_fid should == data_fid at start"
3218 elif [ $event_type == "RESTORE_FINISH" ]; then
3220 if [ $source_fid != $data_fid ]; then
3221 error "source_fid should == data_fid at finish"
3224 elif [ $event_type != "RESTORE_RUNNING" ]; then
3228 # Do some simple checking of the progress update events.
3229 for expected_field in $expected_fields; do
3230 if [ -z ${!expected_field+x} ]; then
3231 error "Missing $expected_field field in event"
3235 if [ $total_bytes -eq 0 ]; then
3236 error "Expected total_bytes to be > 0"
3239 # When a restore starts out, the data fid is the same as the
3240 # source fid. After the restore has gotten going, we learn
3241 # the new data fid. Once the restore has finished, the source
3242 # fid is set to the new data fid.
3244 # We test this because some monitoring software may depend on
3245 # this behavior. If it changes, then the consumers of these
3246 # events may need to be modified.
3247 if [ $source_fid == $data_fid ]; then
3248 error "source_fid should != data_fid during restore"
3250 done < <(echo $"$(get_copytool_event_log)")
3252 if [ -z "$START_EVENT" ]; then
3253 error "Copytool failed to send restore start event to FIFO"
3256 if [ -z "$FINISH_EVENT" ]; then
3257 error "Copytool failed to send restore finish event to FIFO"
3260 echo "Restore events look OK."
3262 run_test 72 "Copytool logs JSON restore events to FIFO"
3265 file_count=51 # Max number of files constrained by LNET message size
3266 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3267 local f=$DIR/$tdir/$tfile
3268 local FILELIST=/tmp/filelist.txt
3272 for i in $(seq 1 $file_count); do
3273 fid=$(copy_file /etc/hosts $f.$i)
3274 echo $f.$i >> $FILELIST
3278 # to be sure wait_all_done will not be mislead by previous tests
3280 wait_for_grace_delay
3281 $LFS hsm_archive --filelist $FILELIST ||
3282 error "cannot archive a file list"
3284 $LFS hsm_release --filelist $FILELIST ||
3285 error "cannot release a file list"
3286 $LFS hsm_restore --filelist $FILELIST ||
3287 error "cannot restore a file list"
3290 run_test 90 "Archive/restore a file list"
3292 double_verify_reset_hsm_param() {
3294 echo "Testing $HSM_PARAM.$p"
3295 local val=$(get_hsm_param $p)
3297 local val2=$(($val * 2))
3298 set_hsm_param $p $val2
3299 val=$(get_hsm_param $p)
3300 [[ $val == $val2 ]] ||
3301 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3302 echo "Set $p to 0 must failed"
3306 set_hsm_param $p $save
3308 if [[ $rc == 0 ]]; then
3309 error "we must not be able to set $HSM_PARAM.$p to 0"
3314 double_verify_reset_hsm_param loop_period
3315 double_verify_reset_hsm_param grace_delay
3316 double_verify_reset_hsm_param active_request_timeout
3317 double_verify_reset_hsm_param max_requests
3318 double_verify_reset_hsm_param default_archive_id
3320 run_test 100 "Set coordinator /proc tunables"
3327 run_test 102 "Verify coordinator control"
3330 # test needs a running copytool
3337 for i in $(seq 1 20); do
3338 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3340 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3344 echo "Current requests"
3345 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3346 $HSM_PARAM.actions |\
3347 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3349 [[ -z "$res" ]] || error "Some request have not been canceled"
3351 run_test 103 "Purge all requests"
3356 local f=$DIR/$tdir/$tfile
3357 local fid=$(create_empty_file "$f")
3359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3360 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3361 $HSM_PARAM.actions |\
3362 grep $fid | cut -f16 -d=")
3364 [[ "$data1" == "$DATAHEX" ]] ||
3365 error "Data field in records is ($data1) and not ($DATAHEX)"
3369 run_test 104 "Copy tool data field"
3372 local max_requests=$(get_hsm_param max_requests)
3376 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3377 set_hsm_param max_requests 300
3380 for i in $(seq -w 1 10); do
3381 cp /etc/passwd $DIR/$tdir/$i
3382 $LFS hsm_archive $DIR/$tdir/$i
3384 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3385 $HSM_PARAM.actions |\
3386 grep WAITING | wc -l")
3390 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3391 $HSM_PARAM.actions |\
3392 grep WAITING | wc -l")
3395 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3396 error "Requests count after shutdown $reqcnt2 != "\
3397 "before shutdown $reqcnt1"
3399 run_test 105 "Restart of coordinator"
3402 # test needs a running copytool
3405 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3407 check_agent_registered $uuid
3409 search_copytools || error "No copytool found"
3412 wait_copytools || error "Copytool failed to stop"
3414 check_agent_unregistered $uuid
3417 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3418 check_agent_registered $uuid
3420 run_test 106 "Copytool register/unregister"
3423 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3425 # test needs a running copytool
3427 # create and archive file
3429 local f1=$DIR/$tdir/$tfile
3430 local fid=$(copy_file /etc/passwd $f1)
3431 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3432 wait_request_state $fid ARCHIVE SUCCEED
3433 # shutdown and restart MDS
3435 # check the copytool still gets messages from MDT
3436 local f2=$DIR/$tdir/2
3437 local fid=$(copy_file /etc/passwd $f2)
3438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3439 # main check of this sanity: this request MUST succeed
3440 wait_request_state $fid ARCHIVE SUCCEED
3442 run_test 107 "Copytool re-register after MDS restart"
3444 policy_set_and_test()
3448 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3449 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3450 [[ "$policy" == "$target" ]] ||
3451 error "Wrong policy after '$change': '$policy' != '$target'"
3455 # to force default policy setting if error
3456 CDT_POLICY_HAD_CHANGED=true
3458 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3459 local default="NonBlockingRestore [NoRetryAction]"
3460 [[ "$policy" == "$default" ]] ||
3461 error "default policy has changed,"\
3462 " '$policy' != '$default' update the test"
3463 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3464 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3465 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3466 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3467 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3468 # useless bacause we know but safer for futur changes to use real value
3469 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3470 echo "Next set_param must failed"
3471 policy_set_and_test "wrong" "$policy"
3474 echo "Back to default policy"
3475 cdt_set_sanity_policy
3477 run_test 109 "Policy display/change"
3480 # test needs a running copytool
3485 copy2archive /etc/passwd $tdir/$tfile
3487 local f=$DIR/$tdir/$tfile
3488 copytool import $tdir/$tfile $f
3489 local fid=$(path2fid $f)
3491 cdt_set_non_blocking_restore
3496 wait_request_state $fid RESTORE SUCCEED
3497 cdt_clear_non_blocking_restore
3501 error "md5sum returns $st != 1, "\
3502 "should also perror ENODATA (No data available)"
3504 run_test 110a "Non blocking restore policy (import case)"
3507 # test needs a running copytool
3511 local f=$DIR/$tdir/$tfile
3512 local fid=$(copy_file /etc/passwd $f)
3513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3514 wait_request_state $fid ARCHIVE SUCCEED
3517 cdt_set_non_blocking_restore
3522 wait_request_state $fid RESTORE SUCCEED
3523 cdt_clear_non_blocking_restore
3527 error "md5sum returns $st != 1, "\
3528 "should also perror ENODATA (No data available)"
3530 run_test 110b "Non blocking restore policy (release case)"
3533 # test needs a running copytool
3537 copy2archive /etc/passwd $tdir/$tfile
3539 local f=$DIR/$tdir/$tfile
3541 copytool import $tdir/$tfile $f
3542 local fid=$(path2fid $f)
3546 copytool_remove_backend $fid
3549 wait_request_state $fid RESTORE FAILED
3556 [[ $st == 0 ]] || error "Restore does not failed"
3558 run_test 111a "No retry policy (import case), restore will error"\
3559 " (No such file or directory)"
3562 # test needs a running copytool
3566 local f=$DIR/$tdir/$tfile
3567 local fid=$(copy_file /etc/passwd $f)
3568 stack_trap cdt_clear_no_retry EXIT
3570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3571 wait_request_state $fid ARCHIVE SUCCEED
3574 copytool_remove_backend $fid
3577 wait_request_state $fid RESTORE FAILED
3581 [[ $st == 0 ]] || error "Restore does not failed"
3583 run_test 111b "No retry policy (release case), restore will error"\
3584 " (No such file or directory)"
3587 # test needs a running copytool
3591 local f=$DIR/$tdir/$tfile
3592 local fid=$(copy_file /etc/passwd $f)
3594 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3595 local l=$($LFS hsm_action $f)
3597 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3600 wait_request_state $fid ARCHIVE SUCCEED
3603 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3605 run_test 112 "State of recorded request"
3608 local file1=$DIR/$tdir/$tfile
3609 local file2=$DIR2/$tdir/$tfile
3611 local fid=$(create_small_sync_file $file1)
3613 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3614 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3615 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3617 copytool setup -m "$MOUNT3"
3619 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3621 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3622 wait_request_state $fid ARCHIVE SUCCEED
3624 $LFS hsm_release $file1
3625 echo "Verifying released state: "
3626 check_hsm_flags $file1 "0x0000000d"
3628 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3631 kill -USR1 $MULTIPID
3636 local size1=$(stat -c "%s" $file1)
3637 local size2=$(stat -c "%s" $file2)
3639 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3641 run_test 113 "wrong stat after restore"
3644 local f=$DIR/$tdir/$tfile
3645 local fid=$(create_empty_file "$f")
3649 # Prevent archive from completing
3652 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3653 # wait archive to register at CDT
3654 wait_request_state $fid ARCHIVE STARTED
3656 # Cancel the archive
3657 $LFS hsm_cancel "$f"
3659 wait_request_state $fid ARCHIVE CANCELED
3662 wait_request_state $fid CANCEL SUCCEED
3664 run_test 200 "Register/Cancel archive"
3667 # test needs a running copytool
3670 local f=$DIR/$tdir/$tfile
3671 create_archive_file $tdir/$tfile
3672 copytool import $tdir/$tfile $f
3673 local fid=$(path2fid $f)
3675 # test with cdt on is made in test_222
3678 # wait restore to register at CDT
3679 wait_request_state $fid RESTORE WAITING
3682 wait_request_state $fid RESTORE CANCELED
3683 wait_request_state $fid CANCEL SUCCEED
3685 run_test 201 "Register/Cancel restore"
3688 local f=$DIR/$tdir/$tfile
3689 local fid=$(create_empty_file "$f")
3691 # test needs a running copytool
3694 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3695 wait_request_state $fid ARCHIVE SUCCEED
3699 # wait remove to register at CDT
3700 wait_request_state $fid REMOVE STARTED
3703 wait_request_state $fid REMOVE CANCELED
3705 run_test 202 "Register/Cancel remove"
3707 test_220A() { # was test_220
3708 # test needs a running copytool
3713 local f=$DIR/$tdir/$tfile
3714 local fid=$(copy_file /etc/passwd $f)
3718 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3719 wait_request_state $fid ARCHIVE SUCCEED
3721 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3722 error "The expected changelog was not emitted"
3724 run_test 220A "Changelog for archive"
3727 # test needs a running copytool
3732 local f=$DIR/$tdir/$tfile
3733 local fid=$(copy_file /etc/passwd $f)
3737 # block copytool operations to allow for HSM request to be
3738 # submitted and file be unlinked (CDT will find object removed)
3741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3743 # wait request to reach CT
3744 wait_request_state $fid ARCHIVE STARTED
3750 wait_request_state $fid ARCHIVE FAILED
3753 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3754 error "The expected changelog was not emitted"
3756 run_test 220a "Changelog for failed archive"
3759 local f=$DIR/$tdir/$tfile
3760 local fid=$(create_empty_file "$f")
3765 # Prevent archive from completing
3767 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3768 wait_request_state $fid ARCHIVE STARTED
3771 wait_request_state $fid ARCHIVE CANCELED
3774 wait_request_state $fid CANCEL SUCCEED
3776 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3777 error "The expected changelog was not emitted"
3779 run_test 221 "Changelog for archive canceled"
3782 # test needs a running copytool
3786 copy2archive /etc/passwd $tdir/$tfile
3788 local f=$DIR/$tdir/$tfile
3789 copytool import $tdir/$tfile $f
3790 local fid=$(path2fid $f)
3795 wait_request_state $fid RESTORE SUCCEED
3797 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3798 error "The expected changelog was not emitted"
3800 run_test 222a "Changelog for explicit restore"
3803 # test needs a running copytool
3807 local f=$DIR/$tdir/$tfile
3808 local fid=$(copy_file /etc/passwd $f)
3811 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3812 wait_request_state $fid ARCHIVE SUCCEED
3817 wait_request_state $fid RESTORE SUCCEED
3819 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3820 error "The expected changelog was not emitted"
3822 run_test 222b "Changelog for implicit restore"
3825 # test needs a running copytool
3829 copy2archive /etc/passwd $tdir/$tfile
3831 local f=$DIR/$tdir/$tfile
3832 copytool import $tdir/$tfile $f
3833 local fid=$(path2fid $f)
3837 # block copytool operations to allow for HSM request to be
3838 # submitted and file be unlinked (CDT will find object removed)
3843 # wait request to reach CT
3844 wait_request_state $fid RESTORE STARTED
3850 wait_request_state $fid RESTORE FAILED
3853 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3854 error "The expected changelog was not emitted"
3856 run_test 222c "Changelog for failed explicit restore"
3859 # test needs a running copytool
3863 local f=$DIR/$tdir/$tfile
3864 local fid=$(copy_file /etc/passwd $f)
3867 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3868 wait_request_state $fid ARCHIVE SUCCEED
3871 copytool_remove_backend $fid
3874 wait_request_state $fid RESTORE FAILED
3877 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3878 error "The expected changelog was not emitted"
3880 run_test 222d "Changelog for failed implicit restore"
3883 # test needs a running copytool
3886 local f=$DIR/$tdir/$tfile
3887 create_archive_file $tdir/$tfile
3891 copytool import $tdir/$tfile $f
3892 local fid=$(path2fid $f)
3895 wait_request_state $fid RESTORE STARTED
3897 wait_request_state $fid RESTORE CANCELED
3898 wait_request_state $fid CANCEL SUCCEED
3900 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3901 error "The expected changelog was not emitted"
3903 run_test 223a "Changelog for restore canceled (import case)"
3906 local f=$DIR/$tdir/$tfile
3907 local fid=$(create_empty_file "$f")
3912 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3913 wait_request_state $fid ARCHIVE SUCCEED
3916 # Prevent restore from completing
3919 wait_request_state $fid RESTORE STARTED
3922 wait_request_state $fid RESTORE CANCELED
3925 wait_request_state $fid CANCEL SUCCEED
3927 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3928 error "The expected changelog was not emitted"
3930 run_test 223b "Changelog for restore canceled (release case)"
3932 test_224A() { # was test_224
3933 # test needs a running copytool
3938 local f=$DIR/$tdir/$tfile
3939 local fid=$(copy_file /etc/passwd $f)
3942 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3943 wait_request_state $fid ARCHIVE SUCCEED
3946 wait_request_state $fid REMOVE SUCCEED
3948 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
3949 error "The expected changelog was not emitted"
3951 run_test 224A "Changelog for remove"
3954 # test needs a running copytool
3959 local f=$DIR/$tdir/$tfile
3960 local fid=$(copy_file /etc/passwd $f)
3963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3964 wait_request_state $fid ARCHIVE SUCCEED
3966 copytool_remove_backend $fid
3968 # block copytool operations to allow for HSM request to be
3969 # submitted and file be unlinked (CDT will find object removed)
3974 # wait for request to reach CT
3975 wait_request_state $fid REMOVE STARTED
3981 wait_request_state $fid REMOVE FAILED
3983 # HE_REMOVE|ENOENT=0x202
3984 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
3985 error "The expected changelog was not emitted"
3987 run_test 224a "Changelog for failed remove"
3990 # test is not usable because remove request is too fast
3991 # so it is always finished before cancel can be done ...
3992 echo "Test disabled"
3995 # test needs a running copytool
3998 local f=$DIR/$tdir/$tfile
3999 local fid=$(create_empty_file "$f")
4002 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4003 wait_request_state $fid ARCHIVE SUCCEED
4005 # Prevent restore from completing
4010 wait_request_state $fid REMOVE CANCELED
4013 wait_request_state $fid CANCEL SUCCEED
4015 changelog_find -type HSM -target-fid $fid -flags 0x27d
4016 error "The expected changelog was not emitted"
4018 run_test 225 "Changelog for remove canceled"
4021 # test needs a running copytool
4026 local f1=$DIR/$tdir/$tfile-1
4027 local f2=$DIR/$tdir/$tfile-2
4028 local f3=$DIR/$tdir/$tfile-3
4029 local fid1=$(copy_file /etc/passwd $f1)
4030 local fid2=$(copy_file /etc/passwd $f2)
4031 copy_file /etc/passwd $f3
4034 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4035 wait_request_state $fid1 ARCHIVE SUCCEED
4037 $LFS hsm_archive $f2
4038 wait_request_state $fid2 ARCHIVE SUCCEED
4040 rm $f1 || error "rm $f1 failed"
4043 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4044 error "The expected changelog was not emitted"
4046 mv $f3 $f2 || error "mv $f3 $f2 failed"
4048 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4049 error "The expected changelog was not emitted"
4051 run_test 226 "changelog for last rm/mv with exiting archive"
4053 # This is just a utility function to clarify what test_227 does
4058 "$LFS" "$action" --$flag "$file" ||
4059 error "Cannot ${action#hsm_} $flag on '$file'"
4061 # Only one changelog should be produced
4062 local entries="$(changelog_find -type HSM -target-fid $fid)"
4063 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4064 error "lfs $action --$flag '$file' produced more than one" \
4067 # Parse the last changelog record
4068 local entry="$(tail -n 1 <<< "$entries")"
4069 eval local -A changelog=$(changelog2array $entry)
4071 # Also check the flags match what is expected
4072 [[ ${changelog[flags]} == $target ]] ||
4073 error "Changelog flag is '${changelog[flags]}', not $target"
4077 local file="$DIR/$tdir/$tfile"
4078 local fid=$(create_empty_file "$file")
4083 for flag in norelease noarchive exists archived lost; do
4084 if [ "$flag" == lost ]; then
4085 # The flag "lost" only works on an archived file
4086 "$LFS" hsm_set --archived "$file"
4090 action="hsm_set" __test_227
4091 action="hsm_clear" __test_227
4094 run_test 227 "changelog when explicit setting of HSM flags"
4097 # test needs a running copytool
4100 local fid=$(create_small_sync_file $DIR/$tfile)
4101 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4102 wait_request_state $fid ARCHIVE SUCCEED
4104 $LFS hsm_release $DIR/$tfile
4105 check_hsm_flags $DIR/$tfile "0x0000000d"
4107 filefrag $DIR/$tfile | grep " 1 extent found" ||
4108 error "filefrag on released file must return only one extent"
4110 # only newer versions of cp detect sparse files by stat/FIEMAP
4112 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4113 error "copying $DIR/$tfile"
4114 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4116 $LFS hsm_release $DIR/$tfile
4117 check_hsm_flags $DIR/$tfile "0x0000000d"
4119 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4121 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4123 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4124 error "comparing untarred $DIR/$tfile"
4126 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4127 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4129 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4132 local file="$DIR/$tdir/$tfile"
4134 # set max_requests to allow one request of each type to be started (3)
4136 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4137 set_hsm_param max_requests 3
4140 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4141 set_hsm_param loop_period 1
4143 # send 1 requests of each kind twice
4146 for action in archive restore remove; do
4147 local filepath="$file"-to-$action
4148 local fid=$(create_empty_file "$filepath")
4149 local fid2=$(create_empty_file "$filepath".bis)
4151 if [ "$action" != archive ]; then
4152 "$LFS" hsm_archive "$filepath"
4153 wait_request_state $fid ARCHIVE SUCCEED
4154 "$LFS" hsm_archive "$filepath".bis
4155 wait_request_state $fid2 ARCHIVE SUCCEED
4157 if [ "$action" == restore ]; then
4158 "$LFS" hsm_release "$filepath"
4159 "$LFS" hsm_release "$filepath".bis
4163 # suspend the copytool to prevent requests from completing
4164 stack_trap "copytool_continue" EXIT
4167 # send `max_requests' requests (one of each kind)
4168 for action in archive restore remove; do
4169 filepath="$file"-to-$action
4170 "$LFS" hsm_${action} "$filepath"
4171 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4174 # send another batch of requests
4175 for action in archive restore remove; do
4176 "$LFS" hsm_${action} "$file-to-$action".bis
4178 # wait for `loop_period' seconds to make sure the coordinator has time
4179 # to register those, even though it should not
4182 # only the first batch of request should be started
4184 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4188 error "expected 3 STARTED requests, found $count"
4190 run_test 250 "Coordinator max request"
4193 local f=$DIR/$tdir/$tfile
4194 local fid=$(create_empty_file "$f")
4197 # to have a short test
4198 local old_to=$(get_hsm_param active_request_timeout)
4199 set_hsm_param active_request_timeout 1
4200 # to be sure the cdt will wake up frequently so
4201 # it will be able to cancel the "old" request
4202 local old_loop=$(get_hsm_param loop_period)
4203 set_hsm_param loop_period 1
4208 # Prevent archive from completing
4210 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4211 wait_request_state $fid ARCHIVE STARTED
4213 # Let the request timeout
4214 wait_request_state $fid ARCHIVE CANCELED
4216 set_hsm_param active_request_timeout $old_to
4217 set_hsm_param loop_period $old_loop
4219 run_test 251 "Coordinator request timeout"
4222 local f=$DIR/$tdir/$tfile
4223 local fid=$(create_empty_file "$f")
4225 # to have a short test
4226 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4227 set_hsm_param loop_period 1
4231 # Prevent archive from completing
4233 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4234 wait_request_state $fid ARCHIVE STARTED
4237 stack_trap "set_hsm_param active_request_timeout \
4238 $(get_hsm_param active_request_timeout)" EXIT
4239 set_hsm_param active_request_timeout 1
4241 wait_request_state $fid ARCHIVE CANCELED
4244 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4248 # test needs a running copytool
4252 local f=$DIR/$tdir/$tfile
4254 dd if=/dev/zero of=$f bs=1MB count=10
4255 local fid=$(path2fid $f)
4257 $LFS hsm_archive $f || error "could not archive file"
4258 wait_request_state $fid ARCHIVE SUCCEED
4260 # clear locks to discard inode data
4261 cancel_lru_locks osc
4263 #define OBD_FAIL_MDC_MERGE 0x807
4264 $LCTL set_param fail_loc=0x807
4266 #expect error here, instead of release with wrong size
4269 if ((rc == 0)); then
4270 file_size=$(stat -c '%s' $f)
4271 if ((file_size != 10485760)); then
4272 error "Wrong file size after hsm_release"
4275 echo "could not release file"
4278 run_test 253 "Check for wrong file size after release"
4282 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4283 skip "need MDS version at least 2.10.56"
4285 # Check that the counters are initialized to 0
4287 for request_type in archive restore remove; do
4288 count="$(get_hsm_param ${request_type}_count)" ||
4289 error "Reading ${request_type}_count failed with $?"
4291 [ "$count" -eq 0 ] ||
4292 error "Expected ${request_type}_count to be " \
4296 run_test 254a "Request counters are initialized to zero"
4300 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4301 skip "need MDS version at least 2.10.56"
4303 # The number of request to launch (at least 32)
4304 local request_count=$((RANDOM % 32 + 32))
4305 printf "Will launch %i requests of each type\n" "$request_count"
4307 # Launch a copytool to process requests
4310 # Set hsm.max_requests to allow starting all requests at the same time
4312 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4313 set_hsm_param max_requests "$request_count"
4317 for request_type in archive restore remove; do
4318 printf "Checking %s requests\n" "${request_type}"
4319 # Suspend the copytool to give us time to read the proc files
4322 for ((i = 0; i < $request_count; i++)); do
4323 case $request_type in
4325 create_empty_file "$DIR/$tdir/$tfile-$i" \
4329 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4332 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4335 # Give the coordinator 10 seconds to start every request
4337 while get_hsm_param actions | grep -q WAITING; do
4340 [ $timeout -gt 0 ] ||
4341 error "${request_type^} requests took too " \
4345 count="$(get_hsm_param ${request_type}_count)"
4346 [ "$count" -eq "$request_count" ] ||
4347 error "Expected '$request_count' (!= '$count') " \
4348 "active $request_type requests"
4350 # Let the copytool process the requests
4352 # Give it 10 seconds maximum
4354 while get_hsm_param actions | grep -q STARTED; do
4357 [ $timeout -gt 0 ] ||
4358 error "${request_type^} requests took too " \
4362 count="$(get_hsm_param ${request_type}_count)"
4363 [ "$count" -eq 0 ] ||
4364 error "Expected 0 (!= '$count') " \
4365 "active $request_type requests"
4368 run_test 254b "Request counters are correctly incremented and decremented"
4372 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4373 skip "Need MDS version at least 2.12.0"
4375 local file="$DIR/$tdir/$tfile"
4376 local fid=$(create_empty_file "$file")
4378 # How do you make sure the coordinator has consumed any outstanding
4379 # event, without triggering an event yourself?
4381 # You wait for a request to disappear from the coordinator's llog.
4383 # Warning: the setup represents 90% of this test
4385 # Create and process an HSM request
4387 "$LFS" hsm_archive "$file"
4388 wait_request_state $fid ARCHIVE SUCCEED
4391 wait_copytools || error "failed to stop copytools"
4393 # Launch a new HSM request
4395 create_empty_file "$file"
4396 "$LFS" hsm_archive "$file"
4400 # Have the completed request be removed as soon as the cdt wakes up
4401 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4402 set_hsm_param grace_delay 1
4403 # (Hopefully, time on the MDS will behave nicely)
4404 do_facet $SINGLEMDS sleep 2 &
4406 # Increase `loop_period' as a mean to prevent the coordinator from
4407 # waking itself up to do some housekeeping.
4408 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4409 set_hsm_param loop_period 1000
4411 wait $! || error "waiting failed"
4413 wait_request_state $fid ARCHIVE ""
4414 # The coordinator will not wake up on its own for ~`loop_period' secs...
4416 # ... Unless a copytool registers. Now the real test begins
4418 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4420 run_test 255 "Copytool registration wakes the coordinator up"
4422 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4423 # break in the future because of that.
4426 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4427 skip "need MDS version 2.11.56 or later"
4429 local -a files=("$DIR/$tdir/$tfile".{0..15})
4432 for file in "${files[@]}"; do
4433 create_small_file "$file"
4436 # Set a few hsm parameters
4438 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4439 set_hsm_param loop_period 1
4441 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4442 set_hsm_param max_requests 3
4446 "$LFS" hsm_archive "${files[0]}"
4447 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4448 "$LFS" hsm_release "${files[0]}"
4452 wait_copytools || error "copytools failed to stop"
4454 # Send several archive requests
4455 for file in "${files[@]:1}"; do
4456 "$LFS" hsm_archive "$file"
4459 # Send one restore request
4460 "$LFS" hsm_restore "${files[0]}"
4465 # Wait for all the requests to complete
4466 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4467 for file in "${files[@]:1}"; do
4468 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4471 # Collect the actions in the order in which the copytool processed them
4473 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4474 "$(copytool_logfile "$SINGLEAGT")")
4477 printf '%s\n' "${actions[@]}"
4480 for action in "${actions[@]:0:3}"; do
4481 [ "$action" == RESTORE ] && return
4484 error "Too many ARCHIVE requests were run before the RESTORE request"
4486 run_test 260a "Restore request have priority over other requests"
4488 # This test is very much tied to the implementation of the current priorisation
4489 # mechanism in the coordinator. It might not make sense to keep it in the future
4492 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4493 skip "need MDS version 2.11.56 or later"
4495 local -a files=("$DIR/$tdir/$tfile".{0..15})
4498 for file in "${files[@]}"; do
4499 create_small_file "$file"
4502 # Set a few hsm parameters
4504 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4505 set_hsm_param loop_period 1
4507 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4508 set_hsm_param max_requests 3
4511 copytool setup --archive-id 2
4512 "$LFS" hsm_archive --archive 2 "${files[0]}"
4513 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4514 "$LFS" hsm_release "${files[0]}"
4518 wait_copytools || error "copytools failed to stop"
4520 # Send several archive requests
4521 for file in "${files[@]:1}"; do
4522 "$LFS" hsm_archive "$file"
4525 # Send one restore request
4526 "$LFS" hsm_restore "${files[0]}"
4530 copytool setup --archive-id 2
4532 # Wait for all the requests to complete
4533 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4534 for file in "${files[@]:1}"; do
4535 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4538 # Collect the actions in the order in which the copytool processed them
4540 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4541 "$(copytool_logfile "$SINGLEAGT")")
4544 printf '%s\n' "${actions[@]}"
4547 for action in "${actions[@]:0:3}"; do
4548 [ "$action" == RESTORE ] && return
4551 error "Too many ARCHIVE requests were run before the RESTORE request"
4553 run_test 260b "Restore request have priority over other requests"
4555 # This test is very much tied to the implementation of the current priorisation
4556 # mechanism in the coordinator. It might not make sense to keep it in the future
4559 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4560 skip "Need MDS version at least 2.12.0"
4562 local -a files=("$DIR/$tdir/$tfile".{0..15})
4565 for file in "${files[@]}"; do
4566 create_small_file "$file"
4569 # Set a few hsm parameters
4571 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4572 set_hsm_param loop_period 1000
4574 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4575 set_hsm_param max_requests 3
4578 copytool setup --archive-id 2
4579 "$LFS" hsm_archive --archive 2 "${files[0]}"
4580 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4581 "$LFS" hsm_release "${files[0]}"
4585 wait_copytools || error "copytools failed to stop"
4587 # Force the next coordinator run to do housekeeping
4591 "$LFS" hsm_archive "${files[1]}"
4595 copytool setup --archive-id 2
4597 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4598 # The coordinator just did a housekeeping run it won't do another one
4599 # for around `loop_period' seconds => requests will not be reordered
4600 # if it costs too much (ie. when the coordinator has to discard a whole
4603 # Send several archive requests
4604 for file in "${files[@]:2}"; do
4605 "$LFS" hsm_archive "$file"
4608 # Send one restore request
4609 "$LFS" hsm_restore "${files[0]}"
4611 # Wait for all the requests to complete
4612 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4613 for file in "${files[@]:2}"; do
4614 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4617 # Collect the actions in the order in which the copytool processed them
4619 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4620 "$(copytool_logfile "$SINGLEAGT")")
4623 printf '%s\n' "${actions[@]}"
4626 for action in "${actions[@]:0:3}"; do
4627 [ "$action" == RESTORE ] &&
4628 error "Restore requests should not be prioritised" \
4629 "unless the coordinator is doing housekeeping"
4633 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4636 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4638 # the only way to test ondisk conf is to restart MDS ...
4639 echo "Stop coordinator and remove coordinator state at mount"
4642 # clean on disk conf set by default
4643 cdt_clear_mount_state
4644 cdt_check_state stopped
4646 # check cdt still off after umount/remount
4648 cdt_check_state stopped
4650 echo "Set coordinator start at mount, and start coordinator"
4651 cdt_set_mount_state enabled
4654 cdt_check_state enabled
4656 # check cdt still on after umount/remount
4658 cdt_check_state enabled
4660 # we are back to original state (cdt started at mount)
4662 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4665 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4667 local ai=$(get_hsm_param default_archive_id)
4668 local new=$((ai + 1))
4670 set_hsm_param default_archive_id $new -P
4672 local res=$(get_hsm_param default_archive_id)
4675 set_hsm_param default_archive_id "" "-P -d"
4677 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4679 run_test 301 "HSM tunnable are persistent"
4682 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4684 local ai=$(get_hsm_param default_archive_id)
4685 local new=$((ai + 1))
4690 set_hsm_param default_archive_id $new -P
4693 for mdtno in $(seq 1 $MDSCOUNT); do
4698 cdt_check_state enabled
4700 local res=$(get_hsm_param default_archive_id)
4703 set_hsm_param default_archive_id "" "-P -d"
4705 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4707 run_test 302 "HSM tunnable are persistent when CDT is off"
4710 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4716 local dir_mdt0=$DIR/$tdir/mdt0
4717 local dir_mdt1=$DIR/$tdir/mdt1
4719 # create 1 dir per MDT
4720 stack_trap "rm -rf $dir_mdt0" EXIT
4721 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4722 stack_trap "rm -rf $dir_mdt1" EXIT
4723 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4725 # create 1 file in each MDT
4726 local fid1=$(create_small_file $dir_mdt0/$tfile)
4727 local fid2=$(create_small_file $dir_mdt1/$tfile)
4729 # check that hsm request on mdt0 is sent to the right MDS
4730 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4731 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4732 echo "archive successful on mdt0"
4734 # check that hsm request on mdt1 is sent to the right MDS
4735 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4736 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4737 echo "archive successful on mdt1"
4739 run_test 400 "Single request is sent to the right MDT"
4742 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4748 local dir_mdt0=$DIR/$tdir/mdt0
4749 local dir_mdt1=$DIR/$tdir/mdt1
4751 # create 1 dir per MDT
4752 stack_trap "rm -rf $dir_mdt0" EXIT
4753 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4754 stack_trap "rm -rf $dir_mdt1" EXIT
4755 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4757 # create 1 file in each MDT
4758 local fid1=$(create_small_file $dir_mdt0/$tfile)
4759 local fid2=$(create_small_file $dir_mdt1/$tfile)
4761 # check that compound requests are shunt to the rights MDTs
4762 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4763 error "lfs hsm_archive"
4764 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4765 echo "archive successful on mdt0"
4766 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4767 echo "archive successful on mdt1"
4769 run_test 401 "Compound requests split and sent to their respective MDTs"
4771 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4776 local node=$(facet_active_host $facet)
4778 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4779 awk '{print $4}'); do
4780 echo "$3 $mdc on $node"
4781 do_facet $facet "$LCTL --device $mdc $state" || return 1
4786 # deactivate all mdc on agent1
4787 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4789 copytool setup --no-fail
4791 check_agent_unregistered "uuid" # match any agent
4793 # no expected running copytool
4794 search_copytools $agent && error "Copytool start should have failed"
4797 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4799 run_test 402a "Copytool start fails if all MDTs are inactive"
4806 local f=$DIR/$tdir/$tfile
4807 touch $f || error "touch $f failed"
4808 local fid=$(path2fid $f)
4810 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4811 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4812 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4814 # give time for CDT to send request and to keep it for retry
4815 wait_for_loop_period
4817 wait_request_state $fid ARCHIVE WAITING
4819 do_facet $SINGLEAGT lctl set_param fail_loc=0
4821 # request should succeed now
4822 wait_request_state $fid ARCHIVE SUCCEED
4824 run_test 402b "CDT must retry request upon slow start of CT"
4827 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4829 local agent=$(facet_active_host $SINGLEAGT)
4831 # deactivate all mdc for MDT0001
4832 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4835 local uuid=$(get_agent_uuid $agent)
4836 # check the agent is registered on MDT0000, and not on MDT0001
4837 check_agent_registered_by_mdt $uuid 0
4838 check_agent_unregistered_by_mdt $uuid 1
4840 # check running copytool process
4841 search_copytools $agent || error "No running copytools on $agent"
4843 # reactivate all mdc for MDT0001
4844 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4846 # make sure the copytool is now registered to all MDTs
4847 check_agent_registered $uuid
4849 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4852 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4856 # create files on both MDT0000 and MDT0001
4859 local dir_mdt0=$DIR/$tdir/mdt0
4860 stack_trap "rm -rf $dir_mdt0" EXIT
4861 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4863 # create 1 file on mdt0
4864 local fid1=$(create_small_file $dir_mdt0/$tfile)
4866 # deactivate all mdc for MDT0001
4867 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4869 # send an HSM request for files in MDT0000
4870 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4872 # check for completion of files in MDT0000
4873 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4874 echo "archive successful on mdt0"
4876 # reactivate all mdc for MDT0001
4877 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4879 run_test 404 "Inactive MDT does not block requests for active MDTs"
4882 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4888 local striped_dir=$DIR/$tdir/striped_dir
4890 # create striped dir on all of MDTs
4891 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4893 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4894 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4895 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4896 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4898 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4899 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4900 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4901 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4903 # check that compound requests are shunt to the rights MDTs
4904 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4905 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4906 error "lfs hsm_archive"
4908 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4909 echo "archive successful on $fid1"
4910 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4911 echo "archive successful on $fid2"
4912 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4913 echo "archive successful on $fid3"
4914 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4915 echo "archive successful on $fid4"
4917 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4918 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4919 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4920 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4922 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4923 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4924 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4925 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4927 run_test 405 "archive and release under striped directory"
4930 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4932 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
4933 skip "need MDS version at least 2.7.64"
4938 fid=$(create_small_file $DIR/$tdir/$tfile)
4943 $LFS hsm_archive $DIR/$tdir/$tfile
4944 wait_request_state "$fid" ARCHIVE SUCCEED
4945 $LFS hsm_release $DIR/$tdir/$tfile
4947 # Should migrate $tdir but not $tfile.
4948 $LFS migrate -m1 $DIR/$tdir &&
4949 error "migrating HSM an archived file should fail"
4951 $LFS hsm_restore $DIR/$tdir/$tfile
4952 wait_request_state "$fid" RESTORE SUCCEED
4954 $LFS hsm_remove $DIR/$tdir/$tfile
4955 wait_request_state "$fid" REMOVE SUCCEED
4957 cat $DIR/$tdir/$tfile > /dev/null ||
4958 error "cannot read $DIR/$tdir/$tfile"
4960 $LFS migrate -m1 $DIR/$tdir ||
4961 error "cannot complete migration after HSM remove"
4963 mdt_index=$($LFS getstripe -m $DIR/$tdir)
4964 if ((mdt_index != 1)); then
4965 error "expected MDT index 1, got $mdt_index"
4968 # Refresh fid after migration.
4969 fid=$(path2fid $DIR/$tdir/$tfile)
4972 $LFS hsm_archive $DIR/$tdir/$tfile
4973 wait_request_state "$fid" ARCHIVE SUCCEED 1
4975 lctl set_param debug=+trace
4976 $LFS hsm_release $DIR/$tdir/$tfile ||
4977 error "cannot release $DIR/$tdir/$tfile"
4979 $LFS hsm_restore $DIR/$tdir/$tfile
4980 wait_request_state "$fid" RESTORE SUCCEED 1
4982 cat $DIR/$tdir/$tfile > /dev/null ||
4983 error "cannot read $DIR/$tdir/$tfile"
4985 run_test 406 "attempting to migrate HSM archived files is safe"
4988 local f=$DIR/$tdir/$tfile
4989 local f2=$DIR2/$tdir/$tfile
4990 local fid=$(create_empty_file "$f")
4994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4995 wait_request_state $fid ARCHIVE SUCCEED
4998 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
4999 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5001 # Prevent restore from completing
5005 # 1st request holds layout lock while appropriate
5006 # RESTORE record is still not added to llog
5010 # after umount hsm_actions->O/x/x log shouldn't have
5011 # double RESTORE records like below
5012 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5013 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5015 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5019 wait_request_state $fid RESTORE SUCCEED
5021 run_test 407 "Check for double RESTORE records in llog"
5025 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5026 skip "HSM migrate is not supported"
5028 test_mkdir -p $DIR/$tdir
5030 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5031 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5033 llapi_hsm_test -d $DIR/$tdir -b ||
5034 error "One llapi HSM test failed"
5036 llapi_hsm_test -d $DIR/$tdir ||
5037 error "One llapi HSM test failed"
5040 run_test 500 "various LLAPI HSM tests"
5043 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5044 skip "need MDS version at least 2.10.58"
5048 local f=$DIR/$tdir/$tfile
5051 # set changelog_mask to ALL
5052 changelog_chmask "ALL"
5054 chmod 777 $DIR/$tdir
5055 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5056 local fid=$(path2fid $f)
5059 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5060 -gid "$RUNAS_GID") ||
5061 error "No matching CREAT entry"
5063 # Parse the changelog
5064 eval local -A changelog=$(changelog2array $entry)
5065 local nid="${changelog[nid]}"
5068 echo "Got NID '$nid'"
5069 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5070 error "nid '$nid' does not match any client NID:" \
5073 run_test 600 "Changelog fields 'u=' and 'nid='"
5076 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5077 skip "need MDS version at least 2.10.58"
5081 local f=$DIR/$tdir/$tfile
5084 # set changelog_mask to ALL
5085 changelog_chmask "ALL"
5087 touch $f || error "touch $f failed"
5088 local fid=$(path2fid $f)
5091 cat $f || error "cat $f failed"
5093 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5094 error "No matching OPEN entry"
5096 run_test 601 "OPEN Changelog entry"
5099 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5100 skip "need MDS version at least 2.10.58"
5104 local f=$DIR/$tdir/$tfile
5107 # set changelog_mask to ALL
5108 changelog_chmask "ALL"
5110 touch $f || error "touch $f failed"
5111 local fid=$(path2fid $f)
5114 cat $f || error "cat $f failed"
5116 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5120 echo f > $f || error "write $f failed"
5123 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5125 # remove OPEN from changelog_mask
5126 changelog_chmask "-OPEN"
5130 cat $f || error "cat $f failed"
5133 changelog_find -type CLOSE -target-fid $fid &&
5134 error "There should be no CLOSE entry"
5138 echo f > $f || error "write $f failed"
5141 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5143 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5146 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5147 skip "need MDS version at least 2.10.58"
5151 local f=$DIR/$tdir/$tfile
5154 # set changelog_mask to ALL
5155 changelog_chmask "ALL"
5157 touch $f || error "touch $f failed"
5158 local fid=$(path2fid $f)
5160 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5163 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5165 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5166 error "No matching GXATR entry"
5168 run_test 603 "GETXATTR Changelog entry"
5171 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5172 skip "need MDS version at least 2.10.58"
5176 local f=$DIR/$tdir/$tfile
5177 local f2=$DIR2/$tdir/$tfile
5178 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5180 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5181 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5182 do_facet mds1 lctl set_param "$procname=20"
5186 # set changelog_mask to ALL
5187 changelog_chmask "ALL"
5189 touch $f || error "touch $f failed"
5190 local fid=$(path2fid $f)
5196 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5200 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5201 -gid "$RUNAS_GID" -mode "r--") ||
5202 error "No matching NOPEN entry"
5204 # Parse the changelog
5205 eval local -A changelog=$(changelog2array $entry)
5206 local nid="${changelog[nid]}"
5209 echo "Got NID '$nid'"
5210 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5211 error "nid '$nid' does not match any client NID:" \
5216 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5219 changelog_find -type NOPEN -target-fid $fid &&
5220 error "There should be no NOPEN entry"
5222 # Sleep for `changelog_deniednext` seconds
5227 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5230 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5231 -gid "$RUNAS_GID" -mode "r--") ||
5232 error "No matching NOPEN entry"
5234 # Parse the changelog
5235 eval local -A changelog=$(changelog2array $entry)
5236 local nid="${changelog[nid]}"
5239 echo "Got NID '$nid'"
5240 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5241 error "nid '$nid' does not match any client NID:" \
5244 run_test 604 "NOPEN Changelog entry"
5247 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5248 skip "need MDS version at least 2.10.58"
5252 local f=$DIR/$tdir/$tfile
5253 local f2=$DIR2/$tdir/$tfile
5256 # set changelog_mask to ALL
5257 changelog_chmask "ALL"
5259 touch $f || error "touch $f failed"
5260 local fid=$(path2fid $f)
5264 exec 3<> $f || error "open $f failed"
5268 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5272 exec 4<> $f || error "open $f failed"
5275 changelog_find -type OPEN -target-fid $fid &&
5276 error "There should be no OPEN entry"
5278 exec 4>&- || error "close $f failed"
5281 changelog_find -type CLOSE -target-fid $fid &&
5282 error "There should be no CLOSE entry"
5286 # access in rw, so different access mode should generate entries
5287 cat $f || error "cat $f failed"
5290 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5292 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5296 # same access as first one, should not generate new entries
5297 exec 4<> $f || error "open $f failed"
5300 changelog_find -type OPEN -target-fid $fid &&
5301 error "There should be no OPEN entry"
5303 exec 4>&- || error "close $f failed"
5306 changelog_find -type CLOSE -target-fid $fid &&
5307 error "There should be no CLOSE entry"
5311 # access by different user should generate new entries
5312 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5315 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5317 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5321 exec 3>&- || error "close $f failed"
5324 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5326 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5329 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5330 skip "need MDS version at least 2.10.58"
5332 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5333 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5334 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5335 skip_env "missing llog_reader" && return
5336 local fstype=$(facet_fstype mds1)
5340 local f=$DIR/$tdir/$tfile
5343 # set changelog_mask to ALL
5344 changelog_chmask "ALL"
5346 chmod 777 $DIR/$tdir
5347 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5348 local fid=$(path2fid $f)
5349 rm $f || error "rm $f failed"
5351 local mntpt=$(facet_mntpt mds1)
5355 #remount mds1 as ldiskfs or zfs type
5356 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5357 stop mds1 || error "stop mds1 failed"
5358 mount_fstype mds1 || error "remount mds1 failed"
5360 for ((i = 0; i < 1; i++)); do
5361 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5362 local cat_file=$(do_facet mds1 $llog_reader \
5363 $mntpt/changelog_catalog | awk \
5364 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5365 [ -n "$cat_file" ] || error "no catalog file"
5367 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5368 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5369 [ -n "$entry" ] || error "no CREAT entry"
5372 local uidgid=$(echo $entry |
5373 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5374 [ -n "$uidgid" ] || error "uidgid is empty"
5375 echo "Got UID/GID $uidgid"
5376 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5377 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5378 local nid=$(echo $entry |
5379 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5380 [ -n "$nid" ] || error "nid is empty"
5382 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5383 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5385 run_test 606 "llog_reader groks changelog fields"
5388 check_and_cleanup_lustre