Whamcloud - gitweb
LU-6836 tests: Skip sanity-quota test 4a for ZFS
[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 # Does e2fsprogs support quota feature?
47 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
48         do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
49                 grep -q 'quota'"; then
50         skip "e2fsprogs doesn't support quota" && exit 0
51 fi
52
53 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
54 # bug number for skipped test:        LU-2836 LU-6836 LU-2836 LU-2059
55         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3       4a      6       7d"
56 # bug number for skipped test:        LU-5638
57         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
58 # bug number:     LU-2887
59         ZFS_SLOW="12a"
60 fi
61
62 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
63
64 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65
66 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
67
68 DIR=${DIR:-$MOUNT}
69 DIR2=${DIR2:-$MOUNT2}
70
71 QUOTA_AUTO_OLD=$QUOTA_AUTO
72 export QUOTA_AUTO=0
73
74 check_and_setup_lustre
75
76 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
77 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
78
79 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
80 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
81 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
82 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
83 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
84 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
85 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
86 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
87
88 build_test_filter
89
90 lustre_fail() {
91         local fail_node=$1
92         local fail_loc=$2
93         local fail_val=${3:-0}
94         local NODES=
95
96         case $fail_node in
97         mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
98         mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
99         ost) NODES="$(comma_list $(osts_nodes))";;
100         esac
101
102         do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
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 -g $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 grace=$3
684         local TIMER=$(($grace * 3 / 2))
685
686         setup_quota_test
687         trap cleanup_quota_test EXIT
688
689         echo "Create files to exceed soft limit"
690         $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
691                 quota_error a $TSTUSR "create failure, but expect success"
692         local trigger_time=$(date +%s)
693
694         sync_all_data || true
695
696         local cur_time=$(date +%s)
697         [ $(($cur_time - $trigger_time)) -ge $grace ] &&
698                 error "Passed grace time $grace, $trigger_time, $cur_time"
699
700         echo "Create file before timer goes off"
701         $RUNAS touch ${TESTFILE}_before ||
702                 quota_error a $TSTUSR "failed create before timer expired," \
703                         "but expect success. $trigger_time, $cur_time"
704         sync_all_data || true
705
706         echo "Sleep $TIMER seconds ..."
707         sleep $TIMER
708
709         $SHOW_QUOTA_USER
710         $SHOW_QUOTA_GROUP
711         $SHOW_QUOTA_INFO_USER
712         $SHOW_QUOTA_INFO_GROUP
713
714         echo "Create file after timer goes off"
715         # There is a window that space is accounted in the quota usage but
716         # hasn't been decreased from the pending write, if we acquire quota
717         # in this window, we'll acquire more than we needed.
718         $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
719         sync_all_data || true
720         $RUNAS touch ${TESTFILE}_after_3 &&
721                 quota_error a $TSTUSR "create after timer expired," \
722                         "but expect EDQUOT"
723         sync_all_data || true
724
725         $SHOW_QUOTA_USER
726         $SHOW_QUOTA_GROUP
727         $SHOW_QUOTA_INFO_USER
728         $SHOW_QUOTA_INFO_GROUP
729
730         echo "Unlink files to stop timer"
731         find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
732         wait_delete_completed
733
734         echo "Create file"
735         $RUNAS touch ${TESTFILE}_xxx ||
736                 quota_error a $TSTUSR "touch after timer stop failure," \
737                         "but expect success"
738         sync_all_data || true
739
740         # cleanup
741         cleanup_quota_test
742 }
743
744 # file soft limit
745 test_4a() {
746         local LIMIT=10 # inodes
747         local TESTFILE=$DIR/$tdir/$tfile-0
748         local GRACE=12
749
750         set_mdt_qtype "ug" || error "enable mdt quota failed"
751
752         echo "User quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
753         # make sure the system is clean
754         local USED=$(getquota -u $TSTUSR global curinodes)
755         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
756
757         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
758                 $GRACE $DIR || error "set user grace time failed"
759         $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
760                 error "set user quota failed"
761
762         test_file_soft $TESTFILE $LIMIT $GRACE
763         resetquota -u $TSTUSR
764
765         echo "Group quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
766         # make sure the system is clean
767         USED=$(getquota -g $TSTUSR global curinodes)
768         [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
769
770         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
771                 $GRACE $DIR || error "set group grace time failed"
772         $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
773                 error "set group quota failed"
774         TESTFILE=$DIR/$tdir/$tfile-1
775
776         test_file_soft $TESTFILE $LIMIT $GRACE
777         resetquota -g $TSTUSR
778
779         # cleanup
780         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
781                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
782         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
783                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
784 }
785 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
786
787 test_4b() {
788         local GR_STR1="1w3d"
789         local GR_STR2="1000s"
790         local GR_STR3="5s"
791         local GR_STR4="1w2d3h4m5s"
792         local GR_STR5="5c"
793         local GR_STR6="1111111111111111"
794
795         wait_delete_completed
796
797         # test of valid grace strings handling
798         echo "Valid grace strings test"
799         $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
800                 $GR_STR2 $DIR || error "set user grace time failed"
801         $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
802         $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
803                 $GR_STR4 $DIR || error "set group grace time quota failed"
804         $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
805
806         # test of invalid grace strings handling
807         echo "  Invalid grace strings test"
808         ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
809         ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
810
811         # cleanup
812         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
813                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
814         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
815                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
816 }
817 run_test 4b "Grace time strings handling"
818
819 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
820 test_5() {
821         local BLIMIT=10 # 10M
822         local ILIMIT=10 # 10 inodes
823
824         setup_quota_test
825         trap cleanup_quota_test EXIT
826
827         set_mdt_qtype "ug" || error "enable mdt quota failed"
828         set_ost_qtype "ug" || error "enable ost quota failed"
829
830         echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
831         $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
832                 error "set user quota failed"
833         $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
834                 error "set group quota failed"
835
836         # make sure the system is clean
837         local USED=$(getquota -u $TSTUSR global curinodes)
838         [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
839         USED=$(getquota -g $TSTUSR global curinodes)
840         [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
841         USED=$(getquota -u $TSTUSR global curspace)
842         [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
843         USED=$(getquota -g $TSTUSR global curspace)
844         [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
845
846         echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
847         createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
848                 error "create failure, expect success"
849         $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
850                 error "write failure, expect success"
851
852         echo "Chown files to $TSTUSR.$TSTUSR ..."
853         for i in `seq 0 $ILIMIT`; do
854                 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
855                         quota_error a $TSTUSR "chown failure, expect success"
856         done
857
858         # cleanup
859         unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
860         cleanup_quota_test
861
862         resetquota -u $TSTUSR
863         resetquota -g $TSTUSR
864 }
865 run_test 5 "Chown & chgrp successfully even out of block/file quota"
866
867 # test dropping acquire request on master
868 test_6() {
869         local LIMIT=3 # 3M
870
871         # Clear dmesg so watchdog is not triggered by previous
872         # test output
873         do_facet ost1 dmesg -c > /dev/null
874
875         setup_quota_test
876         trap cleanup_quota_test EXIT
877
878         # make sure the system is clean
879         local USED=$(getquota -u $TSTUSR global curspace)
880         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
881
882         # make sure no granted quota on ost
883         set_ost_qtype "ug" || error "enable ost quota failed"
884         resetquota -u $TSTUSR
885
886         # create file for $TSTUSR
887         local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
888         $LFS setstripe $TESTFILE -c 1 -i 0
889         chown $TSTUSR.$TSTUSR $TESTFILE
890
891         # create file for $TSTUSR2
892         local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
893         $LFS setstripe $TESTFILE2 -c 1 -i 0
894         chown $TSTUSR2.$TSTUSR2 $TESTFILE2
895
896         # cache per-ID lock for $TSTUSR on slave
897         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
898                 error "set quota failed"
899         $RUNAS $DD of=$TESTFILE count=1 ||
900                 error "write $TESTFILE failure, expect success"
901         $RUNAS2 $DD of=$TESTFILE2 count=1 ||
902                 error "write $TESTFILE2 failure, expect success"
903         sync; sync
904         sync_all_data || true
905
906         #define QUOTA_DQACQ 601
907         #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
908         lustre_fail mds 0x513 601
909
910         # write to un-enforced ID ($TSTUSR2) should succeed
911         $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
912                 error "write failure, expect success"
913
914         # write to enforced ID ($TSTUSR) in background, exceeding limit
915         # to make sure DQACQ is sent
916         $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
917         DDPID=$!
918
919         # watchdog timer uses a factor of 2
920         echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
921         sleep $((TIMEOUT * 2 + 1))
922
923         # write should be blocked and never finished
924         if ! ps -p $DDPID  > /dev/null 2>&1; then
925                 lustre_fail mds 0 0
926                 error "write finished incorrectly!"
927         fi
928
929         lustre_fail mds 0 0
930
931         # no watchdog is triggered
932         do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
933         watchdog=$(awk '/Service thread pid/ && /was inactive/ \
934                         { print; }' $TMP/lustre-log-${TESTNAME}.log)
935         [ -z "$watchdog" ] || error "$watchdog"
936
937         rm -f $TMP/lustre-log-${TESTNAME}.log
938
939         # write should continue then fail with EDQUOT
940         local count=0
941         local c_size
942         while [ true ]; do
943                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
944                 if [ $count -ge 240 ]; then
945                         quota_error u $TSTUSR "dd not finished in $count secs"
946                 fi
947                 count=$((count + 1))
948                 if [ $((count % 30)) -eq 0 ]; then
949                         c_size=$(stat -c %s $TESTFILE)
950                         echo "Waiting $count secs. $c_size"
951                         $SHOW_QUOTA_USER
952                 fi
953                 sleep 1
954         done
955
956         cleanup_quota_test
957         resetquota -u $TSTUSR
958 }
959 run_test 6 "Test dropping acquire request on master"
960
961 # quota reintegration (global index)
962 test_7a() {
963         local TESTFILE=$DIR/$tdir/$tfile
964         local LIMIT=20 # 20M
965
966         [ "$SLOW" = "no" ] && LIMIT=5
967
968         setup_quota_test
969         trap cleanup_quota_test EXIT
970
971         # make sure the system is clean
972         local USED=$(getquota -u $TSTUSR global curspace)
973         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
974
975         # make sure no granted quota on ost1
976         set_ost_qtype "ug" || error "enable ost quota failed"
977         resetquota -u $TSTUSR
978         set_ost_qtype "none" || error "disable ost quota failed"
979
980         local OSTUUID=$(ostuuid_from_index 0)
981         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
982         [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
983                 "$TSTUSR isn't 0."
984
985         # create test file
986         $LFS setstripe $TESTFILE -c 1 -i 0
987         chown $TSTUSR.$TSTUSR $TESTFILE
988
989         echo "Stop ost1..."
990         stop ost1
991
992         echo "Enable quota & set quota limit for $TSTUSR"
993         set_ost_qtype "ug" || error "enable ost quota failed"
994         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
995                 error "set quota failed"
996
997         echo "Start ost1..."
998         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
999         quota_init
1000
1001         wait_ost_reint "ug" || error "reintegration failed"
1002
1003         # hardlimit should have been fetched by slave during global
1004         # reintegration, write will exceed quota
1005         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1006                 quota_error u $TSTUSR "write success, but expect EDQUOT"
1007
1008         rm -f $TESTFILE
1009         wait_delete_completed
1010         sync_all_data || true
1011         sleep 3
1012
1013         echo "Stop ost1..."
1014         stop ost1
1015
1016         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1017                 error "clear quota failed"
1018
1019         echo "Start ost1..."
1020         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1021         quota_init
1022
1023         wait_ost_reint "ug" || error "reintegration failed"
1024
1025         # hardlimit should be cleared on slave during reintegration
1026         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1027                 quota_error u $TSTUSR "write error, but expect success"
1028
1029         cleanup_quota_test
1030         resetquota -u $TSTUSR
1031 }
1032 run_test 7a "Quota reintegration (global index)"
1033
1034 # quota reintegration (slave index)
1035 test_7b() {
1036         local LIMIT="100G"
1037         local TESTFILE=$DIR/$tdir/$tfile
1038
1039         setup_quota_test
1040         trap cleanup_quota_test EXIT
1041
1042         # make sure the system is clean
1043         local USED=$(getquota -u $TSTUSR global curspace)
1044         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1045
1046         # make sure no granted quota on ost1
1047         set_ost_qtype "ug" || error "enable ost quota failed"
1048         resetquota -u $TSTUSR
1049         set_ost_qtype "none" || error "disable ost quota failed"
1050
1051         local OSTUUID=$(ostuuid_from_index 0)
1052         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1053         [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1054                 "$TSTUSR isn't 0."
1055
1056         # create test file
1057         $LFS setstripe $TESTFILE -c 1 -i 0
1058         chown $TSTUSR.$TSTUSR $TESTFILE
1059
1060         # consume some space to make sure the granted space will not
1061         # be released during reconciliation
1062         $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1063                 error "consume space failure, expect success"
1064
1065         # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1066         lustre_fail mds 0xa02
1067
1068         set_ost_qtype "ug" || error "enable ost quota failed"
1069         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1070                 error "set quota failed"
1071
1072         # ignore the write error
1073         $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1074
1075         local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1076
1077         lustre_fail mds 0
1078
1079         echo "Restart ost to trigger reintegration..."
1080         stop ost1
1081         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1082         quota_init
1083
1084         wait_ost_reint "ug" || error "reintegration failed"
1085
1086         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1087         [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1088
1089         cleanup_quota_test
1090         resetquota -u $TSTUSR
1091         $SHOW_QUOTA_USER
1092 }
1093 run_test 7b "Quota reintegration (slave index)"
1094
1095 # quota reintegration (restart mds during reintegration)
1096 test_7c() {
1097         local LIMIT=20 # 20M
1098         local TESTFILE=$DIR/$tdir/$tfile
1099
1100         [ "$SLOW" = "no" ] && LIMIT=5
1101
1102         setup_quota_test
1103         trap cleanup_quota_test EXIT
1104
1105         # make sure the system is clean
1106         local USED=$(getquota -u $TSTUSR global curspace)
1107         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1108
1109         set_ost_qtype "none" || error "disable ost quota failed"
1110         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1111                 error "set quota failed"
1112
1113         # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1114         lustre_fail ost 0xa03
1115
1116         # enable ost quota
1117         set_ost_qtype "ug" || error "enable ost quota failed"
1118         # trigger reintegration
1119         local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1120         procf=${procf}quota_slave.force_reint
1121         do_facet ost1 $LCTL set_param $procf=1 ||
1122                 error "force reintegration failed"
1123
1124         echo "Stop mds..."
1125         stop mds1
1126
1127         lustre_fail ost 0
1128
1129         echo "Start mds..."
1130         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1131         quota_init
1132
1133         # wait longer than usual to make sure the reintegration
1134         # is triggered by quota wb thread.
1135         wait_ost_reint "ug" 200 || error "reintegration failed"
1136
1137         # hardlimit should have been fetched by slave during global
1138         # reintegration, write will exceed quota
1139         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1140                 quota_error u $TSTUSR "write success, but expect EDQUOT"
1141
1142         cleanup_quota_test
1143         resetquota -u $TSTUSR
1144 }
1145 run_test 7c "Quota reintegration (restart mds during reintegration)"
1146
1147 # Quota reintegration (Transfer index in multiple bulks)
1148 test_7d(){
1149         local TESTFILE=$DIR/$tdir/$tfile
1150         local TESTFILE1="$DIR/$tdir/$tfile"-1
1151         local limit=20 #20M
1152
1153         setup_quota_test
1154         trap cleanup_quota_test EXIT
1155
1156         set_ost_qtype "none" || error "disable ost quota failed"
1157         $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1158                 error "set quota for $TSTUSR failed"
1159         $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1160                 error "set quota for $TSTUSR2 failed"
1161
1162         #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1163         lustre_fail mds 0x608 0
1164
1165         # enable quota to tirgger reintegration
1166         set_ost_qtype "u" || error "enable ost quota failed"
1167         wait_ost_reint "u" || error "reintegration failed"
1168
1169         lustre_fail mds 0
1170
1171         # hardlimit should have been fetched by slave during global
1172         # reintegration, write will exceed quota
1173         $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1174                 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1175
1176         $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1177                 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1178
1179         cleanup_quota_test
1180         resetquota -u $TSTUSR
1181         resetquota -u $TSTUSR2
1182 }
1183 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1184
1185 # quota reintegration (inode limits)
1186 test_7e() {
1187         [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1188
1189         local ilimit=$((1024 * 2)) # 2k inodes
1190         local TESTFILE=$DIR/${tdir}-1/$tfile
1191
1192         setup_quota_test
1193         trap cleanup_quota_test EXIT
1194
1195         # make sure the system is clean
1196         local USED=$(getquota -u $TSTUSR global curinodes)
1197         [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1198
1199         # make sure no granted quota on mdt1
1200         set_mdt_qtype "ug" || error "enable mdt quota failed"
1201         resetquota -u $TSTUSR
1202         set_mdt_qtype "none" || error "disable mdt quota failed"
1203
1204         local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1205         USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1206         [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1207                 "$TSTUSR isn't 0."
1208
1209         echo "Stop mds${MDSCOUNT}..."
1210         stop mds${MDSCOUNT}
1211
1212         echo "Enable quota & set quota limit for $TSTUSR"
1213         set_mdt_qtype "ug" || error "enable mdt quota failed"
1214         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit  $DIR ||
1215                 error "set quota failed"
1216
1217         echo "Start mds${MDSCOUNT}..."
1218         start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1219         quota_init
1220
1221         wait_mdt_reint "ug" || error "reintegration failed"
1222
1223         echo "create remote dir"
1224         $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1225                 error "create remote dir failed"
1226         chmod 0777 $DIR/${tdir}-1
1227
1228         # hardlimit should have been fetched by slave during global
1229         # reintegration, create will exceed quota
1230         $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1231                 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1232
1233         $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1234         wait_delete_completed
1235         sync_all_data || true
1236
1237         echo "Stop mds${MDSCOUNT}..."
1238         stop mds${MDSCOUNT}
1239
1240         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1241                 error "clear quota failed"
1242
1243         echo "Start mds${MDSCOUNT}..."
1244         start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1245         quota_init
1246
1247         wait_mdt_reint "ug" || error "reintegration failed"
1248
1249         # hardlimit should be cleared on slave during reintegration
1250         $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1251                 quota_error -u $TSTUSR "create failed, expect success"
1252
1253         $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1254         rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1255
1256         cleanup_quota_test
1257         resetquota -u $TSTUSR
1258 }
1259 run_test 7e "Quota reintegration (inode limits)"
1260
1261 # run dbench with quota enabled
1262 test_8() {
1263         local BLK_LIMIT="100g" #100G
1264         local FILE_LIMIT=1000000
1265
1266         setup_quota_test
1267         trap cleanup_quota_test EXIT
1268
1269         set_mdt_qtype "ug" || error "enable mdt quota failed"
1270         set_ost_qtype "ug" || error "enable ost quota failed"
1271
1272         echo "Set enough high limit for user: $TSTUSR"
1273         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1274                 error "set user quota failed"
1275         echo "Set enough high limit for group: $TSTUSR"
1276         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1277                 error "set group quota failed"
1278
1279         local duration=""
1280         [ "$SLOW" = "no" ] && duration=" -t 120"
1281         $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1282                 quota_error a $TSTUSR "dbench failed!"
1283
1284         cleanup_quota_test
1285         resetquota -u $TSTUSR
1286         resetquota -g $TSTUSR
1287 }
1288 run_test 8 "Run dbench with quota enabled"
1289
1290 # this check is just for test_9
1291 OST0_MIN=4900000 #4.67G
1292
1293 check_whether_skip () {
1294         local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1295         log "OST0_SIZE: $OST0_SIZE  required: $OST0_MIN"
1296         if [ $OST0_SIZE -lt $OST0_MIN ]; then
1297                 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1298                 return 0
1299         else
1300                 return 1
1301         fi
1302 }
1303
1304 # run for fixing bug10707, it needs a big room. test for 64bit
1305 test_9() {
1306         local filesize=$((1024 * 9 / 2)) # 4.5G
1307
1308         check_whether_skip && return 0
1309
1310         setup_quota_test
1311         trap cleanup_quota_test EXIT
1312
1313         set_ost_qtype "ug" || error "enable ost quota failed"
1314
1315         local TESTFILE="$DIR/$tdir/$tfile-0"
1316         local BLK_LIMIT=100G #100G
1317         local FILE_LIMIT=1000000
1318
1319         echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1320
1321         log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1322                 "for user: $TSTUSR"
1323         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1324                 error "set user quota failed"
1325
1326         log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1327                 "for group: $TSTUSR"
1328         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1329                 error "set group quota failed"
1330
1331         quota_show_check a u $TSTUSR
1332         quota_show_check a g $TSTUSR
1333
1334         echo "Create test file"
1335         $LFS setstripe $TESTFILE -c 1 -i 0
1336         chown $TSTUSR.$TSTUSR $TESTFILE
1337
1338         log "Write the big file of 4.5G ..."
1339         $RUNAS $DD of=$TESTFILE count=$filesize ||
1340                 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1341
1342         $SHOW_QUOTA_USER
1343         $SHOW_QUOTA_GROUP
1344
1345         cleanup_quota_test
1346         resetquota -u $TSTUSR
1347         resetquota -g $TSTUSR
1348
1349         $SHOW_QUOTA_USER
1350         $SHOW_QUOTA_GROUP
1351 }
1352 run_test 9 "Block limit larger than 4GB (b10707)"
1353
1354 test_10() {
1355         local TESTFILE=$DIR/$tdir/$tfile
1356
1357         setup_quota_test
1358         trap cleanup_quota_test EXIT
1359
1360         # set limit to root user should fail
1361         $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1362                 error "set limit for root user successfully, expect failure"
1363         $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1364                 error "set limit for root group successfully, expect failure"
1365
1366         # root user can overrun quota
1367         set_ost_qtype "ug" || "enable ost quota failed"
1368
1369         $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1370                 error "set quota failed"
1371         quota_show_check b u $TSTUSR
1372
1373         $LFS setstripe $TESTFILE -c 1
1374         chown $TSTUSR.$TSTUSR $TESTFILE
1375
1376         runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1377                 error "write failure, expect success"
1378
1379         cleanup_quota_test
1380         resetquota -u $TSTUSR
1381 }
1382 run_test 10 "Test quota for root user"
1383
1384 test_11() {
1385         local TESTFILE=$DIR/$tdir/$tfile
1386         setup_quota_test
1387         trap cleanup_quota_test EXIT
1388
1389         set_mdt_qtype "ug" || "enable mdt quota failed"
1390         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1391                 error "set quota failed"
1392
1393         touch "$TESTFILE"-0
1394         touch "$TESTFILE"-1
1395
1396         chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1397         chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1398
1399         $SHOW_QUOTA_USER
1400         local USED=$(getquota -u $TSTUSR global curinodes)
1401         [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1402
1403         cleanup_quota_test
1404         resetquota -u $TSTUSR
1405 }
1406 run_test 11 "Chown/chgrp ignores quota"
1407
1408 test_12a() {
1409         [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1410
1411         local blimit=22 # 22M
1412         local blk_cnt=$((blimit - 5))
1413         local TESTFILE0="$DIR/$tdir/$tfile"-0
1414         local TESTFILE1="$DIR/$tdir/$tfile"-1
1415
1416         setup_quota_test
1417         trap cleanup_quota_test EXIT
1418
1419         set_ost_qtype "u" || "enable ost quota failed"
1420         quota_show_check b u $TSTUSR
1421
1422         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1423                 error "set quota failed"
1424
1425         $LFS setstripe $TESTFILE0 -c 1 -i 0
1426         $LFS setstripe $TESTFILE1 -c 1 -i 1
1427         chown $TSTUSR.$TSTUSR $TESTFILE0
1428         chown $TSTUSR.$TSTUSR $TESTFILE1
1429
1430         echo "Write to ost0..."
1431         $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1432                 quota_error a $TSTUSR "dd failed"
1433
1434         echo "Write to ost1..."
1435         $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1436                 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1437
1438         echo "Free space from ost0..."
1439         rm -f $TESTFILE0
1440         wait_delete_completed
1441         sync_all_data || true
1442
1443         echo "Write to ost1 after space freed from ost0..."
1444         $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1445                 quota_error a $TSTUSR "rebalancing failed"
1446
1447         cleanup_quota_test
1448         resetquota -u $TSTUSR
1449 }
1450 run_test 12a "Block quota rebalancing"
1451
1452 test_12b() {
1453         [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1454
1455         local ilimit=$((1024 * 2)) # 2k inodes
1456         local TESTFILE0=$DIR/$tdir/$tfile
1457         local TESTFILE1=$DIR/${tdir}-1/$tfile
1458
1459         setup_quota_test
1460         trap cleanup_quota_test EXIT
1461
1462         $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1463         chmod 0777 $DIR/${tdir}-1
1464
1465         set_mdt_qtype "u" || "enable mdt quota failed"
1466         quota_show_check f u $TSTUSR
1467
1468         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1469                 error "set quota failed"
1470
1471         echo "Create $ilimit files on mdt0..."
1472         $RUNAS createmany -m $TESTFILE0 $ilimit ||
1473                 quota_error u $TSTUSR "create failed, but expect success"
1474
1475         echo "Create files on mdt1..."
1476         $RUNAS createmany -m $TESTFILE1 1 &&
1477                 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1478
1479         echo "Free space from mdt0..."
1480         $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1481         wait_delete_completed
1482         sync_all_data || true
1483
1484         echo "Create files on mdt1 after space freed from mdt0..."
1485         $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1486                 quota_error a $TSTUSR "rebalancing failed"
1487
1488         $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1489                 error "unlink mdt1 files failed"
1490         rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1491
1492         cleanup_quota_test
1493         resetquota -u $TSTUSR
1494 }
1495 run_test 12b "Inode quota rebalancing"
1496
1497 test_13(){
1498         local TESTFILE=$DIR/$tdir/$tfile
1499         # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1500         local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1501
1502         setup_quota_test
1503         trap cleanup_quota_test EXIT
1504
1505         set_ost_qtype "u" || "enable ost quota failed"
1506         quota_show_check b u $TSTUSR
1507
1508         $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1509                 error "set quota failed"
1510         $LFS setstripe $TESTFILE -c 1 -i 0
1511         chown $TSTUSR.$TSTUSR $TESTFILE
1512
1513         # clear the locks in cache first
1514         do_facet ost1 $LCTL set_param -n $procf=clear
1515         local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1516         [ $nlock -eq 0 ] || error "$nlock cached locks"
1517
1518         # write to acquire the per-ID lock
1519         $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1520                 quota_error a $TSTUSR "dd failed"
1521
1522         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1523         [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1524
1525         # clear quota doesn't trigger per-ID lock cancellation
1526         resetquota -u $TSTUSR
1527         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1528         [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1529
1530         # clear the per-ID lock
1531         do_facet ost1 $LCTL set_param -n $procf=clear
1532         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1533         [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1534
1535         # spare quota should be released
1536         local OSTUUID=$(ostuuid_from_index 0)
1537         local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1538         local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1539         [ $limit -le $space ] ||
1540                 error "spare quota isn't released, limit:$limit, space:$space"
1541
1542         cleanup_quota_test
1543 }
1544 run_test 13 "Cancel per-ID lock in the LRU list"
1545
1546 test_15(){
1547         local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1548
1549         wait_delete_completed
1550         sync_all_data || true
1551
1552         # test for user
1553         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1554                 error "set user quota failed"
1555         local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1556         [ $TOTAL_LIMIT -eq $LIMIT ] ||
1557                 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1558         resetquota -u $TSTUSR
1559
1560         # test for group
1561         $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1562                 error "set group quota failed"
1563         TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1564         [ $TOTAL_LIMIT -eq $LIMIT ] ||
1565                 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1566         resetquota -g $TSTUSR
1567 }
1568 run_test 15 "Set over 4T block quota"
1569
1570 test_17sub() {
1571         local err_code=$1
1572         local BLKS=1    # 1M less than limit
1573         local TESTFILE=$DIR/$tdir/$tfile
1574
1575         setup_quota_test
1576         trap cleanup_quota_test EXIT
1577
1578         # make sure the system is clean
1579         local USED=$(getquota -u $TSTUSR global curspace)
1580         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1581
1582         set_ost_qtype "ug" || error "enable ost quota failed"
1583         # make sure no granted quota on ost
1584         resetquota -u $TSTUSR
1585         $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1586                 error "set quota failed"
1587
1588         quota_show_check b u $TSTUSR
1589
1590         #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1591         lustre_fail mds 0xa04 $err_code
1592
1593         # write in background
1594         $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1595         local DDPID=$!
1596
1597         sleep 2
1598         # write should be blocked and never finished
1599         if ! ps -p $DDPID  > /dev/null 2>&1; then
1600                 lustre_fail mds 0 0
1601                 quota_error u $TSTUSR "write finished incorrectly!"
1602         fi
1603
1604         lustre_fail mds 0 0
1605
1606         local count=0
1607         local timeout=30
1608         while [ true ]; do
1609                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1610                 count=$((count+1))
1611                 if [ $count -gt $timeout ]; then
1612                         quota_error u $TSTUSR "dd is not finished!"
1613                 fi
1614                 sleep 1
1615         done
1616
1617         sync; sync_all_data || true
1618
1619         USED=$(getquota -u $TSTUSR global curspace)
1620         [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1621                 "Used space(${USED}K) is less than ${BLKS}M"
1622
1623         cleanup_quota_test
1624         resetquota -u $TSTUSR
1625 }
1626
1627 # DQACQ return recoverable error
1628 test_17() {
1629         echo "DQACQ return -ENOLCK"
1630         #define ENOLCK  37
1631         test_17sub 37 || error "Handle -ENOLCK failed"
1632
1633         echo "DQACQ return -EAGAIN"
1634         #define EAGAIN  11
1635         test_17sub 11 || error "Handle -EAGAIN failed"
1636
1637         echo "DQACQ return -ETIMEDOUT"
1638         #define ETIMEDOUT 110
1639         test_17sub 110 || error "Handle -ETIMEDOUT failed"
1640
1641         echo "DQACQ return -ENOTCONN"
1642         #define ENOTCONN 107
1643         test_17sub 107 || error "Handle -ENOTCONN failed"
1644 }
1645
1646 run_test 17 "DQACQ return recoverable error"
1647
1648 test_18_sub () {
1649         local io_type=$1
1650         local blimit="200m" # 200M
1651         local TESTFILE="$DIR/$tdir/$tfile"
1652
1653         setup_quota_test
1654         trap cleanup_quota_test EXIT
1655
1656         set_ost_qtype "u" || error "enable ost quota failed"
1657         log "User quota (limit: $blimit)"
1658         $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1659                 error "set quota failed"
1660         quota_show_check b u $TSTUSR
1661
1662         $LFS setstripe $TESTFILE -i 0 -c 1
1663         chown $TSTUSR.$TSTUSR $TESTFILE
1664
1665         local timeout=$(sysctl -n lustre.timeout)
1666
1667         if [ $io_type = "directio" ]; then
1668                 log "Write 100M (directio) ..."
1669                 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1670         else
1671                 log "Write 100M (buffered) ..."
1672                 $RUNAS $DD of=$TESTFILE count=100 &
1673         fi
1674         local DDPID=$!
1675
1676         replay_barrier $SINGLEMDS
1677         log "Fail mds for $((2 * timeout)) seconds"
1678         fail $SINGLEMDS $((2 * timeout))
1679
1680         local count=0
1681         if at_is_enabled; then
1682                 timeout=$(at_max_get mds)
1683         else
1684                 timeout=$(lctl get_param -n timeout)
1685         fi
1686
1687         while [ true ]; do
1688                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1689                 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1690                         log "it took $count second"
1691                 fi
1692                 sleep 1
1693         done
1694
1695         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1696         sync
1697         cancel_lru_locks mdc
1698         cancel_lru_locks osc
1699         $SHOW_QUOTA_USER
1700
1701         local testfile_size=$(stat -c %s $TESTFILE)
1702         if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1703                 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1704                         "got ${testfile_size}. Verifying file failed!"
1705         fi
1706         cleanup_quota_test
1707         resetquota -u $TSTUSR
1708 }
1709
1710 # test when mds does failover, the ost still could work well
1711 # this test shouldn't trigger watchdog b=14840
1712 test_18() {
1713         # Clear dmesg so watchdog is not triggered by previous
1714         # test output
1715         do_facet ost1 dmesg -c > /dev/null
1716
1717         test_18_sub normal
1718         test_18_sub directio
1719
1720         # check if watchdog is triggered
1721         do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1722         local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1723                         { print; }' $TMP/lustre-log-${TESTNAME}.log)
1724         [ -z "$watchdog" ] || error "$watchdog"
1725         rm -f $TMP/lustre-log-${TESTNAME}.log
1726 }
1727 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1728
1729 test_19() {
1730         local blimit=5 # 5M
1731         local TESTFILE=$DIR/$tdir/$tfile
1732
1733         setup_quota_test
1734         trap cleanup_quota_test EXIT
1735
1736         set_ost_qtype "ug" || error "enable ost quota failed"
1737
1738         # bind file to a single OST
1739         $LFS setstripe -c 1 $TESTFILE
1740         chown $TSTUSR.$TSTUSR $TESTFILE
1741
1742         echo "Set user quota (limit: "$blimit"M)"
1743         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1744                 error "set user quota failed"
1745         quota_show_check b u $TSTUSR
1746         echo "Update quota limits"
1747         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1748                 error "set group quota failed"
1749         quota_show_check b u $TSTUSR
1750
1751         # first wirte might be cached
1752         $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1753         cancel_lru_locks osc
1754         $SHOW_QUOTA_USER
1755         $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1756                 quota_error u $TSTUSR "Write success, expect failure"
1757         $SHOW_QUOTA_USER
1758
1759         cleanup_quota_test
1760         resetquota -u $TSTUSR
1761 }
1762 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1763
1764 test_20() { # b15754
1765         local LSTR=(2g 1t 4k 3m) # limits strings
1766         # limits values
1767         local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1768
1769         resetquota -u $TSTUSR
1770
1771         $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1772                 $MOUNT || error "could not set quota limits"
1773         $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1774                                 --inode-softlimit ${LSTR[2]} \
1775                                 --inode-hardlimit ${LSTR[3]} \
1776                                 $MOUNT || error "could not set quota limits"
1777
1778         [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1779                 error "bsoftlimit was not set properly"
1780         [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1781                 error "bhardlimit was not set properly"
1782         [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1783                 error "isoftlimit was not set properly"
1784         [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1785                 error "ihardlimit was not set properly"
1786
1787         resetquota -u $TSTUSR
1788 }
1789 run_test 20 "Test if setquota specifiers work properly (b15754)"
1790
1791 test_21_sub() {
1792         local testfile=$1
1793         local blk_number=$2
1794         local seconds=$3
1795
1796         local time=$(($(date +%s) + seconds))
1797         while [ $(date +%s) -lt $time ]; do
1798                 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1799         done
1800 }
1801
1802 # run for fixing bug16053, setquota shouldn't fail when writing and
1803 # deleting are happening
1804 test_21() {
1805         local TESTFILE="$DIR/$tdir/$tfile"
1806         local BLIMIT=10 # 10G
1807         local ILIMIT=1000000
1808
1809         setup_quota_test
1810         trap cleanup_quota_test EXIT
1811
1812         set_ost_qtype "ug" || error "Enable ost quota failed"
1813
1814         log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1815         $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1816                 error "set user quota failed"
1817         log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1818         $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1819                 error "set group quota failed"
1820
1821         # repeat writing on a 1M file
1822         test_21_sub ${TESTFILE}_1 1 30 &
1823         local DDPID1=$!
1824         # repeat writing on a 128M file
1825         test_21_sub ${TESTFILE}_2 128 30 &
1826         local DDPID2=$!
1827
1828         local time=$(($(date +%s) + 30))
1829         local i=1
1830         while [ $(date +%s) -lt $time ]; do
1831                 log "Set quota for $i times"
1832                 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1833                         -I $((ILIMIT + i)) $MOUNT ||
1834                                 error "Set user quota failed"
1835                 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1836                         -I $((ILIMIT + i)) $MOUNT ||
1837                                 error "Set group quota failed"
1838                 i=$((i+1))
1839                 sleep 1
1840         done
1841
1842         local count=0
1843         while [ true ]; do
1844                 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1845                 count=$((count+1))
1846                 if [ $count -gt 60 ]; then
1847                         quota_error a $TSTUSR "dd should be finished!"
1848                 fi
1849                 sleep 1
1850         done
1851         echo "(dd_pid=$DDPID1, time=$count)successful"
1852
1853         count=0
1854         while [ true ]; do
1855                 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1856                 count=$((count+1))
1857                 if [ $count -gt 60 ]; then
1858                         quota_error a $TSTUSR "dd should be finished!"
1859                 fi
1860                 sleep 1
1861         done
1862         echo "(dd_pid=$DDPID2, time=$count)successful"
1863
1864         cleanup_quota_test
1865         resetquota -u $TSTUSR
1866         resetquota -g $TSTUSR
1867 }
1868 run_test 21 "Setquota while writing & deleting (b16053)"
1869
1870 # enable/disable quota enforcement permanently
1871 test_22() {
1872         echo "Set both mdt & ost quota type as ug"
1873         set_mdt_qtype "ug" || error "enable mdt quota failed"
1874         set_ost_qtype "ug" || error "enable ost quota failed"
1875
1876         echo "Restart..."
1877         stopall
1878         mount
1879         setupall
1880
1881         echo "Verify if quota is enabled"
1882         local qtype=$(mdt_quota_type)
1883         [ $qtype != "ug" ] && error "mdt quota setting is lost"
1884         qtype=$(ost_quota_type)
1885         [ $qtype != "ug" ] && error "ost quota setting is lost"
1886
1887         echo "Set both mdt & ost quota type as none"
1888         set_mdt_qtype "none" || error "disable mdt quota failed"
1889         set_ost_qtype "none" || error "disable ost quota failed"
1890
1891         echo "Restart..."
1892         stopall
1893         mount
1894         setupall
1895         quota_init
1896
1897         echo "Verify if quota is disabled"
1898         qtype=$(mdt_quota_type)
1899         [ $qtype != "none" ] && error "mdt quota setting is lost"
1900         qtype=$(ost_quota_type)
1901         [ $qtype != "none" ] && error "ost quota setting is lost"
1902
1903         return 0
1904 }
1905 run_test 22 "enable/disable quota by 'lctl conf_param'"
1906
1907 test_23_sub() {
1908         local TESTFILE="$DIR/$tdir/$tfile"
1909         local LIMIT=$1
1910
1911         setup_quota_test
1912         trap cleanup_quota_test EXIT
1913
1914         set_ost_qtype "ug" || error "Enable ost quota failed"
1915
1916         # test for user
1917         log "User quota (limit: $LIMIT MB)"
1918         $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1919                 error "set quota failed"
1920         quota_show_check b u $TSTUSR
1921
1922         $LFS setstripe $TESTFILE -c 1 -i 0
1923         chown $TSTUSR.$TSTUSR $TESTFILE
1924
1925         log "Step1: trigger EDQUOT with O_DIRECT"
1926         log "Write half of file"
1927         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1928                 quota_error u $TSTUSR "(1) Write failure, expect success." \
1929                         "limit=$LIMIT"
1930         log "Write out of block quota ..."
1931         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1932                 oflag=direct conv=notrunc &&
1933                 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1934                         "limit=$LIMIT"
1935         log "Step1: done"
1936
1937         log "Step2: rewrite should succeed"
1938         $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1939                 quota_error u $TSTUSR "(3) Write failure, expect success." \
1940                         "limit=$LIMIT"
1941         log "Step2: done"
1942
1943         cleanup_quota_test
1944
1945         local OST0_UUID=$(ostuuid_from_index 0)
1946         local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1947         [ $OST0_QUOTA_USED -ne 0 ] &&
1948                 ($SHOW_QUOTA_USER; \
1949                 quota_error u $TSTUSR "quota isn't released")
1950         $SHOW_QUOTA_USER
1951         resetquota -u $TSTUSR
1952 }
1953
1954 test_23() {
1955         local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1956         check_whether_skip && return 0
1957         log "run for 4MB test file"
1958         test_23_sub 4
1959
1960         OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1961         check_whether_skip && return 0
1962         log "run for 40MB test file"
1963         test_23_sub 40
1964 }
1965 run_test 23 "Quota should be honored with directIO (b16125)"
1966
1967 test_24() {
1968         local blimit=5 # 5M
1969         local TESTFILE="$DIR/$tdir/$tfile"
1970
1971         setup_quota_test
1972         trap cleanup_quota_test EXIT
1973
1974         set_ost_qtype "ug" || error "enable ost quota failed"
1975
1976         # bind file to a single OST
1977         $LFS setstripe -c 1 $TESTFILE
1978         chown $TSTUSR.$TSTUSR $TESTFILE
1979
1980         echo "Set user quota (limit: "$blimit"M)"
1981         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1982                 error "set quota failed"
1983
1984         # overrun quota by root user
1985         runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1986                 error "write failure, expect success"
1987         cancel_lru_locks osc
1988         sync_all_data || true
1989
1990         $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1991
1992         cleanup_quota_test
1993         resetquota -u $TSTUSR
1994 }
1995 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1996
1997 test_27a() { # b19612
1998         $LFS quota $TSTUSR $DIR &&
1999                 error "lfs succeeded with no type, but should have failed"
2000         $LFS setquota $TSTUSR $DIR &&
2001                 error "lfs succeeded with no type, but should have failed"
2002         return 0
2003 }
2004 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2005
2006 test_27b() { # b20200
2007         $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2008                 error "lfs setquota failed with uid argument"
2009         $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2010                 error "lfs stequota failed with gid argument"
2011         $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2012         $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2013         resetquota -u $TSTUSR
2014         resetquota -g $TSTUSR
2015         return 0
2016 }
2017 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2018
2019 test_27c() {
2020         local limit
2021
2022         $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2023                 error "lfs setquota failed"
2024
2025         limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2026         [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2027         limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2028         [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2029
2030         $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2031                 error "lfs setquota for $TSTID failed"
2032
2033         limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2034         [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2035         limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2036         [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2037
2038         $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2039                 error "total allocated inode/block limit not printed"
2040
2041         resetquota -u $TSTUSR
2042 }
2043 run_test 27c "lfs quota should support human-readable output"
2044
2045 test_30() {
2046         local output
2047         local LIMIT=4 # 4MB
2048         local TESTFILE="$DIR/$tdir/$tfile"
2049         local GRACE=10
2050
2051         setup_quota_test
2052         trap cleanup_quota_test EXIT
2053
2054         set_ost_qtype "u" || error "enable ost quota failed"
2055
2056         $LFS setstripe $TESTFILE -i 0 -c 1
2057         chown $TSTUSR.$TSTUSR $TESTFILE
2058
2059         $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2060                 $MAX_IQ_TIME $DIR || error "set grace time failed"
2061         $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2062                 error "set quota failed"
2063         $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2064         cancel_lru_locks osc
2065         sleep $GRACE
2066         $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2067         # over-quota flag has not yet settled since we do not trigger async
2068         # events based on grace time period expiration
2069         $SHOW_QUOTA_USER
2070         $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2071         cancel_lru_locks osc
2072         # now over-quota flag should be settled and further writes should fail
2073         $SHOW_QUOTA_USER
2074         $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2075                 error "grace times were reset"
2076         # cleanup
2077         cleanup_quota_test
2078         resetquota -u $TSTUSR
2079         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2080                 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2081 }
2082 run_test 30 "Hard limit updates should not reset grace times"
2083
2084 # basic usage tracking for user & group
2085 test_33() {
2086         local INODES=10 # 10 files
2087         local BLK_CNT=2 # of 2M each
2088         local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2089
2090         setup_quota_test
2091         trap cleanup_quota_test EXIT
2092
2093         # make sure the system is clean
2094         local USED=$(getquota -u $TSTID global curspace)
2095         [ $USED -ne 0 ] &&
2096                 error "Used space ($USED) for user $TSTID isn't 0."
2097         USED=$(getquota -g $TSTID global curspace)
2098         [ $USED -ne 0 ] &&
2099                 error "Used space ($USED) for group $TSTID isn't 0."
2100
2101         echo "Write files..."
2102         for i in `seq 0 $INODES`; do
2103                 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2104                         error "write failed"
2105                 echo "Iteration $i/$INODES completed"
2106         done
2107         cancel_lru_locks osc
2108         sync; sync_all_data || true
2109
2110         echo "Verify disk usage after write"
2111         USED=$(getquota -u $TSTID global curspace)
2112         [ $USED -lt $TOTAL_BLKS ] &&
2113                 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2114         USED=$(getquota -g $TSTID global curspace)
2115         [ $USED -lt $TOTAL_BLKS ] &&
2116                 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2117
2118         echo "Verify inode usage after write"
2119         USED=$(getquota -u $TSTID global curinodes)
2120         [ $USED -lt $INODES ] &&
2121                 error "Used inode for user $TSTID is $USED, expected $INODES"
2122         USED=$(getquota -g $TSTID global curinodes)
2123         [ $USED -lt $INODES ] &&
2124                 error "Used inode for group $TSTID is $USED, expected $INODES"
2125
2126         cleanup_quota_test
2127
2128         echo "Verify disk usage after delete"
2129         USED=$(getquota -u $TSTID global curspace)
2130         [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2131         USED=$(getquota -u $TSTID global curinodes)
2132         [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2133         USED=$(getquota -g $TSTID global curspace)
2134         [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2135         USED=$(getquota -g $TSTID global curinodes)
2136         [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2137 }
2138 run_test 33 "Basic usage tracking for user & group"
2139
2140 # usage transfer test for user & group
2141 test_34() {
2142         local BLK_CNT=2 # 2MB
2143
2144         setup_quota_test
2145         trap cleanup_quota_test EXIT
2146
2147         # make sure the system is clean
2148         local USED=$(getquota -u $TSTID global curspace)
2149         [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2150         USED=$(getquota -g $TSTID global curspace)
2151         [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2152
2153         local USED=$(getquota -u $TSTID2 global curspace)
2154         [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2155
2156         echo "Write file..."
2157         $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2158                 error "write failed"
2159         cancel_lru_locks osc
2160         sync; sync_all_data || true
2161
2162         echo "chown the file to user $TSTID"
2163         chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2164
2165         echo "Wait for setattr on objects finished..."
2166         wait_delete_completed
2167
2168         BLK_CNT=$((BLK_CNT * 1024))
2169
2170         echo "Verify disk usage for user $TSTID"
2171         USED=$(getquota -u $TSTID global curspace)
2172         [ $USED -lt $BLK_CNT ] &&
2173                 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2174         USED=$(getquota -u $TSTID global curinodes)
2175         [ $USED -ne 1 ] &&
2176                 error "Used inodes for user $TSTID is $USED, expected 1"
2177
2178         echo "chgrp the file to group $TSTID"
2179         chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2180
2181         echo "Wait for setattr on objects finished..."
2182         wait_delete_completed
2183
2184         echo "Verify disk usage for group $TSTID"
2185         USED=$(getquota -g $TSTID global curspace)
2186         [ $USED -ge $BLK_CNT ] ||
2187                 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2188         USED=$(getquota -g $TSTID global curinodes)
2189         [ $USED -eq 1 ] ||
2190                 error "Used inodes for group $TSTID is $USED, expected 1"
2191
2192         # chown won't change the ost object group. LU-4345 */
2193         echo "chown the file to user $TSTID2"
2194         chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2195
2196         echo "Wait for setattr on objects finished..."
2197         wait_delete_completed
2198
2199         echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2200         USED=$(getquota -u $TSTID2 global curspace)
2201         [ $USED -lt $BLK_CNT ] &&
2202                 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2203         USED=$(getquota -u $TSTID global curspace)
2204         [ $USED -ne 0 ] &&
2205                 error "Used space for user $TSTID is $USED, expected 0"
2206         USED=$(getquota -g $TSTID global curspace)
2207         [ $USED -lt $BLK_CNT ] &&
2208                 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2209
2210         cleanup_quota_test
2211 }
2212 run_test 34 "Usage transfer for user & group"
2213
2214 # usage is still accessible across restart
2215 test_35() {
2216         local BLK_CNT=2 # 2 MB
2217
2218         setup_quota_test
2219         trap cleanup_quota_test EXIT
2220
2221         echo "Write file..."
2222         $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2223                 error "write failed"
2224         cancel_lru_locks osc
2225         sync; sync_all_data || true
2226
2227         echo "Save disk usage before restart"
2228         local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2229         [ $ORIG_USR_SPACE -eq 0 ] &&
2230                 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2231         local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2232         [ $ORIG_USR_INODES -eq 0 ] &&
2233                 error "Used inodes for user $TSTID is 0, expected 1"
2234         echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2235         local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2236         [ $ORIG_GRP_SPACE -eq 0 ] &&
2237                 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2238         local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2239         [ $ORIG_GRP_INODES -eq 0 ] &&
2240                 error "Used inodes for group $TSTID is 0, expected 1"
2241         echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2242
2243         log "Restart..."
2244         local ORIG_REFORMAT=$REFORMAT
2245         REFORMAT=""
2246         cleanup_and_setup_lustre
2247         REFORMAT=$ORIG_REFORMAT
2248         quota_init
2249
2250         echo "Verify disk usage after restart"
2251         local USED=$(getquota -u $TSTID global curspace)
2252         [ $USED -eq $ORIG_USR_SPACE ] ||
2253                 error "Used space for user $TSTID changed from " \
2254                         "$ORIG_USR_SPACE to $USED"
2255         USED=$(getquota -u $TSTID global curinodes)
2256         [ $USED -eq $ORIG_USR_INODES ] ||
2257                 error "Used inodes for user $TSTID changed from " \
2258                         "$ORIG_USR_INODES to $USED"
2259         USED=$(getquota -g $TSTID global curspace)
2260         [ $USED -eq $ORIG_GRP_SPACE ] ||
2261                 error "Used space for group $TSTID changed from " \
2262                         "$ORIG_GRP_SPACE to $USED"
2263         USED=$(getquota -g $TSTID global curinodes)
2264         [ $USED -eq $ORIG_GRP_INODES ] ||
2265                 error "Used inodes for group $TSTID changed from " \
2266                         "$ORIG_GRP_INODES to $USED"
2267
2268         # check if the vfs_dq_init() is called before writing
2269         echo "Append to the same file..."
2270         $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2271                 error "write failed"
2272         cancel_lru_locks osc
2273         sync; sync_all_data || true
2274
2275         echo "Verify space usage is increased"
2276         USED=$(getquota -u $TSTID global curspace)
2277         [ $USED -gt $ORIG_USR_SPACE ] ||
2278                 error "Used space for user $TSTID isn't increased" \
2279                         "orig:$ORIG_USR_SPACE, now:$USED"
2280         USED=$(getquota -g $TSTID global curspace)
2281         [ $USED -gt $ORIG_GRP_SPACE ] ||
2282                 error "Used space for group $TSTID isn't increased" \
2283                         "orig:$ORIG_GRP_SPACE, now:$USED"
2284
2285         cleanup_quota_test
2286 }
2287 run_test 35 "Usage is still accessible across reboot"
2288
2289 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2290 # LU-5006
2291 test_37() {
2292         setup_quota_test
2293         trap cleanup_quota_test EXIT
2294
2295         # make sure the system is clean
2296         local USED=$(getquota -u $TSTID global curspace)
2297         [ $USED -ne 0 ] &&
2298                 error "Used space ($USED) for user $TSTID isn't 0."
2299
2300         # create file with MDS_OPEN_DELAY_CREATE flag
2301         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2302                 error "Create file failed"
2303         # write to file
2304         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2305                 oflag=sync || error "Write file failed"
2306         # chown to the file
2307         chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2308
2309         # wait for setattr on objects finished..."
2310         wait_delete_completed
2311
2312         USED=$(getquota -u $TSTID global curspace)
2313         [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2314
2315         cleanup_quota_test
2316 }
2317 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2318
2319 quota_fini()
2320 {
2321         do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2322 }
2323 quota_fini
2324
2325 cd $ORIG_PWD
2326 complete $SECONDS
2327 check_and_cleanup_lustre
2328 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2329 exit_status