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 if [[ $MDSCOUNT -ge 2 ]]; then
34 skip_env "Only run with single MDT for now" && 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 MDT_PARAM="mdt.$FSNAME-MDT0000"
98 HSM_PARAM="$MDT_PARAM.hsm"
100 # archive is purged at copytool setup
101 HSM_ARCHIVE_PURGE=true
104 # Get the backend root path for the given agent facet.
107 local dev=AGTDEV$(facet_number $facet)
112 # Stop copytool and unregister an existing changelog user.
116 cdt_set_sanity_policy
119 search_and_kill_copytool() {
120 local agents=${1:-$(facet_active_host $SINGLEAGT)}
122 echo "Killing existing copytools on $agents"
123 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
127 local facet=${1:-$SINGLEAGT}
128 local lustre_mntpnt=${2:-$MOUNT}
130 local hsm_root=$(copytool_device $facet)
131 local agent=$(facet_active_host $facet)
133 if [[ -z "$arc_id" ]] &&
134 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
135 echo "Wakeup copytool $facet on $agent"
139 if $HSM_ARCHIVE_PURGE; then
140 echo "Purging archive on $agent"
141 do_facet $facet "rm -rf $hsm_root/*"
144 echo "Starting copytool $facet on $agent"
145 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
146 # bandwidth is limited to 1MB/s so the copy time is known and
147 # independent of hardware
148 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
149 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
150 cmd+=" --bandwidth 1 $lustre_mntpnt"
152 # Redirect the standard output and error to a log file which
153 # can be uploaded to Maloo.
154 local prefix=$TESTLOG_PREFIX
155 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
156 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
158 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
159 error "start copytool $facet on $agent failed"
165 local agents=${1:-$(facet_active_host $SINGLEAGT)}
167 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
169 echo "Copytool is stopped on $agents"
173 local agents=${1:-$(facet_active_host $SINGLEAGT)}
175 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
176 echo "Copytool is suspended on $agents"
179 copytool_remove_backend() {
181 local be=$(find $HSM_ARCHIVE -name $fid)
182 echo "Remove from backend: $fid = $be"
183 do_facet $SINGLEAGT rm -f $be
187 do_facet $SINGLEAGT \
188 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
189 --import $1 $2 $MOUNT" ||
190 error "import of $1 to $2 failed"
194 local file=$HSM_ARCHIVE/$1
195 do_facet $SINGLEAGT mkdir -p $(dirname $file)
196 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
197 error "cannot create $file"
201 local file=$HSM_ARCHIVE/$2
202 do_facet $SINGLEAGT mkdir -p $(dirname $file)
203 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
207 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0\
208 changelog_register -n)
209 do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+hsm"
210 $LFS changelog_clear $MDT0 $CL_USER 0
213 changelog_cleanup() {
214 # $LFS changelog $MDT0
215 [[ -n "$CL_USER" ]] || return 0
217 $LFS changelog_clear $MDT0 $CL_USER 0
218 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
222 changelog_get_flags() {
227 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
232 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
240 if [[ "$value" != "" ]]; then
243 do_facet $SINGLEMDS $LCTL set_param $opt -n $HSM_PARAM.$param$value
250 do_facet $SINGLEMDS $LCTL set_param $MDT_PARAM.hsm_control=$cmd
251 wait_result $SINGLEMDS "$LCTL get_param -n $MDT_PARAM.hsm_control"\
252 $target 10 || error "cdt state is not $target"
255 cdt_set_sanity_policy() {
256 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
259 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
260 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
261 CDT_POLICY_HAD_CHANGED=
266 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
267 CDT_POLICY_HAD_CHANGED=true
270 cdt_clear_no_retry() {
271 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NRA
272 CDT_POLICY_HAD_CHANGED=true
275 cdt_set_non_blocking_restore() {
276 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NBR
277 CDT_POLICY_HAD_CHANGED=true
280 cdt_clear_non_blocking_restore() {
281 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
282 CDT_POLICY_HAD_CHANGED=true
285 cdt_clear_mount_state() {
286 do_facet $SINGLEMDS $LCTL set_param -d -P $MDT_PARAM.hsm_control
289 cdt_set_mount_state() {
290 do_facet $SINGLEMDS $LCTL set_param -P $MDT_PARAM.hsm_control=$1
295 wait_result $SINGLEMDS\
296 "$LCTL get_param -n $MDT_PARAM.hsm_control" "$target" 20 ||
297 error "cdt state is not $target"
301 set_test_state disabled disabled
305 set_test_state enabled enabled
309 set_test_state shutdown stopped
313 set_test_state purge enabled
319 cdt_set_sanity_policy
323 local client_count=$1
324 if [[ $CLIENTCOUNT -lt $client_count ]]; then
325 skip "Need $client_count or more clients, have $CLIENTCOUNT"
332 $LFS path2fid $1 | tr -d '[]'
339 if [[ $u == "user" ]]; then
340 local st=$($RUNAS $LFS hsm_state $f)
342 local st=$($LFS hsm_state $f)
346 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
348 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
352 get_hsm_archive_id() {
354 local st=$($LFS hsm_state $f)
355 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
357 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
366 local st=$(get_hsm_flags $f)
367 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
370 check_hsm_flags_user() {
374 local st=$(get_hsm_flags $f user)
375 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
387 if [[ "$3" != 1 ]]; then
391 cp $1 $f || error "cannot copy $1 to $f"
392 path2fid $f || error "cannot get fid on $f"
396 local file2=${1/$DIR/$DIR2}
397 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
398 error "cannot create $file2"
399 path2fid $1 || error "cannot get fid on $1"
402 cleanup_large_files() {
403 local ratio=$(df $MOUNT |awk '{print $5}' |sed 's/%//g' |grep -v Use)
404 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
407 make_large_for_striping() {
408 local file2=${1/$DIR/$DIR2}
409 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
413 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
414 error "cannot create $file2"
415 path2fid $1 || error "cannot get fid on $1"
418 make_large_for_progress() {
419 local file2=${1/$DIR/$DIR2}
423 # big file is large enough, so copy time is > 30s
424 # so copytool make 1 progress
425 # size is not a multiple of 1M to avoid stripe
427 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
428 error "cannot create $file2"
429 path2fid $1 || error "cannot get fid on $1"
432 make_large_for_progress_aligned() {
433 local file2=${1/$DIR/$DIR2}
437 # big file is large enough, so copy time is > 30s
438 # so copytool make 1 progress
439 # size is a multiple of 1M to have stripe
441 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
442 error "cannot create $file2"
443 path2fid $1 || error "cannot get fid on $1"
446 make_large_for_cancel() {
447 local file2=${1/$DIR/$DIR2}
451 # Copy timeout is 100s. 105MB => 105s
452 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
453 error "cannot create $file2"
454 path2fid $1 || error "cannot get fid on $1"
460 wait_update --verbose $(facet_active_host $facet) "$@"
463 wait_request_state() {
468 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
469 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
471 wait_result $SINGLEMDS "$cmd" $state 100 ||
472 error "request on $fid is not $state"
475 get_request_state() {
479 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
480 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
483 get_request_count() {
487 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
488 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
494 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
495 cmd+=" | egrep 'WAITING|STARTED'"
497 wait_result $SINGLEMDS "$cmd" "" $timeout ||
498 error "requests did not complete"
501 wait_for_grace_delay() {
502 local val=$(get_hsm_param grace_delay)
506 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
507 awk '{gsub(/_UUID/,""); print $1}' | head -1)
512 # cleanup from previous bad setup
513 search_and_kill_copytool
515 # for recovery tests, coordinator needs to be started at mount
517 # the lustre conf must be without hsm on (like for sanity.sh)
518 echo "Set HSM on and start"
519 cdt_set_mount_state enabled
520 cdt_check_state enabled
522 echo "Start copytool"
525 echo "Set sanity-hsm HSM policy"
526 cdt_set_sanity_policy
528 # finished requests are quickly removed from list
529 set_hsm_param grace_delay 10
535 local f=$DIR/$tdir/$tfile
539 check_hsm_flags_user $f "0x00000000"
541 $RUNAS $LFS hsm_set --norelease $f ||
542 error "user could not change hsm flags"
543 check_hsm_flags_user $f "0x00000010"
545 $RUNAS $LFS hsm_clear --norelease $f ||
546 error "user could not clear hsm flags"
547 check_hsm_flags_user $f "0x00000000"
549 # User could not change those flags...
550 $RUNAS $LFS hsm_set --exists $f &&
551 error "user should not set this flag"
552 check_hsm_flags_user $f "0x00000000"
555 $LFS hsm_set --exists $f ||
556 error "root could not change hsm flags"
557 check_hsm_flags_user $f "0x00000001"
559 $LFS hsm_clear --exists $f ||
560 error "root could not clear hsm state"
561 check_hsm_flags_user $f "0x00000000"
564 run_test 1 "lfs hsm flags root/non-root access"
568 local f=$DIR/$tdir/$tfile
570 # New files are not dirty
571 check_hsm_flags $f "0x00000000"
573 # For test, we simulate an archived file.
574 $LFS hsm_set --exists $f || error "user could not change hsm flags"
575 check_hsm_flags $f "0x00000001"
577 # chmod do not put the file dirty
578 chmod 600 $f || error "could not chmod test file"
579 check_hsm_flags $f "0x00000001"
581 # chown do not put the file dirty
582 chown $RUNAS_ID $f || error "could not chown test file"
583 check_hsm_flags $f "0x00000001"
585 # truncate put the file dirty
586 $TRUNCATE $f 1 || error "could not truncate test file"
587 check_hsm_flags $f "0x00000003"
589 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
590 check_hsm_flags $f "0x00000001"
592 run_test 2 "Check file dirtyness when doing setattr"
598 # New files are not dirty
600 check_hsm_flags $f "0x00000000"
602 # For test, we simulate an archived file.
603 $LFS hsm_set --exists $f ||
604 error "user could not change hsm flags"
605 check_hsm_flags $f "0x00000001"
607 # Reading a file, does not set dirty
608 cat $f > /dev/null || error "could not read file"
609 check_hsm_flags $f "0x00000001"
611 # Open for write without modifying data, does not set dirty
612 openfile -f O_WRONLY $f || error "could not open test file"
613 check_hsm_flags $f "0x00000001"
615 # Append to a file sets it dirty
616 cp -p /etc/passwd $f.append || error "could not create file"
617 $LFS hsm_set --exists $f.append ||
618 error "user could not change hsm flags"
619 dd if=/etc/passwd of=$f.append bs=1 count=3\
620 conv=notrunc oflag=append status=noxfer ||
621 error "could not append to test file"
622 check_hsm_flags $f.append "0x00000003"
624 # Modify a file sets it dirty
625 cp -p /etc/passwd $f.modify || error "could not create file"
626 $LFS hsm_set --exists $f.modify ||
627 error "user could not change hsm flags"
628 dd if=/dev/zero of=$f.modify bs=1 count=3\
629 conv=notrunc status=noxfer ||
630 error "could not modify test file"
631 check_hsm_flags $f.modify "0x00000003"
633 # Open O_TRUNC sets dirty
634 cp -p /etc/passwd $f.trunc || error "could not create file"
635 $LFS hsm_set --exists $f.trunc ||
636 error "user could not change hsm flags"
637 cp /etc/group $f.trunc || error "could not override a file"
638 check_hsm_flags $f.trunc "0x00000003"
640 # Mmapped a file sets dirty
641 cp -p /etc/passwd $f.mmap || error "could not create file"
642 $LFS hsm_set --exists $f.mmap ||
643 error "user could not change hsm flags"
644 multiop $f.mmap OSMWUc || error "could not mmap a file"
645 check_hsm_flags $f.mmap "0x00000003"
647 run_test 3 "Check file dirtyness when opening for write"
651 local f=$DIR/$tdir/$tfile
652 local fid=$(make_small $f)
655 local st=$(get_request_state $fid CANCEL)
656 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
658 run_test 4 "Useless cancel must not be registered"
661 # test needs a running copytool
665 local f=$DIR/$tdir/$tfile
666 local fid=$(copy_file /etc/passwd $f)
668 wait_request_state $fid ARCHIVE SUCCEED
670 check_hsm_flags $f "0x00000009"
674 run_test 8 "Test default archive number"
678 local f=$DIR/$tdir/$tfile
679 local fid=$(copy_file /etc/passwd $f)
680 # we do not use the default one to be sure
681 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
683 copytool_setup $SINGLEAGT $MOUNT $new_an
684 $LFS hsm_archive --archive $new_an $f
685 wait_request_state $fid ARCHIVE SUCCEED
687 check_hsm_flags $f "0x00000009"
691 run_test 9 "Use of explict archive number, with dedicated copytool"
694 needclients 3 || return 0
700 copytool_cleanup $(comma_list $(agts_nodes))
702 # start all of the copytools
703 for n in $(seq $AGTCOUNT); do
707 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
710 for n in $(seq $AGTCOUNT); do
711 file=$DIR/$tdir/$tfile.$n
712 fid=$(make_small $file)
714 $LFS hsm_archive $file || error "could not archive file $file"
715 wait_request_state $fid ARCHIVE SUCCEED
716 check_hsm_flags $file "0x00000009"
720 copytool_cleanup $(comma_list $(agts_nodes))
722 run_test 9a "Multiple remote agents"
725 # test needs a running copytool
728 mkdir -p $DIR/$tdir/d1
729 local f=$DIR/$tdir/$tfile
730 local fid=$(copy_file /etc/hosts $f)
731 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
732 error "hsm_archive failed"
733 wait_request_state $fid ARCHIVE SUCCEED
735 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
736 error "fid $fid not in archive $HSM_ARCHIVE"
737 echo "Verifying content"
738 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
739 echo "Verifying hsm state "
740 check_hsm_flags $f "0x00000009"
742 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
743 local st=$(get_hsm_archive_id $f)
744 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
745 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
750 run_test 10a "Archive a file"
753 # test needs a running copytool
757 local f=$DIR/$tdir/$tfile
758 local fid=$(copy_file /etc/hosts $f)
759 $LFS hsm_archive $f || error "archive request failed"
760 wait_request_state $fid ARCHIVE SUCCEED
762 $LFS hsm_archive $f || error "archive of non dirty file failed"
763 local cnt=$(get_request_count $fid ARCHIVE)
764 [[ "$cnt" == "1" ]] ||
765 error "archive of non dirty file must not make a request"
769 run_test 10b "Archive of non dirty file must work without doing request"
772 # test needs a running copytool
776 local f=$DIR/$tdir/$tfile
777 local fid=$(copy_file /etc/hosts $f)
778 $LFS hsm_set --noarchive $f
779 $LFS hsm_archive $f && error "archive a noarchive file must fail"
783 run_test 10c "Check forbidden archive"
786 # test needs a running copytool
790 local f=$DIR/$tdir/$tfile
791 local fid=$(copy_file /etc/hosts $f)
792 $LFS hsm_archive $f || error "cannot archive $f"
793 wait_request_state $fid ARCHIVE SUCCEED
795 local ar=$(get_hsm_archive_id $f)
796 local dflt=$(get_hsm_param default_archive_id)
797 [[ $ar == $dflt ]] ||
798 error "archived file is not on default archive: $ar != $dflt"
802 run_test 10d "Archive a file on the default archive id"
806 copy2archive /etc/hosts $tdir/$tfile
807 local f=$DIR/$tdir/$tfile
809 import_file $tdir/$tfile $f
810 echo -n "Verifying released state: "
811 check_hsm_flags $f "0x0000000d"
813 local LSZ=$(stat -c "%s" $f)
814 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
816 echo "Verifying imported size $LSZ=$ASZ"
817 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
818 echo -n "Verifying released pattern: "
819 local PTRN=$($GETSTRIPE -L $f)
821 [[ $PTRN == 80000001 ]] || error "Is not released"
822 local fid=$(path2fid $f)
823 echo "Verifying new fid $fid in archive"
825 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
826 error "fid $fid not in archive $HSM_ARCHIVE"
828 run_test 11 "Import a file"
831 # test needs a running copytool
835 copy2archive /etc/hosts $tdir/$tfile
837 local f=$DIR/$tdir/$tfile
838 import_file $tdir/$tfile $f
839 local f=$DIR2/$tdir/$tfile
840 echo "Verifying released state: "
841 check_hsm_flags $f "0x0000000d"
843 local fid=$(path2fid $f)
845 wait_request_state $fid RESTORE SUCCEED
847 echo "Verifying file state: "
848 check_hsm_flags $f "0x00000009"
850 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
852 [[ $? -eq 0 ]] || error "Restored file differs"
856 run_test 12a "Restore an imported file explicitly"
859 # test needs a running copytool
863 copy2archive /etc/hosts $tdir/$tfile
865 local f=$DIR/$tdir/$tfile
866 import_file $tdir/$tfile $f
867 echo "Verifying released state: "
868 check_hsm_flags $f "0x0000000d"
870 cat $f > /dev/null || error "File read failed"
872 echo "Verifying file state after restore: "
873 check_hsm_flags $f "0x00000009"
875 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
877 [[ $? -eq 0 ]] || error "Restored file differs"
881 run_test 12b "Restore an imported file implicitly"
884 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
886 # test needs a running copytool
890 local f=$DIR/$tdir/$tfile
891 $LFS setstripe -c 2 $f
892 local fid=$(make_large_for_striping $f)
893 local FILE_CRC=$(md5sum $f)
895 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
896 wait_request_state $fid ARCHIVE SUCCEED
897 $LFS hsm_release $f || error "release $f failed"
899 echo "$FILE_CRC" | md5sum -c
901 [[ $? -eq 0 ]] || error "Restored file differs"
905 run_test 12c "Restore a file with stripe of 2"
908 # test needs a running copytool
913 local f=$DIR/$tdir/$tfile
914 local fid=$(copy_file /etc/hosts $f)
915 $LFS hsm_restore $f || error "restore of non archived file failed"
916 local cnt=$(get_request_count $fid RESTORE)
917 [[ "$cnt" == "0" ]] ||
918 error "restore non archived must not make a request"
919 $LFS hsm_archive $f ||
920 error "archive request failed"
921 wait_request_state $fid ARCHIVE SUCCEED
922 $LFS hsm_restore $f ||
923 error "restore of non released file failed"
924 local cnt=$(get_request_count $fid RESTORE)
925 [[ "$cnt" == "0" ]] ||
926 error "restore a non dirty file must not make a request"
930 run_test 12d "Restore of a non archived, non released file must work"\
931 " without doing request"
934 # test needs a running copytool
937 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
938 local f=$DIR/$tdir/$tfile
939 local fid=$(copy_file /etc/hosts $f)
940 $LFS hsm_archive $f || error "archive request failed"
941 wait_request_state $fid ARCHIVE SUCCEED
948 $LFS hsm_restore $f && error "restore a dirty file must fail"
952 run_test 12e "Check forbidden restore"
955 # test needs a running copytool
959 local f=$DIR/$tdir/$tfile
960 local fid=$(copy_file /etc/hosts $f)
962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
963 wait_request_state $fid ARCHIVE SUCCEED
964 $LFS hsm_release $f || error "release of $f failed"
966 wait_request_state $fid RESTORE SUCCEED
968 echo -n "Verifying file state: "
969 check_hsm_flags $f "0x00000009"
971 diff -q /etc/hosts $f
973 [[ $? -eq 0 ]] || error "Restored file differs"
977 run_test 12f "Restore a released file explicitly"
980 # test needs a running copytool
984 local f=$DIR/$tdir/$tfile
985 local fid=$(copy_file /etc/hosts $f)
987 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
988 wait_request_state $fid ARCHIVE SUCCEED
989 $LFS hsm_release $f || error "release of $f failed"
991 diff -q /etc/hosts $f
994 # we check we had a restore done
995 wait_request_state $fid RESTORE SUCCEED
997 [[ $st -eq 0 ]] || error "Restored file differs"
1001 run_test 12g "Restore a released file implicitly"
1004 needclients 2 || return 0
1006 # test needs a running copytool
1010 local f=$DIR/$tdir/$tfile
1011 local fid=$(copy_file /etc/hosts $f)
1013 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1014 wait_request_state $fid ARCHIVE SUCCEED
1015 $LFS hsm_release $f || error "release of $f failed"
1017 do_node $CLIENT2 diff -q /etc/hosts $f
1020 # we check we had a restore done
1021 wait_request_state $fid RESTORE SUCCEED
1023 [[ $st -eq 0 ]] || error "Restored file differs"
1027 run_test 12h "Restore a released file implicitly from a second node"
1030 # test needs a running copytool
1034 local f=$DIR/$tdir/$tfile
1035 local fid=$(copy_file /etc/passwd $f)
1036 $LFS hsm_archive $f || error "archive of $f failed"
1037 wait_request_state $fid ARCHIVE SUCCEED
1039 $LFS hsm_release $f || error "release of $f failed"
1043 [[ $? -eq 0 ]] || error "Restored file differs"
1047 run_test 12m "Archive/release/implicit restore"
1050 # test needs a running copytool
1054 copy2archive /etc/hosts $tdir/$tfile
1056 local f=$DIR/$tdir/$tfile
1057 import_file $tdir/$tfile $f
1059 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1060 error "Restored file differs"
1062 $LFS hsm_release $f || error "release of $f failed"
1066 run_test 12n "Import/implicit restore/release"
1069 # test needs a running copytool
1072 local ARC_SUBDIR="import.orig"
1076 # populate directory to be imported
1077 for d in $(seq 1 10); do
1078 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1079 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1080 for f in $(seq 1 10); do
1081 CURR_FILE="$CURR_DIR/$tfile.$f"
1082 # write file-specific data
1083 do_facet $SINGLEAGT \
1084 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1085 "file=$CURR_FILE > $CURR_FILE"
1089 import_file "$ARC_SUBDIR" $DIR/$tdir
1090 # diff lustre content and origin (triggers file restoration)
1091 # there must be 10x10 identical files, and no difference
1092 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1093 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1094 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1095 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1097 [ $cnt_diff -eq 0 ] ||
1098 error "$cnt_diff imported files differ from read data"
1099 [ $cnt_ok -eq 100 ] ||
1100 error "not enough identical files ($cnt_ok != 100)"
1104 run_test 13 "Recursively import and restore a directory"
1107 # test needs a running copytool
1112 local f=$DIR/$tdir/$tfile
1113 local fid=$(make_small $f)
1114 local sum=$(md5sum $f | awk '{print $1}')
1115 $LFS hsm_archive $f || error "could not archive file"
1116 wait_request_state $fid ARCHIVE SUCCEED
1120 # create released file (simulate llapi_hsm_import call)
1122 local fid2=$(path2fid $f)
1123 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1124 $LFS hsm_release $f || error "could not release file"
1126 # rebind the archive to the newly created file
1127 echo "rebind $fid to $fid2"
1129 do_facet $SINGLEAGT \
1130 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1131 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1133 # restore file and compare md5sum
1134 local sum2=$(md5sum $f | awk '{print $1}')
1136 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1140 run_test 14 "Rebind archived file to a new fid"
1143 # test needs a running copytool
1148 local f=$DIR/$tdir/$tfile
1150 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1154 for i in $(seq 1 $count); do
1155 fids[$i]=$(make_small $f.$i)
1156 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1157 $LFS hsm_archive $f.$i || error "could not archive file"
1159 wait_all_done $(($count*60))
1163 for i in $(seq 1 $count); do
1166 local fid2=$(path2fid $f.$i)
1167 # add the rebind operation to the list
1168 echo ${fids[$i]} $fid2 >> $tmpfile
1170 # set it released (simulate llapi_hsm_import call)
1171 $LFS hsm_set --archived --exists $f.$i ||
1172 error "could not force hsm flags"
1173 $LFS hsm_release $f.$i || error "could not release file"
1175 nl=$(wc -l < $tmpfile)
1176 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1178 echo "rebind list of files"
1179 do_facet $SINGLEAGT \
1180 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1181 --rebind $tmpfile $DIR" || error "could not rebind file list"
1183 # restore files and compare md5sum
1184 for i in $(seq 1 $count); do
1185 local sum2=$(md5sum $f.$i | awk '{print $1}')
1186 [[ $sum2 == ${sums[$i]} ]] ||
1187 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1193 run_test 15 "Rebind a list of files"
1196 # test needs a running copytool
1200 # create a known size file so we can verify transfer speed
1203 dd if=/dev/zero of=$ref bs=1M count=20
1206 local f=$DIR/$tdir/$tfile
1207 local fid=$(copy_file $ref $f)
1209 local start=$(date +%s)
1211 wait_request_state $fid ARCHIVE SUCCEED
1212 local end=$(date +%s)
1213 local duration=$((end - start))
1215 [[ $duration -ge $goal ]] ||
1216 error "Transfer is too fast $duration < $goal"
1220 run_test 16 "Test CT bandwith control option"
1225 local f=$DIR/$tdir/$tfile
1226 touch $f || error "touch $f failed"
1228 # Could not release a non-archived file
1229 $LFS hsm_release $f && error "release should not succeed"
1231 # For following tests, we must test them with HS_ARCHIVED set
1232 $LFS hsm_set --exists --archived $f || error "could not add flag"
1234 # Could not release a file if no-release is set
1235 $LFS hsm_set --norelease $f || error "could not add flag"
1236 $LFS hsm_release $f && error "release should not succeed"
1237 $LFS hsm_clear --norelease $f || error "could not remove flag"
1239 # Could not release a file if lost
1240 $LFS hsm_set --lost $f || error "could not add flag"
1241 $LFS hsm_release $f && error "release should not succeed"
1242 $LFS hsm_clear --lost $f || error "could not remove flag"
1244 # Could not release a file if dirty
1245 $LFS hsm_set --dirty $f || error "could not add flag"
1246 $LFS hsm_release $f && error "release should not succeed"
1247 $LFS hsm_clear --dirty $f || error "could not remove flag"
1249 run_test 20 "Release is not permitted"
1252 # test needs a running copytool
1256 local f=$DIR/$tdir/test_release
1258 # Create a file and check its states
1259 local fid=$(make_small $f)
1260 check_hsm_flags $f "0x00000000"
1262 $LFS hsm_archive $f || error "could not archive file"
1263 wait_request_state $fid ARCHIVE SUCCEED
1265 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1266 local sz=$(stat -c "%s" $f)
1267 [ $sz -ne "0" ] || error "file size should not be zero"
1269 # Release and check states
1270 $LFS hsm_release $f || error "could not release file"
1271 check_hsm_flags $f "0x0000000d"
1273 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1274 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1276 # Check we can release an file without stripe info
1280 check_hsm_flags $f "0x00000000"
1281 $LFS hsm_archive $f || error "could not archive file"
1282 wait_request_state $fid ARCHIVE SUCCEED
1284 # Release and check states
1285 $LFS hsm_release $f || error "could not release file"
1286 check_hsm_flags $f "0x0000000d"
1288 # Release again a file that is already released is OK
1289 $LFS hsm_release $f || fail "second release should succeed"
1290 check_hsm_flags $f "0x0000000d"
1294 run_test 21 "Simple release tests"
1297 # test needs a running copytool
1302 local f=$DIR/$tdir/test_release
1303 local swap=$DIR/$tdir/test_swap
1305 # Create a file and check its states
1306 local fid=$(make_small $f)
1307 check_hsm_flags $f "0x00000000"
1309 $LFS hsm_archive $f || error "could not archive file"
1310 wait_request_state $fid ARCHIVE SUCCEED
1312 # Release and check states
1313 $LFS hsm_release $f || error "could not release file"
1314 check_hsm_flags $f "0x0000000d"
1317 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1322 run_test 22 "Could not swap a release file"
1325 # test needs a running copytool
1330 local f=$DIR/$tdir/test_mtime
1332 # Create a file and check its states
1333 local fid=$(make_small $f)
1334 check_hsm_flags $f "0x00000000"
1336 $LFS hsm_archive $f || error "could not archive file"
1337 wait_request_state $fid ARCHIVE SUCCEED
1339 # Set modification time in the past
1340 touch -m -a -d @978261179 $f
1342 # Release and check states
1343 $LFS hsm_release $f || error "could not release file"
1344 check_hsm_flags $f "0x0000000d"
1346 local MTIME=$(stat -c "%Y" $f)
1347 local ATIME=$(stat -c "%X" $f)
1348 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1349 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1353 run_test 23 "Release does not change a/mtime (utime)"
1356 local file=$DIR/$tdir/$tfile
1365 # test needs a running copytool
1370 fid=$(make_small $file)
1372 # Create a file and check its states
1373 check_hsm_flags $file "0x00000000"
1375 # Ensure atime is less than mtime and ctime.
1379 atime0=$(stat -c "%X" $file)
1380 mtime0=$(stat -c "%Y" $file)
1381 ctime0=$(stat -c "%Z" $file)
1383 [ $atime0 -lt $mtime0 ] ||
1384 error "atime $atime0 is not less than mtime $mtime0"
1386 [ $atime0 -lt $ctime0 ] ||
1387 error "atime $atime0 is not less than ctime $ctime0"
1389 # Archive should not change any timestamps.
1390 $LFS hsm_archive $file || error "cannot archive '$file'"
1391 wait_request_state $fid ARCHIVE SUCCEED
1393 atime1=$(stat -c "%X" $file)
1394 mtime1=$(stat -c "%Y" $file)
1395 ctime1=$(stat -c "%Z" $file)
1397 [ $atime0 -eq $atime1 ] ||
1398 error "archive changed atime from $atime0 to $atime1"
1400 [ $mtime0 -eq $mtime1 ] ||
1401 error "archive changed mtime from $mtime0 to $mtime1"
1403 [ $ctime0 -eq $ctime1 ] ||
1404 error "archive changed ctime from $ctime0 to $ctime1"
1406 # Release should not change any timestamps.
1407 $LFS hsm_release $file || error "cannot release '$file'"
1408 check_hsm_flags $file "0x0000000d"
1410 atime1=$(stat -c "%X" $file)
1411 mtime1=$(stat -c "%Y" $file)
1412 ctime1=$(stat -c "%Z" $file)
1414 [ $atime0 -eq $atime1 ] ||
1415 error "release changed atime from $atime0 to $atime1"
1417 [ $mtime0 -eq $mtime1 ] ||
1418 error "release changed mtime from $mtime0 to $mtime1"
1420 [ $ctime0 -eq $ctime1 ] ||
1421 error "release changed ctime from $ctime0 to $ctime1"
1423 # Restore should not change atime or mtime and should not
1425 $LFS hsm_restore $file
1426 wait_request_state $fid RESTORE SUCCEED
1428 atime1=$(stat -c "%X" $file)
1429 mtime1=$(stat -c "%Y" $file)
1430 ctime1=$(stat -c "%Z" $file)
1432 [ $atime0 -eq $atime1 ] ||
1433 error "restore changed atime from $atime0 to $atime1"
1435 [ $mtime0 -eq $mtime1 ] ||
1436 error "restore changed mtime from $mtime0 to $mtime1"
1438 [ $ctime0 -le $ctime1 ] ||
1439 error "restore changed ctime from $ctime0 to $ctime1"
1443 # Once more, after unmount and mount.
1444 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1445 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1447 atime1=$(stat -c "%X" $file)
1448 mtime1=$(stat -c "%Y" $file)
1449 ctime1=$(stat -c "%Z" $file)
1451 [ $atime0 -eq $atime1 ] ||
1452 error "remount changed atime from $atime0 to $atime1"
1454 [ $mtime0 -eq $mtime1 ] ||
1455 error "remount changed mtime from $mtime0 to $mtime1"
1457 [ $ctime0 -le $ctime1 ] ||
1458 error "remount changed ctime from $ctime0 to $ctime1"
1460 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1463 local file=$DIR/$tdir/$tfile
1469 # Test needs a running copytool.
1473 # Check that root can do HSM actions on a ordinary user's file.
1475 fid=$(make_small $file)
1476 sum0=$(md5sum $file)
1478 chown $RUNAS_ID:$RUNAS_GID $file ||
1479 error "cannot chown '$file' to '$RUNAS_ID'"
1481 chmod ugo-w $DIR/$tdir ||
1482 error "cannot chmod '$DIR/$tdir'"
1484 $LFS hsm_archive $file
1485 wait_request_state $fid ARCHIVE SUCCEED
1487 $LFS hsm_release $file
1488 check_hsm_flags $file "0x0000000d"
1490 $LFS hsm_restore $file
1491 wait_request_state $fid RESTORE SUCCEED
1493 # Check that ordinary user can get HSM state.
1494 $RUNAS $LFS hsm_state $file ||
1495 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1497 $LFS hsm_release $file
1498 check_hsm_flags $file "0x0000000d"
1500 # Check that ordinary user can accessed released file.
1501 sum1=$($RUNAS md5sum $file) ||
1502 error "user '$RUNAS_ID' cannot read '$file'"
1504 [ "$sum0" == "$sum1" ] ||
1505 error "md5sum mismatch for '$file'"
1509 run_test 24b "root can archive, release, and restore user files"
1511 cleanup_test_24c() {
1513 set_hsm_param user_request_mask RESTORE
1514 set_hsm_param group_request_mask RESTORE
1515 set_hsm_param other_request_mask RESTORE
1519 local file=$DIR/$tdir/$tfile
1520 local action=archive
1525 # test needs a running copytool
1530 # Save the default masks and check that cleanup_24c will
1531 # restore the request masks correctly.
1532 user_save=$(get_hsm_param user_request_mask)
1533 group_save=$(get_hsm_param group_request_mask)
1534 other_save=$(get_hsm_param other_request_mask)
1536 [ "$user_save" == RESTORE ] ||
1537 error "user_request_mask is '$user_save' expected 'RESTORE'"
1538 [ "$group_save" == RESTORE ] ||
1539 error "group_request_mask is '$group_save' expected 'RESTORE'"
1540 [ "$other_save" == RESTORE ] ||
1541 error "other_request_mask is '$other_save' expected 'RESTORE'"
1543 trap cleanup_test_24c EXIT
1548 chown $RUNAS_ID:nobody $file ||
1549 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1551 set_hsm_param user_request_mask ""
1552 $RUNAS $LFS hsm_$action $file &&
1553 error "$action by user should fail"
1555 set_hsm_param user_request_mask $action
1556 $RUNAS $LFS hsm_$action $file ||
1557 error "$action by user should succeed"
1562 chown nobody:$RUNAS_GID $file ||
1563 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1565 set_hsm_param group_request_mask ""
1566 $RUNAS $LFS hsm_$action $file &&
1567 error "$action by group should fail"
1569 set_hsm_param group_request_mask $action
1570 $RUNAS $LFS hsm_$action $file ||
1571 error "$action by group should succeed"
1576 chown nobody:nobody $file ||
1577 error "cannot chown '$file' to 'nobody:nobody'"
1579 set_hsm_param other_request_mask ""
1580 $RUNAS $LFS hsm_$action $file &&
1581 error "$action by other should fail"
1583 set_hsm_param other_request_mask $action
1584 $RUNAS $LFS hsm_$action $file ||
1585 error "$action by other should succeed"
1590 run_test 24c "check that user,group,other request masks work"
1592 cleanup_test_24d() {
1594 mount -o remount,rw $MOUNT2
1598 local file1=$DIR/$tdir/$tfile
1599 local file2=$DIR2/$tdir/$tfile
1607 fid1=$(make_small $file1)
1609 trap cleanup_test_24d EXIT
1611 mount -o remount,ro $MOUNT2
1613 fid2=$(path2fid $file2)
1614 [ "$fid1" == "$fid2" ] ||
1615 error "FID mismatch '$fid1' != '$fid2'"
1617 $LFS hsm_archive $file2 &&
1618 error "archive should fail on read-only mount"
1619 check_hsm_flags $file1 "0x00000000"
1621 $LFS hsm_archive $file1
1622 wait_request_state $fid1 ARCHIVE SUCCEED
1624 $LFS hsm_release $file1
1625 $LFS hsm_restore $file2
1626 wait_request_state $fid1 RESTORE SUCCEED
1628 $LFS hsm_release $file1 || error "cannot release '$file1'"
1629 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1631 $LFS hsm_release $file2 &&
1632 error "release should fail on read-only mount"
1637 run_test 24d "check that read-only mounts are respected"
1640 # test needs a running copytool
1644 copy2archive /etc/hosts $tdir/$tfile
1646 local f=$DIR/$tdir/$tfile
1648 import_file $tdir/$tfile $f
1650 $LFS hsm_set --lost $f
1655 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1659 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1660 " (Operation not permitted)"
1663 # test needs a running copytool
1668 local f=$DIR/$tdir/$tfile
1669 local fid=$(copy_file /etc/passwd $f)
1671 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1672 wait_request_state $fid ARCHIVE SUCCEED
1675 $LFS hsm_set --lost $f
1679 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1683 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1684 " (Operation not permitted)"
1687 # test needs a running copytool
1691 local f=$DIR/$tdir/$tfile
1692 local fid=$(make_large_for_progress $f)
1693 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1694 wait_request_state $fid ARCHIVE SUCCEED
1697 wait_request_state $fid REMOVE SUCCEED
1699 check_hsm_flags $f "0x00000000"
1703 run_test 26 "Remove the archive of a valid file"
1706 # test needs a running copytool
1710 make_archive $tdir/$tfile
1711 local f=$DIR/$tdir/$tfile
1712 import_file $tdir/$tfile $f
1713 local fid=$(path2fid $f)
1717 [[ $? != 0 ]] || error "Remove of a released file should fail"
1721 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1724 # test needs a running copytool
1728 local f=$DIR/$tdir/$tfile
1729 local fid=$(make_large_for_progress $f)
1730 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1731 wait_request_state $fid ARCHIVE SUCCEED
1736 [[ $? != 0 ]] || error "Remove of a released file should fail"
1740 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1743 # test needs a running copytool
1747 local f=$DIR/$tdir/$tfile
1748 local fid=$(make_large_for_progress $f)
1749 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1750 wait_request_state $fid ARCHIVE SUCCEED
1759 wait_request_state $fid REMOVE SUCCEED
1763 run_test 28 "Concurrent archive/file remove"
1766 # restore at exec cannot work on agent node (because of Linux kernel
1767 # protection of executables)
1768 needclients 2 || return 0
1770 # test needs a running copytool
1774 copy2archive /bin/true $tdir/$tfile
1776 local f=$DIR/$tdir/true
1777 import_file $tdir/$tfile $f
1779 local fid=$(path2fid $f)
1781 # set no retry action mode
1787 # remove no try action mode
1791 [[ $st == 0 ]] || error "Failed to exec a released file"
1795 run_test 30a "Restore at exec (import case)"
1798 # restore at exec cannot work on agent node (because of Linux kernel
1799 # protection of executables)
1800 needclients 2 || return 0
1802 # test needs a running copytool
1806 local f=$DIR/$tdir/true
1807 local fid=$(copy_file /bin/true $f)
1809 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1810 wait_request_state $fid ARCHIVE SUCCEED
1813 # set no retry action mode
1819 # remove no try action mode
1823 [[ $st == 0 ]] || error "Failed to exec a released file"
1827 run_test 30b "Restore at exec (release case)"
1830 needclients 2 || return 0
1832 # test needs a running copytool
1836 local f=$DIR/$tdir/SLEEP
1837 local fid=$(copy_file /bin/sleep $f)
1839 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1840 wait_request_state $fid ARCHIVE SUCCEED
1842 check_hsm_flags $f "0x0000000d"
1843 # set no retry action mode
1845 do_node $CLIENT2 "$f 10" &
1849 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1851 [[ $? == 0 ]] || error "Execution failed during run"
1853 [[ $? == 0 ]] || error "Binary overwritten during exec"
1856 # remove no try action mode
1858 check_hsm_flags $f "0x00000009"
1862 run_test 30c "Update during exec of released file must fail"
1864 restore_and_check_size() {
1867 local s=$(stat -c "%s" $f)
1869 local st=$(get_hsm_flags $f)
1873 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1875 n=$(stat -c "%s" $f)
1876 # we echo in both cases to show stat is not
1878 if [[ $n != $s ]]; then
1879 echo "size seen is $n != $s"
1882 echo "size seen is right: $n == $s"
1884 st=$(get_hsm_flags $f)
1888 if [[ $cpt -lt 10 ]]; then
1889 echo " restore is too long"
1893 wait_request_state $fid RESTORE SUCCEED
1898 # test needs a running copytool
1903 make_archive $tdir/$tfile
1904 local f=$DIR/$tdir/$tfile
1905 import_file $tdir/$tfile $f
1906 local fid=$($LFS path2fid $f)
1907 HSM_ARCHIVE_PURGE=false copytool_setup
1909 restore_and_check_size $f $fid
1912 [[ $err -eq 0 ]] || error "File size changed during restore"
1916 run_test 31a "Import a large file and check size during restore"
1920 # test needs a running copytool
1925 local f=$DIR/$tdir/$tfile
1926 local fid=$(make_large_for_progress $f)
1927 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1928 wait_request_state $fid ARCHIVE SUCCEED
1931 restore_and_check_size $f $fid
1934 [[ $err -eq 0 ]] || error "File size changed during restore"
1938 run_test 31b "Restore a large unaligned file and check size during restore"
1941 # test needs a running copytool
1946 local f=$DIR/$tdir/$tfile
1947 local fid=$(make_large_for_progress_aligned $f)
1948 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1949 wait_request_state $fid ARCHIVE SUCCEED
1952 restore_and_check_size $f $fid
1955 [[ $err -eq 0 ]] || error "File size changed during restore"
1959 run_test 31c "Restore a large aligned file and check size during restore"
1962 # test needs a running copytool
1967 local f=$DIR/$tdir/$tfile
1968 local fid=$(make_large_for_progress $f)
1969 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1970 wait_request_state $fid ARCHIVE SUCCEED
1973 md5sum $f >/dev/null &
1975 wait_request_state $fid RESTORE STARTED
1980 # Check restore trigger process was killed
1981 local killed=$(ps -o pid,comm hp $pid >/dev/null)
1985 wait_request_state $fid RESTORE CANCELED
1986 wait_request_state $fid CANCEL SUCCEED
1989 error "Cannot kill process waiting for restore ($killed)"
1993 run_test 33 "Kill a restore waiting process"
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 md5sum $f >/dev/null &
2009 wait_request_state $fid RESTORE STARTED
2011 rm $f || error "rm $f failed"
2012 # rm must not block during restore
2013 wait_request_state $fid RESTORE STARTED
2015 wait_request_state $fid RESTORE SUCCEED
2016 # check md5sum pgm finished
2017 local there=$(ps -o pid,comm hp $pid >/dev/null)
2018 [[ -z $there ]] || error "Restore initiator does not exit"
2020 local rc=$(wait $pid)
2021 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2025 run_test 34 "Remove file during restore"
2028 # test needs a running copytool
2033 local f=$DIR/$tdir/$tfile
2034 local f1=$DIR/$tdir/$tfile-1
2035 local fid=$(make_large_for_progress $f)
2036 local fid1=$(copy_file /etc/passwd $f1)
2037 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2038 wait_request_state $fid ARCHIVE SUCCEED
2041 md5sum $f >/dev/null &
2043 wait_request_state $fid RESTORE STARTED
2045 mv $f1 $f || error "mv $f1 $f failed"
2046 # mv must not block during restore
2047 wait_request_state $fid RESTORE STARTED
2049 wait_request_state $fid RESTORE SUCCEED
2050 # check md5sum pgm finished
2051 local there=$(ps -o pid,comm hp $pid >/dev/null)
2052 [[ -z $there ]] || error "Restore initiator does not exit"
2054 local rc=$(wait $pid)
2055 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2058 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2062 run_test 35 "Overwrite file during restore"
2065 # test needs a running copytool
2070 local f=$DIR/$tdir/$tfile
2071 local fid=$(make_large_for_progress $f)
2072 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2073 wait_request_state $fid ARCHIVE SUCCEED
2076 md5sum $f >/dev/null &
2078 wait_request_state $fid RESTORE STARTED
2081 # rm must not block during restore
2082 wait_request_state $fid RESTORE STARTED
2084 wait_request_state $fid RESTORE SUCCEED
2085 # check md5sum pgm finished
2086 local there=$(ps -o pid,comm hp $pid >/dev/null)
2088 error "Restore initiator does not exit"
2090 local rc=$(wait $pid)
2092 error "Restore initiator failed with $rc"
2096 run_test 36 "Move file during restore"
2103 for n in $(seq 1 $count); do
2104 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2106 echo "$count archive requests submitted"
2110 local stream_count=4
2111 local file_count=100
2113 local f=$DIR/$tdir/$tfile
2118 for i in $(seq 1 $file_count); do
2119 for p in $(seq 1 $stream_count); do
2120 fid=$(copy_file /etc/hosts $f.$p.$i)
2124 # to be sure wait_all_done will not be mislead by previous tests
2126 wait_for_grace_delay
2128 # start archive streams in background (archive files in parallel)
2129 for p in $(seq 1 $stream_count); do
2130 multi_archive $f.$p $file_count &
2133 echo -n "Wait for all requests being enqueued..."
2139 run_test 40 "Parallel archive requests"
2142 # test needs a running copytool
2146 local f=$DIR/$tdir/$tfile
2147 local fid=$(copy_file /etc/motd $f 1)
2149 $LFS hsm_archive $f || error "could not archive file"
2150 wait_request_state $fid ARCHIVE SUCCEED
2151 check_hsm_flags $f "0x00000009"
2153 multiop_bg_pause $f O_c || error "multiop failed"
2157 client_up || client_up || true
2159 kill -USR1 $MULTIPID
2160 wait $MULTIPID || error "multiop close failed"
2162 check_hsm_flags $f "0x0000000b"
2166 run_test 52 "Opened for write file on an evicted client should be set dirty"
2169 # test needs a running copytool
2173 local f=$DIR/$tdir/$tfile
2174 local fid=$(copy_file /etc/motd $f 1)
2176 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2177 error "could not archive file"
2178 wait_request_state $fid ARCHIVE SUCCEED
2179 check_hsm_flags $f "0x00000009"
2181 multiop_bg_pause $f o_c || error "multiop failed"
2185 client_up || client_up || true
2187 kill -USR1 $MULTIPID
2188 wait $MULTIPID || error "multiop close failed"
2190 check_hsm_flags $f "0x00000009"
2194 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2197 # test needs a running copytool
2201 local f=$DIR/$tdir/$tfile
2202 local fid=$(make_small $f)
2204 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2205 error "could not archive file"
2206 wait_request_state $fid ARCHIVE STARTED
2208 check_hsm_flags $f "0x00000001"
2210 # Avoid coordinator resending this request as soon it has failed.
2215 wait_request_state $fid ARCHIVE FAILED
2217 check_hsm_flags $f "0x00000003"
2222 run_test 54 "Write during an archive cancels it"
2225 # test needs a running copytool
2229 local f=$DIR/$tdir/$tfile
2230 local fid=$(make_small $f)
2232 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2233 error "could not archive file"
2234 wait_request_state $fid ARCHIVE STARTED
2236 check_hsm_flags $f "0x00000001"
2238 # Avoid coordinator resending this request as soon it has failed.
2241 $TRUNCATE $f 1024 || error "truncate failed"
2243 wait_request_state $fid ARCHIVE FAILED
2245 check_hsm_flags $f "0x00000003"
2250 run_test 55 "Truncate during an archive cancels it"
2253 # test needs a running copytool
2257 local f=$DIR/$tdir/$tfile
2258 local fid=$(make_large_for_progress $f)
2260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2261 error "could not archive file"
2262 wait_request_state $fid ARCHIVE STARTED
2264 check_hsm_flags $f "0x00000001"
2266 # Change metadata and sync to be sure we are not changing only
2271 wait_request_state $fid ARCHIVE SUCCEED
2273 check_hsm_flags $f "0x00000009"
2277 run_test 56 "Setattr during an archive is ok"
2280 # Need one client for I/O, one for request
2281 needclients 2 || return 0
2283 # test needs a running copytool
2287 local f=$DIR/$tdir/test_archive_remote
2288 # Create a file on a remote node
2289 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2290 "count=2 conv=fsync"
2293 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2294 error "hsm_archive failed"
2295 local fid=$(path2fid $f)
2296 wait_request_state $fid ARCHIVE SUCCEED
2298 # Release and implicit restore it
2299 do_node $CLIENT2 "$LFS hsm_release $f" ||
2300 error "hsm_release failed"
2301 do_node $CLIENT2 "md5sum $f" ||
2302 error "hsm_restore failed"
2304 wait_request_state $fid RESTORE SUCCEED
2308 run_test 57 "Archive a file with dirty cache on another node"
2310 truncate_released_file() {
2314 local sz=$(stat -c %s $src_file)
2315 local f=$DIR/$tdir/$tfile
2316 local fid=$(copy_file $1 $f)
2320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2321 error "could not archive file"
2322 wait_request_state $fid ARCHIVE SUCCEED
2324 $LFS hsm_release $f || error "could not release file"
2326 $TRUNCATE $f $trunc_to || error "truncate failed"
2329 local sz1=$(stat -c %s $f)
2330 [[ $sz1 == $trunc_to ]] ||
2331 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2334 check_hsm_flags $f "0x0000000b"
2336 local state=$(get_request_state $fid RESTORE)
2337 [[ "$state" == "SUCCEED" ]] ||
2338 error "truncate $sz does not trig restore, state = $state"
2340 $TRUNCATE $ref $trunc_to
2341 cmp $ref $f || error "file data wrong after truncate"
2347 # test needs a running copytool
2352 local sz=$(stat -c %s /etc/passwd)
2354 echo "truncate up from $sz to $((sz*2))"
2355 truncate_released_file /etc/passwd $((sz*2))
2357 echo "truncate down from $sz to $((sz/2))"
2358 truncate_released_file /etc/passwd $((sz/2))
2360 echo "truncate to 0"
2361 truncate_released_file /etc/passwd 0
2365 run_test 58 "Truncate a released file will trigger restore"
2370 local f=$DIR/$tdir/$tfile
2371 local FILELIST=/tmp/filelist.txt
2375 for i in $(seq 1 $file_count); do
2376 fid=$(copy_file /etc/hosts $f.$i)
2377 echo $f.$i >> $FILELIST
2380 # to be sure wait_all_done will not be mislead by previous tests
2382 wait_for_grace_delay
2383 $LFS hsm_archive --filelist $FILELIST ||
2384 error "cannot archive a file list"
2386 $LFS hsm_release --filelist $FILELIST ||
2387 error "cannot release a file list"
2388 $LFS hsm_restore --filelist $FILELIST ||
2389 error "cannot restore a file list"
2393 run_test 90 "Archive/restore a file list"
2395 double_verify_reset_hsm_param() {
2397 echo "Testing $HSM_PARAM.$p"
2398 local val=$(get_hsm_param $p)
2400 local val2=$(($val * 2))
2401 set_hsm_param $p $val2
2402 val=$(get_hsm_param $p)
2403 [[ $val == $val2 ]] ||
2404 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2405 echo "Set $p to 0 must failed"
2409 set_hsm_param $p $save
2411 if [[ $rc == 0 ]]; then
2412 error "we must not be able to set $HSM_PARAM.$p to 0"
2417 double_verify_reset_hsm_param loop_period
2418 double_verify_reset_hsm_param grace_delay
2419 double_verify_reset_hsm_param active_request_timeout
2420 double_verify_reset_hsm_param max_requests
2421 double_verify_reset_hsm_param default_archive_id
2423 run_test 100 "Set coordinator /proc tunables"
2430 run_test 102 "Verify coordinator control"
2433 # test needs a running copytool
2440 for i in $(seq 1 20); do
2441 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2443 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2447 echo "Current requests"
2448 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2449 $HSM_PARAM.actions |\
2450 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2452 [[ -z "$res" ]] || error "Some request have not been canceled"
2456 run_test 103 "Purge all requests"
2461 # test needs a running copytool
2465 local f=$DIR/$tdir/$tfile
2466 local fid=$(make_large_for_progress $f)
2467 # if cdt is on, it can serve too quickly the request
2469 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2470 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2471 $HSM_PARAM.actions |\
2472 grep $fid | cut -f16 -d=")
2475 [[ "$data1" == "$DATAHEX" ]] ||
2476 error "Data field in records is ($data1) and not ($DATAHEX)"
2480 run_test 104 "Copy tool data field"
2487 for i in $(seq -w 1 10); do
2488 cp /etc/passwd $DIR/$tdir/$i
2489 $LFS hsm_archive $DIR/$tdir/$i
2491 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2492 $HSM_PARAM.actions |\
2493 grep WAITING | wc -l")
2496 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2497 $HSM_PARAM.actions |\
2498 grep WAITING | wc -l")
2501 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2502 error "Requests count after shutdown $reqcnt2 != "\
2503 "before shutdown $reqcnt1"
2505 run_test 105 "Restart of coordinator"
2508 # test needs a running copytool
2511 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2512 get_client_uuid $MOUNT | cut -d' ' -f2)
2513 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2516 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2517 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2519 [[ -z "$agent" ]] ||
2520 error "My uuid $uuid still found in agent list,"\
2521 " after copytool shutdown"
2523 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2526 [[ ! -z "$agent" ]] ||
2527 error "My uuid $uuid not found in agent list after"\
2530 run_test 106 "Copytool register/unregister"
2533 # test needs a running copytool
2535 # create and archive file
2537 local f1=$DIR/$tdir/$tfile
2538 local fid=$(copy_file /etc/passwd $f1)
2539 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2540 wait_request_state $fid ARCHIVE SUCCEED
2541 # shutdown and restart MDS
2543 # check the copytool still gets messages from MDT
2544 local f2=$DIR/$tdir/2
2545 local fid=$(copy_file /etc/passwd $f2)
2546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2547 # main check of this sanity: this request MUST succeed
2548 wait_request_state $fid ARCHIVE SUCCEED
2551 run_test 107 "Copytool re-register after MDS restart"
2553 policy_set_and_test()
2557 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2558 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2559 [[ "$policy" == "$target" ]] ||
2560 error "Wrong policy after '$change': '$policy' != '$target'"
2564 # to force default policy setting if error
2565 CDT_POLICY_HAD_CHANGED=true
2567 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2568 local default="NonBlockingRestore [NoRetryAction]"
2569 [[ "$policy" == "$default" ]] ||
2570 error "default policy has changed,"\
2571 " '$policy' != '$default' update the test"
2572 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2573 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2574 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2575 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2576 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2577 # useless bacause we know but safer for futur changes to use real value
2578 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2579 echo "Next set_param must failed"
2580 policy_set_and_test "wrong" "$policy"
2583 echo "Back to default policy"
2584 cdt_set_sanity_policy
2586 run_test 109 "Policy display/change"
2589 # test needs a running copytool
2594 copy2archive /etc/passwd $tdir/$tfile
2596 local f=$DIR/$tdir/$tfile
2597 import_file $tdir/$tfile $f
2598 local fid=$(path2fid $f)
2600 cdt_set_non_blocking_restore
2605 wait_request_state $fid RESTORE SUCCEED
2606 cdt_clear_non_blocking_restore
2610 error "md5sum returns $st != 1, "\
2611 "should also perror ENODATA (No data available)"
2615 run_test 110a "Non blocking restore policy (import case)"
2618 # test needs a running copytool
2622 local f=$DIR/$tdir/$tfile
2623 local fid=$(copy_file /etc/passwd $f)
2624 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2625 wait_request_state $fid ARCHIVE SUCCEED
2628 cdt_set_non_blocking_restore
2633 wait_request_state $fid RESTORE SUCCEED
2634 cdt_clear_non_blocking_restore
2638 error "md5sum returns $st != 1, "\
2639 "should also perror ENODATA (No data available)"
2643 run_test 110b "Non blocking restore policy (release case)"
2646 # test needs a running copytool
2650 copy2archive /etc/passwd $tdir/$tfile
2652 local f=$DIR/$tdir/$tfile
2654 import_file $tdir/$tfile $f
2655 local fid=$(path2fid $f)
2659 copytool_remove_backend $fid
2662 wait_request_state $fid RESTORE FAILED
2669 [[ $st == 0 ]] || error "Restore does not failed"
2673 run_test 111a "No retry policy (import case), restore will error"\
2674 " (No such file or directory)"
2677 # test needs a running copytool
2681 local f=$DIR/$tdir/$tfile
2682 local fid=$(copy_file /etc/passwd $f)
2684 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2685 wait_request_state $fid ARCHIVE SUCCEED
2688 copytool_remove_backend $fid
2691 wait_request_state $fid RESTORE FAILED
2698 [[ $st == 0 ]] || error "Restore does not failed"
2702 run_test 111b "No retry policy (release case), restore will error"\
2703 " (No such file or directory)"
2706 # test needs a running copytool
2710 local f=$DIR/$tdir/$tfile
2711 local fid=$(copy_file /etc/passwd $f)
2713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2714 local l=$($LFS hsm_action $f)
2716 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2720 wait_request_state $fid ARCHIVE SUCCEED
2723 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2727 run_test 112 "State of recorded request"
2730 # test needs a running copytool
2734 local f=$DIR/$tdir/$tfile
2735 local fid=$(make_large_for_cancel $f)
2736 # test with cdt on is made in test_221
2738 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2741 wait_request_state $fid ARCHIVE CANCELED
2742 wait_request_state $fid CANCEL SUCCEED
2746 run_test 200 "Register/Cancel archive"
2749 # test needs a running copytool
2753 local f=$DIR/$tdir/$tfile
2754 make_archive $tdir/$tfile
2755 import_file $tdir/$tfile $f
2756 local fid=$(path2fid $f)
2758 # test with cdt on is made in test_222
2763 wait_request_state $fid RESTORE CANCELED
2764 wait_request_state $fid CANCEL SUCCEED
2768 run_test 201 "Register/Cancel restore"
2771 # test needs a running copytool
2775 local f=$DIR/$tdir/$tfile
2776 local fid=$(make_large_for_progress $f)
2777 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2778 wait_request_state $fid ARCHIVE SUCCEED
2784 wait_request_state $fid REMOVE CANCELED
2788 run_test 202 "Register/Cancel remove"
2791 # test needs a running copytool
2796 local f=$DIR/$tdir/$tfile
2797 local fid=$(copy_file /etc/passwd $f)
2801 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2802 wait_request_state $fid ARCHIVE SUCCEED
2804 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2808 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2812 run_test 220 "Changelog for archive"
2815 # test needs a running copytool
2820 local f=$DIR/$tdir/$tfile
2821 local fid=$(make_large_for_cancel $f)
2825 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2826 wait_request_state $fid ARCHIVE STARTED
2828 wait_request_state $fid ARCHIVE CANCELED
2829 wait_request_state $fid CANCEL SUCCEED
2831 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2834 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2838 run_test 221 "Changelog for archive canceled"
2841 # test needs a running copytool
2845 copy2archive /etc/passwd $tdir/$tfile
2847 local f=$DIR/$tdir/$tfile
2848 import_file $tdir/$tfile $f
2849 local fid=$(path2fid $f)
2854 wait_request_state $fid RESTORE SUCCEED
2856 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2859 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2863 run_test 222a "Changelog for explicit restore"
2866 # test needs a running copytool
2870 local f=$DIR/$tdir/$tfile
2871 local fid=$(copy_file /etc/passwd $f)
2874 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2875 wait_request_state $fid ARCHIVE SUCCEED
2880 wait_request_state $fid RESTORE SUCCEED
2882 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2885 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2889 run_test 222b "Changelog for implicit restore"
2892 # test needs a running copytool
2897 local f=$DIR/$tdir/$tfile
2898 make_archive $tdir/$tfile
2902 import_file $tdir/$tfile $f
2903 local fid=$(path2fid $f)
2906 wait_request_state $fid RESTORE STARTED
2908 wait_request_state $fid RESTORE CANCELED
2909 wait_request_state $fid CANCEL SUCCEED
2911 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2914 [[ $flags == $target ]] ||
2915 error "Changelog flag is $flags not $target"
2919 run_test 223a "Changelog for restore canceled (import case)"
2922 # test needs a running copytool
2927 local f=$DIR/$tdir/$tfile
2928 local fid=$(make_large_for_progress $f)
2931 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2932 wait_request_state $fid ARCHIVE SUCCEED
2935 wait_request_state $fid RESTORE STARTED
2937 wait_request_state $fid RESTORE CANCELED
2938 wait_request_state $fid CANCEL SUCCEED
2940 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2943 [[ $flags == $target ]] ||
2944 error "Changelog flag is $flags not $target"
2948 run_test 223b "Changelog for restore canceled (release case)"
2951 # test needs a running copytool
2956 local f=$DIR/$tdir/$tfile
2957 local fid=$(copy_file /etc/passwd $f)
2960 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2961 wait_request_state $fid ARCHIVE SUCCEED
2964 wait_request_state $fid REMOVE SUCCEED
2966 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2969 [[ $flags == $target ]] ||
2970 error "Changelog flag is $flags not $target"
2974 run_test 224 "Changelog for remove"
2977 # test needs a running copytool
2980 # test is not usable because remove request is too fast
2981 # so it is always finished before cancel can be done ...
2982 echo "Test disabled"
2987 local f=$DIR/$tdir/$tfile
2988 local fid=$(make_large_for_progress $f)
2991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2992 wait_request_state $fid ARCHIVE SUCCEED
2994 # if cdt is on, it can serve too quickly the request
2999 wait_request_state $fid REMOVE CANCELED
3000 wait_request_state $fid CANCEL SUCCEED
3002 flags=$(changelog_get_flags $MDT0 RENME $fid2)
3003 local flags=$($LFS changelog $MDT0 | grep HSM | grep $fid | tail -1 |
3007 [[ $flags == $target ]] ||
3008 error "Changelog flag is $flags not $target"
3012 run_test 225 "Changelog for remove canceled"
3015 # test needs a running copytool
3020 local f1=$DIR/$tdir/$tfile-1
3021 local f2=$DIR/$tdir/$tfile-2
3022 local f3=$DIR/$tdir/$tfile-3
3023 local fid1=$(copy_file /etc/passwd $f1)
3024 local fid2=$(copy_file /etc/passwd $f2)
3025 copy_file /etc/passwd $f3
3028 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3029 wait_request_state $fid1 ARCHIVE SUCCEED
3031 $LFS hsm_archive $f2
3032 wait_request_state $fid2 ARCHIVE SUCCEED
3034 rm $f1 || error "rm $f1 failed"
3036 local flags=$(changelog_get_flags $MDT0 UNLNK $fid1)
3039 [[ $flags == $target ]] ||
3040 error "Changelog flag is $flags not $target"
3042 mv $f3 $f2 || error "mv $f3 $f2 failed"
3044 flags=$(changelog_get_flags $MDT0 RENME $fid2)
3047 [[ $flags == $target ]] ||
3048 error "Changelog flag is $flags not $target"
3052 run_test 226 "changelog for last rm/mv with exiting archive"
3054 check_flags_changes() {
3062 $LFS hsm_set --$hsm_flag $f ||
3063 error "Cannot set $hsm_flag on $f"
3064 local flags=($(changelog_get_flags $MDT0 HSM $fid))
3065 local seen=${#flags[*]}
3067 [[ $seen == $cnt ]] ||
3068 error "set $hsm_flag: Changelog events $seen != $cnt"
3069 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3070 error "set $hsm_flag: Changelog flags are "\
3071 "${flags[$((cnt - 1))]} not $target"
3073 $LFS hsm_clear --$hsm_flag $f ||
3074 error "Cannot clear $hsm_flag on $f"
3075 flags=($(changelog_get_flags $MDT0 HSM $fid))
3078 [[ $cnt == $seen ]] ||
3079 error "clear $hsm_flag: Changelog events $seen != $cnt"
3081 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3082 error "clear $hsm_flag: Changelog flag is "\
3083 "${flags[$((cnt - 1))]} not $target"
3087 # test needs a running copytool
3094 for i in norelease noarchive exists archived
3096 local f=$DIR/$tdir/$tfile-$i
3097 local fid=$(copy_file /etc/passwd $f)
3098 check_flags_changes $f $fid $i 0 1
3101 f=$DIR/$tdir/$tfile---lost
3102 fid=$(copy_file /etc/passwd $f)
3103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3104 wait_request_state $fid ARCHIVE SUCCEED
3105 check_flags_changes $f $fid lost 3 1
3109 run_test 227 "changelog when explicit setting of HSM flags"
3112 # test needs a running copytool
3115 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3116 error "creating $DIR/$tfile"
3117 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3118 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3120 $LFS hsm_release $DIR/$tfile
3121 check_hsm_flags $DIR/$tfile "0x0000000d"
3123 filefrag $DIR/$tfile | grep " 1 extent found" ||
3124 error "filefrag on released file must return only one extent"
3126 # only newer versions of cp detect sparse files by stat/FIEMAP
3128 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3129 error "copying $DIR/$tfile"
3130 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3132 $LFS hsm_release $DIR/$tfile
3133 check_hsm_flags $DIR/$tfile "0x0000000d"
3137 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3139 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3140 error "comparing untarred $DIR/$tfile"
3144 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3147 # test needs a running copytool
3151 local maxrequest=$(get_hsm_param max_requests)
3152 local rqcnt=$(($maxrequest * 3))
3156 for i in $(seq -w 1 $rqcnt); do
3158 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3160 # we do it in 2 steps, so all requests arrive at the same time
3161 for i in $(seq -w 1 $rqcnt); do
3162 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3167 while [[ $cnt != 0 || $wt != 0 ]]; do
3169 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3170 $HSM_PARAM.actions |\
3171 grep STARTED | grep -v CANCEL | wc -l")
3172 [[ $cnt -le $maxrequest ]] ||
3173 error "$cnt > $maxrequest too many started requests"
3174 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3175 $HSM_PARAM.actions |\
3176 grep WAITING | wc -l")
3177 echo "max=$maxrequest started=$cnt waiting=$wt"
3182 run_test 250 "Coordinator max request"
3185 # test needs a running copytool
3189 local f=$DIR/$tdir/$tfile
3190 local fid=$(make_large_for_cancel $f)
3193 # to have a short test
3194 local old_to=$(get_hsm_param active_request_timeout)
3195 set_hsm_param active_request_timeout 4
3196 # to be sure the cdt will wake up frequently so
3197 # it will be able to cancel the "old" request
3198 local old_loop=$(get_hsm_param loop_period)
3199 set_hsm_param loop_period 2
3202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3203 wait_request_state $fid ARCHIVE STARTED
3205 wait_request_state $fid ARCHIVE CANCELED
3207 set_hsm_param active_request_timeout $old_to
3208 set_hsm_param loop_period $old_loop
3212 run_test 251 "Coordinator request timeout"
3215 # the only way to test ondisk conf is to restart MDS ...
3216 echo "Stop coordinator and remove coordinator state at mount"
3219 # clean on disk conf set by default
3220 cdt_clear_mount_state
3221 cdt_check_state stopped
3223 # check cdt still off after umount/remount
3225 cdt_check_state stopped
3227 echo "Set coordinator start at mount, and start coordinator"
3228 cdt_set_mount_state enabled
3231 cdt_check_state enabled
3233 # check cdt still on after umount/remount
3235 cdt_check_state enabled
3237 # we are back to original state (cdt started at mount)
3239 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3242 local ai=$(get_hsm_param default_archive_id)
3243 local new=$((ai + 1))
3245 set_hsm_param default_archive_id $new -P
3247 local res=$(get_hsm_param default_archive_id)
3250 set_hsm_param default_archive_id "" "-P -d"
3252 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3254 run_test 301 "HSM tunnable are persistent"
3257 local ai=$(get_hsm_param default_archive_id)
3258 local new=$((ai + 1))
3263 set_hsm_param default_archive_id $new -P
3267 cdt_check_state enabled
3269 local res=$(get_hsm_param default_archive_id)
3272 set_hsm_param default_archive_id "" "-P -d"
3274 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3276 run_test 302 "HSM tunnable are persistent when CDT is off"
3281 check_and_cleanup_lustre