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 $LFS hsm_archive $f || error "could not archive file"
1339 wait_request_state $fid ARCHIVE SUCCEED
1341 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1342 local sz=$(stat -c "%s" $f)
1343 [ $sz -ne "0" ] || error "file size should not be zero"
1345 # Release and check states
1346 $LFS hsm_release $f || error "could not release file"
1347 check_hsm_flags $f "0x0000000d"
1349 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1350 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1352 # Check we can release an file without stripe info
1356 check_hsm_flags $f "0x00000000"
1357 $LFS hsm_archive $f || error "could not archive file"
1358 wait_request_state $fid ARCHIVE SUCCEED
1360 # Release and check states
1361 $LFS hsm_release $f || error "could not release file"
1362 check_hsm_flags $f "0x0000000d"
1364 # Release again a file that is already released is OK
1365 $LFS hsm_release $f || fail "second release should succeed"
1366 check_hsm_flags $f "0x0000000d"
1370 run_test 21 "Simple release tests"
1373 # test needs a running copytool
1378 local f=$DIR/$tdir/test_release
1379 local swap=$DIR/$tdir/test_swap
1381 # Create a file and check its states
1382 local fid=$(make_small $f)
1383 check_hsm_flags $f "0x00000000"
1385 $LFS hsm_archive $f || error "could not archive file"
1386 wait_request_state $fid ARCHIVE SUCCEED
1388 # Release and check states
1389 $LFS hsm_release $f || error "could not release file"
1390 check_hsm_flags $f "0x0000000d"
1393 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1398 run_test 22 "Could not swap a release file"
1401 # test needs a running copytool
1406 local f=$DIR/$tdir/test_mtime
1408 # Create a file and check its states
1409 local fid=$(make_small $f)
1410 check_hsm_flags $f "0x00000000"
1412 $LFS hsm_archive $f || error "could not archive file"
1413 wait_request_state $fid ARCHIVE SUCCEED
1415 # Set modification time in the past
1416 touch -m -a -d @978261179 $f
1418 # Release and check states
1419 $LFS hsm_release $f || error "could not release file"
1420 check_hsm_flags $f "0x0000000d"
1422 local MTIME=$(stat -c "%Y" $f)
1423 local ATIME=$(stat -c "%X" $f)
1424 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1425 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1429 run_test 23 "Release does not change a/mtime (utime)"
1432 local file=$DIR/$tdir/$tfile
1441 # test needs a running copytool
1446 fid=$(make_small $file)
1448 # Create a file and check its states
1449 check_hsm_flags $file "0x00000000"
1451 # Ensure atime is less than mtime and ctime.
1455 atime0=$(stat -c "%X" $file)
1456 mtime0=$(stat -c "%Y" $file)
1457 ctime0=$(stat -c "%Z" $file)
1459 [ $atime0 -lt $mtime0 ] ||
1460 error "atime $atime0 is not less than mtime $mtime0"
1462 [ $atime0 -lt $ctime0 ] ||
1463 error "atime $atime0 is not less than ctime $ctime0"
1465 # Archive should not change any timestamps.
1466 $LFS hsm_archive $file || error "cannot archive '$file'"
1467 wait_request_state $fid ARCHIVE SUCCEED
1469 atime1=$(stat -c "%X" $file)
1470 mtime1=$(stat -c "%Y" $file)
1471 ctime1=$(stat -c "%Z" $file)
1473 [ $atime0 -eq $atime1 ] ||
1474 error "archive changed atime from $atime0 to $atime1"
1476 [ $mtime0 -eq $mtime1 ] ||
1477 error "archive changed mtime from $mtime0 to $mtime1"
1479 [ $ctime0 -eq $ctime1 ] ||
1480 error "archive changed ctime from $ctime0 to $ctime1"
1482 # Release should not change any timestamps.
1483 $LFS hsm_release $file || error "cannot release '$file'"
1484 check_hsm_flags $file "0x0000000d"
1486 atime1=$(stat -c "%X" $file)
1487 mtime1=$(stat -c "%Y" $file)
1488 ctime1=$(stat -c "%Z" $file)
1490 [ $atime0 -eq $atime1 ] ||
1491 error "release changed atime from $atime0 to $atime1"
1493 [ $mtime0 -eq $mtime1 ] ||
1494 error "release changed mtime from $mtime0 to $mtime1"
1496 [ $ctime0 -eq $ctime1 ] ||
1497 error "release changed ctime from $ctime0 to $ctime1"
1499 # Restore should not change atime or mtime and should not
1501 $LFS hsm_restore $file
1502 wait_request_state $fid RESTORE SUCCEED
1504 atime1=$(stat -c "%X" $file)
1505 mtime1=$(stat -c "%Y" $file)
1506 ctime1=$(stat -c "%Z" $file)
1508 [ $atime0 -eq $atime1 ] ||
1509 error "restore changed atime from $atime0 to $atime1"
1511 [ $mtime0 -eq $mtime1 ] ||
1512 error "restore changed mtime from $mtime0 to $mtime1"
1514 [ $ctime0 -le $ctime1 ] ||
1515 error "restore changed ctime from $ctime0 to $ctime1"
1519 # Once more, after unmount and mount.
1520 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1521 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1523 atime1=$(stat -c "%X" $file)
1524 mtime1=$(stat -c "%Y" $file)
1525 ctime1=$(stat -c "%Z" $file)
1527 [ $atime0 -eq $atime1 ] ||
1528 error "remount changed atime from $atime0 to $atime1"
1530 [ $mtime0 -eq $mtime1 ] ||
1531 error "remount changed mtime from $mtime0 to $mtime1"
1533 [ $ctime0 -le $ctime1 ] ||
1534 error "remount changed ctime from $ctime0 to $ctime1"
1536 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1539 local file=$DIR/$tdir/$tfile
1545 # Test needs a running copytool.
1549 # Check that root can do HSM actions on a ordinary user's file.
1551 fid=$(make_small $file)
1552 sum0=$(md5sum $file)
1554 chown $RUNAS_ID:$RUNAS_GID $file ||
1555 error "cannot chown '$file' to '$RUNAS_ID'"
1557 chmod ugo-w $DIR/$tdir ||
1558 error "cannot chmod '$DIR/$tdir'"
1560 $LFS hsm_archive $file
1561 wait_request_state $fid ARCHIVE SUCCEED
1563 $LFS hsm_release $file
1564 check_hsm_flags $file "0x0000000d"
1566 $LFS hsm_restore $file
1567 wait_request_state $fid RESTORE SUCCEED
1569 # Check that ordinary user can get HSM state.
1570 $RUNAS $LFS hsm_state $file ||
1571 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1573 $LFS hsm_release $file
1574 check_hsm_flags $file "0x0000000d"
1576 # Check that ordinary user can accessed released file.
1577 sum1=$($RUNAS md5sum $file) ||
1578 error "user '$RUNAS_ID' cannot read '$file'"
1580 [ "$sum0" == "$sum1" ] ||
1581 error "md5sum mismatch for '$file'"
1585 run_test 24b "root can archive, release, and restore user files"
1587 cleanup_test_24c() {
1589 set_hsm_param user_request_mask RESTORE
1590 set_hsm_param group_request_mask RESTORE
1591 set_hsm_param other_request_mask RESTORE
1595 local file=$DIR/$tdir/$tfile
1596 local action=archive
1601 # test needs a running copytool
1606 # Save the default masks and check that cleanup_24c will
1607 # restore the request masks correctly.
1608 user_save=$(get_hsm_param user_request_mask)
1609 group_save=$(get_hsm_param group_request_mask)
1610 other_save=$(get_hsm_param other_request_mask)
1612 [ "$user_save" == RESTORE ] ||
1613 error "user_request_mask is '$user_save' expected 'RESTORE'"
1614 [ "$group_save" == RESTORE ] ||
1615 error "group_request_mask is '$group_save' expected 'RESTORE'"
1616 [ "$other_save" == RESTORE ] ||
1617 error "other_request_mask is '$other_save' expected 'RESTORE'"
1619 trap cleanup_test_24c EXIT
1624 chown $RUNAS_ID:nobody $file ||
1625 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1627 set_hsm_param user_request_mask ""
1628 $RUNAS $LFS hsm_$action $file &&
1629 error "$action by user should fail"
1631 set_hsm_param user_request_mask $action
1632 $RUNAS $LFS hsm_$action $file ||
1633 error "$action by user should succeed"
1638 chown nobody:$RUNAS_GID $file ||
1639 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1641 set_hsm_param group_request_mask ""
1642 $RUNAS $LFS hsm_$action $file &&
1643 error "$action by group should fail"
1645 set_hsm_param group_request_mask $action
1646 $RUNAS $LFS hsm_$action $file ||
1647 error "$action by group should succeed"
1652 chown nobody:nobody $file ||
1653 error "cannot chown '$file' to 'nobody:nobody'"
1655 set_hsm_param other_request_mask ""
1656 $RUNAS $LFS hsm_$action $file &&
1657 error "$action by other should fail"
1659 set_hsm_param other_request_mask $action
1660 $RUNAS $LFS hsm_$action $file ||
1661 error "$action by other should succeed"
1666 run_test 24c "check that user,group,other request masks work"
1668 cleanup_test_24d() {
1670 mount -o remount,rw $MOUNT2
1674 local file1=$DIR/$tdir/$tfile
1675 local file2=$DIR2/$tdir/$tfile
1683 fid1=$(make_small $file1)
1685 trap cleanup_test_24d EXIT
1687 mount -o remount,ro $MOUNT2
1689 fid2=$(path2fid $file2)
1690 [ "$fid1" == "$fid2" ] ||
1691 error "FID mismatch '$fid1' != '$fid2'"
1693 $LFS hsm_archive $file2 &&
1694 error "archive should fail on read-only mount"
1695 check_hsm_flags $file1 "0x00000000"
1697 $LFS hsm_archive $file1
1698 wait_request_state $fid1 ARCHIVE SUCCEED
1700 $LFS hsm_release $file1
1701 $LFS hsm_restore $file2
1702 wait_request_state $fid1 RESTORE SUCCEED
1704 $LFS hsm_release $file1 || error "cannot release '$file1'"
1705 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1707 $LFS hsm_release $file2 &&
1708 error "release should fail on read-only mount"
1713 run_test 24d "check that read-only mounts are respected"
1716 # test needs a running copytool
1720 copy2archive /etc/hosts $tdir/$tfile
1722 local f=$DIR/$tdir/$tfile
1724 import_file $tdir/$tfile $f
1726 $LFS hsm_set --lost $f
1731 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1735 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1736 " (Operation not permitted)"
1739 # test needs a running copytool
1744 local f=$DIR/$tdir/$tfile
1745 local fid=$(copy_file /etc/passwd $f)
1747 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1748 wait_request_state $fid ARCHIVE SUCCEED
1751 $LFS hsm_set --lost $f
1755 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1759 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1760 " (Operation not permitted)"
1763 # test needs a running copytool
1767 local f=$DIR/$tdir/$tfile
1768 local fid=$(make_large_for_progress $f)
1769 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1770 wait_request_state $fid ARCHIVE SUCCEED
1773 wait_request_state $fid REMOVE SUCCEED
1775 check_hsm_flags $f "0x00000000"
1779 run_test 26 "Remove the archive of a valid file"
1782 # test needs a running copytool
1786 make_archive $tdir/$tfile
1787 local f=$DIR/$tdir/$tfile
1788 import_file $tdir/$tfile $f
1789 local fid=$(path2fid $f)
1793 [[ $? != 0 ]] || error "Remove of a released file should fail"
1797 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1800 # test needs a running copytool
1804 local f=$DIR/$tdir/$tfile
1805 local fid=$(make_large_for_progress $f)
1806 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1807 wait_request_state $fid ARCHIVE SUCCEED
1812 [[ $? != 0 ]] || error "Remove of a released file should fail"
1816 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1819 # test needs a running copytool
1823 local f=$DIR/$tdir/$tfile
1824 local fid=$(make_large_for_progress $f)
1825 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1826 wait_request_state $fid ARCHIVE SUCCEED
1835 wait_request_state $fid REMOVE SUCCEED
1839 run_test 28 "Concurrent archive/file remove"
1842 # restore at exec cannot work on agent node (because of Linux kernel
1843 # protection of executables)
1844 needclients 2 || return 0
1846 # test needs a running copytool
1850 copy2archive /bin/true $tdir/$tfile
1852 local f=$DIR/$tdir/true
1853 import_file $tdir/$tfile $f
1855 local fid=$(path2fid $f)
1857 # set no retry action mode
1863 # remove no try action mode
1867 [[ $st == 0 ]] || error "Failed to exec a released file"
1871 run_test 30a "Restore at exec (import case)"
1874 # restore at exec cannot work on agent node (because of Linux kernel
1875 # protection of executables)
1876 needclients 2 || return 0
1878 # test needs a running copytool
1882 local f=$DIR/$tdir/true
1883 local fid=$(copy_file /bin/true $f)
1885 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1886 wait_request_state $fid ARCHIVE SUCCEED
1889 # set no retry action mode
1895 # remove no try action mode
1899 [[ $st == 0 ]] || error "Failed to exec a released file"
1903 run_test 30b "Restore at exec (release case)"
1906 needclients 2 || return 0
1908 # test needs a running copytool
1912 local f=$DIR/$tdir/SLEEP
1913 local fid=$(copy_file /bin/sleep $f)
1915 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1916 wait_request_state $fid ARCHIVE SUCCEED
1918 check_hsm_flags $f "0x0000000d"
1919 # set no retry action mode
1921 do_node $CLIENT2 "$f 10" &
1925 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1927 [[ $? == 0 ]] || error "Execution failed during run"
1929 [[ $? == 0 ]] || error "Binary overwritten during exec"
1932 # remove no try action mode
1934 check_hsm_flags $f "0x00000009"
1938 run_test 30c "Update during exec of released file must fail"
1940 restore_and_check_size() {
1943 local s=$(stat -c "%s" $f)
1945 local st=$(get_hsm_flags $f)
1949 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1951 n=$(stat -c "%s" $f)
1952 # we echo in both cases to show stat is not
1954 if [[ $n != $s ]]; then
1955 echo "size seen is $n != $s"
1958 echo "size seen is right: $n == $s"
1960 st=$(get_hsm_flags $f)
1964 if [[ $cpt -lt 10 ]]; then
1967 echo " restore is too long"
1968 wait_request_state $fid RESTORE SUCCEED
1974 # test needs a running copytool
1979 make_archive $tdir/$tfile
1980 local f=$DIR/$tdir/$tfile
1981 import_file $tdir/$tfile $f
1982 local fid=$($LFS path2fid $f)
1983 HSM_ARCHIVE_PURGE=false copytool_setup
1985 restore_and_check_size $f $fid
1988 [[ $err -eq 0 ]] || error "File size changed during restore"
1992 run_test 31a "Import a large file and check size during restore"
1996 # test needs a running copytool
2001 local f=$DIR/$tdir/$tfile
2002 local fid=$(make_large_for_progress $f)
2003 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2004 wait_request_state $fid ARCHIVE SUCCEED
2007 restore_and_check_size $f $fid
2010 [[ $err -eq 0 ]] || error "File size changed during restore"
2014 run_test 31b "Restore a large unaligned file and check size during restore"
2017 # test needs a running copytool
2022 local f=$DIR/$tdir/$tfile
2023 local fid=$(make_large_for_progress_aligned $f)
2024 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2025 wait_request_state $fid ARCHIVE SUCCEED
2028 restore_and_check_size $f $fid
2031 [[ $err -eq 0 ]] || error "File size changed during restore"
2035 run_test 31c "Restore a large aligned file and check size during restore"
2038 # test needs a running copytool
2043 local f=$DIR/$tdir/$tfile
2044 local fid=$(make_large_for_progress $f)
2045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2046 wait_request_state $fid ARCHIVE SUCCEED
2049 md5sum $f >/dev/null &
2051 wait_request_state $fid RESTORE STARTED
2056 # Check restore trigger process was killed
2057 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2061 wait_request_state $fid RESTORE CANCELED
2062 wait_request_state $fid CANCEL SUCCEED
2065 error "Cannot kill process waiting for restore ($killed)"
2069 run_test 33 "Kill a restore waiting process"
2072 # test needs a running copytool
2077 local f=$DIR/$tdir/$tfile
2078 local fid=$(make_large_for_progress $f)
2079 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2080 wait_request_state $fid ARCHIVE SUCCEED
2083 md5sum $f >/dev/null &
2085 wait_request_state $fid RESTORE STARTED
2087 rm $f || error "rm $f failed"
2088 # rm must not block during restore
2089 wait_request_state $fid RESTORE STARTED
2091 wait_request_state $fid RESTORE SUCCEED
2092 # check md5sum pgm finished
2093 local there=$(ps -o pid,comm hp $pid >/dev/null)
2094 [[ -z $there ]] || error "Restore initiator does not exit"
2096 local rc=$(wait $pid)
2097 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2101 run_test 34 "Remove file during restore"
2104 # test needs a running copytool
2109 local f=$DIR/$tdir/$tfile
2110 local f1=$DIR/$tdir/$tfile-1
2111 local fid=$(make_large_for_progress $f)
2112 local fid1=$(copy_file /etc/passwd $f1)
2113 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2114 wait_request_state $fid ARCHIVE SUCCEED
2117 md5sum $f >/dev/null &
2119 wait_request_state $fid RESTORE STARTED
2121 mv $f1 $f || error "mv $f1 $f failed"
2122 # mv must not block during restore
2123 wait_request_state $fid RESTORE STARTED
2125 wait_request_state $fid RESTORE SUCCEED
2126 # check md5sum pgm finished
2127 local there=$(ps -o pid,comm hp $pid >/dev/null)
2128 [[ -z $there ]] || error "Restore initiator does not exit"
2130 local rc=$(wait $pid)
2131 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2134 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2138 run_test 35 "Overwrite file during restore"
2141 # test needs a running copytool
2146 local f=$DIR/$tdir/$tfile
2147 local fid=$(make_large_for_progress $f)
2148 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2149 wait_request_state $fid ARCHIVE SUCCEED
2152 md5sum $f >/dev/null &
2154 wait_request_state $fid RESTORE STARTED
2157 # rm must not block during restore
2158 wait_request_state $fid RESTORE STARTED
2160 wait_request_state $fid RESTORE SUCCEED
2161 # check md5sum pgm finished
2162 local there=$(ps -o pid,comm hp $pid >/dev/null)
2164 error "Restore initiator does not exit"
2166 local rc=$(wait $pid)
2168 error "Restore initiator failed with $rc"
2172 run_test 36 "Move file during restore"
2179 for n in $(seq 1 $count); do
2180 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2182 echo "$count archive requests submitted"
2186 local stream_count=4
2187 local file_count=100
2189 local f=$DIR/$tdir/$tfile
2194 for i in $(seq 1 $file_count); do
2195 for p in $(seq 1 $stream_count); do
2196 fid=$(copy_file /etc/hosts $f.$p.$i)
2200 # to be sure wait_all_done will not be mislead by previous tests
2202 wait_for_grace_delay
2204 # start archive streams in background (archive files in parallel)
2205 for p in $(seq 1 $stream_count); do
2206 multi_archive $f.$p $file_count &
2209 echo -n "Wait for all requests being enqueued..."
2215 run_test 40 "Parallel archive requests"
2218 # test needs a running copytool
2222 local f=$DIR/$tdir/$tfile
2223 local fid=$(copy_file /etc/motd $f 1)
2225 $LFS hsm_archive $f || error "could not archive file"
2226 wait_request_state $fid ARCHIVE SUCCEED
2227 check_hsm_flags $f "0x00000009"
2229 multiop_bg_pause $f O_c || error "multiop failed"
2233 client_up || client_up || true
2235 kill -USR1 $MULTIPID
2236 wait $MULTIPID || error "multiop close failed"
2238 check_hsm_flags $f "0x0000000b"
2242 run_test 52 "Opened for write file on an evicted client should be set dirty"
2245 # test needs a running copytool
2249 local f=$DIR/$tdir/$tfile
2250 local fid=$(copy_file /etc/motd $f 1)
2252 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2253 error "could not archive file"
2254 wait_request_state $fid ARCHIVE SUCCEED
2255 check_hsm_flags $f "0x00000009"
2257 multiop_bg_pause $f o_c || error "multiop failed"
2261 client_up || client_up || true
2263 kill -USR1 $MULTIPID
2264 wait $MULTIPID || error "multiop close failed"
2266 check_hsm_flags $f "0x00000009"
2270 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2273 # test needs a running copytool
2277 local f=$DIR/$tdir/$tfile
2278 local fid=$(make_small $f)
2280 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2281 error "could not archive file"
2282 wait_request_state $fid ARCHIVE STARTED
2284 check_hsm_flags $f "0x00000001"
2286 # Avoid coordinator resending this request as soon it has failed.
2291 wait_request_state $fid ARCHIVE FAILED
2293 check_hsm_flags $f "0x00000003"
2298 run_test 54 "Write during an archive cancels it"
2301 # test needs a running copytool
2305 local f=$DIR/$tdir/$tfile
2306 local fid=$(make_small $f)
2308 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2309 error "could not archive file"
2310 wait_request_state $fid ARCHIVE STARTED
2312 check_hsm_flags $f "0x00000001"
2314 # Avoid coordinator resending this request as soon it has failed.
2317 $TRUNCATE $f 1024 || error "truncate failed"
2319 wait_request_state $fid ARCHIVE FAILED
2321 check_hsm_flags $f "0x00000003"
2326 run_test 55 "Truncate during an archive cancels it"
2329 # test needs a running copytool
2333 local f=$DIR/$tdir/$tfile
2334 local fid=$(make_large_for_progress $f)
2336 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2337 error "could not archive file"
2338 wait_request_state $fid ARCHIVE STARTED
2340 check_hsm_flags $f "0x00000001"
2342 # Change metadata and sync to be sure we are not changing only
2347 wait_request_state $fid ARCHIVE SUCCEED
2349 check_hsm_flags $f "0x00000009"
2353 run_test 56 "Setattr during an archive is ok"
2356 # Need one client for I/O, one for request
2357 needclients 2 || return 0
2359 # test needs a running copytool
2363 local f=$DIR/$tdir/test_archive_remote
2364 # Create a file on a remote node
2365 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2366 "count=2 conv=fsync"
2369 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2370 error "hsm_archive failed"
2371 local fid=$(path2fid $f)
2372 wait_request_state $fid ARCHIVE SUCCEED
2374 # Release and implicit restore it
2375 do_node $CLIENT2 "$LFS hsm_release $f" ||
2376 error "hsm_release failed"
2377 do_node $CLIENT2 "md5sum $f" ||
2378 error "hsm_restore failed"
2380 wait_request_state $fid RESTORE SUCCEED
2384 run_test 57 "Archive a file with dirty cache on another node"
2386 truncate_released_file() {
2390 local sz=$(stat -c %s $src_file)
2391 local f=$DIR/$tdir/$tfile
2392 local fid=$(copy_file $1 $f)
2396 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2397 error "could not archive file"
2398 wait_request_state $fid ARCHIVE SUCCEED
2400 $LFS hsm_release $f || error "could not release file"
2402 $TRUNCATE $f $trunc_to || error "truncate failed"
2405 local sz1=$(stat -c %s $f)
2406 [[ $sz1 == $trunc_to ]] ||
2407 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2410 check_hsm_flags $f "0x0000000b"
2412 local state=$(get_request_state $fid RESTORE)
2413 [[ "$state" == "SUCCEED" ]] ||
2414 error "truncate $sz does not trig restore, state = $state"
2416 $TRUNCATE $ref $trunc_to
2417 cmp $ref $f || error "file data wrong after truncate"
2423 # test needs a running copytool
2428 local sz=$(stat -c %s /etc/passwd)
2430 echo "truncate up from $sz to $((sz*2))"
2431 truncate_released_file /etc/passwd $((sz*2))
2433 echo "truncate down from $sz to $((sz/2))"
2434 truncate_released_file /etc/passwd $((sz/2))
2436 echo "truncate to 0"
2437 truncate_released_file /etc/passwd 0
2441 run_test 58 "Truncate a released file will trigger restore"
2446 local f=$DIR/$tdir/$tfile
2447 local FILELIST=/tmp/filelist.txt
2451 for i in $(seq 1 $file_count); do
2452 fid=$(copy_file /etc/hosts $f.$i)
2453 echo $f.$i >> $FILELIST
2456 # to be sure wait_all_done will not be mislead by previous tests
2458 wait_for_grace_delay
2459 $LFS hsm_archive --filelist $FILELIST ||
2460 error "cannot archive a file list"
2462 $LFS hsm_release --filelist $FILELIST ||
2463 error "cannot release a file list"
2464 $LFS hsm_restore --filelist $FILELIST ||
2465 error "cannot restore a file list"
2469 run_test 90 "Archive/restore a file list"
2471 double_verify_reset_hsm_param() {
2473 echo "Testing $HSM_PARAM.$p"
2474 local val=$(get_hsm_param $p)
2476 local val2=$(($val * 2))
2477 set_hsm_param $p $val2
2478 val=$(get_hsm_param $p)
2479 [[ $val == $val2 ]] ||
2480 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2481 echo "Set $p to 0 must failed"
2485 set_hsm_param $p $save
2487 if [[ $rc == 0 ]]; then
2488 error "we must not be able to set $HSM_PARAM.$p to 0"
2493 double_verify_reset_hsm_param loop_period
2494 double_verify_reset_hsm_param grace_delay
2495 double_verify_reset_hsm_param active_request_timeout
2496 double_verify_reset_hsm_param max_requests
2497 double_verify_reset_hsm_param default_archive_id
2499 run_test 100 "Set coordinator /proc tunables"
2506 run_test 102 "Verify coordinator control"
2509 # test needs a running copytool
2516 for i in $(seq 1 20); do
2517 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2519 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2523 echo "Current requests"
2524 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2525 $HSM_PARAM.actions |\
2526 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2528 [[ -z "$res" ]] || error "Some request have not been canceled"
2532 run_test 103 "Purge all requests"
2537 # test needs a running copytool
2541 local f=$DIR/$tdir/$tfile
2542 local fid=$(make_large_for_progress $f)
2543 # if cdt is on, it can serve too quickly the request
2545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2546 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2547 $HSM_PARAM.actions |\
2548 grep $fid | cut -f16 -d=")
2551 [[ "$data1" == "$DATAHEX" ]] ||
2552 error "Data field in records is ($data1) and not ($DATAHEX)"
2556 run_test 104 "Copy tool data field"
2563 for i in $(seq -w 1 10); do
2564 cp /etc/passwd $DIR/$tdir/$i
2565 $LFS hsm_archive $DIR/$tdir/$i
2567 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2568 $HSM_PARAM.actions |\
2569 grep WAITING | wc -l")
2572 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2573 $HSM_PARAM.actions |\
2574 grep WAITING | wc -l")
2577 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2578 error "Requests count after shutdown $reqcnt2 != "\
2579 "before shutdown $reqcnt1"
2581 run_test 105 "Restart of coordinator"
2584 # test needs a running copytool
2587 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2588 get_client_uuid $MOUNT | cut -d' ' -f2)
2589 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2592 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2593 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2595 [[ -z "$agent" ]] ||
2596 error "My uuid $uuid still found in agent list,"\
2597 " after copytool shutdown"
2599 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2602 [[ ! -z "$agent" ]] ||
2603 error "My uuid $uuid not found in agent list after"\
2606 run_test 106 "Copytool register/unregister"
2609 # test needs a running copytool
2611 # create and archive file
2613 local f1=$DIR/$tdir/$tfile
2614 local fid=$(copy_file /etc/passwd $f1)
2615 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2616 wait_request_state $fid ARCHIVE SUCCEED
2617 # shutdown and restart MDS
2619 # check the copytool still gets messages from MDT
2620 local f2=$DIR/$tdir/2
2621 local fid=$(copy_file /etc/passwd $f2)
2622 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2623 # main check of this sanity: this request MUST succeed
2624 wait_request_state $fid ARCHIVE SUCCEED
2627 run_test 107 "Copytool re-register after MDS restart"
2629 policy_set_and_test()
2633 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2634 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2635 [[ "$policy" == "$target" ]] ||
2636 error "Wrong policy after '$change': '$policy' != '$target'"
2640 # to force default policy setting if error
2641 CDT_POLICY_HAD_CHANGED=true
2643 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2644 local default="NonBlockingRestore [NoRetryAction]"
2645 [[ "$policy" == "$default" ]] ||
2646 error "default policy has changed,"\
2647 " '$policy' != '$default' update the test"
2648 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2649 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2650 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2651 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2652 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2653 # useless bacause we know but safer for futur changes to use real value
2654 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2655 echo "Next set_param must failed"
2656 policy_set_and_test "wrong" "$policy"
2659 echo "Back to default policy"
2660 cdt_set_sanity_policy
2662 run_test 109 "Policy display/change"
2665 # test needs a running copytool
2670 copy2archive /etc/passwd $tdir/$tfile
2672 local f=$DIR/$tdir/$tfile
2673 import_file $tdir/$tfile $f
2674 local fid=$(path2fid $f)
2676 cdt_set_non_blocking_restore
2681 wait_request_state $fid RESTORE SUCCEED
2682 cdt_clear_non_blocking_restore
2686 error "md5sum returns $st != 1, "\
2687 "should also perror ENODATA (No data available)"
2691 run_test 110a "Non blocking restore policy (import case)"
2694 # test needs a running copytool
2698 local f=$DIR/$tdir/$tfile
2699 local fid=$(copy_file /etc/passwd $f)
2700 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2701 wait_request_state $fid ARCHIVE SUCCEED
2704 cdt_set_non_blocking_restore
2709 wait_request_state $fid RESTORE SUCCEED
2710 cdt_clear_non_blocking_restore
2714 error "md5sum returns $st != 1, "\
2715 "should also perror ENODATA (No data available)"
2719 run_test 110b "Non blocking restore policy (release case)"
2722 # test needs a running copytool
2726 copy2archive /etc/passwd $tdir/$tfile
2728 local f=$DIR/$tdir/$tfile
2730 import_file $tdir/$tfile $f
2731 local fid=$(path2fid $f)
2735 copytool_remove_backend $fid
2738 wait_request_state $fid RESTORE FAILED
2745 [[ $st == 0 ]] || error "Restore does not failed"
2749 run_test 111a "No retry policy (import case), restore will error"\
2750 " (No such file or directory)"
2753 # test needs a running copytool
2757 local f=$DIR/$tdir/$tfile
2758 local fid=$(copy_file /etc/passwd $f)
2760 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2761 wait_request_state $fid ARCHIVE SUCCEED
2764 copytool_remove_backend $fid
2767 wait_request_state $fid RESTORE FAILED
2774 [[ $st == 0 ]] || error "Restore does not failed"
2778 run_test 111b "No retry policy (release case), restore will error"\
2779 " (No such file or directory)"
2782 # test needs a running copytool
2786 local f=$DIR/$tdir/$tfile
2787 local fid=$(copy_file /etc/passwd $f)
2789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2790 local l=$($LFS hsm_action $f)
2792 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2796 wait_request_state $fid ARCHIVE SUCCEED
2799 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2803 run_test 112 "State of recorded request"
2806 # test needs a running copytool
2810 local f=$DIR/$tdir/$tfile
2811 local fid=$(make_large_for_cancel $f)
2812 # test with cdt on is made in test_221
2814 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2817 wait_request_state $fid ARCHIVE CANCELED
2818 wait_request_state $fid CANCEL SUCCEED
2822 run_test 200 "Register/Cancel archive"
2825 # test needs a running copytool
2829 local f=$DIR/$tdir/$tfile
2830 make_archive $tdir/$tfile
2831 import_file $tdir/$tfile $f
2832 local fid=$(path2fid $f)
2834 # test with cdt on is made in test_222
2839 wait_request_state $fid RESTORE CANCELED
2840 wait_request_state $fid CANCEL SUCCEED
2844 run_test 201 "Register/Cancel restore"
2847 # test needs a running copytool
2851 local f=$DIR/$tdir/$tfile
2852 local fid=$(make_large_for_progress $f)
2853 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2854 wait_request_state $fid ARCHIVE SUCCEED
2860 wait_request_state $fid REMOVE CANCELED
2864 run_test 202 "Register/Cancel remove"
2867 # test needs a running copytool
2872 local f=$DIR/$tdir/$tfile
2873 local fid=$(copy_file /etc/passwd $f)
2877 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2878 wait_request_state $fid ARCHIVE SUCCEED
2880 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2884 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2888 run_test 220 "Changelog for archive"
2891 # test needs a running copytool
2896 local f=$DIR/$tdir/$tfile
2897 local fid=$(make_large_for_cancel $f)
2901 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2902 wait_request_state $fid ARCHIVE STARTED
2904 wait_request_state $fid ARCHIVE CANCELED
2905 wait_request_state $fid CANCEL SUCCEED
2907 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2910 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2914 run_test 221 "Changelog for archive canceled"
2917 # test needs a running copytool
2921 copy2archive /etc/passwd $tdir/$tfile
2923 local f=$DIR/$tdir/$tfile
2924 import_file $tdir/$tfile $f
2925 local fid=$(path2fid $f)
2930 wait_request_state $fid RESTORE SUCCEED
2932 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2935 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2939 run_test 222a "Changelog for explicit restore"
2942 # test needs a running copytool
2946 local f=$DIR/$tdir/$tfile
2947 local fid=$(copy_file /etc/passwd $f)
2950 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2951 wait_request_state $fid ARCHIVE SUCCEED
2956 wait_request_state $fid RESTORE SUCCEED
2958 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2961 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2965 run_test 222b "Changelog for implicit restore"
2968 # test needs a running copytool
2973 local f=$DIR/$tdir/$tfile
2974 make_archive $tdir/$tfile
2978 import_file $tdir/$tfile $f
2979 local fid=$(path2fid $f)
2982 wait_request_state $fid RESTORE STARTED
2984 wait_request_state $fid RESTORE CANCELED
2985 wait_request_state $fid CANCEL SUCCEED
2987 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2990 [[ $flags == $target ]] ||
2991 error "Changelog flag is $flags not $target"
2995 run_test 223a "Changelog for restore canceled (import case)"
2998 # test needs a running copytool
3003 local f=$DIR/$tdir/$tfile
3004 local fid=$(make_large_for_progress $f)
3007 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3008 wait_request_state $fid ARCHIVE SUCCEED
3011 wait_request_state $fid RESTORE STARTED
3013 wait_request_state $fid RESTORE CANCELED
3014 wait_request_state $fid CANCEL SUCCEED
3016 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3019 [[ $flags == $target ]] ||
3020 error "Changelog flag is $flags not $target"
3024 run_test 223b "Changelog for restore canceled (release case)"
3027 # test needs a running copytool
3032 local f=$DIR/$tdir/$tfile
3033 local fid=$(copy_file /etc/passwd $f)
3036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3037 wait_request_state $fid ARCHIVE SUCCEED
3040 wait_request_state $fid REMOVE SUCCEED
3042 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3045 [[ $flags == $target ]] ||
3046 error "Changelog flag is $flags not $target"
3050 run_test 224 "Changelog for remove"
3053 # test needs a running copytool
3056 # test is not usable because remove request is too fast
3057 # so it is always finished before cancel can be done ...
3058 echo "Test disabled"
3063 local f=$DIR/$tdir/$tfile
3064 local fid=$(make_large_for_progress $f)
3067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3068 wait_request_state $fid ARCHIVE SUCCEED
3070 # if cdt is on, it can serve too quickly the request
3075 wait_request_state $fid REMOVE CANCELED
3076 wait_request_state $fid CANCEL SUCCEED
3078 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3079 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3080 tail -n 1 | awk '{print $5}')
3083 [[ $flags == $target ]] ||
3084 error "Changelog flag is $flags not $target"
3088 run_test 225 "Changelog for remove canceled"
3091 # test needs a running copytool
3096 local f1=$DIR/$tdir/$tfile-1
3097 local f2=$DIR/$tdir/$tfile-2
3098 local f3=$DIR/$tdir/$tfile-3
3099 local fid1=$(copy_file /etc/passwd $f1)
3100 local fid2=$(copy_file /etc/passwd $f2)
3101 copy_file /etc/passwd $f3
3104 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3105 wait_request_state $fid1 ARCHIVE SUCCEED
3107 $LFS hsm_archive $f2
3108 wait_request_state $fid2 ARCHIVE SUCCEED
3110 rm $f1 || error "rm $f1 failed"
3112 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3115 [[ $flags == $target ]] ||
3116 error "Changelog flag is $flags not $target"
3118 mv $f3 $f2 || error "mv $f3 $f2 failed"
3120 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3123 [[ $flags == $target ]] ||
3124 error "Changelog flag is $flags not $target"
3128 run_test 226 "changelog for last rm/mv with exiting archive"
3130 check_flags_changes() {
3138 $LFS hsm_set --$hsm_flag $f ||
3139 error "Cannot set $hsm_flag on $f"
3140 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3141 local seen=${#flags[*]}
3143 [[ $seen == $cnt ]] ||
3144 error "set $hsm_flag: Changelog events $seen != $cnt"
3145 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3146 error "set $hsm_flag: Changelog flags are "\
3147 "${flags[$((cnt - 1))]} not $target"
3149 $LFS hsm_clear --$hsm_flag $f ||
3150 error "Cannot clear $hsm_flag on $f"
3151 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3154 [[ $cnt == $seen ]] ||
3155 error "clear $hsm_flag: Changelog events $seen != $cnt"
3157 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3158 error "clear $hsm_flag: Changelog flag is "\
3159 "${flags[$((cnt - 1))]} not $target"
3163 # test needs a running copytool
3170 for i in norelease noarchive exists archived
3172 local f=$DIR/$tdir/$tfile-$i
3173 local fid=$(copy_file /etc/passwd $f)
3174 check_flags_changes $f $fid $i 0 1
3177 f=$DIR/$tdir/$tfile---lost
3178 fid=$(copy_file /etc/passwd $f)
3179 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3180 wait_request_state $fid ARCHIVE SUCCEED
3181 check_flags_changes $f $fid lost 3 1
3185 run_test 227 "changelog when explicit setting of HSM flags"
3188 # test needs a running copytool
3191 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3192 error "creating $DIR/$tfile"
3193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3194 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3196 $LFS hsm_release $DIR/$tfile
3197 check_hsm_flags $DIR/$tfile "0x0000000d"
3199 filefrag $DIR/$tfile | grep " 1 extent found" ||
3200 error "filefrag on released file must return only one extent"
3202 # only newer versions of cp detect sparse files by stat/FIEMAP
3204 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3205 error "copying $DIR/$tfile"
3206 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3208 $LFS hsm_release $DIR/$tfile
3209 check_hsm_flags $DIR/$tfile "0x0000000d"
3213 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3215 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3216 error "comparing untarred $DIR/$tfile"
3220 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3223 # test needs a running copytool
3227 local maxrequest=$(get_hsm_param max_requests)
3228 local rqcnt=$(($maxrequest * 3))
3232 for i in $(seq -w 1 $rqcnt); do
3234 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3236 # we do it in 2 steps, so all requests arrive at the same time
3237 for i in $(seq -w 1 $rqcnt); do
3238 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3243 while [[ $cnt != 0 || $wt != 0 ]]; do
3245 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3246 $HSM_PARAM.actions |\
3247 grep STARTED | grep -v CANCEL | wc -l")
3248 [[ $cnt -le $maxrequest ]] ||
3249 error "$cnt > $maxrequest too many started requests"
3250 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3251 $HSM_PARAM.actions |\
3252 grep WAITING | wc -l")
3253 echo "max=$maxrequest started=$cnt waiting=$wt"
3258 run_test 250 "Coordinator max request"
3261 # test needs a running copytool
3265 local f=$DIR/$tdir/$tfile
3266 local fid=$(make_large_for_cancel $f)
3269 # to have a short test
3270 local old_to=$(get_hsm_param active_request_timeout)
3271 set_hsm_param active_request_timeout 4
3272 # to be sure the cdt will wake up frequently so
3273 # it will be able to cancel the "old" request
3274 local old_loop=$(get_hsm_param loop_period)
3275 set_hsm_param loop_period 2
3278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3279 wait_request_state $fid ARCHIVE STARTED
3281 wait_request_state $fid ARCHIVE CANCELED
3283 set_hsm_param active_request_timeout $old_to
3284 set_hsm_param loop_period $old_loop
3288 run_test 251 "Coordinator request timeout"
3291 # the only way to test ondisk conf is to restart MDS ...
3292 echo "Stop coordinator and remove coordinator state at mount"
3295 # clean on disk conf set by default
3296 cdt_clear_mount_state
3297 cdt_check_state stopped
3299 # check cdt still off after umount/remount
3301 cdt_check_state stopped
3303 echo "Set coordinator start at mount, and start coordinator"
3304 cdt_set_mount_state enabled
3307 cdt_check_state enabled
3309 # check cdt still on after umount/remount
3311 cdt_check_state enabled
3313 # we are back to original state (cdt started at mount)
3315 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3318 local ai=$(get_hsm_param default_archive_id)
3319 local new=$((ai + 1))
3321 set_hsm_param default_archive_id $new -P
3323 local res=$(get_hsm_param default_archive_id)
3326 set_hsm_param default_archive_id "" "-P -d"
3328 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3330 run_test 301 "HSM tunnable are persistent"
3333 local ai=$(get_hsm_param default_archive_id)
3334 local new=$((ai + 1))
3339 set_hsm_param default_archive_id $new -P
3343 cdt_check_state enabled
3345 local res=$(get_hsm_param default_archive_id)
3348 set_hsm_param default_archive_id "" "-P -d"
3350 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3352 run_test 302 "HSM tunnable are persistent when CDT is off"
3357 check_and_cleanup_lustre