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