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)}
171 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
173 echo "Copytool is stopped on $agents"
175 # clean all CDTs orphans requests from previous tests
176 # that would otherwise need to timeout to clear.
177 for mdtno in $(seq 1 $MDSCOUNT); do
179 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
180 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
182 # skip already stop[ed,ing] CDTs
183 echo $oldstate | grep stop || continue
185 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
186 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
188 error "mds${mdtno} cdt state is not stopped"
189 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
190 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
192 error "mds${mdtno} cdt state is not $oldstate"
197 local agents=${1:-$(facet_active_host $SINGLEAGT)}
199 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
200 echo "Copytool is suspended on $agents"
203 copytool_remove_backend() {
205 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
206 echo "Remove from backend: $fid = $be"
207 do_facet $SINGLEAGT rm -f $be
211 do_facet $SINGLEAGT \
212 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
213 --import $1 $2 $MOUNT" ||
214 error "import of $1 to $2 failed"
218 local file=$HSM_ARCHIVE/$1
219 do_facet $SINGLEAGT mkdir -p $(dirname $file)
220 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
221 error "cannot create $file"
225 local file=$HSM_ARCHIVE/$2
226 do_facet $SINGLEAGT mkdir -p $(dirname $file)
227 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
231 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0\
232 changelog_register -n)
233 do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+hsm"
234 $LFS changelog_clear $MDT0 $CL_USER 0
237 changelog_cleanup() {
238 # $LFS changelog $MDT0
239 [[ -n "$CL_USER" ]] || return 0
241 $LFS changelog_clear $MDT0 $CL_USER 0
242 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
246 changelog_get_flags() {
251 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
256 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
264 if [[ "$value" != "" ]]; then
267 do_facet $SINGLEMDS $LCTL set_param $opt -n $HSM_PARAM.$param$value
274 do_facet $SINGLEMDS $LCTL set_param $MDT_PARAM.hsm_control=$cmd
275 wait_result $SINGLEMDS "$LCTL get_param -n $MDT_PARAM.hsm_control"\
276 $target 10 || error "cdt state is not $target"
279 cdt_set_sanity_policy() {
280 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
283 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
284 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
285 CDT_POLICY_HAD_CHANGED=
290 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
291 CDT_POLICY_HAD_CHANGED=true
294 cdt_clear_no_retry() {
295 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NRA
296 CDT_POLICY_HAD_CHANGED=true
299 cdt_set_non_blocking_restore() {
300 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NBR
301 CDT_POLICY_HAD_CHANGED=true
304 cdt_clear_non_blocking_restore() {
305 do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
306 CDT_POLICY_HAD_CHANGED=true
309 cdt_clear_mount_state() {
310 do_facet $SINGLEMDS $LCTL set_param -d -P $MDT_PARAM.hsm_control
313 cdt_set_mount_state() {
314 do_facet $SINGLEMDS $LCTL set_param -P $MDT_PARAM.hsm_control=$1
319 wait_result $SINGLEMDS\
320 "$LCTL get_param -n $MDT_PARAM.hsm_control" "$target" 20 ||
321 error "cdt state is not $target"
325 set_test_state disabled disabled
329 set_test_state enabled enabled
333 set_test_state shutdown stopped
337 set_test_state purge enabled
343 cdt_set_sanity_policy
347 local client_count=$1
348 if [[ $CLIENTCOUNT -lt $client_count ]]; then
349 skip "Need $client_count or more clients, have $CLIENTCOUNT"
356 $LFS path2fid $1 | tr -d '[]'
363 if [[ $u == "user" ]]; then
364 local st=$($RUNAS $LFS hsm_state $f)
366 local st=$($LFS hsm_state $f)
370 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
372 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
376 get_hsm_archive_id() {
378 local st=$($LFS hsm_state $f)
379 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
381 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
390 local st=$(get_hsm_flags $f)
391 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
394 check_hsm_flags_user() {
398 local st=$(get_hsm_flags $f user)
399 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
411 if [[ "$3" != 1 ]]; then
415 cp $1 $f || error "cannot copy $1 to $f"
416 path2fid $f || error "cannot get fid on $f"
420 local file2=${1/$DIR/$DIR2}
421 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
422 error "cannot create $file2"
423 path2fid $1 || error "cannot get fid on $1"
426 cleanup_large_files() {
427 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
429 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
432 make_large_for_striping() {
433 local file2=${1/$DIR/$DIR2}
434 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
438 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
439 error "cannot create $file2"
440 path2fid $1 || error "cannot get fid on $1"
443 make_large_for_progress() {
444 local file2=${1/$DIR/$DIR2}
448 # big file is large enough, so copy time is > 30s
449 # so copytool make 1 progress
450 # size is not a multiple of 1M to avoid stripe
452 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
453 error "cannot create $file2"
454 path2fid $1 || error "cannot get fid on $1"
457 make_large_for_progress_aligned() {
458 local file2=${1/$DIR/$DIR2}
462 # big file is large enough, so copy time is > 30s
463 # so copytool make 1 progress
464 # size is a multiple of 1M to have stripe
466 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
467 error "cannot create $file2"
468 path2fid $1 || error "cannot get fid on $1"
471 make_large_for_cancel() {
472 local file2=${1/$DIR/$DIR2}
476 # Copy timeout is 100s. 105MB => 105s
477 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
478 error "cannot create $file2"
479 path2fid $1 || error "cannot get fid on $1"
485 wait_update --verbose $(facet_active_host $facet) "$@"
488 wait_request_state() {
493 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
494 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
496 wait_result $SINGLEMDS "$cmd" $state 100 ||
497 error "request on $fid is not $state"
500 get_request_state() {
504 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
505 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
508 get_request_count() {
512 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
513 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
519 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
520 cmd+=" | egrep 'WAITING|STARTED'"
522 wait_result $SINGLEMDS "$cmd" "" $timeout ||
523 error "requests did not complete"
526 wait_for_grace_delay() {
527 local val=$(get_hsm_param grace_delay)
531 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
532 awk '{gsub(/_UUID/,""); print $1}' | head -1)
537 # cleanup from previous bad setup
538 search_and_kill_copytool
540 # for recovery tests, coordinator needs to be started at mount
542 # the lustre conf must be without hsm on (like for sanity.sh)
543 echo "Set HSM on and start"
544 cdt_set_mount_state enabled
545 cdt_check_state enabled
547 echo "Start copytool"
550 echo "Set sanity-hsm HSM policy"
551 cdt_set_sanity_policy
553 # finished requests are quickly removed from list
554 set_hsm_param grace_delay 10
560 local f=$DIR/$tdir/$tfile
564 check_hsm_flags_user $f "0x00000000"
566 $RUNAS $LFS hsm_set --norelease $f ||
567 error "user could not change hsm flags"
568 check_hsm_flags_user $f "0x00000010"
570 $RUNAS $LFS hsm_clear --norelease $f ||
571 error "user could not clear hsm flags"
572 check_hsm_flags_user $f "0x00000000"
574 # User could not change those flags...
575 $RUNAS $LFS hsm_set --exists $f &&
576 error "user should not set this flag"
577 check_hsm_flags_user $f "0x00000000"
580 $LFS hsm_set --exists $f ||
581 error "root could not change hsm flags"
582 check_hsm_flags_user $f "0x00000001"
584 $LFS hsm_clear --exists $f ||
585 error "root could not clear hsm state"
586 check_hsm_flags_user $f "0x00000000"
589 run_test 1 "lfs hsm flags root/non-root access"
593 local f=$DIR/$tdir/$tfile
595 # New files are not dirty
596 check_hsm_flags $f "0x00000000"
598 # For test, we simulate an archived file.
599 $LFS hsm_set --exists $f || error "user could not change hsm flags"
600 check_hsm_flags $f "0x00000001"
602 # chmod do not put the file dirty
603 chmod 600 $f || error "could not chmod test file"
604 check_hsm_flags $f "0x00000001"
606 # chown do not put the file dirty
607 chown $RUNAS_ID $f || error "could not chown test file"
608 check_hsm_flags $f "0x00000001"
610 # truncate put the file dirty
611 $TRUNCATE $f 1 || error "could not truncate test file"
612 check_hsm_flags $f "0x00000003"
614 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
615 check_hsm_flags $f "0x00000001"
617 run_test 2 "Check file dirtyness when doing setattr"
623 # New files are not dirty
625 check_hsm_flags $f "0x00000000"
627 # For test, we simulate an archived file.
628 $LFS hsm_set --exists $f ||
629 error "user could not change hsm flags"
630 check_hsm_flags $f "0x00000001"
632 # Reading a file, does not set dirty
633 cat $f > /dev/null || error "could not read file"
634 check_hsm_flags $f "0x00000001"
636 # Open for write without modifying data, does not set dirty
637 openfile -f O_WRONLY $f || error "could not open test file"
638 check_hsm_flags $f "0x00000001"
640 # Append to a file sets it dirty
641 cp -p /etc/passwd $f.append || error "could not create file"
642 $LFS hsm_set --exists $f.append ||
643 error "user could not change hsm flags"
644 dd if=/etc/passwd of=$f.append bs=1 count=3\
645 conv=notrunc oflag=append status=noxfer ||
646 error "could not append to test file"
647 check_hsm_flags $f.append "0x00000003"
649 # Modify a file sets it dirty
650 cp -p /etc/passwd $f.modify || error "could not create file"
651 $LFS hsm_set --exists $f.modify ||
652 error "user could not change hsm flags"
653 dd if=/dev/zero of=$f.modify bs=1 count=3\
654 conv=notrunc status=noxfer ||
655 error "could not modify test file"
656 check_hsm_flags $f.modify "0x00000003"
658 # Open O_TRUNC sets dirty
659 cp -p /etc/passwd $f.trunc || error "could not create file"
660 $LFS hsm_set --exists $f.trunc ||
661 error "user could not change hsm flags"
662 cp /etc/group $f.trunc || error "could not override a file"
663 check_hsm_flags $f.trunc "0x00000003"
665 # Mmapped a file sets dirty
666 cp -p /etc/passwd $f.mmap || error "could not create file"
667 $LFS hsm_set --exists $f.mmap ||
668 error "user could not change hsm flags"
669 multiop $f.mmap OSMWUc || error "could not mmap a file"
670 check_hsm_flags $f.mmap "0x00000003"
672 run_test 3 "Check file dirtyness when opening for write"
676 local f=$DIR/$tdir/$tfile
677 local fid=$(make_small $f)
680 local st=$(get_request_state $fid CANCEL)
681 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
683 run_test 4 "Useless cancel must not be registered"
686 # test needs a running copytool
690 local f=$DIR/$tdir/$tfile
691 local fid=$(copy_file /etc/passwd $f)
693 wait_request_state $fid ARCHIVE SUCCEED
695 check_hsm_flags $f "0x00000009"
699 run_test 8 "Test default archive number"
703 local f=$DIR/$tdir/$tfile
704 local fid=$(copy_file /etc/passwd $f)
705 # we do not use the default one to be sure
706 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
708 copytool_setup $SINGLEAGT $MOUNT $new_an
709 $LFS hsm_archive --archive $new_an $f
710 wait_request_state $fid ARCHIVE SUCCEED
712 check_hsm_flags $f "0x00000009"
716 run_test 9 "Use of explict archive number, with dedicated copytool"
719 needclients 3 || return 0
725 copytool_cleanup $(comma_list $(agts_nodes))
727 # start all of the copytools
728 for n in $(seq $AGTCOUNT); do
732 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
735 for n in $(seq $AGTCOUNT); do
736 file=$DIR/$tdir/$tfile.$n
737 fid=$(make_small $file)
739 $LFS hsm_archive $file || error "could not archive file $file"
740 wait_request_state $fid ARCHIVE SUCCEED
741 check_hsm_flags $file "0x00000009"
745 copytool_cleanup $(comma_list $(agts_nodes))
747 run_test 9a "Multiple remote agents"
750 # test needs a running copytool
753 mkdir -p $DIR/$tdir/d1
754 local f=$DIR/$tdir/$tfile
755 local fid=$(copy_file /etc/hosts $f)
756 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
757 error "hsm_archive failed"
758 wait_request_state $fid ARCHIVE SUCCEED
760 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
761 error "fid $fid not in archive $HSM_ARCHIVE"
762 echo "Verifying content"
763 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
764 echo "Verifying hsm state "
765 check_hsm_flags $f "0x00000009"
767 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
768 local st=$(get_hsm_archive_id $f)
769 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
770 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
775 run_test 10a "Archive a file"
778 # test needs a running copytool
782 local f=$DIR/$tdir/$tfile
783 local fid=$(copy_file /etc/hosts $f)
784 $LFS hsm_archive $f || error "archive request failed"
785 wait_request_state $fid ARCHIVE SUCCEED
787 $LFS hsm_archive $f || error "archive of non dirty file failed"
788 local cnt=$(get_request_count $fid ARCHIVE)
789 [[ "$cnt" == "1" ]] ||
790 error "archive of non dirty file must not make a request"
794 run_test 10b "Archive of non dirty file must work without doing request"
797 # test needs a running copytool
801 local f=$DIR/$tdir/$tfile
802 local fid=$(copy_file /etc/hosts $f)
803 $LFS hsm_set --noarchive $f
804 $LFS hsm_archive $f && error "archive a noarchive file must fail"
808 run_test 10c "Check forbidden archive"
811 # test needs a running copytool
815 local f=$DIR/$tdir/$tfile
816 local fid=$(copy_file /etc/hosts $f)
817 $LFS hsm_archive $f || error "cannot archive $f"
818 wait_request_state $fid ARCHIVE SUCCEED
820 local ar=$(get_hsm_archive_id $f)
821 local dflt=$(get_hsm_param default_archive_id)
822 [[ $ar == $dflt ]] ||
823 error "archived file is not on default archive: $ar != $dflt"
827 run_test 10d "Archive a file on the default archive id"
831 copy2archive /etc/hosts $tdir/$tfile
832 local f=$DIR/$tdir/$tfile
834 import_file $tdir/$tfile $f
835 echo -n "Verifying released state: "
836 check_hsm_flags $f "0x0000000d"
838 local LSZ=$(stat -c "%s" $f)
839 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
841 echo "Verifying imported size $LSZ=$ASZ"
842 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
843 echo -n "Verifying released pattern: "
844 local PTRN=$($GETSTRIPE -L $f)
846 [[ $PTRN == 80000001 ]] || error "Is not released"
847 local fid=$(path2fid $f)
848 echo "Verifying new fid $fid in archive"
850 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
851 error "fid $fid not in archive $HSM_ARCHIVE"
853 run_test 11 "Import a file"
856 # test needs a running copytool
860 copy2archive /etc/hosts $tdir/$tfile
862 local f=$DIR/$tdir/$tfile
863 import_file $tdir/$tfile $f
864 local f=$DIR2/$tdir/$tfile
865 echo "Verifying released state: "
866 check_hsm_flags $f "0x0000000d"
868 local fid=$(path2fid $f)
870 wait_request_state $fid RESTORE SUCCEED
872 echo "Verifying file state: "
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 12a "Restore an imported file explicitly"
884 # test needs a running copytool
888 copy2archive /etc/hosts $tdir/$tfile
890 local f=$DIR/$tdir/$tfile
891 import_file $tdir/$tfile $f
892 echo "Verifying released state: "
893 check_hsm_flags $f "0x0000000d"
895 cat $f > /dev/null || error "File read failed"
897 echo "Verifying file state after restore: "
898 check_hsm_flags $f "0x00000009"
900 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
902 [[ $? -eq 0 ]] || error "Restored file differs"
906 run_test 12b "Restore an imported file implicitly"
909 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
911 # test needs a running copytool
915 local f=$DIR/$tdir/$tfile
916 $LFS setstripe -c 2 $f
917 local fid=$(make_large_for_striping $f)
918 local FILE_CRC=$(md5sum $f)
920 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
921 wait_request_state $fid ARCHIVE SUCCEED
922 $LFS hsm_release $f || error "release $f failed"
924 echo "$FILE_CRC" | md5sum -c
926 [[ $? -eq 0 ]] || error "Restored file differs"
930 run_test 12c "Restore a file with stripe of 2"
933 # test needs a running copytool
938 local f=$DIR/$tdir/$tfile
939 local fid=$(copy_file /etc/hosts $f)
940 $LFS hsm_restore $f || error "restore of non archived file failed"
941 local cnt=$(get_request_count $fid RESTORE)
942 [[ "$cnt" == "0" ]] ||
943 error "restore non archived must not make a request"
944 $LFS hsm_archive $f ||
945 error "archive request failed"
946 wait_request_state $fid ARCHIVE SUCCEED
947 $LFS hsm_restore $f ||
948 error "restore of non released file failed"
949 local cnt=$(get_request_count $fid RESTORE)
950 [[ "$cnt" == "0" ]] ||
951 error "restore a non dirty file must not make a request"
955 run_test 12d "Restore of a non archived, non released file must work"\
956 " without doing request"
959 # test needs a running copytool
962 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
963 local f=$DIR/$tdir/$tfile
964 local fid=$(copy_file /etc/hosts $f)
965 $LFS hsm_archive $f || error "archive request failed"
966 wait_request_state $fid ARCHIVE SUCCEED
973 $LFS hsm_restore $f && error "restore a dirty file must fail"
977 run_test 12e "Check forbidden restore"
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 wait_request_state $fid RESTORE SUCCEED
993 echo -n "Verifying file state: "
994 check_hsm_flags $f "0x00000009"
996 diff -q /etc/hosts $f
998 [[ $? -eq 0 ]] || error "Restored file differs"
1002 run_test 12f "Restore a released file explicitly"
1005 # test needs a running copytool
1009 local f=$DIR/$tdir/$tfile
1010 local fid=$(copy_file /etc/hosts $f)
1012 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1013 wait_request_state $fid ARCHIVE SUCCEED
1014 $LFS hsm_release $f || error "release of $f failed"
1016 diff -q /etc/hosts $f
1019 # we check we had a restore done
1020 wait_request_state $fid RESTORE SUCCEED
1022 [[ $st -eq 0 ]] || error "Restored file differs"
1026 run_test 12g "Restore a released file implicitly"
1029 needclients 2 || return 0
1031 # test needs a running copytool
1035 local f=$DIR/$tdir/$tfile
1036 local fid=$(copy_file /etc/hosts $f)
1038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1039 wait_request_state $fid ARCHIVE SUCCEED
1040 $LFS hsm_release $f || error "release of $f failed"
1042 do_node $CLIENT2 diff -q /etc/hosts $f
1045 # we check we had a restore done
1046 wait_request_state $fid RESTORE SUCCEED
1048 [[ $st -eq 0 ]] || error "Restored file differs"
1052 run_test 12h "Restore a released file implicitly from a second node"
1055 # test needs a running copytool
1059 local f=$DIR/$tdir/$tfile
1060 local fid=$(copy_file /etc/passwd $f)
1061 $LFS hsm_archive $f || error "archive of $f failed"
1062 wait_request_state $fid ARCHIVE SUCCEED
1064 $LFS hsm_release $f || error "release of $f failed"
1068 [[ $? -eq 0 ]] || error "Restored file differs"
1072 run_test 12m "Archive/release/implicit restore"
1075 # test needs a running copytool
1079 copy2archive /etc/hosts $tdir/$tfile
1081 local f=$DIR/$tdir/$tfile
1082 import_file $tdir/$tfile $f
1084 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1085 error "Restored file differs"
1087 $LFS hsm_release $f || error "release of $f failed"
1091 run_test 12n "Import/implicit restore/release"
1094 # test needs a running copytool
1097 local ARC_SUBDIR="import.orig"
1101 # populate directory to be imported
1102 for d in $(seq 1 10); do
1103 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1104 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1105 for f in $(seq 1 10); do
1106 CURR_FILE="$CURR_DIR/$tfile.$f"
1107 # write file-specific data
1108 do_facet $SINGLEAGT \
1109 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1110 "file=$CURR_FILE > $CURR_FILE"
1114 import_file "$ARC_SUBDIR" $DIR/$tdir
1115 # diff lustre content and origin (triggers file restoration)
1116 # there must be 10x10 identical files, and no difference
1117 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1118 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1119 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1120 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1122 [ $cnt_diff -eq 0 ] ||
1123 error "$cnt_diff imported files differ from read data"
1124 [ $cnt_ok -eq 100 ] ||
1125 error "not enough identical files ($cnt_ok != 100)"
1129 run_test 13 "Recursively import and restore a directory"
1132 # test needs a running copytool
1137 local f=$DIR/$tdir/$tfile
1138 local fid=$(make_small $f)
1139 local sum=$(md5sum $f | awk '{print $1}')
1140 $LFS hsm_archive $f || error "could not archive file"
1141 wait_request_state $fid ARCHIVE SUCCEED
1145 # create released file (simulate llapi_hsm_import call)
1147 local fid2=$(path2fid $f)
1148 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1149 $LFS hsm_release $f || error "could not release file"
1151 # rebind the archive to the newly created file
1152 echo "rebind $fid to $fid2"
1154 do_facet $SINGLEAGT \
1155 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1156 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1158 # restore file and compare md5sum
1159 local sum2=$(md5sum $f | awk '{print $1}')
1161 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1165 run_test 14 "Rebind archived file to a new fid"
1168 # test needs a running copytool
1173 local f=$DIR/$tdir/$tfile
1175 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1179 for i in $(seq 1 $count); do
1180 fids[$i]=$(make_small $f.$i)
1181 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1182 $LFS hsm_archive $f.$i || error "could not archive file"
1184 wait_all_done $(($count*60))
1188 for i in $(seq 1 $count); do
1191 local fid2=$(path2fid $f.$i)
1192 # add the rebind operation to the list
1193 echo ${fids[$i]} $fid2 >> $tmpfile
1195 # set it released (simulate llapi_hsm_import call)
1196 $LFS hsm_set --archived --exists $f.$i ||
1197 error "could not force hsm flags"
1198 $LFS hsm_release $f.$i || error "could not release file"
1200 nl=$(wc -l < $tmpfile)
1201 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1203 echo "rebind list of files"
1204 do_facet $SINGLEAGT \
1205 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1206 --rebind $tmpfile $DIR" || error "could not rebind file list"
1208 # restore files and compare md5sum
1209 for i in $(seq 1 $count); do
1210 local sum2=$(md5sum $f.$i | awk '{print $1}')
1211 [[ $sum2 == ${sums[$i]} ]] ||
1212 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1218 run_test 15 "Rebind a list of files"
1221 # test needs a running copytool
1225 # create a known size file so we can verify transfer speed
1228 dd if=/dev/zero of=$ref bs=1M count=20
1231 local f=$DIR/$tdir/$tfile
1232 local fid=$(copy_file $ref $f)
1234 local start=$(date +%s)
1236 wait_request_state $fid ARCHIVE SUCCEED
1237 local end=$(date +%s)
1238 local duration=$((end - start))
1240 [[ $duration -ge $goal ]] ||
1241 error "Transfer is too fast $duration < $goal"
1245 run_test 16 "Test CT bandwith control option"
1250 local f=$DIR/$tdir/$tfile
1251 touch $f || error "touch $f failed"
1253 # Could not release a non-archived file
1254 $LFS hsm_release $f && error "release should not succeed"
1256 # For following tests, we must test them with HS_ARCHIVED set
1257 $LFS hsm_set --exists --archived $f || error "could not add flag"
1259 # Could not release a file if no-release is set
1260 $LFS hsm_set --norelease $f || error "could not add flag"
1261 $LFS hsm_release $f && error "release should not succeed"
1262 $LFS hsm_clear --norelease $f || error "could not remove flag"
1264 # Could not release a file if lost
1265 $LFS hsm_set --lost $f || error "could not add flag"
1266 $LFS hsm_release $f && error "release should not succeed"
1267 $LFS hsm_clear --lost $f || error "could not remove flag"
1269 # Could not release a file if dirty
1270 $LFS hsm_set --dirty $f || error "could not add flag"
1271 $LFS hsm_release $f && error "release should not succeed"
1272 $LFS hsm_clear --dirty $f || error "could not remove flag"
1274 run_test 20 "Release is not permitted"
1277 # test needs a running copytool
1281 local f=$DIR/$tdir/test_release
1283 # Create a file and check its states
1284 local fid=$(make_small $f)
1285 check_hsm_flags $f "0x00000000"
1287 $LFS hsm_archive $f || error "could not archive file"
1288 wait_request_state $fid ARCHIVE SUCCEED
1290 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1291 local sz=$(stat -c "%s" $f)
1292 [ $sz -ne "0" ] || error "file size should not be zero"
1294 # Release and check states
1295 $LFS hsm_release $f || error "could not release file"
1296 check_hsm_flags $f "0x0000000d"
1298 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1299 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1301 # Check we can release an file without stripe info
1305 check_hsm_flags $f "0x00000000"
1306 $LFS hsm_archive $f || error "could not archive file"
1307 wait_request_state $fid ARCHIVE SUCCEED
1309 # Release and check states
1310 $LFS hsm_release $f || error "could not release file"
1311 check_hsm_flags $f "0x0000000d"
1313 # Release again a file that is already released is OK
1314 $LFS hsm_release $f || fail "second release should succeed"
1315 check_hsm_flags $f "0x0000000d"
1319 run_test 21 "Simple release tests"
1322 # test needs a running copytool
1327 local f=$DIR/$tdir/test_release
1328 local swap=$DIR/$tdir/test_swap
1330 # Create a file and check its states
1331 local fid=$(make_small $f)
1332 check_hsm_flags $f "0x00000000"
1334 $LFS hsm_archive $f || error "could not archive file"
1335 wait_request_state $fid ARCHIVE SUCCEED
1337 # Release and check states
1338 $LFS hsm_release $f || error "could not release file"
1339 check_hsm_flags $f "0x0000000d"
1342 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1347 run_test 22 "Could not swap a release file"
1350 # test needs a running copytool
1355 local f=$DIR/$tdir/test_mtime
1357 # Create a file and check its states
1358 local fid=$(make_small $f)
1359 check_hsm_flags $f "0x00000000"
1361 $LFS hsm_archive $f || error "could not archive file"
1362 wait_request_state $fid ARCHIVE SUCCEED
1364 # Set modification time in the past
1365 touch -m -a -d @978261179 $f
1367 # Release and check states
1368 $LFS hsm_release $f || error "could not release file"
1369 check_hsm_flags $f "0x0000000d"
1371 local MTIME=$(stat -c "%Y" $f)
1372 local ATIME=$(stat -c "%X" $f)
1373 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1374 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1378 run_test 23 "Release does not change a/mtime (utime)"
1381 local file=$DIR/$tdir/$tfile
1390 # test needs a running copytool
1395 fid=$(make_small $file)
1397 # Create a file and check its states
1398 check_hsm_flags $file "0x00000000"
1400 # Ensure atime is less than mtime and ctime.
1404 atime0=$(stat -c "%X" $file)
1405 mtime0=$(stat -c "%Y" $file)
1406 ctime0=$(stat -c "%Z" $file)
1408 [ $atime0 -lt $mtime0 ] ||
1409 error "atime $atime0 is not less than mtime $mtime0"
1411 [ $atime0 -lt $ctime0 ] ||
1412 error "atime $atime0 is not less than ctime $ctime0"
1414 # Archive should not change any timestamps.
1415 $LFS hsm_archive $file || error "cannot archive '$file'"
1416 wait_request_state $fid ARCHIVE SUCCEED
1418 atime1=$(stat -c "%X" $file)
1419 mtime1=$(stat -c "%Y" $file)
1420 ctime1=$(stat -c "%Z" $file)
1422 [ $atime0 -eq $atime1 ] ||
1423 error "archive changed atime from $atime0 to $atime1"
1425 [ $mtime0 -eq $mtime1 ] ||
1426 error "archive changed mtime from $mtime0 to $mtime1"
1428 [ $ctime0 -eq $ctime1 ] ||
1429 error "archive changed ctime from $ctime0 to $ctime1"
1431 # Release should not change any timestamps.
1432 $LFS hsm_release $file || error "cannot release '$file'"
1433 check_hsm_flags $file "0x0000000d"
1435 atime1=$(stat -c "%X" $file)
1436 mtime1=$(stat -c "%Y" $file)
1437 ctime1=$(stat -c "%Z" $file)
1439 [ $atime0 -eq $atime1 ] ||
1440 error "release changed atime from $atime0 to $atime1"
1442 [ $mtime0 -eq $mtime1 ] ||
1443 error "release changed mtime from $mtime0 to $mtime1"
1445 [ $ctime0 -eq $ctime1 ] ||
1446 error "release changed ctime from $ctime0 to $ctime1"
1448 # Restore should not change atime or mtime and should not
1450 $LFS hsm_restore $file
1451 wait_request_state $fid RESTORE SUCCEED
1453 atime1=$(stat -c "%X" $file)
1454 mtime1=$(stat -c "%Y" $file)
1455 ctime1=$(stat -c "%Z" $file)
1457 [ $atime0 -eq $atime1 ] ||
1458 error "restore changed atime from $atime0 to $atime1"
1460 [ $mtime0 -eq $mtime1 ] ||
1461 error "restore changed mtime from $mtime0 to $mtime1"
1463 [ $ctime0 -le $ctime1 ] ||
1464 error "restore changed ctime from $ctime0 to $ctime1"
1468 # Once more, after unmount and mount.
1469 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1470 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1472 atime1=$(stat -c "%X" $file)
1473 mtime1=$(stat -c "%Y" $file)
1474 ctime1=$(stat -c "%Z" $file)
1476 [ $atime0 -eq $atime1 ] ||
1477 error "remount changed atime from $atime0 to $atime1"
1479 [ $mtime0 -eq $mtime1 ] ||
1480 error "remount changed mtime from $mtime0 to $mtime1"
1482 [ $ctime0 -le $ctime1 ] ||
1483 error "remount changed ctime from $ctime0 to $ctime1"
1485 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1488 local file=$DIR/$tdir/$tfile
1494 # Test needs a running copytool.
1498 # Check that root can do HSM actions on a ordinary user's file.
1500 fid=$(make_small $file)
1501 sum0=$(md5sum $file)
1503 chown $RUNAS_ID:$RUNAS_GID $file ||
1504 error "cannot chown '$file' to '$RUNAS_ID'"
1506 chmod ugo-w $DIR/$tdir ||
1507 error "cannot chmod '$DIR/$tdir'"
1509 $LFS hsm_archive $file
1510 wait_request_state $fid ARCHIVE SUCCEED
1512 $LFS hsm_release $file
1513 check_hsm_flags $file "0x0000000d"
1515 $LFS hsm_restore $file
1516 wait_request_state $fid RESTORE SUCCEED
1518 # Check that ordinary user can get HSM state.
1519 $RUNAS $LFS hsm_state $file ||
1520 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1522 $LFS hsm_release $file
1523 check_hsm_flags $file "0x0000000d"
1525 # Check that ordinary user can accessed released file.
1526 sum1=$($RUNAS md5sum $file) ||
1527 error "user '$RUNAS_ID' cannot read '$file'"
1529 [ "$sum0" == "$sum1" ] ||
1530 error "md5sum mismatch for '$file'"
1534 run_test 24b "root can archive, release, and restore user files"
1536 cleanup_test_24c() {
1538 set_hsm_param user_request_mask RESTORE
1539 set_hsm_param group_request_mask RESTORE
1540 set_hsm_param other_request_mask RESTORE
1544 local file=$DIR/$tdir/$tfile
1545 local action=archive
1550 # test needs a running copytool
1555 # Save the default masks and check that cleanup_24c will
1556 # restore the request masks correctly.
1557 user_save=$(get_hsm_param user_request_mask)
1558 group_save=$(get_hsm_param group_request_mask)
1559 other_save=$(get_hsm_param other_request_mask)
1561 [ "$user_save" == RESTORE ] ||
1562 error "user_request_mask is '$user_save' expected 'RESTORE'"
1563 [ "$group_save" == RESTORE ] ||
1564 error "group_request_mask is '$group_save' expected 'RESTORE'"
1565 [ "$other_save" == RESTORE ] ||
1566 error "other_request_mask is '$other_save' expected 'RESTORE'"
1568 trap cleanup_test_24c EXIT
1573 chown $RUNAS_ID:nobody $file ||
1574 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1576 set_hsm_param user_request_mask ""
1577 $RUNAS $LFS hsm_$action $file &&
1578 error "$action by user should fail"
1580 set_hsm_param user_request_mask $action
1581 $RUNAS $LFS hsm_$action $file ||
1582 error "$action by user should succeed"
1587 chown nobody:$RUNAS_GID $file ||
1588 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1590 set_hsm_param group_request_mask ""
1591 $RUNAS $LFS hsm_$action $file &&
1592 error "$action by group should fail"
1594 set_hsm_param group_request_mask $action
1595 $RUNAS $LFS hsm_$action $file ||
1596 error "$action by group should succeed"
1601 chown nobody:nobody $file ||
1602 error "cannot chown '$file' to 'nobody:nobody'"
1604 set_hsm_param other_request_mask ""
1605 $RUNAS $LFS hsm_$action $file &&
1606 error "$action by other should fail"
1608 set_hsm_param other_request_mask $action
1609 $RUNAS $LFS hsm_$action $file ||
1610 error "$action by other should succeed"
1615 run_test 24c "check that user,group,other request masks work"
1617 cleanup_test_24d() {
1619 mount -o remount,rw $MOUNT2
1623 local file1=$DIR/$tdir/$tfile
1624 local file2=$DIR2/$tdir/$tfile
1632 fid1=$(make_small $file1)
1634 trap cleanup_test_24d EXIT
1636 mount -o remount,ro $MOUNT2
1638 fid2=$(path2fid $file2)
1639 [ "$fid1" == "$fid2" ] ||
1640 error "FID mismatch '$fid1' != '$fid2'"
1642 $LFS hsm_archive $file2 &&
1643 error "archive should fail on read-only mount"
1644 check_hsm_flags $file1 "0x00000000"
1646 $LFS hsm_archive $file1
1647 wait_request_state $fid1 ARCHIVE SUCCEED
1649 $LFS hsm_release $file1
1650 $LFS hsm_restore $file2
1651 wait_request_state $fid1 RESTORE SUCCEED
1653 $LFS hsm_release $file1 || error "cannot release '$file1'"
1654 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1656 $LFS hsm_release $file2 &&
1657 error "release should fail on read-only mount"
1662 run_test 24d "check that read-only mounts are respected"
1665 # test needs a running copytool
1669 copy2archive /etc/hosts $tdir/$tfile
1671 local f=$DIR/$tdir/$tfile
1673 import_file $tdir/$tfile $f
1675 $LFS hsm_set --lost $f
1680 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1684 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1685 " (Operation not permitted)"
1688 # test needs a running copytool
1693 local f=$DIR/$tdir/$tfile
1694 local fid=$(copy_file /etc/passwd $f)
1696 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1697 wait_request_state $fid ARCHIVE SUCCEED
1700 $LFS hsm_set --lost $f
1704 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1708 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1709 " (Operation not permitted)"
1712 # test needs a running copytool
1716 local f=$DIR/$tdir/$tfile
1717 local fid=$(make_large_for_progress $f)
1718 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1719 wait_request_state $fid ARCHIVE SUCCEED
1722 wait_request_state $fid REMOVE SUCCEED
1724 check_hsm_flags $f "0x00000000"
1728 run_test 26 "Remove the archive of a valid file"
1731 # test needs a running copytool
1735 make_archive $tdir/$tfile
1736 local f=$DIR/$tdir/$tfile
1737 import_file $tdir/$tfile $f
1738 local fid=$(path2fid $f)
1742 [[ $? != 0 ]] || error "Remove of a released file should fail"
1746 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1749 # test needs a running copytool
1753 local f=$DIR/$tdir/$tfile
1754 local fid=$(make_large_for_progress $f)
1755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1756 wait_request_state $fid ARCHIVE SUCCEED
1761 [[ $? != 0 ]] || error "Remove of a released file should fail"
1765 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1768 # test needs a running copytool
1772 local f=$DIR/$tdir/$tfile
1773 local fid=$(make_large_for_progress $f)
1774 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1775 wait_request_state $fid ARCHIVE SUCCEED
1784 wait_request_state $fid REMOVE SUCCEED
1788 run_test 28 "Concurrent archive/file remove"
1791 # restore at exec cannot work on agent node (because of Linux kernel
1792 # protection of executables)
1793 needclients 2 || return 0
1795 # test needs a running copytool
1799 copy2archive /bin/true $tdir/$tfile
1801 local f=$DIR/$tdir/true
1802 import_file $tdir/$tfile $f
1804 local fid=$(path2fid $f)
1806 # set no retry action mode
1812 # remove no try action mode
1816 [[ $st == 0 ]] || error "Failed to exec a released file"
1820 run_test 30a "Restore at exec (import case)"
1823 # restore at exec cannot work on agent node (because of Linux kernel
1824 # protection of executables)
1825 needclients 2 || return 0
1827 # test needs a running copytool
1831 local f=$DIR/$tdir/true
1832 local fid=$(copy_file /bin/true $f)
1834 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1835 wait_request_state $fid ARCHIVE SUCCEED
1838 # set no retry action mode
1844 # remove no try action mode
1848 [[ $st == 0 ]] || error "Failed to exec a released file"
1852 run_test 30b "Restore at exec (release case)"
1855 needclients 2 || return 0
1857 # test needs a running copytool
1861 local f=$DIR/$tdir/SLEEP
1862 local fid=$(copy_file /bin/sleep $f)
1864 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1865 wait_request_state $fid ARCHIVE SUCCEED
1867 check_hsm_flags $f "0x0000000d"
1868 # set no retry action mode
1870 do_node $CLIENT2 "$f 10" &
1874 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1876 [[ $? == 0 ]] || error "Execution failed during run"
1878 [[ $? == 0 ]] || error "Binary overwritten during exec"
1881 # remove no try action mode
1883 check_hsm_flags $f "0x00000009"
1887 run_test 30c "Update during exec of released file must fail"
1889 restore_and_check_size() {
1892 local s=$(stat -c "%s" $f)
1894 local st=$(get_hsm_flags $f)
1898 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1900 n=$(stat -c "%s" $f)
1901 # we echo in both cases to show stat is not
1903 if [[ $n != $s ]]; then
1904 echo "size seen is $n != $s"
1907 echo "size seen is right: $n == $s"
1909 st=$(get_hsm_flags $f)
1913 if [[ $cpt -lt 10 ]]; then
1916 echo " restore is too long"
1917 wait_request_state $fid RESTORE SUCCEED
1923 # test needs a running copytool
1928 make_archive $tdir/$tfile
1929 local f=$DIR/$tdir/$tfile
1930 import_file $tdir/$tfile $f
1931 local fid=$($LFS path2fid $f)
1932 HSM_ARCHIVE_PURGE=false copytool_setup
1934 restore_and_check_size $f $fid
1937 [[ $err -eq 0 ]] || error "File size changed during restore"
1941 run_test 31a "Import a large file and check size during restore"
1945 # test needs a running copytool
1950 local f=$DIR/$tdir/$tfile
1951 local fid=$(make_large_for_progress $f)
1952 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1953 wait_request_state $fid ARCHIVE SUCCEED
1956 restore_and_check_size $f $fid
1959 [[ $err -eq 0 ]] || error "File size changed during restore"
1963 run_test 31b "Restore a large unaligned file and check size during restore"
1966 # test needs a running copytool
1971 local f=$DIR/$tdir/$tfile
1972 local fid=$(make_large_for_progress_aligned $f)
1973 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1974 wait_request_state $fid ARCHIVE SUCCEED
1977 restore_and_check_size $f $fid
1980 [[ $err -eq 0 ]] || error "File size changed during restore"
1984 run_test 31c "Restore a large aligned file and check size during restore"
1987 # test needs a running copytool
1992 local f=$DIR/$tdir/$tfile
1993 local fid=$(make_large_for_progress $f)
1994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1995 wait_request_state $fid ARCHIVE SUCCEED
1998 md5sum $f >/dev/null &
2000 wait_request_state $fid RESTORE STARTED
2005 # Check restore trigger process was killed
2006 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2010 wait_request_state $fid RESTORE CANCELED
2011 wait_request_state $fid CANCEL SUCCEED
2014 error "Cannot kill process waiting for restore ($killed)"
2018 run_test 33 "Kill a restore waiting process"
2021 # test needs a running copytool
2026 local f=$DIR/$tdir/$tfile
2027 local fid=$(make_large_for_progress $f)
2028 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2029 wait_request_state $fid ARCHIVE SUCCEED
2032 md5sum $f >/dev/null &
2034 wait_request_state $fid RESTORE STARTED
2036 rm $f || error "rm $f failed"
2037 # rm must not block during restore
2038 wait_request_state $fid RESTORE STARTED
2040 wait_request_state $fid RESTORE SUCCEED
2041 # check md5sum pgm finished
2042 local there=$(ps -o pid,comm hp $pid >/dev/null)
2043 [[ -z $there ]] || error "Restore initiator does not exit"
2045 local rc=$(wait $pid)
2046 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2050 run_test 34 "Remove file during restore"
2053 # test needs a running copytool
2058 local f=$DIR/$tdir/$tfile
2059 local f1=$DIR/$tdir/$tfile-1
2060 local fid=$(make_large_for_progress $f)
2061 local fid1=$(copy_file /etc/passwd $f1)
2062 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2063 wait_request_state $fid ARCHIVE SUCCEED
2066 md5sum $f >/dev/null &
2068 wait_request_state $fid RESTORE STARTED
2070 mv $f1 $f || error "mv $f1 $f failed"
2071 # mv must not block during restore
2072 wait_request_state $fid RESTORE STARTED
2074 wait_request_state $fid RESTORE SUCCEED
2075 # check md5sum pgm finished
2076 local there=$(ps -o pid,comm hp $pid >/dev/null)
2077 [[ -z $there ]] || error "Restore initiator does not exit"
2079 local rc=$(wait $pid)
2080 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2083 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2087 run_test 35 "Overwrite file during restore"
2090 # test needs a running copytool
2095 local f=$DIR/$tdir/$tfile
2096 local fid=$(make_large_for_progress $f)
2097 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2098 wait_request_state $fid ARCHIVE SUCCEED
2101 md5sum $f >/dev/null &
2103 wait_request_state $fid RESTORE STARTED
2106 # rm must not block during restore
2107 wait_request_state $fid RESTORE STARTED
2109 wait_request_state $fid RESTORE SUCCEED
2110 # check md5sum pgm finished
2111 local there=$(ps -o pid,comm hp $pid >/dev/null)
2113 error "Restore initiator does not exit"
2115 local rc=$(wait $pid)
2117 error "Restore initiator failed with $rc"
2121 run_test 36 "Move file during restore"
2128 for n in $(seq 1 $count); do
2129 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2131 echo "$count archive requests submitted"
2135 local stream_count=4
2136 local file_count=100
2138 local f=$DIR/$tdir/$tfile
2143 for i in $(seq 1 $file_count); do
2144 for p in $(seq 1 $stream_count); do
2145 fid=$(copy_file /etc/hosts $f.$p.$i)
2149 # to be sure wait_all_done will not be mislead by previous tests
2151 wait_for_grace_delay
2153 # start archive streams in background (archive files in parallel)
2154 for p in $(seq 1 $stream_count); do
2155 multi_archive $f.$p $file_count &
2158 echo -n "Wait for all requests being enqueued..."
2164 run_test 40 "Parallel archive requests"
2167 # test needs a running copytool
2171 local f=$DIR/$tdir/$tfile
2172 local fid=$(copy_file /etc/motd $f 1)
2174 $LFS hsm_archive $f || error "could not archive file"
2175 wait_request_state $fid ARCHIVE SUCCEED
2176 check_hsm_flags $f "0x00000009"
2178 multiop_bg_pause $f O_c || error "multiop failed"
2182 client_up || client_up || true
2184 kill -USR1 $MULTIPID
2185 wait $MULTIPID || error "multiop close failed"
2187 check_hsm_flags $f "0x0000000b"
2191 run_test 52 "Opened for write file on an evicted client should be set dirty"
2194 # test needs a running copytool
2198 local f=$DIR/$tdir/$tfile
2199 local fid=$(copy_file /etc/motd $f 1)
2201 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2202 error "could not archive file"
2203 wait_request_state $fid ARCHIVE SUCCEED
2204 check_hsm_flags $f "0x00000009"
2206 multiop_bg_pause $f o_c || error "multiop failed"
2210 client_up || client_up || true
2212 kill -USR1 $MULTIPID
2213 wait $MULTIPID || error "multiop close failed"
2215 check_hsm_flags $f "0x00000009"
2219 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2222 # test needs a running copytool
2226 local f=$DIR/$tdir/$tfile
2227 local fid=$(make_small $f)
2229 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2230 error "could not archive file"
2231 wait_request_state $fid ARCHIVE STARTED
2233 check_hsm_flags $f "0x00000001"
2235 # Avoid coordinator resending this request as soon it has failed.
2240 wait_request_state $fid ARCHIVE FAILED
2242 check_hsm_flags $f "0x00000003"
2247 run_test 54 "Write during an archive cancels it"
2250 # test needs a running copytool
2254 local f=$DIR/$tdir/$tfile
2255 local fid=$(make_small $f)
2257 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2258 error "could not archive file"
2259 wait_request_state $fid ARCHIVE STARTED
2261 check_hsm_flags $f "0x00000001"
2263 # Avoid coordinator resending this request as soon it has failed.
2266 $TRUNCATE $f 1024 || error "truncate failed"
2268 wait_request_state $fid ARCHIVE FAILED
2270 check_hsm_flags $f "0x00000003"
2275 run_test 55 "Truncate during an archive cancels it"
2278 # test needs a running copytool
2282 local f=$DIR/$tdir/$tfile
2283 local fid=$(make_large_for_progress $f)
2285 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2286 error "could not archive file"
2287 wait_request_state $fid ARCHIVE STARTED
2289 check_hsm_flags $f "0x00000001"
2291 # Change metadata and sync to be sure we are not changing only
2296 wait_request_state $fid ARCHIVE SUCCEED
2298 check_hsm_flags $f "0x00000009"
2302 run_test 56 "Setattr during an archive is ok"
2305 # Need one client for I/O, one for request
2306 needclients 2 || return 0
2308 # test needs a running copytool
2312 local f=$DIR/$tdir/test_archive_remote
2313 # Create a file on a remote node
2314 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2315 "count=2 conv=fsync"
2318 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2319 error "hsm_archive failed"
2320 local fid=$(path2fid $f)
2321 wait_request_state $fid ARCHIVE SUCCEED
2323 # Release and implicit restore it
2324 do_node $CLIENT2 "$LFS hsm_release $f" ||
2325 error "hsm_release failed"
2326 do_node $CLIENT2 "md5sum $f" ||
2327 error "hsm_restore failed"
2329 wait_request_state $fid RESTORE SUCCEED
2333 run_test 57 "Archive a file with dirty cache on another node"
2335 truncate_released_file() {
2339 local sz=$(stat -c %s $src_file)
2340 local f=$DIR/$tdir/$tfile
2341 local fid=$(copy_file $1 $f)
2345 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2346 error "could not archive file"
2347 wait_request_state $fid ARCHIVE SUCCEED
2349 $LFS hsm_release $f || error "could not release file"
2351 $TRUNCATE $f $trunc_to || error "truncate failed"
2354 local sz1=$(stat -c %s $f)
2355 [[ $sz1 == $trunc_to ]] ||
2356 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2359 check_hsm_flags $f "0x0000000b"
2361 local state=$(get_request_state $fid RESTORE)
2362 [[ "$state" == "SUCCEED" ]] ||
2363 error "truncate $sz does not trig restore, state = $state"
2365 $TRUNCATE $ref $trunc_to
2366 cmp $ref $f || error "file data wrong after truncate"
2372 # test needs a running copytool
2377 local sz=$(stat -c %s /etc/passwd)
2379 echo "truncate up from $sz to $((sz*2))"
2380 truncate_released_file /etc/passwd $((sz*2))
2382 echo "truncate down from $sz to $((sz/2))"
2383 truncate_released_file /etc/passwd $((sz/2))
2385 echo "truncate to 0"
2386 truncate_released_file /etc/passwd 0
2390 run_test 58 "Truncate a released file will trigger restore"
2395 local f=$DIR/$tdir/$tfile
2396 local FILELIST=/tmp/filelist.txt
2400 for i in $(seq 1 $file_count); do
2401 fid=$(copy_file /etc/hosts $f.$i)
2402 echo $f.$i >> $FILELIST
2405 # to be sure wait_all_done will not be mislead by previous tests
2407 wait_for_grace_delay
2408 $LFS hsm_archive --filelist $FILELIST ||
2409 error "cannot archive a file list"
2411 $LFS hsm_release --filelist $FILELIST ||
2412 error "cannot release a file list"
2413 $LFS hsm_restore --filelist $FILELIST ||
2414 error "cannot restore a file list"
2418 run_test 90 "Archive/restore a file list"
2420 double_verify_reset_hsm_param() {
2422 echo "Testing $HSM_PARAM.$p"
2423 local val=$(get_hsm_param $p)
2425 local val2=$(($val * 2))
2426 set_hsm_param $p $val2
2427 val=$(get_hsm_param $p)
2428 [[ $val == $val2 ]] ||
2429 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2430 echo "Set $p to 0 must failed"
2434 set_hsm_param $p $save
2436 if [[ $rc == 0 ]]; then
2437 error "we must not be able to set $HSM_PARAM.$p to 0"
2442 double_verify_reset_hsm_param loop_period
2443 double_verify_reset_hsm_param grace_delay
2444 double_verify_reset_hsm_param active_request_timeout
2445 double_verify_reset_hsm_param max_requests
2446 double_verify_reset_hsm_param default_archive_id
2448 run_test 100 "Set coordinator /proc tunables"
2455 run_test 102 "Verify coordinator control"
2458 # test needs a running copytool
2465 for i in $(seq 1 20); do
2466 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2468 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2472 echo "Current requests"
2473 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2474 $HSM_PARAM.actions |\
2475 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2477 [[ -z "$res" ]] || error "Some request have not been canceled"
2481 run_test 103 "Purge all requests"
2486 # test needs a running copytool
2490 local f=$DIR/$tdir/$tfile
2491 local fid=$(make_large_for_progress $f)
2492 # if cdt is on, it can serve too quickly the request
2494 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2495 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2496 $HSM_PARAM.actions |\
2497 grep $fid | cut -f16 -d=")
2500 [[ "$data1" == "$DATAHEX" ]] ||
2501 error "Data field in records is ($data1) and not ($DATAHEX)"
2505 run_test 104 "Copy tool data field"
2512 for i in $(seq -w 1 10); do
2513 cp /etc/passwd $DIR/$tdir/$i
2514 $LFS hsm_archive $DIR/$tdir/$i
2516 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2517 $HSM_PARAM.actions |\
2518 grep WAITING | wc -l")
2521 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2522 $HSM_PARAM.actions |\
2523 grep WAITING | wc -l")
2526 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2527 error "Requests count after shutdown $reqcnt2 != "\
2528 "before shutdown $reqcnt1"
2530 run_test 105 "Restart of coordinator"
2533 # test needs a running copytool
2536 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2537 get_client_uuid $MOUNT | cut -d' ' -f2)
2538 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2541 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2542 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2544 [[ -z "$agent" ]] ||
2545 error "My uuid $uuid still found in agent list,"\
2546 " after copytool shutdown"
2548 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2551 [[ ! -z "$agent" ]] ||
2552 error "My uuid $uuid not found in agent list after"\
2555 run_test 106 "Copytool register/unregister"
2558 # test needs a running copytool
2560 # create and archive file
2562 local f1=$DIR/$tdir/$tfile
2563 local fid=$(copy_file /etc/passwd $f1)
2564 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2565 wait_request_state $fid ARCHIVE SUCCEED
2566 # shutdown and restart MDS
2568 # check the copytool still gets messages from MDT
2569 local f2=$DIR/$tdir/2
2570 local fid=$(copy_file /etc/passwd $f2)
2571 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2572 # main check of this sanity: this request MUST succeed
2573 wait_request_state $fid ARCHIVE SUCCEED
2576 run_test 107 "Copytool re-register after MDS restart"
2578 policy_set_and_test()
2582 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2583 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2584 [[ "$policy" == "$target" ]] ||
2585 error "Wrong policy after '$change': '$policy' != '$target'"
2589 # to force default policy setting if error
2590 CDT_POLICY_HAD_CHANGED=true
2592 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2593 local default="NonBlockingRestore [NoRetryAction]"
2594 [[ "$policy" == "$default" ]] ||
2595 error "default policy has changed,"\
2596 " '$policy' != '$default' update the test"
2597 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2598 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2599 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2600 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2601 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2602 # useless bacause we know but safer for futur changes to use real value
2603 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2604 echo "Next set_param must failed"
2605 policy_set_and_test "wrong" "$policy"
2608 echo "Back to default policy"
2609 cdt_set_sanity_policy
2611 run_test 109 "Policy display/change"
2614 # test needs a running copytool
2619 copy2archive /etc/passwd $tdir/$tfile
2621 local f=$DIR/$tdir/$tfile
2622 import_file $tdir/$tfile $f
2623 local fid=$(path2fid $f)
2625 cdt_set_non_blocking_restore
2630 wait_request_state $fid RESTORE SUCCEED
2631 cdt_clear_non_blocking_restore
2635 error "md5sum returns $st != 1, "\
2636 "should also perror ENODATA (No data available)"
2640 run_test 110a "Non blocking restore policy (import case)"
2643 # test needs a running copytool
2647 local f=$DIR/$tdir/$tfile
2648 local fid=$(copy_file /etc/passwd $f)
2649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2650 wait_request_state $fid ARCHIVE SUCCEED
2653 cdt_set_non_blocking_restore
2658 wait_request_state $fid RESTORE SUCCEED
2659 cdt_clear_non_blocking_restore
2663 error "md5sum returns $st != 1, "\
2664 "should also perror ENODATA (No data available)"
2668 run_test 110b "Non blocking restore policy (release case)"
2671 # test needs a running copytool
2675 copy2archive /etc/passwd $tdir/$tfile
2677 local f=$DIR/$tdir/$tfile
2679 import_file $tdir/$tfile $f
2680 local fid=$(path2fid $f)
2684 copytool_remove_backend $fid
2687 wait_request_state $fid RESTORE FAILED
2694 [[ $st == 0 ]] || error "Restore does not failed"
2698 run_test 111a "No retry policy (import case), restore will error"\
2699 " (No such file or directory)"
2702 # test needs a running copytool
2706 local f=$DIR/$tdir/$tfile
2707 local fid=$(copy_file /etc/passwd $f)
2709 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2710 wait_request_state $fid ARCHIVE SUCCEED
2713 copytool_remove_backend $fid
2716 wait_request_state $fid RESTORE FAILED
2723 [[ $st == 0 ]] || error "Restore does not failed"
2727 run_test 111b "No retry policy (release case), restore will error"\
2728 " (No such file or directory)"
2731 # test needs a running copytool
2735 local f=$DIR/$tdir/$tfile
2736 local fid=$(copy_file /etc/passwd $f)
2738 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2739 local l=$($LFS hsm_action $f)
2741 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2745 wait_request_state $fid ARCHIVE SUCCEED
2748 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2752 run_test 112 "State of recorded request"
2755 # test needs a running copytool
2759 local f=$DIR/$tdir/$tfile
2760 local fid=$(make_large_for_cancel $f)
2761 # test with cdt on is made in test_221
2763 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2766 wait_request_state $fid ARCHIVE CANCELED
2767 wait_request_state $fid CANCEL SUCCEED
2771 run_test 200 "Register/Cancel archive"
2774 # test needs a running copytool
2778 local f=$DIR/$tdir/$tfile
2779 make_archive $tdir/$tfile
2780 import_file $tdir/$tfile $f
2781 local fid=$(path2fid $f)
2783 # test with cdt on is made in test_222
2788 wait_request_state $fid RESTORE CANCELED
2789 wait_request_state $fid CANCEL SUCCEED
2793 run_test 201 "Register/Cancel restore"
2796 # test needs a running copytool
2800 local f=$DIR/$tdir/$tfile
2801 local fid=$(make_large_for_progress $f)
2802 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2803 wait_request_state $fid ARCHIVE SUCCEED
2809 wait_request_state $fid REMOVE CANCELED
2813 run_test 202 "Register/Cancel remove"
2816 # test needs a running copytool
2821 local f=$DIR/$tdir/$tfile
2822 local fid=$(copy_file /etc/passwd $f)
2826 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2827 wait_request_state $fid ARCHIVE SUCCEED
2829 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2833 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2837 run_test 220 "Changelog for archive"
2840 # test needs a running copytool
2845 local f=$DIR/$tdir/$tfile
2846 local fid=$(make_large_for_cancel $f)
2850 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2851 wait_request_state $fid ARCHIVE STARTED
2853 wait_request_state $fid ARCHIVE CANCELED
2854 wait_request_state $fid CANCEL 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 221 "Changelog for archive canceled"
2866 # test needs a running copytool
2870 copy2archive /etc/passwd $tdir/$tfile
2872 local f=$DIR/$tdir/$tfile
2873 import_file $tdir/$tfile $f
2874 local fid=$(path2fid $f)
2879 wait_request_state $fid RESTORE SUCCEED
2881 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2884 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2888 run_test 222a "Changelog for explicit restore"
2891 # test needs a running copytool
2895 local f=$DIR/$tdir/$tfile
2896 local fid=$(copy_file /etc/passwd $f)
2899 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2900 wait_request_state $fid ARCHIVE SUCCEED
2905 wait_request_state $fid RESTORE SUCCEED
2907 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2910 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2914 run_test 222b "Changelog for implicit restore"
2917 # test needs a running copytool
2922 local f=$DIR/$tdir/$tfile
2923 make_archive $tdir/$tfile
2927 import_file $tdir/$tfile $f
2928 local fid=$(path2fid $f)
2931 wait_request_state $fid RESTORE STARTED
2933 wait_request_state $fid RESTORE CANCELED
2934 wait_request_state $fid CANCEL SUCCEED
2936 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2939 [[ $flags == $target ]] ||
2940 error "Changelog flag is $flags not $target"
2944 run_test 223a "Changelog for restore canceled (import case)"
2947 # test needs a running copytool
2952 local f=$DIR/$tdir/$tfile
2953 local fid=$(make_large_for_progress $f)
2956 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2957 wait_request_state $fid ARCHIVE SUCCEED
2960 wait_request_state $fid RESTORE STARTED
2962 wait_request_state $fid RESTORE CANCELED
2963 wait_request_state $fid CANCEL SUCCEED
2965 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2968 [[ $flags == $target ]] ||
2969 error "Changelog flag is $flags not $target"
2973 run_test 223b "Changelog for restore canceled (release case)"
2976 # test needs a running copytool
2981 local f=$DIR/$tdir/$tfile
2982 local fid=$(copy_file /etc/passwd $f)
2985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2986 wait_request_state $fid ARCHIVE SUCCEED
2989 wait_request_state $fid REMOVE SUCCEED
2991 local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2994 [[ $flags == $target ]] ||
2995 error "Changelog flag is $flags not $target"
2999 run_test 224 "Changelog for remove"
3002 # test needs a running copytool
3005 # test is not usable because remove request is too fast
3006 # so it is always finished before cancel can be done ...
3007 echo "Test disabled"
3012 local f=$DIR/$tdir/$tfile
3013 local fid=$(make_large_for_progress $f)
3016 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3017 wait_request_state $fid ARCHIVE SUCCEED
3019 # if cdt is on, it can serve too quickly the request
3024 wait_request_state $fid REMOVE CANCELED
3025 wait_request_state $fid CANCEL SUCCEED
3027 flags=$(changelog_get_flags $MDT0 RENME $fid2)
3028 local flags=$($LFS changelog $MDT0 | grep HSM | grep $fid | tail -1 |
3032 [[ $flags == $target ]] ||
3033 error "Changelog flag is $flags not $target"
3037 run_test 225 "Changelog for remove canceled"
3040 # test needs a running copytool
3045 local f1=$DIR/$tdir/$tfile-1
3046 local f2=$DIR/$tdir/$tfile-2
3047 local f3=$DIR/$tdir/$tfile-3
3048 local fid1=$(copy_file /etc/passwd $f1)
3049 local fid2=$(copy_file /etc/passwd $f2)
3050 copy_file /etc/passwd $f3
3053 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3054 wait_request_state $fid1 ARCHIVE SUCCEED
3056 $LFS hsm_archive $f2
3057 wait_request_state $fid2 ARCHIVE SUCCEED
3059 rm $f1 || error "rm $f1 failed"
3061 local flags=$(changelog_get_flags $MDT0 UNLNK $fid1)
3064 [[ $flags == $target ]] ||
3065 error "Changelog flag is $flags not $target"
3067 mv $f3 $f2 || error "mv $f3 $f2 failed"
3069 flags=$(changelog_get_flags $MDT0 RENME $fid2)
3072 [[ $flags == $target ]] ||
3073 error "Changelog flag is $flags not $target"
3077 run_test 226 "changelog for last rm/mv with exiting archive"
3079 check_flags_changes() {
3087 $LFS hsm_set --$hsm_flag $f ||
3088 error "Cannot set $hsm_flag on $f"
3089 local flags=($(changelog_get_flags $MDT0 HSM $fid))
3090 local seen=${#flags[*]}
3092 [[ $seen == $cnt ]] ||
3093 error "set $hsm_flag: Changelog events $seen != $cnt"
3094 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3095 error "set $hsm_flag: Changelog flags are "\
3096 "${flags[$((cnt - 1))]} not $target"
3098 $LFS hsm_clear --$hsm_flag $f ||
3099 error "Cannot clear $hsm_flag on $f"
3100 flags=($(changelog_get_flags $MDT0 HSM $fid))
3103 [[ $cnt == $seen ]] ||
3104 error "clear $hsm_flag: Changelog events $seen != $cnt"
3106 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3107 error "clear $hsm_flag: Changelog flag is "\
3108 "${flags[$((cnt - 1))]} not $target"
3112 # test needs a running copytool
3119 for i in norelease noarchive exists archived
3121 local f=$DIR/$tdir/$tfile-$i
3122 local fid=$(copy_file /etc/passwd $f)
3123 check_flags_changes $f $fid $i 0 1
3126 f=$DIR/$tdir/$tfile---lost
3127 fid=$(copy_file /etc/passwd $f)
3128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3129 wait_request_state $fid ARCHIVE SUCCEED
3130 check_flags_changes $f $fid lost 3 1
3134 run_test 227 "changelog when explicit setting of HSM flags"
3137 # test needs a running copytool
3140 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3141 error "creating $DIR/$tfile"
3142 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3143 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3145 $LFS hsm_release $DIR/$tfile
3146 check_hsm_flags $DIR/$tfile "0x0000000d"
3148 filefrag $DIR/$tfile | grep " 1 extent found" ||
3149 error "filefrag on released file must return only one extent"
3151 # only newer versions of cp detect sparse files by stat/FIEMAP
3153 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3154 error "copying $DIR/$tfile"
3155 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3157 $LFS hsm_release $DIR/$tfile
3158 check_hsm_flags $DIR/$tfile "0x0000000d"
3162 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3164 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3165 error "comparing untarred $DIR/$tfile"
3169 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3172 # test needs a running copytool
3176 local maxrequest=$(get_hsm_param max_requests)
3177 local rqcnt=$(($maxrequest * 3))
3181 for i in $(seq -w 1 $rqcnt); do
3183 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3185 # we do it in 2 steps, so all requests arrive at the same time
3186 for i in $(seq -w 1 $rqcnt); do
3187 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3192 while [[ $cnt != 0 || $wt != 0 ]]; do
3194 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3195 $HSM_PARAM.actions |\
3196 grep STARTED | grep -v CANCEL | wc -l")
3197 [[ $cnt -le $maxrequest ]] ||
3198 error "$cnt > $maxrequest too many started requests"
3199 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3200 $HSM_PARAM.actions |\
3201 grep WAITING | wc -l")
3202 echo "max=$maxrequest started=$cnt waiting=$wt"
3207 run_test 250 "Coordinator max request"
3210 # test needs a running copytool
3214 local f=$DIR/$tdir/$tfile
3215 local fid=$(make_large_for_cancel $f)
3218 # to have a short test
3219 local old_to=$(get_hsm_param active_request_timeout)
3220 set_hsm_param active_request_timeout 4
3221 # to be sure the cdt will wake up frequently so
3222 # it will be able to cancel the "old" request
3223 local old_loop=$(get_hsm_param loop_period)
3224 set_hsm_param loop_period 2
3227 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3228 wait_request_state $fid ARCHIVE STARTED
3230 wait_request_state $fid ARCHIVE CANCELED
3232 set_hsm_param active_request_timeout $old_to
3233 set_hsm_param loop_period $old_loop
3237 run_test 251 "Coordinator request timeout"
3240 # the only way to test ondisk conf is to restart MDS ...
3241 echo "Stop coordinator and remove coordinator state at mount"
3244 # clean on disk conf set by default
3245 cdt_clear_mount_state
3246 cdt_check_state stopped
3248 # check cdt still off after umount/remount
3250 cdt_check_state stopped
3252 echo "Set coordinator start at mount, and start coordinator"
3253 cdt_set_mount_state enabled
3256 cdt_check_state enabled
3258 # check cdt still on after umount/remount
3260 cdt_check_state enabled
3262 # we are back to original state (cdt started at mount)
3264 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3267 local ai=$(get_hsm_param default_archive_id)
3268 local new=$((ai + 1))
3270 set_hsm_param default_archive_id $new -P
3272 local res=$(get_hsm_param default_archive_id)
3275 set_hsm_param default_archive_id "" "-P -d"
3277 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3279 run_test 301 "HSM tunnable are persistent"
3282 local ai=$(get_hsm_param default_archive_id)
3283 local new=$((ai + 1))
3288 set_hsm_param default_archive_id $new -P
3292 cdt_check_state enabled
3294 local res=$(get_hsm_param default_archive_id)
3297 set_hsm_param default_archive_id "" "-P -d"
3299 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3301 run_test 302 "HSM tunnable are persistent when CDT is off"
3306 check_and_cleanup_lustre