Whamcloud - gitweb
e43d27fcb4ada0fb0a17d17965f0cc88ecc17750
[fs/lustre-release.git] / lustre / tests / sanity-quota.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 # Run test by setting NOSETUP=true when ltest has setup env for us
7 set -e
8
9 SRCDIR=`dirname $0`
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
11
12 ONLY=${ONLY:-"$*"}
13 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
17         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
18
19 TMP=${TMP:-/tmp}
20
21 ORIG_PWD=${PWD}
22 TSTID=${TSTID:-60000}
23 TSTID2=${TSTID2:-60001}
24 TSTUSR=${TSTUSR:-"quota_usr"}
25 TSTUSR2=${TSTUSR2:-"quota_2usr"}
26 BLK_SZ=1024
27 MAX_DQ_TIME=604800
28 MAX_IQ_TIME=604800
29
30 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/test-framework.sh
32 init_test_env $@
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 init_logging
35 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
36
37 require_dsh_mds || exit 0
38 require_dsh_ost || exit 0
39
40 # XXX Once we drop the interoperability with old server (< 2.3.50), the
41 #     sanity-quota-old.sh should be removed.
42 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
43         exec $LUSTRE/tests/sanity-quota-old.sh
44 fi
45
46 # if e2fsprogs support quota feature?
47 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] && \
48         ! $DEBUGFS -c -R supported_features | grep -q 'quota'; then
49         skip "e2fsprogs doesn't support quota" && exit 0
50 fi
51
52 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
53 # bug number for skipped test:        LU-2872 LU-2836 LU-2836 LU-2059
54         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 1       3       6       7d"
55 # bug number:     LU-2887
56         ZFS_SLOW="12a"
57 fi
58
59 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
60
61 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
62
63 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
64
65 DIR=${DIR:-$MOUNT}
66 DIR2=${DIR2:-$MOUNT2}
67
68 QUOTA_AUTO_OLD=$QUOTA_AUTO
69 export QUOTA_AUTO=0
70
71 check_and_setup_lustre
72
73 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
74 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
75
76 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
77 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
78 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
79 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
80 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
81 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
82 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
83 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
84
85 build_test_filter
86
87 lustre_fail() {
88         local fail_node=$1
89         local fail_loc=$2
90         local fail_val=${3:-0}
91
92         if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
93                 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
94                 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
95         fi
96
97         if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
98                 for num in `seq $OSTCOUNT`; do
99                         do_facet ost$num "lctl set_param fail_val=$fail_val"
100                         do_facet ost$num "lctl set_param fail_loc=$fail_loc"
101                 done
102         fi
103 }
104
105 RUNAS="runas -u $TSTID -g $TSTID"
106 RUNAS2="runas -u $TSTID2 -g $TSTID2"
107 DD="dd if=/dev/zero bs=1M"
108
109 FAIL_ON_ERROR=false
110
111 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
112         error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
113 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
114         error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
115
116 # clear quota limits for a user or a group
117 # usage: resetquota -u username
118 #        resetquota -g groupname
119
120 resetquota() {
121         [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
122         [ "$1" != "-u" -a "$1" != "-g" ] &&
123                 error "resetquota: wrong specifier $1 passed"
124
125         $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
126                 error "clear quota for [type:$1 name:$2] failed"
127         # give a chance to slave to release space
128         sleep 1
129 }
130
131 quota_scan() {
132         local LOCAL_UG=$1
133         local LOCAL_ID=$2
134
135         if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
136                 $LFS quota -v -u $LOCAL_ID $DIR
137                 log "Files for user ($LOCAL_ID):"
138                 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
139                         xargs stat 2>/dev/null)
140         fi
141
142         if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
143                 $LFS quota -v -u $LOCAL_ID $DIR
144                 log "Files for group ($LOCAL_ID):"
145                 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
146                         xargs stat 2>/dev/null)
147         fi
148 }
149
150 quota_error() {
151         quota_scan $1 $2
152         shift 2
153         error "$*"
154 }
155
156 quota_log() {
157         quota_scan $1 $2
158         shift 2
159         log "$*"
160 }
161
162 # get quota for a user or a group
163 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
164 #                 bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
165 #
166 getquota() {
167         local spec
168         local uuid
169
170         [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
171         [ "$1" != "-u" -a "$1" != "-g" ] &&
172                 error "getquota: wrong u/g specifier $1 passed"
173
174         uuid="$3"
175
176         case "$4" in
177                 curspace)   spec=1;;
178                 bsoftlimit) spec=2;;
179                 bhardlimit) spec=3;;
180                 bgrace)     spec=4;;
181                 curinodes)  spec=5;;
182                 isoftlimit) spec=6;;
183                 ihardlimit) spec=7;;
184                 igrace)     spec=8;;
185                 *)          error "unknown quota parameter $4";;
186         esac
187
188         [ "$uuid" = "global" ] && uuid=$DIR
189
190         $LFS quota -v "$1" "$2" $DIR |
191                 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
192                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
193                 | tr -d "*"
194 }
195
196 # set mdt quota type
197 # usage: set_mdt_qtype ug|u|g|none
198 set_mdt_qtype() {
199         local qtype=$1
200         local varsvc
201         local mdts=$(get_facets MDS)
202         local cmd
203         do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
204         # we have to make sure each MDT received config changes
205         for mdt in ${mdts//,/ }; do
206                 varsvc=${mdt}_svc
207                 cmd="$LCTL get_param -n "
208                 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
209                 cmd=${cmd}.quota_slave.enabled
210
211                 if $(facet_up $mdt); then
212                         wait_update_facet $mdt "$cmd" "$qtype" || return 1
213                 fi
214         done
215         return 0
216 }
217
218 # set ost quota type
219 # usage: set_ost_qtype ug|u|g|none
220 set_ost_qtype() {
221         local qtype=$1
222         local varsvc
223         local osts=$(get_facets OST)
224         local cmd
225         do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
226         # we have to make sure each OST received config changes
227         for ost in ${osts//,/ }; do
228                 varsvc=${ost}_svc
229                 cmd="$LCTL get_param -n "
230                 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
231                 cmd=${cmd}.quota_slave.enabled
232
233                 if $(facet_up $ost); then
234                         wait_update_facet $ost "$cmd" "$qtype" || return 1
235                 fi
236         done
237         return 0
238 }
239
240 wait_reintegration() {
241         local ntype=$1
242         local qtype=$2
243         local max=$3
244         local result="glb[1],slv[1],reint[0]"
245         local varsvc
246         local cmd
247         local tgts
248
249         if [ $ntype == "mdt" ]; then
250                 tgts=$(get_facets MDS)
251         else
252                 tgts=$(get_facets OST)
253         fi
254
255         for tgt in ${tgts//,/ }; do
256                 varsvc=${tgt}_svc
257                 cmd="$LCTL get_param -n "
258                 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
259                 cmd=${cmd}.quota_slave.info
260
261                 if $(facet_up $tgt); then
262                         wait_update_facet $tgt "$cmd |
263                                 grep "$qtype" | awk '{ print \\\$3 }'" \
264                                         "$result" $max || return 1
265                 fi
266         done
267         return 0
268 }
269
270 wait_mdt_reint() {
271         local qtype=$1
272         local max=${2:-90}
273
274         if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
275                 wait_reintegration "mdt" "user" $max || return 1
276         fi
277
278         if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
279                 wait_reintegration "mdt" "group" $max || return 1
280         fi
281         return 0
282 }
283
284 wait_ost_reint() {
285         local qtype=$1
286         local max=${2:-90}
287
288         if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
289                 wait_reintegration "ost" "user" $max || return 1
290         fi
291
292         if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
293                 wait_reintegration "ost" "group" $max || return 1
294         fi
295         return 0
296 }
297
298 setup_quota_test() {
299         rm -rf $DIR/$tdir
300         wait_delete_completed
301         echo "Creating test directory"
302         mkdir -p $DIR/$tdir
303         chmod 0777 $DIR/$tdir
304         # always clear fail_loc in case of fail_loc isn't cleared
305         # properly when previous test failed
306         lustre_fail mds_ost 0
307 }
308
309 cleanup_quota_test() {
310         trap 0
311         echo "Delete files..."
312         rm -rf $DIR/$tdir
313         echo "Wait for unlink objects finished..."
314         wait_delete_completed
315         sync_all_data || true
316 }
317
318 quota_show_check() {
319         local bf=$1
320         local ug=$2
321         local qid=$3
322         local usage
323
324         $LFS quota -v -$ug $qid $DIR
325
326         if [ "$bf" == "a" -o "$bf" == "b" ]; then
327                 usage=$(getquota -$ug $qid global curspace)
328                 if [ -z $usage ]; then
329                         quota_error $ug $qid \
330                                 "Query block quota failed ($ug:$qid)."
331                 else
332                         [ $usage -ne 0 ] && quota_log $ug $qid \
333                                 "Block quota isn't 0 ($ug:$qid:$usage)."
334                 fi
335         fi
336
337         if [ "$bf" == "a" -o "$bf" == "f" ]; then
338                 usage=$(getquota -$ug $qid global curinodes)
339                 if [ -z $usage ]; then
340                         quota_error $ug $qid \
341                                 "Query file quota failed ($ug:$qid)."
342                 else
343                         [ $usage -ne 0 ] && quota_log $ug $qid \
344                                 "File quota isn't 0 ($ug:$qid:$usage)."
345                 fi
346         fi
347 }
348
349 # enable quota debug
350 quota_init() {
351         do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
352 }
353 quota_init
354
355 resetquota -u $TSTUSR
356 resetquota -g $TSTUSR
357 resetquota -u $TSTUSR2
358 resetquota -g $TSTUSR2
359
360 test_quota_performance() {
361         local TESTFILE="$DIR/$tdir/$tfile-0"
362         local size=$1 # in MB
363         local stime=$(date +%s)
364         $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
365                 quota_error u $TSTUSR "write failure"
366         local etime=$(date +%s)
367         delta=$((etime - stime))
368         if [ $delta -gt 0 ]; then
369             rate=$((size * 1024 / delta))
370             if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
371                 # LU-2872 - see LU-2887 for fix
372                 [ $rate -gt 64 ] ||
373                         error "SLOW IO for $TSTUSR (user): $rate KB/sec"
374             else
375                 [ $rate -gt 1024 ] ||
376                         error "SLOW IO for $TSTUSR (user): $rate KB/sec"
377             fi
378         fi
379         rm -f $TESTFILE
380 }
381
382 # test basic quota performance b=21696
383 test_0() {
384         local MB=100 # 100M
385         [ "$SLOW" = "no" ] && MB=10
386
387         local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
388         [ $free_space -le $((MB * 1024)) ] &&
389                 skip "not enough space ${free_space} KB, " \
390                         "required $((MB * 1024)) KB" && return
391         setup_quota_test
392         trap cleanup_quota_test EXIT
393
394         set_ost_qtype "none" || error "disable ost quota failed"
395         test_quota_performance $MB
396
397         set_ost_qtype "ug" || error "enable ost quota failed"
398         $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
399                 error "set quota failed"
400         test_quota_performance $MB
401
402         cleanup_quota_test
403         resetquota -u $TSTUSR
404 }
405 run_test 0 "Test basic quota performance"
406
407 # test block hardlimit
408 test_1() {
409         local LIMIT=10  # 10M
410         local TESTFILE="$DIR/$tdir/$tfile-0"
411
412         setup_quota_test
413         trap cleanup_quota_test EXIT
414
415         # enable ost quota
416         set_ost_qtype "ug" || "enable ost quota failed"
417
418         # test for user
419         log "User quota (block hardlimit:$LIMIT MB)"
420         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
421                 error "set user quota failed"
422
423         # make sure the system is clean
424         local USED=$(getquota -u $TSTUSR global curspace)
425         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
426
427         $LFS setstripe $TESTFILE -c 1
428         chown $TSTUSR.$TSTUSR $TESTFILE
429
430         log "Write..."
431         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
432                 quota_error u $TSTUSR "user write failure, but expect success"
433         log "Write out of block quota ..."
434         # this time maybe cache write,  ignore it's failure
435         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
436         # flush cache, ensure noquota flag is set on client
437         cancel_lru_locks osc
438         $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
439                 quota_error u $TSTUSR "user write success, but expect EDQUOT"
440
441         rm -f $TESTFILE
442         wait_delete_completed
443         sync_all_data || true
444         USED=$(getquota -u $TSTUSR global curspace)
445         [ $USED -ne 0 ] && quota_error u $TSTUSR \
446                 "user quota isn't released after deletion"
447         resetquota -u $TSTUSR
448
449         # test for group
450         log "--------------------------------------"
451         log "Group quota (block hardlimit:$LIMIT MB)"
452         $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
453                 error "set group quota failed"
454
455         TESTFILE="$DIR/$tdir/$tfile-1"
456         # make sure the system is clean
457         USED=$(getquota -g $TSTUSR global curspace)
458         [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
459
460         $LFS setstripe $TESTFILE -c 1
461         chown $TSTUSR.$TSTUSR $TESTFILE
462
463         log "Write ..."
464         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
465                 quota_error g $TSTUSR "group write failure, but expect success"
466         log "Write out of block quota ..."
467         # this time maybe cache write, ignore it's failure
468         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
469         cancel_lru_locks osc
470         $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
471                 quota_error g $TSTUSR "group write success, but expect EDQUOT"
472
473         # cleanup
474         cleanup_quota_test
475
476         USED=$(getquota -g $TSTUSR global curspace)
477         [ $USED -ne 0 ] && quota_error g $TSTUSR \
478                 "group quota isn't released after deletion"
479
480         resetquota -g $TSTUSR
481 }
482 run_test 1 "Block hard limit (normal use and out of quota)"
483
484 # test inode hardlimit
485 test_2() {
486         local LIMIT=$((1024 * 1024)) # 1M inodes
487         local TESTFILE="$DIR/$tdir/$tfile-0"
488
489         [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
490
491         local FREE_INODES=$(mdt_free_inodes 0)
492         echo "$FREE_INODES free inodes on master MDT"
493         [ $FREE_INODES -lt $LIMIT ] &&
494                 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
495                 return
496
497         setup_quota_test
498         trap cleanup_quota_test EXIT
499
500         # enable mdt quota
501         set_mdt_qtype "ug" || "enable mdt quota failed"
502
503         # test for user
504         log "User quota (inode hardlimit:$LIMIT files)"
505         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
506                 error "set user quota failed"
507
508         # make sure the system is clean
509         local USED=$(getquota -u $TSTUSR global curinodes)
510         [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
511
512         log "Create $LIMIT files ..."
513         $RUNAS createmany -m ${TESTFILE} $LIMIT || \
514                 quota_error u $TSTUSR "user create failure, but expect success"
515         log "Create out of file quota ..."
516         $RUNAS touch ${TESTFILE}_xxx && \
517                 quota_error u $TSTUSR "user create success, but expect EDQUOT"
518
519         # cleanup
520         unlinkmany ${TESTFILE} $LIMIT
521         rm -f ${TESTFILE}_xxx
522         wait_delete_completed
523
524         USED=$(getquota -u $TSTUSR global curinodes)
525         [ $USED -ne 0 ] && quota_error u $TSTUSR \
526                 "user quota isn't released after deletion"
527         resetquota -u $TSTUSR
528
529         # test for group
530         log "--------------------------------------"
531         log "Group quota (inode hardlimit:$LIMIT files)"
532         $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
533                 error "set group quota failed"
534
535         TESTFILE=$DIR/$tdir/$tfile-1
536         # make sure the system is clean
537         USED=$(getquota -g $TSTUSR global curinodes)
538         [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
539
540         log "Create $LIMIT files ..."
541         $RUNAS createmany -m ${TESTFILE} $LIMIT ||
542                 quota_error g $TSTUSR "group create failure, but expect success"
543         log "Create out of file quota ..."
544         $RUNAS touch ${TESTFILE}_xxx && \
545                 quota_error g $TSTUSR "group create success, but expect EDQUOT"
546
547         # cleanup
548         unlinkmany ${TESTFILE} $LIMIT
549         rm -f ${TESTFILE}_xxx
550         wait_delete_completed
551
552         USED=$(getquota -g $TSTUSR global curinodes)
553         [ $USED -ne 0 ] && quota_error g $TSTUSR \
554                 "user quota isn't released after deletion"
555
556         cleanup_quota_test
557         resetquota -g $TSTUSR
558 }
559 run_test 2 "File hard limit (normal use and out of quota)"
560
561 test_block_soft() {
562         local TESTFILE=$1
563         local TIMER=$(($2 * 3 / 2))
564         local LIMIT=$3
565         local OFFSET=0
566
567         setup_quota_test
568         trap cleanup_quota_test EXIT
569
570         $LFS setstripe $TESTFILE -c 1 -i 0
571         chown $TSTUSR.$TSTUSR $TESTFILE
572
573         echo "Write up to soft limit"
574         $RUNAS $DD of=$TESTFILE count=$LIMIT ||
575                 quota_error a $TSTUSR "write failure, but expect success"
576         OFFSET=$((LIMIT * 1024))
577         cancel_lru_locks osc
578
579         echo "Write to exceed soft limit"
580         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
581                 quota_error a $TSTUSR "write failure, but expect success"
582         OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
583         cancel_lru_locks osc
584
585         $SHOW_QUOTA_USER
586         $SHOW_QUOTA_GROUP
587         $SHOW_QUOTA_INFO_USER
588         $SHOW_QUOTA_INFO_GROUP
589
590         echo "Write before timer goes off"
591         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
592                 quota_error a $TSTUSR "write failure, but expect success"
593         OFFSET=$((OFFSET + 1024))
594         cancel_lru_locks osc
595
596         echo "Sleep $TIMER seconds ..."
597         sleep $TIMER
598
599         $SHOW_QUOTA_USER
600         $SHOW_QUOTA_GROUP
601         $SHOW_QUOTA_INFO_USER
602         $SHOW_QUOTA_INFO_GROUP
603
604         echo "Write after timer goes off"
605         # maybe cache write, ignore.
606         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
607         OFFSET=$((OFFSET + 1024))
608         cancel_lru_locks osc
609         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
610                 quota_error a $TSTUSR "write success, but expect EDQUOT"
611
612         $SHOW_QUOTA_USER
613         $SHOW_QUOTA_GROUP
614         $SHOW_QUOTA_INFO_USER
615         $SHOW_QUOTA_INFO_GROUP
616
617         echo "Unlink file to stop timer"
618         rm -f $TESTFILE
619         wait_delete_completed
620         sync_all_data || true
621
622         $SHOW_QUOTA_USER
623         $SHOW_QUOTA_GROUP
624         $SHOW_QUOTA_INFO_USER
625         $SHOW_QUOTA_INFO_GROUP
626
627         $LFS setstripe $TESTFILE -c 1 -i 0
628         chown $TSTUSR.$TSTUSR $TESTFILE
629
630         echo "Write ..."
631         $RUNAS $DD of=$TESTFILE count=$LIMIT ||
632                 quota_error a $TSTUSR "write failure, but expect success"
633         # cleanup
634         cleanup_quota_test
635 }
636
637 # block soft limit
638 test_3() {
639         local LIMIT=1  # 1MB
640         local GRACE=20 # 20s
641         local TESTFILE=$DIR/$tdir/$tfile-0
642
643         set_ost_qtype "ug" || error "enable ost quota failed"
644
645         echo "User quota (soft limit:$LIMIT MB  grace:$GRACE seconds)"
646         # make sure the system is clean
647         local USED=$(getquota -u $TSTUSR global curspace)
648         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
649
650         $LFS setquota -t -u --block-grace $GRACE --inode-grace \
651                 $MAX_IQ_TIME $DIR || error "set user grace time failed"
652         $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
653                 error "set user quota failed"
654
655         test_block_soft $TESTFILE $GRACE $LIMIT
656         resetquota -u $TSTUSR
657
658         echo "Group quota (soft limit:$LIMIT MB  grace:$GRACE seconds)"
659         TESTFILE=$DIR/$tdir/$tfile-1
660         # make sure the system is clean
661         USED=$(getquota -g $TSTUSR global curspace)
662         [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
663
664         $LFS setquota -t -g --block-grace $GRACE --inode-grace \
665                 $MAX_IQ_TIME $DIR || error "set group grace time failed"
666         $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
667                 error "set group quota failed"
668
669         test_block_soft $TESTFILE $GRACE $LIMIT
670         resetquota -g $TSTUSR
671
672         # cleanup
673         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
674                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
675         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
676                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
677 }
678 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
679
680 test_file_soft() {
681         local TESTFILE=$1
682         local LIMIT=$2
683         local TIMER=$(($3 * 3 / 2))
684
685         setup_quota_test
686         trap cleanup_quota_test EXIT
687
688         echo "Create files to exceed soft limit"
689         $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
690                 quota_error a $TSTUSR "create failure, but expect success"
691         sync; sleep 1; sync
692
693         echo "Create file before timer goes off"
694         $RUNAS touch ${TESTFILE}_before ||
695                 quota_error a $TSTUSR "failed create before timer expired," \
696                         "but expect success"
697         sync; sleep 1; sync
698
699         echo "Sleep $TIMER seconds ..."
700         sleep $TIMER
701
702         $SHOW_QUOTA_USER
703         $SHOW_QUOTA_GROUP
704         $SHOW_QUOTA_INFO_USER
705         $SHOW_QUOTA_INFO_GROUP
706
707         echo "Create file after timer goes off"
708         # There is a window that space is accounted in the quota usage but
709         # hasn't been decreased from the pending write, if we acquire quota
710         # in this window, we'll acquire more than we needed.
711         $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
712         sync; sleep 1; sync
713         $RUNAS touch ${TESTFILE}_after_3 &&
714                 quota_error a $TSTUSR "create after timer expired," \
715                         "but expect EDQUOT"
716         sync; sleep 1; sync
717
718         $SHOW_QUOTA_USER
719         $SHOW_QUOTA_GROUP
720         $SHOW_QUOTA_INFO_USER
721         $SHOW_QUOTA_INFO_GROUP
722
723         echo "Unlink files to stop timer"
724         find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
725         wait_delete_completed
726
727         echo "Create file"
728         $RUNAS touch ${TESTFILE}_xxx ||
729                 quota_error a $TSTUSR "touch after timer stop failure," \
730                         "but expect success"
731         sync; sleep 1; sync
732
733         # cleanup
734         cleanup_quota_test
735 }
736
737 # file soft limit
738 test_4a() {
739         local LIMIT=10 # inodes
740         local TESTFILE=$DIR/$tdir/$tfile-0
741         local GRACE=5
742
743         set_mdt_qtype "ug" || error "enable mdt quota failed"
744
745         echo "User quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
746         # make sure the system is clean
747         local USED=$(getquota -u $TSTUSR global curinodes)
748         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
749
750         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
751                 $GRACE $DIR || error "set user grace time failed"
752         $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
753                 error "set user quota failed"
754
755         test_file_soft $TESTFILE $LIMIT $GRACE
756         resetquota -u $TSTUSR
757
758         echo "Group quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
759         # make sure the system is clean
760         USED=$(getquota -g $TSTUSR global curinodes)
761         [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
762
763         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
764                 $GRACE $DIR || error "set group grace time failed"
765         $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
766                 error "set group quota failed"
767         TESTFILE=$DIR/$tdir/$tfile-1
768
769         test_file_soft $TESTFILE $LIMIT $GRACE
770         resetquota -g $TSTUSR
771
772         # cleanup
773         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
774                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
775         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
776                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
777 }
778 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
779
780 test_4b() {
781         local GR_STR1="1w3d"
782         local GR_STR2="1000s"
783         local GR_STR3="5s"
784         local GR_STR4="1w2d3h4m5s"
785         local GR_STR5="5c"
786         local GR_STR6="1111111111111111"
787
788         wait_delete_completed
789
790         # test of valid grace strings handling
791         echo "Valid grace strings test"
792         $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
793                 $GR_STR2 $DIR || error "set user grace time failed"
794         $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
795         $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
796                 $GR_STR4 $DIR || error "set group grace time quota failed"
797         $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
798
799         # test of invalid grace strings handling
800         echo "  Invalid grace strings test"
801         ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
802         ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
803
804         # cleanup
805         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
806                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
807         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
808                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
809 }
810 run_test 4b "Grace time strings handling"
811
812 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
813 test_5() {
814         local BLIMIT=10 # 10M
815         local ILIMIT=10 # 10 inodes
816
817         setup_quota_test
818         trap cleanup_quota_test EXIT
819
820         set_mdt_qtype "ug" || error "enable mdt quota failed"
821         set_ost_qtype "ug" || error "enable ost quota failed"
822
823         echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
824         $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
825                 error "set user quota failed"
826         $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
827                 error "set group quota failed"
828
829         # make sure the system is clean
830         local USED=$(getquota -u $TSTUSR global curinodes)
831         [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
832         USED=$(getquota -g $TSTUSR global curinodes)
833         [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
834         USED=$(getquota -u $TSTUSR global curspace)
835         [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
836         USED=$(getquota -g $TSTUSR global curspace)
837         [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
838
839         echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
840         createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
841                 error "create failure, expect success"
842         $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
843                 error "write failure, expect success"
844
845         echo "Chown files to $TSTUSR.$TSTUSR ..."
846         for i in `seq 0 $ILIMIT`; do
847                 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
848                         quota_error a $TSTUSR "chown failure, expect success"
849         done
850
851         # cleanup
852         unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
853         cleanup_quota_test
854
855         resetquota -u $TSTUSR
856         resetquota -g $TSTUSR
857 }
858 run_test 5 "Chown & chgrp successfully even out of block/file quota"
859
860 # test dropping acquire request on master
861 test_6() {
862         local LIMIT=3 # 3M
863
864         # Clear dmesg so watchdog is not triggered by previous
865         # test output
866         do_facet ost1 dmesg -c > /dev/null
867
868         setup_quota_test
869         trap cleanup_quota_test EXIT
870
871         # make sure the system is clean
872         local USED=$(getquota -u $TSTUSR global curspace)
873         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
874
875         # make sure no granted quota on ost
876         set_ost_qtype "ug" || error "enable ost quota failed"
877         resetquota -u $TSTUSR
878
879         # create file for $TSTUSR
880         local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
881         $LFS setstripe $TESTFILE -c 1 -i 0
882         chown $TSTUSR.$TSTUSR $TESTFILE
883
884         # create file for $TSTUSR2
885         local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
886         $LFS setstripe $TESTFILE2 -c 1 -i 0
887         chown $TSTUSR2.$TSTUSR2 $TESTFILE2
888
889         # cache per-ID lock for $TSTUSR on slave
890         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
891                 error "set quota failed"
892         $RUNAS $DD of=$TESTFILE count=1 ||
893                 error "write $TESTFILE failure, expect success"
894         $RUNAS2 $DD of=$TESTFILE2 count=1 ||
895                 error "write $TESTFILE2 failure, expect success"
896         sync; sync
897         sync_all_data || true
898
899         #define QUOTA_DQACQ 601
900         #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
901         lustre_fail mds 0x513 601
902
903         # write to un-enforced ID ($TSTUSR2) should succeed
904         $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
905                 error "write failure, expect success"
906
907         # write to enforced ID ($TSTUSR) in background, exceeding limit
908         # to make sure DQACQ is sent
909         $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
910         DDPID=$!
911
912         # watchdog timer uses a factor of 2
913         echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
914         sleep $((TIMEOUT * 2 + 1))
915
916         # write should be blocked and never finished
917         if ! ps -p $DDPID  > /dev/null 2>&1; then
918                 lustre_fail mds 0 0
919                 error "write finished incorrectly!"
920         fi
921
922         lustre_fail mds 0 0
923
924         # no watchdog is triggered
925         do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
926         watchdog=$(awk '/Service thread pid/ && /was inactive/ \
927                         { print; }' $TMP/lustre-log-${TESTNAME}.log)
928         [ -z "$watchdog" ] || error "$watchdog"
929
930         rm -f $TMP/lustre-log-${TESTNAME}.log
931
932         # write should continue & succeed
933         local count=0
934         local o_size=$(stat -c %s $TESTFILE)
935         local c_size
936         while [ true ]; do
937                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
938                 if [ $count -ge 240 ]; then
939                         quota_error u $TSTUSR "dd not finished in $count secs"
940                 fi
941                 count=$((count + 1))
942                 if [ $((count % 30)) -eq 0 ]; then
943                         c_size=$(stat -c %s $TESTFILE)
944                         if [ $c_size -eq $o_size ]; then
945                                 quota_error u $TSTUSR "file not growed" \
946                                 "in 30 seconds $o_size/$c_size"
947                         else
948                                 echo "Waiting $count secs. $o_size/$c_size"
949                                 o_size=$c_size
950                         fi
951                 fi
952                 sleep 1
953         done
954
955         cleanup_quota_test
956         resetquota -u $TSTUSR
957 }
958 run_test 6 "Test dropping acquire request on master"
959
960 # quota reintegration (global index)
961 test_7a() {
962         local TESTFILE=$DIR/$tdir/$tfile
963         local LIMIT=20 # 20M
964
965         [ "$SLOW" = "no" ] && LIMIT=5
966
967         setup_quota_test
968         trap cleanup_quota_test EXIT
969
970         # make sure the system is clean
971         local USED=$(getquota -u $TSTUSR global curspace)
972         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
973
974         # make sure no granted quota on ost1
975         set_ost_qtype "ug" || error "enable ost quota failed"
976         resetquota -u $TSTUSR
977         set_ost_qtype "none" || error "disable ost quota failed"
978
979         local OSTUUID=$(ostuuid_from_index 0)
980         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
981         [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
982                 "$TSTUSR isn't 0."
983
984         # create test file
985         $LFS setstripe $TESTFILE -c 1 -i 0
986         chown $TSTUSR.$TSTUSR $TESTFILE
987
988         echo "Stop ost1..."
989         stop ost1
990
991         echo "Enable quota & set quota limit for $TSTUSR"
992         set_ost_qtype "ug" || error "enable ost quota failed"
993         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
994                 error "set quota failed"
995
996         echo "Start ost1..."
997         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
998         quota_init
999
1000         wait_ost_reint "ug" || error "reintegration failed"
1001
1002         # hardlimit should have been fetched by slave during global
1003         # reintegration, write will exceed quota
1004         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1005                 quota_error u $TSTUSR "write success, but expect EDQUOT"
1006
1007         rm -f $TESTFILE
1008         wait_delete_completed
1009         sync_all_data || true
1010         sleep 3
1011
1012         echo "Stop ost1..."
1013         stop ost1
1014
1015         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1016                 error "clear quota failed"
1017
1018         echo "Start ost1..."
1019         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1020         quota_init
1021
1022         wait_ost_reint "ug" || error "reintegration failed"
1023
1024         # hardlimit should be cleared on slave during reintegration
1025         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1026                 quota_error u $TSTUSR "write error, but expect success"
1027
1028         cleanup_quota_test
1029         resetquota -u $TSTUSR
1030 }
1031 run_test 7a "Quota reintegration (global index)"
1032
1033 # quota reintegration (slave index)
1034 test_7b() {
1035         local LIMIT="100G"
1036         local TESTFILE=$DIR/$tdir/$tfile
1037
1038         setup_quota_test
1039         trap cleanup_quota_test EXIT
1040
1041         # make sure the system is clean
1042         local USED=$(getquota -u $TSTUSR global curspace)
1043         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1044
1045         # make sure no granted quota on ost1
1046         set_ost_qtype "ug" || error "enable ost quota failed"
1047         resetquota -u $TSTUSR
1048         set_ost_qtype "none" || error "disable ost quota failed"
1049
1050         local OSTUUID=$(ostuuid_from_index 0)
1051         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1052         [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1053                 "$TSTUSR isn't 0."
1054
1055         # create test file
1056         $LFS setstripe $TESTFILE -c 1 -i 0
1057         chown $TSTUSR.$TSTUSR $TESTFILE
1058
1059         # consume some space to make sure the granted space will not
1060         # be released during reconciliation
1061         $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1062                 error "consume space failure, expect success"
1063
1064         # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1065         lustre_fail mds 0xa02
1066
1067         set_ost_qtype "ug" || error "enable ost quota failed"
1068         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1069                 error "set quota failed"
1070
1071         # ignore the write error
1072         $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1073
1074         local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1075
1076         lustre_fail mds 0
1077
1078         echo "Restart ost to trigger reintegration..."
1079         stop ost1
1080         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1081         quota_init
1082
1083         wait_ost_reint "ug" || error "reintegration failed"
1084
1085         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1086         [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1087
1088         cleanup_quota_test
1089         resetquota -u $TSTUSR
1090         $SHOW_QUOTA_USER
1091 }
1092 run_test 7b "Quota reintegration (slave index)"
1093
1094 # quota reintegration (restart mds during reintegration)
1095 test_7c() {
1096         local LIMIT=20 # 20M
1097         local TESTFILE=$DIR/$tdir/$tfile
1098
1099         [ "$SLOW" = "no" ] && LIMIT=5
1100
1101         setup_quota_test
1102         trap cleanup_quota_test EXIT
1103
1104         # make sure the system is clean
1105         local USED=$(getquota -u $TSTUSR global curspace)
1106         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1107
1108         set_ost_qtype "none" || error "disable ost quota failed"
1109         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1110                 error "set quota failed"
1111
1112         # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1113         lustre_fail ost 0xa03
1114
1115         # enable ost quota
1116         set_ost_qtype "ug" || error "enable ost quota failed"
1117         # trigger reintegration
1118         local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1119         procf=${procf}quota_slave.force_reint
1120         do_facet ost1 $LCTL set_param $procf=1 ||
1121                 error "force reintegration failed"
1122
1123         echo "Stop mds..."
1124         stop mds1
1125
1126         lustre_fail ost 0
1127
1128         echo "Start mds..."
1129         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1130         quota_init
1131
1132         # wait longer than usual to make sure the reintegration
1133         # is triggered by quota wb thread.
1134         wait_ost_reint "ug" 200 || error "reintegration failed"
1135
1136         # hardlimit should have been fetched by slave during global
1137         # reintegration, write will exceed quota
1138         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1139                 quota_error u $TSTUSR "write success, but expect EDQUOT"
1140
1141         cleanup_quota_test
1142         resetquota -u $TSTUSR
1143 }
1144 run_test 7c "Quota reintegration (restart mds during reintegration)"
1145
1146 # Quota reintegration (Transfer index in multiple bulks)
1147 test_7d(){
1148         local TESTFILE=$DIR/$tdir/$tfile
1149         local TESTFILE1="$DIR/$tdir/$tfile"-1
1150         local limit=20 #20M
1151
1152         setup_quota_test
1153         trap cleanup_quota_test EXIT
1154
1155         set_ost_qtype "none" || error "disable ost quota failed"
1156         $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1157                 error "set quota for $TSTUSR failed"
1158         $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1159                 error "set quota for $TSTUSR2 failed"
1160
1161         #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1162         lustre_fail mds 0x608 0
1163
1164         # enable quota to tirgger reintegration
1165         set_ost_qtype "u" || error "enable ost quota failed"
1166         wait_ost_reint "u" || error "reintegration failed"
1167
1168         lustre_fail mds 0
1169
1170         # hardlimit should have been fetched by slave during global
1171         # reintegration, write will exceed quota
1172         $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1173                 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1174
1175         $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1176                 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1177
1178         cleanup_quota_test
1179         resetquota -u $TSTUSR
1180         resetquota -u $TSTUSR2
1181 }
1182 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1183
1184 # quota reintegration (inode limits)
1185 test_7e() {
1186         [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1187
1188         local ilimit=$((1024 * 2)) # 2k inodes
1189         local TESTFILE=$DIR/${tdir}-1/$tfile
1190
1191         setup_quota_test
1192         trap cleanup_quota_test EXIT
1193
1194         # make sure the system is clean
1195         local USED=$(getquota -u $TSTUSR global curinodes)
1196         [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1197
1198         # make sure no granted quota on mdt1
1199         set_mdt_qtype "ug" || error "enable mdt quota failed"
1200         resetquota -u $TSTUSR
1201         set_mdt_qtype "none" || error "disable mdt quota failed"
1202
1203         local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1204         USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1205         [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1206                 "$TSTUSR isn't 0."
1207
1208         echo "Stop mds${MDSCOUNT}..."
1209         stop mds${MDSCOUNT}
1210
1211         echo "Enable quota & set quota limit for $TSTUSR"
1212         set_mdt_qtype "ug" || error "enable mdt quota failed"
1213         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit  $DIR ||
1214                 error "set quota failed"
1215
1216         echo "Start mds${MDSCOUNT}..."
1217         start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1218         quota_init
1219
1220         wait_mdt_reint "ug" || error "reintegration failed"
1221
1222         echo "create remote dir"
1223         $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1224                 error "create remote dir failed"
1225         chmod 0777 $DIR/${tdir}-1
1226
1227         # hardlimit should have been fetched by slave during global
1228         # reintegration, create will exceed quota
1229         $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1230                 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1231
1232         $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1233         wait_delete_completed
1234         sync_all_data || true
1235
1236         echo "Stop mds${MDSCOUNT}..."
1237         stop mds${MDSCOUNT}
1238
1239         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1240                 error "clear quota failed"
1241
1242         echo "Start mds${MDSCOUNT}..."
1243         start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1244         quota_init
1245
1246         wait_mdt_reint "ug" || error "reintegration failed"
1247
1248         # hardlimit should be cleared on slave during reintegration
1249         $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1250                 quota_error -u $TSTUSR "create failed, expect success"
1251
1252         $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1253         rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1254
1255         cleanup_quota_test
1256         resetquota -u $TSTUSR
1257 }
1258 run_test 7e "Quota reintegration (inode limits)"
1259
1260 # run dbench with quota enabled
1261 test_8() {
1262         local BLK_LIMIT="100g" #100G
1263         local FILE_LIMIT=1000000
1264
1265         setup_quota_test
1266         trap cleanup_quota_test EXIT
1267
1268         set_mdt_qtype "ug" || error "enable mdt quota failed"
1269         set_ost_qtype "ug" || error "enable ost quota failed"
1270
1271         echo "Set enough high limit for user: $TSTUSR"
1272         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1273                 error "set user quota failed"
1274         echo "Set enough high limit for group: $TSTUSR"
1275         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1276                 error "set group quota failed"
1277
1278         local duration=""
1279         [ "$SLOW" = "no" ] && duration=" -t 120"
1280         $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1281                 quota_error a $TSTUSR "dbench failed!"
1282
1283         cleanup_quota_test
1284         resetquota -u $TSTUSR
1285         resetquota -g $TSTUSR
1286 }
1287 run_test 8 "Run dbench with quota enabled"
1288
1289 # this check is just for test_9
1290 OST0_MIN=4900000 #4.67G
1291
1292 check_whether_skip () {
1293         local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1294         log "OST0_SIZE: $OST0_SIZE  required: $OST0_MIN"
1295         if [ $OST0_SIZE -lt $OST0_MIN ]; then
1296                 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1297                 return 0
1298         else
1299                 return 1
1300         fi
1301 }
1302
1303 # run for fixing bug10707, it needs a big room. test for 64bit
1304 test_9() {
1305         local filesize=$((1024 * 9 / 2)) # 4.5G
1306
1307         check_whether_skip && return 0
1308
1309         setup_quota_test
1310         trap cleanup_quota_test EXIT
1311
1312         set_ost_qtype "ug" || error "enable ost quota failed"
1313
1314         local TESTFILE="$DIR/$tdir/$tfile-0"
1315         local BLK_LIMIT=100G #100G
1316         local FILE_LIMIT=1000000
1317
1318         echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1319
1320         log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1321                 "for user: $TSTUSR"
1322         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1323                 error "set user quota failed"
1324
1325         log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1326                 "for group: $TSTUSR"
1327         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1328                 error "set group quota failed"
1329
1330         quota_show_check a u $TSTUSR
1331         quota_show_check a g $TSTUSR
1332
1333         echo "Create test file"
1334         $LFS setstripe $TESTFILE -c 1 -i 0
1335         chown $TSTUSR.$TSTUSR $TESTFILE
1336
1337         log "Write the big file of 4.5G ..."
1338         $RUNAS $DD of=$TESTFILE count=$filesize ||
1339                 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1340
1341         $SHOW_QUOTA_USER
1342         $SHOW_QUOTA_GROUP
1343
1344         cleanup_quota_test
1345         resetquota -u $TSTUSR
1346         resetquota -g $TSTUSR
1347
1348         $SHOW_QUOTA_USER
1349         $SHOW_QUOTA_GROUP
1350 }
1351 run_test 9 "Block limit larger than 4GB (b10707)"
1352
1353 test_10() {
1354         local TESTFILE=$DIR/$tdir/$tfile
1355
1356         setup_quota_test
1357         trap cleanup_quota_test EXIT
1358
1359         # set limit to root user should fail
1360         $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1361                 error "set limit for root user successfully, expect failure"
1362         $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1363                 error "set limit for root group successfully, expect failure"
1364
1365         # root user can overrun quota
1366         set_ost_qtype "ug" || "enable ost quota failed"
1367
1368         $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1369                 error "set quota failed"
1370         quota_show_check b u $TSTUSR
1371
1372         $LFS setstripe $TESTFILE -c 1
1373         chown $TSTUSR.$TSTUSR $TESTFILE
1374
1375         runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1376                 error "write failure, expect success"
1377
1378         cleanup_quota_test
1379         resetquota -u $TSTUSR
1380 }
1381 run_test 10 "Test quota for root user"
1382
1383 test_11() {
1384         local TESTFILE=$DIR/$tdir/$tfile
1385         setup_quota_test
1386         trap cleanup_quota_test EXIT
1387
1388         set_mdt_qtype "ug" || "enable mdt quota failed"
1389         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1390                 error "set quota failed"
1391
1392         touch "$TESTFILE"-0
1393         touch "$TESTFILE"-1
1394
1395         chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1396         chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1397
1398         $SHOW_QUOTA_USER
1399         local USED=$(getquota -u $TSTUSR global curinodes)
1400         [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1401
1402         cleanup_quota_test
1403         resetquota -u $TSTUSR
1404 }
1405 run_test 11 "Chown/chgrp ignores quota"
1406
1407 test_12a() {
1408         [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1409
1410         local blimit=22 # 22M
1411         local blk_cnt=$((blimit - 5))
1412         local TESTFILE0="$DIR/$tdir/$tfile"-0
1413         local TESTFILE1="$DIR/$tdir/$tfile"-1
1414
1415         setup_quota_test
1416         trap cleanup_quota_test EXIT
1417
1418         set_ost_qtype "u" || "enable ost quota failed"
1419         quota_show_check b u $TSTUSR
1420
1421         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1422                 error "set quota failed"
1423
1424         $LFS setstripe $TESTFILE0 -c 1 -i 0
1425         $LFS setstripe $TESTFILE1 -c 1 -i 1
1426         chown $TSTUSR.$TSTUSR $TESTFILE0
1427         chown $TSTUSR.$TSTUSR $TESTFILE1
1428
1429         echo "Write to ost0..."
1430         $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1431                 quota_error a $TSTUSR "dd failed"
1432
1433         echo "Write to ost1..."
1434         $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1435                 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1436
1437         echo "Free space from ost0..."
1438         rm -f $TESTFILE0
1439         wait_delete_completed
1440         sync_all_data || true
1441
1442         echo "Write to ost1 after space freed from ost0..."
1443         $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1444                 quota_error a $TSTUSR "rebalancing failed"
1445
1446         cleanup_quota_test
1447         resetquota -u $TSTUSR
1448 }
1449 run_test 12a "Block quota rebalancing"
1450
1451 test_12b() {
1452         [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1453
1454         local ilimit=$((1024 * 2)) # 2k inodes
1455         local TESTFILE0=$DIR/$tdir/$tfile
1456         local TESTFILE1=$DIR/${tdir}-1/$tfile
1457
1458         setup_quota_test
1459         trap cleanup_quota_test EXIT
1460
1461         $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1462         chmod 0777 $DIR/${tdir}-1
1463
1464         set_mdt_qtype "u" || "enable mdt quota failed"
1465         quota_show_check f u $TSTUSR
1466
1467         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1468                 error "set quota failed"
1469
1470         echo "Create $ilimit files on mdt0..."
1471         $RUNAS createmany -m $TESTFILE0 $ilimit ||
1472                 quota_error u $TSTUSR "create failed, but expect success"
1473
1474         echo "Create files on mdt1..."
1475         $RUNAS createmany -m $TESTFILE1 1 &&
1476                 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1477
1478         echo "Free space from mdt0..."
1479         $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1480         wait_delete_completed
1481         sync_all_data || true
1482
1483         echo "Create files on mdt1 after space freed from mdt0..."
1484         $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1485                 quota_error a $TSTUSR "rebalancing failed"
1486
1487         $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1488                 error "unlink mdt1 files failed"
1489         rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1490
1491         cleanup_quota_test
1492         resetquota -u $TSTUSR
1493 }
1494 run_test 12b "Inode quota rebalancing"
1495
1496 test_13(){
1497         local TESTFILE=$DIR/$tdir/$tfile
1498         # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1499         local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1500
1501         setup_quota_test
1502         trap cleanup_quota_test EXIT
1503
1504         set_ost_qtype "u" || "enable ost quota failed"
1505         quota_show_check b u $TSTUSR
1506
1507         $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1508                 error "set quota failed"
1509         $LFS setstripe $TESTFILE -c 1 -i 0
1510         chown $TSTUSR.$TSTUSR $TESTFILE
1511
1512         # clear the locks in cache first
1513         do_facet ost1 $LCTL set_param -n $procf=clear
1514         local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1515         [ $nlock -eq 0 ] || error "$nlock cached locks"
1516
1517         # write to acquire the per-ID lock
1518         $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1519                 quota_error a $TSTUSR "dd failed"
1520
1521         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1522         [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1523
1524         # clear quota doesn't trigger per-ID lock cancellation
1525         resetquota -u $TSTUSR
1526         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1527         [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1528
1529         # clear the per-ID lock
1530         do_facet ost1 $LCTL set_param -n $procf=clear
1531         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1532         [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1533
1534         # spare quota should be released
1535         local OSTUUID=$(ostuuid_from_index 0)
1536         local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1537         local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1538         [ $limit -le $space ] ||
1539                 error "spare quota isn't released, limit:$limit, space:$space"
1540
1541         cleanup_quota_test
1542 }
1543 run_test 13 "Cancel per-ID lock in the LRU list"
1544
1545 test_15(){
1546         local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1547
1548         wait_delete_completed
1549         sync_all_data || true
1550
1551         # test for user
1552         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1553                 error "set user quota failed"
1554         local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1555         [ $TOTAL_LIMIT -eq $LIMIT ] ||
1556                 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1557         resetquota -u $TSTUSR
1558
1559         # test for group
1560         $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1561                 error "set group quota failed"
1562         TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1563         [ $TOTAL_LIMIT -eq $LIMIT ] ||
1564                 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1565         resetquota -g $TSTUSR
1566 }
1567 run_test 15 "Set over 4T block quota"
1568
1569 test_17sub() {
1570         local err_code=$1
1571         local BLKS=1    # 1M less than limit
1572         local TESTFILE=$DIR/$tdir/$tfile
1573
1574         setup_quota_test
1575         trap cleanup_quota_test EXIT
1576
1577         # make sure the system is clean
1578         local USED=$(getquota -u $TSTUSR global curspace)
1579         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1580
1581         set_ost_qtype "ug" || error "enable ost quota failed"
1582         # make sure no granted quota on ost
1583         resetquota -u $TSTUSR
1584         $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1585                 error "set quota failed"
1586
1587         quota_show_check b u $TSTUSR
1588
1589         #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1590         lustre_fail mds 0xa04 $err_code
1591
1592         # write in background
1593         $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1594         local DDPID=$!
1595
1596         sleep 2
1597         # write should be blocked and never finished
1598         if ! ps -p $DDPID  > /dev/null 2>&1; then
1599                 lustre_fail mds 0 0
1600                 quota_error u $TSTUSR "write finished incorrectly!"
1601         fi
1602
1603         lustre_fail mds 0 0
1604
1605         local count=0
1606         local timeout=30
1607         while [ true ]; do
1608                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1609                 count=$((count+1))
1610                 if [ $count -gt $timeout ]; then
1611                         quota_error u $TSTUSR "dd is not finished!"
1612                 fi
1613                 sleep 1
1614         done
1615
1616         sync; sync_all_data || true
1617
1618         USED=$(getquota -u $TSTUSR global curspace)
1619         [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1620                 "Used space(${USED}K) is less than ${BLKS}M"
1621
1622         cleanup_quota_test
1623         resetquota -u $TSTUSR
1624 }
1625
1626 # DQACQ return recoverable error
1627 test_17() {
1628         echo "DQACQ return -ENOLCK"
1629         #define ENOLCK  37
1630         test_17sub 37 || error "Handle -ENOLCK failed"
1631
1632         echo "DQACQ return -EAGAIN"
1633         #define EAGAIN  11
1634         test_17sub 11 || error "Handle -EAGAIN failed"
1635
1636         echo "DQACQ return -ETIMEDOUT"
1637         #define ETIMEDOUT 110
1638         test_17sub 110 || error "Handle -ETIMEDOUT failed"
1639
1640         echo "DQACQ return -ENOTCONN"
1641         #define ENOTCONN 107
1642         test_17sub 107 || error "Handle -ENOTCONN failed"
1643 }
1644
1645 run_test 17 "DQACQ return recoverable error"
1646
1647 test_18_sub () {
1648         local io_type=$1
1649         local blimit="200m" # 200M
1650         local TESTFILE="$DIR/$tdir/$tfile"
1651
1652         setup_quota_test
1653         trap cleanup_quota_test EXIT
1654
1655         set_ost_qtype "u" || error "enable ost quota failed"
1656         log "User quota (limit: $blimit)"
1657         $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1658                 error "set quota failed"
1659         quota_show_check b u $TSTUSR
1660
1661         $LFS setstripe $TESTFILE -i 0 -c 1
1662         chown $TSTUSR.$TSTUSR $TESTFILE
1663
1664         local timeout=$(sysctl -n lustre.timeout)
1665
1666         if [ $io_type = "directio" ]; then
1667                 log "Write 100M (directio) ..."
1668                 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1669         else
1670                 log "Write 100M (buffered) ..."
1671                 $RUNAS $DD of=$TESTFILE count=100 &
1672         fi
1673         local DDPID=$!
1674
1675         replay_barrier $SINGLEMDS
1676         log "Fail mds for $((2 * timeout)) seconds"
1677         fail $SINGLEMDS $((2 * timeout))
1678
1679         local count=0
1680         if at_is_enabled; then
1681                 timeout=$(at_max_get mds)
1682         else
1683                 timeout=$(lctl get_param -n timeout)
1684         fi
1685
1686         while [ true ]; do
1687                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1688                 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1689                         log "it took $count second"
1690                 fi
1691                 sleep 1
1692         done
1693
1694         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1695         sync
1696         cancel_lru_locks mdc
1697         cancel_lru_locks osc
1698         $SHOW_QUOTA_USER
1699
1700         local testfile_size=$(stat -c %s $TESTFILE)
1701         if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1702                 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1703                         "got ${testfile_size}. Verifying file failed!"
1704         fi
1705         cleanup_quota_test
1706         resetquota -u $TSTUSR
1707 }
1708
1709 # test when mds does failover, the ost still could work well
1710 # this test shouldn't trigger watchdog b=14840
1711 test_18() {
1712         # Clear dmesg so watchdog is not triggered by previous
1713         # test output
1714         do_facet ost1 dmesg -c > /dev/null
1715
1716         test_18_sub normal
1717         test_18_sub directio
1718
1719         # check if watchdog is triggered
1720         do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1721         local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1722                         { print; }' $TMP/lustre-log-${TESTNAME}.log)
1723         [ -z "$watchdog" ] || error "$watchdog"
1724         rm -f $TMP/lustre-log-${TESTNAME}.log
1725 }
1726 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1727
1728 test_19() {
1729         local blimit=5 # 5M
1730         local TESTFILE=$DIR/$tdir/$tfile
1731
1732         setup_quota_test
1733         trap cleanup_quota_test EXIT
1734
1735         set_ost_qtype "ug" || error "enable ost quota failed"
1736
1737         # bind file to a single OST
1738         $LFS setstripe -c 1 $TESTFILE
1739         chown $TSTUSR.$TSTUSR $TESTFILE
1740
1741         echo "Set user quota (limit: "$blimit"M)"
1742         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1743                 error "set user quota failed"
1744         quota_show_check b u $TSTUSR
1745         echo "Update quota limits"
1746         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1747                 error "set group quota failed"
1748         quota_show_check b u $TSTUSR
1749
1750         # first wirte might be cached
1751         $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1752         cancel_lru_locks osc
1753         $SHOW_QUOTA_USER
1754         $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1755                 quota_error u $TSTUSR "Write success, expect failure"
1756         $SHOW_QUOTA_USER
1757
1758         cleanup_quota_test
1759         resetquota -u $TSTUSR
1760 }
1761 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1762
1763 test_20() { # b15754
1764         local LSTR=(2g 1t 4k 3m) # limits strings
1765         # limits values
1766         local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1767
1768         resetquota -u $TSTUSR
1769
1770         $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1771                 $MOUNT || error "could not set quota limits"
1772         $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1773                                 --inode-softlimit ${LSTR[2]} \
1774                                 --inode-hardlimit ${LSTR[3]} \
1775                                 $MOUNT || error "could not set quota limits"
1776
1777         [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1778                 error "bsoftlimit was not set properly"
1779         [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1780                 error "bhardlimit was not set properly"
1781         [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1782                 error "isoftlimit was not set properly"
1783         [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1784                 error "ihardlimit was not set properly"
1785
1786         resetquota -u $TSTUSR
1787 }
1788 run_test 20 "Test if setquota specifiers work properly (b15754)"
1789
1790 test_21_sub() {
1791         local testfile=$1
1792         local blk_number=$2
1793         local seconds=$3
1794
1795         local time=$(($(date +%s) + seconds))
1796         while [ $(date +%s) -lt $time ]; do
1797                 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1798         done
1799 }
1800
1801 # run for fixing bug16053, setquota shouldn't fail when writing and
1802 # deleting are happening
1803 test_21() {
1804         local TESTFILE="$DIR/$tdir/$tfile"
1805         local BLIMIT=10 # 10G
1806         local ILIMIT=1000000
1807
1808         setup_quota_test
1809         trap cleanup_quota_test EXIT
1810
1811         set_ost_qtype "ug" || error "Enable ost quota failed"
1812
1813         log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1814         $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1815                 error "set user quota failed"
1816         log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1817         $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1818                 error "set group quota failed"
1819
1820         # repeat writing on a 1M file
1821         test_21_sub ${TESTFILE}_1 1 30 &
1822         local DDPID1=$!
1823         # repeat writing on a 128M file
1824         test_21_sub ${TESTFILE}_2 128 30 &
1825         local DDPID2=$!
1826
1827         local time=$(($(date +%s) + 30))
1828         local i=1
1829         while [ $(date +%s) -lt $time ]; do
1830                 log "Set quota for $i times"
1831                 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1832                         -I $((ILIMIT + i)) $MOUNT ||
1833                                 error "Set user quota failed"
1834                 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1835                         -I $((ILIMIT + i)) $MOUNT ||
1836                                 error "Set group quota failed"
1837                 i=$((i+1))
1838                 sleep 1
1839         done
1840
1841         local count=0
1842         while [ true ]; do
1843                 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1844                 count=$((count+1))
1845                 if [ $count -gt 60 ]; then
1846                         quota_error a $TSTUSR "dd should be finished!"
1847                 fi
1848                 sleep 1
1849         done
1850         echo "(dd_pid=$DDPID1, time=$count)successful"
1851
1852         count=0
1853         while [ true ]; do
1854                 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1855                 count=$((count+1))
1856                 if [ $count -gt 60 ]; then
1857                         quota_error a $TSTUSR "dd should be finished!"
1858                 fi
1859                 sleep 1
1860         done
1861         echo "(dd_pid=$DDPID2, time=$count)successful"
1862
1863         cleanup_quota_test
1864         resetquota -u $TSTUSR
1865         resetquota -g $TSTUSR
1866 }
1867 run_test 21 "Setquota while writing & deleting (b16053)"
1868
1869 # enable/disable quota enforcement permanently
1870 test_22() {
1871         echo "Set both mdt & ost quota type as ug"
1872         set_mdt_qtype "ug" || error "enable mdt quota failed"
1873         set_ost_qtype "ug" || error "enable ost quota failed"
1874
1875         echo "Restart..."
1876         stopall
1877         mount
1878         setupall
1879
1880         echo "Verify if quota is enabled"
1881         local qtype=$(mdt_quota_type)
1882         [ $qtype != "ug" ] && error "mdt quota setting is lost"
1883         qtype=$(ost_quota_type)
1884         [ $qtype != "ug" ] && error "ost quota setting is lost"
1885
1886         echo "Set both mdt & ost quota type as none"
1887         set_mdt_qtype "none" || error "disable mdt quota failed"
1888         set_ost_qtype "none" || error "disable ost quota failed"
1889
1890         echo "Restart..."
1891         stopall
1892         mount
1893         setupall
1894         quota_init
1895
1896         echo "Verify if quota is disabled"
1897         qtype=$(mdt_quota_type)
1898         [ $qtype != "none" ] && error "mdt quota setting is lost"
1899         qtype=$(ost_quota_type)
1900         [ $qtype != "none" ] && error "ost quota setting is lost"
1901
1902         return 0
1903 }
1904 run_test 22 "enable/disable quota by 'lctl conf_param'"
1905
1906 test_23_sub() {
1907         local TESTFILE="$DIR/$tdir/$tfile"
1908         local LIMIT=$1
1909
1910         setup_quota_test
1911         trap cleanup_quota_test EXIT
1912
1913         set_ost_qtype "ug" || error "Enable ost quota failed"
1914
1915         # test for user
1916         log "User quota (limit: $LIMIT MB)"
1917         $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1918                 error "set quota failed"
1919         quota_show_check b u $TSTUSR
1920
1921         $LFS setstripe $TESTFILE -c 1 -i 0
1922         chown $TSTUSR.$TSTUSR $TESTFILE
1923
1924         log "Step1: trigger EDQUOT with O_DIRECT"
1925         log "Write half of file"
1926         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1927                 quota_error u $TSTUSR "(1) Write failure, expect success." \
1928                         "limit=$LIMIT"
1929         log "Write out of block quota ..."
1930         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1931                 oflag=direct conv=notrunc &&
1932                 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1933                         "limit=$LIMIT"
1934         log "Step1: done"
1935
1936         log "Step2: rewrite should succeed"
1937         $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1938                 quota_error u $TSTUSR "(3) Write failure, expect success." \
1939                         "limit=$LIMIT"
1940         log "Step2: done"
1941
1942         cleanup_quota_test
1943
1944         local OST0_UUID=$(ostuuid_from_index 0)
1945         local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1946         [ $OST0_QUOTA_USED -ne 0 ] &&
1947                 ($SHOW_QUOTA_USER; \
1948                 quota_error u $TSTUSR "quota isn't released")
1949         $SHOW_QUOTA_USER
1950         resetquota -u $TSTUSR
1951 }
1952
1953 test_23() {
1954         local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1955         check_whether_skip && return 0
1956         log "run for 4MB test file"
1957         test_23_sub 4
1958
1959         OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1960         check_whether_skip && return 0
1961         log "run for 40MB test file"
1962         test_23_sub 40
1963 }
1964 run_test 23 "Quota should be honored with directIO (b16125)"
1965
1966 test_24() {
1967         local blimit=5 # 5M
1968         local TESTFILE="$DIR/$tdir/$tfile"
1969
1970         setup_quota_test
1971         trap cleanup_quota_test EXIT
1972
1973         set_ost_qtype "ug" || error "enable ost quota failed"
1974
1975         # bind file to a single OST
1976         $LFS setstripe -c 1 $TESTFILE
1977         chown $TSTUSR.$TSTUSR $TESTFILE
1978
1979         echo "Set user quota (limit: "$blimit"M)"
1980         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1981                 error "set quota failed"
1982
1983         # overrun quota by root user
1984         runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1985                 error "write failure, expect success"
1986         cancel_lru_locks osc
1987         sync_all_data || true
1988
1989         $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1990
1991         cleanup_quota_test
1992         resetquota -u $TSTUSR
1993 }
1994 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1995
1996 test_27a() { # b19612
1997         $LFS quota $TSTUSR $DIR &&
1998                 error "lfs succeeded with no type, but should have failed"
1999         $LFS setquota $TSTUSR $DIR &&
2000                 error "lfs succeeded with no type, but should have failed"
2001         return 0
2002 }
2003 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2004
2005 test_27b() { # b20200
2006         $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2007                 error "lfs setquota failed with uid argument"
2008         $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2009                 error "lfs stequota failed with gid argument"
2010         $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2011         $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2012         resetquota -u $TSTUSR
2013         resetquota -g $TSTUSR
2014         return 0
2015 }
2016 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2017
2018 test_27c() {
2019         local limit
2020
2021         $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2022                 error "lfs setquota failed"
2023
2024         limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2025         [ $limit != "30M" ] && error "softlimit isn't human-readable"
2026         limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2027         [ $limit != "3T" ] && error "hardlimit isn't human-readable"
2028
2029         $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2030                 error "total allocated inode/block limit not printed"
2031
2032         resetquota -u $TSTUSR
2033 }
2034 run_test 27c "lfs quota should support human-readable output"
2035
2036 test_30() {
2037         local output
2038         local LIMIT=4 # 4MB
2039         local TESTFILE="$DIR/$tdir/$tfile"
2040         local GRACE=10
2041
2042         setup_quota_test
2043         trap cleanup_quota_test EXIT
2044
2045         set_ost_qtype "u" || error "enable ost quota failed"
2046
2047         $LFS setstripe $TESTFILE -i 0 -c 1
2048         chown $TSTUSR.$TSTUSR $TESTFILE
2049
2050         $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2051                 $MAX_IQ_TIME $DIR || error "set grace time failed"
2052         $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2053                 error "set quota failed"
2054         $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2055         cancel_lru_locks osc
2056         sleep $GRACE
2057         $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2058         # over-quota flag has not yet settled since we do not trigger async
2059         # events based on grace time period expiration
2060         $SHOW_QUOTA_USER
2061         $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
2062         cancel_lru_locks osc
2063         # now over-quota flag should be settled and further writes should fail
2064         $SHOW_QUOTA_USER
2065         $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
2066                 error "grace times were reset"
2067         # cleanup
2068         cleanup_quota_test
2069         resetquota -u $TSTUSR
2070         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2071                 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2072 }
2073 run_test 30 "Hard limit updates should not reset grace times"
2074
2075 # basic usage tracking for user & group
2076 test_33() {
2077         local INODES=10 # 10 files
2078         local BLK_CNT=2 # of 2M each
2079         local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2080
2081         setup_quota_test
2082         trap cleanup_quota_test EXIT
2083
2084         # make sure the system is clean
2085         local USED=$(getquota -u $TSTID global curspace)
2086         [ $USED -ne 0 ] &&
2087                 error "Used space ($USED) for user $TSTID isn't 0."
2088         USED=$(getquota -g $TSTID global curspace)
2089         [ $USED -ne 0 ] &&
2090                 error "Used space ($USED) for group $TSTID isn't 0."
2091
2092         echo "Write files..."
2093         for i in `seq 0 $INODES`; do
2094                 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2095                         error "write failed"
2096                 echo "Iteration $i/$INODES completed"
2097         done
2098         cancel_lru_locks osc
2099         sync; sync_all_data || true
2100
2101         echo "Verify disk usage after write"
2102         USED=$(getquota -u $TSTID global curspace)
2103         [ $USED -lt $TOTAL_BLKS ] &&
2104                 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2105         USED=$(getquota -g $TSTID global curspace)
2106         [ $USED -lt $TOTAL_BLKS ] &&
2107                 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2108
2109         echo "Verify inode usage after write"
2110         USED=$(getquota -u $TSTID global curinodes)
2111         [ $USED -lt $INODES ] &&
2112                 error "Used inode for user $TSTID is $USED, expected $INODES"
2113         USED=$(getquota -g $TSTID global curinodes)
2114         [ $USED -lt $INODES ] &&
2115                 error "Used inode for group $TSTID is $USED, expected $INODES"
2116
2117         cleanup_quota_test
2118
2119         echo "Verify disk usage after delete"
2120         USED=$(getquota -u $TSTID global curspace)
2121         [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2122         USED=$(getquota -u $TSTID global curinodes)
2123         [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2124         USED=$(getquota -g $TSTID global curspace)
2125         [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2126         USED=$(getquota -g $TSTID global curinodes)
2127         [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2128 }
2129 run_test 33 "Basic usage tracking for user & group"
2130
2131 # usage transfer test for user & group
2132 test_34() {
2133         local BLK_CNT=2 # 2MB
2134
2135         setup_quota_test
2136         trap cleanup_quota_test EXIT
2137
2138         # make sure the system is clean
2139         local USED=$(getquota -u $TSTID global curspace)
2140         [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2141         USED=$(getquota -g $TSTID global curspace)
2142         [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2143
2144         echo "Write file..."
2145         $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2146                 error "write failed"
2147         cancel_lru_locks osc
2148         sync; sync_all_data || true
2149
2150         echo "chown the file to user $TSTID"
2151         chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2152
2153         echo "Wait for setattr on objects finished..."
2154         wait_delete_completed
2155
2156         BLK_CNT=$((BLK_CNT * 1024))
2157
2158         echo "Verify disk usage for user $TSTID"
2159         USED=$(getquota -u $TSTID global curspace)
2160         [ $USED -lt $BLK_CNT ] &&
2161                 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2162         USED=$(getquota -u $TSTID global curinodes)
2163         [ $USED -ne 1 ] &&
2164                 error "Used inodes for user $TSTID is $USED, expected 1"
2165
2166         echo "chgrp the file to group $TSTID"
2167         chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2168
2169         echo "Wait for setattr on objects finished..."
2170         wait_delete_completed
2171
2172         echo "Verify disk usage for group $TSTID"
2173         USED=$(getquota -g $TSTID global curspace)
2174         [ $USED -ge $BLK_CNT ] ||
2175                 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2176         USED=$(getquota -g $TSTID global curinodes)
2177         [ $USED -eq 1 ] ||
2178                 error "Used inodes for group $TSTID is $USED, expected 1"
2179
2180         cleanup_quota_test
2181 }
2182 run_test 34 "Usage transfer for user & group"
2183
2184 # usage is still accessible across restart
2185 test_35() {
2186         local BLK_CNT=2 # 2 MB
2187
2188         setup_quota_test
2189         trap cleanup_quota_test EXIT
2190
2191         echo "Write file..."
2192         $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2193                 error "write failed"
2194         cancel_lru_locks osc
2195         sync; sync_all_data || true
2196
2197         echo "Save disk usage before restart"
2198         local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2199         [ $ORIG_USR_SPACE -eq 0 ] &&
2200                 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2201         local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2202         [ $ORIG_USR_INODES -eq 0 ] &&
2203                 error "Used inodes for user $TSTID is 0, expected 1"
2204         echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2205         local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2206         [ $ORIG_GRP_SPACE -eq 0 ] &&
2207                 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2208         local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2209         [ $ORIG_GRP_INODES -eq 0 ] &&
2210                 error "Used inodes for group $TSTID is 0, expected 1"
2211         echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2212
2213         log "Restart..."
2214         local ORIG_REFORMAT=$REFORMAT
2215         REFORMAT=""
2216         cleanup_and_setup_lustre
2217         REFORMAT=$ORIG_REFORMAT
2218         quota_init
2219
2220         echo "Verify disk usage after restart"
2221         local USED=$(getquota -u $TSTID global curspace)
2222         [ $USED -eq $ORIG_USR_SPACE ] ||
2223                 error "Used space for user $TSTID changed from " \
2224                         "$ORIG_USR_SPACE to $USED"
2225         USED=$(getquota -u $TSTID global curinodes)
2226         [ $USED -eq $ORIG_USR_INODES ] ||
2227                 error "Used inodes for user $TSTID changed from " \
2228                         "$ORIG_USR_INODES to $USED"
2229         USED=$(getquota -g $TSTID global curspace)
2230         [ $USED -eq $ORIG_GRP_SPACE ] ||
2231                 error "Used space for group $TSTID changed from " \
2232                         "$ORIG_GRP_SPACE to $USED"
2233         USED=$(getquota -g $TSTID global curinodes)
2234         [ $USED -eq $ORIG_GRP_INODES ] ||
2235                 error "Used inodes for group $TSTID changed from " \
2236                         "$ORIG_GRP_INODES to $USED"
2237
2238         # check if the vfs_dq_init() is called before writing
2239         echo "Append to the same file..."
2240         $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2241                 error "write failed"
2242         cancel_lru_locks osc
2243         sync; sync_all_data || true
2244
2245         echo "Verify space usage is increased"
2246         USED=$(getquota -u $TSTID global curspace)
2247         [ $USED -gt $ORIG_USR_SPACE ] ||
2248                 error "Used space for user $TSTID isn't increased" \
2249                         "orig:$ORIG_USR_SPACE, now:$USED"
2250         USED=$(getquota -g $TSTID global curspace)
2251         [ $USED -gt $ORIG_GRP_SPACE ] ||
2252                 error "Used space for group $TSTID isn't increased" \
2253                         "orig:$ORIG_GRP_SPACE, now:$USED"
2254
2255         cleanup_quota_test
2256 }
2257 run_test 35 "Usage is still accessible across reboot"
2258
2259 # test migrating old amdin quota files (in Linux quota file format v2) into new
2260 # quota global index (in IAM format)
2261 test_36() {
2262         [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
2263                 skip "skipping migration test" && return
2264
2265         # get the mdt0 device name
2266         local mdt0_node=$(facet_active_host $SINGLEMDS)
2267         local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
2268
2269         echo "Reformat..."
2270         formatall
2271
2272         echo "Copy admin quota files into MDT0..."
2273         local mntpt=$(facet_mntpt $SINGLEMDS)
2274         local mdt0_fstype=$(facet_fstype $SINGLEMDS)
2275         local opt
2276         if ! do_node $mdt0_node test -b $mdt0_fstype; then
2277                 opt="-o loop"
2278         fi
2279         echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
2280         do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
2281         do_node $mdt0_node mkdir $mntpt/OBJECTS
2282         do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
2283         do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
2284         do_node $mdt0_node umount -f $mntpt
2285
2286         echo "Setup all..."
2287         setupall
2288
2289         echo "Verify global limits..."
2290         local id_cnt
2291         local limit
2292
2293         local proc="qmt.*.md-0x0.glb-usr"
2294         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2295         [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
2296         limit=$(getquota -u 1 global isoftlimit)
2297         [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2298         limit=$(getquota -u 1 global ihardlimit)
2299         [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2300
2301         proc="qmt.*.md-0x0.glb-grp"
2302         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2303         [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
2304         limit=$(getquota -g 1 global isoftlimit)
2305         [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2306         limit=$(getquota -g 1 global ihardlimit)
2307         [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2308
2309         proc=" qmt.*.dt-0x0.glb-usr"
2310         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2311         [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2312         limit=$(getquota -u 60001 global bsoftlimit)
2313         [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2314         limit=$(getquota -u 60001 global bhardlimit)
2315         [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2316
2317         proc="qmt.*.dt-0x0.glb-grp"
2318         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2319         [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2320         limit=$(getquota -g 60001 global bsoftlimit)
2321         [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2322         limit=$(getquota -g 60001 global bhardlimit)
2323         [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2324
2325         echo "Cleanup..."
2326         formatall
2327         setupall
2328 }
2329 run_test 36 "Migrate old admin files into new global indexes"
2330
2331 quota_fini()
2332 {
2333         do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2334 }
2335 quota_fini
2336
2337 cd $ORIG_PWD
2338 complete $SECONDS
2339 check_and_cleanup_lustre
2340 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2341 exit_status