3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
12 LUSTRE=${LUSTRE:-$(dirname $0)/..}
13 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT "
19 # bug number for skipped tests: LU-9795
20 ALWAYS_EXCEPT+=" 402b "
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 # Skip tests for PPC that fail frequently
25 if [[ $(uname -m) = ppc64 ]]; then
26 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
27 ALWAYS_EXCEPT+=" 1a 1b 1d 1e 12c 12f "
28 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
29 ALWAYS_EXCEPT+=" 12g 12h 12m 12n 12o 12p "
30 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
31 ALWAYS_EXCEPT+=" 12q 21 22 23 24a 24b "
32 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
33 ALWAYS_EXCEPT+=" 24d 24e 24f 25b 30c 37 "
34 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
35 ALWAYS_EXCEPT+=" 57 58 90 110b 111b 113 "
36 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
37 ALWAYS_EXCEPT+=" 222b 222d 228 260a 260b 260c "
38 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
39 ALWAYS_EXCEPT+=" 220A 220a 221 222a 222c 223a "
40 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
41 ALWAYS_EXCEPT+=" 223b 224A 224a 226 227 600"
42 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
43 ALWAYS_EXCEPT+=" 601 602 603 604 605 "
48 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
50 OPENFILE=${OPENFILE:-openfile}
51 MOUNT_2=${MOUNT_2:-"yes"}
54 # script only handles up to 10 MDTs (because of MDT_PREFIX)
55 [ $MDSCOUNT -gt 9 ] &&
56 error "script cannot handle more than 9 MDTs, please fix"
58 check_and_setup_lustre
60 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
61 skip_env "Need MDS version at least 2.4.53"
64 # $RUNAS_ID may get set incorrectly somewhere else
65 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
66 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
68 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
69 if getent group nobody; then
71 elif getent group nogroup; then
74 error "No generic nobody group"
77 # if there is no CLIENT1 defined, some tests can be ran on localhost
78 CLIENT1=${CLIENT1:-$HOSTNAME}
79 # if CLIENT2 doesn't exist then use CLIENT1 instead
80 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
82 # Exception is the test which need two separate nodes
83 CLIENT2=${CLIENT2:-$CLIENT1}
86 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
87 do_nodesv $hosts "pgrep --pidfile=$HSMTOOL_PID_FILE hsmtool"
91 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
92 local wait_timeout=200
93 local wait_start=$SECONDS
94 local wait_end=$((wait_start + wait_timeout))
97 while ((SECONDS < wait_end)); do
98 if ! search_copytools $hosts; then
99 echo "copytools stopped in $((SECONDS - wait_start))s"
103 echo "copytools still running on $hosts"
105 [ $sleep_time -lt 5 ] && sleep_time=$((sleep_time + 1))
108 # try to dump Copytool's stack
109 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
110 "echo t >/proc/sysrq-trigger"
112 echo "copytools failed to stop in ${wait_timeout}s"
117 copytool_monitor_setup() {
118 local facet=${1:-$SINGLEAGT}
119 local agent=$(facet_active_host $facet)
121 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
122 local test_dir=$(do_node $agent "$cmd") ||
123 error "Failed to create tempdir on $agent"
124 export HSMTOOL_MONITOR_DIR=$test_dir
126 # Create the fifo and a monitor (cat dies when copytool dies)
127 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
128 error "failed to create copytool fifo on $agent"
129 cmd="cat $test_dir/fifo > $test_dir/events &"
130 cmd+=" echo \\\$! > $test_dir/monitor_pid"
132 # This background subshell nonsense is required when pdsh/ssh decides
133 # to wait for the cat process to exit on the remote client
134 (do_node $agent "$cmd") &
135 export HSMTOOL_MONITOR_PDSH=$!
137 # Slightly racy, but just making a best-effort to catch obvious
140 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
142 error "Failed to start copytool monitor on $agent"
150 case "$HSMTOOL_ARCHIVE_FORMAT" in
152 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
155 printf "%s" "$(hsm_root)/*/$fid"
160 get_copytool_event_log() {
161 local facet=${1:-$SINGLEAGT}
162 local agent=$(facet_active_host $facet)
164 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
165 error "Can't get event log: No monitor directory!"
167 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
168 error "Could not collect event log from $agent"
172 local agents=${1:-$(facet_active_host $SINGLEAGT)}
174 stack_trap "pkill_copytools $agents CONT || true" EXIT
175 pkill_copytools $agents STOP || return 0
176 echo "Copytool is suspended on $agents"
179 copytool_remove_backend() {
181 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
182 echo "Remove from backend: $fid = $be"
183 do_facet $SINGLEAGT rm -f $be
186 file_creation_failure() {
193 df $MOUNT $MOUNT2 >&2
194 error "Not enough space to create $file with $cmd"
197 error "cannot create $file with $cmd, status=$err"
202 # Creates a file using dd
208 local source=${5:-/dev/zero}
212 if [ -n "$conv" ]; then
216 # Create the directory in case it does not exist
217 mkdir -p "$(dirname "$file")"
218 # Delete the file in case it already exist
221 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
222 path2fid "$file" || error "cannot get FID of '$file'"
225 echo "cannot create file '$file'" >&2;
226 # Let the caller decide what to do on error
231 create_empty_file() {
232 create_file "${1/$DIR/$DIR2}" 1M 0 ||
233 file_creation_failure dd "${1/$DIR/$DIR2}" $?
236 create_small_file() {
237 local source_file=/dev/urandom
240 local conv=${2:-fsync}
242 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
243 file_creation_failure dd "${1/$DIR/$DIR2}" $?
246 create_small_sync_file() {
247 create_small_file "$1" sync
250 create_archive_file() {
251 local file="$(hsm_root)/$1"
253 local source=/dev/urandom
255 # Create the counterpart directory of the archive
256 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
257 error "cannot create archive directory '$(dirname "$file")'"
259 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
260 error "cannot create archive file '$file'"
264 local hsm_root="$(hsm_root)"
265 local file="$hsm_root/$2"
267 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
268 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
269 error "mkdir '$(dirname "$file")' failed"
270 do_facet $SINGLEAGT cp -p "$1" "$file" ||
271 error "cannot copy '$1' to '$file'"
276 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
283 mdts_set_param "" hsm_control "$cmd"
284 mdts_check_param hsm_control "$target" 10
289 mdts_set_param "" hsm.policy "+NRA"
290 CDT_POLICY_HAD_CHANGED=true
293 cdt_clear_no_retry() {
294 mdts_set_param "" hsm.policy "-NRA"
295 CDT_POLICY_HAD_CHANGED=true
298 cdt_set_non_blocking_restore() {
299 mdts_set_param "" hsm.policy "+NBR"
300 CDT_POLICY_HAD_CHANGED=true
303 cdt_clear_non_blocking_restore() {
304 mdts_set_param "" hsm.policy "-NBR"
305 CDT_POLICY_HAD_CHANGED=true
308 cdt_clear_mount_state() {
309 mdts_set_param "-P -d" hsm_control ""
313 set_test_state disabled disabled
317 set_test_state enabled enabled
321 set_test_state shutdown stopped
325 set_test_state purge enabled
331 cdt_set_sanity_policy
335 get_hsm_archive_id() {
338 st=$($LFS hsm_state $f)
339 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
341 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
345 check_hsm_flags_user() {
349 local st=$(get_hsm_flags $f user)
350 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
362 if [[ "$3" != 1 ]]; then
366 cp $1 $f || file_creation_failure cp $f $?
368 path2fid $f || error "cannot get fid on $f"
371 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
373 # Note that this might lead to surprising behaviours such as deleting an
374 # important file for the currently running test
375 delete_large_files() {
376 printf "Deleting large files...\n" >&2
377 find $MOUNT -size +10M -delete
378 wait_delete_completed
381 get_request_state() {
385 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
386 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
389 get_request_count() {
393 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
394 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
397 # Ensure the number of HSM request for a given FID is correct
398 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
399 assert_request_count() {
400 local request_count=$(get_request_count $1 $2)
401 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
403 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
410 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
411 [[ -n $fid ]] && cmd+=" | grep '$fid'"
412 cmd+=" | egrep 'WAITING|STARTED'"
414 wait_update_facet --verbose mds1 "$cmd" "" $timeout ||
415 error "requests did not complete"
418 wait_for_grace_delay() {
419 local val=$(get_hsm_param grace_delay)
423 wait_for_loop_period() {
424 local val=$(get_hsm_param loop_period)
431 # python2.6 in EL6 includes an internal json module
432 local json_parser='import json; import fileinput;'
433 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
434 json_parser+='json.loads([line for line in '
435 json_parser+='fileinput.input()][0]).items()])'
437 echo $raw_event | python -c "$json_parser"
440 get_agent_by_uuid_mdt() {
443 local mds=mds$(($mdtidx + 1))
444 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
448 check_agent_registered_by_mdt() {
451 local mds=mds$(($mdtidx + 1))
452 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
453 if [[ ! -z "$agent" ]]; then
454 echo "found agent $agent on $mds"
456 error "uuid $uuid not found in agent list on $mds"
460 check_agent_unregistered_by_mdt() {
463 local mds=mds$(($mdtidx + 1))
464 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
465 if [[ -z "$agent" ]]; then
466 echo "uuid not found in agent list on $mds"
468 error "uuid found in agent list on $mds: $agent"
472 check_agent_registered() {
475 for mdsno in $(seq 1 $MDSCOUNT); do
476 check_agent_registered_by_mdt $uuid $((mdsno - 1))
480 check_agent_unregistered() {
483 for mdsno in $(seq 1 $MDSCOUNT); do
484 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
489 local agent=${1:-$(facet_active_host $SINGLEAGT)}
491 # Lustre mount-point is mandatory and last parameter on
493 local mntpnt=$(do_rpc_nodes $agent \
494 pgrep --pidfile=$HSMTOOL_PID_FILE --list-full hsmtool |
496 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
498 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
504 # populate MDT device array
507 # cleanup from previous bad setup
510 # for recovery tests, coordinator needs to be started at mount
512 # the lustre conf must be without hsm on (like for sanity.sh)
513 echo "Set HSM on and start"
514 cdt_set_mount_state enabled
515 cdt_check_state enabled
517 echo "Set sanity-hsm HSM policy"
518 cdt_set_sanity_policy
520 # finished requests are quickly removed from list
521 set_hsm_param grace_delay 10
523 CLIENT_NIDS=( $($LCTL list_nids all) )
525 test_1A() { # was test_1
529 local f=$DIR/$tdir/$tfile
533 check_hsm_flags_user $f "0x00000000"
535 $RUNAS $LFS hsm_set --norelease $f ||
536 error "user could not change hsm flags"
537 check_hsm_flags_user $f "0x00000010"
539 $RUNAS $LFS hsm_clear --norelease $f ||
540 error "user could not clear hsm flags"
541 check_hsm_flags_user $f "0x00000000"
543 # User could not change those flags...
544 $RUNAS $LFS hsm_set --exists $f &&
545 error "user should not set this flag"
546 check_hsm_flags_user $f "0x00000000"
549 $LFS hsm_set --exists $f ||
550 error "root could not change hsm flags"
551 check_hsm_flags_user $f "0x00000001"
553 $LFS hsm_clear --exists $f ||
554 error "root could not clear hsm state"
555 check_hsm_flags_user $f "0x00000000"
558 run_test 1A "lfs hsm flags root/non-root access"
561 mkdir_on_mdt0 $DIR/$tdir
563 local f=$DIR/$tdir/$tfile
564 local fid=$(create_small_file $f)
568 $LFS hsm_archive $f || error "could not archive file"
569 wait_request_state $fid ARCHIVE SUCCEED
571 # Release and check states
572 $LFS hsm_release $f || error "could not release file"
573 echo -n "Verifying released state: "
574 check_hsm_flags $f "0x0000000d"
576 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
578 run_test 1a "mmap & cat a HSM released file"
584 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
585 error "failed to create file"
586 local fid=$(path2fid $f)
591 $LFS hsm_archive $f || error "could not archive file"
592 wait_request_state $fid ARCHIVE SUCCEED
595 $LFS hsm_release $f || error "could not release file"
596 echo "verify released state: "
597 check_hsm_flags $f "0x0000000d" && echo "pass"
600 $LFS hsm_restore $f || error "could not restore file"
601 wait_request_state $fid RESTORE SUCCEED
602 echo "verify restored state: "
603 check_hsm_flags $f "0x00000009" && echo "pass"
607 mkdir_on_mdt0 $DIR/$tdir
608 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
609 error "failed to set default stripe"
610 local f=$DIR/$tdir/$tfile
614 run_test 1b "Archive, Release and Restore composite file"
620 local f=$DIR/$tdir/$tfile
623 # Test whether we can set the maximum archive number.
624 local LOCAL_HSM_ARCHIVE_NUMBER=32
625 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
626 error "root could not change hsm flags"
627 check_hsm_flags_user $f "0x00000001"
628 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
629 local st=$(get_hsm_archive_id $f)
630 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
631 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
633 # Test whether setting archive number 0 results in no change.
634 $LFS hsm_set --exists --archive-id 0 $f ||
635 error "root could not change hsm flags"
636 check_hsm_flags_user $f "0x00000001"
637 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
638 st=$(get_hsm_archive_id $f)
639 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
640 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
642 LOCAL_HSM_ARCHIVE_NUMBER=33
643 if [ "$CLIENT_VERSION" -ge $(version_code 2.11.56) ] &&
644 [ "$MDS1_VERSION" -ge $(version_code 2.11.56) ]; then
645 # lustre in the new version supports unlimited archiveID.
646 # Test whether setting archive number > 32 is supported
647 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
648 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
649 check_hsm_flags_user $f "0x00000001"
651 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
652 st=$(get_hsm_archive_id $f)
653 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
654 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
656 # old client or old mds can only support at most 32 archiveID
657 # test whether setting archive number > 32 results in error.
658 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
659 error "bitmap archive number is larger than 32"
660 check_hsm_flags_user $f "0x00000001"
663 # Test whether setting archive number 16 and archived flag.
664 LOCAL_HSM_ARCHIVE_NUMBER=16
665 $LFS hsm_set --exists --archived \
666 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
667 error "root could not change hsm flags"
668 check_hsm_flags_user $f "0x00000009"
669 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
670 st=$(get_hsm_archive_id $f)
671 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
672 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
674 run_test 1c "Check setting archive-id in lfs hsm_set"
677 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
678 skip "need MDS version at least 2.10.59"
680 mkdir_on_mdt0 $DIR/$tdir
681 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
682 error "failed to set default stripe"
683 local f=$DIR/$tdir/$tfile
687 run_test 1d "Archive, Release and Restore DoM file"
690 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
691 skip "skipped for lustre < $SEL_VER"
693 mkdir_on_mdt0 $DIR/$tdir
694 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
695 error "failed to set default stripe"
696 local comp_file=$DIR/$tdir/$tfile
698 test_1bde_base $comp_file
700 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
701 local found=$($LFS find $flg_opts $comp_file | wc -l)
702 [ $found -eq 1 ] || error "1st component not found"
704 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
705 found=$($LFS find $flg_opts $comp_file | wc -l)
706 [ $found -eq 1 ] || error "2nd component not found"
708 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
709 found=$($LFS find $flg_opts $comp_file | wc -l)
710 [ $found -eq 1 ] || error "3rd component not found"
712 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
713 found=$($LFS find $flg_opts $comp_file | wc -l)
714 [ $found -eq 1 ] || error "4th component not found"
716 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
717 found=$($LFS find $flg_opts $comp_file | wc -l)
718 [ $found -eq 1 ] || error "5th component not found"
720 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
721 found=$($LFS find $flg_opts $comp_file | wc -l)
722 [ $found -eq 1 ] || error "6th component not found"
724 sel_layout_sanity $comp_file 6
726 run_test 1e "Archive, Release and Restore SEL file"
729 local f=$DIR/$tdir/$tfile
731 mkdir_on_mdt0 $DIR/$tdir
732 create_empty_file "$f"
733 # New files are not dirty
734 check_hsm_flags $f "0x00000000"
736 # For test, we simulate an archived file.
737 $LFS hsm_set --exists $f || error "user could not change hsm flags"
738 check_hsm_flags $f "0x00000001"
740 # chmod do not put the file dirty
741 chmod 600 $f || error "could not chmod test file"
742 check_hsm_flags $f "0x00000001"
744 # chown do not put the file dirty
745 chown $RUNAS_ID $f || error "could not chown test file"
746 check_hsm_flags $f "0x00000001"
748 # truncate put the file dirty
749 $TRUNCATE $f 1 || error "could not truncate test file"
750 check_hsm_flags $f "0x00000003"
752 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
753 check_hsm_flags $f "0x00000001"
755 run_test 2 "Check file dirtyness when doing setattr"
758 mkdir_on_mdt0 $DIR/$tdir
761 # New files are not dirty
763 check_hsm_flags $f "0x00000000"
765 # For test, we simulate an archived file.
766 $LFS hsm_set --exists $f ||
767 error "user could not change hsm flags"
768 check_hsm_flags $f "0x00000001"
770 # Reading a file, does not set dirty
771 cat $f > /dev/null || error "could not read file"
772 check_hsm_flags $f "0x00000001"
774 # Open for write without modifying data, does not set dirty
775 openfile -f O_WRONLY $f || error "could not open test file"
776 check_hsm_flags $f "0x00000001"
778 # Append to a file sets it dirty
779 cp -p /etc/passwd $f.append || error "could not create file"
780 $LFS hsm_set --exists $f.append ||
781 error "user could not change hsm flags"
782 dd if=/etc/passwd of=$f.append bs=1 count=3\
783 conv=notrunc oflag=append status=noxfer ||
784 file_creation_failure dd $f.append $?
785 check_hsm_flags $f.append "0x00000003"
787 # Modify a file sets it dirty
788 cp -p /etc/passwd $f.modify || error "could not create file"
789 $LFS hsm_set --exists $f.modify ||
790 error "user could not change hsm flags"
791 dd if=/dev/zero of=$f.modify bs=1 count=3\
792 conv=notrunc status=noxfer ||
793 file_creation_failure dd $f.modify $?
794 check_hsm_flags $f.modify "0x00000003"
796 # Open O_TRUNC sets dirty
797 cp -p /etc/passwd $f.trunc || error "could not create file"
798 $LFS hsm_set --exists $f.trunc ||
799 error "user could not change hsm flags"
800 cp /etc/group $f.trunc || error "could not override a file"
801 check_hsm_flags $f.trunc "0x00000003"
803 # Mmapped a file sets dirty
804 cp -p /etc/passwd $f.mmap || error "could not create file"
805 $LFS hsm_set --exists $f.mmap ||
806 error "user could not change hsm flags"
807 multiop $f.mmap OSMWUc || error "could not mmap a file"
808 check_hsm_flags $f.mmap "0x00000003"
810 run_test 3 "Check file dirtyness when opening for write"
813 local f=$DIR/$tdir/$tfile
814 local fid=$(create_small_file $f)
817 local st=$(get_request_state $fid CANCEL)
818 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
820 run_test 4 "Useless cancel must not be registered"
823 # test needs a running copytool
826 mkdir_on_mdt0 $DIR/$tdir
827 local f=$DIR/$tdir/$tfile
828 local fid=$(copy_file /etc/passwd $f)
830 wait_request_state $fid ARCHIVE SUCCEED
832 check_hsm_flags $f "0x00000009"
834 run_test 8 "Test default archive number"
836 test_9A() { # was test_9
837 # we do not use the default one to be sure
838 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
839 copytool setup --archive-id $archive_id
841 # give time for CT to register with MDTs
842 sleep $(($MDSCOUNT*2))
843 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
844 check_agent_registered $uuid
846 mkdir_on_mdt0 $DIR/$tdir
848 local f=$DIR/$tdir/$tfile
849 local fid=$(copy_file /etc/passwd $f)
850 $LFS hsm_archive --archive $archive_id $f
851 wait_request_state $fid ARCHIVE SUCCEED
853 check_hsm_flags $f "0x00000009"
855 run_test 9A "Use of explicit archive number, with dedicated copytool"
858 needclients 3 || return 0
864 # start all of the copytools
865 for n in $(seq $AGTCOUNT); do
866 copytool setup --facet agt$n
869 mkdir_on_mdt0 $DIR/$tdir
872 for n in $(seq $AGTCOUNT); do
873 file=$DIR/$tdir/$tfile.$n
874 fid=$(create_small_file $file)
876 $LFS hsm_archive $file || error "could not archive file $file"
877 wait_request_state $fid ARCHIVE SUCCEED
878 check_hsm_flags $file "0x00000009"
881 run_test 9a "Multiple remote agents"
884 # test needs a running copytool
887 mkdir_on_mdt0 $DIR/$tdir
888 mkdir -p $DIR/$tdir/d1
889 local f=$DIR/$tdir/$tfile
890 local fid=$(copy_file /etc/hosts $f)
891 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
892 error "hsm_archive failed"
893 wait_request_state $fid ARCHIVE SUCCEED
895 local hsm_root="$(copytool_device $SINGLEAGT)"
896 local archive="$(do_facet $SINGLEAGT \
897 find "$hsm_root" -name "$fid" -print0)"
898 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
900 echo "Verifying content"
901 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
902 echo "Verifying hsm state "
903 check_hsm_flags $f "0x00000009"
905 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
906 local st=$(get_hsm_archive_id $f)
907 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
908 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
910 run_test 10a "Archive a file"
913 # test needs a running copytool
916 mkdir_on_mdt0 $DIR/$tdir
917 local f=$DIR/$tdir/$tfile
918 local fid=$(copy_file /etc/hosts $f)
919 $LFS hsm_archive $f || error "archive request failed"
920 wait_request_state $fid ARCHIVE SUCCEED
922 $LFS hsm_archive $f || error "archive of non dirty file failed"
923 local cnt=$(get_request_count $fid ARCHIVE)
924 [[ "$cnt" == "1" ]] ||
925 error "archive of non dirty file must not make a request"
927 run_test 10b "Archive of non dirty file must work without doing request"
930 # test needs a running copytool
934 local f=$DIR/$tdir/$tfile
935 local fid=$(copy_file /etc/hosts $f)
936 $LFS hsm_set --noarchive $f
937 $LFS hsm_archive $f && error "archive a noarchive file must fail"
940 run_test 10c "Check forbidden archive"
943 # test needs a running copytool
946 mkdir_on_mdt0 $DIR/$tdir
947 local f=$DIR/$tdir/$tfile
948 local fid=$(copy_file /etc/hosts $f)
949 $LFS hsm_archive $f || error "cannot archive $f"
950 wait_request_state $fid ARCHIVE SUCCEED
952 local ar=$(get_hsm_archive_id $f)
953 local dflt=$(get_hsm_param default_archive_id)
954 [[ $ar == $dflt ]] ||
955 error "archived file is not on default archive: $ar != $dflt"
957 run_test 10d "Archive a file on the default archive id"
960 mkdir_on_mdt0 $DIR/$tdir
961 copy2archive /etc/hosts $tdir/$tfile
962 local f=$DIR/$tdir/$tfile
964 copytool import $tdir/$tfile $f
965 echo -n "Verifying released state: "
966 check_hsm_flags $f "0x0000000d"
968 local LSZ=$(stat -c "%s" $f)
969 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
971 echo "Verifying imported size $LSZ=$ASZ"
972 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
973 echo -n "Verifying released pattern: "
974 local PTRN=$($LFS getstripe -L $f)
976 [[ $PTRN == released ]] || error "Is not released"
977 local fid=$(path2fid $f)
978 echo "Verifying new fid $fid in archive"
980 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
981 error "No archive for fid $fid"
983 run_test 11a "Import a file"
986 # test needs a running copytool
989 mkdir_on_mdt0 $DIR/$tdir
990 local f=$DIR/$tdir/$tfile
991 local fid=$(copy_file /etc/hosts $f)
992 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
993 error "hsm_archive failed"
994 wait_request_state $fid ARCHIVE SUCCEED
996 local FILE_HASH=$(md5sum $f)
999 copytool import $fid $f
1001 echo "$FILE_HASH" | md5sum -c
1003 [[ $? -eq 0 ]] || error "Restored file differs"
1005 run_test 11b "Import a deleted file using its FID"
1008 pool_add $TESTNAME || error "Pool creation failed"
1009 pool_add_targets $TESTNAME 1 1 || error "pool_add_targets failed"
1012 $LFS setstripe -p "$TESTNAME" $DIR/$tdir
1014 copy2archive /etc/hosts $tdir/$tfile
1015 copytool import $tdir/$tfile $DIR/$tdir/$tfile
1017 run_test 11c "Import a file to a directory with a pool"
1020 # test needs a running copytool
1023 mkdir_on_mdt0 $DIR/$tdir
1024 copy2archive /etc/hosts $tdir/$tfile
1026 local f=$DIR/$tdir/$tfile
1027 copytool import $tdir/$tfile $f
1028 local f2=$DIR2/$tdir/$tfile
1029 echo "Verifying released state: "
1030 check_hsm_flags $f2 "0x0000000d"
1032 local fid=$(path2fid $f2)
1033 $LFS hsm_restore $f2
1034 wait_request_state $fid RESTORE SUCCEED
1036 echo "Verifying file state: "
1037 check_hsm_flags $f2 "0x00000009"
1039 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1041 [[ $? -eq 0 ]] || error "Restored file differs"
1043 run_test 12a "Restore an imported file explicitly"
1046 # test needs a running copytool
1049 mkdir_on_mdt0 $DIR/$tdir
1050 copy2archive /etc/hosts $tdir/$tfile
1052 local f=$DIR/$tdir/$tfile
1053 copytool import $tdir/$tfile $f
1054 echo "Verifying released state: "
1055 check_hsm_flags $f "0x0000000d"
1057 cat $f > /dev/null || error "File read failed"
1059 echo "Verifying file state after restore: "
1060 check_hsm_flags $f "0x00000009"
1062 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1064 [[ $? -eq 0 ]] || error "Restored file differs"
1066 run_test 12b "Restore an imported file implicitly"
1069 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1071 # test needs a running copytool
1074 local f=$DIR/$tdir/$tfile
1075 mkdir_on_mdt0 $DIR/$tdir
1076 $LFS setstripe -c 2 "$f"
1077 local fid=$(create_file "$f" 1M 5)
1079 local FILE_CRC=$(md5sum $f)
1081 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1082 wait_request_state $fid ARCHIVE SUCCEED
1083 $LFS hsm_release $f || error "release $f failed"
1085 echo "$FILE_CRC" | md5sum -c
1087 [[ $? -eq 0 ]] || error "Restored file differs"
1089 run_test 12c "Restore a file with stripe of 2"
1092 # test needs a running copytool
1095 mkdir_on_mdt0 $DIR/$tdir
1097 local f=$DIR/$tdir/$tfile
1098 local fid=$(copy_file /etc/hosts $f)
1099 $LFS hsm_restore $f || error "restore of non archived file failed"
1100 local cnt=$(get_request_count $fid RESTORE)
1101 [[ "$cnt" == "0" ]] ||
1102 error "restore non archived must not make a request"
1103 $LFS hsm_archive $f ||
1104 error "archive request failed"
1105 wait_request_state $fid ARCHIVE SUCCEED
1106 $LFS hsm_restore $f ||
1107 error "restore of non released file failed"
1108 local cnt=$(get_request_count $fid RESTORE)
1109 [[ "$cnt" == "0" ]] ||
1110 error "restore a non dirty file must not make a request"
1112 run_test 12d "Restore of a non archived, non released file must work"\
1113 " without doing request"
1116 # test needs a running copytool
1119 mkdir_on_mdt0 $DIR/$tdir
1120 local f=$DIR/$tdir/$tfile
1121 local fid=$(copy_file /etc/hosts $f)
1122 $LFS hsm_archive $f || error "archive request failed"
1123 wait_request_state $fid ARCHIVE SUCCEED
1126 cat /etc/hosts >> $f
1130 $LFS hsm_restore $f && error "restore a dirty file must fail"
1133 run_test 12e "Check forbidden restore"
1136 # test needs a running copytool
1139 mkdir_on_mdt0 $DIR/$tdir
1140 local f=$DIR/$tdir/$tfile
1141 local fid=$(copy_file /etc/hosts $f)
1143 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1144 wait_request_state $fid ARCHIVE SUCCEED
1145 $LFS hsm_release $f || error "release of $f failed"
1147 wait_request_state $fid RESTORE SUCCEED
1149 echo -n "Verifying file state: "
1150 check_hsm_flags $f "0x00000009"
1152 diff -q /etc/hosts $f
1154 [[ $? -eq 0 ]] || error "Restored file differs"
1156 run_test 12f "Restore a released file explicitly"
1159 # test needs a running copytool
1162 mkdir_on_mdt0 $DIR/$tdir
1163 local f=$DIR/$tdir/$tfile
1164 local fid=$(copy_file /etc/hosts $f)
1166 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1167 wait_request_state $fid ARCHIVE SUCCEED
1168 $LFS hsm_release $f || error "release of $f failed"
1170 diff -q /etc/hosts $f
1173 # we check we had a restore done
1174 wait_request_state $fid RESTORE SUCCEED
1176 [[ $st -eq 0 ]] || error "Restored file differs"
1178 run_test 12g "Restore a released file implicitly"
1181 needclients 2 || return 0
1183 # test needs a running copytool
1186 mkdir_on_mdt0 $DIR/$tdir
1187 local f=$DIR/$tdir/$tfile
1188 local fid=$(copy_file /etc/hosts $f)
1190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1191 wait_request_state $fid ARCHIVE SUCCEED
1192 $LFS hsm_release $f || error "release of $f failed"
1194 do_node $CLIENT2 diff -q /etc/hosts $f
1197 # we check we had a restore done
1198 wait_request_state $fid RESTORE SUCCEED
1200 [[ $st -eq 0 ]] || error "Restored file differs"
1202 run_test 12h "Restore a released file implicitly from a second node"
1205 # test needs a running copytool
1208 mkdir_on_mdt0 $DIR/$tdir
1209 local f=$DIR/$tdir/$tfile
1210 local fid=$(copy_file /etc/passwd $f)
1211 $LFS hsm_archive $f || error "archive of $f failed"
1212 wait_request_state $fid ARCHIVE SUCCEED
1214 $LFS hsm_release $f || error "release of $f failed"
1218 [[ $? -eq 0 ]] || error "Restored file differs"
1220 run_test 12m "Archive/release/implicit restore"
1223 # test needs a running copytool
1227 copy2archive /etc/hosts $tdir/$tfile
1229 local f=$DIR/$tdir/$tfile
1230 copytool import $tdir/$tfile $f
1232 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1233 error "Restored file differs"
1235 $LFS hsm_release $f || error "release of $f failed"
1237 run_test 12n "Import/implicit restore/release"
1240 # test needs a running copytool
1243 mkdir_on_mdt0 $DIR/$tdir
1244 local f=$DIR/$tdir/$tfile
1245 local fid=$(copy_file /etc/hosts $f)
1247 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1248 wait_request_state $fid ARCHIVE SUCCEED
1249 $LFS hsm_release $f || error "release of $f failed"
1251 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1252 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1254 # set no retry action mode
1257 diff -q /etc/hosts $f
1260 # we check we had a restore failure
1261 wait_request_state $fid RESTORE FAILED
1263 [[ $st -eq 0 ]] && error "Restore must fail"
1265 # remove no retry action mode
1268 # check file is still released
1269 check_hsm_flags $f "0x0000000d"
1271 # retry w/o failure injection
1272 do_facet $SINGLEMDS lctl set_param fail_loc=0
1274 # to be sure previous RESTORE result is gone
1276 wait_for_grace_delay
1278 diff -q /etc/hosts $f
1281 # we check we had a restore done
1282 wait_request_state $fid RESTORE SUCCEED
1284 [[ $st -eq 0 ]] || error "Restored file differs"
1286 run_test 12o "Layout-swap failure during Restore leaves file released"
1289 # test needs a running copytool
1292 mkdir_on_mdt0 $DIR/$tdir
1293 local f=$DIR/$tdir/$tfile
1294 local fid=$(copy_file /etc/hosts $f)
1296 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1297 wait_request_state $fid ARCHIVE SUCCEED
1298 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1299 $LFS hsm_release $f || error "cannot release $f"
1300 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1301 $LFS hsm_release $f || error "cannot release $f"
1302 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1304 run_test 12p "implicit restore of a file on copytool mount point"
1307 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1308 skip "need MDS version at least 2.7.58"
1310 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1311 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1312 error "cannot mount $MOUNT3 on $SINGLEAGT"
1314 # test needs a running copytool
1315 copytool setup -m "$MOUNT3"
1317 mkdir_on_mdt0 $DIR/$tdir
1319 local f=$DIR/$tdir/$tfile
1320 local f2=$DIR2/$tdir/$tfile
1321 local fid=$(create_small_file $f)
1322 local orig_size=$(stat -c "%s" $f)
1324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1325 wait_request_state $fid ARCHIVE SUCCEED
1327 $LFS hsm_release $f || error "could not release file"
1328 check_hsm_flags $f "0x0000000d"
1331 wait_copytools || error "copytool failed to stop"
1333 cat $f > /dev/null &
1335 # wait a bit to allow implicit restore request to be handled.
1336 # if not, next stat would also block on layout-lock.
1339 local size=$(stat -c "%s" $f2)
1340 [ $size -eq $orig_size ] ||
1341 error "$f2: wrong size after archive: $size != $orig_size"
1343 copytool setup -m "$MOUNT3"
1347 size=$(stat -c "%s" $f)
1348 [ $size -eq $orig_size ] ||
1349 error "$f: wrong size after restore: $size != $orig_size"
1351 size=$(stat -c "%s" $f2)
1352 [ $size -eq $orig_size ] ||
1353 error "$f2: wrong size after restore: $size != $orig_size"
1357 size=$(stat -c "%s" $f)
1359 error "$f: wrong size after overwrite: $size != 0"
1361 size=$(stat -c "%s" $f2)
1363 error "$f2: wrong size after overwrite: $size != 0"
1365 run_test 12q "file attributes are refreshed after restore"
1368 # test needs a running copytool
1371 mkdir_on_mdt0 $DIR/$tdir
1372 local f=$DIR/$tdir/$tfile
1373 local fid=$(copy_file /etc/hosts $f)
1375 $LFS hsm_archive $f || error "archive of $f failed"
1376 wait_request_state $fid ARCHIVE SUCCEED
1377 $LFS hsm_release $f || error "release of $f failed"
1379 offset=$(lseek_test -d 7 $f)
1381 # we check we had a restore done
1382 wait_request_state $fid RESTORE SUCCEED
1383 [[ $offset == 7 ]] || error "offset $offset != 7"
1385 run_test 12r "lseek restores released file"
1388 local f=$DIR/$tdir/$tfile
1392 (( MDS1_VERSION >= $(version_code 2.15.50) )) ||
1393 skip "Need MDS version newer than 2.15.50"
1395 # test needs a running copytool
1398 mkdir_on_mdt0 $DIR/$tdir
1399 fid=$(copy_file /etc/hosts $f)
1401 $LFS hsm_archive $f || error "archive of $f failed"
1402 wait_request_state $fid ARCHIVE SUCCEED
1403 $LFS hsm_release $f || error "release of $f failed"
1405 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_HSM_RESTORE_RACE 0x8000018b
1406 do_facet mds1 $LCTL set_param fail_loc=0x8000018b
1407 cat $f > /dev/null & pid1=$!
1408 cat $f > /dev/null & pid2=$!
1410 wait $pid1 || error "cat process 1 fail (pid: $pid1)"
1411 wait $pid2 || error "cat process 2 fail (pid: $pid2)"
1413 # Race exists if more than 1 restore requests is registered
1414 assert_request_count $fid RESTORE 1
1416 run_test 12s "race between restore requests"
1420 for i in {1..10}; do
1421 local archive_dir="$(hsm_root)"/subdir/dir.$i
1423 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1424 for j in {1..10}; do
1425 local archive_file="$archive_dir"/file.$j
1427 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1433 copytool import "subdir" "$DIR/$tdir"
1435 # To check the import, the test uses diff with the -r flag
1436 # This is nice, but diff only checks files one by one, and triggering
1437 # an implicit restore for one file at a time will consume as many
1438 # seconds as there are files to compare. To speed this up, a restore
1439 # operation is triggered manually first.
1441 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1443 # Compare the imported data
1444 do_facet $SINGLEAGT \
1445 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1446 error "imported files differ from archived data"
1448 run_test 13 "Recursively import and restore a directory"
1451 # test needs a running copytool
1454 mkdir_on_mdt0 $DIR/$tdir
1457 local f=$DIR/$tdir/$tfile
1458 local fid=$(create_small_file $f)
1459 local sum=$(md5sum $f | awk '{print $1}')
1460 $LFS hsm_archive $f || error "could not archive file"
1461 wait_request_state $fid ARCHIVE SUCCEED
1463 # create released file (simulate llapi_hsm_import call)
1464 local fid2=$(create_empty_file "$f")
1465 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1466 $LFS hsm_release $f || error "could not release file"
1468 # rebind the archive to the newly created file
1469 echo "rebind $fid to $fid2"
1471 copytool rebind $fid $fid2
1473 # restore file and compare md5sum
1474 local sum2=$(md5sum $f | awk '{print $1}')
1476 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1478 run_test 14 "Rebind archived file to a new fid"
1481 # test needs a running copytool
1484 mkdir_on_mdt0 $DIR/$tdir
1487 local f=$DIR/$tdir/$tfile
1489 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1493 for i in $(seq 1 $count); do
1494 fids[$i]=$(create_small_file $f.$i)
1495 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1496 $LFS hsm_archive $f.$i || error "could not archive file"
1498 wait_all_done $(($count*60))
1500 stack_trap "rm -f $tmpfile" EXIT
1503 for i in $(seq 1 $count); do
1504 local fid2=$(create_empty_file "${f}.${i}")
1505 # add the rebind operation to the list
1506 echo ${fids[$i]} $fid2 >> $tmpfile
1508 # set it released (simulate llapi_hsm_import call)
1509 $LFS hsm_set --archived --exists $f.$i ||
1510 error "could not force hsm flags"
1511 $LFS hsm_release $f.$i || error "could not release file"
1513 nl=$(wc -l < $tmpfile)
1514 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1516 echo "rebind list of files"
1517 copytool rebind "$tmpfile"
1519 # restore files and compare md5sum
1520 for i in $(seq 1 $count); do
1521 local sum2=$(md5sum $f.$i | awk '{print $1}')
1522 [[ $sum2 == ${sums[$i]} ]] ||
1523 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1526 run_test 15 "Rebind a list of files"
1529 # test needs a running copytool
1533 # create a known size file so we can verify transfer speed
1536 dd if=/dev/zero of=$ref bs=1M count=20
1538 mkdir_on_mdt0 $DIR/$tdir
1539 local f=$DIR/$tdir/$tfile
1540 local fid=$(copy_file $ref $f)
1542 local start=$(date +%s)
1544 wait_request_state $fid ARCHIVE SUCCEED
1545 local end=$(date +%s)
1546 # Add 1 to account for rounding errors between start and end (LU-8155)
1547 local duration=$((end - start + 1))
1549 [[ $duration -ge $((goal - 1)) ]] ||
1550 error "Transfer is too fast $duration < $goal"
1552 run_test 16 "Test CT bandwith control option"
1555 local f=$DIR/$tdir/$tfile
1556 create_empty_file "$f"
1558 # Could not release a non-archived file
1559 $LFS hsm_release $f && error "release should not succeed"
1561 # For following tests, we must test them with HS_ARCHIVED set
1562 $LFS hsm_set --exists --archived $f || error "could not add flag"
1564 # Could not release a file if no-release is set
1565 $LFS hsm_set --norelease $f || error "could not add flag"
1566 $LFS hsm_release $f && error "release should not succeed"
1567 $LFS hsm_clear --norelease $f || error "could not remove flag"
1569 # Could not release a file if lost
1570 $LFS hsm_set --lost $f || error "could not add flag"
1571 $LFS hsm_release $f && error "release should not succeed"
1572 $LFS hsm_clear --lost $f || error "could not remove flag"
1574 # Could not release a file if dirty
1575 $LFS hsm_set --dirty $f || error "could not add flag"
1576 $LFS hsm_release $f && error "release should not succeed"
1577 $LFS hsm_clear --dirty $f || error "could not remove flag"
1579 run_test 20 "Release is not permitted"
1582 # test needs a running copytool
1584 mkdir_on_mdt0 $DIR/$tdir
1586 local f=$DIR/$tdir/test_release
1588 # Create a file and check its states
1589 local fid=$(create_small_file $f)
1590 check_hsm_flags $f "0x00000000"
1592 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1593 # used until file is flushed to disk
1594 if [ "$ost1_FSTYPE" == "zfs" ]; then
1595 # this causes an OST_SYNC rpc to be sent
1596 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1597 # clear locks to reread file data
1598 cancel_lru_locks osc
1601 local orig_size=$(stat -c "%s" $f)
1602 local orig_blocks=$(stat -c "%b" $f)
1604 start_full_debug_logging
1606 $LFS hsm_archive $f || error "could not archive file"
1607 wait_request_state $fid ARCHIVE SUCCEED
1609 local blocks=$(stat -c "%b" $f)
1610 [ $blocks -eq $orig_blocks ] ||
1611 error "$f: wrong block number after archive: " \
1612 "$blocks != $orig_blocks"
1613 local size=$(stat -c "%s" $f)
1614 [ $size -eq $orig_size ] ||
1615 error "$f: wrong size after archive: $size != $orig_size"
1617 # Release and check states
1618 $LFS hsm_release $f || error "could not release file"
1619 check_hsm_flags $f "0x0000000d"
1621 blocks=$(stat -c "%b" $f)
1622 [ $blocks -gt 5 ] &&
1623 error "$f: too many blocks after release: $blocks > 5"
1624 size=$(stat -c "%s" $f)
1625 [ $size -ne $orig_size ] &&
1626 error "$f: wrong size after release: $size != $orig_size"
1628 # Check we can release an file without stripe info
1632 check_hsm_flags $f "0x00000000"
1633 $LFS hsm_archive $f || error "could not archive file"
1634 wait_request_state $fid ARCHIVE SUCCEED
1636 # Release and check states
1637 $LFS hsm_release $f || error "could not release file"
1638 check_hsm_flags $f "0x0000000d"
1640 # Release again a file that is already released is OK
1641 $LFS hsm_release $f || fail "second release should succeed"
1642 check_hsm_flags $f "0x0000000d"
1644 stop_full_debug_logging
1646 run_test 21 "Simple release tests"
1649 # test needs a running copytool
1651 mkdir_on_mdt0 $DIR/$tdir
1653 local f=$DIR/$tdir/test_release
1654 local swap=$DIR/$tdir/test_swap
1656 # Create a file and check its states
1657 local fid=$(create_small_file $f)
1658 check_hsm_flags $f "0x00000000"
1660 $LFS hsm_archive $f || error "could not archive file"
1661 wait_request_state $fid ARCHIVE SUCCEED
1663 # Release and check states
1664 $LFS hsm_release $f || error "could not release file"
1665 check_hsm_flags $f "0x0000000d"
1667 create_small_file $swap
1668 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1672 run_test 22 "Could not swap a release file"
1675 # test needs a running copytool
1677 mkdir_on_mdt0 $DIR/$tdir
1679 local f=$DIR/$tdir/test_mtime
1681 # Create a file and check its states
1682 local fid=$(create_small_file $f)
1683 check_hsm_flags $f "0x00000000"
1685 $LFS hsm_archive $f || error "could not archive file"
1686 wait_request_state $fid ARCHIVE SUCCEED
1688 # Set modification time in the past
1689 touch -m -a -d @978261179 $f
1691 # Release and check states
1692 $LFS hsm_release $f || error "could not release file"
1693 check_hsm_flags $f "0x0000000d"
1695 local MTIME=$(stat -c "%Y" $f)
1696 local ATIME=$(stat -c "%X" $f)
1697 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1698 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1700 run_test 23 "Release does not change a/mtime (utime)"
1703 local file=$DIR/$tdir/$tfile
1712 # test needs a running copytool
1714 mkdir_on_mdt0 $DIR/$tdir
1716 fid=$(create_small_file $file)
1718 # Create a file and check its states
1719 check_hsm_flags $file "0x00000000"
1721 # Ensure atime is less than mtime and ctime.
1725 atime0=$(stat -c "%X" $file)
1726 mtime0=$(stat -c "%Y" $file)
1727 ctime0=$(stat -c "%Z" $file)
1729 [ $atime0 -lt $mtime0 ] ||
1730 error "atime $atime0 is not less than mtime $mtime0"
1732 [ $atime0 -lt $ctime0 ] ||
1733 error "atime $atime0 is not less than ctime $ctime0"
1735 # Archive should not change any timestamps.
1736 $LFS hsm_archive $file || error "cannot archive '$file'"
1737 wait_request_state $fid ARCHIVE SUCCEED
1739 atime1=$(stat -c "%X" $file)
1740 mtime1=$(stat -c "%Y" $file)
1741 ctime1=$(stat -c "%Z" $file)
1743 [ $atime0 -eq $atime1 ] ||
1744 error "archive changed atime from $atime0 to $atime1"
1746 [ $mtime0 -eq $mtime1 ] ||
1747 error "archive changed mtime from $mtime0 to $mtime1"
1749 [ $ctime0 -eq $ctime1 ] ||
1750 error "archive changed ctime from $ctime0 to $ctime1"
1752 # Release should not change any timestamps.
1753 $LFS hsm_release $file || error "cannot release '$file'"
1754 check_hsm_flags $file "0x0000000d"
1756 atime1=$(stat -c "%X" $file)
1757 mtime1=$(stat -c "%Y" $file)
1758 ctime1=$(stat -c "%Z" $file)
1760 [ $atime0 -eq $atime1 ] ||
1761 error "release changed atime from $atime0 to $atime1"
1763 [ $mtime0 -eq $mtime1 ] ||
1764 error "release changed mtime from $mtime0 to $mtime1"
1766 [ $ctime0 -eq $ctime1 ] ||
1767 error "release changed ctime from $ctime0 to $ctime1"
1769 # Restore should not change any timestamps.
1770 $LFS hsm_restore $file
1771 wait_request_state $fid RESTORE SUCCEED
1773 atime1=$(stat -c "%X" $file)
1774 mtime1=$(stat -c "%Y" $file)
1775 ctime1=$(stat -c "%Z" $file)
1777 [ $atime0 -eq $atime1 ] ||
1778 error "restore changed atime from $atime0 to $atime1"
1780 [ $mtime0 -eq $mtime1 ] ||
1781 error "restore changed mtime from $mtime0 to $mtime1"
1783 [ $ctime0 -eq $ctime1 ] ||
1784 error "restore changed ctime from $ctime0 to $ctime1"
1787 wait_copytools || error "Copytools failed to stop"
1789 # Once more, after unmount and mount.
1790 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1791 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1793 atime1=$(stat -c "%X" $file)
1794 mtime1=$(stat -c "%Y" $file)
1795 ctime1=$(stat -c "%Z" $file)
1797 [ $atime0 -eq $atime1 ] ||
1798 error "remount changed atime from $atime0 to $atime1"
1800 [ $mtime0 -eq $mtime1 ] ||
1801 error "remount changed mtime from $mtime0 to $mtime1"
1803 [ $ctime0 -eq $ctime1 ] ||
1804 error "remount changed ctime from $ctime0 to $ctime1"
1806 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1809 local file=$DIR/$tdir/$tfile
1815 # Test needs a running copytool.
1817 mkdir_on_mdt0 $DIR/$tdir
1819 # Check that root can do HSM actions on a regular user's file.
1820 fid=$(create_small_file $file)
1821 sum0=$(md5sum $file)
1823 chown $RUNAS_ID:$RUNAS_GID $file ||
1824 error "cannot chown '$file' to '$RUNAS_ID'"
1826 chmod ugo-w $DIR/$tdir ||
1827 error "cannot chmod '$DIR/$tdir'"
1829 $LFS hsm_archive $file
1830 wait_request_state $fid ARCHIVE SUCCEED
1832 $LFS hsm_release $file
1833 check_hsm_flags $file "0x0000000d"
1835 $LFS hsm_restore $file
1836 wait_request_state $fid RESTORE SUCCEED
1838 # Check that ordinary user can get HSM state.
1839 $RUNAS $LFS hsm_state $file ||
1840 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1842 $LFS hsm_release $file
1843 check_hsm_flags $file "0x0000000d"
1845 # Check that ordinary user can accessed released file.
1846 sum1=$($RUNAS md5sum $file) ||
1847 error "user '$RUNAS_ID' cannot read '$file'"
1849 [ "$sum0" == "$sum1" ] ||
1850 error "md5sum mismatch for '$file'"
1852 run_test 24b "root can archive, release, and restore user files"
1855 local file=$DIR/$tdir/$tfile
1856 local action=archive
1861 # test needs a running copytool
1863 mkdir_on_mdt0 $DIR/$tdir
1865 # Save the default masks and check that cleanup_24c will
1866 # restore the request masks correctly.
1867 user_save=$(get_hsm_param user_request_mask)
1868 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1869 group_save=$(get_hsm_param group_request_mask)
1870 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1871 other_save=$(get_hsm_param other_request_mask)
1872 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1874 [ "$user_save" == RESTORE ] ||
1875 error "user_request_mask is '$user_save' expected 'RESTORE'"
1876 [ "$group_save" == RESTORE ] ||
1877 error "group_request_mask is '$group_save' expected 'RESTORE'"
1878 [ "$other_save" == RESTORE ] ||
1879 error "other_request_mask is '$other_save' expected 'RESTORE'"
1882 create_small_file $file
1883 chown $RUNAS_ID:$GROUP $file ||
1884 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1886 $RUNAS $LFS hsm_$action $file &&
1887 error "$action by user should fail"
1889 set_hsm_param user_request_mask $action
1890 $RUNAS $LFS hsm_$action $file ||
1891 error "$action by user should succeed"
1894 create_small_file $file
1895 chown nobody:$RUNAS_GID $file ||
1896 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1898 $RUNAS $LFS hsm_$action $file &&
1899 error "$action by group should fail"
1901 set_hsm_param group_request_mask $action
1902 $RUNAS $LFS hsm_$action $file ||
1903 error "$action by group should succeed"
1906 create_small_file $file
1907 chown nobody:$GROUP $file ||
1908 error "cannot chown '$file' to 'nobody:$GROUP'"
1910 $RUNAS $LFS hsm_$action $file &&
1911 error "$action by other should fail"
1913 set_hsm_param other_request_mask $action
1914 $RUNAS $LFS hsm_$action $file ||
1915 error "$action by other should succeed"
1917 run_test 24c "check that user,group,other request masks work"
1920 local file1=$DIR/$tdir/$tfile
1921 local file2=$DIR2/$tdir/$tfile
1925 mkdir_on_mdt0 $DIR/$tdir
1927 fid1=$(create_small_file $file1)
1930 $LFS getstripe $file1
1932 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1933 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1934 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1936 copytool setup -m "$MOUNT3"
1938 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1939 mount -o remount,ro $MOUNT2
1941 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1943 fid2=$(path2fid $file2)
1944 [ "$fid1" == "$fid2" ] ||
1945 error "FID mismatch '$fid1' != '$fid2'"
1947 $LFS hsm_archive $file2 &&
1948 error "archive should fail on read-only mount"
1949 check_hsm_flags $file1 "0x00000000"
1951 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1952 wait_request_state $fid1 ARCHIVE SUCCEED
1954 $LFS hsm_release $file1
1955 $LFS hsm_restore $file2
1956 wait_request_state $fid1 RESTORE SUCCEED
1958 $LFS hsm_release $file1 || error "cannot release '$file1'"
1959 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1961 $LFS hsm_release $file2 &&
1962 error "release should fail on read-only mount"
1966 run_test 24d "check that read-only mounts are respected"
1970 mkdir_on_mdt0 $DIR/$tdir
1972 local f=$DIR/$tdir/$tfile
1975 fid=$(create_small_file $f) || error "cannot create $f"
1976 $LFS hsm_archive $f || error "cannot archive $f"
1977 wait_request_state $fid ARCHIVE SUCCEED
1978 $LFS hsm_release $f || error "cannot release $f"
1979 while ! $LFS hsm_state $f | grep released; do
1983 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1985 run_test 24e "tar succeeds on HSM released files" # LU-6213
1988 # test needs a running copytool
1990 mkdir_on_mdt0 $DIR/$tdir
1992 mkdir -p $DIR/$tdir/d1
1993 local f=$DIR/$tdir/$tfile
1994 local fid=$(copy_file /etc/hosts $f)
1997 $LFS hsm_archive $f ||
1998 error "hsm_archive failed"
1999 wait_request_state $fid ARCHIVE SUCCEED
2000 $LFS hsm_release $f || error "cannot release $f"
2001 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2004 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2005 error "Can not recover the tar contents"
2007 echo "Sum0 = $sum0, sum1 = $sum1"
2008 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2010 run_test 24f "root can archive, release, and restore tar files"
2013 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2014 skip "need MDS version 2.11.56 or later"
2016 local file=$DIR/$tdir/$tfile
2019 echo "RUNAS = '$RUNAS'"
2023 mkdir_on_mdt0 $DIR/$tdir
2024 chmod ugo+rwx $DIR/$tdir
2026 echo "Please listen carefully as our options have changed." | tee $file
2027 fid=$(path2fid $file)
2030 $LFS hsm_archive $file
2031 wait_request_state $fid ARCHIVE SUCCEED
2032 check_hsm_flags $file 0x00000009 # exists archived
2034 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2035 check_hsm_flags $file 0x0000000b # exists dirty archived
2037 run_test 24g "write by non-owner still sets dirty" # LU-11369
2040 # test needs a running copytool
2044 copy2archive /etc/hosts $tdir/$tfile
2046 local f=$DIR/$tdir/$tfile
2048 copytool import $tdir/$tfile $f
2050 $LFS hsm_set --lost $f
2055 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2057 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2058 " (Operation not permitted)"
2061 # test needs a running copytool
2064 mkdir_on_mdt0 $DIR/$tdir
2066 local f=$DIR/$tdir/$tfile
2067 local fid=$(copy_file /etc/passwd $f)
2069 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2070 wait_request_state $fid ARCHIVE SUCCEED
2073 $LFS hsm_set --lost $f
2077 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2079 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2080 " (Operation not permitted)"
2082 test_26A() { # was test_26
2083 # test needs a running copytool
2085 mkdir_on_mdt0 $DIR/$tdir
2087 local f=$DIR/$tdir/$tfile
2088 local fid=$(create_empty_file "$f")
2090 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2091 wait_request_state $fid ARCHIVE SUCCEED
2094 wait_request_state $fid REMOVE SUCCEED
2096 check_hsm_flags $f "0x00000000"
2098 run_test 26A "Remove the archive of a valid file"
2101 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2102 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2104 # test needs a running copytool
2106 mkdir_on_mdt0 $DIR/$tdir
2108 local f=$DIR/$tdir/$tfile
2109 local fid=$(copy_file /etc/passwd $f)
2111 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2112 wait_request_state $fid ARCHIVE SUCCEED
2114 local f2=$DIR/$tdir/${tfile}_2
2115 local fid2=$(copy_file /etc/passwd $f2)
2117 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2118 wait_request_state $fid2 ARCHIVE SUCCEED
2120 local f3=$DIR/$tdir/${tfile}_3
2121 local fid3=$(copy_file /etc/passwd $f3)
2123 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2124 wait_request_state $fid3 ARCHIVE SUCCEED
2126 # set a long grace_delay vs short loop_period
2127 local orig_loop_period=$(get_hsm_param loop_period)
2128 local orig_grace_delay=$(get_hsm_param grace_delay)
2129 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2130 set_hsm_param loop_period 10
2131 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2132 set_hsm_param grace_delay 100
2136 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2137 set_hsm_param remove_archive_on_last_unlink 1
2139 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2144 wait_request_state $fid2 REMOVE SUCCEED
2146 assert_request_count $fid REMOVE 0 \
2147 "Unexpected archived data remove request for $f"
2148 assert_request_count $fid3 REMOVE 0 \
2149 "Unexpected archived data remove request for $f3"
2151 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2154 # test needs a running copytool
2156 mkdir_on_mdt0 $DIR/$tdir
2158 local f=$DIR/$tdir/$tfile
2159 local fid=$(copy_file /etc/passwd $f)
2161 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2162 wait_request_state $fid ARCHIVE SUCCEED
2164 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2165 set_hsm_param remove_archive_on_last_unlink 1
2168 cdt_check_state stopped
2172 wait_request_state $fid REMOVE WAITING
2176 # copytool must re-register
2178 wait_copytools || error "copytool failed to stop"
2181 wait_request_state $fid REMOVE SUCCEED
2183 run_test 26b "RAoLU policy when CDT off"
2186 # test needs a running copytool
2188 mkdir_on_mdt0 $DIR/$tdir
2190 local f=$DIR/$tdir/$tfile
2191 local fid=$(copy_file /etc/passwd $f)
2193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2194 wait_request_state $fid ARCHIVE SUCCEED
2196 local f2=$DIR/$tdir/${tfile}_2
2197 local fid2=$(copy_file /etc/passwd $f2)
2199 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2200 wait_request_state $fid2 ARCHIVE SUCCEED
2202 # set a long grace_delay vs short loop_period
2203 local orig_loop_period=$(get_hsm_param loop_period)
2204 local orig_grace_delay=$(get_hsm_param grace_delay)
2205 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2206 set_hsm_param loop_period 10
2207 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2208 set_hsm_param grace_delay 100
2210 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2211 set_hsm_param remove_archive_on_last_unlink 1
2213 multiop_bg_pause $f O_c || error "open $f failed"
2219 wait_request_state $fid2 REMOVE SUCCEED
2220 assert_request_count $fid REMOVE 0 \
2221 "Unexpected archived data remove request for $f"
2223 kill -USR1 $pid || error "multiop early exit"
2224 # should reach autotest timeout if multiop fails to trap
2225 # signal, close file, and exit ...
2226 wait $pid || error "wait PID $PID failed"
2228 wait_request_state $fid REMOVE SUCCEED
2230 run_test 26c "RAoLU effective when file closed"
2233 # test needs a running copytool
2235 mkdir_on_mdt0 $DIR/$tdir
2237 local f=$DIR/$tdir/$tfile
2238 local fid=$(create_small_file $f)
2240 $LFS hsm_archive $f || error "could not archive file"
2241 wait_request_state $fid ARCHIVE SUCCEED
2243 # set a long grace_delay vs short loop_period
2244 local orig_loop_period=$(get_hsm_param loop_period)
2245 local orig_grace_delay=$(get_hsm_param grace_delay)
2246 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2247 set_hsm_param loop_period 10
2248 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2249 set_hsm_param grace_delay 100
2251 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2252 set_hsm_param remove_archive_on_last_unlink 1
2254 multiop_bg_pause $f O_c || error "multiop failed"
2261 wait_request_state $fid REMOVE SUCCEED
2263 client_up || client_up || true
2265 kill -USR1 $MULTIPID
2266 wait $MULTIPID || error "multiop close failed"
2268 run_test 26d "RAoLU when Client eviction"
2271 # test needs a running copytool
2274 create_archive_file $tdir/$tfile
2275 local f=$DIR/$tdir/$tfile
2276 copytool import $tdir/$tfile $f
2277 local fid=$(path2fid $f)
2281 [[ $? != 0 ]] || error "Remove of a released file should fail"
2283 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2286 # test needs a running copytool
2288 mkdir_on_mdt0 $DIR/$tdir
2290 local f=$DIR/$tdir/$tfile
2291 local fid=$(create_empty_file "$f")
2293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2294 wait_request_state $fid ARCHIVE SUCCEED
2299 [[ $? != 0 ]] || error "Remove of a released file should fail"
2301 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2304 # test needs a running copytool
2306 mkdir_on_mdt0 $DIR/$tdir
2308 local f=$DIR/$tdir/$tfile
2309 local fid=$(create_empty_file "$f")
2311 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2312 wait_request_state $fid ARCHIVE SUCCEED
2321 wait_request_state $fid REMOVE SUCCEED
2323 run_test 28 "Concurrent archive/file remove"
2326 # Tests --mntpath and --archive options
2329 copytool setup -m "$MOUNT" -a $archive_id
2331 # Bad archive number
2332 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2333 grep "Invalid argument" ||
2334 error "unexpected hsm_remove failure (1)"
2336 # mntpath is present but file is given
2337 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2338 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2339 error "unexpected hsm_remove failure (2)"
2341 run_test 29a "Tests --mntpath and --archive options"
2344 # test needs a running copytool
2346 mkdir_on_mdt0 $DIR/$tdir
2348 local f=$DIR/$tdir/$tfile
2349 local fid=$(create_small_file $f)
2351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2352 wait_request_state $fid ARCHIVE SUCCEED
2356 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2357 wait_request_state $fid REMOVE SUCCEED
2359 run_test 29b "Archive/delete/remove by FID from the archive."
2362 # test needs a running copytool
2364 mkdir_on_mdt0 $DIR/$tdir
2366 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2367 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2368 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2370 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2371 wait_request_state $fid1 ARCHIVE SUCCEED
2372 wait_request_state $fid2 ARCHIVE SUCCEED
2373 wait_request_state $fid3 ARCHIVE SUCCEED
2375 rm -f $DIR/$tdir/$tfile-[1-3]
2377 echo $fid1 > $DIR/$tdir/list
2378 echo $fid2 >> $DIR/$tdir/list
2379 echo $fid3 >> $DIR/$tdir/list
2381 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2382 --filelist $DIR/$tdir/list
2383 wait_request_state $fid1 REMOVE SUCCEED
2384 wait_request_state $fid2 REMOVE SUCCEED
2385 wait_request_state $fid3 REMOVE SUCCEED
2387 run_test 29c "Archive/delete/remove by FID, using a file list."
2390 # test needs more than one CT
2391 needclients 3 || return 0
2397 # start all of the copytools
2398 for n in $(seq $AGTCOUNT); do
2399 copytool setup -f agt$n -a $n
2402 mkdir_on_mdt0 $DIR/$tdir
2405 file=$DIR/$tdir/$tfile
2406 fid=$(create_small_file $file)
2408 $LFS hsm_archive $file
2409 wait_request_state $fid ARCHIVE SUCCEED
2410 check_hsm_flags $file "0x00000009"
2414 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2415 error "cannot hsm_remove '$fid'"
2417 # give time for CDT to handle remove request and create broadcasted
2420 # remove request has been broadcasted ?
2421 local cnt=$(get_request_count $fid REMOVE)
2422 # broadcasted requests + original
2423 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2424 error "remove not broadcasted to all CTs"
2426 # give time for CDT and CTs to handle broadcasted
2427 wait_for_loop_period
2429 # each agent serves one different archive_id, so broadcasted
2430 # hsm_remove request should only succeed once and fail at all others
2434 for n in $(seq $AGTCOUNT); do
2435 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2436 $HSM_PARAM.actions | awk \
2437 '/'$fid'.*action=REMOVE archive#='$n'/ \
2438 {print \\\$13}' | cut -f2 -d=")
2439 if [[ "$res" == "SUCCEED" ]]; then
2441 elif [[ "$res" == "FAILED" ]]; then
2446 [[ $scnt -eq 1 ]] ||
2447 error "one and only CT should have removed successfully"
2449 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2450 error "all but one CT should have failed to remove"
2452 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2453 "request to be sent once for each registered archive_id"
2456 # restore at exec cannot work on agent node (because of Linux kernel
2457 # protection of executables)
2458 needclients 2 || return 0
2460 # test needs a running copytool
2464 copy2archive /bin/true $tdir/$tfile
2466 local f=$DIR/$tdir/true
2467 copytool import $tdir/$tfile $f
2469 local fid=$(path2fid $f)
2471 stack_trap "cdt_clear_no_retry" EXIT
2472 # set no retry action mode
2479 [[ $st == 0 ]] || error "Failed to exec a released file"
2481 run_test 30a "Restore at exec (import case)"
2484 # restore at exec cannot work on agent node (because of Linux kernel
2485 # protection of executables)
2486 needclients 2 || return 0
2488 # test needs a running copytool
2491 mkdir_on_mdt0 $DIR/$tdir
2492 local f=$DIR/$tdir/true
2493 local fid=$(copy_file /bin/true $f)
2495 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2496 wait_request_state $fid ARCHIVE SUCCEED
2500 stack_trap cdt_clear_no_retry EXIT
2501 # set no retry action mode
2509 [[ $st == 0 ]] || error "Failed to exec a released file"
2511 run_test 30b "Restore at exec (release case)"
2514 needclients 2 || return 0
2516 # test needs a running copytool
2519 mkdir_on_mdt0 $DIR/$tdir
2520 local f=$DIR/$tdir/SLEEP
2521 local slp_sum1=$(md5sum /bin/sleep)
2522 local fid=$(copy_file /bin/sleep $f)
2524 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2525 wait_request_state $fid ARCHIVE SUCCEED
2527 check_hsm_flags $f "0x0000000d"
2529 stack_trap cdt_clear_no_retry EXIT
2530 # set no retry action mode
2533 do_node $CLIENT2 "$f 10" &
2537 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2539 [[ $? == 0 ]] || error "Execution failed during run"
2541 if [[ $? != 0 ]]; then
2542 local slp_sum2=$(md5sum /bin/sleep)
2543 # in case sleep file is modified during the test
2544 [[ $slp_sum1 == $slp_sum2 ]] &&
2545 error "Binary overwritten during exec"
2548 check_hsm_flags $f "0x00000009"
2550 run_test 30c "Update during exec of released file must fail"
2552 restore_and_check_size() {
2555 local s=$(stat -c "%s" $f)
2557 local st=$(get_hsm_flags $f)
2561 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2563 n=$(stat -c "%s" $f)
2564 # we echo in both cases to show stat is not hang
2565 if [[ $n != $s ]]; then
2566 echo "size seen is $n != $s"
2569 echo "size seen is right: $n == $s"
2573 st=$(get_hsm_flags $f)
2575 if [[ "$st" = "0x00000009" ]]; then
2578 echo " restore is too long"
2579 wait_request_state $fid RESTORE SUCCEED
2585 # test needs a running copytool
2587 mkdir_on_mdt0 $DIR/$tdir
2589 create_archive_file $tdir/$tfile
2590 local f=$DIR/$tdir/$tfile
2591 copytool import $tdir/$tfile $f
2592 local fid=$($LFS path2fid $f)
2595 restore_and_check_size $f $fid
2598 [[ $err -eq 0 ]] || error "File size changed during restore"
2600 run_test 31a "Import a large file and check size during restore"
2604 # test needs a running copytool
2606 mkdir_on_mdt0 $DIR/$tdir
2608 local f=$DIR/$tdir/$tfile
2609 local fid=$(create_file "$f" 1MB 39)
2611 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2612 wait_request_state $fid ARCHIVE SUCCEED
2615 restore_and_check_size $f $fid
2618 [[ $err -eq 0 ]] || error "File size changed during restore"
2620 run_test 31b "Restore a large unaligned file and check size during restore"
2623 # test needs a running copytool
2625 mkdir_on_mdt0 $DIR/$tdir
2627 local f=$DIR/$tdir/$tfile
2628 local fid=$(create_file "$f" 1M 39)
2630 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2631 wait_request_state $fid ARCHIVE SUCCEED
2634 restore_and_check_size $f $fid
2637 [[ $err -eq 0 ]] || error "File size changed during restore"
2639 run_test 31c "Restore a large aligned file and check size during restore"
2642 local f=$DIR/$tdir/$tfile
2644 mkdir_on_mdt0 $DIR/$tdir
2645 local fid=$(create_empty_file "$f")
2649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2650 wait_request_state $fid ARCHIVE SUCCEED
2653 # Prevent restore from completing
2657 md5sum $f >/dev/null &
2660 wait_request_state $fid RESTORE STARTED
2665 # Check restore trigger process was killed
2667 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2669 run_test 33 "Kill a restore waiting process"
2672 # test needs a running copytool
2674 mkdir_on_mdt0 $DIR/$tdir
2676 local f=$DIR/$tdir/$tfile
2677 local fid=$(create_empty_file "$f")
2679 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2680 wait_request_state $fid ARCHIVE SUCCEED
2683 # Prevent restore from completing
2686 md5sum $f >/dev/null &
2689 wait_request_state $fid RESTORE STARTED
2691 # rm must not block during restore
2692 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2695 wait_request_state $fid RESTORE SUCCEED
2697 # Check md5sum pgm finished
2698 kill -0 $pid && error "Restore initiatior still running"
2699 wait $pid || error "Restore initiator failed with $?"
2701 # Check the file was actually deleted
2702 [ ! -f "$f" ] || error "$f was not deleted"
2704 run_test 34 "Remove file during restore"
2707 # test needs a running copytool
2709 mkdir_on_mdt0 $DIR/$tdir
2711 local f=$DIR/$tdir/$tfile
2712 local f1=$DIR/$tdir/$tfile-1
2713 local fid=$(create_empty_file "$f")
2714 local fid1=$(copy_file /etc/passwd $f1)
2716 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2717 wait_request_state $fid ARCHIVE SUCCEED
2720 # Prevent restore from completing
2723 md5sum $f >/dev/null &
2726 wait_request_state $fid RESTORE STARTED
2728 # mv must not block during restore
2729 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2732 wait_request_state $fid RESTORE SUCCEED
2734 # Check md5sum pgm finished
2735 kill -0 $pid && error "Restore initiatior still running"
2736 wait $pid || error "Restore initiator failed with $?"
2738 local fid2=$(path2fid $f)
2739 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2741 run_test 35 "Overwrite file during restore"
2744 # test needs a running copytool
2746 mkdir_on_mdt0 $DIR/$tdir
2748 local f=$DIR/$tdir/$tfile
2749 local fid=$(create_empty_file "$f")
2751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2752 wait_request_state $fid ARCHIVE SUCCEED
2755 # Prevent restore from completing
2758 md5sum $f >/dev/null &
2761 wait_request_state $fid RESTORE STARTED
2763 # mv must not block during restore
2764 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2765 error "mv '$f' '$f.new' failed with rc=$?"
2768 wait_request_state $fid RESTORE SUCCEED
2770 # Check md5sum pgm finished
2771 kill -0 $pid && error "Restore initiator is still running"
2772 wait $pid || error "Restore initiator failed with $?"
2774 run_test 36 "Move file during restore"
2777 # LU-5683: check that an archived dirty file can be rearchived.
2779 mkdir_on_mdt0 $DIR/$tdir
2781 local f=$DIR/$tdir/$tfile
2784 fid=$(create_small_file $f) || error "cannot create small file"
2786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2787 wait_request_state $fid ARCHIVE SUCCEED
2788 $LFS hsm_release $f || error "cannot release $f"
2790 # Allow previous archive request to expire from the actions log.
2791 wait_for_grace_delay
2794 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2796 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2797 wait_request_state $fid ARCHIVE SUCCEED
2799 run_test 37 "re-archive a dirty file"
2806 for n in $(seq 1 $count); do
2807 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2809 echo "$count archive requests submitted"
2813 local stream_count=4
2814 local file_count=100
2816 local f=$DIR/$tdir/$tfile
2820 local max_requests=$(get_hsm_param max_requests)
2822 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2823 # Increase the number of HSM request that can be performed in
2824 # parallel. With the coordinator running once per second, this
2825 # also limits the number of requests per seconds that can be
2826 # performed, so we pick a decent number. But we also need to keep
2827 # that number low because the copytool has no rate limit and will
2828 # fail some requests if if gets too many at once.
2829 set_hsm_param max_requests 300
2831 for i in $(seq 1 $file_count); do
2832 for p in $(seq 1 $stream_count); do
2833 fid=$(copy_file /etc/hosts $f.$p.$i)
2839 # to be sure wait_all_done will not be mislead by previous tests
2841 wait_for_grace_delay
2843 # start archive streams in background (archive files in parallel)
2844 for p in $(seq 1 $stream_count); do
2845 multi_archive $f.$p $file_count &
2848 echo -n "Wait for all requests being enqueued..."
2853 run_test 40 "Parallel archive requests"
2855 hsm_archive_batch() {
2863 while [ $i -lt $files_num ]; do
2864 if [ $batch_num -eq $batch_max ]; then
2865 $LFS hsm_archive $fileset || error "HSM archive failed"
2866 # Reset the batch container.
2871 fileset+="${filebase}$i "
2872 batch_num=$(( batch_num + 1 ))
2876 if [ $batch_num -ne 0 ]; then
2877 $LFS hsm_archive $fileset || error "HSM archive failed"
2884 local dir=$DIR/$tdir
2887 set_hsm_param max_requests 1000000
2888 mkdir $dir || error "mkdir $dir failed"
2897 filebase="$dir/$tfile.start."
2898 createmany -m $filebase $files_num ||
2899 error "createmany -m $filebase failed: $?"
2902 hsm_archive_batch $files_num $batch_max "$filebase"
2903 elapsed=$((SECONDS - start))
2904 do_facet $SINGLEMDS "$LCTL get_param -n \
2905 $HSM_PARAM.actions | grep WAITING | wc -l"
2906 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2907 echo "Start Phase files_num: $files_num time: $elapsed"
2910 filebase="$dir/$tfile.in."
2911 createmany -m $filebase $files_num ||
2912 error "createmany -m $filebase failed: $?"
2914 hsm_archive_batch $files_num $batch_max "$filebase"
2915 elapsed=$((SECONDS - start))
2916 unlinkmany $filebase $files_num || error "unlinkmany $filabase failed"
2917 echo "Middle Phase files_num: $files_num time: $elapsed"
2920 filebase="$dir/$tfile.end."
2921 createmany -m $filebase $files_num ||
2922 error "createmany -m $filebase failed: $?"
2925 hsm_archive_batch $files_num $batch_max "$filebase"
2926 elapsed=$((SECONDS - start))
2927 do_facet $SINGLEMDS "$LCTL get_param -n \
2928 $HSM_PARAM.actions | grep WAITING | wc -l"
2930 unlinkmany $filebase $files_num || error "unlinkmany $filebase failed"
2931 echo "End Phase files_num: $files_num time: $elapsed"
2933 do_facet $SINGLEMDS "$LCTL get_param -n \
2934 $HSM_PARAM.actions | grep WAITING | wc -l"
2938 run_test 50 "Archive with large number of pending HSM actions"
2941 # test needs a running copytool
2944 mkdir_on_mdt0 $DIR/$tdir
2945 local f=$DIR/$tdir/$tfile
2946 local fid=$(create_small_file $f)
2948 $LFS hsm_archive $f || error "could not archive file"
2949 wait_request_state $fid ARCHIVE SUCCEED
2950 check_hsm_flags $f "0x00000009"
2952 multiop_bg_pause $f O_c || error "multiop failed"
2956 client_up || client_up || true
2958 kill -USR1 $MULTIPID
2959 wait $MULTIPID || error "multiop close failed"
2961 check_hsm_flags $f "0x0000000b"
2963 run_test 52 "Opened for write file on an evicted client should be set dirty"
2966 # test needs a running copytool
2969 mkdir_on_mdt0 $DIR/$tdir
2970 local f=$DIR/$tdir/$tfile
2971 local fid=$(create_small_file $f)
2973 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2974 error "could not archive file"
2975 wait_request_state $fid ARCHIVE SUCCEED
2976 check_hsm_flags $f "0x00000009"
2978 multiop_bg_pause $f o_c || error "multiop failed"
2982 client_up || client_up || true
2984 kill -USR1 $MULTIPID
2985 wait $MULTIPID || error "multiop close failed"
2987 check_hsm_flags $f "0x00000009"
2989 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2992 mkdir_on_mdt0 $DIR/$tdir
2994 local f=$DIR/$tdir/$tfile
2995 local fid=$(create_file "$f" 1MB 39)
2999 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3000 error "could not archive file"
3001 wait_request_state $fid ARCHIVE STARTED
3003 check_hsm_flags $f "0x00000001"
3005 stack_trap "cdt_clear_no_retry" EXIT
3006 # Avoid coordinator resending this request as soon it has failed.
3011 wait_request_state $fid ARCHIVE FAILED
3013 check_hsm_flags $f "0x00000003"
3015 run_test 54 "Write during an archive cancels it"
3018 mkdir_on_mdt0 $DIR/$tdir
3020 local f=$DIR/$tdir/$tfile
3021 local fid=$(create_file "$f" 1MB 39)
3025 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3026 error "could not archive file"
3027 wait_request_state $fid ARCHIVE STARTED
3029 check_hsm_flags $f "0x00000001"
3031 stack_trap "cdt_clear_no_retry" EXIT
3032 # Avoid coordinator resending this request as soon it has failed.
3035 $TRUNCATE $f 1024 || error "truncate failed"
3037 wait_request_state $fid ARCHIVE FAILED
3039 check_hsm_flags $f "0x00000003"
3041 run_test 55 "Truncate during an archive cancels it"
3044 mkdir_on_mdt0 $DIR/$tdir
3046 local f=$DIR/$tdir/$tfile
3047 local fid=$(create_file "$f" 1MB 39)
3051 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3052 error "could not archive file"
3053 wait_request_state $fid ARCHIVE STARTED
3055 check_hsm_flags $f "0x00000001"
3057 # Change metadata and sync to be sure we are not changing only
3062 wait_request_state $fid ARCHIVE SUCCEED
3064 check_hsm_flags $f "0x00000009"
3066 run_test 56 "Setattr during an archive is ok"
3069 # Need one client for I/O, one for request
3070 needclients 2 || return 0
3072 # test needs a running copytool
3075 mkdir_on_mdt0 $DIR/$tdir
3076 local f=$DIR/$tdir/test_archive_remote
3077 # Create a file on a remote node
3078 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3079 "count=2 conv=fsync"
3082 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3083 error "hsm_archive failed"
3084 local fid=$(path2fid $f)
3085 wait_request_state $fid ARCHIVE SUCCEED
3087 # Release and implicit restore it
3088 do_node $CLIENT2 "$LFS hsm_release $f" ||
3089 error "hsm_release failed"
3090 do_node $CLIENT2 "md5sum $f" ||
3091 error "hsm_restore failed"
3093 wait_request_state $fid RESTORE SUCCEED
3095 run_test 57 "Archive a file with dirty cache on another node"
3097 truncate_released_file() {
3101 local sz=$(stat -c %s $src_file)
3102 local f=$DIR/$tdir/$tfile
3103 local fid=$(copy_file $1 $f)
3107 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3108 error "could not archive file"
3109 wait_request_state $fid ARCHIVE SUCCEED
3111 $LFS hsm_release $f || error "could not release file"
3113 $TRUNCATE $f $trunc_to || error "truncate failed"
3116 local sz1=$(stat -c %s $f)
3117 [[ $sz1 == $trunc_to ]] ||
3118 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3121 check_hsm_flags $f "0x0000000b"
3123 local state=$(get_request_state $fid RESTORE)
3124 [[ "$state" == "SUCCEED" ]] ||
3125 error "truncate $sz does not trig restore, state = $state"
3127 $TRUNCATE $ref $trunc_to
3128 cmp $ref $f || error "file data wrong after truncate"
3134 # test needs a running copytool
3137 mkdir_on_mdt0 $DIR/$tdir
3139 local sz=$(stat -c %s /etc/passwd)
3141 echo "truncate up from $sz to $((sz*2))"
3142 truncate_released_file /etc/passwd $((sz*2))
3144 echo "truncate down from $sz to $((sz/2))"
3145 truncate_released_file /etc/passwd $((sz/2))
3147 echo "truncate to 0"
3148 truncate_released_file /etc/passwd 0
3150 run_test 58 "Truncate a released file will trigger restore"
3154 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3155 skip "Need MDS version at least 2.7.63"
3158 $MCREATE $DIR/$tfile || error "mcreate failed"
3159 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3160 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3161 fid=$(path2fid $DIR/$tfile)
3162 wait_request_state $fid ARCHIVE SUCCEED
3163 $LFS hsm_release $DIR/$tfile || error "release failed"
3165 run_test 59 "Release stripeless file with non-zero size"
3168 # This test validates the fix for LU-4512. Ensure that the -u
3169 # option changes the progress reporting interval from the
3170 # default (30 seconds) to the user-specified interval.
3171 mkdir_on_mdt0 $DIR/$tdir
3173 local f=$DIR/$tdir/$tfile
3174 local fid=$(create_file "$f" 1M 10)
3177 local progress_timeout=$((interval * 4))
3178 copytool setup -b 1 --update-interval $interval
3181 local mdt=${MDT_PREFIX}${mdtidx}
3182 local mds=mds$((mdtidx + 1))
3184 # Wait for copytool to register
3185 wait_update_facet $mds \
3186 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3187 uuid 100 || error "coyptool failed to register with $mdt"
3189 local start_at=$(date +%s)
3190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3191 error "could not archive file"
3193 local agent=$(facet_active_host $SINGLEAGT)
3194 local logfile=$(copytool_logfile $SINGLEAGT)
3196 wait_update $agent \
3197 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3198 error "copytool failed to start"
3200 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3201 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3207 echo -n "Expecting a progress update within $progress_timeout seconds... "
3209 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3210 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3211 echo "$RESULT bytes copied in $WAIT seconds."
3213 elif [ $WAIT -ge $progress_timeout ]; then
3214 error "Timed out waiting for progress update!"
3217 WAIT=$((WAIT + sleep))
3221 local finish_at=$(date +%s)
3222 local elapsed=$((finish_at - start_at))
3224 # Ensure that the progress update occurred within the expected window.
3225 if [ $elapsed -lt $((interval - 1)) ]; then
3226 error "Expected progress update after at least $interval seconds"
3229 echo "Wait for on going archive hsm action to complete"
3230 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3231 echo "File archiving not completed even after 10 secs"
3233 run_test 60 "Changing progress update interval from default"
3236 # test needs a running copytool
3239 mkdir_on_mdt0 $DIR/$tdir
3240 local f=$DIR/$tdir/$tfile
3241 local fid=$(copy_file /etc/passwd $f)
3243 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3246 wait_request_state $fid ARCHIVE FAILED
3248 run_test 61 "Waiting archive of a removed file should fail"
3251 # test needs a new running copytool
3252 stack_trap copytool_monitor_cleanup EXIT
3253 copytool_monitor_setup
3254 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3256 # Wait for the copytool to register.
3257 wait_update --verbose $(facet_active_host mds1) \
3258 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3260 error "copytool failed to register with MDT0000"
3263 wait_copytools || error "Copytools failed to stop"
3265 local REGISTER_EVENT
3266 local UNREGISTER_EVENT
3267 while read event; do
3268 local parsed=$(parse_json_event "$event")
3269 if [ -z "$parsed" ]; then
3270 error "Copytool sent malformed event: $event"
3274 if [ $event_type == "REGISTER" ]; then
3275 REGISTER_EVENT=$event
3276 elif [ $event_type == "UNREGISTER" ]; then
3277 UNREGISTER_EVENT=$event
3279 done < <(echo $"$(get_copytool_event_log)")
3281 if [ -z "$REGISTER_EVENT" ]; then
3282 error "Copytool failed to send register event to FIFO"
3285 if [ -z "$UNREGISTER_EVENT" ]; then
3286 error "Copytool failed to send unregister event to FIFO"
3289 echo "Register/Unregister events look OK."
3291 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3294 # Bump progress interval for livelier events.
3297 # test needs a new running copytool
3298 stack_trap copytool_monitor_cleanup EXIT
3299 copytool_monitor_setup
3300 copytool setup --update-interval $interval --event-fifo \
3301 "$HSMTOOL_MONITOR_DIR/fifo"
3303 stack_trap "cdt_clear_no_retry" EXIT
3304 # Just start and stop the copytool to generate events.
3307 mkdir_on_mdt0 $DIR/$tdir
3309 local f=$DIR/$tdir/$tfile
3310 local fid=$(create_small_file "$f")
3312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3313 error "could not archive file"
3314 wait_request_state $fid ARCHIVE SUCCEED
3316 local expected_fields="event_time data_fid source_fid"
3317 expected_fields+=" total_bytes current_bytes"
3320 [ARCHIVE_START]=false
3321 [ARCHIVE_FINISH]=false
3322 [ARCHIVE_RUNNING]=false
3324 while read event; do
3325 # Make sure we're not getting anything from previous events.
3326 for field in $expected_fields; do
3330 local parsed=$(parse_json_event "$event")
3331 if [ -z "$parsed" ]; then
3332 error "Copytool sent malformed event: $event"
3336 events["$event_type"]=true
3338 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3340 # Do some simple checking of the progress update events.
3341 for expected_field in $expected_fields; do
3342 if [ -z ${!expected_field+x} ]; then
3343 error "Missing $expected_field field in event"
3347 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3349 # These should be identical throughout an archive operation
3350 [ $source_fid == $data_fid ] ||
3351 error "Expected source_fid to equal data_fid"
3352 done < <(echo $"$(get_copytool_event_log)")
3354 # Check we received every type of events we were expecting
3355 for event in "${!events[@]}"; do
3356 ${events["$event"]} ||
3357 error "Copytool failed to send '$event' event to FIFO"
3360 echo "Archive events look OK."
3362 run_test 71 "Copytool logs JSON archive events to FIFO"
3365 # Bump progress interval for livelier events.
3368 # test needs a new running copytool
3369 stack_trap copytool_monitor_cleanup EXIT
3370 copytool_monitor_setup
3371 copytool setup --update-interval $interval --event-fifo \
3372 "$HSMTOOL_MONITOR_DIR/fifo"
3373 local test_file=$HSMTOOL_MONITOR_DIR/file
3375 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3377 do_facet $SINGLEAGT "$cmd" ||
3378 error "cannot create $test_file on $SINGLEAGT"
3379 copy2archive $test_file $tdir/$tfile
3381 mkdir_on_mdt0 $DIR/$tdir
3382 local f=$DIR/$tdir/$tfile
3383 copytool import $tdir/$tfile $f
3384 f=$DIR2/$tdir/$tfile
3385 echo "Verifying released state: "
3386 check_hsm_flags $f "0x0000000d"
3388 local fid=$(path2fid $f)
3390 wait_request_state $fid RESTORE SUCCEED
3392 local expected_fields="event_time data_fid source_fid"
3393 expected_fields+=" total_bytes current_bytes"
3397 while read event; do
3398 # Make sure we're not getting anything from previous events.
3399 for field in $expected_fields; do
3403 local parsed=$(parse_json_event "$event")
3404 if [ -z "$parsed" ]; then
3405 error "Copytool sent malformed event: $event"
3409 if [ $event_type == "RESTORE_START" ]; then
3411 if [ $source_fid != $data_fid ]; then
3412 error "source_fid should == data_fid at start"
3415 elif [ $event_type == "RESTORE_FINISH" ]; then
3417 if [ $source_fid != $data_fid ]; then
3418 error "source_fid should == data_fid at finish"
3421 elif [ $event_type != "RESTORE_RUNNING" ]; then
3425 # Do some simple checking of the progress update events.
3426 for expected_field in $expected_fields; do
3427 if [ -z ${!expected_field+x} ]; then
3428 error "Missing $expected_field field in event"
3432 if [ $total_bytes -eq 0 ]; then
3433 error "Expected total_bytes to be > 0"
3436 # When a restore starts out, the data fid is the same as the
3437 # source fid. After the restore has gotten going, we learn
3438 # the new data fid. Once the restore has finished, the source
3439 # fid is set to the new data fid.
3441 # We test this because some monitoring software may depend on
3442 # this behavior. If it changes, then the consumers of these
3443 # events may need to be modified.
3444 if [ $source_fid == $data_fid ]; then
3445 error "source_fid should != data_fid during restore"
3447 done < <(echo $"$(get_copytool_event_log)")
3449 if [ -z "$START_EVENT" ]; then
3450 error "Copytool failed to send restore start event to FIFO"
3453 if [ -z "$FINISH_EVENT" ]; then
3454 error "Copytool failed to send restore finish event to FIFO"
3457 echo "Restore events look OK."
3459 run_test 72 "Copytool logs JSON restore events to FIFO"