3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
12 LUSTRE=${LUSTRE:-$(dirname $0)/..}
13 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT "
19 # bug number for skipped tests: LU-9795 LU-9795
20 ALWAYS_EXCEPT+=" 13 402b "
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 # Skip tests for PPC that fail frequently
25 if [[ $(uname -m) = ppc64 ]]; then
26 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
27 ALWAYS_EXCEPT+=" 1a 1b 1d 1e 12c 12f "
28 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
29 ALWAYS_EXCEPT+=" 12g 12h 12m 12n 12o 12p "
30 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
31 ALWAYS_EXCEPT+=" 12q 21 22 23 24a 24b "
32 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
33 ALWAYS_EXCEPT+=" 24d 24e 24f 25b 30c 37 "
34 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
35 ALWAYS_EXCEPT+=" 57 58 90 110b 111b 113 "
36 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
37 ALWAYS_EXCEPT+=" 222b 222d 228 260a 260b 260c "
38 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
39 ALWAYS_EXCEPT+=" 220A 220a 221 222a 222c 223a "
40 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
41 ALWAYS_EXCEPT+=" 223b 224A 224a 226 227 600"
42 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
43 ALWAYS_EXCEPT+=" 601 602 603 604 605 "
48 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
50 OPENFILE=${OPENFILE:-openfile}
51 MOUNT_2=${MOUNT_2:-"yes"}
54 # script only handles up to 10 MDTs (because of MDT_PREFIX)
55 [ $MDSCOUNT -gt 9 ] &&
56 error "script cannot handle more than 9 MDTs, please fix"
58 check_and_setup_lustre
60 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
61 skip_env "Need MDS version at least 2.4.53"
64 # $RUNAS_ID may get set incorrectly somewhere else
65 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
66 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
68 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
69 if getent group nobody; then
71 elif getent group nogroup; then
74 error "No generic nobody group"
77 # if there is no CLIENT1 defined, some tests can be ran on localhost
78 CLIENT1=${CLIENT1:-$HOSTNAME}
79 # if CLIENT2 doesn't exist then use CLIENT1 instead
80 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
82 # Exception is the test which need two separate nodes
83 CLIENT2=${CLIENT2:-$CLIENT1}
86 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
87 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
91 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
92 local wait_timeout=200
93 local wait_start=$SECONDS
94 local wait_end=$((wait_start + wait_timeout))
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"
1345 for i in {1..10}; do
1346 local archive_dir="$(hsm_root)"/subdir/dir.$i
1348 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1349 for j in {1..10}; do
1350 local archive_file="$archive_dir"/file.$j
1352 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1358 copytool import "subdir" "$DIR/$tdir"
1360 # To check the import, the test uses diff with the -r flag
1361 # This is nice, but diff only checks files one by one, and triggering
1362 # an implicit restore for one file at a time will consume as many
1363 # seconds as there are files to compare. To speed this up, a restore
1364 # operation is triggered manually first.
1366 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1368 # Compare the imported data
1369 do_facet $SINGLEAGT \
1370 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1371 error "imported files differ from archived data"
1373 run_test 13 "Recursively import and restore a directory"
1376 # test needs a running copytool
1380 local f=$DIR/$tdir/$tfile
1381 local fid=$(create_small_file $f)
1382 local sum=$(md5sum $f | awk '{print $1}')
1383 $LFS hsm_archive $f || error "could not archive file"
1384 wait_request_state $fid ARCHIVE SUCCEED
1386 # create released file (simulate llapi_hsm_import call)
1387 local fid2=$(create_empty_file "$f")
1388 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1389 $LFS hsm_release $f || error "could not release file"
1391 # rebind the archive to the newly created file
1392 echo "rebind $fid to $fid2"
1394 copytool rebind $fid $fid2
1396 # restore file and compare md5sum
1397 local sum2=$(md5sum $f | awk '{print $1}')
1399 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1401 run_test 14 "Rebind archived file to a new fid"
1404 # test needs a running copytool
1408 local f=$DIR/$tdir/$tfile
1410 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1414 for i in $(seq 1 $count); do
1415 fids[$i]=$(create_small_file $f.$i)
1416 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1417 $LFS hsm_archive $f.$i || error "could not archive file"
1419 wait_all_done $(($count*60))
1421 stack_trap "rm -f $tmpfile" EXIT
1424 for i in $(seq 1 $count); do
1425 local fid2=$(create_empty_file "${f}.${i}")
1426 # add the rebind operation to the list
1427 echo ${fids[$i]} $fid2 >> $tmpfile
1429 # set it released (simulate llapi_hsm_import call)
1430 $LFS hsm_set --archived --exists $f.$i ||
1431 error "could not force hsm flags"
1432 $LFS hsm_release $f.$i || error "could not release file"
1434 nl=$(wc -l < $tmpfile)
1435 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1437 echo "rebind list of files"
1438 copytool rebind "$tmpfile"
1440 # restore files and compare md5sum
1441 for i in $(seq 1 $count); do
1442 local sum2=$(md5sum $f.$i | awk '{print $1}')
1443 [[ $sum2 == ${sums[$i]} ]] ||
1444 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1447 run_test 15 "Rebind a list of files"
1450 # test needs a running copytool
1454 # create a known size file so we can verify transfer speed
1457 dd if=/dev/zero of=$ref bs=1M count=20
1460 local f=$DIR/$tdir/$tfile
1461 local fid=$(copy_file $ref $f)
1463 local start=$(date +%s)
1465 wait_request_state $fid ARCHIVE SUCCEED
1466 local end=$(date +%s)
1467 # Add 1 to account for rounding errors between start and end (LU-8155)
1468 local duration=$((end - start + 1))
1470 [[ $duration -ge $((goal - 1)) ]] ||
1471 error "Transfer is too fast $duration < $goal"
1473 run_test 16 "Test CT bandwith control option"
1476 local f=$DIR/$tdir/$tfile
1477 create_empty_file "$f"
1479 # Could not release a non-archived file
1480 $LFS hsm_release $f && error "release should not succeed"
1482 # For following tests, we must test them with HS_ARCHIVED set
1483 $LFS hsm_set --exists --archived $f || error "could not add flag"
1485 # Could not release a file if no-release is set
1486 $LFS hsm_set --norelease $f || error "could not add flag"
1487 $LFS hsm_release $f && error "release should not succeed"
1488 $LFS hsm_clear --norelease $f || error "could not remove flag"
1490 # Could not release a file if lost
1491 $LFS hsm_set --lost $f || error "could not add flag"
1492 $LFS hsm_release $f && error "release should not succeed"
1493 $LFS hsm_clear --lost $f || error "could not remove flag"
1495 # Could not release a file if dirty
1496 $LFS hsm_set --dirty $f || error "could not add flag"
1497 $LFS hsm_release $f && error "release should not succeed"
1498 $LFS hsm_clear --dirty $f || error "could not remove flag"
1500 run_test 20 "Release is not permitted"
1503 # test needs a running copytool
1506 local f=$DIR/$tdir/test_release
1508 # Create a file and check its states
1509 local fid=$(create_small_file $f)
1510 check_hsm_flags $f "0x00000000"
1512 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1513 # used until file is flushed to disk
1514 if [ $(facet_fstype ost1) == "zfs" ]; then
1515 # this causes an OST_SYNC rpc to be sent
1516 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1517 # clear locks to reread file data
1518 cancel_lru_locks osc
1521 local orig_size=$(stat -c "%s" $f)
1522 local orig_blocks=$(stat -c "%b" $f)
1524 start_full_debug_logging
1526 $LFS hsm_archive $f || error "could not archive file"
1527 wait_request_state $fid ARCHIVE SUCCEED
1529 local blocks=$(stat -c "%b" $f)
1530 [ $blocks -eq $orig_blocks ] ||
1531 error "$f: wrong block number after archive: " \
1532 "$blocks != $orig_blocks"
1533 local size=$(stat -c "%s" $f)
1534 [ $size -eq $orig_size ] ||
1535 error "$f: wrong size after archive: $size != $orig_size"
1537 # Release and check states
1538 $LFS hsm_release $f || error "could not release file"
1539 check_hsm_flags $f "0x0000000d"
1541 blocks=$(stat -c "%b" $f)
1542 [ $blocks -gt 5 ] &&
1543 error "$f: too many blocks after release: $blocks > 5"
1544 size=$(stat -c "%s" $f)
1545 [ $size -ne $orig_size ] &&
1546 error "$f: wrong size after release: $size != $orig_size"
1548 # Check we can release an file without stripe info
1552 check_hsm_flags $f "0x00000000"
1553 $LFS hsm_archive $f || error "could not archive file"
1554 wait_request_state $fid ARCHIVE SUCCEED
1556 # Release and check states
1557 $LFS hsm_release $f || error "could not release file"
1558 check_hsm_flags $f "0x0000000d"
1560 # Release again a file that is already released is OK
1561 $LFS hsm_release $f || fail "second release should succeed"
1562 check_hsm_flags $f "0x0000000d"
1564 stop_full_debug_logging
1566 run_test 21 "Simple release tests"
1569 # test needs a running copytool
1572 local f=$DIR/$tdir/test_release
1573 local swap=$DIR/$tdir/test_swap
1575 # Create a file and check its states
1576 local fid=$(create_small_file $f)
1577 check_hsm_flags $f "0x00000000"
1579 $LFS hsm_archive $f || error "could not archive file"
1580 wait_request_state $fid ARCHIVE SUCCEED
1582 # Release and check states
1583 $LFS hsm_release $f || error "could not release file"
1584 check_hsm_flags $f "0x0000000d"
1586 create_small_file $swap
1587 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1591 run_test 22 "Could not swap a release file"
1594 # test needs a running copytool
1597 local f=$DIR/$tdir/test_mtime
1599 # Create a file and check its states
1600 local fid=$(create_small_file $f)
1601 check_hsm_flags $f "0x00000000"
1603 $LFS hsm_archive $f || error "could not archive file"
1604 wait_request_state $fid ARCHIVE SUCCEED
1606 # Set modification time in the past
1607 touch -m -a -d @978261179 $f
1609 # Release and check states
1610 $LFS hsm_release $f || error "could not release file"
1611 check_hsm_flags $f "0x0000000d"
1613 local MTIME=$(stat -c "%Y" $f)
1614 local ATIME=$(stat -c "%X" $f)
1615 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1616 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1618 run_test 23 "Release does not change a/mtime (utime)"
1621 local file=$DIR/$tdir/$tfile
1630 # test needs a running copytool
1633 fid=$(create_small_file $file)
1635 # Create a file and check its states
1636 check_hsm_flags $file "0x00000000"
1638 # Ensure atime is less than mtime and ctime.
1642 atime0=$(stat -c "%X" $file)
1643 mtime0=$(stat -c "%Y" $file)
1644 ctime0=$(stat -c "%Z" $file)
1646 [ $atime0 -lt $mtime0 ] ||
1647 error "atime $atime0 is not less than mtime $mtime0"
1649 [ $atime0 -lt $ctime0 ] ||
1650 error "atime $atime0 is not less than ctime $ctime0"
1652 # Archive should not change any timestamps.
1653 $LFS hsm_archive $file || error "cannot archive '$file'"
1654 wait_request_state $fid ARCHIVE SUCCEED
1656 atime1=$(stat -c "%X" $file)
1657 mtime1=$(stat -c "%Y" $file)
1658 ctime1=$(stat -c "%Z" $file)
1660 [ $atime0 -eq $atime1 ] ||
1661 error "archive changed atime from $atime0 to $atime1"
1663 [ $mtime0 -eq $mtime1 ] ||
1664 error "archive changed mtime from $mtime0 to $mtime1"
1666 [ $ctime0 -eq $ctime1 ] ||
1667 error "archive changed ctime from $ctime0 to $ctime1"
1669 # Release should not change any timestamps.
1670 $LFS hsm_release $file || error "cannot release '$file'"
1671 check_hsm_flags $file "0x0000000d"
1673 atime1=$(stat -c "%X" $file)
1674 mtime1=$(stat -c "%Y" $file)
1675 ctime1=$(stat -c "%Z" $file)
1677 [ $atime0 -eq $atime1 ] ||
1678 error "release changed atime from $atime0 to $atime1"
1680 [ $mtime0 -eq $mtime1 ] ||
1681 error "release changed mtime from $mtime0 to $mtime1"
1683 [ $ctime0 -eq $ctime1 ] ||
1684 error "release changed ctime from $ctime0 to $ctime1"
1686 # Restore should not change any timestamps.
1687 $LFS hsm_restore $file
1688 wait_request_state $fid RESTORE SUCCEED
1690 atime1=$(stat -c "%X" $file)
1691 mtime1=$(stat -c "%Y" $file)
1692 ctime1=$(stat -c "%Z" $file)
1694 [ $atime0 -eq $atime1 ] ||
1695 error "restore changed atime from $atime0 to $atime1"
1697 [ $mtime0 -eq $mtime1 ] ||
1698 error "restore changed mtime from $mtime0 to $mtime1"
1700 [ $ctime0 -eq $ctime1 ] ||
1701 error "restore changed ctime from $ctime0 to $ctime1"
1704 wait_copytools || error "Copytools failed to stop"
1706 # Once more, after unmount and mount.
1707 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1708 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1710 atime1=$(stat -c "%X" $file)
1711 mtime1=$(stat -c "%Y" $file)
1712 ctime1=$(stat -c "%Z" $file)
1714 [ $atime0 -eq $atime1 ] ||
1715 error "remount changed atime from $atime0 to $atime1"
1717 [ $mtime0 -eq $mtime1 ] ||
1718 error "remount changed mtime from $mtime0 to $mtime1"
1720 [ $ctime0 -eq $ctime1 ] ||
1721 error "remount changed ctime from $ctime0 to $ctime1"
1723 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1726 local file=$DIR/$tdir/$tfile
1732 # Test needs a running copytool.
1735 # Check that root can do HSM actions on a regular user's file.
1736 fid=$(create_small_file $file)
1737 sum0=$(md5sum $file)
1739 chown $RUNAS_ID:$RUNAS_GID $file ||
1740 error "cannot chown '$file' to '$RUNAS_ID'"
1742 chmod ugo-w $DIR/$tdir ||
1743 error "cannot chmod '$DIR/$tdir'"
1745 $LFS hsm_archive $file
1746 wait_request_state $fid ARCHIVE SUCCEED
1748 $LFS hsm_release $file
1749 check_hsm_flags $file "0x0000000d"
1751 $LFS hsm_restore $file
1752 wait_request_state $fid RESTORE SUCCEED
1754 # Check that ordinary user can get HSM state.
1755 $RUNAS $LFS hsm_state $file ||
1756 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1758 $LFS hsm_release $file
1759 check_hsm_flags $file "0x0000000d"
1761 # Check that ordinary user can accessed released file.
1762 sum1=$($RUNAS md5sum $file) ||
1763 error "user '$RUNAS_ID' cannot read '$file'"
1765 [ "$sum0" == "$sum1" ] ||
1766 error "md5sum mismatch for '$file'"
1768 run_test 24b "root can archive, release, and restore user files"
1771 local file=$DIR/$tdir/$tfile
1772 local action=archive
1777 # test needs a running copytool
1782 # Save the default masks and check that cleanup_24c will
1783 # restore the request masks correctly.
1784 user_save=$(get_hsm_param user_request_mask)
1785 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1786 group_save=$(get_hsm_param group_request_mask)
1787 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1788 other_save=$(get_hsm_param other_request_mask)
1789 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1791 [ "$user_save" == RESTORE ] ||
1792 error "user_request_mask is '$user_save' expected 'RESTORE'"
1793 [ "$group_save" == RESTORE ] ||
1794 error "group_request_mask is '$group_save' expected 'RESTORE'"
1795 [ "$other_save" == RESTORE ] ||
1796 error "other_request_mask is '$other_save' expected 'RESTORE'"
1799 create_small_file $file
1800 chown $RUNAS_ID:$GROUP $file ||
1801 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1803 $RUNAS $LFS hsm_$action $file &&
1804 error "$action by user should fail"
1806 set_hsm_param user_request_mask $action
1807 $RUNAS $LFS hsm_$action $file ||
1808 error "$action by user should succeed"
1811 create_small_file $file
1812 chown nobody:$RUNAS_GID $file ||
1813 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1815 $RUNAS $LFS hsm_$action $file &&
1816 error "$action by group should fail"
1818 set_hsm_param group_request_mask $action
1819 $RUNAS $LFS hsm_$action $file ||
1820 error "$action by group should succeed"
1823 create_small_file $file
1824 chown nobody:$GROUP $file ||
1825 error "cannot chown '$file' to 'nobody:$GROUP'"
1827 $RUNAS $LFS hsm_$action $file &&
1828 error "$action by other should fail"
1830 set_hsm_param other_request_mask $action
1831 $RUNAS $LFS hsm_$action $file ||
1832 error "$action by other should succeed"
1834 run_test 24c "check that user,group,other request masks work"
1837 local file1=$DIR/$tdir/$tfile
1838 local file2=$DIR2/$tdir/$tfile
1842 fid1=$(create_small_file $file1)
1845 $LFS getstripe $file1
1847 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1848 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1849 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1851 copytool setup -m "$MOUNT3"
1853 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1854 mount -o remount,ro $MOUNT2
1856 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1858 fid2=$(path2fid $file2)
1859 [ "$fid1" == "$fid2" ] ||
1860 error "FID mismatch '$fid1' != '$fid2'"
1862 $LFS hsm_archive $file2 &&
1863 error "archive should fail on read-only mount"
1864 check_hsm_flags $file1 "0x00000000"
1866 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1867 wait_request_state $fid1 ARCHIVE SUCCEED
1869 $LFS hsm_release $file1
1870 $LFS hsm_restore $file2
1871 wait_request_state $fid1 RESTORE SUCCEED
1873 $LFS hsm_release $file1 || error "cannot release '$file1'"
1874 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1876 $LFS hsm_release $file2 &&
1877 error "release should fail on read-only mount"
1881 run_test 24d "check that read-only mounts are respected"
1886 local f=$DIR/$tdir/$tfile
1889 fid=$(create_small_file $f) || error "cannot create $f"
1890 $LFS hsm_archive $f || error "cannot archive $f"
1891 wait_request_state $fid ARCHIVE SUCCEED
1892 $LFS hsm_release $f || error "cannot release $f"
1893 while ! $LFS hsm_state $f | grep released; do
1897 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
1899 run_test 24e "tar succeeds on HSM released files" # LU-6213
1902 # test needs a running copytool
1905 mkdir -p $DIR/$tdir/d1
1906 local f=$DIR/$tdir/$tfile
1907 local fid=$(copy_file /etc/hosts $f)
1910 $LFS hsm_archive $f ||
1911 error "hsm_archive failed"
1912 wait_request_state $fid ARCHIVE SUCCEED
1913 $LFS hsm_release $f || error "cannot release $f"
1914 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
1917 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
1918 error "Can not recover the tar contents"
1920 echo "Sum0 = $sum0, sum1 = $sum1"
1921 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
1923 run_test 24f "root can archive, release, and restore tar files"
1926 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
1927 skip "need MDS version 2.11.56 or later"
1929 local file=$DIR/$tdir/$tfile
1932 echo "RUNAS = '$RUNAS'"
1937 chmod ugo+rwx $DIR/$tdir
1939 echo "Please listen carefully as our options have changed." | tee $file
1940 fid=$(path2fid $file)
1943 $LFS hsm_archive $file
1944 wait_request_state $fid ARCHIVE SUCCEED
1945 check_hsm_flags $file 0x00000009 # exists archived
1947 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
1948 check_hsm_flags $file 0x0000000b # exists dirty archived
1950 run_test 24g "write by non-owner still sets dirty" # LU-11369
1953 # test needs a running copytool
1957 copy2archive /etc/hosts $tdir/$tfile
1959 local f=$DIR/$tdir/$tfile
1961 copytool import $tdir/$tfile $f
1963 $LFS hsm_set --lost $f
1968 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1970 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1971 " (Operation not permitted)"
1974 # test needs a running copytool
1979 local f=$DIR/$tdir/$tfile
1980 local fid=$(copy_file /etc/passwd $f)
1982 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1983 wait_request_state $fid ARCHIVE SUCCEED
1986 $LFS hsm_set --lost $f
1990 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1992 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1993 " (Operation not permitted)"
1995 test_26A() { # was test_26
1996 # test needs a running copytool
1999 local f=$DIR/$tdir/$tfile
2000 local fid=$(create_empty_file "$f")
2002 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2003 wait_request_state $fid ARCHIVE SUCCEED
2006 wait_request_state $fid REMOVE SUCCEED
2008 check_hsm_flags $f "0x00000000"
2010 run_test 26A "Remove the archive of a valid file"
2013 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2014 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2016 # test needs a running copytool
2020 local f=$DIR/$tdir/$tfile
2021 local fid=$(copy_file /etc/passwd $f)
2023 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2024 wait_request_state $fid ARCHIVE SUCCEED
2026 local f2=$DIR/$tdir/${tfile}_2
2027 local fid2=$(copy_file /etc/passwd $f2)
2029 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2030 wait_request_state $fid2 ARCHIVE SUCCEED
2032 local f3=$DIR/$tdir/${tfile}_3
2033 local fid3=$(copy_file /etc/passwd $f3)
2035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2036 wait_request_state $fid3 ARCHIVE SUCCEED
2038 # set a long grace_delay vs short loop_period
2039 local orig_loop_period=$(get_hsm_param loop_period)
2040 local orig_grace_delay=$(get_hsm_param grace_delay)
2041 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2042 set_hsm_param loop_period 10
2043 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2044 set_hsm_param grace_delay 100
2048 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2049 set_hsm_param remove_archive_on_last_unlink 1
2051 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2056 wait_request_state $fid2 REMOVE SUCCEED
2058 assert_request_count $fid REMOVE 0 \
2059 "Unexpected archived data remove request for $f"
2060 assert_request_count $fid3 REMOVE 0 \
2061 "Unexpected archived data remove request for $f3"
2063 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2066 # test needs a running copytool
2070 local f=$DIR/$tdir/$tfile
2071 local fid=$(copy_file /etc/passwd $f)
2073 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2074 wait_request_state $fid ARCHIVE SUCCEED
2076 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2077 set_hsm_param remove_archive_on_last_unlink 1
2080 cdt_check_state stopped
2084 wait_request_state $fid REMOVE WAITING
2088 # copytool must re-register
2090 wait_copytools || error "copytool failed to stop"
2093 wait_request_state $fid REMOVE SUCCEED
2095 run_test 26b "RAoLU policy when CDT off"
2098 # test needs a running copytool
2102 local f=$DIR/$tdir/$tfile
2103 local fid=$(copy_file /etc/passwd $f)
2105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2106 wait_request_state $fid ARCHIVE SUCCEED
2108 local f2=$DIR/$tdir/${tfile}_2
2109 local fid2=$(copy_file /etc/passwd $f2)
2111 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2112 wait_request_state $fid2 ARCHIVE SUCCEED
2114 # set a long grace_delay vs short loop_period
2115 local orig_loop_period=$(get_hsm_param loop_period)
2116 local orig_grace_delay=$(get_hsm_param grace_delay)
2117 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2118 set_hsm_param loop_period 10
2119 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2120 set_hsm_param grace_delay 100
2122 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2123 set_hsm_param remove_archive_on_last_unlink 1
2125 multiop_bg_pause $f O_c || error "open $f failed"
2131 wait_request_state $fid2 REMOVE SUCCEED
2132 assert_request_count $fid REMOVE 0 \
2133 "Unexpected archived data remove request for $f"
2135 kill -USR1 $pid || error "multiop early exit"
2136 # should reach autotest timeout if multiop fails to trap
2137 # signal, close file, and exit ...
2138 wait $pid || error "wait PID $PID failed"
2140 wait_request_state $fid REMOVE SUCCEED
2142 run_test 26c "RAoLU effective when file closed"
2145 # test needs a running copytool
2149 local f=$DIR/$tdir/$tfile
2150 local fid=$(create_small_file $f)
2152 $LFS hsm_archive $f || error "could not archive file"
2153 wait_request_state $fid ARCHIVE SUCCEED
2155 # set a long grace_delay vs short loop_period
2156 local orig_loop_period=$(get_hsm_param loop_period)
2157 local orig_grace_delay=$(get_hsm_param grace_delay)
2158 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2159 set_hsm_param loop_period 10
2160 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2161 set_hsm_param grace_delay 100
2163 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2164 set_hsm_param remove_archive_on_last_unlink 1
2166 multiop_bg_pause $f O_c || error "multiop failed"
2173 wait_request_state $fid REMOVE SUCCEED
2175 client_up || client_up || true
2177 kill -USR1 $MULTIPID
2178 wait $MULTIPID || error "multiop close failed"
2180 run_test 26d "RAoLU when Client eviction"
2183 # test needs a running copytool
2186 create_archive_file $tdir/$tfile
2187 local f=$DIR/$tdir/$tfile
2188 copytool import $tdir/$tfile $f
2189 local fid=$(path2fid $f)
2193 [[ $? != 0 ]] || error "Remove of a released file should fail"
2195 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2198 # test needs a running copytool
2201 local f=$DIR/$tdir/$tfile
2202 local fid=$(create_empty_file "$f")
2204 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2205 wait_request_state $fid ARCHIVE SUCCEED
2210 [[ $? != 0 ]] || error "Remove of a released file should fail"
2212 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2215 # test needs a running copytool
2218 local f=$DIR/$tdir/$tfile
2219 local fid=$(create_empty_file "$f")
2221 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2222 wait_request_state $fid ARCHIVE SUCCEED
2231 wait_request_state $fid REMOVE SUCCEED
2233 run_test 28 "Concurrent archive/file remove"
2236 # Tests --mntpath and --archive options
2239 copytool setup -m "$MOUNT" -a $archive_id
2241 # Bad archive number
2242 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2243 grep "Invalid argument" ||
2244 error "unexpected hsm_remove failure (1)"
2246 # mntpath is present but file is given
2247 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2248 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2249 error "unexpected hsm_remove failure (2)"
2251 run_test 29a "Tests --mntpath and --archive options"
2254 # test needs a running copytool
2257 local f=$DIR/$tdir/$tfile
2258 local fid=$(create_small_file $f)
2260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2261 wait_request_state $fid ARCHIVE SUCCEED
2265 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2266 wait_request_state $fid REMOVE SUCCEED
2268 run_test 29b "Archive/delete/remove by FID from the archive."
2271 # test needs a running copytool
2274 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2275 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2276 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2279 wait_request_state $fid1 ARCHIVE SUCCEED
2280 wait_request_state $fid2 ARCHIVE SUCCEED
2281 wait_request_state $fid3 ARCHIVE SUCCEED
2283 rm -f $DIR/$tdir/$tfile-[1-3]
2285 echo $fid1 > $DIR/$tdir/list
2286 echo $fid2 >> $DIR/$tdir/list
2287 echo $fid3 >> $DIR/$tdir/list
2289 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2290 --filelist $DIR/$tdir/list
2291 wait_request_state $fid1 REMOVE SUCCEED
2292 wait_request_state $fid2 REMOVE SUCCEED
2293 wait_request_state $fid3 REMOVE SUCCEED
2295 run_test 29c "Archive/delete/remove by FID, using a file list."
2298 # test needs more than one CT
2299 needclients 3 || return 0
2305 # start all of the copytools
2306 for n in $(seq $AGTCOUNT); do
2307 copytool setup -f agt$n -a $n
2311 file=$DIR/$tdir/$tfile
2312 fid=$(create_small_file $file)
2314 $LFS hsm_archive $file
2315 wait_request_state $fid ARCHIVE SUCCEED
2316 check_hsm_flags $file "0x00000009"
2320 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2321 error "cannot hsm_remove '$fid'"
2323 # give time for CDT to handle remove request and create broadcasted
2326 # remove request has been broadcasted ?
2327 local cnt=$(get_request_count $fid REMOVE)
2328 # broadcasted requests + original
2329 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2330 error "remove not broadcasted to all CTs"
2332 # give time for CDT and CTs to handle broadcasted
2333 wait_for_loop_period
2335 # each agent serves one different archive_id, so broadcasted
2336 # hsm_remove request should only succeed once and fail at all others
2340 for n in $(seq $AGTCOUNT); do
2341 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2342 $HSM_PARAM.actions | awk \
2343 '/'$fid'.*action=REMOVE archive#='$n'/ \
2344 {print \\\$13}' | cut -f2 -d=")
2345 if [[ "$res" == "SUCCEED" ]]; then
2347 elif [[ "$res" == "FAILED" ]]; then
2352 [[ $scnt -eq 1 ]] ||
2353 error "one and only CT should have removed successfully"
2355 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2356 error "all but one CT should have failed to remove"
2358 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2359 "request to be sent once for each registered archive_id"
2362 # restore at exec cannot work on agent node (because of Linux kernel
2363 # protection of executables)
2364 needclients 2 || return 0
2366 # test needs a running copytool
2370 copy2archive /bin/true $tdir/$tfile
2372 local f=$DIR/$tdir/true
2373 copytool import $tdir/$tfile $f
2375 local fid=$(path2fid $f)
2377 stack_trap "cdt_clear_no_retry" EXIT
2378 # set no retry action mode
2385 [[ $st == 0 ]] || error "Failed to exec a released file"
2387 run_test 30a "Restore at exec (import case)"
2390 # restore at exec cannot work on agent node (because of Linux kernel
2391 # protection of executables)
2392 needclients 2 || return 0
2394 # test needs a running copytool
2398 local f=$DIR/$tdir/true
2399 local fid=$(copy_file /bin/true $f)
2401 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2402 wait_request_state $fid ARCHIVE SUCCEED
2406 stack_trap cdt_clear_no_retry EXIT
2407 # set no retry action mode
2415 [[ $st == 0 ]] || error "Failed to exec a released file"
2417 run_test 30b "Restore at exec (release case)"
2420 needclients 2 || return 0
2422 # test needs a running copytool
2426 local f=$DIR/$tdir/SLEEP
2427 local slp_sum1=$(md5sum /bin/sleep)
2428 local fid=$(copy_file /bin/sleep $f)
2430 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2431 wait_request_state $fid ARCHIVE SUCCEED
2433 check_hsm_flags $f "0x0000000d"
2435 stack_trap cdt_clear_no_retry EXIT
2436 # set no retry action mode
2439 do_node $CLIENT2 "$f 10" &
2443 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2445 [[ $? == 0 ]] || error "Execution failed during run"
2447 if [[ $? != 0 ]]; then
2448 local slp_sum2=$(md5sum /bin/sleep)
2449 # in case sleep file is modified during the test
2450 [[ $slp_sum1 == $slp_sum2 ]] &&
2451 error "Binary overwritten during exec"
2454 check_hsm_flags $f "0x00000009"
2456 run_test 30c "Update during exec of released file must fail"
2458 restore_and_check_size() {
2461 local s=$(stat -c "%s" $f)
2463 local st=$(get_hsm_flags $f)
2467 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2469 n=$(stat -c "%s" $f)
2470 # we echo in both cases to show stat is not hang
2471 if [[ $n != $s ]]; then
2472 echo "size seen is $n != $s"
2475 echo "size seen is right: $n == $s"
2479 st=$(get_hsm_flags $f)
2481 if [[ "$st" = "0x00000009" ]]; then
2484 echo " restore is too long"
2485 wait_request_state $fid RESTORE SUCCEED
2491 # test needs a running copytool
2494 create_archive_file $tdir/$tfile
2495 local f=$DIR/$tdir/$tfile
2496 copytool import $tdir/$tfile $f
2497 local fid=$($LFS path2fid $f)
2500 restore_and_check_size $f $fid
2503 [[ $err -eq 0 ]] || error "File size changed during restore"
2505 run_test 31a "Import a large file and check size during restore"
2509 # test needs a running copytool
2512 local f=$DIR/$tdir/$tfile
2513 local fid=$(create_file "$f" 1MB 39)
2515 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2516 wait_request_state $fid ARCHIVE SUCCEED
2519 restore_and_check_size $f $fid
2522 [[ $err -eq 0 ]] || error "File size changed during restore"
2524 run_test 31b "Restore a large unaligned file and check size during restore"
2527 # test needs a running copytool
2530 local f=$DIR/$tdir/$tfile
2531 local fid=$(create_file "$f" 1M 39)
2533 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2534 wait_request_state $fid ARCHIVE SUCCEED
2537 restore_and_check_size $f $fid
2540 [[ $err -eq 0 ]] || error "File size changed during restore"
2542 run_test 31c "Restore a large aligned file and check size during restore"
2545 local f=$DIR/$tdir/$tfile
2546 local fid=$(create_empty_file "$f")
2550 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2551 wait_request_state $fid ARCHIVE SUCCEED
2554 # Prevent restore from completing
2558 md5sum $f >/dev/null &
2561 wait_request_state $fid RESTORE STARTED
2566 # Check restore trigger process was killed
2568 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2570 run_test 33 "Kill a restore waiting process"
2573 # test needs a running copytool
2576 local f=$DIR/$tdir/$tfile
2577 local fid=$(create_empty_file "$f")
2579 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2580 wait_request_state $fid ARCHIVE SUCCEED
2583 # Prevent restore from completing
2586 md5sum $f >/dev/null &
2589 wait_request_state $fid RESTORE STARTED
2591 # rm must not block during restore
2592 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2595 wait_request_state $fid RESTORE SUCCEED
2597 # Check md5sum pgm finished
2598 kill -0 $pid && error "Restore initiatior still running"
2599 wait $pid || error "Restore initiator failed with $?"
2601 # Check the file was actually deleted
2602 [ ! -f "$f" ] || error "$f was not deleted"
2604 run_test 34 "Remove file during restore"
2607 # test needs a running copytool
2610 local f=$DIR/$tdir/$tfile
2611 local f1=$DIR/$tdir/$tfile-1
2612 local fid=$(create_empty_file "$f")
2613 local fid1=$(copy_file /etc/passwd $f1)
2615 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2616 wait_request_state $fid ARCHIVE SUCCEED
2619 # Prevent restore from completing
2622 md5sum $f >/dev/null &
2625 wait_request_state $fid RESTORE STARTED
2627 # mv must not block during restore
2628 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2631 wait_request_state $fid RESTORE SUCCEED
2633 # Check md5sum pgm finished
2634 kill -0 $pid && error "Restore initiatior still running"
2635 wait $pid || error "Restore initiator failed with $?"
2637 local fid2=$(path2fid $f)
2638 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2640 run_test 35 "Overwrite file during restore"
2643 # test needs a running copytool
2646 local f=$DIR/$tdir/$tfile
2647 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
2656 md5sum $f >/dev/null &
2659 wait_request_state $fid RESTORE STARTED
2661 # mv must not block during restore
2662 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2663 error "mv '$f' '$f.new' failed with rc=$?"
2666 wait_request_state $fid RESTORE SUCCEED
2668 # Check md5sum pgm finished
2669 kill -0 $pid && error "Restore initiator is still running"
2670 wait $pid || error "Restore initiator failed with $?"
2672 run_test 36 "Move file during restore"
2675 # LU-5683: check that an archived dirty file can be rearchived.
2678 local f=$DIR/$tdir/$tfile
2681 fid=$(create_small_file $f) || error "cannot create small file"
2683 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2684 wait_request_state $fid ARCHIVE SUCCEED
2685 $LFS hsm_release $f || error "cannot release $f"
2687 # Allow previous archive request to expire from the actions log.
2688 wait_for_grace_delay
2691 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2693 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2694 wait_request_state $fid ARCHIVE SUCCEED
2696 run_test 37 "re-archive a dirty file"
2703 for n in $(seq 1 $count); do
2704 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2706 echo "$count archive requests submitted"
2710 local stream_count=4
2711 local file_count=100
2713 local f=$DIR/$tdir/$tfile
2717 local max_requests=$(get_hsm_param max_requests)
2719 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2720 # Increase the number of HSM request that can be performed in
2721 # parallel. With the coordinator running once per second, this
2722 # also limits the number of requests per seconds that can be
2723 # performed, so we pick a decent number. But we also need to keep
2724 # that number low because the copytool has no rate limit and will
2725 # fail some requests if if gets too many at once.
2726 set_hsm_param max_requests 300
2728 for i in $(seq 1 $file_count); do
2729 for p in $(seq 1 $stream_count); do
2730 fid=$(copy_file /etc/hosts $f.$p.$i)
2736 # to be sure wait_all_done will not be mislead by previous tests
2738 wait_for_grace_delay
2740 # start archive streams in background (archive files in parallel)
2741 for p in $(seq 1 $stream_count); do
2742 multi_archive $f.$p $file_count &
2745 echo -n "Wait for all requests being enqueued..."
2750 run_test 40 "Parallel archive requests"
2753 # test needs a running copytool
2757 local f=$DIR/$tdir/$tfile
2758 local fid=$(create_small_file $f)
2760 $LFS hsm_archive $f || error "could not archive file"
2761 wait_request_state $fid ARCHIVE SUCCEED
2762 check_hsm_flags $f "0x00000009"
2764 multiop_bg_pause $f O_c || error "multiop failed"
2768 client_up || client_up || true
2770 kill -USR1 $MULTIPID
2771 wait $MULTIPID || error "multiop close failed"
2773 check_hsm_flags $f "0x0000000b"
2775 run_test 52 "Opened for write file on an evicted client should be set dirty"
2778 # test needs a running copytool
2782 local f=$DIR/$tdir/$tfile
2783 local fid=$(create_small_file $f)
2785 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2786 error "could not archive file"
2787 wait_request_state $fid ARCHIVE SUCCEED
2788 check_hsm_flags $f "0x00000009"
2790 multiop_bg_pause $f o_c || error "multiop failed"
2794 client_up || client_up || true
2796 kill -USR1 $MULTIPID
2797 wait $MULTIPID || error "multiop close failed"
2799 check_hsm_flags $f "0x00000009"
2801 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2804 local f=$DIR/$tdir/$tfile
2805 local fid=$(create_file "$f" 1MB 39)
2809 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2810 error "could not archive file"
2811 wait_request_state $fid ARCHIVE STARTED
2813 check_hsm_flags $f "0x00000001"
2815 stack_trap "cdt_clear_no_retry" EXIT
2816 # Avoid coordinator resending this request as soon it has failed.
2821 wait_request_state $fid ARCHIVE FAILED
2823 check_hsm_flags $f "0x00000003"
2825 run_test 54 "Write during an archive cancels it"
2828 local f=$DIR/$tdir/$tfile
2829 local fid=$(create_file "$f" 1MB 39)
2833 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2834 error "could not archive file"
2835 wait_request_state $fid ARCHIVE STARTED
2837 check_hsm_flags $f "0x00000001"
2839 stack_trap "cdt_clear_no_retry" EXIT
2840 # Avoid coordinator resending this request as soon it has failed.
2843 $TRUNCATE $f 1024 || error "truncate failed"
2845 wait_request_state $fid ARCHIVE FAILED
2847 check_hsm_flags $f "0x00000003"
2849 run_test 55 "Truncate during an archive cancels it"
2852 local f=$DIR/$tdir/$tfile
2853 local fid=$(create_file "$f" 1MB 39)
2857 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2858 error "could not archive file"
2859 wait_request_state $fid ARCHIVE STARTED
2861 check_hsm_flags $f "0x00000001"
2863 # Change metadata and sync to be sure we are not changing only
2868 wait_request_state $fid ARCHIVE SUCCEED
2870 check_hsm_flags $f "0x00000009"
2872 run_test 56 "Setattr during an archive is ok"
2875 # Need one client for I/O, one for request
2876 needclients 2 || return 0
2878 # test needs a running copytool
2882 local f=$DIR/$tdir/test_archive_remote
2883 # Create a file on a remote node
2884 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2885 "count=2 conv=fsync"
2888 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2889 error "hsm_archive failed"
2890 local fid=$(path2fid $f)
2891 wait_request_state $fid ARCHIVE SUCCEED
2893 # Release and implicit restore it
2894 do_node $CLIENT2 "$LFS hsm_release $f" ||
2895 error "hsm_release failed"
2896 do_node $CLIENT2 "md5sum $f" ||
2897 error "hsm_restore failed"
2899 wait_request_state $fid RESTORE SUCCEED
2901 run_test 57 "Archive a file with dirty cache on another node"
2903 truncate_released_file() {
2907 local sz=$(stat -c %s $src_file)
2908 local f=$DIR/$tdir/$tfile
2909 local fid=$(copy_file $1 $f)
2913 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2914 error "could not archive file"
2915 wait_request_state $fid ARCHIVE SUCCEED
2917 $LFS hsm_release $f || error "could not release file"
2919 $TRUNCATE $f $trunc_to || error "truncate failed"
2922 local sz1=$(stat -c %s $f)
2923 [[ $sz1 == $trunc_to ]] ||
2924 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2927 check_hsm_flags $f "0x0000000b"
2929 local state=$(get_request_state $fid RESTORE)
2930 [[ "$state" == "SUCCEED" ]] ||
2931 error "truncate $sz does not trig restore, state = $state"
2933 $TRUNCATE $ref $trunc_to
2934 cmp $ref $f || error "file data wrong after truncate"
2940 # test needs a running copytool
2945 local sz=$(stat -c %s /etc/passwd)
2947 echo "truncate up from $sz to $((sz*2))"
2948 truncate_released_file /etc/passwd $((sz*2))
2950 echo "truncate down from $sz to $((sz/2))"
2951 truncate_released_file /etc/passwd $((sz/2))
2953 echo "truncate to 0"
2954 truncate_released_file /etc/passwd 0
2956 run_test 58 "Truncate a released file will trigger restore"
2960 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
2961 skip "Need MDS version at least 2.7.63"
2964 $MCREATE $DIR/$tfile || error "mcreate failed"
2965 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
2966 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
2967 fid=$(path2fid $DIR/$tfile)
2968 wait_request_state $fid ARCHIVE SUCCEED
2969 $LFS hsm_release $DIR/$tfile || error "release failed"
2971 run_test 59 "Release stripeless file with non-zero size"
2974 # This test validates the fix for LU-4512. Ensure that the -u
2975 # option changes the progress reporting interval from the
2976 # default (30 seconds) to the user-specified interval.
2977 local f=$DIR/$tdir/$tfile
2978 local fid=$(create_file "$f" 1M 10)
2981 local progress_timeout=$((interval * 4))
2982 copytool setup -b 1 --update-interval $interval
2985 local mdt=${MDT_PREFIX}${mdtidx}
2986 local mds=mds$((mdtidx + 1))
2988 # Wait for copytool to register
2989 wait_update_facet $mds \
2990 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2991 uuid 100 || error "coyptool failed to register with $mdt"
2993 local start_at=$(date +%s)
2994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2995 error "could not archive file"
2997 local agent=$(facet_active_host $SINGLEAGT)
2998 local logfile=$(copytool_logfile $SINGLEAGT)
3000 wait_update $agent \
3001 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3002 error "copytool failed to start"
3004 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3005 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3011 echo -n "Expecting a progress update within $progress_timeout seconds... "
3013 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3014 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3015 echo "$RESULT bytes copied in $WAIT seconds."
3017 elif [ $WAIT -ge $progress_timeout ]; then
3018 error "Timed out waiting for progress update!"
3021 WAIT=$((WAIT + sleep))
3025 local finish_at=$(date +%s)
3026 local elapsed=$((finish_at - start_at))
3028 # Ensure that the progress update occurred within the expected window.
3029 if [ $elapsed -lt $((interval - 1)) ]; then
3030 error "Expected progress update after at least $interval seconds"
3033 echo "Wait for on going archive hsm action to complete"
3034 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3035 echo "File archiving not completed even after 10 secs"
3037 run_test 60 "Changing progress update interval from default"
3040 # test needs a running copytool
3044 local f=$DIR/$tdir/$tfile
3045 local fid=$(copy_file /etc/passwd $f)
3047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3050 wait_request_state $fid ARCHIVE FAILED
3052 run_test 61 "Waiting archive of a removed file should fail"
3055 # test needs a new running copytool
3056 stack_trap copytool_monitor_cleanup EXIT
3057 copytool_monitor_setup
3058 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3060 # Wait for the copytool to register.
3061 wait_update --verbose $(facet_active_host mds1) \
3062 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3064 error "copytool failed to register with MDT0000"
3067 wait_copytools || error "Copytools failed to stop"
3069 local REGISTER_EVENT
3070 local UNREGISTER_EVENT
3071 while read event; do
3072 local parsed=$(parse_json_event "$event")
3073 if [ -z "$parsed" ]; then
3074 error "Copytool sent malformed event: $event"
3078 if [ $event_type == "REGISTER" ]; then
3079 REGISTER_EVENT=$event
3080 elif [ $event_type == "UNREGISTER" ]; then
3081 UNREGISTER_EVENT=$event
3083 done < <(echo $"$(get_copytool_event_log)")
3085 if [ -z "$REGISTER_EVENT" ]; then
3086 error "Copytool failed to send register event to FIFO"
3089 if [ -z "$UNREGISTER_EVENT" ]; then
3090 error "Copytool failed to send unregister event to FIFO"
3093 echo "Register/Unregister events look OK."
3095 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3098 # Bump progress interval for livelier events.
3101 # test needs a new running copytool
3102 stack_trap copytool_monitor_cleanup EXIT
3103 copytool_monitor_setup
3104 copytool setup --update-interval $interval --event-fifo \
3105 "$HSMTOOL_MONITOR_DIR/fifo"
3107 stack_trap "cdt_clear_no_retry" EXIT
3108 # Just start and stop the copytool to generate events.
3111 local f=$DIR/$tdir/$tfile
3112 local fid=$(create_small_file "$f")
3114 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3115 error "could not archive file"
3116 wait_request_state $fid ARCHIVE SUCCEED
3118 local expected_fields="event_time data_fid source_fid"
3119 expected_fields+=" total_bytes current_bytes"
3122 [ARCHIVE_START]=false
3123 [ARCHIVE_FINISH]=false
3124 [ARCHIVE_RUNNING]=false
3126 while read event; do
3127 # Make sure we're not getting anything from previous events.
3128 for field in $expected_fields; do
3132 local parsed=$(parse_json_event "$event")
3133 if [ -z "$parsed" ]; then
3134 error "Copytool sent malformed event: $event"
3138 events["$event_type"]=true
3140 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3142 # Do some simple checking of the progress update events.
3143 for expected_field in $expected_fields; do
3144 if [ -z ${!expected_field+x} ]; then
3145 error "Missing $expected_field field in event"
3149 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3151 # These should be identical throughout an archive operation
3152 [ $source_fid == $data_fid ] ||
3153 error "Expected source_fid to equal data_fid"
3154 done < <(echo $"$(get_copytool_event_log)")
3156 # Check we received every type of events we were expecting
3157 for event in "${!events[@]}"; do
3158 ${events["$event"]} ||
3159 error "Copytool failed to send '$event' event to FIFO"
3162 echo "Archive events look OK."
3164 run_test 71 "Copytool logs JSON archive events to FIFO"
3167 # Bump progress interval for livelier events.
3170 # test needs a new running copytool
3171 stack_trap copytool_monitor_cleanup EXIT
3172 copytool_monitor_setup
3173 copytool setup --update-interval $interval --event-fifo \
3174 "$HSMTOOL_MONITOR_DIR/fifo"
3175 local test_file=$HSMTOOL_MONITOR_DIR/file
3177 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3179 do_facet $SINGLEAGT "$cmd" ||
3180 error "cannot create $test_file on $SINGLEAGT"
3181 copy2archive $test_file $tdir/$tfile
3184 local f=$DIR/$tdir/$tfile
3185 copytool import $tdir/$tfile $f
3186 f=$DIR2/$tdir/$tfile
3187 echo "Verifying released state: "
3188 check_hsm_flags $f "0x0000000d"
3190 local fid=$(path2fid $f)
3192 wait_request_state $fid RESTORE SUCCEED
3194 local expected_fields="event_time data_fid source_fid"
3195 expected_fields+=" total_bytes current_bytes"
3199 while read event; do
3200 # Make sure we're not getting anything from previous events.
3201 for field in $expected_fields; do
3205 local parsed=$(parse_json_event "$event")
3206 if [ -z "$parsed" ]; then
3207 error "Copytool sent malformed event: $event"
3211 if [ $event_type == "RESTORE_START" ]; then
3213 if [ $source_fid != $data_fid ]; then
3214 error "source_fid should == data_fid at start"
3217 elif [ $event_type == "RESTORE_FINISH" ]; then
3219 if [ $source_fid != $data_fid ]; then
3220 error "source_fid should == data_fid at finish"
3223 elif [ $event_type != "RESTORE_RUNNING" ]; then
3227 # Do some simple checking of the progress update events.
3228 for expected_field in $expected_fields; do
3229 if [ -z ${!expected_field+x} ]; then
3230 error "Missing $expected_field field in event"
3234 if [ $total_bytes -eq 0 ]; then
3235 error "Expected total_bytes to be > 0"
3238 # When a restore starts out, the data fid is the same as the
3239 # source fid. After the restore has gotten going, we learn
3240 # the new data fid. Once the restore has finished, the source
3241 # fid is set to the new data fid.
3243 # We test this because some monitoring software may depend on
3244 # this behavior. If it changes, then the consumers of these
3245 # events may need to be modified.
3246 if [ $source_fid == $data_fid ]; then
3247 error "source_fid should != data_fid during restore"
3249 done < <(echo $"$(get_copytool_event_log)")
3251 if [ -z "$START_EVENT" ]; then
3252 error "Copytool failed to send restore start event to FIFO"
3255 if [ -z "$FINISH_EVENT" ]; then
3256 error "Copytool failed to send restore finish event to FIFO"
3259 echo "Restore events look OK."
3261 run_test 72 "Copytool logs JSON restore events to FIFO"
3264 file_count=51 # Max number of files constrained by LNET message size
3265 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3266 local f=$DIR/$tdir/$tfile
3267 local FILELIST=/tmp/filelist.txt
3271 for i in $(seq 1 $file_count); do
3272 fid=$(copy_file /etc/hosts $f.$i)
3273 echo $f.$i >> $FILELIST
3277 # to be sure wait_all_done will not be mislead by previous tests
3279 wait_for_grace_delay
3280 $LFS hsm_archive --filelist $FILELIST ||
3281 error "cannot archive a file list"
3283 $LFS hsm_release --filelist $FILELIST ||
3284 error "cannot release a file list"
3285 $LFS hsm_restore --filelist $FILELIST ||
3286 error "cannot restore a file list"
3289 run_test 90 "Archive/restore a file list"
3291 double_verify_reset_hsm_param() {
3293 echo "Testing $HSM_PARAM.$p"
3294 local val=$(get_hsm_param $p)
3296 local val2=$(($val * 2))
3297 set_hsm_param $p $val2
3298 val=$(get_hsm_param $p)
3299 [[ $val == $val2 ]] ||
3300 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3301 echo "Set $p to 0 must failed"
3305 set_hsm_param $p $save
3307 if [[ $rc == 0 ]]; then
3308 error "we must not be able to set $HSM_PARAM.$p to 0"
3313 double_verify_reset_hsm_param loop_period
3314 double_verify_reset_hsm_param grace_delay
3315 double_verify_reset_hsm_param active_request_timeout
3316 double_verify_reset_hsm_param max_requests
3317 double_verify_reset_hsm_param default_archive_id
3319 run_test 100 "Set coordinator /proc tunables"
3326 run_test 102 "Verify coordinator control"
3329 # test needs a running copytool
3336 for i in $(seq 1 20); do
3337 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3343 echo "Current requests"
3344 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3345 $HSM_PARAM.actions |\
3346 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3348 [[ -z "$res" ]] || error "Some request have not been canceled"
3350 run_test 103 "Purge all requests"
3355 local f=$DIR/$tdir/$tfile
3356 local fid=$(create_empty_file "$f")
3358 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3359 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3360 $HSM_PARAM.actions |\
3361 grep $fid | cut -f16 -d=")
3363 [[ "$data1" == "$DATAHEX" ]] ||
3364 error "Data field in records is ($data1) and not ($DATAHEX)"
3368 run_test 104 "Copy tool data field"
3371 local max_requests=$(get_hsm_param max_requests)
3375 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3376 set_hsm_param max_requests 300
3379 for i in $(seq -w 1 10); do
3380 cp /etc/passwd $DIR/$tdir/$i
3381 $LFS hsm_archive $DIR/$tdir/$i
3383 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3384 $HSM_PARAM.actions |\
3385 grep WAITING | wc -l")
3389 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3390 $HSM_PARAM.actions |\
3391 grep WAITING | wc -l")
3394 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3395 error "Requests count after shutdown $reqcnt2 != "\
3396 "before shutdown $reqcnt1"
3398 run_test 105 "Restart of coordinator"
3401 # test needs a running copytool
3404 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3406 check_agent_registered $uuid
3408 search_copytools || error "No copytool found"
3411 wait_copytools || error "Copytool failed to stop"
3413 check_agent_unregistered $uuid
3416 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3417 check_agent_registered $uuid
3419 run_test 106 "Copytool register/unregister"
3422 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3424 # test needs a running copytool
3426 # create and archive file
3428 local f1=$DIR/$tdir/$tfile
3429 local fid=$(copy_file /etc/passwd $f1)
3430 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3431 wait_request_state $fid ARCHIVE SUCCEED
3432 # shutdown and restart MDS
3434 # check the copytool still gets messages from MDT
3435 local f2=$DIR/$tdir/2
3436 local fid=$(copy_file /etc/passwd $f2)
3437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3438 # main check of this sanity: this request MUST succeed
3439 wait_request_state $fid ARCHIVE SUCCEED
3441 run_test 107 "Copytool re-register after MDS restart"
3443 policy_set_and_test()
3447 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3448 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3449 [[ "$policy" == "$target" ]] ||
3450 error "Wrong policy after '$change': '$policy' != '$target'"
3454 # to force default policy setting if error
3455 CDT_POLICY_HAD_CHANGED=true
3457 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3458 local default="NonBlockingRestore [NoRetryAction]"
3459 [[ "$policy" == "$default" ]] ||
3460 error "default policy has changed,"\
3461 " '$policy' != '$default' update the test"
3462 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3463 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3464 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3465 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3466 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3467 # useless bacause we know but safer for futur changes to use real value
3468 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3469 echo "Next set_param must failed"
3470 policy_set_and_test "wrong" "$policy"
3473 echo "Back to default policy"
3474 cdt_set_sanity_policy
3476 run_test 109 "Policy display/change"
3479 # test needs a running copytool
3484 copy2archive /etc/passwd $tdir/$tfile
3486 local f=$DIR/$tdir/$tfile
3487 copytool import $tdir/$tfile $f
3488 local fid=$(path2fid $f)
3490 cdt_set_non_blocking_restore
3495 wait_request_state $fid RESTORE SUCCEED
3496 cdt_clear_non_blocking_restore
3500 error "md5sum returns $st != 1, "\
3501 "should also perror ENODATA (No data available)"
3503 run_test 110a "Non blocking restore policy (import case)"
3506 # test needs a running copytool
3510 local f=$DIR/$tdir/$tfile
3511 local fid=$(copy_file /etc/passwd $f)
3512 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3513 wait_request_state $fid ARCHIVE SUCCEED
3516 cdt_set_non_blocking_restore
3521 wait_request_state $fid RESTORE SUCCEED
3522 cdt_clear_non_blocking_restore
3526 error "md5sum returns $st != 1, "\
3527 "should also perror ENODATA (No data available)"
3529 run_test 110b "Non blocking restore policy (release case)"
3532 # test needs a running copytool
3536 copy2archive /etc/passwd $tdir/$tfile
3538 local f=$DIR/$tdir/$tfile
3540 copytool import $tdir/$tfile $f
3541 local fid=$(path2fid $f)
3545 copytool_remove_backend $fid
3548 wait_request_state $fid RESTORE FAILED
3555 [[ $st == 0 ]] || error "Restore does not failed"
3557 run_test 111a "No retry policy (import case), restore will error"\
3558 " (No such file or directory)"
3561 # test needs a running copytool
3565 local f=$DIR/$tdir/$tfile
3566 local fid=$(copy_file /etc/passwd $f)
3567 stack_trap cdt_clear_no_retry EXIT
3569 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3570 wait_request_state $fid ARCHIVE SUCCEED
3573 copytool_remove_backend $fid
3576 wait_request_state $fid RESTORE FAILED
3580 [[ $st == 0 ]] || error "Restore does not failed"
3582 run_test 111b "No retry policy (release case), restore will error"\
3583 " (No such file or directory)"
3586 # test needs a running copytool
3590 local f=$DIR/$tdir/$tfile
3591 local fid=$(copy_file /etc/passwd $f)
3593 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3594 local l=$($LFS hsm_action $f)
3596 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3599 wait_request_state $fid ARCHIVE SUCCEED
3602 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3604 run_test 112 "State of recorded request"
3607 local file1=$DIR/$tdir/$tfile
3608 local file2=$DIR2/$tdir/$tfile
3610 local fid=$(create_small_sync_file $file1)
3612 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3613 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3614 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3616 copytool setup -m "$MOUNT3"
3618 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3620 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3621 wait_request_state $fid ARCHIVE SUCCEED
3623 $LFS hsm_release $file1
3624 echo "Verifying released state: "
3625 check_hsm_flags $file1 "0x0000000d"
3627 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3630 kill -USR1 $MULTIPID
3635 local size1=$(stat -c "%s" $file1)
3636 local size2=$(stat -c "%s" $file2)
3638 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3640 run_test 113 "wrong stat after restore"
3643 local f=$DIR/$tdir/$tfile
3644 local fid=$(create_empty_file "$f")
3648 # Prevent archive from completing
3651 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3652 # wait archive to register at CDT
3653 wait_request_state $fid ARCHIVE STARTED
3655 # Cancel the archive
3656 $LFS hsm_cancel "$f"
3658 wait_request_state $fid ARCHIVE CANCELED
3661 wait_request_state $fid CANCEL SUCCEED
3663 run_test 200 "Register/Cancel archive"
3666 # test needs a running copytool
3669 local f=$DIR/$tdir/$tfile
3670 create_archive_file $tdir/$tfile
3671 copytool import $tdir/$tfile $f
3672 local fid=$(path2fid $f)
3674 # test with cdt on is made in test_222
3677 # wait restore to register at CDT
3678 wait_request_state $fid RESTORE WAITING
3681 wait_request_state $fid RESTORE CANCELED
3682 wait_request_state $fid CANCEL SUCCEED
3684 run_test 201 "Register/Cancel restore"
3687 local f=$DIR/$tdir/$tfile
3688 local fid=$(create_empty_file "$f")
3690 # test needs a running copytool
3693 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3694 wait_request_state $fid ARCHIVE SUCCEED
3698 # wait remove to register at CDT
3699 wait_request_state $fid REMOVE STARTED
3702 wait_request_state $fid REMOVE CANCELED
3704 run_test 202 "Register/Cancel remove"
3706 test_220A() { # was test_220
3707 # test needs a running copytool
3712 local f=$DIR/$tdir/$tfile
3713 local fid=$(copy_file /etc/passwd $f)
3717 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3718 wait_request_state $fid ARCHIVE SUCCEED
3720 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3721 error "The expected changelog was not emitted"
3723 run_test 220A "Changelog for archive"
3726 # test needs a running copytool
3731 local f=$DIR/$tdir/$tfile
3732 local fid=$(copy_file /etc/passwd $f)
3736 # block copytool operations to allow for HSM request to be
3737 # submitted and file be unlinked (CDT will find object removed)
3740 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3742 # wait request to reach CT
3743 wait_request_state $fid ARCHIVE STARTED
3749 wait_request_state $fid ARCHIVE FAILED
3752 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3753 error "The expected changelog was not emitted"
3755 run_test 220a "Changelog for failed archive"
3758 local f=$DIR/$tdir/$tfile
3759 local fid=$(create_empty_file "$f")
3764 # Prevent archive from completing
3766 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3767 wait_request_state $fid ARCHIVE STARTED
3770 wait_request_state $fid ARCHIVE CANCELED
3773 wait_request_state $fid CANCEL SUCCEED
3775 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3776 error "The expected changelog was not emitted"
3778 run_test 221 "Changelog for archive canceled"
3781 # test needs a running copytool
3785 copy2archive /etc/passwd $tdir/$tfile
3787 local f=$DIR/$tdir/$tfile
3788 copytool import $tdir/$tfile $f
3789 local fid=$(path2fid $f)
3794 wait_request_state $fid RESTORE SUCCEED
3796 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3797 error "The expected changelog was not emitted"
3799 run_test 222a "Changelog for explicit restore"
3802 # test needs a running copytool
3806 local f=$DIR/$tdir/$tfile
3807 local fid=$(copy_file /etc/passwd $f)
3810 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3811 wait_request_state $fid ARCHIVE SUCCEED
3816 wait_request_state $fid RESTORE SUCCEED
3818 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3819 error "The expected changelog was not emitted"
3821 run_test 222b "Changelog for implicit restore"
3824 # test needs a running copytool
3828 copy2archive /etc/passwd $tdir/$tfile
3830 local f=$DIR/$tdir/$tfile
3831 copytool import $tdir/$tfile $f
3832 local fid=$(path2fid $f)
3836 # block copytool operations to allow for HSM request to be
3837 # submitted and file be unlinked (CDT will find object removed)
3842 # wait request to reach CT
3843 wait_request_state $fid RESTORE STARTED
3849 wait_request_state $fid RESTORE FAILED
3852 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3853 error "The expected changelog was not emitted"
3855 run_test 222c "Changelog for failed explicit restore"
3858 # test needs a running copytool
3862 local f=$DIR/$tdir/$tfile
3863 local fid=$(copy_file /etc/passwd $f)
3866 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3867 wait_request_state $fid ARCHIVE SUCCEED
3870 copytool_remove_backend $fid
3873 wait_request_state $fid RESTORE FAILED
3876 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3877 error "The expected changelog was not emitted"
3879 run_test 222d "Changelog for failed implicit restore"
3882 # test needs a running copytool
3885 local f=$DIR/$tdir/$tfile
3886 create_archive_file $tdir/$tfile
3890 copytool import $tdir/$tfile $f
3891 local fid=$(path2fid $f)
3894 wait_request_state $fid RESTORE STARTED
3896 wait_request_state $fid RESTORE CANCELED
3897 wait_request_state $fid CANCEL SUCCEED
3899 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3900 error "The expected changelog was not emitted"
3902 run_test 223a "Changelog for restore canceled (import case)"
3905 local f=$DIR/$tdir/$tfile
3906 local fid=$(create_empty_file "$f")
3911 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3912 wait_request_state $fid ARCHIVE SUCCEED
3915 # Prevent restore from completing
3918 wait_request_state $fid RESTORE STARTED
3921 wait_request_state $fid RESTORE CANCELED
3924 wait_request_state $fid CANCEL SUCCEED
3926 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
3927 error "The expected changelog was not emitted"
3929 run_test 223b "Changelog for restore canceled (release case)"
3931 test_224A() { # was test_224
3932 # test needs a running copytool
3937 local f=$DIR/$tdir/$tfile
3938 local fid=$(copy_file /etc/passwd $f)
3941 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3942 wait_request_state $fid ARCHIVE SUCCEED
3945 wait_request_state $fid REMOVE SUCCEED
3947 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
3948 error "The expected changelog was not emitted"
3950 run_test 224A "Changelog for remove"
3953 # test needs a running copytool
3958 local f=$DIR/$tdir/$tfile
3959 local fid=$(copy_file /etc/passwd $f)
3962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3963 wait_request_state $fid ARCHIVE SUCCEED
3965 copytool_remove_backend $fid
3967 # block copytool operations to allow for HSM request to be
3968 # submitted and file be unlinked (CDT will find object removed)
3973 # wait for request to reach CT
3974 wait_request_state $fid REMOVE STARTED
3980 wait_request_state $fid REMOVE FAILED
3982 # HE_REMOVE|ENOENT=0x202
3983 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
3984 error "The expected changelog was not emitted"
3986 run_test 224a "Changelog for failed remove"
3989 # test is not usable because remove request is too fast
3990 # so it is always finished before cancel can be done ...
3991 echo "Test disabled"
3994 # test needs a running copytool
3997 local f=$DIR/$tdir/$tfile
3998 local fid=$(create_empty_file "$f")
4001 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4002 wait_request_state $fid ARCHIVE SUCCEED
4004 # Prevent restore from completing
4009 wait_request_state $fid REMOVE CANCELED
4012 wait_request_state $fid CANCEL SUCCEED
4014 changelog_find -type HSM -target-fid $fid -flags 0x27d
4015 error "The expected changelog was not emitted"
4017 run_test 225 "Changelog for remove canceled"
4020 # test needs a running copytool
4025 local f1=$DIR/$tdir/$tfile-1
4026 local f2=$DIR/$tdir/$tfile-2
4027 local f3=$DIR/$tdir/$tfile-3
4028 local fid1=$(copy_file /etc/passwd $f1)
4029 local fid2=$(copy_file /etc/passwd $f2)
4030 copy_file /etc/passwd $f3
4033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4034 wait_request_state $fid1 ARCHIVE SUCCEED
4036 $LFS hsm_archive $f2
4037 wait_request_state $fid2 ARCHIVE SUCCEED
4039 rm $f1 || error "rm $f1 failed"
4042 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4043 error "The expected changelog was not emitted"
4045 mv $f3 $f2 || error "mv $f3 $f2 failed"
4047 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4048 error "The expected changelog was not emitted"
4050 run_test 226 "changelog for last rm/mv with exiting archive"
4052 # This is just a utility function to clarify what test_227 does
4057 "$LFS" "$action" --$flag "$file" ||
4058 error "Cannot ${action#hsm_} $flag on '$file'"
4060 # Only one changelog should be produced
4061 local entries="$(changelog_find -type HSM -target-fid $fid)"
4062 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4063 error "lfs $action --$flag '$file' produced more than one" \
4066 # Parse the last changelog record
4067 local entry="$(tail -n 1 <<< "$entries")"
4068 eval local -A changelog=$(changelog2array $entry)
4070 # Also check the flags match what is expected
4071 [[ ${changelog[flags]} == $target ]] ||
4072 error "Changelog flag is '${changelog[flags]}', not $target"
4076 local file="$DIR/$tdir/$tfile"
4077 local fid=$(create_empty_file "$file")
4082 for flag in norelease noarchive exists archived lost; do
4083 if [ "$flag" == lost ]; then
4084 # The flag "lost" only works on an archived file
4085 "$LFS" hsm_set --archived "$file"
4089 action="hsm_set" __test_227
4090 action="hsm_clear" __test_227
4093 run_test 227 "changelog when explicit setting of HSM flags"
4096 # test needs a running copytool
4099 local fid=$(create_small_sync_file $DIR/$tfile)
4100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4101 wait_request_state $fid ARCHIVE SUCCEED
4103 $LFS hsm_release $DIR/$tfile
4104 check_hsm_flags $DIR/$tfile "0x0000000d"
4106 filefrag $DIR/$tfile | grep " 1 extent found" ||
4107 error "filefrag on released file must return only one extent"
4109 # only newer versions of cp detect sparse files by stat/FIEMAP
4111 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4112 error "copying $DIR/$tfile"
4113 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4115 $LFS hsm_release $DIR/$tfile
4116 check_hsm_flags $DIR/$tfile "0x0000000d"
4118 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4120 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4122 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4123 error "comparing untarred $DIR/$tfile"
4125 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4126 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4128 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4131 local file="$DIR/$tdir/$tfile"
4133 # set max_requests to allow one request of each type to be started (3)
4135 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4136 set_hsm_param max_requests 3
4139 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4140 set_hsm_param loop_period 1
4142 # send 1 requests of each kind twice
4145 for action in archive restore remove; do
4146 local filepath="$file"-to-$action
4147 local fid=$(create_empty_file "$filepath")
4148 local fid2=$(create_empty_file "$filepath".bis)
4150 if [ "$action" != archive ]; then
4151 "$LFS" hsm_archive "$filepath"
4152 wait_request_state $fid ARCHIVE SUCCEED
4153 "$LFS" hsm_archive "$filepath".bis
4154 wait_request_state $fid2 ARCHIVE SUCCEED
4156 if [ "$action" == restore ]; then
4157 "$LFS" hsm_release "$filepath"
4158 "$LFS" hsm_release "$filepath".bis
4162 # suspend the copytool to prevent requests from completing
4163 stack_trap "copytool_continue" EXIT
4166 # send `max_requests' requests (one of each kind)
4167 for action in archive restore remove; do
4168 filepath="$file"-to-$action
4169 "$LFS" hsm_${action} "$filepath"
4170 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4173 # send another batch of requests
4174 for action in archive restore remove; do
4175 "$LFS" hsm_${action} "$file-to-$action".bis
4177 # wait for `loop_period' seconds to make sure the coordinator has time
4178 # to register those, even though it should not
4181 # only the first batch of request should be started
4183 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4187 error "expected 3 STARTED requests, found $count"
4189 run_test 250 "Coordinator max request"
4192 local f=$DIR/$tdir/$tfile
4193 local fid=$(create_empty_file "$f")
4196 # to have a short test
4197 local old_to=$(get_hsm_param active_request_timeout)
4198 set_hsm_param active_request_timeout 1
4199 # to be sure the cdt will wake up frequently so
4200 # it will be able to cancel the "old" request
4201 local old_loop=$(get_hsm_param loop_period)
4202 set_hsm_param loop_period 1
4207 # Prevent archive from completing
4209 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4210 wait_request_state $fid ARCHIVE STARTED
4212 # Let the request timeout
4213 wait_request_state $fid ARCHIVE CANCELED
4215 set_hsm_param active_request_timeout $old_to
4216 set_hsm_param loop_period $old_loop
4218 run_test 251 "Coordinator request timeout"
4221 local f=$DIR/$tdir/$tfile
4222 local fid=$(create_empty_file "$f")
4224 # to have a short test
4225 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4226 set_hsm_param loop_period 1
4230 # Prevent archive from completing
4232 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4233 wait_request_state $fid ARCHIVE STARTED
4236 stack_trap "set_hsm_param active_request_timeout \
4237 $(get_hsm_param active_request_timeout)" EXIT
4238 set_hsm_param active_request_timeout 1
4240 wait_request_state $fid ARCHIVE CANCELED
4243 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4247 # test needs a running copytool
4251 local f=$DIR/$tdir/$tfile
4253 dd if=/dev/zero of=$f bs=1MB count=10
4254 local fid=$(path2fid $f)
4256 $LFS hsm_archive $f || error "could not archive file"
4257 wait_request_state $fid ARCHIVE SUCCEED
4259 # clear locks to discard inode data
4260 cancel_lru_locks osc
4262 #define OBD_FAIL_MDC_MERGE 0x807
4263 $LCTL set_param fail_loc=0x807
4265 #expect error here, instead of release with wrong size
4268 if ((rc == 0)); then
4269 file_size=$(stat -c '%s' $f)
4270 if ((file_size != 10485760)); then
4271 error "Wrong file size after hsm_release"
4274 echo "could not release file"
4277 run_test 253 "Check for wrong file size after release"
4281 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4282 skip "need MDS version at least 2.10.56"
4284 # Check that the counters are initialized to 0
4286 for request_type in archive restore remove; do
4287 count="$(get_hsm_param ${request_type}_count)" ||
4288 error "Reading ${request_type}_count failed with $?"
4290 [ "$count" -eq 0 ] ||
4291 error "Expected ${request_type}_count to be " \
4295 run_test 254a "Request counters are initialized to zero"
4299 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4300 skip "need MDS version at least 2.10.56"
4302 # The number of request to launch (at least 32)
4303 local request_count=$((RANDOM % 32 + 32))
4304 printf "Will launch %i requests of each type\n" "$request_count"
4306 # Launch a copytool to process requests
4309 # Set hsm.max_requests to allow starting all requests at the same time
4311 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4312 set_hsm_param max_requests "$request_count"
4316 for request_type in archive restore remove; do
4317 printf "Checking %s requests\n" "${request_type}"
4318 # Suspend the copytool to give us time to read the proc files
4321 for ((i = 0; i < $request_count; i++)); do
4322 case $request_type in
4324 create_empty_file "$DIR/$tdir/$tfile-$i" \
4328 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4331 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4334 # Give the coordinator 10 seconds to start every request
4336 while get_hsm_param actions | grep -q WAITING; do
4339 [ $timeout -gt 0 ] ||
4340 error "${request_type^} requests took too " \
4344 count="$(get_hsm_param ${request_type}_count)"
4345 [ "$count" -eq "$request_count" ] ||
4346 error "Expected '$request_count' (!= '$count') " \
4347 "active $request_type requests"
4349 # Let the copytool process the requests
4351 # Give it 10 seconds maximum
4353 while get_hsm_param actions | grep -q STARTED; do
4356 [ $timeout -gt 0 ] ||
4357 error "${request_type^} requests took too " \
4361 count="$(get_hsm_param ${request_type}_count)"
4362 [ "$count" -eq 0 ] ||
4363 error "Expected 0 (!= '$count') " \
4364 "active $request_type requests"
4367 run_test 254b "Request counters are correctly incremented and decremented"
4371 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4372 skip "Need MDS version at least 2.12.0"
4374 local file="$DIR/$tdir/$tfile"
4375 local fid=$(create_empty_file "$file")
4377 # How do you make sure the coordinator has consumed any outstanding
4378 # event, without triggering an event yourself?
4380 # You wait for a request to disappear from the coordinator's llog.
4382 # Warning: the setup represents 90% of this test
4384 # Create and process an HSM request
4386 "$LFS" hsm_archive "$file"
4387 wait_request_state $fid ARCHIVE SUCCEED
4390 wait_copytools || error "failed to stop copytools"
4392 # Launch a new HSM request
4394 create_empty_file "$file"
4395 "$LFS" hsm_archive "$file"
4399 # Have the completed request be removed as soon as the cdt wakes up
4400 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4401 set_hsm_param grace_delay 1
4402 # (Hopefully, time on the MDS will behave nicely)
4403 do_facet $SINGLEMDS sleep 2 &
4405 # Increase `loop_period' as a mean to prevent the coordinator from
4406 # waking itself up to do some housekeeping.
4407 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4408 set_hsm_param loop_period 1000
4410 wait $! || error "waiting failed"
4412 wait_request_state $fid ARCHIVE ""
4413 # The coordinator will not wake up on its own for ~`loop_period' secs...
4415 # ... Unless a copytool registers. Now the real test begins
4417 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4419 run_test 255 "Copytool registration wakes the coordinator up"
4421 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4422 # break in the future because of that.
4425 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4426 skip "need MDS version 2.11.56 or later"
4428 local -a files=("$DIR/$tdir/$tfile".{0..15})
4431 for file in "${files[@]}"; do
4432 create_small_file "$file"
4435 # Set a few hsm parameters
4437 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4438 set_hsm_param loop_period 1
4440 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4441 set_hsm_param max_requests 3
4445 "$LFS" hsm_archive "${files[0]}"
4446 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4447 "$LFS" hsm_release "${files[0]}"
4451 wait_copytools || error "copytools failed to stop"
4453 # Send several archive requests
4454 for file in "${files[@]:1}"; do
4455 "$LFS" hsm_archive "$file"
4458 # Send one restore request
4459 "$LFS" hsm_restore "${files[0]}"
4464 # Wait for all the requests to complete
4465 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4466 for file in "${files[@]:1}"; do
4467 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4470 # Collect the actions in the order in which the copytool processed them
4472 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4473 "$(copytool_logfile "$SINGLEAGT")")
4476 printf '%s\n' "${actions[@]}"
4479 for action in "${actions[@]:0:3}"; do
4480 [ "$action" == RESTORE ] && return
4483 error "Too many ARCHIVE requests were run before the RESTORE request"
4485 run_test 260a "Restore request have priority over other requests"
4487 # This test is very much tied to the implementation of the current priorisation
4488 # mechanism in the coordinator. It might not make sense to keep it in the future
4491 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4492 skip "need MDS version 2.11.56 or later"
4494 local -a files=("$DIR/$tdir/$tfile".{0..15})
4497 for file in "${files[@]}"; do
4498 create_small_file "$file"
4501 # Set a few hsm parameters
4503 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4504 set_hsm_param loop_period 1
4506 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4507 set_hsm_param max_requests 3
4510 copytool setup --archive-id 2
4511 "$LFS" hsm_archive --archive 2 "${files[0]}"
4512 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4513 "$LFS" hsm_release "${files[0]}"
4517 wait_copytools || error "copytools failed to stop"
4519 # Send several archive requests
4520 for file in "${files[@]:1}"; do
4521 "$LFS" hsm_archive "$file"
4524 # Send one restore request
4525 "$LFS" hsm_restore "${files[0]}"
4529 copytool setup --archive-id 2
4531 # Wait for all the requests to complete
4532 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4533 for file in "${files[@]:1}"; do
4534 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4537 # Collect the actions in the order in which the copytool processed them
4539 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4540 "$(copytool_logfile "$SINGLEAGT")")
4543 printf '%s\n' "${actions[@]}"
4546 for action in "${actions[@]:0:3}"; do
4547 [ "$action" == RESTORE ] && return
4550 error "Too many ARCHIVE requests were run before the RESTORE request"
4552 run_test 260b "Restore request have priority over other requests"
4554 # This test is very much tied to the implementation of the current priorisation
4555 # mechanism in the coordinator. It might not make sense to keep it in the future
4558 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4559 skip "Need MDS version at least 2.12.0"
4561 local -a files=("$DIR/$tdir/$tfile".{0..15})
4564 for file in "${files[@]}"; do
4565 create_small_file "$file"
4568 # Set a few hsm parameters
4570 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4571 set_hsm_param loop_period 1000
4573 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4574 set_hsm_param max_requests 3
4577 copytool setup --archive-id 2
4578 "$LFS" hsm_archive --archive 2 "${files[0]}"
4579 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4580 "$LFS" hsm_release "${files[0]}"
4584 wait_copytools || error "copytools failed to stop"
4586 # Force the next coordinator run to do housekeeping
4590 "$LFS" hsm_archive "${files[1]}"
4594 copytool setup --archive-id 2
4596 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4597 # The coordinator just did a housekeeping run it won't do another one
4598 # for around `loop_period' seconds => requests will not be reordered
4599 # if it costs too much (ie. when the coordinator has to discard a whole
4602 # Send several archive requests
4603 for file in "${files[@]:2}"; do
4604 "$LFS" hsm_archive "$file"
4607 # Send one restore request
4608 "$LFS" hsm_restore "${files[0]}"
4610 # Wait for all the requests to complete
4611 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4612 for file in "${files[@]:2}"; do
4613 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4616 # Collect the actions in the order in which the copytool processed them
4618 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4619 "$(copytool_logfile "$SINGLEAGT")")
4622 printf '%s\n' "${actions[@]}"
4625 for action in "${actions[@]:0:3}"; do
4626 [ "$action" == RESTORE ] &&
4627 error "Restore requests should not be prioritised" \
4628 "unless the coordinator is doing housekeeping"
4632 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4635 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4637 # the only way to test ondisk conf is to restart MDS ...
4638 echo "Stop coordinator and remove coordinator state at mount"
4641 # clean on disk conf set by default
4642 cdt_clear_mount_state
4643 cdt_check_state stopped
4645 # check cdt still off after umount/remount
4647 cdt_check_state stopped
4649 echo "Set coordinator start at mount, and start coordinator"
4650 cdt_set_mount_state enabled
4653 cdt_check_state enabled
4655 # check cdt still on after umount/remount
4657 cdt_check_state enabled
4659 # we are back to original state (cdt started at mount)
4661 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4664 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4666 local ai=$(get_hsm_param default_archive_id)
4667 local new=$((ai + 1))
4669 set_hsm_param default_archive_id $new -P
4671 local res=$(get_hsm_param default_archive_id)
4674 set_hsm_param default_archive_id "" "-P -d"
4676 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4678 run_test 301 "HSM tunnable are persistent"
4681 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4683 local ai=$(get_hsm_param default_archive_id)
4684 local new=$((ai + 1))
4689 set_hsm_param default_archive_id $new -P
4692 for mdtno in $(seq 1 $MDSCOUNT); do
4697 cdt_check_state enabled
4699 local res=$(get_hsm_param default_archive_id)
4702 set_hsm_param default_archive_id "" "-P -d"
4704 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4706 run_test 302 "HSM tunnable are persistent when CDT is off"
4709 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4715 local dir_mdt0=$DIR/$tdir/mdt0
4716 local dir_mdt1=$DIR/$tdir/mdt1
4718 # create 1 dir per MDT
4719 stack_trap "rm -rf $dir_mdt0" EXIT
4720 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4721 stack_trap "rm -rf $dir_mdt1" EXIT
4722 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4724 # create 1 file in each MDT
4725 local fid1=$(create_small_file $dir_mdt0/$tfile)
4726 local fid2=$(create_small_file $dir_mdt1/$tfile)
4728 # check that hsm request on mdt0 is sent to the right MDS
4729 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4730 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4731 echo "archive successful on mdt0"
4733 # check that hsm request on mdt1 is sent to the right MDS
4734 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4735 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4736 echo "archive successful on mdt1"
4738 run_test 400 "Single request is sent to the right MDT"
4741 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4747 local dir_mdt0=$DIR/$tdir/mdt0
4748 local dir_mdt1=$DIR/$tdir/mdt1
4750 # create 1 dir per MDT
4751 stack_trap "rm -rf $dir_mdt0" EXIT
4752 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4753 stack_trap "rm -rf $dir_mdt1" EXIT
4754 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4756 # create 1 file in each MDT
4757 local fid1=$(create_small_file $dir_mdt0/$tfile)
4758 local fid2=$(create_small_file $dir_mdt1/$tfile)
4760 # check that compound requests are shunt to the rights MDTs
4761 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4762 error "lfs hsm_archive"
4763 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4764 echo "archive successful on mdt0"
4765 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4766 echo "archive successful on mdt1"
4768 run_test 401 "Compound requests split and sent to their respective MDTs"
4770 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4775 local node=$(facet_active_host $facet)
4777 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4778 awk '{print $4}'); do
4779 echo "$3 $mdc on $node"
4780 do_facet $facet "$LCTL --device $mdc $state" || return 1
4785 # deactivate all mdc on agent1
4786 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4788 copytool setup --no-fail
4790 check_agent_unregistered "uuid" # match any agent
4792 # no expected running copytool
4793 search_copytools $agent && error "Copytool start should have failed"
4796 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4798 run_test 402a "Copytool start fails if all MDTs are inactive"
4805 local f=$DIR/$tdir/$tfile
4806 touch $f || error "touch $f failed"
4807 local fid=$(path2fid $f)
4809 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4810 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4811 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4813 # give time for CDT to send request and to keep it for retry
4814 wait_for_loop_period
4816 wait_request_state $fid ARCHIVE WAITING
4818 do_facet $SINGLEAGT lctl set_param fail_loc=0
4820 # request should succeed now
4821 wait_request_state $fid ARCHIVE SUCCEED
4823 run_test 402b "CDT must retry request upon slow start of CT"
4826 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4828 local agent=$(facet_active_host $SINGLEAGT)
4830 # deactivate all mdc for MDT0001
4831 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4834 local uuid=$(get_agent_uuid $agent)
4835 # check the agent is registered on MDT0000, and not on MDT0001
4836 check_agent_registered_by_mdt $uuid 0
4837 check_agent_unregistered_by_mdt $uuid 1
4839 # check running copytool process
4840 search_copytools $agent || error "No running copytools on $agent"
4842 # reactivate all mdc for MDT0001
4843 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4845 # make sure the copytool is now registered to all MDTs
4846 check_agent_registered $uuid
4848 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4851 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4855 # create files on both MDT0000 and MDT0001
4858 local dir_mdt0=$DIR/$tdir/mdt0
4859 stack_trap "rm -rf $dir_mdt0" EXIT
4860 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4862 # create 1 file on mdt0
4863 local fid1=$(create_small_file $dir_mdt0/$tfile)
4865 # deactivate all mdc for MDT0001
4866 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4868 # send an HSM request for files in MDT0000
4869 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4871 # check for completion of files in MDT0000
4872 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4873 echo "archive successful on mdt0"
4875 # reactivate all mdc for MDT0001
4876 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4878 run_test 404 "Inactive MDT does not block requests for active MDTs"
4881 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4887 local striped_dir=$DIR/$tdir/striped_dir
4889 # create striped dir on all of MDTs
4890 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4892 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4893 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4894 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4895 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4897 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4898 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4899 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4900 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4902 # check that compound requests are shunt to the rights MDTs
4903 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4904 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4905 error "lfs hsm_archive"
4907 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4908 echo "archive successful on $fid1"
4909 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4910 echo "archive successful on $fid2"
4911 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4912 echo "archive successful on $fid3"
4913 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4914 echo "archive successful on $fid4"
4916 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4917 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4918 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4919 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4921 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4922 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4923 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4924 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4926 run_test 405 "archive and release under striped directory"
4929 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4931 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
4932 skip "need MDS version at least 2.7.64"
4937 fid=$(create_small_file $DIR/$tdir/$tfile)
4942 $LFS hsm_archive $DIR/$tdir/$tfile
4943 wait_request_state "$fid" ARCHIVE SUCCEED
4944 $LFS hsm_release $DIR/$tdir/$tfile
4946 # Should migrate $tdir but not $tfile.
4947 $LFS migrate -m1 $DIR/$tdir &&
4948 error "migrating HSM an archived file should fail"
4950 $LFS hsm_restore $DIR/$tdir/$tfile
4951 wait_request_state "$fid" RESTORE SUCCEED
4953 $LFS hsm_remove $DIR/$tdir/$tfile
4954 wait_request_state "$fid" REMOVE SUCCEED
4956 cat $DIR/$tdir/$tfile > /dev/null ||
4957 error "cannot read $DIR/$tdir/$tfile"
4959 $LFS migrate -m1 $DIR/$tdir ||
4960 error "cannot complete migration after HSM remove"
4962 mdt_index=$($LFS getstripe -m $DIR/$tdir)
4963 if ((mdt_index != 1)); then
4964 error "expected MDT index 1, got $mdt_index"
4967 # Refresh fid after migration.
4968 fid=$(path2fid $DIR/$tdir/$tfile)
4971 $LFS hsm_archive $DIR/$tdir/$tfile
4972 wait_request_state "$fid" ARCHIVE SUCCEED 1
4974 lctl set_param debug=+trace
4975 $LFS hsm_release $DIR/$tdir/$tfile ||
4976 error "cannot release $DIR/$tdir/$tfile"
4978 $LFS hsm_restore $DIR/$tdir/$tfile
4979 wait_request_state "$fid" RESTORE SUCCEED 1
4981 cat $DIR/$tdir/$tfile > /dev/null ||
4982 error "cannot read $DIR/$tdir/$tfile"
4984 run_test 406 "attempting to migrate HSM archived files is safe"
4987 local f=$DIR/$tdir/$tfile
4988 local f2=$DIR2/$tdir/$tfile
4989 local fid=$(create_empty_file "$f")
4993 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4994 wait_request_state $fid ARCHIVE SUCCEED
4997 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
4998 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5000 # Prevent restore from completing
5004 # 1st request holds layout lock while appropriate
5005 # RESTORE record is still not added to llog
5009 # after umount hsm_actions->O/x/x log shouldn't have
5010 # double RESTORE records like below
5011 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5012 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5014 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5018 wait_request_state $fid RESTORE SUCCEED
5020 run_test 407 "Check for double RESTORE records in llog"
5024 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5025 skip "HSM migrate is not supported"
5027 test_mkdir -p $DIR/$tdir
5029 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5030 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5032 llapi_hsm_test -d $DIR/$tdir -b ||
5033 error "One llapi HSM test failed"
5035 llapi_hsm_test -d $DIR/$tdir ||
5036 error "One llapi HSM test failed"
5039 run_test 500 "various LLAPI HSM tests"
5042 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5043 skip "need MDS version at least 2.10.58"
5047 local f=$DIR/$tdir/$tfile
5050 # set changelog_mask to ALL
5051 changelog_chmask "ALL"
5053 chmod 777 $DIR/$tdir
5054 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5055 local fid=$(path2fid $f)
5058 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5059 -gid "$RUNAS_GID") ||
5060 error "No matching CREAT entry"
5062 # Parse the changelog
5063 eval local -A changelog=$(changelog2array $entry)
5064 local nid="${changelog[nid]}"
5067 echo "Got NID '$nid'"
5068 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5069 error "nid '$nid' does not match any client NID:" \
5072 run_test 600 "Changelog fields 'u=' and 'nid='"
5075 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5076 skip "need MDS version at least 2.10.58"
5080 local f=$DIR/$tdir/$tfile
5083 # set changelog_mask to ALL
5084 changelog_chmask "ALL"
5086 touch $f || error "touch $f failed"
5087 local fid=$(path2fid $f)
5090 cat $f || error "cat $f failed"
5092 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5093 error "No matching OPEN entry"
5095 run_test 601 "OPEN Changelog entry"
5098 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5099 skip "need MDS version at least 2.10.58"
5103 local f=$DIR/$tdir/$tfile
5106 # set changelog_mask to ALL
5107 changelog_chmask "ALL"
5109 touch $f || error "touch $f failed"
5110 local fid=$(path2fid $f)
5113 cat $f || error "cat $f failed"
5115 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5119 echo f > $f || error "write $f failed"
5122 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5124 # remove OPEN from changelog_mask
5125 changelog_chmask "-OPEN"
5129 cat $f || error "cat $f failed"
5132 changelog_find -type CLOSE -target-fid $fid &&
5133 error "There should be no CLOSE entry"
5137 echo f > $f || error "write $f failed"
5140 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5142 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5145 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5146 skip "need MDS version at least 2.10.58"
5150 local f=$DIR/$tdir/$tfile
5153 # set changelog_mask to ALL
5154 changelog_chmask "ALL"
5156 touch $f || error "touch $f failed"
5157 local fid=$(path2fid $f)
5159 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5162 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5164 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5165 error "No matching GXATR entry"
5167 run_test 603 "GETXATTR Changelog entry"
5170 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5171 skip "need MDS version at least 2.10.58"
5175 local f=$DIR/$tdir/$tfile
5176 local f2=$DIR2/$tdir/$tfile
5177 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5179 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5180 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5181 do_facet mds1 lctl set_param "$procname=20"
5185 # set changelog_mask to ALL
5186 changelog_chmask "ALL"
5188 touch $f || error "touch $f failed"
5189 local fid=$(path2fid $f)
5195 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5199 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5200 -gid "$RUNAS_GID" -mode "r--") ||
5201 error "No matching NOPEN entry"
5203 # Parse the changelog
5204 eval local -A changelog=$(changelog2array $entry)
5205 local nid="${changelog[nid]}"
5208 echo "Got NID '$nid'"
5209 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5210 error "nid '$nid' does not match any client NID:" \
5215 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5218 changelog_find -type NOPEN -target-fid $fid &&
5219 error "There should be no NOPEN entry"
5221 # Sleep for `changelog_deniednext` seconds
5226 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5229 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5230 -gid "$RUNAS_GID" -mode "r--") ||
5231 error "No matching NOPEN entry"
5233 # Parse the changelog
5234 eval local -A changelog=$(changelog2array $entry)
5235 local nid="${changelog[nid]}"
5238 echo "Got NID '$nid'"
5239 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5240 error "nid '$nid' does not match any client NID:" \
5243 run_test 604 "NOPEN Changelog entry"
5246 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5247 skip "need MDS version at least 2.10.58"
5251 local f=$DIR/$tdir/$tfile
5252 local f2=$DIR2/$tdir/$tfile
5255 # set changelog_mask to ALL
5256 changelog_chmask "ALL"
5258 touch $f || error "touch $f failed"
5259 local fid=$(path2fid $f)
5263 exec 3<> $f || error "open $f failed"
5267 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5271 exec 4<> $f || error "open $f failed"
5274 changelog_find -type OPEN -target-fid $fid &&
5275 error "There should be no OPEN entry"
5277 exec 4>&- || error "close $f failed"
5280 changelog_find -type CLOSE -target-fid $fid &&
5281 error "There should be no CLOSE entry"
5285 # access in rw, so different access mode should generate entries
5286 cat $f || error "cat $f failed"
5289 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5291 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5295 # same access as first one, should not generate new entries
5296 exec 4<> $f || error "open $f failed"
5299 changelog_find -type OPEN -target-fid $fid &&
5300 error "There should be no OPEN entry"
5302 exec 4>&- || error "close $f failed"
5305 changelog_find -type CLOSE -target-fid $fid &&
5306 error "There should be no CLOSE entry"
5310 # access by different user should generate new entries
5311 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5314 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5316 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5320 exec 3>&- || error "close $f failed"
5323 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5325 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5328 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5329 skip "need MDS version at least 2.10.58"
5331 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5332 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5333 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5334 skip_env "missing llog_reader" && return
5335 local fstype=$(facet_fstype mds1)
5339 local f=$DIR/$tdir/$tfile
5342 # set changelog_mask to ALL
5343 changelog_chmask "ALL"
5345 chmod 777 $DIR/$tdir
5346 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5347 local fid=$(path2fid $f)
5348 rm $f || error "rm $f failed"
5350 local mntpt=$(facet_mntpt mds1)
5354 #remount mds1 as ldiskfs or zfs type
5355 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5356 stop mds1 || error "stop mds1 failed"
5357 mount_fstype mds1 || error "remount mds1 failed"
5359 for ((i = 0; i < 1; i++)); do
5360 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5361 local cat_file=$(do_facet mds1 $llog_reader \
5362 $mntpt/changelog_catalog | awk \
5363 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5364 [ -n "$cat_file" ] || error "no catalog file"
5366 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5367 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5368 [ -n "$entry" ] || error "no CREAT entry"
5371 local uidgid=$(echo $entry |
5372 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5373 [ -n "$uidgid" ] || error "uidgid is empty"
5374 echo "Got UID/GID $uidgid"
5375 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5376 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5377 local nid=$(echo $entry |
5378 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5379 [ -n "$nid" ] || error "nid is empty"
5381 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5382 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5384 run_test 606 "llog_reader groks changelog fields"
5387 check_and_cleanup_lustre