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:
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16 # skip test cases failed before landing - Jinshan
18 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 31a 34 35 36"
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 201 221 223a 223b 225"
21 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
23 . $LUSTRE/tests/test-framework.sh
25 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
28 MULTIOP=${MULTIOP:-multiop}
29 OPENFILE=${OPENFILE:-openfile}
30 MCREATE=${MCREATE:-mcreate}
31 MOUNT_2=${MOUNT_2:-"yes"}
34 if [[ $MDSCOUNT -ge 2 ]]; then
35 skip_env "Only run with single MDT for now" && exit
38 check_and_setup_lustre
40 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
41 skip_env "Need MDS version at least 2.4.53" && exit
44 # $RUNAS_ID may get set incorrectly somewhere else
45 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
46 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
48 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
53 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
54 # the following associated variables are added:
56 # AGTCOUNT: number of agents
57 # AGTDEV{N}: target HSM mount point (root path of the backend)
58 # agt{N}_HOST: hostname of the agent agt{N}
59 # SINGLEAGT: facet of the single agent
61 # The number of agents is initialized as the number of remote client nodes.
62 # By default, only single copytool is started on a remote client/agent. If there
63 # was no remote client, then the copytool will be started on the local client.
69 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
70 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
72 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
73 if [[ $CLIENTCOUNT -gt 1 ]] &&
74 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
75 skip_env "SHARED_DIRECTORY should be accessible"\
80 for n in $(seq $AGTCOUNT); do
81 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
82 agent=CLIENT$((n + 1))
83 if [[ -z "${!agent}" ]]; then
84 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
87 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
90 export SINGLEAGT=${SINGLEAGT:-agt1}
92 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
93 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
94 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
95 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
98 MDT_PARAM="mdt.$FSNAME-MDT0000"
99 HSM_PARAM="$MDT_PARAM.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
120 search_and_kill_copytool() {
121 local agents=${1:-$(facet_active_host $SINGLEAGT)}
123 echo "Killing existing copytools on $agents"
124 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
128 local facet=${1:-$SINGLEAGT}
129 local lustre_mntpnt=${2:-$MOUNT}
131 local hsm_root=$(copytool_device $facet)
132 local agent=$(facet_active_host $facet)
134 if [[ -z "$arc_id" ]] &&
135 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
136 echo "Wakeup copytool $facet on $agent"
140 if $HSM_ARCHIVE_PURGE; then
141 echo "Purging archive on $agent"
142 do_facet $facet "rm -rf $hsm_root/*"
145 echo "Starting copytool $facet on $agent"
146 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
147 # bandwidth is limited to 1MB/s so the copy time is known and
148 # independent of hardware
149 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
150 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
151 cmd+=" --bandwidth 1 $lustre_mntpnt"
153 # Redirect the standard output and error to a log file which
154 # can be uploaded to Maloo.
155 local prefix=$TESTLOG_PREFIX
156 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
157 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
159 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
160 error "start copytool $facet on $agent failed"
166 local agents=${1:-$(facet_active_host $SINGLEAGT)}
168 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
170 echo "Copytool is stopped on $agents"
174 local agents=${1:-$(facet_active_host $SINGLEAGT)}
176 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
177 echo "Copytool is suspended on $agents"
180 copytool_remove_backend() {
182 local be=$(find $HSM_ARCHIVE -name $fid)
183 echo "Remove from backend: $fid = $be"
184 do_facet $SINGLEAGT rm -f $be
188 do_facet $SINGLEAGT \
189 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
190 --import $1 $2 $MOUNT" ||
191 error "import of $1 to $2 failed"
195 local file=$HSM_ARCHIVE/$1
196 do_facet $SINGLEAGT mkdir -p $(dirname $file)
197 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
198 error "cannot create $file"
202 local file=$HSM_ARCHIVE/$2
203 do_facet $SINGLEAGT mkdir -p $(dirname $file)
204 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
208 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0\
209 changelog_register -n)
210 do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+hsm"
211 $LFS changelog_clear $MDT0 $CL_USER 0
214 changelog_cleanup() {
215 # $LFS changelog $MDT0
216 [[ -n "$CL_USER" ]] || return 0
218 $LFS changelog_clear $MDT0 $CL_USER 0
219 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
223 changelog_get_flags() {
228 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
233 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
241 if [[ "$value" != "" ]]; then
244 do_facet $SINGLEMDS $LCTL set_param $opt -n $HSM_PARAM.$param$value
251 do_facet $SINGLEMDS $LCTL set_param $MDT_PARAM.hsm_control=$cmd
252 wait_result $SINGLEMDS "$LCTL get_param -n $MDT_PARAM.hsm_control"\
253 $target 10 || error "cdt state is not $target"
256 cdt_set_sanity_policy() {
257 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
260 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
261 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
262 CDT_POLICY_HAD_CHANGED=
267 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
268 CDT_POLICY_HAD_CHANGED=true
271 cdt_clear_no_retry() {
272 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NRA
273 CDT_POLICY_HAD_CHANGED=true
276 cdt_set_non_blocking_restore() {
277 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NBR
278 CDT_POLICY_HAD_CHANGED=true
281 cdt_clear_non_blocking_restore() {
282 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
283 CDT_POLICY_HAD_CHANGED=true
286 cdt_clear_mount_state() {
287 do_facet $SINGLEMDS $LCTL set_param -d -P $MDT_PARAM.hsm_control
290 cdt_set_mount_state() {
291 do_facet $SINGLEMDS $LCTL set_param -P $MDT_PARAM.hsm_control=$1
296 wait_result $SINGLEMDS\
297 "$LCTL get_param -n $MDT_PARAM.hsm_control" "$target" 20 ||
298 error "cdt state is not $target"
302 set_test_state disabled disabled
306 set_test_state enabled enabled
310 set_test_state shutdown stopped
314 set_test_state purge enabled
320 cdt_set_sanity_policy
324 local client_count=$1
325 if [[ $CLIENTCOUNT -lt $client_count ]]; then
326 skip "Need $client_count or more clients, have $CLIENTCOUNT"
333 $LFS path2fid $1 | tr -d '[]'
340 if [[ $u == "user" ]]; then
341 local st=$($RUNAS $LFS hsm_state $f)
343 local st=$($LFS hsm_state $f)
347 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
349 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
353 get_hsm_archive_id() {
355 local st=$($LFS hsm_state $f)
356 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
358 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
367 local st=$(get_hsm_flags $f)
368 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
371 check_hsm_flags_user() {
375 local st=$(get_hsm_flags $f user)
376 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
388 if [[ "$3" != 1 ]]; then
392 cp $1 $f || error "cannot copy $1 to $f"
393 path2fid $f || error "cannot get fid on $f"
397 local file2=${1/$DIR/$DIR2}
398 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
399 error "cannot create $file2"
400 path2fid $1 || error "cannot get fid on $1"
403 cleanup_large_files() {
404 local ratio=$(df $MOUNT |awk '{print $5}' |sed 's/%//g' |grep -v Use)
405 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
408 make_large_for_striping() {
409 local file2=${1/$DIR/$DIR2}
410 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
414 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
415 error "cannot create $file2"
416 path2fid $1 || error "cannot get fid on $1"
419 make_large_for_progress() {
420 local file2=${1/$DIR/$DIR2}
424 # big file is large enough, so copy time is > 30s
425 # so copytool make 1 progress
426 # size is not a multiple of 1M to avoid stripe
428 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
429 error "cannot create $file2"
430 path2fid $1 || error "cannot get fid on $1"
433 make_large_for_progress_aligned() {
434 local file2=${1/$DIR/$DIR2}
438 # big file is large enough, so copy time is > 30s
439 # so copytool make 1 progress
440 # size is a multiple of 1M to have stripe
442 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
443 error "cannot create $file2"
444 path2fid $1 || error "cannot get fid on $1"
447 make_large_for_cancel() {
448 local file2=${1/$DIR/$DIR2}
452 # Copy timeout is 100s. 105MB => 105s
453 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
454 error "cannot create $file2"
455 path2fid $1 || error "cannot get fid on $1"
461 wait_update --verbose $(facet_active_host $facet) "$@"
464 wait_request_state() {
469 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
470 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
472 wait_result $SINGLEMDS "$cmd" $state 100 ||
473 error "request on $fid is not $state"
476 get_request_state() {
480 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
481 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
484 get_request_count() {
488 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
489 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
495 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
496 cmd+=" | egrep 'WAITING|STARTED'"
498 wait_result $SINGLEMDS "$cmd" "" $timeout ||
499 error "requests did not complete"
502 wait_for_grace_delay() {
503 local val=$(get_hsm_param grace_delay)
507 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
508 awk '{gsub(/_UUID/,""); print $1}' | head -1)
513 # cleanup from previous bad setup
514 search_and_kill_copytool
516 # for recovery tests, coordinator needs to be started at mount
518 # the lustre conf must be without hsm on (like for sanity.sh)
519 echo "Set HSM on and start"
520 cdt_set_mount_state enabled
521 cdt_check_state enabled
523 echo "Start copytool"
526 echo "Set sanity-hsm HSM policy"
527 cdt_set_sanity_policy
529 # finished requests are quickly removed from list
530 set_hsm_param grace_delay 10
536 local f=$DIR/$tdir/$tfile
540 check_hsm_flags_user $f "0x00000000"
542 $RUNAS $LFS hsm_set --norelease $f ||
543 error "user could not change hsm flags"
544 check_hsm_flags_user $f "0x00000010"
546 $RUNAS $LFS hsm_clear --norelease $f ||
547 error "user could not clear hsm flags"
548 check_hsm_flags_user $f "0x00000000"
550 # User could not change those flags...
551 $RUNAS $LFS hsm_set --exists $f &&
552 error "user should not set this flag"
553 check_hsm_flags_user $f "0x00000000"
556 $LFS hsm_set --exists $f ||
557 error "root could not change hsm flags"
558 check_hsm_flags_user $f "0x00000001"
560 $LFS hsm_clear --exists $f ||
561 error "root could not clear hsm state"
562 check_hsm_flags_user $f "0x00000000"
565 run_test 1 "lfs hsm flags root/non-root access"
569 local f=$DIR/$tdir/$tfile
571 # New files are not dirty
572 check_hsm_flags $f "0x00000000"
574 # For test, we simulate an archived file.
575 $LFS hsm_set --exists $f || error "user could not change hsm flags"
576 check_hsm_flags $f "0x00000001"
578 # chmod do not put the file dirty
579 chmod 600 $f || error "could not chmod test file"
580 check_hsm_flags $f "0x00000001"
582 # chown do not put the file dirty
583 chown $RUNAS_ID $f || error "could not chown test file"
584 check_hsm_flags $f "0x00000001"
586 # truncate put the file dirty
587 $TRUNCATE $f 1 || error "could not truncate test file"
588 check_hsm_flags $f "0x00000003"
590 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
591 check_hsm_flags $f "0x00000001"
593 run_test 2 "Check file dirtyness when doing setattr"
599 # New files are not dirty
601 check_hsm_flags $f "0x00000000"
603 # For test, we simulate an archived file.
604 $LFS hsm_set --exists $f ||
605 error "user could not change hsm flags"
606 check_hsm_flags $f "0x00000001"
608 # Reading a file, does not set dirty
609 cat $f > /dev/null || error "could not read file"
610 check_hsm_flags $f "0x00000001"
612 # Open for write without modifying data, does not set dirty
613 openfile -f O_WRONLY $f || error "could not open test file"
614 check_hsm_flags $f "0x00000001"
616 # Append to a file sets it dirty
617 cp -p /etc/passwd $f.append || error "could not create file"
618 $LFS hsm_set --exists $f.append ||
619 error "user could not change hsm flags"
620 dd if=/etc/passwd of=$f.append bs=1 count=3\
621 conv=notrunc oflag=append status=noxfer ||
622 error "could not append to test file"
623 check_hsm_flags $f.append "0x00000003"
625 # Modify a file sets it dirty
626 cp -p /etc/passwd $f.modify || error "could not create file"
627 $LFS hsm_set --exists $f.modify ||
628 error "user could not change hsm flags"
629 dd if=/dev/zero of=$f.modify bs=1 count=3\
630 conv=notrunc status=noxfer ||
631 error "could not modify test file"
632 check_hsm_flags $f.modify "0x00000003"
634 # Open O_TRUNC sets dirty
635 cp -p /etc/passwd $f.trunc || error "could not create file"
636 $LFS hsm_set --exists $f.trunc ||
637 error "user could not change hsm flags"
638 cp /etc/group $f.trunc || error "could not override a file"
639 check_hsm_flags $f.trunc "0x00000003"
641 # Mmapped a file sets dirty
642 cp -p /etc/passwd $f.mmap || error "could not create file"
643 $LFS hsm_set --exists $f.mmap ||
644 error "user could not change hsm flags"
645 multiop $f.mmap OSMWUc || error "could not mmap a file"
646 check_hsm_flags $f.mmap "0x00000003"
648 run_test 3 "Check file dirtyness when opening for write"
652 local f=$DIR/$tdir/$tfile
653 local fid=$(make_small $f)
656 local st=$(get_request_state $fid CANCEL)
657 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
659 run_test 4 "Useless cancel must not be registered"
662 # test needs a running copytool
666 local f=$DIR/$tdir/$tfile
667 local fid=$(copy_file /etc/passwd $f)
669 wait_request_state $fid ARCHIVE SUCCEED
671 check_hsm_flags $f "0x00000009"
675 run_test 8 "Test default archive number"
679 local f=$DIR/$tdir/$tfile
680 local fid=$(copy_file /etc/passwd $f)
681 # we do not use the default one to be sure
682 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
684 copytool_setup $SINGLEAGT $MOUNT $new_an
685 $LFS hsm_archive --archive $new_an $f
686 wait_request_state $fid ARCHIVE SUCCEED
688 check_hsm_flags $f "0x00000009"
692 run_test 9 "Use of explict archive number, with dedicated copytool"
695 needclients 3 || return 0
701 copytool_cleanup $(comma_list $(agts_nodes))
703 # start all of the copytools
704 for n in $(seq $AGTCOUNT); do
708 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
711 for n in $(seq $AGTCOUNT); do
712 file=$DIR/$tdir/$tfile.$n
713 fid=$(make_small $file)
715 $LFS hsm_archive $file || error "could not archive file $file"
716 wait_request_state $fid ARCHIVE SUCCEED
717 check_hsm_flags $file "0x00000009"
721 copytool_cleanup $(comma_list $(agts_nodes))
723 run_test 9a "Multiple remote agents"
726 # test needs a running copytool
729 mkdir -p $DIR/$tdir/d1
730 local f=$DIR/$tdir/$tfile
731 local fid=$(copy_file /etc/hosts $f)
732 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
733 error "hsm_archive failed"
734 wait_request_state $fid ARCHIVE SUCCEED
736 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
737 error "fid $fid not in archive $HSM_ARCHIVE"
738 echo "Verifying content"
739 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
740 echo "Verifying hsm state "
741 check_hsm_flags $f "0x00000009"
743 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
744 local st=$(get_hsm_archive_id $f)
745 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
746 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
751 run_test 10a "Archive a file"
754 # test needs a running copytool
758 local f=$DIR/$tdir/$tfile
759 local fid=$(copy_file /etc/hosts $f)
760 $LFS hsm_archive $f || error "archive request failed"
761 wait_request_state $fid ARCHIVE SUCCEED
763 $LFS hsm_archive $f || error "archive of non dirty file failed"
764 local cnt=$(get_request_count $fid ARCHIVE)
765 [[ "$cnt" == "1" ]] ||
766 error "archive of non dirty file must not make a request"
770 run_test 10b "Archive of non dirty file must work without doing request"
773 # test needs a running copytool
777 local f=$DIR/$tdir/$tfile
778 local fid=$(copy_file /etc/hosts $f)
779 $LFS hsm_set --noarchive $f
780 $LFS hsm_archive $f && error "archive a noarchive file must fail"
784 run_test 10c "Check forbidden archive"
787 # test needs a running copytool
791 local f=$DIR/$tdir/$tfile
792 local fid=$(copy_file /etc/hosts $f)
793 $LFS hsm_archive $f || error "cannot archive $f"
794 wait_request_state $fid ARCHIVE SUCCEED
796 local ar=$(get_hsm_archive_id $f)
797 local dflt=$(get_hsm_param default_archive_id)
798 [[ $ar == $dflt ]] ||
799 error "archived file is not on default archive: $ar != $dflt"
803 run_test 10d "Archive a file on the default archive id"
807 copy2archive /etc/hosts $tdir/$tfile
808 local f=$DIR/$tdir/$tfile
810 import_file $tdir/$tfile $f
811 echo -n "Verifying released state: "
812 check_hsm_flags $f "0x0000000d"
814 local LSZ=$(stat -c "%s" $f)
815 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
817 echo "Verifying imported size $LSZ=$ASZ"
818 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
819 echo -n "Verifying released pattern: "
820 local PTRN=$($GETSTRIPE -L $f)
822 [[ $PTRN == 80000001 ]] || error "Is not released"
823 local fid=$(path2fid $f)
824 echo "Verifying new fid $fid in archive"
826 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
827 error "fid $fid not in archive $HSM_ARCHIVE"
829 run_test 11 "Import a file"
832 # test needs a running copytool
836 copy2archive /etc/hosts $tdir/$tfile
838 local f=$DIR/$tdir/$tfile
839 import_file $tdir/$tfile $f
840 local f=$DIR2/$tdir/$tfile
841 echo "Verifying released state: "
842 check_hsm_flags $f "0x0000000d"
844 local fid=$(path2fid $f)
846 wait_request_state $fid RESTORE SUCCEED
848 echo "Verifying file state: "
849 check_hsm_flags $f "0x00000009"
851 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
853 [[ $? -eq 0 ]] || error "Restored file differs"
857 run_test 12a "Restore an imported file explicitly"
860 # test needs a running copytool
864 copy2archive /etc/hosts $tdir/$tfile
866 local f=$DIR/$tdir/$tfile
867 import_file $tdir/$tfile $f
868 echo "Verifying released state: "
869 check_hsm_flags $f "0x0000000d"
871 cat $f > /dev/null || error "File read failed"
873 echo "Verifying file state after restore: "
874 check_hsm_flags $f "0x00000009"
876 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
878 [[ $? -eq 0 ]] || error "Restored file differs"
882 run_test 12b "Restore an imported file implicitly"
885 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
887 # test needs a running copytool
891 local f=$DIR/$tdir/$tfile
892 $LFS setstripe -c 2 $f
893 local fid=$(make_large_for_striping $f)
894 local FILE_CRC=$(md5sum $f)
896 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
897 wait_request_state $fid ARCHIVE SUCCEED
898 $LFS hsm_release $f || error "release $f failed"
900 echo "$FILE_CRC" | md5sum -c
902 [[ $? -eq 0 ]] || error "Restored file differs"
906 run_test 12c "Restore a file with stripe of 2"
909 # test needs a running copytool
914 local f=$DIR/$tdir/$tfile
915 local fid=$(copy_file /etc/hosts $f)
916 $LFS hsm_restore $f || error "restore of non archived file failed"
917 local cnt=$(get_request_count $fid RESTORE)
918 [[ "$cnt" == "0" ]] ||
919 error "restore non archived must not make a request"
920 $LFS hsm_archive $f ||
921 error "archive request failed"
922 wait_request_state $fid ARCHIVE SUCCEED
923 $LFS hsm_restore $f ||
924 error "restore of non released file failed"
925 local cnt=$(get_request_count $fid RESTORE)
926 [[ "$cnt" == "0" ]] ||
927 error "restore a non dirty file must not make a request"
931 run_test 12d "Restore of a non archived, non released file must work"\
932 " without doing request"
935 # test needs a running copytool
938 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
939 local f=$DIR/$tdir/$tfile
940 local fid=$(copy_file /etc/hosts $f)
941 $LFS hsm_archive $f || error "archive request failed"
942 wait_request_state $fid ARCHIVE SUCCEED
949 $LFS hsm_restore $f && error "restore a dirty file must fail"
953 run_test 12e "Check forbidden restore"
956 # test needs a running copytool
960 local f=$DIR/$tdir/$tfile
961 local fid=$(copy_file /etc/hosts $f)
963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
964 wait_request_state $fid ARCHIVE SUCCEED
965 $LFS hsm_release $f || error "release of $f failed"
967 wait_request_state $fid RESTORE SUCCEED
969 echo -n "Verifying file state: "
970 check_hsm_flags $f "0x00000009"
972 diff -q /etc/hosts $f
974 [[ $? -eq 0 ]] || error "Restored file differs"
978 run_test 12f "Restore a released file explicitly"
981 # test needs a running copytool
985 local f=$DIR/$tdir/$tfile
986 local fid=$(copy_file /etc/hosts $f)
988 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
989 wait_request_state $fid ARCHIVE SUCCEED
990 $LFS hsm_release $f || error "release of $f failed"
992 diff -q /etc/hosts $f
995 # we check we had a restore done
996 wait_request_state $fid RESTORE SUCCEED
998 [[ $st -eq 0 ]] || error "Restored file differs"
1002 run_test 12g "Restore a released file implicitly"
1005 needclients 2 || return 0
1007 # test needs a running copytool
1011 local f=$DIR/$tdir/$tfile
1012 local fid=$(copy_file /etc/hosts $f)
1014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1015 wait_request_state $fid ARCHIVE SUCCEED
1016 $LFS hsm_release $f || error "release of $f failed"
1018 do_node $CLIENT2 diff -q /etc/hosts $f
1021 # we check we had a restore done
1022 wait_request_state $fid RESTORE SUCCEED
1024 [[ $st -eq 0 ]] || error "Restored file differs"
1028 run_test 12h "Restore a released file implicitly from a second node"
1031 # test needs a running copytool
1035 local f=$DIR/$tdir/$tfile
1036 local fid=$(copy_file /etc/passwd $f)
1037 $LFS hsm_archive $f || error "archive of $f failed"
1038 wait_request_state $fid ARCHIVE SUCCEED
1040 $LFS hsm_release $f || error "release of $f failed"
1044 [[ $? -eq 0 ]] || error "Restored file differs"
1048 run_test 12m "Archive/release/implicit restore"
1051 # test needs a running copytool
1055 copy2archive /etc/hosts $tdir/$tfile
1057 local f=$DIR/$tdir/$tfile
1058 import_file $tdir/$tfile $f
1060 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1061 error "Restored file differs"
1063 $LFS hsm_release $f || error "release of $f failed"
1067 run_test 12n "Import/implicit restore/release"
1070 # test needs a running copytool
1073 local ARC_SUBDIR="import.orig"
1077 # populate directory to be imported
1078 for d in $(seq 1 10); do
1079 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1080 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1081 for f in $(seq 1 10); do
1082 CURR_FILE="$CURR_DIR/$tfile.$f"
1083 # write file-specific data
1084 do_facet $SINGLEAGT \
1085 echo "d=$d, f=$f, dir=$CURR_DIR, "\
1086 "file=$CURR_FILE" > $CURR_FILE
1090 import_file "$ARC_SUBDIR" $DIR/$tdir
1091 # diff lustre content and origin (triggers file restoration)
1092 # there must be 10x10 identical files, and no difference
1093 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1094 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1095 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1096 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1098 [ $cnt_diff -eq 0 ] ||
1099 error "$cnt_diff imported files differ from read data"
1100 [ $cnt_ok -eq 100 ] ||
1101 error "not enough identical files ($cnt_ok != 100)"
1105 run_test 13 "Recursively import and restore a directory"
1108 # test needs a running copytool
1113 local f=$DIR/$tdir/$tfile
1114 local fid=$(make_small $f)
1115 local sum=$(md5sum $f | awk '{print $1}')
1116 $LFS hsm_archive $f || error "could not archive file"
1117 wait_request_state $fid ARCHIVE SUCCEED
1121 # create released file (simulate llapi_hsm_import call)
1123 local fid2=$(path2fid $f)
1124 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1125 $LFS hsm_release $f || error "could not release file"
1127 # rebind the archive to the newly created file
1128 echo "rebind $fid to $fid2"
1130 do_facet $SINGLEAGT \
1131 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1132 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1134 # restore file and compare md5sum
1135 local sum2=$(md5sum $f | awk '{print $1}')
1137 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1141 run_test 14 "Rebind archived file to a new fid"
1144 # test needs a running copytool
1149 local f=$DIR/$tdir/$tfile
1151 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1155 for i in $(seq 1 $count); do
1156 fids[$i]=$(make_small $f.$i)
1157 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1158 $LFS hsm_archive $f.$i || error "could not archive file"
1160 wait_all_done $(($count*60))
1164 for i in $(seq 1 $count); do
1167 local fid2=$(path2fid $f.$i)
1168 # add the rebind operation to the list
1169 echo ${fids[$i]} $fid2 >> $tmpfile
1171 # set it released (simulate llapi_hsm_import call)
1172 $LFS hsm_set --archived --exists $f.$i ||
1173 error "could not force hsm flags"
1174 $LFS hsm_release $f.$i || error "could not release file"
1176 nl=$(wc -l < $tmpfile)
1177 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1179 echo "rebind list of files"
1180 do_facet $SINGLEAGT \
1181 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1182 --rebind $tmpfile $DIR" || error "could not rebind file list"
1184 # restore files and compare md5sum
1185 for i in $(seq 1 $count); do
1186 local sum2=$(md5sum $f.$i | awk '{print $1}')
1187 [[ $sum2 == ${sums[$i]} ]] ||
1188 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1194 run_test 15 "Rebind a list of files"
1197 # test needs a running copytool
1201 # create a known size file so we can verify transfer speed
1204 dd if=/dev/zero of=$ref bs=1M count=20
1207 local f=$DIR/$tdir/$tfile
1208 local fid=$(copy_file $ref $f)
1210 local start=$(date +%s)
1212 wait_request_state $fid ARCHIVE SUCCEED
1213 local end=$(date +%s)
1214 local duration=$((end - start))
1216 [[ $duration -ge $goal ]] ||
1217 error "Transfer is too fast $duration < $goal"
1221 run_test 16 "Test CT bandwith control option"
1226 local f=$DIR/$tdir/$tfile
1227 touch $f || error "touch $f failed"
1229 # Could not release a non-archived file
1230 $LFS hsm_release $f && error "release should not succeed"
1232 # For following tests, we must test them with HS_ARCHIVED set
1233 $LFS hsm_set --exists --archived $f || error "could not add flag"
1235 # Could not release a file if no-release is set
1236 $LFS hsm_set --norelease $f || error "could not add flag"
1237 $LFS hsm_release $f && error "release should not succeed"
1238 $LFS hsm_clear --norelease $f || error "could not remove flag"
1240 # Could not release a file if lost
1241 $LFS hsm_set --lost $f || error "could not add flag"
1242 $LFS hsm_release $f && error "release should not succeed"
1243 $LFS hsm_clear --lost $f || error "could not remove flag"
1245 # Could not release a file if dirty
1246 $LFS hsm_set --dirty $f || error "could not add flag"
1247 $LFS hsm_release $f && error "release should not succeed"
1248 $LFS hsm_clear --dirty $f || error "could not remove flag"
1250 run_test 20 "Release is not permitted"
1253 # test needs a running copytool
1257 local f=$DIR/$tdir/test_release
1259 # Create a file and check its states
1260 local fid=$(make_small $f)
1261 check_hsm_flags $f "0x00000000"
1263 $LFS hsm_archive $f || error "could not archive file"
1264 wait_request_state $fid ARCHIVE SUCCEED
1266 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1267 local sz=$(stat -c "%s" $f)
1268 [ $sz -ne "0" ] || error "file size should not be zero"
1270 # Release and check states
1271 $LFS hsm_release $f || error "could not release file"
1272 check_hsm_flags $f "0x0000000d"
1274 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1275 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1277 # Check we can release an file without stripe info
1281 check_hsm_flags $f "0x00000000"
1282 $LFS hsm_archive $f || error "could not archive file"
1283 wait_request_state $fid ARCHIVE SUCCEED
1285 # Release and check states
1286 $LFS hsm_release $f || error "could not release file"
1287 check_hsm_flags $f "0x0000000d"
1289 # Release again a file that is already released is OK
1290 $LFS hsm_release $f || fail "second release should succeed"
1291 check_hsm_flags $f "0x0000000d"
1295 run_test 21 "Simple release tests"
1298 # test needs a running copytool
1303 local f=$DIR/$tdir/test_release
1304 local swap=$DIR/$tdir/test_swap
1306 # Create a file and check its states
1307 local fid=$(make_small $f)
1308 check_hsm_flags $f "0x00000000"
1310 $LFS hsm_archive $f || error "could not archive file"
1311 wait_request_state $fid ARCHIVE SUCCEED
1313 # Release and check states
1314 $LFS hsm_release $f || error "could not release file"
1315 check_hsm_flags $f "0x0000000d"
1318 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1323 run_test 22 "Could not swap a release file"
1326 # test needs a running copytool
1331 local f=$DIR/$tdir/test_mtime
1333 # Create a file and check its states
1334 local fid=$(make_small $f)
1335 check_hsm_flags $f "0x00000000"
1337 $LFS hsm_archive $f || error "could not archive file"
1338 wait_request_state $fid ARCHIVE SUCCEED
1340 # Set modification time in the past
1341 touch -m -a -d @978261179 $f
1343 # Release and check states
1344 $LFS hsm_release $f || error "could not release file"
1345 check_hsm_flags $f "0x0000000d"
1347 local MTIME=$(stat -c "%Y" $f)
1348 local ATIME=$(stat -c "%X" $f)
1349 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1350 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1354 run_test 23 "Release does not change a/mtime (utime)"
1357 local file=$DIR/$tdir/$tfile
1366 # test needs a running copytool
1371 fid=$(make_small $file)
1373 # Create a file and check its states
1374 check_hsm_flags $file "0x00000000"
1376 # Ensure atime is less than mtime and ctime.
1380 atime0=$(stat -c "%X" $file)
1381 mtime0=$(stat -c "%Y" $file)
1382 ctime0=$(stat -c "%Z" $file)
1384 [ $atime0 -lt $mtime0 ] ||
1385 error "atime $atime0 is not less than mtime $mtime0"
1387 [ $atime0 -lt $ctime0 ] ||
1388 error "atime $atime0 is not less than ctime $ctime0"
1390 # Archive should not change any timestamps.
1391 $LFS hsm_archive $file || error "cannot archive '$file'"
1392 wait_request_state $fid ARCHIVE SUCCEED
1394 atime1=$(stat -c "%X" $file)
1395 mtime1=$(stat -c "%Y" $file)
1396 ctime1=$(stat -c "%Z" $file)
1398 [ $atime0 -eq $atime1 ] ||
1399 error "archive changed atime from $atime0 to $atime1"
1401 [ $mtime0 -eq $mtime1 ] ||
1402 error "archive changed mtime from $mtime0 to $mtime1"
1404 [ $ctime0 -eq $ctime1 ] ||
1405 error "archive changed ctime from $ctime0 to $ctime1"
1407 # Release should not change any timestamps.
1408 $LFS hsm_release $file || error "cannot release '$file'"
1409 check_hsm_flags $file "0x0000000d"
1411 atime1=$(stat -c "%X" $file)
1412 mtime1=$(stat -c "%Y" $file)
1413 ctime1=$(stat -c "%Z" $file)
1415 [ $atime0 -eq $atime1 ] ||
1416 error "release changed atime from $atime0 to $atime1"
1418 [ $mtime0 -eq $mtime1 ] ||
1419 error "release changed mtime from $mtime0 to $mtime1"
1421 [ $ctime0 -eq $ctime1 ] ||
1422 error "release changed ctime from $ctime0 to $ctime1"
1424 # Restore should not change atime or mtime and should not
1426 $LFS hsm_restore $file
1427 wait_request_state $fid RESTORE SUCCEED
1429 atime1=$(stat -c "%X" $file)
1430 mtime1=$(stat -c "%Y" $file)
1431 ctime1=$(stat -c "%Z" $file)
1433 [ $atime0 -eq $atime1 ] ||
1434 error "restore changed atime from $atime0 to $atime1"
1436 [ $mtime0 -eq $mtime1 ] ||
1437 error "restore changed mtime from $mtime0 to $mtime1"
1439 [ $ctime0 -le $ctime1 ] ||
1440 error "restore changed ctime from $ctime0 to $ctime1"
1444 # Once more, after unmount and mount.
1445 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1446 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1448 atime1=$(stat -c "%X" $file)
1449 mtime1=$(stat -c "%Y" $file)
1450 ctime1=$(stat -c "%Z" $file)
1452 [ $atime0 -eq $atime1 ] ||
1453 error "remount changed atime from $atime0 to $atime1"
1455 [ $mtime0 -eq $mtime1 ] ||
1456 error "remount changed mtime from $mtime0 to $mtime1"
1458 [ $ctime0 -le $ctime1 ] ||
1459 error "remount changed ctime from $ctime0 to $ctime1"
1461 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1464 local file=$DIR/$tdir/$tfile
1470 # Test needs a running copytool.
1474 # Check that root can do HSM actions on a ordinary user's file.
1476 fid=$(make_small $file)
1477 sum0=$(md5sum $file)
1479 chown $RUNAS_ID:$RUNAS_GID $file ||
1480 error "cannot chown '$file' to '$RUNAS_ID'"
1482 chmod ugo-w $DIR/$tdir ||
1483 error "cannot chmod '$DIR/$tdir'"
1485 $LFS hsm_archive $file
1486 wait_request_state $fid ARCHIVE SUCCEED
1488 $LFS hsm_release $file
1489 check_hsm_flags $file "0x0000000d"
1491 $LFS hsm_restore $file
1492 wait_request_state $fid RESTORE SUCCEED
1494 # Check that ordinary user can get HSM state.
1495 $RUNAS $LFS hsm_state $file ||
1496 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1498 $LFS hsm_release $file
1499 check_hsm_flags $file "0x0000000d"
1501 # Check that ordinary user can accessed released file.
1502 sum1=$($RUNAS md5sum $file) ||
1503 error "user '$RUNAS_ID' cannot read '$file'"
1505 [ "$sum0" == "$sum1" ] ||
1506 error "md5sum mismatch for '$file'"
1510 run_test 24b "root can archive, release, and restore user files"
1512 cleanup_test_24c() {
1514 set_hsm_param user_request_mask RESTORE
1515 set_hsm_param group_request_mask RESTORE
1516 set_hsm_param other_request_mask RESTORE
1520 local file=$DIR/$tdir/$tfile
1521 local action=archive
1526 # test needs a running copytool
1531 # Save the default masks and check that cleanup_24c will
1532 # restore the request masks correctly.
1533 user_save=$(get_hsm_param user_request_mask)
1534 group_save=$(get_hsm_param group_request_mask)
1535 other_save=$(get_hsm_param other_request_mask)
1537 [ "$user_save" == RESTORE ] ||
1538 error "user_request_mask is '$user_save' expected 'RESTORE'"
1539 [ "$group_save" == RESTORE ] ||
1540 error "group_request_mask is '$group_save' expected 'RESTORE'"
1541 [ "$other_save" == RESTORE ] ||
1542 error "other_request_mask is '$other_save' expected 'RESTORE'"
1544 trap cleanup_test_24c EXIT
1549 chown $RUNAS_ID:nobody $file ||
1550 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1552 set_hsm_param user_request_mask ""
1553 $RUNAS $LFS hsm_$action $file &&
1554 error "$action by user should fail"
1556 set_hsm_param user_request_mask $action
1557 $RUNAS $LFS hsm_$action $file ||
1558 error "$action by user should succeed"
1563 chown nobody:$RUNAS_GID $file ||
1564 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1566 set_hsm_param group_request_mask ""
1567 $RUNAS $LFS hsm_$action $file &&
1568 error "$action by group should fail"
1570 set_hsm_param group_request_mask $action
1571 $RUNAS $LFS hsm_$action $file ||
1572 error "$action by group should succeed"
1577 chown nobody:nobody $file ||
1578 error "cannot chown '$file' to 'nobody:nobody'"
1580 set_hsm_param other_request_mask ""
1581 $RUNAS $LFS hsm_$action $file &&
1582 error "$action by other should fail"
1584 set_hsm_param other_request_mask $action
1585 $RUNAS $LFS hsm_$action $file ||
1586 error "$action by other should succeed"
1591 run_test 24c "check that user,group,other request masks work"
1593 cleanup_test_24d() {
1595 mount -o remount,rw $MOUNT2
1599 local file1=$DIR/$tdir/$tfile
1600 local file2=$DIR2/$tdir/$tfile
1608 fid1=$(make_small $file1)
1610 trap cleanup_test_24d EXIT
1612 mount -o remount,ro $MOUNT2
1614 fid2=$(path2fid $file2)
1615 [ "$fid1" == "$fid2" ] ||
1616 error "FID mismatch '$fid1' != '$fid2'"
1618 $LFS hsm_archive $file2 &&
1619 error "archive should fail on read-only mount"
1620 check_hsm_flags $file1 "0x00000000"
1622 $LFS hsm_archive $file1
1623 wait_request_state $fid1 ARCHIVE SUCCEED
1625 $LFS hsm_release $file1
1626 $LFS hsm_restore $file2
1627 wait_request_state $fid1 RESTORE SUCCEED
1629 $LFS hsm_release $file1 || error "cannot release '$file1'"
1630 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1632 $LFS hsm_release $file2 &&
1633 error "release should fail on read-only mount"
1638 run_test 24d "check that read-only mounts are respected"
1641 # test needs a running copytool
1645 copy2archive /etc/hosts $tdir/$tfile
1647 local f=$DIR/$tdir/$tfile
1649 import_file $tdir/$tfile $f
1651 $LFS hsm_set --lost $f
1656 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1660 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1661 " (Operation not permitted)"
1664 # test needs a running copytool
1669 local f=$DIR/$tdir/$tfile
1670 local fid=$(copy_file /etc/passwd $f)
1672 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1673 wait_request_state $fid ARCHIVE SUCCEED
1676 $LFS hsm_set --lost $f
1680 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1684 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1685 " (Operation not permitted)"
1688 # test needs a running copytool
1692 local f=$DIR/$tdir/$tfile
1693 local fid=$(make_large_for_progress $f)
1694 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1695 wait_request_state $fid ARCHIVE SUCCEED
1698 wait_request_state $fid REMOVE SUCCEED
1700 check_hsm_flags $f "0x00000000"
1704 run_test 26 "Remove the archive of a valid file"
1707 # test needs a running copytool
1711 make_archive $tdir/$tfile
1712 local f=$DIR/$tdir/$tfile
1713 import_file $tdir/$tfile $f
1714 local fid=$(path2fid $f)
1718 [[ $? != 0 ]] || error "Remove of a released file should fail"
1722 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1725 # test needs a running copytool
1729 local f=$DIR/$tdir/$tfile
1730 local fid=$(make_large_for_progress $f)
1731 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1732 wait_request_state $fid ARCHIVE SUCCEED
1737 [[ $? != 0 ]] || error "Remove of a released file should fail"
1741 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1744 # test needs a running copytool
1748 local f=$DIR/$tdir/$tfile
1749 local fid=$(make_large_for_progress $f)
1750 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1751 wait_request_state $fid ARCHIVE SUCCEED
1760 wait_request_state $fid REMOVE SUCCEED
1764 run_test 28 "Concurrent archive/file remove"
1767 # restore at exec cannot work on agent node (because of Linux kernel
1768 # protection of executables)
1769 needclients 2 || return 0
1771 # test needs a running copytool
1775 copy2archive /bin/true $tdir/$tfile
1777 local f=$DIR/$tdir/true
1778 import_file $tdir/$tfile $f
1780 local fid=$(path2fid $f)
1782 # set no retry action mode
1788 # remove no try action mode
1792 [[ $st == 0 ]] || error "Failed to exec a released file"
1796 run_test 30a "Restore at exec (import case)"
1799 # restore at exec cannot work on agent node (because of Linux kernel
1800 # protection of executables)
1801 needclients 2 || return 0
1803 # test needs a running copytool
1807 local f=$DIR/$tdir/true
1808 local fid=$(copy_file /bin/true $f)
1810 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1811 wait_request_state $fid ARCHIVE SUCCEED
1814 # set no retry action mode
1820 # remove no try action mode
1824 [[ $st == 0 ]] || error "Failed to exec a released file"
1828 run_test 30b "Restore at exec (release case)"
1830 restore_and_check_size() {
1833 local s=$(stat -c "%s" $f)
1835 local st=$(get_hsm_flags $f)
1839 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1841 n=$(stat -c "%s" $f)
1842 # we echo in both cases to show stat is not
1844 if [[ $n != $s ]]; then
1845 echo "size seen is $n != $s"
1848 echo "size seen is right: $n == $s"
1850 st=$(get_hsm_flags $f)
1854 if [[ $cpt -lt 10 ]]; then
1855 echo " restore is too long"
1859 wait_request_state $fid RESTORE SUCCEED
1864 # test needs a running copytool
1869 make_archive $tdir/$tfile
1870 local f=$DIR/$tdir/$tfile
1871 import_file $tdir/$tfile $f
1872 local fid=$($LFS path2fid $f)
1873 HSM_ARCHIVE_PURGE=false copytool_setup
1875 restore_and_check_size $f $fid
1878 [[ $err -eq 0 ]] || error "File size changed during restore"
1882 run_test 31a "Import a large file and check size during restore"
1886 # test needs a running copytool
1891 local f=$DIR/$tdir/$tfile
1892 local fid=$(make_large_for_progress $f)
1893 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1894 wait_request_state $fid ARCHIVE SUCCEED
1897 restore_and_check_size $f $fid
1900 [[ $err -eq 0 ]] || error "File size changed during restore"
1904 run_test 31b "Restore a large unaligned file and check size during restore"
1907 # test needs a running copytool
1912 local f=$DIR/$tdir/$tfile
1913 local fid=$(make_large_for_progress_aligned $f)
1914 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1915 wait_request_state $fid ARCHIVE SUCCEED
1918 restore_and_check_size $f $fid
1921 [[ $err -eq 0 ]] || error "File size changed during restore"
1925 run_test 31c "Restore a large aligned file and check size during restore"
1928 # test needs a running copytool
1933 local f=$DIR/$tdir/$tfile
1934 local fid=$(make_large_for_progress $f)
1935 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1936 wait_request_state $fid ARCHIVE SUCCEED
1939 md5sum $f >/dev/null &
1941 wait_request_state $fid RESTORE STARTED
1946 # Check restore trigger process was killed
1947 local killed=$(ps -o pid,comm hp $pid >/dev/null)
1951 wait_request_state $fid RESTORE CANCELED
1952 wait_request_state $fid CANCEL SUCCEED
1955 error "Cannot kill process waiting for restore ($killed)"
1959 run_test 33 "Kill a restore waiting process"
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
1977 rm $f || error "rm $f failed"
1978 # rm must not block during restore
1979 wait_request_state $fid RESTORE STARTED
1981 wait_request_state $fid RESTORE SUCCEED
1982 # check md5sum pgm finished
1983 local there=$(ps -o pid,comm hp $pid >/dev/null)
1984 [[ -z $there ]] || error "Restore initiator does not exit"
1986 local rc=$(wait $pid)
1987 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1991 run_test 34 "Remove file during restore"
1994 # test needs a running copytool
1999 local f=$DIR/$tdir/$tfile
2000 local f1=$DIR/$tdir/$tfile-1
2001 local fid=$(make_large_for_progress $f)
2002 local fid1=$(copy_file /etc/passwd $f1)
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 mv $f1 $f || error "mv $f1 $f failed"
2012 # mv 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"
2024 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2028 run_test 35 "Overwrite file during restore"
2031 # test needs a running copytool
2036 local f=$DIR/$tdir/$tfile
2037 local fid=$(make_large_for_progress $f)
2038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2039 wait_request_state $fid ARCHIVE SUCCEED
2042 md5sum $f >/dev/null &
2044 wait_request_state $fid RESTORE STARTED
2047 # rm must not block during restore
2048 wait_request_state $fid RESTORE STARTED
2050 wait_request_state $fid RESTORE SUCCEED
2051 # check md5sum pgm finished
2052 local there=$(ps -o pid,comm hp $pid >/dev/null)
2054 error "Restore initiator does not exit"
2056 local rc=$(wait $pid)
2058 error "Restore initiator failed with $rc"
2062 run_test 36 "Move file during restore"
2069 for n in $(seq 1 $count); do
2070 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2072 echo "$count archive requests submitted"
2076 local stream_count=4
2077 local file_count=100
2079 local f=$DIR/$tdir/$tfile
2084 for i in $(seq 1 $file_count); do
2085 for p in $(seq 1 $stream_count); do
2086 fid=$(copy_file /etc/hosts $f.$p.$i)
2090 # to be sure wait_all_done will not be mislead by previous tests
2092 wait_for_grace_delay
2094 # start archive streams in background (archive files in parallel)
2095 for p in $(seq 1 $stream_count); do
2096 multi_archive $f.$p $file_count &
2099 echo -n "Wait for all requests being enqueued..."
2105 run_test 40 "Parallel archive requests"
2108 # test needs a running copytool
2112 local f=$DIR/$tdir/$tfile
2113 local fid=$(copy_file /etc/motd $f 1)
2115 $LFS hsm_archive $f || error "could not archive file"
2116 wait_request_state $fid ARCHIVE SUCCEED
2117 check_hsm_flags $f "0x00000009"
2119 multiop_bg_pause $f O_c || error "multiop failed"
2123 client_up || client_up || true
2125 kill -USR1 $MULTIPID
2126 wait $MULTIPID || error "multiop close failed"
2128 check_hsm_flags $f "0x0000000b"
2132 run_test 52 "Opened for write file on an evicted client should be set dirty"
2135 # test needs a running copytool
2139 local f=$DIR/$tdir/$tfile
2140 local fid=$(copy_file /etc/motd $f 1)
2142 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2143 error "could not archive file"
2144 wait_request_state $fid ARCHIVE SUCCEED
2145 check_hsm_flags $f "0x00000009"
2147 multiop_bg_pause $f o_c || error "multiop failed"
2151 client_up || client_up || true
2153 kill -USR1 $MULTIPID
2154 wait $MULTIPID || error "multiop close failed"
2156 check_hsm_flags $f "0x00000009"
2160 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2163 # test needs a running copytool
2167 local f=$DIR/$tdir/$tfile
2168 local fid=$(make_small $f)
2170 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2171 error "could not archive file"
2172 wait_request_state $fid ARCHIVE STARTED
2174 check_hsm_flags $f "0x00000001"
2176 # Avoid coordinator resending this request as soon it has failed.
2181 wait_request_state $fid ARCHIVE FAILED
2183 check_hsm_flags $f "0x00000003"
2188 run_test 54 "Write during an archive cancels it"
2191 # test needs a running copytool
2195 local f=$DIR/$tdir/$tfile
2196 local fid=$(make_small $f)
2198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2199 error "could not archive file"
2200 wait_request_state $fid ARCHIVE STARTED
2202 check_hsm_flags $f "0x00000001"
2204 # Avoid coordinator resending this request as soon it has failed.
2207 $TRUNCATE $f 1024 || error "truncate failed"
2209 wait_request_state $fid ARCHIVE FAILED
2211 check_hsm_flags $f "0x00000003"
2216 run_test 55 "Truncate during an archive cancels it"
2219 # test needs a running copytool
2223 local f=$DIR/$tdir/$tfile
2224 local fid=$(make_large_for_progress $f)
2226 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2227 error "could not archive file"
2228 wait_request_state $fid ARCHIVE STARTED
2230 check_hsm_flags $f "0x00000001"
2232 # Change metadata and sync to be sure we are not changing only
2237 wait_request_state $fid ARCHIVE SUCCEED
2239 check_hsm_flags $f "0x00000009"
2243 run_test 56 "Setattr during an archive is ok"
2246 # Need one client for I/O, one for request
2247 needclients 2 || return 0
2249 # test needs a running copytool
2253 local f=$DIR/$tdir/test_archive_remote
2254 # Create a file on a remote node
2255 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2256 "count=2 conv=fsync"
2259 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2260 error "hsm_archive failed"
2261 local fid=$(path2fid $f)
2262 wait_request_state $fid ARCHIVE SUCCEED
2264 # Release and implicit restore it
2265 do_node $CLIENT2 "$LFS hsm_release $f" ||
2266 error "hsm_release failed"
2267 do_node $CLIENT2 "md5sum $f" ||
2268 error "hsm_restore failed"
2270 wait_request_state $fid RESTORE SUCCEED
2274 run_test 57 "Archive a file with dirty cache on another node"
2276 truncate_released_file() {
2280 local sz=$(stat -c %s $src_file)
2281 local f=$DIR/$tdir/$tfile
2282 local fid=$(copy_file $1 $f)
2286 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2287 error "could not archive file"
2288 wait_request_state $fid ARCHIVE SUCCEED
2290 $LFS hsm_release $f || error "could not release file"
2292 $TRUNCATE $f $trunc_to || error "truncate failed"
2295 local sz1=$(stat -c %s $f)
2296 [[ $sz1 == $trunc_to ]] ||
2297 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2300 check_hsm_flags $f "0x0000000b"
2302 local state=$(get_request_state $fid RESTORE)
2303 [[ "$state" == "SUCCEED" ]] ||
2304 error "truncate $sz does not trig restore, state = $state"
2306 $TRUNCATE $ref $trunc_to
2307 cmp $ref $f || error "file data wrong after truncate"
2313 # test needs a running copytool
2318 local sz=$(stat -c %s /etc/passwd)
2320 echo "truncate up from $sz to $((sz*2))"
2321 truncate_released_file /etc/passwd $((sz*2))
2323 echo "truncate down from $sz to $((sz/2))"
2324 truncate_released_file /etc/passwd $((sz/2))
2326 echo "truncate to 0"
2327 truncate_released_file /etc/passwd 0
2331 run_test 58 "Truncate a released file will trigger restore"
2336 local f=$DIR/$tdir/$tfile
2337 local FILELIST=/tmp/filelist.txt
2341 for i in $(seq 1 $file_count); do
2342 fid=$(copy_file /etc/hosts $f.$i)
2343 echo $f.$i >> $FILELIST
2346 # to be sure wait_all_done will not be mislead by previous tests
2348 wait_for_grace_delay
2349 $LFS hsm_archive --filelist $FILELIST ||
2350 error "cannot archive a file list"
2352 $LFS hsm_release --filelist $FILELIST ||
2353 error "cannot release a file list"
2354 $LFS hsm_restore --filelist $FILELIST ||
2355 error "cannot restore a file list"
2359 run_test 90 "Archive/restore a file list"
2361 double_verify_reset_hsm_param() {
2363 echo "Testing $HSM_PARAM.$p"
2364 local val=$(get_hsm_param $p)
2366 local val2=$(($val * 2))
2367 set_hsm_param $p $val2
2368 val=$(get_hsm_param $p)
2369 [[ $val == $val2 ]] ||
2370 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2371 echo "Set $p to 0 must failed"
2375 set_hsm_param $p $save
2377 if [[ $rc == 0 ]]; then
2378 error "we must not be able to set $HSM_PARAM.$p to 0"
2383 double_verify_reset_hsm_param loop_period
2384 double_verify_reset_hsm_param grace_delay
2385 double_verify_reset_hsm_param active_request_timeout
2386 double_verify_reset_hsm_param max_requests
2387 double_verify_reset_hsm_param default_archive_id
2389 run_test 100 "Set coordinator /proc tunables"
2396 run_test 102 "Verify coordinator control"
2399 # test needs a running copytool
2406 for i in $(seq 1 20); do
2407 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2409 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2413 echo "Current requests"
2414 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2415 $HSM_PARAM.actions |\
2416 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2418 [[ -z "$res" ]] || error "Some request have not been canceled"
2422 run_test 103 "Purge all requests"
2427 # test needs a running copytool
2431 local f=$DIR/$tdir/$tfile
2432 local fid=$(make_large_for_progress $f)
2433 # if cdt is on, it can serve too quickly the request
2435 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2436 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2437 $HSM_PARAM.actions |\
2438 grep $fid | cut -f16 -d=")
2441 [[ "$data1" == "$DATAHEX" ]] ||
2442 error "Data field in records is ($data1) and not ($DATAHEX)"
2446 run_test 104 "Copy tool data field"
2453 for i in $(seq -w 1 10); do
2454 cp /etc/passwd $DIR/$tdir/$i
2455 $LFS hsm_archive $DIR/$tdir/$i
2457 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2458 $HSM_PARAM.actions |\
2459 grep WAITING | wc -l")
2462 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2463 $HSM_PARAM.actions |\
2464 grep WAITING | wc -l")
2467 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2468 error "Requests count after shutdown $reqcnt2 != "\
2469 "before shutdown $reqcnt1"
2471 run_test 105 "Restart of coordinator"
2474 # test needs a running copytool
2477 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2478 get_client_uuid $MOUNT | cut -d' ' -f2)
2479 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2482 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2483 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2485 [[ -z "$agent" ]] ||
2486 error "My uuid $uuid still found in agent list,"\
2487 " after copytool shutdown"
2489 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2492 [[ ! -z "$agent" ]] ||
2493 error "My uuid $uuid not found in agent list after"\
2496 run_test 106 "Copytool register/unregister"
2499 # test needs a running copytool
2501 # create and archive file
2503 local f1=$DIR/$tdir/$tfile
2504 local fid=$(copy_file /etc/passwd $f1)
2505 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2506 wait_request_state $fid ARCHIVE SUCCEED
2507 # shutdown and restart MDS
2509 # check the copytool still gets messages from MDT
2510 local f2=$DIR/$tdir/2
2511 local fid=$(copy_file /etc/passwd $f2)
2512 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2513 # main check of this sanity: this request MUST succeed
2514 wait_request_state $fid ARCHIVE SUCCEED
2517 run_test 107 "Copytool re-register after MDS restart"
2519 policy_set_and_test()
2523 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2524 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2525 [[ "$policy" == "$target" ]] ||
2526 error "Wrong policy after '$change': '$policy' != '$target'"
2530 # to force default policy setting if error
2531 CDT_POLICY_HAD_CHANGED=true
2533 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2534 local default="NonBlockingRestore [NoRetryAction]"
2535 [[ "$policy" == "$default" ]] ||
2536 error "default policy has changed,"\
2537 " '$policy' != '$default' update the test"
2538 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2539 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2540 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2541 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2542 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2543 # useless bacause we know but safer for futur changes to use real value
2544 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2545 echo "Next set_param must failed"
2546 policy_set_and_test "wrong" "$policy"
2549 echo "Back to default policy"
2550 cdt_set_sanity_policy
2552 run_test 109 "Policy display/change"
2555 # test needs a running copytool
2560 copy2archive /etc/passwd $tdir/$tfile
2562 local f=$DIR/$tdir/$tfile
2563 import_file $tdir/$tfile $f
2564 local fid=$(path2fid $f)
2566 cdt_set_non_blocking_restore
2571 wait_request_state $fid RESTORE SUCCEED
2572 cdt_clear_non_blocking_restore
2576 error "md5sum returns $st != 1, "\
2577 "should also perror ENODATA (No data available)"
2581 run_test 110a "Non blocking restore policy (import case)"
2584 # test needs a running copytool
2588 local f=$DIR/$tdir/$tfile
2589 local fid=$(copy_file /etc/passwd $f)
2590 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2591 wait_request_state $fid ARCHIVE SUCCEED
2594 cdt_set_non_blocking_restore
2599 wait_request_state $fid RESTORE SUCCEED
2600 cdt_clear_non_blocking_restore
2604 error "md5sum returns $st != 1, "\
2605 "should also perror ENODATA (No data available)"
2609 run_test 110b "Non blocking restore policy (release case)"
2612 # test needs a running copytool
2616 copy2archive /etc/passwd $tdir/$tfile
2618 local f=$DIR/$tdir/$tfile
2620 import_file $tdir/$tfile $f
2621 local fid=$(path2fid $f)
2625 copytool_remove_backend $fid
2628 wait_request_state $fid RESTORE FAILED
2635 [[ $st == 0 ]] || error "Restore does not failed"
2639 run_test 111a "No retry policy (import case), restore will error"\
2640 " (No such file or directory)"
2643 # test needs a running copytool
2647 local f=$DIR/$tdir/$tfile
2648 local fid=$(copy_file /etc/passwd $f)
2650 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2651 wait_request_state $fid ARCHIVE SUCCEED
2654 copytool_remove_backend $fid
2657 wait_request_state $fid RESTORE FAILED
2664 [[ $st == 0 ]] || error "Restore does not failed"
2668 run_test 111b "No retry policy (release case), restore will error"\
2669 " (No such file or directory)"
2672 # test needs a running copytool
2676 local f=$DIR/$tdir/$tfile
2677 local fid=$(copy_file /etc/passwd $f)
2679 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2680 local l=$($LFS hsm_action $f)
2682 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2686 wait_request_state $fid ARCHIVE SUCCEED
2689 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2693 run_test 112 "State of recorded request"
2696 # test needs a running copytool
2700 local f=$DIR/$tdir/$tfile
2701 local fid=$(make_large_for_cancel $f)
2702 # test with cdt on is made in test_221
2704 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2707 wait_request_state $fid ARCHIVE CANCELED
2708 wait_request_state $fid CANCEL SUCCEED
2712 run_test 200 "Register/Cancel archive"
2715 # test needs a running copytool
2719 local f=$DIR/$tdir/$tfile
2720 make_archive $tdir/$tfile
2721 import_file $tdir/$tfile $f
2722 local fid=$(path2fid $f)
2724 # test with cdt on is made in test_222
2729 wait_request_state $fid RESTORE CANCELED
2730 wait_request_state $fid CANCEL SUCCEED
2734 run_test 201 "Register/Cancel restore"
2737 # test needs a running copytool
2741 local f=$DIR/$tdir/$tfile
2742 local fid=$(make_large_for_progress $f)
2743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2744 wait_request_state $fid ARCHIVE SUCCEED
2750 wait_request_state $fid REMOVE CANCELED
2754 run_test 202 "Register/Cancel remove"
2757 # test needs a running copytool
2762 local f=$DIR/$tdir/$tfile
2763 local fid=$(copy_file /etc/passwd $f)
2767 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2768 wait_request_state $fid ARCHIVE SUCCEED
2770 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2774 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2778 run_test 220 "Changelog for archive"
2781 # test needs a running copytool
2786 local f=$DIR/$tdir/$tfile
2787 local fid=$(make_large_for_cancel $f)
2791 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2792 wait_request_state $fid ARCHIVE STARTED
2794 wait_request_state $fid ARCHIVE CANCELED
2795 wait_request_state $fid CANCEL SUCCEED
2797 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2800 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2804 run_test 221 "Changelog for archive canceled"
2807 # test needs a running copytool
2811 copy2archive /etc/passwd $tdir/$tfile
2813 local f=$DIR/$tdir/$tfile
2814 import_file $tdir/$tfile $f
2815 local fid=$(path2fid $f)
2820 wait_request_state $fid RESTORE SUCCEED
2822 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2825 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2829 run_test 222a "Changelog for explicit restore"
2832 # test needs a running copytool
2836 local f=$DIR/$tdir/$tfile
2837 local fid=$(copy_file /etc/passwd $f)
2840 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2841 wait_request_state $fid ARCHIVE SUCCEED
2846 wait_request_state $fid RESTORE SUCCEED
2848 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2851 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2855 run_test 222b "Changelog for implicit restore"
2858 # test needs a running copytool
2863 local f=$DIR/$tdir/$tfile
2864 make_archive $tdir/$tfile
2868 import_file $tdir/$tfile $f
2869 local fid=$(path2fid $f)
2872 wait_request_state $fid RESTORE STARTED
2874 wait_request_state $fid RESTORE CANCELED
2875 wait_request_state $fid CANCEL SUCCEED
2877 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2880 [[ $flags == $target ]] ||
2881 error "Changelog flag is $flags not $target"
2885 run_test 223a "Changelog for restore canceled (import case)"
2888 # test needs a running copytool
2893 local f=$DIR/$tdir/$tfile
2894 local fid=$(make_large_for_progress $f)
2897 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2898 wait_request_state $fid ARCHIVE SUCCEED
2901 wait_request_state $fid RESTORE STARTED
2903 wait_request_state $fid RESTORE CANCELED
2904 wait_request_state $fid CANCEL SUCCEED
2906 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2909 [[ $flags == $target ]] ||
2910 error "Changelog flag is $flags not $target"
2914 run_test 223b "Changelog for restore canceled (release case)"
2917 # test needs a running copytool
2922 local f=$DIR/$tdir/$tfile
2923 local fid=$(copy_file /etc/passwd $f)
2926 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2927 wait_request_state $fid ARCHIVE SUCCEED
2930 wait_request_state $fid REMOVE SUCCEED
2932 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2935 [[ $flags == $target ]] ||
2936 error "Changelog flag is $flags not $target"
2940 run_test 224 "Changelog for remove"
2943 # test needs a running copytool
2946 # test is not usable because remove request is too fast
2947 # so it is always finished before cancel can be done ...
2948 echo "Test disabled"
2953 local f=$DIR/$tdir/$tfile
2954 local fid=$(make_large_for_progress $f)
2957 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2958 wait_request_state $fid ARCHIVE SUCCEED
2960 # if cdt is on, it can serve too quickly the request
2965 wait_request_state $fid REMOVE CANCELED
2966 wait_request_state $fid CANCEL SUCCEED
2968 flags=$(changelog_get_flags $MDT0 RENME $fid2)
2969 local flags=$($LFS changelog $MDT0 | grep HSM | grep $fid | tail -1 |
2973 [[ $flags == $target ]] ||
2974 error "Changelog flag is $flags not $target"
2978 run_test 225 "Changelog for remove canceled"
2981 # test needs a running copytool
2986 local f1=$DIR/$tdir/$tfile-1
2987 local f2=$DIR/$tdir/$tfile-2
2988 local f3=$DIR/$tdir/$tfile-3
2989 local fid1=$(copy_file /etc/passwd $f1)
2990 local fid2=$(copy_file /etc/passwd $f2)
2991 copy_file /etc/passwd $f3
2994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2995 wait_request_state $fid1 ARCHIVE SUCCEED
2997 $LFS hsm_archive $f2
2998 wait_request_state $fid2 ARCHIVE SUCCEED
3000 rm $f1 || error "rm $f1 failed"
3002 local flags=$(changelog_get_flags $MDT0 UNLNK $fid1)
3005 [[ $flags == $target ]] ||
3006 error "Changelog flag is $flags not $target"
3008 mv $f3 $f2 || error "mv $f3 $f2 failed"
3010 flags=$(changelog_get_flags $MDT0 RENME $fid2)
3013 [[ $flags == $target ]] ||
3014 error "Changelog flag is $flags not $target"
3018 run_test 226 "changelog for last rm/mv with exiting archive"
3020 check_flags_changes() {
3028 $LFS hsm_set --$hsm_flag $f ||
3029 error "Cannot set $hsm_flag on $f"
3030 local flags=($(changelog_get_flags $MDT0 HSM $fid))
3031 local seen=${#flags[*]}
3033 [[ $seen == $cnt ]] ||
3034 error "set $hsm_flag: Changelog events $seen != $cnt"
3035 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3036 error "set $hsm_flag: Changelog flags are "\
3037 "${flags[$((cnt - 1))]} not $target"
3039 $LFS hsm_clear --$hsm_flag $f ||
3040 error "Cannot clear $hsm_flag on $f"
3041 flags=($(changelog_get_flags $MDT0 HSM $fid))
3044 [[ $cnt == $seen ]] ||
3045 error "clear $hsm_flag: Changelog events $seen != $cnt"
3047 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3048 error "clear $hsm_flag: Changelog flag is "\
3049 "${flags[$((cnt - 1))]} not $target"
3053 # test needs a running copytool
3060 for i in norelease noarchive exists archived
3062 local f=$DIR/$tdir/$tfile-$i
3063 local fid=$(copy_file /etc/passwd $f)
3064 check_flags_changes $f $fid $i 0 1
3067 f=$DIR/$tdir/$tfile---lost
3068 fid=$(copy_file /etc/passwd $f)
3069 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3070 wait_request_state $fid ARCHIVE SUCCEED
3071 check_flags_changes $f $fid lost 3 1
3075 run_test 227 "changelog when explicit setting of HSM flags"
3078 # test needs a running copytool
3081 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3082 error "creating $DIR/$tfile"
3083 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3084 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3086 $LFS hsm_release $DIR/$tfile
3087 check_hsm_flags $DIR/$tfile "0x0000000d"
3089 filefrag $DIR/$tfile | grep " 1 extent found" ||
3090 error "filefrag on released file must return only one extent"
3092 # only newer versions of cp detect sparse files by stat/FIEMAP
3094 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3095 error "copying $DIR/$tfile"
3096 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3098 $LFS hsm_release $DIR/$tfile
3099 check_hsm_flags $DIR/$tfile "0x0000000d"
3103 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3105 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3106 error "comparing untarred $DIR/$tfile"
3110 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3113 # test needs a running copytool
3117 local maxrequest=$(get_hsm_param max_requests)
3118 local rqcnt=$(($maxrequest * 3))
3122 for i in $(seq -w 1 $rqcnt); do
3124 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3126 # we do it in 2 steps, so all requests arrive at the same time
3127 for i in $(seq -w 1 $rqcnt); do
3128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3133 while [[ $cnt != 0 || $wt != 0 ]]; do
3135 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3136 $HSM_PARAM.actions |\
3137 grep STARTED | grep -v CANCEL | wc -l")
3138 [[ $cnt -le $maxrequest ]] ||
3139 error "$cnt > $maxrequest too many started requests"
3140 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3141 $HSM_PARAM.actions |\
3142 grep WAITING | wc -l")
3143 echo "max=$maxrequest started=$cnt waiting=$wt"
3148 run_test 250 "Coordinator max request"
3151 # test needs a running copytool
3155 local f=$DIR/$tdir/$tfile
3156 local fid=$(make_large_for_cancel $f)
3159 # to have a short test
3160 local old_to=$(get_hsm_param active_request_timeout)
3161 set_hsm_param active_request_timeout 4
3162 # to be sure the cdt will wake up frequently so
3163 # it will be able to cancel the "old" request
3164 local old_loop=$(get_hsm_param loop_period)
3165 set_hsm_param loop_period 2
3168 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3169 wait_request_state $fid ARCHIVE STARTED
3171 wait_request_state $fid ARCHIVE CANCELED
3173 set_hsm_param active_request_timeout $old_to
3174 set_hsm_param loop_period $old_loop
3178 run_test 251 "Coordinator request timeout"
3181 # the only way to test ondisk conf is to restart MDS ...
3182 echo "Stop coordinator and remove coordinator state at mount"
3185 # clean on disk conf set by default
3186 cdt_clear_mount_state
3187 cdt_check_state stopped
3189 # check cdt still off after umount/remount
3191 cdt_check_state stopped
3193 echo "Set coordinator start at mount, and start coordinator"
3194 cdt_set_mount_state enabled
3197 cdt_check_state enabled
3199 # check cdt still on after umount/remount
3201 cdt_check_state enabled
3203 # we are back to original state (cdt started at mount)
3205 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3208 local ai=$(get_hsm_param default_archive_id)
3209 local new=$((ai + 1))
3211 set_hsm_param default_archive_id $new -P
3213 local res=$(get_hsm_param default_archive_id)
3216 set_hsm_param default_archive_id "" "-P -d"
3218 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3220 run_test 301 "HSM tunnable are persistent"
3223 local ai=$(get_hsm_param default_archive_id)
3224 local new=$((ai + 1))
3229 set_hsm_param default_archive_id $new -P
3233 cdt_check_state enabled
3235 local res=$(get_hsm_param default_archive_id)
3238 set_hsm_param default_archive_id "" "-P -d"
3240 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3242 run_test 302 "HSM tunnable are persistent when CDT is off"
3247 check_and_cleanup_lustre