Whamcloud - gitweb
7807177a9b31645412486fbc07609f8c8a7c6de5
[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:
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16 # skip test cases failed before landing - Jinshan
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 12a 12b 12n 13 24 30a 31a 34 35 36 58 59"
18 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 110a 200 201 221 222a 223a 223b 225"
19
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
21
22 . $LUSTRE/tests/test-framework.sh
23 init_test_env $@
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 init_logging
26
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MCREATE=${MCREATE:-mcreate}
30 MOUNT_2=${MOUNT_2:-"yes"}
31 FAIL_ON_ERROR=false
32
33 if [[ $MDSCOUNT -ge 2 ]]; then
34         skip_env "Only run with single MDT for now" && exit
35 fi
36
37 check_and_setup_lustre
38
39 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
40         skip_env "Need MDS version at least 2.4.53" && exit
41 fi
42
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45         skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
46 fi
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
48
49 build_test_filter
50
51 #
52 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
53 # the following associated variables are added:
54 #
55 # AGTCOUNT: number of agents
56 # AGTDEV{N}: target HSM mount point (root path of the backend)
57 # agt{N}_HOST: hostname of the agent agt{N}
58 # SINGLEAGT: facet of the single agent
59 #
60 # The number of agents is initialized as the number of remote client nodes.
61 # By default, only single copytool is started on a remote client/agent. If there
62 # was no remote client, then the copytool will be started on the local client.
63 #
64 init_agt_vars() {
65         local n
66         local agent
67
68         export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
69         [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
70
71         export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
72         if [[ $CLIENTCOUNT -gt 1 ]] &&
73                 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
74                 skip_env "SHARED_DIRECTORY should be accessible"\
75                          "on all client nodes"
76                 exit 0
77         fi
78
79         for n in $(seq $AGTCOUNT); do
80                 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
81                 agent=CLIENT$((n + 1))
82                 if [[ -z "${!agent}" ]]; then
83                         [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
84                                 agent=CLIENT2
85                 fi
86                 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
87         done
88
89         export SINGLEAGT=${SINGLEAGT:-agt1}
90
91         export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
92         export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
93         export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
94         HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
95         HSM_ARCHIVE_NUMBER=2
96
97         MDT_PARAM="mdt.$FSNAME-MDT0000"
98         HSM_PARAM="$MDT_PARAM.hsm"
99
100         # archive is purged at copytool setup
101         HSM_ARCHIVE_PURGE=true
102 }
103
104 # Get the backend root path for the given agent facet.
105 copytool_device() {
106         local facet=$1
107         local dev=AGTDEV$(facet_number $facet)
108
109         echo -n ${!dev}
110 }
111
112 # Stop copytool and unregister an existing changelog user.
113 cleanup() {
114         copytool_cleanup
115         changelog_cleanup
116 }
117
118 search_and_kill_copytool() {
119         local agents=${1:-$(facet_active_host $SINGLEAGT)}
120
121         echo "Killing existing copytools on $agents"
122         do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
123 }
124
125 copytool_setup() {
126         local facet=${1:-$SINGLEAGT}
127         local lustre_mntpnt=${2:-$MOUNT}
128         local arc_id=$3
129         local hsm_root=$(copytool_device $facet)
130         local agent=$(facet_active_host $facet)
131
132         if [[ -z "$arc_id" ]] &&
133                 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
134                         echo "Wakeup copytool $facet on $agent"
135                         return 0
136         fi
137
138         if $HSM_ARCHIVE_PURGE; then
139                 echo "Purging archive on $agent"
140                 do_facet $facet "rm -rf $hsm_root/*"
141         fi
142
143         echo "Starting copytool $facet on $agent"
144         do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
145         # bandwidth is limited to 1MB/s so the copy time is known and
146         # independent of hardware
147         local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
148         [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
149         cmd+=" --bandwidth 1 $lustre_mntpnt"
150
151         # Redirect the standard output and error to a log file which
152         # can be uploaded to Maloo.
153         local prefix=$TESTLOG_PREFIX
154         [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
155         local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
156
157         do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
158                 error "start copytool $facet on $agent failed"
159         trap cleanup EXIT
160 }
161
162 copytool_cleanup() {
163         trap - EXIT
164         local agents=${1:-$(facet_active_host $SINGLEAGT)}
165
166         do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
167         sleep 1
168         echo "Copytool is stopped on $agents"
169 }
170
171 copytool_suspend() {
172         local agents=${1:-$(facet_active_host $SINGLEAGT)}
173
174         do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
175         echo "Copytool is suspended on $agents"
176 }
177
178 copytool_remove_backend() {
179         local fid=$1
180         local be=$(find $HSM_ARCHIVE -name $fid)
181         echo "Remove from backend: $fid = $be"
182         rm -f $be
183 }
184
185 import_file() {
186         do_facet $SINGLEAGT \
187                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
188                 --import $1 $2 $MOUNT" ||
189                 error "import of $1 to $2 failed"
190 }
191
192 make_archive() {
193         local file=$HSM_ARCHIVE/$1
194         mkdir -p $(dirname $file)
195         dd if=/dev/urandom of=$file count=32 bs=1000000 ||
196                 error "cannot create $file"
197 }
198
199 changelog_setup() {
200         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0\
201                   changelog_register -n)
202         do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+hsm"
203         $LFS changelog_clear $MDT0 $CL_USER 0
204 }
205
206 changelog_cleanup() {
207 #       $LFS changelog $MDT0
208         [[ -n "$CL_USER" ]] || return 0
209
210         $LFS changelog_clear $MDT0 $CL_USER 0
211         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
212         CL_USER=
213 }
214
215 changelog_get_flags() {
216         local mdt=$1
217         local cltype=$2
218         local fid=$3
219
220         $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
221 }
222
223 get_hsm_param() {
224         local param=$1
225         local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
226         echo $val
227 }
228
229 set_hsm_param() {
230         local param=$1
231         local value=$2
232         do_facet $SINGLEMDS $LCTL set_param -n $HSM_PARAM.$param=$value
233         return $?
234 }
235
236 set_test_state() {
237         local cmd=$1
238         local target=$2
239         do_facet $SINGLEMDS $LCTL set_param $MDT_PARAM.hsm_control=$cmd
240         wait_result $SINGLEMDS "$LCTL get_param -n $MDT_PARAM.hsm_control"\
241                 $target 10 || error "cdt state is not $target"
242 }
243
244 cdt_set_sanity_policy() {
245         # clear all
246         do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nra
247         do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nbr
248         do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-gc
249 }
250
251 cdt_set_no_retry() {
252         do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+nra
253 }
254
255 cdt_clear_no_retry() {
256         do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nra
257 }
258
259 cdt_set_no_blocking_restore() {
260         do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+nbr
261 }
262
263 cdt_clear_no_blocking_restore() {
264         do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nbr
265 }
266
267 cdt_clear_mount_state() {
268         # /!\ conf_param and set_param syntax differ +> we cannot use
269         # $MDT_PARAM
270         do_facet $SINGLEMDS $LCTL conf_param -d $FSNAME-MDT0000.mdt.hsm_control
271 }
272
273 cdt_set_mount_state() {
274         # /!\ conf_param and set_param syntax differ +> we cannot use
275         # $MDT_PARAM
276         do_facet $SINGLEMDS $LCTL conf_param $FSNAME-MDT0000.mdt.hsm_control=$1
277 }
278
279 cdt_check_state() {
280         local target=$1
281         wait_result $SINGLEMDS\
282                 "$LCTL get_param -n $MDT_PARAM.hsm_control" "$target" 20 ||
283                         error "cdt state is not $target"
284 }
285
286 cdt_disable() {
287         set_test_state disabled disabled
288 }
289
290 cdt_enable() {
291         set_test_state enabled enabled
292 }
293
294 cdt_shutdown() {
295         set_test_state shutdown stopped
296 }
297
298 cdt_purge() {
299         set_test_state purge enabled
300 }
301
302 cdt_restart() {
303         cdt_shutdown
304         cdt_enable
305         cdt_set_sanity_policy
306 }
307
308 need2clients() {
309         if [[ $CLIENTCOUNT -lt 2 ]]; then
310                 skip "Need two or more clients, have $CLIENTCOUNT"
311                 return 1
312         fi
313         return 0
314 }
315
316 path2fid() {
317         $LFS path2fid $1 | tr -d '[]'
318 }
319
320 get_hsm_flags() {
321         local f=$1
322         local u=$2
323
324         if [[ $u == "user" ]]
325         then
326                 local st=$($RUNAS $LFS hsm_state $f)
327         else
328                 local st=$($LFS hsm_state $f)
329                 u=root
330         fi
331
332         [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
333
334         st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
335         echo $st
336 }
337
338 get_hsm_archive_id() {
339         local f=$1
340         local st=$($LFS hsm_state $f)
341         [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
342
343         local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
344                    cut -f2 -d:)
345         echo $ar
346 }
347
348 check_hsm_flags() {
349         local f=$1
350         local fl=$2
351
352         local st=$(get_hsm_flags $f)
353         [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
354 }
355
356 check_hsm_flags_user() {
357         local f=$1
358         local fl=$2
359
360         local st=$(get_hsm_flags $f user)
361         [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
362 }
363
364 copy_file() {
365         local f=
366
367         if [[ -d $2 ]]
368         then
369                 f=$2/$(basename $1)
370         else
371                 f=$2
372         fi
373
374         if [[ "$3" != 1 ]]
375         then
376                 f=${f/$DIR/$DIR2}
377         fi
378         rm -f $f
379         cp $1 $f || error "cannot copy $1 to $f"
380         path2fid $f || error "cannot get fid on $f"
381 }
382
383 make_small() {
384         local file2=${1/$DIR/$DIR2}
385         dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
386                 error "cannot create $file2"
387         path2fid $1 || error "cannot get fid on $1"
388 }
389
390 make_large_for_striping() {
391         local file2=${1/$DIR/$DIR2}
392         local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
393         dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
394                 error "cannot create $file2"
395         path2fid $1 || error "cannot get fid on $1"
396 }
397
398 make_large_for_progress() {
399         local file2=${1/$DIR/$DIR2}
400         # big file is large enough, so copy time is > 30s
401         # so copytool make 1 progress
402         # size is not a multiple of 1M to avoid stripe
403         # aligment
404         dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
405                 error "cannot create $file2"
406         path2fid $1 || error "cannot get fid on $1"
407 }
408
409 make_large_for_progress_aligned() {
410         local file2=${1/$DIR/$DIR2}
411         # big file is large enough, so copy time is > 30s
412         # so copytool make 1 progress
413         # size is a multiple of 1M to have stripe
414         # aligment
415         dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
416                 error "cannot create $file2"
417         path2fid $1 || error "cannot get fid on $1"
418 }
419
420 make_large_for_cancel() {
421         local file2=${1/$DIR/$DIR2}
422         # Copy timeout is 100s. 105MB => 105s
423         dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
424                 error "cannot create $file2"
425         path2fid $1 || error "cannot get fid on $1"
426 }
427
428 wait_result() {
429         local facet=$1
430         shift
431         wait_update --verbose $(facet_active_host $facet) "$@"
432 }
433
434 wait_request_state() {
435         local fid=$1
436         local request=$2
437         local state=$3
438
439         local cmd="$LCTL get_param -n $HSM_PARAM.agent_actions"
440         cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
441
442         wait_result $SINGLEMDS "$cmd" $state 100 ||
443                 error "request on $fid is not $state"
444 }
445
446 get_request_state() {
447         local fid=$1
448         local request=$2
449
450         do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.agent_actions |"\
451                 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
452 }
453
454 get_request_count() {
455         local fid=$1
456         local request=$2
457
458         do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.agent_actions |"\
459                 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
460 }
461
462 wait_all_done() {
463         local timeout=$1
464
465         local cmd="$LCTL get_param -n $HSM_PARAM.agent_actions"
466         cmd+=" | egrep 'WAITING|STARTED'"
467
468         wait_result $SINGLEMDS "$cmd" "" $timeout ||
469                 error "requests did not complete"
470 }
471
472 wait_for_grace_delay() {
473         local val=$(get_hsm_param grace_delay)
474         sleep $val
475 }
476
477 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
478         awk '{gsub(/_UUID/,""); print $1}' | head -1)
479
480 # initiate variables
481 init_agt_vars
482
483 # cleanup from previous bad setup
484 search_and_kill_copytool
485
486 # for recovery tests, coordinator needs to be started at mount
487 # so force it
488 # the lustre conf must be without hsm on (like for sanity.sh)
489 echo "Set HSM on and start"
490 cdt_set_mount_state enabled
491 cdt_check_state enabled
492
493 echo "Start copytool"
494 copytool_setup
495
496 # finished requests are quickly removed from list
497 set_hsm_param grace_delay 10
498
499 test_1() {
500         mkdir -p $DIR/$tdir
501         chmod 777 $DIR/$tdir
502
503         local f=$DIR/$tdir/$tfile
504         $RUNAS touch $f
505
506         # User flags
507         check_hsm_flags_user $f "0x00000000"
508
509         $RUNAS $LFS hsm_set --norelease $f ||
510                 error "user could not change hsm flags"
511         check_hsm_flags_user $f "0x00000010"
512
513         $RUNAS $LFS hsm_clear --norelease $f ||
514                 error "user could not clear hsm flags"
515         check_hsm_flags_user $f "0x00000000"
516
517         # User could not change those flags...
518         $RUNAS $LFS hsm_set --exists $f &&
519                 error "user should not set this flag"
520         check_hsm_flags_user $f "0x00000000"
521
522         # ...but root can
523         $LFS hsm_set --exists $f ||
524                 error "root could not change hsm flags"
525         check_hsm_flags_user $f "0x00000001"
526
527         $LFS hsm_clear --exists $f ||
528                 error "root could not clear hsm state"
529         check_hsm_flags_user $f "0x00000000"
530
531 }
532 run_test 1 "lfs hsm flags root/non-root access"
533
534 test_2() {
535         mkdir -p $DIR/$tdir
536         local f=$DIR/$tdir/$tfile
537         touch $f
538         # New files are not dirty
539         check_hsm_flags $f "0x00000000"
540
541         # For test, we simulate an archived file.
542         $LFS hsm_set --exists $f || error "user could not change hsm flags"
543         check_hsm_flags $f "0x00000001"
544
545         # chmod do not put the file dirty
546         chmod 600 $f || error "could not chmod test file"
547         check_hsm_flags $f "0x00000001"
548
549         # chown do not put the file dirty
550         chown $RUNAS_ID $f || error "could not chown test file"
551         check_hsm_flags $f "0x00000001"
552
553         # truncate put the file dirty
554         $TRUNCATE $f 1 || error "could not truncate test file"
555         check_hsm_flags $f "0x00000003"
556
557         $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
558         check_hsm_flags $f "0x00000001"
559 }
560 run_test 2 "Check file dirtyness when doing setattr"
561
562 test_3() {
563         mkdir -p $DIR/$tdir
564         f=$DIR/$tdir/$tfile
565
566         # New files are not dirty
567         cp -p /etc/passwd $f
568         check_hsm_flags $f "0x00000000"
569
570         # For test, we simulate an archived file.
571         $LFS hsm_set --exists $f ||
572                 error "user could not change hsm flags"
573         check_hsm_flags $f "0x00000001"
574
575         # Reading a file, does not set dirty
576         cat $f > /dev/null || error "could not read file"
577         check_hsm_flags $f "0x00000001"
578
579         # Open for write without modifying data, does not set dirty
580         openfile -f O_WRONLY $f || error "could not open test file"
581         check_hsm_flags $f "0x00000001"
582
583         # Append to a file sets it dirty
584         cp -p /etc/passwd $f.append || error "could not create file"
585         $LFS hsm_set --exists $f.append ||
586                 error "user could not change hsm flags"
587         dd if=/etc/passwd of=$f.append bs=1 count=3\
588            conv=notrunc oflag=append status=noxfer ||
589                 error "could not append to test file"
590         check_hsm_flags $f.append "0x00000003"
591
592         # Modify a file sets it dirty
593         cp -p /etc/passwd $f.modify || error "could not create file"
594         $LFS hsm_set --exists $f.modify ||
595                 error "user could not change hsm flags"
596         dd if=/dev/zero of=$f.modify bs=1 count=3\
597            conv=notrunc status=noxfer ||
598                 error "could not modify test file"
599         check_hsm_flags $f.modify "0x00000003"
600
601         # Open O_TRUNC sets dirty
602         cp -p /etc/passwd $f.trunc || error "could not create file"
603         $LFS hsm_set --exists $f.trunc ||
604                 error "user could not change hsm flags"
605         cp /etc/group $f.trunc || error "could not override a file"
606         check_hsm_flags $f.trunc "0x00000003"
607
608         # Mmapped a file sets dirty
609         cp -p /etc/passwd $f.mmap || error "could not create file"
610         $LFS hsm_set --exists $f.mmap ||
611                 error "user could not change hsm flags"
612         multiop $f.mmap OSMWUc || error "could not mmap a file"
613         check_hsm_flags $f.mmap "0x00000003"
614 }
615 run_test 3 "Check file dirtyness when opening for write"
616
617 test_4() {
618         mkdir -p $DIR/$tdir
619         local f=$DIR/$tdir/$tfile
620         local fid=$(make_small $f)
621
622         $LFS hsm_cancel $f
623         local st=$(get_request_state $fid CANCEL)
624         [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
625 }
626 run_test 4 "Useless cancel must not be registered"
627
628 test_8() {
629         # test needs a running copytool
630         copytool_setup
631
632         mkdir -p $DIR/$tdir
633         local f=$DIR/$tdir/$tfile
634         local fid=$(copy_file /etc/passwd $f)
635         $LFS hsm_archive $f
636         wait_request_state $fid ARCHIVE SUCCEED
637
638         check_hsm_flags $f "0x00000009"
639
640         copytool_cleanup
641 }
642 run_test 8 "Test default archive number"
643
644 test_9() {
645         mkdir -p $DIR/$tdir
646         local f=$DIR/$tdir/$tfile
647         local fid=$(copy_file /etc/passwd $f)
648         # we do not use the default one to be sure
649         local new_an=$((HSM_ARCHIVE_NUMBER + 1))
650         copytool_cleanup
651         copytool_setup $SINGLEAGT $MOUNT $new_an
652         $LFS hsm_archive --archive $new_an $f
653         wait_request_state $fid ARCHIVE SUCCEED
654
655         check_hsm_flags $f "0x00000009"
656
657         copytool_cleanup
658 }
659 run_test 9 "Use of explict archive number, with dedicated copytool"
660
661 test_9a() {
662         [[ $CLIENTCOUNT -ge 3 ]] ||
663                 { skip "Need three or more clients"; return 0; }
664
665         local n
666         local file
667         local fid
668
669         copytool_cleanup $(comma_list $(agts_nodes))
670
671         # start all of the copytools
672         for n in $(seq $AGTCOUNT); do
673                 copytool_setup agt$n
674         done
675
676         trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
677         # archive files
678         mkdir -p $DIR/$tdir
679         for n in $(seq $AGTCOUNT); do
680                 file=$DIR/$tdir/$tfile.$n
681                 fid=$(make_small $file)
682
683                 $LFS hsm_archive $file || error "could not archive file $file"
684                 wait_request_state $fid ARCHIVE SUCCEED
685                 check_hsm_flags $file "0x00000001"
686         done
687
688         trap - EXIT
689         copytool_cleanup $(comma_list $(agts_nodes))
690 }
691 run_test 9a "Multiple remote agents"
692
693 test_10a() {
694         # test needs a running copytool
695         copytool_setup
696
697         mkdir -p $DIR/$tdir/d1
698         local f=$DIR/$tdir/$tfile
699         local fid=$(copy_file /etc/hosts $f)
700         $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
701                 error "hsm_archive failed"
702         wait_request_state $fid ARCHIVE SUCCEED
703
704         local AFILE=$(ls $HSM_ARCHIVE/*/*/*/*/*/*/$fid) ||
705                 error "fid $fid not in archive $HSM_ARCHIVE"
706         echo "Verifying content"
707         diff $f $AFILE || error "archived file differs"
708         echo "Verifying hsm state "
709         check_hsm_flags $f "0x00000009"
710
711         echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
712         local st=$(get_hsm_archive_id $f)
713         [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
714                 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
715
716         copytool_cleanup
717
718 }
719 run_test 10a "Archive a file"
720
721 test_10b() {
722         # test needs a running copytool
723         copytool_setup
724
725         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
726         local f=$DIR/$tdir/$tfile
727         local fid=$(copy_file /etc/hosts $f)
728         $LFS hsm_archive $f || error "archive request failed"
729         wait_request_state $fid ARCHIVE SUCCEED
730
731         $LFS hsm_archive $f || error "archive of non dirty file failed"
732         local cnt=$(get_request_count $fid ARCHIVE)
733         [[ "$cnt" == "1" ]] ||
734                 error "archive of non dirty file must not make a request"
735
736         copytool_cleanup
737 }
738 run_test 10b "Archive of non dirty file must work without doing request"
739
740 test_10c() {
741         # test needs a running copytool
742         copytool_setup
743
744         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
745         local f=$DIR/$tdir/$tfile
746         local fid=$(copy_file /etc/hosts $f)
747         $LFS hsm_set --noarchive $f
748         $LFS hsm_archive $f && error "archive a noarchive file must fail"
749
750         copytool_cleanup
751 }
752 run_test 10c "Check forbidden archive"
753
754 test_11() {
755         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
756         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
757         local f=$DIR/$tdir/$tfile
758
759         import_file $tdir/$tfile $f
760         echo -n "Verifying released state: "
761         check_hsm_flags $f "0x0000000d"
762
763         local LSZ=$(stat -c "%s" $f)
764         local ASZ=$(stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
765
766         echo "Verifying imported size $LSZ=$ASZ"
767         [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
768         echo -n "Verifying released pattern: "
769         local PTRN=$($GETSTRIPE -L $f)
770         echo $PTRN
771         [[ $PTRN == 80000001 ]] || error "Is not released"
772         local fid=$(path2fid $f)
773         echo "Verifying new fid $fid in archive"
774
775         local AFILE=$(ls $HSM_ARCHIVE/*/*/*/*/*/*/$fid) ||
776                 error "fid $fid not in archive $HSM_ARCHIVE"
777 }
778 run_test 11 "Import a file"
779
780 test_12a() {
781         # test needs a running copytool
782         copytool_setup
783
784         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
785         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
786         local f=$DIR/$tdir/$tfile
787         import_file $tdir/$tfile $f
788         local f=$DIR2/$tdir/$tfile
789         echo "Verifying released state: "
790         check_hsm_flags $f "0x0000000d"
791
792         local fid=$(path2fid $f)
793         $LFS hsm_restore $f
794         wait_request_state $fid RESTORE SUCCEED
795
796         echo "Verifying file state: "
797         check_hsm_flags $f "0x00000009"
798
799         diff -q $HSM_ARCHIVE/$tdir/$tfile $f
800
801         [[ $? -eq 0 ]] || error "Restored file differs"
802
803         copytool_cleanup
804 }
805 run_test 12a "Restore an imported file explicitly"
806
807 test_12b() {
808         # test needs a running copytool
809         copytool_setup
810
811         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
812         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
813         local f=$DIR/$tdir/$tfile
814         import_file $tdir/$tfile $f
815         echo "Verifying released state: "
816         check_hsm_flags $f "0x0000000d"
817
818         cat $f > /dev/null || error "File read failed"
819
820         echo "Verifying file state after restore: "
821         check_hsm_flags $f "0x00000009"
822
823         diff -q $HSM_ARCHIVE/$tdir/$tfile $f
824
825         [[ $? -eq 0 ]] || error "Restored file differs"
826
827         copytool_cleanup
828 }
829 run_test 12b "Restore an imported file implicitly"
830
831 test_12c() {
832         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
833
834         # test needs a running copytool
835         copytool_setup
836
837         mkdir -p $DIR/$tdir
838         local f=$DIR/$tdir/$tfile
839         $LFS setstripe -c 2 $f
840         local fid=$(make_large_for_striping $f)
841         local FILE_CRC=$(md5sum $f)
842
843         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
844         wait_request_state $fid ARCHIVE SUCCEED
845         $LFS hsm_release $f || error "release $f failed"
846
847         echo "$FILE_CRC" | md5sum -c
848
849         [[ $? -eq 0 ]] || error "Restored file differs"
850
851         copytool_cleanup
852 }
853 run_test 12c "Restore a file with stripe of 2"
854
855 test_12d() {
856         # test needs a running copytool
857         copytool_setup
858
859         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
860         local f=$DIR/$tdir/$tfile
861         local fid=$(copy_file /etc/hosts $f)
862         $LFS hsm_restore $f || error "restore of non archived file failed"
863         local cnt=$(get_request_count $fid RESTORE)
864         [[ "$cnt" == "0" ]] ||
865                 error "restore non archived must not make a request"
866         $LFS hsm_archive $f ||
867                 error "archive request failed"
868         wait_request_state $fid ARCHIVE SUCCEED
869         $LFS hsm_restore $f ||
870                 error "restore of non released file failed"
871         local cnt=$(get_request_count $fid RESTORE)
872         [[ "$cnt" == "0" ]] ||
873                 error "restore a non dirty file must not make a request"
874
875         copytool_cleanup
876 }
877 run_test 12d "Restore of a non archived, non released file must work"\
878                 " without doing request"
879
880 test_12e() {
881         # test needs a running copytool
882         copytool_setup
883
884         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
885         local f=$DIR/$tdir/$tfile
886         local fid=$(copy_file /etc/hosts $f)
887         $LFS hsm_archive $f || error "archive request failed"
888         wait_request_state $fid ARCHIVE SUCCEED
889
890         # make file dirty
891         cat /etc/hosts >> $f
892         sync
893         $LFS hsm_state $f
894
895         $LFS hsm_restore $f && error "restore a dirty file must fail"
896
897         copytool_cleanup
898 }
899 run_test 12e "Check forbidden restore"
900
901 test_12f() {
902         # test needs a running copytool
903         copytool_setup
904
905         mkdir -p $DIR/$tdir
906         local f=$DIR/$tdir/$tfile
907         local fid=$(copy_file /etc/hosts $f)
908
909         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
910         wait_request_state $fid ARCHIVE SUCCEED
911         $LFS hsm_release $f || error "release of $f failed"
912         $LFS hsm_restore $f
913         wait_request_state $fid RESTORE SUCCEED
914
915         echo -n "Verifying file state: "
916         check_hsm_flags $f "0x00000009"
917
918         diff -q /etc/hosts $f
919
920         [[ $? -eq 0 ]] || error "Restored file differs"
921
922         copytool_cleanup
923 }
924 run_test 12f "Restore a released file explicitly"
925
926 test_12g() {
927         # test needs a running copytool
928         copytool_setup
929
930         mkdir -p $DIR/$tdir
931         local f=$DIR/$tdir/$tfile
932         local fid=$(copy_file /etc/hosts $f)
933
934         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
935         wait_request_state $fid ARCHIVE SUCCEED
936         $LFS hsm_release $f || error "release of $f failed"
937
938         diff -q /etc/hosts $f
939         local st=$?
940
941         # we check we had a restore done
942         wait_request_state $fid RESTORE SUCCEED
943
944         [[ $st -eq 0 ]] || error "Restored file differs"
945
946         copytool_cleanup
947 }
948 run_test 12g "Restore a released file implicitly"
949
950 test_12h() {
951         need2clients || return 0
952
953         # test needs a running copytool
954         copytool_setup
955
956         mkdir -p $DIR/$tdir
957         local f=$DIR/$tdir/$tfile
958         local fid=$(copy_file /etc/hosts $f)
959
960         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
961         wait_request_state $fid ARCHIVE SUCCEED
962         $LFS hsm_release $f || error "release of $f failed"
963
964         do_node $CLIENT2 diff -q /etc/hosts $f
965         local st=$?
966
967         # we check we had a restore done
968         wait_request_state $fid RESTORE SUCCEED
969
970         [[ $st -eq 0 ]] || error "Restored file differs"
971
972         copytool_cleanup
973 }
974 run_test 12h "Restore a released file implicitly from a second node"
975
976 test_12m() {
977         # test needs a running copytool
978         copytool_setup
979
980         mkdir -p $DIR/$tdir
981         local f=$DIR/$tdir/$tfile
982         local fid=$(copy_file /etc/passwd $f)
983         $LFS hsm_archive $f || error "archive of $f failed"
984         wait_request_state $fid ARCHIVE SUCCEED
985
986         $LFS hsm_release $f || error "release of $f failed"
987
988         cmp /etc/passwd $f
989
990         [[ $? -eq 0 ]] || error "Restored file differs"
991
992         copytool_cleanup
993 }
994 run_test 12m "Archive/release/implicit restore"
995
996 test_12n() {
997         # test needs a running copytool
998         copytool_setup
999
1000         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1001         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
1002         local f=$DIR/$tdir/$tfile
1003         import_file $tdir/$tfile $f
1004
1005         cmp /etc/hosts $f || error "Restored file differs"
1006
1007         $LFS hsm_release $f || error "release of $f failed"
1008
1009         copytool_cleanup
1010 }
1011 run_test 12n "Import/implicit restore/release"
1012
1013 test_13() {
1014         # test needs a running copytool
1015         copytool_setup
1016
1017         local ARC_SUBDIR="import.orig"
1018         local d=""
1019         local f=""
1020
1021         # populate directory to be imported
1022         for d in $(seq 1 10); do
1023                 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1024                 mkdir -p "$CURR_DIR"
1025                 for f in $(seq 1 10); do
1026                         CURR_FILE="$CURR_DIR/$tfile.$f"
1027                         # write file-specific data
1028                         echo "d=$d, f=$f, dir=$CURR_DIR, file=$CURR_FILE"\
1029                                 > $CURR_FILE
1030                 done
1031         done
1032         # import to Lustre
1033         import_file "$ARC_SUBDIR" $DIR/$tdir
1034         # diff lustre content and origin (triggers file restoration)
1035         # there must be 10x10 identical files, and no difference
1036         local cnt_ok=$(diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1037                        $DIR/$tdir/$ARC_SUBDIR |
1038                 grep identical | wc -l)
1039         local cnt_diff=$(diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1040                          $DIR/$tdir/$ARC_SUBDIR |
1041                 wc -l)
1042
1043         [ $cnt_diff -eq 0 ] ||
1044                 error "$cnt_diff imported files differ from read data"
1045         [ $cnt_ok -eq 100 ] ||
1046                 error "not enough identical files ($cnt_ok != 100)"
1047
1048         copytool_cleanup
1049 }
1050 run_test 13 "Recursively import and restore a directory"
1051
1052 test_14() {
1053         # test needs a running copytool
1054         copytool_setup
1055
1056         # archive a file
1057         mkdir -p $DIR/$tdir
1058         local f=$DIR/$tdir/$tfile
1059         local fid=$(make_small $f)
1060         local sum=$(md5sum $f | awk '{print $1}')
1061         $LFS hsm_archive $f || error "could not archive file"
1062         wait_request_state $fid ARCHIVE SUCCEED
1063
1064         # delete the file
1065         rm -f $f
1066         # create released file (simulate llapi_hsm_import call)
1067         touch $f
1068         local fid2=$(path2fid $f)
1069         $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1070         $LFS hsm_release $f || error "could not release file"
1071
1072         # rebind the archive to the newly created file
1073         echo "rebind $fid to $fid2"
1074
1075         do_facet $SINGLEAGT \
1076                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1077                  --rebind $fid $fid2 $DIR" || error "could not rebind file"
1078
1079         # restore file and compare md5sum
1080         local sum2=$(md5sum $f | awk '{print $1}')
1081
1082         [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1083
1084         copytool_cleanup
1085 }
1086 run_test 14 "Rebind archived file to a new fid"
1087
1088 test_15() {
1089         # test needs a running copytool
1090         copytool_setup
1091
1092         # archive files
1093         mkdir -p $DIR/$tdir
1094         local f=$DIR/$tdir/$tfile
1095         local count=5
1096         local tmpfile=$SHARED_DIRECTORY/tmp.$$
1097
1098         local fids=()
1099         local sums=()
1100         for i in $(seq 1 $count); do
1101                 fids[$i]=$(make_small $f.$i)
1102                 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1103                 $LFS hsm_archive $f.$i || error "could not archive file"
1104         done
1105         wait_all_done $(($count*60))
1106
1107         :>$tmpfile
1108         # delete the files
1109         for i in $(seq 1 $count); do
1110                 rm -f $f.$i
1111                 touch $f.$i
1112                 local fid2=$(path2fid $f.$i)
1113                 # add the rebind operation to the list
1114                 echo ${fids[$i]} $fid2 >> $tmpfile
1115
1116                 # set it released (simulate llapi_hsm_import call)
1117                 $LFS hsm_set --archived --exists $f.$i ||
1118                         error "could not force hsm flags"
1119                 $LFS hsm_release $f.$i || error "could not release file"
1120         done
1121         nl=$(wc -l < $tmpfile)
1122         [[ $nl == $count ]] || error "$nl files in list, $count expected"
1123
1124         echo "rebind list of files"
1125         do_facet $SINGLEAGT \
1126                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1127                  --rebind $tmpfile $DIR" || error "could not rebind file list"
1128
1129         # restore files and compare md5sum
1130         for i in $(seq 1 $count); do
1131                 local sum2=$(md5sum $f.$i | awk '{print $1}')
1132                 [[ $sum2 == ${sums[$i]} ]] ||
1133                     error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1134         done
1135
1136         rm -f $tmpfile
1137         copytool_cleanup
1138 }
1139 run_test 15 "Rebind a list of files"
1140
1141 test_16() {
1142         # test needs a running copytool
1143         copytool_setup
1144
1145         local ref=/tmp/ref
1146         # create a known size file so we can verify transfer speed
1147         # 20 MB <-> 20s
1148         local goal=20
1149         dd if=/dev/zero of=$ref bs=1M count=20
1150
1151         mkdir -p $DIR/$tdir
1152         local f=$DIR/$tdir/$tfile
1153         local fid=$(copy_file $ref $f)
1154         rm $ref
1155         local start=$(date +%s)
1156         $LFS hsm_archive $f
1157         wait_request_state $fid ARCHIVE SUCCEED
1158         local end=$(date +%s)
1159         local duration=$((end - start))
1160
1161         [[ $duration -ge $goal ]] ||
1162                 error "Transfer is too fast $duration < $goal"
1163
1164         copytool_cleanup
1165 }
1166 run_test 16 "Test CT bandwith control option"
1167
1168 test_20() {
1169         mkdir -p $DIR/$tdir
1170
1171         local f=$DIR/$tdir/$tfile
1172         touch $f || error "touch $f failed"
1173
1174         # Could not release a non-archived file
1175         $LFS hsm_release $f && error "release should not succeed"
1176
1177         # For following tests, we must test them with HS_ARCHIVED set
1178         $LFS hsm_set --exists --archived $f || error "could not add flag"
1179
1180         # Could not release a file if no-release is set
1181         $LFS hsm_set --norelease $f || error "could not add flag"
1182         $LFS hsm_release $f && error "release should not succeed"
1183         $LFS hsm_clear --norelease $f || error "could not remove flag"
1184
1185         # Could not release a file if lost
1186         $LFS hsm_set --lost $f || error "could not add flag"
1187         $LFS hsm_release $f && error "release should not succeed"
1188         $LFS hsm_clear --lost $f || error "could not remove flag"
1189
1190         # Could not release a file if dirty
1191         $LFS hsm_set --dirty $f || error "could not add flag"
1192         $LFS hsm_release $f && error "release should not succeed"
1193         $LFS hsm_clear --dirty $f || error "could not remove flag"
1194 }
1195 run_test 20 "Release is not permitted"
1196
1197 test_21() {
1198         # test needs a running copytool
1199         copytool_setup
1200
1201         mkdir -p $DIR/$tdir
1202         local f=$DIR/$tdir/test_release
1203
1204         # Create a file and check its states
1205         local fid=$(make_small $f)
1206         check_hsm_flags $f "0x00000000"
1207
1208         $LFS hsm_archive $f || error "could not archive file"
1209         wait_request_state $fid ARCHIVE SUCCEED
1210
1211         [ $(stat -c "%b" $f) -ne "0" ] || error "wrong block number"
1212         local sz=$(stat -c "%s" $f)
1213         [ $sz -ne "0" ] || error "file size should not be zero"
1214
1215         # Release and check states
1216         $LFS hsm_release $f || error "could not release file"
1217         check_hsm_flags $f "0x0000000d"
1218
1219         [ $(stat -c "%b" $f) -eq "0" ] || error "wrong block number"
1220         [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1221
1222         # Check we can release an file without stripe info
1223         f=$f.nolov
1224         $MCREATE $f
1225         fid=$(path2fid $f)
1226         check_hsm_flags $f "0x00000000"
1227         $LFS hsm_archive $f || error "could not archive file"
1228         wait_request_state $fid ARCHIVE SUCCEED
1229
1230         # Release and check states
1231         $LFS hsm_release $f || error "could not release file"
1232         check_hsm_flags $f "0x0000000d"
1233
1234         # Release again a file that is already released is OK
1235         $LFS hsm_release $f || fail "second release should succeed"
1236         check_hsm_flags $f "0x0000000d"
1237
1238         copytool_cleanup
1239 }
1240 run_test 21 "Simple release tests"
1241
1242 test_22() {
1243         # test needs a running copytool
1244         copytool_setup
1245
1246         mkdir -p $DIR/$tdir
1247
1248         local f=$DIR/$tdir/test_release
1249         local swap=$DIR/$tdir/test_swap
1250
1251         # Create a file and check its states
1252         local fid=$(make_small $f)
1253         check_hsm_flags $f "0x00000000"
1254
1255         $LFS hsm_archive $f || error "could not archive file"
1256         wait_request_state $fid ARCHIVE SUCCEED
1257
1258         # Release and check states
1259         $LFS hsm_release $f || error "could not release file"
1260         check_hsm_flags $f "0x0000000d"
1261
1262         make_small $swap
1263         $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1264
1265         true
1266         copytool_cleanup
1267 }
1268 run_test 22 "Could not swap a release file"
1269
1270 test_23() {
1271         # test needs a running copytool
1272         copytool_setup
1273
1274         mkdir -p $DIR/$tdir
1275
1276         local f=$DIR/$tdir/test_mtime
1277
1278         # Create a file and check its states
1279         local fid=$(make_small $f)
1280         check_hsm_flags $f "0x00000000"
1281
1282         $LFS hsm_archive $f || error "could not archive file"
1283         wait_request_state $fid ARCHIVE SUCCEED
1284
1285         # Set modification time in the past
1286         touch -m -a -d @978261179 $f
1287
1288         # Release and check states
1289         $LFS hsm_release $f || error "could not release file"
1290         check_hsm_flags $f "0x0000000d"
1291
1292         local MTIME=$(stat -c "%Y" $f)
1293         local ATIME=$(stat -c "%X" $f)
1294         [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1295         [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1296
1297         copytool_cleanup
1298 }
1299 run_test 23 "Release does not change a/mtime (utime)"
1300
1301 test_24() {
1302         # test needs a running copytool
1303         copytool_setup
1304
1305         mkdir -p $DIR/$tdir
1306
1307         local f=$DIR/$tdir/test_mtime
1308
1309         # Create a file and check its states
1310         local fid=$(make_small $f)
1311         check_hsm_flags $f "0x00000000"
1312
1313         # make mtime is different
1314         sleep 1
1315         echo "append" >> $f
1316         local MTIME=$(stat -c "%Y" $f)
1317         local ATIME=$(stat -c "%X" $f)
1318
1319         $LFS hsm_archive $f || error "could not archive file"
1320         wait_request_state $fid ARCHIVE SUCCEED
1321
1322         # Release and check states
1323         $LFS hsm_release $f || error "could not release file"
1324         check_hsm_flags $f "0x0000000d"
1325
1326         [ "$(stat -c "%Y" $f)" -eq "$MTIME" ] ||
1327                 error "mtime should be $MTIME"
1328
1329         [ "$(stat -c "%X" $f)" -eq "$ATIME" ] ||
1330                 error "atime should be $ATIME"
1331
1332         copytool_cleanup
1333 }
1334 run_test 24 "Release does not change a/mtime (i/o)"
1335
1336 test_25a() {
1337         # test needs a running copytool
1338         copytool_setup
1339
1340         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1341         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
1342         local f=$DIR/$tdir/$tfile
1343
1344         import_file $tdir/$tfile $f
1345
1346         $LFS hsm_set --lost $f
1347
1348         md5sum $f
1349         local st=$?
1350
1351         [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1352
1353         copytool_cleanup
1354 }
1355 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1356              " (Operation not permitted)"
1357
1358 test_25b() {
1359         # test needs a running copytool
1360         copytool_setup
1361
1362         mkdir -p $DIR/$tdir
1363
1364         local f=$DIR/$tdir/$tfile
1365         local fid=$(copy_file /etc/passwd $f)
1366
1367         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1368         wait_request_state $fid ARCHIVE SUCCEED
1369
1370         $LFS hsm_release $f
1371         $LFS hsm_set --lost $f
1372         md5sum $f
1373         st=$?
1374
1375         [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1376
1377         copytool_cleanup
1378 }
1379 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1380              " (Operation not permitted)"
1381
1382 test_26() {
1383         # test needs a running copytool
1384         copytool_setup
1385
1386         mkdir -p $DIR/$tdir
1387         local f=$DIR/$tdir/$tfile
1388         local fid=$(make_large_for_progress $f)
1389         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1390         wait_request_state $fid ARCHIVE SUCCEED
1391
1392         $LFS hsm_remove $f
1393         wait_request_state $fid REMOVE SUCCEED
1394
1395         check_hsm_flags $f "0x00000000"
1396
1397         copytool_cleanup
1398 }
1399 run_test 26 "Remove the archive of a valid file"
1400
1401 test_27a() {
1402         # test needs a running copytool
1403         copytool_setup
1404
1405         mkdir -p $DIR/$tdir
1406         make_archive $tdir/$tfile
1407         local f=$DIR/$tdir/$tfile
1408         import_file $tdir/$tfile $f
1409         local fid=$(path2fid $f)
1410
1411         $LFS hsm_remove $f
1412
1413         [[ $? != 0 ]] || error "Remove of a released file should fail"
1414
1415         copytool_cleanup
1416 }
1417 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1418
1419 test_27b() {
1420         # test needs a running copytool
1421         copytool_setup
1422
1423         mkdir -p $DIR/$tdir
1424         local f=$DIR/$tdir/$tfile
1425         local fid=$(make_large_for_progress $f)
1426         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1427         wait_request_state $fid ARCHIVE SUCCEED
1428         $LFS hsm_release $f
1429
1430         $LFS hsm_remove $f
1431
1432         [[ $? != 0 ]] || error "Remove of a released file should fail"
1433
1434         copytool_cleanup
1435 }
1436 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1437
1438 test_28() {
1439         # test needs a running copytool
1440         copytool_setup
1441
1442         mkdir -p $DIR/$tdir
1443         local f=$DIR/$tdir/$tfile
1444         local fid=$(make_large_for_progress $f)
1445         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1446         wait_request_state $fid ARCHIVE SUCCEED
1447
1448         cdt_disable
1449         $LFS hsm_remove $f
1450
1451         rm -f $f
1452
1453         cdt_enable
1454
1455         wait_request_state $fid REMOVE SUCCEED
1456
1457         copytool_cleanup
1458 }
1459 run_test 28 "Concurrent archive/file remove"
1460
1461 test_30a() {
1462         # restore at exec cannot work on agent node (because of Linux kernel
1463         # protection of executables)
1464         need2clients || return 0
1465
1466         # test needs a running copytool
1467         copytool_setup
1468
1469         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1470         cp -p /bin/true $HSM_ARCHIVE/$tdir/$tfile
1471         local f=$DIR/$tdir/true
1472         import_file $tdir/$tfile $f
1473
1474         local fid=$(path2fid $f)
1475
1476         # set no retry action mode
1477         cdt_set_no_retry
1478         do_node $CLIENT2 $f
1479         local st=$?
1480
1481         # cleanup
1482         # remove no try action mode
1483         cdt_clear_no_retry
1484         $LFS hsm_state $f
1485
1486         [[ $st == 0 ]] || error "Failed to exec a released file"
1487
1488         copytool_cleanup
1489 }
1490 run_test 30a "Restore at exec (import case)"
1491
1492 test_30b() {
1493         # restore at exec cannot work on agent node (because of Linux kernel
1494         # protection of executables)
1495         need2clients || return 0
1496
1497         # test needs a running copytool
1498         copytool_setup
1499
1500         mkdir -p $DIR/$tdir
1501         local f=$DIR/$tdir/true
1502         local fid=$(copy_file /bin/true $f)
1503         chmod 755 $f
1504         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1505         wait_request_state $fid ARCHIVE SUCCEED
1506         $LFS hsm_release $f
1507         $LFS hsm_state $f
1508         # set no retry action mode
1509         cdt_set_no_retry
1510         do_node $CLIENT2 $f
1511         local st=$?
1512
1513         # cleanup
1514         # remove no try action mode
1515         cdt_clear_no_retry
1516         $LFS hsm_state $f
1517
1518         [[ $st == 0 ]] || error "Failed to exec a released file"
1519
1520         copytool_cleanup
1521 }
1522 run_test 30b "Restore at exec (release case)"
1523
1524 restore_and_check_size() {
1525         local f=$1
1526         local fid=$2
1527         local s=$(stat -c "%s" $f)
1528         local n=$s
1529         local st=$(get_hsm_flags $f)
1530         local err=0
1531         local cpt=0
1532         $LFS hsm_restore $f
1533         while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1534         do
1535                 n=$(stat -c "%s" $f)
1536                 # we echo in both cases to show stat is not
1537                 # hang
1538                 if [[ $n != $s ]]
1539                 then
1540                         echo "size seen is $n != $s"
1541                         err=1
1542                 else
1543                         echo "size seen is right: $n == $s"
1544                 fi
1545                 st=$(get_hsm_flags $f)
1546                 sleep 10
1547                 cpt=$((cpt + 1))
1548         done
1549         if [[ $cpt -lt 10 ]]
1550         then
1551                 echo " restore is too long"
1552         else
1553                 echo " "done
1554         fi
1555         wait_request_state $fid RESTORE SUCCEED
1556         return $err
1557 }
1558
1559 test_31a() {
1560         # test needs a running copytool
1561         copytool_setup
1562
1563         mkdir -p $DIR/$tdir
1564
1565         make_archive $tdir/$tfile
1566         local f=$DIR/$tdir/$tfile
1567         import_file $tdir/$tfile $f
1568         local fid=$($LFS path2fid $f)
1569         HSM_ARCHIVE_PURGE=false copytool_setup
1570
1571         restore_and_check_size $f $fid
1572         local err=$?
1573
1574         [[ $err -eq 0 ]] || error "File size changed during restore"
1575
1576         copytool_cleanup
1577 }
1578 run_test 31a "Import a large file and check size during restore"
1579
1580
1581 test_31b() {
1582         # test needs a running copytool
1583         copytool_setup
1584
1585         mkdir -p $DIR/$tdir
1586
1587         local f=$DIR/$tdir/$tfile
1588         local fid=$(make_large_for_progress $f)
1589         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1590         wait_request_state $fid ARCHIVE SUCCEED
1591         $LFS hsm_release $f
1592
1593         restore_and_check_size $f $fid
1594         local err=$?
1595
1596         [[ $err -eq 0 ]] || error "File size changed during restore"
1597
1598         copytool_cleanup
1599 }
1600 run_test 31b "Restore a large unaligned file and check size during restore"
1601
1602 test_31c() {
1603         # test needs a running copytool
1604         copytool_setup
1605
1606         mkdir -p $DIR/$tdir
1607
1608         local f=$DIR/$tdir/$tfile
1609         local fid=$(make_large_for_progress_aligned $f)
1610         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1611         wait_request_state $fid ARCHIVE SUCCEED
1612         $LFS hsm_release $f
1613
1614         restore_and_check_size $f $fid
1615         local err=$?
1616
1617         [[ $err -eq 0 ]] || error "File size changed during restore"
1618
1619         copytool_cleanup
1620 }
1621 run_test 31c "Restore a large aligned file and check size during restore"
1622
1623 test_33() {
1624         # test needs a running copytool
1625         copytool_setup
1626
1627         mkdir -p $DIR/$tdir
1628
1629         local f=$DIR/$tdir/$tfile
1630         local fid=$(make_large_for_progress $f)
1631         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1632         wait_request_state $fid ARCHIVE SUCCEED
1633         $LFS hsm_release $f
1634
1635         md5sum $f >/dev/null &
1636         local pid=$!
1637         wait_request_state $fid RESTORE STARTED
1638
1639         kill -15 $pid
1640         sleep 1
1641
1642         # Check restore trigger process was killed
1643         local killed=$(ps -o pid,comm hp $pid >/dev/null)
1644
1645         $LFS hsm_cancel $f
1646
1647         wait_request_state $fid RESTORE CANCELED
1648         wait_request_state $fid CANCEL SUCCEED
1649
1650         [ -z $killed ] ||
1651                 error "Cannot kill process waiting for restore ($killed)"
1652
1653         copytool_cleanup
1654 }
1655 run_test 33 "Kill a restore waiting process"
1656
1657 test_34() {
1658         # test needs a running copytool
1659         copytool_setup
1660
1661         mkdir -p $DIR/$tdir
1662
1663         local f=$DIR/$tdir/$tfile
1664         local fid=$(make_large_for_progress $f)
1665         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1666         wait_request_state $fid ARCHIVE SUCCEED
1667         $LFS hsm_release $f
1668
1669         md5sum $f >/dev/null &
1670         local pid=$!
1671         wait_request_state $fid RESTORE STARTED
1672
1673         rm $f || error "rm $f failed"
1674         # rm must not block during restore
1675         wait_request_state $fid RESTORE STARTED
1676
1677         wait_request_state $fid RESTORE SUCCEED
1678         # check md5sum pgm finished
1679         local there=$(ps -o pid,comm hp $pid >/dev/null)
1680         [[ -z $there ]] || error "Restore initiator does not exit"
1681
1682         local rc=$(wait $pid)
1683         [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1684
1685         copytool_cleanup
1686 }
1687 run_test 34 "Remove file during restore"
1688
1689 test_35() {
1690         # test needs a running copytool
1691         copytool_setup
1692
1693         mkdir -p $DIR/$tdir
1694
1695         local f=$DIR/$tdir/$tfile
1696         local f1=$DIR/$tdir/$tfile-1
1697         local fid=$(make_large_for_progress $f)
1698         local fid1=$(copy_file /etc/passwd $f1)
1699         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1700         wait_request_state $fid ARCHIVE SUCCEED
1701         $LFS hsm_release $f
1702
1703         md5sum $f >/dev/null &
1704         local pid=$!
1705         wait_request_state $fid RESTORE STARTED
1706
1707         mv $f1 $f || error "mv $f1 $f failed"
1708         # mv must not block during restore
1709         wait_request_state $fid RESTORE STARTED
1710
1711         wait_request_state $fid RESTORE SUCCEED
1712         # check md5sum pgm finished
1713         local there=$(ps -o pid,comm hp $pid >/dev/null)
1714         [[ -z $there ]] || error "Restore initiator does not exit"
1715
1716         local rc=$(wait $pid)
1717         [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1718
1719         fid2=$(path2fid $f)
1720         [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
1721
1722         copytool_cleanup
1723 }
1724 run_test 35 "Overwrite file during restore"
1725
1726 test_36() {
1727         # test needs a running copytool
1728         copytool_setup
1729
1730         mkdir -p $DIR/$tdir
1731
1732         local f=$DIR/$tdir/$tfile
1733         local fid=$(make_large_for_progress $f)
1734         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1735         wait_request_state $fid ARCHIVE SUCCEED
1736         $LFS hsm_release $f
1737
1738         md5sum $f >/dev/null &
1739         local pid=$!
1740         wait_request_state $fid RESTORE STARTED
1741
1742         mv $f $f.new
1743         # rm must not block during restore
1744         wait_request_state $fid RESTORE STARTED
1745
1746         wait_request_state $fid RESTORE SUCCEED
1747         # check md5sum pgm finished
1748         local there=$(ps -o pid,comm hp $pid >/dev/null)
1749         [[ -z $there ]] ||
1750                 error "Restore initiator does not exit"
1751
1752         local rc=$(wait $pid)
1753         [[ $rc -eq 0 ]] ||
1754                 error "Restore initiator failed with $rc"
1755
1756         copytool_cleanup
1757 }
1758 run_test 36 "Move file during restore"
1759
1760 multi_archive() {
1761         local prefix=$1
1762         local count=$2
1763         local n=""
1764
1765         for n in $(seq 1 $count); do
1766                 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
1767         done
1768         echo "$count archive requests submitted"
1769 }
1770
1771 test_40() {
1772         local stream_count=4
1773         local file_count=100
1774         mkdir -p $DIR/$tdir
1775         local f=$DIR/$tdir/$tfile
1776         local i=""
1777         local p=""
1778         local fid=""
1779
1780         for i in $(seq 1 $file_count); do
1781                 for p in $(seq 1 $stream_count); do
1782                         fid=$(copy_file /etc/hosts $f.$p.$i)
1783                 done
1784         done
1785         copytool_setup
1786         # to be sure wait_all_done will not be mislead by previous tests
1787         cdt_purge
1788         wait_for_grace_delay
1789         typeset -a pids
1790         # start archive streams in background (archive files in parallel)
1791         for p in $(seq 1 $stream_count); do
1792                 multi_archive $f.$p $file_count &
1793                 pids[$p]=$!
1794         done
1795         echo -n  "Wait for all requests being enqueued..."
1796         wait ${pids[*]}
1797         echo OK
1798         wait_all_done 100
1799         copytool_cleanup
1800 }
1801 run_test 40 "Parallel archive requests"
1802
1803 test_52() {
1804         # test needs a running copytool
1805         copytool_setup
1806
1807         mkdir -p $DIR/$tdir
1808         local f=$DIR/$tdir/$tfile
1809         local fid=$(copy_file /etc/motd $f 1)
1810
1811         $LFS hsm_archive $f || error "could not archive file"
1812         wait_request_state $fid ARCHIVE SUCCEED
1813         check_hsm_flags $f "0x00000009"
1814
1815         multiop_bg_pause $f O_c || error "multiop failed"
1816         local MULTIPID=$!
1817
1818         mds_evict_client
1819         client_up || client_up || true
1820
1821         kill -USR1 $MULTIPID
1822         wait $MULTIPID || error "multiop close failed"
1823
1824         check_hsm_flags $f "0x0000000b"
1825
1826         copytool_cleanup
1827 }
1828 run_test 52 "Opened for write file on an evicted client should be set dirty"
1829
1830 test_53() {
1831         # test needs a running copytool
1832         copytool_setup
1833
1834         mkdir -p $DIR/$tdir
1835         local f=$DIR/$tdir/$tfile
1836         local fid=$(copy_file /etc/motd $f 1)
1837
1838         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1839                 error "could not archive file"
1840         wait_request_state $fid ARCHIVE SUCCEED
1841         check_hsm_flags $f "0x00000009"
1842
1843         multiop_bg_pause $f o_c || error "multiop failed"
1844         MULTIPID=$!
1845
1846         mds_evict_client
1847         client_up || client_up || true
1848
1849         kill -USR1 $MULTIPID
1850         wait $MULTIPID || error "multiop close failed"
1851
1852         check_hsm_flags $f "0x00000009"
1853
1854         copytool_cleanup
1855 }
1856 run_test 53 "Opened for read file on an evicted client should not be set dirty"
1857
1858 test_54() {
1859         # test needs a running copytool
1860         copytool_setup
1861
1862         mkdir -p $DIR/$tdir
1863         local f=$DIR/$tdir/$tfile
1864         local fid=$(make_small $f)
1865
1866         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1867                 error "could not archive file"
1868         wait_request_state $fid ARCHIVE STARTED
1869
1870         check_hsm_flags $f "0x00000001"
1871
1872         # Avoid coordinator resending this request as soon it has failed.
1873         cdt_set_no_retry
1874
1875         echo "foo" >> $f
1876         sync
1877         wait_request_state $fid ARCHIVE FAILED
1878
1879         check_hsm_flags $f "0x00000003"
1880
1881         cdt_clear_no_retry
1882         copytool_cleanup
1883 }
1884 run_test 54 "Write during an archive cancels it"
1885
1886 test_55() {
1887         # test needs a running copytool
1888         copytool_setup
1889
1890         mkdir -p $DIR/$tdir
1891         local f=$DIR/$tdir/$tfile
1892         local fid=$(make_small $f)
1893
1894         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1895                 error "could not archive file"
1896         wait_request_state $fid ARCHIVE STARTED
1897
1898         check_hsm_flags $f "0x00000001"
1899
1900         # Avoid coordinator resending this request as soon it has failed.
1901         cdt_set_no_retry
1902
1903         $TRUNCATE $f 1024 || error "truncate failed"
1904         sync
1905         wait_request_state $fid ARCHIVE FAILED
1906
1907         check_hsm_flags $f "0x00000003"
1908
1909         cdt_clear_no_retry
1910         copytool_cleanup
1911 }
1912 run_test 55 "Truncate during an archive cancels it"
1913
1914 test_56() {
1915         # test needs a running copytool
1916         copytool_setup
1917
1918         mkdir -p $DIR/$tdir
1919         local f=$DIR/$tdir/$tfile
1920         local fid=$(make_large_for_progress $f)
1921
1922         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1923                 error "could not archive file"
1924         wait_request_state $fid ARCHIVE STARTED
1925
1926         check_hsm_flags $f "0x00000001"
1927
1928         # Change metadata and sync to be sure we are not changing only
1929         # in memory.
1930         chmod 644 $f
1931         chgrp sys $f
1932         sync
1933         wait_request_state $fid ARCHIVE SUCCEED
1934
1935         check_hsm_flags $f "0x00000009"
1936
1937         copytool_cleanup
1938 }
1939 run_test 56 "Setattr during an archive is ok"
1940
1941 test_57() {
1942         # Need one client for I/O, one for request
1943         need2clients || return 0
1944
1945         # test needs a running copytool
1946         copytool_setup
1947
1948         mkdir -p $DIR/$tdir
1949         local f=$DIR/$tdir/test_archive_remote
1950         # Create a file on a remote node
1951         do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
1952                 "count=2 conv=fsync"
1953
1954         # And archive it
1955         do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
1956                 error "hsm_archive failed"
1957         local fid=$(path2fid $f)
1958         wait_request_state $fid ARCHIVE SUCCEED
1959
1960         # Release and implicit restore it
1961         do_node $CLIENT2 "$LFS hsm_release $f" ||
1962                 error "hsm_release failed"
1963         do_node $CLIENT2 "md5sum $f" ||
1964                 error "hsm_restore failed"
1965
1966         wait_request_state $fid RESTORE SUCCEED
1967
1968         copytool_cleanup
1969 }
1970 run_test 57 "Archive a file with dirty cache on another node"
1971
1972 test_58() {
1973         # test needs a running copytool
1974         copytool_setup
1975
1976         mkdir -p $DIR/$tdir
1977         local f=$DIR/$tdir/$tfile
1978         local fid=$(make_small $f)
1979
1980         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1981                 error "could not archive file"
1982         wait_request_state $fid ARCHIVE SUCCEED
1983
1984         $LFS hsm_release $f || error "could not release file"
1985
1986         $TRUNCATE $f 0 || error "truncate failed"
1987         sync
1988
1989         local sz=$(stat -c %s $f)
1990         [[ $sz == 0 ]] || error "size after truncate is $sz != 0"
1991
1992         $LFS hsm_state $f
1993
1994         check_hsm_flags $f "0x0000000b"
1995
1996         local state=$(get_request_state $fid RESTORE)
1997         [[ "$state" == "" ]] ||
1998                 error "truncate 0 trigs a restore, state = $state"
1999
2000         copytool_cleanup
2001 }
2002 run_test 58 "Truncate 0 on a released file must not trigger restore"
2003
2004 test_59() {
2005         # test needs a running copytool
2006         copytool_setup
2007
2008         mkdir -p $DIR/$tdir
2009         local f=$DIR/$tdir/$tfile
2010         local fid=$(copy_file /etc/passwd $f)
2011         local ref=$f-ref
2012         cp $f $ref
2013         local sz=$(stat -c %s $ref)
2014         sz=$((sz / 2))
2015         $TRUNCATE $ref $sz
2016
2017         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2018                 error "could not archive file"
2019         wait_request_state $fid ARCHIVE SUCCEED
2020
2021         $LFS hsm_release $f || error "could not release file"
2022
2023         $TRUNCATE $f $sz || error "truncate failed"
2024         sync
2025
2026         local sz1=$(stat -c %s $f)
2027         [[ $sz1 == $sz ]] || error "size after truncate is $sz1 != $sz"
2028
2029         $LFS hsm_state $f
2030
2031         check_hsm_flags $f "0x0000000b"
2032
2033         local state=$(get_request_state $fid RESTORE)
2034         [[ "$state" == "SUCCEED" ]] ||
2035                 error "truncate $sz does not trig a successfull restore,"\
2036                       " state = $state"
2037
2038         cmp $ref $f || error "file data wrong after truncate"
2039
2040         copytool_cleanup
2041 }
2042 run_test 59 "Truncate != 0 on a released file"
2043
2044 test_90() {
2045         file_count=57
2046         mkdir -p $DIR/$tdir
2047         local f=$DIR/$tdir/$tfile
2048         local FILELIST=/tmp/filelist.txt
2049         local i=""
2050
2051         rm -f $FILELIST
2052         for i in $(seq 1 $file_count); do
2053                 fid=$(copy_file /etc/hosts $f.$i)
2054                 echo $f.$i >> $FILELIST
2055         done
2056         copytool_setup
2057         # to be sure wait_all_done will not be mislead by previous tests
2058         cdt_purge
2059         wait_for_grace_delay
2060         $LFS hsm_archive --filelist $FILELIST ||
2061                 error "cannot archive a file list"
2062         wait_all_done 100
2063         $LFS hsm_release --filelist $FILELIST ||
2064                 error "cannot release a file list"
2065         $LFS hsm_restore --filelist $FILELIST ||
2066                 error "cannot restore a file list"
2067         wait_all_done 100
2068         copytool_cleanup
2069 }
2070 run_test 90 "Archive/restore a file list"
2071
2072 double_verify_reset_ham_param() {
2073         local p=$1
2074         echo "Testing $HSM_PARAM.$p"
2075         local val=$(get_hsm_param $p)
2076         local save=$val
2077         local val2=$(($val * 2))
2078         set_hsm_param $p $val2
2079         val=$(get_hsm_param $p)
2080         [[ $val == $val2 ]] ||
2081                 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2082         echo "Set $p to 0 must failed"
2083         set_hsm_param $p 0
2084         local rc=$?
2085         # restore value
2086         set_hsm_param $p $save
2087
2088         if [[ $rc == 0 ]]
2089         then
2090                 error "we must not be able to set $HSM_PARAM.$p to 0"
2091         fi
2092 }
2093
2094 test_100() {
2095         double_verify_reset_ham_param loop_period
2096         double_verify_reset_ham_param grace_delay
2097         double_verify_reset_ham_param request_timeout
2098         double_verify_reset_ham_param max_requests
2099 }
2100 run_test 100 "Set coordinator /proc tunables"
2101
2102 test_102() {
2103         cdt_disable
2104         cdt_enable
2105         cdt_restart
2106 }
2107 run_test 102 "Verify coordinator control"
2108
2109 test_103() {
2110         # test needs a running copytool
2111         copytool_setup
2112
2113         local i=""
2114         local fid=""
2115
2116         mkdir -p $DIR/$tdir
2117         for i in $(seq 1 20); do
2118                 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2119         done
2120         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2121
2122         cdt_purge
2123
2124         echo "Current requests"
2125         local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2126                         $HSM_PARAM.agent_actions |\
2127                         grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2128
2129         [[ -z "$res" ]] || error "Some request have not been canceled"
2130
2131         copytool_cleanup
2132 }
2133 run_test 103 "Purge all requests"
2134
2135 DATA=CEA
2136 DATAHEX='[434541]'
2137 test_104() {
2138         # test needs a running copytool
2139         copytool_setup
2140
2141         mkdir -p $DIR/$tdir
2142         local f=$DIR/$tdir/$tfile
2143         local fid=$(make_large_for_progress $f)
2144         # if cdt is on, it can serve too quickly the request
2145         cdt_disable
2146         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2147         local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2148                         $HSM_PARAM.agent_actions |\
2149                         grep $fid | cut -f16 -d=")
2150         cdt_enable
2151
2152         [[ "$data1" == "$DATAHEX" ]] ||
2153                 error "Data field in records is ($data1) and not ($DATAHEX)"
2154
2155         copytool_cleanup
2156 }
2157 run_test 104 "Copy tool data field"
2158
2159 test_105() {
2160         mkdir -p $DIR/$tdir
2161         local i=""
2162
2163         cdt_disable
2164         for i in $(seq -w 1 10); do
2165                 cp /etc/passwd $DIR/$tdir/$i
2166                 $LFS hsm_archive $DIR/$tdir/$i
2167         done
2168         local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2169                         $HSM_PARAM.agent_actions |\
2170                         grep WAITING | wc -l")
2171         cdt_restart
2172         cdt_disable
2173         local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2174                         $HSM_PARAM.agent_actions |\
2175                         grep WAITING | wc -l")
2176         cdt_enable
2177         cdt_purge
2178         [[ "$reqcnt1" == "$reqcnt2" ]] ||
2179                 error "Requests count after shutdown $reqcnt2 != "\
2180                       "before shutdown $reqcnt1"
2181 }
2182 run_test 105 "Restart of coordinator"
2183
2184 test_106() {
2185         # test needs a running copytool
2186         copytool_setup
2187
2188         local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2189                 get_client_uuid | cut -d' ' -f2)
2190         local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2191                 grep $uuid)
2192         copytool_cleanup
2193         [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2194         local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2195                 grep $uuid)
2196         [[ -z "$agent" ]] ||
2197                 error "My uuid $uuid still found in agent list,"\
2198                       " after copytool shutdown"
2199         copytool_setup
2200         local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2201                 grep $uuid)
2202         copytool_cleanup
2203         [[ ! -z "$agent" ]] ||
2204                 error "My uuid $uuid not found in agent list after"\
2205                       " copytool restart"
2206 }
2207 run_test 106 "Copytool register/unregister"
2208
2209 test_107() {
2210         # test needs a running copytool
2211         copytool_setup
2212         # create and archive file
2213         mkdir -p $DIR/$tdir
2214         local f1=$DIR/$tdir/$tfile
2215         local fid=$(copy_file /etc/passwd $f1)
2216         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2217         wait_request_state $fid ARCHIVE SUCCEED
2218         # shutdown and restart MDS
2219         fail $SINGLEMDS
2220         # check the copytool still gets messages from MDT
2221         local f2=$DIR/$tdir/2
2222         local fid=$(copy_file /etc/passwd $f2)
2223         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2224         # main check of this sanity: this request MUST succeed
2225         wait_request_state $fid ARCHIVE SUCCEED
2226         copytool_cleanup
2227 }
2228 run_test 107 "Copytool re-register after MDS restart"
2229
2230 test_110a() {
2231         # test needs a running copytool
2232         copytool_setup
2233
2234         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2235         cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2236         local f=$DIR/$tdir/$tfile
2237         import_file $tdir/$tfile $f
2238         local fid=$(path2fid $f)
2239
2240         cdt_set_no_blocking_restore
2241         md5sum $f
2242         local st=$?
2243
2244         # cleanup
2245         wait_request_state $fid RESTORE SUCCEED
2246         cdt_clear_no_blocking_restore
2247
2248         # Test result
2249         [[ $st == 1 ]] ||
2250                 error "md5sum returns $st != 1, "\
2251                         "should also perror ENODATA (No data available)"
2252
2253         copytool_cleanup
2254 }
2255 run_test 110a "Non blocking restore policy (import case)"
2256
2257 test_110b() {
2258         # test needs a running copytool
2259         copytool_setup
2260
2261         mkdir -p $DIR/$tdir
2262         local f=$DIR/$tdir/$tfile
2263         local fid=$(copy_file /etc/passwd $f)
2264         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2265         wait_request_state $fid ARCHIVE SUCCEED
2266         $LFS hsm_release $f
2267
2268         cdt_set_no_blocking_restore
2269         md5sum $f
2270         local st=$?
2271
2272         # cleanup
2273         wait_request_state $fid RESTORE SUCCEED
2274         cdt_clear_no_blocking_restore
2275
2276         # Test result
2277         [[ $st == 1 ]] ||
2278                 error "md5sum returns $st != 1, "\
2279                         "should also perror ENODATA (No data available)"
2280
2281         copytool_cleanup
2282 }
2283 run_test 110b "Non blocking restore policy (release case)"
2284
2285 test_111a() {
2286         # test needs a running copytool
2287         copytool_setup
2288
2289         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2290         local f=$DIR/$tdir/$tfile
2291         cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2292         import_file $tdir/$tfile $f
2293         local fid=$(path2fid $f)
2294
2295         cdt_set_no_retry
2296
2297         copytool_remove_backend $fid
2298
2299         $LFS hsm_restore $f
2300         wait_request_state $fid RESTORE FAILED
2301         local st=$?
2302
2303         # cleanup
2304         cdt_clear_no_retry
2305
2306         # Test result
2307         [[ $st == 0 ]] || error "Restore does not failed"
2308
2309         copytool_cleanup
2310 }
2311 run_test 111a "No retry policy (import case), restore will error"\
2312               " (No such file or directory)"
2313
2314 test_111b() {
2315         # test needs a running copytool
2316         copytool_setup
2317
2318         mkdir -p $DIR/$tdir
2319         local f=$DIR/$tdir/$tfile
2320         local fid=$(copy_file /etc/passwd $f)
2321         cdt_set_no_retry
2322         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2323         wait_request_state $fid ARCHIVE SUCCEED
2324         $LFS hsm_release $f
2325
2326         copytool_remove_backend $fid
2327
2328         $LFS hsm_restore $f
2329         wait_request_state $fid RESTORE FAILED
2330         local st=$?
2331
2332         # cleanup
2333         cdt_clear_no_retry
2334
2335         # Test result
2336         [[ $st == 0 ]] || error "Restore does not failed"
2337
2338         copytool_cleanup
2339 }
2340 run_test 111b "No retry policy (release case), restore will error"\
2341               " (No such file or directory)"
2342
2343 test_112() {
2344         # test needs a running copytool
2345         copytool_setup
2346
2347         mkdir -p $DIR/$tdir
2348         local f=$DIR/$tdir/$tfile
2349         local fid=$(copy_file /etc/passwd $f)
2350         cdt_disable
2351         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2352         local l=$($LFS hsm_action $f)
2353         echo $l
2354         local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2355
2356         # cleanup
2357         cdt_enable
2358         wait_request_state $fid ARCHIVE SUCCEED
2359
2360         # Test result
2361         [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2362
2363         copytool_cleanup
2364 }
2365 run_test 112 "State of recorded request"
2366
2367 test_200() {
2368         # test needs a running copytool
2369         copytool_setup
2370
2371         mkdir -p $DIR/$tdir
2372         local f=$DIR/$tdir/$tfile
2373         local fid=$(make_large_for_cancel $f)
2374         # test with cdt on is made in test_221
2375         cdt_disable
2376         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2377         $LFS hsm_cancel $f
2378         cdt_enable
2379         wait_request_state $fid ARCHIVE CANCELED
2380         wait_request_state $fid CANCEL SUCCEED
2381
2382         copytool_cleanup
2383 }
2384 run_test 200 "Register/Cancel archive"
2385
2386 test_201() {
2387         # test needs a running copytool
2388         copytool_setup
2389
2390         mkdir -p $DIR/$tdir
2391         local f=$DIR/$tdir/$tfile
2392         make_archive $tdir/$tfile
2393         import_file $tdir/$tfile $f
2394         local fid=$(path2fid $f)
2395
2396         # test with cdt on is made in test_222
2397         cdt_disable
2398         $LFS hsm_restore $f
2399         $LFS hsm_cancel $f
2400         cdt_enable
2401         wait_request_state $fid RESTORE CANCELED
2402         wait_request_state $fid CANCEL SUCCEED
2403
2404         copytool_cleanup
2405 }
2406 run_test 201 "Register/Cancel restore"
2407
2408 test_202() {
2409         # test needs a running copytool
2410         copytool_setup
2411
2412         mkdir -p $DIR/$tdir
2413         local f=$DIR/$tdir/$tfile
2414         local fid=$(make_large_for_progress $f)
2415         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2416         wait_request_state $fid ARCHIVE SUCCEED
2417
2418         cdt_disable
2419         $LFS hsm_remove $f
2420         $LFS hsm_cancel $f
2421         cdt_enable
2422         wait_request_state $fid REMOVE CANCELED
2423
2424         copytool_cleanup
2425 }
2426 run_test 202 "Register/Cancel remove"
2427
2428 test_220() {
2429         # test needs a running copytool
2430         copytool_setup
2431
2432         mkdir -p $DIR/$tdir
2433
2434         local f=$DIR/$tdir/$tfile
2435         local fid=$(copy_file /etc/passwd $f)
2436
2437         changelog_setup
2438
2439         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2440         wait_request_state $fid ARCHIVE SUCCEED
2441
2442         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2443         changelog_cleanup
2444
2445         local target=0x0
2446         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2447
2448         copytool_cleanup
2449 }
2450 run_test 220 "Changelog for archive"
2451
2452 test_221() {
2453         # test needs a running copytool
2454         copytool_setup
2455
2456         mkdir -p $DIR/$tdir
2457
2458         local f=$DIR/$tdir/$tfile
2459         local fid=$(make_large_for_cancel $f)
2460
2461         changelog_setup
2462
2463         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2464         wait_request_state $fid ARCHIVE STARTED
2465         $LFS hsm_cancel $f
2466         wait_request_state $fid ARCHIVE CANCELED
2467         wait_request_state $fid CANCEL SUCCEED
2468
2469         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2470
2471         local target=0x7d
2472         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2473
2474         cleanup
2475 }
2476 run_test 221 "Changelog for archive canceled"
2477
2478 test_222a() {
2479         # test needs a running copytool
2480         copytool_setup
2481
2482         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2483         local f=$DIR/$tdir/$tfile
2484         cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2485         import_file $tdir/$tfile $f
2486         local fid=$(path2fid $f)
2487
2488         changelog_setup
2489
2490         $LFS hsm_restore $f
2491         wait_request_state $fid RESTORE SUCCEED
2492
2493         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2494
2495         local target=0x80
2496         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2497
2498         cleanup
2499 }
2500 run_test 222a "Changelog for explicit restore"
2501
2502 test_222b() {
2503         # test needs a running copytool
2504         copytool_setup
2505
2506         mkdir -p $DIR/$tdir
2507         local f=$DIR/$tdir/$tfile
2508         local fid=$(copy_file /etc/passwd $f)
2509
2510         changelog_setup
2511         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2512         wait_request_state $fid ARCHIVE SUCCEED
2513         $LFS hsm_release $f
2514
2515         md5sum $f
2516
2517         wait_request_state $fid RESTORE SUCCEED
2518
2519         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2520
2521         local target=0x80
2522         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2523
2524         cleanup
2525 }
2526 run_test 222b "Changelog for implicit restore"
2527
2528 test_223a() {
2529         # test needs a running copytool
2530         copytool_setup
2531
2532         mkdir -p $DIR/$tdir
2533
2534         local f=$DIR/$tdir/$tfile
2535         make_archive $tdir/$tfile
2536
2537         changelog_setup
2538
2539         import_file $tdir/$tfile $f
2540         local fid=$(path2fid $f)
2541
2542         $LFS hsm_restore $f
2543         wait_request_state $fid RESTORE STARTED
2544         $LFS hsm_cancel $f
2545         wait_request_state $fid RESTORE CANCELED
2546         wait_request_state $fid CANCEL SUCCEED
2547
2548         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2549
2550         local target=0xfd
2551         [[ $flags == $target ]] ||
2552                 error "Changelog flag is $flags not $target"
2553
2554         cleanup
2555 }
2556 run_test 223a "Changelog for restore canceled (import case)"
2557
2558 test_223b() {
2559         # test needs a running copytool
2560         copytool_setup
2561
2562         mkdir -p $DIR/$tdir
2563
2564         local f=$DIR/$tdir/$tfile
2565         local fid=$(make_large_for_progress $f)
2566
2567         changelog_setup
2568         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2569         wait_request_state $fid ARCHIVE SUCCEED
2570         $LFS hsm_release $f
2571         $LFS hsm_restore $f
2572         wait_request_state $fid RESTORE STARTED
2573         $LFS hsm_cancel $f
2574         wait_request_state $fid RESTORE CANCELED
2575         wait_request_state $fid CANCEL SUCCEED
2576
2577         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2578
2579         local target=0xfd
2580         [[ $flags == $target ]] ||
2581                 error "Changelog flag is $flags not $target"
2582
2583         cleanup
2584 }
2585 run_test 223b "Changelog for restore canceled (release case)"
2586
2587 test_224() {
2588         # test needs a running copytool
2589         copytool_setup
2590
2591         mkdir -p $DIR/$tdir
2592
2593         local f=$DIR/$tdir/$tfile
2594         local fid=$(copy_file /etc/passwd $f)
2595
2596         changelog_setup
2597         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2598         wait_request_state $fid ARCHIVE SUCCEED
2599
2600         $LFS hsm_remove $f
2601         wait_request_state $fid REMOVE SUCCEED
2602
2603         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2604
2605         local target=0x200
2606         [[ $flags == $target ]] ||
2607                 error "Changelog flag is $flags not $target"
2608
2609         cleanup
2610 }
2611 run_test 224 "Changelog for remove"
2612
2613 test_225() {
2614         # test needs a running copytool
2615         copytool_setup
2616
2617         # test is not usable because remove request is too fast
2618         # so it is always finished before cancel can be done ...
2619         echo "Test disabled"
2620         copytool_cleanup
2621         return 0
2622
2623         mkdir -p $DIR/$tdir
2624         local f=$DIR/$tdir/$tfile
2625         local fid=$(make_large_for_progress $f)
2626
2627         changelog_setup
2628         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2629         wait_request_state $fid ARCHIVE SUCCEED
2630
2631         # if cdt is on, it can serve too quickly the request
2632         cdt_disable
2633         $LFS hsm_remove $f
2634         $LFS hsm_cancel $f
2635         cdt_enable
2636         wait_request_state $fid REMOVE CANCELED
2637         wait_request_state $fid CANCEL SUCCEED
2638
2639         flags=$(changelog_get_flags $MDT0 RENME $fid2)
2640         local flags=$($LFS changelog $MDT0 | grep HSM | grep $fid | tail -1 |
2641                 awk '{print $5}')
2642
2643         local target=0x27d
2644         [[ $flags == $target ]] ||
2645                 error "Changelog flag is $flags not $target"
2646
2647         cleanup
2648 }
2649 run_test 225 "Changelog for remove canceled"
2650
2651 test_226() {
2652         # test needs a running copytool
2653         copytool_setup
2654
2655         mkdir -p $DIR/$tdir
2656
2657         local f1=$DIR/$tdir/$tfile-1
2658         local f2=$DIR/$tdir/$tfile-2
2659         local f3=$DIR/$tdir/$tfile-3
2660         local fid1=$(copy_file /etc/passwd $f1)
2661         local fid2=$(copy_file /etc/passwd $f2)
2662         copy_file /etc/passwd $f3
2663
2664         changelog_setup
2665         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2666         wait_request_state $fid1 ARCHIVE SUCCEED
2667
2668         $LFS hsm_archive $f2
2669         wait_request_state $fid2 ARCHIVE SUCCEED
2670
2671         rm $f1 || error "rm $f1 failed"
2672
2673         local flags=$(changelog_get_flags $MDT0 UNLNK $fid1)
2674
2675         local target=0x3
2676         [[ $flags == $target ]] ||
2677                 error "Changelog flag is $flags not $target"
2678
2679         mv $f3 $f2 || error "mv $f3 $f2 failed"
2680
2681         flags=$(changelog_get_flags $MDT0 RENME $fid2)
2682
2683         target=0x3
2684         [[ $flags == $target ]] ||
2685                 error "Changelog flag is $flags not $target"
2686
2687         cleanup
2688 }
2689 run_test 226 "changelog for last rm/mv with exiting archive"
2690
2691 check_flags_changes() {
2692         local f=$1
2693         local fid=$2
2694         local hsm_flag=$3
2695         local fst=$4
2696         local cnt=$5
2697
2698         local target=0x280
2699         $LFS hsm_set --$hsm_flag $f ||
2700                 error "Cannot set $hsm_flag on $f"
2701         local flags=($(changelog_get_flags $MDT0 HSM $fid))
2702         local seen=${#flags[*]}
2703         cnt=$((fst + cnt))
2704         [[ $seen == $cnt ]] ||
2705                 error "set $hsm_flag: Changelog events $seen != $cnt"
2706         [[ ${flags[$((cnt - 1))]} == $target ]] ||
2707                 error "set $hsm_flag: Changelog flags are "\
2708                         "${flags[$((cnt - 1))]} not $target"
2709
2710         $LFS hsm_clear --$hsm_flag $f ||
2711                 error "Cannot clear $hsm_flag on $f"
2712         flags=($(changelog_get_flags $MDT0 HSM $fid))
2713         seen=${#flags[*]}
2714         cnt=$(($cnt + 1))
2715         [[ $cnt == $seen ]] ||
2716                 error "clear $hsm_flag: Changelog events $seen != $cnt"
2717
2718         [[ ${flags[$((cnt - 1))]} == $target ]] ||
2719                 error "clear $hsm_flag: Changelog flag is "\
2720                         "${flags[$((cnt - 1))]} not $target"
2721 }
2722
2723 test_227() {
2724         # test needs a running copytool
2725         copytool_setup
2726         changelog_setup
2727
2728         mkdir -p $DIR/$tdir
2729         typeset -a flags
2730
2731         for i in norelease noarchive exists archived
2732         do
2733                 local f=$DIR/$tdir/$tfile-$i
2734                 local fid=$(copy_file /etc/passwd $f)
2735                 check_flags_changes $f $fid $i 0 1
2736         done
2737
2738         f=$DIR/$tdir/$tfile---lost
2739         fid=$(copy_file /etc/passwd $f)
2740         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2741         wait_request_state $fid ARCHIVE SUCCEED
2742         check_flags_changes $f $fid lost 3 1
2743
2744         cleanup
2745 }
2746 run_test 227 "changelog when explicit setting of HSM flags"
2747
2748 test_250() {
2749         # test needs a running copytool
2750         copytool_setup
2751
2752         mkdir -p $DIR/$tdir
2753         local maxrequest=$(get_hsm_param max_requests)
2754         local rqcnt=$(($maxrequest * 3))
2755         local i=""
2756
2757         cdt_disable
2758         for i in $(seq -w 1 $rqcnt); do
2759                 rm -f $DIR/$tdir/$i
2760                 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
2761         done
2762         # we do it in 2 steps, so all requests arrive at the same time
2763         for i in $(seq -w 1 $rqcnt); do
2764                 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
2765         done
2766         cdt_enable
2767         local cnt=$rqcnt
2768         local wt=$rqcnt
2769         while [[ $cnt != 0 || $wt != 0 ]]; do
2770                 sleep 1
2771                 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2772                         $HSM_PARAM.agent_actions |\
2773                         grep STARTED | grep -v CANCEL | wc -l")
2774                 [[ $cnt -le $maxrequest ]] ||
2775                         error "$cnt > $maxrequest too many started requests"
2776                 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
2777                         $HSM_PARAM.agent_actions |\
2778                         grep WAITING | wc -l")
2779                 echo "max=$maxrequest started=$cnt waiting=$wt"
2780         done
2781
2782         copytool_cleanup
2783 }
2784 run_test 250 "Coordinator max request"
2785
2786 test_251() {
2787         # test needs a running copytool
2788         copytool_setup
2789
2790         mkdir -p $DIR/$tdir
2791         local f=$DIR/$tdir/$tfile
2792         local fid=$(make_large_for_cancel $f)
2793
2794         cdt_disable
2795         # to have a short test
2796         local old_to=$(get_hsm_param request_timeout)
2797         set_hsm_param request_timeout 4
2798         # to be sure the cdt will wake up frequently so
2799         # it will be able to cancel the "old" request
2800         local old_loop=$(get_hsm_param loop_period)
2801         set_hsm_param loop_period 2
2802         cdt_enable
2803
2804         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2805         wait_request_state $fid ARCHIVE STARTED
2806         sleep 5
2807         wait_request_state $fid ARCHIVE CANCELED
2808
2809         set_hsm_param request_timeout $old_to
2810         set_hsm_param loop_period $old_loop
2811
2812         copytool_cleanup
2813 }
2814 run_test 251 "Coordinator request timeout"
2815
2816 test_300() {
2817         # the only way to test ondisk conf is to restart MDS ...
2818         echo "Stop coordinator and remove coordinator state at mount"
2819         # stop coordinator
2820         cdt_shutdown
2821         # clean on disk conf set by default
2822         cdt_clear_mount_state
2823         cdt_check_state stopped
2824
2825         # check cdt still off after umount/remount
2826         fail $SINGLEMDS
2827         cdt_check_state stopped
2828
2829         echo "Set coordinator start at mount, and start coordinator"
2830         cdt_set_mount_state enabled
2831
2832         # check cdt is on
2833         cdt_check_state enabled
2834
2835         # check cdt still on after umount/remount
2836         fail $SINGLEMDS
2837         cdt_check_state enabled
2838
2839         # we are back to original state (cdt started at mount)
2840 }
2841 run_test 300 "On disk coordinator state kept between MDT umount/mount"
2842
2843 copytool_cleanup
2844
2845 complete $SECONDS
2846 check_and_cleanup_lustre
2847 exit_status