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)
131 search_and_kill_copytool() {
132 local agents=${1:-$(facet_active_host $SINGLEAGT)}
134 echo "Killing existing copytools on $agents"
135 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
139 local facet=${1:-$SINGLEAGT}
140 local lustre_mntpnt=${2:-$MOUNT}
142 local hsm_root=$(copytool_device $facet)
143 local agent=$(facet_active_host $facet)
145 if [[ -z "$arc_id" ]] &&
146 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
147 echo "Wakeup copytool $facet on $agent"
151 if $HSM_ARCHIVE_PURGE; then
152 echo "Purging archive on $agent"
153 do_facet $facet "rm -rf $hsm_root/*"
156 echo "Starting copytool $facet on $agent"
157 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
158 # bandwidth is limited to 1MB/s so the copy time is known and
159 # independent of hardware
160 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
161 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
162 cmd+=" --bandwidth 1 $lustre_mntpnt"
164 # Redirect the standard output and error to a log file which
165 # can be uploaded to Maloo.
166 local prefix=$TESTLOG_PREFIX
167 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
168 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
170 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
171 error "start copytool $facet on $agent failed"
177 local agents=${1:-$(facet_active_host $SINGLEAGT)}
183 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
185 echo "Copytool is stopped on $agents"
187 # clean all CDTs orphans requests from previous tests
188 # that would otherwise need to timeout to clear.
189 for mdtno in $(seq 1 $MDSCOUNT); do
191 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
192 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
194 # skip already stop[ed,ing] CDTs
195 echo $oldstate | grep stop && continue
197 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
198 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
200 error "mds${mdtno} cdt state is not stopped"
201 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
202 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
204 error "mds${mdtno} cdt state is not $oldstate"
209 local agents=${1:-$(facet_active_host $SINGLEAGT)}
211 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
212 echo "Copytool is suspended on $agents"
215 copytool_remove_backend() {
217 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
218 echo "Remove from backend: $fid = $be"
219 do_facet $SINGLEAGT rm -f $be
223 do_facet $SINGLEAGT \
224 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
225 --import $1 $2 $MOUNT" ||
226 error "import of $1 to $2 failed"
230 local file=$HSM_ARCHIVE/$1
231 do_facet $SINGLEAGT mkdir -p $(dirname $file)
232 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
233 error "cannot create $file"
237 local file=$HSM_ARCHIVE/$2
238 do_facet $SINGLEAGT mkdir -p $(dirname $file)
239 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
248 if [[ "$value" != "" ]]; then
251 for mdtno in $(seq 1 $MDSCOUNT); do
252 local idx=$(($mdtno - 1))
253 local facet=mds${mdtno}
254 # if $arg include -P option, run 1 set_param per MDT on the MGS
255 # else, run set_param on each MDT
256 [[ $arg = *"-P"* ]] && facet=mgs
257 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
258 [[ $? != 0 ]] && rc=1
268 for mdtno in $(seq 1 $MDSCOUNT); do
269 local idx=$(($mdtno - 1))
270 wait_result mds${mdtno} \
271 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
273 error "$key state is not '$target' on mds${mdtno}"
280 for mdtno in $(seq 1 $MDSCOUNT); do
281 local idx=$(($mdtno - 1))
282 local cl_user=$(do_facet mds${mdtno} $LCTL \
283 --device ${MDT[$idx]} \
284 changelog_register -n)
286 do_facet mds${mdtno} lctl set_param \
287 mdd.${MDT[$idx]}.changelog_mask="+hsm"
288 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
292 changelog_cleanup() {
294 for mdtno in $(seq 1 $MDSCOUNT); do
295 local idx=$(($mdtno - 1))
296 [[ -z ${CL_USERS[$idx]} ]] && continue
297 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
298 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
299 changelog_deregister ${CL_USERS[$idx]}
304 changelog_get_flags() {
309 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
314 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
322 mdts_set_param "$opt -n" "hsm.$param" "$value"
329 mdts_set_param "" hsm_control "$cmd"
330 mdts_check_param hsm_control "$target" 10
333 cdt_set_sanity_policy() {
334 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
337 mdts_set_param "" hsm.policy "+NRA"
338 mdts_set_param "" hsm.policy "-NBR"
339 CDT_POLICY_HAD_CHANGED=
344 mdts_set_param "" hsm.policy "+NRA"
345 CDT_POLICY_HAD_CHANGED=true
348 cdt_clear_no_retry() {
349 mdts_set_param "" hsm.policy "-NRA"
350 CDT_POLICY_HAD_CHANGED=true
353 cdt_set_non_blocking_restore() {
354 mdts_set_param "" hsm.policy "+NBR"
355 CDT_POLICY_HAD_CHANGED=true
358 cdt_clear_non_blocking_restore() {
359 mdts_set_param "" hsm.policy "-NBR"
360 CDT_POLICY_HAD_CHANGED=true
363 cdt_clear_mount_state() {
364 mdts_set_param "-P -d" hsm_control ""
367 cdt_set_mount_state() {
368 mdts_set_param "-P" hsm_control "$1"
372 mdts_check_param hsm_control "$1" 20
376 set_test_state disabled disabled
380 set_test_state enabled enabled
384 set_test_state shutdown stopped
388 set_test_state purge enabled
394 cdt_set_sanity_policy
398 local client_count=$1
399 if [[ $CLIENTCOUNT -lt $client_count ]]; then
400 skip "Need $client_count or more clients, have $CLIENTCOUNT"
407 $LFS path2fid $1 | tr -d '[]'
414 if [[ $u == "user" ]]; then
415 local st=$($RUNAS $LFS hsm_state $f)
417 local st=$($LFS hsm_state $f)
421 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
423 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
427 get_hsm_archive_id() {
429 local st=$($LFS hsm_state $f)
430 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
432 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
441 local st=$(get_hsm_flags $f)
442 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
445 check_hsm_flags_user() {
449 local st=$(get_hsm_flags $f user)
450 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
462 if [[ "$3" != 1 ]]; then
466 cp $1 $f || error "cannot copy $1 to $f"
467 path2fid $f || error "cannot get fid on $f"
471 local file2=${1/$DIR/$DIR2}
472 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
473 error "cannot create $file2"
474 path2fid $1 || error "cannot get fid on $1"
477 cleanup_large_files() {
478 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
480 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
483 make_large_for_striping() {
484 local file2=${1/$DIR/$DIR2}
485 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
489 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
490 error "cannot create $file2"
491 path2fid $1 || error "cannot get fid on $1"
494 make_large_for_progress() {
495 local file2=${1/$DIR/$DIR2}
499 # big file is large enough, so copy time is > 30s
500 # so copytool make 1 progress
501 # size is not a multiple of 1M to avoid stripe
503 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
504 error "cannot create $file2"
505 path2fid $1 || error "cannot get fid on $1"
508 make_large_for_progress_aligned() {
509 local file2=${1/$DIR/$DIR2}
513 # big file is large enough, so copy time is > 30s
514 # so copytool make 1 progress
515 # size is a multiple of 1M to have stripe
517 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
518 error "cannot create $file2"
519 path2fid $1 || error "cannot get fid on $1"
522 make_large_for_cancel() {
523 local file2=${1/$DIR/$DIR2}
527 # Copy timeout is 100s. 105MB => 105s
528 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
529 error "cannot create $file2"
530 path2fid $1 || error "cannot get fid on $1"
536 wait_update --verbose $(facet_active_host $facet) "$@"
539 wait_request_state() {
544 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
545 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
547 wait_result $SINGLEMDS "$cmd" $state 100 ||
548 error "request on $fid is not $state"
551 get_request_state() {
555 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
556 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
559 get_request_count() {
563 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
564 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
570 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
571 cmd+=" | egrep 'WAITING|STARTED'"
573 wait_result $SINGLEMDS "$cmd" "" $timeout ||
574 error "requests did not complete"
577 wait_for_grace_delay() {
578 local val=$(get_hsm_param grace_delay)
582 # populate MDT device array
588 # cleanup from previous bad setup
589 search_and_kill_copytool
591 # for recovery tests, coordinator needs to be started at mount
593 # the lustre conf must be without hsm on (like for sanity.sh)
594 echo "Set HSM on and start"
595 cdt_set_mount_state enabled
596 cdt_check_state enabled
598 echo "Start copytool"
601 echo "Set sanity-hsm HSM policy"
602 cdt_set_sanity_policy
604 # finished requests are quickly removed from list
605 set_hsm_param grace_delay 10
611 local f=$DIR/$tdir/$tfile
615 check_hsm_flags_user $f "0x00000000"
617 $RUNAS $LFS hsm_set --norelease $f ||
618 error "user could not change hsm flags"
619 check_hsm_flags_user $f "0x00000010"
621 $RUNAS $LFS hsm_clear --norelease $f ||
622 error "user could not clear hsm flags"
623 check_hsm_flags_user $f "0x00000000"
625 # User could not change those flags...
626 $RUNAS $LFS hsm_set --exists $f &&
627 error "user should not set this flag"
628 check_hsm_flags_user $f "0x00000000"
631 $LFS hsm_set --exists $f ||
632 error "root could not change hsm flags"
633 check_hsm_flags_user $f "0x00000001"
635 $LFS hsm_clear --exists $f ||
636 error "root could not clear hsm state"
637 check_hsm_flags_user $f "0x00000000"
640 run_test 1 "lfs hsm flags root/non-root access"
644 local f=$DIR/$tdir/$tfile
646 # New files are not dirty
647 check_hsm_flags $f "0x00000000"
649 # For test, we simulate an archived file.
650 $LFS hsm_set --exists $f || error "user could not change hsm flags"
651 check_hsm_flags $f "0x00000001"
653 # chmod do not put the file dirty
654 chmod 600 $f || error "could not chmod test file"
655 check_hsm_flags $f "0x00000001"
657 # chown do not put the file dirty
658 chown $RUNAS_ID $f || error "could not chown test file"
659 check_hsm_flags $f "0x00000001"
661 # truncate put the file dirty
662 $TRUNCATE $f 1 || error "could not truncate test file"
663 check_hsm_flags $f "0x00000003"
665 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
666 check_hsm_flags $f "0x00000001"
668 run_test 2 "Check file dirtyness when doing setattr"
674 # New files are not dirty
676 check_hsm_flags $f "0x00000000"
678 # For test, we simulate an archived file.
679 $LFS hsm_set --exists $f ||
680 error "user could not change hsm flags"
681 check_hsm_flags $f "0x00000001"
683 # Reading a file, does not set dirty
684 cat $f > /dev/null || error "could not read file"
685 check_hsm_flags $f "0x00000001"
687 # Open for write without modifying data, does not set dirty
688 openfile -f O_WRONLY $f || error "could not open test file"
689 check_hsm_flags $f "0x00000001"
691 # Append to a file sets it dirty
692 cp -p /etc/passwd $f.append || error "could not create file"
693 $LFS hsm_set --exists $f.append ||
694 error "user could not change hsm flags"
695 dd if=/etc/passwd of=$f.append bs=1 count=3\
696 conv=notrunc oflag=append status=noxfer ||
697 error "could not append to test file"
698 check_hsm_flags $f.append "0x00000003"
700 # Modify a file sets it dirty
701 cp -p /etc/passwd $f.modify || error "could not create file"
702 $LFS hsm_set --exists $f.modify ||
703 error "user could not change hsm flags"
704 dd if=/dev/zero of=$f.modify bs=1 count=3\
705 conv=notrunc status=noxfer ||
706 error "could not modify test file"
707 check_hsm_flags $f.modify "0x00000003"
709 # Open O_TRUNC sets dirty
710 cp -p /etc/passwd $f.trunc || error "could not create file"
711 $LFS hsm_set --exists $f.trunc ||
712 error "user could not change hsm flags"
713 cp /etc/group $f.trunc || error "could not override a file"
714 check_hsm_flags $f.trunc "0x00000003"
716 # Mmapped a file sets dirty
717 cp -p /etc/passwd $f.mmap || error "could not create file"
718 $LFS hsm_set --exists $f.mmap ||
719 error "user could not change hsm flags"
720 multiop $f.mmap OSMWUc || error "could not mmap a file"
721 check_hsm_flags $f.mmap "0x00000003"
723 run_test 3 "Check file dirtyness when opening for write"
727 local f=$DIR/$tdir/$tfile
728 local fid=$(make_small $f)
731 local st=$(get_request_state $fid CANCEL)
732 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
734 run_test 4 "Useless cancel must not be registered"
737 # test needs a running copytool
741 local f=$DIR/$tdir/$tfile
742 local fid=$(copy_file /etc/passwd $f)
744 wait_request_state $fid ARCHIVE SUCCEED
746 check_hsm_flags $f "0x00000009"
750 run_test 8 "Test default archive number"
754 local f=$DIR/$tdir/$tfile
755 local fid=$(copy_file /etc/passwd $f)
756 # we do not use the default one to be sure
757 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
759 copytool_setup $SINGLEAGT $MOUNT $new_an
760 $LFS hsm_archive --archive $new_an $f
761 wait_request_state $fid ARCHIVE SUCCEED
763 check_hsm_flags $f "0x00000009"
767 run_test 9 "Use of explict archive number, with dedicated copytool"
770 needclients 3 || return 0
776 copytool_cleanup $(comma_list $(agts_nodes))
778 # start all of the copytools
779 for n in $(seq $AGTCOUNT); do
783 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
786 for n in $(seq $AGTCOUNT); do
787 file=$DIR/$tdir/$tfile.$n
788 fid=$(make_small $file)
790 $LFS hsm_archive $file || error "could not archive file $file"
791 wait_request_state $fid ARCHIVE SUCCEED
792 check_hsm_flags $file "0x00000009"
796 copytool_cleanup $(comma_list $(agts_nodes))
798 run_test 9a "Multiple remote agents"
801 # test needs a running copytool
804 mkdir -p $DIR/$tdir/d1
805 local f=$DIR/$tdir/$tfile
806 local fid=$(copy_file /etc/hosts $f)
807 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
808 error "hsm_archive failed"
809 wait_request_state $fid ARCHIVE SUCCEED
811 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
812 error "fid $fid not in archive $HSM_ARCHIVE"
813 echo "Verifying content"
814 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
815 echo "Verifying hsm state "
816 check_hsm_flags $f "0x00000009"
818 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
819 local st=$(get_hsm_archive_id $f)
820 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
821 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
826 run_test 10a "Archive a file"
829 # test needs a running copytool
833 local f=$DIR/$tdir/$tfile
834 local fid=$(copy_file /etc/hosts $f)
835 $LFS hsm_archive $f || error "archive request failed"
836 wait_request_state $fid ARCHIVE SUCCEED
838 $LFS hsm_archive $f || error "archive of non dirty file failed"
839 local cnt=$(get_request_count $fid ARCHIVE)
840 [[ "$cnt" == "1" ]] ||
841 error "archive of non dirty file must not make a request"
845 run_test 10b "Archive of non dirty file must work without doing request"
848 # test needs a running copytool
852 local f=$DIR/$tdir/$tfile
853 local fid=$(copy_file /etc/hosts $f)
854 $LFS hsm_set --noarchive $f
855 $LFS hsm_archive $f && error "archive a noarchive file must fail"
859 run_test 10c "Check forbidden archive"
862 # test needs a running copytool
866 local f=$DIR/$tdir/$tfile
867 local fid=$(copy_file /etc/hosts $f)
868 $LFS hsm_archive $f || error "cannot archive $f"
869 wait_request_state $fid ARCHIVE SUCCEED
871 local ar=$(get_hsm_archive_id $f)
872 local dflt=$(get_hsm_param default_archive_id)
873 [[ $ar == $dflt ]] ||
874 error "archived file is not on default archive: $ar != $dflt"
878 run_test 10d "Archive a file on the default archive id"
882 copy2archive /etc/hosts $tdir/$tfile
883 local f=$DIR/$tdir/$tfile
885 import_file $tdir/$tfile $f
886 echo -n "Verifying released state: "
887 check_hsm_flags $f "0x0000000d"
889 local LSZ=$(stat -c "%s" $f)
890 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
892 echo "Verifying imported size $LSZ=$ASZ"
893 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
894 echo -n "Verifying released pattern: "
895 local PTRN=$($GETSTRIPE -L $f)
897 [[ $PTRN == 80000001 ]] || error "Is not released"
898 local fid=$(path2fid $f)
899 echo "Verifying new fid $fid in archive"
901 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
902 error "fid $fid not in archive $HSM_ARCHIVE"
904 run_test 11 "Import a file"
907 # test needs a running copytool
911 copy2archive /etc/hosts $tdir/$tfile
913 local f=$DIR/$tdir/$tfile
914 import_file $tdir/$tfile $f
915 local f=$DIR2/$tdir/$tfile
916 echo "Verifying released state: "
917 check_hsm_flags $f "0x0000000d"
919 local fid=$(path2fid $f)
921 wait_request_state $fid RESTORE SUCCEED
923 echo "Verifying file state: "
924 check_hsm_flags $f "0x00000009"
926 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
928 [[ $? -eq 0 ]] || error "Restored file differs"
932 run_test 12a "Restore an imported file explicitly"
935 # test needs a running copytool
939 copy2archive /etc/hosts $tdir/$tfile
941 local f=$DIR/$tdir/$tfile
942 import_file $tdir/$tfile $f
943 echo "Verifying released state: "
944 check_hsm_flags $f "0x0000000d"
946 cat $f > /dev/null || error "File read failed"
948 echo "Verifying file state after restore: "
949 check_hsm_flags $f "0x00000009"
951 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
953 [[ $? -eq 0 ]] || error "Restored file differs"
957 run_test 12b "Restore an imported file implicitly"
960 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
962 # test needs a running copytool
966 local f=$DIR/$tdir/$tfile
967 $LFS setstripe -c 2 $f
968 local fid=$(make_large_for_striping $f)
969 local FILE_CRC=$(md5sum $f)
971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
972 wait_request_state $fid ARCHIVE SUCCEED
973 $LFS hsm_release $f || error "release $f failed"
975 echo "$FILE_CRC" | md5sum -c
977 [[ $? -eq 0 ]] || error "Restored file differs"
981 run_test 12c "Restore a file with stripe of 2"
984 # test needs a running copytool
989 local f=$DIR/$tdir/$tfile
990 local fid=$(copy_file /etc/hosts $f)
991 $LFS hsm_restore $f || error "restore of non archived file failed"
992 local cnt=$(get_request_count $fid RESTORE)
993 [[ "$cnt" == "0" ]] ||
994 error "restore non archived must not make a request"
995 $LFS hsm_archive $f ||
996 error "archive request failed"
997 wait_request_state $fid ARCHIVE SUCCEED
998 $LFS hsm_restore $f ||
999 error "restore of non released file failed"
1000 local cnt=$(get_request_count $fid RESTORE)
1001 [[ "$cnt" == "0" ]] ||
1002 error "restore a non dirty file must not make a request"
1006 run_test 12d "Restore of a non archived, non released file must work"\
1007 " without doing request"
1010 # test needs a running copytool
1013 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1014 local f=$DIR/$tdir/$tfile
1015 local fid=$(copy_file /etc/hosts $f)
1016 $LFS hsm_archive $f || error "archive request failed"
1017 wait_request_state $fid ARCHIVE SUCCEED
1020 cat /etc/hosts >> $f
1024 $LFS hsm_restore $f && error "restore a dirty file must fail"
1028 run_test 12e "Check forbidden restore"
1031 # test needs a running copytool
1035 local f=$DIR/$tdir/$tfile
1036 local fid=$(copy_file /etc/hosts $f)
1038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1039 wait_request_state $fid ARCHIVE SUCCEED
1040 $LFS hsm_release $f || error "release of $f failed"
1042 wait_request_state $fid RESTORE SUCCEED
1044 echo -n "Verifying file state: "
1045 check_hsm_flags $f "0x00000009"
1047 diff -q /etc/hosts $f
1049 [[ $? -eq 0 ]] || error "Restored file differs"
1053 run_test 12f "Restore a released file explicitly"
1056 # test needs a running copytool
1060 local f=$DIR/$tdir/$tfile
1061 local fid=$(copy_file /etc/hosts $f)
1063 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1064 wait_request_state $fid ARCHIVE SUCCEED
1065 $LFS hsm_release $f || error "release of $f failed"
1067 diff -q /etc/hosts $f
1070 # we check we had a restore done
1071 wait_request_state $fid RESTORE SUCCEED
1073 [[ $st -eq 0 ]] || error "Restored file differs"
1077 run_test 12g "Restore a released file implicitly"
1080 needclients 2 || return 0
1082 # test needs a running copytool
1086 local f=$DIR/$tdir/$tfile
1087 local fid=$(copy_file /etc/hosts $f)
1089 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1090 wait_request_state $fid ARCHIVE SUCCEED
1091 $LFS hsm_release $f || error "release of $f failed"
1093 do_node $CLIENT2 diff -q /etc/hosts $f
1096 # we check we had a restore done
1097 wait_request_state $fid RESTORE SUCCEED
1099 [[ $st -eq 0 ]] || error "Restored file differs"
1103 run_test 12h "Restore a released file implicitly from a second node"
1106 # test needs a running copytool
1110 local f=$DIR/$tdir/$tfile
1111 local fid=$(copy_file /etc/passwd $f)
1112 $LFS hsm_archive $f || error "archive of $f failed"
1113 wait_request_state $fid ARCHIVE SUCCEED
1115 $LFS hsm_release $f || error "release of $f failed"
1119 [[ $? -eq 0 ]] || error "Restored file differs"
1123 run_test 12m "Archive/release/implicit restore"
1126 # test needs a running copytool
1130 copy2archive /etc/hosts $tdir/$tfile
1132 local f=$DIR/$tdir/$tfile
1133 import_file $tdir/$tfile $f
1135 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1136 error "Restored file differs"
1138 $LFS hsm_release $f || error "release of $f failed"
1142 run_test 12n "Import/implicit restore/release"
1145 # test needs a running copytool
1148 local ARC_SUBDIR="import.orig"
1152 # populate directory to be imported
1153 for d in $(seq 1 10); do
1154 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1155 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1156 for f in $(seq 1 10); do
1157 CURR_FILE="$CURR_DIR/$tfile.$f"
1158 # write file-specific data
1159 do_facet $SINGLEAGT \
1160 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1161 "file=$CURR_FILE > $CURR_FILE"
1165 import_file "$ARC_SUBDIR" $DIR/$tdir
1166 # diff lustre content and origin (triggers file restoration)
1167 # there must be 10x10 identical files, and no difference
1168 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1169 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1170 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1171 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1173 [ $cnt_diff -eq 0 ] ||
1174 error "$cnt_diff imported files differ from read data"
1175 [ $cnt_ok -eq 100 ] ||
1176 error "not enough identical files ($cnt_ok != 100)"
1180 run_test 13 "Recursively import and restore a directory"
1183 # test needs a running copytool
1188 local f=$DIR/$tdir/$tfile
1189 local fid=$(make_small $f)
1190 local sum=$(md5sum $f | awk '{print $1}')
1191 $LFS hsm_archive $f || error "could not archive file"
1192 wait_request_state $fid ARCHIVE SUCCEED
1196 # create released file (simulate llapi_hsm_import call)
1198 local fid2=$(path2fid $f)
1199 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1200 $LFS hsm_release $f || error "could not release file"
1202 # rebind the archive to the newly created file
1203 echo "rebind $fid to $fid2"
1205 do_facet $SINGLEAGT \
1206 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1207 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1209 # restore file and compare md5sum
1210 local sum2=$(md5sum $f | awk '{print $1}')
1212 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1216 run_test 14 "Rebind archived file to a new fid"
1219 # test needs a running copytool
1224 local f=$DIR/$tdir/$tfile
1226 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1230 for i in $(seq 1 $count); do
1231 fids[$i]=$(make_small $f.$i)
1232 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1233 $LFS hsm_archive $f.$i || error "could not archive file"
1235 wait_all_done $(($count*60))
1239 for i in $(seq 1 $count); do
1242 local fid2=$(path2fid $f.$i)
1243 # add the rebind operation to the list
1244 echo ${fids[$i]} $fid2 >> $tmpfile
1246 # set it released (simulate llapi_hsm_import call)
1247 $LFS hsm_set --archived --exists $f.$i ||
1248 error "could not force hsm flags"
1249 $LFS hsm_release $f.$i || error "could not release file"
1251 nl=$(wc -l < $tmpfile)
1252 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1254 echo "rebind list of files"
1255 do_facet $SINGLEAGT \
1256 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1257 --rebind $tmpfile $DIR" || error "could not rebind file list"
1259 # restore files and compare md5sum
1260 for i in $(seq 1 $count); do
1261 local sum2=$(md5sum $f.$i | awk '{print $1}')
1262 [[ $sum2 == ${sums[$i]} ]] ||
1263 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1269 run_test 15 "Rebind a list of files"
1272 # test needs a running copytool
1276 # create a known size file so we can verify transfer speed
1279 dd if=/dev/zero of=$ref bs=1M count=20
1282 local f=$DIR/$tdir/$tfile
1283 local fid=$(copy_file $ref $f)
1285 local start=$(date +%s)
1287 wait_request_state $fid ARCHIVE SUCCEED
1288 local end=$(date +%s)
1289 local duration=$((end - start))
1291 [[ $duration -ge $goal ]] ||
1292 error "Transfer is too fast $duration < $goal"
1296 run_test 16 "Test CT bandwith control option"
1301 local f=$DIR/$tdir/$tfile
1302 touch $f || error "touch $f failed"
1304 # Could not release a non-archived file
1305 $LFS hsm_release $f && error "release should not succeed"
1307 # For following tests, we must test them with HS_ARCHIVED set
1308 $LFS hsm_set --exists --archived $f || error "could not add flag"
1310 # Could not release a file if no-release is set
1311 $LFS hsm_set --norelease $f || error "could not add flag"
1312 $LFS hsm_release $f && error "release should not succeed"
1313 $LFS hsm_clear --norelease $f || error "could not remove flag"
1315 # Could not release a file if lost
1316 $LFS hsm_set --lost $f || error "could not add flag"
1317 $LFS hsm_release $f && error "release should not succeed"
1318 $LFS hsm_clear --lost $f || error "could not remove flag"
1320 # Could not release a file if dirty
1321 $LFS hsm_set --dirty $f || error "could not add flag"
1322 $LFS hsm_release $f && error "release should not succeed"
1323 $LFS hsm_clear --dirty $f || error "could not remove flag"
1325 run_test 20 "Release is not permitted"
1328 # test needs a running copytool
1332 local f=$DIR/$tdir/test_release
1334 # Create a file and check its states
1335 local fid=$(make_small $f)
1336 check_hsm_flags $f "0x00000000"
1338 local orig_size=$(stat -c "%s" $f)
1339 local orig_blocks=$(stat -c "%b" $f)
1341 start_full_debug_logging
1343 $LFS hsm_archive $f || error "could not archive file"
1344 wait_request_state $fid ARCHIVE SUCCEED
1346 local blocks=$(stat -c "%b" $f)
1347 [ $blocks -eq $orig_blocks ] ||
1348 error "$f: wrong block number after archive: " \
1349 "$blocks != $orig_blocks"
1350 local size=$(stat -c "%s" $f)
1351 [ $size -eq $orig_size ] ||
1352 error "$f: wrong size after archive: $size != $orig_size"
1354 # Release and check states
1355 $LFS hsm_release $f || error "could not release file"
1356 check_hsm_flags $f "0x0000000d"
1358 blocks=$(stat -c "%b" $f)
1359 [ $blocks -gt 5 ] &&
1360 error "$f: too many blocks after release: $blocks > 5"
1361 size=$(stat -c "%s" $f)
1362 [ $size -ne $orig_size ] &&
1363 error "$f: wrong size after release: $size != $orig_size"
1365 # Check we can release an file without stripe info
1369 check_hsm_flags $f "0x00000000"
1370 $LFS hsm_archive $f || error "could not archive file"
1371 wait_request_state $fid ARCHIVE SUCCEED
1373 # Release and check states
1374 $LFS hsm_release $f || error "could not release file"
1375 check_hsm_flags $f "0x0000000d"
1377 # Release again a file that is already released is OK
1378 $LFS hsm_release $f || fail "second release should succeed"
1379 check_hsm_flags $f "0x0000000d"
1381 stop_full_debug_logging
1385 run_test 21 "Simple release tests"
1388 # test needs a running copytool
1393 local f=$DIR/$tdir/test_release
1394 local swap=$DIR/$tdir/test_swap
1396 # Create a file and check its states
1397 local fid=$(make_small $f)
1398 check_hsm_flags $f "0x00000000"
1400 $LFS hsm_archive $f || error "could not archive file"
1401 wait_request_state $fid ARCHIVE SUCCEED
1403 # Release and check states
1404 $LFS hsm_release $f || error "could not release file"
1405 check_hsm_flags $f "0x0000000d"
1408 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1413 run_test 22 "Could not swap a release file"
1416 # test needs a running copytool
1421 local f=$DIR/$tdir/test_mtime
1423 # Create a file and check its states
1424 local fid=$(make_small $f)
1425 check_hsm_flags $f "0x00000000"
1427 $LFS hsm_archive $f || error "could not archive file"
1428 wait_request_state $fid ARCHIVE SUCCEED
1430 # Set modification time in the past
1431 touch -m -a -d @978261179 $f
1433 # Release and check states
1434 $LFS hsm_release $f || error "could not release file"
1435 check_hsm_flags $f "0x0000000d"
1437 local MTIME=$(stat -c "%Y" $f)
1438 local ATIME=$(stat -c "%X" $f)
1439 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1440 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1444 run_test 23 "Release does not change a/mtime (utime)"
1447 local file=$DIR/$tdir/$tfile
1456 # test needs a running copytool
1461 fid=$(make_small $file)
1463 # Create a file and check its states
1464 check_hsm_flags $file "0x00000000"
1466 # Ensure atime is less than mtime and ctime.
1470 atime0=$(stat -c "%X" $file)
1471 mtime0=$(stat -c "%Y" $file)
1472 ctime0=$(stat -c "%Z" $file)
1474 [ $atime0 -lt $mtime0 ] ||
1475 error "atime $atime0 is not less than mtime $mtime0"
1477 [ $atime0 -lt $ctime0 ] ||
1478 error "atime $atime0 is not less than ctime $ctime0"
1480 # Archive should not change any timestamps.
1481 $LFS hsm_archive $file || error "cannot archive '$file'"
1482 wait_request_state $fid ARCHIVE SUCCEED
1484 atime1=$(stat -c "%X" $file)
1485 mtime1=$(stat -c "%Y" $file)
1486 ctime1=$(stat -c "%Z" $file)
1488 [ $atime0 -eq $atime1 ] ||
1489 error "archive changed atime from $atime0 to $atime1"
1491 [ $mtime0 -eq $mtime1 ] ||
1492 error "archive changed mtime from $mtime0 to $mtime1"
1494 [ $ctime0 -eq $ctime1 ] ||
1495 error "archive changed ctime from $ctime0 to $ctime1"
1497 # Release should not change any timestamps.
1498 $LFS hsm_release $file || error "cannot release '$file'"
1499 check_hsm_flags $file "0x0000000d"
1501 atime1=$(stat -c "%X" $file)
1502 mtime1=$(stat -c "%Y" $file)
1503 ctime1=$(stat -c "%Z" $file)
1505 [ $atime0 -eq $atime1 ] ||
1506 error "release changed atime from $atime0 to $atime1"
1508 [ $mtime0 -eq $mtime1 ] ||
1509 error "release changed mtime from $mtime0 to $mtime1"
1511 [ $ctime0 -eq $ctime1 ] ||
1512 error "release changed ctime from $ctime0 to $ctime1"
1514 # Restore should not change atime or mtime and should not
1516 $LFS hsm_restore $file
1517 wait_request_state $fid RESTORE SUCCEED
1519 atime1=$(stat -c "%X" $file)
1520 mtime1=$(stat -c "%Y" $file)
1521 ctime1=$(stat -c "%Z" $file)
1523 [ $atime0 -eq $atime1 ] ||
1524 error "restore changed atime from $atime0 to $atime1"
1526 [ $mtime0 -eq $mtime1 ] ||
1527 error "restore changed mtime from $mtime0 to $mtime1"
1529 [ $ctime0 -le $ctime1 ] ||
1530 error "restore changed ctime from $ctime0 to $ctime1"
1534 # Once more, after unmount and mount.
1535 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1536 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1538 atime1=$(stat -c "%X" $file)
1539 mtime1=$(stat -c "%Y" $file)
1540 ctime1=$(stat -c "%Z" $file)
1542 [ $atime0 -eq $atime1 ] ||
1543 error "remount changed atime from $atime0 to $atime1"
1545 [ $mtime0 -eq $mtime1 ] ||
1546 error "remount changed mtime from $mtime0 to $mtime1"
1548 [ $ctime0 -le $ctime1 ] ||
1549 error "remount changed ctime from $ctime0 to $ctime1"
1551 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1554 local file=$DIR/$tdir/$tfile
1560 # Test needs a running copytool.
1564 # Check that root can do HSM actions on a ordinary user's file.
1566 fid=$(make_small $file)
1567 sum0=$(md5sum $file)
1569 chown $RUNAS_ID:$RUNAS_GID $file ||
1570 error "cannot chown '$file' to '$RUNAS_ID'"
1572 chmod ugo-w $DIR/$tdir ||
1573 error "cannot chmod '$DIR/$tdir'"
1575 $LFS hsm_archive $file
1576 wait_request_state $fid ARCHIVE SUCCEED
1578 $LFS hsm_release $file
1579 check_hsm_flags $file "0x0000000d"
1581 $LFS hsm_restore $file
1582 wait_request_state $fid RESTORE SUCCEED
1584 # Check that ordinary user can get HSM state.
1585 $RUNAS $LFS hsm_state $file ||
1586 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1588 $LFS hsm_release $file
1589 check_hsm_flags $file "0x0000000d"
1591 # Check that ordinary user can accessed released file.
1592 sum1=$($RUNAS md5sum $file) ||
1593 error "user '$RUNAS_ID' cannot read '$file'"
1595 [ "$sum0" == "$sum1" ] ||
1596 error "md5sum mismatch for '$file'"
1600 run_test 24b "root can archive, release, and restore user files"
1602 cleanup_test_24c() {
1604 set_hsm_param user_request_mask RESTORE
1605 set_hsm_param group_request_mask RESTORE
1606 set_hsm_param other_request_mask RESTORE
1610 local file=$DIR/$tdir/$tfile
1611 local action=archive
1616 # test needs a running copytool
1621 # Save the default masks and check that cleanup_24c will
1622 # restore the request masks correctly.
1623 user_save=$(get_hsm_param user_request_mask)
1624 group_save=$(get_hsm_param group_request_mask)
1625 other_save=$(get_hsm_param other_request_mask)
1627 [ "$user_save" == RESTORE ] ||
1628 error "user_request_mask is '$user_save' expected 'RESTORE'"
1629 [ "$group_save" == RESTORE ] ||
1630 error "group_request_mask is '$group_save' expected 'RESTORE'"
1631 [ "$other_save" == RESTORE ] ||
1632 error "other_request_mask is '$other_save' expected 'RESTORE'"
1634 trap cleanup_test_24c EXIT
1639 chown $RUNAS_ID:nobody $file ||
1640 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1642 set_hsm_param user_request_mask ""
1643 $RUNAS $LFS hsm_$action $file &&
1644 error "$action by user should fail"
1646 set_hsm_param user_request_mask $action
1647 $RUNAS $LFS hsm_$action $file ||
1648 error "$action by user should succeed"
1653 chown nobody:$RUNAS_GID $file ||
1654 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1656 set_hsm_param group_request_mask ""
1657 $RUNAS $LFS hsm_$action $file &&
1658 error "$action by group should fail"
1660 set_hsm_param group_request_mask $action
1661 $RUNAS $LFS hsm_$action $file ||
1662 error "$action by group should succeed"
1667 chown nobody:nobody $file ||
1668 error "cannot chown '$file' to 'nobody:nobody'"
1670 set_hsm_param other_request_mask ""
1671 $RUNAS $LFS hsm_$action $file &&
1672 error "$action by other should fail"
1674 set_hsm_param other_request_mask $action
1675 $RUNAS $LFS hsm_$action $file ||
1676 error "$action by other should succeed"
1681 run_test 24c "check that user,group,other request masks work"
1683 cleanup_test_24d() {
1685 mount -o remount,rw $MOUNT2
1689 local file1=$DIR/$tdir/$tfile
1690 local file2=$DIR2/$tdir/$tfile
1698 fid1=$(make_small $file1)
1700 trap cleanup_test_24d EXIT
1702 mount -o remount,ro $MOUNT2
1704 fid2=$(path2fid $file2)
1705 [ "$fid1" == "$fid2" ] ||
1706 error "FID mismatch '$fid1' != '$fid2'"
1708 $LFS hsm_archive $file2 &&
1709 error "archive should fail on read-only mount"
1710 check_hsm_flags $file1 "0x00000000"
1712 $LFS hsm_archive $file1
1713 wait_request_state $fid1 ARCHIVE SUCCEED
1715 $LFS hsm_release $file1
1716 $LFS hsm_restore $file2
1717 wait_request_state $fid1 RESTORE SUCCEED
1719 $LFS hsm_release $file1 || error "cannot release '$file1'"
1720 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1722 $LFS hsm_release $file2 &&
1723 error "release should fail on read-only mount"
1728 run_test 24d "check that read-only mounts are respected"
1731 # test needs a running copytool
1735 copy2archive /etc/hosts $tdir/$tfile
1737 local f=$DIR/$tdir/$tfile
1739 import_file $tdir/$tfile $f
1741 $LFS hsm_set --lost $f
1746 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1750 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1751 " (Operation not permitted)"
1754 # test needs a running copytool
1759 local f=$DIR/$tdir/$tfile
1760 local fid=$(copy_file /etc/passwd $f)
1762 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1763 wait_request_state $fid ARCHIVE SUCCEED
1766 $LFS hsm_set --lost $f
1770 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1774 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1775 " (Operation not permitted)"
1778 # test needs a running copytool
1782 local f=$DIR/$tdir/$tfile
1783 local fid=$(make_large_for_progress $f)
1784 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1785 wait_request_state $fid ARCHIVE SUCCEED
1788 wait_request_state $fid REMOVE SUCCEED
1790 check_hsm_flags $f "0x00000000"
1794 run_test 26 "Remove the archive of a valid file"
1797 # test needs a running copytool
1801 make_archive $tdir/$tfile
1802 local f=$DIR/$tdir/$tfile
1803 import_file $tdir/$tfile $f
1804 local fid=$(path2fid $f)
1808 [[ $? != 0 ]] || error "Remove of a released file should fail"
1812 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1815 # test needs a running copytool
1819 local f=$DIR/$tdir/$tfile
1820 local fid=$(make_large_for_progress $f)
1821 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1822 wait_request_state $fid ARCHIVE SUCCEED
1827 [[ $? != 0 ]] || error "Remove of a released file should fail"
1831 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1834 # test needs a running copytool
1838 local f=$DIR/$tdir/$tfile
1839 local fid=$(make_large_for_progress $f)
1840 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1841 wait_request_state $fid ARCHIVE SUCCEED
1850 wait_request_state $fid REMOVE SUCCEED
1854 run_test 28 "Concurrent archive/file remove"
1857 # restore at exec cannot work on agent node (because of Linux kernel
1858 # protection of executables)
1859 needclients 2 || return 0
1861 # test needs a running copytool
1865 copy2archive /bin/true $tdir/$tfile
1867 local f=$DIR/$tdir/true
1868 import_file $tdir/$tfile $f
1870 local fid=$(path2fid $f)
1872 # set no retry action mode
1878 # remove no try action mode
1882 [[ $st == 0 ]] || error "Failed to exec a released file"
1886 run_test 30a "Restore at exec (import case)"
1889 # restore at exec cannot work on agent node (because of Linux kernel
1890 # protection of executables)
1891 needclients 2 || return 0
1893 # test needs a running copytool
1897 local f=$DIR/$tdir/true
1898 local fid=$(copy_file /bin/true $f)
1900 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1901 wait_request_state $fid ARCHIVE SUCCEED
1904 # set no retry action mode
1910 # remove no try action mode
1914 [[ $st == 0 ]] || error "Failed to exec a released file"
1918 run_test 30b "Restore at exec (release case)"
1921 needclients 2 || return 0
1923 # test needs a running copytool
1927 local f=$DIR/$tdir/SLEEP
1928 local fid=$(copy_file /bin/sleep $f)
1930 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1931 wait_request_state $fid ARCHIVE SUCCEED
1933 check_hsm_flags $f "0x0000000d"
1934 # set no retry action mode
1936 do_node $CLIENT2 "$f 10" &
1940 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1942 [[ $? == 0 ]] || error "Execution failed during run"
1944 [[ $? == 0 ]] || error "Binary overwritten during exec"
1947 # remove no try action mode
1949 check_hsm_flags $f "0x00000009"
1953 run_test 30c "Update during exec of released file must fail"
1955 restore_and_check_size() {
1958 local s=$(stat -c "%s" $f)
1960 local st=$(get_hsm_flags $f)
1964 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1966 n=$(stat -c "%s" $f)
1967 # we echo in both cases to show stat is not
1969 if [[ $n != $s ]]; then
1970 echo "size seen is $n != $s"
1973 echo "size seen is right: $n == $s"
1975 st=$(get_hsm_flags $f)
1979 if [[ $cpt -lt 10 ]]; then
1982 echo " restore is too long"
1983 wait_request_state $fid RESTORE SUCCEED
1989 # test needs a running copytool
1994 make_archive $tdir/$tfile
1995 local f=$DIR/$tdir/$tfile
1996 import_file $tdir/$tfile $f
1997 local fid=$($LFS path2fid $f)
1998 HSM_ARCHIVE_PURGE=false copytool_setup
2000 restore_and_check_size $f $fid
2003 [[ $err -eq 0 ]] || error "File size changed during restore"
2007 run_test 31a "Import a large file and check size during restore"
2011 # test needs a running copytool
2016 local f=$DIR/$tdir/$tfile
2017 local fid=$(make_large_for_progress $f)
2018 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2019 wait_request_state $fid ARCHIVE SUCCEED
2022 restore_and_check_size $f $fid
2025 [[ $err -eq 0 ]] || error "File size changed during restore"
2029 run_test 31b "Restore a large unaligned file and check size during restore"
2032 # test needs a running copytool
2037 local f=$DIR/$tdir/$tfile
2038 local fid=$(make_large_for_progress_aligned $f)
2039 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2040 wait_request_state $fid ARCHIVE SUCCEED
2043 restore_and_check_size $f $fid
2046 [[ $err -eq 0 ]] || error "File size changed during restore"
2050 run_test 31c "Restore a large aligned file and check size during restore"
2053 # test needs a running copytool
2058 local f=$DIR/$tdir/$tfile
2059 local fid=$(make_large_for_progress $f)
2060 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2061 wait_request_state $fid ARCHIVE SUCCEED
2064 md5sum $f >/dev/null &
2066 wait_request_state $fid RESTORE STARTED
2071 # Check restore trigger process was killed
2072 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2076 wait_request_state $fid RESTORE CANCELED
2077 wait_request_state $fid CANCEL SUCCEED
2080 error "Cannot kill process waiting for restore ($killed)"
2084 run_test 33 "Kill a restore waiting process"
2087 # test needs a running copytool
2092 local f=$DIR/$tdir/$tfile
2093 local fid=$(make_large_for_progress $f)
2094 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2095 wait_request_state $fid ARCHIVE SUCCEED
2098 md5sum $f >/dev/null &
2100 wait_request_state $fid RESTORE STARTED
2102 rm $f || error "rm $f failed"
2103 # rm must not block during restore
2104 wait_request_state $fid RESTORE STARTED
2106 wait_request_state $fid RESTORE SUCCEED
2107 # check md5sum pgm finished
2108 local there=$(ps -o pid,comm hp $pid >/dev/null)
2109 [[ -z $there ]] || error "Restore initiator does not exit"
2111 local rc=$(wait $pid)
2112 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2116 run_test 34 "Remove file during restore"
2119 # test needs a running copytool
2124 local f=$DIR/$tdir/$tfile
2125 local f1=$DIR/$tdir/$tfile-1
2126 local fid=$(make_large_for_progress $f)
2127 local fid1=$(copy_file /etc/passwd $f1)
2128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2129 wait_request_state $fid ARCHIVE SUCCEED
2132 md5sum $f >/dev/null &
2134 wait_request_state $fid RESTORE STARTED
2136 mv $f1 $f || error "mv $f1 $f failed"
2137 # mv must not block during restore
2138 wait_request_state $fid RESTORE STARTED
2140 wait_request_state $fid RESTORE SUCCEED
2141 # check md5sum pgm finished
2142 local there=$(ps -o pid,comm hp $pid >/dev/null)
2143 [[ -z $there ]] || error "Restore initiator does not exit"
2145 local rc=$(wait $pid)
2146 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2149 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2153 run_test 35 "Overwrite file during restore"
2156 # test needs a running copytool
2161 local f=$DIR/$tdir/$tfile
2162 local fid=$(make_large_for_progress $f)
2163 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2164 wait_request_state $fid ARCHIVE SUCCEED
2167 md5sum $f >/dev/null &
2169 wait_request_state $fid RESTORE STARTED
2172 # rm must not block during restore
2173 wait_request_state $fid RESTORE STARTED
2175 wait_request_state $fid RESTORE SUCCEED
2176 # check md5sum pgm finished
2177 local there=$(ps -o pid,comm hp $pid >/dev/null)
2179 error "Restore initiator does not exit"
2181 local rc=$(wait $pid)
2183 error "Restore initiator failed with $rc"
2187 run_test 36 "Move file during restore"
2194 for n in $(seq 1 $count); do
2195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2197 echo "$count archive requests submitted"
2201 local stream_count=4
2202 local file_count=100
2204 local f=$DIR/$tdir/$tfile
2209 for i in $(seq 1 $file_count); do
2210 for p in $(seq 1 $stream_count); do
2211 fid=$(copy_file /etc/hosts $f.$p.$i)
2215 # to be sure wait_all_done will not be mislead by previous tests
2217 wait_for_grace_delay
2219 # start archive streams in background (archive files in parallel)
2220 for p in $(seq 1 $stream_count); do
2221 multi_archive $f.$p $file_count &
2224 echo -n "Wait for all requests being enqueued..."
2230 run_test 40 "Parallel archive requests"
2233 # test needs a running copytool
2237 local f=$DIR/$tdir/$tfile
2238 local fid=$(copy_file /etc/motd $f 1)
2240 $LFS hsm_archive $f || error "could not archive file"
2241 wait_request_state $fid ARCHIVE SUCCEED
2242 check_hsm_flags $f "0x00000009"
2244 multiop_bg_pause $f O_c || error "multiop failed"
2248 client_up || client_up || true
2250 kill -USR1 $MULTIPID
2251 wait $MULTIPID || error "multiop close failed"
2253 check_hsm_flags $f "0x0000000b"
2257 run_test 52 "Opened for write file on an evicted client should be set dirty"
2260 # test needs a running copytool
2264 local f=$DIR/$tdir/$tfile
2265 local fid=$(copy_file /etc/motd $f 1)
2267 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2268 error "could not archive file"
2269 wait_request_state $fid ARCHIVE SUCCEED
2270 check_hsm_flags $f "0x00000009"
2272 multiop_bg_pause $f o_c || error "multiop failed"
2276 client_up || client_up || true
2278 kill -USR1 $MULTIPID
2279 wait $MULTIPID || error "multiop close failed"
2281 check_hsm_flags $f "0x00000009"
2285 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2288 # test needs a running copytool
2292 local f=$DIR/$tdir/$tfile
2293 local fid=$(make_small $f)
2295 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2296 error "could not archive file"
2297 wait_request_state $fid ARCHIVE STARTED
2299 check_hsm_flags $f "0x00000001"
2301 # Avoid coordinator resending this request as soon it has failed.
2306 wait_request_state $fid ARCHIVE FAILED
2308 check_hsm_flags $f "0x00000003"
2313 run_test 54 "Write during an archive cancels it"
2316 # test needs a running copytool
2320 local f=$DIR/$tdir/$tfile
2321 local fid=$(make_small $f)
2323 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2324 error "could not archive file"
2325 wait_request_state $fid ARCHIVE STARTED
2327 check_hsm_flags $f "0x00000001"
2329 # Avoid coordinator resending this request as soon it has failed.
2332 $TRUNCATE $f 1024 || error "truncate failed"
2334 wait_request_state $fid ARCHIVE FAILED
2336 check_hsm_flags $f "0x00000003"
2341 run_test 55 "Truncate during an archive cancels it"
2344 # test needs a running copytool
2348 local f=$DIR/$tdir/$tfile
2349 local fid=$(make_large_for_progress $f)
2351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2352 error "could not archive file"
2353 wait_request_state $fid ARCHIVE STARTED
2355 check_hsm_flags $f "0x00000001"
2357 # Change metadata and sync to be sure we are not changing only
2362 wait_request_state $fid ARCHIVE SUCCEED
2364 check_hsm_flags $f "0x00000009"
2368 run_test 56 "Setattr during an archive is ok"
2371 # Need one client for I/O, one for request
2372 needclients 2 || return 0
2374 # test needs a running copytool
2378 local f=$DIR/$tdir/test_archive_remote
2379 # Create a file on a remote node
2380 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2381 "count=2 conv=fsync"
2384 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2385 error "hsm_archive failed"
2386 local fid=$(path2fid $f)
2387 wait_request_state $fid ARCHIVE SUCCEED
2389 # Release and implicit restore it
2390 do_node $CLIENT2 "$LFS hsm_release $f" ||
2391 error "hsm_release failed"
2392 do_node $CLIENT2 "md5sum $f" ||
2393 error "hsm_restore failed"
2395 wait_request_state $fid RESTORE SUCCEED
2399 run_test 57 "Archive a file with dirty cache on another node"
2401 truncate_released_file() {
2405 local sz=$(stat -c %s $src_file)
2406 local f=$DIR/$tdir/$tfile
2407 local fid=$(copy_file $1 $f)
2411 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2412 error "could not archive file"
2413 wait_request_state $fid ARCHIVE SUCCEED
2415 $LFS hsm_release $f || error "could not release file"
2417 $TRUNCATE $f $trunc_to || error "truncate failed"
2420 local sz1=$(stat -c %s $f)
2421 [[ $sz1 == $trunc_to ]] ||
2422 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2425 check_hsm_flags $f "0x0000000b"
2427 local state=$(get_request_state $fid RESTORE)
2428 [[ "$state" == "SUCCEED" ]] ||
2429 error "truncate $sz does not trig restore, state = $state"
2431 $TRUNCATE $ref $trunc_to
2432 cmp $ref $f || error "file data wrong after truncate"
2438 # test needs a running copytool
2443 local sz=$(stat -c %s /etc/passwd)
2445 echo "truncate up from $sz to $((sz*2))"
2446 truncate_released_file /etc/passwd $((sz*2))
2448 echo "truncate down from $sz to $((sz/2))"
2449 truncate_released_file /etc/passwd $((sz/2))
2451 echo "truncate to 0"
2452 truncate_released_file /etc/passwd 0
2456 run_test 58 "Truncate a released file will trigger restore"
2461 local f=$DIR/$tdir/$tfile
2462 local FILELIST=/tmp/filelist.txt
2466 for i in $(seq 1 $file_count); do
2467 fid=$(copy_file /etc/hosts $f.$i)
2468 echo $f.$i >> $FILELIST
2471 # to be sure wait_all_done will not be mislead by previous tests
2473 wait_for_grace_delay
2474 $LFS hsm_archive --filelist $FILELIST ||
2475 error "cannot archive a file list"
2477 $LFS hsm_release --filelist $FILELIST ||
2478 error "cannot release a file list"
2479 $LFS hsm_restore --filelist $FILELIST ||
2480 error "cannot restore a file list"
2484 run_test 90 "Archive/restore a file list"
2486 double_verify_reset_hsm_param() {
2488 echo "Testing $HSM_PARAM.$p"
2489 local val=$(get_hsm_param $p)
2491 local val2=$(($val * 2))
2492 set_hsm_param $p $val2
2493 val=$(get_hsm_param $p)
2494 [[ $val == $val2 ]] ||
2495 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2496 echo "Set $p to 0 must failed"
2500 set_hsm_param $p $save
2502 if [[ $rc == 0 ]]; then
2503 error "we must not be able to set $HSM_PARAM.$p to 0"
2508 double_verify_reset_hsm_param loop_period
2509 double_verify_reset_hsm_param grace_delay
2510 double_verify_reset_hsm_param active_request_timeout
2511 double_verify_reset_hsm_param max_requests
2512 double_verify_reset_hsm_param default_archive_id
2514 run_test 100 "Set coordinator /proc tunables"
2521 run_test 102 "Verify coordinator control"
2524 # test needs a running copytool
2531 for i in $(seq 1 20); do
2532 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2534 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2538 echo "Current requests"
2539 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2540 $HSM_PARAM.actions |\
2541 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2543 [[ -z "$res" ]] || error "Some request have not been canceled"
2547 run_test 103 "Purge all requests"
2552 # test needs a running copytool
2556 local f=$DIR/$tdir/$tfile
2557 local fid=$(make_large_for_progress $f)
2558 # if cdt is on, it can serve too quickly the request
2560 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2561 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2562 $HSM_PARAM.actions |\
2563 grep $fid | cut -f16 -d=")
2566 [[ "$data1" == "$DATAHEX" ]] ||
2567 error "Data field in records is ($data1) and not ($DATAHEX)"
2571 run_test 104 "Copy tool data field"
2578 for i in $(seq -w 1 10); do
2579 cp /etc/passwd $DIR/$tdir/$i
2580 $LFS hsm_archive $DIR/$tdir/$i
2582 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2583 $HSM_PARAM.actions |\
2584 grep WAITING | wc -l")
2587 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2588 $HSM_PARAM.actions |\
2589 grep WAITING | wc -l")
2592 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2593 error "Requests count after shutdown $reqcnt2 != "\
2594 "before shutdown $reqcnt1"
2596 run_test 105 "Restart of coordinator"
2599 # test needs a running copytool
2602 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2603 get_client_uuid $MOUNT | cut -d' ' -f2)
2604 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2607 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2608 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2610 [[ -z "$agent" ]] ||
2611 error "My uuid $uuid still found in agent list,"\
2612 " after copytool shutdown"
2614 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2617 [[ ! -z "$agent" ]] ||
2618 error "My uuid $uuid not found in agent list after"\
2621 run_test 106 "Copytool register/unregister"
2624 # test needs a running copytool
2626 # create and archive file
2628 local f1=$DIR/$tdir/$tfile
2629 local fid=$(copy_file /etc/passwd $f1)
2630 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2631 wait_request_state $fid ARCHIVE SUCCEED
2632 # shutdown and restart MDS
2634 # check the copytool still gets messages from MDT
2635 local f2=$DIR/$tdir/2
2636 local fid=$(copy_file /etc/passwd $f2)
2637 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2638 # main check of this sanity: this request MUST succeed
2639 wait_request_state $fid ARCHIVE SUCCEED
2642 run_test 107 "Copytool re-register after MDS restart"
2644 policy_set_and_test()
2648 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2649 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2650 [[ "$policy" == "$target" ]] ||
2651 error "Wrong policy after '$change': '$policy' != '$target'"
2655 # to force default policy setting if error
2656 CDT_POLICY_HAD_CHANGED=true
2658 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2659 local default="NonBlockingRestore [NoRetryAction]"
2660 [[ "$policy" == "$default" ]] ||
2661 error "default policy has changed,"\
2662 " '$policy' != '$default' update the test"
2663 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2664 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2665 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2666 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2667 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2668 # useless bacause we know but safer for futur changes to use real value
2669 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2670 echo "Next set_param must failed"
2671 policy_set_and_test "wrong" "$policy"
2674 echo "Back to default policy"
2675 cdt_set_sanity_policy
2677 run_test 109 "Policy display/change"
2680 # test needs a running copytool
2685 copy2archive /etc/passwd $tdir/$tfile
2687 local f=$DIR/$tdir/$tfile
2688 import_file $tdir/$tfile $f
2689 local fid=$(path2fid $f)
2691 cdt_set_non_blocking_restore
2696 wait_request_state $fid RESTORE SUCCEED
2697 cdt_clear_non_blocking_restore
2701 error "md5sum returns $st != 1, "\
2702 "should also perror ENODATA (No data available)"
2706 run_test 110a "Non blocking restore policy (import case)"
2709 # test needs a running copytool
2713 local f=$DIR/$tdir/$tfile
2714 local fid=$(copy_file /etc/passwd $f)
2715 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2716 wait_request_state $fid ARCHIVE SUCCEED
2719 cdt_set_non_blocking_restore
2724 wait_request_state $fid RESTORE SUCCEED
2725 cdt_clear_non_blocking_restore
2729 error "md5sum returns $st != 1, "\
2730 "should also perror ENODATA (No data available)"
2734 run_test 110b "Non blocking restore policy (release case)"
2737 # test needs a running copytool
2741 copy2archive /etc/passwd $tdir/$tfile
2743 local f=$DIR/$tdir/$tfile
2745 import_file $tdir/$tfile $f
2746 local fid=$(path2fid $f)
2750 copytool_remove_backend $fid
2753 wait_request_state $fid RESTORE FAILED
2760 [[ $st == 0 ]] || error "Restore does not failed"
2764 run_test 111a "No retry policy (import case), restore will error"\
2765 " (No such file or directory)"
2768 # test needs a running copytool
2772 local f=$DIR/$tdir/$tfile
2773 local fid=$(copy_file /etc/passwd $f)
2775 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2776 wait_request_state $fid ARCHIVE SUCCEED
2779 copytool_remove_backend $fid
2782 wait_request_state $fid RESTORE FAILED
2789 [[ $st == 0 ]] || error "Restore does not failed"
2793 run_test 111b "No retry policy (release case), restore will error"\
2794 " (No such file or directory)"
2797 # test needs a running copytool
2801 local f=$DIR/$tdir/$tfile
2802 local fid=$(copy_file /etc/passwd $f)
2804 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2805 local l=$($LFS hsm_action $f)
2807 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2811 wait_request_state $fid ARCHIVE SUCCEED
2814 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2818 run_test 112 "State of recorded request"
2821 # test needs a running copytool
2825 local f=$DIR/$tdir/$tfile
2826 local fid=$(make_large_for_cancel $f)
2827 # test with cdt on is made in test_221
2829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2832 wait_request_state $fid ARCHIVE CANCELED
2833 wait_request_state $fid CANCEL SUCCEED
2837 run_test 200 "Register/Cancel archive"
2840 # test needs a running copytool
2844 local f=$DIR/$tdir/$tfile
2845 make_archive $tdir/$tfile
2846 import_file $tdir/$tfile $f
2847 local fid=$(path2fid $f)
2849 # test with cdt on is made in test_222
2854 wait_request_state $fid RESTORE CANCELED
2855 wait_request_state $fid CANCEL SUCCEED
2859 run_test 201 "Register/Cancel restore"
2862 # test needs a running copytool
2866 local f=$DIR/$tdir/$tfile
2867 local fid=$(make_large_for_progress $f)
2868 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2869 wait_request_state $fid ARCHIVE SUCCEED
2875 wait_request_state $fid REMOVE CANCELED
2879 run_test 202 "Register/Cancel remove"
2882 # test needs a running copytool
2887 local f=$DIR/$tdir/$tfile
2888 local fid=$(copy_file /etc/passwd $f)
2892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2893 wait_request_state $fid ARCHIVE SUCCEED
2895 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2899 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2903 run_test 220 "Changelog for archive"
2906 # test needs a running copytool
2911 local f=$DIR/$tdir/$tfile
2912 local fid=$(make_large_for_cancel $f)
2916 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2917 wait_request_state $fid ARCHIVE STARTED
2919 wait_request_state $fid ARCHIVE CANCELED
2920 wait_request_state $fid CANCEL SUCCEED
2922 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2925 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2929 run_test 221 "Changelog for archive canceled"
2932 # test needs a running copytool
2936 copy2archive /etc/passwd $tdir/$tfile
2938 local f=$DIR/$tdir/$tfile
2939 import_file $tdir/$tfile $f
2940 local fid=$(path2fid $f)
2945 wait_request_state $fid RESTORE SUCCEED
2947 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2950 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2954 run_test 222a "Changelog for explicit restore"
2957 # test needs a running copytool
2961 local f=$DIR/$tdir/$tfile
2962 local fid=$(copy_file /etc/passwd $f)
2965 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2966 wait_request_state $fid ARCHIVE SUCCEED
2971 wait_request_state $fid RESTORE SUCCEED
2973 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2976 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2980 run_test 222b "Changelog for implicit restore"
2983 # test needs a running copytool
2988 local f=$DIR/$tdir/$tfile
2989 make_archive $tdir/$tfile
2993 import_file $tdir/$tfile $f
2994 local fid=$(path2fid $f)
2997 wait_request_state $fid RESTORE STARTED
2999 wait_request_state $fid RESTORE CANCELED
3000 wait_request_state $fid CANCEL SUCCEED
3002 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3005 [[ $flags == $target ]] ||
3006 error "Changelog flag is $flags not $target"
3010 run_test 223a "Changelog for restore canceled (import case)"
3013 # test needs a running copytool
3018 local f=$DIR/$tdir/$tfile
3019 local fid=$(make_large_for_progress $f)
3022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3023 wait_request_state $fid ARCHIVE SUCCEED
3026 wait_request_state $fid RESTORE STARTED
3028 wait_request_state $fid RESTORE CANCELED
3029 wait_request_state $fid CANCEL SUCCEED
3031 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3034 [[ $flags == $target ]] ||
3035 error "Changelog flag is $flags not $target"
3039 run_test 223b "Changelog for restore canceled (release case)"
3042 # test needs a running copytool
3047 local f=$DIR/$tdir/$tfile
3048 local fid=$(copy_file /etc/passwd $f)
3051 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3052 wait_request_state $fid ARCHIVE SUCCEED
3055 wait_request_state $fid REMOVE SUCCEED
3057 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3060 [[ $flags == $target ]] ||
3061 error "Changelog flag is $flags not $target"
3065 run_test 224 "Changelog for remove"
3068 # test needs a running copytool
3071 # test is not usable because remove request is too fast
3072 # so it is always finished before cancel can be done ...
3073 echo "Test disabled"
3078 local f=$DIR/$tdir/$tfile
3079 local fid=$(make_large_for_progress $f)
3082 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3083 wait_request_state $fid ARCHIVE SUCCEED
3085 # if cdt is on, it can serve too quickly the request
3090 wait_request_state $fid REMOVE CANCELED
3091 wait_request_state $fid CANCEL SUCCEED
3093 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3094 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3095 tail -n 1 | awk '{print $5}')
3098 [[ $flags == $target ]] ||
3099 error "Changelog flag is $flags not $target"
3103 run_test 225 "Changelog for remove canceled"
3106 # test needs a running copytool
3111 local f1=$DIR/$tdir/$tfile-1
3112 local f2=$DIR/$tdir/$tfile-2
3113 local f3=$DIR/$tdir/$tfile-3
3114 local fid1=$(copy_file /etc/passwd $f1)
3115 local fid2=$(copy_file /etc/passwd $f2)
3116 copy_file /etc/passwd $f3
3119 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3120 wait_request_state $fid1 ARCHIVE SUCCEED
3122 $LFS hsm_archive $f2
3123 wait_request_state $fid2 ARCHIVE SUCCEED
3125 rm $f1 || error "rm $f1 failed"
3127 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3130 [[ $flags == $target ]] ||
3131 error "Changelog flag is $flags not $target"
3133 mv $f3 $f2 || error "mv $f3 $f2 failed"
3135 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3138 [[ $flags == $target ]] ||
3139 error "Changelog flag is $flags not $target"
3143 run_test 226 "changelog for last rm/mv with exiting archive"
3145 check_flags_changes() {
3153 $LFS hsm_set --$hsm_flag $f ||
3154 error "Cannot set $hsm_flag on $f"
3155 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3156 local seen=${#flags[*]}
3158 [[ $seen == $cnt ]] ||
3159 error "set $hsm_flag: Changelog events $seen != $cnt"
3160 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3161 error "set $hsm_flag: Changelog flags are "\
3162 "${flags[$((cnt - 1))]} not $target"
3164 $LFS hsm_clear --$hsm_flag $f ||
3165 error "Cannot clear $hsm_flag on $f"
3166 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3169 [[ $cnt == $seen ]] ||
3170 error "clear $hsm_flag: Changelog events $seen != $cnt"
3172 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3173 error "clear $hsm_flag: Changelog flag is "\
3174 "${flags[$((cnt - 1))]} not $target"
3178 # test needs a running copytool
3185 for i in norelease noarchive exists archived
3187 local f=$DIR/$tdir/$tfile-$i
3188 local fid=$(copy_file /etc/passwd $f)
3189 check_flags_changes $f $fid $i 0 1
3192 f=$DIR/$tdir/$tfile---lost
3193 fid=$(copy_file /etc/passwd $f)
3194 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3195 wait_request_state $fid ARCHIVE SUCCEED
3196 check_flags_changes $f $fid lost 3 1
3200 run_test 227 "changelog when explicit setting of HSM flags"
3203 # test needs a running copytool
3206 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3207 error "creating $DIR/$tfile"
3208 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3209 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3211 $LFS hsm_release $DIR/$tfile
3212 check_hsm_flags $DIR/$tfile "0x0000000d"
3214 filefrag $DIR/$tfile | grep " 1 extent found" ||
3215 error "filefrag on released file must return only one extent"
3217 # only newer versions of cp detect sparse files by stat/FIEMAP
3219 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3220 error "copying $DIR/$tfile"
3221 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3223 $LFS hsm_release $DIR/$tfile
3224 check_hsm_flags $DIR/$tfile "0x0000000d"
3228 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3230 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3231 error "comparing untarred $DIR/$tfile"
3235 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3238 # test needs a running copytool
3242 local maxrequest=$(get_hsm_param max_requests)
3243 local rqcnt=$(($maxrequest * 3))
3247 for i in $(seq -w 1 $rqcnt); do
3249 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3251 # we do it in 2 steps, so all requests arrive at the same time
3252 for i in $(seq -w 1 $rqcnt); do
3253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3258 while [[ $cnt != 0 || $wt != 0 ]]; do
3260 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3261 $HSM_PARAM.actions |\
3262 grep STARTED | grep -v CANCEL | wc -l")
3263 [[ $cnt -le $maxrequest ]] ||
3264 error "$cnt > $maxrequest too many started requests"
3265 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3266 $HSM_PARAM.actions |\
3267 grep WAITING | wc -l")
3268 echo "max=$maxrequest started=$cnt waiting=$wt"
3273 run_test 250 "Coordinator max request"
3276 # test needs a running copytool
3280 local f=$DIR/$tdir/$tfile
3281 local fid=$(make_large_for_cancel $f)
3284 # to have a short test
3285 local old_to=$(get_hsm_param active_request_timeout)
3286 set_hsm_param active_request_timeout 4
3287 # to be sure the cdt will wake up frequently so
3288 # it will be able to cancel the "old" request
3289 local old_loop=$(get_hsm_param loop_period)
3290 set_hsm_param loop_period 2
3293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3294 wait_request_state $fid ARCHIVE STARTED
3296 wait_request_state $fid ARCHIVE CANCELED
3298 set_hsm_param active_request_timeout $old_to
3299 set_hsm_param loop_period $old_loop
3303 run_test 251 "Coordinator request timeout"
3306 # the only way to test ondisk conf is to restart MDS ...
3307 echo "Stop coordinator and remove coordinator state at mount"
3310 # clean on disk conf set by default
3311 cdt_clear_mount_state
3312 cdt_check_state stopped
3314 # check cdt still off after umount/remount
3316 cdt_check_state stopped
3318 echo "Set coordinator start at mount, and start coordinator"
3319 cdt_set_mount_state enabled
3322 cdt_check_state enabled
3324 # check cdt still on after umount/remount
3326 cdt_check_state enabled
3328 # we are back to original state (cdt started at mount)
3330 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3333 local ai=$(get_hsm_param default_archive_id)
3334 local new=$((ai + 1))
3336 set_hsm_param default_archive_id $new -P
3338 local res=$(get_hsm_param default_archive_id)
3341 set_hsm_param default_archive_id "" "-P -d"
3343 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3345 run_test 301 "HSM tunnable are persistent"
3348 local ai=$(get_hsm_param default_archive_id)
3349 local new=$((ai + 1))
3354 set_hsm_param default_archive_id $new -P
3358 cdt_check_state enabled
3360 local res=$(get_hsm_param default_archive_id)
3363 set_hsm_param default_archive_id "" "-P -d"
3365 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3367 run_test 302 "HSM tunnable are persistent when CDT is off"
3372 check_and_cleanup_lustre