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: LU-3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
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 MOUNT_2=${MOUNT_2:-"yes"}
30 # script only handles up to 10 MDTs (because of MDT_PREFIX)
31 [ $MDSCOUNT -gt 9 ] &&
32 error "script cannot handle more than 9 MDTs, please fix" && exit
34 check_and_setup_lustre
36 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
37 skip_env "Need MDS version at least 2.4.53" && exit
40 # $RUNAS_ID may get set incorrectly somewhere else
41 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
42 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
50 # the following associated variables are added:
52 # AGTCOUNT: number of agents
53 # AGTDEV{N}: target HSM mount point (root path of the backend)
54 # agt{N}_HOST: hostname of the agent agt{N}
55 # SINGLEAGT: facet of the single agent
57 # The number of agents is initialized as the number of remote client nodes.
58 # By default, only single copytool is started on a remote client/agent. If there
59 # was no remote client, then the copytool will be started on the local client.
65 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
66 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
68 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
69 if [[ $CLIENTCOUNT -gt 1 ]] &&
70 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
71 skip_env "SHARED_DIRECTORY should be accessible"\
76 # We used to put the HSM archive in $SHARED_DIRECTORY but that
77 # meant NFS issues could hose sanity-hsm sessions. So now we
79 for n in $(seq $AGTCOUNT); do
80 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/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_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
94 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
95 export HSMTOOL_TESTDIR
96 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
97 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
100 # The test only support up to 10 MDTs
101 MDT_PREFIX="mdt.$FSNAME-MDT000"
102 HSM_PARAM="${MDT_PREFIX}0.hsm"
104 # archive is purged at copytool setup
105 HSM_ARCHIVE_PURGE=true
107 # Don't allow copytool error upon start/setup
108 HSMTOOL_NOERROR=false
111 # Get the backend root path for the given agent facet.
114 local dev=AGTDEV$(facet_number $facet)
119 # Stop copytool and unregister an existing changelog user.
121 copytool_monitor_cleanup
124 cdt_set_sanity_policy
129 # get MDT device for each mdc
130 for mdtno in $(seq 1 $MDSCOUNT); do
131 local idx=$(($mdtno - 1))
132 MDT[$idx]=$($LCTL get_param -n \
133 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
134 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
139 local agents=${1:-$(facet_active_host $SINGLEAGT)}
140 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
143 search_and_kill_copytool() {
144 local agents=${1:-$(facet_active_host $SINGLEAGT)}
146 echo "Killing existing copytools on $agents"
147 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
150 copytool_monitor_setup() {
151 local facet=${1:-$SINGLEAGT}
152 local agent=$(facet_active_host $facet)
154 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
155 local test_dir=$(do_node $agent "$cmd") ||
156 error "Failed to create tempdir on $agent"
157 export HSMTOOL_MONITOR_DIR=$test_dir
159 # Create the fifo and a monitor (cat dies when copytool dies)
160 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
161 error "failed to create copytool fifo on $agent"
162 cmd="cat $test_dir/fifo > $test_dir/events &"
163 cmd+=" echo \\\$! > $test_dir/monitor_pid"
165 if [[ $PDSH == *Rmrsh* ]]; then
166 # This is required for pdsh -Rmrsh and its handling of remote
168 # Regular ssh and pdsh -Rssh work fine without this
169 # backgrounded subshell nonsense.
170 (do_node $agent "$cmd") &
171 export HSMTOOL_MONITOR_PDSH=$!
173 # Slightly racy, but just making a best-effort to catch obvious
176 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
177 error "Failed to start copytool monitor on $agent"
179 do_node $agent "$cmd"
181 error "Failed to start copytool monitor on $agent"
186 copytool_monitor_cleanup() {
187 local facet=${1:-$SINGLEAGT}
188 local agent=$(facet_active_host $facet)
190 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
191 # Should die when the copytool dies, but just in case.
192 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
193 cmd+=" 2>/dev/null || true"
194 do_node $agent "$cmd"
195 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
196 export HSMTOOL_MONITOR_DIR=
199 # The pdsh should die on its own when the monitor dies. Just
200 # in case, though, try to clean up to avoid any cruft.
201 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
202 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
203 export HSMTOOL_MONITOR_PDSH=
208 local facet=${1:-$SINGLEAGT}
209 local lustre_mntpnt=${2:-$MOUNT}
211 local hsm_root=${4:-$(copytool_device $facet)}
212 local agent=$(facet_active_host $facet)
214 if [[ -z "$arc_id" ]] &&
215 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
216 echo "Only wakeup running copytool $facet on $agent"
220 if $HSM_ARCHIVE_PURGE; then
221 echo "Purging archive on $agent"
222 do_facet $facet "rm -rf $hsm_root/*"
225 echo "Starting copytool $facet on $agent"
226 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
227 # bandwidth is limited to 1MB/s so the copy time is known and
228 # independent of hardware
229 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
230 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
231 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
232 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
233 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
234 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
235 cmd+=" --bandwidth 1 $lustre_mntpnt"
237 # Redirect the standard output and error to a log file which
238 # can be uploaded to Maloo.
239 local prefix=$TESTLOG_PREFIX
240 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
241 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
243 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
244 if [[ $? != 0 ]]; then
245 [[ $HSMTOOL_NOERROR == true ]] ||
246 error "start copytool $facet on $agent failed"
247 echo "start copytool $facet on $agent failed"
253 get_copytool_event_log() {
254 local facet=${1:-$SINGLEAGT}
255 local agent=$(facet_active_host $facet)
257 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
258 error "Can't get event log: No monitor directory!"
260 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
261 error "Could not collect event log from $agent"
266 local facet=$SINGLEAGT
267 local agents=${1:-$(facet_active_host $facet)}
272 local hsm_root=$(copytool_device $facet)
273 local end_wait=$(( SECONDS + TIMEOUT ))
275 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
277 while (( SECONDS < end_wait )); do
279 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
280 if [ $? -ne 0 ]; then
281 echo "Copytool is stopped on $agents"
284 echo "Copytool still running on $agents"
286 if do_nodesv $agents "pgrep -x $HSMTOOL_BASE"; then
287 error "Copytool failed to stop in ${TIMEOUT}s ..."
289 echo "Copytool has stopped in " \
290 "$((TIMEOUT - (end_wait - SECONDS)))s."
293 # clean all CDTs orphans requests from previous tests
294 # that would otherwise need to timeout to clear.
295 for mdtno in $(seq 1 $MDSCOUNT); do
297 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
298 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
300 # skip already stop[ed,ing] CDTs
301 echo $oldstate | grep stop && continue
303 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
304 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
306 error "mds${mdtno} cdt state is not stopped"
307 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
308 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
310 error "mds${mdtno} cdt state is not $oldstate"
312 if do_facet $facet "df $hsm_root" >/dev/null 2>&1 ; then
313 do_facet $facet "rm -rf $hsm_root/*"
318 local agents=${1:-$(facet_active_host $SINGLEAGT)}
320 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
321 echo "Copytool is suspended on $agents"
324 copytool_remove_backend() {
326 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
327 echo "Remove from backend: $fid = $be"
328 do_facet $SINGLEAGT rm -f $be
332 do_facet $SINGLEAGT \
333 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
334 --import $1 $2 $MOUNT" ||
335 error "import of $1 to $2 failed"
339 local file=$HSM_ARCHIVE/$1
340 do_facet $SINGLEAGT mkdir -p $(dirname $file)
341 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
342 file_creation_failure dd $file $?
346 local file=$HSM_ARCHIVE/$2
347 do_facet $SINGLEAGT mkdir -p $(dirname $file)
348 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
357 if [[ "$value" != "" ]]; then
360 for mdtno in $(seq 1 $MDSCOUNT); do
361 local idx=$(($mdtno - 1))
362 local facet=mds${mdtno}
363 # if $arg include -P option, run 1 set_param per MDT on the MGS
364 # else, run set_param on each MDT
365 [[ $arg = *"-P"* ]] && facet=mgs
366 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
367 [[ $? != 0 ]] && rc=1
377 for mdtno in $(seq 1 $MDSCOUNT); do
378 local idx=$(($mdtno - 1))
379 wait_result mds${mdtno} \
380 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
382 error "$key state is not '$target' on mds${mdtno}"
389 for mdtno in $(seq 1 $MDSCOUNT); do
390 local idx=$(($mdtno - 1))
391 local cl_user=$(do_facet mds${mdtno} $LCTL \
392 --device ${MDT[$idx]} \
393 changelog_register -n)
395 do_facet mds${mdtno} lctl set_param \
396 mdd.${MDT[$idx]}.changelog_mask="+hsm"
397 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
401 changelog_cleanup() {
403 for mdtno in $(seq 1 $MDSCOUNT); do
404 local idx=$(($mdtno - 1))
405 [[ -z ${CL_USERS[$idx]} ]] && continue
406 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
407 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
408 changelog_deregister ${CL_USERS[$idx]}
413 changelog_get_flags() {
418 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
423 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
431 mdts_set_param "$opt -n" "hsm.$param" "$value"
438 mdts_set_param "" hsm_control "$cmd"
439 mdts_check_param hsm_control "$target" 10
442 cdt_set_sanity_policy() {
443 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
446 mdts_set_param "" hsm.policy "+NRA"
447 mdts_set_param "" hsm.policy "-NBR"
448 CDT_POLICY_HAD_CHANGED=
453 mdts_set_param "" hsm.policy "+NRA"
454 CDT_POLICY_HAD_CHANGED=true
457 cdt_clear_no_retry() {
458 mdts_set_param "" hsm.policy "-NRA"
459 CDT_POLICY_HAD_CHANGED=true
462 cdt_set_non_blocking_restore() {
463 mdts_set_param "" hsm.policy "+NBR"
464 CDT_POLICY_HAD_CHANGED=true
467 cdt_clear_non_blocking_restore() {
468 mdts_set_param "" hsm.policy "-NBR"
469 CDT_POLICY_HAD_CHANGED=true
472 cdt_clear_mount_state() {
473 mdts_set_param "-P -d" hsm_control ""
476 cdt_set_mount_state() {
477 mdts_set_param "-P" hsm_control "$1"
481 mdts_check_param hsm_control "$1" 20
485 set_test_state disabled disabled
489 set_test_state enabled enabled
493 set_test_state shutdown stopped
497 set_test_state purge enabled
503 cdt_set_sanity_policy
507 local client_count=$1
508 if [[ $CLIENTCOUNT -lt $client_count ]]; then
509 skip "Need $client_count or more clients, have $CLIENTCOUNT"
516 $LFS path2fid $1 | tr -d '[]'
517 return ${PIPESTATUS[0]}
525 if [[ $u == "user" ]]; then
526 st=$($RUNAS $LFS hsm_state $f)
529 st=$($LFS hsm_state $f)
532 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
534 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
538 get_hsm_archive_id() {
541 st=$($LFS hsm_state $f)
542 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
544 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
553 local st=$(get_hsm_flags $f)
554 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
557 check_hsm_flags_user() {
561 local st=$(get_hsm_flags $f user)
562 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
565 file_creation_failure() {
570 df $MOUNT $MOUNT2 >&2
571 error "cannot create $f with $cmd, status=$err"
583 if [[ "$3" != 1 ]]; then
587 cp $1 $f || file_creation_failure cp $f $?
589 path2fid $f || error "cannot get fid on $f"
593 local file2=${1/$DIR/$DIR2}
594 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
595 file_creation_failure dd $file2 $?
597 path2fid $1 || error "cannot get fid on $1"
601 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
602 file_creation_failure dd $1 $?
603 path2fid $1 || error "cannot get fid on $1"
606 cleanup_large_files() {
607 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
609 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
612 check_enough_free_space() {
615 local need=$((nb * unit /1024))
616 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
617 (( $need >= $free )) && return 1
621 make_large_for_striping() {
622 local file2=${1/$DIR/$DIR2}
623 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
627 check_enough_free_space 5 $sz
628 [ $? != 0 ] && return $?
630 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
631 file_creation_failure dd $file2 $?
633 path2fid $1 || error "cannot get fid on $1"
636 make_large_for_progress() {
637 local file2=${1/$DIR/$DIR2}
641 check_enough_free_space 39 1000000
642 [ $? != 0 ] && return $?
644 # big file is large enough, so copy time is > 30s
645 # so copytool make 1 progress
646 # size is not a multiple of 1M to avoid stripe
648 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
649 file_creation_failure dd $file2 $?
651 path2fid $1 || error "cannot get fid on $1"
654 make_large_for_progress_aligned() {
655 local file2=${1/$DIR/$DIR2}
659 check_enough_free_space 33 1048576
660 [ $? != 0 ] && return $?
662 # big file is large enough, so copy time is > 30s
663 # so copytool make 1 progress
664 # size is a multiple of 1M to have stripe
666 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
667 file_creation_failure dd $file2 $?
668 path2fid $1 || error "cannot get fid on $1"
671 make_large_for_cancel() {
672 local file2=${1/$DIR/$DIR2}
676 check_enough_free_space 103 1048576
677 [ $? != 0 ] && return $?
679 # Copy timeout is 100s. 105MB => 105s
680 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
681 file_creation_failure dd $file2 $?
682 path2fid $1 || error "cannot get fid on $1"
688 wait_update --verbose $(facet_active_host $facet) "$@"
691 wait_request_state() {
695 # 4th arg (mdt index) is optional
697 local mds=mds$(($mdtidx + 1))
699 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
700 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
702 wait_result $mds "$cmd" $state 200 ||
703 error "request on $fid is not $state on $mds"
706 get_request_state() {
710 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
711 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
714 get_request_count() {
718 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
719 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
726 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
727 [[ -n $fid ]] && cmd+=" | grep '$fid'"
728 cmd+=" | egrep 'WAITING|STARTED'"
730 wait_result $SINGLEMDS "$cmd" "" $timeout ||
731 error "requests did not complete"
734 wait_for_grace_delay() {
735 local val=$(get_hsm_param grace_delay)
742 # python2.6 in EL6 includes an internal json module
743 local json_parser='import json; import fileinput;'
744 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
745 json_parser+='json.loads([line for line in '
746 json_parser+='fileinput.input()][0]).items()])'
748 echo $raw_event | python -c "$json_parser"
751 # populate MDT device array
757 # cleanup from previous bad setup
758 search_and_kill_copytool
760 # for recovery tests, coordinator needs to be started at mount
762 # the lustre conf must be without hsm on (like for sanity.sh)
763 echo "Set HSM on and start"
764 cdt_set_mount_state enabled
765 cdt_check_state enabled
767 echo "Start copytool"
770 echo "Set sanity-hsm HSM policy"
771 cdt_set_sanity_policy
773 # finished requests are quickly removed from list
774 set_hsm_param grace_delay 10
780 local f=$DIR/$tdir/$tfile
784 check_hsm_flags_user $f "0x00000000"
786 $RUNAS $LFS hsm_set --norelease $f ||
787 error "user could not change hsm flags"
788 check_hsm_flags_user $f "0x00000010"
790 $RUNAS $LFS hsm_clear --norelease $f ||
791 error "user could not clear hsm flags"
792 check_hsm_flags_user $f "0x00000000"
794 # User could not change those flags...
795 $RUNAS $LFS hsm_set --exists $f &&
796 error "user should not set this flag"
797 check_hsm_flags_user $f "0x00000000"
800 $LFS hsm_set --exists $f ||
801 error "root could not change hsm flags"
802 check_hsm_flags_user $f "0x00000001"
804 $LFS hsm_clear --exists $f ||
805 error "root could not clear hsm state"
806 check_hsm_flags_user $f "0x00000000"
809 run_test 1 "lfs hsm flags root/non-root access"
813 local f=$DIR/$tdir/$tfile
815 # New files are not dirty
816 check_hsm_flags $f "0x00000000"
818 # For test, we simulate an archived file.
819 $LFS hsm_set --exists $f || error "user could not change hsm flags"
820 check_hsm_flags $f "0x00000001"
822 # chmod do not put the file dirty
823 chmod 600 $f || error "could not chmod test file"
824 check_hsm_flags $f "0x00000001"
826 # chown do not put the file dirty
827 chown $RUNAS_ID $f || error "could not chown test file"
828 check_hsm_flags $f "0x00000001"
830 # truncate put the file dirty
831 $TRUNCATE $f 1 || error "could not truncate test file"
832 check_hsm_flags $f "0x00000003"
834 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
835 check_hsm_flags $f "0x00000001"
837 run_test 2 "Check file dirtyness when doing setattr"
843 # New files are not dirty
845 check_hsm_flags $f "0x00000000"
847 # For test, we simulate an archived file.
848 $LFS hsm_set --exists $f ||
849 error "user could not change hsm flags"
850 check_hsm_flags $f "0x00000001"
852 # Reading a file, does not set dirty
853 cat $f > /dev/null || error "could not read file"
854 check_hsm_flags $f "0x00000001"
856 # Open for write without modifying data, does not set dirty
857 openfile -f O_WRONLY $f || error "could not open test file"
858 check_hsm_flags $f "0x00000001"
860 # Append to a file sets it dirty
861 cp -p /etc/passwd $f.append || error "could not create file"
862 $LFS hsm_set --exists $f.append ||
863 error "user could not change hsm flags"
864 dd if=/etc/passwd of=$f.append bs=1 count=3\
865 conv=notrunc oflag=append status=noxfer ||
866 file_creation_failure dd $f.append $?
867 check_hsm_flags $f.append "0x00000003"
869 # Modify a file sets it dirty
870 cp -p /etc/passwd $f.modify || error "could not create file"
871 $LFS hsm_set --exists $f.modify ||
872 error "user could not change hsm flags"
873 dd if=/dev/zero of=$f.modify bs=1 count=3\
874 conv=notrunc status=noxfer ||
875 file_creation_failure dd $f.modify $?
876 check_hsm_flags $f.modify "0x00000003"
878 # Open O_TRUNC sets dirty
879 cp -p /etc/passwd $f.trunc || error "could not create file"
880 $LFS hsm_set --exists $f.trunc ||
881 error "user could not change hsm flags"
882 cp /etc/group $f.trunc || error "could not override a file"
883 check_hsm_flags $f.trunc "0x00000003"
885 # Mmapped a file sets dirty
886 cp -p /etc/passwd $f.mmap || error "could not create file"
887 $LFS hsm_set --exists $f.mmap ||
888 error "user could not change hsm flags"
889 multiop $f.mmap OSMWUc || error "could not mmap a file"
890 check_hsm_flags $f.mmap "0x00000003"
892 run_test 3 "Check file dirtyness when opening for write"
896 local f=$DIR/$tdir/$tfile
897 local fid=$(make_small $f)
900 local st=$(get_request_state $fid CANCEL)
901 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
903 run_test 4 "Useless cancel must not be registered"
906 # test needs a running copytool
910 local f=$DIR/$tdir/$tfile
911 local fid=$(copy_file /etc/passwd $f)
913 wait_request_state $fid ARCHIVE SUCCEED
915 check_hsm_flags $f "0x00000009"
919 run_test 8 "Test default archive number"
923 local f=$DIR/$tdir/$tfile
924 local fid=$(copy_file /etc/passwd $f)
925 # we do not use the default one to be sure
926 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
928 copytool_setup $SINGLEAGT $MOUNT $new_an
929 $LFS hsm_archive --archive $new_an $f
930 wait_request_state $fid ARCHIVE SUCCEED
932 check_hsm_flags $f "0x00000009"
936 run_test 9 "Use of explicit archive number, with dedicated copytool"
939 needclients 3 || return 0
945 copytool_cleanup $(comma_list $(agts_nodes))
947 # start all of the copytools
948 for n in $(seq $AGTCOUNT); do
952 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
955 for n in $(seq $AGTCOUNT); do
956 file=$DIR/$tdir/$tfile.$n
957 fid=$(make_small $file)
959 $LFS hsm_archive $file || error "could not archive file $file"
960 wait_request_state $fid ARCHIVE SUCCEED
961 check_hsm_flags $file "0x00000009"
965 copytool_cleanup $(comma_list $(agts_nodes))
967 run_test 9a "Multiple remote agents"
970 # test needs a running copytool
973 mkdir -p $DIR/$tdir/d1
974 local f=$DIR/$tdir/$tfile
975 local fid=$(copy_file /etc/hosts $f)
976 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
977 error "hsm_archive failed"
978 wait_request_state $fid ARCHIVE SUCCEED
980 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
981 error "fid $fid not in archive $HSM_ARCHIVE"
982 echo "Verifying content"
983 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
984 echo "Verifying hsm state "
985 check_hsm_flags $f "0x00000009"
987 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
988 local st=$(get_hsm_archive_id $f)
989 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
990 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
995 run_test 10a "Archive a file"
998 # test needs a running copytool
1002 local f=$DIR/$tdir/$tfile
1003 local fid=$(copy_file /etc/hosts $f)
1004 $LFS hsm_archive $f || error "archive request failed"
1005 wait_request_state $fid ARCHIVE SUCCEED
1007 $LFS hsm_archive $f || error "archive of non dirty file failed"
1008 local cnt=$(get_request_count $fid ARCHIVE)
1009 [[ "$cnt" == "1" ]] ||
1010 error "archive of non dirty file must not make a request"
1014 run_test 10b "Archive of non dirty file must work without doing request"
1017 # test needs a running copytool
1021 local f=$DIR/$tdir/$tfile
1022 local fid=$(copy_file /etc/hosts $f)
1023 $LFS hsm_set --noarchive $f
1024 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1028 run_test 10c "Check forbidden archive"
1031 # test needs a running copytool
1035 local f=$DIR/$tdir/$tfile
1036 local fid=$(copy_file /etc/hosts $f)
1037 $LFS hsm_archive $f || error "cannot archive $f"
1038 wait_request_state $fid ARCHIVE SUCCEED
1040 local ar=$(get_hsm_archive_id $f)
1041 local dflt=$(get_hsm_param default_archive_id)
1042 [[ $ar == $dflt ]] ||
1043 error "archived file is not on default archive: $ar != $dflt"
1047 run_test 10d "Archive a file on the default archive id"
1051 copy2archive /etc/hosts $tdir/$tfile
1052 local f=$DIR/$tdir/$tfile
1054 import_file $tdir/$tfile $f
1055 echo -n "Verifying released state: "
1056 check_hsm_flags $f "0x0000000d"
1058 local LSZ=$(stat -c "%s" $f)
1059 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1061 echo "Verifying imported size $LSZ=$ASZ"
1062 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1063 echo -n "Verifying released pattern: "
1064 local PTRN=$($GETSTRIPE -L $f)
1066 [[ $PTRN == 80000001 ]] || error "Is not released"
1067 local fid=$(path2fid $f)
1068 echo "Verifying new fid $fid in archive"
1070 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1071 error "fid $fid not in archive $HSM_ARCHIVE"
1073 run_test 11a "Import a file"
1076 # test needs a running copytool
1080 local f=$DIR/$tdir/$tfile
1081 local fid=$(copy_file /etc/hosts $f)
1082 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1083 error "hsm_archive failed"
1084 wait_request_state $fid ARCHIVE SUCCEED
1086 local FILE_HASH=$(md5sum $f)
1091 echo "$FILE_HASH" | md5sum -c
1093 [[ $? -eq 0 ]] || error "Restored file differs"
1097 run_test 11b "Import a deleted file using its FID"
1100 # test needs a running copytool
1104 copy2archive /etc/hosts $tdir/$tfile
1106 local f=$DIR/$tdir/$tfile
1107 import_file $tdir/$tfile $f
1108 local f2=$DIR2/$tdir/$tfile
1109 echo "Verifying released state: "
1110 check_hsm_flags $f2 "0x0000000d"
1112 local fid=$(path2fid $f2)
1113 $LFS hsm_restore $f2
1114 wait_request_state $fid RESTORE SUCCEED
1116 echo "Verifying file state: "
1117 check_hsm_flags $f2 "0x00000009"
1119 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1121 [[ $? -eq 0 ]] || error "Restored file differs"
1125 run_test 12a "Restore an imported file explicitly"
1128 # test needs a running copytool
1132 copy2archive /etc/hosts $tdir/$tfile
1134 local f=$DIR/$tdir/$tfile
1135 import_file $tdir/$tfile $f
1136 echo "Verifying released state: "
1137 check_hsm_flags $f "0x0000000d"
1139 cat $f > /dev/null || error "File read failed"
1141 echo "Verifying file state after restore: "
1142 check_hsm_flags $f "0x00000009"
1144 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1146 [[ $? -eq 0 ]] || error "Restored file differs"
1150 run_test 12b "Restore an imported file implicitly"
1153 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1155 # test needs a running copytool
1159 local f=$DIR/$tdir/$tfile
1160 $LFS setstripe -c 2 $f
1162 fid=$(make_large_for_striping $f)
1163 [ $? != 0 ] && skip "not enough free space" && return
1165 local FILE_CRC=$(md5sum $f)
1167 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1168 wait_request_state $fid ARCHIVE SUCCEED
1169 $LFS hsm_release $f || error "release $f failed"
1171 echo "$FILE_CRC" | md5sum -c
1173 [[ $? -eq 0 ]] || error "Restored file differs"
1177 run_test 12c "Restore a file with stripe of 2"
1180 # test needs a running copytool
1185 local f=$DIR/$tdir/$tfile
1186 local fid=$(copy_file /etc/hosts $f)
1187 $LFS hsm_restore $f || error "restore of non archived file failed"
1188 local cnt=$(get_request_count $fid RESTORE)
1189 [[ "$cnt" == "0" ]] ||
1190 error "restore non archived must not make a request"
1191 $LFS hsm_archive $f ||
1192 error "archive request failed"
1193 wait_request_state $fid ARCHIVE SUCCEED
1194 $LFS hsm_restore $f ||
1195 error "restore of non released file failed"
1196 local cnt=$(get_request_count $fid RESTORE)
1197 [[ "$cnt" == "0" ]] ||
1198 error "restore a non dirty file must not make a request"
1202 run_test 12d "Restore of a non archived, non released file must work"\
1203 " without doing request"
1206 # test needs a running copytool
1209 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1210 local f=$DIR/$tdir/$tfile
1211 local fid=$(copy_file /etc/hosts $f)
1212 $LFS hsm_archive $f || error "archive request failed"
1213 wait_request_state $fid ARCHIVE SUCCEED
1216 cat /etc/hosts >> $f
1220 $LFS hsm_restore $f && error "restore a dirty file must fail"
1224 run_test 12e "Check forbidden restore"
1227 # test needs a running copytool
1231 local f=$DIR/$tdir/$tfile
1232 local fid=$(copy_file /etc/hosts $f)
1234 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1235 wait_request_state $fid ARCHIVE SUCCEED
1236 $LFS hsm_release $f || error "release of $f failed"
1238 wait_request_state $fid RESTORE SUCCEED
1240 echo -n "Verifying file state: "
1241 check_hsm_flags $f "0x00000009"
1243 diff -q /etc/hosts $f
1245 [[ $? -eq 0 ]] || error "Restored file differs"
1249 run_test 12f "Restore a released file explicitly"
1252 # test needs a running copytool
1256 local f=$DIR/$tdir/$tfile
1257 local fid=$(copy_file /etc/hosts $f)
1259 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1260 wait_request_state $fid ARCHIVE SUCCEED
1261 $LFS hsm_release $f || error "release of $f failed"
1263 diff -q /etc/hosts $f
1266 # we check we had a restore done
1267 wait_request_state $fid RESTORE SUCCEED
1269 [[ $st -eq 0 ]] || error "Restored file differs"
1273 run_test 12g "Restore a released file implicitly"
1276 needclients 2 || return 0
1278 # test needs a running copytool
1282 local f=$DIR/$tdir/$tfile
1283 local fid=$(copy_file /etc/hosts $f)
1285 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1286 wait_request_state $fid ARCHIVE SUCCEED
1287 $LFS hsm_release $f || error "release of $f failed"
1289 do_node $CLIENT2 diff -q /etc/hosts $f
1292 # we check we had a restore done
1293 wait_request_state $fid RESTORE SUCCEED
1295 [[ $st -eq 0 ]] || error "Restored file differs"
1299 run_test 12h "Restore a released file implicitly from a second node"
1302 # test needs a running copytool
1306 local f=$DIR/$tdir/$tfile
1307 local fid=$(copy_file /etc/passwd $f)
1308 $LFS hsm_archive $f || error "archive of $f failed"
1309 wait_request_state $fid ARCHIVE SUCCEED
1311 $LFS hsm_release $f || error "release of $f failed"
1315 [[ $? -eq 0 ]] || error "Restored file differs"
1319 run_test 12m "Archive/release/implicit restore"
1322 # test needs a running copytool
1326 copy2archive /etc/hosts $tdir/$tfile
1328 local f=$DIR/$tdir/$tfile
1329 import_file $tdir/$tfile $f
1331 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1332 error "Restored file differs"
1334 $LFS hsm_release $f || error "release of $f failed"
1338 run_test 12n "Import/implicit restore/release"
1341 # test needs a running copytool
1345 local f=$DIR/$tdir/$tfile
1346 local fid=$(copy_file /etc/hosts $f)
1348 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1349 wait_request_state $fid ARCHIVE SUCCEED
1350 $LFS hsm_release $f || error "release of $f failed"
1352 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1353 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1355 # set no retry action mode
1358 diff -q /etc/hosts $f
1361 # we check we had a restore failure
1362 wait_request_state $fid RESTORE FAILED
1364 [[ $st -eq 0 ]] && error "Restore must fail"
1366 # remove no retry action mode
1369 # check file is still released
1370 check_hsm_flags $f "0x0000000d"
1372 # retry w/o failure injection
1373 do_facet $SINGLEMDS lctl set_param fail_loc=0
1375 # to be sure previous RESTORE result is gone
1377 wait_for_grace_delay
1379 diff -q /etc/hosts $f
1382 # we check we had a restore done
1383 wait_request_state $fid RESTORE SUCCEED
1385 [[ $st -eq 0 ]] || error "Restored file differs"
1389 run_test 12o "Layout-swap failure during Restore leaves file released"
1392 # test needs a running copytool
1396 local f=$DIR/$tdir/$tfile
1397 local fid=$(copy_file /etc/hosts $f)
1399 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1400 wait_request_state $fid ARCHIVE SUCCEED
1401 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1402 $LFS hsm_release $f || error "cannot release $f"
1403 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1404 $LFS hsm_release $f || error "cannot release $f"
1405 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1409 run_test 12p "implicit restore of a file on copytool mount point"
1412 # test needs a running copytool
1415 local ARC_SUBDIR="import.orig"
1419 # populate directory to be imported
1420 for d in $(seq 1 10); do
1421 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1422 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1423 for f in $(seq 1 10); do
1424 CURR_FILE="$CURR_DIR/$tfile.$f"
1425 # write file-specific data
1426 do_facet $SINGLEAGT \
1427 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1428 "file=$CURR_FILE > $CURR_FILE"
1432 import_file "$ARC_SUBDIR" $DIR/$tdir
1433 # diff lustre content and origin (triggers file restoration)
1434 # there must be 10x10 identical files, and no difference
1435 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1436 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1437 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1438 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1440 [ $cnt_diff -eq 0 ] ||
1441 error "$cnt_diff imported files differ from read data"
1442 [ $cnt_ok -eq 100 ] ||
1443 error "not enough identical files ($cnt_ok != 100)"
1447 run_test 13 "Recursively import and restore a directory"
1450 # test needs a running copytool
1455 local f=$DIR/$tdir/$tfile
1456 local fid=$(make_small $f)
1457 local sum=$(md5sum $f | awk '{print $1}')
1458 $LFS hsm_archive $f || error "could not archive file"
1459 wait_request_state $fid ARCHIVE SUCCEED
1463 # create released file (simulate llapi_hsm_import call)
1465 local fid2=$(path2fid $f)
1466 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1467 $LFS hsm_release $f || error "could not release file"
1469 # rebind the archive to the newly created file
1470 echo "rebind $fid to $fid2"
1472 do_facet $SINGLEAGT \
1473 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1474 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1476 # restore file and compare md5sum
1477 local sum2=$(md5sum $f | awk '{print $1}')
1479 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1483 run_test 14 "Rebind archived file to a new fid"
1486 # test needs a running copytool
1491 local f=$DIR/$tdir/$tfile
1493 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1497 for i in $(seq 1 $count); do
1498 fids[$i]=$(make_small $f.$i)
1499 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1500 $LFS hsm_archive $f.$i || error "could not archive file"
1502 wait_all_done $(($count*60))
1506 for i in $(seq 1 $count); do
1509 local fid2=$(path2fid $f.$i)
1510 # add the rebind operation to the list
1511 echo ${fids[$i]} $fid2 >> $tmpfile
1513 # set it released (simulate llapi_hsm_import call)
1514 $LFS hsm_set --archived --exists $f.$i ||
1515 error "could not force hsm flags"
1516 $LFS hsm_release $f.$i || error "could not release file"
1518 nl=$(wc -l < $tmpfile)
1519 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1521 echo "rebind list of files"
1522 do_facet $SINGLEAGT \
1523 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1524 --rebind $tmpfile $DIR" || error "could not rebind file list"
1526 # restore files and compare md5sum
1527 for i in $(seq 1 $count); do
1528 local sum2=$(md5sum $f.$i | awk '{print $1}')
1529 [[ $sum2 == ${sums[$i]} ]] ||
1530 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1536 run_test 15 "Rebind a list of files"
1539 # test needs a running copytool
1543 # create a known size file so we can verify transfer speed
1546 dd if=/dev/zero of=$ref bs=1M count=20
1549 local f=$DIR/$tdir/$tfile
1550 local fid=$(copy_file $ref $f)
1552 local start=$(date +%s)
1554 wait_request_state $fid ARCHIVE SUCCEED
1555 local end=$(date +%s)
1556 local duration=$((end - start))
1558 [[ $duration -ge $goal ]] ||
1559 error "Transfer is too fast $duration < $goal"
1563 run_test 16 "Test CT bandwith control option"
1568 local f=$DIR/$tdir/$tfile
1569 touch $f || error "touch $f failed"
1571 # Could not release a non-archived file
1572 $LFS hsm_release $f && error "release should not succeed"
1574 # For following tests, we must test them with HS_ARCHIVED set
1575 $LFS hsm_set --exists --archived $f || error "could not add flag"
1577 # Could not release a file if no-release is set
1578 $LFS hsm_set --norelease $f || error "could not add flag"
1579 $LFS hsm_release $f && error "release should not succeed"
1580 $LFS hsm_clear --norelease $f || error "could not remove flag"
1582 # Could not release a file if lost
1583 $LFS hsm_set --lost $f || error "could not add flag"
1584 $LFS hsm_release $f && error "release should not succeed"
1585 $LFS hsm_clear --lost $f || error "could not remove flag"
1587 # Could not release a file if dirty
1588 $LFS hsm_set --dirty $f || error "could not add flag"
1589 $LFS hsm_release $f && error "release should not succeed"
1590 $LFS hsm_clear --dirty $f || error "could not remove flag"
1592 run_test 20 "Release is not permitted"
1595 # test needs a running copytool
1599 local f=$DIR/$tdir/test_release
1601 # Create a file and check its states
1602 local fid=$(make_small $f)
1603 check_hsm_flags $f "0x00000000"
1605 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1606 # used until file is flushed to disk
1607 if [ $(facet_fstype ost1) == "zfs" ]; then
1608 # this causes an OST_SYNC rpc to be sent
1609 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1610 # clear locks to reread file data
1611 cancel_lru_locks osc
1614 local orig_size=$(stat -c "%s" $f)
1615 local orig_blocks=$(stat -c "%b" $f)
1617 start_full_debug_logging
1619 $LFS hsm_archive $f || error "could not archive file"
1620 wait_request_state $fid ARCHIVE SUCCEED
1622 local blocks=$(stat -c "%b" $f)
1623 [ $blocks -eq $orig_blocks ] ||
1624 error "$f: wrong block number after archive: " \
1625 "$blocks != $orig_blocks"
1626 local size=$(stat -c "%s" $f)
1627 [ $size -eq $orig_size ] ||
1628 error "$f: wrong size after archive: $size != $orig_size"
1630 # Release and check states
1631 $LFS hsm_release $f || error "could not release file"
1632 check_hsm_flags $f "0x0000000d"
1634 blocks=$(stat -c "%b" $f)
1635 [ $blocks -gt 5 ] &&
1636 error "$f: too many blocks after release: $blocks > 5"
1637 size=$(stat -c "%s" $f)
1638 [ $size -ne $orig_size ] &&
1639 error "$f: wrong size after release: $size != $orig_size"
1641 # Check we can release an file without stripe info
1645 check_hsm_flags $f "0x00000000"
1646 $LFS hsm_archive $f || error "could not archive file"
1647 wait_request_state $fid ARCHIVE SUCCEED
1649 # Release and check states
1650 $LFS hsm_release $f || error "could not release file"
1651 check_hsm_flags $f "0x0000000d"
1653 # Release again a file that is already released is OK
1654 $LFS hsm_release $f || fail "second release should succeed"
1655 check_hsm_flags $f "0x0000000d"
1657 stop_full_debug_logging
1661 run_test 21 "Simple release tests"
1664 # test needs a running copytool
1669 local f=$DIR/$tdir/test_release
1670 local swap=$DIR/$tdir/test_swap
1672 # Create a file and check its states
1673 local fid=$(make_small $f)
1674 check_hsm_flags $f "0x00000000"
1676 $LFS hsm_archive $f || error "could not archive file"
1677 wait_request_state $fid ARCHIVE SUCCEED
1679 # Release and check states
1680 $LFS hsm_release $f || error "could not release file"
1681 check_hsm_flags $f "0x0000000d"
1684 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1689 run_test 22 "Could not swap a release file"
1692 # test needs a running copytool
1697 local f=$DIR/$tdir/test_mtime
1699 # Create a file and check its states
1700 local fid=$(make_small $f)
1701 check_hsm_flags $f "0x00000000"
1703 $LFS hsm_archive $f || error "could not archive file"
1704 wait_request_state $fid ARCHIVE SUCCEED
1706 # Set modification time in the past
1707 touch -m -a -d @978261179 $f
1709 # Release and check states
1710 $LFS hsm_release $f || error "could not release file"
1711 check_hsm_flags $f "0x0000000d"
1713 local MTIME=$(stat -c "%Y" $f)
1714 local ATIME=$(stat -c "%X" $f)
1715 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1716 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1720 run_test 23 "Release does not change a/mtime (utime)"
1723 local file=$DIR/$tdir/$tfile
1732 # test needs a running copytool
1737 fid=$(make_small $file)
1739 # Create a file and check its states
1740 check_hsm_flags $file "0x00000000"
1742 # Ensure atime is less than mtime and ctime.
1746 atime0=$(stat -c "%X" $file)
1747 mtime0=$(stat -c "%Y" $file)
1748 ctime0=$(stat -c "%Z" $file)
1750 [ $atime0 -lt $mtime0 ] ||
1751 error "atime $atime0 is not less than mtime $mtime0"
1753 [ $atime0 -lt $ctime0 ] ||
1754 error "atime $atime0 is not less than ctime $ctime0"
1756 # Archive should not change any timestamps.
1757 $LFS hsm_archive $file || error "cannot archive '$file'"
1758 wait_request_state $fid ARCHIVE SUCCEED
1760 atime1=$(stat -c "%X" $file)
1761 mtime1=$(stat -c "%Y" $file)
1762 ctime1=$(stat -c "%Z" $file)
1764 [ $atime0 -eq $atime1 ] ||
1765 error "archive changed atime from $atime0 to $atime1"
1767 [ $mtime0 -eq $mtime1 ] ||
1768 error "archive changed mtime from $mtime0 to $mtime1"
1770 [ $ctime0 -eq $ctime1 ] ||
1771 error "archive changed ctime from $ctime0 to $ctime1"
1773 # Release should not change any timestamps.
1774 $LFS hsm_release $file || error "cannot release '$file'"
1775 check_hsm_flags $file "0x0000000d"
1777 atime1=$(stat -c "%X" $file)
1778 mtime1=$(stat -c "%Y" $file)
1779 ctime1=$(stat -c "%Z" $file)
1781 [ $atime0 -eq $atime1 ] ||
1782 error "release changed atime from $atime0 to $atime1"
1784 [ $mtime0 -eq $mtime1 ] ||
1785 error "release changed mtime from $mtime0 to $mtime1"
1787 [ $ctime0 -eq $ctime1 ] ||
1788 error "release changed ctime from $ctime0 to $ctime1"
1790 # Restore should not change atime or mtime and should not
1792 $LFS hsm_restore $file
1793 wait_request_state $fid RESTORE SUCCEED
1795 atime1=$(stat -c "%X" $file)
1796 mtime1=$(stat -c "%Y" $file)
1797 ctime1=$(stat -c "%Z" $file)
1799 [ $atime0 -eq $atime1 ] ||
1800 error "restore changed atime from $atime0 to $atime1"
1802 [ $mtime0 -eq $mtime1 ] ||
1803 error "restore changed mtime from $mtime0 to $mtime1"
1805 [ $ctime0 -le $ctime1 ] ||
1806 error "restore changed ctime from $ctime0 to $ctime1"
1810 # Once more, after unmount and mount.
1811 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1812 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1814 atime1=$(stat -c "%X" $file)
1815 mtime1=$(stat -c "%Y" $file)
1816 ctime1=$(stat -c "%Z" $file)
1818 [ $atime0 -eq $atime1 ] ||
1819 error "remount changed atime from $atime0 to $atime1"
1821 [ $mtime0 -eq $mtime1 ] ||
1822 error "remount changed mtime from $mtime0 to $mtime1"
1824 [ $ctime0 -le $ctime1 ] ||
1825 error "remount changed ctime from $ctime0 to $ctime1"
1827 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1830 local file=$DIR/$tdir/$tfile
1836 # Test needs a running copytool.
1840 # Check that root can do HSM actions on a regular user's file.
1842 fid=$(make_small $file)
1843 sum0=$(md5sum $file)
1845 chown $RUNAS_ID:$RUNAS_GID $file ||
1846 error "cannot chown '$file' to '$RUNAS_ID'"
1848 chmod ugo-w $DIR/$tdir ||
1849 error "cannot chmod '$DIR/$tdir'"
1851 $LFS hsm_archive $file
1852 wait_request_state $fid ARCHIVE SUCCEED
1854 $LFS hsm_release $file
1855 check_hsm_flags $file "0x0000000d"
1857 $LFS hsm_restore $file
1858 wait_request_state $fid RESTORE SUCCEED
1860 # Check that ordinary user can get HSM state.
1861 $RUNAS $LFS hsm_state $file ||
1862 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1864 $LFS hsm_release $file
1865 check_hsm_flags $file "0x0000000d"
1867 # Check that ordinary user can accessed released file.
1868 sum1=$($RUNAS md5sum $file) ||
1869 error "user '$RUNAS_ID' cannot read '$file'"
1871 [ "$sum0" == "$sum1" ] ||
1872 error "md5sum mismatch for '$file'"
1876 run_test 24b "root can archive, release, and restore user files"
1878 cleanup_test_24c() {
1880 set_hsm_param user_request_mask RESTORE
1881 set_hsm_param group_request_mask RESTORE
1882 set_hsm_param other_request_mask RESTORE
1886 local file=$DIR/$tdir/$tfile
1887 local action=archive
1892 # test needs a running copytool
1897 # Save the default masks and check that cleanup_24c will
1898 # restore the request masks correctly.
1899 user_save=$(get_hsm_param user_request_mask)
1900 group_save=$(get_hsm_param group_request_mask)
1901 other_save=$(get_hsm_param other_request_mask)
1903 [ "$user_save" == RESTORE ] ||
1904 error "user_request_mask is '$user_save' expected 'RESTORE'"
1905 [ "$group_save" == RESTORE ] ||
1906 error "group_request_mask is '$group_save' expected 'RESTORE'"
1907 [ "$other_save" == RESTORE ] ||
1908 error "other_request_mask is '$other_save' expected 'RESTORE'"
1910 trap cleanup_test_24c EXIT
1915 chown $RUNAS_ID:nobody $file ||
1916 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1918 set_hsm_param user_request_mask ""
1919 $RUNAS $LFS hsm_$action $file &&
1920 error "$action by user should fail"
1922 set_hsm_param user_request_mask $action
1923 $RUNAS $LFS hsm_$action $file ||
1924 error "$action by user should succeed"
1929 chown nobody:$RUNAS_GID $file ||
1930 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1932 set_hsm_param group_request_mask ""
1933 $RUNAS $LFS hsm_$action $file &&
1934 error "$action by group should fail"
1936 set_hsm_param group_request_mask $action
1937 $RUNAS $LFS hsm_$action $file ||
1938 error "$action by group should succeed"
1943 chown nobody:nobody $file ||
1944 error "cannot chown '$file' to 'nobody:nobody'"
1946 set_hsm_param other_request_mask ""
1947 $RUNAS $LFS hsm_$action $file &&
1948 error "$action by other should fail"
1950 set_hsm_param other_request_mask $action
1951 $RUNAS $LFS hsm_$action $file ||
1952 error "$action by other should succeed"
1957 run_test 24c "check that user,group,other request masks work"
1959 cleanup_test_24d() {
1961 mount -o remount,rw $MOUNT2
1965 local file1=$DIR/$tdir/$tfile
1966 local file2=$DIR2/$tdir/$tfile
1974 fid1=$(make_small $file1)
1976 trap cleanup_test_24d EXIT
1978 mount -o remount,ro $MOUNT2
1980 fid2=$(path2fid $file2)
1981 [ "$fid1" == "$fid2" ] ||
1982 error "FID mismatch '$fid1' != '$fid2'"
1984 $LFS hsm_archive $file2 &&
1985 error "archive should fail on read-only mount"
1986 check_hsm_flags $file1 "0x00000000"
1988 $LFS hsm_archive $file1
1989 wait_request_state $fid1 ARCHIVE SUCCEED
1991 $LFS hsm_release $file1
1992 $LFS hsm_restore $file2
1993 wait_request_state $fid1 RESTORE SUCCEED
1995 $LFS hsm_release $file1 || error "cannot release '$file1'"
1996 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1998 $LFS hsm_release $file2 &&
1999 error "release should fail on read-only mount"
2004 run_test 24d "check that read-only mounts are respected"
2007 # test needs a running copytool
2011 copy2archive /etc/hosts $tdir/$tfile
2013 local f=$DIR/$tdir/$tfile
2015 import_file $tdir/$tfile $f
2017 $LFS hsm_set --lost $f
2022 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2026 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2027 " (Operation not permitted)"
2030 # test needs a running copytool
2035 local f=$DIR/$tdir/$tfile
2036 local fid=$(copy_file /etc/passwd $f)
2038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2039 wait_request_state $fid ARCHIVE SUCCEED
2042 $LFS hsm_set --lost $f
2046 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2050 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2051 " (Operation not permitted)"
2054 # test needs a running copytool
2058 local f=$DIR/$tdir/$tfile
2060 fid=$(make_large_for_progress $f)
2061 [ $? != 0 ] && skip "not enough free space" && return
2063 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2064 wait_request_state $fid ARCHIVE SUCCEED
2067 wait_request_state $fid REMOVE SUCCEED
2069 check_hsm_flags $f "0x00000000"
2073 run_test 26 "Remove the archive of a valid file"
2076 # test needs a running copytool
2080 make_archive $tdir/$tfile
2081 local f=$DIR/$tdir/$tfile
2082 import_file $tdir/$tfile $f
2083 local fid=$(path2fid $f)
2087 [[ $? != 0 ]] || error "Remove of a released file should fail"
2091 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2094 # test needs a running copytool
2098 local f=$DIR/$tdir/$tfile
2100 fid=$(make_large_for_progress $f)
2101 [ $? != 0 ] && skip "not enough free space" && return
2103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2104 wait_request_state $fid ARCHIVE SUCCEED
2109 [[ $? != 0 ]] || error "Remove of a released file should fail"
2113 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2116 # test needs a running copytool
2120 local f=$DIR/$tdir/$tfile
2122 fid=$(make_large_for_progress $f)
2123 [ $? != 0 ] && skip "not enough free space" && return
2125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2126 wait_request_state $fid ARCHIVE SUCCEED
2135 wait_request_state $fid REMOVE SUCCEED
2139 run_test 28 "Concurrent archive/file remove"
2142 # restore at exec cannot work on agent node (because of Linux kernel
2143 # protection of executables)
2144 needclients 2 || return 0
2146 # test needs a running copytool
2150 copy2archive /bin/true $tdir/$tfile
2152 local f=$DIR/$tdir/true
2153 import_file $tdir/$tfile $f
2155 local fid=$(path2fid $f)
2157 # set no retry action mode
2163 # remove no try action mode
2167 [[ $st == 0 ]] || error "Failed to exec a released file"
2171 run_test 30a "Restore at exec (import case)"
2174 # restore at exec cannot work on agent node (because of Linux kernel
2175 # protection of executables)
2176 needclients 2 || return 0
2178 # test needs a running copytool
2182 local f=$DIR/$tdir/true
2183 local fid=$(copy_file /bin/true $f)
2185 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2186 wait_request_state $fid ARCHIVE SUCCEED
2189 # set no retry action mode
2195 # remove no try action mode
2199 [[ $st == 0 ]] || error "Failed to exec a released file"
2203 run_test 30b "Restore at exec (release case)"
2206 needclients 2 || return 0
2208 # test needs a running copytool
2212 local f=$DIR/$tdir/SLEEP
2213 local slp_sum1=$(md5sum /bin/sleep)
2214 local fid=$(copy_file /bin/sleep $f)
2216 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2217 wait_request_state $fid ARCHIVE SUCCEED
2219 check_hsm_flags $f "0x0000000d"
2220 # set no retry action mode
2222 do_node $CLIENT2 "$f 10" &
2226 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2228 [[ $? == 0 ]] || error "Execution failed during run"
2230 if [[ $? != 0 ]]; then
2231 local slp_sum2=$(md5sum /bin/sleep)
2232 # in case sleep file is modified during the test
2233 [[ $slp_sum1 == $slp_sum2 ]] &&
2234 error "Binary overwritten during exec"
2238 # remove no try action mode
2240 check_hsm_flags $f "0x00000009"
2244 run_test 30c "Update during exec of released file must fail"
2246 restore_and_check_size() {
2249 local s=$(stat -c "%s" $f)
2251 local st=$(get_hsm_flags $f)
2255 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2257 n=$(stat -c "%s" $f)
2258 # we echo in both cases to show stat is not
2260 if [[ $n != $s ]]; then
2261 echo "size seen is $n != $s"
2264 echo "size seen is right: $n == $s"
2266 st=$(get_hsm_flags $f)
2270 if [[ $cpt -lt 10 ]]; then
2273 echo " restore is too long"
2274 wait_request_state $fid RESTORE SUCCEED
2280 # test needs a running copytool
2285 make_archive $tdir/$tfile
2286 local f=$DIR/$tdir/$tfile
2287 import_file $tdir/$tfile $f
2288 local fid=$($LFS path2fid $f)
2289 HSM_ARCHIVE_PURGE=false copytool_setup
2291 restore_and_check_size $f $fid
2294 [[ $err -eq 0 ]] || error "File size changed during restore"
2298 run_test 31a "Import a large file and check size during restore"
2302 # test needs a running copytool
2307 local f=$DIR/$tdir/$tfile
2309 fid=$(make_large_for_progress $f)
2310 [ $? != 0 ] && skip "not enough free space" && return
2312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2313 wait_request_state $fid ARCHIVE SUCCEED
2316 restore_and_check_size $f $fid
2319 [[ $err -eq 0 ]] || error "File size changed during restore"
2323 run_test 31b "Restore a large unaligned file and check size during restore"
2326 # test needs a running copytool
2331 local f=$DIR/$tdir/$tfile
2333 fid=$(make_large_for_progress_aligned $f)
2334 [ $? != 0 ] && skip "not enough free space" && return
2336 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2337 wait_request_state $fid ARCHIVE SUCCEED
2340 restore_and_check_size $f $fid
2343 [[ $err -eq 0 ]] || error "File size changed during restore"
2347 run_test 31c "Restore a large aligned file and check size during restore"
2350 # test needs a running copytool
2355 local f=$DIR/$tdir/$tfile
2357 fid=$(make_large_for_progress $f)
2358 [ $? != 0 ] && skip "not enough free space" && return
2360 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2361 wait_request_state $fid ARCHIVE SUCCEED
2364 # to be sure wait_all_done will not be mislead by previous tests
2367 wait_for_grace_delay
2368 # Also raise grace_delay significantly so the Canceled
2369 # Restore action will stay enough long avail.
2370 local old_grace=$(get_hsm_param grace_delay)
2371 set_hsm_param grace_delay 100
2373 md5sum $f >/dev/null &
2375 wait_request_state $fid RESTORE STARTED
2380 # Check restore trigger process was killed
2381 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2385 # instead of waiting+checking both Restore and Cancel ops
2386 # sequentially, wait for both to be finished and then check
2388 wait_all_done 100 $fid
2389 local rstate=$(get_request_state $fid RESTORE)
2390 local cstate=$(get_request_state $fid CANCEL)
2392 # restore orig grace_delay.
2393 set_hsm_param grace_delay $old_grace
2395 if [[ "$rstate" == "CANCELED" ]] ; then
2396 [[ "$cstate" == "SUCCEED" ]] ||
2397 error "Restore state is CANCELED and Cancel state " \
2398 "is not SUCCEED but $cstate"
2399 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2400 elif [[ "$rstate" == "SUCCEED" ]] ; then
2401 [[ "$cstate" == "FAILED" ]] ||
2402 error "Restore state is SUCCEED and Cancel state " \
2403 "is not FAILED but $cstate"
2404 echo "Restore state is SUCCEED, Cancel state is FAILED"
2406 error "Restore state is $rstate and Cancel state is $cstate"
2410 error "Cannot kill process waiting for restore ($killed)"
2414 run_test 33 "Kill a restore waiting process"
2417 # test needs a running copytool
2422 local f=$DIR/$tdir/$tfile
2424 fid=$(make_large_for_progress $f)
2425 [ $? != 0 ] && skip "not enough free space" && return
2427 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2428 wait_request_state $fid ARCHIVE SUCCEED
2431 md5sum $f >/dev/null &
2433 wait_request_state $fid RESTORE STARTED
2435 rm $f || error "rm $f failed"
2436 # rm must not block during restore
2437 wait_request_state $fid RESTORE STARTED
2439 wait_request_state $fid RESTORE SUCCEED
2440 # check md5sum pgm finished
2441 local there=$(ps -o pid,comm hp $pid >/dev/null)
2442 [[ -z $there ]] || error "Restore initiator does not exit"
2444 local rc=$(wait $pid)
2445 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2449 run_test 34 "Remove file during restore"
2452 # test needs a running copytool
2457 local f=$DIR/$tdir/$tfile
2458 local f1=$DIR/$tdir/$tfile-1
2460 fid=$(make_large_for_progress $f)
2461 [ $? != 0 ] && skip "not enough free space" && return
2463 local fid1=$(copy_file /etc/passwd $f1)
2464 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2465 wait_request_state $fid ARCHIVE SUCCEED
2468 md5sum $f >/dev/null &
2470 wait_request_state $fid RESTORE STARTED
2472 mv $f1 $f || error "mv $f1 $f failed"
2473 # mv must not block during restore
2474 wait_request_state $fid RESTORE STARTED
2476 wait_request_state $fid RESTORE SUCCEED
2477 # check md5sum pgm finished
2478 local there=$(ps -o pid,comm hp $pid >/dev/null)
2479 [[ -z $there ]] || error "Restore initiator does not exit"
2481 local rc=$(wait $pid)
2482 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2485 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2489 run_test 35 "Overwrite file during restore"
2492 # test needs a running copytool
2497 local f=$DIR/$tdir/$tfile
2499 fid=$(make_large_for_progress $f)
2500 [ $? != 0 ] && skip "not enough free space" && return
2502 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2503 wait_request_state $fid ARCHIVE SUCCEED
2506 md5sum $f >/dev/null &
2508 wait_request_state $fid RESTORE STARTED
2511 # rm must not block during restore
2512 wait_request_state $fid RESTORE STARTED
2514 wait_request_state $fid RESTORE SUCCEED
2515 # check md5sum pgm finished
2516 local there=$(ps -o pid,comm hp $pid >/dev/null)
2518 error "Restore initiator does not exit"
2520 local rc=$(wait $pid)
2522 error "Restore initiator failed with $rc"
2526 run_test 36 "Move file during restore"
2529 # LU-5683: check that an archived dirty file can be rearchived.
2531 copytool_setup $SINGLEAGT $MOUNT2
2534 local f=$DIR/$tdir/$tfile
2537 fid=$(make_small $f) || error "cannot create small file"
2539 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2540 wait_request_state $fid ARCHIVE SUCCEED
2541 $LFS hsm_release $f || error "cannot release $f"
2544 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2547 wait_request_state $fid ARCHIVE SUCCEED
2551 run_test 37 "re-archive a dirty file"
2558 for n in $(seq 1 $count); do
2559 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2561 echo "$count archive requests submitted"
2565 local stream_count=4
2566 local file_count=100
2568 local f=$DIR/$tdir/$tfile
2573 for i in $(seq 1 $file_count); do
2574 for p in $(seq 1 $stream_count); do
2575 fid=$(copy_file /etc/hosts $f.$p.$i)
2578 # force copytool to use a local/temp archive dir to ensure best
2579 # performance vs remote/NFS mounts used in auto-tests
2580 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2583 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2585 # to be sure wait_all_done will not be mislead by previous tests
2587 wait_for_grace_delay
2589 # start archive streams in background (archive files in parallel)
2590 for p in $(seq 1 $stream_count); do
2591 multi_archive $f.$p $file_count &
2594 echo -n "Wait for all requests being enqueued..."
2600 run_test 40 "Parallel archive requests"
2603 # test needs a running copytool
2607 local f=$DIR/$tdir/$tfile
2608 local fid=$(copy_file /etc/motd $f 1)
2610 $LFS hsm_archive $f || error "could not archive file"
2611 wait_request_state $fid ARCHIVE SUCCEED
2612 check_hsm_flags $f "0x00000009"
2614 multiop_bg_pause $f O_c || error "multiop failed"
2618 client_up || client_up || true
2620 kill -USR1 $MULTIPID
2621 wait $MULTIPID || error "multiop close failed"
2623 check_hsm_flags $f "0x0000000b"
2627 run_test 52 "Opened for write file on an evicted client should be set dirty"
2630 # test needs a running copytool
2634 local f=$DIR/$tdir/$tfile
2635 local fid=$(copy_file /etc/motd $f 1)
2637 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2638 error "could not archive file"
2639 wait_request_state $fid ARCHIVE SUCCEED
2640 check_hsm_flags $f "0x00000009"
2642 multiop_bg_pause $f o_c || error "multiop failed"
2646 client_up || client_up || true
2648 kill -USR1 $MULTIPID
2649 wait $MULTIPID || error "multiop close failed"
2651 check_hsm_flags $f "0x00000009"
2655 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2658 # test needs a running copytool
2662 local f=$DIR/$tdir/$tfile
2663 local fid=$(make_large_for_progress $f)
2665 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2666 error "could not archive file"
2667 wait_request_state $fid ARCHIVE STARTED
2669 check_hsm_flags $f "0x00000001"
2671 # Avoid coordinator resending this request as soon it has failed.
2676 wait_request_state $fid ARCHIVE FAILED
2678 check_hsm_flags $f "0x00000003"
2683 run_test 54 "Write during an archive cancels it"
2686 # test needs a running copytool
2690 local f=$DIR/$tdir/$tfile
2691 local fid=$(make_large_for_progress $f)
2693 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2694 error "could not archive file"
2695 wait_request_state $fid ARCHIVE STARTED
2697 check_hsm_flags $f "0x00000001"
2699 # Avoid coordinator resending this request as soon it has failed.
2702 $TRUNCATE $f 1024 || error "truncate failed"
2704 wait_request_state $fid ARCHIVE FAILED
2706 check_hsm_flags $f "0x00000003"
2711 run_test 55 "Truncate during an archive cancels it"
2714 # test needs a running copytool
2718 local f=$DIR/$tdir/$tfile
2720 fid=$(make_large_for_progress $f)
2721 [ $? != 0 ] && skip "not enough free space" && return
2723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2724 error "could not archive file"
2725 wait_request_state $fid ARCHIVE STARTED
2727 check_hsm_flags $f "0x00000001"
2729 # Change metadata and sync to be sure we are not changing only
2734 wait_request_state $fid ARCHIVE SUCCEED
2736 check_hsm_flags $f "0x00000009"
2740 run_test 56 "Setattr during an archive is ok"
2743 # Need one client for I/O, one for request
2744 needclients 2 || return 0
2746 # test needs a running copytool
2750 local f=$DIR/$tdir/test_archive_remote
2751 # Create a file on a remote node
2752 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2753 "count=2 conv=fsync"
2756 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2757 error "hsm_archive failed"
2758 local fid=$(path2fid $f)
2759 wait_request_state $fid ARCHIVE SUCCEED
2761 # Release and implicit restore it
2762 do_node $CLIENT2 "$LFS hsm_release $f" ||
2763 error "hsm_release failed"
2764 do_node $CLIENT2 "md5sum $f" ||
2765 error "hsm_restore failed"
2767 wait_request_state $fid RESTORE SUCCEED
2771 run_test 57 "Archive a file with dirty cache on another node"
2773 truncate_released_file() {
2777 local sz=$(stat -c %s $src_file)
2778 local f=$DIR/$tdir/$tfile
2779 local fid=$(copy_file $1 $f)
2783 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2784 error "could not archive file"
2785 wait_request_state $fid ARCHIVE SUCCEED
2787 $LFS hsm_release $f || error "could not release file"
2789 $TRUNCATE $f $trunc_to || error "truncate failed"
2792 local sz1=$(stat -c %s $f)
2793 [[ $sz1 == $trunc_to ]] ||
2794 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2797 check_hsm_flags $f "0x0000000b"
2799 local state=$(get_request_state $fid RESTORE)
2800 [[ "$state" == "SUCCEED" ]] ||
2801 error "truncate $sz does not trig restore, state = $state"
2803 $TRUNCATE $ref $trunc_to
2804 cmp $ref $f || error "file data wrong after truncate"
2810 # test needs a running copytool
2815 local sz=$(stat -c %s /etc/passwd)
2817 echo "truncate up from $sz to $((sz*2))"
2818 truncate_released_file /etc/passwd $((sz*2))
2820 echo "truncate down from $sz to $((sz/2))"
2821 truncate_released_file /etc/passwd $((sz/2))
2823 echo "truncate to 0"
2824 truncate_released_file /etc/passwd 0
2828 run_test 58 "Truncate a released file will trigger restore"
2831 # This test validates the fix for LU-4512. Ensure that the -u
2832 # option changes the progress reporting interval from the
2833 # default (30 seconds) to the user-specified interval.
2835 local progress_timeout=$((interval * 4))
2837 # test needs a new running copytool
2839 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2842 local f=$DIR/$tdir/$tfile
2844 fid=$(make_large_for_progress $f)
2845 [ $? != 0 ] && skip "not enough free space" && return
2848 local mdt=${MDT_PREFIX}${mdtidx}
2849 local mds=mds$((mdtidx + 1))
2851 # Wait for copytool to register
2852 wait_update_facet $mds \
2853 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2854 uuid 100 || error "coyptool failed to register with $mdt"
2856 local start_at=$(date +%s)
2857 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2858 error "could not archive file"
2860 local agent=$(facet_active_host $SINGLEAGT)
2861 local prefix=$TESTLOG_PREFIX
2862 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
2863 local copytool_log=$prefix.copytool_log.$agent.log
2866 wait_update $agent \
2867 "grep -o start.copy $copytool_log" "start copy" 100 ||
2868 error "copytool failed to start"
2870 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2871 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2877 echo -n "Expecting a progress update within $progress_timeout seconds... "
2879 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2880 if [ $RESULT -gt 0 ]; then
2881 echo "$RESULT bytes copied in $WAIT seconds."
2883 elif [ $WAIT -ge $progress_timeout ]; then
2884 error "Timed out waiting for progress update!"
2887 WAIT=$((WAIT + sleep))
2891 local finish_at=$(date +%s)
2892 local elapsed=$((finish_at - start_at))
2894 # Ensure that the progress update occurred within the expected window.
2895 if [ $elapsed -lt $interval ]; then
2896 error "Expected progress update after at least $interval seconds"
2902 run_test 60 "Changing progress update interval from default"
2905 # test needs a new running copytool
2907 copytool_monitor_setup
2908 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2910 # Just start and stop the copytool to generate events.
2913 # Wait for the copytool to register.
2914 wait_update --verbose $(facet_active_host mds1) \
2915 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
2917 error "copytool failed to register with MDT0000"
2921 local REGISTER_EVENT
2922 local UNREGISTER_EVENT
2923 while read event; do
2924 local parsed=$(parse_json_event "$event")
2925 if [ -z "$parsed" ]; then
2926 error "Copytool sent malformed event: $event"
2930 if [ $event_type == "REGISTER" ]; then
2931 REGISTER_EVENT=$event
2932 elif [ $event_type == "UNREGISTER" ]; then
2933 UNREGISTER_EVENT=$event
2935 done < <(echo $"$(get_copytool_event_log)")
2937 if [ -z "$REGISTER_EVENT" ]; then
2938 error "Copytool failed to send register event to FIFO"
2941 if [ -z "$UNREGISTER_EVENT" ]; then
2942 error "Copytool failed to send unregister event to FIFO"
2945 copytool_monitor_cleanup
2946 echo "Register/Unregister events look OK."
2948 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2951 # Bump progress interval for livelier events.
2954 # test needs a new running copytool
2956 copytool_monitor_setup
2957 HSMTOOL_UPDATE_INTERVAL=$interval \
2958 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2961 local f=$DIR/$tdir/$tfile
2963 fid=$(make_large_for_progress $f)
2964 [ $? != 0 ] && skip "not enough free space" && return
2966 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2967 error "could not archive file"
2968 wait_request_state $fid ARCHIVE SUCCEED
2970 local expected_fields="event_time data_fid source_fid"
2971 expected_fields+=" total_bytes current_bytes"
2975 while read event; do
2976 # Make sure we're not getting anything from previous events.
2977 for field in $expected_fields; do
2981 local parsed=$(parse_json_event "$event")
2982 if [ -z "$parsed" ]; then
2983 error "Copytool sent malformed event: $event"
2987 if [ $event_type == "ARCHIVE_START" ]; then
2990 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2993 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2997 # Do some simple checking of the progress update events.
2998 for expected_field in $expected_fields; do
2999 if [ -z ${!expected_field+x} ]; then
3000 error "Missing $expected_field field in event"
3004 if [ $total_bytes -eq 0 ]; then
3005 error "Expected total_bytes to be > 0"
3008 # These should be identical throughout an archive
3010 if [ $source_fid != $data_fid ]; then
3011 error "Expected source_fid to equal data_fid"
3013 done < <(echo $"$(get_copytool_event_log)")
3015 if [ -z "$START_EVENT" ]; then
3016 error "Copytool failed to send archive start event to FIFO"
3019 if [ -z "$FINISH_EVENT" ]; then
3020 error "Copytool failed to send archive finish event to FIFO"
3023 echo "Archive events look OK."
3027 copytool_monitor_cleanup
3029 run_test 71 "Copytool logs JSON archive events to FIFO"
3032 # Bump progress interval for livelier events.
3035 # test needs a new running copytool
3037 copytool_monitor_setup
3038 HSMTOOL_UPDATE_INTERVAL=$interval \
3039 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3040 local test_file=$HSMTOOL_MONITOR_DIR/file
3042 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3044 do_facet $SINGLEAGT "$cmd" ||
3045 error "cannot create $test_file on $SINGLEAGT"
3046 copy2archive $test_file $tdir/$tfile
3049 local f=$DIR/$tdir/$tfile
3050 import_file $tdir/$tfile $f
3051 f=$DIR2/$tdir/$tfile
3052 echo "Verifying released state: "
3053 check_hsm_flags $f "0x0000000d"
3055 local fid=$(path2fid $f)
3057 wait_request_state $fid RESTORE SUCCEED
3059 local expected_fields="event_time data_fid source_fid"
3060 expected_fields+=" total_bytes current_bytes"
3064 while read event; do
3065 # Make sure we're not getting anything from previous events.
3066 for field in $expected_fields; do
3070 local parsed=$(parse_json_event "$event")
3071 if [ -z "$parsed" ]; then
3072 error "Copytool sent malformed event: $event"
3076 if [ $event_type == "RESTORE_START" ]; then
3078 if [ $source_fid != $data_fid ]; then
3079 error "source_fid should == data_fid at start"
3082 elif [ $event_type == "RESTORE_FINISH" ]; then
3084 if [ $source_fid != $data_fid ]; then
3085 error "source_fid should == data_fid at finish"
3088 elif [ $event_type != "RESTORE_RUNNING" ]; then
3092 # Do some simple checking of the progress update events.
3093 for expected_field in $expected_fields; do
3094 if [ -z ${!expected_field+x} ]; then
3095 error "Missing $expected_field field in event"
3099 if [ $total_bytes -eq 0 ]; then
3100 error "Expected total_bytes to be > 0"
3103 # When a restore starts out, the data fid is the same as the
3104 # source fid. After the restore has gotten going, we learn
3105 # the new data fid. Once the restore has finished, the source
3106 # fid is set to the new data fid.
3108 # We test this because some monitoring software may depend on
3109 # this behavior. If it changes, then the consumers of these
3110 # events may need to be modified.
3111 if [ $source_fid == $data_fid ]; then
3112 error "source_fid should != data_fid during restore"
3114 done < <(echo $"$(get_copytool_event_log)")
3116 if [ -z "$START_EVENT" ]; then
3117 error "Copytool failed to send restore start event to FIFO"
3120 if [ -z "$FINISH_EVENT" ]; then
3121 error "Copytool failed to send restore finish event to FIFO"
3124 echo "Restore events look OK."
3128 copytool_monitor_cleanup
3132 run_test 72 "Copytool logs JSON restore events to FIFO"
3135 file_count=51 # Max number of files constrained by LNET message size
3136 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3137 local f=$DIR/$tdir/$tfile
3138 local FILELIST=/tmp/filelist.txt
3142 for i in $(seq 1 $file_count); do
3143 fid=$(copy_file /etc/hosts $f.$i)
3144 echo $f.$i >> $FILELIST
3146 # force copytool to use a local/temp archive dir to ensure best
3147 # performance vs remote/NFS mounts used in auto-tests
3148 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3151 local dai=$(get_hsm_param default_archive_id)
3152 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3154 # to be sure wait_all_done will not be mislead by previous tests
3156 wait_for_grace_delay
3157 $LFS hsm_archive --filelist $FILELIST ||
3158 error "cannot archive a file list"
3160 $LFS hsm_release --filelist $FILELIST ||
3161 error "cannot release a file list"
3162 $LFS hsm_restore --filelist $FILELIST ||
3163 error "cannot restore a file list"
3167 run_test 90 "Archive/restore a file list"
3169 double_verify_reset_hsm_param() {
3171 echo "Testing $HSM_PARAM.$p"
3172 local val=$(get_hsm_param $p)
3174 local val2=$(($val * 2))
3175 set_hsm_param $p $val2
3176 val=$(get_hsm_param $p)
3177 [[ $val == $val2 ]] ||
3178 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3179 echo "Set $p to 0 must failed"
3183 set_hsm_param $p $save
3185 if [[ $rc == 0 ]]; then
3186 error "we must not be able to set $HSM_PARAM.$p to 0"
3191 double_verify_reset_hsm_param loop_period
3192 double_verify_reset_hsm_param grace_delay
3193 double_verify_reset_hsm_param active_request_timeout
3194 double_verify_reset_hsm_param max_requests
3195 double_verify_reset_hsm_param default_archive_id
3197 run_test 100 "Set coordinator /proc tunables"
3204 run_test 102 "Verify coordinator control"
3207 # test needs a running copytool
3214 for i in $(seq 1 20); do
3215 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3217 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3221 echo "Current requests"
3222 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3223 $HSM_PARAM.actions |\
3224 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3226 [[ -z "$res" ]] || error "Some request have not been canceled"
3230 run_test 103 "Purge all requests"
3235 # test needs a running copytool
3239 local f=$DIR/$tdir/$tfile
3241 fid=$(make_large_for_progress $f)
3242 [ $? != 0 ] && skip "not enough free space" && return
3244 # if cdt is on, it can serve too quickly the request
3246 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3247 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3248 $HSM_PARAM.actions |\
3249 grep $fid | cut -f16 -d=")
3252 [[ "$data1" == "$DATAHEX" ]] ||
3253 error "Data field in records is ($data1) and not ($DATAHEX)"
3257 run_test 104 "Copy tool data field"
3264 for i in $(seq -w 1 10); do
3265 cp /etc/passwd $DIR/$tdir/$i
3266 $LFS hsm_archive $DIR/$tdir/$i
3268 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3269 $HSM_PARAM.actions |\
3270 grep WAITING | wc -l")
3273 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3274 $HSM_PARAM.actions |\
3275 grep WAITING | wc -l")
3278 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3279 error "Requests count after shutdown $reqcnt2 != "\
3280 "before shutdown $reqcnt1"
3282 run_test 105 "Restart of coordinator"
3284 get_agent_by_uuid_mdt() {
3287 local mds=mds$(($mdtidx + 1))
3288 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3292 check_agent_registered_by_mdt() {
3295 local mds=mds$(($mdtidx + 1))
3296 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3297 if [[ ! -z "$agent" ]]; then
3298 echo "found agent $agent on $mds"
3300 error "uuid $uuid not found in agent list on $mds"
3304 check_agent_unregistered_by_mdt() {
3307 local mds=mds$(($mdtidx + 1))
3308 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3309 if [[ -z "$agent" ]]; then
3310 echo "uuid not found in agent list on $mds"
3312 error "uuid found in agent list on $mds: $agent"
3316 check_agent_registered() {
3319 for mdsno in $(seq 1 $MDSCOUNT); do
3320 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3324 check_agent_unregistered() {
3327 for mdsno in $(seq 1 $MDSCOUNT); do
3328 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3333 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3334 get_client_uuid $MOUNT | cut -d' ' -f2)
3337 check_agent_registered $uuid
3339 search_copytools || error "No copytool found"
3342 check_agent_unregistered $uuid
3345 check_agent_registered $uuid
3349 run_test 106 "Copytool register/unregister"
3352 # test needs a running copytool
3354 # create and archive file
3356 local f1=$DIR/$tdir/$tfile
3357 local fid=$(copy_file /etc/passwd $f1)
3358 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3359 wait_request_state $fid ARCHIVE SUCCEED
3360 # shutdown and restart MDS
3362 # check the copytool still gets messages from MDT
3363 local f2=$DIR/$tdir/2
3364 local fid=$(copy_file /etc/passwd $f2)
3365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3366 # main check of this sanity: this request MUST succeed
3367 wait_request_state $fid ARCHIVE SUCCEED
3370 run_test 107 "Copytool re-register after MDS restart"
3372 policy_set_and_test()
3376 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3377 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3378 [[ "$policy" == "$target" ]] ||
3379 error "Wrong policy after '$change': '$policy' != '$target'"
3383 # to force default policy setting if error
3384 CDT_POLICY_HAD_CHANGED=true
3386 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3387 local default="NonBlockingRestore [NoRetryAction]"
3388 [[ "$policy" == "$default" ]] ||
3389 error "default policy has changed,"\
3390 " '$policy' != '$default' update the test"
3391 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3392 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3393 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3394 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3395 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3396 # useless bacause we know but safer for futur changes to use real value
3397 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3398 echo "Next set_param must failed"
3399 policy_set_and_test "wrong" "$policy"
3402 echo "Back to default policy"
3403 cdt_set_sanity_policy
3405 run_test 109 "Policy display/change"
3408 # test needs a running copytool
3413 copy2archive /etc/passwd $tdir/$tfile
3415 local f=$DIR/$tdir/$tfile
3416 import_file $tdir/$tfile $f
3417 local fid=$(path2fid $f)
3419 cdt_set_non_blocking_restore
3424 wait_request_state $fid RESTORE SUCCEED
3425 cdt_clear_non_blocking_restore
3429 error "md5sum returns $st != 1, "\
3430 "should also perror ENODATA (No data available)"
3434 run_test 110a "Non blocking restore policy (import case)"
3437 # test needs a running copytool
3441 local f=$DIR/$tdir/$tfile
3442 local fid=$(copy_file /etc/passwd $f)
3443 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3444 wait_request_state $fid ARCHIVE SUCCEED
3447 cdt_set_non_blocking_restore
3452 wait_request_state $fid RESTORE SUCCEED
3453 cdt_clear_non_blocking_restore
3457 error "md5sum returns $st != 1, "\
3458 "should also perror ENODATA (No data available)"
3462 run_test 110b "Non blocking restore policy (release case)"
3465 # test needs a running copytool
3469 copy2archive /etc/passwd $tdir/$tfile
3471 local f=$DIR/$tdir/$tfile
3473 import_file $tdir/$tfile $f
3474 local fid=$(path2fid $f)
3478 copytool_remove_backend $fid
3481 wait_request_state $fid RESTORE FAILED
3488 [[ $st == 0 ]] || error "Restore does not failed"
3492 run_test 111a "No retry policy (import case), restore will error"\
3493 " (No such file or directory)"
3496 # test needs a running copytool
3500 local f=$DIR/$tdir/$tfile
3501 local fid=$(copy_file /etc/passwd $f)
3503 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3504 wait_request_state $fid ARCHIVE SUCCEED
3507 copytool_remove_backend $fid
3510 wait_request_state $fid RESTORE FAILED
3517 [[ $st == 0 ]] || error "Restore does not failed"
3521 run_test 111b "No retry policy (release case), restore will error"\
3522 " (No such file or directory)"
3525 # test needs a running copytool
3529 local f=$DIR/$tdir/$tfile
3530 local fid=$(copy_file /etc/passwd $f)
3532 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3533 local l=$($LFS hsm_action $f)
3535 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3539 wait_request_state $fid ARCHIVE SUCCEED
3542 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3546 run_test 112 "State of recorded request"
3549 # test needs a running copytool
3553 local f=$DIR/$tdir/$tfile
3555 fid=$(make_large_for_cancel $f)
3556 [ $? != 0 ] && skip "not enough free space" && return
3558 # test with cdt on is made in test_221
3560 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3563 wait_request_state $fid ARCHIVE CANCELED
3564 wait_request_state $fid CANCEL SUCCEED
3568 run_test 200 "Register/Cancel archive"
3571 # test needs a running copytool
3575 local f=$DIR/$tdir/$tfile
3576 make_archive $tdir/$tfile
3577 import_file $tdir/$tfile $f
3578 local fid=$(path2fid $f)
3580 # test with cdt on is made in test_222
3585 wait_request_state $fid RESTORE CANCELED
3586 wait_request_state $fid CANCEL SUCCEED
3590 run_test 201 "Register/Cancel restore"
3593 # test needs a running copytool
3597 local f=$DIR/$tdir/$tfile
3599 fid=$(make_large_for_progress $f)
3600 [ $? != 0 ] && skip "not enough free space" && return
3602 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3603 wait_request_state $fid ARCHIVE SUCCEED
3609 wait_request_state $fid REMOVE CANCELED
3613 run_test 202 "Register/Cancel remove"
3616 # test needs a running copytool
3621 local f=$DIR/$tdir/$tfile
3622 local fid=$(copy_file /etc/passwd $f)
3626 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3627 wait_request_state $fid ARCHIVE SUCCEED
3629 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3633 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3637 run_test 220 "Changelog for archive"
3640 # test needs a running copytool
3645 local f=$DIR/$tdir/$tfile
3647 fid=$(make_large_for_cancel $f)
3648 [ $? != 0 ] && skip "not enough free space" && return
3652 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3653 wait_request_state $fid ARCHIVE STARTED
3655 wait_request_state $fid ARCHIVE CANCELED
3656 wait_request_state $fid CANCEL SUCCEED
3658 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3661 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3665 run_test 221 "Changelog for archive canceled"
3668 # test needs a running copytool
3672 copy2archive /etc/passwd $tdir/$tfile
3674 local f=$DIR/$tdir/$tfile
3675 import_file $tdir/$tfile $f
3676 local fid=$(path2fid $f)
3681 wait_request_state $fid RESTORE SUCCEED
3683 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3686 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3690 run_test 222a "Changelog for explicit restore"
3693 # test needs a running copytool
3697 local f=$DIR/$tdir/$tfile
3698 local fid=$(copy_file /etc/passwd $f)
3701 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3702 wait_request_state $fid ARCHIVE SUCCEED
3707 wait_request_state $fid RESTORE SUCCEED
3709 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3712 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3716 run_test 222b "Changelog for implicit restore"
3719 # test needs a running copytool
3724 local f=$DIR/$tdir/$tfile
3725 make_archive $tdir/$tfile
3729 import_file $tdir/$tfile $f
3730 local fid=$(path2fid $f)
3733 wait_request_state $fid RESTORE STARTED
3735 wait_request_state $fid RESTORE CANCELED
3736 wait_request_state $fid CANCEL SUCCEED
3738 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3741 [[ $flags == $target ]] ||
3742 error "Changelog flag is $flags not $target"
3746 run_test 223a "Changelog for restore canceled (import case)"
3749 # test needs a running copytool
3754 local f=$DIR/$tdir/$tfile
3756 fid=$(make_large_for_progress $f)
3757 [ $? != 0 ] && skip "not enough free space" && return
3760 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3761 wait_request_state $fid ARCHIVE SUCCEED
3764 wait_request_state $fid RESTORE STARTED
3766 wait_request_state $fid RESTORE CANCELED
3767 wait_request_state $fid CANCEL SUCCEED
3769 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3772 [[ $flags == $target ]] ||
3773 error "Changelog flag is $flags not $target"
3777 run_test 223b "Changelog for restore canceled (release case)"
3780 # test needs a running copytool
3785 local f=$DIR/$tdir/$tfile
3786 local fid=$(copy_file /etc/passwd $f)
3789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3790 wait_request_state $fid ARCHIVE SUCCEED
3793 wait_request_state $fid REMOVE SUCCEED
3795 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3798 [[ $flags == $target ]] ||
3799 error "Changelog flag is $flags not $target"
3803 run_test 224 "Changelog for remove"
3806 # test needs a running copytool
3809 # test is not usable because remove request is too fast
3810 # so it is always finished before cancel can be done ...
3811 echo "Test disabled"
3816 local f=$DIR/$tdir/$tfile
3818 fid=$(make_large_for_progress $f)
3819 [ $? != 0 ] && skip "not enough free space" && return
3822 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3823 wait_request_state $fid ARCHIVE SUCCEED
3825 # if cdt is on, it can serve too quickly the request
3830 wait_request_state $fid REMOVE CANCELED
3831 wait_request_state $fid CANCEL SUCCEED
3833 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3834 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3835 tail -n 1 | awk '{print $5}')
3838 [[ $flags == $target ]] ||
3839 error "Changelog flag is $flags not $target"
3843 run_test 225 "Changelog for remove canceled"
3846 # test needs a running copytool
3851 local f1=$DIR/$tdir/$tfile-1
3852 local f2=$DIR/$tdir/$tfile-2
3853 local f3=$DIR/$tdir/$tfile-3
3854 local fid1=$(copy_file /etc/passwd $f1)
3855 local fid2=$(copy_file /etc/passwd $f2)
3856 copy_file /etc/passwd $f3
3859 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3860 wait_request_state $fid1 ARCHIVE SUCCEED
3862 $LFS hsm_archive $f2
3863 wait_request_state $fid2 ARCHIVE SUCCEED
3865 rm $f1 || error "rm $f1 failed"
3867 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3870 [[ $flags == $target ]] ||
3871 error "Changelog flag is $flags not $target"
3873 mv $f3 $f2 || error "mv $f3 $f2 failed"
3875 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3878 [[ $flags == $target ]] ||
3879 error "Changelog flag is $flags not $target"
3883 run_test 226 "changelog for last rm/mv with exiting archive"
3885 check_flags_changes() {
3893 $LFS hsm_set --$hsm_flag $f ||
3894 error "Cannot set $hsm_flag on $f"
3895 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3896 local seen=${#flags[*]}
3898 [[ $seen == $cnt ]] ||
3899 error "set $hsm_flag: Changelog events $seen != $cnt"
3900 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3901 error "set $hsm_flag: Changelog flags are "\
3902 "${flags[$((cnt - 1))]} not $target"
3904 $LFS hsm_clear --$hsm_flag $f ||
3905 error "Cannot clear $hsm_flag on $f"
3906 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3909 [[ $cnt == $seen ]] ||
3910 error "clear $hsm_flag: Changelog events $seen != $cnt"
3912 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3913 error "clear $hsm_flag: Changelog flag is "\
3914 "${flags[$((cnt - 1))]} not $target"
3918 # test needs a running copytool
3925 for i in norelease noarchive exists archived
3927 local f=$DIR/$tdir/$tfile-$i
3928 local fid=$(copy_file /etc/passwd $f)
3929 check_flags_changes $f $fid $i 0 1
3932 f=$DIR/$tdir/$tfile---lost
3933 fid=$(copy_file /etc/passwd $f)
3934 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3935 wait_request_state $fid ARCHIVE SUCCEED
3936 check_flags_changes $f $fid lost 3 1
3940 run_test 227 "changelog when explicit setting of HSM flags"
3943 # test needs a running copytool
3946 local fid=$(make_small_sync $DIR/$tfile)
3947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3948 wait_request_state $fid ARCHIVE SUCCEED
3950 $LFS hsm_release $DIR/$tfile
3951 check_hsm_flags $DIR/$tfile "0x0000000d"
3953 filefrag $DIR/$tfile | grep " 1 extent found" ||
3954 error "filefrag on released file must return only one extent"
3956 # only newer versions of cp detect sparse files by stat/FIEMAP
3958 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3959 error "copying $DIR/$tfile"
3960 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3962 $LFS hsm_release $DIR/$tfile
3963 check_hsm_flags $DIR/$tfile "0x0000000d"
3965 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3967 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3969 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3970 error "comparing untarred $DIR/$tfile"
3972 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3973 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3976 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3979 # test needs a running copytool
3983 local maxrequest=$(get_hsm_param max_requests)
3984 local rqcnt=$(($maxrequest * 3))
3988 for i in $(seq -w 1 $rqcnt); do
3990 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3992 # we do it in 2 steps, so all requests arrive at the same time
3993 for i in $(seq -w 1 $rqcnt); do
3994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3999 while [[ $cnt != 0 || $wt != 0 ]]; do
4001 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4002 $HSM_PARAM.actions |\
4003 grep STARTED | grep -v CANCEL | wc -l")
4004 [[ $cnt -le $maxrequest ]] ||
4005 error "$cnt > $maxrequest too many started requests"
4006 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4007 $HSM_PARAM.actions |\
4008 grep WAITING | wc -l")
4009 echo "max=$maxrequest started=$cnt waiting=$wt"
4014 run_test 250 "Coordinator max request"
4017 # test needs a running copytool
4021 local f=$DIR/$tdir/$tfile
4023 fid=$(make_large_for_cancel $f)
4024 [ $? != 0 ] && skip "not enough free space" && return
4027 # to have a short test
4028 local old_to=$(get_hsm_param active_request_timeout)
4029 set_hsm_param active_request_timeout 4
4030 # to be sure the cdt will wake up frequently so
4031 # it will be able to cancel the "old" request
4032 local old_loop=$(get_hsm_param loop_period)
4033 set_hsm_param loop_period 2
4036 # clear locks to avoid extra delay caused by flush/cancel
4037 # and thus prevent early copytool death to timeout.
4038 cancel_lru_locks osc
4040 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4041 wait_request_state $fid ARCHIVE STARTED
4043 wait_request_state $fid ARCHIVE CANCELED
4045 set_hsm_param active_request_timeout $old_to
4046 set_hsm_param loop_period $old_loop
4050 run_test 251 "Coordinator request timeout"
4053 # the only way to test ondisk conf is to restart MDS ...
4054 echo "Stop coordinator and remove coordinator state at mount"
4057 # clean on disk conf set by default
4058 cdt_clear_mount_state
4059 cdt_check_state stopped
4061 # check cdt still off after umount/remount
4063 cdt_check_state stopped
4065 echo "Set coordinator start at mount, and start coordinator"
4066 cdt_set_mount_state enabled
4069 cdt_check_state enabled
4071 # check cdt still on after umount/remount
4073 cdt_check_state enabled
4075 # we are back to original state (cdt started at mount)
4077 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4080 local ai=$(get_hsm_param default_archive_id)
4081 local new=$((ai + 1))
4083 set_hsm_param default_archive_id $new -P
4085 local res=$(get_hsm_param default_archive_id)
4088 set_hsm_param default_archive_id "" "-P -d"
4090 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4092 run_test 301 "HSM tunnable are persistent"
4095 local ai=$(get_hsm_param default_archive_id)
4096 local new=$((ai + 1))
4101 set_hsm_param default_archive_id $new -P
4104 for mdtno in $(seq 1 $MDSCOUNT); do
4109 cdt_check_state enabled
4111 local res=$(get_hsm_param default_archive_id)
4114 set_hsm_param default_archive_id "" "-P -d"
4116 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4118 run_test 302 "HSM tunnable are persistent when CDT is off"
4121 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4127 local dir_mdt0=$DIR/$tdir/mdt0
4128 local dir_mdt1=$DIR/$tdir/mdt1
4130 # create 1 dir per MDT
4131 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4132 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4134 # create 1 file in each MDT
4135 local fid1=$(make_small $dir_mdt0/$tfile)
4136 local fid2=$(make_small $dir_mdt1/$tfile)
4138 # check that hsm request on mdt0 is sent to the right MDS
4139 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4140 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4141 echo "archive successful on mdt0"
4143 # check that hsm request on mdt1 is sent to the right MDS
4144 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4145 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4146 echo "archive successful on mdt1"
4149 # clean test files and directories
4150 rm -rf $dir_mdt0 $dir_mdt1
4152 run_test 400 "Single request is sent to the right MDT"
4155 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4161 local dir_mdt0=$DIR/$tdir/mdt0
4162 local dir_mdt1=$DIR/$tdir/mdt1
4164 # create 1 dir per MDT
4165 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4166 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4168 # create 1 file in each MDT
4169 local fid1=$(make_small $dir_mdt0/$tfile)
4170 local fid2=$(make_small $dir_mdt1/$tfile)
4172 # check that compound requests are shunt to the rights MDTs
4173 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4174 error "lfs hsm_archive"
4175 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4176 echo "archive successful on mdt0"
4177 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4178 echo "archive successful on mdt1"
4181 # clean test files and directories
4182 rm -rf $dir_mdt0 $dir_mdt1
4184 run_test 401 "Compound requests split and sent to their respective MDTs"
4186 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4191 local node=$(facet_active_host $facet)
4193 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4194 awk '{print $4}'); do
4195 echo "$3 $mdc on $node"
4196 do_facet $facet "$LCTL --device $mdc $state" || return 1
4201 # make sure there is no running copytool
4204 # deactivate all mdc on agent1
4205 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4207 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4209 check_agent_unregistered "uuid" # match any agent
4211 # no expected running copytool
4212 search_copytools $agent && error "Copytool start should have failed"
4215 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4217 run_test 402 "Copytool start fails if all MDTs are inactive"
4220 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4222 # make sure there is no running copytool
4225 local agent=$(facet_active_host $SINGLEAGT)
4226 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4228 # deactivate all mdc for MDT0001
4229 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4232 # check the agent is registered on MDT0000, and not on MDT0001
4233 check_agent_registered_by_mdt $uuid 0
4234 check_agent_unregistered_by_mdt $uuid 1
4236 # check running copytool process
4237 search_copytools $agent || error "No running copytools on $agent"
4239 # reactivate all mdc for MDT0001
4240 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4242 # make sure the copytool is now registered to all MDTs
4243 check_agent_registered $uuid
4247 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4250 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4254 # create files on both MDT0000 and MDT0001
4257 local dir_mdt0=$DIR/$tdir/mdt0
4258 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4260 # create 1 file on mdt0
4261 local fid1=$(make_small $dir_mdt0/$tfile)
4263 # deactivate all mdc for MDT0001
4264 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4266 # send an HSM request for files in MDT0000
4267 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4269 # check for completion of files in MDT0000
4270 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4271 echo "archive successful on mdt0"
4273 # reactivate all mdc for MDT0001
4274 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4277 # clean test files and directories
4280 run_test 404 "Inactive MDT does not block requests for active MDTs"
4283 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4289 local striped_dir=$DIR/$tdir/striped_dir
4291 # create striped dir on all of MDTs
4292 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4294 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4295 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4296 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4297 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4299 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4300 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4301 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4302 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4304 # check that compound requests are shunt to the rights MDTs
4305 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4306 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4307 error "lfs hsm_archive"
4309 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4310 echo "archive successful on $fid1"
4311 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4312 echo "archive successful on $fid2"
4313 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4314 echo "archive successful on $fid3"
4315 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4316 echo "archive successful on $fid4"
4318 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4319 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4320 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4321 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4323 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4324 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4325 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4326 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4330 run_test 405 "archive and release under striped directory"
4334 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4335 skip "HSM migrate is not supported" && return
4337 # Stop the existing copytool
4340 test_mkdir -p $DIR/$tdir
4341 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4343 run_test 500 "various LLAPI HSM tests"
4348 check_and_cleanup_lustre