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 3939
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36 40"
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 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
38 # bug number for skipped test: LU-3700
39 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 51b"
41 check_and_setup_lustre
43 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
44 skip_env "Need MDS version at least 2.4.53" && exit
47 # $RUNAS_ID may get set incorrectly somewhere else
48 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
49 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
51 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
56 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
57 # the following associated variables are added:
59 # AGTCOUNT: number of agents
60 # AGTDEV{N}: target HSM mount point (root path of the backend)
61 # agt{N}_HOST: hostname of the agent agt{N}
62 # SINGLEAGT: facet of the single agent
64 # The number of agents is initialized as the number of remote client nodes.
65 # By default, only single copytool is started on a remote client/agent. If there
66 # was no remote client, then the copytool will be started on the local client.
72 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
73 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
75 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
76 if [[ $CLIENTCOUNT -gt 1 ]] &&
77 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
78 skip_env "SHARED_DIRECTORY should be accessible"\
83 for n in $(seq $AGTCOUNT); do
84 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
85 agent=CLIENT$((n + 1))
86 if [[ -z "${!agent}" ]]; then
87 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
90 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
93 export SINGLEAGT=${SINGLEAGT:-agt1}
95 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
96 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
97 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
98 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
101 # The test only support up to 10 MDTs
102 MDT_PREFIX="mdt.$FSNAME-MDT000"
103 HSM_PARAM="${MDT_PREFIX}0.hsm"
105 # archive is purged at copytool setup
106 HSM_ARCHIVE_PURGE=true
109 # Get the backend root path for the given agent facet.
112 local dev=AGTDEV$(facet_number $facet)
117 # Stop copytool and unregister an existing changelog user.
121 cdt_set_sanity_policy
126 # get MDT device for each mdc
127 for mdtno in $(seq 1 $MDSCOUNT); do
128 local idx=$(($mdtno - 1))
129 MDT[$idx]=$($LCTL get_param -n \
130 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
131 awk '{gsub(/_UUID/,""); print $1}' | head -1)
136 local agents=${1:-$(facet_active_host $SINGLEAGT)}
137 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
140 search_and_kill_copytool() {
141 local agents=${1:-$(facet_active_host $SINGLEAGT)}
143 echo "Killing existing copytools on $agents"
144 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
148 local facet=${1:-$SINGLEAGT}
149 local lustre_mntpnt=${2:-$MOUNT}
151 local hsm_root=$(copytool_device $facet)
152 local agent=$(facet_active_host $facet)
154 if [[ -z "$arc_id" ]] &&
155 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
156 echo "Wakeup copytool $facet on $agent"
160 if $HSM_ARCHIVE_PURGE; then
161 echo "Purging archive on $agent"
162 do_facet $facet "rm -rf $hsm_root/*"
165 echo "Starting copytool $facet on $agent"
166 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
167 # bandwidth is limited to 1MB/s so the copy time is known and
168 # independent of hardware
169 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
170 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
171 cmd+=" --bandwidth 1 $lustre_mntpnt"
173 # Redirect the standard output and error to a log file which
174 # can be uploaded to Maloo.
175 local prefix=$TESTLOG_PREFIX
176 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
177 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
179 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
180 error "start copytool $facet on $agent failed"
186 local agents=${1:-$(facet_active_host $SINGLEAGT)}
192 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
194 echo "Copytool is stopped on $agents"
196 # clean all CDTs orphans requests from previous tests
197 # that would otherwise need to timeout to clear.
198 for mdtno in $(seq 1 $MDSCOUNT); do
200 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
201 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
203 # skip already stop[ed,ing] CDTs
204 echo $oldstate | grep stop && continue
206 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
207 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
209 error "mds${mdtno} cdt state is not stopped"
210 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
211 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
213 error "mds${mdtno} cdt state is not $oldstate"
218 local agents=${1:-$(facet_active_host $SINGLEAGT)}
220 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
221 echo "Copytool is suspended on $agents"
224 copytool_remove_backend() {
226 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
227 echo "Remove from backend: $fid = $be"
228 do_facet $SINGLEAGT rm -f $be
232 do_facet $SINGLEAGT \
233 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
234 --import $1 $2 $MOUNT" ||
235 error "import of $1 to $2 failed"
239 local file=$HSM_ARCHIVE/$1
240 do_facet $SINGLEAGT mkdir -p $(dirname $file)
241 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
242 error "cannot create $file"
246 local file=$HSM_ARCHIVE/$2
247 do_facet $SINGLEAGT mkdir -p $(dirname $file)
248 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
257 if [[ "$value" != "" ]]; then
260 for mdtno in $(seq 1 $MDSCOUNT); do
261 local idx=$(($mdtno - 1))
262 local facet=mds${mdtno}
263 # if $arg include -P option, run 1 set_param per MDT on the MGS
264 # else, run set_param on each MDT
265 [[ $arg = *"-P"* ]] && facet=mgs
266 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
267 [[ $? != 0 ]] && rc=1
277 for mdtno in $(seq 1 $MDSCOUNT); do
278 local idx=$(($mdtno - 1))
279 wait_result mds${mdtno} \
280 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
282 error "$key state is not '$target' on mds${mdtno}"
289 for mdtno in $(seq 1 $MDSCOUNT); do
290 local idx=$(($mdtno - 1))
291 local cl_user=$(do_facet mds${mdtno} $LCTL \
292 --device ${MDT[$idx]} \
293 changelog_register -n)
295 do_facet mds${mdtno} lctl set_param \
296 mdd.${MDT[$idx]}.changelog_mask="+hsm"
297 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
301 changelog_cleanup() {
303 for mdtno in $(seq 1 $MDSCOUNT); do
304 local idx=$(($mdtno - 1))
305 [[ -z ${CL_USERS[$idx]} ]] && continue
306 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
307 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
308 changelog_deregister ${CL_USERS[$idx]}
313 changelog_get_flags() {
318 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
323 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
331 mdts_set_param "$opt -n" "hsm.$param" "$value"
338 mdts_set_param "" hsm_control "$cmd"
339 mdts_check_param hsm_control "$target" 10
342 cdt_set_sanity_policy() {
343 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
346 mdts_set_param "" hsm.policy "+NRA"
347 mdts_set_param "" hsm.policy "-NBR"
348 CDT_POLICY_HAD_CHANGED=
353 mdts_set_param "" hsm.policy "+NRA"
354 CDT_POLICY_HAD_CHANGED=true
357 cdt_clear_no_retry() {
358 mdts_set_param "" hsm.policy "-NRA"
359 CDT_POLICY_HAD_CHANGED=true
362 cdt_set_non_blocking_restore() {
363 mdts_set_param "" hsm.policy "+NBR"
364 CDT_POLICY_HAD_CHANGED=true
367 cdt_clear_non_blocking_restore() {
368 mdts_set_param "" hsm.policy "-NBR"
369 CDT_POLICY_HAD_CHANGED=true
372 cdt_clear_mount_state() {
373 mdts_set_param "-P -d" hsm_control ""
376 cdt_set_mount_state() {
377 mdts_set_param "-P" hsm_control "$1"
381 mdts_check_param hsm_control "$1" 20
385 set_test_state disabled disabled
389 set_test_state enabled enabled
393 set_test_state shutdown stopped
397 set_test_state purge enabled
403 cdt_set_sanity_policy
407 local client_count=$1
408 if [[ $CLIENTCOUNT -lt $client_count ]]; then
409 skip "Need $client_count or more clients, have $CLIENTCOUNT"
416 $LFS path2fid $1 | tr -d '[]'
423 if [[ $u == "user" ]]; then
424 local st=$($RUNAS $LFS hsm_state $f)
426 local st=$($LFS hsm_state $f)
430 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
432 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
436 get_hsm_archive_id() {
438 local st=$($LFS hsm_state $f)
439 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
441 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
450 local st=$(get_hsm_flags $f)
451 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
454 check_hsm_flags_user() {
458 local st=$(get_hsm_flags $f user)
459 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
471 if [[ "$3" != 1 ]]; then
475 cp $1 $f || error "cannot copy $1 to $f"
476 path2fid $f || error "cannot get fid on $f"
480 local file2=${1/$DIR/$DIR2}
481 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
482 error "cannot create $file2"
483 path2fid $1 || error "cannot get fid on $1"
486 cleanup_large_files() {
487 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
489 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
492 make_large_for_striping() {
493 local file2=${1/$DIR/$DIR2}
494 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
498 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
499 error "cannot create $file2"
500 path2fid $1 || error "cannot get fid on $1"
503 make_large_for_progress() {
504 local file2=${1/$DIR/$DIR2}
508 # big file is large enough, so copy time is > 30s
509 # so copytool make 1 progress
510 # size is not a multiple of 1M to avoid stripe
512 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
513 error "cannot create $file2"
514 path2fid $1 || error "cannot get fid on $1"
517 make_large_for_progress_aligned() {
518 local file2=${1/$DIR/$DIR2}
522 # big file is large enough, so copy time is > 30s
523 # so copytool make 1 progress
524 # size is a multiple of 1M to have stripe
526 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
527 error "cannot create $file2"
528 path2fid $1 || error "cannot get fid on $1"
531 make_large_for_cancel() {
532 local file2=${1/$DIR/$DIR2}
536 # Copy timeout is 100s. 105MB => 105s
537 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
538 error "cannot create $file2"
539 path2fid $1 || error "cannot get fid on $1"
545 wait_update --verbose $(facet_active_host $facet) "$@"
548 wait_request_state() {
552 # 4th arg (mdt index) is optional
554 local mds=mds$(($mdtidx + 1))
556 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
557 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
559 wait_result $mds "$cmd" $state 100 ||
560 error "request on $fid is not $state on $mds"
563 get_request_state() {
567 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
568 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
571 get_request_count() {
575 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
576 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
582 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
583 cmd+=" | egrep 'WAITING|STARTED'"
585 wait_result $SINGLEMDS "$cmd" "" $timeout ||
586 error "requests did not complete"
589 wait_for_grace_delay() {
590 local val=$(get_hsm_param grace_delay)
594 # populate MDT device array
600 # cleanup from previous bad setup
601 search_and_kill_copytool
603 # for recovery tests, coordinator needs to be started at mount
605 # the lustre conf must be without hsm on (like for sanity.sh)
606 echo "Set HSM on and start"
607 cdt_set_mount_state enabled
608 cdt_check_state enabled
610 echo "Start copytool"
613 echo "Set sanity-hsm HSM policy"
614 cdt_set_sanity_policy
616 # finished requests are quickly removed from list
617 set_hsm_param grace_delay 10
623 local f=$DIR/$tdir/$tfile
627 check_hsm_flags_user $f "0x00000000"
629 $RUNAS $LFS hsm_set --norelease $f ||
630 error "user could not change hsm flags"
631 check_hsm_flags_user $f "0x00000010"
633 $RUNAS $LFS hsm_clear --norelease $f ||
634 error "user could not clear hsm flags"
635 check_hsm_flags_user $f "0x00000000"
637 # User could not change those flags...
638 $RUNAS $LFS hsm_set --exists $f &&
639 error "user should not set this flag"
640 check_hsm_flags_user $f "0x00000000"
643 $LFS hsm_set --exists $f ||
644 error "root could not change hsm flags"
645 check_hsm_flags_user $f "0x00000001"
647 $LFS hsm_clear --exists $f ||
648 error "root could not clear hsm state"
649 check_hsm_flags_user $f "0x00000000"
652 run_test 1 "lfs hsm flags root/non-root access"
656 local f=$DIR/$tdir/$tfile
658 # New files are not dirty
659 check_hsm_flags $f "0x00000000"
661 # For test, we simulate an archived file.
662 $LFS hsm_set --exists $f || error "user could not change hsm flags"
663 check_hsm_flags $f "0x00000001"
665 # chmod do not put the file dirty
666 chmod 600 $f || error "could not chmod test file"
667 check_hsm_flags $f "0x00000001"
669 # chown do not put the file dirty
670 chown $RUNAS_ID $f || error "could not chown test file"
671 check_hsm_flags $f "0x00000001"
673 # truncate put the file dirty
674 $TRUNCATE $f 1 || error "could not truncate test file"
675 check_hsm_flags $f "0x00000003"
677 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
678 check_hsm_flags $f "0x00000001"
680 run_test 2 "Check file dirtyness when doing setattr"
686 # New files are not dirty
688 check_hsm_flags $f "0x00000000"
690 # For test, we simulate an archived file.
691 $LFS hsm_set --exists $f ||
692 error "user could not change hsm flags"
693 check_hsm_flags $f "0x00000001"
695 # Reading a file, does not set dirty
696 cat $f > /dev/null || error "could not read file"
697 check_hsm_flags $f "0x00000001"
699 # Open for write without modifying data, does not set dirty
700 openfile -f O_WRONLY $f || error "could not open test file"
701 check_hsm_flags $f "0x00000001"
703 # Append to a file sets it dirty
704 cp -p /etc/passwd $f.append || error "could not create file"
705 $LFS hsm_set --exists $f.append ||
706 error "user could not change hsm flags"
707 dd if=/etc/passwd of=$f.append bs=1 count=3\
708 conv=notrunc oflag=append status=noxfer ||
709 error "could not append to test file"
710 check_hsm_flags $f.append "0x00000003"
712 # Modify a file sets it dirty
713 cp -p /etc/passwd $f.modify || error "could not create file"
714 $LFS hsm_set --exists $f.modify ||
715 error "user could not change hsm flags"
716 dd if=/dev/zero of=$f.modify bs=1 count=3\
717 conv=notrunc status=noxfer ||
718 error "could not modify test file"
719 check_hsm_flags $f.modify "0x00000003"
721 # Open O_TRUNC sets dirty
722 cp -p /etc/passwd $f.trunc || error "could not create file"
723 $LFS hsm_set --exists $f.trunc ||
724 error "user could not change hsm flags"
725 cp /etc/group $f.trunc || error "could not override a file"
726 check_hsm_flags $f.trunc "0x00000003"
728 # Mmapped a file sets dirty
729 cp -p /etc/passwd $f.mmap || error "could not create file"
730 $LFS hsm_set --exists $f.mmap ||
731 error "user could not change hsm flags"
732 multiop $f.mmap OSMWUc || error "could not mmap a file"
733 check_hsm_flags $f.mmap "0x00000003"
735 run_test 3 "Check file dirtyness when opening for write"
739 local f=$DIR/$tdir/$tfile
740 local fid=$(make_small $f)
743 local st=$(get_request_state $fid CANCEL)
744 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
746 run_test 4 "Useless cancel must not be registered"
749 # test needs a running copytool
753 local f=$DIR/$tdir/$tfile
754 local fid=$(copy_file /etc/passwd $f)
756 wait_request_state $fid ARCHIVE SUCCEED
758 check_hsm_flags $f "0x00000009"
762 run_test 8 "Test default archive number"
766 local f=$DIR/$tdir/$tfile
767 local fid=$(copy_file /etc/passwd $f)
768 # we do not use the default one to be sure
769 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
771 copytool_setup $SINGLEAGT $MOUNT $new_an
772 $LFS hsm_archive --archive $new_an $f
773 wait_request_state $fid ARCHIVE SUCCEED
775 check_hsm_flags $f "0x00000009"
779 run_test 9 "Use of explict archive number, with dedicated copytool"
782 needclients 3 || return 0
788 copytool_cleanup $(comma_list $(agts_nodes))
790 # start all of the copytools
791 for n in $(seq $AGTCOUNT); do
795 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
798 for n in $(seq $AGTCOUNT); do
799 file=$DIR/$tdir/$tfile.$n
800 fid=$(make_small $file)
802 $LFS hsm_archive $file || error "could not archive file $file"
803 wait_request_state $fid ARCHIVE SUCCEED
804 check_hsm_flags $file "0x00000009"
808 copytool_cleanup $(comma_list $(agts_nodes))
810 run_test 9a "Multiple remote agents"
813 # test needs a running copytool
816 mkdir -p $DIR/$tdir/d1
817 local f=$DIR/$tdir/$tfile
818 local fid=$(copy_file /etc/hosts $f)
819 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
820 error "hsm_archive failed"
821 wait_request_state $fid ARCHIVE SUCCEED
823 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
824 error "fid $fid not in archive $HSM_ARCHIVE"
825 echo "Verifying content"
826 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
827 echo "Verifying hsm state "
828 check_hsm_flags $f "0x00000009"
830 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
831 local st=$(get_hsm_archive_id $f)
832 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
833 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
838 run_test 10a "Archive a file"
841 # test needs a running copytool
845 local f=$DIR/$tdir/$tfile
846 local fid=$(copy_file /etc/hosts $f)
847 $LFS hsm_archive $f || error "archive request failed"
848 wait_request_state $fid ARCHIVE SUCCEED
850 $LFS hsm_archive $f || error "archive of non dirty file failed"
851 local cnt=$(get_request_count $fid ARCHIVE)
852 [[ "$cnt" == "1" ]] ||
853 error "archive of non dirty file must not make a request"
857 run_test 10b "Archive of non dirty file must work without doing request"
860 # test needs a running copytool
864 local f=$DIR/$tdir/$tfile
865 local fid=$(copy_file /etc/hosts $f)
866 $LFS hsm_set --noarchive $f
867 $LFS hsm_archive $f && error "archive a noarchive file must fail"
871 run_test 10c "Check forbidden archive"
874 # test needs a running copytool
878 local f=$DIR/$tdir/$tfile
879 local fid=$(copy_file /etc/hosts $f)
880 $LFS hsm_archive $f || error "cannot archive $f"
881 wait_request_state $fid ARCHIVE SUCCEED
883 local ar=$(get_hsm_archive_id $f)
884 local dflt=$(get_hsm_param default_archive_id)
885 [[ $ar == $dflt ]] ||
886 error "archived file is not on default archive: $ar != $dflt"
890 run_test 10d "Archive a file on the default archive id"
894 copy2archive /etc/hosts $tdir/$tfile
895 local f=$DIR/$tdir/$tfile
897 import_file $tdir/$tfile $f
898 echo -n "Verifying released state: "
899 check_hsm_flags $f "0x0000000d"
901 local LSZ=$(stat -c "%s" $f)
902 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
904 echo "Verifying imported size $LSZ=$ASZ"
905 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
906 echo -n "Verifying released pattern: "
907 local PTRN=$($GETSTRIPE -L $f)
909 [[ $PTRN == 80000001 ]] || error "Is not released"
910 local fid=$(path2fid $f)
911 echo "Verifying new fid $fid in archive"
913 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
914 error "fid $fid not in archive $HSM_ARCHIVE"
916 run_test 11 "Import a file"
919 # test needs a running copytool
923 copy2archive /etc/hosts $tdir/$tfile
925 local f=$DIR/$tdir/$tfile
926 import_file $tdir/$tfile $f
927 local f=$DIR2/$tdir/$tfile
928 echo "Verifying released state: "
929 check_hsm_flags $f "0x0000000d"
931 local fid=$(path2fid $f)
933 wait_request_state $fid RESTORE SUCCEED
935 echo "Verifying file state: "
936 check_hsm_flags $f "0x00000009"
938 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
940 [[ $? -eq 0 ]] || error "Restored file differs"
944 run_test 12a "Restore an imported file explicitly"
947 # test needs a running copytool
951 copy2archive /etc/hosts $tdir/$tfile
953 local f=$DIR/$tdir/$tfile
954 import_file $tdir/$tfile $f
955 echo "Verifying released state: "
956 check_hsm_flags $f "0x0000000d"
958 cat $f > /dev/null || error "File read failed"
960 echo "Verifying file state after restore: "
961 check_hsm_flags $f "0x00000009"
963 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
965 [[ $? -eq 0 ]] || error "Restored file differs"
969 run_test 12b "Restore an imported file implicitly"
972 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
974 # test needs a running copytool
978 local f=$DIR/$tdir/$tfile
979 $LFS setstripe -c 2 $f
980 local fid=$(make_large_for_striping $f)
981 local FILE_CRC=$(md5sum $f)
983 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
984 wait_request_state $fid ARCHIVE SUCCEED
985 $LFS hsm_release $f || error "release $f failed"
987 echo "$FILE_CRC" | md5sum -c
989 [[ $? -eq 0 ]] || error "Restored file differs"
993 run_test 12c "Restore a file with stripe of 2"
996 # test needs a running copytool
1001 local f=$DIR/$tdir/$tfile
1002 local fid=$(copy_file /etc/hosts $f)
1003 $LFS hsm_restore $f || error "restore of non archived file failed"
1004 local cnt=$(get_request_count $fid RESTORE)
1005 [[ "$cnt" == "0" ]] ||
1006 error "restore non archived must not make a request"
1007 $LFS hsm_archive $f ||
1008 error "archive request failed"
1009 wait_request_state $fid ARCHIVE SUCCEED
1010 $LFS hsm_restore $f ||
1011 error "restore of non released file failed"
1012 local cnt=$(get_request_count $fid RESTORE)
1013 [[ "$cnt" == "0" ]] ||
1014 error "restore a non dirty file must not make a request"
1018 run_test 12d "Restore of a non archived, non released file must work"\
1019 " without doing request"
1022 # test needs a running copytool
1025 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1026 local f=$DIR/$tdir/$tfile
1027 local fid=$(copy_file /etc/hosts $f)
1028 $LFS hsm_archive $f || error "archive request failed"
1029 wait_request_state $fid ARCHIVE SUCCEED
1032 cat /etc/hosts >> $f
1036 $LFS hsm_restore $f && error "restore a dirty file must fail"
1040 run_test 12e "Check forbidden restore"
1043 # test needs a running copytool
1047 local f=$DIR/$tdir/$tfile
1048 local fid=$(copy_file /etc/hosts $f)
1050 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1051 wait_request_state $fid ARCHIVE SUCCEED
1052 $LFS hsm_release $f || error "release of $f failed"
1054 wait_request_state $fid RESTORE SUCCEED
1056 echo -n "Verifying file state: "
1057 check_hsm_flags $f "0x00000009"
1059 diff -q /etc/hosts $f
1061 [[ $? -eq 0 ]] || error "Restored file differs"
1065 run_test 12f "Restore a released file explicitly"
1068 # test needs a running copytool
1072 local f=$DIR/$tdir/$tfile
1073 local fid=$(copy_file /etc/hosts $f)
1075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1076 wait_request_state $fid ARCHIVE SUCCEED
1077 $LFS hsm_release $f || error "release of $f failed"
1079 diff -q /etc/hosts $f
1082 # we check we had a restore done
1083 wait_request_state $fid RESTORE SUCCEED
1085 [[ $st -eq 0 ]] || error "Restored file differs"
1089 run_test 12g "Restore a released file implicitly"
1092 needclients 2 || return 0
1094 # test needs a running copytool
1098 local f=$DIR/$tdir/$tfile
1099 local fid=$(copy_file /etc/hosts $f)
1101 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1102 wait_request_state $fid ARCHIVE SUCCEED
1103 $LFS hsm_release $f || error "release of $f failed"
1105 do_node $CLIENT2 diff -q /etc/hosts $f
1108 # we check we had a restore done
1109 wait_request_state $fid RESTORE SUCCEED
1111 [[ $st -eq 0 ]] || error "Restored file differs"
1115 run_test 12h "Restore a released file implicitly from a second node"
1118 # test needs a running copytool
1122 local f=$DIR/$tdir/$tfile
1123 local fid=$(copy_file /etc/passwd $f)
1124 $LFS hsm_archive $f || error "archive of $f failed"
1125 wait_request_state $fid ARCHIVE SUCCEED
1127 $LFS hsm_release $f || error "release of $f failed"
1131 [[ $? -eq 0 ]] || error "Restored file differs"
1135 run_test 12m "Archive/release/implicit restore"
1138 # test needs a running copytool
1142 copy2archive /etc/hosts $tdir/$tfile
1144 local f=$DIR/$tdir/$tfile
1145 import_file $tdir/$tfile $f
1147 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1148 error "Restored file differs"
1150 $LFS hsm_release $f || error "release of $f failed"
1154 run_test 12n "Import/implicit restore/release"
1157 # test needs a running copytool
1160 local ARC_SUBDIR="import.orig"
1164 # populate directory to be imported
1165 for d in $(seq 1 10); do
1166 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1167 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1168 for f in $(seq 1 10); do
1169 CURR_FILE="$CURR_DIR/$tfile.$f"
1170 # write file-specific data
1171 do_facet $SINGLEAGT \
1172 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1173 "file=$CURR_FILE > $CURR_FILE"
1177 import_file "$ARC_SUBDIR" $DIR/$tdir
1178 # diff lustre content and origin (triggers file restoration)
1179 # there must be 10x10 identical files, and no difference
1180 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1181 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1182 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1183 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1185 [ $cnt_diff -eq 0 ] ||
1186 error "$cnt_diff imported files differ from read data"
1187 [ $cnt_ok -eq 100 ] ||
1188 error "not enough identical files ($cnt_ok != 100)"
1192 run_test 13 "Recursively import and restore a directory"
1195 # test needs a running copytool
1200 local f=$DIR/$tdir/$tfile
1201 local fid=$(make_small $f)
1202 local sum=$(md5sum $f | awk '{print $1}')
1203 $LFS hsm_archive $f || error "could not archive file"
1204 wait_request_state $fid ARCHIVE SUCCEED
1208 # create released file (simulate llapi_hsm_import call)
1210 local fid2=$(path2fid $f)
1211 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1212 $LFS hsm_release $f || error "could not release file"
1214 # rebind the archive to the newly created file
1215 echo "rebind $fid to $fid2"
1217 do_facet $SINGLEAGT \
1218 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1219 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1221 # restore file and compare md5sum
1222 local sum2=$(md5sum $f | awk '{print $1}')
1224 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1228 run_test 14 "Rebind archived file to a new fid"
1231 # test needs a running copytool
1236 local f=$DIR/$tdir/$tfile
1238 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1242 for i in $(seq 1 $count); do
1243 fids[$i]=$(make_small $f.$i)
1244 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1245 $LFS hsm_archive $f.$i || error "could not archive file"
1247 wait_all_done $(($count*60))
1251 for i in $(seq 1 $count); do
1254 local fid2=$(path2fid $f.$i)
1255 # add the rebind operation to the list
1256 echo ${fids[$i]} $fid2 >> $tmpfile
1258 # set it released (simulate llapi_hsm_import call)
1259 $LFS hsm_set --archived --exists $f.$i ||
1260 error "could not force hsm flags"
1261 $LFS hsm_release $f.$i || error "could not release file"
1263 nl=$(wc -l < $tmpfile)
1264 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1266 echo "rebind list of files"
1267 do_facet $SINGLEAGT \
1268 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1269 --rebind $tmpfile $DIR" || error "could not rebind file list"
1271 # restore files and compare md5sum
1272 for i in $(seq 1 $count); do
1273 local sum2=$(md5sum $f.$i | awk '{print $1}')
1274 [[ $sum2 == ${sums[$i]} ]] ||
1275 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1281 run_test 15 "Rebind a list of files"
1284 # test needs a running copytool
1288 # create a known size file so we can verify transfer speed
1291 dd if=/dev/zero of=$ref bs=1M count=20
1294 local f=$DIR/$tdir/$tfile
1295 local fid=$(copy_file $ref $f)
1297 local start=$(date +%s)
1299 wait_request_state $fid ARCHIVE SUCCEED
1300 local end=$(date +%s)
1301 local duration=$((end - start))
1303 [[ $duration -ge $goal ]] ||
1304 error "Transfer is too fast $duration < $goal"
1308 run_test 16 "Test CT bandwith control option"
1313 local f=$DIR/$tdir/$tfile
1314 touch $f || error "touch $f failed"
1316 # Could not release a non-archived file
1317 $LFS hsm_release $f && error "release should not succeed"
1319 # For following tests, we must test them with HS_ARCHIVED set
1320 $LFS hsm_set --exists --archived $f || error "could not add flag"
1322 # Could not release a file if no-release is set
1323 $LFS hsm_set --norelease $f || error "could not add flag"
1324 $LFS hsm_release $f && error "release should not succeed"
1325 $LFS hsm_clear --norelease $f || error "could not remove flag"
1327 # Could not release a file if lost
1328 $LFS hsm_set --lost $f || error "could not add flag"
1329 $LFS hsm_release $f && error "release should not succeed"
1330 $LFS hsm_clear --lost $f || error "could not remove flag"
1332 # Could not release a file if dirty
1333 $LFS hsm_set --dirty $f || error "could not add flag"
1334 $LFS hsm_release $f && error "release should not succeed"
1335 $LFS hsm_clear --dirty $f || error "could not remove flag"
1337 run_test 20 "Release is not permitted"
1340 # test needs a running copytool
1344 local f=$DIR/$tdir/test_release
1346 # Create a file and check its states
1347 local fid=$(make_small $f)
1348 check_hsm_flags $f "0x00000000"
1350 local orig_size=$(stat -c "%s" $f)
1351 local orig_blocks=$(stat -c "%b" $f)
1353 start_full_debug_logging
1355 $LFS hsm_archive $f || error "could not archive file"
1356 wait_request_state $fid ARCHIVE SUCCEED
1358 local blocks=$(stat -c "%b" $f)
1359 [ $blocks -eq $orig_blocks ] ||
1360 error "$f: wrong block number after archive: " \
1361 "$blocks != $orig_blocks"
1362 local size=$(stat -c "%s" $f)
1363 [ $size -eq $orig_size ] ||
1364 error "$f: wrong size after archive: $size != $orig_size"
1366 # Release and check states
1367 $LFS hsm_release $f || error "could not release file"
1368 check_hsm_flags $f "0x0000000d"
1370 blocks=$(stat -c "%b" $f)
1371 [ $blocks -gt 5 ] &&
1372 error "$f: too many blocks after release: $blocks > 5"
1373 size=$(stat -c "%s" $f)
1374 [ $size -ne $orig_size ] &&
1375 error "$f: wrong size after release: $size != $orig_size"
1377 # Check we can release an file without stripe info
1381 check_hsm_flags $f "0x00000000"
1382 $LFS hsm_archive $f || error "could not archive file"
1383 wait_request_state $fid ARCHIVE SUCCEED
1385 # Release and check states
1386 $LFS hsm_release $f || error "could not release file"
1387 check_hsm_flags $f "0x0000000d"
1389 # Release again a file that is already released is OK
1390 $LFS hsm_release $f || fail "second release should succeed"
1391 check_hsm_flags $f "0x0000000d"
1393 stop_full_debug_logging
1397 run_test 21 "Simple release tests"
1400 # test needs a running copytool
1405 local f=$DIR/$tdir/test_release
1406 local swap=$DIR/$tdir/test_swap
1408 # Create a file and check its states
1409 local fid=$(make_small $f)
1410 check_hsm_flags $f "0x00000000"
1412 $LFS hsm_archive $f || error "could not archive file"
1413 wait_request_state $fid ARCHIVE SUCCEED
1415 # Release and check states
1416 $LFS hsm_release $f || error "could not release file"
1417 check_hsm_flags $f "0x0000000d"
1420 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1425 run_test 22 "Could not swap a release file"
1428 # test needs a running copytool
1433 local f=$DIR/$tdir/test_mtime
1435 # Create a file and check its states
1436 local fid=$(make_small $f)
1437 check_hsm_flags $f "0x00000000"
1439 $LFS hsm_archive $f || error "could not archive file"
1440 wait_request_state $fid ARCHIVE SUCCEED
1442 # Set modification time in the past
1443 touch -m -a -d @978261179 $f
1445 # Release and check states
1446 $LFS hsm_release $f || error "could not release file"
1447 check_hsm_flags $f "0x0000000d"
1449 local MTIME=$(stat -c "%Y" $f)
1450 local ATIME=$(stat -c "%X" $f)
1451 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1452 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1456 run_test 23 "Release does not change a/mtime (utime)"
1459 local file=$DIR/$tdir/$tfile
1468 # test needs a running copytool
1473 fid=$(make_small $file)
1475 # Create a file and check its states
1476 check_hsm_flags $file "0x00000000"
1478 # Ensure atime is less than mtime and ctime.
1482 atime0=$(stat -c "%X" $file)
1483 mtime0=$(stat -c "%Y" $file)
1484 ctime0=$(stat -c "%Z" $file)
1486 [ $atime0 -lt $mtime0 ] ||
1487 error "atime $atime0 is not less than mtime $mtime0"
1489 [ $atime0 -lt $ctime0 ] ||
1490 error "atime $atime0 is not less than ctime $ctime0"
1492 # Archive should not change any timestamps.
1493 $LFS hsm_archive $file || error "cannot archive '$file'"
1494 wait_request_state $fid ARCHIVE SUCCEED
1496 atime1=$(stat -c "%X" $file)
1497 mtime1=$(stat -c "%Y" $file)
1498 ctime1=$(stat -c "%Z" $file)
1500 [ $atime0 -eq $atime1 ] ||
1501 error "archive changed atime from $atime0 to $atime1"
1503 [ $mtime0 -eq $mtime1 ] ||
1504 error "archive changed mtime from $mtime0 to $mtime1"
1506 [ $ctime0 -eq $ctime1 ] ||
1507 error "archive changed ctime from $ctime0 to $ctime1"
1509 # Release should not change any timestamps.
1510 $LFS hsm_release $file || error "cannot release '$file'"
1511 check_hsm_flags $file "0x0000000d"
1513 atime1=$(stat -c "%X" $file)
1514 mtime1=$(stat -c "%Y" $file)
1515 ctime1=$(stat -c "%Z" $file)
1517 [ $atime0 -eq $atime1 ] ||
1518 error "release changed atime from $atime0 to $atime1"
1520 [ $mtime0 -eq $mtime1 ] ||
1521 error "release changed mtime from $mtime0 to $mtime1"
1523 [ $ctime0 -eq $ctime1 ] ||
1524 error "release changed ctime from $ctime0 to $ctime1"
1526 # Restore should not change atime or mtime and should not
1528 $LFS hsm_restore $file
1529 wait_request_state $fid RESTORE SUCCEED
1531 atime1=$(stat -c "%X" $file)
1532 mtime1=$(stat -c "%Y" $file)
1533 ctime1=$(stat -c "%Z" $file)
1535 [ $atime0 -eq $atime1 ] ||
1536 error "restore changed atime from $atime0 to $atime1"
1538 [ $mtime0 -eq $mtime1 ] ||
1539 error "restore changed mtime from $mtime0 to $mtime1"
1541 [ $ctime0 -le $ctime1 ] ||
1542 error "restore changed ctime from $ctime0 to $ctime1"
1546 # Once more, after unmount and mount.
1547 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1548 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1550 atime1=$(stat -c "%X" $file)
1551 mtime1=$(stat -c "%Y" $file)
1552 ctime1=$(stat -c "%Z" $file)
1554 [ $atime0 -eq $atime1 ] ||
1555 error "remount changed atime from $atime0 to $atime1"
1557 [ $mtime0 -eq $mtime1 ] ||
1558 error "remount changed mtime from $mtime0 to $mtime1"
1560 [ $ctime0 -le $ctime1 ] ||
1561 error "remount changed ctime from $ctime0 to $ctime1"
1563 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1566 local file=$DIR/$tdir/$tfile
1572 # Test needs a running copytool.
1576 # Check that root can do HSM actions on a ordinary user's file.
1578 fid=$(make_small $file)
1579 sum0=$(md5sum $file)
1581 chown $RUNAS_ID:$RUNAS_GID $file ||
1582 error "cannot chown '$file' to '$RUNAS_ID'"
1584 chmod ugo-w $DIR/$tdir ||
1585 error "cannot chmod '$DIR/$tdir'"
1587 $LFS hsm_archive $file
1588 wait_request_state $fid ARCHIVE SUCCEED
1590 $LFS hsm_release $file
1591 check_hsm_flags $file "0x0000000d"
1593 $LFS hsm_restore $file
1594 wait_request_state $fid RESTORE SUCCEED
1596 # Check that ordinary user can get HSM state.
1597 $RUNAS $LFS hsm_state $file ||
1598 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1600 $LFS hsm_release $file
1601 check_hsm_flags $file "0x0000000d"
1603 # Check that ordinary user can accessed released file.
1604 sum1=$($RUNAS md5sum $file) ||
1605 error "user '$RUNAS_ID' cannot read '$file'"
1607 [ "$sum0" == "$sum1" ] ||
1608 error "md5sum mismatch for '$file'"
1612 run_test 24b "root can archive, release, and restore user files"
1614 cleanup_test_24c() {
1616 set_hsm_param user_request_mask RESTORE
1617 set_hsm_param group_request_mask RESTORE
1618 set_hsm_param other_request_mask RESTORE
1622 local file=$DIR/$tdir/$tfile
1623 local action=archive
1628 # test needs a running copytool
1633 # Save the default masks and check that cleanup_24c will
1634 # restore the request masks correctly.
1635 user_save=$(get_hsm_param user_request_mask)
1636 group_save=$(get_hsm_param group_request_mask)
1637 other_save=$(get_hsm_param other_request_mask)
1639 [ "$user_save" == RESTORE ] ||
1640 error "user_request_mask is '$user_save' expected 'RESTORE'"
1641 [ "$group_save" == RESTORE ] ||
1642 error "group_request_mask is '$group_save' expected 'RESTORE'"
1643 [ "$other_save" == RESTORE ] ||
1644 error "other_request_mask is '$other_save' expected 'RESTORE'"
1646 trap cleanup_test_24c EXIT
1651 chown $RUNAS_ID:nobody $file ||
1652 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1654 set_hsm_param user_request_mask ""
1655 $RUNAS $LFS hsm_$action $file &&
1656 error "$action by user should fail"
1658 set_hsm_param user_request_mask $action
1659 $RUNAS $LFS hsm_$action $file ||
1660 error "$action by user should succeed"
1665 chown nobody:$RUNAS_GID $file ||
1666 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1668 set_hsm_param group_request_mask ""
1669 $RUNAS $LFS hsm_$action $file &&
1670 error "$action by group should fail"
1672 set_hsm_param group_request_mask $action
1673 $RUNAS $LFS hsm_$action $file ||
1674 error "$action by group should succeed"
1679 chown nobody:nobody $file ||
1680 error "cannot chown '$file' to 'nobody:nobody'"
1682 set_hsm_param other_request_mask ""
1683 $RUNAS $LFS hsm_$action $file &&
1684 error "$action by other should fail"
1686 set_hsm_param other_request_mask $action
1687 $RUNAS $LFS hsm_$action $file ||
1688 error "$action by other should succeed"
1693 run_test 24c "check that user,group,other request masks work"
1695 cleanup_test_24d() {
1697 mount -o remount,rw $MOUNT2
1701 local file1=$DIR/$tdir/$tfile
1702 local file2=$DIR2/$tdir/$tfile
1710 fid1=$(make_small $file1)
1712 trap cleanup_test_24d EXIT
1714 mount -o remount,ro $MOUNT2
1716 fid2=$(path2fid $file2)
1717 [ "$fid1" == "$fid2" ] ||
1718 error "FID mismatch '$fid1' != '$fid2'"
1720 $LFS hsm_archive $file2 &&
1721 error "archive should fail on read-only mount"
1722 check_hsm_flags $file1 "0x00000000"
1724 $LFS hsm_archive $file1
1725 wait_request_state $fid1 ARCHIVE SUCCEED
1727 $LFS hsm_release $file1
1728 $LFS hsm_restore $file2
1729 wait_request_state $fid1 RESTORE SUCCEED
1731 $LFS hsm_release $file1 || error "cannot release '$file1'"
1732 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1734 $LFS hsm_release $file2 &&
1735 error "release should fail on read-only mount"
1740 run_test 24d "check that read-only mounts are respected"
1743 # test needs a running copytool
1747 copy2archive /etc/hosts $tdir/$tfile
1749 local f=$DIR/$tdir/$tfile
1751 import_file $tdir/$tfile $f
1753 $LFS hsm_set --lost $f
1758 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1762 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1763 " (Operation not permitted)"
1766 # test needs a running copytool
1771 local f=$DIR/$tdir/$tfile
1772 local fid=$(copy_file /etc/passwd $f)
1774 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1775 wait_request_state $fid ARCHIVE SUCCEED
1778 $LFS hsm_set --lost $f
1782 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1786 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1787 " (Operation not permitted)"
1790 # test needs a running copytool
1794 local f=$DIR/$tdir/$tfile
1795 local fid=$(make_large_for_progress $f)
1796 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1797 wait_request_state $fid ARCHIVE SUCCEED
1800 wait_request_state $fid REMOVE SUCCEED
1802 check_hsm_flags $f "0x00000000"
1806 run_test 26 "Remove the archive of a valid file"
1809 # test needs a running copytool
1813 make_archive $tdir/$tfile
1814 local f=$DIR/$tdir/$tfile
1815 import_file $tdir/$tfile $f
1816 local fid=$(path2fid $f)
1820 [[ $? != 0 ]] || error "Remove of a released file should fail"
1824 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1827 # test needs a running copytool
1831 local f=$DIR/$tdir/$tfile
1832 local fid=$(make_large_for_progress $f)
1833 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1834 wait_request_state $fid ARCHIVE SUCCEED
1839 [[ $? != 0 ]] || error "Remove of a released file should fail"
1843 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1846 # test needs a running copytool
1850 local f=$DIR/$tdir/$tfile
1851 local fid=$(make_large_for_progress $f)
1852 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1853 wait_request_state $fid ARCHIVE SUCCEED
1862 wait_request_state $fid REMOVE SUCCEED
1866 run_test 28 "Concurrent archive/file remove"
1869 # restore at exec cannot work on agent node (because of Linux kernel
1870 # protection of executables)
1871 needclients 2 || return 0
1873 # test needs a running copytool
1877 copy2archive /bin/true $tdir/$tfile
1879 local f=$DIR/$tdir/true
1880 import_file $tdir/$tfile $f
1882 local fid=$(path2fid $f)
1884 # set no retry action mode
1890 # remove no try action mode
1894 [[ $st == 0 ]] || error "Failed to exec a released file"
1898 run_test 30a "Restore at exec (import case)"
1901 # restore at exec cannot work on agent node (because of Linux kernel
1902 # protection of executables)
1903 needclients 2 || return 0
1905 # test needs a running copytool
1909 local f=$DIR/$tdir/true
1910 local fid=$(copy_file /bin/true $f)
1912 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1913 wait_request_state $fid ARCHIVE SUCCEED
1916 # set no retry action mode
1922 # remove no try action mode
1926 [[ $st == 0 ]] || error "Failed to exec a released file"
1930 run_test 30b "Restore at exec (release case)"
1933 needclients 2 || return 0
1935 # test needs a running copytool
1939 local f=$DIR/$tdir/SLEEP
1940 local fid=$(copy_file /bin/sleep $f)
1942 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1943 wait_request_state $fid ARCHIVE SUCCEED
1945 check_hsm_flags $f "0x0000000d"
1946 # set no retry action mode
1948 do_node $CLIENT2 "$f 10" &
1952 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1954 [[ $? == 0 ]] || error "Execution failed during run"
1956 [[ $? == 0 ]] || error "Binary overwritten during exec"
1959 # remove no try action mode
1961 check_hsm_flags $f "0x00000009"
1965 run_test 30c "Update during exec of released file must fail"
1967 restore_and_check_size() {
1970 local s=$(stat -c "%s" $f)
1972 local st=$(get_hsm_flags $f)
1976 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1978 n=$(stat -c "%s" $f)
1979 # we echo in both cases to show stat is not
1981 if [[ $n != $s ]]; then
1982 echo "size seen is $n != $s"
1985 echo "size seen is right: $n == $s"
1987 st=$(get_hsm_flags $f)
1991 if [[ $cpt -lt 10 ]]; then
1994 echo " restore is too long"
1995 wait_request_state $fid RESTORE SUCCEED
2001 # test needs a running copytool
2006 make_archive $tdir/$tfile
2007 local f=$DIR/$tdir/$tfile
2008 import_file $tdir/$tfile $f
2009 local fid=$($LFS path2fid $f)
2010 HSM_ARCHIVE_PURGE=false copytool_setup
2012 restore_and_check_size $f $fid
2015 [[ $err -eq 0 ]] || error "File size changed during restore"
2019 run_test 31a "Import a large file and check size during restore"
2023 # test needs a running copytool
2028 local f=$DIR/$tdir/$tfile
2029 local fid=$(make_large_for_progress $f)
2030 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2031 wait_request_state $fid ARCHIVE SUCCEED
2034 restore_and_check_size $f $fid
2037 [[ $err -eq 0 ]] || error "File size changed during restore"
2041 run_test 31b "Restore a large unaligned file and check size during restore"
2044 # test needs a running copytool
2049 local f=$DIR/$tdir/$tfile
2050 local fid=$(make_large_for_progress_aligned $f)
2051 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2052 wait_request_state $fid ARCHIVE SUCCEED
2055 restore_and_check_size $f $fid
2058 [[ $err -eq 0 ]] || error "File size changed during restore"
2062 run_test 31c "Restore a large aligned file and check size during restore"
2065 # test needs a running copytool
2070 local f=$DIR/$tdir/$tfile
2071 local fid=$(make_large_for_progress $f)
2072 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2073 wait_request_state $fid ARCHIVE SUCCEED
2076 md5sum $f >/dev/null &
2078 wait_request_state $fid RESTORE STARTED
2083 # Check restore trigger process was killed
2084 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2088 wait_request_state $fid RESTORE CANCELED
2089 wait_request_state $fid CANCEL SUCCEED
2092 error "Cannot kill process waiting for restore ($killed)"
2096 run_test 33 "Kill a restore waiting process"
2099 # test needs a running copytool
2104 local f=$DIR/$tdir/$tfile
2105 local fid=$(make_large_for_progress $f)
2106 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2107 wait_request_state $fid ARCHIVE SUCCEED
2110 md5sum $f >/dev/null &
2112 wait_request_state $fid RESTORE STARTED
2114 rm $f || error "rm $f failed"
2115 # rm must not block during restore
2116 wait_request_state $fid RESTORE STARTED
2118 wait_request_state $fid RESTORE SUCCEED
2119 # check md5sum pgm finished
2120 local there=$(ps -o pid,comm hp $pid >/dev/null)
2121 [[ -z $there ]] || error "Restore initiator does not exit"
2123 local rc=$(wait $pid)
2124 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2128 run_test 34 "Remove file during restore"
2131 # test needs a running copytool
2136 local f=$DIR/$tdir/$tfile
2137 local f1=$DIR/$tdir/$tfile-1
2138 local fid=$(make_large_for_progress $f)
2139 local fid1=$(copy_file /etc/passwd $f1)
2140 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2141 wait_request_state $fid ARCHIVE SUCCEED
2144 md5sum $f >/dev/null &
2146 wait_request_state $fid RESTORE STARTED
2148 mv $f1 $f || error "mv $f1 $f failed"
2149 # mv must not block during restore
2150 wait_request_state $fid RESTORE STARTED
2152 wait_request_state $fid RESTORE SUCCEED
2153 # check md5sum pgm finished
2154 local there=$(ps -o pid,comm hp $pid >/dev/null)
2155 [[ -z $there ]] || error "Restore initiator does not exit"
2157 local rc=$(wait $pid)
2158 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2161 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2165 run_test 35 "Overwrite file during restore"
2168 # test needs a running copytool
2173 local f=$DIR/$tdir/$tfile
2174 local fid=$(make_large_for_progress $f)
2175 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2176 wait_request_state $fid ARCHIVE SUCCEED
2179 md5sum $f >/dev/null &
2181 wait_request_state $fid RESTORE STARTED
2184 # rm must not block during restore
2185 wait_request_state $fid RESTORE STARTED
2187 wait_request_state $fid RESTORE SUCCEED
2188 # check md5sum pgm finished
2189 local there=$(ps -o pid,comm hp $pid >/dev/null)
2191 error "Restore initiator does not exit"
2193 local rc=$(wait $pid)
2195 error "Restore initiator failed with $rc"
2199 run_test 36 "Move file during restore"
2206 for n in $(seq 1 $count); do
2207 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2209 echo "$count archive requests submitted"
2213 local stream_count=4
2214 local file_count=100
2216 local f=$DIR/$tdir/$tfile
2221 for i in $(seq 1 $file_count); do
2222 for p in $(seq 1 $stream_count); do
2223 fid=$(copy_file /etc/hosts $f.$p.$i)
2227 # to be sure wait_all_done will not be mislead by previous tests
2229 wait_for_grace_delay
2231 # start archive streams in background (archive files in parallel)
2232 for p in $(seq 1 $stream_count); do
2233 multi_archive $f.$p $file_count &
2236 echo -n "Wait for all requests being enqueued..."
2242 run_test 40 "Parallel archive requests"
2245 # test needs a running copytool
2249 local f=$DIR/$tdir/$tfile
2250 local fid=$(copy_file /etc/motd $f 1)
2252 $LFS hsm_archive $f || error "could not archive file"
2253 wait_request_state $fid ARCHIVE SUCCEED
2254 check_hsm_flags $f "0x00000009"
2256 multiop_bg_pause $f O_c || error "multiop failed"
2260 client_up || client_up || true
2262 kill -USR1 $MULTIPID
2263 wait $MULTIPID || error "multiop close failed"
2265 check_hsm_flags $f "0x0000000b"
2269 run_test 52 "Opened for write file on an evicted client should be set dirty"
2272 # test needs a running copytool
2276 local f=$DIR/$tdir/$tfile
2277 local fid=$(copy_file /etc/motd $f 1)
2279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2280 error "could not archive file"
2281 wait_request_state $fid ARCHIVE SUCCEED
2282 check_hsm_flags $f "0x00000009"
2284 multiop_bg_pause $f o_c || error "multiop failed"
2288 client_up || client_up || true
2290 kill -USR1 $MULTIPID
2291 wait $MULTIPID || error "multiop close failed"
2293 check_hsm_flags $f "0x00000009"
2297 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2300 # test needs a running copytool
2304 local f=$DIR/$tdir/$tfile
2305 local fid=$(make_small $f)
2307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2308 error "could not archive file"
2309 wait_request_state $fid ARCHIVE STARTED
2311 check_hsm_flags $f "0x00000001"
2313 # Avoid coordinator resending this request as soon it has failed.
2318 wait_request_state $fid ARCHIVE FAILED
2320 check_hsm_flags $f "0x00000003"
2325 run_test 54 "Write during an archive cancels it"
2328 # test needs a running copytool
2332 local f=$DIR/$tdir/$tfile
2333 local fid=$(make_small $f)
2335 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2336 error "could not archive file"
2337 wait_request_state $fid ARCHIVE STARTED
2339 check_hsm_flags $f "0x00000001"
2341 # Avoid coordinator resending this request as soon it has failed.
2344 $TRUNCATE $f 1024 || error "truncate failed"
2346 wait_request_state $fid ARCHIVE FAILED
2348 check_hsm_flags $f "0x00000003"
2353 run_test 55 "Truncate during an archive cancels it"
2356 # test needs a running copytool
2360 local f=$DIR/$tdir/$tfile
2361 local fid=$(make_large_for_progress $f)
2363 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2364 error "could not archive file"
2365 wait_request_state $fid ARCHIVE STARTED
2367 check_hsm_flags $f "0x00000001"
2369 # Change metadata and sync to be sure we are not changing only
2374 wait_request_state $fid ARCHIVE SUCCEED
2376 check_hsm_flags $f "0x00000009"
2380 run_test 56 "Setattr during an archive is ok"
2383 # Need one client for I/O, one for request
2384 needclients 2 || return 0
2386 # test needs a running copytool
2390 local f=$DIR/$tdir/test_archive_remote
2391 # Create a file on a remote node
2392 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2393 "count=2 conv=fsync"
2396 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2397 error "hsm_archive failed"
2398 local fid=$(path2fid $f)
2399 wait_request_state $fid ARCHIVE SUCCEED
2401 # Release and implicit restore it
2402 do_node $CLIENT2 "$LFS hsm_release $f" ||
2403 error "hsm_release failed"
2404 do_node $CLIENT2 "md5sum $f" ||
2405 error "hsm_restore failed"
2407 wait_request_state $fid RESTORE SUCCEED
2411 run_test 57 "Archive a file with dirty cache on another node"
2413 truncate_released_file() {
2417 local sz=$(stat -c %s $src_file)
2418 local f=$DIR/$tdir/$tfile
2419 local fid=$(copy_file $1 $f)
2423 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2424 error "could not archive file"
2425 wait_request_state $fid ARCHIVE SUCCEED
2427 $LFS hsm_release $f || error "could not release file"
2429 $TRUNCATE $f $trunc_to || error "truncate failed"
2432 local sz1=$(stat -c %s $f)
2433 [[ $sz1 == $trunc_to ]] ||
2434 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2437 check_hsm_flags $f "0x0000000b"
2439 local state=$(get_request_state $fid RESTORE)
2440 [[ "$state" == "SUCCEED" ]] ||
2441 error "truncate $sz does not trig restore, state = $state"
2443 $TRUNCATE $ref $trunc_to
2444 cmp $ref $f || error "file data wrong after truncate"
2450 # test needs a running copytool
2455 local sz=$(stat -c %s /etc/passwd)
2457 echo "truncate up from $sz to $((sz*2))"
2458 truncate_released_file /etc/passwd $((sz*2))
2460 echo "truncate down from $sz to $((sz/2))"
2461 truncate_released_file /etc/passwd $((sz/2))
2463 echo "truncate to 0"
2464 truncate_released_file /etc/passwd 0
2468 run_test 58 "Truncate a released file will trigger restore"
2473 local f=$DIR/$tdir/$tfile
2474 local FILELIST=/tmp/filelist.txt
2478 for i in $(seq 1 $file_count); do
2479 fid=$(copy_file /etc/hosts $f.$i)
2480 echo $f.$i >> $FILELIST
2483 # to be sure wait_all_done will not be mislead by previous tests
2485 wait_for_grace_delay
2486 $LFS hsm_archive --filelist $FILELIST ||
2487 error "cannot archive a file list"
2489 $LFS hsm_release --filelist $FILELIST ||
2490 error "cannot release a file list"
2491 $LFS hsm_restore --filelist $FILELIST ||
2492 error "cannot restore a file list"
2496 run_test 90 "Archive/restore a file list"
2498 double_verify_reset_hsm_param() {
2500 echo "Testing $HSM_PARAM.$p"
2501 local val=$(get_hsm_param $p)
2503 local val2=$(($val * 2))
2504 set_hsm_param $p $val2
2505 val=$(get_hsm_param $p)
2506 [[ $val == $val2 ]] ||
2507 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2508 echo "Set $p to 0 must failed"
2512 set_hsm_param $p $save
2514 if [[ $rc == 0 ]]; then
2515 error "we must not be able to set $HSM_PARAM.$p to 0"
2520 double_verify_reset_hsm_param loop_period
2521 double_verify_reset_hsm_param grace_delay
2522 double_verify_reset_hsm_param active_request_timeout
2523 double_verify_reset_hsm_param max_requests
2524 double_verify_reset_hsm_param default_archive_id
2526 run_test 100 "Set coordinator /proc tunables"
2533 run_test 102 "Verify coordinator control"
2536 # test needs a running copytool
2543 for i in $(seq 1 20); do
2544 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2550 echo "Current requests"
2551 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2552 $HSM_PARAM.actions |\
2553 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2555 [[ -z "$res" ]] || error "Some request have not been canceled"
2559 run_test 103 "Purge all requests"
2564 # test needs a running copytool
2568 local f=$DIR/$tdir/$tfile
2569 local fid=$(make_large_for_progress $f)
2570 # if cdt is on, it can serve too quickly the request
2572 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2573 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2574 $HSM_PARAM.actions |\
2575 grep $fid | cut -f16 -d=")
2578 [[ "$data1" == "$DATAHEX" ]] ||
2579 error "Data field in records is ($data1) and not ($DATAHEX)"
2583 run_test 104 "Copy tool data field"
2590 for i in $(seq -w 1 10); do
2591 cp /etc/passwd $DIR/$tdir/$i
2592 $LFS hsm_archive $DIR/$tdir/$i
2594 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2595 $HSM_PARAM.actions |\
2596 grep WAITING | wc -l")
2599 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2600 $HSM_PARAM.actions |\
2601 grep WAITING | wc -l")
2604 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2605 error "Requests count after shutdown $reqcnt2 != "\
2606 "before shutdown $reqcnt1"
2608 run_test 105 "Restart of coordinator"
2610 get_agent_by_uuid_mdt() {
2613 local mds=mds$(($mdtidx + 1))
2614 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
2618 check_agent_registered_by_mdt() {
2621 local mds=mds$(($mdtidx + 1))
2622 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2623 if [[ ! -z "$agent" ]]; then
2624 echo "found agent $agent on $mds"
2626 error "uuid $uuid not found in agent list on $mds"
2630 check_agent_unregistered_by_mdt() {
2633 local mds=mds$(($mdtidx + 1))
2634 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2635 if [[ -z "$agent" ]]; then
2636 echo "uuid not found in agent list on $mds"
2638 error "uuid found in agent list on $mds: $agent"
2642 check_agent_registered() {
2645 for mdsno in $(seq 1 $MDSCOUNT); do
2646 check_agent_registered_by_mdt $uuid $((mdsno - 1))
2650 check_agent_unregistered() {
2653 for mdsno in $(seq 1 $MDSCOUNT); do
2654 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
2659 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2660 get_client_uuid $MOUNT | cut -d' ' -f2)
2663 check_agent_registered $uuid
2665 search_copytools || error "No copytool found"
2668 check_agent_unregistered $uuid
2671 check_agent_registered $uuid
2675 run_test 106 "Copytool register/unregister"
2678 # test needs a running copytool
2680 # create and archive file
2682 local f1=$DIR/$tdir/$tfile
2683 local fid=$(copy_file /etc/passwd $f1)
2684 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2685 wait_request_state $fid ARCHIVE SUCCEED
2686 # shutdown and restart MDS
2688 # check the copytool still gets messages from MDT
2689 local f2=$DIR/$tdir/2
2690 local fid=$(copy_file /etc/passwd $f2)
2691 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2692 # main check of this sanity: this request MUST succeed
2693 wait_request_state $fid ARCHIVE SUCCEED
2696 run_test 107 "Copytool re-register after MDS restart"
2698 policy_set_and_test()
2702 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2703 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2704 [[ "$policy" == "$target" ]] ||
2705 error "Wrong policy after '$change': '$policy' != '$target'"
2709 # to force default policy setting if error
2710 CDT_POLICY_HAD_CHANGED=true
2712 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2713 local default="NonBlockingRestore [NoRetryAction]"
2714 [[ "$policy" == "$default" ]] ||
2715 error "default policy has changed,"\
2716 " '$policy' != '$default' update the test"
2717 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2718 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2719 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2720 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2721 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2722 # useless bacause we know but safer for futur changes to use real value
2723 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2724 echo "Next set_param must failed"
2725 policy_set_and_test "wrong" "$policy"
2728 echo "Back to default policy"
2729 cdt_set_sanity_policy
2731 run_test 109 "Policy display/change"
2734 # test needs a running copytool
2739 copy2archive /etc/passwd $tdir/$tfile
2741 local f=$DIR/$tdir/$tfile
2742 import_file $tdir/$tfile $f
2743 local fid=$(path2fid $f)
2745 cdt_set_non_blocking_restore
2750 wait_request_state $fid RESTORE SUCCEED
2751 cdt_clear_non_blocking_restore
2755 error "md5sum returns $st != 1, "\
2756 "should also perror ENODATA (No data available)"
2760 run_test 110a "Non blocking restore policy (import case)"
2763 # test needs a running copytool
2767 local f=$DIR/$tdir/$tfile
2768 local fid=$(copy_file /etc/passwd $f)
2769 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2770 wait_request_state $fid ARCHIVE SUCCEED
2773 cdt_set_non_blocking_restore
2778 wait_request_state $fid RESTORE SUCCEED
2779 cdt_clear_non_blocking_restore
2783 error "md5sum returns $st != 1, "\
2784 "should also perror ENODATA (No data available)"
2788 run_test 110b "Non blocking restore policy (release case)"
2791 # test needs a running copytool
2795 copy2archive /etc/passwd $tdir/$tfile
2797 local f=$DIR/$tdir/$tfile
2799 import_file $tdir/$tfile $f
2800 local fid=$(path2fid $f)
2804 copytool_remove_backend $fid
2807 wait_request_state $fid RESTORE FAILED
2814 [[ $st == 0 ]] || error "Restore does not failed"
2818 run_test 111a "No retry policy (import case), restore will error"\
2819 " (No such file or directory)"
2822 # test needs a running copytool
2826 local f=$DIR/$tdir/$tfile
2827 local fid=$(copy_file /etc/passwd $f)
2829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2830 wait_request_state $fid ARCHIVE SUCCEED
2833 copytool_remove_backend $fid
2836 wait_request_state $fid RESTORE FAILED
2843 [[ $st == 0 ]] || error "Restore does not failed"
2847 run_test 111b "No retry policy (release case), restore will error"\
2848 " (No such file or directory)"
2851 # test needs a running copytool
2855 local f=$DIR/$tdir/$tfile
2856 local fid=$(copy_file /etc/passwd $f)
2858 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2859 local l=$($LFS hsm_action $f)
2861 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2865 wait_request_state $fid ARCHIVE SUCCEED
2868 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2872 run_test 112 "State of recorded request"
2875 # test needs a running copytool
2879 local f=$DIR/$tdir/$tfile
2880 local fid=$(make_large_for_cancel $f)
2881 # test with cdt on is made in test_221
2883 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2886 wait_request_state $fid ARCHIVE CANCELED
2887 wait_request_state $fid CANCEL SUCCEED
2891 run_test 200 "Register/Cancel archive"
2894 # test needs a running copytool
2898 local f=$DIR/$tdir/$tfile
2899 make_archive $tdir/$tfile
2900 import_file $tdir/$tfile $f
2901 local fid=$(path2fid $f)
2903 # test with cdt on is made in test_222
2908 wait_request_state $fid RESTORE CANCELED
2909 wait_request_state $fid CANCEL SUCCEED
2913 run_test 201 "Register/Cancel restore"
2916 # test needs a running copytool
2920 local f=$DIR/$tdir/$tfile
2921 local fid=$(make_large_for_progress $f)
2922 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2923 wait_request_state $fid ARCHIVE SUCCEED
2929 wait_request_state $fid REMOVE CANCELED
2933 run_test 202 "Register/Cancel remove"
2936 # test needs a running copytool
2941 local f=$DIR/$tdir/$tfile
2942 local fid=$(copy_file /etc/passwd $f)
2946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2947 wait_request_state $fid ARCHIVE SUCCEED
2949 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2953 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2957 run_test 220 "Changelog for archive"
2960 # test needs a running copytool
2965 local f=$DIR/$tdir/$tfile
2966 local fid=$(make_large_for_cancel $f)
2970 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2971 wait_request_state $fid ARCHIVE STARTED
2973 wait_request_state $fid ARCHIVE CANCELED
2974 wait_request_state $fid CANCEL SUCCEED
2976 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2979 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2983 run_test 221 "Changelog for archive canceled"
2986 # test needs a running copytool
2990 copy2archive /etc/passwd $tdir/$tfile
2992 local f=$DIR/$tdir/$tfile
2993 import_file $tdir/$tfile $f
2994 local fid=$(path2fid $f)
2999 wait_request_state $fid RESTORE SUCCEED
3001 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3004 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3008 run_test 222a "Changelog for explicit restore"
3011 # test needs a running copytool
3015 local f=$DIR/$tdir/$tfile
3016 local fid=$(copy_file /etc/passwd $f)
3019 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3020 wait_request_state $fid ARCHIVE SUCCEED
3025 wait_request_state $fid RESTORE SUCCEED
3027 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3030 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3034 run_test 222b "Changelog for implicit restore"
3037 # test needs a running copytool
3042 local f=$DIR/$tdir/$tfile
3043 make_archive $tdir/$tfile
3047 import_file $tdir/$tfile $f
3048 local fid=$(path2fid $f)
3051 wait_request_state $fid RESTORE STARTED
3053 wait_request_state $fid RESTORE CANCELED
3054 wait_request_state $fid CANCEL SUCCEED
3056 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3059 [[ $flags == $target ]] ||
3060 error "Changelog flag is $flags not $target"
3064 run_test 223a "Changelog for restore canceled (import case)"
3067 # test needs a running copytool
3072 local f=$DIR/$tdir/$tfile
3073 local fid=$(make_large_for_progress $f)
3076 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3077 wait_request_state $fid ARCHIVE SUCCEED
3080 wait_request_state $fid RESTORE STARTED
3082 wait_request_state $fid RESTORE CANCELED
3083 wait_request_state $fid CANCEL SUCCEED
3085 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3088 [[ $flags == $target ]] ||
3089 error "Changelog flag is $flags not $target"
3093 run_test 223b "Changelog for restore canceled (release case)"
3096 # test needs a running copytool
3101 local f=$DIR/$tdir/$tfile
3102 local fid=$(copy_file /etc/passwd $f)
3105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3106 wait_request_state $fid ARCHIVE SUCCEED
3109 wait_request_state $fid REMOVE SUCCEED
3111 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3114 [[ $flags == $target ]] ||
3115 error "Changelog flag is $flags not $target"
3119 run_test 224 "Changelog for remove"
3122 # test needs a running copytool
3125 # test is not usable because remove request is too fast
3126 # so it is always finished before cancel can be done ...
3127 echo "Test disabled"
3132 local f=$DIR/$tdir/$tfile
3133 local fid=$(make_large_for_progress $f)
3136 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3137 wait_request_state $fid ARCHIVE SUCCEED
3139 # if cdt is on, it can serve too quickly the request
3144 wait_request_state $fid REMOVE CANCELED
3145 wait_request_state $fid CANCEL SUCCEED
3147 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3148 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3149 tail -n 1 | awk '{print $5}')
3152 [[ $flags == $target ]] ||
3153 error "Changelog flag is $flags not $target"
3157 run_test 225 "Changelog for remove canceled"
3160 # test needs a running copytool
3165 local f1=$DIR/$tdir/$tfile-1
3166 local f2=$DIR/$tdir/$tfile-2
3167 local f3=$DIR/$tdir/$tfile-3
3168 local fid1=$(copy_file /etc/passwd $f1)
3169 local fid2=$(copy_file /etc/passwd $f2)
3170 copy_file /etc/passwd $f3
3173 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3174 wait_request_state $fid1 ARCHIVE SUCCEED
3176 $LFS hsm_archive $f2
3177 wait_request_state $fid2 ARCHIVE SUCCEED
3179 rm $f1 || error "rm $f1 failed"
3181 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3184 [[ $flags == $target ]] ||
3185 error "Changelog flag is $flags not $target"
3187 mv $f3 $f2 || error "mv $f3 $f2 failed"
3189 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3192 [[ $flags == $target ]] ||
3193 error "Changelog flag is $flags not $target"
3197 run_test 226 "changelog for last rm/mv with exiting archive"
3199 check_flags_changes() {
3207 $LFS hsm_set --$hsm_flag $f ||
3208 error "Cannot set $hsm_flag on $f"
3209 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3210 local seen=${#flags[*]}
3212 [[ $seen == $cnt ]] ||
3213 error "set $hsm_flag: Changelog events $seen != $cnt"
3214 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3215 error "set $hsm_flag: Changelog flags are "\
3216 "${flags[$((cnt - 1))]} not $target"
3218 $LFS hsm_clear --$hsm_flag $f ||
3219 error "Cannot clear $hsm_flag on $f"
3220 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3223 [[ $cnt == $seen ]] ||
3224 error "clear $hsm_flag: Changelog events $seen != $cnt"
3226 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3227 error "clear $hsm_flag: Changelog flag is "\
3228 "${flags[$((cnt - 1))]} not $target"
3232 # test needs a running copytool
3239 for i in norelease noarchive exists archived
3241 local f=$DIR/$tdir/$tfile-$i
3242 local fid=$(copy_file /etc/passwd $f)
3243 check_flags_changes $f $fid $i 0 1
3246 f=$DIR/$tdir/$tfile---lost
3247 fid=$(copy_file /etc/passwd $f)
3248 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3249 wait_request_state $fid ARCHIVE SUCCEED
3250 check_flags_changes $f $fid lost 3 1
3254 run_test 227 "changelog when explicit setting of HSM flags"
3257 # test needs a running copytool
3260 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3261 error "creating $DIR/$tfile"
3262 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3263 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3265 $LFS hsm_release $DIR/$tfile
3266 check_hsm_flags $DIR/$tfile "0x0000000d"
3268 filefrag $DIR/$tfile | grep " 1 extent found" ||
3269 error "filefrag on released file must return only one extent"
3271 # only newer versions of cp detect sparse files by stat/FIEMAP
3273 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3274 error "copying $DIR/$tfile"
3275 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3277 $LFS hsm_release $DIR/$tfile
3278 check_hsm_flags $DIR/$tfile "0x0000000d"
3282 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3284 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3285 error "comparing untarred $DIR/$tfile"
3289 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3292 # test needs a running copytool
3296 local maxrequest=$(get_hsm_param max_requests)
3297 local rqcnt=$(($maxrequest * 3))
3301 for i in $(seq -w 1 $rqcnt); do
3303 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3305 # we do it in 2 steps, so all requests arrive at the same time
3306 for i in $(seq -w 1 $rqcnt); do
3307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3312 while [[ $cnt != 0 || $wt != 0 ]]; do
3314 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3315 $HSM_PARAM.actions |\
3316 grep STARTED | grep -v CANCEL | wc -l")
3317 [[ $cnt -le $maxrequest ]] ||
3318 error "$cnt > $maxrequest too many started requests"
3319 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3320 $HSM_PARAM.actions |\
3321 grep WAITING | wc -l")
3322 echo "max=$maxrequest started=$cnt waiting=$wt"
3327 run_test 250 "Coordinator max request"
3330 # test needs a running copytool
3334 local f=$DIR/$tdir/$tfile
3335 local fid=$(make_large_for_cancel $f)
3338 # to have a short test
3339 local old_to=$(get_hsm_param active_request_timeout)
3340 set_hsm_param active_request_timeout 4
3341 # to be sure the cdt will wake up frequently so
3342 # it will be able to cancel the "old" request
3343 local old_loop=$(get_hsm_param loop_period)
3344 set_hsm_param loop_period 2
3347 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3348 wait_request_state $fid ARCHIVE STARTED
3350 wait_request_state $fid ARCHIVE CANCELED
3352 set_hsm_param active_request_timeout $old_to
3353 set_hsm_param loop_period $old_loop
3357 run_test 251 "Coordinator request timeout"
3360 # the only way to test ondisk conf is to restart MDS ...
3361 echo "Stop coordinator and remove coordinator state at mount"
3364 # clean on disk conf set by default
3365 cdt_clear_mount_state
3366 cdt_check_state stopped
3368 # check cdt still off after umount/remount
3370 cdt_check_state stopped
3372 echo "Set coordinator start at mount, and start coordinator"
3373 cdt_set_mount_state enabled
3376 cdt_check_state enabled
3378 # check cdt still on after umount/remount
3380 cdt_check_state enabled
3382 # we are back to original state (cdt started at mount)
3384 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3387 local ai=$(get_hsm_param default_archive_id)
3388 local new=$((ai + 1))
3390 set_hsm_param default_archive_id $new -P
3392 local res=$(get_hsm_param default_archive_id)
3395 set_hsm_param default_archive_id "" "-P -d"
3397 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3399 run_test 301 "HSM tunnable are persistent"
3402 local ai=$(get_hsm_param default_archive_id)
3403 local new=$((ai + 1))
3408 set_hsm_param default_archive_id $new -P
3411 for mdtno in $(seq 1 $MDSCOUNT); do
3416 cdt_check_state enabled
3418 local res=$(get_hsm_param default_archive_id)
3421 set_hsm_param default_archive_id "" "-P -d"
3423 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3425 run_test 302 "HSM tunnable are persistent when CDT is off"
3428 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3434 local dir_mdt0=$DIR/$tdir/mdt0
3435 local dir_mdt1=$DIR/$tdir/mdt1
3437 # create 1 dir per MDT
3438 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3439 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3441 # create 1 file in each MDT
3442 local fid1=$(make_small $dir_mdt0/$tfile)
3443 local fid2=$(make_small $dir_mdt1/$tfile)
3445 # check that hsm request on mdt0 is sent to the right MDS
3446 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3447 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3448 echo "archive successful on mdt0"
3450 # check that hsm request on mdt1 is sent to the right MDS
3451 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3452 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3453 echo "archive successful on mdt1"
3456 # clean test files and directories
3457 rm -rf $dir_mdt0 $dir_mdt1
3459 run_test 400 "Single request is sent to the right MDT"
3462 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3468 local dir_mdt0=$DIR/$tdir/mdt0
3469 local dir_mdt1=$DIR/$tdir/mdt1
3471 # create 1 dir per MDT
3472 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3473 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3475 # create 1 file in each MDT
3476 local fid1=$(make_small $dir_mdt0/$tfile)
3477 local fid2=$(make_small $dir_mdt1/$tfile)
3479 # check that compound requests are shunt to the rights MDTs
3480 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3481 error "lfs hsm_archive"
3482 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3483 echo "archive successful on mdt0"
3484 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3485 echo "archive successful on mdt1"
3488 # clean test files and directories
3489 rm -rf $dir_mdt0 $dir_mdt1
3491 run_test 401 "Compound requests split and sent to their respective MDTs"
3493 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3498 local node=$(facet_active_host $facet)
3500 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3501 awk '{print $4}'); do
3502 echo "$3 $mdc on $node"
3503 do_facet $facet "$LCTL --device $mdc $state" || return 1
3508 # make sure there is no running copytool
3511 # deactivate all mdc on agent1
3512 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3514 copytool_setup $SINGLEAGT
3516 check_agent_unregistered "uuid" # match any agent
3518 # no expected running copytool
3519 search_copytools $agent && error "Copytool start should have failed"
3522 mdc_change_state $SINGLEAGT "MDT000." "activate"
3524 run_test 402 "Copytool start fails if all MDTs are inactive"
3527 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3529 # make sure there is no running copytool
3532 local agent=$(facet_active_host $SINGLEAGT)
3533 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3535 # deactivate all mdc for MDT0001
3536 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3539 # check the agent is registered on MDT0000, and not on MDT0001
3540 check_agent_registered_by_mdt $uuid 0
3541 check_agent_unregistered_by_mdt $uuid 1
3543 # check running copytool process
3544 search_copytools $agent || error "No running copytools on $agent"
3546 # reactivate all mdc for MDT0001
3547 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3549 # make sure the copytool is now registered to all MDTs
3550 check_agent_registered $uuid
3554 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3557 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3561 # create files on both MDT0000 and MDT0001
3564 local dir_mdt0=$DIR/$tdir/mdt0
3565 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3567 # create 1 file on mdt0
3568 local fid1=$(make_small $dir_mdt0/$tfile)
3570 # deactivate all mdc for MDT0001
3571 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3573 # send an HSM request for files in MDT0000
3574 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3576 # check for completion of files in MDT0000
3577 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3578 echo "archive successful on mdt0"
3580 # reactivate all mdc for MDT0001
3581 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3584 # clean test files and directories
3587 run_test 404 "Inactive MDT does not block requests for active MDTs"
3592 check_and_cleanup_lustre