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 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MCREATE=${MCREATE:-mcreate}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
50 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
51 # the following associated variables are added:
53 # AGTCOUNT: number of agents
54 # AGTDEV{N}: target HSM mount point (root path of the backend)
55 # agt{N}_HOST: hostname of the agent agt{N}
56 # SINGLEAGT: facet of the single agent
58 # The number of agents is initialized as the number of remote client nodes.
59 # By default, only single copytool is started on a remote client/agent. If there
60 # was no remote client, then the copytool will be started on the local client.
66 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
67 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
69 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
70 if [[ $CLIENTCOUNT -gt 1 ]] &&
71 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
72 skip_env "SHARED_DIRECTORY should be accessible"\
77 for n in $(seq $AGTCOUNT); do
78 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
79 agent=CLIENT$((n + 1))
80 if [[ -z "${!agent}" ]]; then
81 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
84 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
87 export SINGLEAGT=${SINGLEAGT:-agt1}
89 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
90 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
91 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
92 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
95 # The test only support up to 10 MDTs
96 MDT_PREFIX="mdt.$FSNAME-MDT000"
97 HSM_PARAM="${MDT_PREFIX}0.hsm"
99 # archive is purged at copytool setup
100 HSM_ARCHIVE_PURGE=true
103 # Get the backend root path for the given agent facet.
106 local dev=AGTDEV$(facet_number $facet)
111 # Stop copytool and unregister an existing changelog user.
115 cdt_set_sanity_policy
120 # get MDT device for each mdc
121 for mdtno in $(seq 1 $MDSCOUNT); do
122 local idx=$(($mdtno - 1))
123 MDT[$idx]=$($LCTL get_param -n \
124 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
125 awk '{gsub(/_UUID/,""); print $1}' | head -1)
129 search_and_kill_copytool() {
130 local agents=${1:-$(facet_active_host $SINGLEAGT)}
132 echo "Killing existing copytools on $agents"
133 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
137 local facet=${1:-$SINGLEAGT}
138 local lustre_mntpnt=${2:-$MOUNT}
140 local hsm_root=$(copytool_device $facet)
141 local agent=$(facet_active_host $facet)
143 if [[ -z "$arc_id" ]] &&
144 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
145 echo "Wakeup copytool $facet on $agent"
149 if $HSM_ARCHIVE_PURGE; then
150 echo "Purging archive on $agent"
151 do_facet $facet "rm -rf $hsm_root/*"
154 echo "Starting copytool $facet on $agent"
155 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
156 # bandwidth is limited to 1MB/s so the copy time is known and
157 # independent of hardware
158 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
159 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
160 cmd+=" --bandwidth 1 $lustre_mntpnt"
162 # Redirect the standard output and error to a log file which
163 # can be uploaded to Maloo.
164 local prefix=$TESTLOG_PREFIX
165 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
166 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
168 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
169 error "start copytool $facet on $agent failed"
175 local agents=${1:-$(facet_active_host $SINGLEAGT)}
181 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
183 echo "Copytool is stopped on $agents"
185 # clean all CDTs orphans requests from previous tests
186 # that would otherwise need to timeout to clear.
187 for mdtno in $(seq 1 $MDSCOUNT); do
189 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
190 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
192 # skip already stop[ed,ing] CDTs
193 echo $oldstate | grep stop && continue
195 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
196 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
198 error "mds${mdtno} cdt state is not stopped"
199 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
200 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
202 error "mds${mdtno} cdt state is not $oldstate"
207 local agents=${1:-$(facet_active_host $SINGLEAGT)}
209 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
210 echo "Copytool is suspended on $agents"
213 copytool_remove_backend() {
215 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
216 echo "Remove from backend: $fid = $be"
217 do_facet $SINGLEAGT rm -f $be
221 do_facet $SINGLEAGT \
222 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
223 --import $1 $2 $MOUNT" ||
224 error "import of $1 to $2 failed"
228 local file=$HSM_ARCHIVE/$1
229 do_facet $SINGLEAGT mkdir -p $(dirname $file)
230 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
231 error "cannot create $file"
235 local file=$HSM_ARCHIVE/$2
236 do_facet $SINGLEAGT mkdir -p $(dirname $file)
237 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
246 if [[ "$value" != "" ]]; then
249 for mdtno in $(seq 1 $MDSCOUNT); do
250 local idx=$(($mdtno - 1))
251 local facet=mds${mdtno}
252 # if $arg include -P option, run 1 set_param per MDT on the MGS
253 # else, run set_param on each MDT
254 [[ $arg = *"-P"* ]] && facet=mgs
255 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
256 [[ $? != 0 ]] && rc=1
266 for mdtno in $(seq 1 $MDSCOUNT); do
267 local idx=$(($mdtno - 1))
268 wait_result mds${mdtno} \
269 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
271 error "$key state is not '$target' on mds${mdtno}"
278 for mdtno in $(seq 1 $MDSCOUNT); do
279 local idx=$(($mdtno - 1))
280 local cl_user=$(do_facet mds${mdtno} $LCTL \
281 --device ${MDT[$idx]} \
282 changelog_register -n)
284 do_facet mds${mdtno} lctl set_param \
285 mdd.${MDT[$idx]}.changelog_mask="+hsm"
286 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
290 changelog_cleanup() {
292 for mdtno in $(seq 1 $MDSCOUNT); do
293 local idx=$(($mdtno - 1))
294 [[ -z ${CL_USERS[$idx]} ]] && continue
295 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
296 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
297 changelog_deregister ${CL_USERS[$idx]}
302 changelog_get_flags() {
307 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
312 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
320 mdts_set_param "$opt -n" "hsm.$param" "$value"
327 mdts_set_param "" hsm_control "$cmd"
328 mdts_check_param hsm_control "$target" 10
331 cdt_set_sanity_policy() {
332 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
335 mdts_set_param "" hsm.policy "+NRA"
336 mdts_set_param "" hsm.policy "-NBR"
337 CDT_POLICY_HAD_CHANGED=
342 mdts_set_param "" hsm.policy "+NRA"
343 CDT_POLICY_HAD_CHANGED=true
346 cdt_clear_no_retry() {
347 mdts_set_param "" hsm.policy "-NRA"
348 CDT_POLICY_HAD_CHANGED=true
351 cdt_set_non_blocking_restore() {
352 mdts_set_param "" hsm.policy "+NBR"
353 CDT_POLICY_HAD_CHANGED=true
356 cdt_clear_non_blocking_restore() {
357 mdts_set_param "" hsm.policy "-NBR"
358 CDT_POLICY_HAD_CHANGED=true
361 cdt_clear_mount_state() {
362 mdts_set_param "-P -d" hsm_control ""
365 cdt_set_mount_state() {
366 mdts_set_param "-P" hsm_control "$1"
370 mdts_check_param hsm_control "$1" 20
374 set_test_state disabled disabled
378 set_test_state enabled enabled
382 set_test_state shutdown stopped
386 set_test_state purge enabled
392 cdt_set_sanity_policy
396 local client_count=$1
397 if [[ $CLIENTCOUNT -lt $client_count ]]; then
398 skip "Need $client_count or more clients, have $CLIENTCOUNT"
405 $LFS path2fid $1 | tr -d '[]'
412 if [[ $u == "user" ]]; then
413 local st=$($RUNAS $LFS hsm_state $f)
415 local st=$($LFS hsm_state $f)
419 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
421 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
425 get_hsm_archive_id() {
427 local st=$($LFS hsm_state $f)
428 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
430 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
439 local st=$(get_hsm_flags $f)
440 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
443 check_hsm_flags_user() {
447 local st=$(get_hsm_flags $f user)
448 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
460 if [[ "$3" != 1 ]]; then
464 cp $1 $f || error "cannot copy $1 to $f"
465 path2fid $f || error "cannot get fid on $f"
469 local file2=${1/$DIR/$DIR2}
470 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
471 error "cannot create $file2"
472 path2fid $1 || error "cannot get fid on $1"
475 cleanup_large_files() {
476 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
478 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
481 make_large_for_striping() {
482 local file2=${1/$DIR/$DIR2}
483 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
487 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
488 error "cannot create $file2"
489 path2fid $1 || error "cannot get fid on $1"
492 make_large_for_progress() {
493 local file2=${1/$DIR/$DIR2}
497 # big file is large enough, so copy time is > 30s
498 # so copytool make 1 progress
499 # size is not a multiple of 1M to avoid stripe
501 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
502 error "cannot create $file2"
503 path2fid $1 || error "cannot get fid on $1"
506 make_large_for_progress_aligned() {
507 local file2=${1/$DIR/$DIR2}
511 # big file is large enough, so copy time is > 30s
512 # so copytool make 1 progress
513 # size is a multiple of 1M to have stripe
515 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
516 error "cannot create $file2"
517 path2fid $1 || error "cannot get fid on $1"
520 make_large_for_cancel() {
521 local file2=${1/$DIR/$DIR2}
525 # Copy timeout is 100s. 105MB => 105s
526 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
527 error "cannot create $file2"
528 path2fid $1 || error "cannot get fid on $1"
534 wait_update --verbose $(facet_active_host $facet) "$@"
537 wait_request_state() {
542 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
543 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
545 wait_result $SINGLEMDS "$cmd" $state 100 ||
546 error "request on $fid is not $state"
549 get_request_state() {
553 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
554 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
557 get_request_count() {
561 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
562 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
568 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
569 cmd+=" | egrep 'WAITING|STARTED'"
571 wait_result $SINGLEMDS "$cmd" "" $timeout ||
572 error "requests did not complete"
575 wait_for_grace_delay() {
576 local val=$(get_hsm_param grace_delay)
580 # populate MDT device array
586 # cleanup from previous bad setup
587 search_and_kill_copytool
589 # for recovery tests, coordinator needs to be started at mount
591 # the lustre conf must be without hsm on (like for sanity.sh)
592 echo "Set HSM on and start"
593 cdt_set_mount_state enabled
594 cdt_check_state enabled
596 echo "Start copytool"
599 echo "Set sanity-hsm HSM policy"
600 cdt_set_sanity_policy
602 # finished requests are quickly removed from list
603 set_hsm_param grace_delay 10
609 local f=$DIR/$tdir/$tfile
613 check_hsm_flags_user $f "0x00000000"
615 $RUNAS $LFS hsm_set --norelease $f ||
616 error "user could not change hsm flags"
617 check_hsm_flags_user $f "0x00000010"
619 $RUNAS $LFS hsm_clear --norelease $f ||
620 error "user could not clear hsm flags"
621 check_hsm_flags_user $f "0x00000000"
623 # User could not change those flags...
624 $RUNAS $LFS hsm_set --exists $f &&
625 error "user should not set this flag"
626 check_hsm_flags_user $f "0x00000000"
629 $LFS hsm_set --exists $f ||
630 error "root could not change hsm flags"
631 check_hsm_flags_user $f "0x00000001"
633 $LFS hsm_clear --exists $f ||
634 error "root could not clear hsm state"
635 check_hsm_flags_user $f "0x00000000"
638 run_test 1 "lfs hsm flags root/non-root access"
642 local f=$DIR/$tdir/$tfile
644 # New files are not dirty
645 check_hsm_flags $f "0x00000000"
647 # For test, we simulate an archived file.
648 $LFS hsm_set --exists $f || error "user could not change hsm flags"
649 check_hsm_flags $f "0x00000001"
651 # chmod do not put the file dirty
652 chmod 600 $f || error "could not chmod test file"
653 check_hsm_flags $f "0x00000001"
655 # chown do not put the file dirty
656 chown $RUNAS_ID $f || error "could not chown test file"
657 check_hsm_flags $f "0x00000001"
659 # truncate put the file dirty
660 $TRUNCATE $f 1 || error "could not truncate test file"
661 check_hsm_flags $f "0x00000003"
663 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
664 check_hsm_flags $f "0x00000001"
666 run_test 2 "Check file dirtyness when doing setattr"
672 # New files are not dirty
674 check_hsm_flags $f "0x00000000"
676 # For test, we simulate an archived file.
677 $LFS hsm_set --exists $f ||
678 error "user could not change hsm flags"
679 check_hsm_flags $f "0x00000001"
681 # Reading a file, does not set dirty
682 cat $f > /dev/null || error "could not read file"
683 check_hsm_flags $f "0x00000001"
685 # Open for write without modifying data, does not set dirty
686 openfile -f O_WRONLY $f || error "could not open test file"
687 check_hsm_flags $f "0x00000001"
689 # Append to a file sets it dirty
690 cp -p /etc/passwd $f.append || error "could not create file"
691 $LFS hsm_set --exists $f.append ||
692 error "user could not change hsm flags"
693 dd if=/etc/passwd of=$f.append bs=1 count=3\
694 conv=notrunc oflag=append status=noxfer ||
695 error "could not append to test file"
696 check_hsm_flags $f.append "0x00000003"
698 # Modify a file sets it dirty
699 cp -p /etc/passwd $f.modify || error "could not create file"
700 $LFS hsm_set --exists $f.modify ||
701 error "user could not change hsm flags"
702 dd if=/dev/zero of=$f.modify bs=1 count=3\
703 conv=notrunc status=noxfer ||
704 error "could not modify test file"
705 check_hsm_flags $f.modify "0x00000003"
707 # Open O_TRUNC sets dirty
708 cp -p /etc/passwd $f.trunc || error "could not create file"
709 $LFS hsm_set --exists $f.trunc ||
710 error "user could not change hsm flags"
711 cp /etc/group $f.trunc || error "could not override a file"
712 check_hsm_flags $f.trunc "0x00000003"
714 # Mmapped a file sets dirty
715 cp -p /etc/passwd $f.mmap || error "could not create file"
716 $LFS hsm_set --exists $f.mmap ||
717 error "user could not change hsm flags"
718 multiop $f.mmap OSMWUc || error "could not mmap a file"
719 check_hsm_flags $f.mmap "0x00000003"
721 run_test 3 "Check file dirtyness when opening for write"
725 local f=$DIR/$tdir/$tfile
726 local fid=$(make_small $f)
729 local st=$(get_request_state $fid CANCEL)
730 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
732 run_test 4 "Useless cancel must not be registered"
735 # test needs a running copytool
739 local f=$DIR/$tdir/$tfile
740 local fid=$(copy_file /etc/passwd $f)
742 wait_request_state $fid ARCHIVE SUCCEED
744 check_hsm_flags $f "0x00000009"
748 run_test 8 "Test default archive number"
752 local f=$DIR/$tdir/$tfile
753 local fid=$(copy_file /etc/passwd $f)
754 # we do not use the default one to be sure
755 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
757 copytool_setup $SINGLEAGT $MOUNT $new_an
758 $LFS hsm_archive --archive $new_an $f
759 wait_request_state $fid ARCHIVE SUCCEED
761 check_hsm_flags $f "0x00000009"
765 run_test 9 "Use of explict archive number, with dedicated copytool"
768 needclients 3 || return 0
774 copytool_cleanup $(comma_list $(agts_nodes))
776 # start all of the copytools
777 for n in $(seq $AGTCOUNT); do
781 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
784 for n in $(seq $AGTCOUNT); do
785 file=$DIR/$tdir/$tfile.$n
786 fid=$(make_small $file)
788 $LFS hsm_archive $file || error "could not archive file $file"
789 wait_request_state $fid ARCHIVE SUCCEED
790 check_hsm_flags $file "0x00000009"
794 copytool_cleanup $(comma_list $(agts_nodes))
796 run_test 9a "Multiple remote agents"
799 # test needs a running copytool
802 mkdir -p $DIR/$tdir/d1
803 local f=$DIR/$tdir/$tfile
804 local fid=$(copy_file /etc/hosts $f)
805 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
806 error "hsm_archive failed"
807 wait_request_state $fid ARCHIVE SUCCEED
809 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
810 error "fid $fid not in archive $HSM_ARCHIVE"
811 echo "Verifying content"
812 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
813 echo "Verifying hsm state "
814 check_hsm_flags $f "0x00000009"
816 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
817 local st=$(get_hsm_archive_id $f)
818 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
819 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
824 run_test 10a "Archive a file"
827 # test needs a running copytool
831 local f=$DIR/$tdir/$tfile
832 local fid=$(copy_file /etc/hosts $f)
833 $LFS hsm_archive $f || error "archive request failed"
834 wait_request_state $fid ARCHIVE SUCCEED
836 $LFS hsm_archive $f || error "archive of non dirty file failed"
837 local cnt=$(get_request_count $fid ARCHIVE)
838 [[ "$cnt" == "1" ]] ||
839 error "archive of non dirty file must not make a request"
843 run_test 10b "Archive of non dirty file must work without doing request"
846 # test needs a running copytool
850 local f=$DIR/$tdir/$tfile
851 local fid=$(copy_file /etc/hosts $f)
852 $LFS hsm_set --noarchive $f
853 $LFS hsm_archive $f && error "archive a noarchive file must fail"
857 run_test 10c "Check forbidden archive"
860 # test needs a running copytool
864 local f=$DIR/$tdir/$tfile
865 local fid=$(copy_file /etc/hosts $f)
866 $LFS hsm_archive $f || error "cannot archive $f"
867 wait_request_state $fid ARCHIVE SUCCEED
869 local ar=$(get_hsm_archive_id $f)
870 local dflt=$(get_hsm_param default_archive_id)
871 [[ $ar == $dflt ]] ||
872 error "archived file is not on default archive: $ar != $dflt"
876 run_test 10d "Archive a file on the default archive id"
880 copy2archive /etc/hosts $tdir/$tfile
881 local f=$DIR/$tdir/$tfile
883 import_file $tdir/$tfile $f
884 echo -n "Verifying released state: "
885 check_hsm_flags $f "0x0000000d"
887 local LSZ=$(stat -c "%s" $f)
888 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
890 echo "Verifying imported size $LSZ=$ASZ"
891 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
892 echo -n "Verifying released pattern: "
893 local PTRN=$($GETSTRIPE -L $f)
895 [[ $PTRN == 80000001 ]] || error "Is not released"
896 local fid=$(path2fid $f)
897 echo "Verifying new fid $fid in archive"
899 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
900 error "fid $fid not in archive $HSM_ARCHIVE"
902 run_test 11 "Import a file"
905 # test needs a running copytool
909 copy2archive /etc/hosts $tdir/$tfile
911 local f=$DIR/$tdir/$tfile
912 import_file $tdir/$tfile $f
913 local f=$DIR2/$tdir/$tfile
914 echo "Verifying released state: "
915 check_hsm_flags $f "0x0000000d"
917 local fid=$(path2fid $f)
919 wait_request_state $fid RESTORE SUCCEED
921 echo "Verifying file state: "
922 check_hsm_flags $f "0x00000009"
924 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
926 [[ $? -eq 0 ]] || error "Restored file differs"
930 run_test 12a "Restore an imported file explicitly"
933 # test needs a running copytool
937 copy2archive /etc/hosts $tdir/$tfile
939 local f=$DIR/$tdir/$tfile
940 import_file $tdir/$tfile $f
941 echo "Verifying released state: "
942 check_hsm_flags $f "0x0000000d"
944 cat $f > /dev/null || error "File read failed"
946 echo "Verifying file state after restore: "
947 check_hsm_flags $f "0x00000009"
949 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
951 [[ $? -eq 0 ]] || error "Restored file differs"
955 run_test 12b "Restore an imported file implicitly"
958 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
960 # test needs a running copytool
964 local f=$DIR/$tdir/$tfile
965 $LFS setstripe -c 2 $f
966 local fid=$(make_large_for_striping $f)
967 local FILE_CRC=$(md5sum $f)
969 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
970 wait_request_state $fid ARCHIVE SUCCEED
971 $LFS hsm_release $f || error "release $f failed"
973 echo "$FILE_CRC" | md5sum -c
975 [[ $? -eq 0 ]] || error "Restored file differs"
979 run_test 12c "Restore a file with stripe of 2"
982 # test needs a running copytool
987 local f=$DIR/$tdir/$tfile
988 local fid=$(copy_file /etc/hosts $f)
989 $LFS hsm_restore $f || error "restore of non archived file failed"
990 local cnt=$(get_request_count $fid RESTORE)
991 [[ "$cnt" == "0" ]] ||
992 error "restore non archived must not make a request"
993 $LFS hsm_archive $f ||
994 error "archive request failed"
995 wait_request_state $fid ARCHIVE SUCCEED
996 $LFS hsm_restore $f ||
997 error "restore of non released file failed"
998 local cnt=$(get_request_count $fid RESTORE)
999 [[ "$cnt" == "0" ]] ||
1000 error "restore a non dirty file must not make a request"
1004 run_test 12d "Restore of a non archived, non released file must work"\
1005 " without doing request"
1008 # test needs a running copytool
1011 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1012 local f=$DIR/$tdir/$tfile
1013 local fid=$(copy_file /etc/hosts $f)
1014 $LFS hsm_archive $f || error "archive request failed"
1015 wait_request_state $fid ARCHIVE SUCCEED
1018 cat /etc/hosts >> $f
1022 $LFS hsm_restore $f && error "restore a dirty file must fail"
1026 run_test 12e "Check forbidden restore"
1029 # test needs a running copytool
1033 local f=$DIR/$tdir/$tfile
1034 local fid=$(copy_file /etc/hosts $f)
1036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1037 wait_request_state $fid ARCHIVE SUCCEED
1038 $LFS hsm_release $f || error "release of $f failed"
1040 wait_request_state $fid RESTORE SUCCEED
1042 echo -n "Verifying file state: "
1043 check_hsm_flags $f "0x00000009"
1045 diff -q /etc/hosts $f
1047 [[ $? -eq 0 ]] || error "Restored file differs"
1051 run_test 12f "Restore a released file explicitly"
1054 # test needs a running copytool
1058 local f=$DIR/$tdir/$tfile
1059 local fid=$(copy_file /etc/hosts $f)
1061 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1062 wait_request_state $fid ARCHIVE SUCCEED
1063 $LFS hsm_release $f || error "release of $f failed"
1065 diff -q /etc/hosts $f
1068 # we check we had a restore done
1069 wait_request_state $fid RESTORE SUCCEED
1071 [[ $st -eq 0 ]] || error "Restored file differs"
1075 run_test 12g "Restore a released file implicitly"
1078 needclients 2 || return 0
1080 # test needs a running copytool
1084 local f=$DIR/$tdir/$tfile
1085 local fid=$(copy_file /etc/hosts $f)
1087 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1088 wait_request_state $fid ARCHIVE SUCCEED
1089 $LFS hsm_release $f || error "release of $f failed"
1091 do_node $CLIENT2 diff -q /etc/hosts $f
1094 # we check we had a restore done
1095 wait_request_state $fid RESTORE SUCCEED
1097 [[ $st -eq 0 ]] || error "Restored file differs"
1101 run_test 12h "Restore a released file implicitly from a second node"
1104 # test needs a running copytool
1108 local f=$DIR/$tdir/$tfile
1109 local fid=$(copy_file /etc/passwd $f)
1110 $LFS hsm_archive $f || error "archive of $f failed"
1111 wait_request_state $fid ARCHIVE SUCCEED
1113 $LFS hsm_release $f || error "release of $f failed"
1117 [[ $? -eq 0 ]] || error "Restored file differs"
1121 run_test 12m "Archive/release/implicit restore"
1124 # test needs a running copytool
1128 copy2archive /etc/hosts $tdir/$tfile
1130 local f=$DIR/$tdir/$tfile
1131 import_file $tdir/$tfile $f
1133 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1134 error "Restored file differs"
1136 $LFS hsm_release $f || error "release of $f failed"
1140 run_test 12n "Import/implicit restore/release"
1143 # test needs a running copytool
1146 local ARC_SUBDIR="import.orig"
1150 # populate directory to be imported
1151 for d in $(seq 1 10); do
1152 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1153 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1154 for f in $(seq 1 10); do
1155 CURR_FILE="$CURR_DIR/$tfile.$f"
1156 # write file-specific data
1157 do_facet $SINGLEAGT \
1158 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1159 "file=$CURR_FILE > $CURR_FILE"
1163 import_file "$ARC_SUBDIR" $DIR/$tdir
1164 # diff lustre content and origin (triggers file restoration)
1165 # there must be 10x10 identical files, and no difference
1166 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1167 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1168 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1169 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1171 [ $cnt_diff -eq 0 ] ||
1172 error "$cnt_diff imported files differ from read data"
1173 [ $cnt_ok -eq 100 ] ||
1174 error "not enough identical files ($cnt_ok != 100)"
1178 run_test 13 "Recursively import and restore a directory"
1181 # test needs a running copytool
1186 local f=$DIR/$tdir/$tfile
1187 local fid=$(make_small $f)
1188 local sum=$(md5sum $f | awk '{print $1}')
1189 $LFS hsm_archive $f || error "could not archive file"
1190 wait_request_state $fid ARCHIVE SUCCEED
1194 # create released file (simulate llapi_hsm_import call)
1196 local fid2=$(path2fid $f)
1197 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1198 $LFS hsm_release $f || error "could not release file"
1200 # rebind the archive to the newly created file
1201 echo "rebind $fid to $fid2"
1203 do_facet $SINGLEAGT \
1204 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1205 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1207 # restore file and compare md5sum
1208 local sum2=$(md5sum $f | awk '{print $1}')
1210 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1214 run_test 14 "Rebind archived file to a new fid"
1217 # test needs a running copytool
1222 local f=$DIR/$tdir/$tfile
1224 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1228 for i in $(seq 1 $count); do
1229 fids[$i]=$(make_small $f.$i)
1230 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1231 $LFS hsm_archive $f.$i || error "could not archive file"
1233 wait_all_done $(($count*60))
1237 for i in $(seq 1 $count); do
1240 local fid2=$(path2fid $f.$i)
1241 # add the rebind operation to the list
1242 echo ${fids[$i]} $fid2 >> $tmpfile
1244 # set it released (simulate llapi_hsm_import call)
1245 $LFS hsm_set --archived --exists $f.$i ||
1246 error "could not force hsm flags"
1247 $LFS hsm_release $f.$i || error "could not release file"
1249 nl=$(wc -l < $tmpfile)
1250 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1252 echo "rebind list of files"
1253 do_facet $SINGLEAGT \
1254 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1255 --rebind $tmpfile $DIR" || error "could not rebind file list"
1257 # restore files and compare md5sum
1258 for i in $(seq 1 $count); do
1259 local sum2=$(md5sum $f.$i | awk '{print $1}')
1260 [[ $sum2 == ${sums[$i]} ]] ||
1261 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1267 run_test 15 "Rebind a list of files"
1270 # test needs a running copytool
1274 # create a known size file so we can verify transfer speed
1277 dd if=/dev/zero of=$ref bs=1M count=20
1280 local f=$DIR/$tdir/$tfile
1281 local fid=$(copy_file $ref $f)
1283 local start=$(date +%s)
1285 wait_request_state $fid ARCHIVE SUCCEED
1286 local end=$(date +%s)
1287 local duration=$((end - start))
1289 [[ $duration -ge $goal ]] ||
1290 error "Transfer is too fast $duration < $goal"
1294 run_test 16 "Test CT bandwith control option"
1299 local f=$DIR/$tdir/$tfile
1300 touch $f || error "touch $f failed"
1302 # Could not release a non-archived file
1303 $LFS hsm_release $f && error "release should not succeed"
1305 # For following tests, we must test them with HS_ARCHIVED set
1306 $LFS hsm_set --exists --archived $f || error "could not add flag"
1308 # Could not release a file if no-release is set
1309 $LFS hsm_set --norelease $f || error "could not add flag"
1310 $LFS hsm_release $f && error "release should not succeed"
1311 $LFS hsm_clear --norelease $f || error "could not remove flag"
1313 # Could not release a file if lost
1314 $LFS hsm_set --lost $f || error "could not add flag"
1315 $LFS hsm_release $f && error "release should not succeed"
1316 $LFS hsm_clear --lost $f || error "could not remove flag"
1318 # Could not release a file if dirty
1319 $LFS hsm_set --dirty $f || error "could not add flag"
1320 $LFS hsm_release $f && error "release should not succeed"
1321 $LFS hsm_clear --dirty $f || error "could not remove flag"
1323 run_test 20 "Release is not permitted"
1326 # test needs a running copytool
1330 local f=$DIR/$tdir/test_release
1332 # Create a file and check its states
1333 local fid=$(make_small $f)
1334 check_hsm_flags $f "0x00000000"
1336 $LFS hsm_archive $f || error "could not archive file"
1337 wait_request_state $fid ARCHIVE SUCCEED
1339 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1340 local sz=$(stat -c "%s" $f)
1341 [ $sz -ne "0" ] || error "file size should not be zero"
1343 # Release and check states
1344 $LFS hsm_release $f || error "could not release file"
1345 check_hsm_flags $f "0x0000000d"
1347 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1348 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1350 # Check we can release an file without stripe info
1354 check_hsm_flags $f "0x00000000"
1355 $LFS hsm_archive $f || error "could not archive file"
1356 wait_request_state $fid ARCHIVE SUCCEED
1358 # Release and check states
1359 $LFS hsm_release $f || error "could not release file"
1360 check_hsm_flags $f "0x0000000d"
1362 # Release again a file that is already released is OK
1363 $LFS hsm_release $f || fail "second release should succeed"
1364 check_hsm_flags $f "0x0000000d"
1368 run_test 21 "Simple release tests"
1371 # test needs a running copytool
1376 local f=$DIR/$tdir/test_release
1377 local swap=$DIR/$tdir/test_swap
1379 # Create a file and check its states
1380 local fid=$(make_small $f)
1381 check_hsm_flags $f "0x00000000"
1383 $LFS hsm_archive $f || error "could not archive file"
1384 wait_request_state $fid ARCHIVE SUCCEED
1386 # Release and check states
1387 $LFS hsm_release $f || error "could not release file"
1388 check_hsm_flags $f "0x0000000d"
1391 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1396 run_test 22 "Could not swap a release file"
1399 # test needs a running copytool
1404 local f=$DIR/$tdir/test_mtime
1406 # Create a file and check its states
1407 local fid=$(make_small $f)
1408 check_hsm_flags $f "0x00000000"
1410 $LFS hsm_archive $f || error "could not archive file"
1411 wait_request_state $fid ARCHIVE SUCCEED
1413 # Set modification time in the past
1414 touch -m -a -d @978261179 $f
1416 # Release and check states
1417 $LFS hsm_release $f || error "could not release file"
1418 check_hsm_flags $f "0x0000000d"
1420 local MTIME=$(stat -c "%Y" $f)
1421 local ATIME=$(stat -c "%X" $f)
1422 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1423 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1427 run_test 23 "Release does not change a/mtime (utime)"
1430 local file=$DIR/$tdir/$tfile
1439 # test needs a running copytool
1444 fid=$(make_small $file)
1446 # Create a file and check its states
1447 check_hsm_flags $file "0x00000000"
1449 # Ensure atime is less than mtime and ctime.
1453 atime0=$(stat -c "%X" $file)
1454 mtime0=$(stat -c "%Y" $file)
1455 ctime0=$(stat -c "%Z" $file)
1457 [ $atime0 -lt $mtime0 ] ||
1458 error "atime $atime0 is not less than mtime $mtime0"
1460 [ $atime0 -lt $ctime0 ] ||
1461 error "atime $atime0 is not less than ctime $ctime0"
1463 # Archive should not change any timestamps.
1464 $LFS hsm_archive $file || error "cannot archive '$file'"
1465 wait_request_state $fid ARCHIVE SUCCEED
1467 atime1=$(stat -c "%X" $file)
1468 mtime1=$(stat -c "%Y" $file)
1469 ctime1=$(stat -c "%Z" $file)
1471 [ $atime0 -eq $atime1 ] ||
1472 error "archive changed atime from $atime0 to $atime1"
1474 [ $mtime0 -eq $mtime1 ] ||
1475 error "archive changed mtime from $mtime0 to $mtime1"
1477 [ $ctime0 -eq $ctime1 ] ||
1478 error "archive changed ctime from $ctime0 to $ctime1"
1480 # Release should not change any timestamps.
1481 $LFS hsm_release $file || error "cannot release '$file'"
1482 check_hsm_flags $file "0x0000000d"
1484 atime1=$(stat -c "%X" $file)
1485 mtime1=$(stat -c "%Y" $file)
1486 ctime1=$(stat -c "%Z" $file)
1488 [ $atime0 -eq $atime1 ] ||
1489 error "release changed atime from $atime0 to $atime1"
1491 [ $mtime0 -eq $mtime1 ] ||
1492 error "release changed mtime from $mtime0 to $mtime1"
1494 [ $ctime0 -eq $ctime1 ] ||
1495 error "release changed ctime from $ctime0 to $ctime1"
1497 # Restore should not change atime or mtime and should not
1499 $LFS hsm_restore $file
1500 wait_request_state $fid RESTORE SUCCEED
1502 atime1=$(stat -c "%X" $file)
1503 mtime1=$(stat -c "%Y" $file)
1504 ctime1=$(stat -c "%Z" $file)
1506 [ $atime0 -eq $atime1 ] ||
1507 error "restore changed atime from $atime0 to $atime1"
1509 [ $mtime0 -eq $mtime1 ] ||
1510 error "restore changed mtime from $mtime0 to $mtime1"
1512 [ $ctime0 -le $ctime1 ] ||
1513 error "restore changed ctime from $ctime0 to $ctime1"
1517 # Once more, after unmount and mount.
1518 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1519 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1521 atime1=$(stat -c "%X" $file)
1522 mtime1=$(stat -c "%Y" $file)
1523 ctime1=$(stat -c "%Z" $file)
1525 [ $atime0 -eq $atime1 ] ||
1526 error "remount changed atime from $atime0 to $atime1"
1528 [ $mtime0 -eq $mtime1 ] ||
1529 error "remount changed mtime from $mtime0 to $mtime1"
1531 [ $ctime0 -le $ctime1 ] ||
1532 error "remount changed ctime from $ctime0 to $ctime1"
1534 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1537 local file=$DIR/$tdir/$tfile
1543 # Test needs a running copytool.
1547 # Check that root can do HSM actions on a ordinary user's file.
1549 fid=$(make_small $file)
1550 sum0=$(md5sum $file)
1552 chown $RUNAS_ID:$RUNAS_GID $file ||
1553 error "cannot chown '$file' to '$RUNAS_ID'"
1555 chmod ugo-w $DIR/$tdir ||
1556 error "cannot chmod '$DIR/$tdir'"
1558 $LFS hsm_archive $file
1559 wait_request_state $fid ARCHIVE SUCCEED
1561 $LFS hsm_release $file
1562 check_hsm_flags $file "0x0000000d"
1564 $LFS hsm_restore $file
1565 wait_request_state $fid RESTORE SUCCEED
1567 # Check that ordinary user can get HSM state.
1568 $RUNAS $LFS hsm_state $file ||
1569 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1571 $LFS hsm_release $file
1572 check_hsm_flags $file "0x0000000d"
1574 # Check that ordinary user can accessed released file.
1575 sum1=$($RUNAS md5sum $file) ||
1576 error "user '$RUNAS_ID' cannot read '$file'"
1578 [ "$sum0" == "$sum1" ] ||
1579 error "md5sum mismatch for '$file'"
1583 run_test 24b "root can archive, release, and restore user files"
1585 cleanup_test_24c() {
1587 set_hsm_param user_request_mask RESTORE
1588 set_hsm_param group_request_mask RESTORE
1589 set_hsm_param other_request_mask RESTORE
1593 local file=$DIR/$tdir/$tfile
1594 local action=archive
1599 # test needs a running copytool
1604 # Save the default masks and check that cleanup_24c will
1605 # restore the request masks correctly.
1606 user_save=$(get_hsm_param user_request_mask)
1607 group_save=$(get_hsm_param group_request_mask)
1608 other_save=$(get_hsm_param other_request_mask)
1610 [ "$user_save" == RESTORE ] ||
1611 error "user_request_mask is '$user_save' expected 'RESTORE'"
1612 [ "$group_save" == RESTORE ] ||
1613 error "group_request_mask is '$group_save' expected 'RESTORE'"
1614 [ "$other_save" == RESTORE ] ||
1615 error "other_request_mask is '$other_save' expected 'RESTORE'"
1617 trap cleanup_test_24c EXIT
1622 chown $RUNAS_ID:nobody $file ||
1623 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1625 set_hsm_param user_request_mask ""
1626 $RUNAS $LFS hsm_$action $file &&
1627 error "$action by user should fail"
1629 set_hsm_param user_request_mask $action
1630 $RUNAS $LFS hsm_$action $file ||
1631 error "$action by user should succeed"
1636 chown nobody:$RUNAS_GID $file ||
1637 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1639 set_hsm_param group_request_mask ""
1640 $RUNAS $LFS hsm_$action $file &&
1641 error "$action by group should fail"
1643 set_hsm_param group_request_mask $action
1644 $RUNAS $LFS hsm_$action $file ||
1645 error "$action by group should succeed"
1650 chown nobody:nobody $file ||
1651 error "cannot chown '$file' to 'nobody:nobody'"
1653 set_hsm_param other_request_mask ""
1654 $RUNAS $LFS hsm_$action $file &&
1655 error "$action by other should fail"
1657 set_hsm_param other_request_mask $action
1658 $RUNAS $LFS hsm_$action $file ||
1659 error "$action by other should succeed"
1664 run_test 24c "check that user,group,other request masks work"
1666 cleanup_test_24d() {
1668 mount -o remount,rw $MOUNT2
1672 local file1=$DIR/$tdir/$tfile
1673 local file2=$DIR2/$tdir/$tfile
1681 fid1=$(make_small $file1)
1683 trap cleanup_test_24d EXIT
1685 mount -o remount,ro $MOUNT2
1687 fid2=$(path2fid $file2)
1688 [ "$fid1" == "$fid2" ] ||
1689 error "FID mismatch '$fid1' != '$fid2'"
1691 $LFS hsm_archive $file2 &&
1692 error "archive should fail on read-only mount"
1693 check_hsm_flags $file1 "0x00000000"
1695 $LFS hsm_archive $file1
1696 wait_request_state $fid1 ARCHIVE SUCCEED
1698 $LFS hsm_release $file1
1699 $LFS hsm_restore $file2
1700 wait_request_state $fid1 RESTORE SUCCEED
1702 $LFS hsm_release $file1 || error "cannot release '$file1'"
1703 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1705 $LFS hsm_release $file2 &&
1706 error "release should fail on read-only mount"
1711 run_test 24d "check that read-only mounts are respected"
1714 # test needs a running copytool
1718 copy2archive /etc/hosts $tdir/$tfile
1720 local f=$DIR/$tdir/$tfile
1722 import_file $tdir/$tfile $f
1724 $LFS hsm_set --lost $f
1729 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1733 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1734 " (Operation not permitted)"
1737 # test needs a running copytool
1742 local f=$DIR/$tdir/$tfile
1743 local fid=$(copy_file /etc/passwd $f)
1745 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1746 wait_request_state $fid ARCHIVE SUCCEED
1749 $LFS hsm_set --lost $f
1753 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1757 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1758 " (Operation not permitted)"
1761 # test needs a running copytool
1765 local f=$DIR/$tdir/$tfile
1766 local fid=$(make_large_for_progress $f)
1767 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1768 wait_request_state $fid ARCHIVE SUCCEED
1771 wait_request_state $fid REMOVE SUCCEED
1773 check_hsm_flags $f "0x00000000"
1777 run_test 26 "Remove the archive of a valid file"
1780 # test needs a running copytool
1784 make_archive $tdir/$tfile
1785 local f=$DIR/$tdir/$tfile
1786 import_file $tdir/$tfile $f
1787 local fid=$(path2fid $f)
1791 [[ $? != 0 ]] || error "Remove of a released file should fail"
1795 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1798 # test needs a running copytool
1802 local f=$DIR/$tdir/$tfile
1803 local fid=$(make_large_for_progress $f)
1804 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1805 wait_request_state $fid ARCHIVE SUCCEED
1810 [[ $? != 0 ]] || error "Remove of a released file should fail"
1814 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1817 # test needs a running copytool
1821 local f=$DIR/$tdir/$tfile
1822 local fid=$(make_large_for_progress $f)
1823 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1824 wait_request_state $fid ARCHIVE SUCCEED
1833 wait_request_state $fid REMOVE SUCCEED
1837 run_test 28 "Concurrent archive/file remove"
1840 # restore at exec cannot work on agent node (because of Linux kernel
1841 # protection of executables)
1842 needclients 2 || return 0
1844 # test needs a running copytool
1848 copy2archive /bin/true $tdir/$tfile
1850 local f=$DIR/$tdir/true
1851 import_file $tdir/$tfile $f
1853 local fid=$(path2fid $f)
1855 # set no retry action mode
1861 # remove no try action mode
1865 [[ $st == 0 ]] || error "Failed to exec a released file"
1869 run_test 30a "Restore at exec (import case)"
1872 # restore at exec cannot work on agent node (because of Linux kernel
1873 # protection of executables)
1874 needclients 2 || return 0
1876 # test needs a running copytool
1880 local f=$DIR/$tdir/true
1881 local fid=$(copy_file /bin/true $f)
1883 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1884 wait_request_state $fid ARCHIVE SUCCEED
1887 # set no retry action mode
1893 # remove no try action mode
1897 [[ $st == 0 ]] || error "Failed to exec a released file"
1901 run_test 30b "Restore at exec (release case)"
1904 needclients 2 || return 0
1906 # test needs a running copytool
1910 local f=$DIR/$tdir/SLEEP
1911 local fid=$(copy_file /bin/sleep $f)
1913 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1914 wait_request_state $fid ARCHIVE SUCCEED
1916 check_hsm_flags $f "0x0000000d"
1917 # set no retry action mode
1919 do_node $CLIENT2 "$f 10" &
1923 [[ $? == 0 ]] && error "Update during exec of released file must fail"
1925 [[ $? == 0 ]] || error "Execution failed during run"
1927 [[ $? == 0 ]] || error "Binary overwritten during exec"
1930 # remove no try action mode
1932 check_hsm_flags $f "0x00000009"
1936 run_test 30c "Update during exec of released file must fail"
1938 restore_and_check_size() {
1941 local s=$(stat -c "%s" $f)
1943 local st=$(get_hsm_flags $f)
1947 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1949 n=$(stat -c "%s" $f)
1950 # we echo in both cases to show stat is not
1952 if [[ $n != $s ]]; then
1953 echo "size seen is $n != $s"
1956 echo "size seen is right: $n == $s"
1958 st=$(get_hsm_flags $f)
1962 if [[ $cpt -lt 10 ]]; then
1965 echo " restore is too long"
1966 wait_request_state $fid RESTORE SUCCEED
1972 # test needs a running copytool
1977 make_archive $tdir/$tfile
1978 local f=$DIR/$tdir/$tfile
1979 import_file $tdir/$tfile $f
1980 local fid=$($LFS path2fid $f)
1981 HSM_ARCHIVE_PURGE=false copytool_setup
1983 restore_and_check_size $f $fid
1986 [[ $err -eq 0 ]] || error "File size changed during restore"
1990 run_test 31a "Import a large file and check size during restore"
1994 # test needs a running copytool
1999 local f=$DIR/$tdir/$tfile
2000 local fid=$(make_large_for_progress $f)
2001 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2002 wait_request_state $fid ARCHIVE SUCCEED
2005 restore_and_check_size $f $fid
2008 [[ $err -eq 0 ]] || error "File size changed during restore"
2012 run_test 31b "Restore a large unaligned file and check size during restore"
2015 # test needs a running copytool
2020 local f=$DIR/$tdir/$tfile
2021 local fid=$(make_large_for_progress_aligned $f)
2022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2023 wait_request_state $fid ARCHIVE SUCCEED
2026 restore_and_check_size $f $fid
2029 [[ $err -eq 0 ]] || error "File size changed during restore"
2033 run_test 31c "Restore a large aligned file and check size during restore"
2036 # test needs a running copytool
2041 local f=$DIR/$tdir/$tfile
2042 local fid=$(make_large_for_progress $f)
2043 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2044 wait_request_state $fid ARCHIVE SUCCEED
2047 md5sum $f >/dev/null &
2049 wait_request_state $fid RESTORE STARTED
2054 # Check restore trigger process was killed
2055 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2059 wait_request_state $fid RESTORE CANCELED
2060 wait_request_state $fid CANCEL SUCCEED
2063 error "Cannot kill process waiting for restore ($killed)"
2067 run_test 33 "Kill a restore waiting process"
2070 # test needs a running copytool
2075 local f=$DIR/$tdir/$tfile
2076 local fid=$(make_large_for_progress $f)
2077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2078 wait_request_state $fid ARCHIVE SUCCEED
2081 md5sum $f >/dev/null &
2083 wait_request_state $fid RESTORE STARTED
2085 rm $f || error "rm $f failed"
2086 # rm must not block during restore
2087 wait_request_state $fid RESTORE STARTED
2089 wait_request_state $fid RESTORE SUCCEED
2090 # check md5sum pgm finished
2091 local there=$(ps -o pid,comm hp $pid >/dev/null)
2092 [[ -z $there ]] || error "Restore initiator does not exit"
2094 local rc=$(wait $pid)
2095 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2099 run_test 34 "Remove file during restore"
2102 # test needs a running copytool
2107 local f=$DIR/$tdir/$tfile
2108 local f1=$DIR/$tdir/$tfile-1
2109 local fid=$(make_large_for_progress $f)
2110 local fid1=$(copy_file /etc/passwd $f1)
2111 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2112 wait_request_state $fid ARCHIVE SUCCEED
2115 md5sum $f >/dev/null &
2117 wait_request_state $fid RESTORE STARTED
2119 mv $f1 $f || error "mv $f1 $f failed"
2120 # mv must not block during restore
2121 wait_request_state $fid RESTORE STARTED
2123 wait_request_state $fid RESTORE SUCCEED
2124 # check md5sum pgm finished
2125 local there=$(ps -o pid,comm hp $pid >/dev/null)
2126 [[ -z $there ]] || error "Restore initiator does not exit"
2128 local rc=$(wait $pid)
2129 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2132 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2136 run_test 35 "Overwrite file during restore"
2139 # test needs a running copytool
2144 local f=$DIR/$tdir/$tfile
2145 local fid=$(make_large_for_progress $f)
2146 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2147 wait_request_state $fid ARCHIVE SUCCEED
2150 md5sum $f >/dev/null &
2152 wait_request_state $fid RESTORE STARTED
2155 # rm must not block during restore
2156 wait_request_state $fid RESTORE STARTED
2158 wait_request_state $fid RESTORE SUCCEED
2159 # check md5sum pgm finished
2160 local there=$(ps -o pid,comm hp $pid >/dev/null)
2162 error "Restore initiator does not exit"
2164 local rc=$(wait $pid)
2166 error "Restore initiator failed with $rc"
2170 run_test 36 "Move file during restore"
2177 for n in $(seq 1 $count); do
2178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2180 echo "$count archive requests submitted"
2184 local stream_count=4
2185 local file_count=100
2187 local f=$DIR/$tdir/$tfile
2192 for i in $(seq 1 $file_count); do
2193 for p in $(seq 1 $stream_count); do
2194 fid=$(copy_file /etc/hosts $f.$p.$i)
2198 # to be sure wait_all_done will not be mislead by previous tests
2200 wait_for_grace_delay
2202 # start archive streams in background (archive files in parallel)
2203 for p in $(seq 1 $stream_count); do
2204 multi_archive $f.$p $file_count &
2207 echo -n "Wait for all requests being enqueued..."
2213 run_test 40 "Parallel archive requests"
2216 # test needs a running copytool
2220 local f=$DIR/$tdir/$tfile
2221 local fid=$(copy_file /etc/motd $f 1)
2223 $LFS hsm_archive $f || error "could not archive file"
2224 wait_request_state $fid ARCHIVE SUCCEED
2225 check_hsm_flags $f "0x00000009"
2227 multiop_bg_pause $f O_c || error "multiop failed"
2231 client_up || client_up || true
2233 kill -USR1 $MULTIPID
2234 wait $MULTIPID || error "multiop close failed"
2236 check_hsm_flags $f "0x0000000b"
2240 run_test 52 "Opened for write file on an evicted client should be set dirty"
2243 # test needs a running copytool
2247 local f=$DIR/$tdir/$tfile
2248 local fid=$(copy_file /etc/motd $f 1)
2250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2251 error "could not archive file"
2252 wait_request_state $fid ARCHIVE SUCCEED
2253 check_hsm_flags $f "0x00000009"
2255 multiop_bg_pause $f o_c || error "multiop failed"
2259 client_up || client_up || true
2261 kill -USR1 $MULTIPID
2262 wait $MULTIPID || error "multiop close failed"
2264 check_hsm_flags $f "0x00000009"
2268 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2271 # test needs a running copytool
2275 local f=$DIR/$tdir/$tfile
2276 local fid=$(make_small $f)
2278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2279 error "could not archive file"
2280 wait_request_state $fid ARCHIVE STARTED
2282 check_hsm_flags $f "0x00000001"
2284 # Avoid coordinator resending this request as soon it has failed.
2289 wait_request_state $fid ARCHIVE FAILED
2291 check_hsm_flags $f "0x00000003"
2296 run_test 54 "Write during an archive cancels it"
2299 # test needs a running copytool
2303 local f=$DIR/$tdir/$tfile
2304 local fid=$(make_small $f)
2306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2307 error "could not archive file"
2308 wait_request_state $fid ARCHIVE STARTED
2310 check_hsm_flags $f "0x00000001"
2312 # Avoid coordinator resending this request as soon it has failed.
2315 $TRUNCATE $f 1024 || error "truncate failed"
2317 wait_request_state $fid ARCHIVE FAILED
2319 check_hsm_flags $f "0x00000003"
2324 run_test 55 "Truncate during an archive cancels it"
2327 # test needs a running copytool
2331 local f=$DIR/$tdir/$tfile
2332 local fid=$(make_large_for_progress $f)
2334 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2335 error "could not archive file"
2336 wait_request_state $fid ARCHIVE STARTED
2338 check_hsm_flags $f "0x00000001"
2340 # Change metadata and sync to be sure we are not changing only
2345 wait_request_state $fid ARCHIVE SUCCEED
2347 check_hsm_flags $f "0x00000009"
2351 run_test 56 "Setattr during an archive is ok"
2354 # Need one client for I/O, one for request
2355 needclients 2 || return 0
2357 # test needs a running copytool
2361 local f=$DIR/$tdir/test_archive_remote
2362 # Create a file on a remote node
2363 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2364 "count=2 conv=fsync"
2367 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2368 error "hsm_archive failed"
2369 local fid=$(path2fid $f)
2370 wait_request_state $fid ARCHIVE SUCCEED
2372 # Release and implicit restore it
2373 do_node $CLIENT2 "$LFS hsm_release $f" ||
2374 error "hsm_release failed"
2375 do_node $CLIENT2 "md5sum $f" ||
2376 error "hsm_restore failed"
2378 wait_request_state $fid RESTORE SUCCEED
2382 run_test 57 "Archive a file with dirty cache on another node"
2384 truncate_released_file() {
2388 local sz=$(stat -c %s $src_file)
2389 local f=$DIR/$tdir/$tfile
2390 local fid=$(copy_file $1 $f)
2394 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2395 error "could not archive file"
2396 wait_request_state $fid ARCHIVE SUCCEED
2398 $LFS hsm_release $f || error "could not release file"
2400 $TRUNCATE $f $trunc_to || error "truncate failed"
2403 local sz1=$(stat -c %s $f)
2404 [[ $sz1 == $trunc_to ]] ||
2405 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2408 check_hsm_flags $f "0x0000000b"
2410 local state=$(get_request_state $fid RESTORE)
2411 [[ "$state" == "SUCCEED" ]] ||
2412 error "truncate $sz does not trig restore, state = $state"
2414 $TRUNCATE $ref $trunc_to
2415 cmp $ref $f || error "file data wrong after truncate"
2421 # test needs a running copytool
2426 local sz=$(stat -c %s /etc/passwd)
2428 echo "truncate up from $sz to $((sz*2))"
2429 truncate_released_file /etc/passwd $((sz*2))
2431 echo "truncate down from $sz to $((sz/2))"
2432 truncate_released_file /etc/passwd $((sz/2))
2434 echo "truncate to 0"
2435 truncate_released_file /etc/passwd 0
2439 run_test 58 "Truncate a released file will trigger restore"
2444 local f=$DIR/$tdir/$tfile
2445 local FILELIST=/tmp/filelist.txt
2449 for i in $(seq 1 $file_count); do
2450 fid=$(copy_file /etc/hosts $f.$i)
2451 echo $f.$i >> $FILELIST
2454 # to be sure wait_all_done will not be mislead by previous tests
2456 wait_for_grace_delay
2457 $LFS hsm_archive --filelist $FILELIST ||
2458 error "cannot archive a file list"
2460 $LFS hsm_release --filelist $FILELIST ||
2461 error "cannot release a file list"
2462 $LFS hsm_restore --filelist $FILELIST ||
2463 error "cannot restore a file list"
2467 run_test 90 "Archive/restore a file list"
2469 double_verify_reset_hsm_param() {
2471 echo "Testing $HSM_PARAM.$p"
2472 local val=$(get_hsm_param $p)
2474 local val2=$(($val * 2))
2475 set_hsm_param $p $val2
2476 val=$(get_hsm_param $p)
2477 [[ $val == $val2 ]] ||
2478 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2479 echo "Set $p to 0 must failed"
2483 set_hsm_param $p $save
2485 if [[ $rc == 0 ]]; then
2486 error "we must not be able to set $HSM_PARAM.$p to 0"
2491 double_verify_reset_hsm_param loop_period
2492 double_verify_reset_hsm_param grace_delay
2493 double_verify_reset_hsm_param active_request_timeout
2494 double_verify_reset_hsm_param max_requests
2495 double_verify_reset_hsm_param default_archive_id
2497 run_test 100 "Set coordinator /proc tunables"
2504 run_test 102 "Verify coordinator control"
2507 # test needs a running copytool
2514 for i in $(seq 1 20); do
2515 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2517 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2521 echo "Current requests"
2522 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2523 $HSM_PARAM.actions |\
2524 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2526 [[ -z "$res" ]] || error "Some request have not been canceled"
2530 run_test 103 "Purge all requests"
2535 # test needs a running copytool
2539 local f=$DIR/$tdir/$tfile
2540 local fid=$(make_large_for_progress $f)
2541 # if cdt is on, it can serve too quickly the request
2543 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2544 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2545 $HSM_PARAM.actions |\
2546 grep $fid | cut -f16 -d=")
2549 [[ "$data1" == "$DATAHEX" ]] ||
2550 error "Data field in records is ($data1) and not ($DATAHEX)"
2554 run_test 104 "Copy tool data field"
2561 for i in $(seq -w 1 10); do
2562 cp /etc/passwd $DIR/$tdir/$i
2563 $LFS hsm_archive $DIR/$tdir/$i
2565 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2566 $HSM_PARAM.actions |\
2567 grep WAITING | wc -l")
2570 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2571 $HSM_PARAM.actions |\
2572 grep WAITING | wc -l")
2575 [[ "$reqcnt1" == "$reqcnt2" ]] ||
2576 error "Requests count after shutdown $reqcnt2 != "\
2577 "before shutdown $reqcnt1"
2579 run_test 105 "Restart of coordinator"
2582 # test needs a running copytool
2585 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2586 get_client_uuid $MOUNT | cut -d' ' -f2)
2587 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2590 [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2591 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2593 [[ -z "$agent" ]] ||
2594 error "My uuid $uuid still found in agent list,"\
2595 " after copytool shutdown"
2597 local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2600 [[ ! -z "$agent" ]] ||
2601 error "My uuid $uuid not found in agent list after"\
2604 run_test 106 "Copytool register/unregister"
2607 # test needs a running copytool
2609 # create and archive file
2611 local f1=$DIR/$tdir/$tfile
2612 local fid=$(copy_file /etc/passwd $f1)
2613 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2614 wait_request_state $fid ARCHIVE SUCCEED
2615 # shutdown and restart MDS
2617 # check the copytool still gets messages from MDT
2618 local f2=$DIR/$tdir/2
2619 local fid=$(copy_file /etc/passwd $f2)
2620 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2621 # main check of this sanity: this request MUST succeed
2622 wait_request_state $fid ARCHIVE SUCCEED
2625 run_test 107 "Copytool re-register after MDS restart"
2627 policy_set_and_test()
2631 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
2632 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2633 [[ "$policy" == "$target" ]] ||
2634 error "Wrong policy after '$change': '$policy' != '$target'"
2638 # to force default policy setting if error
2639 CDT_POLICY_HAD_CHANGED=true
2641 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2642 local default="NonBlockingRestore [NoRetryAction]"
2643 [[ "$policy" == "$default" ]] ||
2644 error "default policy has changed,"\
2645 " '$policy' != '$default' update the test"
2646 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
2647 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
2648 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
2649 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
2650 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
2651 # useless bacause we know but safer for futur changes to use real value
2652 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
2653 echo "Next set_param must failed"
2654 policy_set_and_test "wrong" "$policy"
2657 echo "Back to default policy"
2658 cdt_set_sanity_policy
2660 run_test 109 "Policy display/change"
2663 # test needs a running copytool
2668 copy2archive /etc/passwd $tdir/$tfile
2670 local f=$DIR/$tdir/$tfile
2671 import_file $tdir/$tfile $f
2672 local fid=$(path2fid $f)
2674 cdt_set_non_blocking_restore
2679 wait_request_state $fid RESTORE SUCCEED
2680 cdt_clear_non_blocking_restore
2684 error "md5sum returns $st != 1, "\
2685 "should also perror ENODATA (No data available)"
2689 run_test 110a "Non blocking restore policy (import case)"
2692 # test needs a running copytool
2696 local f=$DIR/$tdir/$tfile
2697 local fid=$(copy_file /etc/passwd $f)
2698 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2699 wait_request_state $fid ARCHIVE SUCCEED
2702 cdt_set_non_blocking_restore
2707 wait_request_state $fid RESTORE SUCCEED
2708 cdt_clear_non_blocking_restore
2712 error "md5sum returns $st != 1, "\
2713 "should also perror ENODATA (No data available)"
2717 run_test 110b "Non blocking restore policy (release case)"
2720 # test needs a running copytool
2724 copy2archive /etc/passwd $tdir/$tfile
2726 local f=$DIR/$tdir/$tfile
2728 import_file $tdir/$tfile $f
2729 local fid=$(path2fid $f)
2733 copytool_remove_backend $fid
2736 wait_request_state $fid RESTORE FAILED
2743 [[ $st == 0 ]] || error "Restore does not failed"
2747 run_test 111a "No retry policy (import case), restore will error"\
2748 " (No such file or directory)"
2751 # test needs a running copytool
2755 local f=$DIR/$tdir/$tfile
2756 local fid=$(copy_file /etc/passwd $f)
2758 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2759 wait_request_state $fid ARCHIVE SUCCEED
2762 copytool_remove_backend $fid
2765 wait_request_state $fid RESTORE FAILED
2772 [[ $st == 0 ]] || error "Restore does not failed"
2776 run_test 111b "No retry policy (release case), restore will error"\
2777 " (No such file or directory)"
2780 # test needs a running copytool
2784 local f=$DIR/$tdir/$tfile
2785 local fid=$(copy_file /etc/passwd $f)
2787 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2788 local l=$($LFS hsm_action $f)
2790 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2794 wait_request_state $fid ARCHIVE SUCCEED
2797 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2801 run_test 112 "State of recorded request"
2804 # test needs a running copytool
2808 local f=$DIR/$tdir/$tfile
2809 local fid=$(make_large_for_cancel $f)
2810 # test with cdt on is made in test_221
2812 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2815 wait_request_state $fid ARCHIVE CANCELED
2816 wait_request_state $fid CANCEL SUCCEED
2820 run_test 200 "Register/Cancel archive"
2823 # test needs a running copytool
2827 local f=$DIR/$tdir/$tfile
2828 make_archive $tdir/$tfile
2829 import_file $tdir/$tfile $f
2830 local fid=$(path2fid $f)
2832 # test with cdt on is made in test_222
2837 wait_request_state $fid RESTORE CANCELED
2838 wait_request_state $fid CANCEL SUCCEED
2842 run_test 201 "Register/Cancel restore"
2845 # test needs a running copytool
2849 local f=$DIR/$tdir/$tfile
2850 local fid=$(make_large_for_progress $f)
2851 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2852 wait_request_state $fid ARCHIVE SUCCEED
2858 wait_request_state $fid REMOVE CANCELED
2862 run_test 202 "Register/Cancel remove"
2865 # test needs a running copytool
2870 local f=$DIR/$tdir/$tfile
2871 local fid=$(copy_file /etc/passwd $f)
2875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2876 wait_request_state $fid ARCHIVE SUCCEED
2878 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2882 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2886 run_test 220 "Changelog for archive"
2889 # test needs a running copytool
2894 local f=$DIR/$tdir/$tfile
2895 local fid=$(make_large_for_cancel $f)
2899 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2900 wait_request_state $fid ARCHIVE STARTED
2902 wait_request_state $fid ARCHIVE CANCELED
2903 wait_request_state $fid CANCEL SUCCEED
2905 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2908 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2912 run_test 221 "Changelog for archive canceled"
2915 # test needs a running copytool
2919 copy2archive /etc/passwd $tdir/$tfile
2921 local f=$DIR/$tdir/$tfile
2922 import_file $tdir/$tfile $f
2923 local fid=$(path2fid $f)
2928 wait_request_state $fid RESTORE SUCCEED
2930 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2933 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2937 run_test 222a "Changelog for explicit restore"
2940 # test needs a running copytool
2944 local f=$DIR/$tdir/$tfile
2945 local fid=$(copy_file /etc/passwd $f)
2948 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2949 wait_request_state $fid ARCHIVE SUCCEED
2954 wait_request_state $fid RESTORE SUCCEED
2956 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2959 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2963 run_test 222b "Changelog for implicit restore"
2966 # test needs a running copytool
2971 local f=$DIR/$tdir/$tfile
2972 make_archive $tdir/$tfile
2976 import_file $tdir/$tfile $f
2977 local fid=$(path2fid $f)
2980 wait_request_state $fid RESTORE STARTED
2982 wait_request_state $fid RESTORE CANCELED
2983 wait_request_state $fid CANCEL SUCCEED
2985 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
2988 [[ $flags == $target ]] ||
2989 error "Changelog flag is $flags not $target"
2993 run_test 223a "Changelog for restore canceled (import case)"
2996 # test needs a running copytool
3001 local f=$DIR/$tdir/$tfile
3002 local fid=$(make_large_for_progress $f)
3005 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3006 wait_request_state $fid ARCHIVE SUCCEED
3009 wait_request_state $fid RESTORE STARTED
3011 wait_request_state $fid RESTORE CANCELED
3012 wait_request_state $fid CANCEL SUCCEED
3014 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3017 [[ $flags == $target ]] ||
3018 error "Changelog flag is $flags not $target"
3022 run_test 223b "Changelog for restore canceled (release case)"
3025 # test needs a running copytool
3030 local f=$DIR/$tdir/$tfile
3031 local fid=$(copy_file /etc/passwd $f)
3034 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3035 wait_request_state $fid ARCHIVE SUCCEED
3038 wait_request_state $fid REMOVE SUCCEED
3040 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3043 [[ $flags == $target ]] ||
3044 error "Changelog flag is $flags not $target"
3048 run_test 224 "Changelog for remove"
3051 # test needs a running copytool
3054 # test is not usable because remove request is too fast
3055 # so it is always finished before cancel can be done ...
3056 echo "Test disabled"
3061 local f=$DIR/$tdir/$tfile
3062 local fid=$(make_large_for_progress $f)
3065 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3066 wait_request_state $fid ARCHIVE SUCCEED
3068 # if cdt is on, it can serve too quickly the request
3073 wait_request_state $fid REMOVE CANCELED
3074 wait_request_state $fid CANCEL SUCCEED
3076 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3077 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3078 tail -n 1 | awk '{print $5}')
3081 [[ $flags == $target ]] ||
3082 error "Changelog flag is $flags not $target"
3086 run_test 225 "Changelog for remove canceled"
3089 # test needs a running copytool
3094 local f1=$DIR/$tdir/$tfile-1
3095 local f2=$DIR/$tdir/$tfile-2
3096 local f3=$DIR/$tdir/$tfile-3
3097 local fid1=$(copy_file /etc/passwd $f1)
3098 local fid2=$(copy_file /etc/passwd $f2)
3099 copy_file /etc/passwd $f3
3102 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3103 wait_request_state $fid1 ARCHIVE SUCCEED
3105 $LFS hsm_archive $f2
3106 wait_request_state $fid2 ARCHIVE SUCCEED
3108 rm $f1 || error "rm $f1 failed"
3110 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3113 [[ $flags == $target ]] ||
3114 error "Changelog flag is $flags not $target"
3116 mv $f3 $f2 || error "mv $f3 $f2 failed"
3118 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3121 [[ $flags == $target ]] ||
3122 error "Changelog flag is $flags not $target"
3126 run_test 226 "changelog for last rm/mv with exiting archive"
3128 check_flags_changes() {
3136 $LFS hsm_set --$hsm_flag $f ||
3137 error "Cannot set $hsm_flag on $f"
3138 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3139 local seen=${#flags[*]}
3141 [[ $seen == $cnt ]] ||
3142 error "set $hsm_flag: Changelog events $seen != $cnt"
3143 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3144 error "set $hsm_flag: Changelog flags are "\
3145 "${flags[$((cnt - 1))]} not $target"
3147 $LFS hsm_clear --$hsm_flag $f ||
3148 error "Cannot clear $hsm_flag on $f"
3149 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3152 [[ $cnt == $seen ]] ||
3153 error "clear $hsm_flag: Changelog events $seen != $cnt"
3155 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3156 error "clear $hsm_flag: Changelog flag is "\
3157 "${flags[$((cnt - 1))]} not $target"
3161 # test needs a running copytool
3168 for i in norelease noarchive exists archived
3170 local f=$DIR/$tdir/$tfile-$i
3171 local fid=$(copy_file /etc/passwd $f)
3172 check_flags_changes $f $fid $i 0 1
3175 f=$DIR/$tdir/$tfile---lost
3176 fid=$(copy_file /etc/passwd $f)
3177 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3178 wait_request_state $fid ARCHIVE SUCCEED
3179 check_flags_changes $f $fid lost 3 1
3183 run_test 227 "changelog when explicit setting of HSM flags"
3186 # test needs a running copytool
3189 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 conv=sync ||
3190 error "creating $DIR/$tfile"
3191 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3192 wait_request_state $(path2fid $DIR/$tfile) ARCHIVE SUCCEED
3194 $LFS hsm_release $DIR/$tfile
3195 check_hsm_flags $DIR/$tfile "0x0000000d"
3197 filefrag $DIR/$tfile | grep " 1 extent found" ||
3198 error "filefrag on released file must return only one extent"
3200 # only newer versions of cp detect sparse files by stat/FIEMAP
3202 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3203 error "copying $DIR/$tfile"
3204 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3206 $LFS hsm_release $DIR/$tfile
3207 check_hsm_flags $DIR/$tfile "0x0000000d"
3211 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3213 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3214 error "comparing untarred $DIR/$tfile"
3218 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3221 # test needs a running copytool
3225 local maxrequest=$(get_hsm_param max_requests)
3226 local rqcnt=$(($maxrequest * 3))
3230 for i in $(seq -w 1 $rqcnt); do
3232 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3234 # we do it in 2 steps, so all requests arrive at the same time
3235 for i in $(seq -w 1 $rqcnt); do
3236 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3241 while [[ $cnt != 0 || $wt != 0 ]]; do
3243 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3244 $HSM_PARAM.actions |\
3245 grep STARTED | grep -v CANCEL | wc -l")
3246 [[ $cnt -le $maxrequest ]] ||
3247 error "$cnt > $maxrequest too many started requests"
3248 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3249 $HSM_PARAM.actions |\
3250 grep WAITING | wc -l")
3251 echo "max=$maxrequest started=$cnt waiting=$wt"
3256 run_test 250 "Coordinator max request"
3259 # test needs a running copytool
3263 local f=$DIR/$tdir/$tfile
3264 local fid=$(make_large_for_cancel $f)
3267 # to have a short test
3268 local old_to=$(get_hsm_param active_request_timeout)
3269 set_hsm_param active_request_timeout 4
3270 # to be sure the cdt will wake up frequently so
3271 # it will be able to cancel the "old" request
3272 local old_loop=$(get_hsm_param loop_period)
3273 set_hsm_param loop_period 2
3276 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3277 wait_request_state $fid ARCHIVE STARTED
3279 wait_request_state $fid ARCHIVE CANCELED
3281 set_hsm_param active_request_timeout $old_to
3282 set_hsm_param loop_period $old_loop
3286 run_test 251 "Coordinator request timeout"
3289 # the only way to test ondisk conf is to restart MDS ...
3290 echo "Stop coordinator and remove coordinator state at mount"
3293 # clean on disk conf set by default
3294 cdt_clear_mount_state
3295 cdt_check_state stopped
3297 # check cdt still off after umount/remount
3299 cdt_check_state stopped
3301 echo "Set coordinator start at mount, and start coordinator"
3302 cdt_set_mount_state enabled
3305 cdt_check_state enabled
3307 # check cdt still on after umount/remount
3309 cdt_check_state enabled
3311 # we are back to original state (cdt started at mount)
3313 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3316 local ai=$(get_hsm_param default_archive_id)
3317 local new=$((ai + 1))
3319 set_hsm_param default_archive_id $new -P
3321 local res=$(get_hsm_param default_archive_id)
3324 set_hsm_param default_archive_id "" "-P -d"
3326 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3328 run_test 301 "HSM tunnable are persistent"
3331 local ai=$(get_hsm_param default_archive_id)
3332 local new=$((ai + 1))
3337 set_hsm_param default_archive_id $new -P
3341 cdt_check_state enabled
3343 local res=$(get_hsm_param default_archive_id)
3346 set_hsm_param default_archive_id "" "-P -d"
3348 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3350 run_test 302 "HSM tunnable are persistent when CDT is off"
3355 check_and_cleanup_lustre