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 12a 12b 12n 13 30a 31a 34 35 36 58 59"
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 110a 200 201 221 222a 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.
119 search_and_kill_copytool() {
120 local agents=${1:-$(facet_active_host $SINGLEAGT)}
122 echo "Killing existing copytools on $agents"
123 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
127 local facet=${1:-$SINGLEAGT}
128 local lustre_mntpnt=${2:-$MOUNT}
130 local hsm_root=$(copytool_device $facet)
131 local agent=$(facet_active_host $facet)
133 if [[ -z "$arc_id" ]] &&
134 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
135 echo "Wakeup copytool $facet on $agent"
139 if $HSM_ARCHIVE_PURGE; then
140 echo "Purging archive on $agent"
141 do_facet $facet "rm -rf $hsm_root/*"
144 echo "Starting copytool $facet on $agent"
145 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
146 # bandwidth is limited to 1MB/s so the copy time is known and
147 # independent of hardware
148 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
149 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
150 cmd+=" --bandwidth 1 $lustre_mntpnt"
152 # Redirect the standard output and error to a log file which
153 # can be uploaded to Maloo.
154 local prefix=$TESTLOG_PREFIX
155 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
156 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
158 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
159 error "start copytool $facet on $agent failed"
165 local agents=${1:-$(facet_active_host $SINGLEAGT)}
167 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
169 echo "Copytool is stopped on $agents"
173 local agents=${1:-$(facet_active_host $SINGLEAGT)}
175 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
176 echo "Copytool is suspended on $agents"
179 copytool_remove_backend() {
181 local be=$(find $HSM_ARCHIVE -name $fid)
182 echo "Remove from backend: $fid = $be"
187 do_facet $SINGLEAGT \
188 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
189 --import $1 $2 $MOUNT" ||
190 error "import of $1 to $2 failed"
194 local file=$HSM_ARCHIVE/$1
195 mkdir -p $(dirname $file)
196 dd if=/dev/urandom of=$file count=32 bs=1000000 ||
197 error "cannot create $file"
201 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0\
202 changelog_register -n)
203 do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+hsm"
204 $LFS changelog_clear $MDT0 $CL_USER 0
207 changelog_cleanup() {
208 # $LFS changelog $MDT0
209 [[ -n "$CL_USER" ]] || return 0
211 $LFS changelog_clear $MDT0 $CL_USER 0
212 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
216 changelog_get_flags() {
221 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
226 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
233 do_facet $SINGLEMDS $LCTL set_param -n $HSM_PARAM.$param=$value
240 do_facet $SINGLEMDS $LCTL set_param $MDT_PARAM.hsm_control=$cmd
241 wait_result $SINGLEMDS "$LCTL get_param -n $MDT_PARAM.hsm_control"\
242 $target 10 || error "cdt state is not $target"
245 cdt_set_sanity_policy() {
247 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nra
248 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nbr
249 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-gc
253 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+nra
256 cdt_clear_no_retry() {
257 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nra
260 cdt_set_no_blocking_restore() {
261 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+nbr
264 cdt_clear_no_blocking_restore() {
265 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nbr
268 cdt_clear_mount_state() {
269 # /!\ conf_param and set_param syntax differ +> we cannot use
271 do_facet $SINGLEMDS $LCTL conf_param -d $FSNAME-MDT0000.mdt.hsm_control
274 cdt_set_mount_state() {
275 # /!\ conf_param and set_param syntax differ +> we cannot use
277 do_facet $SINGLEMDS $LCTL conf_param $FSNAME-MDT0000.mdt.hsm_control=$1
282 wait_result $SINGLEMDS\
283 "$LCTL get_param -n $MDT_PARAM.hsm_control" "$target" 20 ||
284 error "cdt state is not $target"
288 set_test_state disabled disabled
292 set_test_state enabled enabled
296 set_test_state shutdown stopped
300 set_test_state purge enabled
306 cdt_set_sanity_policy
310 if [[ $CLIENTCOUNT -lt 2 ]]; then
311 skip "Need two or more clients, have $CLIENTCOUNT"
318 $LFS path2fid $1 | tr -d '[]'
325 if [[ $u == "user" ]]
327 local st=$($RUNAS $LFS hsm_state $f)
329 local st=$($LFS hsm_state $f)
333 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
335 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
339 get_hsm_archive_id() {
341 local st=$($LFS hsm_state $f)
342 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
344 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
353 local st=$(get_hsm_flags $f)
354 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
357 check_hsm_flags_user() {
361 local st=$(get_hsm_flags $f user)
362 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
380 cp $1 $f || error "cannot copy $1 to $f"
381 path2fid $f || error "cannot get fid on $f"
385 local file2=${1/$DIR/$DIR2}
386 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
387 error "cannot create $file2"
388 path2fid $1 || error "cannot get fid on $1"
391 cleanup_large_files() {
392 local ratio=$(df $MOUNT |awk '{print $5}' |sed 's/%//g' |grep -v Use)
393 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
396 make_large_for_striping() {
397 local file2=${1/$DIR/$DIR2}
398 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
402 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
403 error "cannot create $file2"
404 path2fid $1 || error "cannot get fid on $1"
407 make_large_for_progress() {
408 local file2=${1/$DIR/$DIR2}
412 # big file is large enough, so copy time is > 30s
413 # so copytool make 1 progress
414 # size is not a multiple of 1M to avoid stripe
416 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
417 error "cannot create $file2"
418 path2fid $1 || error "cannot get fid on $1"
421 make_large_for_progress_aligned() {
422 local file2=${1/$DIR/$DIR2}
426 # big file is large enough, so copy time is > 30s
427 # so copytool make 1 progress
428 # size is a multiple of 1M to have stripe
430 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
431 error "cannot create $file2"
432 path2fid $1 || error "cannot get fid on $1"
435 make_large_for_cancel() {
436 local file2=${1/$DIR/$DIR2}
440 # Copy timeout is 100s. 105MB => 105s
441 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
442 error "cannot create $file2"
443 path2fid $1 || error "cannot get fid on $1"
449 wait_update --verbose $(facet_active_host $facet) "$@"
452 wait_request_state() {
457 local cmd="$LCTL get_param -n $HSM_PARAM.agent_actions"
458 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
460 wait_result $SINGLEMDS "$cmd" $state 100 ||
461 error "request on $fid is not $state"
464 get_request_state() {
468 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.agent_actions |"\
469 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
472 get_request_count() {
476 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.agent_actions |"\
477 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
483 local cmd="$LCTL get_param -n $HSM_PARAM.agent_actions"
484 cmd+=" | egrep 'WAITING|STARTED'"
486 wait_result $SINGLEMDS "$cmd" "" $timeout ||
487 error "requests did not complete"
490 wait_for_grace_delay() {
491 local val=$(get_hsm_param grace_delay)
495 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
496 awk '{gsub(/_UUID/,""); print $1}' | head -1)
501 # cleanup from previous bad setup
502 search_and_kill_copytool
504 # for recovery tests, coordinator needs to be started at mount
506 # the lustre conf must be without hsm on (like for sanity.sh)
507 echo "Set HSM on and start"
508 cdt_set_mount_state enabled
509 cdt_check_state enabled
511 echo "Start copytool"
514 # finished requests are quickly removed from list
515 set_hsm_param grace_delay 10
521 local f=$DIR/$tdir/$tfile
525 check_hsm_flags_user $f "0x00000000"
527 $RUNAS $LFS hsm_set --norelease $f ||
528 error "user could not change hsm flags"
529 check_hsm_flags_user $f "0x00000010"
531 $RUNAS $LFS hsm_clear --norelease $f ||
532 error "user could not clear hsm flags"
533 check_hsm_flags_user $f "0x00000000"
535 # User could not change those flags...
536 $RUNAS $LFS hsm_set --exists $f &&
537 error "user should not set this flag"
538 check_hsm_flags_user $f "0x00000000"
541 $LFS hsm_set --exists $f ||
542 error "root could not change hsm flags"
543 check_hsm_flags_user $f "0x00000001"
545 $LFS hsm_clear --exists $f ||
546 error "root could not clear hsm state"
547 check_hsm_flags_user $f "0x00000000"
550 run_test 1 "lfs hsm flags root/non-root access"
554 local f=$DIR/$tdir/$tfile
556 # New files are not dirty
557 check_hsm_flags $f "0x00000000"
559 # For test, we simulate an archived file.
560 $LFS hsm_set --exists $f || error "user could not change hsm flags"
561 check_hsm_flags $f "0x00000001"
563 # chmod do not put the file dirty
564 chmod 600 $f || error "could not chmod test file"
565 check_hsm_flags $f "0x00000001"
567 # chown do not put the file dirty
568 chown $RUNAS_ID $f || error "could not chown test file"
569 check_hsm_flags $f "0x00000001"
571 # truncate put the file dirty
572 $TRUNCATE $f 1 || error "could not truncate test file"
573 check_hsm_flags $f "0x00000003"
575 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
576 check_hsm_flags $f "0x00000001"
578 run_test 2 "Check file dirtyness when doing setattr"
584 # New files are not dirty
586 check_hsm_flags $f "0x00000000"
588 # For test, we simulate an archived file.
589 $LFS hsm_set --exists $f ||
590 error "user could not change hsm flags"
591 check_hsm_flags $f "0x00000001"
593 # Reading a file, does not set dirty
594 cat $f > /dev/null || error "could not read file"
595 check_hsm_flags $f "0x00000001"
597 # Open for write without modifying data, does not set dirty
598 openfile -f O_WRONLY $f || error "could not open test file"
599 check_hsm_flags $f "0x00000001"
601 # Append to a file sets it dirty
602 cp -p /etc/passwd $f.append || error "could not create file"
603 $LFS hsm_set --exists $f.append ||
604 error "user could not change hsm flags"
605 dd if=/etc/passwd of=$f.append bs=1 count=3\
606 conv=notrunc oflag=append status=noxfer ||
607 error "could not append to test file"
608 check_hsm_flags $f.append "0x00000003"
610 # Modify a file sets it dirty
611 cp -p /etc/passwd $f.modify || error "could not create file"
612 $LFS hsm_set --exists $f.modify ||
613 error "user could not change hsm flags"
614 dd if=/dev/zero of=$f.modify bs=1 count=3\
615 conv=notrunc status=noxfer ||
616 error "could not modify test file"
617 check_hsm_flags $f.modify "0x00000003"
619 # Open O_TRUNC sets dirty
620 cp -p /etc/passwd $f.trunc || error "could not create file"
621 $LFS hsm_set --exists $f.trunc ||
622 error "user could not change hsm flags"
623 cp /etc/group $f.trunc || error "could not override a file"
624 check_hsm_flags $f.trunc "0x00000003"
626 # Mmapped a file sets dirty
627 cp -p /etc/passwd $f.mmap || error "could not create file"
628 $LFS hsm_set --exists $f.mmap ||
629 error "user could not change hsm flags"
630 multiop $f.mmap OSMWUc || error "could not mmap a file"
631 check_hsm_flags $f.mmap "0x00000003"
633 run_test 3 "Check file dirtyness when opening for write"
637 local f=$DIR/$tdir/$tfile
638 local fid=$(make_small $f)
641 local st=$(get_request_state $fid CANCEL)
642 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
644 run_test 4 "Useless cancel must not be registered"
647 # test needs a running copytool
651 local f=$DIR/$tdir/$tfile
652 local fid=$(copy_file /etc/passwd $f)
654 wait_request_state $fid ARCHIVE SUCCEED
656 check_hsm_flags $f "0x00000009"
660 run_test 8 "Test default archive number"
664 local f=$DIR/$tdir/$tfile
665 local fid=$(copy_file /etc/passwd $f)
666 # we do not use the default one to be sure
667 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
669 copytool_setup $SINGLEAGT $MOUNT $new_an
670 $LFS hsm_archive --archive $new_an $f
671 wait_request_state $fid ARCHIVE SUCCEED
673 check_hsm_flags $f "0x00000009"
677 run_test 9 "Use of explict archive number, with dedicated copytool"
680 [[ $CLIENTCOUNT -ge 3 ]] ||
681 { skip "Need three or more clients"; return 0; }
687 copytool_cleanup $(comma_list $(agts_nodes))
689 # start all of the copytools
690 for n in $(seq $AGTCOUNT); do
694 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
697 for n in $(seq $AGTCOUNT); do
698 file=$DIR/$tdir/$tfile.$n
699 fid=$(make_small $file)
701 $LFS hsm_archive $file || error "could not archive file $file"
702 wait_request_state $fid ARCHIVE SUCCEED
703 check_hsm_flags $file "0x00000001"
707 copytool_cleanup $(comma_list $(agts_nodes))
709 run_test 9a "Multiple remote agents"
712 # test needs a running copytool
715 mkdir -p $DIR/$tdir/d1
716 local f=$DIR/$tdir/$tfile
717 local fid=$(copy_file /etc/hosts $f)
718 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
719 error "hsm_archive failed"
720 wait_request_state $fid ARCHIVE SUCCEED
722 local AFILE=$(ls $HSM_ARCHIVE/*/*/*/*/*/*/$fid) ||
723 error "fid $fid not in archive $HSM_ARCHIVE"
724 echo "Verifying content"
725 diff $f $AFILE || error "archived file differs"
726 echo "Verifying hsm state "
727 check_hsm_flags $f "0x00000009"
729 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
730 local st=$(get_hsm_archive_id $f)
731 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
732 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
737 run_test 10a "Archive a file"
740 # test needs a running copytool
743 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
744 local f=$DIR/$tdir/$tfile
745 local fid=$(copy_file /etc/hosts $f)
746 $LFS hsm_archive $f || error "archive request failed"
747 wait_request_state $fid ARCHIVE SUCCEED
749 $LFS hsm_archive $f || error "archive of non dirty file failed"
750 local cnt=$(get_request_count $fid ARCHIVE)
751 [[ "$cnt" == "1" ]] ||
752 error "archive of non dirty file must not make a request"
756 run_test 10b "Archive of non dirty file must work without doing request"
759 # test needs a running copytool
762 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
763 local f=$DIR/$tdir/$tfile
764 local fid=$(copy_file /etc/hosts $f)
765 $LFS hsm_set --noarchive $f
766 $LFS hsm_archive $f && error "archive a noarchive file must fail"
770 run_test 10c "Check forbidden archive"
773 # test needs a running copytool
777 local f=$DIR/$tdir/$tfile
778 local fid=$(copy_file /etc/hosts $f)
779 $LFS hsm_archive $f || error "cannot archive $f"
780 wait_request_state $fid ARCHIVE SUCCEED
782 local ar=$(get_hsm_archive_id $f)
783 local dflt=$(get_hsm_param archive_id)
784 [[ $ar == $dflt ]] ||
785 error "archived file is not on default archive: $ar != $dflt"
789 run_test 10d "Archive a file on the default archive id"
792 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
793 cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
794 local f=$DIR/$tdir/$tfile
796 import_file $tdir/$tfile $f
797 echo -n "Verifying released state: "
798 check_hsm_flags $f "0x0000000d"
800 local LSZ=$(stat -c "%s" $f)
801 local ASZ=$(stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
803 echo "Verifying imported size $LSZ=$ASZ"
804 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
805 echo -n "Verifying released pattern: "
806 local PTRN=$($GETSTRIPE -L $f)
808 [[ $PTRN == 80000001 ]] || error "Is not released"
809 local fid=$(path2fid $f)
810 echo "Verifying new fid $fid in archive"
812 local AFILE=$(ls $HSM_ARCHIVE/*/*/*/*/*/*/$fid) ||
813 error "fid $fid not in archive $HSM_ARCHIVE"
815 run_test 11 "Import a file"
818 # test needs a running copytool
821 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
822 cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
823 local f=$DIR/$tdir/$tfile
824 import_file $tdir/$tfile $f
825 local f=$DIR2/$tdir/$tfile
826 echo "Verifying released state: "
827 check_hsm_flags $f "0x0000000d"
829 local fid=$(path2fid $f)
831 wait_request_state $fid RESTORE SUCCEED
833 echo "Verifying file state: "
834 check_hsm_flags $f "0x00000009"
836 diff -q $HSM_ARCHIVE/$tdir/$tfile $f
838 [[ $? -eq 0 ]] || error "Restored file differs"
842 run_test 12a "Restore an imported file explicitly"
845 # test needs a running copytool
848 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
849 cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
850 local f=$DIR/$tdir/$tfile
851 import_file $tdir/$tfile $f
852 echo "Verifying released state: "
853 check_hsm_flags $f "0x0000000d"
855 cat $f > /dev/null || error "File read failed"
857 echo "Verifying file state after restore: "
858 check_hsm_flags $f "0x00000009"
860 diff -q $HSM_ARCHIVE/$tdir/$tfile $f
862 [[ $? -eq 0 ]] || error "Restored file differs"
866 run_test 12b "Restore an imported file implicitly"
869 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
871 # test needs a running copytool
875 local f=$DIR/$tdir/$tfile
876 $LFS setstripe -c 2 $f
877 local fid=$(make_large_for_striping $f)
878 local FILE_CRC=$(md5sum $f)
880 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
881 wait_request_state $fid ARCHIVE SUCCEED
882 $LFS hsm_release $f || error "release $f failed"
884 echo "$FILE_CRC" | md5sum -c
886 [[ $? -eq 0 ]] || error "Restored file differs"
890 run_test 12c "Restore a file with stripe of 2"
893 # test needs a running copytool
896 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
897 local f=$DIR/$tdir/$tfile
898 local fid=$(copy_file /etc/hosts $f)
899 $LFS hsm_restore $f || error "restore of non archived file failed"
900 local cnt=$(get_request_count $fid RESTORE)
901 [[ "$cnt" == "0" ]] ||
902 error "restore non archived must not make a request"
903 $LFS hsm_archive $f ||
904 error "archive request failed"
905 wait_request_state $fid ARCHIVE SUCCEED
906 $LFS hsm_restore $f ||
907 error "restore of non released file failed"
908 local cnt=$(get_request_count $fid RESTORE)
909 [[ "$cnt" == "0" ]] ||
910 error "restore a non dirty file must not make a request"
914 run_test 12d "Restore of a non archived, non released file must work"\
915 " without doing request"
918 # test needs a running copytool
921 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
922 local f=$DIR/$tdir/$tfile
923 local fid=$(copy_file /etc/hosts $f)
924 $LFS hsm_archive $f || error "archive request failed"
925 wait_request_state $fid ARCHIVE SUCCEED
932 $LFS hsm_restore $f && error "restore a dirty file must fail"
936 run_test 12e "Check forbidden restore"
939 # test needs a running copytool
943 local f=$DIR/$tdir/$tfile
944 local fid=$(copy_file /etc/hosts $f)
946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
947 wait_request_state $fid ARCHIVE SUCCEED
948 $LFS hsm_release $f || error "release of $f failed"
950 wait_request_state $fid RESTORE SUCCEED
952 echo -n "Verifying file state: "
953 check_hsm_flags $f "0x00000009"
955 diff -q /etc/hosts $f
957 [[ $? -eq 0 ]] || error "Restored file differs"
961 run_test 12f "Restore a released file explicitly"
964 # test needs a running copytool
968 local f=$DIR/$tdir/$tfile
969 local fid=$(copy_file /etc/hosts $f)
971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
972 wait_request_state $fid ARCHIVE SUCCEED
973 $LFS hsm_release $f || error "release of $f failed"
975 diff -q /etc/hosts $f
978 # we check we had a restore done
979 wait_request_state $fid RESTORE SUCCEED
981 [[ $st -eq 0 ]] || error "Restored file differs"
985 run_test 12g "Restore a released file implicitly"
988 need2clients || return 0
990 # test needs a running copytool
994 local f=$DIR/$tdir/$tfile
995 local fid=$(copy_file /etc/hosts $f)
997 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
998 wait_request_state $fid ARCHIVE SUCCEED
999 $LFS hsm_release $f || error "release of $f failed"
1001 do_node $CLIENT2 diff -q /etc/hosts $f
1004 # we check we had a restore done
1005 wait_request_state $fid RESTORE SUCCEED
1007 [[ $st -eq 0 ]] || error "Restored file differs"
1011 run_test 12h "Restore a released file implicitly from a second node"
1014 # test needs a running copytool
1018 local f=$DIR/$tdir/$tfile
1019 local fid=$(copy_file /etc/passwd $f)
1020 $LFS hsm_archive $f || error "archive of $f failed"
1021 wait_request_state $fid ARCHIVE SUCCEED
1023 $LFS hsm_release $f || error "release of $f failed"
1027 [[ $? -eq 0 ]] || error "Restored file differs"
1031 run_test 12m "Archive/release/implicit restore"
1034 # test needs a running copytool
1037 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1038 cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
1039 local f=$DIR/$tdir/$tfile
1040 import_file $tdir/$tfile $f
1042 cmp /etc/hosts $f || error "Restored file differs"
1044 $LFS hsm_release $f || error "release of $f failed"
1048 run_test 12n "Import/implicit restore/release"
1051 # test needs a running copytool
1054 local ARC_SUBDIR="import.orig"
1058 # populate directory to be imported
1059 for d in $(seq 1 10); do
1060 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1061 mkdir -p "$CURR_DIR"
1062 for f in $(seq 1 10); do
1063 CURR_FILE="$CURR_DIR/$tfile.$f"
1064 # write file-specific data
1065 echo "d=$d, f=$f, dir=$CURR_DIR, file=$CURR_FILE"\
1070 import_file "$ARC_SUBDIR" $DIR/$tdir
1071 # diff lustre content and origin (triggers file restoration)
1072 # there must be 10x10 identical files, and no difference
1073 local cnt_ok=$(diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1074 $DIR/$tdir/$ARC_SUBDIR |
1075 grep identical | wc -l)
1076 local cnt_diff=$(diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1077 $DIR/$tdir/$ARC_SUBDIR |
1080 [ $cnt_diff -eq 0 ] ||
1081 error "$cnt_diff imported files differ from read data"
1082 [ $cnt_ok -eq 100 ] ||
1083 error "not enough identical files ($cnt_ok != 100)"
1087 run_test 13 "Recursively import and restore a directory"
1090 # test needs a running copytool
1095 local f=$DIR/$tdir/$tfile
1096 local fid=$(make_small $f)
1097 local sum=$(md5sum $f | awk '{print $1}')
1098 $LFS hsm_archive $f || error "could not archive file"
1099 wait_request_state $fid ARCHIVE SUCCEED
1103 # create released file (simulate llapi_hsm_import call)
1105 local fid2=$(path2fid $f)
1106 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1107 $LFS hsm_release $f || error "could not release file"
1109 # rebind the archive to the newly created file
1110 echo "rebind $fid to $fid2"
1112 do_facet $SINGLEAGT \
1113 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1114 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1116 # restore file and compare md5sum
1117 local sum2=$(md5sum $f | awk '{print $1}')
1119 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1123 run_test 14 "Rebind archived file to a new fid"
1126 # test needs a running copytool
1131 local f=$DIR/$tdir/$tfile
1133 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1137 for i in $(seq 1 $count); do
1138 fids[$i]=$(make_small $f.$i)
1139 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1140 $LFS hsm_archive $f.$i || error "could not archive file"
1142 wait_all_done $(($count*60))
1146 for i in $(seq 1 $count); do
1149 local fid2=$(path2fid $f.$i)
1150 # add the rebind operation to the list
1151 echo ${fids[$i]} $fid2 >> $tmpfile
1153 # set it released (simulate llapi_hsm_import call)
1154 $LFS hsm_set --archived --exists $f.$i ||
1155 error "could not force hsm flags"
1156 $LFS hsm_release $f.$i || error "could not release file"
1158 nl=$(wc -l < $tmpfile)
1159 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1161 echo "rebind list of files"
1162 do_facet $SINGLEAGT \
1163 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1164 --rebind $tmpfile $DIR" || error "could not rebind file list"
1166 # restore files and compare md5sum
1167 for i in $(seq 1 $count); do
1168 local sum2=$(md5sum $f.$i | awk '{print $1}')
1169 [[ $sum2 == ${sums[$i]} ]] ||
1170 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1176 run_test 15 "Rebind a list of files"
1179 # test needs a running copytool
1183 # create a known size file so we can verify transfer speed
1186 dd if=/dev/zero of=$ref bs=1M count=20
1189 local f=$DIR/$tdir/$tfile
1190 local fid=$(copy_file $ref $f)
1192 local start=$(date +%s)
1194 wait_request_state $fid ARCHIVE SUCCEED
1195 local end=$(date +%s)
1196 local duration=$((end - start))
1198 [[ $duration -ge $goal ]] ||
1199 error "Transfer is too fast $duration < $goal"
1203 run_test 16 "Test CT bandwith control option"
1208 local f=$DIR/$tdir/$tfile
1209 touch $f || error "touch $f failed"
1211 # Could not release a non-archived file
1212 $LFS hsm_release $f && error "release should not succeed"
1214 # For following tests, we must test them with HS_ARCHIVED set
1215 $LFS hsm_set --exists --archived $f || error "could not add flag"
1217 # Could not release a file if no-release is set
1218 $LFS hsm_set --norelease $f || error "could not add flag"
1219 $LFS hsm_release $f && error "release should not succeed"
1220 $LFS hsm_clear --norelease $f || error "could not remove flag"
1222 # Could not release a file if lost
1223 $LFS hsm_set --lost $f || error "could not add flag"
1224 $LFS hsm_release $f && error "release should not succeed"
1225 $LFS hsm_clear --lost $f || error "could not remove flag"
1227 # Could not release a file if dirty
1228 $LFS hsm_set --dirty $f || error "could not add flag"
1229 $LFS hsm_release $f && error "release should not succeed"
1230 $LFS hsm_clear --dirty $f || error "could not remove flag"
1232 run_test 20 "Release is not permitted"
1235 # test needs a running copytool
1239 local f=$DIR/$tdir/test_release
1241 # Create a file and check its states
1242 local fid=$(make_small $f)
1243 check_hsm_flags $f "0x00000000"
1245 $LFS hsm_archive $f || error "could not archive file"
1246 wait_request_state $fid ARCHIVE SUCCEED
1248 [ $(stat -c "%b" $f) -ne "0" ] || error "wrong block number"
1249 local sz=$(stat -c "%s" $f)
1250 [ $sz -ne "0" ] || error "file size should not be zero"
1252 # Release and check states
1253 $LFS hsm_release $f || error "could not release file"
1254 check_hsm_flags $f "0x0000000d"
1256 [ $(stat -c "%b" $f) -eq "0" ] || error "wrong block number"
1257 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1259 # Check we can release an file without stripe info
1263 check_hsm_flags $f "0x00000000"
1264 $LFS hsm_archive $f || error "could not archive file"
1265 wait_request_state $fid ARCHIVE SUCCEED
1267 # Release and check states
1268 $LFS hsm_release $f || error "could not release file"
1269 check_hsm_flags $f "0x0000000d"
1271 # Release again a file that is already released is OK
1272 $LFS hsm_release $f || fail "second release should succeed"
1273 check_hsm_flags $f "0x0000000d"
1277 run_test 21 "Simple release tests"
1280 # test needs a running copytool
1285 local f=$DIR/$tdir/test_release
1286 local swap=$DIR/$tdir/test_swap
1288 # Create a file and check its states
1289 local fid=$(make_small $f)
1290 check_hsm_flags $f "0x00000000"
1292 $LFS hsm_archive $f || error "could not archive file"
1293 wait_request_state $fid ARCHIVE SUCCEED
1295 # Release and check states
1296 $LFS hsm_release $f || error "could not release file"
1297 check_hsm_flags $f "0x0000000d"
1300 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1305 run_test 22 "Could not swap a release file"
1308 # test needs a running copytool
1313 local f=$DIR/$tdir/test_mtime
1315 # Create a file and check its states
1316 local fid=$(make_small $f)
1317 check_hsm_flags $f "0x00000000"
1319 $LFS hsm_archive $f || error "could not archive file"
1320 wait_request_state $fid ARCHIVE SUCCEED
1322 # Set modification time in the past
1323 touch -m -a -d @978261179 $f
1325 # Release and check states
1326 $LFS hsm_release $f || error "could not release file"
1327 check_hsm_flags $f "0x0000000d"
1329 local MTIME=$(stat -c "%Y" $f)
1330 local ATIME=$(stat -c "%X" $f)
1331 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1332 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1336 run_test 23 "Release does not change a/mtime (utime)"
1339 local file=$DIR/$tdir/$tfile
1348 # test needs a running copytool
1353 fid=$(make_small $file)
1355 # Create a file and check its states
1356 check_hsm_flags $file "0x00000000"
1358 # Ensure atime is less than mtime and ctime.
1362 atime0=$(stat -c "%X" $file)
1363 mtime0=$(stat -c "%Y" $file)
1364 ctime0=$(stat -c "%Z" $file)
1366 [ $atime0 -lt $mtime0 ] ||
1367 error "atime $atime0 is not less than mtime $mtime0"
1369 [ $atime0 -lt $ctime0 ] ||
1370 error "atime $atime0 is not less than ctime $ctime0"
1372 # Archive should not change any timestamps.
1373 $LFS hsm_archive $file || error "cannot archive '$file'"
1374 wait_request_state $fid ARCHIVE SUCCEED
1376 atime1=$(stat -c "%X" $file)
1377 mtime1=$(stat -c "%Y" $file)
1378 ctime1=$(stat -c "%Z" $file)
1380 [ $atime0 -eq $atime1 ] ||
1381 error "archive changed atime from $atime0 to $atime1"
1383 [ $mtime0 -eq $mtime1 ] ||
1384 error "archive changed mtime from $mtime0 to $mtime1"
1386 [ $ctime0 -eq $ctime1 ] ||
1387 error "archive changed ctime from $ctime0 to $ctime1"
1389 # Release should not change any timestamps.
1390 $LFS hsm_release $file || error "cannot release '$file'"
1391 check_hsm_flags $file "0x0000000d"
1393 atime1=$(stat -c "%X" $file)
1394 mtime1=$(stat -c "%Y" $file)
1395 ctime1=$(stat -c "%Z" $file)
1397 [ $atime0 -eq $atime1 ] ||
1398 error "release changed atime from $atime0 to $atime1"
1400 [ $mtime0 -eq $mtime1 ] ||
1401 error "release changed mtime from $mtime0 to $mtime1"
1403 [ $ctime0 -eq $ctime1 ] ||
1404 error "release changed ctime from $ctime0 to $ctime1"
1406 # Restore should not change atime or mtime and should not
1408 $LFS hsm_restore $file
1409 wait_request_state $fid RESTORE SUCCEED
1411 atime1=$(stat -c "%X" $file)
1412 mtime1=$(stat -c "%Y" $file)
1413 ctime1=$(stat -c "%Z" $file)
1415 [ $atime0 -eq $atime1 ] ||
1416 error "restore changed atime from $atime0 to $atime1"
1418 [ $mtime0 -eq $mtime1 ] ||
1419 error "restore changed mtime from $mtime0 to $mtime1"
1421 [ $ctime0 -le $ctime1 ] ||
1422 error "restore changed ctime from $ctime0 to $ctime1"
1426 # Once more, after unmount and mount.
1427 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1428 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1430 atime1=$(stat -c "%X" $file)
1431 mtime1=$(stat -c "%Y" $file)
1432 ctime1=$(stat -c "%Z" $file)
1434 [ $atime0 -eq $atime1 ] ||
1435 error "remount changed atime from $atime0 to $atime1"
1437 [ $mtime0 -eq $mtime1 ] ||
1438 error "remount changed mtime from $mtime0 to $mtime1"
1440 [ $ctime0 -le $ctime1 ] ||
1441 error "remount changed ctime from $ctime0 to $ctime1"
1443 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1446 local file=$DIR/$tdir/$tfile
1452 # Test needs a running copytool.
1456 # Check that root can do HSM actions on a ordinary user's file.
1458 fid=$(make_small $file)
1459 sum0=$(md5sum $file)
1461 chown $RUNAS_ID:$RUNAS_GID $file ||
1462 error "cannot chown '$file' to '$RUNAS_ID'"
1464 chmod ugo-w $DIR/$tdir ||
1465 error "cannot chmod '$DIR/$tdir'"
1467 $LFS hsm_archive $file
1468 wait_request_state $fid ARCHIVE SUCCEED
1470 $LFS hsm_release $file ||
1471 check_hsm_flags $file "0x0000000d"
1473 $LFS hsm_restore $file
1474 wait_request_state $fid RESTORE SUCCEED
1476 # Check that ordinary user can get HSM state.
1477 $RUNAS $LFS hsm_state $file ||
1478 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1480 $LFS hsm_release $file ||
1481 check_hsm_flags $file "0x0000000d"
1483 # Check that ordinary user can accessed released file.
1484 sum1=$($RUNAS md5sum $file) ||
1485 error "user '$RUNAS_ID' cannot read '$file'"
1487 [ "$sum0" == "$sum1" ] ||
1488 error "md5sum mismatch for '$file'"
1492 run_test 24b "root can archive, release, and restore user files"
1495 # test needs a running copytool
1498 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1499 cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
1500 local f=$DIR/$tdir/$tfile
1502 import_file $tdir/$tfile $f
1504 $LFS hsm_set --lost $f
1509 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1513 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1514 " (Operation not permitted)"
1517 # test needs a running copytool
1522 local f=$DIR/$tdir/$tfile
1523 local fid=$(copy_file /etc/passwd $f)
1525 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1526 wait_request_state $fid ARCHIVE SUCCEED
1529 $LFS hsm_set --lost $f
1533 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1537 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1538 " (Operation not permitted)"
1541 # test needs a running copytool
1545 local f=$DIR/$tdir/$tfile
1546 local fid=$(make_large_for_progress $f)
1547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1548 wait_request_state $fid ARCHIVE SUCCEED
1551 wait_request_state $fid REMOVE SUCCEED
1553 check_hsm_flags $f "0x00000000"
1557 run_test 26 "Remove the archive of a valid file"
1560 # test needs a running copytool
1564 make_archive $tdir/$tfile
1565 local f=$DIR/$tdir/$tfile
1566 import_file $tdir/$tfile $f
1567 local fid=$(path2fid $f)
1571 [[ $? != 0 ]] || error "Remove of a released file should fail"
1575 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1578 # test needs a running copytool
1582 local f=$DIR/$tdir/$tfile
1583 local fid=$(make_large_for_progress $f)
1584 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1585 wait_request_state $fid ARCHIVE SUCCEED
1590 [[ $? != 0 ]] || error "Remove of a released file should fail"
1594 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1597 # test needs a running copytool
1601 local f=$DIR/$tdir/$tfile
1602 local fid=$(make_large_for_progress $f)
1603 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1604 wait_request_state $fid ARCHIVE SUCCEED
1613 wait_request_state $fid REMOVE SUCCEED
1617 run_test 28 "Concurrent archive/file remove"
1620 # restore at exec cannot work on agent node (because of Linux kernel
1621 # protection of executables)
1622 need2clients || return 0
1624 # test needs a running copytool
1627 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1628 cp -p /bin/true $HSM_ARCHIVE/$tdir/$tfile
1629 local f=$DIR/$tdir/true
1630 import_file $tdir/$tfile $f
1632 local fid=$(path2fid $f)
1634 # set no retry action mode
1640 # remove no try action mode
1644 [[ $st == 0 ]] || error "Failed to exec a released file"
1648 run_test 30a "Restore at exec (import case)"
1651 # restore at exec cannot work on agent node (because of Linux kernel
1652 # protection of executables)
1653 need2clients || return 0
1655 # test needs a running copytool
1659 local f=$DIR/$tdir/true
1660 local fid=$(copy_file /bin/true $f)
1662 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1663 wait_request_state $fid ARCHIVE SUCCEED
1666 # set no retry action mode
1672 # remove no try action mode
1676 [[ $st == 0 ]] || error "Failed to exec a released file"
1680 run_test 30b "Restore at exec (release case)"
1682 restore_and_check_size() {
1685 local s=$(stat -c "%s" $f)
1687 local st=$(get_hsm_flags $f)
1691 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1693 n=$(stat -c "%s" $f)
1694 # we echo in both cases to show stat is not
1698 echo "size seen is $n != $s"
1701 echo "size seen is right: $n == $s"
1703 st=$(get_hsm_flags $f)
1707 if [[ $cpt -lt 10 ]]
1709 echo " restore is too long"
1713 wait_request_state $fid RESTORE SUCCEED
1718 # test needs a running copytool
1723 make_archive $tdir/$tfile
1724 local f=$DIR/$tdir/$tfile
1725 import_file $tdir/$tfile $f
1726 local fid=$($LFS path2fid $f)
1727 HSM_ARCHIVE_PURGE=false copytool_setup
1729 restore_and_check_size $f $fid
1732 [[ $err -eq 0 ]] || error "File size changed during restore"
1736 run_test 31a "Import a large file and check size during restore"
1740 # test needs a running copytool
1745 local f=$DIR/$tdir/$tfile
1746 local fid=$(make_large_for_progress $f)
1747 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1748 wait_request_state $fid ARCHIVE SUCCEED
1751 restore_and_check_size $f $fid
1754 [[ $err -eq 0 ]] || error "File size changed during restore"
1758 run_test 31b "Restore a large unaligned file and check size during restore"
1761 # test needs a running copytool
1766 local f=$DIR/$tdir/$tfile
1767 local fid=$(make_large_for_progress_aligned $f)
1768 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1769 wait_request_state $fid ARCHIVE SUCCEED
1772 restore_and_check_size $f $fid
1775 [[ $err -eq 0 ]] || error "File size changed during restore"
1779 run_test 31c "Restore a large aligned file and check size during restore"
1782 # test needs a running copytool
1787 local f=$DIR/$tdir/$tfile
1788 local fid=$(make_large_for_progress $f)
1789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1790 wait_request_state $fid ARCHIVE SUCCEED
1793 md5sum $f >/dev/null &
1795 wait_request_state $fid RESTORE STARTED
1800 # Check restore trigger process was killed
1801 local killed=$(ps -o pid,comm hp $pid >/dev/null)
1805 wait_request_state $fid RESTORE CANCELED
1806 wait_request_state $fid CANCEL SUCCEED
1809 error "Cannot kill process waiting for restore ($killed)"
1813 run_test 33 "Kill a restore waiting process"
1816 # test needs a running copytool
1821 local f=$DIR/$tdir/$tfile
1822 local fid=$(make_large_for_progress $f)
1823 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1824 wait_request_state $fid ARCHIVE SUCCEED
1827 md5sum $f >/dev/null &
1829 wait_request_state $fid RESTORE STARTED
1831 rm $f || error "rm $f failed"
1832 # rm must not block during restore
1833 wait_request_state $fid RESTORE STARTED
1835 wait_request_state $fid RESTORE SUCCEED
1836 # check md5sum pgm finished
1837 local there=$(ps -o pid,comm hp $pid >/dev/null)
1838 [[ -z $there ]] || error "Restore initiator does not exit"
1840 local rc=$(wait $pid)
1841 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1845 run_test 34 "Remove file during restore"
1848 # test needs a running copytool
1853 local f=$DIR/$tdir/$tfile
1854 local f1=$DIR/$tdir/$tfile-1
1855 local fid=$(make_large_for_progress $f)
1856 local fid1=$(copy_file /etc/passwd $f1)
1857 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1858 wait_request_state $fid ARCHIVE SUCCEED
1861 md5sum $f >/dev/null &
1863 wait_request_state $fid RESTORE STARTED
1865 mv $f1 $f || error "mv $f1 $f failed"
1866 # mv must not block during restore
1867 wait_request_state $fid RESTORE STARTED
1869 wait_request_state $fid RESTORE SUCCEED
1870 # check md5sum pgm finished
1871 local there=$(ps -o pid,comm hp $pid >/dev/null)
1872 [[ -z $there ]] || error "Restore initiator does not exit"
1874 local rc=$(wait $pid)
1875 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1878 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
1882 run_test 35 "Overwrite file during restore"
1885 # test needs a running copytool
1890 local f=$DIR/$tdir/$tfile
1891 local fid=$(make_large_for_progress $f)
1892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1893 wait_request_state $fid ARCHIVE SUCCEED
1896 md5sum $f >/dev/null &
1898 wait_request_state $fid RESTORE STARTED
1901 # rm must not block during restore
1902 wait_request_state $fid RESTORE STARTED
1904 wait_request_state $fid RESTORE SUCCEED
1905 # check md5sum pgm finished
1906 local there=$(ps -o pid,comm hp $pid >/dev/null)
1908 error "Restore initiator does not exit"
1910 local rc=$(wait $pid)
1912 error "Restore initiator failed with $rc"
1916 run_test 36 "Move file during restore"
1923 for n in $(seq 1 $count); do
1924 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
1926 echo "$count archive requests submitted"
1930 local stream_count=4
1931 local file_count=100
1933 local f=$DIR/$tdir/$tfile
1938 for i in $(seq 1 $file_count); do
1939 for p in $(seq 1 $stream_count); do
1940 fid=$(copy_file /etc/hosts $f.$p.$i)
1944 # to be sure wait_all_done will not be mislead by previous tests
1946 wait_for_grace_delay
1948 # start archive streams in background (archive files in parallel)
1949 for p in $(seq 1 $stream_count); do
1950 multi_archive $f.$p $file_count &
1953 echo -n "Wait for all requests being enqueued..."
1959 run_test 40 "Parallel archive requests"
1962 # test needs a running copytool
1966 local f=$DIR/$tdir/$tfile
1967 local fid=$(copy_file /etc/motd $f 1)
1969 $LFS hsm_archive $f || error "could not archive file"
1970 wait_request_state $fid ARCHIVE SUCCEED
1971 check_hsm_flags $f "0x00000009"
1973 multiop_bg_pause $f O_c || error "multiop failed"
1977 client_up || client_up || true
1979 kill -USR1 $MULTIPID
1980 wait $MULTIPID || error "multiop close failed"
1982 check_hsm_flags $f "0x0000000b"
1986 run_test 52 "Opened for write file on an evicted client should be set dirty"
1989 # test needs a running copytool
1993 local f=$DIR/$tdir/$tfile
1994 local fid=$(copy_file /etc/motd $f 1)
1996 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1997 error "could not archive file"
1998 wait_request_state $fid ARCHIVE SUCCEED
1999 check_hsm_flags $f "0x00000009"
2001 multiop_bg_pause $f o_c || error "multiop failed"
2005 client_up || client_up || true
2007 kill -USR1 $MULTIPID
2008 wait $MULTIPID || error "multiop close failed"
2010 check_hsm_flags $f "0x00000009"
2014 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2017 # test needs a running copytool
2021 local f=$DIR/$tdir/$tfile
2022 local fid=$(make_small $f)
2024 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2025 error "could not archive file"
2026 wait_request_state $fid ARCHIVE STARTED
2028 check_hsm_flags $f "0x00000001"
2030 # Avoid coordinator resending this request as soon it has failed.
2035 wait_request_state $fid ARCHIVE FAILED
2037 check_hsm_flags $f "0x00000003"
2042 run_test 54 "Write during an archive cancels it"
2045 # test needs a running copytool
2049 local f=$DIR/$tdir/$tfile
2050 local fid=$(make_small $f)
2052 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2053 error "could not archive file"
2054 wait_request_state $fid ARCHIVE STARTED
2056 check_hsm_flags $f "0x00000001"
2058 # Avoid coordinator resending this request as soon it has failed.
2061 $TRUNCATE $f 1024 || error "truncate failed"
2063 wait_request_state $fid ARCHIVE FAILED
2065 check_hsm_flags $f "0x00000003"
2070 run_test 55 "Truncate during an archive cancels it"
2073 # test needs a running copytool
2077 local f=$DIR/$tdir/$tfile
2078 local fid=$(make_large_for_progress $f)
2080 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2081 error "could not archive file"
2082 wait_request_state $fid ARCHIVE STARTED
2084 check_hsm_flags $f "0x00000001"
2086 # Change metadata and sync to be sure we are not changing only
2091 wait_request_state $fid ARCHIVE SUCCEED
2093 check_hsm_flags $f "0x00000009"
2097 run_test 56 "Setattr during an archive is ok"
2100 # Need one client for I/O, one for request
2101 need2clients || return 0
2103 # test needs a running copytool
2107 local f=$DIR/$tdir/test_archive_remote
2108 # Create a file on a remote node
2109 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2110 "count=2 conv=fsync"
2113 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2114 error "hsm_archive failed"
2115 local fid=$(path2fid $f)
2116 wait_request_state $fid ARCHIVE SUCCEED
2118 # Release and implicit restore it
2119 do_node $CLIENT2 "$LFS hsm_release $f" ||
2120 error "hsm_release failed"
2121 do_node $CLIENT2 "md5sum $f" ||
2122 error "hsm_restore failed"
2124 wait_request_state $fid RESTORE SUCCEED
2128 run_test 57 "Archive a file with dirty cache on another node"
2131 # test needs a running copytool
2135 local f=$DIR/$tdir/$tfile
2136 local fid=$(make_small $f)
2138 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2139 error "could not archive file"
2140 wait_request_state $fid ARCHIVE SUCCEED
2142 $LFS hsm_release $f || error "could not release file"
2144 $TRUNCATE $f 0 || error "truncate failed"
2147 local sz=$(stat -c %s $f)
2148 [[ $sz == 0 ]] || error "size after truncate is $sz != 0"
2152 check_hsm_flags $f "0x0000000b"
2154 local state=$(get_request_state $fid RESTORE)
2155 [[ "$state" == "" ]] ||
2156 error "truncate 0 trigs a restore, state = $state"
2160 run_test 58 "Truncate 0 on a released file must not trigger restore"
2163 # test needs a running copytool
2167 local f=$DIR/$tdir/$tfile
2168 local fid=$(copy_file /etc/passwd $f)
2171 local sz=$(stat -c %s $ref)
2175 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2176 error "could not archive file"
2177 wait_request_state $fid ARCHIVE SUCCEED
2179 $LFS hsm_release $f || error "could not release file"
2181 $TRUNCATE $f $sz || error "truncate failed"
2184 local sz1=$(stat -c %s $f)
2185 [[ $sz1 == $sz ]] || error "size after truncate is $sz1 != $sz"
2189 check_hsm_flags $f "0x0000000b"
2191 local state=$(get_request_state $fid RESTORE)
2192 [[ "$state" == "SUCCEED" ]] ||
2193 error "truncate $sz does not trig a successfull restore,"\
2196 cmp $ref $f || error "file data wrong after truncate"
2200 run_test 59 "Truncate != 0 on a released file"
2205 local f=$DIR/$tdir/$tfile
2206 local FILELIST=/tmp/filelist.txt
2210 for i in $(seq 1 $file_count); do
2211 fid=$(copy_file /etc/hosts $f.$i)
2212 echo $f.$i >> $FILELIST
2215 # to be sure wait_all_done will not be mislead by previous tests
2217 wait_for_grace_delay
2218 $LFS hsm_archive --filelist $FILELIST ||
2219 error "cannot archive a file list"
2221 $LFS hsm_release --filelist $FILELIST ||
2222 error "cannot release a file list"
2223 $LFS hsm_restore --filelist $FILELIST ||
2224 error "cannot restore a file list"
2228 run_test 90 "Archive/restore a file list"
2230 double_verify_reset_hsm_param() {
2232 echo "Testing $HSM_PARAM.$p"
2233 local val=$(get_hsm_param $p)
2235 local val2=$(($val * 2))
2236 set_hsm_param $p $val2
2237 val=$(get_hsm_param $p)
2238 [[ $val == $val2 ]] ||
2239 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2240 echo "Set $p to 0 must failed"
2244 set_hsm_param $p $save
2248 error "we must not be able to set $HSM_PARAM.$p to 0"
2253 double_verify_reset_hsm_param loop_period
2254 double_verify_reset_hsm_param grace_delay
2255 double_verify_reset_hsm_param request_timeout
2256 double_verify_reset_hsm_param max_requests
2257 double_verify_reset_hsm_param archive_id
2259 run_test 100 "Set coordinator /proc tunables"
2266 run_test 102 "Verify coordinator control"
2269 # test needs a running copytool
2276 for i in $(seq 1 20); do
2277 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2283 echo "Current requests"
2284 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2285 $HSM_PARAM.agent_actions |\
2286 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2288 [[ -z "$res" ]] || error "Some request have not been canceled"
2292 run_test 103 "Purge all requests"
2297 # test needs a running copytool
2301 local f=$DIR/$tdir/$tfile
2302 local fid=$(make_large_for_progress $f)
2303 # if cdt is on, it can serve too quickly the request
2305 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2306 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2307 $HSM_PARAM.agent_actions |\
2308 grep $fid | cut -f16 -d=")
2311 [[ "$data1" == "$DATAHEX" ]] ||
2312 error "Data field in records is ($data1) and not ($DATAHEX)"
2316 run_test 104 "Copy tool data field"
2323 for i in $(seq -w 1 10); do
2324 cp /etc/passwd $DIR/$tdir/$i
2325 $LFS hsm_archive $DIR/$tdir/$i
2327 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2328 $HSM_PARAM.agent_actions |\
2329 grep WAITING | wc -l")
2332 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2333 $HSM_PARAM.agent_actions |\
2334 grep WAITING | wc -l")
2337 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2338 error "Requests count after shutdown $reqcnt2 != "\
2339 "before shutdown $reqcnt1"
2341 run_test 105 "Restart of coordinator"
2344 # test needs a running copytool
2347 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2348 get_client_uuid | cut -d' ' -f2)
2349 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2352 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2353 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2355 [[ -z "$agent" ]] ||
2356 error "My uuid $uuid still found in agent list,"\
2357 " after copytool shutdown"
2359 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2362 [[ ! -z "$agent" ]] ||
2363 error "My uuid $uuid not found in agent list after"\
2366 run_test 106 "Copytool register/unregister"
2369 # test needs a running copytool
2371 # create and archive file
2373 local f1=$DIR/$tdir/$tfile
2374 local fid=$(copy_file /etc/passwd $f1)
2375 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2376 wait_request_state $fid ARCHIVE SUCCEED
2377 # shutdown and restart MDS
2379 # check the copytool still gets messages from MDT
2380 local f2=$DIR/$tdir/2
2381 local fid=$(copy_file /etc/passwd $f2)
2382 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2383 # main check of this sanity: this request MUST succeed
2384 wait_request_state $fid ARCHIVE SUCCEED
2387 run_test 107 "Copytool re-register after MDS restart"
2390 # test needs a running copytool
2393 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2394 cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2395 local f=$DIR/$tdir/$tfile
2396 import_file $tdir/$tfile $f
2397 local fid=$(path2fid $f)
2399 cdt_set_no_blocking_restore
2404 wait_request_state $fid RESTORE SUCCEED
2405 cdt_clear_no_blocking_restore
2409 error "md5sum returns $st != 1, "\
2410 "should also perror ENODATA (No data available)"
2414 run_test 110a "Non blocking restore policy (import case)"
2417 # test needs a running copytool
2421 local f=$DIR/$tdir/$tfile
2422 local fid=$(copy_file /etc/passwd $f)
2423 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2424 wait_request_state $fid ARCHIVE SUCCEED
2427 cdt_set_no_blocking_restore
2432 wait_request_state $fid RESTORE SUCCEED
2433 cdt_clear_no_blocking_restore
2437 error "md5sum returns $st != 1, "\
2438 "should also perror ENODATA (No data available)"
2442 run_test 110b "Non blocking restore policy (release case)"
2445 # test needs a running copytool
2448 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2449 local f=$DIR/$tdir/$tfile
2450 cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2451 import_file $tdir/$tfile $f
2452 local fid=$(path2fid $f)
2456 copytool_remove_backend $fid
2459 wait_request_state $fid RESTORE FAILED
2466 [[ $st == 0 ]] || error "Restore does not failed"
2470 run_test 111a "No retry policy (import case), restore will error"\
2471 " (No such file or directory)"
2474 # test needs a running copytool
2478 local f=$DIR/$tdir/$tfile
2479 local fid=$(copy_file /etc/passwd $f)
2481 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2482 wait_request_state $fid ARCHIVE SUCCEED
2485 copytool_remove_backend $fid
2488 wait_request_state $fid RESTORE FAILED
2495 [[ $st == 0 ]] || error "Restore does not failed"
2499 run_test 111b "No retry policy (release case), restore will error"\
2500 " (No such file or directory)"
2503 # test needs a running copytool
2507 local f=$DIR/$tdir/$tfile
2508 local fid=$(copy_file /etc/passwd $f)
2510 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2511 local l=$($LFS hsm_action $f)
2513 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2517 wait_request_state $fid ARCHIVE SUCCEED
2520 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2524 run_test 112 "State of recorded request"
2527 # test needs a running copytool
2531 local f=$DIR/$tdir/$tfile
2532 local fid=$(make_large_for_cancel $f)
2533 # test with cdt on is made in test_221
2535 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2538 wait_request_state $fid ARCHIVE CANCELED
2539 wait_request_state $fid CANCEL SUCCEED
2543 run_test 200 "Register/Cancel archive"
2546 # test needs a running copytool
2550 local f=$DIR/$tdir/$tfile
2551 make_archive $tdir/$tfile
2552 import_file $tdir/$tfile $f
2553 local fid=$(path2fid $f)
2555 # test with cdt on is made in test_222
2560 wait_request_state $fid RESTORE CANCELED
2561 wait_request_state $fid CANCEL SUCCEED
2565 run_test 201 "Register/Cancel restore"
2568 # test needs a running copytool
2572 local f=$DIR/$tdir/$tfile
2573 local fid=$(make_large_for_progress $f)
2574 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2575 wait_request_state $fid ARCHIVE SUCCEED
2581 wait_request_state $fid REMOVE CANCELED
2585 run_test 202 "Register/Cancel remove"
2588 # test needs a running copytool
2593 local f=$DIR/$tdir/$tfile
2594 local fid=$(copy_file /etc/passwd $f)
2598 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2599 wait_request_state $fid ARCHIVE SUCCEED
2601 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2605 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2609 run_test 220 "Changelog for archive"
2612 # test needs a running copytool
2617 local f=$DIR/$tdir/$tfile
2618 local fid=$(make_large_for_cancel $f)
2622 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2623 wait_request_state $fid ARCHIVE STARTED
2625 wait_request_state $fid ARCHIVE CANCELED
2626 wait_request_state $fid CANCEL SUCCEED
2628 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2631 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2635 run_test 221 "Changelog for archive canceled"
2638 # test needs a running copytool
2641 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2642 local f=$DIR/$tdir/$tfile
2643 cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2644 import_file $tdir/$tfile $f
2645 local fid=$(path2fid $f)
2650 wait_request_state $fid RESTORE SUCCEED
2652 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2655 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2659 run_test 222a "Changelog for explicit restore"
2662 # test needs a running copytool
2666 local f=$DIR/$tdir/$tfile
2667 local fid=$(copy_file /etc/passwd $f)
2670 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2671 wait_request_state $fid ARCHIVE SUCCEED
2676 wait_request_state $fid RESTORE SUCCEED
2678 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2681 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2685 run_test 222b "Changelog for implicit restore"
2688 # test needs a running copytool
2693 local f=$DIR/$tdir/$tfile
2694 make_archive $tdir/$tfile
2698 import_file $tdir/$tfile $f
2699 local fid=$(path2fid $f)
2702 wait_request_state $fid RESTORE STARTED
2704 wait_request_state $fid RESTORE CANCELED
2705 wait_request_state $fid CANCEL SUCCEED
2707 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2710 [[ $flags == $target ]] ||
2711 error "Changelog flag is $flags not $target"
2715 run_test 223a "Changelog for restore canceled (import case)"
2718 # test needs a running copytool
2723 local f=$DIR/$tdir/$tfile
2724 local fid=$(make_large_for_progress $f)
2727 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2728 wait_request_state $fid ARCHIVE SUCCEED
2731 wait_request_state $fid RESTORE STARTED
2733 wait_request_state $fid RESTORE CANCELED
2734 wait_request_state $fid CANCEL SUCCEED
2736 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2739 [[ $flags == $target ]] ||
2740 error "Changelog flag is $flags not $target"
2744 run_test 223b "Changelog for restore canceled (release case)"
2747 # test needs a running copytool
2752 local f=$DIR/$tdir/$tfile
2753 local fid=$(copy_file /etc/passwd $f)
2756 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2757 wait_request_state $fid ARCHIVE SUCCEED
2760 wait_request_state $fid REMOVE SUCCEED
2762 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2765 [[ $flags == $target ]] ||
2766 error "Changelog flag is $flags not $target"
2770 run_test 224 "Changelog for remove"
2773 # test needs a running copytool
2776 # test is not usable because remove request is too fast
2777 # so it is always finished before cancel can be done ...
2778 echo "Test disabled"
2783 local f=$DIR/$tdir/$tfile
2784 local fid=$(make_large_for_progress $f)
2787 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2788 wait_request_state $fid ARCHIVE SUCCEED
2790 # if cdt is on, it can serve too quickly the request
2795 wait_request_state $fid REMOVE CANCELED
2796 wait_request_state $fid CANCEL SUCCEED
2798 flags=$(changelog_get_flags $MDT0 RENME $fid2)
2799 local flags=$($LFS changelog $MDT0 | grep HSM | grep $fid | tail -1 |
2803 [[ $flags == $target ]] ||
2804 error "Changelog flag is $flags not $target"
2808 run_test 225 "Changelog for remove canceled"
2811 # test needs a running copytool
2816 local f1=$DIR/$tdir/$tfile-1
2817 local f2=$DIR/$tdir/$tfile-2
2818 local f3=$DIR/$tdir/$tfile-3
2819 local fid1=$(copy_file /etc/passwd $f1)
2820 local fid2=$(copy_file /etc/passwd $f2)
2821 copy_file /etc/passwd $f3
2824 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2825 wait_request_state $fid1 ARCHIVE SUCCEED
2827 $LFS hsm_archive $f2
2828 wait_request_state $fid2 ARCHIVE SUCCEED
2830 rm $f1 || error "rm $f1 failed"
2832 local flags=$(changelog_get_flags $MDT0 UNLNK $fid1)
2835 [[ $flags == $target ]] ||
2836 error "Changelog flag is $flags not $target"
2838 mv $f3 $f2 || error "mv $f3 $f2 failed"
2840 flags=$(changelog_get_flags $MDT0 RENME $fid2)
2843 [[ $flags == $target ]] ||
2844 error "Changelog flag is $flags not $target"
2848 run_test 226 "changelog for last rm/mv with exiting archive"
2850 check_flags_changes() {
2858 $LFS hsm_set --$hsm_flag $f ||
2859 error "Cannot set $hsm_flag on $f"
2860 local flags=($(changelog_get_flags $MDT0 HSM $fid))
2861 local seen=${#flags[*]}
2863 [[ $seen == $cnt ]] ||
2864 error "set $hsm_flag: Changelog events $seen != $cnt"
2865 [[ ${flags[$((cnt - 1))]} == $target ]] ||
2866 error "set $hsm_flag: Changelog flags are "\
2867 "${flags[$((cnt - 1))]} not $target"
2869 $LFS hsm_clear --$hsm_flag $f ||
2870 error "Cannot clear $hsm_flag on $f"
2871 flags=($(changelog_get_flags $MDT0 HSM $fid))
2874 [[ $cnt == $seen ]] ||
2875 error "clear $hsm_flag: Changelog events $seen != $cnt"
2877 [[ ${flags[$((cnt - 1))]} == $target ]] ||
2878 error "clear $hsm_flag: Changelog flag is "\
2879 "${flags[$((cnt - 1))]} not $target"
2883 # test needs a running copytool
2890 for i in norelease noarchive exists archived
2892 local f=$DIR/$tdir/$tfile-$i
2893 local fid=$(copy_file /etc/passwd $f)
2894 check_flags_changes $f $fid $i 0 1
2897 f=$DIR/$tdir/$tfile---lost
2898 fid=$(copy_file /etc/passwd $f)
2899 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2900 wait_request_state $fid ARCHIVE SUCCEED
2901 check_flags_changes $f $fid lost 3 1
2905 run_test 227 "changelog when explicit setting of HSM flags"
2908 # test needs a running copytool
2912 local maxrequest=$(get_hsm_param max_requests)
2913 local rqcnt=$(($maxrequest * 3))
2917 for i in $(seq -w 1 $rqcnt); do
2919 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
2921 # we do it in 2 steps, so all requests arrive at the same time
2922 for i in $(seq -w 1 $rqcnt); do
2923 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
2928 while [[ $cnt != 0 || $wt != 0 ]]; do
2930 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2931 $HSM_PARAM.agent_actions |\
2932 grep STARTED | grep -v CANCEL | wc -l")
2933 [[ $cnt -le $maxrequest ]] ||
2934 error "$cnt > $maxrequest too many started requests"
2935 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
2936 $HSM_PARAM.agent_actions |\
2937 grep WAITING | wc -l")
2938 echo "max=$maxrequest started=$cnt waiting=$wt"
2943 run_test 250 "Coordinator max request"
2946 # test needs a running copytool
2950 local f=$DIR/$tdir/$tfile
2951 local fid=$(make_large_for_cancel $f)
2954 # to have a short test
2955 local old_to=$(get_hsm_param request_timeout)
2956 set_hsm_param request_timeout 4
2957 # to be sure the cdt will wake up frequently so
2958 # it will be able to cancel the "old" request
2959 local old_loop=$(get_hsm_param loop_period)
2960 set_hsm_param loop_period 2
2963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2964 wait_request_state $fid ARCHIVE STARTED
2966 wait_request_state $fid ARCHIVE CANCELED
2968 set_hsm_param request_timeout $old_to
2969 set_hsm_param loop_period $old_loop
2973 run_test 251 "Coordinator request timeout"
2976 # the only way to test ondisk conf is to restart MDS ...
2977 echo "Stop coordinator and remove coordinator state at mount"
2980 # clean on disk conf set by default
2981 cdt_clear_mount_state
2982 cdt_check_state stopped
2984 # check cdt still off after umount/remount
2986 cdt_check_state stopped
2988 echo "Set coordinator start at mount, and start coordinator"
2989 cdt_set_mount_state enabled
2992 cdt_check_state enabled
2994 # check cdt still on after umount/remount
2996 cdt_check_state enabled
2998 # we are back to original state (cdt started at mount)
3000 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3005 check_and_cleanup_lustre