Whamcloud - gitweb
LU-3711 mdt: default archive id is tunable
[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_10d() {
755         # test needs a running copytool
756         copytool_setup
757
758         mkdir -p $DIR/$tdir
759         local f=$DIR/$tdir/$tfile
760         local fid=$(copy_file /etc/hosts $f)
761         $LFS hsm_archive $f || error "cannot archive $f"
762         wait_request_state $fid ARCHIVE SUCCEED
763
764         local ar=$(get_hsm_archive_id $f)
765         local dflt=$(get_hsm_param archive_id)
766         [[ $ar == $dflt ]] ||
767                 error "archived file is not on default archive: $ar != $dflt"
768
769         copytool_cleanup
770 }
771 run_test 10d "Archive a file on the default archive id"
772
773 test_11() {
774         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
775         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
776         local f=$DIR/$tdir/$tfile
777
778         import_file $tdir/$tfile $f
779         echo -n "Verifying released state: "
780         check_hsm_flags $f "0x0000000d"
781
782         local LSZ=$(stat -c "%s" $f)
783         local ASZ=$(stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
784
785         echo "Verifying imported size $LSZ=$ASZ"
786         [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
787         echo -n "Verifying released pattern: "
788         local PTRN=$($GETSTRIPE -L $f)
789         echo $PTRN
790         [[ $PTRN == 80000001 ]] || error "Is not released"
791         local fid=$(path2fid $f)
792         echo "Verifying new fid $fid in archive"
793
794         local AFILE=$(ls $HSM_ARCHIVE/*/*/*/*/*/*/$fid) ||
795                 error "fid $fid not in archive $HSM_ARCHIVE"
796 }
797 run_test 11 "Import a file"
798
799 test_12a() {
800         # test needs a running copytool
801         copytool_setup
802
803         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
804         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
805         local f=$DIR/$tdir/$tfile
806         import_file $tdir/$tfile $f
807         local f=$DIR2/$tdir/$tfile
808         echo "Verifying released state: "
809         check_hsm_flags $f "0x0000000d"
810
811         local fid=$(path2fid $f)
812         $LFS hsm_restore $f
813         wait_request_state $fid RESTORE SUCCEED
814
815         echo "Verifying file state: "
816         check_hsm_flags $f "0x00000009"
817
818         diff -q $HSM_ARCHIVE/$tdir/$tfile $f
819
820         [[ $? -eq 0 ]] || error "Restored file differs"
821
822         copytool_cleanup
823 }
824 run_test 12a "Restore an imported file explicitly"
825
826 test_12b() {
827         # test needs a running copytool
828         copytool_setup
829
830         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
831         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
832         local f=$DIR/$tdir/$tfile
833         import_file $tdir/$tfile $f
834         echo "Verifying released state: "
835         check_hsm_flags $f "0x0000000d"
836
837         cat $f > /dev/null || error "File read failed"
838
839         echo "Verifying file state after restore: "
840         check_hsm_flags $f "0x00000009"
841
842         diff -q $HSM_ARCHIVE/$tdir/$tfile $f
843
844         [[ $? -eq 0 ]] || error "Restored file differs"
845
846         copytool_cleanup
847 }
848 run_test 12b "Restore an imported file implicitly"
849
850 test_12c() {
851         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
852
853         # test needs a running copytool
854         copytool_setup
855
856         mkdir -p $DIR/$tdir
857         local f=$DIR/$tdir/$tfile
858         $LFS setstripe -c 2 $f
859         local fid=$(make_large_for_striping $f)
860         local FILE_CRC=$(md5sum $f)
861
862         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
863         wait_request_state $fid ARCHIVE SUCCEED
864         $LFS hsm_release $f || error "release $f failed"
865
866         echo "$FILE_CRC" | md5sum -c
867
868         [[ $? -eq 0 ]] || error "Restored file differs"
869
870         copytool_cleanup
871 }
872 run_test 12c "Restore a file with stripe of 2"
873
874 test_12d() {
875         # test needs a running copytool
876         copytool_setup
877
878         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
879         local f=$DIR/$tdir/$tfile
880         local fid=$(copy_file /etc/hosts $f)
881         $LFS hsm_restore $f || error "restore of non archived file failed"
882         local cnt=$(get_request_count $fid RESTORE)
883         [[ "$cnt" == "0" ]] ||
884                 error "restore non archived must not make a request"
885         $LFS hsm_archive $f ||
886                 error "archive request failed"
887         wait_request_state $fid ARCHIVE SUCCEED
888         $LFS hsm_restore $f ||
889                 error "restore of non released file failed"
890         local cnt=$(get_request_count $fid RESTORE)
891         [[ "$cnt" == "0" ]] ||
892                 error "restore a non dirty file must not make a request"
893
894         copytool_cleanup
895 }
896 run_test 12d "Restore of a non archived, non released file must work"\
897                 " without doing request"
898
899 test_12e() {
900         # test needs a running copytool
901         copytool_setup
902
903         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
904         local f=$DIR/$tdir/$tfile
905         local fid=$(copy_file /etc/hosts $f)
906         $LFS hsm_archive $f || error "archive request failed"
907         wait_request_state $fid ARCHIVE SUCCEED
908
909         # make file dirty
910         cat /etc/hosts >> $f
911         sync
912         $LFS hsm_state $f
913
914         $LFS hsm_restore $f && error "restore a dirty file must fail"
915
916         copytool_cleanup
917 }
918 run_test 12e "Check forbidden restore"
919
920 test_12f() {
921         # test needs a running copytool
922         copytool_setup
923
924         mkdir -p $DIR/$tdir
925         local f=$DIR/$tdir/$tfile
926         local fid=$(copy_file /etc/hosts $f)
927
928         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
929         wait_request_state $fid ARCHIVE SUCCEED
930         $LFS hsm_release $f || error "release of $f failed"
931         $LFS hsm_restore $f
932         wait_request_state $fid RESTORE SUCCEED
933
934         echo -n "Verifying file state: "
935         check_hsm_flags $f "0x00000009"
936
937         diff -q /etc/hosts $f
938
939         [[ $? -eq 0 ]] || error "Restored file differs"
940
941         copytool_cleanup
942 }
943 run_test 12f "Restore a released file explicitly"
944
945 test_12g() {
946         # test needs a running copytool
947         copytool_setup
948
949         mkdir -p $DIR/$tdir
950         local f=$DIR/$tdir/$tfile
951         local fid=$(copy_file /etc/hosts $f)
952
953         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
954         wait_request_state $fid ARCHIVE SUCCEED
955         $LFS hsm_release $f || error "release of $f failed"
956
957         diff -q /etc/hosts $f
958         local st=$?
959
960         # we check we had a restore done
961         wait_request_state $fid RESTORE SUCCEED
962
963         [[ $st -eq 0 ]] || error "Restored file differs"
964
965         copytool_cleanup
966 }
967 run_test 12g "Restore a released file implicitly"
968
969 test_12h() {
970         need2clients || return 0
971
972         # test needs a running copytool
973         copytool_setup
974
975         mkdir -p $DIR/$tdir
976         local f=$DIR/$tdir/$tfile
977         local fid=$(copy_file /etc/hosts $f)
978
979         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
980         wait_request_state $fid ARCHIVE SUCCEED
981         $LFS hsm_release $f || error "release of $f failed"
982
983         do_node $CLIENT2 diff -q /etc/hosts $f
984         local st=$?
985
986         # we check we had a restore done
987         wait_request_state $fid RESTORE SUCCEED
988
989         [[ $st -eq 0 ]] || error "Restored file differs"
990
991         copytool_cleanup
992 }
993 run_test 12h "Restore a released file implicitly from a second node"
994
995 test_12m() {
996         # test needs a running copytool
997         copytool_setup
998
999         mkdir -p $DIR/$tdir
1000         local f=$DIR/$tdir/$tfile
1001         local fid=$(copy_file /etc/passwd $f)
1002         $LFS hsm_archive $f || error "archive of $f failed"
1003         wait_request_state $fid ARCHIVE SUCCEED
1004
1005         $LFS hsm_release $f || error "release of $f failed"
1006
1007         cmp /etc/passwd $f
1008
1009         [[ $? -eq 0 ]] || error "Restored file differs"
1010
1011         copytool_cleanup
1012 }
1013 run_test 12m "Archive/release/implicit restore"
1014
1015 test_12n() {
1016         # test needs a running copytool
1017         copytool_setup
1018
1019         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1020         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
1021         local f=$DIR/$tdir/$tfile
1022         import_file $tdir/$tfile $f
1023
1024         cmp /etc/hosts $f || error "Restored file differs"
1025
1026         $LFS hsm_release $f || error "release of $f failed"
1027
1028         copytool_cleanup
1029 }
1030 run_test 12n "Import/implicit restore/release"
1031
1032 test_13() {
1033         # test needs a running copytool
1034         copytool_setup
1035
1036         local ARC_SUBDIR="import.orig"
1037         local d=""
1038         local f=""
1039
1040         # populate directory to be imported
1041         for d in $(seq 1 10); do
1042                 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1043                 mkdir -p "$CURR_DIR"
1044                 for f in $(seq 1 10); do
1045                         CURR_FILE="$CURR_DIR/$tfile.$f"
1046                         # write file-specific data
1047                         echo "d=$d, f=$f, dir=$CURR_DIR, file=$CURR_FILE"\
1048                                 > $CURR_FILE
1049                 done
1050         done
1051         # import to Lustre
1052         import_file "$ARC_SUBDIR" $DIR/$tdir
1053         # diff lustre content and origin (triggers file restoration)
1054         # there must be 10x10 identical files, and no difference
1055         local cnt_ok=$(diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1056                        $DIR/$tdir/$ARC_SUBDIR |
1057                 grep identical | wc -l)
1058         local cnt_diff=$(diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1059                          $DIR/$tdir/$ARC_SUBDIR |
1060                 wc -l)
1061
1062         [ $cnt_diff -eq 0 ] ||
1063                 error "$cnt_diff imported files differ from read data"
1064         [ $cnt_ok -eq 100 ] ||
1065                 error "not enough identical files ($cnt_ok != 100)"
1066
1067         copytool_cleanup
1068 }
1069 run_test 13 "Recursively import and restore a directory"
1070
1071 test_14() {
1072         # test needs a running copytool
1073         copytool_setup
1074
1075         # archive a file
1076         mkdir -p $DIR/$tdir
1077         local f=$DIR/$tdir/$tfile
1078         local fid=$(make_small $f)
1079         local sum=$(md5sum $f | awk '{print $1}')
1080         $LFS hsm_archive $f || error "could not archive file"
1081         wait_request_state $fid ARCHIVE SUCCEED
1082
1083         # delete the file
1084         rm -f $f
1085         # create released file (simulate llapi_hsm_import call)
1086         touch $f
1087         local fid2=$(path2fid $f)
1088         $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1089         $LFS hsm_release $f || error "could not release file"
1090
1091         # rebind the archive to the newly created file
1092         echo "rebind $fid to $fid2"
1093
1094         do_facet $SINGLEAGT \
1095                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1096                  --rebind $fid $fid2 $DIR" || error "could not rebind file"
1097
1098         # restore file and compare md5sum
1099         local sum2=$(md5sum $f | awk '{print $1}')
1100
1101         [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1102
1103         copytool_cleanup
1104 }
1105 run_test 14 "Rebind archived file to a new fid"
1106
1107 test_15() {
1108         # test needs a running copytool
1109         copytool_setup
1110
1111         # archive files
1112         mkdir -p $DIR/$tdir
1113         local f=$DIR/$tdir/$tfile
1114         local count=5
1115         local tmpfile=$SHARED_DIRECTORY/tmp.$$
1116
1117         local fids=()
1118         local sums=()
1119         for i in $(seq 1 $count); do
1120                 fids[$i]=$(make_small $f.$i)
1121                 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1122                 $LFS hsm_archive $f.$i || error "could not archive file"
1123         done
1124         wait_all_done $(($count*60))
1125
1126         :>$tmpfile
1127         # delete the files
1128         for i in $(seq 1 $count); do
1129                 rm -f $f.$i
1130                 touch $f.$i
1131                 local fid2=$(path2fid $f.$i)
1132                 # add the rebind operation to the list
1133                 echo ${fids[$i]} $fid2 >> $tmpfile
1134
1135                 # set it released (simulate llapi_hsm_import call)
1136                 $LFS hsm_set --archived --exists $f.$i ||
1137                         error "could not force hsm flags"
1138                 $LFS hsm_release $f.$i || error "could not release file"
1139         done
1140         nl=$(wc -l < $tmpfile)
1141         [[ $nl == $count ]] || error "$nl files in list, $count expected"
1142
1143         echo "rebind list of files"
1144         do_facet $SINGLEAGT \
1145                 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1146                  --rebind $tmpfile $DIR" || error "could not rebind file list"
1147
1148         # restore files and compare md5sum
1149         for i in $(seq 1 $count); do
1150                 local sum2=$(md5sum $f.$i | awk '{print $1}')
1151                 [[ $sum2 == ${sums[$i]} ]] ||
1152                     error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1153         done
1154
1155         rm -f $tmpfile
1156         copytool_cleanup
1157 }
1158 run_test 15 "Rebind a list of files"
1159
1160 test_16() {
1161         # test needs a running copytool
1162         copytool_setup
1163
1164         local ref=/tmp/ref
1165         # create a known size file so we can verify transfer speed
1166         # 20 MB <-> 20s
1167         local goal=20
1168         dd if=/dev/zero of=$ref bs=1M count=20
1169
1170         mkdir -p $DIR/$tdir
1171         local f=$DIR/$tdir/$tfile
1172         local fid=$(copy_file $ref $f)
1173         rm $ref
1174         local start=$(date +%s)
1175         $LFS hsm_archive $f
1176         wait_request_state $fid ARCHIVE SUCCEED
1177         local end=$(date +%s)
1178         local duration=$((end - start))
1179
1180         [[ $duration -ge $goal ]] ||
1181                 error "Transfer is too fast $duration < $goal"
1182
1183         copytool_cleanup
1184 }
1185 run_test 16 "Test CT bandwith control option"
1186
1187 test_20() {
1188         mkdir -p $DIR/$tdir
1189
1190         local f=$DIR/$tdir/$tfile
1191         touch $f || error "touch $f failed"
1192
1193         # Could not release a non-archived file
1194         $LFS hsm_release $f && error "release should not succeed"
1195
1196         # For following tests, we must test them with HS_ARCHIVED set
1197         $LFS hsm_set --exists --archived $f || error "could not add flag"
1198
1199         # Could not release a file if no-release is set
1200         $LFS hsm_set --norelease $f || error "could not add flag"
1201         $LFS hsm_release $f && error "release should not succeed"
1202         $LFS hsm_clear --norelease $f || error "could not remove flag"
1203
1204         # Could not release a file if lost
1205         $LFS hsm_set --lost $f || error "could not add flag"
1206         $LFS hsm_release $f && error "release should not succeed"
1207         $LFS hsm_clear --lost $f || error "could not remove flag"
1208
1209         # Could not release a file if dirty
1210         $LFS hsm_set --dirty $f || error "could not add flag"
1211         $LFS hsm_release $f && error "release should not succeed"
1212         $LFS hsm_clear --dirty $f || error "could not remove flag"
1213 }
1214 run_test 20 "Release is not permitted"
1215
1216 test_21() {
1217         # test needs a running copytool
1218         copytool_setup
1219
1220         mkdir -p $DIR/$tdir
1221         local f=$DIR/$tdir/test_release
1222
1223         # Create a file and check its states
1224         local fid=$(make_small $f)
1225         check_hsm_flags $f "0x00000000"
1226
1227         $LFS hsm_archive $f || error "could not archive file"
1228         wait_request_state $fid ARCHIVE SUCCEED
1229
1230         [ $(stat -c "%b" $f) -ne "0" ] || error "wrong block number"
1231         local sz=$(stat -c "%s" $f)
1232         [ $sz -ne "0" ] || error "file size should not be zero"
1233
1234         # Release and check states
1235         $LFS hsm_release $f || error "could not release file"
1236         check_hsm_flags $f "0x0000000d"
1237
1238         [ $(stat -c "%b" $f) -eq "0" ] || error "wrong block number"
1239         [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1240
1241         # Check we can release an file without stripe info
1242         f=$f.nolov
1243         $MCREATE $f
1244         fid=$(path2fid $f)
1245         check_hsm_flags $f "0x00000000"
1246         $LFS hsm_archive $f || error "could not archive file"
1247         wait_request_state $fid ARCHIVE SUCCEED
1248
1249         # Release and check states
1250         $LFS hsm_release $f || error "could not release file"
1251         check_hsm_flags $f "0x0000000d"
1252
1253         # Release again a file that is already released is OK
1254         $LFS hsm_release $f || fail "second release should succeed"
1255         check_hsm_flags $f "0x0000000d"
1256
1257         copytool_cleanup
1258 }
1259 run_test 21 "Simple release tests"
1260
1261 test_22() {
1262         # test needs a running copytool
1263         copytool_setup
1264
1265         mkdir -p $DIR/$tdir
1266
1267         local f=$DIR/$tdir/test_release
1268         local swap=$DIR/$tdir/test_swap
1269
1270         # Create a file and check its states
1271         local fid=$(make_small $f)
1272         check_hsm_flags $f "0x00000000"
1273
1274         $LFS hsm_archive $f || error "could not archive file"
1275         wait_request_state $fid ARCHIVE SUCCEED
1276
1277         # Release and check states
1278         $LFS hsm_release $f || error "could not release file"
1279         check_hsm_flags $f "0x0000000d"
1280
1281         make_small $swap
1282         $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1283
1284         true
1285         copytool_cleanup
1286 }
1287 run_test 22 "Could not swap a release file"
1288
1289 test_23() {
1290         # test needs a running copytool
1291         copytool_setup
1292
1293         mkdir -p $DIR/$tdir
1294
1295         local f=$DIR/$tdir/test_mtime
1296
1297         # Create a file and check its states
1298         local fid=$(make_small $f)
1299         check_hsm_flags $f "0x00000000"
1300
1301         $LFS hsm_archive $f || error "could not archive file"
1302         wait_request_state $fid ARCHIVE SUCCEED
1303
1304         # Set modification time in the past
1305         touch -m -a -d @978261179 $f
1306
1307         # Release and check states
1308         $LFS hsm_release $f || error "could not release file"
1309         check_hsm_flags $f "0x0000000d"
1310
1311         local MTIME=$(stat -c "%Y" $f)
1312         local ATIME=$(stat -c "%X" $f)
1313         [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1314         [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1315
1316         copytool_cleanup
1317 }
1318 run_test 23 "Release does not change a/mtime (utime)"
1319
1320 test_24() {
1321         # test needs a running copytool
1322         copytool_setup
1323
1324         mkdir -p $DIR/$tdir
1325
1326         local f=$DIR/$tdir/test_mtime
1327
1328         # Create a file and check its states
1329         local fid=$(make_small $f)
1330         check_hsm_flags $f "0x00000000"
1331
1332         # make mtime is different
1333         sleep 1
1334         echo "append" >> $f
1335         local MTIME=$(stat -c "%Y" $f)
1336         local ATIME=$(stat -c "%X" $f)
1337
1338         $LFS hsm_archive $f || error "could not archive file"
1339         wait_request_state $fid ARCHIVE SUCCEED
1340
1341         # Release and check states
1342         $LFS hsm_release $f || error "could not release file"
1343         check_hsm_flags $f "0x0000000d"
1344
1345         [ "$(stat -c "%Y" $f)" -eq "$MTIME" ] ||
1346                 error "mtime should be $MTIME"
1347
1348         [ "$(stat -c "%X" $f)" -eq "$ATIME" ] ||
1349                 error "atime should be $ATIME"
1350
1351         copytool_cleanup
1352 }
1353 run_test 24 "Release does not change a/mtime (i/o)"
1354
1355 test_25a() {
1356         # test needs a running copytool
1357         copytool_setup
1358
1359         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1360         cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
1361         local f=$DIR/$tdir/$tfile
1362
1363         import_file $tdir/$tfile $f
1364
1365         $LFS hsm_set --lost $f
1366
1367         md5sum $f
1368         local st=$?
1369
1370         [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1371
1372         copytool_cleanup
1373 }
1374 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1375              " (Operation not permitted)"
1376
1377 test_25b() {
1378         # test needs a running copytool
1379         copytool_setup
1380
1381         mkdir -p $DIR/$tdir
1382
1383         local f=$DIR/$tdir/$tfile
1384         local fid=$(copy_file /etc/passwd $f)
1385
1386         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1387         wait_request_state $fid ARCHIVE SUCCEED
1388
1389         $LFS hsm_release $f
1390         $LFS hsm_set --lost $f
1391         md5sum $f
1392         st=$?
1393
1394         [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1395
1396         copytool_cleanup
1397 }
1398 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1399              " (Operation not permitted)"
1400
1401 test_26() {
1402         # test needs a running copytool
1403         copytool_setup
1404
1405         mkdir -p $DIR/$tdir
1406         local f=$DIR/$tdir/$tfile
1407         local fid=$(make_large_for_progress $f)
1408         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1409         wait_request_state $fid ARCHIVE SUCCEED
1410
1411         $LFS hsm_remove $f
1412         wait_request_state $fid REMOVE SUCCEED
1413
1414         check_hsm_flags $f "0x00000000"
1415
1416         copytool_cleanup
1417 }
1418 run_test 26 "Remove the archive of a valid file"
1419
1420 test_27a() {
1421         # test needs a running copytool
1422         copytool_setup
1423
1424         mkdir -p $DIR/$tdir
1425         make_archive $tdir/$tfile
1426         local f=$DIR/$tdir/$tfile
1427         import_file $tdir/$tfile $f
1428         local fid=$(path2fid $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 27a "Remove the archive of an imported file (Operation not permitted)"
1437
1438 test_27b() {
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         $LFS hsm_release $f
1448
1449         $LFS hsm_remove $f
1450
1451         [[ $? != 0 ]] || error "Remove of a released file should fail"
1452
1453         copytool_cleanup
1454 }
1455 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1456
1457 test_28() {
1458         # test needs a running copytool
1459         copytool_setup
1460
1461         mkdir -p $DIR/$tdir
1462         local f=$DIR/$tdir/$tfile
1463         local fid=$(make_large_for_progress $f)
1464         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1465         wait_request_state $fid ARCHIVE SUCCEED
1466
1467         cdt_disable
1468         $LFS hsm_remove $f
1469
1470         rm -f $f
1471
1472         cdt_enable
1473
1474         wait_request_state $fid REMOVE SUCCEED
1475
1476         copytool_cleanup
1477 }
1478 run_test 28 "Concurrent archive/file remove"
1479
1480 test_30a() {
1481         # restore at exec cannot work on agent node (because of Linux kernel
1482         # protection of executables)
1483         need2clients || return 0
1484
1485         # test needs a running copytool
1486         copytool_setup
1487
1488         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1489         cp -p /bin/true $HSM_ARCHIVE/$tdir/$tfile
1490         local f=$DIR/$tdir/true
1491         import_file $tdir/$tfile $f
1492
1493         local fid=$(path2fid $f)
1494
1495         # set no retry action mode
1496         cdt_set_no_retry
1497         do_node $CLIENT2 $f
1498         local st=$?
1499
1500         # cleanup
1501         # remove no try action mode
1502         cdt_clear_no_retry
1503         $LFS hsm_state $f
1504
1505         [[ $st == 0 ]] || error "Failed to exec a released file"
1506
1507         copytool_cleanup
1508 }
1509 run_test 30a "Restore at exec (import case)"
1510
1511 test_30b() {
1512         # restore at exec cannot work on agent node (because of Linux kernel
1513         # protection of executables)
1514         need2clients || return 0
1515
1516         # test needs a running copytool
1517         copytool_setup
1518
1519         mkdir -p $DIR/$tdir
1520         local f=$DIR/$tdir/true
1521         local fid=$(copy_file /bin/true $f)
1522         chmod 755 $f
1523         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1524         wait_request_state $fid ARCHIVE SUCCEED
1525         $LFS hsm_release $f
1526         $LFS hsm_state $f
1527         # set no retry action mode
1528         cdt_set_no_retry
1529         do_node $CLIENT2 $f
1530         local st=$?
1531
1532         # cleanup
1533         # remove no try action mode
1534         cdt_clear_no_retry
1535         $LFS hsm_state $f
1536
1537         [[ $st == 0 ]] || error "Failed to exec a released file"
1538
1539         copytool_cleanup
1540 }
1541 run_test 30b "Restore at exec (release case)"
1542
1543 restore_and_check_size() {
1544         local f=$1
1545         local fid=$2
1546         local s=$(stat -c "%s" $f)
1547         local n=$s
1548         local st=$(get_hsm_flags $f)
1549         local err=0
1550         local cpt=0
1551         $LFS hsm_restore $f
1552         while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
1553         do
1554                 n=$(stat -c "%s" $f)
1555                 # we echo in both cases to show stat is not
1556                 # hang
1557                 if [[ $n != $s ]]
1558                 then
1559                         echo "size seen is $n != $s"
1560                         err=1
1561                 else
1562                         echo "size seen is right: $n == $s"
1563                 fi
1564                 st=$(get_hsm_flags $f)
1565                 sleep 10
1566                 cpt=$((cpt + 1))
1567         done
1568         if [[ $cpt -lt 10 ]]
1569         then
1570                 echo " restore is too long"
1571         else
1572                 echo " "done
1573         fi
1574         wait_request_state $fid RESTORE SUCCEED
1575         return $err
1576 }
1577
1578 test_31a() {
1579         # test needs a running copytool
1580         copytool_setup
1581
1582         mkdir -p $DIR/$tdir
1583
1584         make_archive $tdir/$tfile
1585         local f=$DIR/$tdir/$tfile
1586         import_file $tdir/$tfile $f
1587         local fid=$($LFS path2fid $f)
1588         HSM_ARCHIVE_PURGE=false copytool_setup
1589
1590         restore_and_check_size $f $fid
1591         local err=$?
1592
1593         [[ $err -eq 0 ]] || error "File size changed during restore"
1594
1595         copytool_cleanup
1596 }
1597 run_test 31a "Import a large file and check size during restore"
1598
1599
1600 test_31b() {
1601         # test needs a running copytool
1602         copytool_setup
1603
1604         mkdir -p $DIR/$tdir
1605
1606         local f=$DIR/$tdir/$tfile
1607         local fid=$(make_large_for_progress $f)
1608         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1609         wait_request_state $fid ARCHIVE SUCCEED
1610         $LFS hsm_release $f
1611
1612         restore_and_check_size $f $fid
1613         local err=$?
1614
1615         [[ $err -eq 0 ]] || error "File size changed during restore"
1616
1617         copytool_cleanup
1618 }
1619 run_test 31b "Restore a large unaligned file and check size during restore"
1620
1621 test_31c() {
1622         # test needs a running copytool
1623         copytool_setup
1624
1625         mkdir -p $DIR/$tdir
1626
1627         local f=$DIR/$tdir/$tfile
1628         local fid=$(make_large_for_progress_aligned $f)
1629         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1630         wait_request_state $fid ARCHIVE SUCCEED
1631         $LFS hsm_release $f
1632
1633         restore_and_check_size $f $fid
1634         local err=$?
1635
1636         [[ $err -eq 0 ]] || error "File size changed during restore"
1637
1638         copytool_cleanup
1639 }
1640 run_test 31c "Restore a large aligned file and check size during restore"
1641
1642 test_33() {
1643         # test needs a running copytool
1644         copytool_setup
1645
1646         mkdir -p $DIR/$tdir
1647
1648         local f=$DIR/$tdir/$tfile
1649         local fid=$(make_large_for_progress $f)
1650         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1651         wait_request_state $fid ARCHIVE SUCCEED
1652         $LFS hsm_release $f
1653
1654         md5sum $f >/dev/null &
1655         local pid=$!
1656         wait_request_state $fid RESTORE STARTED
1657
1658         kill -15 $pid
1659         sleep 1
1660
1661         # Check restore trigger process was killed
1662         local killed=$(ps -o pid,comm hp $pid >/dev/null)
1663
1664         $LFS hsm_cancel $f
1665
1666         wait_request_state $fid RESTORE CANCELED
1667         wait_request_state $fid CANCEL SUCCEED
1668
1669         [ -z $killed ] ||
1670                 error "Cannot kill process waiting for restore ($killed)"
1671
1672         copytool_cleanup
1673 }
1674 run_test 33 "Kill a restore waiting process"
1675
1676 test_34() {
1677         # test needs a running copytool
1678         copytool_setup
1679
1680         mkdir -p $DIR/$tdir
1681
1682         local f=$DIR/$tdir/$tfile
1683         local fid=$(make_large_for_progress $f)
1684         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1685         wait_request_state $fid ARCHIVE SUCCEED
1686         $LFS hsm_release $f
1687
1688         md5sum $f >/dev/null &
1689         local pid=$!
1690         wait_request_state $fid RESTORE STARTED
1691
1692         rm $f || error "rm $f failed"
1693         # rm must not block during restore
1694         wait_request_state $fid RESTORE STARTED
1695
1696         wait_request_state $fid RESTORE SUCCEED
1697         # check md5sum pgm finished
1698         local there=$(ps -o pid,comm hp $pid >/dev/null)
1699         [[ -z $there ]] || error "Restore initiator does not exit"
1700
1701         local rc=$(wait $pid)
1702         [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1703
1704         copytool_cleanup
1705 }
1706 run_test 34 "Remove file during restore"
1707
1708 test_35() {
1709         # test needs a running copytool
1710         copytool_setup
1711
1712         mkdir -p $DIR/$tdir
1713
1714         local f=$DIR/$tdir/$tfile
1715         local f1=$DIR/$tdir/$tfile-1
1716         local fid=$(make_large_for_progress $f)
1717         local fid1=$(copy_file /etc/passwd $f1)
1718         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1719         wait_request_state $fid ARCHIVE SUCCEED
1720         $LFS hsm_release $f
1721
1722         md5sum $f >/dev/null &
1723         local pid=$!
1724         wait_request_state $fid RESTORE STARTED
1725
1726         mv $f1 $f || error "mv $f1 $f failed"
1727         # mv must not block during restore
1728         wait_request_state $fid RESTORE STARTED
1729
1730         wait_request_state $fid RESTORE SUCCEED
1731         # check md5sum pgm finished
1732         local there=$(ps -o pid,comm hp $pid >/dev/null)
1733         [[ -z $there ]] || error "Restore initiator does not exit"
1734
1735         local rc=$(wait $pid)
1736         [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
1737
1738         fid2=$(path2fid $f)
1739         [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
1740
1741         copytool_cleanup
1742 }
1743 run_test 35 "Overwrite file during restore"
1744
1745 test_36() {
1746         # test needs a running copytool
1747         copytool_setup
1748
1749         mkdir -p $DIR/$tdir
1750
1751         local f=$DIR/$tdir/$tfile
1752         local fid=$(make_large_for_progress $f)
1753         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1754         wait_request_state $fid ARCHIVE SUCCEED
1755         $LFS hsm_release $f
1756
1757         md5sum $f >/dev/null &
1758         local pid=$!
1759         wait_request_state $fid RESTORE STARTED
1760
1761         mv $f $f.new
1762         # rm must not block during restore
1763         wait_request_state $fid RESTORE STARTED
1764
1765         wait_request_state $fid RESTORE SUCCEED
1766         # check md5sum pgm finished
1767         local there=$(ps -o pid,comm hp $pid >/dev/null)
1768         [[ -z $there ]] ||
1769                 error "Restore initiator does not exit"
1770
1771         local rc=$(wait $pid)
1772         [[ $rc -eq 0 ]] ||
1773                 error "Restore initiator failed with $rc"
1774
1775         copytool_cleanup
1776 }
1777 run_test 36 "Move file during restore"
1778
1779 multi_archive() {
1780         local prefix=$1
1781         local count=$2
1782         local n=""
1783
1784         for n in $(seq 1 $count); do
1785                 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
1786         done
1787         echo "$count archive requests submitted"
1788 }
1789
1790 test_40() {
1791         local stream_count=4
1792         local file_count=100
1793         mkdir -p $DIR/$tdir
1794         local f=$DIR/$tdir/$tfile
1795         local i=""
1796         local p=""
1797         local fid=""
1798
1799         for i in $(seq 1 $file_count); do
1800                 for p in $(seq 1 $stream_count); do
1801                         fid=$(copy_file /etc/hosts $f.$p.$i)
1802                 done
1803         done
1804         copytool_setup
1805         # to be sure wait_all_done will not be mislead by previous tests
1806         cdt_purge
1807         wait_for_grace_delay
1808         typeset -a pids
1809         # start archive streams in background (archive files in parallel)
1810         for p in $(seq 1 $stream_count); do
1811                 multi_archive $f.$p $file_count &
1812                 pids[$p]=$!
1813         done
1814         echo -n  "Wait for all requests being enqueued..."
1815         wait ${pids[*]}
1816         echo OK
1817         wait_all_done 100
1818         copytool_cleanup
1819 }
1820 run_test 40 "Parallel archive requests"
1821
1822 test_52() {
1823         # test needs a running copytool
1824         copytool_setup
1825
1826         mkdir -p $DIR/$tdir
1827         local f=$DIR/$tdir/$tfile
1828         local fid=$(copy_file /etc/motd $f 1)
1829
1830         $LFS hsm_archive $f || error "could not archive file"
1831         wait_request_state $fid ARCHIVE SUCCEED
1832         check_hsm_flags $f "0x00000009"
1833
1834         multiop_bg_pause $f O_c || error "multiop failed"
1835         local MULTIPID=$!
1836
1837         mds_evict_client
1838         client_up || client_up || true
1839
1840         kill -USR1 $MULTIPID
1841         wait $MULTIPID || error "multiop close failed"
1842
1843         check_hsm_flags $f "0x0000000b"
1844
1845         copytool_cleanup
1846 }
1847 run_test 52 "Opened for write file on an evicted client should be set dirty"
1848
1849 test_53() {
1850         # test needs a running copytool
1851         copytool_setup
1852
1853         mkdir -p $DIR/$tdir
1854         local f=$DIR/$tdir/$tfile
1855         local fid=$(copy_file /etc/motd $f 1)
1856
1857         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1858                 error "could not archive file"
1859         wait_request_state $fid ARCHIVE SUCCEED
1860         check_hsm_flags $f "0x00000009"
1861
1862         multiop_bg_pause $f o_c || error "multiop failed"
1863         MULTIPID=$!
1864
1865         mds_evict_client
1866         client_up || client_up || true
1867
1868         kill -USR1 $MULTIPID
1869         wait $MULTIPID || error "multiop close failed"
1870
1871         check_hsm_flags $f "0x00000009"
1872
1873         copytool_cleanup
1874 }
1875 run_test 53 "Opened for read file on an evicted client should not be set dirty"
1876
1877 test_54() {
1878         # test needs a running copytool
1879         copytool_setup
1880
1881         mkdir -p $DIR/$tdir
1882         local f=$DIR/$tdir/$tfile
1883         local fid=$(make_small $f)
1884
1885         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1886                 error "could not archive file"
1887         wait_request_state $fid ARCHIVE STARTED
1888
1889         check_hsm_flags $f "0x00000001"
1890
1891         # Avoid coordinator resending this request as soon it has failed.
1892         cdt_set_no_retry
1893
1894         echo "foo" >> $f
1895         sync
1896         wait_request_state $fid ARCHIVE FAILED
1897
1898         check_hsm_flags $f "0x00000003"
1899
1900         cdt_clear_no_retry
1901         copytool_cleanup
1902 }
1903 run_test 54 "Write during an archive cancels it"
1904
1905 test_55() {
1906         # test needs a running copytool
1907         copytool_setup
1908
1909         mkdir -p $DIR/$tdir
1910         local f=$DIR/$tdir/$tfile
1911         local fid=$(make_small $f)
1912
1913         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1914                 error "could not archive file"
1915         wait_request_state $fid ARCHIVE STARTED
1916
1917         check_hsm_flags $f "0x00000001"
1918
1919         # Avoid coordinator resending this request as soon it has failed.
1920         cdt_set_no_retry
1921
1922         $TRUNCATE $f 1024 || error "truncate failed"
1923         sync
1924         wait_request_state $fid ARCHIVE FAILED
1925
1926         check_hsm_flags $f "0x00000003"
1927
1928         cdt_clear_no_retry
1929         copytool_cleanup
1930 }
1931 run_test 55 "Truncate during an archive cancels it"
1932
1933 test_56() {
1934         # test needs a running copytool
1935         copytool_setup
1936
1937         mkdir -p $DIR/$tdir
1938         local f=$DIR/$tdir/$tfile
1939         local fid=$(make_large_for_progress $f)
1940
1941         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
1942                 error "could not archive file"
1943         wait_request_state $fid ARCHIVE STARTED
1944
1945         check_hsm_flags $f "0x00000001"
1946
1947         # Change metadata and sync to be sure we are not changing only
1948         # in memory.
1949         chmod 644 $f
1950         chgrp sys $f
1951         sync
1952         wait_request_state $fid ARCHIVE SUCCEED
1953
1954         check_hsm_flags $f "0x00000009"
1955
1956         copytool_cleanup
1957 }
1958 run_test 56 "Setattr during an archive is ok"
1959
1960 test_57() {
1961         # Need one client for I/O, one for request
1962         need2clients || return 0
1963
1964         # test needs a running copytool
1965         copytool_setup
1966
1967         mkdir -p $DIR/$tdir
1968         local f=$DIR/$tdir/test_archive_remote
1969         # Create a file on a remote node
1970         do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
1971                 "count=2 conv=fsync"
1972
1973         # And archive it
1974         do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
1975                 error "hsm_archive failed"
1976         local fid=$(path2fid $f)
1977         wait_request_state $fid ARCHIVE SUCCEED
1978
1979         # Release and implicit restore it
1980         do_node $CLIENT2 "$LFS hsm_release $f" ||
1981                 error "hsm_release failed"
1982         do_node $CLIENT2 "md5sum $f" ||
1983                 error "hsm_restore failed"
1984
1985         wait_request_state $fid RESTORE SUCCEED
1986
1987         copytool_cleanup
1988 }
1989 run_test 57 "Archive a file with dirty cache on another node"
1990
1991 test_58() {
1992         # test needs a running copytool
1993         copytool_setup
1994
1995         mkdir -p $DIR/$tdir
1996         local f=$DIR/$tdir/$tfile
1997         local fid=$(make_small $f)
1998
1999         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2000                 error "could not archive file"
2001         wait_request_state $fid ARCHIVE SUCCEED
2002
2003         $LFS hsm_release $f || error "could not release file"
2004
2005         $TRUNCATE $f 0 || error "truncate failed"
2006         sync
2007
2008         local sz=$(stat -c %s $f)
2009         [[ $sz == 0 ]] || error "size after truncate is $sz != 0"
2010
2011         $LFS hsm_state $f
2012
2013         check_hsm_flags $f "0x0000000b"
2014
2015         local state=$(get_request_state $fid RESTORE)
2016         [[ "$state" == "" ]] ||
2017                 error "truncate 0 trigs a restore, state = $state"
2018
2019         copytool_cleanup
2020 }
2021 run_test 58 "Truncate 0 on a released file must not trigger restore"
2022
2023 test_59() {
2024         # test needs a running copytool
2025         copytool_setup
2026
2027         mkdir -p $DIR/$tdir
2028         local f=$DIR/$tdir/$tfile
2029         local fid=$(copy_file /etc/passwd $f)
2030         local ref=$f-ref
2031         cp $f $ref
2032         local sz=$(stat -c %s $ref)
2033         sz=$((sz / 2))
2034         $TRUNCATE $ref $sz
2035
2036         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2037                 error "could not archive file"
2038         wait_request_state $fid ARCHIVE SUCCEED
2039
2040         $LFS hsm_release $f || error "could not release file"
2041
2042         $TRUNCATE $f $sz || error "truncate failed"
2043         sync
2044
2045         local sz1=$(stat -c %s $f)
2046         [[ $sz1 == $sz ]] || error "size after truncate is $sz1 != $sz"
2047
2048         $LFS hsm_state $f
2049
2050         check_hsm_flags $f "0x0000000b"
2051
2052         local state=$(get_request_state $fid RESTORE)
2053         [[ "$state" == "SUCCEED" ]] ||
2054                 error "truncate $sz does not trig a successfull restore,"\
2055                       " state = $state"
2056
2057         cmp $ref $f || error "file data wrong after truncate"
2058
2059         copytool_cleanup
2060 }
2061 run_test 59 "Truncate != 0 on a released file"
2062
2063 test_90() {
2064         file_count=57
2065         mkdir -p $DIR/$tdir
2066         local f=$DIR/$tdir/$tfile
2067         local FILELIST=/tmp/filelist.txt
2068         local i=""
2069
2070         rm -f $FILELIST
2071         for i in $(seq 1 $file_count); do
2072                 fid=$(copy_file /etc/hosts $f.$i)
2073                 echo $f.$i >> $FILELIST
2074         done
2075         copytool_setup
2076         # to be sure wait_all_done will not be mislead by previous tests
2077         cdt_purge
2078         wait_for_grace_delay
2079         $LFS hsm_archive --filelist $FILELIST ||
2080                 error "cannot archive a file list"
2081         wait_all_done 100
2082         $LFS hsm_release --filelist $FILELIST ||
2083                 error "cannot release a file list"
2084         $LFS hsm_restore --filelist $FILELIST ||
2085                 error "cannot restore a file list"
2086         wait_all_done 100
2087         copytool_cleanup
2088 }
2089 run_test 90 "Archive/restore a file list"
2090
2091 double_verify_reset_hsm_param() {
2092         local p=$1
2093         echo "Testing $HSM_PARAM.$p"
2094         local val=$(get_hsm_param $p)
2095         local save=$val
2096         local val2=$(($val * 2))
2097         set_hsm_param $p $val2
2098         val=$(get_hsm_param $p)
2099         [[ $val == $val2 ]] ||
2100                 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2101         echo "Set $p to 0 must failed"
2102         set_hsm_param $p 0
2103         local rc=$?
2104         # restore value
2105         set_hsm_param $p $save
2106
2107         if [[ $rc == 0 ]]
2108         then
2109                 error "we must not be able to set $HSM_PARAM.$p to 0"
2110         fi
2111 }
2112
2113 test_100() {
2114         double_verify_reset_hsm_param loop_period
2115         double_verify_reset_hsm_param grace_delay
2116         double_verify_reset_hsm_param request_timeout
2117         double_verify_reset_hsm_param max_requests
2118         double_verify_reset_hsm_param archive_id
2119 }
2120 run_test 100 "Set coordinator /proc tunables"
2121
2122 test_102() {
2123         cdt_disable
2124         cdt_enable
2125         cdt_restart
2126 }
2127 run_test 102 "Verify coordinator control"
2128
2129 test_103() {
2130         # test needs a running copytool
2131         copytool_setup
2132
2133         local i=""
2134         local fid=""
2135
2136         mkdir -p $DIR/$tdir
2137         for i in $(seq 1 20); do
2138                 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2139         done
2140         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2141
2142         cdt_purge
2143
2144         echo "Current requests"
2145         local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2146                         $HSM_PARAM.agent_actions |\
2147                         grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2148
2149         [[ -z "$res" ]] || error "Some request have not been canceled"
2150
2151         copytool_cleanup
2152 }
2153 run_test 103 "Purge all requests"
2154
2155 DATA=CEA
2156 DATAHEX='[434541]'
2157 test_104() {
2158         # test needs a running copytool
2159         copytool_setup
2160
2161         mkdir -p $DIR/$tdir
2162         local f=$DIR/$tdir/$tfile
2163         local fid=$(make_large_for_progress $f)
2164         # if cdt is on, it can serve too quickly the request
2165         cdt_disable
2166         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
2167         local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2168                         $HSM_PARAM.agent_actions |\
2169                         grep $fid | cut -f16 -d=")
2170         cdt_enable
2171
2172         [[ "$data1" == "$DATAHEX" ]] ||
2173                 error "Data field in records is ($data1) and not ($DATAHEX)"
2174
2175         copytool_cleanup
2176 }
2177 run_test 104 "Copy tool data field"
2178
2179 test_105() {
2180         mkdir -p $DIR/$tdir
2181         local i=""
2182
2183         cdt_disable
2184         for i in $(seq -w 1 10); do
2185                 cp /etc/passwd $DIR/$tdir/$i
2186                 $LFS hsm_archive $DIR/$tdir/$i
2187         done
2188         local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2189                         $HSM_PARAM.agent_actions |\
2190                         grep WAITING | wc -l")
2191         cdt_restart
2192         cdt_disable
2193         local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2194                         $HSM_PARAM.agent_actions |\
2195                         grep WAITING | wc -l")
2196         cdt_enable
2197         cdt_purge
2198         [[ "$reqcnt1" == "$reqcnt2" ]] ||
2199                 error "Requests count after shutdown $reqcnt2 != "\
2200                       "before shutdown $reqcnt1"
2201 }
2202 run_test 105 "Restart of coordinator"
2203
2204 test_106() {
2205         # test needs a running copytool
2206         copytool_setup
2207
2208         local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
2209                 get_client_uuid | cut -d' ' -f2)
2210         local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2211                 grep $uuid)
2212         copytool_cleanup
2213         [[ ! -z "$agent" ]] || error "My uuid $uuid not found in agent list"
2214         local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2215                 grep $uuid)
2216         [[ -z "$agent" ]] ||
2217                 error "My uuid $uuid still found in agent list,"\
2218                       " after copytool shutdown"
2219         copytool_setup
2220         local agent=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.agents |
2221                 grep $uuid)
2222         copytool_cleanup
2223         [[ ! -z "$agent" ]] ||
2224                 error "My uuid $uuid not found in agent list after"\
2225                       " copytool restart"
2226 }
2227 run_test 106 "Copytool register/unregister"
2228
2229 test_107() {
2230         # test needs a running copytool
2231         copytool_setup
2232         # create and archive file
2233         mkdir -p $DIR/$tdir
2234         local f1=$DIR/$tdir/$tfile
2235         local fid=$(copy_file /etc/passwd $f1)
2236         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2237         wait_request_state $fid ARCHIVE SUCCEED
2238         # shutdown and restart MDS
2239         fail $SINGLEMDS
2240         # check the copytool still gets messages from MDT
2241         local f2=$DIR/$tdir/2
2242         local fid=$(copy_file /etc/passwd $f2)
2243         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2244         # main check of this sanity: this request MUST succeed
2245         wait_request_state $fid ARCHIVE SUCCEED
2246         copytool_cleanup
2247 }
2248 run_test 107 "Copytool re-register after MDS restart"
2249
2250 test_110a() {
2251         # test needs a running copytool
2252         copytool_setup
2253
2254         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2255         cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2256         local f=$DIR/$tdir/$tfile
2257         import_file $tdir/$tfile $f
2258         local fid=$(path2fid $f)
2259
2260         cdt_set_no_blocking_restore
2261         md5sum $f
2262         local st=$?
2263
2264         # cleanup
2265         wait_request_state $fid RESTORE SUCCEED
2266         cdt_clear_no_blocking_restore
2267
2268         # Test result
2269         [[ $st == 1 ]] ||
2270                 error "md5sum returns $st != 1, "\
2271                         "should also perror ENODATA (No data available)"
2272
2273         copytool_cleanup
2274 }
2275 run_test 110a "Non blocking restore policy (import case)"
2276
2277 test_110b() {
2278         # test needs a running copytool
2279         copytool_setup
2280
2281         mkdir -p $DIR/$tdir
2282         local f=$DIR/$tdir/$tfile
2283         local fid=$(copy_file /etc/passwd $f)
2284         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2285         wait_request_state $fid ARCHIVE SUCCEED
2286         $LFS hsm_release $f
2287
2288         cdt_set_no_blocking_restore
2289         md5sum $f
2290         local st=$?
2291
2292         # cleanup
2293         wait_request_state $fid RESTORE SUCCEED
2294         cdt_clear_no_blocking_restore
2295
2296         # Test result
2297         [[ $st == 1 ]] ||
2298                 error "md5sum returns $st != 1, "\
2299                         "should also perror ENODATA (No data available)"
2300
2301         copytool_cleanup
2302 }
2303 run_test 110b "Non blocking restore policy (release case)"
2304
2305 test_111a() {
2306         # test needs a running copytool
2307         copytool_setup
2308
2309         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2310         local f=$DIR/$tdir/$tfile
2311         cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2312         import_file $tdir/$tfile $f
2313         local fid=$(path2fid $f)
2314
2315         cdt_set_no_retry
2316
2317         copytool_remove_backend $fid
2318
2319         $LFS hsm_restore $f
2320         wait_request_state $fid RESTORE FAILED
2321         local st=$?
2322
2323         # cleanup
2324         cdt_clear_no_retry
2325
2326         # Test result
2327         [[ $st == 0 ]] || error "Restore does not failed"
2328
2329         copytool_cleanup
2330 }
2331 run_test 111a "No retry policy (import case), restore will error"\
2332               " (No such file or directory)"
2333
2334 test_111b() {
2335         # test needs a running copytool
2336         copytool_setup
2337
2338         mkdir -p $DIR/$tdir
2339         local f=$DIR/$tdir/$tfile
2340         local fid=$(copy_file /etc/passwd $f)
2341         cdt_set_no_retry
2342         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2343         wait_request_state $fid ARCHIVE SUCCEED
2344         $LFS hsm_release $f
2345
2346         copytool_remove_backend $fid
2347
2348         $LFS hsm_restore $f
2349         wait_request_state $fid RESTORE FAILED
2350         local st=$?
2351
2352         # cleanup
2353         cdt_clear_no_retry
2354
2355         # Test result
2356         [[ $st == 0 ]] || error "Restore does not failed"
2357
2358         copytool_cleanup
2359 }
2360 run_test 111b "No retry policy (release case), restore will error"\
2361               " (No such file or directory)"
2362
2363 test_112() {
2364         # test needs a running copytool
2365         copytool_setup
2366
2367         mkdir -p $DIR/$tdir
2368         local f=$DIR/$tdir/$tfile
2369         local fid=$(copy_file /etc/passwd $f)
2370         cdt_disable
2371         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2372         local l=$($LFS hsm_action $f)
2373         echo $l
2374         local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
2375
2376         # cleanup
2377         cdt_enable
2378         wait_request_state $fid ARCHIVE SUCCEED
2379
2380         # Test result
2381         [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
2382
2383         copytool_cleanup
2384 }
2385 run_test 112 "State of recorded request"
2386
2387 test_200() {
2388         # test needs a running copytool
2389         copytool_setup
2390
2391         mkdir -p $DIR/$tdir
2392         local f=$DIR/$tdir/$tfile
2393         local fid=$(make_large_for_cancel $f)
2394         # test with cdt on is made in test_221
2395         cdt_disable
2396         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2397         $LFS hsm_cancel $f
2398         cdt_enable
2399         wait_request_state $fid ARCHIVE CANCELED
2400         wait_request_state $fid CANCEL SUCCEED
2401
2402         copytool_cleanup
2403 }
2404 run_test 200 "Register/Cancel archive"
2405
2406 test_201() {
2407         # test needs a running copytool
2408         copytool_setup
2409
2410         mkdir -p $DIR/$tdir
2411         local f=$DIR/$tdir/$tfile
2412         make_archive $tdir/$tfile
2413         import_file $tdir/$tfile $f
2414         local fid=$(path2fid $f)
2415
2416         # test with cdt on is made in test_222
2417         cdt_disable
2418         $LFS hsm_restore $f
2419         $LFS hsm_cancel $f
2420         cdt_enable
2421         wait_request_state $fid RESTORE CANCELED
2422         wait_request_state $fid CANCEL SUCCEED
2423
2424         copytool_cleanup
2425 }
2426 run_test 201 "Register/Cancel restore"
2427
2428 test_202() {
2429         # test needs a running copytool
2430         copytool_setup
2431
2432         mkdir -p $DIR/$tdir
2433         local f=$DIR/$tdir/$tfile
2434         local fid=$(make_large_for_progress $f)
2435         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2436         wait_request_state $fid ARCHIVE SUCCEED
2437
2438         cdt_disable
2439         $LFS hsm_remove $f
2440         $LFS hsm_cancel $f
2441         cdt_enable
2442         wait_request_state $fid REMOVE CANCELED
2443
2444         copytool_cleanup
2445 }
2446 run_test 202 "Register/Cancel remove"
2447
2448 test_220() {
2449         # test needs a running copytool
2450         copytool_setup
2451
2452         mkdir -p $DIR/$tdir
2453
2454         local f=$DIR/$tdir/$tfile
2455         local fid=$(copy_file /etc/passwd $f)
2456
2457         changelog_setup
2458
2459         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2460         wait_request_state $fid ARCHIVE SUCCEED
2461
2462         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2463         changelog_cleanup
2464
2465         local target=0x0
2466         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2467
2468         copytool_cleanup
2469 }
2470 run_test 220 "Changelog for archive"
2471
2472 test_221() {
2473         # test needs a running copytool
2474         copytool_setup
2475
2476         mkdir -p $DIR/$tdir
2477
2478         local f=$DIR/$tdir/$tfile
2479         local fid=$(make_large_for_cancel $f)
2480
2481         changelog_setup
2482
2483         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2484         wait_request_state $fid ARCHIVE STARTED
2485         $LFS hsm_cancel $f
2486         wait_request_state $fid ARCHIVE CANCELED
2487         wait_request_state $fid CANCEL SUCCEED
2488
2489         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2490
2491         local target=0x7d
2492         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2493
2494         cleanup
2495 }
2496 run_test 221 "Changelog for archive canceled"
2497
2498 test_222a() {
2499         # test needs a running copytool
2500         copytool_setup
2501
2502         mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
2503         local f=$DIR/$tdir/$tfile
2504         cp /etc/passwd $HSM_ARCHIVE/$tdir/$tfile
2505         import_file $tdir/$tfile $f
2506         local fid=$(path2fid $f)
2507
2508         changelog_setup
2509
2510         $LFS hsm_restore $f
2511         wait_request_state $fid RESTORE SUCCEED
2512
2513         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2514
2515         local target=0x80
2516         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2517
2518         cleanup
2519 }
2520 run_test 222a "Changelog for explicit restore"
2521
2522 test_222b() {
2523         # test needs a running copytool
2524         copytool_setup
2525
2526         mkdir -p $DIR/$tdir
2527         local f=$DIR/$tdir/$tfile
2528         local fid=$(copy_file /etc/passwd $f)
2529
2530         changelog_setup
2531         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2532         wait_request_state $fid ARCHIVE SUCCEED
2533         $LFS hsm_release $f
2534
2535         md5sum $f
2536
2537         wait_request_state $fid RESTORE SUCCEED
2538
2539         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2540
2541         local target=0x80
2542         [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
2543
2544         cleanup
2545 }
2546 run_test 222b "Changelog for implicit restore"
2547
2548 test_223a() {
2549         # test needs a running copytool
2550         copytool_setup
2551
2552         mkdir -p $DIR/$tdir
2553
2554         local f=$DIR/$tdir/$tfile
2555         make_archive $tdir/$tfile
2556
2557         changelog_setup
2558
2559         import_file $tdir/$tfile $f
2560         local fid=$(path2fid $f)
2561
2562         $LFS hsm_restore $f
2563         wait_request_state $fid RESTORE STARTED
2564         $LFS hsm_cancel $f
2565         wait_request_state $fid RESTORE CANCELED
2566         wait_request_state $fid CANCEL SUCCEED
2567
2568         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2569
2570         local target=0xfd
2571         [[ $flags == $target ]] ||
2572                 error "Changelog flag is $flags not $target"
2573
2574         cleanup
2575 }
2576 run_test 223a "Changelog for restore canceled (import case)"
2577
2578 test_223b() {
2579         # test needs a running copytool
2580         copytool_setup
2581
2582         mkdir -p $DIR/$tdir
2583
2584         local f=$DIR/$tdir/$tfile
2585         local fid=$(make_large_for_progress $f)
2586
2587         changelog_setup
2588         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2589         wait_request_state $fid ARCHIVE SUCCEED
2590         $LFS hsm_release $f
2591         $LFS hsm_restore $f
2592         wait_request_state $fid RESTORE STARTED
2593         $LFS hsm_cancel $f
2594         wait_request_state $fid RESTORE CANCELED
2595         wait_request_state $fid CANCEL SUCCEED
2596
2597         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2598
2599         local target=0xfd
2600         [[ $flags == $target ]] ||
2601                 error "Changelog flag is $flags not $target"
2602
2603         cleanup
2604 }
2605 run_test 223b "Changelog for restore canceled (release case)"
2606
2607 test_224() {
2608         # test needs a running copytool
2609         copytool_setup
2610
2611         mkdir -p $DIR/$tdir
2612
2613         local f=$DIR/$tdir/$tfile
2614         local fid=$(copy_file /etc/passwd $f)
2615
2616         changelog_setup
2617         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2618         wait_request_state $fid ARCHIVE SUCCEED
2619
2620         $LFS hsm_remove $f
2621         wait_request_state $fid REMOVE SUCCEED
2622
2623         local flags=$(changelog_get_flags $MDT0 HSM $fid | tail -1)
2624
2625         local target=0x200
2626         [[ $flags == $target ]] ||
2627                 error "Changelog flag is $flags not $target"
2628
2629         cleanup
2630 }
2631 run_test 224 "Changelog for remove"
2632
2633 test_225() {
2634         # test needs a running copytool
2635         copytool_setup
2636
2637         # test is not usable because remove request is too fast
2638         # so it is always finished before cancel can be done ...
2639         echo "Test disabled"
2640         copytool_cleanup
2641         return 0
2642
2643         mkdir -p $DIR/$tdir
2644         local f=$DIR/$tdir/$tfile
2645         local fid=$(make_large_for_progress $f)
2646
2647         changelog_setup
2648         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2649         wait_request_state $fid ARCHIVE SUCCEED
2650
2651         # if cdt is on, it can serve too quickly the request
2652         cdt_disable
2653         $LFS hsm_remove $f
2654         $LFS hsm_cancel $f
2655         cdt_enable
2656         wait_request_state $fid REMOVE CANCELED
2657         wait_request_state $fid CANCEL SUCCEED
2658
2659         flags=$(changelog_get_flags $MDT0 RENME $fid2)
2660         local flags=$($LFS changelog $MDT0 | grep HSM | grep $fid | tail -1 |
2661                 awk '{print $5}')
2662
2663         local target=0x27d
2664         [[ $flags == $target ]] ||
2665                 error "Changelog flag is $flags not $target"
2666
2667         cleanup
2668 }
2669 run_test 225 "Changelog for remove canceled"
2670
2671 test_226() {
2672         # test needs a running copytool
2673         copytool_setup
2674
2675         mkdir -p $DIR/$tdir
2676
2677         local f1=$DIR/$tdir/$tfile-1
2678         local f2=$DIR/$tdir/$tfile-2
2679         local f3=$DIR/$tdir/$tfile-3
2680         local fid1=$(copy_file /etc/passwd $f1)
2681         local fid2=$(copy_file /etc/passwd $f2)
2682         copy_file /etc/passwd $f3
2683
2684         changelog_setup
2685         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
2686         wait_request_state $fid1 ARCHIVE SUCCEED
2687
2688         $LFS hsm_archive $f2
2689         wait_request_state $fid2 ARCHIVE SUCCEED
2690
2691         rm $f1 || error "rm $f1 failed"
2692
2693         local flags=$(changelog_get_flags $MDT0 UNLNK $fid1)
2694
2695         local target=0x3
2696         [[ $flags == $target ]] ||
2697                 error "Changelog flag is $flags not $target"
2698
2699         mv $f3 $f2 || error "mv $f3 $f2 failed"
2700
2701         flags=$(changelog_get_flags $MDT0 RENME $fid2)
2702
2703         target=0x3
2704         [[ $flags == $target ]] ||
2705                 error "Changelog flag is $flags not $target"
2706
2707         cleanup
2708 }
2709 run_test 226 "changelog for last rm/mv with exiting archive"
2710
2711 check_flags_changes() {
2712         local f=$1
2713         local fid=$2
2714         local hsm_flag=$3
2715         local fst=$4
2716         local cnt=$5
2717
2718         local target=0x280
2719         $LFS hsm_set --$hsm_flag $f ||
2720                 error "Cannot set $hsm_flag on $f"
2721         local flags=($(changelog_get_flags $MDT0 HSM $fid))
2722         local seen=${#flags[*]}
2723         cnt=$((fst + cnt))
2724         [[ $seen == $cnt ]] ||
2725                 error "set $hsm_flag: Changelog events $seen != $cnt"
2726         [[ ${flags[$((cnt - 1))]} == $target ]] ||
2727                 error "set $hsm_flag: Changelog flags are "\
2728                         "${flags[$((cnt - 1))]} not $target"
2729
2730         $LFS hsm_clear --$hsm_flag $f ||
2731                 error "Cannot clear $hsm_flag on $f"
2732         flags=($(changelog_get_flags $MDT0 HSM $fid))
2733         seen=${#flags[*]}
2734         cnt=$(($cnt + 1))
2735         [[ $cnt == $seen ]] ||
2736                 error "clear $hsm_flag: Changelog events $seen != $cnt"
2737
2738         [[ ${flags[$((cnt - 1))]} == $target ]] ||
2739                 error "clear $hsm_flag: Changelog flag is "\
2740                         "${flags[$((cnt - 1))]} not $target"
2741 }
2742
2743 test_227() {
2744         # test needs a running copytool
2745         copytool_setup
2746         changelog_setup
2747
2748         mkdir -p $DIR/$tdir
2749         typeset -a flags
2750
2751         for i in norelease noarchive exists archived
2752         do
2753                 local f=$DIR/$tdir/$tfile-$i
2754                 local fid=$(copy_file /etc/passwd $f)
2755                 check_flags_changes $f $fid $i 0 1
2756         done
2757
2758         f=$DIR/$tdir/$tfile---lost
2759         fid=$(copy_file /etc/passwd $f)
2760         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2761         wait_request_state $fid ARCHIVE SUCCEED
2762         check_flags_changes $f $fid lost 3 1
2763
2764         cleanup
2765 }
2766 run_test 227 "changelog when explicit setting of HSM flags"
2767
2768 test_250() {
2769         # test needs a running copytool
2770         copytool_setup
2771
2772         mkdir -p $DIR/$tdir
2773         local maxrequest=$(get_hsm_param max_requests)
2774         local rqcnt=$(($maxrequest * 3))
2775         local i=""
2776
2777         cdt_disable
2778         for i in $(seq -w 1 $rqcnt); do
2779                 rm -f $DIR/$tdir/$i
2780                 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
2781         done
2782         # we do it in 2 steps, so all requests arrive at the same time
2783         for i in $(seq -w 1 $rqcnt); do
2784                 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
2785         done
2786         cdt_enable
2787         local cnt=$rqcnt
2788         local wt=$rqcnt
2789         while [[ $cnt != 0 || $wt != 0 ]]; do
2790                 sleep 1
2791                 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2792                         $HSM_PARAM.agent_actions |\
2793                         grep STARTED | grep -v CANCEL | wc -l")
2794                 [[ $cnt -le $maxrequest ]] ||
2795                         error "$cnt > $maxrequest too many started requests"
2796                 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
2797                         $HSM_PARAM.agent_actions |\
2798                         grep WAITING | wc -l")
2799                 echo "max=$maxrequest started=$cnt waiting=$wt"
2800         done
2801
2802         copytool_cleanup
2803 }
2804 run_test 250 "Coordinator max request"
2805
2806 test_251() {
2807         # test needs a running copytool
2808         copytool_setup
2809
2810         mkdir -p $DIR/$tdir
2811         local f=$DIR/$tdir/$tfile
2812         local fid=$(make_large_for_cancel $f)
2813
2814         cdt_disable
2815         # to have a short test
2816         local old_to=$(get_hsm_param request_timeout)
2817         set_hsm_param request_timeout 4
2818         # to be sure the cdt will wake up frequently so
2819         # it will be able to cancel the "old" request
2820         local old_loop=$(get_hsm_param loop_period)
2821         set_hsm_param loop_period 2
2822         cdt_enable
2823
2824         $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2825         wait_request_state $fid ARCHIVE STARTED
2826         sleep 5
2827         wait_request_state $fid ARCHIVE CANCELED
2828
2829         set_hsm_param request_timeout $old_to
2830         set_hsm_param loop_period $old_loop
2831
2832         copytool_cleanup
2833 }
2834 run_test 251 "Coordinator request timeout"
2835
2836 test_300() {
2837         # the only way to test ondisk conf is to restart MDS ...
2838         echo "Stop coordinator and remove coordinator state at mount"
2839         # stop coordinator
2840         cdt_shutdown
2841         # clean on disk conf set by default
2842         cdt_clear_mount_state
2843         cdt_check_state stopped
2844
2845         # check cdt still off after umount/remount
2846         fail $SINGLEMDS
2847         cdt_check_state stopped
2848
2849         echo "Set coordinator start at mount, and start coordinator"
2850         cdt_set_mount_state enabled
2851
2852         # check cdt is on
2853         cdt_check_state enabled
2854
2855         # check cdt still on after umount/remount
2856         fail $SINGLEMDS
2857         cdt_check_state enabled
2858
2859         # we are back to original state (cdt started at mount)
2860 }
2861 run_test 300 "On disk coordinator state kept between MDT umount/mount"
2862
2863 copytool_cleanup
2864
2865 complete $SECONDS
2866 check_and_cleanup_lustre
2867 exit_status