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 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=$(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"
482 cleanup_large_files() {
483 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
485 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
488 make_large_for_striping() {
489 local file2=${1/$DIR/$DIR2}
490 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
494 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
495 error "cannot create $file2"
496 path2fid $1 || error "cannot get fid on $1"
499 make_large_for_progress() {
500 local file2=${1/$DIR/$DIR2}
504 # big file is large enough, so copy time is > 30s
505 # so copytool make 1 progress
506 # size is not a multiple of 1M to avoid stripe
508 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
509 error "cannot create $file2"
510 path2fid $1 || error "cannot get fid on $1"
513 make_large_for_progress_aligned() {
514 local file2=${1/$DIR/$DIR2}
518 # big file is large enough, so copy time is > 30s
519 # so copytool make 1 progress
520 # size is a multiple of 1M to have stripe
522 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
523 error "cannot create $file2"
524 path2fid $1 || error "cannot get fid on $1"
527 make_large_for_cancel() {
528 local file2=${1/$DIR/$DIR2}
532 # Copy timeout is 100s. 105MB => 105s
533 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
534 error "cannot create $file2"
535 path2fid $1 || error "cannot get fid on $1"
541 wait_update --verbose $(facet_active_host $facet) "$@"
544 wait_request_state() {
548 # 4th arg (mdt index) is optional
550 local mds=mds$(($mdtidx + 1))
552 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
553 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
555 wait_result $mds "$cmd" $state 100 ||
556 error "request on $fid is not $state on $mds"
559 get_request_state() {
563 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
564 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
567 get_request_count() {
571 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
572 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
578 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
579 cmd+=" | egrep 'WAITING|STARTED'"
581 wait_result $SINGLEMDS "$cmd" "" $timeout ||
582 error "requests did not complete"
585 wait_for_grace_delay() {
586 local val=$(get_hsm_param grace_delay)
590 # populate MDT device array
596 # cleanup from previous bad setup
597 search_and_kill_copytool
599 # for recovery tests, coordinator needs to be started at mount
601 # the lustre conf must be without hsm on (like for sanity.sh)
602 echo "Set HSM on and start"
603 cdt_set_mount_state enabled
604 cdt_check_state enabled
606 echo "Start copytool"
609 echo "Set sanity-hsm HSM policy"
610 cdt_set_sanity_policy
612 # finished requests are quickly removed from list
613 set_hsm_param grace_delay 10
619 local f=$DIR/$tdir/$tfile
623 check_hsm_flags_user $f "0x00000000"
625 $RUNAS $LFS hsm_set --norelease $f ||
626 error "user could not change hsm flags"
627 check_hsm_flags_user $f "0x00000010"
629 $RUNAS $LFS hsm_clear --norelease $f ||
630 error "user could not clear hsm flags"
631 check_hsm_flags_user $f "0x00000000"
633 # User could not change those flags...
634 $RUNAS $LFS hsm_set --exists $f &&
635 error "user should not set this flag"
636 check_hsm_flags_user $f "0x00000000"
639 $LFS hsm_set --exists $f ||
640 error "root could not change hsm flags"
641 check_hsm_flags_user $f "0x00000001"
643 $LFS hsm_clear --exists $f ||
644 error "root could not clear hsm state"
645 check_hsm_flags_user $f "0x00000000"
648 run_test 1 "lfs hsm flags root/non-root access"
652 local f=$DIR/$tdir/$tfile
654 # New files are not dirty
655 check_hsm_flags $f "0x00000000"
657 # For test, we simulate an archived file.
658 $LFS hsm_set --exists $f || error "user could not change hsm flags"
659 check_hsm_flags $f "0x00000001"
661 # chmod do not put the file dirty
662 chmod 600 $f || error "could not chmod test file"
663 check_hsm_flags $f "0x00000001"
665 # chown do not put the file dirty
666 chown $RUNAS_ID $f || error "could not chown test file"
667 check_hsm_flags $f "0x00000001"
669 # truncate put the file dirty
670 $TRUNCATE $f 1 || error "could not truncate test file"
671 check_hsm_flags $f "0x00000003"
673 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
674 check_hsm_flags $f "0x00000001"
676 run_test 2 "Check file dirtyness when doing setattr"
682 # New files are not dirty
684 check_hsm_flags $f "0x00000000"
686 # For test, we simulate an archived file.
687 $LFS hsm_set --exists $f ||
688 error "user could not change hsm flags"
689 check_hsm_flags $f "0x00000001"
691 # Reading a file, does not set dirty
692 cat $f > /dev/null || error "could not read file"
693 check_hsm_flags $f "0x00000001"
695 # Open for write without modifying data, does not set dirty
696 openfile -f O_WRONLY $f || error "could not open test file"
697 check_hsm_flags $f "0x00000001"
699 # Append to a file sets it dirty
700 cp -p /etc/passwd $f.append || error "could not create file"
701 $LFS hsm_set --exists $f.append ||
702 error "user could not change hsm flags"
703 dd if=/etc/passwd of=$f.append bs=1 count=3\
704 conv=notrunc oflag=append status=noxfer ||
705 error "could not append to test file"
706 check_hsm_flags $f.append "0x00000003"
708 # Modify a file sets it dirty
709 cp -p /etc/passwd $f.modify || error "could not create file"
710 $LFS hsm_set --exists $f.modify ||
711 error "user could not change hsm flags"
712 dd if=/dev/zero of=$f.modify bs=1 count=3\
713 conv=notrunc status=noxfer ||
714 error "could not modify test file"
715 check_hsm_flags $f.modify "0x00000003"
717 # Open O_TRUNC sets dirty
718 cp -p /etc/passwd $f.trunc || error "could not create file"
719 $LFS hsm_set --exists $f.trunc ||
720 error "user could not change hsm flags"
721 cp /etc/group $f.trunc || error "could not override a file"
722 check_hsm_flags $f.trunc "0x00000003"
724 # Mmapped a file sets dirty
725 cp -p /etc/passwd $f.mmap || error "could not create file"
726 $LFS hsm_set --exists $f.mmap ||
727 error "user could not change hsm flags"
728 multiop $f.mmap OSMWUc || error "could not mmap a file"
729 check_hsm_flags $f.mmap "0x00000003"
731 run_test 3 "Check file dirtyness when opening for write"
735 local f=$DIR/$tdir/$tfile
736 local fid=$(make_small $f)
739 local st=$(get_request_state $fid CANCEL)
740 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
742 run_test 4 "Useless cancel must not be registered"
745 # test needs a running copytool
749 local f=$DIR/$tdir/$tfile
750 local fid=$(copy_file /etc/passwd $f)
752 wait_request_state $fid ARCHIVE SUCCEED
754 check_hsm_flags $f "0x00000009"
758 run_test 8 "Test default archive number"
762 local f=$DIR/$tdir/$tfile
763 local fid=$(copy_file /etc/passwd $f)
764 # we do not use the default one to be sure
765 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
767 copytool_setup $SINGLEAGT $MOUNT $new_an
768 $LFS hsm_archive --archive $new_an $f
769 wait_request_state $fid ARCHIVE SUCCEED
771 check_hsm_flags $f "0x00000009"
775 run_test 9 "Use of explict archive number, with dedicated copytool"
778 needclients 3 || return 0
784 copytool_cleanup $(comma_list $(agts_nodes))
786 # start all of the copytools
787 for n in $(seq $AGTCOUNT); do
791 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
794 for n in $(seq $AGTCOUNT); do
795 file=$DIR/$tdir/$tfile.$n
796 fid=$(make_small $file)
798 $LFS hsm_archive $file || error "could not archive file $file"
799 wait_request_state $fid ARCHIVE SUCCEED
800 check_hsm_flags $file "0x00000009"
804 copytool_cleanup $(comma_list $(agts_nodes))
806 run_test 9a "Multiple remote agents"
809 # test needs a running copytool
812 mkdir -p $DIR/$tdir/d1
813 local f=$DIR/$tdir/$tfile
814 local fid=$(copy_file /etc/hosts $f)
815 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
816 error "hsm_archive failed"
817 wait_request_state $fid ARCHIVE SUCCEED
819 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
820 error "fid $fid not in archive $HSM_ARCHIVE"
821 echo "Verifying content"
822 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
823 echo "Verifying hsm state "
824 check_hsm_flags $f "0x00000009"
826 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
827 local st=$(get_hsm_archive_id $f)
828 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
829 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
834 run_test 10a "Archive a file"
837 # test needs a running copytool
841 local f=$DIR/$tdir/$tfile
842 local fid=$(copy_file /etc/hosts $f)
843 $LFS hsm_archive $f || error "archive request failed"
844 wait_request_state $fid ARCHIVE SUCCEED
846 $LFS hsm_archive $f || error "archive of non dirty file failed"
847 local cnt=$(get_request_count $fid ARCHIVE)
848 [[ "$cnt" == "1" ]] ||
849 error "archive of non dirty file must not make a request"
853 run_test 10b "Archive of non dirty file must work without doing request"
856 # test needs a running copytool
860 local f=$DIR/$tdir/$tfile
861 local fid=$(copy_file /etc/hosts $f)
862 $LFS hsm_set --noarchive $f
863 $LFS hsm_archive $f && error "archive a noarchive file must fail"
867 run_test 10c "Check forbidden archive"
870 # test needs a running copytool
874 local f=$DIR/$tdir/$tfile
875 local fid=$(copy_file /etc/hosts $f)
876 $LFS hsm_archive $f || error "cannot archive $f"
877 wait_request_state $fid ARCHIVE SUCCEED
879 local ar=$(get_hsm_archive_id $f)
880 local dflt=$(get_hsm_param default_archive_id)
881 [[ $ar == $dflt ]] ||
882 error "archived file is not on default archive: $ar != $dflt"
886 run_test 10d "Archive a file on the default archive id"
890 copy2archive /etc/hosts $tdir/$tfile
891 local f=$DIR/$tdir/$tfile
893 import_file $tdir/$tfile $f
894 echo -n "Verifying released state: "
895 check_hsm_flags $f "0x0000000d"
897 local LSZ=$(stat -c "%s" $f)
898 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
900 echo "Verifying imported size $LSZ=$ASZ"
901 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
902 echo -n "Verifying released pattern: "
903 local PTRN=$($GETSTRIPE -L $f)
905 [[ $PTRN == 80000001 ]] || error "Is not released"
906 local fid=$(path2fid $f)
907 echo "Verifying new fid $fid in archive"
909 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
910 error "fid $fid not in archive $HSM_ARCHIVE"
912 run_test 11 "Import a file"
915 # test needs a running copytool
919 copy2archive /etc/hosts $tdir/$tfile
921 local f=$DIR/$tdir/$tfile
922 import_file $tdir/$tfile $f
923 local f=$DIR2/$tdir/$tfile
924 echo "Verifying released state: "
925 check_hsm_flags $f "0x0000000d"
927 local fid=$(path2fid $f)
929 wait_request_state $fid RESTORE SUCCEED
931 echo "Verifying file state: "
932 check_hsm_flags $f "0x00000009"
934 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
936 [[ $? -eq 0 ]] || error "Restored file differs"
940 run_test 12a "Restore an imported file explicitly"
943 # test needs a running copytool
947 copy2archive /etc/hosts $tdir/$tfile
949 local f=$DIR/$tdir/$tfile
950 import_file $tdir/$tfile $f
951 echo "Verifying released state: "
952 check_hsm_flags $f "0x0000000d"
954 cat $f > /dev/null || error "File read failed"
956 echo "Verifying file state after restore: "
957 check_hsm_flags $f "0x00000009"
959 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
961 [[ $? -eq 0 ]] || error "Restored file differs"
965 run_test 12b "Restore an imported file implicitly"
968 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
970 # test needs a running copytool
974 local f=$DIR/$tdir/$tfile
975 $LFS setstripe -c 2 $f
976 local fid=$(make_large_for_striping $f)
977 local FILE_CRC=$(md5sum $f)
979 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
980 wait_request_state $fid ARCHIVE SUCCEED
981 $LFS hsm_release $f || error "release $f failed"
983 echo "$FILE_CRC" | md5sum -c
985 [[ $? -eq 0 ]] || error "Restored file differs"
989 run_test 12c "Restore a file with stripe of 2"
992 # test needs a running copytool
997 local f=$DIR/$tdir/$tfile
998 local fid=$(copy_file /etc/hosts $f)
999 $LFS hsm_restore $f || error "restore of non archived file failed"
1000 local cnt=$(get_request_count $fid RESTORE)
1001 [[ "$cnt" == "0" ]] ||
1002 error "restore non archived must not make a request"
1003 $LFS hsm_archive $f ||
1004 error "archive request failed"
1005 wait_request_state $fid ARCHIVE SUCCEED
1006 $LFS hsm_restore $f ||
1007 error "restore of non released file failed"
1008 local cnt=$(get_request_count $fid RESTORE)
1009 [[ "$cnt" == "0" ]] ||
1010 error "restore a non dirty file must not make a request"
1014 run_test 12d "Restore of a non archived, non released file must work"\
1015 " without doing request"
1018 # test needs a running copytool
1021 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1022 local f=$DIR/$tdir/$tfile
1023 local fid=$(copy_file /etc/hosts $f)
1024 $LFS hsm_archive $f || error "archive request failed"
1025 wait_request_state $fid ARCHIVE SUCCEED
1028 cat /etc/hosts >> $f
1032 $LFS hsm_restore $f && error "restore a dirty file must fail"
1036 run_test 12e "Check forbidden restore"
1039 # test needs a running copytool
1043 local f=$DIR/$tdir/$tfile
1044 local fid=$(copy_file /etc/hosts $f)
1046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1047 wait_request_state $fid ARCHIVE SUCCEED
1048 $LFS hsm_release $f || error "release of $f failed"
1050 wait_request_state $fid RESTORE SUCCEED
1052 echo -n "Verifying file state: "
1053 check_hsm_flags $f "0x00000009"
1055 diff -q /etc/hosts $f
1057 [[ $? -eq 0 ]] || error "Restored file differs"
1061 run_test 12f "Restore a released file explicitly"
1064 # test needs a running copytool
1068 local f=$DIR/$tdir/$tfile
1069 local fid=$(copy_file /etc/hosts $f)
1071 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1072 wait_request_state $fid ARCHIVE SUCCEED
1073 $LFS hsm_release $f || error "release of $f failed"
1075 diff -q /etc/hosts $f
1078 # we check we had a restore done
1079 wait_request_state $fid RESTORE SUCCEED
1081 [[ $st -eq 0 ]] || error "Restored file differs"
1085 run_test 12g "Restore a released file implicitly"
1088 needclients 2 || return 0
1090 # test needs a running copytool
1094 local f=$DIR/$tdir/$tfile
1095 local fid=$(copy_file /etc/hosts $f)
1097 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1098 wait_request_state $fid ARCHIVE SUCCEED
1099 $LFS hsm_release $f || error "release of $f failed"
1101 do_node $CLIENT2 diff -q /etc/hosts $f
1104 # we check we had a restore done
1105 wait_request_state $fid RESTORE SUCCEED
1107 [[ $st -eq 0 ]] || error "Restored file differs"
1111 run_test 12h "Restore a released file implicitly from a second node"
1114 # test needs a running copytool
1118 local f=$DIR/$tdir/$tfile
1119 local fid=$(copy_file /etc/passwd $f)
1120 $LFS hsm_archive $f || error "archive of $f failed"
1121 wait_request_state $fid ARCHIVE SUCCEED
1123 $LFS hsm_release $f || error "release of $f failed"
1127 [[ $? -eq 0 ]] || error "Restored file differs"
1131 run_test 12m "Archive/release/implicit restore"
1134 # test needs a running copytool
1138 copy2archive /etc/hosts $tdir/$tfile
1140 local f=$DIR/$tdir/$tfile
1141 import_file $tdir/$tfile $f
1143 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1144 error "Restored file differs"
1146 $LFS hsm_release $f || error "release of $f failed"
1150 run_test 12n "Import/implicit restore/release"
1153 # test needs a running copytool
1156 local ARC_SUBDIR="import.orig"
1160 # populate directory to be imported
1161 for d in $(seq 1 10); do
1162 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1163 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1164 for f in $(seq 1 10); do
1165 CURR_FILE="$CURR_DIR/$tfile.$f"
1166 # write file-specific data
1167 do_facet $SINGLEAGT \
1168 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1169 "file=$CURR_FILE > $CURR_FILE"
1173 import_file "$ARC_SUBDIR" $DIR/$tdir
1174 # diff lustre content and origin (triggers file restoration)
1175 # there must be 10x10 identical files, and no difference
1176 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1177 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1178 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1179 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1181 [ $cnt_diff -eq 0 ] ||
1182 error "$cnt_diff imported files differ from read data"
1183 [ $cnt_ok -eq 100 ] ||
1184 error "not enough identical files ($cnt_ok != 100)"
1188 run_test 13 "Recursively import and restore a directory"
1191 # test needs a running copytool
1196 local f=$DIR/$tdir/$tfile
1197 local fid=$(make_small $f)
1198 local sum=$(md5sum $f | awk '{print $1}')
1199 $LFS hsm_archive $f || error "could not archive file"
1200 wait_request_state $fid ARCHIVE SUCCEED
1204 # create released file (simulate llapi_hsm_import call)
1206 local fid2=$(path2fid $f)
1207 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1208 $LFS hsm_release $f || error "could not release file"
1210 # rebind the archive to the newly created file
1211 echo "rebind $fid to $fid2"
1213 do_facet $SINGLEAGT \
1214 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1215 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1217 # restore file and compare md5sum
1218 local sum2=$(md5sum $f | awk '{print $1}')
1220 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1224 run_test 14 "Rebind archived file to a new fid"
1227 # test needs a running copytool
1232 local f=$DIR/$tdir/$tfile
1234 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1238 for i in $(seq 1 $count); do
1239 fids[$i]=$(make_small $f.$i)
1240 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1241 $LFS hsm_archive $f.$i || error "could not archive file"
1243 wait_all_done $(($count*60))
1247 for i in $(seq 1 $count); do
1250 local fid2=$(path2fid $f.$i)
1251 # add the rebind operation to the list
1252 echo ${fids[$i]} $fid2 >> $tmpfile
1254 # set it released (simulate llapi_hsm_import call)
1255 $LFS hsm_set --archived --exists $f.$i ||
1256 error "could not force hsm flags"
1257 $LFS hsm_release $f.$i || error "could not release file"
1259 nl=$(wc -l < $tmpfile)
1260 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1262 echo "rebind list of files"
1263 do_facet $SINGLEAGT \
1264 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1265 --rebind $tmpfile $DIR" || error "could not rebind file list"
1267 # restore files and compare md5sum
1268 for i in $(seq 1 $count); do
1269 local sum2=$(md5sum $f.$i | awk '{print $1}')
1270 [[ $sum2 == ${sums[$i]} ]] ||
1271 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1277 run_test 15 "Rebind a list of files"
1280 # test needs a running copytool
1284 # create a known size file so we can verify transfer speed
1287 dd if=/dev/zero of=$ref bs=1M count=20
1290 local f=$DIR/$tdir/$tfile
1291 local fid=$(copy_file $ref $f)
1293 local start=$(date +%s)
1295 wait_request_state $fid ARCHIVE SUCCEED
1296 local end=$(date +%s)
1297 local duration=$((end - start))
1299 [[ $duration -ge $goal ]] ||
1300 error "Transfer is too fast $duration < $goal"
1304 run_test 16 "Test CT bandwith control option"
1309 local f=$DIR/$tdir/$tfile
1310 touch $f || error "touch $f failed"
1312 # Could not release a non-archived file
1313 $LFS hsm_release $f && error "release should not succeed"
1315 # For following tests, we must test them with HS_ARCHIVED set
1316 $LFS hsm_set --exists --archived $f || error "could not add flag"
1318 # Could not release a file if no-release is set
1319 $LFS hsm_set --norelease $f || error "could not add flag"
1320 $LFS hsm_release $f && error "release should not succeed"
1321 $LFS hsm_clear --norelease $f || error "could not remove flag"
1323 # Could not release a file if lost
1324 $LFS hsm_set --lost $f || error "could not add flag"
1325 $LFS hsm_release $f && error "release should not succeed"
1326 $LFS hsm_clear --lost $f || error "could not remove flag"
1328 # Could not release a file if dirty
1329 $LFS hsm_set --dirty $f || error "could not add flag"
1330 $LFS hsm_release $f && error "release should not succeed"
1331 $LFS hsm_clear --dirty $f || error "could not remove flag"
1333 run_test 20 "Release is not permitted"
1336 # test needs a running copytool
1340 local f=$DIR/$tdir/test_release
1342 # Create a file and check its states
1343 local fid=$(make_small $f)
1344 check_hsm_flags $f "0x00000000"
1346 local orig_size=$(stat -c "%s" $f)
1347 local orig_blocks=$(stat -c "%b" $f)
1349 start_full_debug_logging
1351 $LFS hsm_archive $f || error "could not archive file"
1352 wait_request_state $fid ARCHIVE SUCCEED
1354 local blocks=$(stat -c "%b" $f)
1355 [ $blocks -eq $orig_blocks ] ||
1356 error "$f: wrong block number after archive: " \
1357 "$blocks != $orig_blocks"
1358 local size=$(stat -c "%s" $f)
1359 [ $size -eq $orig_size ] ||
1360 error "$f: wrong size after archive: $size != $orig_size"
1362 # Release and check states
1363 $LFS hsm_release $f || error "could not release file"
1364 check_hsm_flags $f "0x0000000d"
1366 blocks=$(stat -c "%b" $f)
1367 [ $blocks -gt 5 ] &&
1368 error "$f: too many blocks after release: $blocks > 5"
1369 size=$(stat -c "%s" $f)
1370 [ $size -ne $orig_size ] &&
1371 error "$f: wrong size after release: $size != $orig_size"
1373 # Check we can release an file without stripe info
1377 check_hsm_flags $f "0x00000000"
1378 $LFS hsm_archive $f || error "could not archive file"
1379 wait_request_state $fid ARCHIVE SUCCEED
1381 # Release and check states
1382 $LFS hsm_release $f || error "could not release file"
1383 check_hsm_flags $f "0x0000000d"
1385 # Release again a file that is already released is OK
1386 $LFS hsm_release $f || fail "second release should succeed"
1387 check_hsm_flags $f "0x0000000d"
1389 stop_full_debug_logging
1393 run_test 21 "Simple release tests"
1396 # test needs a running copytool
1401 local f=$DIR/$tdir/test_release
1402 local swap=$DIR/$tdir/test_swap
1404 # Create a file and check its states
1405 local fid=$(make_small $f)
1406 check_hsm_flags $f "0x00000000"
1408 $LFS hsm_archive $f || error "could not archive file"
1409 wait_request_state $fid ARCHIVE SUCCEED
1411 # Release and check states
1412 $LFS hsm_release $f || error "could not release file"
1413 check_hsm_flags $f "0x0000000d"
1416 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1421 run_test 22 "Could not swap a release file"
1424 # test needs a running copytool
1429 local f=$DIR/$tdir/test_mtime
1431 # Create a file and check its states
1432 local fid=$(make_small $f)
1433 check_hsm_flags $f "0x00000000"
1435 $LFS hsm_archive $f || error "could not archive file"
1436 wait_request_state $fid ARCHIVE SUCCEED
1438 # Set modification time in the past
1439 touch -m -a -d @978261179 $f
1441 # Release and check states
1442 $LFS hsm_release $f || error "could not release file"
1443 check_hsm_flags $f "0x0000000d"
1445 local MTIME=$(stat -c "%Y" $f)
1446 local ATIME=$(stat -c "%X" $f)
1447 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1448 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1452 run_test 23 "Release does not change a/mtime (utime)"
1455 local file=$DIR/$tdir/$tfile
1464 # test needs a running copytool
1469 fid=$(make_small $file)
1471 # Create a file and check its states
1472 check_hsm_flags $file "0x00000000"
1474 # Ensure atime is less than mtime and ctime.
1478 atime0=$(stat -c "%X" $file)
1479 mtime0=$(stat -c "%Y" $file)
1480 ctime0=$(stat -c "%Z" $file)
1482 [ $atime0 -lt $mtime0 ] ||
1483 error "atime $atime0 is not less than mtime $mtime0"
1485 [ $atime0 -lt $ctime0 ] ||
1486 error "atime $atime0 is not less than ctime $ctime0"
1488 # Archive should not change any timestamps.
1489 $LFS hsm_archive $file || error "cannot archive '$file'"
1490 wait_request_state $fid ARCHIVE SUCCEED
1492 atime1=$(stat -c "%X" $file)
1493 mtime1=$(stat -c "%Y" $file)
1494 ctime1=$(stat -c "%Z" $file)
1496 [ $atime0 -eq $atime1 ] ||
1497 error "archive changed atime from $atime0 to $atime1"
1499 [ $mtime0 -eq $mtime1 ] ||
1500 error "archive changed mtime from $mtime0 to $mtime1"
1502 [ $ctime0 -eq $ctime1 ] ||
1503 error "archive changed ctime from $ctime0 to $ctime1"
1505 # Release should not change any timestamps.
1506 $LFS hsm_release $file || error "cannot release '$file'"
1507 check_hsm_flags $file "0x0000000d"
1509 atime1=$(stat -c "%X" $file)
1510 mtime1=$(stat -c "%Y" $file)
1511 ctime1=$(stat -c "%Z" $file)
1513 [ $atime0 -eq $atime1 ] ||
1514 error "release changed atime from $atime0 to $atime1"
1516 [ $mtime0 -eq $mtime1 ] ||
1517 error "release changed mtime from $mtime0 to $mtime1"
1519 [ $ctime0 -eq $ctime1 ] ||
1520 error "release changed ctime from $ctime0 to $ctime1"
1522 # Restore should not change atime or mtime and should not
1524 $LFS hsm_restore $file
1525 wait_request_state $fid RESTORE SUCCEED
1527 atime1=$(stat -c "%X" $file)
1528 mtime1=$(stat -c "%Y" $file)
1529 ctime1=$(stat -c "%Z" $file)
1531 [ $atime0 -eq $atime1 ] ||
1532 error "restore changed atime from $atime0 to $atime1"
1534 [ $mtime0 -eq $mtime1 ] ||
1535 error "restore changed mtime from $mtime0 to $mtime1"
1537 [ $ctime0 -le $ctime1 ] ||
1538 error "restore changed ctime from $ctime0 to $ctime1"
1542 # Once more, after unmount and mount.
1543 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1544 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1546 atime1=$(stat -c "%X" $file)
1547 mtime1=$(stat -c "%Y" $file)
1548 ctime1=$(stat -c "%Z" $file)
1550 [ $atime0 -eq $atime1 ] ||
1551 error "remount changed atime from $atime0 to $atime1"
1553 [ $mtime0 -eq $mtime1 ] ||
1554 error "remount changed mtime from $mtime0 to $mtime1"
1556 [ $ctime0 -le $ctime1 ] ||
1557 error "remount changed ctime from $ctime0 to $ctime1"
1559 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1562 local file=$DIR/$tdir/$tfile
1568 # Test needs a running copytool.
1572 # Check that root can do HSM actions on a ordinary user's file.
1574 fid=$(make_small $file)
1575 sum0=$(md5sum $file)
1577 chown $RUNAS_ID:$RUNAS_GID $file ||
1578 error "cannot chown '$file' to '$RUNAS_ID'"
1580 chmod ugo-w $DIR/$tdir ||
1581 error "cannot chmod '$DIR/$tdir'"
1583 $LFS hsm_archive $file
1584 wait_request_state $fid ARCHIVE SUCCEED
1586 $LFS hsm_release $file
1587 check_hsm_flags $file "0x0000000d"
1589 $LFS hsm_restore $file
1590 wait_request_state $fid RESTORE SUCCEED
1592 # Check that ordinary user can get HSM state.
1593 $RUNAS $LFS hsm_state $file ||
1594 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1596 $LFS hsm_release $file
1597 check_hsm_flags $file "0x0000000d"
1599 # Check that ordinary user can accessed released file.
1600 sum1=$($RUNAS md5sum $file) ||
1601 error "user '$RUNAS_ID' cannot read '$file'"
1603 [ "$sum0" == "$sum1" ] ||
1604 error "md5sum mismatch for '$file'"
1608 run_test 24b "root can archive, release, and restore user files"
1610 cleanup_test_24c() {
1612 set_hsm_param user_request_mask RESTORE
1613 set_hsm_param group_request_mask RESTORE
1614 set_hsm_param other_request_mask RESTORE
1618 local file=$DIR/$tdir/$tfile
1619 local action=archive
1624 # test needs a running copytool
1629 # Save the default masks and check that cleanup_24c will
1630 # restore the request masks correctly.
1631 user_save=$(get_hsm_param user_request_mask)
1632 group_save=$(get_hsm_param group_request_mask)
1633 other_save=$(get_hsm_param other_request_mask)
1635 [ "$user_save" == RESTORE ] ||
1636 error "user_request_mask is '$user_save' expected 'RESTORE'"
1637 [ "$group_save" == RESTORE ] ||
1638 error "group_request_mask is '$group_save' expected 'RESTORE'"
1639 [ "$other_save" == RESTORE ] ||
1640 error "other_request_mask is '$other_save' expected 'RESTORE'"
1642 trap cleanup_test_24c EXIT
1647 chown $RUNAS_ID:nobody $file ||
1648 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1650 set_hsm_param user_request_mask ""
1651 $RUNAS $LFS hsm_$action $file &&
1652 error "$action by user should fail"
1654 set_hsm_param user_request_mask $action
1655 $RUNAS $LFS hsm_$action $file ||
1656 error "$action by user should succeed"
1661 chown nobody:$RUNAS_GID $file ||
1662 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1664 set_hsm_param group_request_mask ""
1665 $RUNAS $LFS hsm_$action $file &&
1666 error "$action by group should fail"
1668 set_hsm_param group_request_mask $action
1669 $RUNAS $LFS hsm_$action $file ||
1670 error "$action by group should succeed"
1675 chown nobody:nobody $file ||
1676 error "cannot chown '$file' to 'nobody:nobody'"
1678 set_hsm_param other_request_mask ""
1679 $RUNAS $LFS hsm_$action $file &&
1680 error "$action by other should fail"
1682 set_hsm_param other_request_mask $action
1683 $RUNAS $LFS hsm_$action $file ||
1684 error "$action by other should succeed"
1689 run_test 24c "check that user,group,other request masks work"
1691 cleanup_test_24d() {
1693 mount -o remount,rw $MOUNT2
1697 local file1=$DIR/$tdir/$tfile
1698 local file2=$DIR2/$tdir/$tfile
1706 fid1=$(make_small $file1)
1708 trap cleanup_test_24d EXIT
1710 mount -o remount,ro $MOUNT2
1712 fid2=$(path2fid $file2)
1713 [ "$fid1" == "$fid2" ] ||
1714 error "FID mismatch '$fid1' != '$fid2'"
1716 $LFS hsm_archive $file2 &&
1717 error "archive should fail on read-only mount"
1718 check_hsm_flags $file1 "0x00000000"
1720 $LFS hsm_archive $file1
1721 wait_request_state $fid1 ARCHIVE SUCCEED
1723 $LFS hsm_release $file1
1724 $LFS hsm_restore $file2
1725 wait_request_state $fid1 RESTORE SUCCEED
1727 $LFS hsm_release $file1 || error "cannot release '$file1'"
1728 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1730 $LFS hsm_release $file2 &&
1731 error "release should fail on read-only mount"
1736 run_test 24d "check that read-only mounts are respected"
1739 # test needs a running copytool
1743 copy2archive /etc/hosts $tdir/$tfile
1745 local f=$DIR/$tdir/$tfile
1747 import_file $tdir/$tfile $f
1749 $LFS hsm_set --lost $f
1754 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1758 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1759 " (Operation not permitted)"
1762 # test needs a running copytool
1767 local f=$DIR/$tdir/$tfile
1768 local fid=$(copy_file /etc/passwd $f)
1770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1771 wait_request_state $fid ARCHIVE SUCCEED
1774 $LFS hsm_set --lost $f
1778 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1782 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1783 " (Operation not permitted)"
1786 # test needs a running copytool
1790 local f=$DIR/$tdir/$tfile
1791 local fid=$(make_large_for_progress $f)
1792 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1793 wait_request_state $fid ARCHIVE SUCCEED
1796 wait_request_state $fid REMOVE SUCCEED
1798 check_hsm_flags $f "0x00000000"
1802 run_test 26 "Remove the archive of a valid file"
1805 # test needs a running copytool
1809 make_archive $tdir/$tfile
1810 local f=$DIR/$tdir/$tfile
1811 import_file $tdir/$tfile $f
1812 local fid=$(path2fid $f)
1816 [[ $? != 0 ]] || error "Remove of a released file should fail"
1820 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1823 # test needs a running copytool
1827 local f=$DIR/$tdir/$tfile
1828 local fid=$(make_large_for_progress $f)
1829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1830 wait_request_state $fid ARCHIVE SUCCEED
1835 [[ $? != 0 ]] || error "Remove of a released file should fail"
1839 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1842 # test needs a running copytool
1846 local f=$DIR/$tdir/$tfile
1847 local fid=$(make_large_for_progress $f)
1848 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1849 wait_request_state $fid ARCHIVE SUCCEED
1858 wait_request_state $fid REMOVE SUCCEED
1862 run_test 28 "Concurrent archive/file remove"
1865 # restore at exec cannot work on agent node (because of Linux kernel
1866 # protection of executables)
1867 needclients 2 || return 0
1869 # test needs a running copytool
1873 copy2archive /bin/true $tdir/$tfile
1875 local f=$DIR/$tdir/true
1876 import_file $tdir/$tfile $f
1878 local fid=$(path2fid $f)
1880 # set no retry action mode
1886 # remove no try action mode
1890 [[ $st == 0 ]] || error "Failed to exec a released file"
1894 run_test 30a "Restore at exec (import case)"
1897 # restore at exec cannot work on agent node (because of Linux kernel
1898 # protection of executables)
1899 needclients 2 || return 0
1901 # test needs a running copytool
1905 local f=$DIR/$tdir/true
1906 local fid=$(copy_file /bin/true $f)
1908 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1909 wait_request_state $fid ARCHIVE SUCCEED
1912 # set no retry action mode
1918 # remove no try action mode
1922 [[ $st == 0 ]] || error "Failed to exec a released file"
1926 run_test 30b "Restore at exec (release case)"
1929 needclients 2 || return 0
1931 # test needs a running copytool
1935 local f=$DIR/$tdir/SLEEP
1936 local fid=$(copy_file /bin/sleep $f)
1938 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1939 wait_request_state $fid ARCHIVE SUCCEED
1941 check_hsm_flags $f "0x0000000d"
1942 # set no retry action mode
1944 do_node $CLIENT2 "$f 10" &
1948 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1950 [[ $? == 0 ]] || error "Execution failed during run"
1952 [[ $? == 0 ]] || error "Binary overwritten during exec"
1955 # remove no try action mode
1957 check_hsm_flags $f "0x00000009"
1961 run_test 30c "Update during exec of released file must fail"
1963 restore_and_check_size() {
1966 local s=$(stat -c "%s" $f)
1968 local st=$(get_hsm_flags $f)
1972 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1974 n=$(stat -c "%s" $f)
1975 # we echo in both cases to show stat is not
1977 if [[ $n != $s ]]; then
1978 echo "size seen is $n != $s"
1981 echo "size seen is right: $n == $s"
1983 st=$(get_hsm_flags $f)
1987 if [[ $cpt -lt 10 ]]; then
1990 echo " restore is too long"
1991 wait_request_state $fid RESTORE SUCCEED
1997 # test needs a running copytool
2002 make_archive $tdir/$tfile
2003 local f=$DIR/$tdir/$tfile
2004 import_file $tdir/$tfile $f
2005 local fid=$($LFS path2fid $f)
2006 HSM_ARCHIVE_PURGE=false copytool_setup
2008 restore_and_check_size $f $fid
2011 [[ $err -eq 0 ]] || error "File size changed during restore"
2015 run_test 31a "Import a large file and check size during restore"
2019 # test needs a running copytool
2024 local f=$DIR/$tdir/$tfile
2025 local fid=$(make_large_for_progress $f)
2026 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2027 wait_request_state $fid ARCHIVE SUCCEED
2030 restore_and_check_size $f $fid
2033 [[ $err -eq 0 ]] || error "File size changed during restore"
2037 run_test 31b "Restore a large unaligned file and check size during restore"
2040 # test needs a running copytool
2045 local f=$DIR/$tdir/$tfile
2046 local fid=$(make_large_for_progress_aligned $f)
2047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2048 wait_request_state $fid ARCHIVE SUCCEED
2051 restore_and_check_size $f $fid
2054 [[ $err -eq 0 ]] || error "File size changed during restore"
2058 run_test 31c "Restore a large aligned file and check size during restore"
2061 # test needs a running copytool
2066 local f=$DIR/$tdir/$tfile
2067 local fid=$(make_large_for_progress $f)
2068 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2069 wait_request_state $fid ARCHIVE SUCCEED
2072 md5sum $f >/dev/null &
2074 wait_request_state $fid RESTORE STARTED
2079 # Check restore trigger process was killed
2080 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2084 wait_request_state $fid RESTORE CANCELED
2085 wait_request_state $fid CANCEL SUCCEED
2088 error "Cannot kill process waiting for restore ($killed)"
2092 run_test 33 "Kill a restore waiting process"
2095 # test needs a running copytool
2100 local f=$DIR/$tdir/$tfile
2101 local fid=$(make_large_for_progress $f)
2102 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2103 wait_request_state $fid ARCHIVE SUCCEED
2106 md5sum $f >/dev/null &
2108 wait_request_state $fid RESTORE STARTED
2110 rm $f || error "rm $f failed"
2111 # rm must not block during restore
2112 wait_request_state $fid RESTORE STARTED
2114 wait_request_state $fid RESTORE SUCCEED
2115 # check md5sum pgm finished
2116 local there=$(ps -o pid,comm hp $pid >/dev/null)
2117 [[ -z $there ]] || error "Restore initiator does not exit"
2119 local rc=$(wait $pid)
2120 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2124 run_test 34 "Remove file during restore"
2127 # test needs a running copytool
2132 local f=$DIR/$tdir/$tfile
2133 local f1=$DIR/$tdir/$tfile-1
2134 local fid=$(make_large_for_progress $f)
2135 local fid1=$(copy_file /etc/passwd $f1)
2136 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2137 wait_request_state $fid ARCHIVE SUCCEED
2140 md5sum $f >/dev/null &
2142 wait_request_state $fid RESTORE STARTED
2144 mv $f1 $f || error "mv $f1 $f failed"
2145 # mv must not block during restore
2146 wait_request_state $fid RESTORE STARTED
2148 wait_request_state $fid RESTORE SUCCEED
2149 # check md5sum pgm finished
2150 local there=$(ps -o pid,comm hp $pid >/dev/null)
2151 [[ -z $there ]] || error "Restore initiator does not exit"
2153 local rc=$(wait $pid)
2154 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2157 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2161 run_test 35 "Overwrite file during restore"
2164 # test needs a running copytool
2169 local f=$DIR/$tdir/$tfile
2170 local fid=$(make_large_for_progress $f)
2171 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2172 wait_request_state $fid ARCHIVE SUCCEED
2175 md5sum $f >/dev/null &
2177 wait_request_state $fid RESTORE STARTED
2180 # rm must not block during restore
2181 wait_request_state $fid RESTORE STARTED
2183 wait_request_state $fid RESTORE SUCCEED
2184 # check md5sum pgm finished
2185 local there=$(ps -o pid,comm hp $pid >/dev/null)
2187 error "Restore initiator does not exit"
2189 local rc=$(wait $pid)
2191 error "Restore initiator failed with $rc"
2195 run_test 36 "Move file during restore"
2202 for n in $(seq 1 $count); do
2203 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2205 echo "$count archive requests submitted"
2209 local stream_count=4
2210 local file_count=100
2212 local f=$DIR/$tdir/$tfile
2217 for i in $(seq 1 $file_count); do
2218 for p in $(seq 1 $stream_count); do
2219 fid=$(copy_file /etc/hosts $f.$p.$i)
2223 # to be sure wait_all_done will not be mislead by previous tests
2225 wait_for_grace_delay
2227 # start archive streams in background (archive files in parallel)
2228 for p in $(seq 1 $stream_count); do
2229 multi_archive $f.$p $file_count &
2232 echo -n "Wait for all requests being enqueued..."
2238 run_test 40 "Parallel archive requests"
2241 # test needs a running copytool
2245 local f=$DIR/$tdir/$tfile
2246 local fid=$(copy_file /etc/motd $f 1)
2248 $LFS hsm_archive $f || error "could not archive file"
2249 wait_request_state $fid ARCHIVE SUCCEED
2250 check_hsm_flags $f "0x00000009"
2252 multiop_bg_pause $f O_c || error "multiop failed"
2256 client_up || client_up || true
2258 kill -USR1 $MULTIPID
2259 wait $MULTIPID || error "multiop close failed"
2261 check_hsm_flags $f "0x0000000b"
2265 run_test 52 "Opened for write file on an evicted client should be set dirty"
2268 # test needs a running copytool
2272 local f=$DIR/$tdir/$tfile
2273 local fid=$(copy_file /etc/motd $f 1)
2275 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2276 error "could not archive file"
2277 wait_request_state $fid ARCHIVE SUCCEED
2278 check_hsm_flags $f "0x00000009"
2280 multiop_bg_pause $f o_c || error "multiop failed"
2284 client_up || client_up || true
2286 kill -USR1 $MULTIPID
2287 wait $MULTIPID || error "multiop close failed"
2289 check_hsm_flags $f "0x00000009"
2293 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2296 # test needs a running copytool
2300 local f=$DIR/$tdir/$tfile
2301 local fid=$(make_small $f)
2303 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2304 error "could not archive file"
2305 wait_request_state $fid ARCHIVE STARTED
2307 check_hsm_flags $f "0x00000001"
2309 # Avoid coordinator resending this request as soon it has failed.
2314 wait_request_state $fid ARCHIVE FAILED
2316 check_hsm_flags $f "0x00000003"
2321 run_test 54 "Write during an archive cancels it"
2324 # test needs a running copytool
2328 local f=$DIR/$tdir/$tfile
2329 local fid=$(make_small $f)
2331 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2332 error "could not archive file"
2333 wait_request_state $fid ARCHIVE STARTED
2335 check_hsm_flags $f "0x00000001"
2337 # Avoid coordinator resending this request as soon it has failed.
2340 $TRUNCATE $f 1024 || error "truncate failed"
2342 wait_request_state $fid ARCHIVE FAILED
2344 check_hsm_flags $f "0x00000003"
2349 run_test 55 "Truncate during an archive cancels it"
2352 # test needs a running copytool
2356 local f=$DIR/$tdir/$tfile
2357 local fid=$(make_large_for_progress $f)
2359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2360 error "could not archive file"
2361 wait_request_state $fid ARCHIVE STARTED
2363 check_hsm_flags $f "0x00000001"
2365 # Change metadata and sync to be sure we are not changing only
2370 wait_request_state $fid ARCHIVE SUCCEED
2372 check_hsm_flags $f "0x00000009"
2376 run_test 56 "Setattr during an archive is ok"
2379 # Need one client for I/O, one for request
2380 needclients 2 || return 0
2382 # test needs a running copytool
2386 local f=$DIR/$tdir/test_archive_remote
2387 # Create a file on a remote node
2388 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2389 "count=2 conv=fsync"
2392 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2393 error "hsm_archive failed"
2394 local fid=$(path2fid $f)
2395 wait_request_state $fid ARCHIVE SUCCEED
2397 # Release and implicit restore it
2398 do_node $CLIENT2 "$LFS hsm_release $f" ||
2399 error "hsm_release failed"
2400 do_node $CLIENT2 "md5sum $f" ||
2401 error "hsm_restore failed"
2403 wait_request_state $fid RESTORE SUCCEED
2407 run_test 57 "Archive a file with dirty cache on another node"
2409 truncate_released_file() {
2413 local sz=$(stat -c %s $src_file)
2414 local f=$DIR/$tdir/$tfile
2415 local fid=$(copy_file $1 $f)
2419 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2420 error "could not archive file"
2421 wait_request_state $fid ARCHIVE SUCCEED
2423 $LFS hsm_release $f || error "could not release file"
2425 $TRUNCATE $f $trunc_to || error "truncate failed"
2428 local sz1=$(stat -c %s $f)
2429 [[ $sz1 == $trunc_to ]] ||
2430 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2433 check_hsm_flags $f "0x0000000b"
2435 local state=$(get_request_state $fid RESTORE)
2436 [[ "$state" == "SUCCEED" ]] ||
2437 error "truncate $sz does not trig restore, state = $state"
2439 $TRUNCATE $ref $trunc_to
2440 cmp $ref $f || error "file data wrong after truncate"
2446 # test needs a running copytool
2451 local sz=$(stat -c %s /etc/passwd)
2453 echo "truncate up from $sz to $((sz*2))"
2454 truncate_released_file /etc/passwd $((sz*2))
2456 echo "truncate down from $sz to $((sz/2))"
2457 truncate_released_file /etc/passwd $((sz/2))
2459 echo "truncate to 0"
2460 truncate_released_file /etc/passwd 0
2464 run_test 58 "Truncate a released file will trigger restore"
2469 local f=$DIR/$tdir/$tfile
2470 local FILELIST=/tmp/filelist.txt
2474 for i in $(seq 1 $file_count); do
2475 fid=$(copy_file /etc/hosts $f.$i)
2476 echo $f.$i >> $FILELIST
2479 # to be sure wait_all_done will not be mislead by previous tests
2481 wait_for_grace_delay
2482 $LFS hsm_archive --filelist $FILELIST ||
2483 error "cannot archive a file list"
2485 $LFS hsm_release --filelist $FILELIST ||
2486 error "cannot release a file list"
2487 $LFS hsm_restore --filelist $FILELIST ||
2488 error "cannot restore a file list"
2492 run_test 90 "Archive/restore a file list"
2494 double_verify_reset_hsm_param() {
2496 echo "Testing $HSM_PARAM.$p"
2497 local val=$(get_hsm_param $p)
2499 local val2=$(($val * 2))
2500 set_hsm_param $p $val2
2501 val=$(get_hsm_param $p)
2502 [[ $val == $val2 ]] ||
2503 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2504 echo "Set $p to 0 must failed"
2508 set_hsm_param $p $save
2510 if [[ $rc == 0 ]]; then
2511 error "we must not be able to set $HSM_PARAM.$p to 0"
2516 double_verify_reset_hsm_param loop_period
2517 double_verify_reset_hsm_param grace_delay
2518 double_verify_reset_hsm_param active_request_timeout
2519 double_verify_reset_hsm_param max_requests
2520 double_verify_reset_hsm_param default_archive_id
2522 run_test 100 "Set coordinator /proc tunables"
2529 run_test 102 "Verify coordinator control"
2532 # test needs a running copytool
2539 for i in $(seq 1 20); do
2540 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2542 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2546 echo "Current requests"
2547 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2548 $HSM_PARAM.actions |\
2549 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2551 [[ -z "$res" ]] || error "Some request have not been canceled"
2555 run_test 103 "Purge all requests"
2560 # test needs a running copytool
2564 local f=$DIR/$tdir/$tfile
2565 local fid=$(make_large_for_progress $f)
2566 # if cdt is on, it can serve too quickly the request
2568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2569 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2570 $HSM_PARAM.actions |\
2571 grep $fid | cut -f16 -d=")
2574 [[ "$data1" == "$DATAHEX" ]] ||
2575 error "Data field in records is ($data1) and not ($DATAHEX)"
2579 run_test 104 "Copy tool data field"
2586 for i in $(seq -w 1 10); do
2587 cp /etc/passwd $DIR/$tdir/$i
2588 $LFS hsm_archive $DIR/$tdir/$i
2590 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2591 $HSM_PARAM.actions |\
2592 grep WAITING | wc -l")
2595 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2596 $HSM_PARAM.actions |\
2597 grep WAITING | wc -l")
2600 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2601 error "Requests count after shutdown $reqcnt2 != "\
2602 "before shutdown $reqcnt1"
2604 run_test 105 "Restart of coordinator"
2606 get_agent_by_uuid_mdt() {
2609 local mds=mds$(($mdtidx + 1))
2610 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
2614 check_agent_registered_by_mdt() {
2617 local mds=mds$(($mdtidx + 1))
2618 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2619 if [[ ! -z "$agent" ]]; then
2620 echo "found agent $agent on $mds"
2622 error "uuid $uuid not found in agent list on $mds"
2626 check_agent_unregistered_by_mdt() {
2629 local mds=mds$(($mdtidx + 1))
2630 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2631 if [[ -z "$agent" ]]; then
2632 echo "uuid not found in agent list on $mds"
2634 error "uuid found in agent list on $mds: $agent"
2638 check_agent_registered() {
2641 for mdsno in $(seq 1 $MDSCOUNT); do
2642 check_agent_registered_by_mdt $uuid $((mdsno - 1))
2646 check_agent_unregistered() {
2649 for mdsno in $(seq 1 $MDSCOUNT); do
2650 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
2655 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2656 get_client_uuid $MOUNT | cut -d' ' -f2)
2659 check_agent_registered $uuid
2661 search_copytools || error "No copytool found"
2664 check_agent_unregistered $uuid
2667 check_agent_registered $uuid
2671 run_test 106 "Copytool register/unregister"
2674 # test needs a running copytool
2676 # create and archive file
2678 local f1=$DIR/$tdir/$tfile
2679 local fid=$(copy_file /etc/passwd $f1)
2680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2681 wait_request_state $fid ARCHIVE SUCCEED
2682 # shutdown and restart MDS
2684 # check the copytool still gets messages from MDT
2685 local f2=$DIR/$tdir/2
2686 local fid=$(copy_file /etc/passwd $f2)
2687 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2688 # main check of this sanity: this request MUST succeed
2689 wait_request_state $fid ARCHIVE SUCCEED
2692 run_test 107 "Copytool re-register after MDS restart"
2694 policy_set_and_test()
2698 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2699 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2700 [[ "$policy" == "$target" ]] ||
2701 error "Wrong policy after '$change': '$policy' != '$target'"
2705 # to force default policy setting if error
2706 CDT_POLICY_HAD_CHANGED=true
2708 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2709 local default="NonBlockingRestore [NoRetryAction]"
2710 [[ "$policy" == "$default" ]] ||
2711 error "default policy has changed,"\
2712 " '$policy' != '$default' update the test"
2713 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2714 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2715 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2716 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2717 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2718 # useless bacause we know but safer for futur changes to use real value
2719 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2720 echo "Next set_param must failed"
2721 policy_set_and_test "wrong" "$policy"
2724 echo "Back to default policy"
2725 cdt_set_sanity_policy
2727 run_test 109 "Policy display/change"
2730 # test needs a running copytool
2735 copy2archive /etc/passwd $tdir/$tfile
2737 local f=$DIR/$tdir/$tfile
2738 import_file $tdir/$tfile $f
2739 local fid=$(path2fid $f)
2741 cdt_set_non_blocking_restore
2746 wait_request_state $fid RESTORE SUCCEED
2747 cdt_clear_non_blocking_restore
2751 error "md5sum returns $st != 1, "\
2752 "should also perror ENODATA (No data available)"
2756 run_test 110a "Non blocking restore policy (import case)"
2759 # test needs a running copytool
2763 local f=$DIR/$tdir/$tfile
2764 local fid=$(copy_file /etc/passwd $f)
2765 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2766 wait_request_state $fid ARCHIVE SUCCEED
2769 cdt_set_non_blocking_restore
2774 wait_request_state $fid RESTORE SUCCEED
2775 cdt_clear_non_blocking_restore
2779 error "md5sum returns $st != 1, "\
2780 "should also perror ENODATA (No data available)"
2784 run_test 110b "Non blocking restore policy (release case)"
2787 # test needs a running copytool
2791 copy2archive /etc/passwd $tdir/$tfile
2793 local f=$DIR/$tdir/$tfile
2795 import_file $tdir/$tfile $f
2796 local fid=$(path2fid $f)
2800 copytool_remove_backend $fid
2803 wait_request_state $fid RESTORE FAILED
2810 [[ $st == 0 ]] || error "Restore does not failed"
2814 run_test 111a "No retry policy (import case), restore will error"\
2815 " (No such file or directory)"
2818 # test needs a running copytool
2822 local f=$DIR/$tdir/$tfile
2823 local fid=$(copy_file /etc/passwd $f)
2825 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2826 wait_request_state $fid ARCHIVE SUCCEED
2829 copytool_remove_backend $fid
2832 wait_request_state $fid RESTORE FAILED
2839 [[ $st == 0 ]] || error "Restore does not failed"
2843 run_test 111b "No retry policy (release case), restore will error"\
2844 " (No such file or directory)"
2847 # test needs a running copytool
2851 local f=$DIR/$tdir/$tfile
2852 local fid=$(copy_file /etc/passwd $f)
2854 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2855 local l=$($LFS hsm_action $f)
2857 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2861 wait_request_state $fid ARCHIVE SUCCEED
2864 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2868 run_test 112 "State of recorded request"
2871 # test needs a running copytool
2875 local f=$DIR/$tdir/$tfile
2876 local fid=$(make_large_for_cancel $f)
2877 # test with cdt on is made in test_221
2879 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2882 wait_request_state $fid ARCHIVE CANCELED
2883 wait_request_state $fid CANCEL SUCCEED
2887 run_test 200 "Register/Cancel archive"
2890 # test needs a running copytool
2894 local f=$DIR/$tdir/$tfile
2895 make_archive $tdir/$tfile
2896 import_file $tdir/$tfile $f
2897 local fid=$(path2fid $f)
2899 # test with cdt on is made in test_222
2904 wait_request_state $fid RESTORE CANCELED
2905 wait_request_state $fid CANCEL SUCCEED
2909 run_test 201 "Register/Cancel restore"
2912 # test needs a running copytool
2916 local f=$DIR/$tdir/$tfile
2917 local fid=$(make_large_for_progress $f)
2918 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2919 wait_request_state $fid ARCHIVE SUCCEED
2925 wait_request_state $fid REMOVE CANCELED
2929 run_test 202 "Register/Cancel remove"
2932 # test needs a running copytool
2937 local f=$DIR/$tdir/$tfile
2938 local fid=$(copy_file /etc/passwd $f)
2942 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2943 wait_request_state $fid ARCHIVE SUCCEED
2945 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2949 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2953 run_test 220 "Changelog for archive"
2956 # test needs a running copytool
2961 local f=$DIR/$tdir/$tfile
2962 local fid=$(make_large_for_cancel $f)
2966 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2967 wait_request_state $fid ARCHIVE STARTED
2969 wait_request_state $fid ARCHIVE CANCELED
2970 wait_request_state $fid CANCEL SUCCEED
2972 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2975 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2979 run_test 221 "Changelog for archive canceled"
2982 # test needs a running copytool
2986 copy2archive /etc/passwd $tdir/$tfile
2988 local f=$DIR/$tdir/$tfile
2989 import_file $tdir/$tfile $f
2990 local fid=$(path2fid $f)
2995 wait_request_state $fid RESTORE SUCCEED
2997 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3000 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3004 run_test 222a "Changelog for explicit restore"
3007 # test needs a running copytool
3011 local f=$DIR/$tdir/$tfile
3012 local fid=$(copy_file /etc/passwd $f)
3015 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3016 wait_request_state $fid ARCHIVE SUCCEED
3021 wait_request_state $fid RESTORE SUCCEED
3023 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3026 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3030 run_test 222b "Changelog for implicit restore"
3033 # test needs a running copytool
3038 local f=$DIR/$tdir/$tfile
3039 make_archive $tdir/$tfile
3043 import_file $tdir/$tfile $f
3044 local fid=$(path2fid $f)
3047 wait_request_state $fid RESTORE STARTED
3049 wait_request_state $fid RESTORE CANCELED
3050 wait_request_state $fid CANCEL SUCCEED
3052 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3055 [[ $flags == $target ]] ||
3056 error "Changelog flag is $flags not $target"
3060 run_test 223a "Changelog for restore canceled (import case)"
3063 # test needs a running copytool
3068 local f=$DIR/$tdir/$tfile
3069 local fid=$(make_large_for_progress $f)
3072 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3073 wait_request_state $fid ARCHIVE SUCCEED
3076 wait_request_state $fid RESTORE STARTED
3078 wait_request_state $fid RESTORE CANCELED
3079 wait_request_state $fid CANCEL SUCCEED
3081 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3084 [[ $flags == $target ]] ||
3085 error "Changelog flag is $flags not $target"
3089 run_test 223b "Changelog for restore canceled (release case)"
3092 # test needs a running copytool
3097 local f=$DIR/$tdir/$tfile
3098 local fid=$(copy_file /etc/passwd $f)
3101 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3102 wait_request_state $fid ARCHIVE SUCCEED
3105 wait_request_state $fid REMOVE SUCCEED
3107 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3110 [[ $flags == $target ]] ||
3111 error "Changelog flag is $flags not $target"
3115 run_test 224 "Changelog for remove"
3118 # test needs a running copytool
3121 # test is not usable because remove request is too fast
3122 # so it is always finished before cancel can be done ...
3123 echo "Test disabled"
3128 local f=$DIR/$tdir/$tfile
3129 local fid=$(make_large_for_progress $f)
3132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3133 wait_request_state $fid ARCHIVE SUCCEED
3135 # if cdt is on, it can serve too quickly the request
3140 wait_request_state $fid REMOVE CANCELED
3141 wait_request_state $fid CANCEL SUCCEED
3143 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3144 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3145 tail -n 1 | awk '{print $5}')
3148 [[ $flags == $target ]] ||
3149 error "Changelog flag is $flags not $target"
3153 run_test 225 "Changelog for remove canceled"
3156 # test needs a running copytool
3161 local f1=$DIR/$tdir/$tfile-1
3162 local f2=$DIR/$tdir/$tfile-2
3163 local f3=$DIR/$tdir/$tfile-3
3164 local fid1=$(copy_file /etc/passwd $f1)
3165 local fid2=$(copy_file /etc/passwd $f2)
3166 copy_file /etc/passwd $f3
3169 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3170 wait_request_state $fid1 ARCHIVE SUCCEED
3172 $LFS hsm_archive $f2
3173 wait_request_state $fid2 ARCHIVE SUCCEED
3175 rm $f1 || error "rm $f1 failed"
3177 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3180 [[ $flags == $target ]] ||
3181 error "Changelog flag is $flags not $target"
3183 mv $f3 $f2 || error "mv $f3 $f2 failed"
3185 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3188 [[ $flags == $target ]] ||
3189 error "Changelog flag is $flags not $target"
3193 run_test 226 "changelog for last rm/mv with exiting archive"
3195 check_flags_changes() {
3203 $LFS hsm_set --$hsm_flag $f ||
3204 error "Cannot set $hsm_flag on $f"
3205 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3206 local seen=${#flags[*]}
3208 [[ $seen == $cnt ]] ||
3209 error "set $hsm_flag: Changelog events $seen != $cnt"
3210 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3211 error "set $hsm_flag: Changelog flags are "\
3212 "${flags[$((cnt - 1))]} not $target"
3214 $LFS hsm_clear --$hsm_flag $f ||
3215 error "Cannot clear $hsm_flag on $f"
3216 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3219 [[ $cnt == $seen ]] ||
3220 error "clear $hsm_flag: Changelog events $seen != $cnt"
3222 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3223 error "clear $hsm_flag: Changelog flag is "\
3224 "${flags[$((cnt - 1))]} not $target"
3228 # test needs a running copytool
3235 for i in norelease noarchive exists archived
3237 local f=$DIR/$tdir/$tfile-$i
3238 local fid=$(copy_file /etc/passwd $f)
3239 check_flags_changes $f $fid $i 0 1
3242 f=$DIR/$tdir/$tfile---lost
3243 fid=$(copy_file /etc/passwd $f)
3244 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3245 wait_request_state $fid ARCHIVE SUCCEED
3246 check_flags_changes $f $fid lost 3 1
3250 run_test 227 "changelog when explicit setting of HSM flags"
3253 # test needs a running copytool
3256 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3257 error "creating $DIR/$tfile"
3258 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3259 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3261 $LFS hsm_release $DIR/$tfile
3262 check_hsm_flags $DIR/$tfile "0x0000000d"
3264 filefrag $DIR/$tfile | grep " 1 extent found" ||
3265 error "filefrag on released file must return only one extent"
3267 # only newer versions of cp detect sparse files by stat/FIEMAP
3269 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3270 error "copying $DIR/$tfile"
3271 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3273 $LFS hsm_release $DIR/$tfile
3274 check_hsm_flags $DIR/$tfile "0x0000000d"
3278 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3280 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3281 error "comparing untarred $DIR/$tfile"
3285 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3288 # test needs a running copytool
3292 local maxrequest=$(get_hsm_param max_requests)
3293 local rqcnt=$(($maxrequest * 3))
3297 for i in $(seq -w 1 $rqcnt); do
3299 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3301 # we do it in 2 steps, so all requests arrive at the same time
3302 for i in $(seq -w 1 $rqcnt); do
3303 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3308 while [[ $cnt != 0 || $wt != 0 ]]; do
3310 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3311 $HSM_PARAM.actions |\
3312 grep STARTED | grep -v CANCEL | wc -l")
3313 [[ $cnt -le $maxrequest ]] ||
3314 error "$cnt > $maxrequest too many started requests"
3315 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3316 $HSM_PARAM.actions |\
3317 grep WAITING | wc -l")
3318 echo "max=$maxrequest started=$cnt waiting=$wt"
3323 run_test 250 "Coordinator max request"
3326 # test needs a running copytool
3330 local f=$DIR/$tdir/$tfile
3331 local fid=$(make_large_for_cancel $f)
3334 # to have a short test
3335 local old_to=$(get_hsm_param active_request_timeout)
3336 set_hsm_param active_request_timeout 4
3337 # to be sure the cdt will wake up frequently so
3338 # it will be able to cancel the "old" request
3339 local old_loop=$(get_hsm_param loop_period)
3340 set_hsm_param loop_period 2
3343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3344 wait_request_state $fid ARCHIVE STARTED
3346 wait_request_state $fid ARCHIVE CANCELED
3348 set_hsm_param active_request_timeout $old_to
3349 set_hsm_param loop_period $old_loop
3353 run_test 251 "Coordinator request timeout"
3356 # the only way to test ondisk conf is to restart MDS ...
3357 echo "Stop coordinator and remove coordinator state at mount"
3360 # clean on disk conf set by default
3361 cdt_clear_mount_state
3362 cdt_check_state stopped
3364 # check cdt still off after umount/remount
3366 cdt_check_state stopped
3368 echo "Set coordinator start at mount, and start coordinator"
3369 cdt_set_mount_state enabled
3372 cdt_check_state enabled
3374 # check cdt still on after umount/remount
3376 cdt_check_state enabled
3378 # we are back to original state (cdt started at mount)
3380 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3383 local ai=$(get_hsm_param default_archive_id)
3384 local new=$((ai + 1))
3386 set_hsm_param default_archive_id $new -P
3388 local res=$(get_hsm_param default_archive_id)
3391 set_hsm_param default_archive_id "" "-P -d"
3393 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3395 run_test 301 "HSM tunnable are persistent"
3398 local ai=$(get_hsm_param default_archive_id)
3399 local new=$((ai + 1))
3404 set_hsm_param default_archive_id $new -P
3407 for mdtno in $(seq 1 $MDSCOUNT); do
3412 cdt_check_state enabled
3414 local res=$(get_hsm_param default_archive_id)
3417 set_hsm_param default_archive_id "" "-P -d"
3419 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3421 run_test 302 "HSM tunnable are persistent when CDT is off"
3424 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3430 local dir_mdt0=$DIR/$tdir/mdt0
3431 local dir_mdt1=$DIR/$tdir/mdt1
3433 # create 1 dir per MDT
3434 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3435 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3437 # create 1 file in each MDT
3438 local fid1=$(make_small $dir_mdt0/$tfile)
3439 local fid2=$(make_small $dir_mdt1/$tfile)
3441 # check that hsm request on mdt0 is sent to the right MDS
3442 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3443 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3444 echo "archive successful on mdt0"
3446 # check that hsm request on mdt1 is sent to the right MDS
3447 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3448 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3449 echo "archive successful on mdt1"
3452 # clean test files and directories
3453 rm -rf $dir_mdt0 $dir_mdt1
3455 run_test 400 "Single request is sent to the right MDT"
3458 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3464 local dir_mdt0=$DIR/$tdir/mdt0
3465 local dir_mdt1=$DIR/$tdir/mdt1
3467 # create 1 dir per MDT
3468 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3469 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3471 # create 1 file in each MDT
3472 local fid1=$(make_small $dir_mdt0/$tfile)
3473 local fid2=$(make_small $dir_mdt1/$tfile)
3475 # check that compound requests are shunt to the rights MDTs
3476 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3477 error "lfs hsm_archive"
3478 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3479 echo "archive successful on mdt0"
3480 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3481 echo "archive successful on mdt1"
3484 # clean test files and directories
3485 rm -rf $dir_mdt0 $dir_mdt1
3487 run_test 401 "Compound requests split and sent to their respective MDTs"
3489 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3494 local node=$(facet_active_host $facet)
3496 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3497 awk '{print $4}'); do
3498 echo "$3 $mdc on $node"
3499 do_facet $facet "$LCTL --device $mdc $state" || return 1
3504 # make sure there is no running copytool
3507 # deactivate all mdc on agent1
3508 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3510 copytool_setup $SINGLEAGT
3512 check_agent_unregistered "uuid" # match any agent
3514 # no expected running copytool
3515 search_copytools $agent && error "Copytool start should have failed"
3518 mdc_change_state $SINGLEAGT "MDT000." "activate"
3520 run_test 402 "Copytool start fails if all MDTs are inactive"
3523 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3525 # make sure there is no running copytool
3528 local agent=$(facet_active_host $SINGLEAGT)
3529 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3531 # deactivate all mdc for MDT0001
3532 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3535 # check the agent is registered on MDT0000, and not on MDT0001
3536 check_agent_registered_by_mdt $uuid 0
3537 check_agent_unregistered_by_mdt $uuid 1
3539 # check running copytool process
3540 search_copytools $agent || error "No running copytools on $agent"
3542 # reactivate all mdc for MDT0001
3543 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3545 # make sure the copytool is now registered to all MDTs
3546 check_agent_registered $uuid
3550 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3553 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3557 # create files on both MDT0000 and MDT0001
3560 local dir_mdt0=$DIR/$tdir/mdt0
3561 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3563 # create 1 file on mdt0
3564 local fid1=$(make_small $dir_mdt0/$tfile)
3566 # deactivate all mdc for MDT0001
3567 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3569 # send an HSM request for files in MDT0000
3570 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3572 # check for completion of files in MDT0000
3573 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3574 echo "archive successful on mdt0"
3576 # reactivate all mdc for MDT0001
3577 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3580 # clean test files and directories
3583 run_test 404 "Inactive MDT does not block requests for active MDTs"
3588 check_and_cleanup_lustre