3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test: 3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MCREATE=${MCREATE:-mcreate}
30 MOUNT_2=${MOUNT_2:-"yes"}
33 # script only handles up to 10 MDTs (because of MDT_PREFIX)
34 [ $MDSCOUNT -gt 9 ] &&
35 error "script cannot handle more than 9 MDTs, please fix" && exit
37 check_and_setup_lustre
39 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
40 skip_env "Need MDS version at least 2.4.53" && exit
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
52 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
53 # the following associated variables are added:
55 # AGTCOUNT: number of agents
56 # AGTDEV{N}: target HSM mount point (root path of the backend)
57 # agt{N}_HOST: hostname of the agent agt{N}
58 # SINGLEAGT: facet of the single agent
60 # The number of agents is initialized as the number of remote client nodes.
61 # By default, only single copytool is started on a remote client/agent. If there
62 # was no remote client, then the copytool will be started on the local client.
68 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
69 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
71 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
72 if [[ $CLIENTCOUNT -gt 1 ]] &&
73 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
74 skip_env "SHARED_DIRECTORY should be accessible"\
79 for n in $(seq $AGTCOUNT); do
80 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
81 agent=CLIENT$((n + 1))
82 if [[ -z "${!agent}" ]]; then
83 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
86 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
89 export SINGLEAGT=${SINGLEAGT:-agt1}
91 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
92 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
93 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
94 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
97 # The test only support up to 10 MDTs
98 MDT_PREFIX="mdt.$FSNAME-MDT000"
99 HSM_PARAM="${MDT_PREFIX}0.hsm"
101 # archive is purged at copytool setup
102 HSM_ARCHIVE_PURGE=true
105 # Get the backend root path for the given agent facet.
108 local dev=AGTDEV$(facet_number $facet)
113 # Stop copytool and unregister an existing changelog user.
117 cdt_set_sanity_policy
122 # get MDT device for each mdc
123 for mdtno in $(seq 1 $MDSCOUNT); do
124 local idx=$(($mdtno - 1))
125 MDT[$idx]=$($LCTL get_param -n \
126 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
127 awk '{gsub(/_UUID/,""); print $1}' | head -1)
132 local agents=${1:-$(facet_active_host $SINGLEAGT)}
133 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
136 search_and_kill_copytool() {
137 local agents=${1:-$(facet_active_host $SINGLEAGT)}
139 echo "Killing existing copytools on $agents"
140 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
144 local facet=${1:-$SINGLEAGT}
145 local lustre_mntpnt=${2:-$MOUNT}
147 local hsm_root=${4:-$(copytool_device $facet)}
148 local agent=$(facet_active_host $facet)
150 if [[ -z "$arc_id" ]] &&
151 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
152 echo "Wakeup copytool $facet on $agent"
156 if $HSM_ARCHIVE_PURGE; then
157 echo "Purging archive on $agent"
158 do_facet $facet "rm -rf $hsm_root/*"
161 echo "Starting copytool $facet on $agent"
162 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
163 # bandwidth is limited to 1MB/s so the copy time is known and
164 # independent of hardware
165 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
166 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
167 cmd+=" --bandwidth 1 $lustre_mntpnt"
169 # Redirect the standard output and error to a log file which
170 # can be uploaded to Maloo.
171 local prefix=$TESTLOG_PREFIX
172 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
173 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
175 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
176 error "start copytool $facet on $agent failed"
182 local agents=${1:-$(facet_active_host $SINGLEAGT)}
188 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
190 echo "Copytool is stopped on $agents"
192 # clean all CDTs orphans requests from previous tests
193 # that would otherwise need to timeout to clear.
194 for mdtno in $(seq 1 $MDSCOUNT); do
196 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
197 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
199 # skip already stop[ed,ing] CDTs
200 echo $oldstate | grep stop && continue
202 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
203 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
205 error "mds${mdtno} cdt state is not stopped"
206 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
207 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
209 error "mds${mdtno} cdt state is not $oldstate"
214 local agents=${1:-$(facet_active_host $SINGLEAGT)}
216 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
217 echo "Copytool is suspended on $agents"
220 copytool_remove_backend() {
222 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
223 echo "Remove from backend: $fid = $be"
224 do_facet $SINGLEAGT rm -f $be
228 do_facet $SINGLEAGT \
229 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
230 --import $1 $2 $MOUNT" ||
231 error "import of $1 to $2 failed"
235 local file=$HSM_ARCHIVE/$1
236 do_facet $SINGLEAGT mkdir -p $(dirname $file)
237 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
238 error "cannot create $file"
242 local file=$HSM_ARCHIVE/$2
243 do_facet $SINGLEAGT mkdir -p $(dirname $file)
244 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
253 if [[ "$value" != "" ]]; then
256 for mdtno in $(seq 1 $MDSCOUNT); do
257 local idx=$(($mdtno - 1))
258 local facet=mds${mdtno}
259 # if $arg include -P option, run 1 set_param per MDT on the MGS
260 # else, run set_param on each MDT
261 [[ $arg = *"-P"* ]] && facet=mgs
262 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
263 [[ $? != 0 ]] && rc=1
273 for mdtno in $(seq 1 $MDSCOUNT); do
274 local idx=$(($mdtno - 1))
275 wait_result mds${mdtno} \
276 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
278 error "$key state is not '$target' on mds${mdtno}"
285 for mdtno in $(seq 1 $MDSCOUNT); do
286 local idx=$(($mdtno - 1))
287 local cl_user=$(do_facet mds${mdtno} $LCTL \
288 --device ${MDT[$idx]} \
289 changelog_register -n)
291 do_facet mds${mdtno} lctl set_param \
292 mdd.${MDT[$idx]}.changelog_mask="+hsm"
293 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
297 changelog_cleanup() {
299 for mdtno in $(seq 1 $MDSCOUNT); do
300 local idx=$(($mdtno - 1))
301 [[ -z ${CL_USERS[$idx]} ]] && continue
302 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
303 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
304 changelog_deregister ${CL_USERS[$idx]}
309 changelog_get_flags() {
314 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
319 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
327 mdts_set_param "$opt -n" "hsm.$param" "$value"
334 mdts_set_param "" hsm_control "$cmd"
335 mdts_check_param hsm_control "$target" 10
338 cdt_set_sanity_policy() {
339 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
342 mdts_set_param "" hsm.policy "+NRA"
343 mdts_set_param "" hsm.policy "-NBR"
344 CDT_POLICY_HAD_CHANGED=
349 mdts_set_param "" hsm.policy "+NRA"
350 CDT_POLICY_HAD_CHANGED=true
353 cdt_clear_no_retry() {
354 mdts_set_param "" hsm.policy "-NRA"
355 CDT_POLICY_HAD_CHANGED=true
358 cdt_set_non_blocking_restore() {
359 mdts_set_param "" hsm.policy "+NBR"
360 CDT_POLICY_HAD_CHANGED=true
363 cdt_clear_non_blocking_restore() {
364 mdts_set_param "" hsm.policy "-NBR"
365 CDT_POLICY_HAD_CHANGED=true
368 cdt_clear_mount_state() {
369 mdts_set_param "-P -d" hsm_control ""
372 cdt_set_mount_state() {
373 mdts_set_param "-P" hsm_control "$1"
377 mdts_check_param hsm_control "$1" 20
381 set_test_state disabled disabled
385 set_test_state enabled enabled
389 set_test_state shutdown stopped
393 set_test_state purge enabled
399 cdt_set_sanity_policy
403 local client_count=$1
404 if [[ $CLIENTCOUNT -lt $client_count ]]; then
405 skip "Need $client_count or more clients, have $CLIENTCOUNT"
412 $LFS path2fid $1 | tr -d '[]'
419 if [[ $u == "user" ]]; then
420 local st=$($RUNAS $LFS hsm_state $f)
422 local st=$($LFS hsm_state $f)
426 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
428 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
432 get_hsm_archive_id() {
434 local st=$($LFS hsm_state $f)
435 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
437 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
446 local st=$(get_hsm_flags $f)
447 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
450 check_hsm_flags_user() {
454 local st=$(get_hsm_flags $f user)
455 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
467 if [[ "$3" != 1 ]]; then
471 cp $1 $f || error "cannot copy $1 to $f"
472 path2fid $f || error "cannot get fid on $f"
476 local file2=${1/$DIR/$DIR2}
477 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
478 error "cannot create $file2"
479 path2fid $1 || error "cannot get fid on $1"
483 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
484 error "cannot create $1"
485 path2fid $1 || error "cannot get fid on $1"
488 cleanup_large_files() {
489 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
491 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
494 make_large_for_striping() {
495 local file2=${1/$DIR/$DIR2}
496 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
500 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
501 error "cannot create $file2"
502 path2fid $1 || error "cannot get fid on $1"
505 make_large_for_progress() {
506 local file2=${1/$DIR/$DIR2}
510 # big file is large enough, so copy time is > 30s
511 # so copytool make 1 progress
512 # size is not a multiple of 1M to avoid stripe
514 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
515 error "cannot create $file2"
516 path2fid $1 || error "cannot get fid on $1"
519 make_large_for_progress_aligned() {
520 local file2=${1/$DIR/$DIR2}
524 # big file is large enough, so copy time is > 30s
525 # so copytool make 1 progress
526 # size is a multiple of 1M to have stripe
528 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
529 error "cannot create $file2"
530 path2fid $1 || error "cannot get fid on $1"
533 make_large_for_cancel() {
534 local file2=${1/$DIR/$DIR2}
538 # Copy timeout is 100s. 105MB => 105s
539 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
540 error "cannot create $file2"
541 path2fid $1 || error "cannot get fid on $1"
547 wait_update --verbose $(facet_active_host $facet) "$@"
550 wait_request_state() {
554 # 4th arg (mdt index) is optional
556 local mds=mds$(($mdtidx + 1))
558 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
559 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
561 wait_result $mds "$cmd" $state 100 ||
562 error "request on $fid is not $state on $mds"
565 get_request_state() {
569 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
570 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
573 get_request_count() {
577 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
578 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
584 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
585 cmd+=" | egrep 'WAITING|STARTED'"
587 wait_result $SINGLEMDS "$cmd" "" $timeout ||
588 error "requests did not complete"
591 wait_for_grace_delay() {
592 local val=$(get_hsm_param grace_delay)
596 # populate MDT device array
602 # cleanup from previous bad setup
603 search_and_kill_copytool
605 # for recovery tests, coordinator needs to be started at mount
607 # the lustre conf must be without hsm on (like for sanity.sh)
608 echo "Set HSM on and start"
609 cdt_set_mount_state enabled
610 cdt_check_state enabled
612 echo "Start copytool"
615 echo "Set sanity-hsm HSM policy"
616 cdt_set_sanity_policy
618 # finished requests are quickly removed from list
619 set_hsm_param grace_delay 10
625 local f=$DIR/$tdir/$tfile
629 check_hsm_flags_user $f "0x00000000"
631 $RUNAS $LFS hsm_set --norelease $f ||
632 error "user could not change hsm flags"
633 check_hsm_flags_user $f "0x00000010"
635 $RUNAS $LFS hsm_clear --norelease $f ||
636 error "user could not clear hsm flags"
637 check_hsm_flags_user $f "0x00000000"
639 # User could not change those flags...
640 $RUNAS $LFS hsm_set --exists $f &&
641 error "user should not set this flag"
642 check_hsm_flags_user $f "0x00000000"
645 $LFS hsm_set --exists $f ||
646 error "root could not change hsm flags"
647 check_hsm_flags_user $f "0x00000001"
649 $LFS hsm_clear --exists $f ||
650 error "root could not clear hsm state"
651 check_hsm_flags_user $f "0x00000000"
654 run_test 1 "lfs hsm flags root/non-root access"
658 local f=$DIR/$tdir/$tfile
660 # New files are not dirty
661 check_hsm_flags $f "0x00000000"
663 # For test, we simulate an archived file.
664 $LFS hsm_set --exists $f || error "user could not change hsm flags"
665 check_hsm_flags $f "0x00000001"
667 # chmod do not put the file dirty
668 chmod 600 $f || error "could not chmod test file"
669 check_hsm_flags $f "0x00000001"
671 # chown do not put the file dirty
672 chown $RUNAS_ID $f || error "could not chown test file"
673 check_hsm_flags $f "0x00000001"
675 # truncate put the file dirty
676 $TRUNCATE $f 1 || error "could not truncate test file"
677 check_hsm_flags $f "0x00000003"
679 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
680 check_hsm_flags $f "0x00000001"
682 run_test 2 "Check file dirtyness when doing setattr"
688 # New files are not dirty
690 check_hsm_flags $f "0x00000000"
692 # For test, we simulate an archived file.
693 $LFS hsm_set --exists $f ||
694 error "user could not change hsm flags"
695 check_hsm_flags $f "0x00000001"
697 # Reading a file, does not set dirty
698 cat $f > /dev/null || error "could not read file"
699 check_hsm_flags $f "0x00000001"
701 # Open for write without modifying data, does not set dirty
702 openfile -f O_WRONLY $f || error "could not open test file"
703 check_hsm_flags $f "0x00000001"
705 # Append to a file sets it dirty
706 cp -p /etc/passwd $f.append || error "could not create file"
707 $LFS hsm_set --exists $f.append ||
708 error "user could not change hsm flags"
709 dd if=/etc/passwd of=$f.append bs=1 count=3\
710 conv=notrunc oflag=append status=noxfer ||
711 error "could not append to test file"
712 check_hsm_flags $f.append "0x00000003"
714 # Modify a file sets it dirty
715 cp -p /etc/passwd $f.modify || error "could not create file"
716 $LFS hsm_set --exists $f.modify ||
717 error "user could not change hsm flags"
718 dd if=/dev/zero of=$f.modify bs=1 count=3\
719 conv=notrunc status=noxfer ||
720 error "could not modify test file"
721 check_hsm_flags $f.modify "0x00000003"
723 # Open O_TRUNC sets dirty
724 cp -p /etc/passwd $f.trunc || error "could not create file"
725 $LFS hsm_set --exists $f.trunc ||
726 error "user could not change hsm flags"
727 cp /etc/group $f.trunc || error "could not override a file"
728 check_hsm_flags $f.trunc "0x00000003"
730 # Mmapped a file sets dirty
731 cp -p /etc/passwd $f.mmap || error "could not create file"
732 $LFS hsm_set --exists $f.mmap ||
733 error "user could not change hsm flags"
734 multiop $f.mmap OSMWUc || error "could not mmap a file"
735 check_hsm_flags $f.mmap "0x00000003"
737 run_test 3 "Check file dirtyness when opening for write"
741 local f=$DIR/$tdir/$tfile
742 local fid=$(make_small $f)
745 local st=$(get_request_state $fid CANCEL)
746 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
748 run_test 4 "Useless cancel must not be registered"
751 # test needs a running copytool
755 local f=$DIR/$tdir/$tfile
756 local fid=$(copy_file /etc/passwd $f)
758 wait_request_state $fid ARCHIVE SUCCEED
760 check_hsm_flags $f "0x00000009"
764 run_test 8 "Test default archive number"
768 local f=$DIR/$tdir/$tfile
769 local fid=$(copy_file /etc/passwd $f)
770 # we do not use the default one to be sure
771 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
773 copytool_setup $SINGLEAGT $MOUNT $new_an
774 $LFS hsm_archive --archive $new_an $f
775 wait_request_state $fid ARCHIVE SUCCEED
777 check_hsm_flags $f "0x00000009"
781 run_test 9 "Use of explict archive number, with dedicated copytool"
784 needclients 3 || return 0
790 copytool_cleanup $(comma_list $(agts_nodes))
792 # start all of the copytools
793 for n in $(seq $AGTCOUNT); do
797 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
800 for n in $(seq $AGTCOUNT); do
801 file=$DIR/$tdir/$tfile.$n
802 fid=$(make_small $file)
804 $LFS hsm_archive $file || error "could not archive file $file"
805 wait_request_state $fid ARCHIVE SUCCEED
806 check_hsm_flags $file "0x00000009"
810 copytool_cleanup $(comma_list $(agts_nodes))
812 run_test 9a "Multiple remote agents"
815 # test needs a running copytool
818 mkdir -p $DIR/$tdir/d1
819 local f=$DIR/$tdir/$tfile
820 local fid=$(copy_file /etc/hosts $f)
821 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
822 error "hsm_archive failed"
823 wait_request_state $fid ARCHIVE SUCCEED
825 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
826 error "fid $fid not in archive $HSM_ARCHIVE"
827 echo "Verifying content"
828 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
829 echo "Verifying hsm state "
830 check_hsm_flags $f "0x00000009"
832 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
833 local st=$(get_hsm_archive_id $f)
834 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
835 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
840 run_test 10a "Archive a file"
843 # test needs a running copytool
847 local f=$DIR/$tdir/$tfile
848 local fid=$(copy_file /etc/hosts $f)
849 $LFS hsm_archive $f || error "archive request failed"
850 wait_request_state $fid ARCHIVE SUCCEED
852 $LFS hsm_archive $f || error "archive of non dirty file failed"
853 local cnt=$(get_request_count $fid ARCHIVE)
854 [[ "$cnt" == "1" ]] ||
855 error "archive of non dirty file must not make a request"
859 run_test 10b "Archive of non dirty file must work without doing request"
862 # test needs a running copytool
866 local f=$DIR/$tdir/$tfile
867 local fid=$(copy_file /etc/hosts $f)
868 $LFS hsm_set --noarchive $f
869 $LFS hsm_archive $f && error "archive a noarchive file must fail"
873 run_test 10c "Check forbidden archive"
876 # test needs a running copytool
880 local f=$DIR/$tdir/$tfile
881 local fid=$(copy_file /etc/hosts $f)
882 $LFS hsm_archive $f || error "cannot archive $f"
883 wait_request_state $fid ARCHIVE SUCCEED
885 local ar=$(get_hsm_archive_id $f)
886 local dflt=$(get_hsm_param default_archive_id)
887 [[ $ar == $dflt ]] ||
888 error "archived file is not on default archive: $ar != $dflt"
892 run_test 10d "Archive a file on the default archive id"
896 copy2archive /etc/hosts $tdir/$tfile
897 local f=$DIR/$tdir/$tfile
899 import_file $tdir/$tfile $f
900 echo -n "Verifying released state: "
901 check_hsm_flags $f "0x0000000d"
903 local LSZ=$(stat -c "%s" $f)
904 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
906 echo "Verifying imported size $LSZ=$ASZ"
907 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
908 echo -n "Verifying released pattern: "
909 local PTRN=$($GETSTRIPE -L $f)
911 [[ $PTRN == 80000001 ]] || error "Is not released"
912 local fid=$(path2fid $f)
913 echo "Verifying new fid $fid in archive"
915 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
916 error "fid $fid not in archive $HSM_ARCHIVE"
918 run_test 11 "Import a file"
921 # test needs a running copytool
925 copy2archive /etc/hosts $tdir/$tfile
927 local f=$DIR/$tdir/$tfile
928 import_file $tdir/$tfile $f
929 local f=$DIR2/$tdir/$tfile
930 echo "Verifying released state: "
931 check_hsm_flags $f "0x0000000d"
933 local fid=$(path2fid $f)
935 wait_request_state $fid RESTORE SUCCEED
937 echo "Verifying file state: "
938 check_hsm_flags $f "0x00000009"
940 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
942 [[ $? -eq 0 ]] || error "Restored file differs"
946 run_test 12a "Restore an imported file explicitly"
949 # test needs a running copytool
953 copy2archive /etc/hosts $tdir/$tfile
955 local f=$DIR/$tdir/$tfile
956 import_file $tdir/$tfile $f
957 echo "Verifying released state: "
958 check_hsm_flags $f "0x0000000d"
960 cat $f > /dev/null || error "File read failed"
962 echo "Verifying file state after restore: "
963 check_hsm_flags $f "0x00000009"
965 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
967 [[ $? -eq 0 ]] || error "Restored file differs"
971 run_test 12b "Restore an imported file implicitly"
974 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
976 # test needs a running copytool
980 local f=$DIR/$tdir/$tfile
981 $LFS setstripe -c 2 $f
982 local fid=$(make_large_for_striping $f)
983 local FILE_CRC=$(md5sum $f)
985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
986 wait_request_state $fid ARCHIVE SUCCEED
987 $LFS hsm_release $f || error "release $f failed"
989 echo "$FILE_CRC" | md5sum -c
991 [[ $? -eq 0 ]] || error "Restored file differs"
995 run_test 12c "Restore a file with stripe of 2"
998 # test needs a running copytool
1003 local f=$DIR/$tdir/$tfile
1004 local fid=$(copy_file /etc/hosts $f)
1005 $LFS hsm_restore $f || error "restore of non archived file failed"
1006 local cnt=$(get_request_count $fid RESTORE)
1007 [[ "$cnt" == "0" ]] ||
1008 error "restore non archived must not make a request"
1009 $LFS hsm_archive $f ||
1010 error "archive request failed"
1011 wait_request_state $fid ARCHIVE SUCCEED
1012 $LFS hsm_restore $f ||
1013 error "restore of non released file failed"
1014 local cnt=$(get_request_count $fid RESTORE)
1015 [[ "$cnt" == "0" ]] ||
1016 error "restore a non dirty file must not make a request"
1020 run_test 12d "Restore of a non archived, non released file must work"\
1021 " without doing request"
1024 # test needs a running copytool
1027 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1028 local f=$DIR/$tdir/$tfile
1029 local fid=$(copy_file /etc/hosts $f)
1030 $LFS hsm_archive $f || error "archive request failed"
1031 wait_request_state $fid ARCHIVE SUCCEED
1034 cat /etc/hosts >> $f
1038 $LFS hsm_restore $f && error "restore a dirty file must fail"
1042 run_test 12e "Check forbidden restore"
1045 # test needs a running copytool
1049 local f=$DIR/$tdir/$tfile
1050 local fid=$(copy_file /etc/hosts $f)
1052 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1053 wait_request_state $fid ARCHIVE SUCCEED
1054 $LFS hsm_release $f || error "release of $f failed"
1056 wait_request_state $fid RESTORE SUCCEED
1058 echo -n "Verifying file state: "
1059 check_hsm_flags $f "0x00000009"
1061 diff -q /etc/hosts $f
1063 [[ $? -eq 0 ]] || error "Restored file differs"
1067 run_test 12f "Restore a released file explicitly"
1070 # test needs a running copytool
1074 local f=$DIR/$tdir/$tfile
1075 local fid=$(copy_file /etc/hosts $f)
1077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1078 wait_request_state $fid ARCHIVE SUCCEED
1079 $LFS hsm_release $f || error "release of $f failed"
1081 diff -q /etc/hosts $f
1084 # we check we had a restore done
1085 wait_request_state $fid RESTORE SUCCEED
1087 [[ $st -eq 0 ]] || error "Restored file differs"
1091 run_test 12g "Restore a released file implicitly"
1094 needclients 2 || return 0
1096 # test needs a running copytool
1100 local f=$DIR/$tdir/$tfile
1101 local fid=$(copy_file /etc/hosts $f)
1103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1104 wait_request_state $fid ARCHIVE SUCCEED
1105 $LFS hsm_release $f || error "release of $f failed"
1107 do_node $CLIENT2 diff -q /etc/hosts $f
1110 # we check we had a restore done
1111 wait_request_state $fid RESTORE SUCCEED
1113 [[ $st -eq 0 ]] || error "Restored file differs"
1117 run_test 12h "Restore a released file implicitly from a second node"
1120 # test needs a running copytool
1124 local f=$DIR/$tdir/$tfile
1125 local fid=$(copy_file /etc/passwd $f)
1126 $LFS hsm_archive $f || error "archive of $f failed"
1127 wait_request_state $fid ARCHIVE SUCCEED
1129 $LFS hsm_release $f || error "release of $f failed"
1133 [[ $? -eq 0 ]] || error "Restored file differs"
1137 run_test 12m "Archive/release/implicit restore"
1140 # test needs a running copytool
1144 copy2archive /etc/hosts $tdir/$tfile
1146 local f=$DIR/$tdir/$tfile
1147 import_file $tdir/$tfile $f
1149 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1150 error "Restored file differs"
1152 $LFS hsm_release $f || error "release of $f failed"
1156 run_test 12n "Import/implicit restore/release"
1159 # test needs a running copytool
1163 local f=$DIR/$tdir/$tfile
1164 local fid=$(copy_file /etc/hosts $f)
1166 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1167 wait_request_state $fid ARCHIVE SUCCEED
1168 $LFS hsm_release $f || error "release of $f failed"
1170 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1171 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1173 # set no retry action mode
1176 diff -q /etc/hosts $f
1179 # we check we had a restore failure
1180 wait_request_state $fid RESTORE FAILED
1182 [[ $st -eq 0 ]] && error "Restore must fail"
1184 # remove no retry action mode
1187 # check file is still released
1188 check_hsm_flags $f "0x0000000d"
1190 # retry w/o failure injection
1191 do_facet $SINGLEMDS lctl set_param fail_loc=0
1193 diff -q /etc/hosts $f
1196 # we check we had a restore done
1197 wait_request_state $fid RESTORE SUCCEED
1199 [[ $st -eq 0 ]] || error "Restored file differs"
1203 run_test 12o "Layout-swap failure during Restore leaves file released"
1206 # test needs a running copytool
1209 local ARC_SUBDIR="import.orig"
1213 # populate directory to be imported
1214 for d in $(seq 1 10); do
1215 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1216 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1217 for f in $(seq 1 10); do
1218 CURR_FILE="$CURR_DIR/$tfile.$f"
1219 # write file-specific data
1220 do_facet $SINGLEAGT \
1221 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1222 "file=$CURR_FILE > $CURR_FILE"
1226 import_file "$ARC_SUBDIR" $DIR/$tdir
1227 # diff lustre content and origin (triggers file restoration)
1228 # there must be 10x10 identical files, and no difference
1229 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1230 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1231 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1232 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1234 [ $cnt_diff -eq 0 ] ||
1235 error "$cnt_diff imported files differ from read data"
1236 [ $cnt_ok -eq 100 ] ||
1237 error "not enough identical files ($cnt_ok != 100)"
1241 run_test 13 "Recursively import and restore a directory"
1244 # test needs a running copytool
1249 local f=$DIR/$tdir/$tfile
1250 local fid=$(make_small $f)
1251 local sum=$(md5sum $f | awk '{print $1}')
1252 $LFS hsm_archive $f || error "could not archive file"
1253 wait_request_state $fid ARCHIVE SUCCEED
1257 # create released file (simulate llapi_hsm_import call)
1259 local fid2=$(path2fid $f)
1260 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1261 $LFS hsm_release $f || error "could not release file"
1263 # rebind the archive to the newly created file
1264 echo "rebind $fid to $fid2"
1266 do_facet $SINGLEAGT \
1267 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1268 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1270 # restore file and compare md5sum
1271 local sum2=$(md5sum $f | awk '{print $1}')
1273 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1277 run_test 14 "Rebind archived file to a new fid"
1280 # test needs a running copytool
1285 local f=$DIR/$tdir/$tfile
1287 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1291 for i in $(seq 1 $count); do
1292 fids[$i]=$(make_small $f.$i)
1293 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1294 $LFS hsm_archive $f.$i || error "could not archive file"
1296 wait_all_done $(($count*60))
1300 for i in $(seq 1 $count); do
1303 local fid2=$(path2fid $f.$i)
1304 # add the rebind operation to the list
1305 echo ${fids[$i]} $fid2 >> $tmpfile
1307 # set it released (simulate llapi_hsm_import call)
1308 $LFS hsm_set --archived --exists $f.$i ||
1309 error "could not force hsm flags"
1310 $LFS hsm_release $f.$i || error "could not release file"
1312 nl=$(wc -l < $tmpfile)
1313 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1315 echo "rebind list of files"
1316 do_facet $SINGLEAGT \
1317 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1318 --rebind $tmpfile $DIR" || error "could not rebind file list"
1320 # restore files and compare md5sum
1321 for i in $(seq 1 $count); do
1322 local sum2=$(md5sum $f.$i | awk '{print $1}')
1323 [[ $sum2 == ${sums[$i]} ]] ||
1324 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1330 run_test 15 "Rebind a list of files"
1333 # test needs a running copytool
1337 # create a known size file so we can verify transfer speed
1340 dd if=/dev/zero of=$ref bs=1M count=20
1343 local f=$DIR/$tdir/$tfile
1344 local fid=$(copy_file $ref $f)
1346 local start=$(date +%s)
1348 wait_request_state $fid ARCHIVE SUCCEED
1349 local end=$(date +%s)
1350 local duration=$((end - start))
1352 [[ $duration -ge $goal ]] ||
1353 error "Transfer is too fast $duration < $goal"
1357 run_test 16 "Test CT bandwith control option"
1362 local f=$DIR/$tdir/$tfile
1363 touch $f || error "touch $f failed"
1365 # Could not release a non-archived file
1366 $LFS hsm_release $f && error "release should not succeed"
1368 # For following tests, we must test them with HS_ARCHIVED set
1369 $LFS hsm_set --exists --archived $f || error "could not add flag"
1371 # Could not release a file if no-release is set
1372 $LFS hsm_set --norelease $f || error "could not add flag"
1373 $LFS hsm_release $f && error "release should not succeed"
1374 $LFS hsm_clear --norelease $f || error "could not remove flag"
1376 # Could not release a file if lost
1377 $LFS hsm_set --lost $f || error "could not add flag"
1378 $LFS hsm_release $f && error "release should not succeed"
1379 $LFS hsm_clear --lost $f || error "could not remove flag"
1381 # Could not release a file if dirty
1382 $LFS hsm_set --dirty $f || error "could not add flag"
1383 $LFS hsm_release $f && error "release should not succeed"
1384 $LFS hsm_clear --dirty $f || error "could not remove flag"
1386 run_test 20 "Release is not permitted"
1389 # test needs a running copytool
1393 local f=$DIR/$tdir/test_release
1395 # Create a file and check its states
1396 local fid=$(make_small $f)
1397 check_hsm_flags $f "0x00000000"
1399 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1400 # used until file is flushed to disk
1401 if [ $(facet_fstype ost1) == "zfs" ]; then
1402 # this causes an OST_SYNC rpc to be sent
1403 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1404 # clear locks to reread file data
1405 cancel_lru_locks osc
1408 local orig_size=$(stat -c "%s" $f)
1409 local orig_blocks=$(stat -c "%b" $f)
1411 start_full_debug_logging
1413 $LFS hsm_archive $f || error "could not archive file"
1414 wait_request_state $fid ARCHIVE SUCCEED
1416 local blocks=$(stat -c "%b" $f)
1417 [ $blocks -eq $orig_blocks ] ||
1418 error "$f: wrong block number after archive: " \
1419 "$blocks != $orig_blocks"
1420 local size=$(stat -c "%s" $f)
1421 [ $size -eq $orig_size ] ||
1422 error "$f: wrong size after archive: $size != $orig_size"
1424 # Release and check states
1425 $LFS hsm_release $f || error "could not release file"
1426 check_hsm_flags $f "0x0000000d"
1428 blocks=$(stat -c "%b" $f)
1429 [ $blocks -gt 5 ] &&
1430 error "$f: too many blocks after release: $blocks > 5"
1431 size=$(stat -c "%s" $f)
1432 [ $size -ne $orig_size ] &&
1433 error "$f: wrong size after release: $size != $orig_size"
1435 # Check we can release an file without stripe info
1439 check_hsm_flags $f "0x00000000"
1440 $LFS hsm_archive $f || error "could not archive file"
1441 wait_request_state $fid ARCHIVE SUCCEED
1443 # Release and check states
1444 $LFS hsm_release $f || error "could not release file"
1445 check_hsm_flags $f "0x0000000d"
1447 # Release again a file that is already released is OK
1448 $LFS hsm_release $f || fail "second release should succeed"
1449 check_hsm_flags $f "0x0000000d"
1451 stop_full_debug_logging
1455 run_test 21 "Simple release tests"
1458 # test needs a running copytool
1463 local f=$DIR/$tdir/test_release
1464 local swap=$DIR/$tdir/test_swap
1466 # Create a file and check its states
1467 local fid=$(make_small $f)
1468 check_hsm_flags $f "0x00000000"
1470 $LFS hsm_archive $f || error "could not archive file"
1471 wait_request_state $fid ARCHIVE SUCCEED
1473 # Release and check states
1474 $LFS hsm_release $f || error "could not release file"
1475 check_hsm_flags $f "0x0000000d"
1478 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1483 run_test 22 "Could not swap a release file"
1486 # test needs a running copytool
1491 local f=$DIR/$tdir/test_mtime
1493 # Create a file and check its states
1494 local fid=$(make_small $f)
1495 check_hsm_flags $f "0x00000000"
1497 $LFS hsm_archive $f || error "could not archive file"
1498 wait_request_state $fid ARCHIVE SUCCEED
1500 # Set modification time in the past
1501 touch -m -a -d @978261179 $f
1503 # Release and check states
1504 $LFS hsm_release $f || error "could not release file"
1505 check_hsm_flags $f "0x0000000d"
1507 local MTIME=$(stat -c "%Y" $f)
1508 local ATIME=$(stat -c "%X" $f)
1509 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1510 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1514 run_test 23 "Release does not change a/mtime (utime)"
1517 local file=$DIR/$tdir/$tfile
1526 # test needs a running copytool
1531 fid=$(make_small $file)
1533 # Create a file and check its states
1534 check_hsm_flags $file "0x00000000"
1536 # Ensure atime is less than mtime and ctime.
1540 atime0=$(stat -c "%X" $file)
1541 mtime0=$(stat -c "%Y" $file)
1542 ctime0=$(stat -c "%Z" $file)
1544 [ $atime0 -lt $mtime0 ] ||
1545 error "atime $atime0 is not less than mtime $mtime0"
1547 [ $atime0 -lt $ctime0 ] ||
1548 error "atime $atime0 is not less than ctime $ctime0"
1550 # Archive should not change any timestamps.
1551 $LFS hsm_archive $file || error "cannot archive '$file'"
1552 wait_request_state $fid ARCHIVE SUCCEED
1554 atime1=$(stat -c "%X" $file)
1555 mtime1=$(stat -c "%Y" $file)
1556 ctime1=$(stat -c "%Z" $file)
1558 [ $atime0 -eq $atime1 ] ||
1559 error "archive changed atime from $atime0 to $atime1"
1561 [ $mtime0 -eq $mtime1 ] ||
1562 error "archive changed mtime from $mtime0 to $mtime1"
1564 [ $ctime0 -eq $ctime1 ] ||
1565 error "archive changed ctime from $ctime0 to $ctime1"
1567 # Release should not change any timestamps.
1568 $LFS hsm_release $file || error "cannot release '$file'"
1569 check_hsm_flags $file "0x0000000d"
1571 atime1=$(stat -c "%X" $file)
1572 mtime1=$(stat -c "%Y" $file)
1573 ctime1=$(stat -c "%Z" $file)
1575 [ $atime0 -eq $atime1 ] ||
1576 error "release changed atime from $atime0 to $atime1"
1578 [ $mtime0 -eq $mtime1 ] ||
1579 error "release changed mtime from $mtime0 to $mtime1"
1581 [ $ctime0 -eq $ctime1 ] ||
1582 error "release changed ctime from $ctime0 to $ctime1"
1584 # Restore should not change atime or mtime and should not
1586 $LFS hsm_restore $file
1587 wait_request_state $fid RESTORE SUCCEED
1589 atime1=$(stat -c "%X" $file)
1590 mtime1=$(stat -c "%Y" $file)
1591 ctime1=$(stat -c "%Z" $file)
1593 [ $atime0 -eq $atime1 ] ||
1594 error "restore changed atime from $atime0 to $atime1"
1596 [ $mtime0 -eq $mtime1 ] ||
1597 error "restore changed mtime from $mtime0 to $mtime1"
1599 [ $ctime0 -le $ctime1 ] ||
1600 error "restore changed ctime from $ctime0 to $ctime1"
1604 # Once more, after unmount and mount.
1605 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1606 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1608 atime1=$(stat -c "%X" $file)
1609 mtime1=$(stat -c "%Y" $file)
1610 ctime1=$(stat -c "%Z" $file)
1612 [ $atime0 -eq $atime1 ] ||
1613 error "remount changed atime from $atime0 to $atime1"
1615 [ $mtime0 -eq $mtime1 ] ||
1616 error "remount changed mtime from $mtime0 to $mtime1"
1618 [ $ctime0 -le $ctime1 ] ||
1619 error "remount changed ctime from $ctime0 to $ctime1"
1621 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1624 local file=$DIR/$tdir/$tfile
1630 # Test needs a running copytool.
1634 # Check that root can do HSM actions on a ordinary user's file.
1636 fid=$(make_small $file)
1637 sum0=$(md5sum $file)
1639 chown $RUNAS_ID:$RUNAS_GID $file ||
1640 error "cannot chown '$file' to '$RUNAS_ID'"
1642 chmod ugo-w $DIR/$tdir ||
1643 error "cannot chmod '$DIR/$tdir'"
1645 $LFS hsm_archive $file
1646 wait_request_state $fid ARCHIVE SUCCEED
1648 $LFS hsm_release $file
1649 check_hsm_flags $file "0x0000000d"
1651 $LFS hsm_restore $file
1652 wait_request_state $fid RESTORE SUCCEED
1654 # Check that ordinary user can get HSM state.
1655 $RUNAS $LFS hsm_state $file ||
1656 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1658 $LFS hsm_release $file
1659 check_hsm_flags $file "0x0000000d"
1661 # Check that ordinary user can accessed released file.
1662 sum1=$($RUNAS md5sum $file) ||
1663 error "user '$RUNAS_ID' cannot read '$file'"
1665 [ "$sum0" == "$sum1" ] ||
1666 error "md5sum mismatch for '$file'"
1670 run_test 24b "root can archive, release, and restore user files"
1672 cleanup_test_24c() {
1674 set_hsm_param user_request_mask RESTORE
1675 set_hsm_param group_request_mask RESTORE
1676 set_hsm_param other_request_mask RESTORE
1680 local file=$DIR/$tdir/$tfile
1681 local action=archive
1686 # test needs a running copytool
1691 # Save the default masks and check that cleanup_24c will
1692 # restore the request masks correctly.
1693 user_save=$(get_hsm_param user_request_mask)
1694 group_save=$(get_hsm_param group_request_mask)
1695 other_save=$(get_hsm_param other_request_mask)
1697 [ "$user_save" == RESTORE ] ||
1698 error "user_request_mask is '$user_save' expected 'RESTORE'"
1699 [ "$group_save" == RESTORE ] ||
1700 error "group_request_mask is '$group_save' expected 'RESTORE'"
1701 [ "$other_save" == RESTORE ] ||
1702 error "other_request_mask is '$other_save' expected 'RESTORE'"
1704 trap cleanup_test_24c EXIT
1709 chown $RUNAS_ID:nobody $file ||
1710 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1712 set_hsm_param user_request_mask ""
1713 $RUNAS $LFS hsm_$action $file &&
1714 error "$action by user should fail"
1716 set_hsm_param user_request_mask $action
1717 $RUNAS $LFS hsm_$action $file ||
1718 error "$action by user should succeed"
1723 chown nobody:$RUNAS_GID $file ||
1724 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1726 set_hsm_param group_request_mask ""
1727 $RUNAS $LFS hsm_$action $file &&
1728 error "$action by group should fail"
1730 set_hsm_param group_request_mask $action
1731 $RUNAS $LFS hsm_$action $file ||
1732 error "$action by group should succeed"
1737 chown nobody:nobody $file ||
1738 error "cannot chown '$file' to 'nobody:nobody'"
1740 set_hsm_param other_request_mask ""
1741 $RUNAS $LFS hsm_$action $file &&
1742 error "$action by other should fail"
1744 set_hsm_param other_request_mask $action
1745 $RUNAS $LFS hsm_$action $file ||
1746 error "$action by other should succeed"
1751 run_test 24c "check that user,group,other request masks work"
1753 cleanup_test_24d() {
1755 mount -o remount,rw $MOUNT2
1759 local file1=$DIR/$tdir/$tfile
1760 local file2=$DIR2/$tdir/$tfile
1768 fid1=$(make_small $file1)
1770 trap cleanup_test_24d EXIT
1772 mount -o remount,ro $MOUNT2
1774 fid2=$(path2fid $file2)
1775 [ "$fid1" == "$fid2" ] ||
1776 error "FID mismatch '$fid1' != '$fid2'"
1778 $LFS hsm_archive $file2 &&
1779 error "archive should fail on read-only mount"
1780 check_hsm_flags $file1 "0x00000000"
1782 $LFS hsm_archive $file1
1783 wait_request_state $fid1 ARCHIVE SUCCEED
1785 $LFS hsm_release $file1
1786 $LFS hsm_restore $file2
1787 wait_request_state $fid1 RESTORE SUCCEED
1789 $LFS hsm_release $file1 || error "cannot release '$file1'"
1790 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1792 $LFS hsm_release $file2 &&
1793 error "release should fail on read-only mount"
1798 run_test 24d "check that read-only mounts are respected"
1801 # test needs a running copytool
1805 copy2archive /etc/hosts $tdir/$tfile
1807 local f=$DIR/$tdir/$tfile
1809 import_file $tdir/$tfile $f
1811 $LFS hsm_set --lost $f
1816 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1820 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1821 " (Operation not permitted)"
1824 # test needs a running copytool
1829 local f=$DIR/$tdir/$tfile
1830 local fid=$(copy_file /etc/passwd $f)
1832 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1833 wait_request_state $fid ARCHIVE SUCCEED
1836 $LFS hsm_set --lost $f
1840 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1844 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1845 " (Operation not permitted)"
1848 # test needs a running copytool
1852 local f=$DIR/$tdir/$tfile
1853 local fid=$(make_large_for_progress $f)
1854 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1855 wait_request_state $fid ARCHIVE SUCCEED
1858 wait_request_state $fid REMOVE SUCCEED
1860 check_hsm_flags $f "0x00000000"
1864 run_test 26 "Remove the archive of a valid file"
1867 # test needs a running copytool
1871 make_archive $tdir/$tfile
1872 local f=$DIR/$tdir/$tfile
1873 import_file $tdir/$tfile $f
1874 local fid=$(path2fid $f)
1878 [[ $? != 0 ]] || error "Remove of a released file should fail"
1882 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1885 # test needs a running copytool
1889 local f=$DIR/$tdir/$tfile
1890 local fid=$(make_large_for_progress $f)
1891 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1892 wait_request_state $fid ARCHIVE SUCCEED
1897 [[ $? != 0 ]] || error "Remove of a released file should fail"
1901 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1904 # test needs a running copytool
1908 local f=$DIR/$tdir/$tfile
1909 local fid=$(make_large_for_progress $f)
1910 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1911 wait_request_state $fid ARCHIVE SUCCEED
1920 wait_request_state $fid REMOVE SUCCEED
1924 run_test 28 "Concurrent archive/file remove"
1927 # restore at exec cannot work on agent node (because of Linux kernel
1928 # protection of executables)
1929 needclients 2 || return 0
1931 # test needs a running copytool
1935 copy2archive /bin/true $tdir/$tfile
1937 local f=$DIR/$tdir/true
1938 import_file $tdir/$tfile $f
1940 local fid=$(path2fid $f)
1942 # set no retry action mode
1948 # remove no try action mode
1952 [[ $st == 0 ]] || error "Failed to exec a released file"
1956 run_test 30a "Restore at exec (import case)"
1959 # restore at exec cannot work on agent node (because of Linux kernel
1960 # protection of executables)
1961 needclients 2 || return 0
1963 # test needs a running copytool
1967 local f=$DIR/$tdir/true
1968 local fid=$(copy_file /bin/true $f)
1970 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1971 wait_request_state $fid ARCHIVE SUCCEED
1974 # set no retry action mode
1980 # remove no try action mode
1984 [[ $st == 0 ]] || error "Failed to exec a released file"
1988 run_test 30b "Restore at exec (release case)"
1991 needclients 2 || return 0
1993 # test needs a running copytool
1997 local f=$DIR/$tdir/SLEEP
1998 local fid=$(copy_file /bin/sleep $f)
2000 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2001 wait_request_state $fid ARCHIVE SUCCEED
2003 check_hsm_flags $f "0x0000000d"
2004 # set no retry action mode
2006 do_node $CLIENT2 "$f 10" &
2010 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2012 [[ $? == 0 ]] || error "Execution failed during run"
2014 [[ $? == 0 ]] || error "Binary overwritten during exec"
2017 # remove no try action mode
2019 check_hsm_flags $f "0x00000009"
2023 run_test 30c "Update during exec of released file must fail"
2025 restore_and_check_size() {
2028 local s=$(stat -c "%s" $f)
2030 local st=$(get_hsm_flags $f)
2034 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2036 n=$(stat -c "%s" $f)
2037 # we echo in both cases to show stat is not
2039 if [[ $n != $s ]]; then
2040 echo "size seen is $n != $s"
2043 echo "size seen is right: $n == $s"
2045 st=$(get_hsm_flags $f)
2049 if [[ $cpt -lt 10 ]]; then
2052 echo " restore is too long"
2053 wait_request_state $fid RESTORE SUCCEED
2059 # test needs a running copytool
2064 make_archive $tdir/$tfile
2065 local f=$DIR/$tdir/$tfile
2066 import_file $tdir/$tfile $f
2067 local fid=$($LFS path2fid $f)
2068 HSM_ARCHIVE_PURGE=false copytool_setup
2070 restore_and_check_size $f $fid
2073 [[ $err -eq 0 ]] || error "File size changed during restore"
2077 run_test 31a "Import a large file and check size during restore"
2081 # test needs a running copytool
2086 local f=$DIR/$tdir/$tfile
2087 local fid=$(make_large_for_progress $f)
2088 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2089 wait_request_state $fid ARCHIVE SUCCEED
2092 restore_and_check_size $f $fid
2095 [[ $err -eq 0 ]] || error "File size changed during restore"
2099 run_test 31b "Restore a large unaligned file and check size during restore"
2102 # test needs a running copytool
2107 local f=$DIR/$tdir/$tfile
2108 local fid=$(make_large_for_progress_aligned $f)
2109 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2110 wait_request_state $fid ARCHIVE SUCCEED
2113 restore_and_check_size $f $fid
2116 [[ $err -eq 0 ]] || error "File size changed during restore"
2120 run_test 31c "Restore a large aligned file and check size during restore"
2123 # test needs a running copytool
2128 local f=$DIR/$tdir/$tfile
2129 local fid=$(make_large_for_progress $f)
2130 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2131 wait_request_state $fid ARCHIVE SUCCEED
2134 md5sum $f >/dev/null &
2136 wait_request_state $fid RESTORE STARTED
2141 # Check restore trigger process was killed
2142 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2146 wait_request_state $fid RESTORE CANCELED
2147 wait_request_state $fid CANCEL SUCCEED
2150 error "Cannot kill process waiting for restore ($killed)"
2154 run_test 33 "Kill a restore waiting process"
2157 # test needs a running copytool
2162 local f=$DIR/$tdir/$tfile
2163 local fid=$(make_large_for_progress $f)
2164 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2165 wait_request_state $fid ARCHIVE SUCCEED
2168 md5sum $f >/dev/null &
2170 wait_request_state $fid RESTORE STARTED
2172 rm $f || error "rm $f failed"
2173 # rm must not block during restore
2174 wait_request_state $fid RESTORE STARTED
2176 wait_request_state $fid RESTORE SUCCEED
2177 # check md5sum pgm finished
2178 local there=$(ps -o pid,comm hp $pid >/dev/null)
2179 [[ -z $there ]] || error "Restore initiator does not exit"
2181 local rc=$(wait $pid)
2182 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2186 run_test 34 "Remove file during restore"
2189 # test needs a running copytool
2194 local f=$DIR/$tdir/$tfile
2195 local f1=$DIR/$tdir/$tfile-1
2196 local fid=$(make_large_for_progress $f)
2197 local fid1=$(copy_file /etc/passwd $f1)
2198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2199 wait_request_state $fid ARCHIVE SUCCEED
2202 md5sum $f >/dev/null &
2204 wait_request_state $fid RESTORE STARTED
2206 mv $f1 $f || error "mv $f1 $f failed"
2207 # mv must not block during restore
2208 wait_request_state $fid RESTORE STARTED
2210 wait_request_state $fid RESTORE SUCCEED
2211 # check md5sum pgm finished
2212 local there=$(ps -o pid,comm hp $pid >/dev/null)
2213 [[ -z $there ]] || error "Restore initiator does not exit"
2215 local rc=$(wait $pid)
2216 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2219 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2223 run_test 35 "Overwrite file during restore"
2226 # test needs a running copytool
2231 local f=$DIR/$tdir/$tfile
2232 local fid=$(make_large_for_progress $f)
2233 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2234 wait_request_state $fid ARCHIVE SUCCEED
2237 md5sum $f >/dev/null &
2239 wait_request_state $fid RESTORE STARTED
2242 # rm must not block during restore
2243 wait_request_state $fid RESTORE STARTED
2245 wait_request_state $fid RESTORE SUCCEED
2246 # check md5sum pgm finished
2247 local there=$(ps -o pid,comm hp $pid >/dev/null)
2249 error "Restore initiator does not exit"
2251 local rc=$(wait $pid)
2253 error "Restore initiator failed with $rc"
2257 run_test 36 "Move file during restore"
2264 for n in $(seq 1 $count); do
2265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2267 echo "$count archive requests submitted"
2271 local stream_count=4
2272 local file_count=100
2274 local f=$DIR/$tdir/$tfile
2279 for i in $(seq 1 $file_count); do
2280 for p in $(seq 1 $stream_count); do
2281 fid=$(copy_file /etc/hosts $f.$p.$i)
2284 # force copytool to use a local/temp archive dir to ensure best
2285 # performance vs remote/NFS mounts used in auto-tests
2286 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2289 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2291 # to be sure wait_all_done will not be mislead by previous tests
2293 wait_for_grace_delay
2295 # start archive streams in background (archive files in parallel)
2296 for p in $(seq 1 $stream_count); do
2297 multi_archive $f.$p $file_count &
2300 echo -n "Wait for all requests being enqueued..."
2306 run_test 40 "Parallel archive requests"
2309 # test needs a running copytool
2313 local f=$DIR/$tdir/$tfile
2314 local fid=$(copy_file /etc/motd $f 1)
2316 $LFS hsm_archive $f || error "could not archive file"
2317 wait_request_state $fid ARCHIVE SUCCEED
2318 check_hsm_flags $f "0x00000009"
2320 multiop_bg_pause $f O_c || error "multiop failed"
2324 client_up || client_up || true
2326 kill -USR1 $MULTIPID
2327 wait $MULTIPID || error "multiop close failed"
2329 check_hsm_flags $f "0x0000000b"
2333 run_test 52 "Opened for write file on an evicted client should be set dirty"
2336 # test needs a running copytool
2340 local f=$DIR/$tdir/$tfile
2341 local fid=$(copy_file /etc/motd $f 1)
2343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2344 error "could not archive file"
2345 wait_request_state $fid ARCHIVE SUCCEED
2346 check_hsm_flags $f "0x00000009"
2348 multiop_bg_pause $f o_c || error "multiop failed"
2352 client_up || client_up || true
2354 kill -USR1 $MULTIPID
2355 wait $MULTIPID || error "multiop close failed"
2357 check_hsm_flags $f "0x00000009"
2361 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2364 # test needs a running copytool
2368 local f=$DIR/$tdir/$tfile
2369 local fid=$(make_small $f)
2371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2372 error "could not archive file"
2373 wait_request_state $fid ARCHIVE STARTED
2375 check_hsm_flags $f "0x00000001"
2377 # Avoid coordinator resending this request as soon it has failed.
2382 wait_request_state $fid ARCHIVE FAILED
2384 check_hsm_flags $f "0x00000003"
2389 run_test 54 "Write during an archive cancels it"
2392 # test needs a running copytool
2396 local f=$DIR/$tdir/$tfile
2397 local fid=$(make_small $f)
2399 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2400 error "could not archive file"
2401 wait_request_state $fid ARCHIVE STARTED
2403 check_hsm_flags $f "0x00000001"
2405 # Avoid coordinator resending this request as soon it has failed.
2408 $TRUNCATE $f 1024 || error "truncate failed"
2410 wait_request_state $fid ARCHIVE FAILED
2412 check_hsm_flags $f "0x00000003"
2417 run_test 55 "Truncate during an archive cancels it"
2420 # test needs a running copytool
2424 local f=$DIR/$tdir/$tfile
2425 local fid=$(make_large_for_progress $f)
2427 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2428 error "could not archive file"
2429 wait_request_state $fid ARCHIVE STARTED
2431 check_hsm_flags $f "0x00000001"
2433 # Change metadata and sync to be sure we are not changing only
2438 wait_request_state $fid ARCHIVE SUCCEED
2440 check_hsm_flags $f "0x00000009"
2444 run_test 56 "Setattr during an archive is ok"
2447 # Need one client for I/O, one for request
2448 needclients 2 || return 0
2450 # test needs a running copytool
2454 local f=$DIR/$tdir/test_archive_remote
2455 # Create a file on a remote node
2456 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2457 "count=2 conv=fsync"
2460 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2461 error "hsm_archive failed"
2462 local fid=$(path2fid $f)
2463 wait_request_state $fid ARCHIVE SUCCEED
2465 # Release and implicit restore it
2466 do_node $CLIENT2 "$LFS hsm_release $f" ||
2467 error "hsm_release failed"
2468 do_node $CLIENT2 "md5sum $f" ||
2469 error "hsm_restore failed"
2471 wait_request_state $fid RESTORE SUCCEED
2475 run_test 57 "Archive a file with dirty cache on another node"
2477 truncate_released_file() {
2481 local sz=$(stat -c %s $src_file)
2482 local f=$DIR/$tdir/$tfile
2483 local fid=$(copy_file $1 $f)
2487 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2488 error "could not archive file"
2489 wait_request_state $fid ARCHIVE SUCCEED
2491 $LFS hsm_release $f || error "could not release file"
2493 $TRUNCATE $f $trunc_to || error "truncate failed"
2496 local sz1=$(stat -c %s $f)
2497 [[ $sz1 == $trunc_to ]] ||
2498 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2501 check_hsm_flags $f "0x0000000b"
2503 local state=$(get_request_state $fid RESTORE)
2504 [[ "$state" == "SUCCEED" ]] ||
2505 error "truncate $sz does not trig restore, state = $state"
2507 $TRUNCATE $ref $trunc_to
2508 cmp $ref $f || error "file data wrong after truncate"
2514 # test needs a running copytool
2519 local sz=$(stat -c %s /etc/passwd)
2521 echo "truncate up from $sz to $((sz*2))"
2522 truncate_released_file /etc/passwd $((sz*2))
2524 echo "truncate down from $sz to $((sz/2))"
2525 truncate_released_file /etc/passwd $((sz/2))
2527 echo "truncate to 0"
2528 truncate_released_file /etc/passwd 0
2532 run_test 58 "Truncate a released file will trigger restore"
2537 local f=$DIR/$tdir/$tfile
2538 local FILELIST=/tmp/filelist.txt
2542 for i in $(seq 1 $file_count); do
2543 fid=$(copy_file /etc/hosts $f.$i)
2544 echo $f.$i >> $FILELIST
2547 # to be sure wait_all_done will not be mislead by previous tests
2549 wait_for_grace_delay
2550 $LFS hsm_archive --filelist $FILELIST ||
2551 error "cannot archive a file list"
2553 $LFS hsm_release --filelist $FILELIST ||
2554 error "cannot release a file list"
2555 $LFS hsm_restore --filelist $FILELIST ||
2556 error "cannot restore a file list"
2560 run_test 90 "Archive/restore a file list"
2562 double_verify_reset_hsm_param() {
2564 echo "Testing $HSM_PARAM.$p"
2565 local val=$(get_hsm_param $p)
2567 local val2=$(($val * 2))
2568 set_hsm_param $p $val2
2569 val=$(get_hsm_param $p)
2570 [[ $val == $val2 ]] ||
2571 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2572 echo "Set $p to 0 must failed"
2576 set_hsm_param $p $save
2578 if [[ $rc == 0 ]]; then
2579 error "we must not be able to set $HSM_PARAM.$p to 0"
2584 double_verify_reset_hsm_param loop_period
2585 double_verify_reset_hsm_param grace_delay
2586 double_verify_reset_hsm_param active_request_timeout
2587 double_verify_reset_hsm_param max_requests
2588 double_verify_reset_hsm_param default_archive_id
2590 run_test 100 "Set coordinator /proc tunables"
2597 run_test 102 "Verify coordinator control"
2600 # test needs a running copytool
2607 for i in $(seq 1 20); do
2608 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2610 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2614 echo "Current requests"
2615 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2616 $HSM_PARAM.actions |\
2617 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2619 [[ -z "$res" ]] || error "Some request have not been canceled"
2623 run_test 103 "Purge all requests"
2628 # test needs a running copytool
2632 local f=$DIR/$tdir/$tfile
2633 local fid=$(make_large_for_progress $f)
2634 # if cdt is on, it can serve too quickly the request
2636 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2637 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2638 $HSM_PARAM.actions |\
2639 grep $fid | cut -f16 -d=")
2642 [[ "$data1" == "$DATAHEX" ]] ||
2643 error "Data field in records is ($data1) and not ($DATAHEX)"
2647 run_test 104 "Copy tool data field"
2654 for i in $(seq -w 1 10); do
2655 cp /etc/passwd $DIR/$tdir/$i
2656 $LFS hsm_archive $DIR/$tdir/$i
2658 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2659 $HSM_PARAM.actions |\
2660 grep WAITING | wc -l")
2663 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2664 $HSM_PARAM.actions |\
2665 grep WAITING | wc -l")
2668 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2669 error "Requests count after shutdown $reqcnt2 != "\
2670 "before shutdown $reqcnt1"
2672 run_test 105 "Restart of coordinator"
2674 get_agent_by_uuid_mdt() {
2677 local mds=mds$(($mdtidx + 1))
2678 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
2682 check_agent_registered_by_mdt() {
2685 local mds=mds$(($mdtidx + 1))
2686 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2687 if [[ ! -z "$agent" ]]; then
2688 echo "found agent $agent on $mds"
2690 error "uuid $uuid not found in agent list on $mds"
2694 check_agent_unregistered_by_mdt() {
2697 local mds=mds$(($mdtidx + 1))
2698 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
2699 if [[ -z "$agent" ]]; then
2700 echo "uuid not found in agent list on $mds"
2702 error "uuid found in agent list on $mds: $agent"
2706 check_agent_registered() {
2709 for mdsno in $(seq 1 $MDSCOUNT); do
2710 check_agent_registered_by_mdt $uuid $((mdsno - 1))
2714 check_agent_unregistered() {
2717 for mdsno in $(seq 1 $MDSCOUNT); do
2718 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
2723 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2724 get_client_uuid $MOUNT | cut -d' ' -f2)
2727 check_agent_registered $uuid
2729 search_copytools || error "No copytool found"
2732 check_agent_unregistered $uuid
2735 check_agent_registered $uuid
2739 run_test 106 "Copytool register/unregister"
2742 # test needs a running copytool
2744 # create and archive file
2746 local f1=$DIR/$tdir/$tfile
2747 local fid=$(copy_file /etc/passwd $f1)
2748 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2749 wait_request_state $fid ARCHIVE SUCCEED
2750 # shutdown and restart MDS
2752 # check the copytool still gets messages from MDT
2753 local f2=$DIR/$tdir/2
2754 local fid=$(copy_file /etc/passwd $f2)
2755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2756 # main check of this sanity: this request MUST succeed
2757 wait_request_state $fid ARCHIVE SUCCEED
2760 run_test 107 "Copytool re-register after MDS restart"
2762 policy_set_and_test()
2766 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2767 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2768 [[ "$policy" == "$target" ]] ||
2769 error "Wrong policy after '$change': '$policy' != '$target'"
2773 # to force default policy setting if error
2774 CDT_POLICY_HAD_CHANGED=true
2776 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2777 local default="NonBlockingRestore [NoRetryAction]"
2778 [[ "$policy" == "$default" ]] ||
2779 error "default policy has changed,"\
2780 " '$policy' != '$default' update the test"
2781 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2782 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2783 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2784 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2785 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2786 # useless bacause we know but safer for futur changes to use real value
2787 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2788 echo "Next set_param must failed"
2789 policy_set_and_test "wrong" "$policy"
2792 echo "Back to default policy"
2793 cdt_set_sanity_policy
2795 run_test 109 "Policy display/change"
2798 # test needs a running copytool
2803 copy2archive /etc/passwd $tdir/$tfile
2805 local f=$DIR/$tdir/$tfile
2806 import_file $tdir/$tfile $f
2807 local fid=$(path2fid $f)
2809 cdt_set_non_blocking_restore
2814 wait_request_state $fid RESTORE SUCCEED
2815 cdt_clear_non_blocking_restore
2819 error "md5sum returns $st != 1, "\
2820 "should also perror ENODATA (No data available)"
2824 run_test 110a "Non blocking restore policy (import case)"
2827 # test needs a running copytool
2831 local f=$DIR/$tdir/$tfile
2832 local fid=$(copy_file /etc/passwd $f)
2833 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2834 wait_request_state $fid ARCHIVE SUCCEED
2837 cdt_set_non_blocking_restore
2842 wait_request_state $fid RESTORE SUCCEED
2843 cdt_clear_non_blocking_restore
2847 error "md5sum returns $st != 1, "\
2848 "should also perror ENODATA (No data available)"
2852 run_test 110b "Non blocking restore policy (release case)"
2855 # test needs a running copytool
2859 copy2archive /etc/passwd $tdir/$tfile
2861 local f=$DIR/$tdir/$tfile
2863 import_file $tdir/$tfile $f
2864 local fid=$(path2fid $f)
2868 copytool_remove_backend $fid
2871 wait_request_state $fid RESTORE FAILED
2878 [[ $st == 0 ]] || error "Restore does not failed"
2882 run_test 111a "No retry policy (import case), restore will error"\
2883 " (No such file or directory)"
2886 # test needs a running copytool
2890 local f=$DIR/$tdir/$tfile
2891 local fid=$(copy_file /etc/passwd $f)
2893 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2894 wait_request_state $fid ARCHIVE SUCCEED
2897 copytool_remove_backend $fid
2900 wait_request_state $fid RESTORE FAILED
2907 [[ $st == 0 ]] || error "Restore does not failed"
2911 run_test 111b "No retry policy (release case), restore will error"\
2912 " (No such file or directory)"
2915 # test needs a running copytool
2919 local f=$DIR/$tdir/$tfile
2920 local fid=$(copy_file /etc/passwd $f)
2922 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2923 local l=$($LFS hsm_action $f)
2925 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2929 wait_request_state $fid ARCHIVE SUCCEED
2932 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2936 run_test 112 "State of recorded request"
2939 # test needs a running copytool
2943 local f=$DIR/$tdir/$tfile
2944 local fid=$(make_large_for_cancel $f)
2945 # test with cdt on is made in test_221
2947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2950 wait_request_state $fid ARCHIVE CANCELED
2951 wait_request_state $fid CANCEL SUCCEED
2955 run_test 200 "Register/Cancel archive"
2958 # test needs a running copytool
2962 local f=$DIR/$tdir/$tfile
2963 make_archive $tdir/$tfile
2964 import_file $tdir/$tfile $f
2965 local fid=$(path2fid $f)
2967 # test with cdt on is made in test_222
2972 wait_request_state $fid RESTORE CANCELED
2973 wait_request_state $fid CANCEL SUCCEED
2977 run_test 201 "Register/Cancel restore"
2980 # test needs a running copytool
2984 local f=$DIR/$tdir/$tfile
2985 local fid=$(make_large_for_progress $f)
2986 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2987 wait_request_state $fid ARCHIVE SUCCEED
2993 wait_request_state $fid REMOVE CANCELED
2997 run_test 202 "Register/Cancel remove"
3000 # test needs a running copytool
3005 local f=$DIR/$tdir/$tfile
3006 local fid=$(copy_file /etc/passwd $f)
3010 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3011 wait_request_state $fid ARCHIVE SUCCEED
3013 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3017 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3021 run_test 220 "Changelog for archive"
3024 # test needs a running copytool
3029 local f=$DIR/$tdir/$tfile
3030 local fid=$(make_large_for_cancel $f)
3034 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3035 wait_request_state $fid ARCHIVE STARTED
3037 wait_request_state $fid ARCHIVE CANCELED
3038 wait_request_state $fid CANCEL SUCCEED
3040 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3043 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3047 run_test 221 "Changelog for archive canceled"
3050 # test needs a running copytool
3054 copy2archive /etc/passwd $tdir/$tfile
3056 local f=$DIR/$tdir/$tfile
3057 import_file $tdir/$tfile $f
3058 local fid=$(path2fid $f)
3063 wait_request_state $fid RESTORE SUCCEED
3065 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3068 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3072 run_test 222a "Changelog for explicit restore"
3075 # test needs a running copytool
3079 local f=$DIR/$tdir/$tfile
3080 local fid=$(copy_file /etc/passwd $f)
3083 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3084 wait_request_state $fid ARCHIVE SUCCEED
3089 wait_request_state $fid RESTORE SUCCEED
3091 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3094 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3098 run_test 222b "Changelog for implicit restore"
3101 # test needs a running copytool
3106 local f=$DIR/$tdir/$tfile
3107 make_archive $tdir/$tfile
3111 import_file $tdir/$tfile $f
3112 local fid=$(path2fid $f)
3115 wait_request_state $fid RESTORE STARTED
3117 wait_request_state $fid RESTORE CANCELED
3118 wait_request_state $fid CANCEL SUCCEED
3120 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3123 [[ $flags == $target ]] ||
3124 error "Changelog flag is $flags not $target"
3128 run_test 223a "Changelog for restore canceled (import case)"
3131 # test needs a running copytool
3136 local f=$DIR/$tdir/$tfile
3137 local fid=$(make_large_for_progress $f)
3140 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3141 wait_request_state $fid ARCHIVE SUCCEED
3144 wait_request_state $fid RESTORE STARTED
3146 wait_request_state $fid RESTORE CANCELED
3147 wait_request_state $fid CANCEL SUCCEED
3149 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3152 [[ $flags == $target ]] ||
3153 error "Changelog flag is $flags not $target"
3157 run_test 223b "Changelog for restore canceled (release case)"
3160 # test needs a running copytool
3165 local f=$DIR/$tdir/$tfile
3166 local fid=$(copy_file /etc/passwd $f)
3169 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3170 wait_request_state $fid ARCHIVE SUCCEED
3173 wait_request_state $fid REMOVE SUCCEED
3175 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3178 [[ $flags == $target ]] ||
3179 error "Changelog flag is $flags not $target"
3183 run_test 224 "Changelog for remove"
3186 # test needs a running copytool
3189 # test is not usable because remove request is too fast
3190 # so it is always finished before cancel can be done ...
3191 echo "Test disabled"
3196 local f=$DIR/$tdir/$tfile
3197 local fid=$(make_large_for_progress $f)
3200 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3201 wait_request_state $fid ARCHIVE SUCCEED
3203 # if cdt is on, it can serve too quickly the request
3208 wait_request_state $fid REMOVE CANCELED
3209 wait_request_state $fid CANCEL SUCCEED
3211 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3212 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3213 tail -n 1 | awk '{print $5}')
3216 [[ $flags == $target ]] ||
3217 error "Changelog flag is $flags not $target"
3221 run_test 225 "Changelog for remove canceled"
3224 # test needs a running copytool
3229 local f1=$DIR/$tdir/$tfile-1
3230 local f2=$DIR/$tdir/$tfile-2
3231 local f3=$DIR/$tdir/$tfile-3
3232 local fid1=$(copy_file /etc/passwd $f1)
3233 local fid2=$(copy_file /etc/passwd $f2)
3234 copy_file /etc/passwd $f3
3237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3238 wait_request_state $fid1 ARCHIVE SUCCEED
3240 $LFS hsm_archive $f2
3241 wait_request_state $fid2 ARCHIVE SUCCEED
3243 rm $f1 || error "rm $f1 failed"
3245 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3248 [[ $flags == $target ]] ||
3249 error "Changelog flag is $flags not $target"
3251 mv $f3 $f2 || error "mv $f3 $f2 failed"
3253 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3256 [[ $flags == $target ]] ||
3257 error "Changelog flag is $flags not $target"
3261 run_test 226 "changelog for last rm/mv with exiting archive"
3263 check_flags_changes() {
3271 $LFS hsm_set --$hsm_flag $f ||
3272 error "Cannot set $hsm_flag on $f"
3273 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3274 local seen=${#flags[*]}
3276 [[ $seen == $cnt ]] ||
3277 error "set $hsm_flag: Changelog events $seen != $cnt"
3278 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3279 error "set $hsm_flag: Changelog flags are "\
3280 "${flags[$((cnt - 1))]} not $target"
3282 $LFS hsm_clear --$hsm_flag $f ||
3283 error "Cannot clear $hsm_flag on $f"
3284 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3287 [[ $cnt == $seen ]] ||
3288 error "clear $hsm_flag: Changelog events $seen != $cnt"
3290 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3291 error "clear $hsm_flag: Changelog flag is "\
3292 "${flags[$((cnt - 1))]} not $target"
3296 # test needs a running copytool
3303 for i in norelease noarchive exists archived
3305 local f=$DIR/$tdir/$tfile-$i
3306 local fid=$(copy_file /etc/passwd $f)
3307 check_flags_changes $f $fid $i 0 1
3310 f=$DIR/$tdir/$tfile---lost
3311 fid=$(copy_file /etc/passwd $f)
3312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3313 wait_request_state $fid ARCHIVE SUCCEED
3314 check_flags_changes $f $fid lost 3 1
3318 run_test 227 "changelog when explicit setting of HSM flags"
3321 # test needs a running copytool
3324 local fid=$(make_small_sync $DIR/$tfile)
3325 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3326 wait_request_state $fid ARCHIVE SUCCEED
3328 $LFS hsm_release $DIR/$tfile
3329 check_hsm_flags $DIR/$tfile "0x0000000d"
3331 filefrag $DIR/$tfile | grep " 1 extent found" ||
3332 error "filefrag on released file must return only one extent"
3334 # only newer versions of cp detect sparse files by stat/FIEMAP
3336 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3337 error "copying $DIR/$tfile"
3338 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3340 $LFS hsm_release $DIR/$tfile
3341 check_hsm_flags $DIR/$tfile "0x0000000d"
3343 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3345 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3347 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3348 error "comparing untarred $DIR/$tfile"
3350 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3351 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3354 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3357 # test needs a running copytool
3361 local maxrequest=$(get_hsm_param max_requests)
3362 local rqcnt=$(($maxrequest * 3))
3366 for i in $(seq -w 1 $rqcnt); do
3368 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3370 # we do it in 2 steps, so all requests arrive at the same time
3371 for i in $(seq -w 1 $rqcnt); do
3372 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3377 while [[ $cnt != 0 || $wt != 0 ]]; do
3379 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3380 $HSM_PARAM.actions |\
3381 grep STARTED | grep -v CANCEL | wc -l")
3382 [[ $cnt -le $maxrequest ]] ||
3383 error "$cnt > $maxrequest too many started requests"
3384 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3385 $HSM_PARAM.actions |\
3386 grep WAITING | wc -l")
3387 echo "max=$maxrequest started=$cnt waiting=$wt"
3392 run_test 250 "Coordinator max request"
3395 # test needs a running copytool
3399 local f=$DIR/$tdir/$tfile
3400 local fid=$(make_large_for_cancel $f)
3403 # to have a short test
3404 local old_to=$(get_hsm_param active_request_timeout)
3405 set_hsm_param active_request_timeout 4
3406 # to be sure the cdt will wake up frequently so
3407 # it will be able to cancel the "old" request
3408 local old_loop=$(get_hsm_param loop_period)
3409 set_hsm_param loop_period 2
3412 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3413 wait_request_state $fid ARCHIVE STARTED
3415 wait_request_state $fid ARCHIVE CANCELED
3417 set_hsm_param active_request_timeout $old_to
3418 set_hsm_param loop_period $old_loop
3422 run_test 251 "Coordinator request timeout"
3425 # the only way to test ondisk conf is to restart MDS ...
3426 echo "Stop coordinator and remove coordinator state at mount"
3429 # clean on disk conf set by default
3430 cdt_clear_mount_state
3431 cdt_check_state stopped
3433 # check cdt still off after umount/remount
3435 cdt_check_state stopped
3437 echo "Set coordinator start at mount, and start coordinator"
3438 cdt_set_mount_state enabled
3441 cdt_check_state enabled
3443 # check cdt still on after umount/remount
3445 cdt_check_state enabled
3447 # we are back to original state (cdt started at mount)
3449 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3452 local ai=$(get_hsm_param default_archive_id)
3453 local new=$((ai + 1))
3455 set_hsm_param default_archive_id $new -P
3457 local res=$(get_hsm_param default_archive_id)
3460 set_hsm_param default_archive_id "" "-P -d"
3462 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3464 run_test 301 "HSM tunnable are persistent"
3467 local ai=$(get_hsm_param default_archive_id)
3468 local new=$((ai + 1))
3473 set_hsm_param default_archive_id $new -P
3476 for mdtno in $(seq 1 $MDSCOUNT); do
3481 cdt_check_state enabled
3483 local res=$(get_hsm_param default_archive_id)
3486 set_hsm_param default_archive_id "" "-P -d"
3488 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3490 run_test 302 "HSM tunnable are persistent when CDT is off"
3493 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3499 local dir_mdt0=$DIR/$tdir/mdt0
3500 local dir_mdt1=$DIR/$tdir/mdt1
3502 # create 1 dir per MDT
3503 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3504 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3506 # create 1 file in each MDT
3507 local fid1=$(make_small $dir_mdt0/$tfile)
3508 local fid2=$(make_small $dir_mdt1/$tfile)
3510 # check that hsm request on mdt0 is sent to the right MDS
3511 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3512 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3513 echo "archive successful on mdt0"
3515 # check that hsm request on mdt1 is sent to the right MDS
3516 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3517 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3518 echo "archive successful on mdt1"
3521 # clean test files and directories
3522 rm -rf $dir_mdt0 $dir_mdt1
3524 run_test 400 "Single request is sent to the right MDT"
3527 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3533 local dir_mdt0=$DIR/$tdir/mdt0
3534 local dir_mdt1=$DIR/$tdir/mdt1
3536 # create 1 dir per MDT
3537 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3538 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3540 # create 1 file in each MDT
3541 local fid1=$(make_small $dir_mdt0/$tfile)
3542 local fid2=$(make_small $dir_mdt1/$tfile)
3544 # check that compound requests are shunt to the rights MDTs
3545 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3546 error "lfs hsm_archive"
3547 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3548 echo "archive successful on mdt0"
3549 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3550 echo "archive successful on mdt1"
3553 # clean test files and directories
3554 rm -rf $dir_mdt0 $dir_mdt1
3556 run_test 401 "Compound requests split and sent to their respective MDTs"
3558 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3563 local node=$(facet_active_host $facet)
3565 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3566 awk '{print $4}'); do
3567 echo "$3 $mdc on $node"
3568 do_facet $facet "$LCTL --device $mdc $state" || return 1
3573 # make sure there is no running copytool
3576 # deactivate all mdc on agent1
3577 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3579 copytool_setup $SINGLEAGT
3581 check_agent_unregistered "uuid" # match any agent
3583 # no expected running copytool
3584 search_copytools $agent && error "Copytool start should have failed"
3587 mdc_change_state $SINGLEAGT "MDT000." "activate"
3589 run_test 402 "Copytool start fails if all MDTs are inactive"
3592 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3594 # make sure there is no running copytool
3597 local agent=$(facet_active_host $SINGLEAGT)
3598 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3600 # deactivate all mdc for MDT0001
3601 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3604 # check the agent is registered on MDT0000, and not on MDT0001
3605 check_agent_registered_by_mdt $uuid 0
3606 check_agent_unregistered_by_mdt $uuid 1
3608 # check running copytool process
3609 search_copytools $agent || error "No running copytools on $agent"
3611 # reactivate all mdc for MDT0001
3612 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3614 # make sure the copytool is now registered to all MDTs
3615 check_agent_registered $uuid
3619 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3622 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3626 # create files on both MDT0000 and MDT0001
3629 local dir_mdt0=$DIR/$tdir/mdt0
3630 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3632 # create 1 file on mdt0
3633 local fid1=$(make_small $dir_mdt0/$tfile)
3635 # deactivate all mdc for MDT0001
3636 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3638 # send an HSM request for files in MDT0000
3639 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3641 # check for completion of files in MDT0000
3642 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3643 echo "archive successful on mdt0"
3645 # reactivate all mdc for MDT0001
3646 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3649 # clean test files and directories
3652 run_test 404 "Inactive MDT does not block requests for active MDTs"
3657 check_and_cleanup_lustre