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: 3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MCREATE=${MCREATE:-mcreate}
30 MOUNT_2=${MOUNT_2:-"yes"}
33 # script only handles up to 10 MDTs (because of MDT_PREFIX)
34 [ $MDSCOUNT -gt 9 ] &&
35 error "script cannot handle more than 9 MDTs, please fix" && exit
37 check_and_setup_lustre
39 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
40 skip_env "Need MDS version at least 2.4.53" && exit
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
52 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
53 # the following associated variables are added:
55 # AGTCOUNT: number of agents
56 # AGTDEV{N}: target HSM mount point (root path of the backend)
57 # agt{N}_HOST: hostname of the agent agt{N}
58 # SINGLEAGT: facet of the single agent
60 # The number of agents is initialized as the number of remote client nodes.
61 # By default, only single copytool is started on a remote client/agent. If there
62 # was no remote client, then the copytool will be started on the local client.
68 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
69 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
71 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
72 if [[ $CLIENTCOUNT -gt 1 ]] &&
73 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
74 skip_env "SHARED_DIRECTORY should be accessible"\
79 for n in $(seq $AGTCOUNT); do
80 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
81 agent=CLIENT$((n + 1))
82 if [[ -z "${!agent}" ]]; then
83 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
86 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
89 export SINGLEAGT=${SINGLEAGT:-agt1}
91 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
92 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
93 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
94 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
97 # The test only support up to 10 MDTs
98 MDT_PREFIX="mdt.$FSNAME-MDT000"
99 HSM_PARAM="${MDT_PREFIX}0.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
122 # get MDT device for each mdc
123 for mdtno in $(seq 1 $MDSCOUNT); do
124 local idx=$(($mdtno - 1))
125 MDT[$idx]=$($LCTL get_param -n \
126 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
127 awk '{gsub(/_UUID/,""); print $1}' | head -1)
132 local agents=${1:-$(facet_active_host $SINGLEAGT)}
133 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
136 search_and_kill_copytool() {
137 local agents=${1:-$(facet_active_host $SINGLEAGT)}
139 echo "Killing existing copytools on $agents"
140 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
144 local facet=${1:-$SINGLEAGT}
145 local lustre_mntpnt=${2:-$MOUNT}
147 local hsm_root=${4:-$(copytool_device $facet)}
148 local agent=$(facet_active_host $facet)
150 if [[ -z "$arc_id" ]] &&
151 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
152 echo "Wakeup copytool $facet on $agent"
156 if $HSM_ARCHIVE_PURGE; then
157 echo "Purging archive on $agent"
158 do_facet $facet "rm -rf $hsm_root/*"
161 echo "Starting copytool $facet on $agent"
162 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
163 # bandwidth is limited to 1MB/s so the copy time is known and
164 # independent of hardware
165 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
166 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
167 cmd+=" --bandwidth 1 $lustre_mntpnt"
169 # Redirect the standard output and error to a log file which
170 # can be uploaded to Maloo.
171 local prefix=$TESTLOG_PREFIX
172 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
173 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
175 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
176 error "start copytool $facet on $agent failed"
182 local agents=${1:-$(facet_active_host $SINGLEAGT)}
188 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
190 echo "Copytool is stopped on $agents"
192 # clean all CDTs orphans requests from previous tests
193 # that would otherwise need to timeout to clear.
194 for mdtno in $(seq 1 $MDSCOUNT); do
196 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
197 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
199 # skip already stop[ed,ing] CDTs
200 echo $oldstate | grep stop && continue
202 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
203 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
205 error "mds${mdtno} cdt state is not stopped"
206 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
207 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
209 error "mds${mdtno} cdt state is not $oldstate"
214 local agents=${1:-$(facet_active_host $SINGLEAGT)}
216 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
217 echo "Copytool is suspended on $agents"
220 copytool_remove_backend() {
222 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
223 echo "Remove from backend: $fid = $be"
224 do_facet $SINGLEAGT rm -f $be
228 do_facet $SINGLEAGT \
229 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
230 --import $1 $2 $MOUNT" ||
231 error "import of $1 to $2 failed"
235 local file=$HSM_ARCHIVE/$1
236 do_facet $SINGLEAGT mkdir -p $(dirname $file)
237 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
238 error "cannot create $file"
242 local file=$HSM_ARCHIVE/$2
243 do_facet $SINGLEAGT mkdir -p $(dirname $file)
244 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
253 if [[ "$value" != "" ]]; then
256 for mdtno in $(seq 1 $MDSCOUNT); do
257 local idx=$(($mdtno - 1))
258 local facet=mds${mdtno}
259 # if $arg include -P option, run 1 set_param per MDT on the MGS
260 # else, run set_param on each MDT
261 [[ $arg = *"-P"* ]] && facet=mgs
262 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
263 [[ $? != 0 ]] && rc=1
273 for mdtno in $(seq 1 $MDSCOUNT); do
274 local idx=$(($mdtno - 1))
275 wait_result mds${mdtno} \
276 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
278 error "$key state is not '$target' on mds${mdtno}"
285 for mdtno in $(seq 1 $MDSCOUNT); do
286 local idx=$(($mdtno - 1))
287 local cl_user=$(do_facet mds${mdtno} $LCTL \
288 --device ${MDT[$idx]} \
289 changelog_register -n)
291 do_facet mds${mdtno} lctl set_param \
292 mdd.${MDT[$idx]}.changelog_mask="+hsm"
293 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
297 changelog_cleanup() {
299 for mdtno in $(seq 1 $MDSCOUNT); do
300 local idx=$(($mdtno - 1))
301 [[ -z ${CL_USERS[$idx]} ]] && continue
302 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
303 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
304 changelog_deregister ${CL_USERS[$idx]}
309 changelog_get_flags() {
314 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
319 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
327 mdts_set_param "$opt -n" "hsm.$param" "$value"
334 mdts_set_param "" hsm_control "$cmd"
335 mdts_check_param hsm_control "$target" 10
338 cdt_set_sanity_policy() {
339 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
342 mdts_set_param "" hsm.policy "+NRA"
343 mdts_set_param "" hsm.policy "-NBR"
344 CDT_POLICY_HAD_CHANGED=
349 mdts_set_param "" hsm.policy "+NRA"
350 CDT_POLICY_HAD_CHANGED=true
353 cdt_clear_no_retry() {
354 mdts_set_param "" hsm.policy "-NRA"
355 CDT_POLICY_HAD_CHANGED=true
358 cdt_set_non_blocking_restore() {
359 mdts_set_param "" hsm.policy "+NBR"
360 CDT_POLICY_HAD_CHANGED=true
363 cdt_clear_non_blocking_restore() {
364 mdts_set_param "" hsm.policy "-NBR"
365 CDT_POLICY_HAD_CHANGED=true
368 cdt_clear_mount_state() {
369 mdts_set_param "-P -d" hsm_control ""
372 cdt_set_mount_state() {
373 mdts_set_param "-P" hsm_control "$1"
377 mdts_check_param hsm_control "$1" 20
381 set_test_state disabled disabled
385 set_test_state enabled enabled
389 set_test_state shutdown stopped
393 set_test_state purge enabled
399 cdt_set_sanity_policy
403 local client_count=$1
404 if [[ $CLIENTCOUNT -lt $client_count ]]; then
405 skip "Need $client_count or more clients, have $CLIENTCOUNT"
412 $LFS path2fid $1 | tr -d '[]'
419 if [[ $u == "user" ]]; then
420 local st=$($RUNAS $LFS hsm_state $f)
422 local st=$($LFS hsm_state $f)
426 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
428 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
432 get_hsm_archive_id() {
434 local st=$($LFS hsm_state $f)
435 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
437 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
446 local st=$(get_hsm_flags $f)
447 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
450 check_hsm_flags_user() {
454 local st=$(get_hsm_flags $f user)
455 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
467 if [[ "$3" != 1 ]]; then
471 cp $1 $f || error "cannot copy $1 to $f"
472 path2fid $f || error "cannot get fid on $f"
476 local file2=${1/$DIR/$DIR2}
477 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
478 error "cannot create $file2"
479 path2fid $1 || error "cannot get fid on $1"
483 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
484 error "cannot create $1"
485 path2fid $1 || error "cannot get fid on $1"
488 cleanup_large_files() {
489 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
491 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
494 make_large_for_striping() {
495 local file2=${1/$DIR/$DIR2}
496 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
500 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
501 error "cannot create $file2"
502 path2fid $1 || error "cannot get fid on $1"
505 make_large_for_progress() {
506 local file2=${1/$DIR/$DIR2}
510 # big file is large enough, so copy time is > 30s
511 # so copytool make 1 progress
512 # size is not a multiple of 1M to avoid stripe
514 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
515 error "cannot create $file2"
516 path2fid $1 || error "cannot get fid on $1"
519 make_large_for_progress_aligned() {
520 local file2=${1/$DIR/$DIR2}
524 # big file is large enough, so copy time is > 30s
525 # so copytool make 1 progress
526 # size is a multiple of 1M to have stripe
528 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
529 error "cannot create $file2"
530 path2fid $1 || error "cannot get fid on $1"
533 make_large_for_cancel() {
534 local file2=${1/$DIR/$DIR2}
538 # Copy timeout is 100s. 105MB => 105s
539 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
540 error "cannot create $file2"
541 path2fid $1 || error "cannot get fid on $1"
547 wait_update --verbose $(facet_active_host $facet) "$@"
550 wait_request_state() {
554 # 4th arg (mdt index) is optional
556 local mds=mds$(($mdtidx + 1))
558 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
559 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
561 wait_result $mds "$cmd" $state 100 ||
562 error "request on $fid is not $state on $mds"
565 get_request_state() {
569 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
570 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
573 get_request_count() {
577 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
578 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
584 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
585 cmd+=" | egrep 'WAITING|STARTED'"
587 wait_result $SINGLEMDS "$cmd" "" $timeout ||
588 error "requests did not complete"
591 wait_for_grace_delay() {
592 local val=$(get_hsm_param grace_delay)
596 # populate MDT device array
602 # cleanup from previous bad setup
603 search_and_kill_copytool
605 # for recovery tests, coordinator needs to be started at mount
607 # the lustre conf must be without hsm on (like for sanity.sh)
608 echo "Set HSM on and start"
609 cdt_set_mount_state enabled
610 cdt_check_state enabled
612 echo "Start copytool"
615 echo "Set sanity-hsm HSM policy"
616 cdt_set_sanity_policy
618 # finished requests are quickly removed from list
619 set_hsm_param grace_delay 10
625 local f=$DIR/$tdir/$tfile
629 check_hsm_flags_user $f "0x00000000"
631 $RUNAS $LFS hsm_set --norelease $f ||
632 error "user could not change hsm flags"
633 check_hsm_flags_user $f "0x00000010"
635 $RUNAS $LFS hsm_clear --norelease $f ||
636 error "user could not clear hsm flags"
637 check_hsm_flags_user $f "0x00000000"
639 # User could not change those flags...
640 $RUNAS $LFS hsm_set --exists $f &&
641 error "user should not set this flag"
642 check_hsm_flags_user $f "0x00000000"
645 $LFS hsm_set --exists $f ||
646 error "root could not change hsm flags"
647 check_hsm_flags_user $f "0x00000001"
649 $LFS hsm_clear --exists $f ||
650 error "root could not clear hsm state"
651 check_hsm_flags_user $f "0x00000000"
654 run_test 1 "lfs hsm flags root/non-root access"
658 local f=$DIR/$tdir/$tfile
660 # New files are not dirty
661 check_hsm_flags $f "0x00000000"
663 # For test, we simulate an archived file.
664 $LFS hsm_set --exists $f || error "user could not change hsm flags"
665 check_hsm_flags $f "0x00000001"
667 # chmod do not put the file dirty
668 chmod 600 $f || error "could not chmod test file"
669 check_hsm_flags $f "0x00000001"
671 # chown do not put the file dirty
672 chown $RUNAS_ID $f || error "could not chown test file"
673 check_hsm_flags $f "0x00000001"
675 # truncate put the file dirty
676 $TRUNCATE $f 1 || error "could not truncate test file"
677 check_hsm_flags $f "0x00000003"
679 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
680 check_hsm_flags $f "0x00000001"
682 run_test 2 "Check file dirtyness when doing setattr"
688 # New files are not dirty
690 check_hsm_flags $f "0x00000000"
692 # For test, we simulate an archived file.
693 $LFS hsm_set --exists $f ||
694 error "user could not change hsm flags"
695 check_hsm_flags $f "0x00000001"
697 # Reading a file, does not set dirty
698 cat $f > /dev/null || error "could not read file"
699 check_hsm_flags $f "0x00000001"
701 # Open for write without modifying data, does not set dirty
702 openfile -f O_WRONLY $f || error "could not open test file"
703 check_hsm_flags $f "0x00000001"
705 # Append to a file sets it dirty
706 cp -p /etc/passwd $f.append || error "could not create file"
707 $LFS hsm_set --exists $f.append ||
708 error "user could not change hsm flags"
709 dd if=/etc/passwd of=$f.append bs=1 count=3\
710 conv=notrunc oflag=append status=noxfer ||
711 error "could not append to test file"
712 check_hsm_flags $f.append "0x00000003"
714 # Modify a file sets it dirty
715 cp -p /etc/passwd $f.modify || error "could not create file"
716 $LFS hsm_set --exists $f.modify ||
717 error "user could not change hsm flags"
718 dd if=/dev/zero of=$f.modify bs=1 count=3\
719 conv=notrunc status=noxfer ||
720 error "could not modify test file"
721 check_hsm_flags $f.modify "0x00000003"
723 # Open O_TRUNC sets dirty
724 cp -p /etc/passwd $f.trunc || error "could not create file"
725 $LFS hsm_set --exists $f.trunc ||
726 error "user could not change hsm flags"
727 cp /etc/group $f.trunc || error "could not override a file"
728 check_hsm_flags $f.trunc "0x00000003"
730 # Mmapped a file sets dirty
731 cp -p /etc/passwd $f.mmap || error "could not create file"
732 $LFS hsm_set --exists $f.mmap ||
733 error "user could not change hsm flags"
734 multiop $f.mmap OSMWUc || error "could not mmap a file"
735 check_hsm_flags $f.mmap "0x00000003"
737 run_test 3 "Check file dirtyness when opening for write"
741 local f=$DIR/$tdir/$tfile
742 local fid=$(make_small $f)
745 local st=$(get_request_state $fid CANCEL)
746 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
748 run_test 4 "Useless cancel must not be registered"
751 # test needs a running copytool
755 local f=$DIR/$tdir/$tfile
756 local fid=$(copy_file /etc/passwd $f)
758 wait_request_state $fid ARCHIVE SUCCEED
760 check_hsm_flags $f "0x00000009"
764 run_test 8 "Test default archive number"
768 local f=$DIR/$tdir/$tfile
769 local fid=$(copy_file /etc/passwd $f)
770 # we do not use the default one to be sure
771 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
773 copytool_setup $SINGLEAGT $MOUNT $new_an
774 $LFS hsm_archive --archive $new_an $f
775 wait_request_state $fid ARCHIVE SUCCEED
777 check_hsm_flags $f "0x00000009"
781 run_test 9 "Use of explict archive number, with dedicated copytool"
784 needclients 3 || return 0
790 copytool_cleanup $(comma_list $(agts_nodes))
792 # start all of the copytools
793 for n in $(seq $AGTCOUNT); do
797 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
800 for n in $(seq $AGTCOUNT); do
801 file=$DIR/$tdir/$tfile.$n
802 fid=$(make_small $file)
804 $LFS hsm_archive $file || error "could not archive file $file"
805 wait_request_state $fid ARCHIVE SUCCEED
806 check_hsm_flags $file "0x00000009"
810 copytool_cleanup $(comma_list $(agts_nodes))
812 run_test 9a "Multiple remote agents"
815 # test needs a running copytool
818 mkdir -p $DIR/$tdir/d1
819 local f=$DIR/$tdir/$tfile
820 local fid=$(copy_file /etc/hosts $f)
821 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
822 error "hsm_archive failed"
823 wait_request_state $fid ARCHIVE SUCCEED
825 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
826 error "fid $fid not in archive $HSM_ARCHIVE"
827 echo "Verifying content"
828 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
829 echo "Verifying hsm state "
830 check_hsm_flags $f "0x00000009"
832 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
833 local st=$(get_hsm_archive_id $f)
834 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
835 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
840 run_test 10a "Archive a file"
843 # test needs a running copytool
847 local f=$DIR/$tdir/$tfile
848 local fid=$(copy_file /etc/hosts $f)
849 $LFS hsm_archive $f || error "archive request failed"
850 wait_request_state $fid ARCHIVE SUCCEED
852 $LFS hsm_archive $f || error "archive of non dirty file failed"
853 local cnt=$(get_request_count $fid ARCHIVE)
854 [[ "$cnt" == "1" ]] ||
855 error "archive of non dirty file must not make a request"
859 run_test 10b "Archive of non dirty file must work without doing request"
862 # test needs a running copytool
866 local f=$DIR/$tdir/$tfile
867 local fid=$(copy_file /etc/hosts $f)
868 $LFS hsm_set --noarchive $f
869 $LFS hsm_archive $f && error "archive a noarchive file must fail"
873 run_test 10c "Check forbidden archive"
876 # test needs a running copytool
880 local f=$DIR/$tdir/$tfile
881 local fid=$(copy_file /etc/hosts $f)
882 $LFS hsm_archive $f || error "cannot archive $f"
883 wait_request_state $fid ARCHIVE SUCCEED
885 local ar=$(get_hsm_archive_id $f)
886 local dflt=$(get_hsm_param default_archive_id)
887 [[ $ar == $dflt ]] ||
888 error "archived file is not on default archive: $ar != $dflt"
892 run_test 10d "Archive a file on the default archive id"
896 copy2archive /etc/hosts $tdir/$tfile
897 local f=$DIR/$tdir/$tfile
899 import_file $tdir/$tfile $f
900 echo -n "Verifying released state: "
901 check_hsm_flags $f "0x0000000d"
903 local LSZ=$(stat -c "%s" $f)
904 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
906 echo "Verifying imported size $LSZ=$ASZ"
907 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
908 echo -n "Verifying released pattern: "
909 local PTRN=$($GETSTRIPE -L $f)
911 [[ $PTRN == 80000001 ]] || error "Is not released"
912 local fid=$(path2fid $f)
913 echo "Verifying new fid $fid in archive"
915 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
916 error "fid $fid not in archive $HSM_ARCHIVE"
918 run_test 11 "Import a file"
921 # test needs a running copytool
925 copy2archive /etc/hosts $tdir/$tfile
927 local f=$DIR/$tdir/$tfile
928 import_file $tdir/$tfile $f
929 local f=$DIR2/$tdir/$tfile
930 echo "Verifying released state: "
931 check_hsm_flags $f "0x0000000d"
933 local fid=$(path2fid $f)
935 wait_request_state $fid RESTORE SUCCEED
937 echo "Verifying file state: "
938 check_hsm_flags $f "0x00000009"
940 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
942 [[ $? -eq 0 ]] || error "Restored file differs"
946 run_test 12a "Restore an imported file explicitly"
949 # test needs a running copytool
953 copy2archive /etc/hosts $tdir/$tfile
955 local f=$DIR/$tdir/$tfile
956 import_file $tdir/$tfile $f
957 echo "Verifying released state: "
958 check_hsm_flags $f "0x0000000d"
960 cat $f > /dev/null || error "File read failed"
962 echo "Verifying file state after restore: "
963 check_hsm_flags $f "0x00000009"
965 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
967 [[ $? -eq 0 ]] || error "Restored file differs"
971 run_test 12b "Restore an imported file implicitly"
974 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
976 # test needs a running copytool
980 local f=$DIR/$tdir/$tfile
981 $LFS setstripe -c 2 $f
982 local fid=$(make_large_for_striping $f)
983 local FILE_CRC=$(md5sum $f)
985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
986 wait_request_state $fid ARCHIVE SUCCEED
987 $LFS hsm_release $f || error "release $f failed"
989 echo "$FILE_CRC" | md5sum -c
991 [[ $? -eq 0 ]] || error "Restored file differs"
995 run_test 12c "Restore a file with stripe of 2"
998 # test needs a running copytool
1003 local f=$DIR/$tdir/$tfile
1004 local fid=$(copy_file /etc/hosts $f)
1005 $LFS hsm_restore $f || error "restore of non archived file failed"
1006 local cnt=$(get_request_count $fid RESTORE)
1007 [[ "$cnt" == "0" ]] ||
1008 error "restore non archived must not make a request"
1009 $LFS hsm_archive $f ||
1010 error "archive request failed"
1011 wait_request_state $fid ARCHIVE SUCCEED
1012 $LFS hsm_restore $f ||
1013 error "restore of non released file failed"
1014 local cnt=$(get_request_count $fid RESTORE)
1015 [[ "$cnt" == "0" ]] ||
1016 error "restore a non dirty file must not make a request"
1020 run_test 12d "Restore of a non archived, non released file must work"\
1021 " without doing request"
1024 # test needs a running copytool
1027 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1028 local f=$DIR/$tdir/$tfile
1029 local fid=$(copy_file /etc/hosts $f)
1030 $LFS hsm_archive $f || error "archive request failed"
1031 wait_request_state $fid ARCHIVE SUCCEED
1034 cat /etc/hosts >> $f
1038 $LFS hsm_restore $f && error "restore a dirty file must fail"
1042 run_test 12e "Check forbidden restore"
1045 # test needs a running copytool
1049 local f=$DIR/$tdir/$tfile
1050 local fid=$(copy_file /etc/hosts $f)
1052 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1053 wait_request_state $fid ARCHIVE SUCCEED
1054 $LFS hsm_release $f || error "release of $f failed"
1056 wait_request_state $fid RESTORE SUCCEED
1058 echo -n "Verifying file state: "
1059 check_hsm_flags $f "0x00000009"
1061 diff -q /etc/hosts $f
1063 [[ $? -eq 0 ]] || error "Restored file differs"
1067 run_test 12f "Restore a released file explicitly"
1070 # test needs a running copytool
1074 local f=$DIR/$tdir/$tfile
1075 local fid=$(copy_file /etc/hosts $f)
1077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1078 wait_request_state $fid ARCHIVE SUCCEED
1079 $LFS hsm_release $f || error "release of $f failed"
1081 diff -q /etc/hosts $f
1084 # we check we had a restore done
1085 wait_request_state $fid RESTORE SUCCEED
1087 [[ $st -eq 0 ]] || error "Restored file differs"
1091 run_test 12g "Restore a released file implicitly"
1094 needclients 2 || return 0
1096 # test needs a running copytool
1100 local f=$DIR/$tdir/$tfile
1101 local fid=$(copy_file /etc/hosts $f)
1103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1104 wait_request_state $fid ARCHIVE SUCCEED
1105 $LFS hsm_release $f || error "release of $f failed"
1107 do_node $CLIENT2 diff -q /etc/hosts $f
1110 # we check we had a restore done
1111 wait_request_state $fid RESTORE SUCCEED
1113 [[ $st -eq 0 ]] || error "Restored file differs"
1117 run_test 12h "Restore a released file implicitly from a second node"
1120 # test needs a running copytool
1124 local f=$DIR/$tdir/$tfile
1125 local fid=$(copy_file /etc/passwd $f)
1126 $LFS hsm_archive $f || error "archive of $f failed"
1127 wait_request_state $fid ARCHIVE SUCCEED
1129 $LFS hsm_release $f || error "release of $f failed"
1133 [[ $? -eq 0 ]] || error "Restored file differs"
1137 run_test 12m "Archive/release/implicit restore"
1140 # test needs a running copytool
1144 copy2archive /etc/hosts $tdir/$tfile
1146 local f=$DIR/$tdir/$tfile
1147 import_file $tdir/$tfile $f
1149 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1150 error "Restored file differs"
1152 $LFS hsm_release $f || error "release of $f failed"
1156 run_test 12n "Import/implicit restore/release"
1159 # test needs a running copytool
1162 local ARC_SUBDIR="import.orig"
1166 # populate directory to be imported
1167 for d in $(seq 1 10); do
1168 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1169 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1170 for f in $(seq 1 10); do
1171 CURR_FILE="$CURR_DIR/$tfile.$f"
1172 # write file-specific data
1173 do_facet $SINGLEAGT \
1174 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1175 "file=$CURR_FILE > $CURR_FILE"
1179 import_file "$ARC_SUBDIR" $DIR/$tdir
1180 # diff lustre content and origin (triggers file restoration)
1181 # there must be 10x10 identical files, and no difference
1182 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1183 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1184 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1185 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1187 [ $cnt_diff -eq 0 ] ||
1188 error "$cnt_diff imported files differ from read data"
1189 [ $cnt_ok -eq 100 ] ||
1190 error "not enough identical files ($cnt_ok != 100)"
1194 run_test 13 "Recursively import and restore a directory"
1197 # test needs a running copytool
1202 local f=$DIR/$tdir/$tfile
1203 local fid=$(make_small $f)
1204 local sum=$(md5sum $f | awk '{print $1}')
1205 $LFS hsm_archive $f || error "could not archive file"
1206 wait_request_state $fid ARCHIVE SUCCEED
1210 # create released file (simulate llapi_hsm_import call)
1212 local fid2=$(path2fid $f)
1213 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1214 $LFS hsm_release $f || error "could not release file"
1216 # rebind the archive to the newly created file
1217 echo "rebind $fid to $fid2"
1219 do_facet $SINGLEAGT \
1220 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1221 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1223 # restore file and compare md5sum
1224 local sum2=$(md5sum $f | awk '{print $1}')
1226 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1230 run_test 14 "Rebind archived file to a new fid"
1233 # test needs a running copytool
1238 local f=$DIR/$tdir/$tfile
1240 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1244 for i in $(seq 1 $count); do
1245 fids[$i]=$(make_small $f.$i)
1246 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1247 $LFS hsm_archive $f.$i || error "could not archive file"
1249 wait_all_done $(($count*60))
1253 for i in $(seq 1 $count); do
1256 local fid2=$(path2fid $f.$i)
1257 # add the rebind operation to the list
1258 echo ${fids[$i]} $fid2 >> $tmpfile
1260 # set it released (simulate llapi_hsm_import call)
1261 $LFS hsm_set --archived --exists $f.$i ||
1262 error "could not force hsm flags"
1263 $LFS hsm_release $f.$i || error "could not release file"
1265 nl=$(wc -l < $tmpfile)
1266 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1268 echo "rebind list of files"
1269 do_facet $SINGLEAGT \
1270 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1271 --rebind $tmpfile $DIR" || error "could not rebind file list"
1273 # restore files and compare md5sum
1274 for i in $(seq 1 $count); do
1275 local sum2=$(md5sum $f.$i | awk '{print $1}')
1276 [[ $sum2 == ${sums[$i]} ]] ||
1277 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1283 run_test 15 "Rebind a list of files"
1286 # test needs a running copytool
1290 # create a known size file so we can verify transfer speed
1293 dd if=/dev/zero of=$ref bs=1M count=20
1296 local f=$DIR/$tdir/$tfile
1297 local fid=$(copy_file $ref $f)
1299 local start=$(date +%s)
1301 wait_request_state $fid ARCHIVE SUCCEED
1302 local end=$(date +%s)
1303 local duration=$((end - start))
1305 [[ $duration -ge $goal ]] ||
1306 error "Transfer is too fast $duration < $goal"
1310 run_test 16 "Test CT bandwith control option"
1315 local f=$DIR/$tdir/$tfile
1316 touch $f || error "touch $f failed"
1318 # Could not release a non-archived file
1319 $LFS hsm_release $f && error "release should not succeed"
1321 # For following tests, we must test them with HS_ARCHIVED set
1322 $LFS hsm_set --exists --archived $f || error "could not add flag"
1324 # Could not release a file if no-release is set
1325 $LFS hsm_set --norelease $f || error "could not add flag"
1326 $LFS hsm_release $f && error "release should not succeed"
1327 $LFS hsm_clear --norelease $f || error "could not remove flag"
1329 # Could not release a file if lost
1330 $LFS hsm_set --lost $f || error "could not add flag"
1331 $LFS hsm_release $f && error "release should not succeed"
1332 $LFS hsm_clear --lost $f || error "could not remove flag"
1334 # Could not release a file if dirty
1335 $LFS hsm_set --dirty $f || error "could not add flag"
1336 $LFS hsm_release $f && error "release should not succeed"
1337 $LFS hsm_clear --dirty $f || error "could not remove flag"
1339 run_test 20 "Release is not permitted"
1342 # test needs a running copytool
1346 local f=$DIR/$tdir/test_release
1348 # Create a file and check its states
1349 local fid=$(make_small $f)
1350 check_hsm_flags $f "0x00000000"
1352 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1353 # used until file is flushed to disk
1354 if [ $(facet_fstype ost1) == "zfs" ]; then
1355 # this causes an OST_SYNC rpc to be sent
1356 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1357 # clear locks to reread file data
1358 cancel_lru_locks osc
1361 local orig_size=$(stat -c "%s" $f)
1362 local orig_blocks=$(stat -c "%b" $f)
1364 start_full_debug_logging
1366 $LFS hsm_archive $f || error "could not archive file"
1367 wait_request_state $fid ARCHIVE SUCCEED
1369 local blocks=$(stat -c "%b" $f)
1370 [ $blocks -eq $orig_blocks ] ||
1371 error "$f: wrong block number after archive: " \
1372 "$blocks != $orig_blocks"
1373 local size=$(stat -c "%s" $f)
1374 [ $size -eq $orig_size ] ||
1375 error "$f: wrong size after archive: $size != $orig_size"
1377 # Release and check states
1378 $LFS hsm_release $f || error "could not release file"
1379 check_hsm_flags $f "0x0000000d"
1381 blocks=$(stat -c "%b" $f)
1382 [ $blocks -gt 5 ] &&
1383 error "$f: too many blocks after release: $blocks > 5"
1384 size=$(stat -c "%s" $f)
1385 [ $size -ne $orig_size ] &&
1386 error "$f: wrong size after release: $size != $orig_size"
1388 # Check we can release an file without stripe info
1392 check_hsm_flags $f "0x00000000"
1393 $LFS hsm_archive $f || error "could not archive file"
1394 wait_request_state $fid ARCHIVE SUCCEED
1396 # Release and check states
1397 $LFS hsm_release $f || error "could not release file"
1398 check_hsm_flags $f "0x0000000d"
1400 # Release again a file that is already released is OK
1401 $LFS hsm_release $f || fail "second release should succeed"
1402 check_hsm_flags $f "0x0000000d"
1404 stop_full_debug_logging
1408 run_test 21 "Simple release tests"
1411 # test needs a running copytool
1416 local f=$DIR/$tdir/test_release
1417 local swap=$DIR/$tdir/test_swap
1419 # Create a file and check its states
1420 local fid=$(make_small $f)
1421 check_hsm_flags $f "0x00000000"
1423 $LFS hsm_archive $f || error "could not archive file"
1424 wait_request_state $fid ARCHIVE SUCCEED
1426 # Release and check states
1427 $LFS hsm_release $f || error "could not release file"
1428 check_hsm_flags $f "0x0000000d"
1431 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1436 run_test 22 "Could not swap a release file"
1439 # test needs a running copytool
1444 local f=$DIR/$tdir/test_mtime
1446 # Create a file and check its states
1447 local fid=$(make_small $f)
1448 check_hsm_flags $f "0x00000000"
1450 $LFS hsm_archive $f || error "could not archive file"
1451 wait_request_state $fid ARCHIVE SUCCEED
1453 # Set modification time in the past
1454 touch -m -a -d @978261179 $f
1456 # Release and check states
1457 $LFS hsm_release $f || error "could not release file"
1458 check_hsm_flags $f "0x0000000d"
1460 local MTIME=$(stat -c "%Y" $f)
1461 local ATIME=$(stat -c "%X" $f)
1462 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1463 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1467 run_test 23 "Release does not change a/mtime (utime)"
1470 local file=$DIR/$tdir/$tfile
1479 # test needs a running copytool
1484 fid=$(make_small $file)
1486 # Create a file and check its states
1487 check_hsm_flags $file "0x00000000"
1489 # Ensure atime is less than mtime and ctime.
1493 atime0=$(stat -c "%X" $file)
1494 mtime0=$(stat -c "%Y" $file)
1495 ctime0=$(stat -c "%Z" $file)
1497 [ $atime0 -lt $mtime0 ] ||
1498 error "atime $atime0 is not less than mtime $mtime0"
1500 [ $atime0 -lt $ctime0 ] ||
1501 error "atime $atime0 is not less than ctime $ctime0"
1503 # Archive should not change any timestamps.
1504 $LFS hsm_archive $file || error "cannot archive '$file'"
1505 wait_request_state $fid ARCHIVE SUCCEED
1507 atime1=$(stat -c "%X" $file)
1508 mtime1=$(stat -c "%Y" $file)
1509 ctime1=$(stat -c "%Z" $file)
1511 [ $atime0 -eq $atime1 ] ||
1512 error "archive changed atime from $atime0 to $atime1"
1514 [ $mtime0 -eq $mtime1 ] ||
1515 error "archive changed mtime from $mtime0 to $mtime1"
1517 [ $ctime0 -eq $ctime1 ] ||
1518 error "archive changed ctime from $ctime0 to $ctime1"
1520 # Release should not change any timestamps.
1521 $LFS hsm_release $file || error "cannot release '$file'"
1522 check_hsm_flags $file "0x0000000d"
1524 atime1=$(stat -c "%X" $file)
1525 mtime1=$(stat -c "%Y" $file)
1526 ctime1=$(stat -c "%Z" $file)
1528 [ $atime0 -eq $atime1 ] ||
1529 error "release changed atime from $atime0 to $atime1"
1531 [ $mtime0 -eq $mtime1 ] ||
1532 error "release changed mtime from $mtime0 to $mtime1"
1534 [ $ctime0 -eq $ctime1 ] ||
1535 error "release changed ctime from $ctime0 to $ctime1"
1537 # Restore should not change atime or mtime and should not
1539 $LFS hsm_restore $file
1540 wait_request_state $fid RESTORE SUCCEED
1542 atime1=$(stat -c "%X" $file)
1543 mtime1=$(stat -c "%Y" $file)
1544 ctime1=$(stat -c "%Z" $file)
1546 [ $atime0 -eq $atime1 ] ||
1547 error "restore changed atime from $atime0 to $atime1"
1549 [ $mtime0 -eq $mtime1 ] ||
1550 error "restore changed mtime from $mtime0 to $mtime1"
1552 [ $ctime0 -le $ctime1 ] ||
1553 error "restore changed ctime from $ctime0 to $ctime1"
1557 # Once more, after unmount and mount.
1558 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1559 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1561 atime1=$(stat -c "%X" $file)
1562 mtime1=$(stat -c "%Y" $file)
1563 ctime1=$(stat -c "%Z" $file)
1565 [ $atime0 -eq $atime1 ] ||
1566 error "remount changed atime from $atime0 to $atime1"
1568 [ $mtime0 -eq $mtime1 ] ||
1569 error "remount changed mtime from $mtime0 to $mtime1"
1571 [ $ctime0 -le $ctime1 ] ||
1572 error "remount changed ctime from $ctime0 to $ctime1"
1574 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1577 local file=$DIR/$tdir/$tfile
1583 # Test needs a running copytool.
1587 # Check that root can do HSM actions on a ordinary user's file.
1589 fid=$(make_small $file)
1590 sum0=$(md5sum $file)
1592 chown $RUNAS_ID:$RUNAS_GID $file ||
1593 error "cannot chown '$file' to '$RUNAS_ID'"
1595 chmod ugo-w $DIR/$tdir ||
1596 error "cannot chmod '$DIR/$tdir'"
1598 $LFS hsm_archive $file
1599 wait_request_state $fid ARCHIVE SUCCEED
1601 $LFS hsm_release $file
1602 check_hsm_flags $file "0x0000000d"
1604 $LFS hsm_restore $file
1605 wait_request_state $fid RESTORE SUCCEED
1607 # Check that ordinary user can get HSM state.
1608 $RUNAS $LFS hsm_state $file ||
1609 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1611 $LFS hsm_release $file
1612 check_hsm_flags $file "0x0000000d"
1614 # Check that ordinary user can accessed released file.
1615 sum1=$($RUNAS md5sum $file) ||
1616 error "user '$RUNAS_ID' cannot read '$file'"
1618 [ "$sum0" == "$sum1" ] ||
1619 error "md5sum mismatch for '$file'"
1623 run_test 24b "root can archive, release, and restore user files"
1625 cleanup_test_24c() {
1627 set_hsm_param user_request_mask RESTORE
1628 set_hsm_param group_request_mask RESTORE
1629 set_hsm_param other_request_mask RESTORE
1633 local file=$DIR/$tdir/$tfile
1634 local action=archive
1639 # test needs a running copytool
1644 # Save the default masks and check that cleanup_24c will
1645 # restore the request masks correctly.
1646 user_save=$(get_hsm_param user_request_mask)
1647 group_save=$(get_hsm_param group_request_mask)
1648 other_save=$(get_hsm_param other_request_mask)
1650 [ "$user_save" == RESTORE ] ||
1651 error "user_request_mask is '$user_save' expected 'RESTORE'"
1652 [ "$group_save" == RESTORE ] ||
1653 error "group_request_mask is '$group_save' expected 'RESTORE'"
1654 [ "$other_save" == RESTORE ] ||
1655 error "other_request_mask is '$other_save' expected 'RESTORE'"
1657 trap cleanup_test_24c EXIT
1662 chown $RUNAS_ID:nobody $file ||
1663 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1665 set_hsm_param user_request_mask ""
1666 $RUNAS $LFS hsm_$action $file &&
1667 error "$action by user should fail"
1669 set_hsm_param user_request_mask $action
1670 $RUNAS $LFS hsm_$action $file ||
1671 error "$action by user should succeed"
1676 chown nobody:$RUNAS_GID $file ||
1677 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1679 set_hsm_param group_request_mask ""
1680 $RUNAS $LFS hsm_$action $file &&
1681 error "$action by group should fail"
1683 set_hsm_param group_request_mask $action
1684 $RUNAS $LFS hsm_$action $file ||
1685 error "$action by group should succeed"
1690 chown nobody:nobody $file ||
1691 error "cannot chown '$file' to 'nobody:nobody'"
1693 set_hsm_param other_request_mask ""
1694 $RUNAS $LFS hsm_$action $file &&
1695 error "$action by other should fail"
1697 set_hsm_param other_request_mask $action
1698 $RUNAS $LFS hsm_$action $file ||
1699 error "$action by other should succeed"
1704 run_test 24c "check that user,group,other request masks work"
1706 cleanup_test_24d() {
1708 mount -o remount,rw $MOUNT2
1712 local file1=$DIR/$tdir/$tfile
1713 local file2=$DIR2/$tdir/$tfile
1721 fid1=$(make_small $file1)
1723 trap cleanup_test_24d EXIT
1725 mount -o remount,ro $MOUNT2
1727 fid2=$(path2fid $file2)
1728 [ "$fid1" == "$fid2" ] ||
1729 error "FID mismatch '$fid1' != '$fid2'"
1731 $LFS hsm_archive $file2 &&
1732 error "archive should fail on read-only mount"
1733 check_hsm_flags $file1 "0x00000000"
1735 $LFS hsm_archive $file1
1736 wait_request_state $fid1 ARCHIVE SUCCEED
1738 $LFS hsm_release $file1
1739 $LFS hsm_restore $file2
1740 wait_request_state $fid1 RESTORE SUCCEED
1742 $LFS hsm_release $file1 || error "cannot release '$file1'"
1743 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1745 $LFS hsm_release $file2 &&
1746 error "release should fail on read-only mount"
1751 run_test 24d "check that read-only mounts are respected"
1754 # test needs a running copytool
1758 copy2archive /etc/hosts $tdir/$tfile
1760 local f=$DIR/$tdir/$tfile
1762 import_file $tdir/$tfile $f
1764 $LFS hsm_set --lost $f
1769 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1773 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1774 " (Operation not permitted)"
1777 # test needs a running copytool
1782 local f=$DIR/$tdir/$tfile
1783 local fid=$(copy_file /etc/passwd $f)
1785 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1786 wait_request_state $fid ARCHIVE SUCCEED
1789 $LFS hsm_set --lost $f
1793 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1797 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1798 " (Operation not permitted)"
1801 # test needs a running copytool
1805 local f=$DIR/$tdir/$tfile
1806 local fid=$(make_large_for_progress $f)
1807 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1808 wait_request_state $fid ARCHIVE SUCCEED
1811 wait_request_state $fid REMOVE SUCCEED
1813 check_hsm_flags $f "0x00000000"
1817 run_test 26 "Remove the archive of a valid file"
1820 # test needs a running copytool
1824 make_archive $tdir/$tfile
1825 local f=$DIR/$tdir/$tfile
1826 import_file $tdir/$tfile $f
1827 local fid=$(path2fid $f)
1831 [[ $? != 0 ]] || error "Remove of a released file should fail"
1835 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1838 # test needs a running copytool
1842 local f=$DIR/$tdir/$tfile
1843 local fid=$(make_large_for_progress $f)
1844 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1845 wait_request_state $fid ARCHIVE SUCCEED
1850 [[ $? != 0 ]] || error "Remove of a released file should fail"
1854 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1857 # test needs a running copytool
1861 local f=$DIR/$tdir/$tfile
1862 local fid=$(make_large_for_progress $f)
1863 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1864 wait_request_state $fid ARCHIVE SUCCEED
1873 wait_request_state $fid REMOVE SUCCEED
1877 run_test 28 "Concurrent archive/file remove"
1880 # restore at exec cannot work on agent node (because of Linux kernel
1881 # protection of executables)
1882 needclients 2 || return 0
1884 # test needs a running copytool
1888 copy2archive /bin/true $tdir/$tfile
1890 local f=$DIR/$tdir/true
1891 import_file $tdir/$tfile $f
1893 local fid=$(path2fid $f)
1895 # set no retry action mode
1901 # remove no try action mode
1905 [[ $st == 0 ]] || error "Failed to exec a released file"
1909 run_test 30a "Restore at exec (import case)"
1912 # restore at exec cannot work on agent node (because of Linux kernel
1913 # protection of executables)
1914 needclients 2 || return 0
1916 # test needs a running copytool
1920 local f=$DIR/$tdir/true
1921 local fid=$(copy_file /bin/true $f)
1923 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1924 wait_request_state $fid ARCHIVE SUCCEED
1927 # set no retry action mode
1933 # remove no try action mode
1937 [[ $st == 0 ]] || error "Failed to exec a released file"
1941 run_test 30b "Restore at exec (release case)"
1944 needclients 2 || return 0
1946 # test needs a running copytool
1950 local f=$DIR/$tdir/SLEEP
1951 local fid=$(copy_file /bin/sleep $f)
1953 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1954 wait_request_state $fid ARCHIVE SUCCEED
1956 check_hsm_flags $f "0x0000000d"
1957 # set no retry action mode
1959 do_node $CLIENT2 "$f 10" &
1963 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1965 [[ $? == 0 ]] || error "Execution failed during run"
1967 [[ $? == 0 ]] || error "Binary overwritten during exec"
1970 # remove no try action mode
1972 check_hsm_flags $f "0x00000009"
1976 run_test 30c "Update during exec of released file must fail"
1978 restore_and_check_size() {
1981 local s=$(stat -c "%s" $f)
1983 local st=$(get_hsm_flags $f)
1987 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1989 n=$(stat -c "%s" $f)
1990 # we echo in both cases to show stat is not
1992 if [[ $n != $s ]]; then
1993 echo "size seen is $n != $s"
1996 echo "size seen is right: $n == $s"
1998 st=$(get_hsm_flags $f)
2002 if [[ $cpt -lt 10 ]]; then
2005 echo " restore is too long"
2006 wait_request_state $fid RESTORE SUCCEED
2012 # test needs a running copytool
2017 make_archive $tdir/$tfile
2018 local f=$DIR/$tdir/$tfile
2019 import_file $tdir/$tfile $f
2020 local fid=$($LFS path2fid $f)
2021 HSM_ARCHIVE_PURGE=false copytool_setup
2023 restore_and_check_size $f $fid
2026 [[ $err -eq 0 ]] || error "File size changed during restore"
2030 run_test 31a "Import a large file and check size during restore"
2034 # test needs a running copytool
2039 local f=$DIR/$tdir/$tfile
2040 local fid=$(make_large_for_progress $f)
2041 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2042 wait_request_state $fid ARCHIVE SUCCEED
2045 restore_and_check_size $f $fid
2048 [[ $err -eq 0 ]] || error "File size changed during restore"
2052 run_test 31b "Restore a large unaligned file and check size during restore"
2055 # test needs a running copytool
2060 local f=$DIR/$tdir/$tfile
2061 local fid=$(make_large_for_progress_aligned $f)
2062 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2063 wait_request_state $fid ARCHIVE SUCCEED
2066 restore_and_check_size $f $fid
2069 [[ $err -eq 0 ]] || error "File size changed during restore"
2073 run_test 31c "Restore a large aligned file and check size during restore"
2076 # test needs a running copytool
2081 local f=$DIR/$tdir/$tfile
2082 local fid=$(make_large_for_progress $f)
2083 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2084 wait_request_state $fid ARCHIVE SUCCEED
2087 md5sum $f >/dev/null &
2089 wait_request_state $fid RESTORE STARTED
2094 # Check restore trigger process was killed
2095 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2099 wait_request_state $fid RESTORE CANCELED
2100 wait_request_state $fid CANCEL SUCCEED
2103 error "Cannot kill process waiting for restore ($killed)"
2107 run_test 33 "Kill a restore waiting process"
2110 # test needs a running copytool
2115 local f=$DIR/$tdir/$tfile
2116 local fid=$(make_large_for_progress $f)
2117 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2118 wait_request_state $fid ARCHIVE SUCCEED
2121 md5sum $f >/dev/null &
2123 wait_request_state $fid RESTORE STARTED
2125 rm $f || error "rm $f failed"
2126 # rm must not block during restore
2127 wait_request_state $fid RESTORE STARTED
2129 wait_request_state $fid RESTORE SUCCEED
2130 # check md5sum pgm finished
2131 local there=$(ps -o pid,comm hp $pid >/dev/null)
2132 [[ -z $there ]] || error "Restore initiator does not exit"
2134 local rc=$(wait $pid)
2135 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2139 run_test 34 "Remove file during restore"
2142 # test needs a running copytool
2147 local f=$DIR/$tdir/$tfile
2148 local f1=$DIR/$tdir/$tfile-1
2149 local fid=$(make_large_for_progress $f)
2150 local fid1=$(copy_file /etc/passwd $f1)
2151 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2152 wait_request_state $fid ARCHIVE SUCCEED
2155 md5sum $f >/dev/null &
2157 wait_request_state $fid RESTORE STARTED
2159 mv $f1 $f || error "mv $f1 $f failed"
2160 # mv must not block during restore
2161 wait_request_state $fid RESTORE STARTED
2163 wait_request_state $fid RESTORE SUCCEED
2164 # check md5sum pgm finished
2165 local there=$(ps -o pid,comm hp $pid >/dev/null)
2166 [[ -z $there ]] || error "Restore initiator does not exit"
2168 local rc=$(wait $pid)
2169 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2172 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2176 run_test 35 "Overwrite file during restore"
2179 # test needs a running copytool
2184 local f=$DIR/$tdir/$tfile
2185 local fid=$(make_large_for_progress $f)
2186 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2187 wait_request_state $fid ARCHIVE SUCCEED
2190 md5sum $f >/dev/null &
2192 wait_request_state $fid RESTORE STARTED
2195 # rm must not block during restore
2196 wait_request_state $fid RESTORE STARTED
2198 wait_request_state $fid RESTORE SUCCEED
2199 # check md5sum pgm finished
2200 local there=$(ps -o pid,comm hp $pid >/dev/null)
2202 error "Restore initiator does not exit"
2204 local rc=$(wait $pid)
2206 error "Restore initiator failed with $rc"
2210 run_test 36 "Move file during restore"
2217 for n in $(seq 1 $count); do
2218 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2220 echo "$count archive requests submitted"
2224 local stream_count=4
2225 local file_count=100
2227 local f=$DIR/$tdir/$tfile
2232 for i in $(seq 1 $file_count); do
2233 for p in $(seq 1 $stream_count); do
2234 fid=$(copy_file /etc/hosts $f.$p.$i)
2237 # force copytool to use a local/temp archive dir to ensure best
2238 # performance vs remote/NFS mounts used in auto-tests
2239 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2242 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2244 # to be sure wait_all_done will not be mislead by previous tests
2246 wait_for_grace_delay
2248 # start archive streams in background (archive files in parallel)
2249 for p in $(seq 1 $stream_count); do
2250 multi_archive $f.$p $file_count &
2253 echo -n "Wait for all requests being enqueued..."
2259 run_test 40 "Parallel archive requests"
2262 # test needs a running copytool
2266 local f=$DIR/$tdir/$tfile
2267 local fid=$(copy_file /etc/motd $f 1)
2269 $LFS hsm_archive $f || error "could not archive file"
2270 wait_request_state $fid ARCHIVE SUCCEED
2271 check_hsm_flags $f "0x00000009"
2273 multiop_bg_pause $f O_c || error "multiop failed"
2277 client_up || client_up || true
2279 kill -USR1 $MULTIPID
2280 wait $MULTIPID || error "multiop close failed"
2282 check_hsm_flags $f "0x0000000b"
2286 run_test 52 "Opened for write file on an evicted client should be set dirty"
2289 # test needs a running copytool
2293 local f=$DIR/$tdir/$tfile
2294 local fid=$(copy_file /etc/motd $f 1)
2296 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2297 error "could not archive file"
2298 wait_request_state $fid ARCHIVE SUCCEED
2299 check_hsm_flags $f "0x00000009"
2301 multiop_bg_pause $f o_c || error "multiop failed"
2305 client_up || client_up || true
2307 kill -USR1 $MULTIPID
2308 wait $MULTIPID || error "multiop close failed"
2310 check_hsm_flags $f "0x00000009"
2314 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2317 # test needs a running copytool
2321 local f=$DIR/$tdir/$tfile
2322 local fid=$(make_small $f)
2324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2325 error "could not archive file"
2326 wait_request_state $fid ARCHIVE STARTED
2328 check_hsm_flags $f "0x00000001"
2330 # Avoid coordinator resending this request as soon it has failed.
2335 wait_request_state $fid ARCHIVE FAILED
2337 check_hsm_flags $f "0x00000003"
2342 run_test 54 "Write during an archive cancels it"
2345 # test needs a running copytool
2349 local f=$DIR/$tdir/$tfile
2350 local fid=$(make_small $f)
2352 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2353 error "could not archive file"
2354 wait_request_state $fid ARCHIVE STARTED
2356 check_hsm_flags $f "0x00000001"
2358 # Avoid coordinator resending this request as soon it has failed.
2361 $TRUNCATE $f 1024 || error "truncate failed"
2363 wait_request_state $fid ARCHIVE FAILED
2365 check_hsm_flags $f "0x00000003"
2370 run_test 55 "Truncate during an archive cancels it"
2373 # test needs a running copytool
2377 local f=$DIR/$tdir/$tfile
2378 local fid=$(make_large_for_progress $f)
2380 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2381 error "could not archive file"
2382 wait_request_state $fid ARCHIVE STARTED
2384 check_hsm_flags $f "0x00000001"
2386 # Change metadata and sync to be sure we are not changing only
2391 wait_request_state $fid ARCHIVE SUCCEED
2393 check_hsm_flags $f "0x00000009"
2397 run_test 56 "Setattr during an archive is ok"
2400 # Need one client for I/O, one for request
2401 needclients 2 || return 0
2403 # test needs a running copytool
2407 local f=$DIR/$tdir/test_archive_remote
2408 # Create a file on a remote node
2409 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2410 "count=2 conv=fsync"
2413 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2414 error "hsm_archive failed"
2415 local fid=$(path2fid $f)
2416 wait_request_state $fid ARCHIVE SUCCEED
2418 # Release and implicit restore it
2419 do_node $CLIENT2 "$LFS hsm_release $f" ||
2420 error "hsm_release failed"
2421 do_node $CLIENT2 "md5sum $f" ||
2422 error "hsm_restore failed"
2424 wait_request_state $fid RESTORE SUCCEED
2428 run_test 57 "Archive a file with dirty cache on another node"
2430 truncate_released_file() {
2434 local sz=$(stat -c %s $src_file)
2435 local f=$DIR/$tdir/$tfile
2436 local fid=$(copy_file $1 $f)
2440 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2441 error "could not archive file"
2442 wait_request_state $fid ARCHIVE SUCCEED
2444 $LFS hsm_release $f || error "could not release file"
2446 $TRUNCATE $f $trunc_to || error "truncate failed"
2449 local sz1=$(stat -c %s $f)
2450 [[ $sz1 == $trunc_to ]] ||
2451 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2454 check_hsm_flags $f "0x0000000b"
2456 local state=$(get_request_state $fid RESTORE)
2457 [[ "$state" == "SUCCEED" ]] ||
2458 error "truncate $sz does not trig restore, state = $state"
2460 $TRUNCATE $ref $trunc_to
2461 cmp $ref $f || error "file data wrong after truncate"
2467 # test needs a running copytool
2472 local sz=$(stat -c %s /etc/passwd)
2474 echo "truncate up from $sz to $((sz*2))"
2475 truncate_released_file /etc/passwd $((sz*2))
2477 echo "truncate down from $sz to $((sz/2))"
2478 truncate_released_file /etc/passwd $((sz/2))
2480 echo "truncate to 0"
2481 truncate_released_file /etc/passwd 0
2485 run_test 58 "Truncate a released file will trigger restore"
2490 local f=$DIR/$tdir/$tfile
2491 local FILELIST=/tmp/filelist.txt
2495 for i in $(seq 1 $file_count); do
2496 fid=$(copy_file /etc/hosts $f.$i)
2497 echo $f.$i >> $FILELIST
2500 # to be sure wait_all_done will not be mislead by previous tests
2502 wait_for_grace_delay
2503 $LFS hsm_archive --filelist $FILELIST ||
2504 error "cannot archive a file list"
2506 $LFS hsm_release --filelist $FILELIST ||
2507 error "cannot release a file list"
2508 $LFS hsm_restore --filelist $FILELIST ||
2509 error "cannot restore a file list"
2513 run_test 90 "Archive/restore a file list"
2515 double_verify_reset_hsm_param() {
2517 echo "Testing $HSM_PARAM.$p"
2518 local val=$(get_hsm_param $p)
2520 local val2=$(($val * 2))
2521 set_hsm_param $p $val2
2522 val=$(get_hsm_param $p)
2523 [[ $val == $val2 ]] ||
2524 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2525 echo "Set $p to 0 must failed"
2529 set_hsm_param $p $save
2531 if [[ $rc == 0 ]]; then
2532 error "we must not be able to set $HSM_PARAM.$p to 0"
2537 double_verify_reset_hsm_param loop_period
2538 double_verify_reset_hsm_param grace_delay
2539 double_verify_reset_hsm_param active_request_timeout
2540 double_verify_reset_hsm_param max_requests
2541 double_verify_reset_hsm_param default_archive_id
2543 run_test 100 "Set coordinator /proc tunables"
2550 run_test 102 "Verify coordinator control"
2553 # test needs a running copytool
2560 for i in $(seq 1 20); do
2561 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2563 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2567 echo "Current requests"
2568 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2569 $HSM_PARAM.actions |\
2570 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2572 [[ -z "$res" ]] || error "Some request have not been canceled"
2576 run_test 103 "Purge all requests"
2581 # test needs a running copytool
2585 local f=$DIR/$tdir/$tfile
2586 local fid=$(make_large_for_progress $f)
2587 # if cdt is on, it can serve too quickly the request
2589 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2590 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2591 $HSM_PARAM.actions |\
2592 grep $fid | cut -f16 -d=")
2595 [[ "$data1" == "$DATAHEX" ]] ||
2596 error "Data field in records is ($data1) and not ($DATAHEX)"
2600 run_test 104 "Copy tool data field"
2607 for i in $(seq -w 1 10); do
2608 cp /etc/passwd $DIR/$tdir/$i
2609 $LFS hsm_archive $DIR/$tdir/$i
2611 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2612 $HSM_PARAM.actions |\
2613 grep WAITING | wc -l")
2616 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2617 $HSM_PARAM.actions |\
2618 grep WAITING | wc -l")
2621 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2622 error "Requests count after shutdown $reqcnt2 != "\
2623 "before shutdown $reqcnt1"
2625 run_test 105 "Restart of coordinator"
2627 get_agent_by_uuid_mdt() {
2630 local mds=mds$(($mdtidx + 1))
2631 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
2635 check_agent_registered_by_mdt() {
2638 local mds=mds$(($mdtidx + 1))
2639 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2640 if [[ ! -z "$agent" ]]; then
2641 echo "found agent $agent on $mds"
2643 error "uuid $uuid not found in agent list on $mds"
2647 check_agent_unregistered_by_mdt() {
2650 local mds=mds$(($mdtidx + 1))
2651 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2652 if [[ -z "$agent" ]]; then
2653 echo "uuid not found in agent list on $mds"
2655 error "uuid found in agent list on $mds: $agent"
2659 check_agent_registered() {
2662 for mdsno in $(seq 1 $MDSCOUNT); do
2663 check_agent_registered_by_mdt $uuid $((mdsno - 1))
2667 check_agent_unregistered() {
2670 for mdsno in $(seq 1 $MDSCOUNT); do
2671 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
2676 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2677 get_client_uuid $MOUNT | cut -d' ' -f2)
2680 check_agent_registered $uuid
2682 search_copytools || error "No copytool found"
2685 check_agent_unregistered $uuid
2688 check_agent_registered $uuid
2692 run_test 106 "Copytool register/unregister"
2695 # test needs a running copytool
2697 # create and archive file
2699 local f1=$DIR/$tdir/$tfile
2700 local fid=$(copy_file /etc/passwd $f1)
2701 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2702 wait_request_state $fid ARCHIVE SUCCEED
2703 # shutdown and restart MDS
2705 # check the copytool still gets messages from MDT
2706 local f2=$DIR/$tdir/2
2707 local fid=$(copy_file /etc/passwd $f2)
2708 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2709 # main check of this sanity: this request MUST succeed
2710 wait_request_state $fid ARCHIVE SUCCEED
2713 run_test 107 "Copytool re-register after MDS restart"
2715 policy_set_and_test()
2719 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2720 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2721 [[ "$policy" == "$target" ]] ||
2722 error "Wrong policy after '$change': '$policy' != '$target'"
2726 # to force default policy setting if error
2727 CDT_POLICY_HAD_CHANGED=true
2729 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2730 local default="NonBlockingRestore [NoRetryAction]"
2731 [[ "$policy" == "$default" ]] ||
2732 error "default policy has changed,"\
2733 " '$policy' != '$default' update the test"
2734 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2735 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2736 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2737 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2738 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2739 # useless bacause we know but safer for futur changes to use real value
2740 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2741 echo "Next set_param must failed"
2742 policy_set_and_test "wrong" "$policy"
2745 echo "Back to default policy"
2746 cdt_set_sanity_policy
2748 run_test 109 "Policy display/change"
2751 # test needs a running copytool
2756 copy2archive /etc/passwd $tdir/$tfile
2758 local f=$DIR/$tdir/$tfile
2759 import_file $tdir/$tfile $f
2760 local fid=$(path2fid $f)
2762 cdt_set_non_blocking_restore
2767 wait_request_state $fid RESTORE SUCCEED
2768 cdt_clear_non_blocking_restore
2772 error "md5sum returns $st != 1, "\
2773 "should also perror ENODATA (No data available)"
2777 run_test 110a "Non blocking restore policy (import case)"
2780 # test needs a running copytool
2784 local f=$DIR/$tdir/$tfile
2785 local fid=$(copy_file /etc/passwd $f)
2786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2787 wait_request_state $fid ARCHIVE SUCCEED
2790 cdt_set_non_blocking_restore
2795 wait_request_state $fid RESTORE SUCCEED
2796 cdt_clear_non_blocking_restore
2800 error "md5sum returns $st != 1, "\
2801 "should also perror ENODATA (No data available)"
2805 run_test 110b "Non blocking restore policy (release case)"
2808 # test needs a running copytool
2812 copy2archive /etc/passwd $tdir/$tfile
2814 local f=$DIR/$tdir/$tfile
2816 import_file $tdir/$tfile $f
2817 local fid=$(path2fid $f)
2821 copytool_remove_backend $fid
2824 wait_request_state $fid RESTORE FAILED
2831 [[ $st == 0 ]] || error "Restore does not failed"
2835 run_test 111a "No retry policy (import case), restore will error"\
2836 " (No such file or directory)"
2839 # test needs a running copytool
2843 local f=$DIR/$tdir/$tfile
2844 local fid=$(copy_file /etc/passwd $f)
2846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2847 wait_request_state $fid ARCHIVE SUCCEED
2850 copytool_remove_backend $fid
2853 wait_request_state $fid RESTORE FAILED
2860 [[ $st == 0 ]] || error "Restore does not failed"
2864 run_test 111b "No retry policy (release case), restore will error"\
2865 " (No such file or directory)"
2868 # test needs a running copytool
2872 local f=$DIR/$tdir/$tfile
2873 local fid=$(copy_file /etc/passwd $f)
2875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2876 local l=$($LFS hsm_action $f)
2878 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2882 wait_request_state $fid ARCHIVE SUCCEED
2885 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2889 run_test 112 "State of recorded request"
2892 # test needs a running copytool
2896 local f=$DIR/$tdir/$tfile
2897 local fid=$(make_large_for_cancel $f)
2898 # test with cdt on is made in test_221
2900 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2903 wait_request_state $fid ARCHIVE CANCELED
2904 wait_request_state $fid CANCEL SUCCEED
2908 run_test 200 "Register/Cancel archive"
2911 # test needs a running copytool
2915 local f=$DIR/$tdir/$tfile
2916 make_archive $tdir/$tfile
2917 import_file $tdir/$tfile $f
2918 local fid=$(path2fid $f)
2920 # test with cdt on is made in test_222
2925 wait_request_state $fid RESTORE CANCELED
2926 wait_request_state $fid CANCEL SUCCEED
2930 run_test 201 "Register/Cancel restore"
2933 # test needs a running copytool
2937 local f=$DIR/$tdir/$tfile
2938 local fid=$(make_large_for_progress $f)
2939 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2940 wait_request_state $fid ARCHIVE SUCCEED
2946 wait_request_state $fid REMOVE CANCELED
2950 run_test 202 "Register/Cancel remove"
2953 # test needs a running copytool
2958 local f=$DIR/$tdir/$tfile
2959 local fid=$(copy_file /etc/passwd $f)
2963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2964 wait_request_state $fid ARCHIVE SUCCEED
2966 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2970 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2974 run_test 220 "Changelog for archive"
2977 # test needs a running copytool
2982 local f=$DIR/$tdir/$tfile
2983 local fid=$(make_large_for_cancel $f)
2987 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2988 wait_request_state $fid ARCHIVE STARTED
2990 wait_request_state $fid ARCHIVE CANCELED
2991 wait_request_state $fid CANCEL SUCCEED
2993 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2996 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3000 run_test 221 "Changelog for archive canceled"
3003 # test needs a running copytool
3007 copy2archive /etc/passwd $tdir/$tfile
3009 local f=$DIR/$tdir/$tfile
3010 import_file $tdir/$tfile $f
3011 local fid=$(path2fid $f)
3016 wait_request_state $fid RESTORE SUCCEED
3018 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3021 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3025 run_test 222a "Changelog for explicit restore"
3028 # test needs a running copytool
3032 local f=$DIR/$tdir/$tfile
3033 local fid=$(copy_file /etc/passwd $f)
3036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3037 wait_request_state $fid ARCHIVE SUCCEED
3042 wait_request_state $fid RESTORE SUCCEED
3044 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3047 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3051 run_test 222b "Changelog for implicit restore"
3054 # test needs a running copytool
3059 local f=$DIR/$tdir/$tfile
3060 make_archive $tdir/$tfile
3064 import_file $tdir/$tfile $f
3065 local fid=$(path2fid $f)
3068 wait_request_state $fid RESTORE STARTED
3070 wait_request_state $fid RESTORE CANCELED
3071 wait_request_state $fid CANCEL SUCCEED
3073 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3076 [[ $flags == $target ]] ||
3077 error "Changelog flag is $flags not $target"
3081 run_test 223a "Changelog for restore canceled (import case)"
3084 # test needs a running copytool
3089 local f=$DIR/$tdir/$tfile
3090 local fid=$(make_large_for_progress $f)
3093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3094 wait_request_state $fid ARCHIVE SUCCEED
3097 wait_request_state $fid RESTORE STARTED
3099 wait_request_state $fid RESTORE CANCELED
3100 wait_request_state $fid CANCEL SUCCEED
3102 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3105 [[ $flags == $target ]] ||
3106 error "Changelog flag is $flags not $target"
3110 run_test 223b "Changelog for restore canceled (release case)"
3113 # test needs a running copytool
3118 local f=$DIR/$tdir/$tfile
3119 local fid=$(copy_file /etc/passwd $f)
3122 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3123 wait_request_state $fid ARCHIVE SUCCEED
3126 wait_request_state $fid REMOVE SUCCEED
3128 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3131 [[ $flags == $target ]] ||
3132 error "Changelog flag is $flags not $target"
3136 run_test 224 "Changelog for remove"
3139 # test needs a running copytool
3142 # test is not usable because remove request is too fast
3143 # so it is always finished before cancel can be done ...
3144 echo "Test disabled"
3149 local f=$DIR/$tdir/$tfile
3150 local fid=$(make_large_for_progress $f)
3153 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3154 wait_request_state $fid ARCHIVE SUCCEED
3156 # if cdt is on, it can serve too quickly the request
3161 wait_request_state $fid REMOVE CANCELED
3162 wait_request_state $fid CANCEL SUCCEED
3164 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3165 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3166 tail -n 1 | awk '{print $5}')
3169 [[ $flags == $target ]] ||
3170 error "Changelog flag is $flags not $target"
3174 run_test 225 "Changelog for remove canceled"
3177 # test needs a running copytool
3182 local f1=$DIR/$tdir/$tfile-1
3183 local f2=$DIR/$tdir/$tfile-2
3184 local f3=$DIR/$tdir/$tfile-3
3185 local fid1=$(copy_file /etc/passwd $f1)
3186 local fid2=$(copy_file /etc/passwd $f2)
3187 copy_file /etc/passwd $f3
3190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3191 wait_request_state $fid1 ARCHIVE SUCCEED
3193 $LFS hsm_archive $f2
3194 wait_request_state $fid2 ARCHIVE SUCCEED
3196 rm $f1 || error "rm $f1 failed"
3198 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3201 [[ $flags == $target ]] ||
3202 error "Changelog flag is $flags not $target"
3204 mv $f3 $f2 || error "mv $f3 $f2 failed"
3206 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3209 [[ $flags == $target ]] ||
3210 error "Changelog flag is $flags not $target"
3214 run_test 226 "changelog for last rm/mv with exiting archive"
3216 check_flags_changes() {
3224 $LFS hsm_set --$hsm_flag $f ||
3225 error "Cannot set $hsm_flag on $f"
3226 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3227 local seen=${#flags[*]}
3229 [[ $seen == $cnt ]] ||
3230 error "set $hsm_flag: Changelog events $seen != $cnt"
3231 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3232 error "set $hsm_flag: Changelog flags are "\
3233 "${flags[$((cnt - 1))]} not $target"
3235 $LFS hsm_clear --$hsm_flag $f ||
3236 error "Cannot clear $hsm_flag on $f"
3237 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3240 [[ $cnt == $seen ]] ||
3241 error "clear $hsm_flag: Changelog events $seen != $cnt"
3243 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3244 error "clear $hsm_flag: Changelog flag is "\
3245 "${flags[$((cnt - 1))]} not $target"
3249 # test needs a running copytool
3256 for i in norelease noarchive exists archived
3258 local f=$DIR/$tdir/$tfile-$i
3259 local fid=$(copy_file /etc/passwd $f)
3260 check_flags_changes $f $fid $i 0 1
3263 f=$DIR/$tdir/$tfile---lost
3264 fid=$(copy_file /etc/passwd $f)
3265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3266 wait_request_state $fid ARCHIVE SUCCEED
3267 check_flags_changes $f $fid lost 3 1
3271 run_test 227 "changelog when explicit setting of HSM flags"
3274 # test needs a running copytool
3277 local fid=$(make_small_sync $DIR/$tfile)
3278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3279 wait_request_state $fid ARCHIVE SUCCEED
3281 $LFS hsm_release $DIR/$tfile
3282 check_hsm_flags $DIR/$tfile "0x0000000d"
3284 filefrag $DIR/$tfile | grep " 1 extent found" ||
3285 error "filefrag on released file must return only one extent"
3287 # only newer versions of cp detect sparse files by stat/FIEMAP
3289 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3290 error "copying $DIR/$tfile"
3291 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3293 $LFS hsm_release $DIR/$tfile
3294 check_hsm_flags $DIR/$tfile "0x0000000d"
3296 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3298 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3300 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3301 error "comparing untarred $DIR/$tfile"
3303 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3304 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3307 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3310 # test needs a running copytool
3314 local maxrequest=$(get_hsm_param max_requests)
3315 local rqcnt=$(($maxrequest * 3))
3319 for i in $(seq -w 1 $rqcnt); do
3321 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3323 # we do it in 2 steps, so all requests arrive at the same time
3324 for i in $(seq -w 1 $rqcnt); do
3325 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3330 while [[ $cnt != 0 || $wt != 0 ]]; do
3332 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3333 $HSM_PARAM.actions |\
3334 grep STARTED | grep -v CANCEL | wc -l")
3335 [[ $cnt -le $maxrequest ]] ||
3336 error "$cnt > $maxrequest too many started requests"
3337 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3338 $HSM_PARAM.actions |\
3339 grep WAITING | wc -l")
3340 echo "max=$maxrequest started=$cnt waiting=$wt"
3345 run_test 250 "Coordinator max request"
3348 # test needs a running copytool
3352 local f=$DIR/$tdir/$tfile
3353 local fid=$(make_large_for_cancel $f)
3356 # to have a short test
3357 local old_to=$(get_hsm_param active_request_timeout)
3358 set_hsm_param active_request_timeout 4
3359 # to be sure the cdt will wake up frequently so
3360 # it will be able to cancel the "old" request
3361 local old_loop=$(get_hsm_param loop_period)
3362 set_hsm_param loop_period 2
3365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3366 wait_request_state $fid ARCHIVE STARTED
3368 wait_request_state $fid ARCHIVE CANCELED
3370 set_hsm_param active_request_timeout $old_to
3371 set_hsm_param loop_period $old_loop
3375 run_test 251 "Coordinator request timeout"
3378 # the only way to test ondisk conf is to restart MDS ...
3379 echo "Stop coordinator and remove coordinator state at mount"
3382 # clean on disk conf set by default
3383 cdt_clear_mount_state
3384 cdt_check_state stopped
3386 # check cdt still off after umount/remount
3388 cdt_check_state stopped
3390 echo "Set coordinator start at mount, and start coordinator"
3391 cdt_set_mount_state enabled
3394 cdt_check_state enabled
3396 # check cdt still on after umount/remount
3398 cdt_check_state enabled
3400 # we are back to original state (cdt started at mount)
3402 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3405 local ai=$(get_hsm_param default_archive_id)
3406 local new=$((ai + 1))
3408 set_hsm_param default_archive_id $new -P
3410 local res=$(get_hsm_param default_archive_id)
3413 set_hsm_param default_archive_id "" "-P -d"
3415 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3417 run_test 301 "HSM tunnable are persistent"
3420 local ai=$(get_hsm_param default_archive_id)
3421 local new=$((ai + 1))
3426 set_hsm_param default_archive_id $new -P
3429 for mdtno in $(seq 1 $MDSCOUNT); do
3434 cdt_check_state enabled
3436 local res=$(get_hsm_param default_archive_id)
3439 set_hsm_param default_archive_id "" "-P -d"
3441 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3443 run_test 302 "HSM tunnable are persistent when CDT is off"
3446 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3452 local dir_mdt0=$DIR/$tdir/mdt0
3453 local dir_mdt1=$DIR/$tdir/mdt1
3455 # create 1 dir per MDT
3456 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3457 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3459 # create 1 file in each MDT
3460 local fid1=$(make_small $dir_mdt0/$tfile)
3461 local fid2=$(make_small $dir_mdt1/$tfile)
3463 # check that hsm request on mdt0 is sent to the right MDS
3464 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3465 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3466 echo "archive successful on mdt0"
3468 # check that hsm request on mdt1 is sent to the right MDS
3469 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3470 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3471 echo "archive successful on mdt1"
3474 # clean test files and directories
3475 rm -rf $dir_mdt0 $dir_mdt1
3477 run_test 400 "Single request is sent to the right MDT"
3480 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3486 local dir_mdt0=$DIR/$tdir/mdt0
3487 local dir_mdt1=$DIR/$tdir/mdt1
3489 # create 1 dir per MDT
3490 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3491 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3493 # create 1 file in each MDT
3494 local fid1=$(make_small $dir_mdt0/$tfile)
3495 local fid2=$(make_small $dir_mdt1/$tfile)
3497 # check that compound requests are shunt to the rights MDTs
3498 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3499 error "lfs hsm_archive"
3500 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3501 echo "archive successful on mdt0"
3502 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3503 echo "archive successful on mdt1"
3506 # clean test files and directories
3507 rm -rf $dir_mdt0 $dir_mdt1
3509 run_test 401 "Compound requests split and sent to their respective MDTs"
3511 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3516 local node=$(facet_active_host $facet)
3518 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3519 awk '{print $4}'); do
3520 echo "$3 $mdc on $node"
3521 do_facet $facet "$LCTL --device $mdc $state" || return 1
3526 # make sure there is no running copytool
3529 # deactivate all mdc on agent1
3530 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3532 copytool_setup $SINGLEAGT
3534 check_agent_unregistered "uuid" # match any agent
3536 # no expected running copytool
3537 search_copytools $agent && error "Copytool start should have failed"
3540 mdc_change_state $SINGLEAGT "MDT000." "activate"
3542 run_test 402 "Copytool start fails if all MDTs are inactive"
3545 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3547 # make sure there is no running copytool
3550 local agent=$(facet_active_host $SINGLEAGT)
3551 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3553 # deactivate all mdc for MDT0001
3554 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3557 # check the agent is registered on MDT0000, and not on MDT0001
3558 check_agent_registered_by_mdt $uuid 0
3559 check_agent_unregistered_by_mdt $uuid 1
3561 # check running copytool process
3562 search_copytools $agent || error "No running copytools on $agent"
3564 # reactivate all mdc for MDT0001
3565 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3567 # make sure the copytool is now registered to all MDTs
3568 check_agent_registered $uuid
3572 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3575 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3579 # create files on both MDT0000 and MDT0001
3582 local dir_mdt0=$DIR/$tdir/mdt0
3583 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3585 # create 1 file on mdt0
3586 local fid1=$(make_small $dir_mdt0/$tfile)
3588 # deactivate all mdc for MDT0001
3589 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3591 # send an HSM request for files in MDT0000
3592 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3594 # check for completion of files in MDT0000
3595 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3596 echo "archive successful on mdt0"
3598 # reactivate all mdc for MDT0001
3599 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3602 # clean test files and directories
3605 run_test 404 "Inactive MDT does not block requests for active MDTs"
3610 check_and_cleanup_lustre