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 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1347 # used until file is flushed to disk
1348 if [ $(facet_fstype ost1) == "zfs" ]; then
1349 # this causes an OST_SYNC rpc to be sent
1350 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1351 # clear locks to reread file data
1352 cancel_lru_locks osc
1355 local orig_size=$(stat -c "%s" $f)
1356 local orig_blocks=$(stat -c "%b" $f)
1358 start_full_debug_logging
1360 $LFS hsm_archive $f || error "could not archive file"
1361 wait_request_state $fid ARCHIVE SUCCEED
1363 local blocks=$(stat -c "%b" $f)
1364 [ $blocks -eq $orig_blocks ] ||
1365 error "$f: wrong block number after archive: " \
1366 "$blocks != $orig_blocks"
1367 local size=$(stat -c "%s" $f)
1368 [ $size -eq $orig_size ] ||
1369 error "$f: wrong size after archive: $size != $orig_size"
1371 # Release and check states
1372 $LFS hsm_release $f || error "could not release file"
1373 check_hsm_flags $f "0x0000000d"
1375 blocks=$(stat -c "%b" $f)
1376 [ $blocks -gt 5 ] &&
1377 error "$f: too many blocks after release: $blocks > 5"
1378 size=$(stat -c "%s" $f)
1379 [ $size -ne $orig_size ] &&
1380 error "$f: wrong size after release: $size != $orig_size"
1382 # Check we can release an file without stripe info
1386 check_hsm_flags $f "0x00000000"
1387 $LFS hsm_archive $f || error "could not archive file"
1388 wait_request_state $fid ARCHIVE SUCCEED
1390 # Release and check states
1391 $LFS hsm_release $f || error "could not release file"
1392 check_hsm_flags $f "0x0000000d"
1394 # Release again a file that is already released is OK
1395 $LFS hsm_release $f || fail "second release should succeed"
1396 check_hsm_flags $f "0x0000000d"
1398 stop_full_debug_logging
1402 run_test 21 "Simple release tests"
1405 # test needs a running copytool
1410 local f=$DIR/$tdir/test_release
1411 local swap=$DIR/$tdir/test_swap
1413 # Create a file and check its states
1414 local fid=$(make_small $f)
1415 check_hsm_flags $f "0x00000000"
1417 $LFS hsm_archive $f || error "could not archive file"
1418 wait_request_state $fid ARCHIVE SUCCEED
1420 # Release and check states
1421 $LFS hsm_release $f || error "could not release file"
1422 check_hsm_flags $f "0x0000000d"
1425 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1430 run_test 22 "Could not swap a release file"
1433 # test needs a running copytool
1438 local f=$DIR/$tdir/test_mtime
1440 # Create a file and check its states
1441 local fid=$(make_small $f)
1442 check_hsm_flags $f "0x00000000"
1444 $LFS hsm_archive $f || error "could not archive file"
1445 wait_request_state $fid ARCHIVE SUCCEED
1447 # Set modification time in the past
1448 touch -m -a -d @978261179 $f
1450 # Release and check states
1451 $LFS hsm_release $f || error "could not release file"
1452 check_hsm_flags $f "0x0000000d"
1454 local MTIME=$(stat -c "%Y" $f)
1455 local ATIME=$(stat -c "%X" $f)
1456 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1457 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1461 run_test 23 "Release does not change a/mtime (utime)"
1464 local file=$DIR/$tdir/$tfile
1473 # test needs a running copytool
1478 fid=$(make_small $file)
1480 # Create a file and check its states
1481 check_hsm_flags $file "0x00000000"
1483 # Ensure atime is less than mtime and ctime.
1487 atime0=$(stat -c "%X" $file)
1488 mtime0=$(stat -c "%Y" $file)
1489 ctime0=$(stat -c "%Z" $file)
1491 [ $atime0 -lt $mtime0 ] ||
1492 error "atime $atime0 is not less than mtime $mtime0"
1494 [ $atime0 -lt $ctime0 ] ||
1495 error "atime $atime0 is not less than ctime $ctime0"
1497 # Archive should not change any timestamps.
1498 $LFS hsm_archive $file || error "cannot archive '$file'"
1499 wait_request_state $fid ARCHIVE SUCCEED
1501 atime1=$(stat -c "%X" $file)
1502 mtime1=$(stat -c "%Y" $file)
1503 ctime1=$(stat -c "%Z" $file)
1505 [ $atime0 -eq $atime1 ] ||
1506 error "archive changed atime from $atime0 to $atime1"
1508 [ $mtime0 -eq $mtime1 ] ||
1509 error "archive changed mtime from $mtime0 to $mtime1"
1511 [ $ctime0 -eq $ctime1 ] ||
1512 error "archive changed ctime from $ctime0 to $ctime1"
1514 # Release should not change any timestamps.
1515 $LFS hsm_release $file || error "cannot release '$file'"
1516 check_hsm_flags $file "0x0000000d"
1518 atime1=$(stat -c "%X" $file)
1519 mtime1=$(stat -c "%Y" $file)
1520 ctime1=$(stat -c "%Z" $file)
1522 [ $atime0 -eq $atime1 ] ||
1523 error "release changed atime from $atime0 to $atime1"
1525 [ $mtime0 -eq $mtime1 ] ||
1526 error "release changed mtime from $mtime0 to $mtime1"
1528 [ $ctime0 -eq $ctime1 ] ||
1529 error "release changed ctime from $ctime0 to $ctime1"
1531 # Restore should not change atime or mtime and should not
1533 $LFS hsm_restore $file
1534 wait_request_state $fid RESTORE SUCCEED
1536 atime1=$(stat -c "%X" $file)
1537 mtime1=$(stat -c "%Y" $file)
1538 ctime1=$(stat -c "%Z" $file)
1540 [ $atime0 -eq $atime1 ] ||
1541 error "restore changed atime from $atime0 to $atime1"
1543 [ $mtime0 -eq $mtime1 ] ||
1544 error "restore changed mtime from $mtime0 to $mtime1"
1546 [ $ctime0 -le $ctime1 ] ||
1547 error "restore changed ctime from $ctime0 to $ctime1"
1551 # Once more, after unmount and mount.
1552 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1553 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1555 atime1=$(stat -c "%X" $file)
1556 mtime1=$(stat -c "%Y" $file)
1557 ctime1=$(stat -c "%Z" $file)
1559 [ $atime0 -eq $atime1 ] ||
1560 error "remount changed atime from $atime0 to $atime1"
1562 [ $mtime0 -eq $mtime1 ] ||
1563 error "remount changed mtime from $mtime0 to $mtime1"
1565 [ $ctime0 -le $ctime1 ] ||
1566 error "remount changed ctime from $ctime0 to $ctime1"
1568 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1571 local file=$DIR/$tdir/$tfile
1577 # Test needs a running copytool.
1581 # Check that root can do HSM actions on a ordinary user's file.
1583 fid=$(make_small $file)
1584 sum0=$(md5sum $file)
1586 chown $RUNAS_ID:$RUNAS_GID $file ||
1587 error "cannot chown '$file' to '$RUNAS_ID'"
1589 chmod ugo-w $DIR/$tdir ||
1590 error "cannot chmod '$DIR/$tdir'"
1592 $LFS hsm_archive $file
1593 wait_request_state $fid ARCHIVE SUCCEED
1595 $LFS hsm_release $file
1596 check_hsm_flags $file "0x0000000d"
1598 $LFS hsm_restore $file
1599 wait_request_state $fid RESTORE SUCCEED
1601 # Check that ordinary user can get HSM state.
1602 $RUNAS $LFS hsm_state $file ||
1603 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1605 $LFS hsm_release $file
1606 check_hsm_flags $file "0x0000000d"
1608 # Check that ordinary user can accessed released file.
1609 sum1=$($RUNAS md5sum $file) ||
1610 error "user '$RUNAS_ID' cannot read '$file'"
1612 [ "$sum0" == "$sum1" ] ||
1613 error "md5sum mismatch for '$file'"
1617 run_test 24b "root can archive, release, and restore user files"
1619 cleanup_test_24c() {
1621 set_hsm_param user_request_mask RESTORE
1622 set_hsm_param group_request_mask RESTORE
1623 set_hsm_param other_request_mask RESTORE
1627 local file=$DIR/$tdir/$tfile
1628 local action=archive
1633 # test needs a running copytool
1638 # Save the default masks and check that cleanup_24c will
1639 # restore the request masks correctly.
1640 user_save=$(get_hsm_param user_request_mask)
1641 group_save=$(get_hsm_param group_request_mask)
1642 other_save=$(get_hsm_param other_request_mask)
1644 [ "$user_save" == RESTORE ] ||
1645 error "user_request_mask is '$user_save' expected 'RESTORE'"
1646 [ "$group_save" == RESTORE ] ||
1647 error "group_request_mask is '$group_save' expected 'RESTORE'"
1648 [ "$other_save" == RESTORE ] ||
1649 error "other_request_mask is '$other_save' expected 'RESTORE'"
1651 trap cleanup_test_24c EXIT
1656 chown $RUNAS_ID:nobody $file ||
1657 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1659 set_hsm_param user_request_mask ""
1660 $RUNAS $LFS hsm_$action $file &&
1661 error "$action by user should fail"
1663 set_hsm_param user_request_mask $action
1664 $RUNAS $LFS hsm_$action $file ||
1665 error "$action by user should succeed"
1670 chown nobody:$RUNAS_GID $file ||
1671 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1673 set_hsm_param group_request_mask ""
1674 $RUNAS $LFS hsm_$action $file &&
1675 error "$action by group should fail"
1677 set_hsm_param group_request_mask $action
1678 $RUNAS $LFS hsm_$action $file ||
1679 error "$action by group should succeed"
1684 chown nobody:nobody $file ||
1685 error "cannot chown '$file' to 'nobody:nobody'"
1687 set_hsm_param other_request_mask ""
1688 $RUNAS $LFS hsm_$action $file &&
1689 error "$action by other should fail"
1691 set_hsm_param other_request_mask $action
1692 $RUNAS $LFS hsm_$action $file ||
1693 error "$action by other should succeed"
1698 run_test 24c "check that user,group,other request masks work"
1700 cleanup_test_24d() {
1702 mount -o remount,rw $MOUNT2
1706 local file1=$DIR/$tdir/$tfile
1707 local file2=$DIR2/$tdir/$tfile
1715 fid1=$(make_small $file1)
1717 trap cleanup_test_24d EXIT
1719 mount -o remount,ro $MOUNT2
1721 fid2=$(path2fid $file2)
1722 [ "$fid1" == "$fid2" ] ||
1723 error "FID mismatch '$fid1' != '$fid2'"
1725 $LFS hsm_archive $file2 &&
1726 error "archive should fail on read-only mount"
1727 check_hsm_flags $file1 "0x00000000"
1729 $LFS hsm_archive $file1
1730 wait_request_state $fid1 ARCHIVE SUCCEED
1732 $LFS hsm_release $file1
1733 $LFS hsm_restore $file2
1734 wait_request_state $fid1 RESTORE SUCCEED
1736 $LFS hsm_release $file1 || error "cannot release '$file1'"
1737 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1739 $LFS hsm_release $file2 &&
1740 error "release should fail on read-only mount"
1745 run_test 24d "check that read-only mounts are respected"
1748 # test needs a running copytool
1752 copy2archive /etc/hosts $tdir/$tfile
1754 local f=$DIR/$tdir/$tfile
1756 import_file $tdir/$tfile $f
1758 $LFS hsm_set --lost $f
1763 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1767 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1768 " (Operation not permitted)"
1771 # test needs a running copytool
1776 local f=$DIR/$tdir/$tfile
1777 local fid=$(copy_file /etc/passwd $f)
1779 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1780 wait_request_state $fid ARCHIVE SUCCEED
1783 $LFS hsm_set --lost $f
1787 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1791 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1792 " (Operation not permitted)"
1795 # test needs a running copytool
1799 local f=$DIR/$tdir/$tfile
1800 local fid=$(make_large_for_progress $f)
1801 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1802 wait_request_state $fid ARCHIVE SUCCEED
1805 wait_request_state $fid REMOVE SUCCEED
1807 check_hsm_flags $f "0x00000000"
1811 run_test 26 "Remove the archive of a valid file"
1814 # test needs a running copytool
1818 make_archive $tdir/$tfile
1819 local f=$DIR/$tdir/$tfile
1820 import_file $tdir/$tfile $f
1821 local fid=$(path2fid $f)
1825 [[ $? != 0 ]] || error "Remove of a released file should fail"
1829 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1832 # test needs a running copytool
1836 local f=$DIR/$tdir/$tfile
1837 local fid=$(make_large_for_progress $f)
1838 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1839 wait_request_state $fid ARCHIVE SUCCEED
1844 [[ $? != 0 ]] || error "Remove of a released file should fail"
1848 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1851 # test needs a running copytool
1855 local f=$DIR/$tdir/$tfile
1856 local fid=$(make_large_for_progress $f)
1857 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1858 wait_request_state $fid ARCHIVE SUCCEED
1867 wait_request_state $fid REMOVE SUCCEED
1871 run_test 28 "Concurrent archive/file remove"
1874 # restore at exec cannot work on agent node (because of Linux kernel
1875 # protection of executables)
1876 needclients 2 || return 0
1878 # test needs a running copytool
1882 copy2archive /bin/true $tdir/$tfile
1884 local f=$DIR/$tdir/true
1885 import_file $tdir/$tfile $f
1887 local fid=$(path2fid $f)
1889 # set no retry action mode
1895 # remove no try action mode
1899 [[ $st == 0 ]] || error "Failed to exec a released file"
1903 run_test 30a "Restore at exec (import case)"
1906 # restore at exec cannot work on agent node (because of Linux kernel
1907 # protection of executables)
1908 needclients 2 || return 0
1910 # test needs a running copytool
1914 local f=$DIR/$tdir/true
1915 local fid=$(copy_file /bin/true $f)
1917 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1918 wait_request_state $fid ARCHIVE SUCCEED
1921 # set no retry action mode
1927 # remove no try action mode
1931 [[ $st == 0 ]] || error "Failed to exec a released file"
1935 run_test 30b "Restore at exec (release case)"
1938 needclients 2 || return 0
1940 # test needs a running copytool
1944 local f=$DIR/$tdir/SLEEP
1945 local fid=$(copy_file /bin/sleep $f)
1947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1948 wait_request_state $fid ARCHIVE SUCCEED
1950 check_hsm_flags $f "0x0000000d"
1951 # set no retry action mode
1953 do_node $CLIENT2 "$f 10" &
1957 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1959 [[ $? == 0 ]] || error "Execution failed during run"
1961 [[ $? == 0 ]] || error "Binary overwritten during exec"
1964 # remove no try action mode
1966 check_hsm_flags $f "0x00000009"
1970 run_test 30c "Update during exec of released file must fail"
1972 restore_and_check_size() {
1975 local s=$(stat -c "%s" $f)
1977 local st=$(get_hsm_flags $f)
1981 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1983 n=$(stat -c "%s" $f)
1984 # we echo in both cases to show stat is not
1986 if [[ $n != $s ]]; then
1987 echo "size seen is $n != $s"
1990 echo "size seen is right: $n == $s"
1992 st=$(get_hsm_flags $f)
1996 if [[ $cpt -lt 10 ]]; then
1999 echo " restore is too long"
2000 wait_request_state $fid RESTORE SUCCEED
2006 # test needs a running copytool
2011 make_archive $tdir/$tfile
2012 local f=$DIR/$tdir/$tfile
2013 import_file $tdir/$tfile $f
2014 local fid=$($LFS path2fid $f)
2015 HSM_ARCHIVE_PURGE=false copytool_setup
2017 restore_and_check_size $f $fid
2020 [[ $err -eq 0 ]] || error "File size changed during restore"
2024 run_test 31a "Import a large file and check size during restore"
2028 # test needs a running copytool
2033 local f=$DIR/$tdir/$tfile
2034 local fid=$(make_large_for_progress $f)
2035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2036 wait_request_state $fid ARCHIVE SUCCEED
2039 restore_and_check_size $f $fid
2042 [[ $err -eq 0 ]] || error "File size changed during restore"
2046 run_test 31b "Restore a large unaligned file and check size during restore"
2049 # test needs a running copytool
2054 local f=$DIR/$tdir/$tfile
2055 local fid=$(make_large_for_progress_aligned $f)
2056 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2057 wait_request_state $fid ARCHIVE SUCCEED
2060 restore_and_check_size $f $fid
2063 [[ $err -eq 0 ]] || error "File size changed during restore"
2067 run_test 31c "Restore a large aligned file and check size during restore"
2070 # test needs a running copytool
2075 local f=$DIR/$tdir/$tfile
2076 local fid=$(make_large_for_progress $f)
2077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2078 wait_request_state $fid ARCHIVE SUCCEED
2081 md5sum $f >/dev/null &
2083 wait_request_state $fid RESTORE STARTED
2088 # Check restore trigger process was killed
2089 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2093 wait_request_state $fid RESTORE CANCELED
2094 wait_request_state $fid CANCEL SUCCEED
2097 error "Cannot kill process waiting for restore ($killed)"
2101 run_test 33 "Kill a restore waiting process"
2104 # test needs a running copytool
2109 local f=$DIR/$tdir/$tfile
2110 local fid=$(make_large_for_progress $f)
2111 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2112 wait_request_state $fid ARCHIVE SUCCEED
2115 md5sum $f >/dev/null &
2117 wait_request_state $fid RESTORE STARTED
2119 rm $f || error "rm $f failed"
2120 # rm must not block during restore
2121 wait_request_state $fid RESTORE STARTED
2123 wait_request_state $fid RESTORE SUCCEED
2124 # check md5sum pgm finished
2125 local there=$(ps -o pid,comm hp $pid >/dev/null)
2126 [[ -z $there ]] || error "Restore initiator does not exit"
2128 local rc=$(wait $pid)
2129 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2133 run_test 34 "Remove file during restore"
2136 # test needs a running copytool
2141 local f=$DIR/$tdir/$tfile
2142 local f1=$DIR/$tdir/$tfile-1
2143 local fid=$(make_large_for_progress $f)
2144 local fid1=$(copy_file /etc/passwd $f1)
2145 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2146 wait_request_state $fid ARCHIVE SUCCEED
2149 md5sum $f >/dev/null &
2151 wait_request_state $fid RESTORE STARTED
2153 mv $f1 $f || error "mv $f1 $f failed"
2154 # mv must not block during restore
2155 wait_request_state $fid RESTORE STARTED
2157 wait_request_state $fid RESTORE SUCCEED
2158 # check md5sum pgm finished
2159 local there=$(ps -o pid,comm hp $pid >/dev/null)
2160 [[ -z $there ]] || error "Restore initiator does not exit"
2162 local rc=$(wait $pid)
2163 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2166 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2170 run_test 35 "Overwrite file during restore"
2173 # test needs a running copytool
2178 local f=$DIR/$tdir/$tfile
2179 local fid=$(make_large_for_progress $f)
2180 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2181 wait_request_state $fid ARCHIVE SUCCEED
2184 md5sum $f >/dev/null &
2186 wait_request_state $fid RESTORE STARTED
2189 # rm must not block during restore
2190 wait_request_state $fid RESTORE STARTED
2192 wait_request_state $fid RESTORE SUCCEED
2193 # check md5sum pgm finished
2194 local there=$(ps -o pid,comm hp $pid >/dev/null)
2196 error "Restore initiator does not exit"
2198 local rc=$(wait $pid)
2200 error "Restore initiator failed with $rc"
2204 run_test 36 "Move file during restore"
2211 for n in $(seq 1 $count); do
2212 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2214 echo "$count archive requests submitted"
2218 local stream_count=4
2219 local file_count=100
2221 local f=$DIR/$tdir/$tfile
2226 for i in $(seq 1 $file_count); do
2227 for p in $(seq 1 $stream_count); do
2228 fid=$(copy_file /etc/hosts $f.$p.$i)
2232 # to be sure wait_all_done will not be mislead by previous tests
2234 wait_for_grace_delay
2236 # start archive streams in background (archive files in parallel)
2237 for p in $(seq 1 $stream_count); do
2238 multi_archive $f.$p $file_count &
2241 echo -n "Wait for all requests being enqueued..."
2247 run_test 40 "Parallel archive requests"
2250 # test needs a running copytool
2254 local f=$DIR/$tdir/$tfile
2255 local fid=$(copy_file /etc/motd $f 1)
2257 $LFS hsm_archive $f || error "could not archive file"
2258 wait_request_state $fid ARCHIVE SUCCEED
2259 check_hsm_flags $f "0x00000009"
2261 multiop_bg_pause $f O_c || error "multiop failed"
2265 client_up || client_up || true
2267 kill -USR1 $MULTIPID
2268 wait $MULTIPID || error "multiop close failed"
2270 check_hsm_flags $f "0x0000000b"
2274 run_test 52 "Opened for write file on an evicted client should be set dirty"
2277 # test needs a running copytool
2281 local f=$DIR/$tdir/$tfile
2282 local fid=$(copy_file /etc/motd $f 1)
2284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2285 error "could not archive file"
2286 wait_request_state $fid ARCHIVE SUCCEED
2287 check_hsm_flags $f "0x00000009"
2289 multiop_bg_pause $f o_c || error "multiop failed"
2293 client_up || client_up || true
2295 kill -USR1 $MULTIPID
2296 wait $MULTIPID || error "multiop close failed"
2298 check_hsm_flags $f "0x00000009"
2302 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2305 # test needs a running copytool
2309 local f=$DIR/$tdir/$tfile
2310 local fid=$(make_small $f)
2312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2313 error "could not archive file"
2314 wait_request_state $fid ARCHIVE STARTED
2316 check_hsm_flags $f "0x00000001"
2318 # Avoid coordinator resending this request as soon it has failed.
2323 wait_request_state $fid ARCHIVE FAILED
2325 check_hsm_flags $f "0x00000003"
2330 run_test 54 "Write during an archive cancels it"
2333 # test needs a running copytool
2337 local f=$DIR/$tdir/$tfile
2338 local fid=$(make_small $f)
2340 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2341 error "could not archive file"
2342 wait_request_state $fid ARCHIVE STARTED
2344 check_hsm_flags $f "0x00000001"
2346 # Avoid coordinator resending this request as soon it has failed.
2349 $TRUNCATE $f 1024 || error "truncate failed"
2351 wait_request_state $fid ARCHIVE FAILED
2353 check_hsm_flags $f "0x00000003"
2358 run_test 55 "Truncate during an archive cancels it"
2361 # test needs a running copytool
2365 local f=$DIR/$tdir/$tfile
2366 local fid=$(make_large_for_progress $f)
2368 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2369 error "could not archive file"
2370 wait_request_state $fid ARCHIVE STARTED
2372 check_hsm_flags $f "0x00000001"
2374 # Change metadata and sync to be sure we are not changing only
2379 wait_request_state $fid ARCHIVE SUCCEED
2381 check_hsm_flags $f "0x00000009"
2385 run_test 56 "Setattr during an archive is ok"
2388 # Need one client for I/O, one for request
2389 needclients 2 || return 0
2391 # test needs a running copytool
2395 local f=$DIR/$tdir/test_archive_remote
2396 # Create a file on a remote node
2397 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2398 "count=2 conv=fsync"
2401 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2402 error "hsm_archive failed"
2403 local fid=$(path2fid $f)
2404 wait_request_state $fid ARCHIVE SUCCEED
2406 # Release and implicit restore it
2407 do_node $CLIENT2 "$LFS hsm_release $f" ||
2408 error "hsm_release failed"
2409 do_node $CLIENT2 "md5sum $f" ||
2410 error "hsm_restore failed"
2412 wait_request_state $fid RESTORE SUCCEED
2416 run_test 57 "Archive a file with dirty cache on another node"
2418 truncate_released_file() {
2422 local sz=$(stat -c %s $src_file)
2423 local f=$DIR/$tdir/$tfile
2424 local fid=$(copy_file $1 $f)
2428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2429 error "could not archive file"
2430 wait_request_state $fid ARCHIVE SUCCEED
2432 $LFS hsm_release $f || error "could not release file"
2434 $TRUNCATE $f $trunc_to || error "truncate failed"
2437 local sz1=$(stat -c %s $f)
2438 [[ $sz1 == $trunc_to ]] ||
2439 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2442 check_hsm_flags $f "0x0000000b"
2444 local state=$(get_request_state $fid RESTORE)
2445 [[ "$state" == "SUCCEED" ]] ||
2446 error "truncate $sz does not trig restore, state = $state"
2448 $TRUNCATE $ref $trunc_to
2449 cmp $ref $f || error "file data wrong after truncate"
2455 # test needs a running copytool
2460 local sz=$(stat -c %s /etc/passwd)
2462 echo "truncate up from $sz to $((sz*2))"
2463 truncate_released_file /etc/passwd $((sz*2))
2465 echo "truncate down from $sz to $((sz/2))"
2466 truncate_released_file /etc/passwd $((sz/2))
2468 echo "truncate to 0"
2469 truncate_released_file /etc/passwd 0
2473 run_test 58 "Truncate a released file will trigger restore"
2478 local f=$DIR/$tdir/$tfile
2479 local FILELIST=/tmp/filelist.txt
2483 for i in $(seq 1 $file_count); do
2484 fid=$(copy_file /etc/hosts $f.$i)
2485 echo $f.$i >> $FILELIST
2488 # to be sure wait_all_done will not be mislead by previous tests
2490 wait_for_grace_delay
2491 $LFS hsm_archive --filelist $FILELIST ||
2492 error "cannot archive a file list"
2494 $LFS hsm_release --filelist $FILELIST ||
2495 error "cannot release a file list"
2496 $LFS hsm_restore --filelist $FILELIST ||
2497 error "cannot restore a file list"
2501 run_test 90 "Archive/restore a file list"
2503 double_verify_reset_hsm_param() {
2505 echo "Testing $HSM_PARAM.$p"
2506 local val=$(get_hsm_param $p)
2508 local val2=$(($val * 2))
2509 set_hsm_param $p $val2
2510 val=$(get_hsm_param $p)
2511 [[ $val == $val2 ]] ||
2512 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2513 echo "Set $p to 0 must failed"
2517 set_hsm_param $p $save
2519 if [[ $rc == 0 ]]; then
2520 error "we must not be able to set $HSM_PARAM.$p to 0"
2525 double_verify_reset_hsm_param loop_period
2526 double_verify_reset_hsm_param grace_delay
2527 double_verify_reset_hsm_param active_request_timeout
2528 double_verify_reset_hsm_param max_requests
2529 double_verify_reset_hsm_param default_archive_id
2531 run_test 100 "Set coordinator /proc tunables"
2538 run_test 102 "Verify coordinator control"
2541 # test needs a running copytool
2548 for i in $(seq 1 20); do
2549 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2551 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2555 echo "Current requests"
2556 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2557 $HSM_PARAM.actions |\
2558 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2560 [[ -z "$res" ]] || error "Some request have not been canceled"
2564 run_test 103 "Purge all requests"
2569 # test needs a running copytool
2573 local f=$DIR/$tdir/$tfile
2574 local fid=$(make_large_for_progress $f)
2575 # if cdt is on, it can serve too quickly the request
2577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2578 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2579 $HSM_PARAM.actions |\
2580 grep $fid | cut -f16 -d=")
2583 [[ "$data1" == "$DATAHEX" ]] ||
2584 error "Data field in records is ($data1) and not ($DATAHEX)"
2588 run_test 104 "Copy tool data field"
2595 for i in $(seq -w 1 10); do
2596 cp /etc/passwd $DIR/$tdir/$i
2597 $LFS hsm_archive $DIR/$tdir/$i
2599 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2600 $HSM_PARAM.actions |\
2601 grep WAITING | wc -l")
2604 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2605 $HSM_PARAM.actions |\
2606 grep WAITING | wc -l")
2609 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2610 error "Requests count after shutdown $reqcnt2 != "\
2611 "before shutdown $reqcnt1"
2613 run_test 105 "Restart of coordinator"
2615 get_agent_by_uuid_mdt() {
2618 local mds=mds$(($mdtidx + 1))
2619 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
2623 check_agent_registered_by_mdt() {
2626 local mds=mds$(($mdtidx + 1))
2627 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2628 if [[ ! -z "$agent" ]]; then
2629 echo "found agent $agent on $mds"
2631 error "uuid $uuid not found in agent list on $mds"
2635 check_agent_unregistered_by_mdt() {
2638 local mds=mds$(($mdtidx + 1))
2639 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2640 if [[ -z "$agent" ]]; then
2641 echo "uuid not found in agent list on $mds"
2643 error "uuid found in agent list on $mds: $agent"
2647 check_agent_registered() {
2650 for mdsno in $(seq 1 $MDSCOUNT); do
2651 check_agent_registered_by_mdt $uuid $((mdsno - 1))
2655 check_agent_unregistered() {
2658 for mdsno in $(seq 1 $MDSCOUNT); do
2659 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
2664 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2665 get_client_uuid $MOUNT | cut -d' ' -f2)
2668 check_agent_registered $uuid
2670 search_copytools || error "No copytool found"
2673 check_agent_unregistered $uuid
2676 check_agent_registered $uuid
2680 run_test 106 "Copytool register/unregister"
2683 # test needs a running copytool
2685 # create and archive file
2687 local f1=$DIR/$tdir/$tfile
2688 local fid=$(copy_file /etc/passwd $f1)
2689 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2690 wait_request_state $fid ARCHIVE SUCCEED
2691 # shutdown and restart MDS
2693 # check the copytool still gets messages from MDT
2694 local f2=$DIR/$tdir/2
2695 local fid=$(copy_file /etc/passwd $f2)
2696 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2697 # main check of this sanity: this request MUST succeed
2698 wait_request_state $fid ARCHIVE SUCCEED
2701 run_test 107 "Copytool re-register after MDS restart"
2703 policy_set_and_test()
2707 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2708 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2709 [[ "$policy" == "$target" ]] ||
2710 error "Wrong policy after '$change': '$policy' != '$target'"
2714 # to force default policy setting if error
2715 CDT_POLICY_HAD_CHANGED=true
2717 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2718 local default="NonBlockingRestore [NoRetryAction]"
2719 [[ "$policy" == "$default" ]] ||
2720 error "default policy has changed,"\
2721 " '$policy' != '$default' update the test"
2722 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2723 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2724 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2725 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2726 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2727 # useless bacause we know but safer for futur changes to use real value
2728 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2729 echo "Next set_param must failed"
2730 policy_set_and_test "wrong" "$policy"
2733 echo "Back to default policy"
2734 cdt_set_sanity_policy
2736 run_test 109 "Policy display/change"
2739 # test needs a running copytool
2744 copy2archive /etc/passwd $tdir/$tfile
2746 local f=$DIR/$tdir/$tfile
2747 import_file $tdir/$tfile $f
2748 local fid=$(path2fid $f)
2750 cdt_set_non_blocking_restore
2755 wait_request_state $fid RESTORE SUCCEED
2756 cdt_clear_non_blocking_restore
2760 error "md5sum returns $st != 1, "\
2761 "should also perror ENODATA (No data available)"
2765 run_test 110a "Non blocking restore policy (import case)"
2768 # test needs a running copytool
2772 local f=$DIR/$tdir/$tfile
2773 local fid=$(copy_file /etc/passwd $f)
2774 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2775 wait_request_state $fid ARCHIVE SUCCEED
2778 cdt_set_non_blocking_restore
2783 wait_request_state $fid RESTORE SUCCEED
2784 cdt_clear_non_blocking_restore
2788 error "md5sum returns $st != 1, "\
2789 "should also perror ENODATA (No data available)"
2793 run_test 110b "Non blocking restore policy (release case)"
2796 # test needs a running copytool
2800 copy2archive /etc/passwd $tdir/$tfile
2802 local f=$DIR/$tdir/$tfile
2804 import_file $tdir/$tfile $f
2805 local fid=$(path2fid $f)
2809 copytool_remove_backend $fid
2812 wait_request_state $fid RESTORE FAILED
2819 [[ $st == 0 ]] || error "Restore does not failed"
2823 run_test 111a "No retry policy (import case), restore will error"\
2824 " (No such file or directory)"
2827 # test needs a running copytool
2831 local f=$DIR/$tdir/$tfile
2832 local fid=$(copy_file /etc/passwd $f)
2834 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2835 wait_request_state $fid ARCHIVE SUCCEED
2838 copytool_remove_backend $fid
2841 wait_request_state $fid RESTORE FAILED
2848 [[ $st == 0 ]] || error "Restore does not failed"
2852 run_test 111b "No retry policy (release case), restore will error"\
2853 " (No such file or directory)"
2856 # test needs a running copytool
2860 local f=$DIR/$tdir/$tfile
2861 local fid=$(copy_file /etc/passwd $f)
2863 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2864 local l=$($LFS hsm_action $f)
2866 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2870 wait_request_state $fid ARCHIVE SUCCEED
2873 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2877 run_test 112 "State of recorded request"
2880 # test needs a running copytool
2884 local f=$DIR/$tdir/$tfile
2885 local fid=$(make_large_for_cancel $f)
2886 # test with cdt on is made in test_221
2888 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2891 wait_request_state $fid ARCHIVE CANCELED
2892 wait_request_state $fid CANCEL SUCCEED
2896 run_test 200 "Register/Cancel archive"
2899 # test needs a running copytool
2903 local f=$DIR/$tdir/$tfile
2904 make_archive $tdir/$tfile
2905 import_file $tdir/$tfile $f
2906 local fid=$(path2fid $f)
2908 # test with cdt on is made in test_222
2913 wait_request_state $fid RESTORE CANCELED
2914 wait_request_state $fid CANCEL SUCCEED
2918 run_test 201 "Register/Cancel restore"
2921 # test needs a running copytool
2925 local f=$DIR/$tdir/$tfile
2926 local fid=$(make_large_for_progress $f)
2927 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2928 wait_request_state $fid ARCHIVE SUCCEED
2934 wait_request_state $fid REMOVE CANCELED
2938 run_test 202 "Register/Cancel remove"
2941 # test needs a running copytool
2946 local f=$DIR/$tdir/$tfile
2947 local fid=$(copy_file /etc/passwd $f)
2951 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2952 wait_request_state $fid ARCHIVE SUCCEED
2954 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2958 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2962 run_test 220 "Changelog for archive"
2965 # test needs a running copytool
2970 local f=$DIR/$tdir/$tfile
2971 local fid=$(make_large_for_cancel $f)
2975 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2976 wait_request_state $fid ARCHIVE STARTED
2978 wait_request_state $fid ARCHIVE CANCELED
2979 wait_request_state $fid CANCEL SUCCEED
2981 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2984 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2988 run_test 221 "Changelog for archive canceled"
2991 # test needs a running copytool
2995 copy2archive /etc/passwd $tdir/$tfile
2997 local f=$DIR/$tdir/$tfile
2998 import_file $tdir/$tfile $f
2999 local fid=$(path2fid $f)
3004 wait_request_state $fid RESTORE SUCCEED
3006 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3009 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3013 run_test 222a "Changelog for explicit restore"
3016 # test needs a running copytool
3020 local f=$DIR/$tdir/$tfile
3021 local fid=$(copy_file /etc/passwd $f)
3024 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3025 wait_request_state $fid ARCHIVE SUCCEED
3030 wait_request_state $fid RESTORE SUCCEED
3032 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3035 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3039 run_test 222b "Changelog for implicit restore"
3042 # test needs a running copytool
3047 local f=$DIR/$tdir/$tfile
3048 make_archive $tdir/$tfile
3052 import_file $tdir/$tfile $f
3053 local fid=$(path2fid $f)
3056 wait_request_state $fid RESTORE STARTED
3058 wait_request_state $fid RESTORE CANCELED
3059 wait_request_state $fid CANCEL SUCCEED
3061 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3064 [[ $flags == $target ]] ||
3065 error "Changelog flag is $flags not $target"
3069 run_test 223a "Changelog for restore canceled (import case)"
3072 # test needs a running copytool
3077 local f=$DIR/$tdir/$tfile
3078 local fid=$(make_large_for_progress $f)
3081 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3082 wait_request_state $fid ARCHIVE SUCCEED
3085 wait_request_state $fid RESTORE STARTED
3087 wait_request_state $fid RESTORE CANCELED
3088 wait_request_state $fid CANCEL SUCCEED
3090 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3093 [[ $flags == $target ]] ||
3094 error "Changelog flag is $flags not $target"
3098 run_test 223b "Changelog for restore canceled (release case)"
3101 # test needs a running copytool
3106 local f=$DIR/$tdir/$tfile
3107 local fid=$(copy_file /etc/passwd $f)
3110 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3111 wait_request_state $fid ARCHIVE SUCCEED
3114 wait_request_state $fid REMOVE SUCCEED
3116 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3119 [[ $flags == $target ]] ||
3120 error "Changelog flag is $flags not $target"
3124 run_test 224 "Changelog for remove"
3127 # test needs a running copytool
3130 # test is not usable because remove request is too fast
3131 # so it is always finished before cancel can be done ...
3132 echo "Test disabled"
3137 local f=$DIR/$tdir/$tfile
3138 local fid=$(make_large_for_progress $f)
3141 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3142 wait_request_state $fid ARCHIVE SUCCEED
3144 # if cdt is on, it can serve too quickly the request
3149 wait_request_state $fid REMOVE CANCELED
3150 wait_request_state $fid CANCEL SUCCEED
3152 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3153 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3154 tail -n 1 | awk '{print $5}')
3157 [[ $flags == $target ]] ||
3158 error "Changelog flag is $flags not $target"
3162 run_test 225 "Changelog for remove canceled"
3165 # test needs a running copytool
3170 local f1=$DIR/$tdir/$tfile-1
3171 local f2=$DIR/$tdir/$tfile-2
3172 local f3=$DIR/$tdir/$tfile-3
3173 local fid1=$(copy_file /etc/passwd $f1)
3174 local fid2=$(copy_file /etc/passwd $f2)
3175 copy_file /etc/passwd $f3
3178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3179 wait_request_state $fid1 ARCHIVE SUCCEED
3181 $LFS hsm_archive $f2
3182 wait_request_state $fid2 ARCHIVE SUCCEED
3184 rm $f1 || error "rm $f1 failed"
3186 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3189 [[ $flags == $target ]] ||
3190 error "Changelog flag is $flags not $target"
3192 mv $f3 $f2 || error "mv $f3 $f2 failed"
3194 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3197 [[ $flags == $target ]] ||
3198 error "Changelog flag is $flags not $target"
3202 run_test 226 "changelog for last rm/mv with exiting archive"
3204 check_flags_changes() {
3212 $LFS hsm_set --$hsm_flag $f ||
3213 error "Cannot set $hsm_flag on $f"
3214 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3215 local seen=${#flags[*]}
3217 [[ $seen == $cnt ]] ||
3218 error "set $hsm_flag: Changelog events $seen != $cnt"
3219 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3220 error "set $hsm_flag: Changelog flags are "\
3221 "${flags[$((cnt - 1))]} not $target"
3223 $LFS hsm_clear --$hsm_flag $f ||
3224 error "Cannot clear $hsm_flag on $f"
3225 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3228 [[ $cnt == $seen ]] ||
3229 error "clear $hsm_flag: Changelog events $seen != $cnt"
3231 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3232 error "clear $hsm_flag: Changelog flag is "\
3233 "${flags[$((cnt - 1))]} not $target"
3237 # test needs a running copytool
3244 for i in norelease noarchive exists archived
3246 local f=$DIR/$tdir/$tfile-$i
3247 local fid=$(copy_file /etc/passwd $f)
3248 check_flags_changes $f $fid $i 0 1
3251 f=$DIR/$tdir/$tfile---lost
3252 fid=$(copy_file /etc/passwd $f)
3253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3254 wait_request_state $fid ARCHIVE SUCCEED
3255 check_flags_changes $f $fid lost 3 1
3259 run_test 227 "changelog when explicit setting of HSM flags"
3262 # test needs a running copytool
3265 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3266 error "creating $DIR/$tfile"
3267 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3268 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3270 $LFS hsm_release $DIR/$tfile
3271 check_hsm_flags $DIR/$tfile "0x0000000d"
3273 filefrag $DIR/$tfile | grep " 1 extent found" ||
3274 error "filefrag on released file must return only one extent"
3276 # only newer versions of cp detect sparse files by stat/FIEMAP
3278 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3279 error "copying $DIR/$tfile"
3280 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3282 $LFS hsm_release $DIR/$tfile
3283 check_hsm_flags $DIR/$tfile "0x0000000d"
3287 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3289 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3290 error "comparing untarred $DIR/$tfile"
3294 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3297 # test needs a running copytool
3301 local maxrequest=$(get_hsm_param max_requests)
3302 local rqcnt=$(($maxrequest * 3))
3306 for i in $(seq -w 1 $rqcnt); do
3308 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3310 # we do it in 2 steps, so all requests arrive at the same time
3311 for i in $(seq -w 1 $rqcnt); do
3312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3317 while [[ $cnt != 0 || $wt != 0 ]]; do
3319 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3320 $HSM_PARAM.actions |\
3321 grep STARTED | grep -v CANCEL | wc -l")
3322 [[ $cnt -le $maxrequest ]] ||
3323 error "$cnt > $maxrequest too many started requests"
3324 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3325 $HSM_PARAM.actions |\
3326 grep WAITING | wc -l")
3327 echo "max=$maxrequest started=$cnt waiting=$wt"
3332 run_test 250 "Coordinator max request"
3335 # test needs a running copytool
3339 local f=$DIR/$tdir/$tfile
3340 local fid=$(make_large_for_cancel $f)
3343 # to have a short test
3344 local old_to=$(get_hsm_param active_request_timeout)
3345 set_hsm_param active_request_timeout 4
3346 # to be sure the cdt will wake up frequently so
3347 # it will be able to cancel the "old" request
3348 local old_loop=$(get_hsm_param loop_period)
3349 set_hsm_param loop_period 2
3352 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3353 wait_request_state $fid ARCHIVE STARTED
3355 wait_request_state $fid ARCHIVE CANCELED
3357 set_hsm_param active_request_timeout $old_to
3358 set_hsm_param loop_period $old_loop
3362 run_test 251 "Coordinator request timeout"
3365 # the only way to test ondisk conf is to restart MDS ...
3366 echo "Stop coordinator and remove coordinator state at mount"
3369 # clean on disk conf set by default
3370 cdt_clear_mount_state
3371 cdt_check_state stopped
3373 # check cdt still off after umount/remount
3375 cdt_check_state stopped
3377 echo "Set coordinator start at mount, and start coordinator"
3378 cdt_set_mount_state enabled
3381 cdt_check_state enabled
3383 # check cdt still on after umount/remount
3385 cdt_check_state enabled
3387 # we are back to original state (cdt started at mount)
3389 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3392 local ai=$(get_hsm_param default_archive_id)
3393 local new=$((ai + 1))
3395 set_hsm_param default_archive_id $new -P
3397 local res=$(get_hsm_param default_archive_id)
3400 set_hsm_param default_archive_id "" "-P -d"
3402 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3404 run_test 301 "HSM tunnable are persistent"
3407 local ai=$(get_hsm_param default_archive_id)
3408 local new=$((ai + 1))
3413 set_hsm_param default_archive_id $new -P
3416 for mdtno in $(seq 1 $MDSCOUNT); do
3421 cdt_check_state enabled
3423 local res=$(get_hsm_param default_archive_id)
3426 set_hsm_param default_archive_id "" "-P -d"
3428 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3430 run_test 302 "HSM tunnable are persistent when CDT is off"
3433 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3439 local dir_mdt0=$DIR/$tdir/mdt0
3440 local dir_mdt1=$DIR/$tdir/mdt1
3442 # create 1 dir per MDT
3443 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3444 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3446 # create 1 file in each MDT
3447 local fid1=$(make_small $dir_mdt0/$tfile)
3448 local fid2=$(make_small $dir_mdt1/$tfile)
3450 # check that hsm request on mdt0 is sent to the right MDS
3451 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3452 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3453 echo "archive successful on mdt0"
3455 # check that hsm request on mdt1 is sent to the right MDS
3456 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3457 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3458 echo "archive successful on mdt1"
3461 # clean test files and directories
3462 rm -rf $dir_mdt0 $dir_mdt1
3464 run_test 400 "Single request is sent to the right MDT"
3467 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3473 local dir_mdt0=$DIR/$tdir/mdt0
3474 local dir_mdt1=$DIR/$tdir/mdt1
3476 # create 1 dir per MDT
3477 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3478 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3480 # create 1 file in each MDT
3481 local fid1=$(make_small $dir_mdt0/$tfile)
3482 local fid2=$(make_small $dir_mdt1/$tfile)
3484 # check that compound requests are shunt to the rights MDTs
3485 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3486 error "lfs hsm_archive"
3487 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3488 echo "archive successful on mdt0"
3489 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3490 echo "archive successful on mdt1"
3493 # clean test files and directories
3494 rm -rf $dir_mdt0 $dir_mdt1
3496 run_test 401 "Compound requests split and sent to their respective MDTs"
3498 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3503 local node=$(facet_active_host $facet)
3505 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3506 awk '{print $4}'); do
3507 echo "$3 $mdc on $node"
3508 do_facet $facet "$LCTL --device $mdc $state" || return 1
3513 # make sure there is no running copytool
3516 # deactivate all mdc on agent1
3517 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3519 copytool_setup $SINGLEAGT
3521 check_agent_unregistered "uuid" # match any agent
3523 # no expected running copytool
3524 search_copytools $agent && error "Copytool start should have failed"
3527 mdc_change_state $SINGLEAGT "MDT000." "activate"
3529 run_test 402 "Copytool start fails if all MDTs are inactive"
3532 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3534 # make sure there is no running copytool
3537 local agent=$(facet_active_host $SINGLEAGT)
3538 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3540 # deactivate all mdc for MDT0001
3541 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3544 # check the agent is registered on MDT0000, and not on MDT0001
3545 check_agent_registered_by_mdt $uuid 0
3546 check_agent_unregistered_by_mdt $uuid 1
3548 # check running copytool process
3549 search_copytools $agent || error "No running copytools on $agent"
3551 # reactivate all mdc for MDT0001
3552 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3554 # make sure the copytool is now registered to all MDTs
3555 check_agent_registered $uuid
3559 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3562 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3566 # create files on both MDT0000 and MDT0001
3569 local dir_mdt0=$DIR/$tdir/mdt0
3570 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3572 # create 1 file on mdt0
3573 local fid1=$(make_small $dir_mdt0/$tfile)
3575 # deactivate all mdc for MDT0001
3576 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3578 # send an HSM request for files in MDT0000
3579 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3581 # check for completion of files in MDT0000
3582 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3583 echo "archive successful on mdt0"
3585 # reactivate all mdc for MDT0001
3586 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3589 # clean test files and directories
3592 run_test 404 "Inactive MDT does not block requests for active MDTs"
3597 check_and_cleanup_lustre