3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
12 LUSTRE=${LUSTRE:-$(dirname $0)/..}
13 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT "
19 # bug number for skipped tests: LU-9795
20 ALWAYS_EXCEPT+=" 402b "
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 # Skip tests for PPC that fail frequently
25 if [[ $(uname -m) = ppc64 ]]; then
26 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
27 ALWAYS_EXCEPT+=" 1a 1b 1d 1e 12c 12f "
28 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
29 ALWAYS_EXCEPT+=" 12g 12h 12m 12n 12o 12p "
30 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
31 ALWAYS_EXCEPT+=" 12q 21 22 23 24a 24b "
32 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
33 ALWAYS_EXCEPT+=" 24d 24e 24f 25b 30c 37 "
34 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
35 ALWAYS_EXCEPT+=" 57 58 90 110b 111b 113 "
36 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
37 ALWAYS_EXCEPT+=" 222b 222d 228 260a 260b 260c "
38 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
39 ALWAYS_EXCEPT+=" 220A 220a 221 222a 222c 223a "
40 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
41 ALWAYS_EXCEPT+=" 223b 224A 224a 226 227 600"
42 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
43 ALWAYS_EXCEPT+=" 601 602 603 604 605 "
48 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
50 OPENFILE=${OPENFILE:-openfile}
51 MOUNT_2=${MOUNT_2:-"yes"}
54 # script only handles up to 10 MDTs (because of MDT_PREFIX)
55 [ $MDSCOUNT -gt 9 ] &&
56 error "script cannot handle more than 9 MDTs, please fix"
58 check_and_setup_lustre
60 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
61 skip_env "Need MDS version at least 2.4.53"
64 # $RUNAS_ID may get set incorrectly somewhere else
65 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
66 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
68 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
69 if getent group nobody; then
71 elif getent group nogroup; then
74 error "No generic nobody group"
77 # if there is no CLIENT1 defined, some tests can be ran on localhost
78 CLIENT1=${CLIENT1:-$HOSTNAME}
79 # if CLIENT2 doesn't exist then use CLIENT1 instead
80 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
82 # Exception is the test which need two separate nodes
83 CLIENT2=${CLIENT2:-$CLIENT1}
86 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
87 do_nodesv $hosts "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))
97 while ((SECONDS < wait_end)); do
98 if ! search_copytools $hosts; then
99 echo "copytools stopped in $((SECONDS - wait_start))s"
103 echo "copytools still running on $hosts"
105 [ $sleep_time -lt 5 ] && sleep_time=$((sleep_time + 1))
108 # try to dump Copytool's stack
109 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
110 "echo t >/proc/sysrq-trigger"
112 echo "copytools failed to stop in ${wait_timeout}s"
117 copytool_monitor_setup() {
118 local facet=${1:-$SINGLEAGT}
119 local agent=$(facet_active_host $facet)
121 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
122 local test_dir=$(do_node $agent "$cmd") ||
123 error "Failed to create tempdir on $agent"
124 export HSMTOOL_MONITOR_DIR=$test_dir
126 # Create the fifo and a monitor (cat dies when copytool dies)
127 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
128 error "failed to create copytool fifo on $agent"
129 cmd="cat $test_dir/fifo > $test_dir/events &"
130 cmd+=" echo \\\$! > $test_dir/monitor_pid"
132 # This background subshell nonsense is required when pdsh/ssh decides
133 # to wait for the cat process to exit on the remote client
134 (do_node $agent "$cmd") &
135 export HSMTOOL_MONITOR_PDSH=$!
137 # Slightly racy, but just making a best-effort to catch obvious
140 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
142 error "Failed to start copytool monitor on $agent"
152 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
157 get_copytool_event_log() {
158 local facet=${1:-$SINGLEAGT}
159 local agent=$(facet_active_host $facet)
161 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
162 error "Can't get event log: No monitor directory!"
164 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
165 error "Could not collect event log from $agent"
169 local agents=${1:-$(facet_active_host $SINGLEAGT)}
172 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
173 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
174 echo "Copytool is suspended on $agents"
177 copytool_remove_backend() {
179 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
180 echo "Remove from backend: $fid = $be"
181 do_facet $SINGLEAGT rm -f $be
184 file_creation_failure() {
191 df $MOUNT $MOUNT2 >&2
192 error "Not enough space to create $file with $cmd"
195 error "cannot create $file with $cmd, status=$err"
200 # Creates a file using dd
206 local source=${5:-/dev/zero}
210 if [ -n "$conv" ]; then
214 # Create the directory in case it does not exist
215 mkdir -p "$(dirname "$file")"
216 # Delete the file in case it already exist
219 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
220 path2fid "$file" || error "cannot get FID of '$file'"
223 echo "cannot create file '$file'" >&2;
224 # Let the caller decide what to do on error
229 create_empty_file() {
230 create_file "${1/$DIR/$DIR2}" 1M 0 ||
231 file_creation_failure dd "${1/$DIR/$DIR2}" $?
234 create_small_file() {
235 local source_file=/dev/urandom
238 local conv=${2:-fsync}
240 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
241 file_creation_failure dd "${1/$DIR/$DIR2}" $?
244 create_small_sync_file() {
245 create_small_file "$1" sync
248 create_archive_file() {
249 local file="$(hsm_root)/$1"
251 local source=/dev/urandom
253 # Create the counterpart directory of the archive
254 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
255 error "cannot create archive directory '$(dirname "$file")'"
257 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
258 error "cannot create archive file '$file'"
262 local hsm_root="$(hsm_root)"
263 local file="$hsm_root/$2"
265 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
266 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
267 error "mkdir '$(dirname "$file")' failed"
268 do_facet $SINGLEAGT cp -p "$1" "$file" ||
269 error "cannot copy '$1' to '$file'"
274 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
281 mdts_set_param "" hsm_control "$cmd"
282 mdts_check_param hsm_control "$target" 10
287 mdts_set_param "" hsm.policy "+NRA"
288 CDT_POLICY_HAD_CHANGED=true
291 cdt_clear_no_retry() {
292 mdts_set_param "" hsm.policy "-NRA"
293 CDT_POLICY_HAD_CHANGED=true
296 cdt_set_non_blocking_restore() {
297 mdts_set_param "" hsm.policy "+NBR"
298 CDT_POLICY_HAD_CHANGED=true
301 cdt_clear_non_blocking_restore() {
302 mdts_set_param "" hsm.policy "-NBR"
303 CDT_POLICY_HAD_CHANGED=true
306 cdt_clear_mount_state() {
307 mdts_set_param "-P -d" hsm_control ""
311 set_test_state disabled disabled
315 set_test_state enabled enabled
319 set_test_state shutdown stopped
323 set_test_state purge enabled
329 cdt_set_sanity_policy
333 get_hsm_archive_id() {
336 st=$($LFS hsm_state $f)
337 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
339 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
343 check_hsm_flags_user() {
347 local st=$(get_hsm_flags $f user)
348 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
360 if [[ "$3" != 1 ]]; then
364 cp $1 $f || file_creation_failure cp $f $?
366 path2fid $f || error "cannot get fid on $f"
369 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
371 # Note that this might lead to surprising behaviours such as deleting an
372 # important file for the currently running test
373 delete_large_files() {
374 printf "Deleting large files...\n" >&2
375 find $MOUNT -size +10M -delete
376 wait_delete_completed
379 get_request_state() {
383 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
384 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
387 get_request_count() {
391 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
392 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
395 # Ensure the number of HSM request for a given FID is correct
396 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
397 assert_request_count() {
398 local request_count=$(get_request_count $1 $2)
399 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
401 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
408 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
409 [[ -n $fid ]] && cmd+=" | grep '$fid'"
410 cmd+=" | egrep 'WAITING|STARTED'"
412 wait_update_facet --verbose mds1 "$cmd" "" $timeout ||
413 error "requests did not complete"
416 wait_for_grace_delay() {
417 local val=$(get_hsm_param grace_delay)
421 wait_for_loop_period() {
422 local val=$(get_hsm_param loop_period)
429 # python2.6 in EL6 includes an internal json module
430 local json_parser='import json; import fileinput;'
431 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
432 json_parser+='json.loads([line for line in '
433 json_parser+='fileinput.input()][0]).items()])'
435 echo $raw_event | python -c "$json_parser"
438 get_agent_by_uuid_mdt() {
441 local mds=mds$(($mdtidx + 1))
442 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
446 check_agent_registered_by_mdt() {
449 local mds=mds$(($mdtidx + 1))
450 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
451 if [[ ! -z "$agent" ]]; then
452 echo "found agent $agent on $mds"
454 error "uuid $uuid not found in agent list on $mds"
458 check_agent_unregistered_by_mdt() {
461 local mds=mds$(($mdtidx + 1))
462 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
463 if [[ -z "$agent" ]]; then
464 echo "uuid not found in agent list on $mds"
466 error "uuid found in agent list on $mds: $agent"
470 check_agent_registered() {
473 for mdsno in $(seq 1 $MDSCOUNT); do
474 check_agent_registered_by_mdt $uuid $((mdsno - 1))
478 check_agent_unregistered() {
481 for mdsno in $(seq 1 $MDSCOUNT); do
482 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
487 local agent=${1:-$(facet_active_host $SINGLEAGT)}
489 # Lustre mount-point is mandatory and last parameter on
491 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
493 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
495 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
501 # populate MDT device array
504 # cleanup from previous bad setup
507 # for recovery tests, coordinator needs to be started at mount
509 # the lustre conf must be without hsm on (like for sanity.sh)
510 echo "Set HSM on and start"
511 cdt_set_mount_state enabled
512 cdt_check_state enabled
514 echo "Set sanity-hsm HSM policy"
515 cdt_set_sanity_policy
517 # finished requests are quickly removed from list
518 set_hsm_param grace_delay 10
520 CLIENT_NIDS=( $($LCTL list_nids all) )
522 test_1A() { # was test_1
526 local f=$DIR/$tdir/$tfile
530 check_hsm_flags_user $f "0x00000000"
532 $RUNAS $LFS hsm_set --norelease $f ||
533 error "user could not change hsm flags"
534 check_hsm_flags_user $f "0x00000010"
536 $RUNAS $LFS hsm_clear --norelease $f ||
537 error "user could not clear hsm flags"
538 check_hsm_flags_user $f "0x00000000"
540 # User could not change those flags...
541 $RUNAS $LFS hsm_set --exists $f &&
542 error "user should not set this flag"
543 check_hsm_flags_user $f "0x00000000"
546 $LFS hsm_set --exists $f ||
547 error "root could not change hsm flags"
548 check_hsm_flags_user $f "0x00000001"
550 $LFS hsm_clear --exists $f ||
551 error "root could not clear hsm state"
552 check_hsm_flags_user $f "0x00000000"
555 run_test 1A "lfs hsm flags root/non-root access"
558 local f=$DIR/$tdir/$tfile
559 local fid=$(create_small_file $f)
563 $LFS hsm_archive $f || error "could not archive file"
564 wait_request_state $fid ARCHIVE SUCCEED
566 # Release and check states
567 $LFS hsm_release $f || error "could not release file"
568 echo -n "Verifying released state: "
569 check_hsm_flags $f "0x0000000d"
571 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
573 run_test 1a "mmap & cat a HSM released file"
579 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
580 error "failed to create file"
581 local fid=$(path2fid $f)
586 $LFS hsm_archive $f || error "could not archive file"
587 wait_request_state $fid ARCHIVE SUCCEED
590 $LFS hsm_release $f || error "could not release file"
591 echo "verify released state: "
592 check_hsm_flags $f "0x0000000d" && echo "pass"
595 $LFS hsm_restore $f || error "could not restore file"
596 wait_request_state $fid RESTORE SUCCEED
597 echo "verify restored state: "
598 check_hsm_flags $f "0x00000009" && echo "pass"
603 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
604 error "failed to set default stripe"
605 local f=$DIR/$tdir/$tfile
609 run_test 1b "Archive, Release and Restore composite file"
615 local f=$DIR/$tdir/$tfile
618 # Test whether we can set the maximum archive number.
619 local LOCAL_HSM_ARCHIVE_NUMBER=32
620 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
621 error "root could not change hsm flags"
622 check_hsm_flags_user $f "0x00000001"
623 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
624 local st=$(get_hsm_archive_id $f)
625 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
626 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
628 # Test whether setting archive number 0 results in no change.
629 $LFS hsm_set --exists --archive-id 0 $f ||
630 error "root could not change hsm flags"
631 check_hsm_flags_user $f "0x00000001"
632 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
633 st=$(get_hsm_archive_id $f)
634 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
635 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
637 LOCAL_HSM_ARCHIVE_NUMBER=33
638 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
639 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
640 # lustre in the new version supports unlimited archiveID.
641 # Test whether setting archive number > 32 is supported
642 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
643 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
644 check_hsm_flags_user $f "0x00000001"
646 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
647 st=$(get_hsm_archive_id $f)
648 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
649 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
651 # old client or old mds can only support at most 32 archiveID
652 # test whether setting archive number > 32 results in error.
653 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
654 error "bitmap archive number is larger than 32"
655 check_hsm_flags_user $f "0x00000001"
658 # Test whether setting archive number 16 and archived flag.
659 LOCAL_HSM_ARCHIVE_NUMBER=16
660 $LFS hsm_set --exists --archived \
661 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
662 error "root could not change hsm flags"
663 check_hsm_flags_user $f "0x00000009"
664 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
665 st=$(get_hsm_archive_id $f)
666 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
667 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
669 run_test 1c "Check setting archive-id in lfs hsm_set"
672 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
673 skip "need MDS version at least 2.10.59"
676 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
677 error "failed to set default stripe"
678 local f=$DIR/$tdir/$tfile
682 run_test 1d "Archive, Release and Restore DoM file"
685 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
686 skip "skipped for lustre < $SEL_VER"
689 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
690 error "failed to set default stripe"
691 local comp_file=$DIR/$tdir/$tfile
693 test_1bde_base $comp_file
695 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
696 local found=$($LFS find $flg_opts $comp_file | wc -l)
697 [ $found -eq 1 ] || error "1st component not found"
699 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
700 found=$($LFS find $flg_opts $comp_file | wc -l)
701 [ $found -eq 1 ] || error "2nd component not found"
703 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
704 found=$($LFS find $flg_opts $comp_file | wc -l)
705 [ $found -eq 1 ] || error "3rd component not found"
707 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
708 found=$($LFS find $flg_opts $comp_file | wc -l)
709 [ $found -eq 1 ] || error "4th component not found"
711 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
712 found=$($LFS find $flg_opts $comp_file | wc -l)
713 [ $found -eq 1 ] || error "5th component not found"
715 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
716 found=$($LFS find $flg_opts $comp_file | wc -l)
717 [ $found -eq 1 ] || error "6th component not found"
719 sel_layout_sanity $comp_file 6
721 run_test 1e "Archive, Release and Restore SEL file"
724 local f=$DIR/$tdir/$tfile
726 create_empty_file "$f"
727 # New files are not dirty
728 check_hsm_flags $f "0x00000000"
730 # For test, we simulate an archived file.
731 $LFS hsm_set --exists $f || error "user could not change hsm flags"
732 check_hsm_flags $f "0x00000001"
734 # chmod do not put the file dirty
735 chmod 600 $f || error "could not chmod test file"
736 check_hsm_flags $f "0x00000001"
738 # chown do not put the file dirty
739 chown $RUNAS_ID $f || error "could not chown test file"
740 check_hsm_flags $f "0x00000001"
742 # truncate put the file dirty
743 $TRUNCATE $f 1 || error "could not truncate test file"
744 check_hsm_flags $f "0x00000003"
746 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
747 check_hsm_flags $f "0x00000001"
749 run_test 2 "Check file dirtyness when doing setattr"
755 # New files are not dirty
757 check_hsm_flags $f "0x00000000"
759 # For test, we simulate an archived file.
760 $LFS hsm_set --exists $f ||
761 error "user could not change hsm flags"
762 check_hsm_flags $f "0x00000001"
764 # Reading a file, does not set dirty
765 cat $f > /dev/null || error "could not read file"
766 check_hsm_flags $f "0x00000001"
768 # Open for write without modifying data, does not set dirty
769 openfile -f O_WRONLY $f || error "could not open test file"
770 check_hsm_flags $f "0x00000001"
772 # Append to a file sets it dirty
773 cp -p /etc/passwd $f.append || error "could not create file"
774 $LFS hsm_set --exists $f.append ||
775 error "user could not change hsm flags"
776 dd if=/etc/passwd of=$f.append bs=1 count=3\
777 conv=notrunc oflag=append status=noxfer ||
778 file_creation_failure dd $f.append $?
779 check_hsm_flags $f.append "0x00000003"
781 # Modify a file sets it dirty
782 cp -p /etc/passwd $f.modify || error "could not create file"
783 $LFS hsm_set --exists $f.modify ||
784 error "user could not change hsm flags"
785 dd if=/dev/zero of=$f.modify bs=1 count=3\
786 conv=notrunc status=noxfer ||
787 file_creation_failure dd $f.modify $?
788 check_hsm_flags $f.modify "0x00000003"
790 # Open O_TRUNC sets dirty
791 cp -p /etc/passwd $f.trunc || error "could not create file"
792 $LFS hsm_set --exists $f.trunc ||
793 error "user could not change hsm flags"
794 cp /etc/group $f.trunc || error "could not override a file"
795 check_hsm_flags $f.trunc "0x00000003"
797 # Mmapped a file sets dirty
798 cp -p /etc/passwd $f.mmap || error "could not create file"
799 $LFS hsm_set --exists $f.mmap ||
800 error "user could not change hsm flags"
801 multiop $f.mmap OSMWUc || error "could not mmap a file"
802 check_hsm_flags $f.mmap "0x00000003"
804 run_test 3 "Check file dirtyness when opening for write"
807 local f=$DIR/$tdir/$tfile
808 local fid=$(create_small_file $f)
811 local st=$(get_request_state $fid CANCEL)
812 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
814 run_test 4 "Useless cancel must not be registered"
817 # test needs a running copytool
821 local f=$DIR/$tdir/$tfile
822 local fid=$(copy_file /etc/passwd $f)
824 wait_request_state $fid ARCHIVE SUCCEED
826 check_hsm_flags $f "0x00000009"
828 run_test 8 "Test default archive number"
830 test_9A() { # was test_9
831 # we do not use the default one to be sure
832 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
833 copytool setup --archive-id $archive_id
835 # give time for CT to register with MDTs
836 sleep $(($MDSCOUNT*2))
837 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
838 check_agent_registered $uuid
841 local f=$DIR/$tdir/$tfile
842 local fid=$(copy_file /etc/passwd $f)
843 $LFS hsm_archive --archive $archive_id $f
844 wait_request_state $fid ARCHIVE SUCCEED
846 check_hsm_flags $f "0x00000009"
848 run_test 9A "Use of explicit archive number, with dedicated copytool"
851 needclients 3 || return 0
857 # start all of the copytools
858 for n in $(seq $AGTCOUNT); do
859 copytool setup --facet agt$n
863 for n in $(seq $AGTCOUNT); do
864 file=$DIR/$tdir/$tfile.$n
865 fid=$(create_small_file $file)
867 $LFS hsm_archive $file || error "could not archive file $file"
868 wait_request_state $fid ARCHIVE SUCCEED
869 check_hsm_flags $file "0x00000009"
872 run_test 9a "Multiple remote agents"
875 # test needs a running copytool
878 mkdir -p $DIR/$tdir/d1
879 local f=$DIR/$tdir/$tfile
880 local fid=$(copy_file /etc/hosts $f)
881 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
882 error "hsm_archive failed"
883 wait_request_state $fid ARCHIVE SUCCEED
885 local hsm_root="$(copytool_device $SINGLEAGT)"
886 local archive="$(do_facet $SINGLEAGT \
887 find "$hsm_root" -name "$fid" -print0)"
888 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
890 echo "Verifying content"
891 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
892 echo "Verifying hsm state "
893 check_hsm_flags $f "0x00000009"
895 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
896 local st=$(get_hsm_archive_id $f)
897 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
898 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
900 run_test 10a "Archive a file"
903 # test needs a running copytool
907 local f=$DIR/$tdir/$tfile
908 local fid=$(copy_file /etc/hosts $f)
909 $LFS hsm_archive $f || error "archive request failed"
910 wait_request_state $fid ARCHIVE SUCCEED
912 $LFS hsm_archive $f || error "archive of non dirty file failed"
913 local cnt=$(get_request_count $fid ARCHIVE)
914 [[ "$cnt" == "1" ]] ||
915 error "archive of non dirty file must not make a request"
917 run_test 10b "Archive of non dirty file must work without doing request"
920 # test needs a running copytool
924 local f=$DIR/$tdir/$tfile
925 local fid=$(copy_file /etc/hosts $f)
926 $LFS hsm_set --noarchive $f
927 $LFS hsm_archive $f && error "archive a noarchive file must fail"
930 run_test 10c "Check forbidden archive"
933 # test needs a running copytool
937 local f=$DIR/$tdir/$tfile
938 local fid=$(copy_file /etc/hosts $f)
939 $LFS hsm_archive $f || error "cannot archive $f"
940 wait_request_state $fid ARCHIVE SUCCEED
942 local ar=$(get_hsm_archive_id $f)
943 local dflt=$(get_hsm_param default_archive_id)
944 [[ $ar == $dflt ]] ||
945 error "archived file is not on default archive: $ar != $dflt"
947 run_test 10d "Archive a file on the default archive id"
951 copy2archive /etc/hosts $tdir/$tfile
952 local f=$DIR/$tdir/$tfile
954 copytool import $tdir/$tfile $f
955 echo -n "Verifying released state: "
956 check_hsm_flags $f "0x0000000d"
958 local LSZ=$(stat -c "%s" $f)
959 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
961 echo "Verifying imported size $LSZ=$ASZ"
962 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
963 echo -n "Verifying released pattern: "
964 local PTRN=$($LFS getstripe -L $f)
966 [[ $PTRN == released ]] || error "Is not released"
967 local fid=$(path2fid $f)
968 echo "Verifying new fid $fid in archive"
970 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
971 error "No archive for fid $fid"
973 run_test 11a "Import a file"
976 # test needs a running copytool
980 local f=$DIR/$tdir/$tfile
981 local fid=$(copy_file /etc/hosts $f)
982 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
983 error "hsm_archive failed"
984 wait_request_state $fid ARCHIVE SUCCEED
986 local FILE_HASH=$(md5sum $f)
989 copytool import $fid $f
991 echo "$FILE_HASH" | md5sum -c
993 [[ $? -eq 0 ]] || error "Restored file differs"
995 run_test 11b "Import a deleted file using its FID"
998 # test needs a running copytool
1002 copy2archive /etc/hosts $tdir/$tfile
1004 local f=$DIR/$tdir/$tfile
1005 copytool import $tdir/$tfile $f
1006 local f2=$DIR2/$tdir/$tfile
1007 echo "Verifying released state: "
1008 check_hsm_flags $f2 "0x0000000d"
1010 local fid=$(path2fid $f2)
1011 $LFS hsm_restore $f2
1012 wait_request_state $fid RESTORE SUCCEED
1014 echo "Verifying file state: "
1015 check_hsm_flags $f2 "0x00000009"
1017 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1019 [[ $? -eq 0 ]] || error "Restored file differs"
1021 run_test 12a "Restore an imported file explicitly"
1024 # test needs a running copytool
1028 copy2archive /etc/hosts $tdir/$tfile
1030 local f=$DIR/$tdir/$tfile
1031 copytool import $tdir/$tfile $f
1032 echo "Verifying released state: "
1033 check_hsm_flags $f "0x0000000d"
1035 cat $f > /dev/null || error "File read failed"
1037 echo "Verifying file state after restore: "
1038 check_hsm_flags $f "0x00000009"
1040 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1042 [[ $? -eq 0 ]] || error "Restored file differs"
1044 run_test 12b "Restore an imported file implicitly"
1047 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1049 # test needs a running copytool
1052 local f=$DIR/$tdir/$tfile
1054 $LFS setstripe -c 2 "$f"
1055 local fid=$(create_file "$f" 1M 5)
1057 local FILE_CRC=$(md5sum $f)
1059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1060 wait_request_state $fid ARCHIVE SUCCEED
1061 $LFS hsm_release $f || error "release $f failed"
1063 echo "$FILE_CRC" | md5sum -c
1065 [[ $? -eq 0 ]] || error "Restored file differs"
1067 run_test 12c "Restore a file with stripe of 2"
1070 # test needs a running copytool
1075 local f=$DIR/$tdir/$tfile
1076 local fid=$(copy_file /etc/hosts $f)
1077 $LFS hsm_restore $f || error "restore of non archived file failed"
1078 local cnt=$(get_request_count $fid RESTORE)
1079 [[ "$cnt" == "0" ]] ||
1080 error "restore non archived must not make a request"
1081 $LFS hsm_archive $f ||
1082 error "archive request failed"
1083 wait_request_state $fid ARCHIVE SUCCEED
1084 $LFS hsm_restore $f ||
1085 error "restore of non released file failed"
1086 local cnt=$(get_request_count $fid RESTORE)
1087 [[ "$cnt" == "0" ]] ||
1088 error "restore a non dirty file must not make a request"
1090 run_test 12d "Restore of a non archived, non released file must work"\
1091 " without doing request"
1094 # test needs a running copytool
1098 local f=$DIR/$tdir/$tfile
1099 local fid=$(copy_file /etc/hosts $f)
1100 $LFS hsm_archive $f || error "archive request failed"
1101 wait_request_state $fid ARCHIVE SUCCEED
1104 cat /etc/hosts >> $f
1108 $LFS hsm_restore $f && error "restore a dirty file must fail"
1111 run_test 12e "Check forbidden restore"
1114 # test needs a running copytool
1118 local f=$DIR/$tdir/$tfile
1119 local fid=$(copy_file /etc/hosts $f)
1121 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1122 wait_request_state $fid ARCHIVE SUCCEED
1123 $LFS hsm_release $f || error "release of $f failed"
1125 wait_request_state $fid RESTORE SUCCEED
1127 echo -n "Verifying file state: "
1128 check_hsm_flags $f "0x00000009"
1130 diff -q /etc/hosts $f
1132 [[ $? -eq 0 ]] || error "Restored file differs"
1134 run_test 12f "Restore a released file explicitly"
1137 # test needs a running copytool
1141 local f=$DIR/$tdir/$tfile
1142 local fid=$(copy_file /etc/hosts $f)
1144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1145 wait_request_state $fid ARCHIVE SUCCEED
1146 $LFS hsm_release $f || error "release of $f failed"
1148 diff -q /etc/hosts $f
1151 # we check we had a restore done
1152 wait_request_state $fid RESTORE SUCCEED
1154 [[ $st -eq 0 ]] || error "Restored file differs"
1156 run_test 12g "Restore a released file implicitly"
1159 needclients 2 || return 0
1161 # test needs a running copytool
1165 local f=$DIR/$tdir/$tfile
1166 local fid=$(copy_file /etc/hosts $f)
1168 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1169 wait_request_state $fid ARCHIVE SUCCEED
1170 $LFS hsm_release $f || error "release of $f failed"
1172 do_node $CLIENT2 diff -q /etc/hosts $f
1175 # we check we had a restore done
1176 wait_request_state $fid RESTORE SUCCEED
1178 [[ $st -eq 0 ]] || error "Restored file differs"
1180 run_test 12h "Restore a released file implicitly from a second node"
1183 # test needs a running copytool
1187 local f=$DIR/$tdir/$tfile
1188 local fid=$(copy_file /etc/passwd $f)
1189 $LFS hsm_archive $f || error "archive of $f failed"
1190 wait_request_state $fid ARCHIVE SUCCEED
1192 $LFS hsm_release $f || error "release of $f failed"
1196 [[ $? -eq 0 ]] || error "Restored file differs"
1198 run_test 12m "Archive/release/implicit restore"
1201 # test needs a running copytool
1205 copy2archive /etc/hosts $tdir/$tfile
1207 local f=$DIR/$tdir/$tfile
1208 copytool import $tdir/$tfile $f
1210 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1211 error "Restored file differs"
1213 $LFS hsm_release $f || error "release of $f failed"
1215 run_test 12n "Import/implicit restore/release"
1218 # test needs a running copytool
1222 local f=$DIR/$tdir/$tfile
1223 local fid=$(copy_file /etc/hosts $f)
1225 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1226 wait_request_state $fid ARCHIVE SUCCEED
1227 $LFS hsm_release $f || error "release of $f failed"
1229 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1230 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1232 # set no retry action mode
1235 diff -q /etc/hosts $f
1238 # we check we had a restore failure
1239 wait_request_state $fid RESTORE FAILED
1241 [[ $st -eq 0 ]] && error "Restore must fail"
1243 # remove no retry action mode
1246 # check file is still released
1247 check_hsm_flags $f "0x0000000d"
1249 # retry w/o failure injection
1250 do_facet $SINGLEMDS lctl set_param fail_loc=0
1252 # to be sure previous RESTORE result is gone
1254 wait_for_grace_delay
1256 diff -q /etc/hosts $f
1259 # we check we had a restore done
1260 wait_request_state $fid RESTORE SUCCEED
1262 [[ $st -eq 0 ]] || error "Restored file differs"
1264 run_test 12o "Layout-swap failure during Restore leaves file released"
1267 # test needs a running copytool
1271 local f=$DIR/$tdir/$tfile
1272 local fid=$(copy_file /etc/hosts $f)
1274 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1275 wait_request_state $fid ARCHIVE SUCCEED
1276 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1277 $LFS hsm_release $f || error "cannot release $f"
1278 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1279 $LFS hsm_release $f || error "cannot release $f"
1280 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1282 run_test 12p "implicit restore of a file on copytool mount point"
1285 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1286 skip "need MDS version at least 2.7.58"
1288 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1289 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1290 error "cannot mount $MOUNT3 on $SINGLEAGT"
1292 # test needs a running copytool
1293 copytool setup -m "$MOUNT3"
1295 local f=$DIR/$tdir/$tfile
1296 local f2=$DIR2/$tdir/$tfile
1297 local fid=$(create_small_file $f)
1298 local orig_size=$(stat -c "%s" $f)
1300 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1301 wait_request_state $fid ARCHIVE SUCCEED
1303 $LFS hsm_release $f || error "could not release file"
1304 check_hsm_flags $f "0x0000000d"
1307 wait_copytools || error "copytool failed to stop"
1309 cat $f > /dev/null &
1311 # wait a bit to allow implicit restore request to be handled.
1312 # if not, next stat would also block on layout-lock.
1315 local size=$(stat -c "%s" $f2)
1316 [ $size -eq $orig_size ] ||
1317 error "$f2: wrong size after archive: $size != $orig_size"
1319 copytool setup -m "$MOUNT3"
1323 size=$(stat -c "%s" $f)
1324 [ $size -eq $orig_size ] ||
1325 error "$f: wrong size after restore: $size != $orig_size"
1327 size=$(stat -c "%s" $f2)
1328 [ $size -eq $orig_size ] ||
1329 error "$f2: wrong size after restore: $size != $orig_size"
1333 size=$(stat -c "%s" $f)
1335 error "$f: wrong size after overwrite: $size != 0"
1337 size=$(stat -c "%s" $f2)
1339 error "$f2: wrong size after overwrite: $size != 0"
1341 run_test 12q "file attributes are refreshed after restore"
1344 # test needs a running copytool
1348 local f=$DIR/$tdir/$tfile
1349 local fid=$(copy_file /etc/hosts $f)
1351 $LFS hsm_archive $f || error "archive of $f failed"
1352 wait_request_state $fid ARCHIVE SUCCEED
1353 $LFS hsm_release $f || error "release of $f failed"
1355 offset=$(lseek_test -d 7 $f)
1357 # we check we had a restore done
1358 wait_request_state $fid RESTORE SUCCEED
1359 [[ $offset == 7 ]] || error "offset $offset != 7"
1361 run_test 12r "lseek restores released file"
1365 for i in {1..10}; do
1366 local archive_dir="$(hsm_root)"/subdir/dir.$i
1368 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1369 for j in {1..10}; do
1370 local archive_file="$archive_dir"/file.$j
1372 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1378 copytool import "subdir" "$DIR/$tdir"
1380 # To check the import, the test uses diff with the -r flag
1381 # This is nice, but diff only checks files one by one, and triggering
1382 # an implicit restore for one file at a time will consume as many
1383 # seconds as there are files to compare. To speed this up, a restore
1384 # operation is triggered manually first.
1386 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1388 # Compare the imported data
1389 do_facet $SINGLEAGT \
1390 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1391 error "imported files differ from archived data"
1393 run_test 13 "Recursively import and restore a directory"
1396 # test needs a running copytool
1400 local f=$DIR/$tdir/$tfile
1401 local fid=$(create_small_file $f)
1402 local sum=$(md5sum $f | awk '{print $1}')
1403 $LFS hsm_archive $f || error "could not archive file"
1404 wait_request_state $fid ARCHIVE SUCCEED
1406 # create released file (simulate llapi_hsm_import call)
1407 local fid2=$(create_empty_file "$f")
1408 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1409 $LFS hsm_release $f || error "could not release file"
1411 # rebind the archive to the newly created file
1412 echo "rebind $fid to $fid2"
1414 copytool rebind $fid $fid2
1416 # restore file and compare md5sum
1417 local sum2=$(md5sum $f | awk '{print $1}')
1419 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1421 run_test 14 "Rebind archived file to a new fid"
1424 # test needs a running copytool
1428 local f=$DIR/$tdir/$tfile
1430 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1434 for i in $(seq 1 $count); do
1435 fids[$i]=$(create_small_file $f.$i)
1436 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1437 $LFS hsm_archive $f.$i || error "could not archive file"
1439 wait_all_done $(($count*60))
1441 stack_trap "rm -f $tmpfile" EXIT
1444 for i in $(seq 1 $count); do
1445 local fid2=$(create_empty_file "${f}.${i}")
1446 # add the rebind operation to the list
1447 echo ${fids[$i]} $fid2 >> $tmpfile
1449 # set it released (simulate llapi_hsm_import call)
1450 $LFS hsm_set --archived --exists $f.$i ||
1451 error "could not force hsm flags"
1452 $LFS hsm_release $f.$i || error "could not release file"
1454 nl=$(wc -l < $tmpfile)
1455 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1457 echo "rebind list of files"
1458 copytool rebind "$tmpfile"
1460 # restore files and compare md5sum
1461 for i in $(seq 1 $count); do
1462 local sum2=$(md5sum $f.$i | awk '{print $1}')
1463 [[ $sum2 == ${sums[$i]} ]] ||
1464 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1467 run_test 15 "Rebind a list of files"
1470 # test needs a running copytool
1474 # create a known size file so we can verify transfer speed
1477 dd if=/dev/zero of=$ref bs=1M count=20
1480 local f=$DIR/$tdir/$tfile
1481 local fid=$(copy_file $ref $f)
1483 local start=$(date +%s)
1485 wait_request_state $fid ARCHIVE SUCCEED
1486 local end=$(date +%s)
1487 # Add 1 to account for rounding errors between start and end (LU-8155)
1488 local duration=$((end - start + 1))
1490 [[ $duration -ge $((goal - 1)) ]] ||
1491 error "Transfer is too fast $duration < $goal"
1493 run_test 16 "Test CT bandwith control option"
1496 local f=$DIR/$tdir/$tfile
1497 create_empty_file "$f"
1499 # Could not release a non-archived file
1500 $LFS hsm_release $f && error "release should not succeed"
1502 # For following tests, we must test them with HS_ARCHIVED set
1503 $LFS hsm_set --exists --archived $f || error "could not add flag"
1505 # Could not release a file if no-release is set
1506 $LFS hsm_set --norelease $f || error "could not add flag"
1507 $LFS hsm_release $f && error "release should not succeed"
1508 $LFS hsm_clear --norelease $f || error "could not remove flag"
1510 # Could not release a file if lost
1511 $LFS hsm_set --lost $f || error "could not add flag"
1512 $LFS hsm_release $f && error "release should not succeed"
1513 $LFS hsm_clear --lost $f || error "could not remove flag"
1515 # Could not release a file if dirty
1516 $LFS hsm_set --dirty $f || error "could not add flag"
1517 $LFS hsm_release $f && error "release should not succeed"
1518 $LFS hsm_clear --dirty $f || error "could not remove flag"
1520 run_test 20 "Release is not permitted"
1523 # test needs a running copytool
1526 local f=$DIR/$tdir/test_release
1528 # Create a file and check its states
1529 local fid=$(create_small_file $f)
1530 check_hsm_flags $f "0x00000000"
1532 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1533 # used until file is flushed to disk
1534 if [ $(facet_fstype ost1) == "zfs" ]; then
1535 # this causes an OST_SYNC rpc to be sent
1536 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1537 # clear locks to reread file data
1538 cancel_lru_locks osc
1541 local orig_size=$(stat -c "%s" $f)
1542 local orig_blocks=$(stat -c "%b" $f)
1544 start_full_debug_logging
1546 $LFS hsm_archive $f || error "could not archive file"
1547 wait_request_state $fid ARCHIVE SUCCEED
1549 local blocks=$(stat -c "%b" $f)
1550 [ $blocks -eq $orig_blocks ] ||
1551 error "$f: wrong block number after archive: " \
1552 "$blocks != $orig_blocks"
1553 local size=$(stat -c "%s" $f)
1554 [ $size -eq $orig_size ] ||
1555 error "$f: wrong size after archive: $size != $orig_size"
1557 # Release and check states
1558 $LFS hsm_release $f || error "could not release file"
1559 check_hsm_flags $f "0x0000000d"
1561 blocks=$(stat -c "%b" $f)
1562 [ $blocks -gt 5 ] &&
1563 error "$f: too many blocks after release: $blocks > 5"
1564 size=$(stat -c "%s" $f)
1565 [ $size -ne $orig_size ] &&
1566 error "$f: wrong size after release: $size != $orig_size"
1568 # Check we can release an file without stripe info
1572 check_hsm_flags $f "0x00000000"
1573 $LFS hsm_archive $f || error "could not archive file"
1574 wait_request_state $fid ARCHIVE SUCCEED
1576 # Release and check states
1577 $LFS hsm_release $f || error "could not release file"
1578 check_hsm_flags $f "0x0000000d"
1580 # Release again a file that is already released is OK
1581 $LFS hsm_release $f || fail "second release should succeed"
1582 check_hsm_flags $f "0x0000000d"
1584 stop_full_debug_logging
1586 run_test 21 "Simple release tests"
1589 # test needs a running copytool
1592 local f=$DIR/$tdir/test_release
1593 local swap=$DIR/$tdir/test_swap
1595 # Create a file and check its states
1596 local fid=$(create_small_file $f)
1597 check_hsm_flags $f "0x00000000"
1599 $LFS hsm_archive $f || error "could not archive file"
1600 wait_request_state $fid ARCHIVE SUCCEED
1602 # Release and check states
1603 $LFS hsm_release $f || error "could not release file"
1604 check_hsm_flags $f "0x0000000d"
1606 create_small_file $swap
1607 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1611 run_test 22 "Could not swap a release file"
1614 # test needs a running copytool
1617 local f=$DIR/$tdir/test_mtime
1619 # Create a file and check its states
1620 local fid=$(create_small_file $f)
1621 check_hsm_flags $f "0x00000000"
1623 $LFS hsm_archive $f || error "could not archive file"
1624 wait_request_state $fid ARCHIVE SUCCEED
1626 # Set modification time in the past
1627 touch -m -a -d @978261179 $f
1629 # Release and check states
1630 $LFS hsm_release $f || error "could not release file"
1631 check_hsm_flags $f "0x0000000d"
1633 local MTIME=$(stat -c "%Y" $f)
1634 local ATIME=$(stat -c "%X" $f)
1635 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1636 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1638 run_test 23 "Release does not change a/mtime (utime)"
1641 local file=$DIR/$tdir/$tfile
1650 # test needs a running copytool
1653 fid=$(create_small_file $file)
1655 # Create a file and check its states
1656 check_hsm_flags $file "0x00000000"
1658 # Ensure atime is less than mtime and ctime.
1662 atime0=$(stat -c "%X" $file)
1663 mtime0=$(stat -c "%Y" $file)
1664 ctime0=$(stat -c "%Z" $file)
1666 [ $atime0 -lt $mtime0 ] ||
1667 error "atime $atime0 is not less than mtime $mtime0"
1669 [ $atime0 -lt $ctime0 ] ||
1670 error "atime $atime0 is not less than ctime $ctime0"
1672 # Archive should not change any timestamps.
1673 $LFS hsm_archive $file || error "cannot archive '$file'"
1674 wait_request_state $fid ARCHIVE SUCCEED
1676 atime1=$(stat -c "%X" $file)
1677 mtime1=$(stat -c "%Y" $file)
1678 ctime1=$(stat -c "%Z" $file)
1680 [ $atime0 -eq $atime1 ] ||
1681 error "archive changed atime from $atime0 to $atime1"
1683 [ $mtime0 -eq $mtime1 ] ||
1684 error "archive changed mtime from $mtime0 to $mtime1"
1686 [ $ctime0 -eq $ctime1 ] ||
1687 error "archive changed ctime from $ctime0 to $ctime1"
1689 # Release should not change any timestamps.
1690 $LFS hsm_release $file || error "cannot release '$file'"
1691 check_hsm_flags $file "0x0000000d"
1693 atime1=$(stat -c "%X" $file)
1694 mtime1=$(stat -c "%Y" $file)
1695 ctime1=$(stat -c "%Z" $file)
1697 [ $atime0 -eq $atime1 ] ||
1698 error "release changed atime from $atime0 to $atime1"
1700 [ $mtime0 -eq $mtime1 ] ||
1701 error "release changed mtime from $mtime0 to $mtime1"
1703 [ $ctime0 -eq $ctime1 ] ||
1704 error "release changed ctime from $ctime0 to $ctime1"
1706 # Restore should not change any timestamps.
1707 $LFS hsm_restore $file
1708 wait_request_state $fid RESTORE SUCCEED
1710 atime1=$(stat -c "%X" $file)
1711 mtime1=$(stat -c "%Y" $file)
1712 ctime1=$(stat -c "%Z" $file)
1714 [ $atime0 -eq $atime1 ] ||
1715 error "restore changed atime from $atime0 to $atime1"
1717 [ $mtime0 -eq $mtime1 ] ||
1718 error "restore changed mtime from $mtime0 to $mtime1"
1720 [ $ctime0 -eq $ctime1 ] ||
1721 error "restore changed ctime from $ctime0 to $ctime1"
1724 wait_copytools || error "Copytools failed to stop"
1726 # Once more, after unmount and mount.
1727 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1728 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1730 atime1=$(stat -c "%X" $file)
1731 mtime1=$(stat -c "%Y" $file)
1732 ctime1=$(stat -c "%Z" $file)
1734 [ $atime0 -eq $atime1 ] ||
1735 error "remount changed atime from $atime0 to $atime1"
1737 [ $mtime0 -eq $mtime1 ] ||
1738 error "remount changed mtime from $mtime0 to $mtime1"
1740 [ $ctime0 -eq $ctime1 ] ||
1741 error "remount changed ctime from $ctime0 to $ctime1"
1743 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1746 local file=$DIR/$tdir/$tfile
1752 # Test needs a running copytool.
1755 # Check that root can do HSM actions on a regular user's file.
1756 fid=$(create_small_file $file)
1757 sum0=$(md5sum $file)
1759 chown $RUNAS_ID:$RUNAS_GID $file ||
1760 error "cannot chown '$file' to '$RUNAS_ID'"
1762 chmod ugo-w $DIR/$tdir ||
1763 error "cannot chmod '$DIR/$tdir'"
1765 $LFS hsm_archive $file
1766 wait_request_state $fid ARCHIVE SUCCEED
1768 $LFS hsm_release $file
1769 check_hsm_flags $file "0x0000000d"
1771 $LFS hsm_restore $file
1772 wait_request_state $fid RESTORE SUCCEED
1774 # Check that ordinary user can get HSM state.
1775 $RUNAS $LFS hsm_state $file ||
1776 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1778 $LFS hsm_release $file
1779 check_hsm_flags $file "0x0000000d"
1781 # Check that ordinary user can accessed released file.
1782 sum1=$($RUNAS md5sum $file) ||
1783 error "user '$RUNAS_ID' cannot read '$file'"
1785 [ "$sum0" == "$sum1" ] ||
1786 error "md5sum mismatch for '$file'"
1788 run_test 24b "root can archive, release, and restore user files"
1791 local file=$DIR/$tdir/$tfile
1792 local action=archive
1797 # test needs a running copytool
1802 # Save the default masks and check that cleanup_24c will
1803 # restore the request masks correctly.
1804 user_save=$(get_hsm_param user_request_mask)
1805 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1806 group_save=$(get_hsm_param group_request_mask)
1807 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1808 other_save=$(get_hsm_param other_request_mask)
1809 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1811 [ "$user_save" == RESTORE ] ||
1812 error "user_request_mask is '$user_save' expected 'RESTORE'"
1813 [ "$group_save" == RESTORE ] ||
1814 error "group_request_mask is '$group_save' expected 'RESTORE'"
1815 [ "$other_save" == RESTORE ] ||
1816 error "other_request_mask is '$other_save' expected 'RESTORE'"
1819 create_small_file $file
1820 chown $RUNAS_ID:$GROUP $file ||
1821 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1823 $RUNAS $LFS hsm_$action $file &&
1824 error "$action by user should fail"
1826 set_hsm_param user_request_mask $action
1827 $RUNAS $LFS hsm_$action $file ||
1828 error "$action by user should succeed"
1831 create_small_file $file
1832 chown nobody:$RUNAS_GID $file ||
1833 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1835 $RUNAS $LFS hsm_$action $file &&
1836 error "$action by group should fail"
1838 set_hsm_param group_request_mask $action
1839 $RUNAS $LFS hsm_$action $file ||
1840 error "$action by group should succeed"
1843 create_small_file $file
1844 chown nobody:$GROUP $file ||
1845 error "cannot chown '$file' to 'nobody:$GROUP'"
1847 $RUNAS $LFS hsm_$action $file &&
1848 error "$action by other should fail"
1850 set_hsm_param other_request_mask $action
1851 $RUNAS $LFS hsm_$action $file ||
1852 error "$action by other should succeed"
1854 run_test 24c "check that user,group,other request masks work"
1857 local file1=$DIR/$tdir/$tfile
1858 local file2=$DIR2/$tdir/$tfile
1862 fid1=$(create_small_file $file1)
1865 $LFS getstripe $file1
1867 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1868 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1869 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1871 copytool setup -m "$MOUNT3"
1873 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1874 mount -o remount,ro $MOUNT2
1876 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1878 fid2=$(path2fid $file2)
1879 [ "$fid1" == "$fid2" ] ||
1880 error "FID mismatch '$fid1' != '$fid2'"
1882 $LFS hsm_archive $file2 &&
1883 error "archive should fail on read-only mount"
1884 check_hsm_flags $file1 "0x00000000"
1886 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1887 wait_request_state $fid1 ARCHIVE SUCCEED
1889 $LFS hsm_release $file1
1890 $LFS hsm_restore $file2
1891 wait_request_state $fid1 RESTORE SUCCEED
1893 $LFS hsm_release $file1 || error "cannot release '$file1'"
1894 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1896 $LFS hsm_release $file2 &&
1897 error "release should fail on read-only mount"
1901 run_test 24d "check that read-only mounts are respected"
1906 local f=$DIR/$tdir/$tfile
1909 fid=$(create_small_file $f) || error "cannot create $f"
1910 $LFS hsm_archive $f || error "cannot archive $f"
1911 wait_request_state $fid ARCHIVE SUCCEED
1912 $LFS hsm_release $f || error "cannot release $f"
1913 while ! $LFS hsm_state $f | grep released; do
1917 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1919 run_test 24e "tar succeeds on HSM released files" # LU-6213
1922 # test needs a running copytool
1925 mkdir -p $DIR/$tdir/d1
1926 local f=$DIR/$tdir/$tfile
1927 local fid=$(copy_file /etc/hosts $f)
1930 $LFS hsm_archive $f ||
1931 error "hsm_archive failed"
1932 wait_request_state $fid ARCHIVE SUCCEED
1933 $LFS hsm_release $f || error "cannot release $f"
1934 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1937 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1938 error "Can not recover the tar contents"
1940 echo "Sum0 = $sum0, sum1 = $sum1"
1941 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1943 run_test 24f "root can archive, release, and restore tar files"
1946 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1947 skip "need MDS version 2.11.56 or later"
1949 local file=$DIR/$tdir/$tfile
1952 echo "RUNAS = '$RUNAS'"
1957 chmod ugo+rwx $DIR/$tdir
1959 echo "Please listen carefully as our options have changed." | tee $file
1960 fid=$(path2fid $file)
1963 $LFS hsm_archive $file
1964 wait_request_state $fid ARCHIVE SUCCEED
1965 check_hsm_flags $file 0x00000009 # exists archived
1967 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
1968 check_hsm_flags $file 0x0000000b # exists dirty archived
1970 run_test 24g "write by non-owner still sets dirty" # LU-11369
1973 # test needs a running copytool
1977 copy2archive /etc/hosts $tdir/$tfile
1979 local f=$DIR/$tdir/$tfile
1981 copytool import $tdir/$tfile $f
1983 $LFS hsm_set --lost $f
1988 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1990 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1991 " (Operation not permitted)"
1994 # test needs a running copytool
1999 local f=$DIR/$tdir/$tfile
2000 local fid=$(copy_file /etc/passwd $f)
2002 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2003 wait_request_state $fid ARCHIVE SUCCEED
2006 $LFS hsm_set --lost $f
2010 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2012 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2013 " (Operation not permitted)"
2015 test_26A() { # was test_26
2016 # test needs a running copytool
2019 local f=$DIR/$tdir/$tfile
2020 local fid=$(create_empty_file "$f")
2022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2023 wait_request_state $fid ARCHIVE SUCCEED
2026 wait_request_state $fid REMOVE SUCCEED
2028 check_hsm_flags $f "0x00000000"
2030 run_test 26A "Remove the archive of a valid file"
2033 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2034 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2036 # test needs a running copytool
2040 local f=$DIR/$tdir/$tfile
2041 local fid=$(copy_file /etc/passwd $f)
2043 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2044 wait_request_state $fid ARCHIVE SUCCEED
2046 local f2=$DIR/$tdir/${tfile}_2
2047 local fid2=$(copy_file /etc/passwd $f2)
2049 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2050 wait_request_state $fid2 ARCHIVE SUCCEED
2052 local f3=$DIR/$tdir/${tfile}_3
2053 local fid3=$(copy_file /etc/passwd $f3)
2055 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2056 wait_request_state $fid3 ARCHIVE SUCCEED
2058 # set a long grace_delay vs short loop_period
2059 local orig_loop_period=$(get_hsm_param loop_period)
2060 local orig_grace_delay=$(get_hsm_param grace_delay)
2061 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2062 set_hsm_param loop_period 10
2063 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2064 set_hsm_param grace_delay 100
2068 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2069 set_hsm_param remove_archive_on_last_unlink 1
2071 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2076 wait_request_state $fid2 REMOVE SUCCEED
2078 assert_request_count $fid REMOVE 0 \
2079 "Unexpected archived data remove request for $f"
2080 assert_request_count $fid3 REMOVE 0 \
2081 "Unexpected archived data remove request for $f3"
2083 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2086 # test needs a running copytool
2090 local f=$DIR/$tdir/$tfile
2091 local fid=$(copy_file /etc/passwd $f)
2093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2094 wait_request_state $fid ARCHIVE SUCCEED
2096 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2097 set_hsm_param remove_archive_on_last_unlink 1
2100 cdt_check_state stopped
2104 wait_request_state $fid REMOVE WAITING
2108 # copytool must re-register
2110 wait_copytools || error "copytool failed to stop"
2113 wait_request_state $fid REMOVE SUCCEED
2115 run_test 26b "RAoLU policy when CDT off"
2118 # test needs a running copytool
2122 local f=$DIR/$tdir/$tfile
2123 local fid=$(copy_file /etc/passwd $f)
2125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2126 wait_request_state $fid ARCHIVE SUCCEED
2128 local f2=$DIR/$tdir/${tfile}_2
2129 local fid2=$(copy_file /etc/passwd $f2)
2131 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2132 wait_request_state $fid2 ARCHIVE SUCCEED
2134 # set a long grace_delay vs short loop_period
2135 local orig_loop_period=$(get_hsm_param loop_period)
2136 local orig_grace_delay=$(get_hsm_param grace_delay)
2137 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2138 set_hsm_param loop_period 10
2139 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2140 set_hsm_param grace_delay 100
2142 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2143 set_hsm_param remove_archive_on_last_unlink 1
2145 multiop_bg_pause $f O_c || error "open $f failed"
2151 wait_request_state $fid2 REMOVE SUCCEED
2152 assert_request_count $fid REMOVE 0 \
2153 "Unexpected archived data remove request for $f"
2155 kill -USR1 $pid || error "multiop early exit"
2156 # should reach autotest timeout if multiop fails to trap
2157 # signal, close file, and exit ...
2158 wait $pid || error "wait PID $PID failed"
2160 wait_request_state $fid REMOVE SUCCEED
2162 run_test 26c "RAoLU effective when file closed"
2165 # test needs a running copytool
2169 local f=$DIR/$tdir/$tfile
2170 local fid=$(create_small_file $f)
2172 $LFS hsm_archive $f || error "could not archive file"
2173 wait_request_state $fid ARCHIVE SUCCEED
2175 # set a long grace_delay vs short loop_period
2176 local orig_loop_period=$(get_hsm_param loop_period)
2177 local orig_grace_delay=$(get_hsm_param grace_delay)
2178 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2179 set_hsm_param loop_period 10
2180 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2181 set_hsm_param grace_delay 100
2183 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2184 set_hsm_param remove_archive_on_last_unlink 1
2186 multiop_bg_pause $f O_c || error "multiop failed"
2193 wait_request_state $fid REMOVE SUCCEED
2195 client_up || client_up || true
2197 kill -USR1 $MULTIPID
2198 wait $MULTIPID || error "multiop close failed"
2200 run_test 26d "RAoLU when Client eviction"
2203 # test needs a running copytool
2206 create_archive_file $tdir/$tfile
2207 local f=$DIR/$tdir/$tfile
2208 copytool import $tdir/$tfile $f
2209 local fid=$(path2fid $f)
2213 [[ $? != 0 ]] || error "Remove of a released file should fail"
2215 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2218 # test needs a running copytool
2221 local f=$DIR/$tdir/$tfile
2222 local fid=$(create_empty_file "$f")
2224 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2225 wait_request_state $fid ARCHIVE SUCCEED
2230 [[ $? != 0 ]] || error "Remove of a released file should fail"
2232 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2235 # test needs a running copytool
2238 local f=$DIR/$tdir/$tfile
2239 local fid=$(create_empty_file "$f")
2241 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2242 wait_request_state $fid ARCHIVE SUCCEED
2251 wait_request_state $fid REMOVE SUCCEED
2253 run_test 28 "Concurrent archive/file remove"
2256 # Tests --mntpath and --archive options
2259 copytool setup -m "$MOUNT" -a $archive_id
2261 # Bad archive number
2262 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2263 grep "Invalid argument" ||
2264 error "unexpected hsm_remove failure (1)"
2266 # mntpath is present but file is given
2267 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2268 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2269 error "unexpected hsm_remove failure (2)"
2271 run_test 29a "Tests --mntpath and --archive options"
2274 # test needs a running copytool
2277 local f=$DIR/$tdir/$tfile
2278 local fid=$(create_small_file $f)
2280 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2281 wait_request_state $fid ARCHIVE SUCCEED
2285 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2286 wait_request_state $fid REMOVE SUCCEED
2288 run_test 29b "Archive/delete/remove by FID from the archive."
2291 # test needs a running copytool
2294 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2295 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2296 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2298 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2299 wait_request_state $fid1 ARCHIVE SUCCEED
2300 wait_request_state $fid2 ARCHIVE SUCCEED
2301 wait_request_state $fid3 ARCHIVE SUCCEED
2303 rm -f $DIR/$tdir/$tfile-[1-3]
2305 echo $fid1 > $DIR/$tdir/list
2306 echo $fid2 >> $DIR/$tdir/list
2307 echo $fid3 >> $DIR/$tdir/list
2309 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2310 --filelist $DIR/$tdir/list
2311 wait_request_state $fid1 REMOVE SUCCEED
2312 wait_request_state $fid2 REMOVE SUCCEED
2313 wait_request_state $fid3 REMOVE SUCCEED
2315 run_test 29c "Archive/delete/remove by FID, using a file list."
2318 # test needs more than one CT
2319 needclients 3 || return 0
2325 # start all of the copytools
2326 for n in $(seq $AGTCOUNT); do
2327 copytool setup -f agt$n -a $n
2331 file=$DIR/$tdir/$tfile
2332 fid=$(create_small_file $file)
2334 $LFS hsm_archive $file
2335 wait_request_state $fid ARCHIVE SUCCEED
2336 check_hsm_flags $file "0x00000009"
2340 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2341 error "cannot hsm_remove '$fid'"
2343 # give time for CDT to handle remove request and create broadcasted
2346 # remove request has been broadcasted ?
2347 local cnt=$(get_request_count $fid REMOVE)
2348 # broadcasted requests + original
2349 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2350 error "remove not broadcasted to all CTs"
2352 # give time for CDT and CTs to handle broadcasted
2353 wait_for_loop_period
2355 # each agent serves one different archive_id, so broadcasted
2356 # hsm_remove request should only succeed once and fail at all others
2360 for n in $(seq $AGTCOUNT); do
2361 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2362 $HSM_PARAM.actions | awk \
2363 '/'$fid'.*action=REMOVE archive#='$n'/ \
2364 {print \\\$13}' | cut -f2 -d=")
2365 if [[ "$res" == "SUCCEED" ]]; then
2367 elif [[ "$res" == "FAILED" ]]; then
2372 [[ $scnt -eq 1 ]] ||
2373 error "one and only CT should have removed successfully"
2375 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2376 error "all but one CT should have failed to remove"
2378 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2379 "request to be sent once for each registered archive_id"
2382 # restore at exec cannot work on agent node (because of Linux kernel
2383 # protection of executables)
2384 needclients 2 || return 0
2386 # test needs a running copytool
2390 copy2archive /bin/true $tdir/$tfile
2392 local f=$DIR/$tdir/true
2393 copytool import $tdir/$tfile $f
2395 local fid=$(path2fid $f)
2397 stack_trap "cdt_clear_no_retry" EXIT
2398 # set no retry action mode
2405 [[ $st == 0 ]] || error "Failed to exec a released file"
2407 run_test 30a "Restore at exec (import case)"
2410 # restore at exec cannot work on agent node (because of Linux kernel
2411 # protection of executables)
2412 needclients 2 || return 0
2414 # test needs a running copytool
2418 local f=$DIR/$tdir/true
2419 local fid=$(copy_file /bin/true $f)
2421 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2422 wait_request_state $fid ARCHIVE SUCCEED
2426 stack_trap cdt_clear_no_retry EXIT
2427 # set no retry action mode
2435 [[ $st == 0 ]] || error "Failed to exec a released file"
2437 run_test 30b "Restore at exec (release case)"
2440 needclients 2 || return 0
2442 # test needs a running copytool
2446 local f=$DIR/$tdir/SLEEP
2447 local slp_sum1=$(md5sum /bin/sleep)
2448 local fid=$(copy_file /bin/sleep $f)
2450 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2451 wait_request_state $fid ARCHIVE SUCCEED
2453 check_hsm_flags $f "0x0000000d"
2455 stack_trap cdt_clear_no_retry EXIT
2456 # set no retry action mode
2459 do_node $CLIENT2 "$f 10" &
2463 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2465 [[ $? == 0 ]] || error "Execution failed during run"
2467 if [[ $? != 0 ]]; then
2468 local slp_sum2=$(md5sum /bin/sleep)
2469 # in case sleep file is modified during the test
2470 [[ $slp_sum1 == $slp_sum2 ]] &&
2471 error "Binary overwritten during exec"
2474 check_hsm_flags $f "0x00000009"
2476 run_test 30c "Update during exec of released file must fail"
2478 restore_and_check_size() {
2481 local s=$(stat -c "%s" $f)
2483 local st=$(get_hsm_flags $f)
2487 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2489 n=$(stat -c "%s" $f)
2490 # we echo in both cases to show stat is not hang
2491 if [[ $n != $s ]]; then
2492 echo "size seen is $n != $s"
2495 echo "size seen is right: $n == $s"
2499 st=$(get_hsm_flags $f)
2501 if [[ "$st" = "0x00000009" ]]; then
2504 echo " restore is too long"
2505 wait_request_state $fid RESTORE SUCCEED
2511 # test needs a running copytool
2514 create_archive_file $tdir/$tfile
2515 local f=$DIR/$tdir/$tfile
2516 copytool import $tdir/$tfile $f
2517 local fid=$($LFS path2fid $f)
2520 restore_and_check_size $f $fid
2523 [[ $err -eq 0 ]] || error "File size changed during restore"
2525 run_test 31a "Import a large file and check size during restore"
2529 # test needs a running copytool
2532 local f=$DIR/$tdir/$tfile
2533 local fid=$(create_file "$f" 1MB 39)
2535 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2536 wait_request_state $fid ARCHIVE SUCCEED
2539 restore_and_check_size $f $fid
2542 [[ $err -eq 0 ]] || error "File size changed during restore"
2544 run_test 31b "Restore a large unaligned file and check size during restore"
2547 # test needs a running copytool
2550 local f=$DIR/$tdir/$tfile
2551 local fid=$(create_file "$f" 1M 39)
2553 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2554 wait_request_state $fid ARCHIVE SUCCEED
2557 restore_and_check_size $f $fid
2560 [[ $err -eq 0 ]] || error "File size changed during restore"
2562 run_test 31c "Restore a large aligned file and check size during restore"
2565 local f=$DIR/$tdir/$tfile
2566 local fid=$(create_empty_file "$f")
2570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2571 wait_request_state $fid ARCHIVE SUCCEED
2574 # Prevent restore from completing
2578 md5sum $f >/dev/null &
2581 wait_request_state $fid RESTORE STARTED
2586 # Check restore trigger process was killed
2588 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2590 run_test 33 "Kill a restore waiting process"
2593 # test needs a running copytool
2596 local f=$DIR/$tdir/$tfile
2597 local fid=$(create_empty_file "$f")
2599 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2600 wait_request_state $fid ARCHIVE SUCCEED
2603 # Prevent restore from completing
2606 md5sum $f >/dev/null &
2609 wait_request_state $fid RESTORE STARTED
2611 # rm must not block during restore
2612 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2615 wait_request_state $fid RESTORE SUCCEED
2617 # Check md5sum pgm finished
2618 kill -0 $pid && error "Restore initiatior still running"
2619 wait $pid || error "Restore initiator failed with $?"
2621 # Check the file was actually deleted
2622 [ ! -f "$f" ] || error "$f was not deleted"
2624 run_test 34 "Remove file during restore"
2627 # test needs a running copytool
2630 local f=$DIR/$tdir/$tfile
2631 local f1=$DIR/$tdir/$tfile-1
2632 local fid=$(create_empty_file "$f")
2633 local fid1=$(copy_file /etc/passwd $f1)
2635 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2636 wait_request_state $fid ARCHIVE SUCCEED
2639 # Prevent restore from completing
2642 md5sum $f >/dev/null &
2645 wait_request_state $fid RESTORE STARTED
2647 # mv must not block during restore
2648 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2651 wait_request_state $fid RESTORE SUCCEED
2653 # Check md5sum pgm finished
2654 kill -0 $pid && error "Restore initiatior still running"
2655 wait $pid || error "Restore initiator failed with $?"
2657 local fid2=$(path2fid $f)
2658 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2660 run_test 35 "Overwrite file during restore"
2663 # test needs a running copytool
2666 local f=$DIR/$tdir/$tfile
2667 local fid=$(create_empty_file "$f")
2669 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2670 wait_request_state $fid ARCHIVE SUCCEED
2673 # Prevent restore from completing
2676 md5sum $f >/dev/null &
2679 wait_request_state $fid RESTORE STARTED
2681 # mv must not block during restore
2682 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2683 error "mv '$f' '$f.new' failed with rc=$?"
2686 wait_request_state $fid RESTORE SUCCEED
2688 # Check md5sum pgm finished
2689 kill -0 $pid && error "Restore initiator is still running"
2690 wait $pid || error "Restore initiator failed with $?"
2692 run_test 36 "Move file during restore"
2695 # LU-5683: check that an archived dirty file can be rearchived.
2698 local f=$DIR/$tdir/$tfile
2701 fid=$(create_small_file $f) || error "cannot create small file"
2703 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2704 wait_request_state $fid ARCHIVE SUCCEED
2705 $LFS hsm_release $f || error "cannot release $f"
2707 # Allow previous archive request to expire from the actions log.
2708 wait_for_grace_delay
2711 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2714 wait_request_state $fid ARCHIVE SUCCEED
2716 run_test 37 "re-archive a dirty file"
2723 for n in $(seq 1 $count); do
2724 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2726 echo "$count archive requests submitted"
2730 local stream_count=4
2731 local file_count=100
2733 local f=$DIR/$tdir/$tfile
2737 local max_requests=$(get_hsm_param max_requests)
2739 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2740 # Increase the number of HSM request that can be performed in
2741 # parallel. With the coordinator running once per second, this
2742 # also limits the number of requests per seconds that can be
2743 # performed, so we pick a decent number. But we also need to keep
2744 # that number low because the copytool has no rate limit and will
2745 # fail some requests if if gets too many at once.
2746 set_hsm_param max_requests 300
2748 for i in $(seq 1 $file_count); do
2749 for p in $(seq 1 $stream_count); do
2750 fid=$(copy_file /etc/hosts $f.$p.$i)
2756 # to be sure wait_all_done will not be mislead by previous tests
2758 wait_for_grace_delay
2760 # start archive streams in background (archive files in parallel)
2761 for p in $(seq 1 $stream_count); do
2762 multi_archive $f.$p $file_count &
2765 echo -n "Wait for all requests being enqueued..."
2770 run_test 40 "Parallel archive requests"
2773 # test needs a running copytool
2777 local f=$DIR/$tdir/$tfile
2778 local fid=$(create_small_file $f)
2780 $LFS hsm_archive $f || error "could not archive file"
2781 wait_request_state $fid ARCHIVE SUCCEED
2782 check_hsm_flags $f "0x00000009"
2784 multiop_bg_pause $f O_c || error "multiop failed"
2788 client_up || client_up || true
2790 kill -USR1 $MULTIPID
2791 wait $MULTIPID || error "multiop close failed"
2793 check_hsm_flags $f "0x0000000b"
2795 run_test 52 "Opened for write file on an evicted client should be set dirty"
2798 # test needs a running copytool
2802 local f=$DIR/$tdir/$tfile
2803 local fid=$(create_small_file $f)
2805 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2806 error "could not archive file"
2807 wait_request_state $fid ARCHIVE SUCCEED
2808 check_hsm_flags $f "0x00000009"
2810 multiop_bg_pause $f o_c || error "multiop failed"
2814 client_up || client_up || true
2816 kill -USR1 $MULTIPID
2817 wait $MULTIPID || error "multiop close failed"
2819 check_hsm_flags $f "0x00000009"
2821 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2824 local f=$DIR/$tdir/$tfile
2825 local fid=$(create_file "$f" 1MB 39)
2829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2830 error "could not archive file"
2831 wait_request_state $fid ARCHIVE STARTED
2833 check_hsm_flags $f "0x00000001"
2835 stack_trap "cdt_clear_no_retry" EXIT
2836 # Avoid coordinator resending this request as soon it has failed.
2841 wait_request_state $fid ARCHIVE FAILED
2843 check_hsm_flags $f "0x00000003"
2845 run_test 54 "Write during an archive cancels it"
2848 local f=$DIR/$tdir/$tfile
2849 local fid=$(create_file "$f" 1MB 39)
2853 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2854 error "could not archive file"
2855 wait_request_state $fid ARCHIVE STARTED
2857 check_hsm_flags $f "0x00000001"
2859 stack_trap "cdt_clear_no_retry" EXIT
2860 # Avoid coordinator resending this request as soon it has failed.
2863 $TRUNCATE $f 1024 || error "truncate failed"
2865 wait_request_state $fid ARCHIVE FAILED
2867 check_hsm_flags $f "0x00000003"
2869 run_test 55 "Truncate during an archive cancels it"
2872 local f=$DIR/$tdir/$tfile
2873 local fid=$(create_file "$f" 1MB 39)
2877 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2878 error "could not archive file"
2879 wait_request_state $fid ARCHIVE STARTED
2881 check_hsm_flags $f "0x00000001"
2883 # Change metadata and sync to be sure we are not changing only
2888 wait_request_state $fid ARCHIVE SUCCEED
2890 check_hsm_flags $f "0x00000009"
2892 run_test 56 "Setattr during an archive is ok"
2895 # Need one client for I/O, one for request
2896 needclients 2 || return 0
2898 # test needs a running copytool
2902 local f=$DIR/$tdir/test_archive_remote
2903 # Create a file on a remote node
2904 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2905 "count=2 conv=fsync"
2908 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2909 error "hsm_archive failed"
2910 local fid=$(path2fid $f)
2911 wait_request_state $fid ARCHIVE SUCCEED
2913 # Release and implicit restore it
2914 do_node $CLIENT2 "$LFS hsm_release $f" ||
2915 error "hsm_release failed"
2916 do_node $CLIENT2 "md5sum $f" ||
2917 error "hsm_restore failed"
2919 wait_request_state $fid RESTORE SUCCEED
2921 run_test 57 "Archive a file with dirty cache on another node"
2923 truncate_released_file() {
2927 local sz=$(stat -c %s $src_file)
2928 local f=$DIR/$tdir/$tfile
2929 local fid=$(copy_file $1 $f)
2933 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2934 error "could not archive file"
2935 wait_request_state $fid ARCHIVE SUCCEED
2937 $LFS hsm_release $f || error "could not release file"
2939 $TRUNCATE $f $trunc_to || error "truncate failed"
2942 local sz1=$(stat -c %s $f)
2943 [[ $sz1 == $trunc_to ]] ||
2944 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2947 check_hsm_flags $f "0x0000000b"
2949 local state=$(get_request_state $fid RESTORE)
2950 [[ "$state" == "SUCCEED" ]] ||
2951 error "truncate $sz does not trig restore, state = $state"
2953 $TRUNCATE $ref $trunc_to
2954 cmp $ref $f || error "file data wrong after truncate"
2960 # test needs a running copytool
2965 local sz=$(stat -c %s /etc/passwd)
2967 echo "truncate up from $sz to $((sz*2))"
2968 truncate_released_file /etc/passwd $((sz*2))
2970 echo "truncate down from $sz to $((sz/2))"
2971 truncate_released_file /etc/passwd $((sz/2))
2973 echo "truncate to 0"
2974 truncate_released_file /etc/passwd 0
2976 run_test 58 "Truncate a released file will trigger restore"
2980 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
2981 skip "Need MDS version at least 2.7.63"
2984 $MCREATE $DIR/$tfile || error "mcreate failed"
2985 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
2986 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
2987 fid=$(path2fid $DIR/$tfile)
2988 wait_request_state $fid ARCHIVE SUCCEED
2989 $LFS hsm_release $DIR/$tfile || error "release failed"
2991 run_test 59 "Release stripeless file with non-zero size"
2994 # This test validates the fix for LU-4512. Ensure that the -u
2995 # option changes the progress reporting interval from the
2996 # default (30 seconds) to the user-specified interval.
2997 local f=$DIR/$tdir/$tfile
2998 local fid=$(create_file "$f" 1M 10)
3001 local progress_timeout=$((interval * 4))
3002 copytool setup -b 1 --update-interval $interval
3005 local mdt=${MDT_PREFIX}${mdtidx}
3006 local mds=mds$((mdtidx + 1))
3008 # Wait for copytool to register
3009 wait_update_facet $mds \
3010 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3011 uuid 100 || error "coyptool failed to register with $mdt"
3013 local start_at=$(date +%s)
3014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3015 error "could not archive file"
3017 local agent=$(facet_active_host $SINGLEAGT)
3018 local logfile=$(copytool_logfile $SINGLEAGT)
3020 wait_update $agent \
3021 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3022 error "copytool failed to start"
3024 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3025 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3031 echo -n "Expecting a progress update within $progress_timeout seconds... "
3033 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3034 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3035 echo "$RESULT bytes copied in $WAIT seconds."
3037 elif [ $WAIT -ge $progress_timeout ]; then
3038 error "Timed out waiting for progress update!"
3041 WAIT=$((WAIT + sleep))
3045 local finish_at=$(date +%s)
3046 local elapsed=$((finish_at - start_at))
3048 # Ensure that the progress update occurred within the expected window.
3049 if [ $elapsed -lt $((interval - 1)) ]; then
3050 error "Expected progress update after at least $interval seconds"
3053 echo "Wait for on going archive hsm action to complete"
3054 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3055 echo "File archiving not completed even after 10 secs"
3057 run_test 60 "Changing progress update interval from default"
3060 # test needs a running copytool
3064 local f=$DIR/$tdir/$tfile
3065 local fid=$(copy_file /etc/passwd $f)
3067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3070 wait_request_state $fid ARCHIVE FAILED
3072 run_test 61 "Waiting archive of a removed file should fail"
3075 # test needs a new running copytool
3076 stack_trap copytool_monitor_cleanup EXIT
3077 copytool_monitor_setup
3078 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3080 # Wait for the copytool to register.
3081 wait_update --verbose $(facet_active_host mds1) \
3082 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3084 error "copytool failed to register with MDT0000"
3087 wait_copytools || error "Copytools failed to stop"
3089 local REGISTER_EVENT
3090 local UNREGISTER_EVENT
3091 while read event; do
3092 local parsed=$(parse_json_event "$event")
3093 if [ -z "$parsed" ]; then
3094 error "Copytool sent malformed event: $event"
3098 if [ $event_type == "REGISTER" ]; then
3099 REGISTER_EVENT=$event
3100 elif [ $event_type == "UNREGISTER" ]; then
3101 UNREGISTER_EVENT=$event
3103 done < <(echo $"$(get_copytool_event_log)")
3105 if [ -z "$REGISTER_EVENT" ]; then
3106 error "Copytool failed to send register event to FIFO"
3109 if [ -z "$UNREGISTER_EVENT" ]; then
3110 error "Copytool failed to send unregister event to FIFO"
3113 echo "Register/Unregister events look OK."
3115 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3118 # Bump progress interval for livelier events.
3121 # test needs a new running copytool
3122 stack_trap copytool_monitor_cleanup EXIT
3123 copytool_monitor_setup
3124 copytool setup --update-interval $interval --event-fifo \
3125 "$HSMTOOL_MONITOR_DIR/fifo"
3127 stack_trap "cdt_clear_no_retry" EXIT
3128 # Just start and stop the copytool to generate events.
3131 local f=$DIR/$tdir/$tfile
3132 local fid=$(create_small_file "$f")
3134 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3135 error "could not archive file"
3136 wait_request_state $fid ARCHIVE SUCCEED
3138 local expected_fields="event_time data_fid source_fid"
3139 expected_fields+=" total_bytes current_bytes"
3142 [ARCHIVE_START]=false
3143 [ARCHIVE_FINISH]=false
3144 [ARCHIVE_RUNNING]=false
3146 while read event; do
3147 # Make sure we're not getting anything from previous events.
3148 for field in $expected_fields; do
3152 local parsed=$(parse_json_event "$event")
3153 if [ -z "$parsed" ]; then
3154 error "Copytool sent malformed event: $event"
3158 events["$event_type"]=true
3160 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3162 # Do some simple checking of the progress update events.
3163 for expected_field in $expected_fields; do
3164 if [ -z ${!expected_field+x} ]; then
3165 error "Missing $expected_field field in event"
3169 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3171 # These should be identical throughout an archive operation
3172 [ $source_fid == $data_fid ] ||
3173 error "Expected source_fid to equal data_fid"
3174 done < <(echo $"$(get_copytool_event_log)")
3176 # Check we received every type of events we were expecting
3177 for event in "${!events[@]}"; do
3178 ${events["$event"]} ||
3179 error "Copytool failed to send '$event' event to FIFO"
3182 echo "Archive events look OK."
3184 run_test 71 "Copytool logs JSON archive events to FIFO"
3187 # Bump progress interval for livelier events.
3190 # test needs a new running copytool
3191 stack_trap copytool_monitor_cleanup EXIT
3192 copytool_monitor_setup
3193 copytool setup --update-interval $interval --event-fifo \
3194 "$HSMTOOL_MONITOR_DIR/fifo"
3195 local test_file=$HSMTOOL_MONITOR_DIR/file
3197 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3199 do_facet $SINGLEAGT "$cmd" ||
3200 error "cannot create $test_file on $SINGLEAGT"
3201 copy2archive $test_file $tdir/$tfile
3204 local f=$DIR/$tdir/$tfile
3205 copytool import $tdir/$tfile $f
3206 f=$DIR2/$tdir/$tfile
3207 echo "Verifying released state: "
3208 check_hsm_flags $f "0x0000000d"
3210 local fid=$(path2fid $f)
3212 wait_request_state $fid RESTORE SUCCEED
3214 local expected_fields="event_time data_fid source_fid"
3215 expected_fields+=" total_bytes current_bytes"
3219 while read event; do
3220 # Make sure we're not getting anything from previous events.
3221 for field in $expected_fields; do
3225 local parsed=$(parse_json_event "$event")
3226 if [ -z "$parsed" ]; then
3227 error "Copytool sent malformed event: $event"
3231 if [ $event_type == "RESTORE_START" ]; then
3233 if [ $source_fid != $data_fid ]; then
3234 error "source_fid should == data_fid at start"
3237 elif [ $event_type == "RESTORE_FINISH" ]; then
3239 if [ $source_fid != $data_fid ]; then
3240 error "source_fid should == data_fid at finish"
3243 elif [ $event_type != "RESTORE_RUNNING" ]; then
3247 # Do some simple checking of the progress update events.
3248 for expected_field in $expected_fields; do
3249 if [ -z ${!expected_field+x} ]; then
3250 error "Missing $expected_field field in event"
3254 if [ $total_bytes -eq 0 ]; then
3255 error "Expected total_bytes to be > 0"
3258 # When a restore starts out, the data fid is the same as the
3259 # source fid. After the restore has gotten going, we learn
3260 # the new data fid. Once the restore has finished, the source
3261 # fid is set to the new data fid.
3263 # We test this because some monitoring software may depend on
3264 # this behavior. If it changes, then the consumers of these
3265 # events may need to be modified.
3266 if [ $source_fid == $data_fid ]; then
3267 error "source_fid should != data_fid during restore"
3269 done < <(echo $"$(get_copytool_event_log)")
3271 if [ -z "$START_EVENT" ]; then
3272 error "Copytool failed to send restore start event to FIFO"
3275 if [ -z "$FINISH_EVENT" ]; then
3276 error "Copytool failed to send restore finish event to FIFO"
3279 echo "Restore events look OK."
3281 run_test 72 "Copytool logs JSON restore events to FIFO"
3284 file_count=51 # Max number of files constrained by LNET message size
3285 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3286 local f=$DIR/$tdir/$tfile
3287 local FILELIST=/tmp/filelist.txt
3291 for i in $(seq 1 $file_count); do
3292 fid=$(copy_file /etc/hosts $f.$i)
3293 echo $f.$i >> $FILELIST
3297 # to be sure wait_all_done will not be mislead by previous tests
3299 wait_for_grace_delay
3300 $LFS hsm_archive --filelist $FILELIST ||
3301 error "cannot archive a file list"
3303 $LFS hsm_release --filelist $FILELIST ||
3304 error "cannot release a file list"
3305 $LFS hsm_restore --filelist $FILELIST ||
3306 error "cannot restore a file list"
3309 run_test 90 "Archive/restore a file list"
3311 double_verify_reset_hsm_param() {
3313 echo "Testing $HSM_PARAM.$p"
3314 local val=$(get_hsm_param $p)
3316 local val2=$(($val * 2))
3317 set_hsm_param $p $val2
3318 val=$(get_hsm_param $p)
3319 [[ $val == $val2 ]] ||
3320 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3321 echo "Set $p to 0 must failed"
3325 set_hsm_param $p $save
3327 if [[ $rc == 0 ]]; then
3328 error "we must not be able to set $HSM_PARAM.$p to 0"
3333 double_verify_reset_hsm_param loop_period
3334 double_verify_reset_hsm_param grace_delay
3335 double_verify_reset_hsm_param active_request_timeout
3336 double_verify_reset_hsm_param max_requests
3337 double_verify_reset_hsm_param default_archive_id
3339 run_test 100 "Set coordinator /proc tunables"
3346 run_test 102 "Verify coordinator control"
3349 # test needs a running copytool
3356 for i in $(seq 1 20); do
3357 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3363 echo "Current requests"
3364 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3365 $HSM_PARAM.actions |\
3366 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3368 [[ -z "$res" ]] || error "Some request have not been canceled"
3370 run_test 103 "Purge all requests"
3375 local f=$DIR/$tdir/$tfile
3376 local fid=$(create_empty_file "$f")
3378 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3379 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3380 $HSM_PARAM.actions |\
3381 grep $fid | cut -f16 -d=")
3383 [[ "$data1" == "$DATAHEX" ]] ||
3384 error "Data field in records is ($data1) and not ($DATAHEX)"
3388 run_test 104 "Copy tool data field"
3391 local max_requests=$(get_hsm_param max_requests)
3395 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3396 set_hsm_param max_requests 300
3399 for i in $(seq -w 1 10); do
3400 cp /etc/passwd $DIR/$tdir/$i
3401 $LFS hsm_archive $DIR/$tdir/$i
3403 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3404 $HSM_PARAM.actions |\
3405 grep WAITING | wc -l")
3409 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3410 $HSM_PARAM.actions |\
3411 grep WAITING | wc -l")
3414 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3415 error "Requests count after shutdown $reqcnt2 != "\
3416 "before shutdown $reqcnt1"
3418 run_test 105 "Restart of coordinator"
3421 # test needs a running copytool
3424 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3426 check_agent_registered $uuid
3428 search_copytools || error "No copytool found"
3431 wait_copytools || error "Copytool failed to stop"
3433 check_agent_unregistered $uuid
3436 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3437 check_agent_registered $uuid
3439 run_test 106 "Copytool register/unregister"
3442 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3444 # test needs a running copytool
3446 # create and archive file
3448 local f1=$DIR/$tdir/$tfile
3449 local fid=$(copy_file /etc/passwd $f1)
3450 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3451 wait_request_state $fid ARCHIVE SUCCEED
3452 # shutdown and restart MDS
3454 # check the copytool still gets messages from MDT
3455 local f2=$DIR/$tdir/2
3456 local fid=$(copy_file /etc/passwd $f2)
3457 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3458 # main check of this sanity: this request MUST succeed
3459 wait_request_state $fid ARCHIVE SUCCEED