Whamcloud - gitweb
67f260e86242e42b4d13ef73070d3b370fac36b4
[fs/lustre-release.git] / lustre / tests / sanity-hsm.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # exit on error
7 set -e
8 set +o monitor
9
10 SRCDIR=$(dirname $0)
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
12
13 ONLY=${ONLY:-"$*"}
14 # bug number for skipped test:    3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # bug number for skipped test:4178         4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # bug number for skipped test:LU-3852
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 251"
20 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
21
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
23
24 . $LUSTRE/tests/test-framework.sh
25 init_test_env $@
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 init_logging
28
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MCREATE=${MCREATE:-mcreate}
32 MOUNT_2=${MOUNT_2:-"yes"}
33 FAIL_ON_ERROR=false
34
35 # script only handles up to 10 MDTs (because of MDT_PREFIX)
36 [ $MDSCOUNT -gt 9 ] &&
37         error "script cannot handle more than 9 MDTs, please fix" && exit
38
39 check_and_setup_lustre
40
41 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
42         skip_env "Need MDS version at least 2.4.53" && exit
43 fi
44
45 # $RUNAS_ID may get set incorrectly somewhere else
46 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
47         skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
48 fi
49 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
50
51 build_test_filter
52
53 #
54 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
55 # the following associated variables are added:
56 #
57 # AGTCOUNT: number of agents
58 # AGTDEV{N}: target HSM mount point (root path of the backend)
59 # agt{N}_HOST: hostname of the agent agt{N}
60 # SINGLEAGT: facet of the single agent
61 #
62 # The number of agents is initialized as the number of remote client nodes.
63 # By default, only single copytool is started on a remote client/agent. If there
64 # was no remote client, then the copytool will be started on the local client.
65 #
66 init_agt_vars() {
67         local n
68         local agent
69
70         export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
71         [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
72
73         export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
74         if [[ $CLIENTCOUNT -gt 1 ]] &&
75                 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
76                 skip_env "SHARED_DIRECTORY should be accessible"\
77                          "on all client nodes"
78                 exit 0
79         fi
80
81         for n in $(seq $AGTCOUNT); do
82                 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
83                 agent=CLIENT$((n + 1))
84                 if [[ -z "${!agent}" ]]; then
85                         [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
86                                 agent=CLIENT2
87                 fi
88                 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
89         done
90
91         export SINGLEAGT=${SINGLEAGT:-agt1}
92
93         export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
94         export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
95         export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
96         export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
97         export HSMTOOL_TESTDIR
98         export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
99         HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
100         HSM_ARCHIVE_NUMBER=2
101
102         # The test only support up to 10 MDTs
103         MDT_PREFIX="mdt.$FSNAME-MDT000"
104         HSM_PARAM="${MDT_PREFIX}0.hsm"
105
106         # archive is purged at copytool setup
107         HSM_ARCHIVE_PURGE=true
108 }
109
110 # Get the backend root path for the given agent facet.
111 copytool_device() {
112         local facet=$1
113         local dev=AGTDEV$(facet_number $facet)
114
115         echo -n ${!dev}
116 }
117
118 # Stop copytool and unregister an existing changelog user.
119 cleanup() {
120         copytool_monitor_cleanup
121         copytool_cleanup
122         changelog_cleanup
123         cdt_set_sanity_policy
124 }
125
126 get_mdt_devices() {
127         local mdtno
128         # get MDT device for each mdc
129         for mdtno in $(seq 1 $MDSCOUNT); do
130                 local idx=$(($mdtno - 1))
131                 MDT[$idx]=$($LCTL get_param -n \
132                         mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
133                         awk '{gsub(/_UUID/,""); print $1}' | head -n1)
134         done
135 }
136
137 search_copytools() {
138         local agents=${1:-$(facet_active_host $SINGLEAGT)}
139         do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
140 }
141
142 search_and_kill_copytool() {
143         local agents=${1:-$(facet_active_host $SINGLEAGT)}
144
145         echo "Killing existing copytools on $agents"
146         do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
147 }
148
149 copytool_monitor_setup() {
150         local facet=${1:-$SINGLEAGT}
151         local agent=$(facet_active_host $facet)
152
153         local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
154         local test_dir=$(do_node $agent "$cmd") ||
155                 error "Failed to create tempdir on $agent"
156         export HSMTOOL_MONITOR_DIR=$test_dir
157
158         # Create the fifo and a monitor (cat dies when copytool dies)
159         do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
160                 error "failed to create copytool fifo on $agent"
161         cmd="cat $test_dir/fifo > $test_dir/events &"
162         cmd+=" echo \\\$! > $test_dir/monitor_pid"
163
164         if [[ $PDSH == *Rmrsh* ]]; then
165                 # This is required for pdsh -Rmrsh and its handling of remote
166                 # shells.
167                 # Regular ssh and pdsh -Rssh work fine without this
168                 # backgrounded subshell nonsense.
169                 (do_node $agent "$cmd") &
170                 export HSMTOOL_MONITOR_PDSH=$!
171
172                 # Slightly racy, but just making a best-effort to catch obvious
173                 # problems.
174                 sleep 1
175                 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
176                         error "Failed to start copytool monitor on $agent"
177         else
178                 do_node $agent "$cmd"
179                 if [ $? != 0 ]; then
180                         error "Failed to start copytool monitor on $agent"
181                 fi
182         fi
183 }
184
185 copytool_monitor_cleanup() {
186         local facet=${1:-$SINGLEAGT}
187         local agent=$(facet_active_host $facet)
188
189         if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
190                 # Should die when the copytool dies, but just in case.
191                 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
192                 cmd+=" 2>/dev/null || true"
193                 do_node $agent "$cmd"
194                 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
195                 export HSMTOOL_MONITOR_DIR=
196         fi
197
198         # The pdsh should die on its own when the monitor dies. Just
199         # in case, though, try to clean up to avoid any cruft.
200         if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
201                 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
202                 export HSMTOOL_MONITOR_PDSH=
203         fi
204 }
205
206 copytool_setup() {
207         local facet=${1:-$SINGLEAGT}
208         local lustre_mntpnt=${2:-$MOUNT}
209         local arc_id=$3
210         local hsm_root=${4:-$(copytool_device $facet)}
211         local agent=$(facet_active_host $facet)
212
213         if [[ -z "$arc_id" ]] &&
214                 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
215                         echo "Wakeup copytool $facet on $agent"
216                         return 0
217         fi
218
219         if $HSM_ARCHIVE_PURGE; then
220                 echo "Purging archive on $agent"
221                 do_facet $facet "rm -rf $hsm_root/*"
222         fi
223
224         echo "Starting copytool $facet on $agent"
225         do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
226         # bandwidth is limited to 1MB/s so the copy time is known and
227         # independent of hardware
228         local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
229         [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
230         [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
231                 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
232         [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
233                 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
234         cmd+=" --bandwidth 1 $lustre_mntpnt"
235
236         # Redirect the standard output and error to a log file which
237         # can be uploaded to Maloo.
238         local prefix=$TESTLOG_PREFIX
239         [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
240         local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
241
242         do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
243                 error "start copytool $facet on $agent failed"
244         trap cleanup EXIT
245 }
246
247 get_copytool_event_log() {
248         local facet=${1:-$SINGLEAGT}
249         local agent=$(facet_active_host $facet)
250
251         [ -z "$HSMTOOL_MONITOR_DIR" ] &&
252                 error "Can't get event log: No monitor directory!"
253
254         do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
255                 error "Could not collect event log from $agent"
256 }
257
258 copytool_cleanup() {
259         trap - EXIT
260         local agents=${1:-$(facet_active_host $SINGLEAGT)}
261         local mdtno
262         local idx
263         local oldstate
264         local mdt_hsmctrl
265
266         do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
267         sleep 1
268         echo "Copytool is stopped on $agents"
269
270         # clean all CDTs orphans requests from previous tests
271         # that would otherwise need to timeout to clear.
272         for mdtno in $(seq 1 $MDSCOUNT); do
273                 idx=$(($mdtno - 1))
274                 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
275                 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
276                                    "$mdt_hsmctrl")
277                 # skip already stop[ed,ing] CDTs
278                 echo $oldstate | grep stop && continue
279
280                 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
281                 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
282                         "stopped" 20 ||
283                         error "mds${mdtno} cdt state is not stopped"
284                 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
285                 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
286                         "$oldstate" 20 ||
287                         error "mds${mdtno} cdt state is not $oldstate"
288         done
289 }
290
291 copytool_suspend() {
292         local agents=${1:-$(facet_active_host $SINGLEAGT)}
293
294         do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
295         echo "Copytool is suspended on $agents"
296 }
297
298 copytool_remove_backend() {
299         local fid=$1
300         local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
301         echo "Remove from backend: $fid = $be"
302         do_facet $SINGLEAGT rm -f $be
303 }
304
305 import_file() {
306         do_facet $SINGLEAGT \
307                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
308                 --import $1 $2 $MOUNT" ||
309                 error "import of $1 to $2 failed"
310 }
311
312 make_archive() {
313         local file=$HSM_ARCHIVE/$1
314         do_facet $SINGLEAGT mkdir -p $(dirname $file)
315         do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
316                 error "cannot create $file"
317 }
318
319 copy2archive() {
320         local file=$HSM_ARCHIVE/$2
321         do_facet $SINGLEAGT mkdir -p $(dirname $file)
322         do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
323 }
324
325 mdts_set_param() {
326         local arg=$1
327         local key=$2
328         local value=$3
329         local mdtno
330         local rc=0
331         if [[ "$value" != "" ]]; then
332                 value="=$value"
333         fi
334         for mdtno in $(seq 1 $MDSCOUNT); do
335                 local idx=$(($mdtno - 1))
336                 local facet=mds${mdtno}
337                 # if $arg include -P option, run 1 set_param per MDT on the MGS
338                 # else, run set_param on each MDT
339                 [[ $arg = *"-P"* ]] && facet=mgs
340                 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
341                 [[ $? != 0 ]] && rc=1
342         done
343         return $rc
344 }
345
346 mdts_check_param() {
347         local key="$1"
348         local target="$2"
349         local timeout="$3"
350         local mdtno
351         for mdtno in $(seq 1 $MDSCOUNT); do
352                 local idx=$(($mdtno - 1))
353                 wait_result mds${mdtno} \
354                         "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
355                         $timeout ||
356                         error "$key state is not '$target' on mds${mdtno}"
357         done
358 }
359
360 changelog_setup() {
361         CL_USERS=()
362         local mdtno
363         for mdtno in $(seq 1 $MDSCOUNT); do
364                 local idx=$(($mdtno - 1))
365                 local cl_user=$(do_facet mds${mdtno} $LCTL \
366                              --device ${MDT[$idx]} \
367                              changelog_register -n)
368                 CL_USERS+=($cl_user)
369                 do_facet mds${mdtno} lctl set_param \
370                         mdd.${MDT[$idx]}.changelog_mask="+hsm"
371                 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
372         done
373 }
374
375 changelog_cleanup() {
376         local mdtno
377         for mdtno in $(seq 1 $MDSCOUNT); do
378                 local idx=$(($mdtno - 1))
379                 [[ -z  ${CL_USERS[$idx]} ]] && continue
380                 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
381                 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
382                         changelog_deregister ${CL_USERS[$idx]}
383         done
384         CL_USERS=()
385 }
386
387 changelog_get_flags() {
388         local mdt=$1
389         local cltype=$2
390         local fid=$3
391
392         $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
393 }
394
395 get_hsm_param() {
396         local param=$1
397         local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
398         echo $val
399 }
400
401 set_hsm_param() {
402         local param=$1
403         local value=$2
404         local opt=$3
405         mdts_set_param "$opt -n" "hsm.$param" "$value"
406         return $?
407 }
408
409 set_test_state() {
410         local cmd=$1
411         local target=$2
412         mdts_set_param "" hsm_control "$cmd"
413         mdts_check_param hsm_control "$target" 10
414 }
415
416 cdt_set_sanity_policy() {
417         if [[ "$CDT_POLICY_HAD_CHANGED" ]]
418         then
419                 # clear all
420                 mdts_set_param "" hsm.policy "+NRA"
421                 mdts_set_param "" hsm.policy "-NBR"
422                 CDT_POLICY_HAD_CHANGED=
423         fi
424 }
425
426 cdt_set_no_retry() {
427         mdts_set_param "" hsm.policy "+NRA"
428         CDT_POLICY_HAD_CHANGED=true
429 }
430
431 cdt_clear_no_retry() {
432         mdts_set_param "" hsm.policy "-NRA"
433         CDT_POLICY_HAD_CHANGED=true
434 }
435
436 cdt_set_non_blocking_restore() {
437         mdts_set_param "" hsm.policy "+NBR"
438         CDT_POLICY_HAD_CHANGED=true
439 }
440
441 cdt_clear_non_blocking_restore() {
442         mdts_set_param "" hsm.policy "-NBR"
443         CDT_POLICY_HAD_CHANGED=true
444 }
445
446 cdt_clear_mount_state() {
447         mdts_set_param "-P -d" hsm_control ""
448 }
449
450 cdt_set_mount_state() {
451         mdts_set_param "-P" hsm_control "$1"
452 }
453
454 cdt_check_state() {
455         mdts_check_param hsm_control "$1" 20
456 }
457
458 cdt_disable() {
459         set_test_state disabled disabled
460 }
461
462 cdt_enable() {
463         set_test_state enabled enabled
464 }
465
466 cdt_shutdown() {
467         set_test_state shutdown stopped
468 }
469
470 cdt_purge() {
471         set_test_state purge enabled
472 }
473
474 cdt_restart() {
475         cdt_shutdown
476         cdt_enable
477         cdt_set_sanity_policy
478 }
479
480 needclients() {
481         local client_count=$1
482         if [[ $CLIENTCOUNT -lt $client_count ]]; then
483                 skip "Need $client_count or more clients, have $CLIENTCOUNT"
484                 return 1
485         fi
486         return 0
487 }
488
489 path2fid() {
490         $LFS path2fid $1 | tr -d '[]'
491 }
492
493 get_hsm_flags() {
494         local f=$1
495         local u=$2
496
497         if [[ $u == "user" ]]; then
498                 local st=$($RUNAS $LFS hsm_state $f)
499         else
500                 local st=$($LFS hsm_state $f)
501                 u=root
502         fi
503
504         [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
505
506         st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
507         echo $st
508 }
509
510 get_hsm_archive_id() {
511         local f=$1
512         local st=$($LFS hsm_state $f)
513         [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
514
515         local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
516                    cut -f2 -d:)
517         echo $ar
518 }
519
520 check_hsm_flags() {
521         local f=$1
522         local fl=$2
523
524         local st=$(get_hsm_flags $f)
525         [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
526 }
527
528 check_hsm_flags_user() {
529         local f=$1
530         local fl=$2
531
532         local st=$(get_hsm_flags $f user)
533         [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
534 }
535
536 copy_file() {
537         local f=
538
539         if [[ -d $2 ]]; then
540                 f=$2/$(basename $1)
541         else
542                 f=$2
543         fi
544
545         if [[ "$3" != 1 ]]; then
546                 f=${f/$DIR/$DIR2}
547         fi
548         rm -f $f
549         cp $1 $f || error "cannot copy $1 to $f"
550         path2fid $f || error "cannot get fid on $f"
551 }
552
553 make_small() {
554         local file2=${1/$DIR/$DIR2}
555         dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
556                 error "cannot create $file2"
557         path2fid $1 || error "cannot get fid on $1"
558 }
559
560 make_small_sync() {
561         dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
562                 error "cannot create $1"
563         path2fid $1 || error "cannot get fid on $1"
564 }
565
566 cleanup_large_files() {
567         local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
568                       sed 's/%//g')
569         [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
570 }
571
572 make_large_for_striping() {
573         local file2=${1/$DIR/$DIR2}
574         local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
575
576         cleanup_large_files
577
578         dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
579                 error "cannot create $file2"
580         path2fid $1 || error "cannot get fid on $1"
581 }
582
583 make_large_for_progress() {
584         local file2=${1/$DIR/$DIR2}
585
586         cleanup_large_files
587
588         # big file is large enough, so copy time is > 30s
589         # so copytool make 1 progress
590         # size is not a multiple of 1M to avoid stripe
591         # aligment
592         dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
593                 error "cannot create $file2"
594         path2fid $1 || error "cannot get fid on $1"
595 }
596
597 make_large_for_progress_aligned() {
598         local file2=${1/$DIR/$DIR2}
599
600         cleanup_large_files
601
602         # big file is large enough, so copy time is > 30s
603         # so copytool make 1 progress
604         # size is a multiple of 1M to have stripe
605         # aligment
606         dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
607                 error "cannot create $file2"
608         path2fid $1 || error "cannot get fid on $1"
609 }
610
611 make_large_for_cancel() {
612         local file2=${1/$DIR/$DIR2}
613
614         cleanup_large_files
615
616         # Copy timeout is 100s. 105MB => 105s
617         dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
618                 error "cannot create $file2"
619         path2fid $1 || error "cannot get fid on $1"
620 }
621
622 wait_result() {
623         local facet=$1
624         shift
625         wait_update --verbose $(facet_active_host $facet) "$@"
626 }
627
628 wait_request_state() {
629         local fid=$1
630         local request=$2
631         local state=$3
632         # 4th arg (mdt index) is optional
633         local mdtidx=${4:-0}
634         local mds=mds$(($mdtidx + 1))
635
636         local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
637         cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
638
639         wait_result $mds "$cmd" $state 100 ||
640                 error "request on $fid is not $state on $mds"
641 }
642
643 get_request_state() {
644         local fid=$1
645         local request=$2
646
647         do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
648                 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
649 }
650
651 get_request_count() {
652         local fid=$1
653         local request=$2
654
655         do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
656                 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
657 }
658
659 wait_all_done() {
660         local timeout=$1
661         local fid=$2
662
663         local cmd="$LCTL get_param -n $HSM_PARAM.actions"
664         [[ -n $fid ]] && cmd+=" | grep '$fid'"
665         cmd+=" | egrep 'WAITING|STARTED'"
666
667         wait_result $SINGLEMDS "$cmd" "" $timeout ||
668                 error "requests did not complete"
669 }
670
671 wait_for_grace_delay() {
672         local val=$(get_hsm_param grace_delay)
673         sleep $val
674 }
675
676 parse_json_event() {
677         local raw_event=$1
678
679         # python2.6 in EL6 includes an internal json module
680         local json_parser='import json; import fileinput;'
681         json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
682         json_parser+='json.loads([line for line in '
683         json_parser+='fileinput.input()][0]).items()])'
684
685         echo $raw_event | python -c "$json_parser"
686 }
687
688 # populate MDT device array
689 get_mdt_devices
690
691 # initiate variables
692 init_agt_vars
693
694 # cleanup from previous bad setup
695 search_and_kill_copytool
696
697 # for recovery tests, coordinator needs to be started at mount
698 # so force it
699 # the lustre conf must be without hsm on (like for sanity.sh)
700 echo "Set HSM on and start"
701 cdt_set_mount_state enabled
702 cdt_check_state enabled
703
704 echo "Start copytool"
705 copytool_setup
706
707 echo "Set sanity-hsm HSM policy"
708 cdt_set_sanity_policy
709
710 # finished requests are quickly removed from list
711 set_hsm_param grace_delay 10
712
713 test_1() {
714         mkdir -p $DIR/$tdir
715         chmod 777 $DIR/$tdir
716
717         local f=$DIR/$tdir/$tfile
718         $RUNAS touch $f
719
720         # User flags
721         check_hsm_flags_user $f "0x00000000"
722
723         $RUNAS $LFS hsm_set --norelease $f ||
724                 error "user could not change hsm flags"
725         check_hsm_flags_user $f "0x00000010"
726
727         $RUNAS $LFS hsm_clear --norelease $f ||
728                 error "user could not clear hsm flags"
729         check_hsm_flags_user $f "0x00000000"
730
731         # User could not change those flags...
732         $RUNAS $LFS hsm_set --exists $f &&
733                 error "user should not set this flag"
734         check_hsm_flags_user $f "0x00000000"
735
736         # ...but root can
737         $LFS hsm_set --exists $f ||
738                 error "root could not change hsm flags"
739         check_hsm_flags_user $f "0x00000001"
740
741         $LFS hsm_clear --exists $f ||
742                 error "root could not clear hsm state"
743         check_hsm_flags_user $f "0x00000000"
744
745 }
746 run_test 1 "lfs hsm flags root/non-root access"
747
748 test_2() {
749         mkdir -p $DIR/$tdir
750         local f=$DIR/$tdir/$tfile
751         touch $f
752         # New files are not dirty
753         check_hsm_flags $f "0x00000000"
754
755         # For test, we simulate an archived file.
756         $LFS hsm_set --exists $f || error "user could not change hsm flags"
757         check_hsm_flags $f "0x00000001"
758
759         # chmod do not put the file dirty
760         chmod 600 $f || error "could not chmod test file"
761         check_hsm_flags $f "0x00000001"
762
763         # chown do not put the file dirty
764         chown $RUNAS_ID $f || error "could not chown test file"
765         check_hsm_flags $f "0x00000001"
766
767         # truncate put the file dirty
768         $TRUNCATE $f 1 || error "could not truncate test file"
769         check_hsm_flags $f "0x00000003"
770
771         $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
772         check_hsm_flags $f "0x00000001"
773 }
774 run_test 2 "Check file dirtyness when doing setattr"
775
776 test_3() {
777         mkdir -p $DIR/$tdir
778         f=$DIR/$tdir/$tfile
779
780         # New files are not dirty
781         cp -p /etc/passwd $f
782         check_hsm_flags $f "0x00000000"
783
784         # For test, we simulate an archived file.
785         $LFS hsm_set --exists $f ||
786                 error "user could not change hsm flags"
787         check_hsm_flags $f "0x00000001"
788
789         # Reading a file, does not set dirty
790         cat $f > /dev/null || error "could not read file"
791         check_hsm_flags $f "0x00000001"
792
793         # Open for write without modifying data, does not set dirty
794         openfile -f O_WRONLY $f || error "could not open test file"
795         check_hsm_flags $f "0x00000001"
796
797         # Append to a file sets it dirty
798         cp -p /etc/passwd $f.append || error "could not create file"
799         $LFS hsm_set --exists $f.append ||
800                 error "user could not change hsm flags"
801         dd if=/etc/passwd of=$f.append bs=1 count=3\
802            conv=notrunc oflag=append status=noxfer ||
803                 error "could not append to test file"
804         check_hsm_flags $f.append "0x00000003"
805
806         # Modify a file sets it dirty
807         cp -p /etc/passwd $f.modify || error "could not create file"
808         $LFS hsm_set --exists $f.modify ||
809                 error "user could not change hsm flags"
810         dd if=/dev/zero of=$f.modify bs=1 count=3\
811            conv=notrunc status=noxfer ||
812                 error "could not modify test file"
813         check_hsm_flags $f.modify "0x00000003"
814
815         # Open O_TRUNC sets dirty
816         cp -p /etc/passwd $f.trunc || error "could not create file"
817         $LFS hsm_set --exists $f.trunc ||
818                 error "user could not change hsm flags"
819         cp /etc/group $f.trunc || error "could not override a file"
820         check_hsm_flags $f.trunc "0x00000003"
821
822         # Mmapped a file sets dirty
823         cp -p /etc/passwd $f.mmap || error "could not create file"
824         $LFS hsm_set --exists $f.mmap ||
825                 error "user could not change hsm flags"
826         multiop $f.mmap OSMWUc || error "could not mmap a file"
827         check_hsm_flags $f.mmap "0x00000003"
828 }
829 run_test 3 "Check file dirtyness when opening for write"
830
831 test_4() {
832         mkdir -p $DIR/$tdir
833         local f=$DIR/$tdir/$tfile
834         local fid=$(make_small $f)
835
836         $LFS hsm_cancel $f
837         local st=$(get_request_state $fid CANCEL)
838         [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
839 }
840 run_test 4 "Useless cancel must not be registered"
841
842 test_8() {
843         # test needs a running copytool
844         copytool_setup
845
846         mkdir -p $DIR/$tdir
847         local f=$DIR/$tdir/$tfile
848         local fid=$(copy_file /etc/passwd $f)
849         $LFS hsm_archive $f
850         wait_request_state $fid ARCHIVE SUCCEED
851
852         check_hsm_flags $f "0x00000009"
853
854         copytool_cleanup
855 }
856 run_test 8 "Test default archive number"
857
858 test_9() {
859         mkdir -p $DIR/$tdir
860         local f=$DIR/$tdir/$tfile
861         local fid=$(copy_file /etc/passwd $f)
862         # we do not use the default one to be sure
863         local new_an=$((HSM_ARCHIVE_NUMBER + 1))
864         copytool_cleanup
865         copytool_setup $SINGLEAGT $MOUNT $new_an
866         $LFS hsm_archive --archive $new_an $f
867         wait_request_state $fid ARCHIVE SUCCEED
868
869         check_hsm_flags $f "0x00000009"
870
871         copytool_cleanup
872 }
873 run_test 9 "Use of explict archive number, with dedicated copytool"
874
875 test_9a() {
876         needclients 3 || return 0
877
878         local n
879         local file
880         local fid
881
882         copytool_cleanup $(comma_list $(agts_nodes))
883
884         # start all of the copytools
885         for n in $(seq $AGTCOUNT); do
886                 copytool_setup agt$n
887         done
888
889         trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
890         # archive files
891         mkdir -p $DIR/$tdir
892         for n in $(seq $AGTCOUNT); do
893                 file=$DIR/$tdir/$tfile.$n
894                 fid=$(make_small $file)
895
896                 $LFS hsm_archive $file || error "could not archive file $file"
897                 wait_request_state $fid ARCHIVE SUCCEED
898                 check_hsm_flags $file "0x00000009"
899         done
900
901         trap - EXIT
902         copytool_cleanup $(comma_list $(agts_nodes))
903 }
904 run_test 9a "Multiple remote agents"
905
906 test_10a() {
907         # test needs a running copytool
908         copytool_setup
909
910         mkdir -p $DIR/$tdir/d1
911         local f=$DIR/$tdir/$tfile
912         local fid=$(copy_file /etc/hosts $f)
913         $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
914                 error "hsm_archive failed"
915         wait_request_state $fid ARCHIVE SUCCEED
916
917         local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
918                 error "fid $fid not in archive $HSM_ARCHIVE"
919         echo "Verifying content"
920         do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
921         echo "Verifying hsm state "
922         check_hsm_flags $f "0x00000009"
923
924         echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
925         local st=$(get_hsm_archive_id $f)
926         [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
927                 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
928
929         copytool_cleanup
930
931 }
932 run_test 10a "Archive a file"
933
934 test_10b() {
935         # test needs a running copytool
936         copytool_setup
937
938         mkdir -p $DIR/$tdir
939         local f=$DIR/$tdir/$tfile
940         local fid=$(copy_file /etc/hosts $f)
941         $LFS hsm_archive $f || error "archive request failed"
942         wait_request_state $fid ARCHIVE SUCCEED
943
944         $LFS hsm_archive $f || error "archive of non dirty file failed"
945         local cnt=$(get_request_count $fid ARCHIVE)
946         [[ "$cnt" == "1" ]] ||
947                 error "archive of non dirty file must not make a request"
948
949         copytool_cleanup
950 }
951 run_test 10b "Archive of non dirty file must work without doing request"
952
953 test_10c() {
954         # test needs a running copytool
955         copytool_setup
956
957         mkdir -p $DIR/$tdir
958         local f=$DIR/$tdir/$tfile
959         local fid=$(copy_file /etc/hosts $f)
960         $LFS hsm_set --noarchive $f
961         $LFS hsm_archive $f && error "archive a noarchive file must fail"
962
963         copytool_cleanup
964 }
965 run_test 10c "Check forbidden archive"
966
967 test_10d() {
968         # test needs a running copytool
969         copytool_setup
970
971         mkdir -p $DIR/$tdir
972         local f=$DIR/$tdir/$tfile
973         local fid=$(copy_file /etc/hosts $f)
974         $LFS hsm_archive $f || error "cannot archive $f"
975         wait_request_state $fid ARCHIVE SUCCEED
976
977         local ar=$(get_hsm_archive_id $f)
978         local dflt=$(get_hsm_param default_archive_id)
979         [[ $ar == $dflt ]] ||
980                 error "archived file is not on default archive: $ar != $dflt"
981
982         copytool_cleanup
983 }
984 run_test 10d "Archive a file on the default archive id"
985
986 test_11a() {
987         mkdir -p $DIR/$tdir
988         copy2archive /etc/hosts $tdir/$tfile
989         local f=$DIR/$tdir/$tfile
990
991         import_file $tdir/$tfile $f
992         echo -n "Verifying released state: "
993         check_hsm_flags $f "0x0000000d"
994
995         local LSZ=$(stat -c "%s" $f)
996         local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
997
998         echo "Verifying imported size $LSZ=$ASZ"
999         [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1000         echo -n "Verifying released pattern: "
1001         local PTRN=$($GETSTRIPE -L $f)
1002         echo $PTRN
1003         [[ $PTRN == 80000001 ]] || error "Is not released"
1004         local fid=$(path2fid $f)
1005         echo "Verifying new fid $fid in archive"
1006
1007         local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1008                 error "fid $fid not in archive $HSM_ARCHIVE"
1009 }
1010 run_test 11a "Import a file"
1011
1012 test_11b() {
1013         # test needs a running copytool
1014         copytool_setup
1015
1016         mkdir -p $DIR/$tdir
1017         local f=$DIR/$tdir/$tfile
1018         local fid=$(copy_file /etc/hosts $f)
1019         $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1020                 error "hsm_archive failed"
1021         wait_request_state $fid ARCHIVE SUCCEED
1022
1023         local FILE_HASH=$(md5sum $f)
1024         rm -f $f
1025
1026         import_file $fid $f
1027
1028         echo "$FILE_HASH" | md5sum -c
1029
1030         [[ $? -eq 0 ]] || error "Restored file differs"
1031
1032         copytool_cleanup
1033 }
1034 run_test 11b "Import a deleted file using its FID"
1035
1036 test_12a() {
1037         # test needs a running copytool
1038         copytool_setup
1039
1040         mkdir -p $DIR/$tdir
1041         copy2archive /etc/hosts $tdir/$tfile
1042
1043         local f=$DIR/$tdir/$tfile
1044         import_file $tdir/$tfile $f
1045         local f2=$DIR2/$tdir/$tfile
1046         echo "Verifying released state: "
1047         check_hsm_flags $f2 "0x0000000d"
1048
1049         local fid=$(path2fid $f2)
1050         $LFS hsm_restore $f2
1051         wait_request_state $fid RESTORE SUCCEED
1052
1053         echo "Verifying file state: "
1054         check_hsm_flags $f2 "0x00000009"
1055
1056         do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1057
1058         [[ $? -eq 0 ]] || error "Restored file differs"
1059
1060         copytool_cleanup
1061 }
1062 run_test 12a "Restore an imported file explicitly"
1063
1064 test_12b() {
1065         # test needs a running copytool
1066         copytool_setup
1067
1068         mkdir -p $DIR/$tdir
1069         copy2archive /etc/hosts $tdir/$tfile
1070
1071         local f=$DIR/$tdir/$tfile
1072         import_file $tdir/$tfile $f
1073         echo "Verifying released state: "
1074         check_hsm_flags $f "0x0000000d"
1075
1076         cat $f > /dev/null || error "File read failed"
1077
1078         echo "Verifying file state after restore: "
1079         check_hsm_flags $f "0x00000009"
1080
1081         do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1082
1083         [[ $? -eq 0 ]] || error "Restored file differs"
1084
1085         copytool_cleanup
1086 }
1087 run_test 12b "Restore an imported file implicitly"
1088
1089 test_12c() {
1090         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1091
1092         # test needs a running copytool
1093         copytool_setup
1094
1095         mkdir -p $DIR/$tdir
1096         local f=$DIR/$tdir/$tfile
1097         $LFS setstripe -c 2 $f
1098         local fid=$(make_large_for_striping $f)
1099         local FILE_CRC=$(md5sum $f)
1100
1101         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1102         wait_request_state $fid ARCHIVE SUCCEED
1103         $LFS hsm_release $f || error "release $f failed"
1104
1105         echo "$FILE_CRC" | md5sum -c
1106
1107         [[ $? -eq 0 ]] || error "Restored file differs"
1108
1109         copytool_cleanup
1110 }
1111 run_test 12c "Restore a file with stripe of 2"
1112
1113 test_12d() {
1114         # test needs a running copytool
1115         copytool_setup
1116
1117         mkdir -p $DIR/$tdir
1118
1119         local f=$DIR/$tdir/$tfile
1120         local fid=$(copy_file /etc/hosts $f)
1121         $LFS hsm_restore $f || error "restore of non archived file failed"
1122         local cnt=$(get_request_count $fid RESTORE)
1123         [[ "$cnt" == "0" ]] ||
1124                 error "restore non archived must not make a request"
1125         $LFS hsm_archive $f ||
1126                 error "archive request failed"
1127         wait_request_state $fid ARCHIVE SUCCEED
1128         $LFS hsm_restore $f ||
1129                 error "restore of non released file failed"
1130         local cnt=$(get_request_count $fid RESTORE)
1131         [[ "$cnt" == "0" ]] ||
1132                 error "restore a non dirty file must not make a request"
1133
1134         copytool_cleanup
1135 }
1136 run_test 12d "Restore of a non archived, non released file must work"\
1137                 " without doing request"
1138
1139 test_12e() {
1140         # test needs a running copytool
1141         copytool_setup
1142
1143         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1144         local f=$DIR/$tdir/$tfile
1145         local fid=$(copy_file /etc/hosts $f)
1146         $LFS hsm_archive $f || error "archive request failed"
1147         wait_request_state $fid ARCHIVE SUCCEED
1148
1149         # make file dirty
1150         cat /etc/hosts >> $f
1151         sync
1152         $LFS hsm_state $f
1153
1154         $LFS hsm_restore $f && error "restore a dirty file must fail"
1155
1156         copytool_cleanup
1157 }
1158 run_test 12e "Check forbidden restore"
1159
1160 test_12f() {
1161         # test needs a running copytool
1162         copytool_setup
1163
1164         mkdir -p $DIR/$tdir
1165         local f=$DIR/$tdir/$tfile
1166         local fid=$(copy_file /etc/hosts $f)
1167
1168         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1169         wait_request_state $fid ARCHIVE SUCCEED
1170         $LFS hsm_release $f || error "release of $f failed"
1171         $LFS hsm_restore $f
1172         wait_request_state $fid RESTORE SUCCEED
1173
1174         echo -n "Verifying file state: "
1175         check_hsm_flags $f "0x00000009"
1176
1177         diff -q /etc/hosts $f
1178
1179         [[ $? -eq 0 ]] || error "Restored file differs"
1180
1181         copytool_cleanup
1182 }
1183 run_test 12f "Restore a released file explicitly"
1184
1185 test_12g() {
1186         # test needs a running copytool
1187         copytool_setup
1188
1189         mkdir -p $DIR/$tdir
1190         local f=$DIR/$tdir/$tfile
1191         local fid=$(copy_file /etc/hosts $f)
1192
1193         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1194         wait_request_state $fid ARCHIVE SUCCEED
1195         $LFS hsm_release $f || error "release of $f failed"
1196
1197         diff -q /etc/hosts $f
1198         local st=$?
1199
1200         # we check we had a restore done
1201         wait_request_state $fid RESTORE SUCCEED
1202
1203         [[ $st -eq 0 ]] || error "Restored file differs"
1204
1205         copytool_cleanup
1206 }
1207 run_test 12g "Restore a released file implicitly"
1208
1209 test_12h() {
1210         needclients 2 || return 0
1211
1212         # test needs a running copytool
1213         copytool_setup
1214
1215         mkdir -p $DIR/$tdir
1216         local f=$DIR/$tdir/$tfile
1217         local fid=$(copy_file /etc/hosts $f)
1218
1219         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1220         wait_request_state $fid ARCHIVE SUCCEED
1221         $LFS hsm_release $f || error "release of $f failed"
1222
1223         do_node $CLIENT2 diff -q /etc/hosts $f
1224         local st=$?
1225
1226         # we check we had a restore done
1227         wait_request_state $fid RESTORE SUCCEED
1228
1229         [[ $st -eq 0 ]] || error "Restored file differs"
1230
1231         copytool_cleanup
1232 }
1233 run_test 12h "Restore a released file implicitly from a second node"
1234
1235 test_12m() {
1236         # test needs a running copytool
1237         copytool_setup
1238
1239         mkdir -p $DIR/$tdir
1240         local f=$DIR/$tdir/$tfile
1241         local fid=$(copy_file /etc/passwd $f)
1242         $LFS hsm_archive $f || error "archive of $f failed"
1243         wait_request_state $fid ARCHIVE SUCCEED
1244
1245         $LFS hsm_release $f || error "release of $f failed"
1246
1247         cmp /etc/passwd $f
1248
1249         [[ $? -eq 0 ]] || error "Restored file differs"
1250
1251         copytool_cleanup
1252 }
1253 run_test 12m "Archive/release/implicit restore"
1254
1255 test_12n() {
1256         # test needs a running copytool
1257         copytool_setup
1258
1259         mkdir -p $DIR/$tdir
1260         copy2archive /etc/hosts $tdir/$tfile
1261
1262         local f=$DIR/$tdir/$tfile
1263         import_file $tdir/$tfile $f
1264
1265         do_facet $SINGLEAGT cmp /etc/hosts $f ||
1266                 error "Restored file differs"
1267
1268         $LFS hsm_release $f || error "release of $f failed"
1269
1270         copytool_cleanup
1271 }
1272 run_test 12n "Import/implicit restore/release"
1273
1274 test_12o() {
1275         # test needs a running copytool
1276         copytool_setup
1277
1278         mkdir -p $DIR/$tdir
1279         local f=$DIR/$tdir/$tfile
1280         local fid=$(copy_file /etc/hosts $f)
1281
1282         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1283         wait_request_state $fid ARCHIVE SUCCEED
1284         $LFS hsm_release $f || error "release of $f failed"
1285
1286 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS           0x152
1287         do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1288
1289         # set no retry action mode
1290         cdt_set_no_retry
1291
1292         diff -q /etc/hosts $f
1293         local st=$?
1294
1295         # we check we had a restore failure
1296         wait_request_state $fid RESTORE FAILED
1297
1298         [[ $st -eq 0 ]] && error "Restore must fail"
1299
1300         # remove no retry action mode
1301         cdt_clear_no_retry
1302
1303         # check file is still released
1304         check_hsm_flags $f "0x0000000d"
1305
1306         # retry w/o failure injection
1307         do_facet $SINGLEMDS lctl set_param fail_loc=0
1308
1309         # to be sure previous RESTORE result is gone
1310         cdt_purge
1311         wait_for_grace_delay
1312
1313         diff -q /etc/hosts $f
1314         st=$?
1315
1316         # we check we had a restore done
1317         wait_request_state $fid RESTORE SUCCEED
1318
1319         [[ $st -eq 0 ]] || error "Restored file differs"
1320
1321         copytool_cleanup
1322 }
1323 run_test 12o "Layout-swap failure during Restore leaves file released"
1324
1325 test_13() {
1326         # test needs a running copytool
1327         copytool_setup
1328
1329         local ARC_SUBDIR="import.orig"
1330         local d=""
1331         local f=""
1332
1333         # populate directory to be imported
1334         for d in $(seq 1 10); do
1335                 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1336                 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1337                 for f in $(seq 1 10); do
1338                         CURR_FILE="$CURR_DIR/$tfile.$f"
1339                         # write file-specific data
1340                         do_facet $SINGLEAGT \
1341                                 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1342                                         "file=$CURR_FILE > $CURR_FILE"
1343                 done
1344         done
1345         # import to Lustre
1346         import_file "$ARC_SUBDIR" $DIR/$tdir
1347         # diff lustre content and origin (triggers file restoration)
1348         # there must be 10x10 identical files, and no difference
1349         local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1350                        $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1351         local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1352                          $DIR/$tdir/$ARC_SUBDIR | wc -l)
1353
1354         [ $cnt_diff -eq 0 ] ||
1355                 error "$cnt_diff imported files differ from read data"
1356         [ $cnt_ok -eq 100 ] ||
1357                 error "not enough identical files ($cnt_ok != 100)"
1358
1359         copytool_cleanup
1360 }
1361 run_test 13 "Recursively import and restore a directory"
1362
1363 test_14() {
1364         # test needs a running copytool
1365         copytool_setup
1366
1367         # archive a file
1368         mkdir -p $DIR/$tdir
1369         local f=$DIR/$tdir/$tfile
1370         local fid=$(make_small $f)
1371         local sum=$(md5sum $f | awk '{print $1}')
1372         $LFS hsm_archive $f || error "could not archive file"
1373         wait_request_state $fid ARCHIVE SUCCEED
1374
1375         # delete the file
1376         rm -f $f
1377         # create released file (simulate llapi_hsm_import call)
1378         touch $f
1379         local fid2=$(path2fid $f)
1380         $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1381         $LFS hsm_release $f || error "could not release file"
1382
1383         # rebind the archive to the newly created file
1384         echo "rebind $fid to $fid2"
1385
1386         do_facet $SINGLEAGT \
1387                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1388                  --rebind $fid $fid2 $DIR" || error "could not rebind file"
1389
1390         # restore file and compare md5sum
1391         local sum2=$(md5sum $f | awk '{print $1}')
1392
1393         [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1394
1395         copytool_cleanup
1396 }
1397 run_test 14 "Rebind archived file to a new fid"
1398
1399 test_15() {
1400         # test needs a running copytool
1401         copytool_setup
1402
1403         # archive files
1404         mkdir -p $DIR/$tdir
1405         local f=$DIR/$tdir/$tfile
1406         local count=5
1407         local tmpfile=$SHARED_DIRECTORY/tmp.$$
1408
1409         local fids=()
1410         local sums=()
1411         for i in $(seq 1 $count); do
1412                 fids[$i]=$(make_small $f.$i)
1413                 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1414                 $LFS hsm_archive $f.$i || error "could not archive file"
1415         done
1416         wait_all_done $(($count*60))
1417
1418         :>$tmpfile
1419         # delete the files
1420         for i in $(seq 1 $count); do
1421                 rm -f $f.$i
1422                 touch $f.$i
1423                 local fid2=$(path2fid $f.$i)
1424                 # add the rebind operation to the list
1425                 echo ${fids[$i]} $fid2 >> $tmpfile
1426
1427                 # set it released (simulate llapi_hsm_import call)
1428                 $LFS hsm_set --archived --exists $f.$i ||
1429                         error "could not force hsm flags"
1430                 $LFS hsm_release $f.$i || error "could not release file"
1431         done
1432         nl=$(wc -l < $tmpfile)
1433         [[ $nl == $count ]] || error "$nl files in list, $count expected"
1434
1435         echo "rebind list of files"
1436         do_facet $SINGLEAGT \
1437                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1438                  --rebind $tmpfile $DIR" || error "could not rebind file list"
1439
1440         # restore files and compare md5sum
1441         for i in $(seq 1 $count); do
1442                 local sum2=$(md5sum $f.$i | awk '{print $1}')
1443                 [[ $sum2 == ${sums[$i]} ]] ||
1444                     error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1445         done
1446
1447         rm -f $tmpfile
1448         copytool_cleanup
1449 }
1450 run_test 15 "Rebind a list of files"
1451
1452 test_16() {
1453         # test needs a running copytool
1454         copytool_setup
1455
1456         local ref=/tmp/ref
1457         # create a known size file so we can verify transfer speed
1458         # 20 MB <-> 20s
1459         local goal=20
1460         dd if=/dev/zero of=$ref bs=1M count=20
1461
1462         mkdir -p $DIR/$tdir
1463         local f=$DIR/$tdir/$tfile
1464         local fid=$(copy_file $ref $f)
1465         rm $ref
1466         local start=$(date +%s)
1467         $LFS hsm_archive $f
1468         wait_request_state $fid ARCHIVE SUCCEED
1469         local end=$(date +%s)
1470         local duration=$((end - start))
1471
1472         [[ $duration -ge $goal ]] ||
1473                 error "Transfer is too fast $duration < $goal"
1474
1475         copytool_cleanup
1476 }
1477 run_test 16 "Test CT bandwith control option"
1478
1479 test_20() {
1480         mkdir -p $DIR/$tdir
1481
1482         local f=$DIR/$tdir/$tfile
1483         touch $f || error "touch $f failed"
1484
1485         # Could not release a non-archived file
1486         $LFS hsm_release $f && error "release should not succeed"
1487
1488         # For following tests, we must test them with HS_ARCHIVED set
1489         $LFS hsm_set --exists --archived $f || error "could not add flag"
1490
1491         # Could not release a file if no-release is set
1492         $LFS hsm_set --norelease $f || error "could not add flag"
1493         $LFS hsm_release $f && error "release should not succeed"
1494         $LFS hsm_clear --norelease $f || error "could not remove flag"
1495
1496         # Could not release a file if lost
1497         $LFS hsm_set --lost $f || error "could not add flag"
1498         $LFS hsm_release $f && error "release should not succeed"
1499         $LFS hsm_clear --lost $f || error "could not remove flag"
1500
1501         # Could not release a file if dirty
1502         $LFS hsm_set --dirty $f || error "could not add flag"
1503         $LFS hsm_release $f && error "release should not succeed"
1504         $LFS hsm_clear --dirty $f || error "could not remove flag"
1505 }
1506 run_test 20 "Release is not permitted"
1507
1508 test_21() {
1509         # test needs a running copytool
1510         copytool_setup
1511
1512         mkdir -p $DIR/$tdir
1513         local f=$DIR/$tdir/test_release
1514
1515         # Create a file and check its states
1516         local fid=$(make_small $f)
1517         check_hsm_flags $f "0x00000000"
1518
1519         # LU-4388/LU-4389 - ZFS does not report full number of blocks
1520         # used until file is flushed to disk
1521         if [  $(facet_fstype ost1) == "zfs" ]; then
1522             # this causes an OST_SYNC rpc to be sent
1523             dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1524             # clear locks to reread file data
1525             cancel_lru_locks osc
1526         fi
1527
1528         local orig_size=$(stat -c "%s" $f)
1529         local orig_blocks=$(stat -c "%b" $f)
1530
1531         start_full_debug_logging
1532
1533         $LFS hsm_archive $f || error "could not archive file"
1534         wait_request_state $fid ARCHIVE SUCCEED
1535
1536         local blocks=$(stat -c "%b" $f)
1537         [ $blocks -eq $orig_blocks ] ||
1538                 error "$f: wrong block number after archive: " \
1539                       "$blocks != $orig_blocks"
1540         local size=$(stat -c "%s" $f)
1541         [ $size -eq $orig_size ] ||
1542                 error "$f: wrong size after archive: $size != $orig_size"
1543
1544         # Release and check states
1545         $LFS hsm_release $f || error "could not release file"
1546         check_hsm_flags $f "0x0000000d"
1547
1548         blocks=$(stat -c "%b" $f)
1549         [ $blocks -gt 5 ] &&
1550                 error "$f: too many blocks after release: $blocks > 5"
1551         size=$(stat -c "%s" $f)
1552         [ $size -ne $orig_size ] &&
1553                 error "$f: wrong size after release: $size != $orig_size"
1554
1555         # Check we can release an file without stripe info
1556         f=$f.nolov
1557         $MCREATE $f
1558         fid=$(path2fid $f)
1559         check_hsm_flags $f "0x00000000"
1560         $LFS hsm_archive $f || error "could not archive file"
1561         wait_request_state $fid ARCHIVE SUCCEED
1562
1563         # Release and check states
1564         $LFS hsm_release $f || error "could not release file"
1565         check_hsm_flags $f "0x0000000d"
1566
1567         # Release again a file that is already released is OK
1568         $LFS hsm_release $f || fail "second release should succeed"
1569         check_hsm_flags $f "0x0000000d"
1570
1571         stop_full_debug_logging
1572
1573         copytool_cleanup
1574 }
1575 run_test 21 "Simple release tests"
1576
1577 test_22() {
1578         # test needs a running copytool
1579         copytool_setup
1580
1581         mkdir -p $DIR/$tdir
1582
1583         local f=$DIR/$tdir/test_release
1584         local swap=$DIR/$tdir/test_swap
1585
1586         # Create a file and check its states
1587         local fid=$(make_small $f)
1588         check_hsm_flags $f "0x00000000"
1589
1590         $LFS hsm_archive $f || error "could not archive file"
1591         wait_request_state $fid ARCHIVE SUCCEED
1592
1593         # Release and check states
1594         $LFS hsm_release $f || error "could not release file"
1595         check_hsm_flags $f "0x0000000d"
1596
1597         make_small $swap
1598         $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1599
1600         true
1601         copytool_cleanup
1602 }
1603 run_test 22 "Could not swap a release file"
1604
1605 test_23() {
1606         # test needs a running copytool
1607         copytool_setup
1608
1609         mkdir -p $DIR/$tdir
1610
1611         local f=$DIR/$tdir/test_mtime
1612
1613         # Create a file and check its states
1614         local fid=$(make_small $f)
1615         check_hsm_flags $f "0x00000000"
1616
1617         $LFS hsm_archive $f || error "could not archive file"
1618         wait_request_state $fid ARCHIVE SUCCEED
1619
1620         # Set modification time in the past
1621         touch -m -a -d @978261179 $f
1622
1623         # Release and check states
1624         $LFS hsm_release $f || error "could not release file"
1625         check_hsm_flags $f "0x0000000d"
1626
1627         local MTIME=$(stat -c "%Y" $f)
1628         local ATIME=$(stat -c "%X" $f)
1629         [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1630         [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1631
1632         copytool_cleanup
1633 }
1634 run_test 23 "Release does not change a/mtime (utime)"
1635
1636 test_24a() {
1637         local file=$DIR/$tdir/$tfile
1638         local fid
1639         local atime0
1640         local atime1
1641         local mtime0
1642         local mtime1
1643         local ctime0
1644         local ctime1
1645
1646         # test needs a running copytool
1647         copytool_setup
1648
1649         mkdir -p $DIR/$tdir
1650         rm -f $file
1651         fid=$(make_small $file)
1652
1653         # Create a file and check its states
1654         check_hsm_flags $file "0x00000000"
1655
1656         # Ensure atime is less than mtime and ctime.
1657         sleep 1
1658         echo >> $file
1659
1660         atime0=$(stat -c "%X" $file)
1661         mtime0=$(stat -c "%Y" $file)
1662         ctime0=$(stat -c "%Z" $file)
1663
1664         [ $atime0 -lt $mtime0 ] ||
1665                 error "atime $atime0 is not less than mtime $mtime0"
1666
1667         [ $atime0 -lt $ctime0 ] ||
1668                 error "atime $atime0 is not less than ctime $ctime0"
1669
1670         # Archive should not change any timestamps.
1671         $LFS hsm_archive $file || error "cannot archive '$file'"
1672         wait_request_state $fid ARCHIVE SUCCEED
1673
1674         atime1=$(stat -c "%X" $file)
1675         mtime1=$(stat -c "%Y" $file)
1676         ctime1=$(stat -c "%Z" $file)
1677
1678         [ $atime0 -eq $atime1 ] ||
1679                 error "archive changed atime from $atime0 to $atime1"
1680
1681         [ $mtime0 -eq $mtime1 ] ||
1682                 error "archive changed mtime from $mtime0 to $mtime1"
1683
1684         [ $ctime0 -eq $ctime1 ] ||
1685                 error "archive changed ctime from $ctime0 to $ctime1"
1686
1687         # Release should not change any timestamps.
1688         $LFS hsm_release $file || error "cannot release '$file'"
1689         check_hsm_flags $file "0x0000000d"
1690
1691         atime1=$(stat -c "%X" $file)
1692         mtime1=$(stat -c "%Y" $file)
1693         ctime1=$(stat -c "%Z" $file)
1694
1695         [ $atime0 -eq $atime1 ] ||
1696                 error "release changed atime from $atime0 to $atime1"
1697
1698         [ $mtime0 -eq $mtime1 ] ||
1699                 error "release changed mtime from $mtime0 to $mtime1"
1700
1701         [ $ctime0 -eq $ctime1 ] ||
1702                 error "release changed ctime from $ctime0 to $ctime1"
1703
1704         # Restore should not change atime or mtime and should not
1705         # decrease ctime.
1706         $LFS hsm_restore $file
1707         wait_request_state $fid RESTORE SUCCEED
1708
1709         atime1=$(stat -c "%X" $file)
1710         mtime1=$(stat -c "%Y" $file)
1711         ctime1=$(stat -c "%Z" $file)
1712
1713         [ $atime0 -eq $atime1 ] ||
1714                 error "restore changed atime from $atime0 to $atime1"
1715
1716         [ $mtime0 -eq $mtime1 ] ||
1717                 error "restore changed mtime from $mtime0 to $mtime1"
1718
1719         [ $ctime0 -le $ctime1 ] ||
1720                 error "restore changed ctime from $ctime0 to $ctime1"
1721
1722         copytool_cleanup
1723
1724         # Once more, after unmount and mount.
1725         umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1726         mount_client $MOUNT || error "cannot mount '$MOUNT'"
1727
1728         atime1=$(stat -c "%X" $file)
1729         mtime1=$(stat -c "%Y" $file)
1730         ctime1=$(stat -c "%Z" $file)
1731
1732         [ $atime0 -eq $atime1 ] ||
1733                 error "remount changed atime from $atime0 to $atime1"
1734
1735         [ $mtime0 -eq $mtime1 ] ||
1736                 error "remount changed mtime from $mtime0 to $mtime1"
1737
1738         [ $ctime0 -le $ctime1 ] ||
1739                 error "remount changed ctime from $ctime0 to $ctime1"
1740 }
1741 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1742
1743 test_24b() {
1744         local file=$DIR/$tdir/$tfile
1745         local fid
1746         local sum0
1747         local sum1
1748         # LU-3811
1749
1750         # Test needs a running copytool.
1751         copytool_setup
1752         mkdir -p $DIR/$tdir
1753
1754         # Check that root can do HSM actions on a ordinary user's file.
1755         rm -f $file
1756         fid=$(make_small $file)
1757         sum0=$(md5sum $file)
1758
1759         chown $RUNAS_ID:$RUNAS_GID $file ||
1760                 error "cannot chown '$file' to '$RUNAS_ID'"
1761
1762         chmod ugo-w $DIR/$tdir ||
1763                 error "cannot chmod '$DIR/$tdir'"
1764
1765         $LFS hsm_archive $file
1766         wait_request_state $fid ARCHIVE SUCCEED
1767
1768         $LFS hsm_release $file
1769         check_hsm_flags $file "0x0000000d"
1770
1771         $LFS hsm_restore $file
1772         wait_request_state $fid RESTORE SUCCEED
1773
1774         # Check that ordinary user can get HSM state.
1775         $RUNAS $LFS hsm_state $file ||
1776                 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1777
1778         $LFS hsm_release $file
1779         check_hsm_flags $file "0x0000000d"
1780
1781         # Check that ordinary user can accessed released file.
1782         sum1=$($RUNAS md5sum $file) ||
1783                 error "user '$RUNAS_ID' cannot read '$file'"
1784
1785         [ "$sum0" == "$sum1" ] ||
1786                 error "md5sum mismatch for '$file'"
1787
1788         copytool_cleanup
1789 }
1790 run_test 24b "root can archive, release, and restore user files"
1791
1792 cleanup_test_24c() {
1793         trap 0
1794         set_hsm_param user_request_mask RESTORE
1795         set_hsm_param group_request_mask RESTORE
1796         set_hsm_param other_request_mask RESTORE
1797 }
1798
1799 test_24c() {
1800         local file=$DIR/$tdir/$tfile
1801         local action=archive
1802         local user_save
1803         local group_save
1804         local other_save
1805
1806         # test needs a running copytool
1807         copytool_setup
1808
1809         mkdir -p $DIR/$tdir
1810
1811         # Save the default masks and check that cleanup_24c will
1812         # restore the request masks correctly.
1813         user_save=$(get_hsm_param user_request_mask)
1814         group_save=$(get_hsm_param group_request_mask)
1815         other_save=$(get_hsm_param other_request_mask)
1816
1817         [ "$user_save" == RESTORE ] ||
1818                 error "user_request_mask is '$user_save' expected 'RESTORE'"
1819         [ "$group_save" == RESTORE ] ||
1820                 error "group_request_mask is '$group_save' expected 'RESTORE'"
1821         [ "$other_save" == RESTORE ] ||
1822                 error "other_request_mask is '$other_save' expected 'RESTORE'"
1823
1824         trap cleanup_test_24c EXIT
1825
1826         # User.
1827         rm -f $file
1828         make_small $file
1829         chown $RUNAS_ID:nobody $file ||
1830                 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1831
1832         set_hsm_param user_request_mask ""
1833         $RUNAS $LFS hsm_$action $file &&
1834                 error "$action by user should fail"
1835
1836         set_hsm_param user_request_mask $action
1837         $RUNAS $LFS hsm_$action $file ||
1838                 error "$action by user should succeed"
1839
1840         # Group.
1841         rm -f $file
1842         make_small $file
1843         chown nobody:$RUNAS_GID $file ||
1844                 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1845
1846         set_hsm_param group_request_mask ""
1847         $RUNAS $LFS hsm_$action $file &&
1848                 error "$action by group should fail"
1849
1850         set_hsm_param group_request_mask $action
1851         $RUNAS $LFS hsm_$action $file ||
1852                 error "$action by group should succeed"
1853
1854         # Other.
1855         rm -f $file
1856         make_small $file
1857         chown nobody:nobody $file ||
1858                 error "cannot chown '$file' to 'nobody:nobody'"
1859
1860         set_hsm_param other_request_mask ""
1861         $RUNAS $LFS hsm_$action $file &&
1862                 error "$action by other should fail"
1863
1864         set_hsm_param other_request_mask $action
1865         $RUNAS $LFS hsm_$action $file ||
1866                 error "$action by other should succeed"
1867
1868         copytool_cleanup
1869         cleanup_test_24c
1870 }
1871 run_test 24c "check that user,group,other request masks work"
1872
1873 cleanup_test_24d() {
1874         trap 0
1875         mount -o remount,rw $MOUNT2
1876 }
1877
1878 test_24d() {
1879         local file1=$DIR/$tdir/$tfile
1880         local file2=$DIR2/$tdir/$tfile
1881         local fid1
1882         local fid2
1883
1884         copytool_setup
1885
1886         mkdir -p $DIR/$tdir
1887         rm -f $file1
1888         fid1=$(make_small $file1)
1889
1890         trap cleanup_test_24d EXIT
1891
1892         mount -o remount,ro $MOUNT2
1893
1894         fid2=$(path2fid $file2)
1895         [ "$fid1" == "$fid2" ] ||
1896                 error "FID mismatch '$fid1' != '$fid2'"
1897
1898         $LFS hsm_archive $file2 &&
1899                 error "archive should fail on read-only mount"
1900         check_hsm_flags $file1 "0x00000000"
1901
1902         $LFS hsm_archive $file1
1903         wait_request_state $fid1 ARCHIVE SUCCEED
1904
1905         $LFS hsm_release $file1
1906         $LFS hsm_restore $file2
1907         wait_request_state $fid1 RESTORE SUCCEED
1908
1909         $LFS hsm_release $file1 || error "cannot release '$file1'"
1910         dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1911
1912         $LFS hsm_release $file2 &&
1913                 error "release should fail on read-only mount"
1914
1915         copytool_cleanup
1916         cleanup_test_24d
1917 }
1918 run_test 24d "check that read-only mounts are respected"
1919
1920 test_25a() {
1921         # test needs a running copytool
1922         copytool_setup
1923
1924         mkdir -p $DIR/$tdir
1925         copy2archive /etc/hosts $tdir/$tfile
1926
1927         local f=$DIR/$tdir/$tfile
1928
1929         import_file $tdir/$tfile $f
1930
1931         $LFS hsm_set --lost $f
1932
1933         md5sum $f
1934         local st=$?
1935
1936         [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1937
1938         copytool_cleanup
1939 }
1940 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1941              " (Operation not permitted)"
1942
1943 test_25b() {
1944         # test needs a running copytool
1945         copytool_setup
1946
1947         mkdir -p $DIR/$tdir
1948
1949         local f=$DIR/$tdir/$tfile
1950         local fid=$(copy_file /etc/passwd $f)
1951
1952         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1953         wait_request_state $fid ARCHIVE SUCCEED
1954
1955         $LFS hsm_release $f
1956         $LFS hsm_set --lost $f
1957         md5sum $f
1958         st=$?
1959
1960         [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1961
1962         copytool_cleanup
1963 }
1964 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1965              " (Operation not permitted)"
1966
1967 test_26() {
1968         # test needs a running copytool
1969         copytool_setup
1970
1971         mkdir -p $DIR/$tdir
1972         local f=$DIR/$tdir/$tfile
1973         local fid=$(make_large_for_progress $f)
1974         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1975         wait_request_state $fid ARCHIVE SUCCEED
1976
1977         $LFS hsm_remove $f
1978         wait_request_state $fid REMOVE SUCCEED
1979
1980         check_hsm_flags $f "0x00000000"
1981
1982         copytool_cleanup
1983 }
1984 run_test 26 "Remove the archive of a valid file"
1985
1986 test_27a() {
1987         # test needs a running copytool
1988         copytool_setup
1989
1990         mkdir -p $DIR/$tdir
1991         make_archive $tdir/$tfile
1992         local f=$DIR/$tdir/$tfile
1993         import_file $tdir/$tfile $f
1994         local fid=$(path2fid $f)
1995
1996         $LFS hsm_remove $f
1997
1998         [[ $? != 0 ]] || error "Remove of a released file should fail"
1999
2000         copytool_cleanup
2001 }
2002 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2003
2004 test_27b() {
2005         # test needs a running copytool
2006         copytool_setup
2007
2008         mkdir -p $DIR/$tdir
2009         local f=$DIR/$tdir/$tfile
2010         local fid=$(make_large_for_progress $f)
2011         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2012         wait_request_state $fid ARCHIVE SUCCEED
2013         $LFS hsm_release $f
2014
2015         $LFS hsm_remove $f
2016
2017         [[ $? != 0 ]] || error "Remove of a released file should fail"
2018
2019         copytool_cleanup
2020 }
2021 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2022
2023 test_28() {
2024         # test needs a running copytool
2025         copytool_setup
2026
2027         mkdir -p $DIR/$tdir
2028         local f=$DIR/$tdir/$tfile
2029         local fid=$(make_large_for_progress $f)
2030         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2031         wait_request_state $fid ARCHIVE SUCCEED
2032
2033         cdt_disable
2034         $LFS hsm_remove $f
2035
2036         rm -f $f
2037
2038         cdt_enable
2039
2040         wait_request_state $fid REMOVE SUCCEED
2041
2042         copytool_cleanup
2043 }
2044 run_test 28 "Concurrent archive/file remove"
2045
2046 test_30a() {
2047         # restore at exec cannot work on agent node (because of Linux kernel
2048         # protection of executables)
2049         needclients 2 || return 0
2050
2051         # test needs a running copytool
2052         copytool_setup
2053
2054         mkdir -p $DIR/$tdir
2055         copy2archive /bin/true $tdir/$tfile
2056
2057         local f=$DIR/$tdir/true
2058         import_file $tdir/$tfile $f
2059
2060         local fid=$(path2fid $f)
2061
2062         # set no retry action mode
2063         cdt_set_no_retry
2064         do_node $CLIENT2 $f
2065         local st=$?
2066
2067         # cleanup
2068         # remove no try action mode
2069         cdt_clear_no_retry
2070         $LFS hsm_state $f
2071
2072         [[ $st == 0 ]] || error "Failed to exec a released file"
2073
2074         copytool_cleanup
2075 }
2076 run_test 30a "Restore at exec (import case)"
2077
2078 test_30b() {
2079         # restore at exec cannot work on agent node (because of Linux kernel
2080         # protection of executables)
2081         needclients 2 || return 0
2082
2083         # test needs a running copytool
2084         copytool_setup
2085
2086         mkdir -p $DIR/$tdir
2087         local f=$DIR/$tdir/true
2088         local fid=$(copy_file /bin/true $f)
2089         chmod 755 $f
2090         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2091         wait_request_state $fid ARCHIVE SUCCEED
2092         $LFS hsm_release $f
2093         $LFS hsm_state $f
2094         # set no retry action mode
2095         cdt_set_no_retry
2096         do_node $CLIENT2 $f
2097         local st=$?
2098
2099         # cleanup
2100         # remove no try action mode
2101         cdt_clear_no_retry
2102         $LFS hsm_state $f
2103
2104         [[ $st == 0 ]] || error "Failed to exec a released file"
2105
2106         copytool_cleanup
2107 }
2108 run_test 30b "Restore at exec (release case)"
2109
2110 test_30c() {
2111         needclients 2 || return 0
2112
2113         # test needs a running copytool
2114         copytool_setup
2115
2116         mkdir -p $DIR/$tdir
2117         local f=$DIR/$tdir/SLEEP
2118         local fid=$(copy_file /bin/sleep $f)
2119         chmod 755 $f
2120         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2121         wait_request_state $fid ARCHIVE SUCCEED
2122         $LFS hsm_release $f
2123         check_hsm_flags $f "0x0000000d"
2124         # set no retry action mode
2125         cdt_set_no_retry
2126         do_node $CLIENT2 "$f 10" &
2127         local pid=$!
2128         sleep 3
2129         echo 'Hi!' > $f
2130         [[ $? == 0 ]] && error "Update during exec of released file must fail"
2131         wait $pid
2132         [[ $? == 0 ]] || error "Execution failed during run"
2133         cmp /bin/sleep $f
2134         [[ $? == 0 ]] || error "Binary overwritten during exec"
2135
2136         # cleanup
2137         # remove no try action mode
2138         cdt_clear_no_retry
2139         check_hsm_flags $f "0x00000009"
2140
2141         copytool_cleanup
2142 }
2143 run_test 30c "Update during exec of released file must fail"
2144
2145 restore_and_check_size() {
2146         local f=$1
2147         local fid=$2
2148         local s=$(stat -c "%s" $f)
2149         local n=$s
2150         local st=$(get_hsm_flags $f)
2151         local err=0
2152         local cpt=0
2153         $LFS hsm_restore $f
2154         while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2155         do
2156                 n=$(stat -c "%s" $f)
2157                 # we echo in both cases to show stat is not
2158                 # hang
2159                 if [[ $n != $s ]]; then
2160                         echo "size seen is $n != $s"
2161                         err=1
2162                 else
2163                         echo "size seen is right: $n == $s"
2164                 fi
2165                 st=$(get_hsm_flags $f)
2166                 sleep 10
2167                 cpt=$((cpt + 1))
2168         done
2169         if [[ $cpt -lt 10 ]]; then
2170                 echo " "done
2171         else
2172                 echo " restore is too long"
2173                 wait_request_state $fid RESTORE SUCCEED
2174         fi
2175         return $err
2176 }
2177
2178 test_31a() {
2179         # test needs a running copytool
2180         copytool_setup
2181
2182         mkdir -p $DIR/$tdir
2183
2184         make_archive $tdir/$tfile
2185         local f=$DIR/$tdir/$tfile
2186         import_file $tdir/$tfile $f
2187         local fid=$($LFS path2fid $f)
2188         HSM_ARCHIVE_PURGE=false copytool_setup
2189
2190         restore_and_check_size $f $fid
2191         local err=$?
2192
2193         [[ $err -eq 0 ]] || error "File size changed during restore"
2194
2195         copytool_cleanup
2196 }
2197 run_test 31a "Import a large file and check size during restore"
2198
2199
2200 test_31b() {
2201         # test needs a running copytool
2202         copytool_setup
2203
2204         mkdir -p $DIR/$tdir
2205
2206         local f=$DIR/$tdir/$tfile
2207         local fid=$(make_large_for_progress $f)
2208         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2209         wait_request_state $fid ARCHIVE SUCCEED
2210         $LFS hsm_release $f
2211
2212         restore_and_check_size $f $fid
2213         local err=$?
2214
2215         [[ $err -eq 0 ]] || error "File size changed during restore"
2216
2217         copytool_cleanup
2218 }
2219 run_test 31b "Restore a large unaligned file and check size during restore"
2220
2221 test_31c() {
2222         # test needs a running copytool
2223         copytool_setup
2224
2225         mkdir -p $DIR/$tdir
2226
2227         local f=$DIR/$tdir/$tfile
2228         local fid=$(make_large_for_progress_aligned $f)
2229         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2230         wait_request_state $fid ARCHIVE SUCCEED
2231         $LFS hsm_release $f
2232
2233         restore_and_check_size $f $fid
2234         local err=$?
2235
2236         [[ $err -eq 0 ]] || error "File size changed during restore"
2237
2238         copytool_cleanup
2239 }
2240 run_test 31c "Restore a large aligned file and check size during restore"
2241
2242 test_33() {
2243         # test needs a running copytool
2244         copytool_setup
2245
2246         mkdir -p $DIR/$tdir
2247
2248         local f=$DIR/$tdir/$tfile
2249         local fid=$(make_large_for_progress $f)
2250         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2251         wait_request_state $fid ARCHIVE SUCCEED
2252         $LFS hsm_release $f
2253
2254         # to be sure wait_all_done will not be mislead by previous tests
2255         # and ops.
2256         cdt_purge
2257         wait_for_grace_delay
2258         # Also raise grace_delay significantly so the Canceled
2259         # Restore action will stay enough long avail.
2260         local old_grace=$(get_hsm_param grace_delay)
2261         set_hsm_param grace_delay 100
2262
2263         md5sum $f >/dev/null &
2264         local pid=$!
2265         wait_request_state $fid RESTORE STARTED
2266
2267         kill -15 $pid
2268         sleep 1
2269
2270         # Check restore trigger process was killed
2271         local killed=$(ps -o pid,comm hp $pid >/dev/null)
2272
2273         $LFS hsm_cancel $f
2274
2275         # instead of waiting+checking both Restore and Cancel ops
2276         # sequentially, wait for both to be finished and then check
2277         # each results.
2278         wait_all_done 100 $fid
2279         local rstate=$(get_request_state $fid RESTORE)
2280         local cstate=$(get_request_state $fid CANCEL)
2281
2282         # restore orig grace_delay.
2283         set_hsm_param grace_delay $old_grace
2284
2285         if [[ "$rstate" == "CANCELED" ]] ; then
2286                 [[ "$cstate" == "SUCCEED" ]] ||
2287                         error "Restore state is CANCELED and Cancel state " \
2288                                "is not SUCCEED but $cstate"
2289                 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2290         elif [[ "$rstate" == "SUCCEED" ]] ; then
2291                 [[ "$cstate" == "FAILED" ]] ||
2292                         error "Restore state is SUCCEED and Cancel state " \
2293                                 "is not FAILED but $cstate"
2294                 echo "Restore state is SUCCEED, Cancel state is FAILED"
2295         else
2296                 error "Restore state is $rstate and Cancel state is $cstate"
2297         fi
2298
2299         [ -z $killed ] ||
2300                 error "Cannot kill process waiting for restore ($killed)"
2301
2302         copytool_cleanup
2303 }
2304 run_test 33 "Kill a restore waiting process"
2305
2306 test_34() {
2307         # test needs a running copytool
2308         copytool_setup
2309
2310         mkdir -p $DIR/$tdir
2311
2312         local f=$DIR/$tdir/$tfile
2313         local fid=$(make_large_for_progress $f)
2314         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2315         wait_request_state $fid ARCHIVE SUCCEED
2316         $LFS hsm_release $f
2317
2318         md5sum $f >/dev/null &
2319         local pid=$!
2320         wait_request_state $fid RESTORE STARTED
2321
2322         rm $f || error "rm $f failed"
2323         # rm must not block during restore
2324         wait_request_state $fid RESTORE STARTED
2325
2326         wait_request_state $fid RESTORE SUCCEED
2327         # check md5sum pgm finished
2328         local there=$(ps -o pid,comm hp $pid >/dev/null)
2329         [[ -z $there ]] || error "Restore initiator does not exit"
2330
2331         local rc=$(wait $pid)
2332         [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2333
2334         copytool_cleanup
2335 }
2336 run_test 34 "Remove file during restore"
2337
2338 test_35() {
2339         # test needs a running copytool
2340         copytool_setup
2341
2342         mkdir -p $DIR/$tdir
2343
2344         local f=$DIR/$tdir/$tfile
2345         local f1=$DIR/$tdir/$tfile-1
2346         local fid=$(make_large_for_progress $f)
2347         local fid1=$(copy_file /etc/passwd $f1)
2348         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2349         wait_request_state $fid ARCHIVE SUCCEED
2350         $LFS hsm_release $f
2351
2352         md5sum $f >/dev/null &
2353         local pid=$!
2354         wait_request_state $fid RESTORE STARTED
2355
2356         mv $f1 $f || error "mv $f1 $f failed"
2357         # mv must not block during restore
2358         wait_request_state $fid RESTORE STARTED
2359
2360         wait_request_state $fid RESTORE SUCCEED
2361         # check md5sum pgm finished
2362         local there=$(ps -o pid,comm hp $pid >/dev/null)
2363         [[ -z $there ]] || error "Restore initiator does not exit"
2364
2365         local rc=$(wait $pid)
2366         [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2367
2368         fid2=$(path2fid $f)
2369         [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2370
2371         copytool_cleanup
2372 }
2373 run_test 35 "Overwrite file during restore"
2374
2375 test_36() {
2376         # test needs a running copytool
2377         copytool_setup
2378
2379         mkdir -p $DIR/$tdir
2380
2381         local f=$DIR/$tdir/$tfile
2382         local fid=$(make_large_for_progress $f)
2383         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2384         wait_request_state $fid ARCHIVE SUCCEED
2385         $LFS hsm_release $f
2386
2387         md5sum $f >/dev/null &
2388         local pid=$!
2389         wait_request_state $fid RESTORE STARTED
2390
2391         mv $f $f.new
2392         # rm must not block during restore
2393         wait_request_state $fid RESTORE STARTED
2394
2395         wait_request_state $fid RESTORE SUCCEED
2396         # check md5sum pgm finished
2397         local there=$(ps -o pid,comm hp $pid >/dev/null)
2398         [[ -z $there ]] ||
2399                 error "Restore initiator does not exit"
2400
2401         local rc=$(wait $pid)
2402         [[ $rc -eq 0 ]] ||
2403                 error "Restore initiator failed with $rc"
2404
2405         copytool_cleanup
2406 }
2407 run_test 36 "Move file during restore"
2408
2409 multi_archive() {
2410         local prefix=$1
2411         local count=$2
2412         local n=""
2413
2414         for n in $(seq 1 $count); do
2415                 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2416         done
2417         echo "$count archive requests submitted"
2418 }
2419
2420 test_40() {
2421         local stream_count=4
2422         local file_count=100
2423         mkdir -p $DIR/$tdir
2424         local f=$DIR/$tdir/$tfile
2425         local i=""
2426         local p=""
2427         local fid=""
2428
2429         for i in $(seq 1 $file_count); do
2430                 for p in $(seq 1 $stream_count); do
2431                         fid=$(copy_file /etc/hosts $f.$p.$i)
2432                 done
2433         done
2434         # force copytool to use a local/temp archive dir to ensure best
2435         # performance vs remote/NFS mounts used in auto-tests
2436         if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2437                 copytool_setup
2438         else
2439                 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2440         fi
2441         # to be sure wait_all_done will not be mislead by previous tests
2442         cdt_purge
2443         wait_for_grace_delay
2444         typeset -a pids
2445         # start archive streams in background (archive files in parallel)
2446         for p in $(seq 1 $stream_count); do
2447                 multi_archive $f.$p $file_count &
2448                 pids[$p]=$!
2449         done
2450         echo -n  "Wait for all requests being enqueued..."
2451         wait ${pids[*]}
2452         echo OK
2453         wait_all_done 100
2454         copytool_cleanup
2455 }
2456 run_test 40 "Parallel archive requests"
2457
2458 test_52() {
2459         # test needs a running copytool
2460         copytool_setup
2461
2462         mkdir -p $DIR/$tdir
2463         local f=$DIR/$tdir/$tfile
2464         local fid=$(copy_file /etc/motd $f 1)
2465
2466         $LFS hsm_archive $f || error "could not archive file"
2467         wait_request_state $fid ARCHIVE SUCCEED
2468         check_hsm_flags $f "0x00000009"
2469
2470         multiop_bg_pause $f O_c || error "multiop failed"
2471         local MULTIPID=$!
2472
2473         mds_evict_client
2474         client_up || client_up || true
2475
2476         kill -USR1 $MULTIPID
2477         wait $MULTIPID || error "multiop close failed"
2478
2479         check_hsm_flags $f "0x0000000b"
2480
2481         copytool_cleanup
2482 }
2483 run_test 52 "Opened for write file on an evicted client should be set dirty"
2484
2485 test_53() {
2486         # test needs a running copytool
2487         copytool_setup
2488
2489         mkdir -p $DIR/$tdir
2490         local f=$DIR/$tdir/$tfile
2491         local fid=$(copy_file /etc/motd $f 1)
2492
2493         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2494                 error "could not archive file"
2495         wait_request_state $fid ARCHIVE SUCCEED
2496         check_hsm_flags $f "0x00000009"
2497
2498         multiop_bg_pause $f o_c || error "multiop failed"
2499         MULTIPID=$!
2500
2501         mds_evict_client
2502         client_up || client_up || true
2503
2504         kill -USR1 $MULTIPID
2505         wait $MULTIPID || error "multiop close failed"
2506
2507         check_hsm_flags $f "0x00000009"
2508
2509         copytool_cleanup
2510 }
2511 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2512
2513 test_54() {
2514         # test needs a running copytool
2515         copytool_setup
2516
2517         mkdir -p $DIR/$tdir
2518         local f=$DIR/$tdir/$tfile
2519         local fid=$(make_small $f)
2520
2521         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2522                 error "could not archive file"
2523         wait_request_state $fid ARCHIVE STARTED
2524
2525         check_hsm_flags $f "0x00000001"
2526
2527         # Avoid coordinator resending this request as soon it has failed.
2528         cdt_set_no_retry
2529
2530         echo "foo" >> $f
2531         sync
2532         wait_request_state $fid ARCHIVE FAILED
2533
2534         check_hsm_flags $f "0x00000003"
2535
2536         cdt_clear_no_retry
2537         copytool_cleanup
2538 }
2539 run_test 54 "Write during an archive cancels it"
2540
2541 test_55() {
2542         # test needs a running copytool
2543         copytool_setup
2544
2545         mkdir -p $DIR/$tdir
2546         local f=$DIR/$tdir/$tfile
2547         local fid=$(make_small $f)
2548
2549         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2550                 error "could not archive file"
2551         wait_request_state $fid ARCHIVE STARTED
2552
2553         check_hsm_flags $f "0x00000001"
2554
2555         # Avoid coordinator resending this request as soon it has failed.
2556         cdt_set_no_retry
2557
2558         $TRUNCATE $f 1024 || error "truncate failed"
2559         sync
2560         wait_request_state $fid ARCHIVE FAILED
2561
2562         check_hsm_flags $f "0x00000003"
2563
2564         cdt_clear_no_retry
2565         copytool_cleanup
2566 }
2567 run_test 55 "Truncate during an archive cancels it"
2568
2569 test_56() {
2570         # test needs a running copytool
2571         copytool_setup
2572
2573         mkdir -p $DIR/$tdir
2574         local f=$DIR/$tdir/$tfile
2575         local fid=$(make_large_for_progress $f)
2576
2577         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2578                 error "could not archive file"
2579         wait_request_state $fid ARCHIVE STARTED
2580
2581         check_hsm_flags $f "0x00000001"
2582
2583         # Change metadata and sync to be sure we are not changing only
2584         # in memory.
2585         chmod 644 $f
2586         chgrp sys $f
2587         sync
2588         wait_request_state $fid ARCHIVE SUCCEED
2589
2590         check_hsm_flags $f "0x00000009"
2591
2592         copytool_cleanup
2593 }
2594 run_test 56 "Setattr during an archive is ok"
2595
2596 test_57() {
2597         # Need one client for I/O, one for request
2598         needclients 2 || return 0
2599
2600         # test needs a running copytool
2601         copytool_setup
2602
2603         mkdir -p $DIR/$tdir
2604         local f=$DIR/$tdir/test_archive_remote
2605         # Create a file on a remote node
2606         do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2607                 "count=2 conv=fsync"
2608
2609         # And archive it
2610         do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2611                 error "hsm_archive failed"
2612         local fid=$(path2fid $f)
2613         wait_request_state $fid ARCHIVE SUCCEED
2614
2615         # Release and implicit restore it
2616         do_node $CLIENT2 "$LFS hsm_release $f" ||
2617                 error "hsm_release failed"
2618         do_node $CLIENT2 "md5sum $f" ||
2619                 error "hsm_restore failed"
2620
2621         wait_request_state $fid RESTORE SUCCEED
2622
2623         copytool_cleanup
2624 }
2625 run_test 57 "Archive a file with dirty cache on another node"
2626
2627 truncate_released_file() {
2628         local src_file=$1
2629         local trunc_to=$2
2630
2631         local sz=$(stat -c %s $src_file)
2632         local f=$DIR/$tdir/$tfile
2633         local fid=$(copy_file $1 $f)
2634         local ref=$f-ref
2635         cp $f $f-ref
2636
2637         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2638                 error "could not archive file"
2639         wait_request_state $fid ARCHIVE SUCCEED
2640
2641         $LFS hsm_release $f || error "could not release file"
2642
2643         $TRUNCATE $f $trunc_to || error "truncate failed"
2644         sync
2645
2646         local sz1=$(stat -c %s $f)
2647         [[ $sz1 == $trunc_to ]] ||
2648                 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2649
2650         $LFS hsm_state $f
2651         check_hsm_flags $f "0x0000000b"
2652
2653         local state=$(get_request_state $fid RESTORE)
2654         [[ "$state" == "SUCCEED" ]] ||
2655                 error "truncate $sz does not trig restore, state = $state"
2656
2657         $TRUNCATE $ref $trunc_to
2658         cmp $ref $f || error "file data wrong after truncate"
2659
2660         rm -f $f $f-ref
2661 }
2662
2663 test_58() {
2664         # test needs a running copytool
2665         copytool_setup
2666
2667         mkdir -p $DIR/$tdir
2668
2669         local sz=$(stat -c %s /etc/passwd)
2670
2671         echo "truncate up from $sz to $((sz*2))"
2672         truncate_released_file /etc/passwd $((sz*2))
2673
2674         echo "truncate down from $sz to $((sz/2))"
2675         truncate_released_file /etc/passwd $((sz/2))
2676
2677         echo "truncate to 0"
2678         truncate_released_file /etc/passwd 0
2679
2680         copytool_cleanup
2681 }
2682 run_test 58 "Truncate a released file will trigger restore"
2683
2684 test_60() {
2685         # This test validates the fix for LU-4512. Ensure that the -u
2686         # option changes the progress reporting interval from the default
2687         # (30 seconds) to the user-specified interval.
2688         local interval=5
2689         local progress_timeout=$((interval * 3))
2690
2691         # test needs a new running copytool
2692         copytool_cleanup
2693         HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2694
2695         mkdir -p $DIR/$tdir
2696         local f=$DIR/$tdir/$tfile
2697         local fid=$(make_large_for_progress $f)
2698
2699         local start_at=$(date +%s)
2700         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2701                 error "could not archive file"
2702
2703         local mdtidx=0
2704         local mdt=${MDT_PREFIX}${mdtidx}
2705         local mds=mds$((mdtidx + 1))
2706
2707         local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2708         cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2709
2710         local RESULT
2711         local WAIT=0
2712         local sleep=1
2713
2714         echo -n "Expecting a progress update within $progress_timeout seconds... "
2715         while [ true ]; do
2716                 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2717                 if [ $RESULT -gt 0 ]; then
2718                         echo "$RESULT bytes copied in $WAIT seconds."
2719                         break
2720                 elif [ $WAIT -ge $progress_timeout ]; then
2721                         error "Timed out waiting for progress update!"
2722                         break
2723                 fi
2724                 WAIT=$((WAIT + sleep))
2725                 sleep $sleep
2726         done
2727
2728         local finish_at=$(date +%s)
2729         local elapsed=$((finish_at - start_at))
2730
2731         # Ensure that the progress update occurred within the expected window.
2732         if [ $elapsed -lt $interval ]; then
2733                 error "Expected progress update after at least $interval seconds"
2734         fi
2735
2736         cdt_clear_no_retry
2737         copytool_cleanup
2738 }
2739 run_test 60 "Changing progress update interval from default"
2740
2741 test_70() {
2742         # test needs a new running copytool
2743         copytool_cleanup
2744         copytool_monitor_setup
2745         HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2746
2747         # Just start and stop the copytool to generate events.
2748         cdt_clear_no_retry
2749         copytool_cleanup
2750
2751         local REGISTER_EVENT
2752         local UNREGISTER_EVENT
2753         while read event; do
2754                 local parsed=$(parse_json_event "$event")
2755                 if [ -z "$parsed" ]; then
2756                         error "Copytool sent malformed event: $event"
2757                 fi
2758                 eval $parsed
2759
2760                 if [ $event_type == "REGISTER" ]; then
2761                         REGISTER_EVENT=$event
2762                 elif [ $event_type == "UNREGISTER" ]; then
2763                         UNREGISTER_EVENT=$event
2764                 fi
2765         done < <(echo $"$(get_copytool_event_log)")
2766
2767         if [ -z "$REGISTER_EVENT" ]; then
2768                 error "Copytool failed to send register event to FIFO"
2769         fi
2770
2771         if [ -z "$UNREGISTER_EVENT" ]; then
2772                 error "Copytool failed to send unregister event to FIFO"
2773         fi
2774
2775         copytool_monitor_cleanup
2776         echo "Register/Unregister events look OK."
2777 }
2778 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2779
2780 test_71() {
2781         # Bump progress interval for livelier events.
2782         local interval=5
2783
2784         # test needs a new running copytool
2785         copytool_cleanup
2786         copytool_monitor_setup
2787         HSMTOOL_UPDATE_INTERVAL=$interval \
2788         HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2789
2790         mkdir -p $DIR/$tdir
2791         local f=$DIR/$tdir/$tfile
2792         local fid=$(make_large_for_progress $f)
2793
2794         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2795                 error "could not archive file"
2796         wait_request_state $fid ARCHIVE SUCCEED
2797
2798         local expected_fields="event_time data_fid source_fid"
2799         expected_fields+=" total_bytes current_bytes"
2800
2801         local START_EVENT
2802         local FINISH_EVENT
2803         while read event; do
2804                 # Make sure we're not getting anything from previous events.
2805                 for field in $expected_fields; do
2806                         unset $field
2807                 done
2808
2809                 local parsed=$(parse_json_event "$event")
2810                 if [ -z "$parsed" ]; then
2811                         error "Copytool sent malformed event: $event"
2812                 fi
2813                 eval $parsed
2814
2815                 if [ $event_type == "ARCHIVE_START" ]; then
2816                         START_EVENT=$event
2817                         continue
2818                 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2819                         FINISH_EVENT=$event
2820                         continue
2821                 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2822                         continue
2823                 fi
2824
2825                 # Do some simple checking of the progress update events.
2826                 for expected_field in $expected_fields; do
2827                         if [ -z ${!expected_field+x} ]; then
2828                                 error "Missing $expected_field field in event"
2829                         fi
2830                 done
2831
2832                 if [ $total_bytes -eq 0 ]; then
2833                         error "Expected total_bytes to be > 0"
2834                 fi
2835
2836                 # These should be identical throughout an archive
2837                 # operation.
2838                 if [ $source_fid != $data_fid ]; then
2839                         error "Expected source_fid to equal data_fid"
2840                 fi
2841         done < <(echo $"$(get_copytool_event_log)")
2842
2843         if [ -z "$START_EVENT" ]; then
2844                 error "Copytool failed to send archive start event to FIFO"
2845         fi
2846
2847         if [ -z "$FINISH_EVENT" ]; then
2848                 error "Copytool failed to send archive finish event to FIFO"
2849         fi
2850
2851         echo "Archive events look OK."
2852
2853         cdt_clear_no_retry
2854         copytool_cleanup
2855         copytool_monitor_cleanup
2856 }
2857 run_test 71 "Copytool logs JSON archive events to FIFO"
2858
2859 test_72() {
2860         # Bump progress interval for livelier events.
2861         local interval=5
2862
2863         # test needs a new running copytool
2864         copytool_cleanup
2865         copytool_monitor_setup
2866         HSMTOOL_UPDATE_INTERVAL=$interval \
2867         HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2868         local test_file=$HSMTOOL_MONITOR_DIR/file
2869
2870         local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2871         cmd+="conv=fsync"
2872         do_facet $SINGLEAGT "$cmd" ||
2873                 error "cannot create $test_file on $SINGLEAGT"
2874         copy2archive $test_file $tdir/$tfile
2875
2876         mkdir -p $DIR/$tdir
2877         local f=$DIR/$tdir/$tfile
2878         import_file $tdir/$tfile $f
2879         f=$DIR2/$tdir/$tfile
2880         echo "Verifying released state: "
2881         check_hsm_flags $f "0x0000000d"
2882
2883         local fid=$(path2fid $f)
2884         $LFS hsm_restore $f
2885         wait_request_state $fid RESTORE SUCCEED
2886
2887         local expected_fields="event_time data_fid source_fid"
2888         expected_fields+=" total_bytes current_bytes"
2889
2890         local START_EVENT
2891         local FINISH_EVENT
2892         while read event; do
2893                 # Make sure we're not getting anything from previous events.
2894                 for field in $expected_fields; do
2895                         unset $field
2896                 done
2897
2898                 local parsed=$(parse_json_event "$event")
2899                 if [ -z "$parsed" ]; then
2900                         error "Copytool sent malformed event: $event"
2901                 fi
2902                 eval $parsed
2903
2904                 if [ $event_type == "RESTORE_START" ]; then
2905                         START_EVENT=$event
2906                         if [ $source_fid != $data_fid ]; then
2907                                 error "source_fid should == data_fid at start"
2908                         fi
2909                         continue
2910                 elif [ $event_type == "RESTORE_FINISH" ]; then
2911                         FINISH_EVENT=$event
2912                         if [ $source_fid != $data_fid ]; then
2913                                 error "source_fid should == data_fid at finish"
2914                         fi
2915                         continue
2916                 elif [ $event_type != "RESTORE_RUNNING" ]; then
2917                         continue
2918                 fi
2919
2920                 # Do some simple checking of the progress update events.
2921                 for expected_field in $expected_fields; do
2922                         if [ -z ${!expected_field+x} ]; then
2923                                 error "Missing $expected_field field in event"
2924                         fi
2925                 done
2926
2927                 if [ $total_bytes -eq 0 ]; then
2928                         error "Expected total_bytes to be > 0"
2929                 fi
2930
2931                 # When a restore starts out, the data fid is the same as the
2932                 # source fid. After the restore has gotten going, we learn
2933                 # the new data fid. Once the restore has finished, the source
2934                 # fid is set to the new data fid.
2935                 #
2936                 # We test this because some monitoring software may depend on
2937                 # this behavior. If it changes, then the consumers of these
2938                 # events may need to be modified.
2939                 if [ $source_fid == $data_fid ]; then
2940                         error "source_fid should != data_fid during restore"
2941                 fi
2942         done < <(echo $"$(get_copytool_event_log)")
2943
2944         if [ -z "$START_EVENT" ]; then
2945                 error "Copytool failed to send restore start event to FIFO"
2946         fi
2947
2948         if [ -z "$FINISH_EVENT" ]; then
2949                 error "Copytool failed to send restore finish event to FIFO"
2950         fi
2951
2952         echo "Restore events look OK."
2953
2954         cdt_clear_no_retry
2955         copytool_cleanup
2956         copytool_monitor_cleanup
2957
2958         rm -rf $test_dir
2959 }
2960 run_test 72 "Copytool logs JSON restore events to FIFO"
2961
2962 test_90() {
2963         file_count=51 # Max number of files constrained by LNET message size
2964         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2965         local f=$DIR/$tdir/$tfile
2966         local FILELIST=/tmp/filelist.txt
2967         local i=""
2968
2969         rm -f $FILELIST
2970         for i in $(seq 1 $file_count); do
2971                 fid=$(copy_file /etc/hosts $f.$i)
2972                 echo $f.$i >> $FILELIST
2973         done
2974         copytool_setup
2975         # to be sure wait_all_done will not be mislead by previous tests
2976         cdt_purge
2977         wait_for_grace_delay
2978         $LFS hsm_archive --filelist $FILELIST ||
2979                 error "cannot archive a file list"
2980         wait_all_done 100
2981         $LFS hsm_release --filelist $FILELIST ||
2982                 error "cannot release a file list"
2983         $LFS hsm_restore --filelist $FILELIST ||
2984                 error "cannot restore a file list"
2985         wait_all_done 100
2986         copytool_cleanup
2987 }
2988 run_test 90 "Archive/restore a file list"
2989
2990 double_verify_reset_hsm_param() {
2991         local p=$1
2992         echo "Testing $HSM_PARAM.$p"
2993         local val=$(get_hsm_param $p)
2994         local save=$val
2995         local val2=$(($val * 2))
2996         set_hsm_param $p $val2
2997         val=$(get_hsm_param $p)
2998         [[ $val == $val2 ]] ||
2999                 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3000         echo "Set $p to 0 must failed"
3001         set_hsm_param $p 0
3002         local rc=$?
3003         # restore value
3004         set_hsm_param $p $save
3005
3006         if [[ $rc == 0 ]]; then
3007                 error "we must not be able to set $HSM_PARAM.$p to 0"
3008         fi
3009 }
3010
3011 test_100() {
3012         double_verify_reset_hsm_param loop_period
3013         double_verify_reset_hsm_param grace_delay
3014         double_verify_reset_hsm_param active_request_timeout
3015         double_verify_reset_hsm_param max_requests
3016         double_verify_reset_hsm_param default_archive_id
3017 }
3018 run_test 100 "Set coordinator /proc tunables"
3019
3020 test_102() {
3021         cdt_disable
3022         cdt_enable
3023         cdt_restart
3024 }
3025 run_test 102 "Verify coordinator control"
3026
3027 test_103() {
3028         # test needs a running copytool
3029         copytool_setup
3030
3031         local i=""
3032         local fid=""
3033
3034         mkdir -p $DIR/$tdir
3035         for i in $(seq 1 20); do
3036                 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3037         done
3038         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3039
3040         cdt_purge
3041
3042         echo "Current requests"
3043         local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3044                         $HSM_PARAM.actions |\
3045                         grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3046
3047         [[ -z "$res" ]] || error "Some request have not been canceled"
3048
3049         copytool_cleanup
3050 }
3051 run_test 103 "Purge all requests"
3052
3053 DATA=CEA
3054 DATAHEX='[434541]'
3055 test_104() {
3056         # test needs a running copytool
3057         copytool_setup
3058
3059         mkdir -p $DIR/$tdir
3060         local f=$DIR/$tdir/$tfile
3061         local fid=$(make_large_for_progress $f)
3062         # if cdt is on, it can serve too quickly the request
3063         cdt_disable
3064         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3065         local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3066                         $HSM_PARAM.actions |\
3067                         grep $fid | cut -f16 -d=")
3068         cdt_enable
3069
3070         [[ "$data1" == "$DATAHEX" ]] ||
3071                 error "Data field in records is ($data1) and not ($DATAHEX)"
3072
3073         copytool_cleanup
3074 }
3075 run_test 104 "Copy tool data field"
3076
3077 test_105() {
3078         mkdir -p $DIR/$tdir
3079         local i=""
3080
3081         cdt_disable
3082         for i in $(seq -w 1 10); do
3083                 cp /etc/passwd $DIR/$tdir/$i
3084                 $LFS hsm_archive $DIR/$tdir/$i
3085         done
3086         local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3087                         $HSM_PARAM.actions |\
3088                         grep WAITING | wc -l")
3089         cdt_restart
3090         cdt_disable
3091         local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3092                         $HSM_PARAM.actions |\
3093                         grep WAITING | wc -l")
3094         cdt_enable
3095         cdt_purge
3096         [[ "$reqcnt1" == "$reqcnt2" ]] ||
3097                 error "Requests count after shutdown $reqcnt2 != "\
3098                       "before shutdown $reqcnt1"
3099 }
3100 run_test 105 "Restart of coordinator"
3101
3102 get_agent_by_uuid_mdt() {
3103         local uuid=$1
3104         local mdtidx=$2
3105         local mds=mds$(($mdtidx + 1))
3106         do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3107                  grep $uuid"
3108 }
3109
3110 check_agent_registered_by_mdt() {
3111         local uuid=$1
3112         local mdtidx=$2
3113         local mds=mds$(($mdtidx + 1))
3114         local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3115         if [[ ! -z "$agent" ]]; then
3116                 echo "found agent $agent on $mds"
3117         else
3118                 error "uuid $uuid not found in agent list on $mds"
3119         fi
3120 }
3121
3122 check_agent_unregistered_by_mdt() {
3123         local uuid=$1
3124         local mdtidx=$2
3125         local mds=mds$(($mdtidx + 1))
3126         local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3127         if [[ -z "$agent" ]]; then
3128                 echo "uuid not found in agent list on $mds"
3129         else
3130                 error "uuid found in agent list on $mds: $agent"
3131         fi
3132 }
3133
3134 check_agent_registered() {
3135         local uuid=$1
3136         local mdsno
3137         for mdsno in $(seq 1 $MDSCOUNT); do
3138                 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3139         done
3140 }
3141
3142 check_agent_unregistered() {
3143         local uuid=$1
3144         local mdsno
3145         for mdsno in $(seq 1 $MDSCOUNT); do
3146                 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3147         done
3148 }
3149
3150 test_106() {
3151         local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3152                 get_client_uuid $MOUNT | cut -d' ' -f2)
3153
3154         copytool_setup
3155         check_agent_registered $uuid
3156
3157         search_copytools || error "No copytool found"
3158
3159         copytool_cleanup
3160         check_agent_unregistered $uuid
3161
3162         copytool_setup
3163         check_agent_registered $uuid
3164
3165         copytool_cleanup
3166 }
3167 run_test 106 "Copytool register/unregister"
3168
3169 test_107() {
3170         # test needs a running copytool
3171         copytool_setup
3172         # create and archive file
3173         mkdir -p $DIR/$tdir
3174         local f1=$DIR/$tdir/$tfile
3175         local fid=$(copy_file /etc/passwd $f1)
3176         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3177         wait_request_state $fid ARCHIVE SUCCEED
3178         # shutdown and restart MDS
3179         fail $SINGLEMDS
3180         # check the copytool still gets messages from MDT
3181         local f2=$DIR/$tdir/2
3182         local fid=$(copy_file /etc/passwd $f2)
3183         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3184         # main check of this sanity: this request MUST succeed
3185         wait_request_state $fid ARCHIVE SUCCEED
3186         copytool_cleanup
3187 }
3188 run_test 107 "Copytool re-register after MDS restart"
3189
3190 policy_set_and_test()
3191 {
3192         local change="$1"
3193         local target="$2"
3194         do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3195         local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3196         [[ "$policy" == "$target" ]] ||
3197                 error "Wrong policy after '$change': '$policy' != '$target'"
3198 }
3199
3200 test_109() {
3201         # to force default policy setting if error
3202         CDT_POLICY_HAD_CHANGED=true
3203
3204         local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3205         local default="NonBlockingRestore [NoRetryAction]"
3206         [[ "$policy" == "$default" ]] ||
3207                 error "default policy has changed,"\
3208                       " '$policy' != '$default' update the test"
3209         policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3210         policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3211         policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3212         policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3213         policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3214         # useless bacause we know but safer for futur changes to use real value
3215         local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3216         echo "Next set_param must failed"
3217         policy_set_and_test "wrong" "$policy"
3218
3219         # return to default
3220         echo "Back to default policy"
3221         cdt_set_sanity_policy
3222 }
3223 run_test 109 "Policy display/change"
3224
3225 test_110a() {
3226         # test needs a running copytool
3227         copytool_setup
3228
3229         mkdir -p $DIR/$tdir
3230
3231         copy2archive /etc/passwd $tdir/$tfile
3232
3233         local f=$DIR/$tdir/$tfile
3234         import_file $tdir/$tfile $f
3235         local fid=$(path2fid $f)
3236
3237         cdt_set_non_blocking_restore
3238         md5sum $f
3239         local st=$?
3240
3241         # cleanup
3242         wait_request_state $fid RESTORE SUCCEED
3243         cdt_clear_non_blocking_restore
3244
3245         # Test result
3246         [[ $st == 1 ]] ||
3247                 error "md5sum returns $st != 1, "\
3248                         "should also perror ENODATA (No data available)"
3249
3250         copytool_cleanup
3251 }
3252 run_test 110a "Non blocking restore policy (import case)"
3253
3254 test_110b() {
3255         # test needs a running copytool
3256         copytool_setup
3257
3258         mkdir -p $DIR/$tdir
3259         local f=$DIR/$tdir/$tfile
3260         local fid=$(copy_file /etc/passwd $f)
3261         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3262         wait_request_state $fid ARCHIVE SUCCEED
3263         $LFS hsm_release $f
3264
3265         cdt_set_non_blocking_restore
3266         md5sum $f
3267         local st=$?
3268
3269         # cleanup
3270         wait_request_state $fid RESTORE SUCCEED
3271         cdt_clear_non_blocking_restore
3272
3273         # Test result
3274         [[ $st == 1 ]] ||
3275                 error "md5sum returns $st != 1, "\
3276                         "should also perror ENODATA (No data available)"
3277
3278         copytool_cleanup
3279 }
3280 run_test 110b "Non blocking restore policy (release case)"
3281
3282 test_111a() {
3283         # test needs a running copytool
3284         copytool_setup
3285
3286         mkdir -p $DIR/$tdir
3287         copy2archive /etc/passwd $tdir/$tfile
3288
3289         local f=$DIR/$tdir/$tfile
3290
3291         import_file $tdir/$tfile $f
3292         local fid=$(path2fid $f)
3293
3294         cdt_set_no_retry
3295
3296         copytool_remove_backend $fid
3297
3298         $LFS hsm_restore $f
3299         wait_request_state $fid RESTORE FAILED
3300         local st=$?
3301
3302         # cleanup
3303         cdt_clear_no_retry
3304
3305         # Test result
3306         [[ $st == 0 ]] || error "Restore does not failed"
3307
3308         copytool_cleanup
3309 }
3310 run_test 111a "No retry policy (import case), restore will error"\
3311               " (No such file or directory)"
3312
3313 test_111b() {
3314         # test needs a running copytool
3315         copytool_setup
3316
3317         mkdir -p $DIR/$tdir
3318         local f=$DIR/$tdir/$tfile
3319         local fid=$(copy_file /etc/passwd $f)
3320         cdt_set_no_retry
3321         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3322         wait_request_state $fid ARCHIVE SUCCEED
3323         $LFS hsm_release $f
3324
3325         copytool_remove_backend $fid
3326
3327         $LFS hsm_restore $f
3328         wait_request_state $fid RESTORE FAILED
3329         local st=$?
3330
3331         # cleanup
3332         cdt_clear_no_retry
3333
3334         # Test result
3335         [[ $st == 0 ]] || error "Restore does not failed"
3336
3337         copytool_cleanup
3338 }
3339 run_test 111b "No retry policy (release case), restore will error"\
3340               " (No such file or directory)"
3341
3342 test_112() {
3343         # test needs a running copytool
3344         copytool_setup
3345
3346         mkdir -p $DIR/$tdir
3347         local f=$DIR/$tdir/$tfile
3348         local fid=$(copy_file /etc/passwd $f)
3349         cdt_disable
3350         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3351         local l=$($LFS hsm_action $f)
3352         echo $l
3353         local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3354
3355         # cleanup
3356         cdt_enable
3357         wait_request_state $fid ARCHIVE SUCCEED
3358
3359         # Test result
3360         [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3361
3362         copytool_cleanup
3363 }
3364 run_test 112 "State of recorded request"
3365
3366 test_200() {
3367         # test needs a running copytool
3368         copytool_setup
3369
3370         mkdir -p $DIR/$tdir
3371         local f=$DIR/$tdir/$tfile
3372         local fid=$(make_large_for_cancel $f)
3373         # test with cdt on is made in test_221
3374         cdt_disable
3375         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3376         $LFS hsm_cancel $f
3377         cdt_enable
3378         wait_request_state $fid ARCHIVE CANCELED
3379         wait_request_state $fid CANCEL SUCCEED
3380
3381         copytool_cleanup
3382 }
3383 run_test 200 "Register/Cancel archive"
3384
3385 test_201() {
3386         # test needs a running copytool
3387         copytool_setup
3388
3389         mkdir -p $DIR/$tdir
3390         local f=$DIR/$tdir/$tfile
3391         make_archive $tdir/$tfile
3392         import_file $tdir/$tfile $f
3393         local fid=$(path2fid $f)
3394
3395         # test with cdt on is made in test_222
3396         cdt_disable
3397         $LFS hsm_restore $f
3398         $LFS hsm_cancel $f
3399         cdt_enable
3400         wait_request_state $fid RESTORE CANCELED
3401         wait_request_state $fid CANCEL SUCCEED
3402
3403         copytool_cleanup
3404 }
3405 run_test 201 "Register/Cancel restore"
3406
3407 test_202() {
3408         # test needs a running copytool
3409         copytool_setup
3410
3411         mkdir -p $DIR/$tdir
3412         local f=$DIR/$tdir/$tfile
3413         local fid=$(make_large_for_progress $f)
3414         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3415         wait_request_state $fid ARCHIVE SUCCEED
3416
3417         cdt_disable
3418         $LFS hsm_remove $f
3419         $LFS hsm_cancel $f
3420         cdt_enable
3421         wait_request_state $fid REMOVE CANCELED
3422
3423         copytool_cleanup
3424 }
3425 run_test 202 "Register/Cancel remove"
3426
3427 test_220() {
3428         # test needs a running copytool
3429         copytool_setup
3430
3431         mkdir -p $DIR/$tdir
3432
3433         local f=$DIR/$tdir/$tfile
3434         local fid=$(copy_file /etc/passwd $f)
3435
3436         changelog_setup
3437
3438         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3439         wait_request_state $fid ARCHIVE SUCCEED
3440
3441         local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3442         changelog_cleanup
3443
3444         local target=0x0
3445         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3446
3447         copytool_cleanup
3448 }
3449 run_test 220 "Changelog for archive"
3450
3451 test_221() {
3452         # test needs a running copytool
3453         copytool_setup
3454
3455         mkdir -p $DIR/$tdir
3456
3457         local f=$DIR/$tdir/$tfile
3458         local fid=$(make_large_for_cancel $f)
3459
3460         changelog_setup
3461
3462         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3463         wait_request_state $fid ARCHIVE STARTED
3464         $LFS hsm_cancel $f
3465         wait_request_state $fid ARCHIVE CANCELED
3466         wait_request_state $fid CANCEL SUCCEED
3467
3468         local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3469
3470         local target=0x7d
3471         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3472
3473         cleanup
3474 }
3475 run_test 221 "Changelog for archive canceled"
3476
3477 test_222a() {
3478         # test needs a running copytool
3479         copytool_setup
3480
3481         mkdir -p $DIR/$tdir
3482         copy2archive /etc/passwd $tdir/$tfile
3483
3484         local f=$DIR/$tdir/$tfile
3485         import_file $tdir/$tfile $f
3486         local fid=$(path2fid $f)
3487
3488         changelog_setup
3489
3490         $LFS hsm_restore $f
3491         wait_request_state $fid RESTORE SUCCEED
3492
3493         local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3494
3495         local target=0x80
3496         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3497
3498         cleanup
3499 }
3500 run_test 222a "Changelog for explicit restore"
3501
3502 test_222b() {
3503         # test needs a running copytool
3504         copytool_setup
3505
3506         mkdir -p $DIR/$tdir
3507         local f=$DIR/$tdir/$tfile
3508         local fid=$(copy_file /etc/passwd $f)
3509
3510         changelog_setup
3511         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3512         wait_request_state $fid ARCHIVE SUCCEED
3513         $LFS hsm_release $f
3514
3515         md5sum $f
3516
3517         wait_request_state $fid RESTORE SUCCEED
3518
3519         local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3520
3521         local target=0x80
3522         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3523
3524         cleanup
3525 }
3526 run_test 222b "Changelog for implicit restore"
3527
3528 test_223a() {
3529         # test needs a running copytool
3530         copytool_setup
3531
3532         mkdir -p $DIR/$tdir
3533
3534         local f=$DIR/$tdir/$tfile
3535         make_archive $tdir/$tfile
3536
3537         changelog_setup
3538
3539         import_file $tdir/$tfile $f
3540         local fid=$(path2fid $f)
3541
3542         $LFS hsm_restore $f
3543         wait_request_state $fid RESTORE STARTED
3544         $LFS hsm_cancel $f
3545         wait_request_state $fid RESTORE CANCELED
3546         wait_request_state $fid CANCEL SUCCEED
3547
3548         local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3549
3550         local target=0xfd
3551         [[ $flags == $target ]] ||
3552                 error "Changelog flag is $flags not $target"
3553
3554         cleanup
3555 }
3556 run_test 223a "Changelog for restore canceled (import case)"
3557
3558 test_223b() {
3559         # test needs a running copytool
3560         copytool_setup
3561
3562         mkdir -p $DIR/$tdir
3563
3564         local f=$DIR/$tdir/$tfile
3565         local fid=$(make_large_for_progress $f)
3566
3567         changelog_setup
3568         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3569         wait_request_state $fid ARCHIVE SUCCEED
3570         $LFS hsm_release $f
3571         $LFS hsm_restore $f
3572         wait_request_state $fid RESTORE STARTED
3573         $LFS hsm_cancel $f
3574         wait_request_state $fid RESTORE CANCELED
3575         wait_request_state $fid CANCEL SUCCEED
3576
3577         local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3578
3579         local target=0xfd
3580         [[ $flags == $target ]] ||
3581                 error "Changelog flag is $flags not $target"
3582
3583         cleanup
3584 }
3585 run_test 223b "Changelog for restore canceled (release case)"
3586
3587 test_224() {
3588         # test needs a running copytool
3589         copytool_setup
3590
3591         mkdir -p $DIR/$tdir
3592
3593         local f=$DIR/$tdir/$tfile
3594         local fid=$(copy_file /etc/passwd $f)
3595
3596         changelog_setup
3597         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3598         wait_request_state $fid ARCHIVE SUCCEED
3599
3600         $LFS hsm_remove $f
3601         wait_request_state $fid REMOVE SUCCEED
3602
3603         local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3604
3605         local target=0x200
3606         [[ $flags == $target ]] ||
3607                 error "Changelog flag is $flags not $target"
3608
3609         cleanup
3610 }
3611 run_test 224 "Changelog for remove"
3612
3613 test_225() {
3614         # test needs a running copytool
3615         copytool_setup
3616
3617         # test is not usable because remove request is too fast
3618         # so it is always finished before cancel can be done ...
3619         echo "Test disabled"
3620         copytool_cleanup
3621         return 0
3622
3623         mkdir -p $DIR/$tdir
3624         local f=$DIR/$tdir/$tfile
3625         local fid=$(make_large_for_progress $f)
3626
3627         changelog_setup
3628         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3629         wait_request_state $fid ARCHIVE SUCCEED
3630
3631         # if cdt is on, it can serve too quickly the request
3632         cdt_disable
3633         $LFS hsm_remove $f
3634         $LFS hsm_cancel $f
3635         cdt_enable
3636         wait_request_state $fid REMOVE CANCELED
3637         wait_request_state $fid CANCEL SUCCEED
3638
3639         flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3640         local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3641                 tail -n 1 | awk '{print $5}')
3642
3643         local target=0x27d
3644         [[ $flags == $target ]] ||
3645                 error "Changelog flag is $flags not $target"
3646
3647         cleanup
3648 }
3649 run_test 225 "Changelog for remove canceled"
3650
3651 test_226() {
3652         # test needs a running copytool
3653         copytool_setup
3654
3655         mkdir -p $DIR/$tdir
3656
3657         local f1=$DIR/$tdir/$tfile-1
3658         local f2=$DIR/$tdir/$tfile-2
3659         local f3=$DIR/$tdir/$tfile-3
3660         local fid1=$(copy_file /etc/passwd $f1)
3661         local fid2=$(copy_file /etc/passwd $f2)
3662         copy_file /etc/passwd $f3
3663
3664         changelog_setup
3665         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3666         wait_request_state $fid1 ARCHIVE SUCCEED
3667
3668         $LFS hsm_archive $f2
3669         wait_request_state $fid2 ARCHIVE SUCCEED
3670
3671         rm $f1 || error "rm $f1 failed"
3672
3673         local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3674
3675         local target=0x3
3676         [[ $flags == $target ]] ||
3677                 error "Changelog flag is $flags not $target"
3678
3679         mv $f3 $f2 || error "mv $f3 $f2 failed"
3680
3681         flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3682
3683         target=0x3
3684         [[ $flags == $target ]] ||
3685                 error "Changelog flag is $flags not $target"
3686
3687         cleanup
3688 }
3689 run_test 226 "changelog for last rm/mv with exiting archive"
3690
3691 check_flags_changes() {
3692         local f=$1
3693         local fid=$2
3694         local hsm_flag=$3
3695         local fst=$4
3696         local cnt=$5
3697
3698         local target=0x280
3699         $LFS hsm_set --$hsm_flag $f ||
3700                 error "Cannot set $hsm_flag on $f"
3701         local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3702         local seen=${#flags[*]}
3703         cnt=$((fst + cnt))
3704         [[ $seen == $cnt ]] ||
3705                 error "set $hsm_flag: Changelog events $seen != $cnt"
3706         [[ ${flags[$((cnt - 1))]} == $target ]] ||
3707                 error "set $hsm_flag: Changelog flags are "\
3708                         "${flags[$((cnt - 1))]} not $target"
3709
3710         $LFS hsm_clear --$hsm_flag $f ||
3711                 error "Cannot clear $hsm_flag on $f"
3712         flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3713         seen=${#flags[*]}
3714         cnt=$(($cnt + 1))
3715         [[ $cnt == $seen ]] ||
3716                 error "clear $hsm_flag: Changelog events $seen != $cnt"
3717
3718         [[ ${flags[$((cnt - 1))]} == $target ]] ||
3719                 error "clear $hsm_flag: Changelog flag is "\
3720                         "${flags[$((cnt - 1))]} not $target"
3721 }
3722
3723 test_227() {
3724         # test needs a running copytool
3725         copytool_setup
3726         changelog_setup
3727
3728         mkdir -p $DIR/$tdir
3729         typeset -a flags
3730
3731         for i in norelease noarchive exists archived
3732         do
3733                 local f=$DIR/$tdir/$tfile-$i
3734                 local fid=$(copy_file /etc/passwd $f)
3735                 check_flags_changes $f $fid $i 0 1
3736         done
3737
3738         f=$DIR/$tdir/$tfile---lost
3739         fid=$(copy_file /etc/passwd $f)
3740         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3741         wait_request_state $fid ARCHIVE SUCCEED
3742         check_flags_changes $f $fid lost 3 1
3743
3744         cleanup
3745 }
3746 run_test 227 "changelog when explicit setting of HSM flags"
3747
3748 test_228() {
3749         # test needs a running copytool
3750         copytool_setup
3751
3752         local fid=$(make_small_sync $DIR/$tfile)
3753         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3754         wait_request_state $fid ARCHIVE SUCCEED
3755
3756         $LFS hsm_release $DIR/$tfile
3757         check_hsm_flags $DIR/$tfile "0x0000000d"
3758
3759         filefrag $DIR/$tfile | grep " 1 extent found" ||
3760                 error "filefrag on released file must return only one extent"
3761
3762         # only newer versions of cp detect sparse files by stat/FIEMAP
3763         # (LU-2580)
3764         cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3765                 error "copying $DIR/$tfile"
3766         cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3767
3768         $LFS hsm_release $DIR/$tfile
3769         check_hsm_flags $DIR/$tfile "0x0000000d"
3770
3771         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3772
3773         tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3774                 error "tar failed"
3775         cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3776                 error "comparing untarred $DIR/$tfile"
3777
3778         rm -f $DIR/$tfile $DIR/$tfile.2 ||
3779                 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3780         copytool_cleanup
3781 }
3782 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3783
3784 test_250() {
3785         # test needs a running copytool
3786         copytool_setup
3787
3788         mkdir -p $DIR/$tdir
3789         local maxrequest=$(get_hsm_param max_requests)
3790         local rqcnt=$(($maxrequest * 3))
3791         local i=""
3792
3793         cdt_disable
3794         for i in $(seq -w 1 $rqcnt); do
3795                 rm -f $DIR/$tdir/$i
3796                 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3797         done
3798         # we do it in 2 steps, so all requests arrive at the same time
3799         for i in $(seq -w 1 $rqcnt); do
3800                 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3801         done
3802         cdt_enable
3803         local cnt=$rqcnt
3804         local wt=$rqcnt
3805         while [[ $cnt != 0 || $wt != 0 ]]; do
3806                 sleep 1
3807                 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3808                         $HSM_PARAM.actions |\
3809                         grep STARTED | grep -v CANCEL | wc -l")
3810                 [[ $cnt -le $maxrequest ]] ||
3811                         error "$cnt > $maxrequest too many started requests"
3812                 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3813                         $HSM_PARAM.actions |\
3814                         grep WAITING | wc -l")
3815                 echo "max=$maxrequest started=$cnt waiting=$wt"
3816         done
3817
3818         copytool_cleanup
3819 }
3820 run_test 250 "Coordinator max request"
3821
3822 test_251() {
3823         # test needs a running copytool
3824         copytool_setup
3825
3826         mkdir -p $DIR/$tdir
3827         local f=$DIR/$tdir/$tfile
3828         local fid=$(make_large_for_cancel $f)
3829
3830         cdt_disable
3831         # to have a short test
3832         local old_to=$(get_hsm_param active_request_timeout)
3833         set_hsm_param active_request_timeout 4
3834         # to be sure the cdt will wake up frequently so
3835         # it will be able to cancel the "old" request
3836         local old_loop=$(get_hsm_param loop_period)
3837         set_hsm_param loop_period 2
3838         cdt_enable
3839
3840         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3841         wait_request_state $fid ARCHIVE STARTED
3842         sleep 5
3843         wait_request_state $fid ARCHIVE CANCELED
3844
3845         set_hsm_param active_request_timeout $old_to
3846         set_hsm_param loop_period $old_loop
3847
3848         copytool_cleanup
3849 }
3850 run_test 251 "Coordinator request timeout"
3851
3852 test_300() {
3853         # the only way to test ondisk conf is to restart MDS ...
3854         echo "Stop coordinator and remove coordinator state at mount"
3855         # stop coordinator
3856         cdt_shutdown
3857         # clean on disk conf set by default
3858         cdt_clear_mount_state
3859         cdt_check_state stopped
3860
3861         # check cdt still off after umount/remount
3862         fail $SINGLEMDS
3863         cdt_check_state stopped
3864
3865         echo "Set coordinator start at mount, and start coordinator"
3866         cdt_set_mount_state enabled
3867
3868         # check cdt is on
3869         cdt_check_state enabled
3870
3871         # check cdt still on after umount/remount
3872         fail $SINGLEMDS
3873         cdt_check_state enabled
3874
3875         # we are back to original state (cdt started at mount)
3876 }
3877 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3878
3879 test_301() {
3880         local ai=$(get_hsm_param default_archive_id)
3881         local new=$((ai + 1))
3882
3883         set_hsm_param default_archive_id $new -P
3884         fail $SINGLEMDS
3885         local res=$(get_hsm_param default_archive_id)
3886
3887         # clear value
3888         set_hsm_param default_archive_id "" "-P -d"
3889
3890         [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3891 }
3892 run_test 301 "HSM tunnable are persistent"
3893
3894 test_302() {
3895         local ai=$(get_hsm_param default_archive_id)
3896         local new=$((ai + 1))
3897
3898         # stop coordinator
3899         cdt_shutdown
3900
3901         set_hsm_param default_archive_id $new -P
3902
3903         local mdtno
3904         for mdtno in $(seq 1 $MDSCOUNT); do
3905                 fail mds${mdtno}
3906         done
3907
3908         # check cdt is on
3909         cdt_check_state enabled
3910
3911         local res=$(get_hsm_param default_archive_id)
3912
3913         # clear value
3914         set_hsm_param default_archive_id "" "-P -d"
3915
3916         [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3917 }
3918 run_test 302 "HSM tunnable are persistent when CDT is off"
3919
3920 test_400() {
3921         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3922
3923         copytool_setup
3924
3925         mkdir -p $DIR/$tdir
3926
3927         local dir_mdt0=$DIR/$tdir/mdt0
3928         local dir_mdt1=$DIR/$tdir/mdt1
3929
3930         # create 1 dir per MDT
3931         $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3932         $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3933
3934         # create 1 file in each MDT
3935         local fid1=$(make_small $dir_mdt0/$tfile)
3936         local fid2=$(make_small $dir_mdt1/$tfile)
3937
3938         # check that hsm request on mdt0 is sent to the right MDS
3939         $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3940         wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3941                 echo "archive successful on mdt0"
3942
3943         # check that hsm request on mdt1 is sent to the right MDS
3944         $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3945         wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3946                 echo "archive successful on mdt1"
3947
3948         copytool_cleanup
3949         # clean test files and directories
3950         rm -rf $dir_mdt0 $dir_mdt1
3951 }
3952 run_test 400 "Single request is sent to the right MDT"
3953
3954 test_401() {
3955         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3956
3957         copytool_setup
3958
3959         mkdir -p $DIR/$tdir
3960
3961         local dir_mdt0=$DIR/$tdir/mdt0
3962         local dir_mdt1=$DIR/$tdir/mdt1
3963
3964         # create 1 dir per MDT
3965         $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3966         $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3967
3968         # create 1 file in each MDT
3969         local fid1=$(make_small $dir_mdt0/$tfile)
3970         local fid2=$(make_small $dir_mdt1/$tfile)
3971
3972         # check that compound requests are shunt to the rights MDTs
3973         $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3974                 error "lfs hsm_archive"
3975         wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3976                 echo "archive successful on mdt0"
3977         wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3978                 echo "archive successful on mdt1"
3979
3980         copytool_cleanup
3981         # clean test files and directories
3982         rm -rf $dir_mdt0 $dir_mdt1
3983 }
3984 run_test 401 "Compound requests split and sent to their respective MDTs"
3985
3986 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3987 {
3988         local facet=$1
3989         local pattern="$2"
3990         local state=$3
3991         local node=$(facet_active_host $facet)
3992         local mdc
3993         for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3994                         awk '{print $4}'); do
3995                 echo "$3 $mdc on $node"
3996                 do_facet $facet "$LCTL --device $mdc $state" || return 1
3997         done
3998 }
3999
4000 test_402() {
4001         # make sure there is no running copytool
4002         copytool_cleanup
4003
4004         # deactivate all mdc on agent1
4005         mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4006
4007         copytool_setup $SINGLEAGT
4008
4009         check_agent_unregistered "uuid" # match any agent
4010
4011         # no expected running copytool
4012         search_copytools $agent && error "Copytool start should have failed"
4013
4014         # reactivate MDCs
4015         mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4016 }
4017 run_test 402 "Copytool start fails if all MDTs are inactive"
4018
4019 test_403() {
4020         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4021
4022         # make sure there is no running copytool
4023         copytool_cleanup
4024
4025         local agent=$(facet_active_host $SINGLEAGT)
4026         local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4027
4028         # deactivate all mdc for MDT0001
4029         mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4030
4031         copytool_setup
4032         # check the agent is registered on MDT0000, and not on MDT0001
4033         check_agent_registered_by_mdt $uuid 0
4034         check_agent_unregistered_by_mdt $uuid 1
4035
4036         # check running copytool process
4037         search_copytools $agent || error "No running copytools on $agent"
4038
4039         # reactivate all mdc for MDT0001
4040         mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4041
4042         # make sure the copytool is now registered to all MDTs
4043         check_agent_registered $uuid
4044
4045         copytool_cleanup
4046 }
4047 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4048
4049 test_404() {
4050         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4051
4052         copytool_setup
4053
4054         # create files on both MDT0000 and MDT0001
4055         mkdir -p $DIR/$tdir
4056
4057         local dir_mdt0=$DIR/$tdir/mdt0
4058         $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4059
4060         # create 1 file on mdt0
4061         local fid1=$(make_small $dir_mdt0/$tfile)
4062
4063         # deactivate all mdc for MDT0001
4064         mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4065
4066         # send an HSM request for files in MDT0000
4067         $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4068
4069         # check for completion of files in MDT0000
4070         wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4071                 echo "archive successful on mdt0"
4072
4073         # reactivate all mdc for MDT0001
4074         mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4075
4076         copytool_cleanup
4077         # clean test files and directories
4078         rm -rf $dir_mdt0
4079 }
4080 run_test 404 "Inactive MDT does not block requests for active MDTs"
4081
4082 copytool_cleanup
4083
4084 complete $SECONDS
4085 check_and_cleanup_lustre
4086 exit_status