3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16 # skip test cases failed before landing - Jinshan
18 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 31a 34 35 36"
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 201 221 223a 223b 225"
21 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
23 . $LUSTRE/tests/test-framework.sh
25 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
28 MULTIOP=${MULTIOP:-multiop}
29 OPENFILE=${OPENFILE:-openfile}
30 MCREATE=${MCREATE:-mcreate}
31 MOUNT_2=${MOUNT_2:-"yes"}
34 if [[ $MDSCOUNT -ge 2 ]]; then
35 skip_env "Only run with single MDT for now" && exit
38 check_and_setup_lustre
40 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
41 skip_env "Need MDS version at least 2.4.53" && exit
44 # $RUNAS_ID may get set incorrectly somewhere else
45 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
46 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
48 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
53 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
54 # the following associated variables are added:
56 # AGTCOUNT: number of agents
57 # AGTDEV{N}: target HSM mount point (root path of the backend)
58 # agt{N}_HOST: hostname of the agent agt{N}
59 # SINGLEAGT: facet of the single agent
61 # The number of agents is initialized as the number of remote client nodes.
62 # By default, only single copytool is started on a remote client/agent. If there
63 # was no remote client, then the copytool will be started on the local client.
69 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
70 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
72 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
73 if [[ $CLIENTCOUNT -gt 1 ]] &&
74 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
75 skip_env "SHARED_DIRECTORY should be accessible"\
80 for n in $(seq $AGTCOUNT); do
81 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
82 agent=CLIENT$((n + 1))
83 if [[ -z "${!agent}" ]]; then
84 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
87 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
90 export SINGLEAGT=${SINGLEAGT:-agt1}
92 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
93 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
94 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
95 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
98 MDT_PARAM="mdt.$FSNAME-MDT0000"
99 HSM_PARAM="$MDT_PARAM.hsm"
101 # archive is purged at copytool setup
102 HSM_ARCHIVE_PURGE=true
105 # Get the backend root path for the given agent facet.
108 local dev=AGTDEV$(facet_number $facet)
113 # Stop copytool and unregister an existing changelog user.
117 cdt_set_sanity_policy
120 search_and_kill_copytool() {
121 local agents=${1:-$(facet_active_host $SINGLEAGT)}
123 echo "Killing existing copytools on $agents"
124 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
128 local facet=${1:-$SINGLEAGT}
129 local lustre_mntpnt=${2:-$MOUNT}
131 local hsm_root=$(copytool_device $facet)
132 local agent=$(facet_active_host $facet)
134 if [[ -z "$arc_id" ]] &&
135 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
136 echo "Wakeup copytool $facet on $agent"
140 if $HSM_ARCHIVE_PURGE; then
141 echo "Purging archive on $agent"
142 do_facet $facet "rm -rf $hsm_root/*"
145 echo "Starting copytool $facet on $agent"
146 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
147 # bandwidth is limited to 1MB/s so the copy time is known and
148 # independent of hardware
149 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
150 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
151 cmd+=" --bandwidth 1 $lustre_mntpnt"
153 # Redirect the standard output and error to a log file which
154 # can be uploaded to Maloo.
155 local prefix=$TESTLOG_PREFIX
156 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
157 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
159 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
160 error "start copytool $facet on $agent failed"
166 local agents=${1:-$(facet_active_host $SINGLEAGT)}
168 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
170 echo "Copytool is stopped on $agents"
174 local agents=${1:-$(facet_active_host $SINGLEAGT)}
176 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
177 echo "Copytool is suspended on $agents"
180 copytool_remove_backend() {
182 local be=$(find $HSM_ARCHIVE -name $fid)
183 echo "Remove from backend: $fid = $be"
184 do_facet $SINGLEAGT rm -f $be
188 do_facet $SINGLEAGT \
189 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
190 --import $1 $2 $MOUNT" ||
191 error "import of $1 to $2 failed"
195 local file=$HSM_ARCHIVE/$1
196 do_facet $SINGLEAGT mkdir -p $(dirname $file)
197 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
198 error "cannot create $file"
202 local file=$HSM_ARCHIVE/$2
203 do_facet $SINGLEAGT mkdir -p $(dirname $file)
204 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
208 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0\
209 changelog_register -n)
210 do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+hsm"
211 $LFS changelog_clear $MDT0 $CL_USER 0
214 changelog_cleanup() {
215 # $LFS changelog $MDT0
216 [[ -n "$CL_USER" ]] || return 0
218 $LFS changelog_clear $MDT0 $CL_USER 0
219 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
223 changelog_get_flags() {
228 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
233 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
240 do_facet $SINGLEMDS $LCTL set_param -n $HSM_PARAM.$param=$value
247 do_facet $SINGLEMDS $LCTL set_param $MDT_PARAM.hsm_control=$cmd
248 wait_result $SINGLEMDS "$LCTL get_param -n $MDT_PARAM.hsm_control"\
249 $target 10 || error "cdt state is not $target"
252 cdt_set_sanity_policy() {
253 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
256 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
257 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
258 CDT_POLICY_HAD_CHANGED=
263 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
264 CDT_POLICY_HAD_CHANGED=true
267 cdt_clear_no_retry() {
268 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NRA
269 CDT_POLICY_HAD_CHANGED=true
272 cdt_set_non_blocking_restore() {
273 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NBR
274 CDT_POLICY_HAD_CHANGED=true
277 cdt_clear_non_blocking_restore() {
278 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
279 CDT_POLICY_HAD_CHANGED=true
282 cdt_clear_mount_state() {
283 # /!\ conf_param and set_param syntax differ +> we cannot use
285 do_facet $SINGLEMDS $LCTL conf_param -d $FSNAME-MDT0000.mdt.hsm_control
288 cdt_set_mount_state() {
289 # /!\ conf_param and set_param syntax differ +> we cannot use
291 do_facet $SINGLEMDS $LCTL conf_param $FSNAME-MDT0000.mdt.hsm_control=$1
296 wait_result $SINGLEMDS\
297 "$LCTL get_param -n $MDT_PARAM.hsm_control" "$target" 20 ||
298 error "cdt state is not $target"
302 set_test_state disabled disabled
306 set_test_state enabled enabled
310 set_test_state shutdown stopped
314 set_test_state purge enabled
320 cdt_set_sanity_policy
324 local client_count=$1
325 if [[ $CLIENTCOUNT -lt $client_count ]]; then
326 skip "Need $client_count or more clients, have $CLIENTCOUNT"
333 $LFS path2fid $1 | tr -d '[]'
340 if [[ $u == "user" ]]
342 local st=$($RUNAS $LFS hsm_state $f)
344 local st=$($LFS hsm_state $f)
348 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
350 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
354 get_hsm_archive_id() {
356 local st=$($LFS hsm_state $f)
357 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
359 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
368 local st=$(get_hsm_flags $f)
369 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
372 check_hsm_flags_user() {
376 local st=$(get_hsm_flags $f user)
377 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
395 cp $1 $f || error "cannot copy $1 to $f"
396 path2fid $f || error "cannot get fid on $f"
400 local file2=${1/$DIR/$DIR2}
401 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
402 error "cannot create $file2"
403 path2fid $1 || error "cannot get fid on $1"
406 cleanup_large_files() {
407 local ratio=$(df $MOUNT |awk '{print $5}' |sed 's/%//g' |grep -v Use)
408 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
411 make_large_for_striping() {
412 local file2=${1/$DIR/$DIR2}
413 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
417 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
418 error "cannot create $file2"
419 path2fid $1 || error "cannot get fid on $1"
422 make_large_for_progress() {
423 local file2=${1/$DIR/$DIR2}
427 # big file is large enough, so copy time is > 30s
428 # so copytool make 1 progress
429 # size is not a multiple of 1M to avoid stripe
431 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
432 error "cannot create $file2"
433 path2fid $1 || error "cannot get fid on $1"
436 make_large_for_progress_aligned() {
437 local file2=${1/$DIR/$DIR2}
441 # big file is large enough, so copy time is > 30s
442 # so copytool make 1 progress
443 # size is a multiple of 1M to have stripe
445 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
446 error "cannot create $file2"
447 path2fid $1 || error "cannot get fid on $1"
450 make_large_for_cancel() {
451 local file2=${1/$DIR/$DIR2}
455 # Copy timeout is 100s. 105MB => 105s
456 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
457 error "cannot create $file2"
458 path2fid $1 || error "cannot get fid on $1"
464 wait_update --verbose $(facet_active_host $facet) "$@"
467 wait_request_state() {
472 local cmd="$LCTL get_param -n $HSM_PARAM.agent_actions"
473 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
475 wait_result $SINGLEMDS "$cmd" $state 100 ||
476 error "request on $fid is not $state"
479 get_request_state() {
483 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.agent_actions |"\
484 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
487 get_request_count() {
491 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.agent_actions |"\
492 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
498 local cmd="$LCTL get_param -n $HSM_PARAM.agent_actions"
499 cmd+=" | egrep 'WAITING|STARTED'"
501 wait_result $SINGLEMDS "$cmd" "" $timeout ||
502 error "requests did not complete"
505 wait_for_grace_delay() {
506 local val=$(get_hsm_param grace_delay)
510 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
511 awk '{gsub(/_UUID/,""); print $1}' | head -1)
516 # cleanup from previous bad setup
517 search_and_kill_copytool
519 # for recovery tests, coordinator needs to be started at mount
521 # the lustre conf must be without hsm on (like for sanity.sh)
522 echo "Set HSM on and start"
523 cdt_set_mount_state enabled
524 cdt_check_state enabled
526 echo "Start copytool"
529 echo "Set sanity-hsm HSM policy"
530 cdt_set_sanity_policy
532 # finished requests are quickly removed from list
533 set_hsm_param grace_delay 10
539 local f=$DIR/$tdir/$tfile
543 check_hsm_flags_user $f "0x00000000"
545 $RUNAS $LFS hsm_set --norelease $f ||
546 error "user could not change hsm flags"
547 check_hsm_flags_user $f "0x00000010"
549 $RUNAS $LFS hsm_clear --norelease $f ||
550 error "user could not clear hsm flags"
551 check_hsm_flags_user $f "0x00000000"
553 # User could not change those flags...
554 $RUNAS $LFS hsm_set --exists $f &&
555 error "user should not set this flag"
556 check_hsm_flags_user $f "0x00000000"
559 $LFS hsm_set --exists $f ||
560 error "root could not change hsm flags"
561 check_hsm_flags_user $f "0x00000001"
563 $LFS hsm_clear --exists $f ||
564 error "root could not clear hsm state"
565 check_hsm_flags_user $f "0x00000000"
568 run_test 1 "lfs hsm flags root/non-root access"
572 local f=$DIR/$tdir/$tfile
574 # New files are not dirty
575 check_hsm_flags $f "0x00000000"
577 # For test, we simulate an archived file.
578 $LFS hsm_set --exists $f || error "user could not change hsm flags"
579 check_hsm_flags $f "0x00000001"
581 # chmod do not put the file dirty
582 chmod 600 $f || error "could not chmod test file"
583 check_hsm_flags $f "0x00000001"
585 # chown do not put the file dirty
586 chown $RUNAS_ID $f || error "could not chown test file"
587 check_hsm_flags $f "0x00000001"
589 # truncate put the file dirty
590 $TRUNCATE $f 1 || error "could not truncate test file"
591 check_hsm_flags $f "0x00000003"
593 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
594 check_hsm_flags $f "0x00000001"
596 run_test 2 "Check file dirtyness when doing setattr"
602 # New files are not dirty
604 check_hsm_flags $f "0x00000000"
606 # For test, we simulate an archived file.
607 $LFS hsm_set --exists $f ||
608 error "user could not change hsm flags"
609 check_hsm_flags $f "0x00000001"
611 # Reading a file, does not set dirty
612 cat $f > /dev/null || error "could not read file"
613 check_hsm_flags $f "0x00000001"
615 # Open for write without modifying data, does not set dirty
616 openfile -f O_WRONLY $f || error "could not open test file"
617 check_hsm_flags $f "0x00000001"
619 # Append to a file sets it dirty
620 cp -p /etc/passwd $f.append || error "could not create file"
621 $LFS hsm_set --exists $f.append ||
622 error "user could not change hsm flags"
623 dd if=/etc/passwd of=$f.append bs=1 count=3\
624 conv=notrunc oflag=append status=noxfer ||
625 error "could not append to test file"
626 check_hsm_flags $f.append "0x00000003"
628 # Modify a file sets it dirty
629 cp -p /etc/passwd $f.modify || error "could not create file"
630 $LFS hsm_set --exists $f.modify ||
631 error "user could not change hsm flags"
632 dd if=/dev/zero of=$f.modify bs=1 count=3\
633 conv=notrunc status=noxfer ||
634 error "could not modify test file"
635 check_hsm_flags $f.modify "0x00000003"
637 # Open O_TRUNC sets dirty
638 cp -p /etc/passwd $f.trunc || error "could not create file"
639 $LFS hsm_set --exists $f.trunc ||
640 error "user could not change hsm flags"
641 cp /etc/group $f.trunc || error "could not override a file"
642 check_hsm_flags $f.trunc "0x00000003"
644 # Mmapped a file sets dirty
645 cp -p /etc/passwd $f.mmap || error "could not create file"
646 $LFS hsm_set --exists $f.mmap ||
647 error "user could not change hsm flags"
648 multiop $f.mmap OSMWUc || error "could not mmap a file"
649 check_hsm_flags $f.mmap "0x00000003"
651 run_test 3 "Check file dirtyness when opening for write"
655 local f=$DIR/$tdir/$tfile
656 local fid=$(make_small $f)
659 local st=$(get_request_state $fid CANCEL)
660 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
662 run_test 4 "Useless cancel must not be registered"
665 # test needs a running copytool
669 local f=$DIR/$tdir/$tfile
670 local fid=$(copy_file /etc/passwd $f)
672 wait_request_state $fid ARCHIVE SUCCEED
674 check_hsm_flags $f "0x00000009"
678 run_test 8 "Test default archive number"
682 local f=$DIR/$tdir/$tfile
683 local fid=$(copy_file /etc/passwd $f)
684 # we do not use the default one to be sure
685 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
687 copytool_setup $SINGLEAGT $MOUNT $new_an
688 $LFS hsm_archive --archive $new_an $f
689 wait_request_state $fid ARCHIVE SUCCEED
691 check_hsm_flags $f "0x00000009"
695 run_test 9 "Use of explict archive number, with dedicated copytool"
698 needclients 3 || return 0
704 copytool_cleanup $(comma_list $(agts_nodes))
706 # start all of the copytools
707 for n in $(seq $AGTCOUNT); do
711 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
714 for n in $(seq $AGTCOUNT); do
715 file=$DIR/$tdir/$tfile.$n
716 fid=$(make_small $file)
718 $LFS hsm_archive $file || error "could not archive file $file"
719 wait_request_state $fid ARCHIVE SUCCEED
720 check_hsm_flags $file "0x00000009"
724 copytool_cleanup $(comma_list $(agts_nodes))
726 run_test 9a "Multiple remote agents"
729 # test needs a running copytool
732 mkdir -p $DIR/$tdir/d1
733 local f=$DIR/$tdir/$tfile
734 local fid=$(copy_file /etc/hosts $f)
735 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
736 error "hsm_archive failed"
737 wait_request_state $fid ARCHIVE SUCCEED
739 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
740 error "fid $fid not in archive $HSM_ARCHIVE"
741 echo "Verifying content"
742 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
743 echo "Verifying hsm state "
744 check_hsm_flags $f "0x00000009"
746 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
747 local st=$(get_hsm_archive_id $f)
748 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
749 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
754 run_test 10a "Archive a file"
757 # test needs a running copytool
761 local f=$DIR/$tdir/$tfile
762 local fid=$(copy_file /etc/hosts $f)
763 $LFS hsm_archive $f || error "archive request failed"
764 wait_request_state $fid ARCHIVE SUCCEED
766 $LFS hsm_archive $f || error "archive of non dirty file failed"
767 local cnt=$(get_request_count $fid ARCHIVE)
768 [[ "$cnt" == "1" ]] ||
769 error "archive of non dirty file must not make a request"
773 run_test 10b "Archive of non dirty file must work without doing request"
776 # test needs a running copytool
780 local f=$DIR/$tdir/$tfile
781 local fid=$(copy_file /etc/hosts $f)
782 $LFS hsm_set --noarchive $f
783 $LFS hsm_archive $f && error "archive a noarchive file must fail"
787 run_test 10c "Check forbidden archive"
790 # test needs a running copytool
794 local f=$DIR/$tdir/$tfile
795 local fid=$(copy_file /etc/hosts $f)
796 $LFS hsm_archive $f || error "cannot archive $f"
797 wait_request_state $fid ARCHIVE SUCCEED
799 local ar=$(get_hsm_archive_id $f)
800 local dflt=$(get_hsm_param archive_id)
801 [[ $ar == $dflt ]] ||
802 error "archived file is not on default archive: $ar != $dflt"
806 run_test 10d "Archive a file on the default archive id"
810 copy2archive /etc/hosts $tdir/$tfile
811 local f=$DIR/$tdir/$tfile
813 import_file $tdir/$tfile $f
814 echo -n "Verifying released state: "
815 check_hsm_flags $f "0x0000000d"
817 local LSZ=$(stat -c "%s" $f)
818 local ASZ=$(stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
820 echo "Verifying imported size $LSZ=$ASZ"
821 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
822 echo -n "Verifying released pattern: "
823 local PTRN=$($GETSTRIPE -L $f)
825 [[ $PTRN == 80000001 ]] || error "Is not released"
826 local fid=$(path2fid $f)
827 echo "Verifying new fid $fid in archive"
829 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
830 error "fid $fid not in archive $HSM_ARCHIVE"
832 run_test 11 "Import a file"
835 # test needs a running copytool
839 copy2archive /etc/hosts $tdir/$tfile
841 local f=$DIR/$tdir/$tfile
842 import_file $tdir/$tfile $f
843 local f=$DIR2/$tdir/$tfile
844 echo "Verifying released state: "
845 check_hsm_flags $f "0x0000000d"
847 local fid=$(path2fid $f)
849 wait_request_state $fid RESTORE SUCCEED
851 echo "Verifying file state: "
852 check_hsm_flags $f "0x00000009"
854 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
856 [[ $? -eq 0 ]] || error "Restored file differs"
860 run_test 12a "Restore an imported file explicitly"
863 # test needs a running copytool
867 copy2archive /etc/hosts $tdir/$tfile
869 local f=$DIR/$tdir/$tfile
870 import_file $tdir/$tfile $f
871 echo "Verifying released state: "
872 check_hsm_flags $f "0x0000000d"
874 cat $f > /dev/null || error "File read failed"
876 echo "Verifying file state after restore: "
877 check_hsm_flags $f "0x00000009"
879 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
881 [[ $? -eq 0 ]] || error "Restored file differs"
885 run_test 12b "Restore an imported file implicitly"
888 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
890 # test needs a running copytool
894 local f=$DIR/$tdir/$tfile
895 $LFS setstripe -c 2 $f
896 local fid=$(make_large_for_striping $f)
897 local FILE_CRC=$(md5sum $f)
899 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
900 wait_request_state $fid ARCHIVE SUCCEED
901 $LFS hsm_release $f || error "release $f failed"
903 echo "$FILE_CRC" | md5sum -c
905 [[ $? -eq 0 ]] || error "Restored file differs"
909 run_test 12c "Restore a file with stripe of 2"
912 # test needs a running copytool
917 local f=$DIR/$tdir/$tfile
918 local fid=$(copy_file /etc/hosts $f)
919 $LFS hsm_restore $f || error "restore of non archived file failed"
920 local cnt=$(get_request_count $fid RESTORE)
921 [[ "$cnt" == "0" ]] ||
922 error "restore non archived must not make a request"
923 $LFS hsm_archive $f ||
924 error "archive request failed"
925 wait_request_state $fid ARCHIVE SUCCEED
926 $LFS hsm_restore $f ||
927 error "restore of non released file failed"
928 local cnt=$(get_request_count $fid RESTORE)
929 [[ "$cnt" == "0" ]] ||
930 error "restore a non dirty file must not make a request"
934 run_test 12d "Restore of a non archived, non released file must work"\
935 " without doing request"
938 # test needs a running copytool
941 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
942 local f=$DIR/$tdir/$tfile
943 local fid=$(copy_file /etc/hosts $f)
944 $LFS hsm_archive $f || error "archive request failed"
945 wait_request_state $fid ARCHIVE SUCCEED
952 $LFS hsm_restore $f && error "restore a dirty file must fail"
956 run_test 12e "Check forbidden restore"
959 # test needs a running copytool
963 local f=$DIR/$tdir/$tfile
964 local fid=$(copy_file /etc/hosts $f)
966 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
967 wait_request_state $fid ARCHIVE SUCCEED
968 $LFS hsm_release $f || error "release of $f failed"
970 wait_request_state $fid RESTORE SUCCEED
972 echo -n "Verifying file state: "
973 check_hsm_flags $f "0x00000009"
975 diff -q /etc/hosts $f
977 [[ $? -eq 0 ]] || error "Restored file differs"
981 run_test 12f "Restore a released file explicitly"
984 # test needs a running copytool
988 local f=$DIR/$tdir/$tfile
989 local fid=$(copy_file /etc/hosts $f)
991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
992 wait_request_state $fid ARCHIVE SUCCEED
993 $LFS hsm_release $f || error "release of $f failed"
995 diff -q /etc/hosts $f
998 # we check we had a restore done
999 wait_request_state $fid RESTORE SUCCEED
1001 [[ $st -eq 0 ]] || error "Restored file differs"
1005 run_test 12g "Restore a released file implicitly"
1008 needclients 2 || return 0
1010 # test needs a running copytool
1014 local f=$DIR/$tdir/$tfile
1015 local fid=$(copy_file /etc/hosts $f)
1017 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1018 wait_request_state $fid ARCHIVE SUCCEED
1019 $LFS hsm_release $f || error "release of $f failed"
1021 do_node $CLIENT2 diff -q /etc/hosts $f
1024 # we check we had a restore done
1025 wait_request_state $fid RESTORE SUCCEED
1027 [[ $st -eq 0 ]] || error "Restored file differs"
1031 run_test 12h "Restore a released file implicitly from a second node"
1034 # test needs a running copytool
1038 local f=$DIR/$tdir/$tfile
1039 local fid=$(copy_file /etc/passwd $f)
1040 $LFS hsm_archive $f || error "archive of $f failed"
1041 wait_request_state $fid ARCHIVE SUCCEED
1043 $LFS hsm_release $f || error "release of $f failed"
1047 [[ $? -eq 0 ]] || error "Restored file differs"
1051 run_test 12m "Archive/release/implicit restore"
1054 # test needs a running copytool
1058 copy2archive /etc/hosts $tdir/$tfile
1060 local f=$DIR/$tdir/$tfile
1061 import_file $tdir/$tfile $f
1063 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1064 error "Restored file differs"
1066 $LFS hsm_release $f || error "release of $f failed"
1070 run_test 12n "Import/implicit restore/release"
1073 # test needs a running copytool
1076 local ARC_SUBDIR="import.orig"
1080 # populate directory to be imported
1081 for d in $(seq 1 10); do
1082 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1083 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1084 for f in $(seq 1 10); do
1085 CURR_FILE="$CURR_DIR/$tfile.$f"
1086 # write file-specific data
1087 do_facet $SINGLEAGT \
1088 echo "d=$d, f=$f, dir=$CURR_DIR, "\
1089 "file=$CURR_FILE" > $CURR_FILE
1093 import_file "$ARC_SUBDIR" $DIR/$tdir
1094 # diff lustre content and origin (triggers file restoration)
1095 # there must be 10x10 identical files, and no difference
1096 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1097 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1098 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1099 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1101 [ $cnt_diff -eq 0 ] ||
1102 error "$cnt_diff imported files differ from read data"
1103 [ $cnt_ok -eq 100 ] ||
1104 error "not enough identical files ($cnt_ok != 100)"
1108 run_test 13 "Recursively import and restore a directory"
1111 # test needs a running copytool
1116 local f=$DIR/$tdir/$tfile
1117 local fid=$(make_small $f)
1118 local sum=$(md5sum $f | awk '{print $1}')
1119 $LFS hsm_archive $f || error "could not archive file"
1120 wait_request_state $fid ARCHIVE SUCCEED
1124 # create released file (simulate llapi_hsm_import call)
1126 local fid2=$(path2fid $f)
1127 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1128 $LFS hsm_release $f || error "could not release file"
1130 # rebind the archive to the newly created file
1131 echo "rebind $fid to $fid2"
1133 do_facet $SINGLEAGT \
1134 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1135 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1137 # restore file and compare md5sum
1138 local sum2=$(md5sum $f | awk '{print $1}')
1140 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1144 run_test 14 "Rebind archived file to a new fid"
1147 # test needs a running copytool
1152 local f=$DIR/$tdir/$tfile
1154 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1158 for i in $(seq 1 $count); do
1159 fids[$i]=$(make_small $f.$i)
1160 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1161 $LFS hsm_archive $f.$i || error "could not archive file"
1163 wait_all_done $(($count*60))
1167 for i in $(seq 1 $count); do
1170 local fid2=$(path2fid $f.$i)
1171 # add the rebind operation to the list
1172 echo ${fids[$i]} $fid2 >> $tmpfile
1174 # set it released (simulate llapi_hsm_import call)
1175 $LFS hsm_set --archived --exists $f.$i ||
1176 error "could not force hsm flags"
1177 $LFS hsm_release $f.$i || error "could not release file"
1179 nl=$(wc -l < $tmpfile)
1180 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1182 echo "rebind list of files"
1183 do_facet $SINGLEAGT \
1184 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1185 --rebind $tmpfile $DIR" || error "could not rebind file list"
1187 # restore files and compare md5sum
1188 for i in $(seq 1 $count); do
1189 local sum2=$(md5sum $f.$i | awk '{print $1}')
1190 [[ $sum2 == ${sums[$i]} ]] ||
1191 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1197 run_test 15 "Rebind a list of files"
1200 # test needs a running copytool
1204 # create a known size file so we can verify transfer speed
1207 dd if=/dev/zero of=$ref bs=1M count=20
1210 local f=$DIR/$tdir/$tfile
1211 local fid=$(copy_file $ref $f)
1213 local start=$(date +%s)
1215 wait_request_state $fid ARCHIVE SUCCEED
1216 local end=$(date +%s)
1217 local duration=$((end - start))
1219 [[ $duration -ge $goal ]] ||
1220 error "Transfer is too fast $duration < $goal"
1224 run_test 16 "Test CT bandwith control option"
1229 local f=$DIR/$tdir/$tfile
1230 touch $f || error "touch $f failed"
1232 # Could not release a non-archived file
1233 $LFS hsm_release $f && error "release should not succeed"
1235 # For following tests, we must test them with HS_ARCHIVED set
1236 $LFS hsm_set --exists --archived $f || error "could not add flag"
1238 # Could not release a file if no-release is set
1239 $LFS hsm_set --norelease $f || error "could not add flag"
1240 $LFS hsm_release $f && error "release should not succeed"
1241 $LFS hsm_clear --norelease $f || error "could not remove flag"
1243 # Could not release a file if lost
1244 $LFS hsm_set --lost $f || error "could not add flag"
1245 $LFS hsm_release $f && error "release should not succeed"
1246 $LFS hsm_clear --lost $f || error "could not remove flag"
1248 # Could not release a file if dirty
1249 $LFS hsm_set --dirty $f || error "could not add flag"
1250 $LFS hsm_release $f && error "release should not succeed"
1251 $LFS hsm_clear --dirty $f || error "could not remove flag"
1253 run_test 20 "Release is not permitted"
1256 # test needs a running copytool
1260 local f=$DIR/$tdir/test_release
1262 # Create a file and check its states
1263 local fid=$(make_small $f)
1264 check_hsm_flags $f "0x00000000"
1266 $LFS hsm_archive $f || error "could not archive file"
1267 wait_request_state $fid ARCHIVE SUCCEED
1269 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1270 local sz=$(stat -c "%s" $f)
1271 [ $sz -ne "0" ] || error "file size should not be zero"
1273 # Release and check states
1274 $LFS hsm_release $f || error "could not release file"
1275 check_hsm_flags $f "0x0000000d"
1277 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1278 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1280 # Check we can release an file without stripe info
1284 check_hsm_flags $f "0x00000000"
1285 $LFS hsm_archive $f || error "could not archive file"
1286 wait_request_state $fid ARCHIVE SUCCEED
1288 # Release and check states
1289 $LFS hsm_release $f || error "could not release file"
1290 check_hsm_flags $f "0x0000000d"
1292 # Release again a file that is already released is OK
1293 $LFS hsm_release $f || fail "second release should succeed"
1294 check_hsm_flags $f "0x0000000d"
1298 run_test 21 "Simple release tests"
1301 # test needs a running copytool
1306 local f=$DIR/$tdir/test_release
1307 local swap=$DIR/$tdir/test_swap
1309 # Create a file and check its states
1310 local fid=$(make_small $f)
1311 check_hsm_flags $f "0x00000000"
1313 $LFS hsm_archive $f || error "could not archive file"
1314 wait_request_state $fid ARCHIVE SUCCEED
1316 # Release and check states
1317 $LFS hsm_release $f || error "could not release file"
1318 check_hsm_flags $f "0x0000000d"
1321 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1326 run_test 22 "Could not swap a release file"
1329 # test needs a running copytool
1334 local f=$DIR/$tdir/test_mtime
1336 # Create a file and check its states
1337 local fid=$(make_small $f)
1338 check_hsm_flags $f "0x00000000"
1340 $LFS hsm_archive $f || error "could not archive file"
1341 wait_request_state $fid ARCHIVE SUCCEED
1343 # Set modification time in the past
1344 touch -m -a -d @978261179 $f
1346 # Release and check states
1347 $LFS hsm_release $f || error "could not release file"
1348 check_hsm_flags $f "0x0000000d"
1350 local MTIME=$(stat -c "%Y" $f)
1351 local ATIME=$(stat -c "%X" $f)
1352 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1353 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1357 run_test 23 "Release does not change a/mtime (utime)"
1360 local file=$DIR/$tdir/$tfile
1369 # test needs a running copytool
1374 fid=$(make_small $file)
1376 # Create a file and check its states
1377 check_hsm_flags $file "0x00000000"
1379 # Ensure atime is less than mtime and ctime.
1383 atime0=$(stat -c "%X" $file)
1384 mtime0=$(stat -c "%Y" $file)
1385 ctime0=$(stat -c "%Z" $file)
1387 [ $atime0 -lt $mtime0 ] ||
1388 error "atime $atime0 is not less than mtime $mtime0"
1390 [ $atime0 -lt $ctime0 ] ||
1391 error "atime $atime0 is not less than ctime $ctime0"
1393 # Archive should not change any timestamps.
1394 $LFS hsm_archive $file || error "cannot archive '$file'"
1395 wait_request_state $fid ARCHIVE SUCCEED
1397 atime1=$(stat -c "%X" $file)
1398 mtime1=$(stat -c "%Y" $file)
1399 ctime1=$(stat -c "%Z" $file)
1401 [ $atime0 -eq $atime1 ] ||
1402 error "archive changed atime from $atime0 to $atime1"
1404 [ $mtime0 -eq $mtime1 ] ||
1405 error "archive changed mtime from $mtime0 to $mtime1"
1407 [ $ctime0 -eq $ctime1 ] ||
1408 error "archive changed ctime from $ctime0 to $ctime1"
1410 # Release should not change any timestamps.
1411 $LFS hsm_release $file || error "cannot release '$file'"
1412 check_hsm_flags $file "0x0000000d"
1414 atime1=$(stat -c "%X" $file)
1415 mtime1=$(stat -c "%Y" $file)
1416 ctime1=$(stat -c "%Z" $file)
1418 [ $atime0 -eq $atime1 ] ||
1419 error "release changed atime from $atime0 to $atime1"
1421 [ $mtime0 -eq $mtime1 ] ||
1422 error "release changed mtime from $mtime0 to $mtime1"
1424 [ $ctime0 -eq $ctime1 ] ||
1425 error "release changed ctime from $ctime0 to $ctime1"
1427 # Restore should not change atime or mtime and should not
1429 $LFS hsm_restore $file
1430 wait_request_state $fid RESTORE SUCCEED
1432 atime1=$(stat -c "%X" $file)
1433 mtime1=$(stat -c "%Y" $file)
1434 ctime1=$(stat -c "%Z" $file)
1436 [ $atime0 -eq $atime1 ] ||
1437 error "restore changed atime from $atime0 to $atime1"
1439 [ $mtime0 -eq $mtime1 ] ||
1440 error "restore changed mtime from $mtime0 to $mtime1"
1442 [ $ctime0 -le $ctime1 ] ||
1443 error "restore changed ctime from $ctime0 to $ctime1"
1447 # Once more, after unmount and mount.
1448 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1449 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1451 atime1=$(stat -c "%X" $file)
1452 mtime1=$(stat -c "%Y" $file)
1453 ctime1=$(stat -c "%Z" $file)
1455 [ $atime0 -eq $atime1 ] ||
1456 error "remount changed atime from $atime0 to $atime1"
1458 [ $mtime0 -eq $mtime1 ] ||
1459 error "remount changed mtime from $mtime0 to $mtime1"
1461 [ $ctime0 -le $ctime1 ] ||
1462 error "remount changed ctime from $ctime0 to $ctime1"
1464 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1467 local file=$DIR/$tdir/$tfile
1473 # Test needs a running copytool.
1477 # Check that root can do HSM actions on a ordinary user's file.
1479 fid=$(make_small $file)
1480 sum0=$(md5sum $file)
1482 chown $RUNAS_ID:$RUNAS_GID $file ||
1483 error "cannot chown '$file' to '$RUNAS_ID'"
1485 chmod ugo-w $DIR/$tdir ||
1486 error "cannot chmod '$DIR/$tdir'"
1488 $LFS hsm_archive $file
1489 wait_request_state $fid ARCHIVE SUCCEED
1491 $LFS hsm_release $file ||
1492 check_hsm_flags $file "0x0000000d"
1494 $LFS hsm_restore $file
1495 wait_request_state $fid RESTORE SUCCEED
1497 # Check that ordinary user can get HSM state.
1498 $RUNAS $LFS hsm_state $file ||
1499 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1501 $LFS hsm_release $file ||
1502 check_hsm_flags $file "0x0000000d"
1504 # Check that ordinary user can accessed released file.
1505 sum1=$($RUNAS md5sum $file) ||
1506 error "user '$RUNAS_ID' cannot read '$file'"
1508 [ "$sum0" == "$sum1" ] ||
1509 error "md5sum mismatch for '$file'"
1513 run_test 24b "root can archive, release, and restore user files"
1516 # test needs a running copytool
1520 copy2archive /etc/hosts $tdir/$tfile
1522 local f=$DIR/$tdir/$tfile
1524 import_file $tdir/$tfile $f
1526 $LFS hsm_set --lost $f
1531 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1535 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1536 " (Operation not permitted)"
1539 # test needs a running copytool
1544 local f=$DIR/$tdir/$tfile
1545 local fid=$(copy_file /etc/passwd $f)
1547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1548 wait_request_state $fid ARCHIVE SUCCEED
1551 $LFS hsm_set --lost $f
1555 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1559 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1560 " (Operation not permitted)"
1563 # test needs a running copytool
1567 local f=$DIR/$tdir/$tfile
1568 local fid=$(make_large_for_progress $f)
1569 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1570 wait_request_state $fid ARCHIVE SUCCEED
1573 wait_request_state $fid REMOVE SUCCEED
1575 check_hsm_flags $f "0x00000000"
1579 run_test 26 "Remove the archive of a valid file"
1582 # test needs a running copytool
1586 make_archive $tdir/$tfile
1587 local f=$DIR/$tdir/$tfile
1588 import_file $tdir/$tfile $f
1589 local fid=$(path2fid $f)
1593 [[ $? != 0 ]] || error "Remove of a released file should fail"
1597 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1600 # test needs a running copytool
1604 local f=$DIR/$tdir/$tfile
1605 local fid=$(make_large_for_progress $f)
1606 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1607 wait_request_state $fid ARCHIVE SUCCEED
1612 [[ $? != 0 ]] || error "Remove of a released file should fail"
1616 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1619 # test needs a running copytool
1623 local f=$DIR/$tdir/$tfile
1624 local fid=$(make_large_for_progress $f)
1625 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1626 wait_request_state $fid ARCHIVE SUCCEED
1635 wait_request_state $fid REMOVE SUCCEED
1639 run_test 28 "Concurrent archive/file remove"
1642 # restore at exec cannot work on agent node (because of Linux kernel
1643 # protection of executables)
1644 needclients 2 || return 0
1646 # test needs a running copytool
1650 copy2archive /bin/true $tdir/$tfile
1652 local f=$DIR/$tdir/true
1653 import_file $tdir/$tfile $f
1655 local fid=$(path2fid $f)
1657 # set no retry action mode
1663 # remove no try action mode
1667 [[ $st == 0 ]] || error "Failed to exec a released file"
1671 run_test 30a "Restore at exec (import case)"
1674 # restore at exec cannot work on agent node (because of Linux kernel
1675 # protection of executables)
1676 needclients 2 || return 0
1678 # test needs a running copytool
1682 local f=$DIR/$tdir/true
1683 local fid=$(copy_file /bin/true $f)
1685 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1686 wait_request_state $fid ARCHIVE SUCCEED
1689 # set no retry action mode
1695 # remove no try action mode
1699 [[ $st == 0 ]] || error "Failed to exec a released file"
1703 run_test 30b "Restore at exec (release case)"
1705 restore_and_check_size() {
1708 local s=$(stat -c "%s" $f)
1710 local st=$(get_hsm_flags $f)
1714 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1716 n=$(stat -c "%s" $f)
1717 # we echo in both cases to show stat is not
1721 echo "size seen is $n != $s"
1724 echo "size seen is right: $n == $s"
1726 st=$(get_hsm_flags $f)
1730 if [[ $cpt -lt 10 ]]
1732 echo " restore is too long"
1736 wait_request_state $fid RESTORE SUCCEED
1741 # test needs a running copytool
1746 make_archive $tdir/$tfile
1747 local f=$DIR/$tdir/$tfile
1748 import_file $tdir/$tfile $f
1749 local fid=$($LFS path2fid $f)
1750 HSM_ARCHIVE_PURGE=false copytool_setup
1752 restore_and_check_size $f $fid
1755 [[ $err -eq 0 ]] || error "File size changed during restore"
1759 run_test 31a "Import a large file and check size during restore"
1763 # test needs a running copytool
1768 local f=$DIR/$tdir/$tfile
1769 local fid=$(make_large_for_progress $f)
1770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1771 wait_request_state $fid ARCHIVE SUCCEED
1774 restore_and_check_size $f $fid
1777 [[ $err -eq 0 ]] || error "File size changed during restore"
1781 run_test 31b "Restore a large unaligned file and check size during restore"
1784 # test needs a running copytool
1789 local f=$DIR/$tdir/$tfile
1790 local fid=$(make_large_for_progress_aligned $f)
1791 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1792 wait_request_state $fid ARCHIVE SUCCEED
1795 restore_and_check_size $f $fid
1798 [[ $err -eq 0 ]] || error "File size changed during restore"
1802 run_test 31c "Restore a large aligned file and check size during restore"
1805 # test needs a running copytool
1810 local f=$DIR/$tdir/$tfile
1811 local fid=$(make_large_for_progress $f)
1812 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1813 wait_request_state $fid ARCHIVE SUCCEED
1816 md5sum $f >/dev/null &
1818 wait_request_state $fid RESTORE STARTED
1823 # Check restore trigger process was killed
1824 local killed=$(ps -o pid,comm hp $pid >/dev/null)
1828 wait_request_state $fid RESTORE CANCELED
1829 wait_request_state $fid CANCEL SUCCEED
1832 error "Cannot kill process waiting for restore ($killed)"
1836 run_test 33 "Kill a restore waiting process"
1839 # test needs a running copytool
1844 local f=$DIR/$tdir/$tfile
1845 local fid=$(make_large_for_progress $f)
1846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1847 wait_request_state $fid ARCHIVE SUCCEED
1850 md5sum $f >/dev/null &
1852 wait_request_state $fid RESTORE STARTED
1854 rm $f || error "rm $f failed"
1855 # rm must not block during restore
1856 wait_request_state $fid RESTORE STARTED
1858 wait_request_state $fid RESTORE SUCCEED
1859 # check md5sum pgm finished
1860 local there=$(ps -o pid,comm hp $pid >/dev/null)
1861 [[ -z $there ]] || error "Restore initiator does not exit"
1863 local rc=$(wait $pid)
1864 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1868 run_test 34 "Remove file during restore"
1871 # test needs a running copytool
1876 local f=$DIR/$tdir/$tfile
1877 local f1=$DIR/$tdir/$tfile-1
1878 local fid=$(make_large_for_progress $f)
1879 local fid1=$(copy_file /etc/passwd $f1)
1880 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1881 wait_request_state $fid ARCHIVE SUCCEED
1884 md5sum $f >/dev/null &
1886 wait_request_state $fid RESTORE STARTED
1888 mv $f1 $f || error "mv $f1 $f failed"
1889 # mv must not block during restore
1890 wait_request_state $fid RESTORE STARTED
1892 wait_request_state $fid RESTORE SUCCEED
1893 # check md5sum pgm finished
1894 local there=$(ps -o pid,comm hp $pid >/dev/null)
1895 [[ -z $there ]] || error "Restore initiator does not exit"
1897 local rc=$(wait $pid)
1898 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1901 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
1905 run_test 35 "Overwrite file during restore"
1908 # test needs a running copytool
1913 local f=$DIR/$tdir/$tfile
1914 local fid=$(make_large_for_progress $f)
1915 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1916 wait_request_state $fid ARCHIVE SUCCEED
1919 md5sum $f >/dev/null &
1921 wait_request_state $fid RESTORE STARTED
1924 # rm must not block during restore
1925 wait_request_state $fid RESTORE STARTED
1927 wait_request_state $fid RESTORE SUCCEED
1928 # check md5sum pgm finished
1929 local there=$(ps -o pid,comm hp $pid >/dev/null)
1931 error "Restore initiator does not exit"
1933 local rc=$(wait $pid)
1935 error "Restore initiator failed with $rc"
1939 run_test 36 "Move file during restore"
1946 for n in $(seq 1 $count); do
1947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
1949 echo "$count archive requests submitted"
1953 local stream_count=4
1954 local file_count=100
1956 local f=$DIR/$tdir/$tfile
1961 for i in $(seq 1 $file_count); do
1962 for p in $(seq 1 $stream_count); do
1963 fid=$(copy_file /etc/hosts $f.$p.$i)
1967 # to be sure wait_all_done will not be mislead by previous tests
1969 wait_for_grace_delay
1971 # start archive streams in background (archive files in parallel)
1972 for p in $(seq 1 $stream_count); do
1973 multi_archive $f.$p $file_count &
1976 echo -n "Wait for all requests being enqueued..."
1982 run_test 40 "Parallel archive requests"
1985 # test needs a running copytool
1989 local f=$DIR/$tdir/$tfile
1990 local fid=$(copy_file /etc/motd $f 1)
1992 $LFS hsm_archive $f || error "could not archive file"
1993 wait_request_state $fid ARCHIVE SUCCEED
1994 check_hsm_flags $f "0x00000009"
1996 multiop_bg_pause $f O_c || error "multiop failed"
2000 client_up || client_up || true
2002 kill -USR1 $MULTIPID
2003 wait $MULTIPID || error "multiop close failed"
2005 check_hsm_flags $f "0x0000000b"
2009 run_test 52 "Opened for write file on an evicted client should be set dirty"
2012 # test needs a running copytool
2016 local f=$DIR/$tdir/$tfile
2017 local fid=$(copy_file /etc/motd $f 1)
2019 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2020 error "could not archive file"
2021 wait_request_state $fid ARCHIVE SUCCEED
2022 check_hsm_flags $f "0x00000009"
2024 multiop_bg_pause $f o_c || error "multiop failed"
2028 client_up || client_up || true
2030 kill -USR1 $MULTIPID
2031 wait $MULTIPID || error "multiop close failed"
2033 check_hsm_flags $f "0x00000009"
2037 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2040 # test needs a running copytool
2044 local f=$DIR/$tdir/$tfile
2045 local fid=$(make_small $f)
2047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2048 error "could not archive file"
2049 wait_request_state $fid ARCHIVE STARTED
2051 check_hsm_flags $f "0x00000001"
2053 # Avoid coordinator resending this request as soon it has failed.
2058 wait_request_state $fid ARCHIVE FAILED
2060 check_hsm_flags $f "0x00000003"
2065 run_test 54 "Write during an archive cancels it"
2068 # test needs a running copytool
2072 local f=$DIR/$tdir/$tfile
2073 local fid=$(make_small $f)
2075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2076 error "could not archive file"
2077 wait_request_state $fid ARCHIVE STARTED
2079 check_hsm_flags $f "0x00000001"
2081 # Avoid coordinator resending this request as soon it has failed.
2084 $TRUNCATE $f 1024 || error "truncate failed"
2086 wait_request_state $fid ARCHIVE FAILED
2088 check_hsm_flags $f "0x00000003"
2093 run_test 55 "Truncate during an archive cancels it"
2096 # test needs a running copytool
2100 local f=$DIR/$tdir/$tfile
2101 local fid=$(make_large_for_progress $f)
2103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2104 error "could not archive file"
2105 wait_request_state $fid ARCHIVE STARTED
2107 check_hsm_flags $f "0x00000001"
2109 # Change metadata and sync to be sure we are not changing only
2114 wait_request_state $fid ARCHIVE SUCCEED
2116 check_hsm_flags $f "0x00000009"
2120 run_test 56 "Setattr during an archive is ok"
2123 # Need one client for I/O, one for request
2124 needclients 2 || return 0
2126 # test needs a running copytool
2130 local f=$DIR/$tdir/test_archive_remote
2131 # Create a file on a remote node
2132 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2133 "count=2 conv=fsync"
2136 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2137 error "hsm_archive failed"
2138 local fid=$(path2fid $f)
2139 wait_request_state $fid ARCHIVE SUCCEED
2141 # Release and implicit restore it
2142 do_node $CLIENT2 "$LFS hsm_release $f" ||
2143 error "hsm_release failed"
2144 do_node $CLIENT2 "md5sum $f" ||
2145 error "hsm_restore failed"
2147 wait_request_state $fid RESTORE SUCCEED
2151 run_test 57 "Archive a file with dirty cache on another node"
2153 truncate_released_file() {
2157 local sz=$(stat -c %s $src_file)
2158 local f=$DIR/$tdir/$tfile
2159 local fid=$(copy_file $1 $f)
2163 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2164 error "could not archive file"
2165 wait_request_state $fid ARCHIVE SUCCEED
2167 $LFS hsm_release $f || error "could not release file"
2169 $TRUNCATE $f $trunc_to || error "truncate failed"
2172 local sz1=$(stat -c %s $f)
2173 [[ $sz1 == $trunc_to ]] ||
2174 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2177 check_hsm_flags $f "0x0000000b"
2179 local state=$(get_request_state $fid RESTORE)
2180 [[ "$state" == "SUCCEED" ]] ||
2181 error "truncate $sz does not trig restore, state = $state"
2183 $TRUNCATE $ref $trunc_to
2184 cmp $ref $f || error "file data wrong after truncate"
2190 # test needs a running copytool
2195 local sz=$(stat -c %s /etc/passwd)
2197 echo "truncate up from $sz to $((sz*2))"
2198 truncate_released_file /etc/passwd $((sz*2))
2200 echo "truncate down from $sz to $((sz/2))"
2201 truncate_released_file /etc/passwd $((sz/2))
2203 echo "truncate to 0"
2204 truncate_released_file /etc/passwd 0
2208 run_test 58 "Truncate a released file will trigger restore"
2213 local f=$DIR/$tdir/$tfile
2214 local FILELIST=/tmp/filelist.txt
2218 for i in $(seq 1 $file_count); do
2219 fid=$(copy_file /etc/hosts $f.$i)
2220 echo $f.$i >> $FILELIST
2223 # to be sure wait_all_done will not be mislead by previous tests
2225 wait_for_grace_delay
2226 $LFS hsm_archive --filelist $FILELIST ||
2227 error "cannot archive a file list"
2229 $LFS hsm_release --filelist $FILELIST ||
2230 error "cannot release a file list"
2231 $LFS hsm_restore --filelist $FILELIST ||
2232 error "cannot restore a file list"
2236 run_test 90 "Archive/restore a file list"
2238 double_verify_reset_hsm_param() {
2240 echo "Testing $HSM_PARAM.$p"
2241 local val=$(get_hsm_param $p)
2243 local val2=$(($val * 2))
2244 set_hsm_param $p $val2
2245 val=$(get_hsm_param $p)
2246 [[ $val == $val2 ]] ||
2247 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2248 echo "Set $p to 0 must failed"
2252 set_hsm_param $p $save
2256 error "we must not be able to set $HSM_PARAM.$p to 0"
2261 double_verify_reset_hsm_param loop_period
2262 double_verify_reset_hsm_param grace_delay
2263 double_verify_reset_hsm_param request_timeout
2264 double_verify_reset_hsm_param max_requests
2265 double_verify_reset_hsm_param archive_id
2267 run_test 100 "Set coordinator /proc tunables"
2274 run_test 102 "Verify coordinator control"
2277 # test needs a running copytool
2284 for i in $(seq 1 20); do
2285 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2291 echo "Current requests"
2292 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2293 $HSM_PARAM.agent_actions |\
2294 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2296 [[ -z "$res" ]] || error "Some request have not been canceled"
2300 run_test 103 "Purge all requests"
2305 # test needs a running copytool
2309 local f=$DIR/$tdir/$tfile
2310 local fid=$(make_large_for_progress $f)
2311 # if cdt is on, it can serve too quickly the request
2313 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2314 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2315 $HSM_PARAM.agent_actions |\
2316 grep $fid | cut -f16 -d=")
2319 [[ "$data1" == "$DATAHEX" ]] ||
2320 error "Data field in records is ($data1) and not ($DATAHEX)"
2324 run_test 104 "Copy tool data field"
2331 for i in $(seq -w 1 10); do
2332 cp /etc/passwd $DIR/$tdir/$i
2333 $LFS hsm_archive $DIR/$tdir/$i
2335 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2336 $HSM_PARAM.agent_actions |\
2337 grep WAITING | wc -l")
2340 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2341 $HSM_PARAM.agent_actions |\
2342 grep WAITING | wc -l")
2345 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2346 error "Requests count after shutdown $reqcnt2 != "\
2347 "before shutdown $reqcnt1"
2349 run_test 105 "Restart of coordinator"
2352 # test needs a running copytool
2355 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2356 get_client_uuid $MOUNT | cut -d' ' -f2)
2357 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2360 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2361 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2363 [[ -z "$agent" ]] ||
2364 error "My uuid $uuid still found in agent list,"\
2365 " after copytool shutdown"
2367 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2370 [[ ! -z "$agent" ]] ||
2371 error "My uuid $uuid not found in agent list after"\
2374 run_test 106 "Copytool register/unregister"
2377 # test needs a running copytool
2379 # create and archive file
2381 local f1=$DIR/$tdir/$tfile
2382 local fid=$(copy_file /etc/passwd $f1)
2383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2384 wait_request_state $fid ARCHIVE SUCCEED
2385 # shutdown and restart MDS
2387 # check the copytool still gets messages from MDT
2388 local f2=$DIR/$tdir/2
2389 local fid=$(copy_file /etc/passwd $f2)
2390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2391 # main check of this sanity: this request MUST succeed
2392 wait_request_state $fid ARCHIVE SUCCEED
2395 run_test 107 "Copytool re-register after MDS restart"
2397 policy_set_and_test()
2401 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2402 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2403 [[ "$policy" == "$target" ]] ||
2404 error "Wrong policy after '$change': '$policy' != '$target'"
2408 # to force default policy setting if error
2409 CDT_POLICY_HAD_CHANGED=true
2411 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2412 local default="NonBlockingRestore [NoRetryAction]"
2413 [[ "$policy" == "$default" ]] ||
2414 error "default policy has changed,"\
2415 " '$policy' != '$default' update the test"
2416 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2417 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2418 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2419 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2420 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2421 # useless bacause we know but safer for futur changes to use real value
2422 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2423 echo "Next set_param must failed"
2424 policy_set_and_test "wrong" "$policy"
2427 echo "Back to default policy"
2428 cdt_set_sanity_policy
2430 run_test 109 "Policy display/change"
2433 # test needs a running copytool
2438 copy2archive /etc/passwd $tdir/$tfile
2440 local f=$DIR/$tdir/$tfile
2441 import_file $tdir/$tfile $f
2442 local fid=$(path2fid $f)
2444 cdt_set_non_blocking_restore
2449 wait_request_state $fid RESTORE SUCCEED
2450 cdt_clear_non_blocking_restore
2454 error "md5sum returns $st != 1, "\
2455 "should also perror ENODATA (No data available)"
2459 run_test 110a "Non blocking restore policy (import case)"
2462 # test needs a running copytool
2466 local f=$DIR/$tdir/$tfile
2467 local fid=$(copy_file /etc/passwd $f)
2468 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2469 wait_request_state $fid ARCHIVE SUCCEED
2472 cdt_set_non_blocking_restore
2477 wait_request_state $fid RESTORE SUCCEED
2478 cdt_clear_non_blocking_restore
2482 error "md5sum returns $st != 1, "\
2483 "should also perror ENODATA (No data available)"
2487 run_test 110b "Non blocking restore policy (release case)"
2490 # test needs a running copytool
2494 copy2archive /etc/passwd $tdir/$tfile
2496 local f=$DIR/$tdir/$tfile
2498 import_file $tdir/$tfile $f
2499 local fid=$(path2fid $f)
2503 copytool_remove_backend $fid
2506 wait_request_state $fid RESTORE FAILED
2513 [[ $st == 0 ]] || error "Restore does not failed"
2517 run_test 111a "No retry policy (import case), restore will error"\
2518 " (No such file or directory)"
2521 # test needs a running copytool
2525 local f=$DIR/$tdir/$tfile
2526 local fid=$(copy_file /etc/passwd $f)
2528 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2529 wait_request_state $fid ARCHIVE SUCCEED
2532 copytool_remove_backend $fid
2535 wait_request_state $fid RESTORE FAILED
2542 [[ $st == 0 ]] || error "Restore does not failed"
2546 run_test 111b "No retry policy (release case), restore will error"\
2547 " (No such file or directory)"
2550 # test needs a running copytool
2554 local f=$DIR/$tdir/$tfile
2555 local fid=$(copy_file /etc/passwd $f)
2557 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2558 local l=$($LFS hsm_action $f)
2560 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2564 wait_request_state $fid ARCHIVE SUCCEED
2567 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2571 run_test 112 "State of recorded request"
2574 # test needs a running copytool
2578 local f=$DIR/$tdir/$tfile
2579 local fid=$(make_large_for_cancel $f)
2580 # test with cdt on is made in test_221
2582 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2585 wait_request_state $fid ARCHIVE CANCELED
2586 wait_request_state $fid CANCEL SUCCEED
2590 run_test 200 "Register/Cancel archive"
2593 # test needs a running copytool
2597 local f=$DIR/$tdir/$tfile
2598 make_archive $tdir/$tfile
2599 import_file $tdir/$tfile $f
2600 local fid=$(path2fid $f)
2602 # test with cdt on is made in test_222
2607 wait_request_state $fid RESTORE CANCELED
2608 wait_request_state $fid CANCEL SUCCEED
2612 run_test 201 "Register/Cancel restore"
2615 # test needs a running copytool
2619 local f=$DIR/$tdir/$tfile
2620 local fid=$(make_large_for_progress $f)
2621 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2622 wait_request_state $fid ARCHIVE SUCCEED
2628 wait_request_state $fid REMOVE CANCELED
2632 run_test 202 "Register/Cancel remove"
2635 # test needs a running copytool
2640 local f=$DIR/$tdir/$tfile
2641 local fid=$(copy_file /etc/passwd $f)
2645 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2646 wait_request_state $fid ARCHIVE SUCCEED
2648 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2652 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2656 run_test 220 "Changelog for archive"
2659 # test needs a running copytool
2664 local f=$DIR/$tdir/$tfile
2665 local fid=$(make_large_for_cancel $f)
2669 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2670 wait_request_state $fid ARCHIVE STARTED
2672 wait_request_state $fid ARCHIVE CANCELED
2673 wait_request_state $fid CANCEL SUCCEED
2675 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2678 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2682 run_test 221 "Changelog for archive canceled"
2685 # test needs a running copytool
2689 copy2archive /etc/passwd $tdir/$tfile
2691 local f=$DIR/$tdir/$tfile
2692 import_file $tdir/$tfile $f
2693 local fid=$(path2fid $f)
2698 wait_request_state $fid RESTORE SUCCEED
2700 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2703 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2707 run_test 222a "Changelog for explicit restore"
2710 # test needs a running copytool
2714 local f=$DIR/$tdir/$tfile
2715 local fid=$(copy_file /etc/passwd $f)
2718 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2719 wait_request_state $fid ARCHIVE SUCCEED
2724 wait_request_state $fid RESTORE SUCCEED
2726 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2729 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2733 run_test 222b "Changelog for implicit restore"
2736 # test needs a running copytool
2741 local f=$DIR/$tdir/$tfile
2742 make_archive $tdir/$tfile
2746 import_file $tdir/$tfile $f
2747 local fid=$(path2fid $f)
2750 wait_request_state $fid RESTORE STARTED
2752 wait_request_state $fid RESTORE CANCELED
2753 wait_request_state $fid CANCEL SUCCEED
2755 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2758 [[ $flags == $target ]] ||
2759 error "Changelog flag is $flags not $target"
2763 run_test 223a "Changelog for restore canceled (import case)"
2766 # test needs a running copytool
2771 local f=$DIR/$tdir/$tfile
2772 local fid=$(make_large_for_progress $f)
2775 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2776 wait_request_state $fid ARCHIVE SUCCEED
2779 wait_request_state $fid RESTORE STARTED
2781 wait_request_state $fid RESTORE CANCELED
2782 wait_request_state $fid CANCEL SUCCEED
2784 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2787 [[ $flags == $target ]] ||
2788 error "Changelog flag is $flags not $target"
2792 run_test 223b "Changelog for restore canceled (release case)"
2795 # test needs a running copytool
2800 local f=$DIR/$tdir/$tfile
2801 local fid=$(copy_file /etc/passwd $f)
2804 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2805 wait_request_state $fid ARCHIVE SUCCEED
2808 wait_request_state $fid REMOVE SUCCEED
2810 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2813 [[ $flags == $target ]] ||
2814 error "Changelog flag is $flags not $target"
2818 run_test 224 "Changelog for remove"
2821 # test needs a running copytool
2824 # test is not usable because remove request is too fast
2825 # so it is always finished before cancel can be done ...
2826 echo "Test disabled"
2831 local f=$DIR/$tdir/$tfile
2832 local fid=$(make_large_for_progress $f)
2835 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2836 wait_request_state $fid ARCHIVE SUCCEED
2838 # if cdt is on, it can serve too quickly the request
2843 wait_request_state $fid REMOVE CANCELED
2844 wait_request_state $fid CANCEL SUCCEED
2846 flags=$(changelog_get_flags $MDT0 RENME $fid2)
2847 local flags=$($LFS changelog $MDT0 | grep HSM | grep $fid | tail -1 |
2851 [[ $flags == $target ]] ||
2852 error "Changelog flag is $flags not $target"
2856 run_test 225 "Changelog for remove canceled"
2859 # test needs a running copytool
2864 local f1=$DIR/$tdir/$tfile-1
2865 local f2=$DIR/$tdir/$tfile-2
2866 local f3=$DIR/$tdir/$tfile-3
2867 local fid1=$(copy_file /etc/passwd $f1)
2868 local fid2=$(copy_file /etc/passwd $f2)
2869 copy_file /etc/passwd $f3
2872 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2873 wait_request_state $fid1 ARCHIVE SUCCEED
2875 $LFS hsm_archive $f2
2876 wait_request_state $fid2 ARCHIVE SUCCEED
2878 rm $f1 || error "rm $f1 failed"
2880 local flags=$(changelog_get_flags $MDT0 UNLNK $fid1)
2883 [[ $flags == $target ]] ||
2884 error "Changelog flag is $flags not $target"
2886 mv $f3 $f2 || error "mv $f3 $f2 failed"
2888 flags=$(changelog_get_flags $MDT0 RENME $fid2)
2891 [[ $flags == $target ]] ||
2892 error "Changelog flag is $flags not $target"
2896 run_test 226 "changelog for last rm/mv with exiting archive"
2898 check_flags_changes() {
2906 $LFS hsm_set --$hsm_flag $f ||
2907 error "Cannot set $hsm_flag on $f"
2908 local flags=($(changelog_get_flags $MDT0 HSM $fid))
2909 local seen=${#flags[*]}
2911 [[ $seen == $cnt ]] ||
2912 error "set $hsm_flag: Changelog events $seen != $cnt"
2913 [[ ${flags[$((cnt - 1))]} == $target ]] ||
2914 error "set $hsm_flag: Changelog flags are "\
2915 "${flags[$((cnt - 1))]} not $target"
2917 $LFS hsm_clear --$hsm_flag $f ||
2918 error "Cannot clear $hsm_flag on $f"
2919 flags=($(changelog_get_flags $MDT0 HSM $fid))
2922 [[ $cnt == $seen ]] ||
2923 error "clear $hsm_flag: Changelog events $seen != $cnt"
2925 [[ ${flags[$((cnt - 1))]} == $target ]] ||
2926 error "clear $hsm_flag: Changelog flag is "\
2927 "${flags[$((cnt - 1))]} not $target"
2931 # test needs a running copytool
2938 for i in norelease noarchive exists archived
2940 local f=$DIR/$tdir/$tfile-$i
2941 local fid=$(copy_file /etc/passwd $f)
2942 check_flags_changes $f $fid $i 0 1
2945 f=$DIR/$tdir/$tfile---lost
2946 fid=$(copy_file /etc/passwd $f)
2947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2948 wait_request_state $fid ARCHIVE SUCCEED
2949 check_flags_changes $f $fid lost 3 1
2953 run_test 227 "changelog when explicit setting of HSM flags"
2956 # test needs a running copytool
2960 local maxrequest=$(get_hsm_param max_requests)
2961 local rqcnt=$(($maxrequest * 3))
2965 for i in $(seq -w 1 $rqcnt); do
2967 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
2969 # we do it in 2 steps, so all requests arrive at the same time
2970 for i in $(seq -w 1 $rqcnt); do
2971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
2976 while [[ $cnt != 0 || $wt != 0 ]]; do
2978 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2979 $HSM_PARAM.agent_actions |\
2980 grep STARTED | grep -v CANCEL | wc -l")
2981 [[ $cnt -le $maxrequest ]] ||
2982 error "$cnt > $maxrequest too many started requests"
2983 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
2984 $HSM_PARAM.agent_actions |\
2985 grep WAITING | wc -l")
2986 echo "max=$maxrequest started=$cnt waiting=$wt"
2991 run_test 250 "Coordinator max request"
2994 # test needs a running copytool
2998 local f=$DIR/$tdir/$tfile
2999 local fid=$(make_large_for_cancel $f)
3002 # to have a short test
3003 local old_to=$(get_hsm_param request_timeout)
3004 set_hsm_param request_timeout 4
3005 # to be sure the cdt will wake up frequently so
3006 # it will be able to cancel the "old" request
3007 local old_loop=$(get_hsm_param loop_period)
3008 set_hsm_param loop_period 2
3011 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3012 wait_request_state $fid ARCHIVE STARTED
3014 wait_request_state $fid ARCHIVE CANCELED
3016 set_hsm_param request_timeout $old_to
3017 set_hsm_param loop_period $old_loop
3021 run_test 251 "Coordinator request timeout"
3024 # the only way to test ondisk conf is to restart MDS ...
3025 echo "Stop coordinator and remove coordinator state at mount"
3028 # clean on disk conf set by default
3029 cdt_clear_mount_state
3030 cdt_check_state stopped
3032 # check cdt still off after umount/remount
3034 cdt_check_state stopped
3036 echo "Set coordinator start at mount, and start coordinator"
3037 cdt_set_mount_state enabled
3040 cdt_check_state enabled
3042 # check cdt still on after umount/remount
3044 cdt_check_state enabled
3046 # we are back to original state (cdt started at mount)
3048 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3053 check_and_cleanup_lustre