3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
17 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
23 TSTID2=${TSTID2:-60001}
24 TSTUSR=${TSTUSR:-"quota_usr"}
25 TSTUSR2=${TSTUSR2:-"quota_2usr"}
30 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/test-framework.sh
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
35 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
37 require_dsh_mds || exit 0
38 require_dsh_ost || exit 0
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
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
53 # bug number for skipped test: LU-4515
54 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34"
56 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
57 # bug number for skipped test: LU-2872 LU-2836 LU-2836 LU-2059
58 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 1 3 6 7d"
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
65 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
67 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
72 QUOTA_AUTO_OLD=$QUOTA_AUTO
75 check_and_setup_lustre
77 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
78 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
80 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
81 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
82 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
83 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
84 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
85 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
86 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
87 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
94 local fail_val=${3:-0}
96 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
97 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
98 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
101 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
102 for num in `seq $OSTCOUNT`; do
103 do_facet ost$num "lctl set_param fail_val=$fail_val"
104 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
109 RUNAS="runas -u $TSTID -g $TSTID"
110 RUNAS2="runas -u $TSTID2 -g $TSTID2"
111 DD="dd if=/dev/zero bs=1M"
115 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
116 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
117 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
118 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
120 # clear quota limits for a user or a group
121 # usage: resetquota -u username
122 # resetquota -g groupname
125 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
126 [ "$1" != "-u" -a "$1" != "-g" ] &&
127 error "resetquota: wrong specifier $1 passed"
129 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
130 error "clear quota for [type:$1 name:$2] failed"
131 # give a chance to slave to release space
139 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
140 $LFS quota -v -u $LOCAL_ID $DIR
141 log "Files for user ($LOCAL_ID):"
142 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
143 xargs stat 2>/dev/null)
146 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
147 $LFS quota -v -u $LOCAL_ID $DIR
148 log "Files for group ($LOCAL_ID):"
149 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
150 xargs stat 2>/dev/null)
166 # get quota for a user or a group
167 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
168 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
174 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
175 [ "$1" != "-u" -a "$1" != "-g" ] &&
176 error "getquota: wrong u/g specifier $1 passed"
189 *) error "unknown quota parameter $4";;
192 [ "$uuid" = "global" ] && uuid=$DIR
194 $LFS quota -v "$1" "$2" $DIR |
195 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
196 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
201 # usage: set_mdt_qtype ug|u|g|none
205 local mdts=$(get_facets MDS)
207 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
208 # we have to make sure each MDT received config changes
209 for mdt in ${mdts//,/ }; do
211 cmd="$LCTL get_param -n "
212 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
213 cmd=${cmd}.quota_slave.enabled
215 if $(facet_up $mdt); then
216 wait_update_facet $mdt "$cmd" "$qtype" || return 1
223 # usage: set_ost_qtype ug|u|g|none
227 local osts=$(get_facets OST)
229 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
230 # we have to make sure each OST received config changes
231 for ost in ${osts//,/ }; do
233 cmd="$LCTL get_param -n "
234 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
235 cmd=${cmd}.quota_slave.enabled
237 if $(facet_up $ost); then
238 wait_update_facet $ost "$cmd" "$qtype" || return 1
244 wait_reintegration() {
248 local result="glb[1],slv[1],reint[0]"
253 if [ $ntype == "mdt" ]; then
254 tgts=$(get_facets MDS)
256 tgts=$(get_facets OST)
259 for tgt in ${tgts//,/ }; do
261 cmd="$LCTL get_param -n "
262 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
263 cmd=${cmd}.quota_slave.info
265 if $(facet_up $tgt); then
266 wait_update_facet $tgt "$cmd |
267 grep "$qtype" | awk '{ print \\\$3 }'" \
268 "$result" $max || return 1
278 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
279 wait_reintegration "mdt" "user" $max || return 1
282 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
283 wait_reintegration "mdt" "group" $max || return 1
292 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
293 wait_reintegration "ost" "user" $max || return 1
296 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
297 wait_reintegration "ost" "group" $max || return 1
304 wait_delete_completed
305 echo "Creating test directory"
307 chmod 0777 $DIR/$tdir
308 # always clear fail_loc in case of fail_loc isn't cleared
309 # properly when previous test failed
310 lustre_fail mds_ost 0
313 cleanup_quota_test() {
315 echo "Delete files..."
317 echo "Wait for unlink objects finished..."
318 wait_delete_completed
319 sync_all_data || true
328 $LFS quota -v -$ug $qid $DIR
330 if [ "$bf" == "a" -o "$bf" == "b" ]; then
331 usage=$(getquota -$ug $qid global curspace)
332 if [ -z $usage ]; then
333 quota_error $ug $qid \
334 "Query block quota failed ($ug:$qid)."
336 [ $usage -ne 0 ] && quota_log $ug $qid \
337 "Block quota isn't 0 ($ug:$qid:$usage)."
341 if [ "$bf" == "a" -o "$bf" == "f" ]; then
342 usage=$(getquota -$ug $qid global curinodes)
343 if [ -z $usage ]; then
344 quota_error $ug $qid \
345 "Query file quota failed ($ug:$qid)."
347 [ $usage -ne 0 ] && quota_log $ug $qid \
348 "File quota isn't 0 ($ug:$qid:$usage)."
355 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
359 resetquota -u $TSTUSR
360 resetquota -g $TSTUSR
361 resetquota -u $TSTUSR2
362 resetquota -g $TSTUSR2
364 test_quota_performance() {
365 local TESTFILE="$DIR/$tdir/$tfile-0"
366 local size=$1 # in MB
367 local stime=$(date +%s)
368 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
369 quota_error u $TSTUSR "write failure"
370 local etime=$(date +%s)
371 delta=$((etime - stime))
372 if [ $delta -gt 0 ]; then
373 rate=$((size * 1024 / delta))
374 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
375 # LU-2872 - see LU-2887 for fix
377 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
379 [ $rate -gt 1024 ] ||
380 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
386 # test basic quota performance b=21696
389 [ "$SLOW" = "no" ] && MB=10
391 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
392 [ $free_space -le $((MB * 1024)) ] &&
393 skip "not enough space ${free_space} KB, " \
394 "required $((MB * 1024)) KB" && return
396 trap cleanup_quota_test EXIT
398 set_ost_qtype "none" || error "disable ost quota failed"
399 test_quota_performance $MB
401 set_ost_qtype "ug" || error "enable ost quota failed"
402 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
403 error "set quota failed"
404 test_quota_performance $MB
407 resetquota -u $TSTUSR
409 run_test 0 "Test basic quota performance"
411 # test block hardlimit
414 local TESTFILE="$DIR/$tdir/$tfile-0"
417 trap cleanup_quota_test EXIT
420 set_ost_qtype "ug" || "enable ost quota failed"
423 log "User quota (block hardlimit:$LIMIT MB)"
424 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
425 error "set user quota failed"
427 # make sure the system is clean
428 local USED=$(getquota -u $TSTUSR global curspace)
429 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
431 $LFS setstripe $TESTFILE -c 1
432 chown $TSTUSR.$TSTUSR $TESTFILE
435 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
436 quota_error u $TSTUSR "user write failure, but expect success"
437 log "Write out of block quota ..."
438 # this time maybe cache write, ignore it's failure
439 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
440 # flush cache, ensure noquota flag is set on client
442 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
443 quota_error u $TSTUSR "user write success, but expect EDQUOT"
446 wait_delete_completed
447 sync_all_data || true
448 USED=$(getquota -u $TSTUSR global curspace)
449 [ $USED -ne 0 ] && quota_error u $TSTUSR \
450 "user quota isn't released after deletion"
451 resetquota -u $TSTUSR
454 log "--------------------------------------"
455 log "Group quota (block hardlimit:$LIMIT MB)"
456 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
457 error "set group quota failed"
459 TESTFILE="$DIR/$tdir/$tfile-1"
460 # make sure the system is clean
461 USED=$(getquota -g $TSTUSR global curspace)
462 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
464 $LFS setstripe $TESTFILE -c 1
465 chown $TSTUSR.$TSTUSR $TESTFILE
468 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
469 quota_error g $TSTUSR "group write failure, but expect success"
470 log "Write out of block quota ..."
471 # this time maybe cache write, ignore it's failure
472 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
474 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
475 quota_error g $TSTUSR "group write success, but expect EDQUOT"
480 USED=$(getquota -g $TSTUSR global curspace)
481 [ $USED -ne 0 ] && quota_error g $TSTUSR \
482 "group quota isn't released after deletion"
484 resetquota -g $TSTUSR
486 run_test 1 "Block hard limit (normal use and out of quota)"
488 # test inode hardlimit
490 local LIMIT=$((1024 * 1024)) # 1M inodes
491 local TESTFILE="$DIR/$tdir/$tfile-0"
493 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
495 local FREE_INODES=$(mdt_free_inodes 0)
496 echo "$FREE_INODES free inodes on master MDT"
497 [ $FREE_INODES -lt $LIMIT ] &&
498 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
502 trap cleanup_quota_test EXIT
505 set_mdt_qtype "ug" || "enable mdt quota failed"
508 log "User quota (inode hardlimit:$LIMIT files)"
509 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
510 error "set user quota failed"
512 # make sure the system is clean
513 local USED=$(getquota -u $TSTUSR global curinodes)
514 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
516 log "Create $LIMIT files ..."
517 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
518 quota_error u $TSTUSR "user create failure, but expect success"
519 log "Create out of file quota ..."
520 $RUNAS touch ${TESTFILE}_xxx && \
521 quota_error u $TSTUSR "user create success, but expect EDQUOT"
524 unlinkmany ${TESTFILE} $LIMIT
525 rm -f ${TESTFILE}_xxx
526 wait_delete_completed
528 USED=$(getquota -u $TSTUSR global curinodes)
529 [ $USED -ne 0 ] && quota_error u $TSTUSR \
530 "user quota isn't released after deletion"
531 resetquota -u $TSTUSR
534 log "--------------------------------------"
535 log "Group quota (inode hardlimit:$LIMIT files)"
536 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
537 error "set group quota failed"
539 TESTFILE=$DIR/$tdir/$tfile-1
540 # make sure the system is clean
541 USED=$(getquota -g $TSTUSR global curinodes)
542 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
544 log "Create $LIMIT files ..."
545 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
546 quota_error g $TSTUSR "group create failure, but expect success"
547 log "Create out of file quota ..."
548 $RUNAS touch ${TESTFILE}_xxx && \
549 quota_error g $TSTUSR "group create success, but expect EDQUOT"
552 unlinkmany ${TESTFILE} $LIMIT
553 rm -f ${TESTFILE}_xxx
554 wait_delete_completed
556 USED=$(getquota -g $TSTUSR global curinodes)
557 [ $USED -ne 0 ] && quota_error g $TSTUSR \
558 "user quota isn't released after deletion"
561 resetquota -g $TSTUSR
563 run_test 2 "File hard limit (normal use and out of quota)"
567 local TIMER=$(($2 * 3 / 2))
572 trap cleanup_quota_test EXIT
574 $LFS setstripe $TESTFILE -c 1 -i 0
575 chown $TSTUSR.$TSTUSR $TESTFILE
577 echo "Write up to soft limit"
578 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
579 quota_error a $TSTUSR "write failure, but expect success"
580 OFFSET=$((LIMIT * 1024))
583 echo "Write to exceed soft limit"
584 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
585 quota_error a $TSTUSR "write failure, but expect success"
586 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
591 $SHOW_QUOTA_INFO_USER
592 $SHOW_QUOTA_INFO_GROUP
594 echo "Write before timer goes off"
595 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
596 quota_error a $TSTUSR "write failure, but expect success"
597 OFFSET=$((OFFSET + 1024))
600 echo "Sleep $TIMER seconds ..."
605 $SHOW_QUOTA_INFO_USER
606 $SHOW_QUOTA_INFO_GROUP
608 echo "Write after timer goes off"
609 # maybe cache write, ignore.
610 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
611 OFFSET=$((OFFSET + 1024))
613 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
614 quota_error a $TSTUSR "write success, but expect EDQUOT"
618 $SHOW_QUOTA_INFO_USER
619 $SHOW_QUOTA_INFO_GROUP
621 echo "Unlink file to stop timer"
623 wait_delete_completed
624 sync_all_data || true
628 $SHOW_QUOTA_INFO_USER
629 $SHOW_QUOTA_INFO_GROUP
631 $LFS setstripe $TESTFILE -c 1 -i 0
632 chown $TSTUSR.$TSTUSR $TESTFILE
635 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
636 quota_error a $TSTUSR "write failure, but expect success"
645 local TESTFILE=$DIR/$tdir/$tfile-0
647 set_ost_qtype "ug" || error "enable ost quota failed"
649 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
650 # make sure the system is clean
651 local USED=$(getquota -u $TSTUSR global curspace)
652 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
654 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
655 $MAX_IQ_TIME $DIR || error "set user grace time failed"
656 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
657 error "set user quota failed"
659 test_block_soft $TESTFILE $GRACE $LIMIT
660 resetquota -u $TSTUSR
662 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
663 TESTFILE=$DIR/$tdir/$tfile-1
664 # make sure the system is clean
665 USED=$(getquota -g $TSTUSR global curspace)
666 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
668 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
669 $MAX_IQ_TIME $DIR || error "set group grace time failed"
670 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
671 error "set group quota failed"
673 test_block_soft $TESTFILE $GRACE $LIMIT
674 resetquota -g $TSTUSR
677 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
678 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
679 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
680 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
682 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
687 local TIMER=$(($3 * 3 / 2))
690 trap cleanup_quota_test EXIT
692 echo "Create files to exceed soft limit"
693 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
694 quota_error a $TSTUSR "create failure, but expect success"
697 echo "Create file before timer goes off"
698 $RUNAS touch ${TESTFILE}_before ||
699 quota_error a $TSTUSR "failed create before timer expired," \
703 echo "Sleep $TIMER seconds ..."
708 $SHOW_QUOTA_INFO_USER
709 $SHOW_QUOTA_INFO_GROUP
711 echo "Create file after timer goes off"
712 # There is a window that space is accounted in the quota usage but
713 # hasn't been decreased from the pending write, if we acquire quota
714 # in this window, we'll acquire more than we needed.
715 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
717 $RUNAS touch ${TESTFILE}_after_3 &&
718 quota_error a $TSTUSR "create after timer expired," \
724 $SHOW_QUOTA_INFO_USER
725 $SHOW_QUOTA_INFO_GROUP
727 echo "Unlink files to stop timer"
728 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
729 wait_delete_completed
732 $RUNAS touch ${TESTFILE}_xxx ||
733 quota_error a $TSTUSR "touch after timer stop failure," \
743 local LIMIT=10 # inodes
744 local TESTFILE=$DIR/$tdir/$tfile-0
747 set_mdt_qtype "ug" || error "enable mdt quota failed"
749 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
750 # make sure the system is clean
751 local USED=$(getquota -u $TSTUSR global curinodes)
752 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
754 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
755 $GRACE $DIR || error "set user grace time failed"
756 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
757 error "set user quota failed"
759 test_file_soft $TESTFILE $LIMIT $GRACE
760 resetquota -u $TSTUSR
762 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
763 # make sure the system is clean
764 USED=$(getquota -g $TSTUSR global curinodes)
765 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
767 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
768 $GRACE $DIR || error "set group grace time failed"
769 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
770 error "set group quota failed"
771 TESTFILE=$DIR/$tdir/$tfile-1
773 test_file_soft $TESTFILE $LIMIT $GRACE
774 resetquota -g $TSTUSR
777 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
778 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
779 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
780 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
782 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
786 local GR_STR2="1000s"
788 local GR_STR4="1w2d3h4m5s"
790 local GR_STR6="1111111111111111"
792 wait_delete_completed
794 # test of valid grace strings handling
795 echo "Valid grace strings test"
796 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
797 $GR_STR2 $DIR || error "set user grace time failed"
798 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
799 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
800 $GR_STR4 $DIR || error "set group grace time quota failed"
801 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
803 # test of invalid grace strings handling
804 echo " Invalid grace strings test"
805 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
806 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
809 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
810 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
811 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
812 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
814 run_test 4b "Grace time strings handling"
816 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
818 local BLIMIT=10 # 10M
819 local ILIMIT=10 # 10 inodes
822 trap cleanup_quota_test EXIT
824 set_mdt_qtype "ug" || error "enable mdt quota failed"
825 set_ost_qtype "ug" || error "enable ost quota failed"
827 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
828 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
829 error "set user quota failed"
830 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
831 error "set group quota failed"
833 # make sure the system is clean
834 local USED=$(getquota -u $TSTUSR global curinodes)
835 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
836 USED=$(getquota -g $TSTUSR global curinodes)
837 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
838 USED=$(getquota -u $TSTUSR global curspace)
839 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
840 USED=$(getquota -g $TSTUSR global curspace)
841 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
843 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
844 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
845 error "create failure, expect success"
846 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
847 error "write failure, expect success"
849 echo "Chown files to $TSTUSR.$TSTUSR ..."
850 for i in `seq 0 $ILIMIT`; do
851 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
852 quota_error a $TSTUSR "chown failure, expect success"
856 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
859 resetquota -u $TSTUSR
860 resetquota -g $TSTUSR
862 run_test 5 "Chown & chgrp successfully even out of block/file quota"
864 # test dropping acquire request on master
867 [ $MDSCOUNT -ge 2 ] && skip "disable test_6 for DNE temporary" && return
871 # Clear dmesg so watchdog is not triggered by previous
873 do_facet ost1 dmesg -c > /dev/null
876 trap cleanup_quota_test EXIT
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."
882 # make sure no granted quota on ost
883 set_ost_qtype "ug" || error "enable ost quota failed"
884 resetquota -u $TSTUSR
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
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
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"
904 sync_all_data || true
906 #define QUOTA_DQACQ 601
907 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
908 lustre_fail mds 0x513 601
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"
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 &
919 # watchdog timer uses a factor of 2
920 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
921 sleep $((TIMEOUT * 2 + 1))
923 # write should be blocked and never finished
924 if ! ps -p $DDPID > /dev/null 2>&1; then
926 error "write finished incorrectly!"
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"
937 rm -f $TMP/lustre-log-${TESTNAME}.log
939 # write should continue & succeed
941 local o_size=$(stat -c %s $TESTFILE)
944 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
945 if [ $count -ge 240 ]; then
946 quota_error u $TSTUSR "dd not finished in $count secs"
949 if [ $((count % 30)) -eq 0 ]; then
950 c_size=$(stat -c %s $TESTFILE)
951 if [ $c_size -eq $o_size ]; then
952 quota_error u $TSTUSR "file not growed" \
953 "in 30 seconds $o_size/$c_size"
955 echo "Waiting $count secs. $o_size/$c_size"
963 resetquota -u $TSTUSR
965 run_test 6 "Test dropping acquire request on master"
967 # quota reintegration (global index)
969 local TESTFILE=$DIR/$tdir/$tfile
972 [ "$SLOW" = "no" ] && LIMIT=5
975 trap cleanup_quota_test EXIT
977 # make sure the system is clean
978 local USED=$(getquota -u $TSTUSR global curspace)
979 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
981 # make sure no granted quota on ost1
982 set_ost_qtype "ug" || error "enable ost quota failed"
983 resetquota -u $TSTUSR
984 set_ost_qtype "none" || error "disable ost quota failed"
986 local OSTUUID=$(ostuuid_from_index 0)
987 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
988 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
992 $LFS setstripe $TESTFILE -c 1 -i 0
993 chown $TSTUSR.$TSTUSR $TESTFILE
998 echo "Enable quota & set quota limit for $TSTUSR"
999 set_ost_qtype "ug" || error "enable ost quota failed"
1000 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1001 error "set quota failed"
1003 echo "Start ost1..."
1004 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1007 wait_ost_reint "ug" || error "reintegration failed"
1009 # hardlimit should have been fetched by slave during global
1010 # reintegration, write will exceed quota
1011 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1012 quota_error u $TSTUSR "write success, but expect EDQUOT"
1015 wait_delete_completed
1016 sync_all_data || true
1022 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1023 error "clear quota failed"
1025 echo "Start ost1..."
1026 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1029 wait_ost_reint "ug" || error "reintegration failed"
1031 # hardlimit should be cleared on slave during reintegration
1032 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1033 quota_error u $TSTUSR "write error, but expect success"
1036 resetquota -u $TSTUSR
1038 run_test 7a "Quota reintegration (global index)"
1040 # quota reintegration (slave index)
1043 local TESTFILE=$DIR/$tdir/$tfile
1046 trap cleanup_quota_test EXIT
1048 # make sure the system is clean
1049 local USED=$(getquota -u $TSTUSR global curspace)
1050 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1052 # make sure no granted quota on ost1
1053 set_ost_qtype "ug" || error "enable ost quota failed"
1054 resetquota -u $TSTUSR
1055 set_ost_qtype "none" || error "disable ost quota failed"
1057 local OSTUUID=$(ostuuid_from_index 0)
1058 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1059 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1063 $LFS setstripe $TESTFILE -c 1 -i 0
1064 chown $TSTUSR.$TSTUSR $TESTFILE
1066 # consume some space to make sure the granted space will not
1067 # be released during reconciliation
1068 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1069 error "consume space failure, expect success"
1071 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1072 lustre_fail mds 0xa02
1074 set_ost_qtype "ug" || error "enable ost quota failed"
1075 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1076 error "set quota failed"
1078 # ignore the write error
1079 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1081 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1085 echo "Restart ost to trigger reintegration..."
1087 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1090 wait_ost_reint "ug" || error "reintegration failed"
1092 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1093 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1096 resetquota -u $TSTUSR
1099 run_test 7b "Quota reintegration (slave index)"
1101 # quota reintegration (restart mds during reintegration)
1103 local LIMIT=20 # 20M
1104 local TESTFILE=$DIR/$tdir/$tfile
1106 [ "$SLOW" = "no" ] && LIMIT=5
1109 trap cleanup_quota_test EXIT
1111 # make sure the system is clean
1112 local USED=$(getquota -u $TSTUSR global curspace)
1113 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1115 set_ost_qtype "none" || error "disable ost quota failed"
1116 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1117 error "set quota failed"
1119 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1120 lustre_fail ost 0xa03
1123 set_ost_qtype "ug" || error "enable ost quota failed"
1124 # trigger reintegration
1125 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1126 procf=${procf}quota_slave.force_reint
1127 do_facet ost1 $LCTL set_param $procf=1 ||
1128 error "force reintegration failed"
1136 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1139 # wait longer than usual to make sure the reintegration
1140 # is triggered by quota wb thread.
1141 wait_ost_reint "ug" 200 || error "reintegration failed"
1143 # hardlimit should have been fetched by slave during global
1144 # reintegration, write will exceed quota
1145 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1146 quota_error u $TSTUSR "write success, but expect EDQUOT"
1149 resetquota -u $TSTUSR
1151 run_test 7c "Quota reintegration (restart mds during reintegration)"
1153 # Quota reintegration (Transfer index in multiple bulks)
1155 local TESTFILE=$DIR/$tdir/$tfile
1156 local TESTFILE1="$DIR/$tdir/$tfile"-1
1160 trap cleanup_quota_test EXIT
1162 set_ost_qtype "none" || error "disable ost quota failed"
1163 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1164 error "set quota for $TSTUSR failed"
1165 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1166 error "set quota for $TSTUSR2 failed"
1168 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1169 lustre_fail mds 0x608 0
1171 # enable quota to tirgger reintegration
1172 set_ost_qtype "u" || error "enable ost quota failed"
1173 wait_ost_reint "u" || error "reintegration failed"
1177 # hardlimit should have been fetched by slave during global
1178 # reintegration, write will exceed quota
1179 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1180 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1182 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1183 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1186 resetquota -u $TSTUSR
1187 resetquota -u $TSTUSR2
1189 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1191 # quota reintegration (inode limits)
1193 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1195 local ilimit=$((1024 * 2)) # 2k inodes
1196 local TESTFILE=$DIR/${tdir}-1/$tfile
1199 trap cleanup_quota_test EXIT
1201 # make sure the system is clean
1202 local USED=$(getquota -u $TSTUSR global curinodes)
1203 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1205 # make sure no granted quota on mdt1
1206 set_mdt_qtype "ug" || error "enable mdt quota failed"
1207 resetquota -u $TSTUSR
1208 set_mdt_qtype "none" || error "disable mdt quota failed"
1210 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1211 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1212 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1215 echo "Stop mds${MDSCOUNT}..."
1218 echo "Enable quota & set quota limit for $TSTUSR"
1219 set_mdt_qtype "ug" || error "enable mdt quota failed"
1220 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1221 error "set quota failed"
1223 echo "Start mds${MDSCOUNT}..."
1224 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1227 wait_mdt_reint "ug" || error "reintegration failed"
1229 echo "create remote dir"
1230 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1231 error "create remote dir failed"
1232 chmod 0777 $DIR/${tdir}-1
1234 # hardlimit should have been fetched by slave during global
1235 # reintegration, create will exceed quota
1236 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1237 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1239 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1240 wait_delete_completed
1241 sync_all_data || true
1243 echo "Stop mds${MDSCOUNT}..."
1246 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1247 error "clear quota failed"
1249 echo "Start mds${MDSCOUNT}..."
1250 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1253 wait_mdt_reint "ug" || error "reintegration failed"
1255 # hardlimit should be cleared on slave during reintegration
1256 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1257 quota_error -u $TSTUSR "create failed, expect success"
1259 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1260 rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1263 resetquota -u $TSTUSR
1265 run_test 7e "Quota reintegration (inode limits)"
1267 # run dbench with quota enabled
1269 local BLK_LIMIT="100g" #100G
1270 local FILE_LIMIT=1000000
1273 trap cleanup_quota_test EXIT
1275 set_mdt_qtype "ug" || error "enable mdt quota failed"
1276 set_ost_qtype "ug" || error "enable ost quota failed"
1278 echo "Set enough high limit for user: $TSTUSR"
1279 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1280 error "set user quota failed"
1281 echo "Set enough high limit for group: $TSTUSR"
1282 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1283 error "set group quota failed"
1286 [ "$SLOW" = "no" ] && duration=" -t 120"
1287 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1288 quota_error a $TSTUSR "dbench failed!"
1291 resetquota -u $TSTUSR
1292 resetquota -g $TSTUSR
1294 run_test 8 "Run dbench with quota enabled"
1296 # this check is just for test_9
1297 OST0_MIN=4900000 #4.67G
1299 check_whether_skip () {
1300 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1301 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1302 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1303 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1310 # run for fixing bug10707, it needs a big room. test for 64bit
1312 local filesize=$((1024 * 9 / 2)) # 4.5G
1314 check_whether_skip && return 0
1317 trap cleanup_quota_test EXIT
1319 set_ost_qtype "ug" || error "enable ost quota failed"
1321 local TESTFILE="$DIR/$tdir/$tfile-0"
1322 local BLK_LIMIT=100G #100G
1323 local FILE_LIMIT=1000000
1325 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1327 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1329 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1330 error "set user quota failed"
1332 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1333 "for group: $TSTUSR"
1334 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1335 error "set group quota failed"
1337 quota_show_check a u $TSTUSR
1338 quota_show_check a g $TSTUSR
1340 echo "Create test file"
1341 $LFS setstripe $TESTFILE -c 1 -i 0
1342 chown $TSTUSR.$TSTUSR $TESTFILE
1344 log "Write the big file of 4.5G ..."
1345 $RUNAS $DD of=$TESTFILE count=$filesize ||
1346 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1352 resetquota -u $TSTUSR
1353 resetquota -g $TSTUSR
1358 run_test 9 "Block limit larger than 4GB (b10707)"
1361 local TESTFILE=$DIR/$tdir/$tfile
1364 trap cleanup_quota_test EXIT
1366 # set limit to root user should fail
1367 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1368 error "set limit for root user successfully, expect failure"
1369 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1370 error "set limit for root group successfully, expect failure"
1372 # root user can overrun quota
1373 set_ost_qtype "ug" || "enable ost quota failed"
1375 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1376 error "set quota failed"
1377 quota_show_check b u $TSTUSR
1379 $LFS setstripe $TESTFILE -c 1
1380 chown $TSTUSR.$TSTUSR $TESTFILE
1382 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1383 error "write failure, expect success"
1386 resetquota -u $TSTUSR
1388 run_test 10 "Test quota for root user"
1391 local TESTFILE=$DIR/$tdir/$tfile
1393 trap cleanup_quota_test EXIT
1395 set_mdt_qtype "ug" || "enable mdt quota failed"
1396 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1397 error "set quota failed"
1402 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1403 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1406 local USED=$(getquota -u $TSTUSR global curinodes)
1407 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1410 resetquota -u $TSTUSR
1412 run_test 11 "Chown/chgrp ignores quota"
1415 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1417 local blimit=22 # 22M
1418 local blk_cnt=$((blimit - 5))
1419 local TESTFILE0="$DIR/$tdir/$tfile"-0
1420 local TESTFILE1="$DIR/$tdir/$tfile"-1
1423 trap cleanup_quota_test EXIT
1425 set_ost_qtype "u" || "enable ost quota failed"
1426 quota_show_check b u $TSTUSR
1428 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1429 error "set quota failed"
1431 $LFS setstripe $TESTFILE0 -c 1 -i 0
1432 $LFS setstripe $TESTFILE1 -c 1 -i 1
1433 chown $TSTUSR.$TSTUSR $TESTFILE0
1434 chown $TSTUSR.$TSTUSR $TESTFILE1
1436 echo "Write to ost0..."
1437 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1438 quota_error a $TSTUSR "dd failed"
1440 echo "Write to ost1..."
1441 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1442 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1444 echo "Free space from ost0..."
1446 wait_delete_completed
1447 sync_all_data || true
1449 echo "Write to ost1 after space freed from ost0..."
1450 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1451 quota_error a $TSTUSR "rebalancing failed"
1454 resetquota -u $TSTUSR
1456 run_test 12a "Block quota rebalancing"
1459 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1461 local ilimit=$((1024 * 2)) # 2k inodes
1462 local TESTFILE0=$DIR/$tdir/$tfile
1463 local TESTFILE1=$DIR/${tdir}-1/$tfile
1466 trap cleanup_quota_test EXIT
1468 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1469 chmod 0777 $DIR/${tdir}-1
1471 set_mdt_qtype "u" || "enable mdt quota failed"
1472 quota_show_check f u $TSTUSR
1474 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1475 error "set quota failed"
1477 echo "Create $ilimit files on mdt0..."
1478 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1479 quota_error u $TSTUSR "create failed, but expect success"
1481 echo "Create files on mdt1..."
1482 $RUNAS createmany -m $TESTFILE1 1 &&
1483 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1485 echo "Free space from mdt0..."
1486 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1487 wait_delete_completed
1488 sync_all_data || true
1490 echo "Create files on mdt1 after space freed from mdt0..."
1491 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1492 quota_error a $TSTUSR "rebalancing failed"
1494 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1495 error "unlink mdt1 files failed"
1496 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1499 resetquota -u $TSTUSR
1501 run_test 12b "Inode quota rebalancing"
1504 local TESTFILE=$DIR/$tdir/$tfile
1505 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1506 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1509 trap cleanup_quota_test EXIT
1511 set_ost_qtype "u" || "enable ost quota failed"
1512 quota_show_check b u $TSTUSR
1514 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1515 error "set quota failed"
1516 $LFS setstripe $TESTFILE -c 1 -i 0
1517 chown $TSTUSR.$TSTUSR $TESTFILE
1519 # clear the locks in cache first
1520 do_facet ost1 $LCTL set_param -n $procf=clear
1521 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1522 [ $nlock -eq 0 ] || error "$nlock cached locks"
1524 # write to acquire the per-ID lock
1525 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1526 quota_error a $TSTUSR "dd failed"
1528 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1529 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1531 # clear quota doesn't trigger per-ID lock cancellation
1532 resetquota -u $TSTUSR
1533 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1534 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1536 # clear the per-ID lock
1537 do_facet ost1 $LCTL set_param -n $procf=clear
1538 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1539 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1541 # spare quota should be released
1542 local OSTUUID=$(ostuuid_from_index 0)
1543 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1544 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1545 [ $limit -le $space ] ||
1546 error "spare quota isn't released, limit:$limit, space:$space"
1550 run_test 13 "Cancel per-ID lock in the LRU list"
1553 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1555 wait_delete_completed
1556 sync_all_data || true
1559 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1560 error "set user quota failed"
1561 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1562 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1563 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1564 resetquota -u $TSTUSR
1567 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1568 error "set group quota failed"
1569 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1570 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1571 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1572 resetquota -g $TSTUSR
1574 run_test 15 "Set over 4T block quota"
1578 local BLKS=1 # 1M less than limit
1579 local TESTFILE=$DIR/$tdir/$tfile
1582 trap cleanup_quota_test EXIT
1584 # make sure the system is clean
1585 local USED=$(getquota -u $TSTUSR global curspace)
1586 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1588 set_ost_qtype "ug" || error "enable ost quota failed"
1589 # make sure no granted quota on ost
1590 resetquota -u $TSTUSR
1591 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1592 error "set quota failed"
1594 quota_show_check b u $TSTUSR
1596 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1597 lustre_fail mds 0xa04 $err_code
1599 # write in background
1600 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1604 # write should be blocked and never finished
1605 if ! ps -p $DDPID > /dev/null 2>&1; then
1607 quota_error u $TSTUSR "write finished incorrectly!"
1615 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1617 if [ $count -gt $timeout ]; then
1618 quota_error u $TSTUSR "dd is not finished!"
1623 sync; sync_all_data || true
1625 USED=$(getquota -u $TSTUSR global curspace)
1626 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1627 "Used space(${USED}K) is less than ${BLKS}M"
1630 resetquota -u $TSTUSR
1633 # DQACQ return recoverable error
1635 echo "DQACQ return -ENOLCK"
1637 test_17sub 37 || error "Handle -ENOLCK failed"
1639 echo "DQACQ return -EAGAIN"
1641 test_17sub 11 || error "Handle -EAGAIN failed"
1643 echo "DQACQ return -ETIMEDOUT"
1644 #define ETIMEDOUT 110
1645 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1647 echo "DQACQ return -ENOTCONN"
1648 #define ENOTCONN 107
1649 test_17sub 107 || error "Handle -ENOTCONN failed"
1652 run_test 17 "DQACQ return recoverable error"
1656 local blimit="200m" # 200M
1657 local TESTFILE="$DIR/$tdir/$tfile"
1660 trap cleanup_quota_test EXIT
1662 set_ost_qtype "u" || error "enable ost quota failed"
1663 log "User quota (limit: $blimit)"
1664 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1665 error "set quota failed"
1666 quota_show_check b u $TSTUSR
1668 $LFS setstripe $TESTFILE -i 0 -c 1
1669 chown $TSTUSR.$TSTUSR $TESTFILE
1671 local timeout=$(sysctl -n lustre.timeout)
1673 if [ $io_type = "directio" ]; then
1674 log "Write 100M (directio) ..."
1675 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1677 log "Write 100M (buffered) ..."
1678 $RUNAS $DD of=$TESTFILE count=100 &
1682 replay_barrier $SINGLEMDS
1683 log "Fail mds for $((2 * timeout)) seconds"
1684 fail $SINGLEMDS $((2 * timeout))
1687 if at_is_enabled; then
1688 timeout=$(at_max_get mds)
1690 timeout=$(lctl get_param -n timeout)
1694 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1695 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1696 log "it took $count second"
1701 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1703 cancel_lru_locks mdc
1704 cancel_lru_locks osc
1707 local testfile_size=$(stat -c %s $TESTFILE)
1708 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1709 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1710 "got ${testfile_size}. Verifying file failed!"
1713 resetquota -u $TSTUSR
1716 # test when mds does failover, the ost still could work well
1717 # this test shouldn't trigger watchdog b=14840
1719 # Clear dmesg so watchdog is not triggered by previous
1721 do_facet ost1 dmesg -c > /dev/null
1724 test_18_sub directio
1726 # check if watchdog is triggered
1727 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1728 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1729 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1730 [ -z "$watchdog" ] || error "$watchdog"
1731 rm -f $TMP/lustre-log-${TESTNAME}.log
1733 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1737 local TESTFILE=$DIR/$tdir/$tfile
1740 trap cleanup_quota_test EXIT
1742 set_ost_qtype "ug" || error "enable ost quota failed"
1744 # bind file to a single OST
1745 $LFS setstripe -c 1 $TESTFILE
1746 chown $TSTUSR.$TSTUSR $TESTFILE
1748 echo "Set user quota (limit: "$blimit"M)"
1749 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1750 error "set user quota failed"
1751 quota_show_check b u $TSTUSR
1752 echo "Update quota limits"
1753 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1754 error "set group quota failed"
1755 quota_show_check b u $TSTUSR
1757 # first wirte might be cached
1758 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1759 cancel_lru_locks osc
1761 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1762 quota_error u $TSTUSR "Write success, expect failure"
1766 resetquota -u $TSTUSR
1768 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1770 test_20() { # b15754
1771 local LSTR=(2g 1t 4k 3m) # limits strings
1773 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1775 resetquota -u $TSTUSR
1777 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1778 $MOUNT || error "could not set quota limits"
1779 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1780 --inode-softlimit ${LSTR[2]} \
1781 --inode-hardlimit ${LSTR[3]} \
1782 $MOUNT || error "could not set quota limits"
1784 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1785 error "bsoftlimit was not set properly"
1786 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1787 error "bhardlimit was not set properly"
1788 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1789 error "isoftlimit was not set properly"
1790 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1791 error "ihardlimit was not set properly"
1793 resetquota -u $TSTUSR
1795 run_test 20 "Test if setquota specifiers work properly (b15754)"
1802 local time=$(($(date +%s) + seconds))
1803 while [ $(date +%s) -lt $time ]; do
1804 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1808 # run for fixing bug16053, setquota shouldn't fail when writing and
1809 # deleting are happening
1811 local TESTFILE="$DIR/$tdir/$tfile"
1812 local BLIMIT=10 # 10G
1813 local ILIMIT=1000000
1816 trap cleanup_quota_test EXIT
1818 set_ost_qtype "ug" || error "Enable ost quota failed"
1820 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1821 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1822 error "set user quota failed"
1823 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1824 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1825 error "set group quota failed"
1827 # repeat writing on a 1M file
1828 test_21_sub ${TESTFILE}_1 1 30 &
1830 # repeat writing on a 128M file
1831 test_21_sub ${TESTFILE}_2 128 30 &
1834 local time=$(($(date +%s) + 30))
1836 while [ $(date +%s) -lt $time ]; do
1837 log "Set quota for $i times"
1838 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1839 -I $((ILIMIT + i)) $MOUNT ||
1840 error "Set user quota failed"
1841 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1842 -I $((ILIMIT + i)) $MOUNT ||
1843 error "Set group quota failed"
1850 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1852 if [ $count -gt 60 ]; then
1853 quota_error a $TSTUSR "dd should be finished!"
1857 echo "(dd_pid=$DDPID1, time=$count)successful"
1861 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1863 if [ $count -gt 60 ]; then
1864 quota_error a $TSTUSR "dd should be finished!"
1868 echo "(dd_pid=$DDPID2, time=$count)successful"
1871 resetquota -u $TSTUSR
1872 resetquota -g $TSTUSR
1874 run_test 21 "Setquota while writing & deleting (b16053)"
1876 # enable/disable quota enforcement permanently
1878 echo "Set both mdt & ost quota type as ug"
1879 set_mdt_qtype "ug" || error "enable mdt quota failed"
1880 set_ost_qtype "ug" || error "enable ost quota failed"
1887 echo "Verify if quota is enabled"
1888 local qtype=$(mdt_quota_type)
1889 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1890 qtype=$(ost_quota_type)
1891 [ $qtype != "ug" ] && error "ost quota setting is lost"
1893 echo "Set both mdt & ost quota type as none"
1894 set_mdt_qtype "none" || error "disable mdt quota failed"
1895 set_ost_qtype "none" || error "disable ost quota failed"
1903 echo "Verify if quota is disabled"
1904 qtype=$(mdt_quota_type)
1905 [ $qtype != "none" ] && error "mdt quota setting is lost"
1906 qtype=$(ost_quota_type)
1907 [ $qtype != "none" ] && error "ost quota setting is lost"
1911 run_test 22 "enable/disable quota by 'lctl conf_param'"
1914 local TESTFILE="$DIR/$tdir/$tfile"
1918 trap cleanup_quota_test EXIT
1920 set_ost_qtype "ug" || error "Enable ost quota failed"
1923 log "User quota (limit: $LIMIT MB)"
1924 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1925 error "set quota failed"
1926 quota_show_check b u $TSTUSR
1928 $LFS setstripe $TESTFILE -c 1 -i 0
1929 chown $TSTUSR.$TSTUSR $TESTFILE
1931 log "Step1: trigger EDQUOT with O_DIRECT"
1932 log "Write half of file"
1933 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1934 quota_error u $TSTUSR "(1) Write failure, expect success." \
1936 log "Write out of block quota ..."
1937 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1938 oflag=direct conv=notrunc &&
1939 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1943 log "Step2: rewrite should succeed"
1944 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1945 quota_error u $TSTUSR "(3) Write failure, expect success." \
1951 local OST0_UUID=$(ostuuid_from_index 0)
1952 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1953 [ $OST0_QUOTA_USED -ne 0 ] &&
1954 ($SHOW_QUOTA_USER; \
1955 quota_error u $TSTUSR "quota isn't released")
1957 resetquota -u $TSTUSR
1961 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1962 check_whether_skip && return 0
1963 log "run for 4MB test file"
1966 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1967 check_whether_skip && return 0
1968 log "run for 40MB test file"
1971 run_test 23 "Quota should be honored with directIO (b16125)"
1975 local TESTFILE="$DIR/$tdir/$tfile"
1978 trap cleanup_quota_test EXIT
1980 set_ost_qtype "ug" || error "enable ost quota failed"
1982 # bind file to a single OST
1983 $LFS setstripe -c 1 $TESTFILE
1984 chown $TSTUSR.$TSTUSR $TESTFILE
1986 echo "Set user quota (limit: "$blimit"M)"
1987 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1988 error "set quota failed"
1990 # overrun quota by root user
1991 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1992 error "write failure, expect success"
1993 cancel_lru_locks osc
1994 sync_all_data || true
1996 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1999 resetquota -u $TSTUSR
2001 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2003 test_27a() { # b19612
2004 $LFS quota $TSTUSR $DIR &&
2005 error "lfs succeeded with no type, but should have failed"
2006 $LFS setquota $TSTUSR $DIR &&
2007 error "lfs succeeded with no type, but should have failed"
2010 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2012 test_27b() { # b20200
2013 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2014 error "lfs setquota failed with uid argument"
2015 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2016 error "lfs stequota failed with gid argument"
2017 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2018 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2019 resetquota -u $TSTUSR
2020 resetquota -g $TSTUSR
2023 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2028 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2029 error "lfs setquota failed"
2031 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2032 [ $limit != "30M" ] && error "softlimit isn't human-readable"
2033 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2034 [ $limit != "3T" ] && error "hardlimit isn't human-readable"
2036 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2037 error "total allocated inode/block limit not printed"
2039 resetquota -u $TSTUSR
2041 run_test 27c "lfs quota should support human-readable output"
2046 local TESTFILE="$DIR/$tdir/$tfile"
2050 trap cleanup_quota_test EXIT
2052 set_ost_qtype "u" || error "enable ost quota failed"
2054 $LFS setstripe $TESTFILE -i 0 -c 1
2055 chown $TSTUSR.$TSTUSR $TESTFILE
2057 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2058 $MAX_IQ_TIME $DIR || error "set grace time failed"
2059 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2060 error "set quota failed"
2061 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2062 cancel_lru_locks osc
2064 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2065 # over-quota flag has not yet settled since we do not trigger async
2066 # events based on grace time period expiration
2068 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
2069 cancel_lru_locks osc
2070 # now over-quota flag should be settled and further writes should fail
2072 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
2073 error "grace times were reset"
2076 resetquota -u $TSTUSR
2077 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2078 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2080 run_test 30 "Hard limit updates should not reset grace times"
2082 # basic usage tracking for user & group
2084 local INODES=10 # 10 files
2085 local BLK_CNT=2 # of 2M each
2086 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2089 trap cleanup_quota_test EXIT
2091 # make sure the system is clean
2092 local USED=$(getquota -u $TSTID global curspace)
2094 error "Used space ($USED) for user $TSTID isn't 0."
2095 USED=$(getquota -g $TSTID global curspace)
2097 error "Used space ($USED) for group $TSTID isn't 0."
2099 echo "Write files..."
2100 for i in `seq 0 $INODES`; do
2101 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2102 error "write failed"
2103 echo "Iteration $i/$INODES completed"
2105 cancel_lru_locks osc
2106 sync; sync_all_data || true
2108 echo "Verify disk usage after write"
2109 USED=$(getquota -u $TSTID global curspace)
2110 [ $USED -lt $TOTAL_BLKS ] &&
2111 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2112 USED=$(getquota -g $TSTID global curspace)
2113 [ $USED -lt $TOTAL_BLKS ] &&
2114 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2116 echo "Verify inode usage after write"
2117 USED=$(getquota -u $TSTID global curinodes)
2118 [ $USED -lt $INODES ] &&
2119 error "Used inode for user $TSTID is $USED, expected $INODES"
2120 USED=$(getquota -g $TSTID global curinodes)
2121 [ $USED -lt $INODES ] &&
2122 error "Used inode for group $TSTID is $USED, expected $INODES"
2126 echo "Verify disk usage after delete"
2127 USED=$(getquota -u $TSTID global curspace)
2128 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2129 USED=$(getquota -u $TSTID global curinodes)
2130 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2131 USED=$(getquota -g $TSTID global curspace)
2132 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2133 USED=$(getquota -g $TSTID global curinodes)
2134 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2136 run_test 33 "Basic usage tracking for user & group"
2138 # usage transfer test for user & group
2140 local BLK_CNT=2 # 2MB
2143 trap cleanup_quota_test EXIT
2145 # make sure the system is clean
2146 local USED=$(getquota -u $TSTID global curspace)
2147 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2148 USED=$(getquota -g $TSTID global curspace)
2149 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2151 echo "Write file..."
2152 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2153 error "write failed"
2154 cancel_lru_locks osc
2155 sync; sync_all_data || true
2157 echo "chown the file to user $TSTID"
2158 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2160 echo "Wait for setattr on objects finished..."
2161 wait_delete_completed
2163 BLK_CNT=$((BLK_CNT * 1024))
2165 echo "Verify disk usage for user $TSTID"
2166 USED=$(getquota -u $TSTID global curspace)
2167 [ $USED -lt $BLK_CNT ] &&
2168 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2169 USED=$(getquota -u $TSTID global curinodes)
2171 error "Used inodes for user $TSTID is $USED, expected 1"
2173 echo "chgrp the file to group $TSTID"
2174 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2176 echo "Wait for setattr on objects finished..."
2177 wait_delete_completed
2179 echo "Verify disk usage for group $TSTID"
2180 USED=$(getquota -g $TSTID global curspace)
2181 [ $USED -ge $BLK_CNT ] ||
2182 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2183 USED=$(getquota -g $TSTID global curinodes)
2185 error "Used inodes for group $TSTID is $USED, expected 1"
2189 run_test 34 "Usage transfer for user & group"
2191 # usage is still accessible across restart
2193 local BLK_CNT=2 # 2 MB
2196 trap cleanup_quota_test EXIT
2198 echo "Write file..."
2199 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2200 error "write failed"
2201 cancel_lru_locks osc
2202 sync; sync_all_data || true
2204 echo "Save disk usage before restart"
2205 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2206 [ $ORIG_USR_SPACE -eq 0 ] &&
2207 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2208 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2209 [ $ORIG_USR_INODES -eq 0 ] &&
2210 error "Used inodes for user $TSTID is 0, expected 1"
2211 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2212 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2213 [ $ORIG_GRP_SPACE -eq 0 ] &&
2214 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2215 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2216 [ $ORIG_GRP_INODES -eq 0 ] &&
2217 error "Used inodes for group $TSTID is 0, expected 1"
2218 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2221 local ORIG_REFORMAT=$REFORMAT
2223 cleanup_and_setup_lustre
2224 REFORMAT=$ORIG_REFORMAT
2227 echo "Verify disk usage after restart"
2228 local USED=$(getquota -u $TSTID global curspace)
2229 [ $USED -eq $ORIG_USR_SPACE ] ||
2230 error "Used space for user $TSTID changed from " \
2231 "$ORIG_USR_SPACE to $USED"
2232 USED=$(getquota -u $TSTID global curinodes)
2233 [ $USED -eq $ORIG_USR_INODES ] ||
2234 error "Used inodes for user $TSTID changed from " \
2235 "$ORIG_USR_INODES to $USED"
2236 USED=$(getquota -g $TSTID global curspace)
2237 [ $USED -eq $ORIG_GRP_SPACE ] ||
2238 error "Used space for group $TSTID changed from " \
2239 "$ORIG_GRP_SPACE to $USED"
2240 USED=$(getquota -g $TSTID global curinodes)
2241 [ $USED -eq $ORIG_GRP_INODES ] ||
2242 error "Used inodes for group $TSTID changed from " \
2243 "$ORIG_GRP_INODES to $USED"
2245 # check if the vfs_dq_init() is called before writing
2246 echo "Append to the same file..."
2247 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2248 error "write failed"
2249 cancel_lru_locks osc
2250 sync; sync_all_data || true
2252 echo "Verify space usage is increased"
2253 USED=$(getquota -u $TSTID global curspace)
2254 [ $USED -gt $ORIG_USR_SPACE ] ||
2255 error "Used space for user $TSTID isn't increased" \
2256 "orig:$ORIG_USR_SPACE, now:$USED"
2257 USED=$(getquota -g $TSTID global curspace)
2258 [ $USED -gt $ORIG_GRP_SPACE ] ||
2259 error "Used space for group $TSTID isn't increased" \
2260 "orig:$ORIG_GRP_SPACE, now:$USED"
2264 run_test 35 "Usage is still accessible across reboot"
2266 # test migrating old amdin quota files (in Linux quota file format v2) into new
2267 # quota global index (in IAM format)
2269 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
2270 skip "skipping migration test" && return
2272 # get the mdt0 device name
2273 local mdt0_node=$(facet_active_host $SINGLEMDS)
2274 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
2279 echo "Copy admin quota files into MDT0..."
2280 local mntpt=$(facet_mntpt $SINGLEMDS)
2281 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
2283 if ! do_node $mdt0_node test -b $mdt0_fstype; then
2286 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
2287 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
2288 do_node $mdt0_node mkdir $mntpt/OBJECTS
2289 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
2290 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
2291 do_node $mdt0_node umount -d -f $mntpt
2296 echo "Verify global limits..."
2300 local proc="qmt.*.md-0x0.glb-usr"
2301 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2302 [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
2303 limit=$(getquota -u 1 global isoftlimit)
2304 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2305 limit=$(getquota -u 1 global ihardlimit)
2306 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2308 proc="qmt.*.md-0x0.glb-grp"
2309 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2310 [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
2311 limit=$(getquota -g 1 global isoftlimit)
2312 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2313 limit=$(getquota -g 1 global ihardlimit)
2314 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2316 proc=" qmt.*.dt-0x0.glb-usr"
2317 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2318 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2319 limit=$(getquota -u 60001 global bsoftlimit)
2320 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2321 limit=$(getquota -u 60001 global bhardlimit)
2322 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2324 proc="qmt.*.dt-0x0.glb-grp"
2325 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2326 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2327 limit=$(getquota -g 60001 global bsoftlimit)
2328 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2329 limit=$(getquota -g 60001 global bhardlimit)
2330 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2336 run_test 36 "Migrate old admin files into new global indexes"
2340 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2346 check_and_cleanup_lustre
2347 export QUOTA_AUTO=$QUOTA_AUTO_OLD