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 # Bug number for skipped test:
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
38 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
40 require_dsh_mds || exit 0
41 require_dsh_ost || exit 0
43 # Does e2fsprogs support quota feature?
44 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
45 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
46 grep -q 'quota'"; then
47 skip_env "e2fsprogs doesn't support quota" && exit 0
50 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
51 # bug number for skipped test: LU-2836 LU-6836 LU-2836
52 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6"
53 # bug number for skipped test: LU-5638
54 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW"
62 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
64 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
69 QUOTA_AUTO_OLD=$QUOTA_AUTO
72 check_and_setup_lustre
74 is_project_quota_supported() {
75 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
76 [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ] &&
77 egrep -q "7." /etc/redhat-release
80 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
81 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
82 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
83 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
84 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
85 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
86 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
87 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
94 local fail_val=${3:-0}
98 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
99 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
100 ost) NODES="$(comma_list $(osts_nodes))";;
103 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
106 RUNAS="runas -u $TSTID -g $TSTID"
107 RUNAS2="runas -u $TSTID2 -g $TSTID2"
108 DD="dd if=/dev/zero bs=1M"
112 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
113 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
114 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
115 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
117 # clear quota limits for a user or a group
118 # usage: resetquota -u username
119 # resetquota -g groupname
120 # resetquota -p projid
123 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
124 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
125 error "resetquota: wrong specifier $1 passed"
127 if [ $1 == "-p" ]; then
128 is_project_quota_supported || return 0
131 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
132 error "clear quota for [type:$1 name:$2] failed"
133 # give a chance to slave to release space
141 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
142 $LFS quota -v -u $local_id $DIR
143 log "Files for user ($local_id):"
144 ($LFS find --user $local_id $DIR | head -n 4 |
145 xargs stat 2>/dev/null)
148 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
149 $LFS quota -v -g $local_id $DIR
150 log "Files for group ($local_id):"
151 ($LFS find --group $local_id $DIR | head -n 4 |
152 xargs stat 2>/dev/null)
155 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
156 $LFS quota -v -p $local_id $DIR
157 log "Files for project ($local_id):"
158 ($LFS find --projid $local_id $DIR | head -n 4 |
159 xargs stat 2>/dev/null)
175 # get quota for a user or a group
176 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
177 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
182 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
183 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
184 error "getquota: wrong u/g/p specifier $1 passed"
197 *) error "unknown quota parameter $4";;
200 [ "$uuid" = "global" ] && uuid=$DIR
202 $LFS quota -v "$1" "$2" $DIR |
203 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
204 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
209 # usage: set_mdt_qtype ugp|u|g|p|none
213 local mdts=$(get_facets MDS)
215 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
216 qtype=$(tr -d 'p' <<<$qtype)
217 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
218 # we have to make sure each MDT received config changes
219 for mdt in ${mdts//,/ }; do
221 cmd="$LCTL get_param -n "
222 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
223 cmd=${cmd}.quota_slave.enabled
225 if $(facet_up $mdt); then
226 wait_update_facet $mdt "$cmd" "$qtype" || return 1
233 # usage: set_ost_qtype ugp|u|g|p|none
237 local osts=$(get_facets OST)
239 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
240 qtype=$(tr -d 'p' <<<$qtype)
241 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
242 # we have to make sure each OST received config changes
243 for ost in ${osts//,/ }; do
245 cmd="$LCTL get_param -n "
246 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
247 cmd=${cmd}.quota_slave.enabled
249 if $(facet_up $ost); then
250 wait_update_facet $ost "$cmd" "$qtype" || return 1
256 wait_reintegration() {
260 local result="glb[1],slv[1],reint[0]"
265 if [ $ntype == "mdt" ]; then
266 tgts=$(get_facets MDS)
268 tgts=$(get_facets OST)
271 for tgt in ${tgts//,/ }; do
273 cmd="$LCTL get_param -n "
274 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
275 cmd=${cmd}.quota_slave.info
277 if $(facet_up $tgt); then
278 wait_update_facet $tgt "$cmd |
279 grep "$qtype" | awk '{ print \\\$3 }'" \
280 "$result" $max || return 1
290 if [[ "$qtype" =~ "u" ]]; then
291 wait_reintegration "mdt" "user" $max || return 1
294 if [[ "$qtype" =~ "g" ]]; then
295 wait_reintegration "mdt" "group" $max || return 1
298 if [[ "$qtype" =~ "p" ]]; then
299 ! is_project_quota_supported && return 0
300 wait_reintegration "mdt" "project" $max || return 1
309 if [[ "$qtype" =~ "u" ]]; then
310 wait_reintegration "ost" "user" $max || return 1
313 if [[ "$qtype" =~ "g" ]]; then
314 wait_reintegration "ost" "group" $max || return 1
317 if [[ "$qtype" =~ "p" ]]; then
318 ! is_project_quota_supported && return 0
319 wait_reintegration "ost" "project" $max || return 1
324 disable_project_quota() {
325 is_project_quota_supported || return 0
326 stopall || error "failed to stopall (1)"
328 for num in $(seq $MDSCOUNT); do
329 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
330 error "tune2fs $(mdsdevname $num) failed"
333 for num in $(seq $OSTCOUNT); do
334 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
335 error "tune2fs $(ostdevname $num) failed"
343 wait_delete_completed
344 echo "Creating test directory"
345 mkdir $DIR/$tdir || return 1
346 chmod 0777 $DIR/$tdir || return 2
347 # always clear fail_loc in case of fail_loc isn't cleared
348 # properly when previous test failed
349 lustre_fail mds_ost 0
352 cleanup_quota_test() {
354 echo "Delete files..."
356 echo "Wait for unlink objects finished..."
357 wait_delete_completed
358 sync_all_data || true
367 $LFS quota -v -$ugp $qid $DIR
369 if [ "$bf" == "a" -o "$bf" == "b" ]; then
370 usage=$(getquota -$ugp $qid global curspace)
371 if [ -z $usage ]; then
372 quota_error $ugp $qid \
373 "Query block quota failed ($ugp:$qid)."
375 [ $usage -ne 0 ] && quota_log $ugp $qid \
376 "Block quota isn't 0 ($ugp:$qid:$usage)."
380 if [ "$bf" == "a" -o "$bf" == "f" ]; then
381 usage=$(getquota -$ugp $qid global curinodes)
382 if [ -z $usage ]; then
383 quota_error $ugp $qid \
384 "Query file quota failed ($ugp:$qid)."
386 [ $usage -ne 0 ] && quota_log $ugp $qid \
387 "File quota isn't 0 ($ugp:$qid:$usage)."
392 enable_project_quota() {
393 is_project_quota_supported || return 0
394 stopall || error "failed to stopall (1)"
396 for num in $(seq $MDSCOUNT); do
397 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
398 error "tune2fs $(mdsdevname $num) failed"
401 for num in $(seq $OSTCOUNT); do
402 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
403 error "tune2fs $(ostdevname $num) failed"
413 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
417 resetquota -u $TSTUSR
418 resetquota -g $TSTUSR
419 resetquota -u $TSTUSR2
420 resetquota -g $TSTUSR2
421 resetquota -p $TSTPRJID
423 test_quota_performance() {
424 local TESTFILE="$DIR/$tdir/$tfile-0"
425 local size=$1 # in MB
426 local stime=$(date +%s)
427 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
428 quota_error u $TSTUSR "write failure"
429 local etime=$(date +%s)
430 delta=$((etime - stime))
431 if [ $delta -gt 0 ]; then
432 rate=$((size * 1024 / delta))
433 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
434 # LU-2872 - see LU-2887 for fix
436 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
438 [ $rate -gt 1024 ] ||
439 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
445 # test basic quota performance b=21696
448 [ "$SLOW" = "no" ] && MB=10
450 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
451 [ $free_space -le $((MB * 1024)) ] &&
452 skip "not enough space ${free_space} KB, " \
453 "required $((MB * 1024)) KB" && return
454 setup_quota_test || error "setup quota failed with $?"
455 trap cleanup_quota_test EXIT
457 set_ost_qtype "none" || error "disable ost quota failed"
458 test_quota_performance $MB
460 set_ost_qtype $QTYPE || error "enable ost quota failed"
461 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
462 error "set quota failed"
463 test_quota_performance $MB
466 resetquota -u $TSTUSR
468 run_test 0 "Test basic quota performance"
470 # test block hardlimit
473 local TESTFILE="$DIR/$tdir/$tfile-0"
475 setup_quota_test || error "setup quota failed with $?"
476 trap cleanup_quota_test EXIT
479 set_ost_qtype $QTYPE || error "enable ost quota failed"
482 log "User quota (block hardlimit:$LIMIT MB)"
483 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
484 error "set user quota failed"
486 # make sure the system is clean
487 local USED=$(getquota -u $TSTUSR global curspace)
488 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
490 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
491 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
494 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
495 quota_error u $TSTUSR "user write failure, but expect success"
496 log "Write out of block quota ..."
497 # this time maybe cache write, ignore it's failure
498 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
499 # flush cache, ensure noquota flag is set on client
501 sync; sync_all_data || true
502 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
503 quota_error u $TSTUSR "user write success, but expect EDQUOT"
506 wait_delete_completed || error "wait_delete_completed failed"
507 sync_all_data || true
508 USED=$(getquota -u $TSTUSR global curspace)
509 [ $USED -ne 0 ] && quota_error u $TSTUSR \
510 "user quota isn't released after deletion"
511 resetquota -u $TSTUSR
514 log "--------------------------------------"
515 log "Group quota (block hardlimit:$LIMIT MB)"
516 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
517 error "set group quota failed"
519 TESTFILE="$DIR/$tdir/$tfile-1"
520 # make sure the system is clean
521 USED=$(getquota -g $TSTUSR global curspace)
522 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
524 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
525 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
528 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
529 quota_error g $TSTUSR "Group write failure, but expect success"
530 log "Write out of block quota ..."
531 # this time maybe cache write, ignore it's failure
532 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
534 sync; sync_all_data || true
535 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
536 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
538 wait_delete_completed || error "wait_delete_completed failed"
539 sync_all_data || true
540 USED=$(getquota -g $TSTUSR global curspace)
541 [ $USED -ne 0 ] && quota_error g $TSTUSR \
542 "Group quota isn't released after deletion"
543 resetquota -g $TSTUSR
545 if ! is_project_quota_supported; then
546 echo "Project quota is not supported"
551 TESTFILE="$DIR/$tdir/$tfile-2"
552 # make sure the system is clean
553 USED=$(getquota -p $TSTPRJID global curspace)
555 error "used space($USED) for project $TSTPRJID isn't 0"
558 log "--------------------------------------"
559 log "project quota (block hardlimit:$LIMIT mb)"
560 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
561 error "set project quota failed"
563 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
564 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
565 chattr -p $TSTPRJID $TESTFILE
568 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
569 "project write failure, but expect success"
570 log "write out of block quota ..."
571 # this time maybe cache write, ignore it's failure
572 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
574 sync; sync_all_data || true
575 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
576 $TSTPRJID "project write success, but expect edquot"
581 USED=$(getquota -p $TSTPRJID global curspace)
582 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
583 "project quota isn't released after deletion"
585 resetquota -p $TSTPRJID
587 run_test 1 "Block hard limit (normal use and out of quota)"
589 # test inode hardlimit
591 local LIMIT=$((1024 * 1024)) # 1M inodes
592 local TESTFILE="$DIR/$tdir/$tfile-0"
594 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
596 local FREE_INODES=$(mdt_free_inodes 0)
597 echo "$FREE_INODES free inodes on master MDT"
598 [ $FREE_INODES -lt $LIMIT ] &&
599 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
602 setup_quota_test || error "setup quota failed with $?"
603 trap cleanup_quota_test EXIT
606 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
609 log "User quota (inode hardlimit:$LIMIT files)"
610 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
611 error "set user quota failed"
613 # make sure the system is clean
614 local USED=$(getquota -u $TSTUSR global curinodes)
615 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
617 log "Create $LIMIT files ..."
618 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
619 quota_error u $TSTUSR "user create failure, but expect success"
620 log "Create out of file quota ..."
621 $RUNAS touch ${TESTFILE}_xxx &&
622 quota_error u $TSTUSR "user create success, but expect EDQUOT"
625 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
626 rm -f ${TESTFILE}_xxx
627 wait_delete_completed
629 USED=$(getquota -u $TSTUSR global curinodes)
630 [ $USED -ne 0 ] && quota_error u $TSTUSR \
631 "user quota isn't released after deletion"
632 resetquota -u $TSTUSR
635 log "--------------------------------------"
636 log "Group quota (inode hardlimit:$LIMIT files)"
637 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
638 error "set group quota failed"
640 TESTFILE=$DIR/$tdir/$tfile-1
641 # make sure the system is clean
642 USED=$(getquota -g $TSTUSR global curinodes)
643 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
645 log "Create $LIMIT files ..."
646 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
647 quota_error g $TSTUSR "group create failure, but expect success"
648 log "Create out of file quota ..."
649 $RUNAS touch ${TESTFILE}_xxx &&
650 quota_error g $TSTUSR "group create success, but expect EDQUOT"
653 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
654 rm -f ${TESTFILE}_xxx
655 wait_delete_completed
657 USED=$(getquota -g $TSTUSR global curinodes)
658 [ $USED -ne 0 ] && quota_error g $TSTUSR \
659 "user quota isn't released after deletion"
661 resetquota -g $TSTUSR
662 ! is_project_quota_supported && cleanup_quota_test &&
663 echo "Skip project quota is not supported" && return 0
666 log "--------------------------------------"
667 log "Project quota (inode hardlimit:$LIMIT files)"
668 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
669 error "set project quota failed"
671 TESTFILE=$DIR/$tdir/$tfile-1
672 # make sure the system is clean
673 USED=$(getquota -p $TSTPRJID global curinodes)
675 error "Used inodes($USED) for project $TSTPRJID isn't 0"
677 chattr +P $DIR/$tdir/
678 chattr -p $TSTPRJID -d $DIR/$tdir
679 log "Create $LIMIT files ..."
680 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
681 $TSTPRJID "project create fail, but expect success"
682 log "Create out of file quota ..."
683 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
684 "project create success, but expect EDQUOT"
686 chattr -p 0 -d $DIR/$tdir
689 USED=$(getquota -p $TSTPRJID global curinodes)
690 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
691 "project quota isn't released after deletion"
693 resetquota -p $TSTPRJID
696 run_test 2 "File hard limit (normal use and out of quota)"
700 local TIMER=$(($2 * 3 / 2))
706 trap cleanup_quota_test EXIT
708 $SETSTRIPE $TESTFILE -c 1 -i 0
709 chown $TSTUSR.$TSTUSR $TESTFILE
710 [ "$qtype" == "p" ] && is_project_quota_supported &&
711 chattr -p $TSTPRJID $TESTFILE
713 echo "Write up to soft limit"
714 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
715 quota_error a $TSTUSR "write failure, but expect success"
716 OFFSET=$((LIMIT * 1024))
719 echo "Write to exceed soft limit"
720 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
721 quota_error a $TSTUSR "write failure, but expect success"
722 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
728 $SHOW_QUOTA_INFO_USER
729 $SHOW_QUOTA_INFO_GROUP
730 $SHOW_QUOTA_INFO_PROJID
732 echo "Write before timer goes off"
733 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
734 quota_error a $TSTUSR "write failure, but expect success"
735 OFFSET=$((OFFSET + 1024))
738 echo "Sleep $TIMER seconds ..."
744 $SHOW_QUOTA_INFO_USER
745 $SHOW_QUOTA_INFO_GROUP
746 $SHOW_QUOTA_INFO_PROJID
748 echo "Write after timer goes off"
749 # maybe cache write, ignore.
750 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
751 OFFSET=$((OFFSET + 1024))
753 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
754 quota_error a $TSTUSR "write success, but expect EDQUOT"
759 $SHOW_QUOTA_INFO_USER
760 $SHOW_QUOTA_INFO_GROUP
761 $SHOW_QUOTA_INFO_PROJID
763 echo "Unlink file to stop timer"
765 wait_delete_completed
766 sync_all_data || true
771 $SHOW_QUOTA_INFO_USER
772 $SHOW_QUOTA_INFO_GROUP
773 $SHOW_QUOTA_INFO_PROJID
775 $SETSTRIPE $TESTFILE -c 1 -i 0
776 chown $TSTUSR.$TSTUSR $TESTFILE
777 [ "$qtype" == "p" ] && chattr -p $TSTPRJID $TESTFILE
780 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
781 quota_error a $TSTUSR "write failure, but expect success"
790 local TESTFILE=$DIR/$tdir/$tfile-0
792 set_ost_qtype $QTYPE || error "enable ost quota failed"
794 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
795 # make sure the system is clean
796 local USED=$(getquota -u $TSTUSR global curspace)
797 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
799 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
800 $MAX_IQ_TIME $DIR || error "set user grace time failed"
801 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
802 error "set user quota failed"
804 test_block_soft $TESTFILE $GRACE $LIMIT "u"
805 resetquota -u $TSTUSR
807 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
808 TESTFILE=$DIR/$tdir/$tfile-1
809 # make sure the system is clean
810 USED=$(getquota -g $TSTUSR global curspace)
811 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
813 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
814 $MAX_IQ_TIME $DIR || error "set group grace time failed"
815 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
816 error "set group quota failed"
818 test_block_soft $TESTFILE $GRACE $LIMIT "g"
819 resetquota -g $TSTUSR
821 if is_project_quota_supported; then
822 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
823 TESTFILE=$DIR/$tdir/$tfile-2
824 # make sure the system is clean
825 USED=$(getquota -p $TSTPRJID global curspace)
826 [ $USED -ne 0 ] && error \
827 "Used space($USED) for project $TSTPROJID isn't 0."
829 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
831 error "set project grace time failed"
832 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
833 $DIR || error "set project quota failed"
835 test_block_soft $TESTFILE $GRACE $LIMIT "p"
836 resetquota -p $TSTPRJID
837 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
839 error "restore project grace time failed"
843 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
844 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
845 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
846 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
848 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
854 local TIMER=$(($grace * 3 / 2))
857 trap cleanup_quota_test EXIT
858 is_project_quota_supported && chattr +P $DIR/$tdir/ &&
859 chattr -p $TSTPRJID -d $DIR/$tdir
861 echo "Create files to exceed soft limit"
862 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
863 quota_error a $TSTUSR "create failure, but expect success"
864 local trigger_time=$(date +%s)
866 sync_all_data || true
868 local cur_time=$(date +%s)
869 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
870 error "Passed grace time $grace, $trigger_time, $cur_time"
872 echo "Create file before timer goes off"
873 $RUNAS touch ${TESTFILE}_before ||
874 quota_error a $TSTUSR "failed create before timer expired," \
875 "but expect success. $trigger_time, $cur_time"
876 sync_all_data || true
878 echo "Sleep $TIMER seconds ..."
884 $SHOW_QUOTA_INFO_USER
885 $SHOW_QUOTA_INFO_GROUP
886 $SHOW_QUOTA_INFO_PROJID
888 echo "Create file after timer goes off"
889 # There is a window that space is accounted in the quota usage but
890 # hasn't been decreased from the pending write, if we acquire quota
891 # in this window, we'll acquire more than we needed.
892 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
893 sync_all_data || true
894 $RUNAS touch ${TESTFILE}_after_3 &&
895 quota_error a $TSTUSR "create after timer expired," \
897 sync_all_data || true
902 $SHOW_QUOTA_INFO_USER
903 $SHOW_QUOTA_INFO_GROUP
904 $SHOW_QUOTA_INFO_PROJID
906 echo "Unlink files to stop timer"
907 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
908 wait_delete_completed
911 $RUNAS touch ${TESTFILE}_xxx ||
912 quota_error a $TSTUSR "touch after timer stop failure," \
914 sync_all_data || true
922 local LIMIT=10 # inodes
923 local TESTFILE=$DIR/$tdir/$tfile-0
926 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
928 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
929 # make sure the system is clean
930 local USED=$(getquota -u $TSTUSR global curinodes)
931 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
933 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
934 $GRACE $DIR || error "set user grace time failed"
935 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
936 error "set user quota failed"
938 test_file_soft $TESTFILE $LIMIT $GRACE
939 resetquota -u $TSTUSR
941 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
942 # make sure the system is clean
943 USED=$(getquota -g $TSTUSR global curinodes)
944 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
946 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
947 $GRACE $DIR || error "set group grace time failed"
948 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
949 error "set group quota failed"
950 TESTFILE=$DIR/$tdir/$tfile-1
952 test_file_soft $TESTFILE $LIMIT $GRACE
953 resetquota -g $TSTUSR
955 if is_project_quota_supported; then
956 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
957 # make sure the system is clean
958 USED=$(getquota -p $TSTPRJID global curinodes)
959 [ $USED -ne 0 ] && error \
960 "Used space($USED) for project $TSTPRJID isn't 0."
962 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
963 $GRACE $DIR || error "set project grace time failed"
964 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
965 error "set project quota failed"
967 TESTFILE=$DIR/$tdir/$tfile-1
968 # one less than limit, because of parent directory included.
969 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
970 resetquota -p $TSTPRJID
971 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
973 error "restore project grace time failed"
977 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
978 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
979 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
980 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
982 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
986 local GR_STR2="1000s"
988 local GR_STR4="1w2d3h4m5s"
990 local GR_STR6="18446744073709551615"
993 wait_delete_completed
995 # test of valid grace strings handling
996 echo "Valid grace strings test"
997 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
998 $GR_STR2 $DIR || error "set user grace time failed"
999 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1000 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1001 $GR_STR4 $DIR || error "set group grace time quota failed"
1002 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1004 # test of invalid grace strings handling
1005 echo " Invalid grace strings test"
1006 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1007 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1008 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1012 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1013 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1014 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1015 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1017 run_test 4b "Grace time strings handling"
1019 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1021 local BLIMIT=10 # 10M
1022 local ILIMIT=10 # 10 inodes
1024 setup_quota_test || error "setup quota failed with $?"
1025 trap cleanup_quota_test EXIT
1027 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1028 set_ost_qtype $QTYPE || error "enable ost quota failed"
1030 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1031 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1032 error "set user quota failed"
1033 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1034 if is_project_quota_supported; then
1035 error "set group quota failed"
1036 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1037 -I $ILIMIT $DIR || error "set project quota failed"
1040 # make sure the system is clean
1041 local USED=$(getquota -u $TSTUSR global curinodes)
1042 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1043 USED=$(getquota -g $TSTUSR global curinodes)
1044 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1045 USED=$(getquota -u $TSTUSR global curspace)
1046 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1047 USED=$(getquota -g $TSTUSR global curspace)
1048 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1049 if is_project_quota_supported; then
1050 USED=$(getquota -p $TSTPRJID global curspace)
1052 error "Used block($USED) for project $TSTPRJID isn't 0."
1055 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1056 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1057 error "create failure, expect success"
1058 if [ "$(facet_fstype $singlemds)" == "ldiskfs" ]; then
1059 touch $DIR/$tdir/$tfile-0_1
1060 chattr -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1062 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1063 error "write failure, expect success"
1065 echo "Chown files to $TSTUSR.$TSTUSR ..."
1066 for i in $(seq 0 $ILIMIT); do
1067 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1068 quota_error a $TSTUSR "chown failure, expect success"
1072 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1073 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1076 resetquota -u $TSTUSR
1077 resetquota -g $TSTUSR
1078 resetquota -p $TSTPRJID
1080 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1082 # test dropping acquire request on master
1086 # Clear dmesg so watchdog is not triggered by previous
1088 do_facet ost1 dmesg -c > /dev/null
1090 setup_quota_test || error "setup quota failed with $?"
1091 trap cleanup_quota_test EXIT
1093 # make sure the system is clean
1094 local USED=$(getquota -u $TSTUSR global curspace)
1095 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1097 # make sure no granted quota on ost
1098 set_ost_qtype $QTYPE || error "enable ost quota failed"
1099 resetquota -u $TSTUSR
1101 # create file for $TSTUSR
1102 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1103 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1104 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1106 # create file for $TSTUSR2
1107 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1108 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1109 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1111 # cache per-ID lock for $TSTUSR on slave
1112 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1113 error "set quota failed"
1114 $RUNAS $DD of=$TESTFILE count=1 ||
1115 error "write $TESTFILE failure, expect success"
1116 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1117 error "write $TESTFILE2 failure, expect success"
1119 sync_all_data || true
1121 #define QUOTA_DQACQ 601
1122 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1123 lustre_fail mds 0x513 601
1125 # write to un-enforced ID ($TSTUSR2) should succeed
1126 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1127 error "write failure, expect success"
1129 # write to enforced ID ($TSTUSR) in background, exceeding limit
1130 # to make sure DQACQ is sent
1131 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1134 # watchdog timer uses a factor of 2
1135 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1136 sleep $((TIMEOUT * 2 + 1))
1138 # write should be blocked and never finished
1139 if ! ps -p $DDPID > /dev/null 2>&1; then
1141 error "write finished incorrectly!"
1146 # no watchdog is triggered
1147 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1148 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1149 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1150 [ -z "$watchdog" ] || error "$watchdog"
1152 rm -f $TMP/lustre-log-${TESTNAME}.log
1154 # write should continue then fail with EDQUOT
1158 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1159 if [ $count -ge 240 ]; then
1160 quota_error u $TSTUSR "dd not finished in $count secs"
1162 count=$((count + 1))
1163 if [ $((count % 30)) -eq 0 ]; then
1164 c_size=$(stat -c %s $TESTFILE)
1165 echo "Waiting $count secs. $c_size"
1172 resetquota -u $TSTUSR
1174 run_test 6 "Test dropping acquire request on master"
1176 # quota reintegration (global index)
1178 local TESTFILE=$DIR/$tdir/$tfile
1179 local LIMIT=20 # 20M
1181 [ "$SLOW" = "no" ] && LIMIT=5
1183 setup_quota_test || error "setup quota failed with $?"
1184 trap cleanup_quota_test EXIT
1186 # make sure the system is clean
1187 local USED=$(getquota -u $TSTUSR global curspace)
1188 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1190 # make sure no granted quota on ost1
1191 set_ost_qtype $QTYPE || error "enable ost quota failed"
1192 resetquota -u $TSTUSR
1193 set_ost_qtype "none" || error "disable ost quota failed"
1195 local OSTUUID=$(ostuuid_from_index 0)
1196 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1198 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1201 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1202 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1207 echo "Enable quota & set quota limit for $TSTUSR"
1208 set_ost_qtype $QTYPE || error "enable ost quota failed"
1209 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1210 error "set quota failed"
1212 echo "Start ost1..."
1213 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1216 wait_ost_reint $QTYPE || error "reintegration failed"
1218 # hardlimit should have been fetched by slave during global
1219 # reintegration, write will exceed quota
1220 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1221 quota_error u $TSTUSR "write success, but expect EDQUOT"
1224 wait_delete_completed
1225 sync_all_data || true
1231 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1232 error "clear quota failed"
1234 echo "Start ost1..."
1235 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1238 wait_ost_reint $QTYPE || error "reintegration failed"
1240 # hardlimit should be cleared on slave during reintegration
1241 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1242 quota_error u $TSTUSR "write error, but expect success"
1245 resetquota -u $TSTUSR
1247 run_test 7a "Quota reintegration (global index)"
1249 # quota reintegration (slave index)
1252 local TESTFILE=$DIR/$tdir/$tfile
1254 setup_quota_test || error "setup quota failed with $?"
1255 trap cleanup_quota_test EXIT
1257 # make sure the system is clean
1258 local USED=$(getquota -u $TSTUSR global curspace)
1259 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1261 # make sure no granted quota on ost1
1262 set_ost_qtype $QTYPE || error "enable ost quota failed"
1263 resetquota -u $TSTUSR
1264 set_ost_qtype "none" || error "disable ost quota failed"
1266 local OSTUUID=$(ostuuid_from_index 0)
1267 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1269 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1272 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1273 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1275 # consume some space to make sure the granted space will not
1276 # be released during reconciliation
1277 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1278 error "consume space failure, expect success"
1280 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1281 lustre_fail mds 0xa02
1283 set_ost_qtype $QTYPE || error "enable ost quota failed"
1284 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1285 error "set quota failed"
1287 # ignore the write error
1288 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1290 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1294 echo "Restart ost to trigger reintegration..."
1296 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1299 wait_ost_reint $QTYPE || error "reintegration failed"
1301 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1302 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1305 resetquota -u $TSTUSR
1308 run_test 7b "Quota reintegration (slave index)"
1310 # quota reintegration (restart mds during reintegration)
1312 local LIMIT=20 # 20M
1313 local TESTFILE=$DIR/$tdir/$tfile
1315 [ "$SLOW" = "no" ] && LIMIT=5
1317 setup_quota_test || error "setup quota failed with $?"
1318 trap cleanup_quota_test EXIT
1320 # make sure the system is clean
1321 local USED=$(getquota -u $TSTUSR global curspace)
1322 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1324 set_ost_qtype "none" || error "disable ost quota failed"
1325 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1326 error "set quota failed"
1328 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1329 lustre_fail ost 0xa03
1332 set_ost_qtype $QTYPE || error "enable ost quota failed"
1333 # trigger reintegration
1334 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1335 procf=${procf}quota_slave.force_reint
1336 do_facet ost1 $LCTL set_param $procf=1 ||
1337 error "force reintegration failed"
1345 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1348 # wait longer than usual to make sure the reintegration
1349 # is triggered by quota wb thread.
1350 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1352 # hardlimit should have been fetched by slave during global
1353 # reintegration, write will exceed quota
1354 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1355 quota_error u $TSTUSR "write success, but expect EDQUOT"
1358 resetquota -u $TSTUSR
1360 run_test 7c "Quota reintegration (restart mds during reintegration)"
1362 # Quota reintegration (Transfer index in multiple bulks)
1364 local TESTFILE=$DIR/$tdir/$tfile
1365 local TESTFILE1="$DIR/$tdir/$tfile"-1
1368 setup_quota_test || error "setup quota failed with $?"
1369 trap cleanup_quota_test EXIT
1371 set_ost_qtype "none" || error "disable ost quota failed"
1372 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1373 error "set quota for $TSTUSR failed"
1374 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1375 error "set quota for $TSTUSR2 failed"
1377 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1378 lustre_fail mds 0x608 0
1380 # enable quota to tirgger reintegration
1381 set_ost_qtype "u" || error "enable ost quota failed"
1382 wait_ost_reint "u" || error "reintegration failed"
1386 # hardlimit should have been fetched by slave during global
1387 # reintegration, write will exceed quota
1388 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1389 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1391 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1392 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1395 resetquota -u $TSTUSR
1396 resetquota -u $TSTUSR2
1398 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1400 # quota reintegration (inode limits)
1402 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1404 # LU-2435: skip this quota test if underlying zfs version has not
1405 # supported native dnode accounting
1406 [ "$(facet_fstype mds1)" == "zfs" ] && {
1407 local zfs_version=$(do_facet mds1 cat /sys/module/zfs/version)
1409 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] &&
1410 skip "requires zfs version at least 0.7.0" && return
1413 local ilimit=$((1024 * 2)) # 2k inodes
1414 local TESTFILE=$DIR/${tdir}-1/$tfile
1416 setup_quota_test || error "setup quota failed with $?"
1417 trap cleanup_quota_test EXIT
1419 # make sure the system is clean
1420 local USED=$(getquota -u $TSTUSR global curinodes)
1421 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1423 # make sure no granted quota on mdt1
1424 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1425 resetquota -u $TSTUSR
1426 set_mdt_qtype "none" || error "disable mdt quota failed"
1428 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1429 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1430 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1433 echo "Stop mds${MDSCOUNT}..."
1436 echo "Enable quota & set quota limit for $TSTUSR"
1437 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1438 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1439 error "set quota failed"
1441 echo "Start mds${MDSCOUNT}..."
1442 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1445 wait_mdt_reint $QTYPE || error "reintegration failed"
1447 echo "create remote dir"
1448 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1449 error "create remote dir failed"
1450 chmod 0777 $DIR/${tdir}-1
1452 # hardlimit should have been fetched by slave during global
1453 # reintegration, create will exceed quota
1454 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1455 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1457 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1458 wait_delete_completed
1459 sync_all_data || true
1461 echo "Stop mds${MDSCOUNT}..."
1464 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1465 error "clear quota failed"
1467 echo "Start mds${MDSCOUNT}..."
1468 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1471 wait_mdt_reint $QTYPE || error "reintegration failed"
1473 # hardlimit should be cleared on slave during reintegration
1474 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1475 quota_error -u $TSTUSR "create failed, expect success"
1477 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1478 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1481 resetquota -u $TSTUSR
1483 run_test 7e "Quota reintegration (inode limits)"
1485 # run dbench with quota enabled
1487 local BLK_LIMIT="100g" #100G
1488 local FILE_LIMIT=1000000
1490 setup_quota_test || error "setup quota failed with $?"
1491 trap cleanup_quota_test EXIT
1493 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1494 set_ost_qtype $QTYPE || error "enable ost quota failed"
1496 echo "Set enough high limit for user: $TSTUSR"
1497 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1498 error "set user quota failed"
1499 echo "Set enough high limit for group: $TSTUSR"
1500 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1501 error "set group quota failed"
1502 if is_project_quota_supported; then
1503 chattr +P $DIR/$tdir && chattr -p $TSTPRJID -d $DIR/$tdir
1504 echo "Set enough high limit for project: $TSTPRJID"
1505 $LFS setquota -p $TSTPRJID -b 0 \
1506 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1507 error "set project quota failed"
1511 [ "$SLOW" = "no" ] && duration=" -t 120"
1512 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1513 quota_error a $TSTUSR "dbench failed!"
1515 is_project_quota_supported && chattr -P $DIR/$tdir &&
1516 chattr -dp 0 $DIR/$tdir
1518 resetquota -u $TSTUSR
1519 resetquota -g $TSTUSR
1520 resetquota -p $TSTPRJID
1522 run_test 8 "Run dbench with quota enabled"
1524 # this check is just for test_9
1525 OST0_MIN=4900000 #4.67G
1527 check_whether_skip () {
1528 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1529 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1530 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1531 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1538 # run for fixing bug10707, it needs a big room. test for 64bit
1540 local filesize=$((1024 * 9 / 2)) # 4.5G
1542 check_whether_skip && return 0
1544 setup_quota_test || error "setup quota failed with $?"
1545 trap cleanup_quota_test EXIT
1547 set_ost_qtype "ug" || error "enable ost quota failed"
1549 local TESTFILE="$DIR/$tdir/$tfile-0"
1550 local BLK_LIMIT=100G #100G
1551 local FILE_LIMIT=1000000
1553 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1555 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1557 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1558 error "set user quota failed"
1560 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1561 "for group: $TSTUSR"
1562 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1563 error "set group quota failed"
1565 quota_show_check a u $TSTUSR
1566 quota_show_check a g $TSTUSR
1568 echo "Create test file"
1569 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1570 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1572 log "Write the big file of 4.5G ..."
1573 $RUNAS $DD of=$TESTFILE count=$filesize ||
1574 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1580 resetquota -u $TSTUSR
1581 resetquota -g $TSTUSR
1586 run_test 9 "Block limit larger than 4GB (b10707)"
1589 local TESTFILE=$DIR/$tdir/$tfile
1591 setup_quota_test || error "setup quota failed with $?"
1592 trap cleanup_quota_test EXIT
1594 # set limit to root user should fail
1595 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1596 error "set limit for root user successfully, expect failure"
1597 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1598 error "set limit for root group successfully, expect failure"
1599 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1600 error "set limit for project 0 successfully, expect failure"
1602 # root user can overrun quota
1603 set_ost_qtype "ug" || error "enable ost quota failed"
1605 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1606 error "set quota failed"
1607 quota_show_check b u $TSTUSR
1609 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1610 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1612 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1613 error "write failure, expect success"
1616 resetquota -u $TSTUSR
1618 run_test 10 "Test quota for root user"
1621 local TESTFILE=$DIR/$tdir/$tfile
1622 setup_quota_test || error "setup quota failed with $?"
1623 trap cleanup_quota_test EXIT
1625 set_mdt_qtype "ug" || error "enable mdt quota failed"
1626 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1627 error "set quota failed"
1629 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1630 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1632 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1633 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1636 local USED=$(getquota -u $TSTUSR global curinodes)
1637 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1640 resetquota -u $TSTUSR
1642 run_test 11 "Chown/chgrp ignores quota"
1645 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1647 local blimit=22 # 22M
1648 local blk_cnt=$((blimit - 5))
1649 local TESTFILE0="$DIR/$tdir/$tfile"-0
1650 local TESTFILE1="$DIR/$tdir/$tfile"-1
1652 setup_quota_test || error "setup quota failed with $?"
1653 trap cleanup_quota_test EXIT
1655 set_ost_qtype "u" || error "enable ost quota failed"
1656 quota_show_check b u $TSTUSR
1658 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1659 error "set quota failed"
1661 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1662 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1663 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1664 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1666 echo "Write to ost0..."
1667 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1668 quota_error a $TSTUSR "dd failed"
1670 echo "Write to ost1..."
1671 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1672 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1674 echo "Free space from ost0..."
1676 wait_delete_completed
1677 sync_all_data || true
1679 echo "Write to ost1 after space freed from ost0..."
1680 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1681 quota_error a $TSTUSR "rebalancing failed"
1684 resetquota -u $TSTUSR
1686 run_test 12a "Block quota rebalancing"
1689 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1691 local ilimit=$((1024 * 2)) # 2k inodes
1692 local TESTFILE0=$DIR/$tdir/$tfile
1693 local TESTFILE1=$DIR/${tdir}-1/$tfile
1695 setup_quota_test || error "setup quota failed with $?"
1696 trap cleanup_quota_test EXIT
1698 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1699 chmod 0777 $DIR/${tdir}-1
1701 set_mdt_qtype "u" || error "enable mdt quota failed"
1702 quota_show_check f u $TSTUSR
1704 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1705 error "set quota failed"
1707 echo "Create $ilimit files on mdt0..."
1708 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1709 quota_error u $TSTUSR "create failed, but expect success"
1711 echo "Create files on mdt1..."
1712 $RUNAS createmany -m $TESTFILE1 1 &&
1713 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1715 echo "Free space from mdt0..."
1716 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1717 wait_delete_completed
1718 sync_all_data || true
1720 echo "Create files on mdt1 after space freed from mdt0..."
1721 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1722 quota_error a $TSTUSR "rebalancing failed"
1724 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1725 error "unlink mdt1 files failed"
1726 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1729 resetquota -u $TSTUSR
1731 run_test 12b "Inode quota rebalancing"
1734 local TESTFILE=$DIR/$tdir/$tfile
1735 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1736 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1738 setup_quota_test || error "setup quota failed with $?"
1739 trap cleanup_quota_test EXIT
1741 set_ost_qtype "u" || error "enable ost quota failed"
1742 quota_show_check b u $TSTUSR
1744 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1745 error "set quota failed"
1746 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1747 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1749 # clear the locks in cache first
1750 do_facet ost1 $LCTL set_param -n $procf=clear
1751 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1752 [ $nlock -eq 0 ] || error "$nlock cached locks"
1754 # write to acquire the per-ID lock
1755 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1756 quota_error a $TSTUSR "dd failed"
1758 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1759 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1761 # clear quota doesn't trigger per-ID lock cancellation
1762 resetquota -u $TSTUSR
1763 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1764 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1766 # clear the per-ID lock
1767 do_facet ost1 $LCTL set_param -n $procf=clear
1768 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1769 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1771 # spare quota should be released
1772 local OSTUUID=$(ostuuid_from_index 0)
1773 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1774 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1775 [ $limit -le $space ] ||
1776 error "spare quota isn't released, limit:$limit, space:$space"
1780 run_test 13 "Cancel per-ID lock in the LRU list"
1783 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1785 wait_delete_completed
1786 sync_all_data || true
1789 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1790 error "set user quota failed"
1791 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1792 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1793 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1794 resetquota -u $TSTUSR
1797 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1798 error "set group quota failed"
1799 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1800 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1801 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1802 resetquota -g $TSTUSR
1804 run_test 15 "Set over 4T block quota"
1808 local BLKS=1 # 1M less than limit
1809 local TESTFILE=$DIR/$tdir/$tfile
1811 setup_quota_test || error "setup quota failed with $?"
1812 trap cleanup_quota_test EXIT
1814 # make sure the system is clean
1815 local USED=$(getquota -u $TSTUSR global curspace)
1816 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1818 set_ost_qtype "ug" || error "enable ost quota failed"
1819 # make sure no granted quota on ost
1820 resetquota -u $TSTUSR
1821 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1822 error "set quota failed"
1824 quota_show_check b u $TSTUSR
1826 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1827 lustre_fail mds 0xa04 $err_code
1829 # write in background
1830 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1834 # write should be blocked and never finished
1835 if ! ps -p $DDPID > /dev/null 2>&1; then
1837 quota_error u $TSTUSR "write finished incorrectly!"
1845 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1847 if [ $count -gt $timeout ]; then
1848 quota_error u $TSTUSR "dd is not finished!"
1853 sync; sync_all_data || true
1855 USED=$(getquota -u $TSTUSR global curspace)
1856 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1857 "Used space(${USED}K) is less than ${BLKS}M"
1860 resetquota -u $TSTUSR
1863 # DQACQ return recoverable error
1865 echo "DQACQ return -ENOLCK"
1867 test_17sub 37 || error "Handle -ENOLCK failed"
1869 echo "DQACQ return -EAGAIN"
1871 test_17sub 11 || error "Handle -EAGAIN failed"
1873 echo "DQACQ return -ETIMEDOUT"
1874 #define ETIMEDOUT 110
1875 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1877 echo "DQACQ return -ENOTCONN"
1878 #define ENOTCONN 107
1879 test_17sub 107 || error "Handle -ENOTCONN failed"
1882 run_test 17 "DQACQ return recoverable error"
1886 local blimit="200m" # 200M
1887 local TESTFILE="$DIR/$tdir/$tfile"
1889 setup_quota_test || error "setup quota failed with $?"
1890 trap cleanup_quota_test EXIT
1892 set_ost_qtype "u" || error "enable ost quota failed"
1893 log "User quota (limit: $blimit)"
1894 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1895 error "set quota failed"
1896 quota_show_check b u $TSTUSR
1898 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1899 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1901 local timeout=$(sysctl -n lustre.timeout)
1903 if [ $io_type = "directio" ]; then
1904 log "Write 100M (directio) ..."
1905 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1907 log "Write 100M (buffered) ..."
1908 $RUNAS $DD of=$TESTFILE count=100 &
1912 replay_barrier $SINGLEMDS
1913 log "Fail mds for $((2 * timeout)) seconds"
1914 fail $SINGLEMDS $((2 * timeout))
1917 if at_is_enabled; then
1918 timeout=$(at_max_get mds)
1920 timeout=$(lctl get_param -n timeout)
1924 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1925 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1926 log "it took $count second"
1931 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1933 cancel_lru_locks mdc
1934 cancel_lru_locks osc
1937 local testfile_size=$(stat -c %s $TESTFILE)
1938 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1939 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1940 "got ${testfile_size}. Verifying file failed!"
1943 resetquota -u $TSTUSR
1946 # test when mds does failover, the ost still could work well
1947 # this test shouldn't trigger watchdog b=14840
1949 # Clear dmesg so watchdog is not triggered by previous
1951 do_facet ost1 dmesg -c > /dev/null
1954 test_18_sub directio
1956 # check if watchdog is triggered
1957 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1958 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1959 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1960 [ -z "$watchdog" ] || error "$watchdog"
1961 rm -f $TMP/lustre-log-${TESTNAME}.log
1963 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1967 local TESTFILE=$DIR/$tdir/$tfile
1969 setup_quota_test || error "setup quota failed with $?"
1970 trap cleanup_quota_test EXIT
1972 set_ost_qtype $QTYPE || error "enable ost quota failed"
1974 # bind file to a single OST
1975 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1976 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1978 echo "Set user quota (limit: ${blimit}M)"
1979 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1980 error "set user quota failed"
1981 quota_show_check b u $TSTUSR
1982 echo "Update quota limits"
1983 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1984 error "set group quota failed"
1985 quota_show_check b u $TSTUSR
1987 # first wirte might be cached
1988 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1989 cancel_lru_locks osc
1991 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1992 quota_error u $TSTUSR "Write success, expect failure"
1996 resetquota -u $TSTUSR
1998 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2000 test_20() { # b15754
2001 local LSTR=(2g 1t 4k 3m) # limits strings
2003 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2006 resetquota -u $TSTUSR
2008 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2009 $MOUNT || error "could not set quota limits"
2010 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2011 --inode-softlimit ${LSTR[2]} \
2012 --inode-hardlimit ${LSTR[3]} \
2013 $MOUNT || error "could not set quota limits"
2015 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2016 error "bsoftlimit was not set properly"
2017 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2018 error "bhardlimit was not set properly"
2019 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2020 error "isoftlimit was not set properly"
2021 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2022 error "ihardlimit was not set properly"
2024 resetquota -u $TSTUSR
2026 run_test 20 "Test if setquota specifiers work properly (b15754)"
2033 local time=$(($(date +%s) + seconds))
2034 while [ $(date +%s) -lt $time ]; do
2035 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2039 # run for fixing bug16053, setquota shouldn't fail when writing and
2040 # deleting are happening
2042 local TESTFILE="$DIR/$tdir/$tfile"
2043 local BLIMIT=10 # 10G
2044 local ILIMIT=1000000
2046 setup_quota_test || error "setup quota failed with $?"
2047 trap cleanup_quota_test EXIT
2049 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2051 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2052 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2053 error "set user quota failed"
2054 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2055 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2056 error "set group quota failed"
2057 if is_project_quota_supported; then
2058 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2059 "project: $TSTPRJID"
2060 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2061 $MOUNT || error "set project quota failed"
2064 # repeat writing on a 1M file
2065 test_21_sub ${TESTFILE}_1 1 30 &
2067 # repeat writing on a 128M file
2068 test_21_sub ${TESTFILE}_2 128 30 &
2071 local time=$(($(date +%s) + 30))
2073 while [ $(date +%s) -lt $time ]; do
2074 log "Set quota for $i times"
2075 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2076 -I $((ILIMIT + i)) $MOUNT ||
2077 error "Set user quota failed"
2078 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2079 -I $((ILIMIT + i)) $MOUNT ||
2080 error "Set group quota failed"
2081 if is_project_quota_supported; then
2082 $LFS setquota -p $TSTPRJID -b 0 -B \
2083 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2084 error "Set project quota failed"
2092 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2094 if [ $count -gt 60 ]; then
2095 quota_error a $TSTUSR "dd should be finished!"
2099 echo "(dd_pid=$DDPID1, time=$count)successful"
2103 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2105 if [ $count -gt 60 ]; then
2106 quota_error a $TSTUSR "dd should be finished!"
2110 echo "(dd_pid=$DDPID2, time=$count)successful"
2113 resetquota -u $TSTUSR
2114 resetquota -g $TSTUSR
2115 resetquota -p $TSTPRJID
2117 run_test 21 "Setquota while writing & deleting (b16053)"
2119 # enable/disable quota enforcement permanently
2121 echo "Set both mdt & ost quota type as ug"
2123 is_project_quota_supported && qtype=$QTYPE
2124 set_mdt_qtype $qtype || error "enable mdt quota failed"
2125 set_ost_qtype $qtype || error "enable ost quota failed"
2128 stopall || error "failed to stopall (1)"
2132 echo "Verify if quota is enabled"
2133 local qtype1=$(mdt_quota_type)
2134 [ $qtype1 != $qtype] && error "mdt quota setting is lost"
2135 qtype=$(ost_quota_type)
2136 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2138 echo "Set both mdt & ost quota type as none"
2139 set_mdt_qtype "none" || error "disable mdt quota failed"
2140 set_ost_qtype "none" || error "disable ost quota failed"
2143 stopall || error "failed to stopall (2)"
2148 echo "Verify if quota is disabled"
2149 qtype=$(mdt_quota_type)
2150 [ $qtype != "none" ] && error "mdt quota setting is lost"
2151 qtype=$(ost_quota_type)
2152 [ $qtype != "none" ] && error "ost quota setting is lost"
2156 run_test 22 "enable/disable quota by 'lctl conf_param'"
2159 local TESTFILE="$DIR/$tdir/$tfile"
2162 setup_quota_test || error "setup quota failed with $?"
2163 trap cleanup_quota_test EXIT
2165 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2168 log "User quota (limit: $LIMIT MB)"
2169 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2170 error "set quota failed"
2171 quota_show_check b u $TSTUSR
2173 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2174 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2176 log "Step1: trigger EDQUOT with O_DIRECT"
2177 log "Write half of file"
2178 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2179 quota_error u $TSTUSR "(1) Write failure, expect success." \
2181 log "Write out of block quota ..."
2182 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2183 oflag=direct conv=notrunc &&
2184 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2188 log "Step2: rewrite should succeed"
2189 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2190 quota_error u $TSTUSR "(3) Write failure, expect success." \
2196 local OST0_UUID=$(ostuuid_from_index 0)
2197 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2198 [ $OST0_QUOTA_USED -ne 0 ] &&
2199 ($SHOW_QUOTA_USER; \
2200 quota_error u $TSTUSR "quota isn't released")
2202 resetquota -u $TSTUSR
2206 [ $(facet_fstype ost1) == "zfs" ] &&
2207 skip "Overwrite in place is not guaranteed to be " \
2208 "space neutral on ZFS" && return
2210 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2211 check_whether_skip && return 0
2212 log "run for 4MB test file"
2215 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2216 check_whether_skip && return 0
2217 log "run for 40MB test file"
2220 run_test 23 "Quota should be honored with directIO (b16125)"
2224 local TESTFILE="$DIR/$tdir/$tfile"
2226 setup_quota_test || error "setup quota failed with $?"
2227 trap cleanup_quota_test EXIT
2229 set_ost_qtype $QTYPE || error "enable ost quota failed"
2231 # bind file to a single OST
2232 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2233 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2235 echo "Set user quota (limit: ${blimit}M)"
2236 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2237 error "set quota failed"
2239 # overrun quota by root user
2240 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2241 error "write failure, expect success"
2242 cancel_lru_locks osc
2243 sync_all_data || true
2245 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2248 resetquota -u $TSTUSR
2250 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2252 test_27a() { # b19612
2253 $LFS quota $TSTUSR $DIR &&
2254 error "lfs succeeded with no type, but should have failed"
2255 $LFS setquota $TSTUSR $DIR &&
2256 error "lfs succeeded with no type, but should have failed"
2259 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2261 test_27b() { # b20200
2262 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2263 error "lfs setquota failed with uid argument"
2264 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2265 error "lfs stequota failed with gid argument"
2266 if is_project_quota_supported; then
2267 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2268 1000 $DIR || error \
2269 "lfs stequota failed with projid argument"
2271 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2272 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2273 if is_project_quota_supported; then
2274 $SHOW_QUOTA_PROJID ||
2275 error "lfs quota failed with projid argument"
2277 resetquota -u $TSTUSR
2278 resetquota -g $TSTUSR
2279 resetquota -p $TSTPRJID
2282 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2287 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2288 error "lfs setquota failed"
2290 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2291 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2292 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2293 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2295 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2296 error "lfs setquota for $TSTID failed"
2298 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2299 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2300 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2301 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2303 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2304 error "total allocated inode/block limit not printed"
2306 resetquota -u $TSTUSR
2308 run_test 27c "lfs quota should support human-readable output"
2315 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2316 error "set fraction block limit failed"
2317 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2318 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2319 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2320 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2322 resetquota -u $TSTUSR
2324 run_test 27d "lfs setquota should support fraction block limit"
2328 local TESTFILE="$DIR/$tdir/$tfile"
2331 setup_quota_test || error "setup quota failed with $?"
2332 trap cleanup_quota_test EXIT
2334 set_ost_qtype "u" || error "enable ost quota failed"
2336 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2337 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2339 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2340 $MAX_IQ_TIME $DIR || error "set grace time failed"
2341 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2342 error "set quota failed"
2343 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2344 cancel_lru_locks osc
2346 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2347 # over-quota flag has not yet settled since we do not trigger async
2348 # events based on grace time period expiration
2350 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2351 cancel_lru_locks osc
2352 # now over-quota flag should be settled and further writes should fail
2354 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2355 error "grace times were reset"
2358 resetquota -u $TSTUSR
2359 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2360 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2362 run_test 30 "Hard limit updates should not reset grace times"
2364 # basic usage tracking for user & group
2366 local INODES=10 # 10 files
2367 local BLK_CNT=2 # of 2M each
2368 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2370 setup_quota_test || error "setup quota failed with $?"
2371 trap cleanup_quota_test EXIT
2373 # make sure the system is clean
2374 local USED=$(getquota -u $TSTID global curspace)
2376 error "Used space ($USED) for user $TSTID isn't 0."
2377 USED=$(getquota -g $TSTID global curspace)
2379 error "Used space ($USED) for group $TSTID isn't 0."
2380 if is_project_quota_supported; then
2381 USED=$(getquota -p $TSTPRJID global curspace)
2382 [ $USED -ne 0 ] && error \
2383 "Used space ($USED) for project $TSTPRJID isn't 0."
2386 echo "Write files..."
2387 for i in $(seq 0 $INODES); do
2388 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2389 error "write failed"
2390 is_project_quota_supported &&
2391 chattr -p $TSTPRJID $DIR/$tdir/$tfile-$i
2392 echo "Iteration $i/$INODES completed"
2394 cancel_lru_locks osc
2395 sync; sync_all_data || true
2397 echo "Verify disk usage after write"
2398 USED=$(getquota -u $TSTID global curspace)
2399 [ $USED -lt $TOTAL_BLKS ] &&
2400 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2401 USED=$(getquota -g $TSTID global curspace)
2402 [ $USED -lt $TOTAL_BLKS ] &&
2403 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2404 if is_project_quota_supported; then
2405 USED=$(getquota -p $TSTPRJID global curspace)
2406 [ $USED -lt $TOTAL_BLKS ] && error \
2407 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2410 echo "Verify inode usage after write"
2411 USED=$(getquota -u $TSTID global curinodes)
2412 [ $USED -lt $INODES ] &&
2413 error "Used inode for user $TSTID is $USED, expected $INODES"
2414 USED=$(getquota -g $TSTID global curinodes)
2415 [ $USED -lt $INODES ] &&
2416 error "Used inode for group $TSTID is $USED, expected $INODES"
2417 if is_project_quota_supported; then
2418 USED=$(getquota -p $TSTPRJID global curinodes)
2419 [ $USED -lt $INODES ] && error \
2420 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2425 echo "Verify disk usage after delete"
2426 USED=$(getquota -u $TSTID global curspace)
2427 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2428 USED=$(getquota -u $TSTID global curinodes)
2429 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2430 USED=$(getquota -g $TSTID global curspace)
2431 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2432 USED=$(getquota -g $TSTID global curinodes)
2433 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2434 if is_project_quota_supported; then
2435 USED=$(getquota -p $TSTPRJID global curinodes)
2437 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2440 run_test 33 "Basic usage tracking for user & group & project"
2442 # usage transfer test for user & group & project
2444 local BLK_CNT=2 # 2MB
2445 local project_supported="no"
2447 is_project_quota_supported && project_supported="yes"
2448 setup_quota_test || error "setup quota failed with $?"
2449 trap cleanup_quota_test EXIT
2451 # make sure the system is clean
2452 local USED=$(getquota -u $TSTID global curspace)
2453 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2454 USED=$(getquota -g $TSTID global curspace)
2455 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2457 local USED=$(getquota -u $TSTID2 global curspace)
2458 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2459 if [ $project_supported == "yes" ]; then
2460 USED=$(getquota -p $TSTPRJID global curspace)
2461 [ $USED -ne 0 ] && error \
2462 "Used space ($USED) for Project $TSTPRJID isn't 0."
2465 echo "Write file..."
2466 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2467 error "write failed"
2468 cancel_lru_locks osc
2469 sync; sync_all_data || true
2471 echo "chown the file to user $TSTID"
2472 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2474 echo "Wait for setattr on objects finished..."
2475 wait_delete_completed
2477 BLK_CNT=$((BLK_CNT * 1024))
2479 echo "Verify disk usage for user $TSTID"
2480 USED=$(getquota -u $TSTID global curspace)
2481 [ $USED -lt $BLK_CNT ] &&
2482 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2483 USED=$(getquota -u $TSTID global curinodes)
2485 error "Used inodes for user $TSTID is $USED, expected 1"
2487 echo "chgrp the file to group $TSTID"
2488 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2490 echo "Wait for setattr on objects finished..."
2491 wait_delete_completed
2493 echo "Verify disk usage for group $TSTID"
2494 USED=$(getquota -g $TSTID global curspace)
2495 [ $USED -ge $BLK_CNT ] ||
2496 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2497 USED=$(getquota -g $TSTID global curinodes)
2499 error "Used inodes for group $TSTID is $USED, expected 1"
2501 # chown won't change the ost object group. LU-4345 */
2502 echo "chown the file to user $TSTID2"
2503 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2505 echo "Wait for setattr on objects finished..."
2506 wait_delete_completed
2508 echo "chattr project id to $TSTPRJID"
2509 [ $project_supported == "yes" ] &&
2510 chattr -p $TSTPRJID $DIR/$tdir/$tfile
2511 echo "Wait for setattr on objects finished..."
2512 wait_delete_completed
2514 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2515 USED=$(getquota -u $TSTID2 global curspace)
2516 [ $USED -lt $BLK_CNT ] &&
2517 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2518 USED=$(getquota -u $TSTID global curspace)
2520 error "Used space for user $TSTID is $USED, expected 0"
2521 USED=$(getquota -g $TSTID global curspace)
2522 [ $USED -lt $BLK_CNT ] &&
2523 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2524 if [ $project_supported == "yes" ]; then
2525 USED=$(getquota -p $TSTPRJID global curspace)
2526 [ $USED -lt $BLK_CNT ] && error \
2527 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2532 run_test 34 "Usage transfer for user & group & project"
2534 # usage is still accessible across restart
2536 local BLK_CNT=2 # 2 MB
2538 setup_quota_test || error "setup quota failed with $?"
2539 trap cleanup_quota_test EXIT
2541 echo "Write file..."
2542 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2543 error "write failed"
2544 is_project_quota_supported &&
2545 chattr -p $TSTPRJID $DIR/$tdir/$tfile
2546 cancel_lru_locks osc
2547 sync; sync_all_data || true
2549 echo "Save disk usage before restart"
2550 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2551 [ $ORIG_USR_SPACE -eq 0 ] &&
2552 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2553 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2554 [ $ORIG_USR_INODES -eq 0 ] &&
2555 error "Used inodes for user $TSTID is 0, expected 1"
2556 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2557 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2558 [ $ORIG_GRP_SPACE -eq 0 ] &&
2559 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2560 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2561 [ $ORIG_GRP_INODES -eq 0 ] &&
2562 error "Used inodes for group $TSTID is 0, expected 1"
2563 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2565 if is_project_quota_supported; then
2566 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2567 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2568 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2569 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2570 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2571 "Used inodes for project $TSTPRJID is 0, expected 1"
2572 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2576 local ORIG_REFORMAT=$REFORMAT
2578 cleanup_and_setup_lustre
2579 REFORMAT=$ORIG_REFORMAT
2582 echo "Verify disk usage after restart"
2583 local USED=$(getquota -u $TSTID global curspace)
2584 [ $USED -eq $ORIG_USR_SPACE ] ||
2585 error "Used space for user $TSTID changed from " \
2586 "$ORIG_USR_SPACE to $USED"
2587 USED=$(getquota -u $TSTID global curinodes)
2588 [ $USED -eq $ORIG_USR_INODES ] ||
2589 error "Used inodes for user $TSTID changed from " \
2590 "$ORIG_USR_INODES to $USED"
2591 USED=$(getquota -g $TSTID global curspace)
2592 [ $USED -eq $ORIG_GRP_SPACE ] ||
2593 error "Used space for group $TSTID changed from " \
2594 "$ORIG_GRP_SPACE to $USED"
2595 USED=$(getquota -g $TSTID global curinodes)
2596 [ $USED -eq $ORIG_GRP_INODES ] ||
2597 error "Used inodes for group $TSTID changed from " \
2598 "$ORIG_GRP_INODES to $USED"
2599 if [ $project_supported == "yes" ]; then
2600 USED=$(getquota -p $TSTPRJID global curinodes)
2601 [ $USED -eq $ORIG_PRJ_INODES ] ||
2602 error "Used inodes for project $TSTPRJID " \
2603 "changed from $ORIG_PRJ_INODES to $USED"
2604 USED=$(getquota -p $TSTPRJID global curspace)
2605 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2606 error "Used space for project $TSTPRJID "\
2607 "changed from $ORIG_PRJ_SPACE to $USED"
2610 # check if the vfs_dq_init() is called before writing
2611 echo "Append to the same file..."
2612 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2613 error "write failed"
2614 cancel_lru_locks osc
2615 sync; sync_all_data || true
2617 echo "Verify space usage is increased"
2618 USED=$(getquota -u $TSTID global curspace)
2619 [ $USED -gt $ORIG_USR_SPACE ] ||
2620 error "Used space for user $TSTID isn't increased" \
2621 "orig:$ORIG_USR_SPACE, now:$USED"
2622 USED=$(getquota -g $TSTID global curspace)
2623 [ $USED -gt $ORIG_GRP_SPACE ] ||
2624 error "Used space for group $TSTID isn't increased" \
2625 "orig:$ORIG_GRP_SPACE, now:$USED"
2626 if [ $project_supported == "yes" ]; then
2627 USED=$(getquota -p $TSTPRJID global curspace)
2628 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2629 error "Used space for project $TSTPRJID isn't " \
2630 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2635 run_test 35 "Usage is still accessible across reboot"
2637 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2640 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2641 skip "Old server doesn't have LU-5006 fix." && return
2643 setup_quota_test || error "setup quota failed with $?"
2644 trap cleanup_quota_test EXIT
2646 # make sure the system is clean
2647 local USED=$(getquota -u $TSTID global curspace)
2649 error "Used space ($USED) for user $TSTID isn't 0."
2651 # create file with MDS_OPEN_DELAY_CREATE flag
2652 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2653 error "Create file failed"
2655 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2656 oflag=sync || error "Write file failed"
2658 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2660 # wait for setattr on objects finished..."
2661 wait_delete_completed
2663 USED=$(getquota -u $TSTID global curspace)
2664 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2668 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2672 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2673 skip "Old server doesn't have LU-8801 fix." && return
2675 [ "$UID" != 0 ] && skip_env "must run as root" && return
2677 setup_quota_test || error "setup quota failed with $?"
2678 trap cleanup_quota_test EXIT
2680 # make sure the system is clean
2681 local USED=$(getquota -u $TSTID global curspace)
2683 error "Used space ($USED) for user $TSTID isn't 0."
2684 USED=$(getquota -u $TSTID2 global curspace)
2686 error "Used space ($USED) for user $TSTID2 isn't 0."
2688 local TESTFILE="$DIR/$tdir/$tfile"
2689 local file_cnt=10000
2691 # Generate id entries in accounting file
2692 echo "Create $file_cnt files..."
2693 for i in `seq $file_cnt`; do
2695 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i
2697 cancel_lru_locks osc
2698 sync; sync_all_data || true
2700 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2701 procf=${procf}.quota_slave.acct_user
2704 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
2705 echo "Found $acct_cnt id entries"
2707 [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
2711 run_test 38 "Quota accounting iterator doesn't skip id entries"
2714 local TESTFILE="$DIR/$tdir/project"
2715 ! is_project_quota_supported &&
2716 skip "Project quota is not supported" && return 0
2718 setup_quota_test || error "setup quota failed with $?"
2721 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2722 [ $projectid -ne 0 ] &&
2723 error "Project id should be 0 not $projectid"
2724 chattr -p 1024 $TESTFILE
2725 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2726 [ $projectid -ne 1024 ] &&
2727 error "Project id should be 1024 not $projectid"
2729 stopall || error "failed to stopall (1)"
2732 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2733 [ $projectid -ne 1024 ] &&
2734 error "Project id should be 1024 not $projectid"
2738 run_test 39 "Project ID interface works correctly"
2741 ! is_project_quota_supported &&
2742 skip "Project quota is not supported" && return 0
2743 local dir1="$DIR/$tdir/dir1"
2744 local dir2="$DIR/$tdir/dir2"
2746 setup_quota_test || error "setup quota failed with $?"
2748 mkdir -p $dir1 $dir2
2749 chattr +P $dir1 && chattr -p 1 -d $dir1 && touch $dir1/1
2750 chattr +P $dir2 && chattr -p 2 -d $dir2
2752 ln $dir1/1 $dir2/1_link &&
2753 error "Hard link across different project quota should fail"
2758 run_test 40a "Hard link across different project ID"
2761 ! is_project_quota_supported &&
2762 skip "Project quota is not supported" && return 0
2763 local dir1="$DIR/$tdir/dir1"
2764 local dir2="$DIR/$tdir/dir2"
2766 setup_quota_test || error "setup quota failed with $?"
2767 mkdir -p $dir1 $dir2
2768 chattr +P $dir1 && chattr -p 1 -d $dir1 && touch $dir1/1
2769 chattr +P $dir2 && chattr -p 2 -d $dir2
2771 mv $dir1/1 $dir2/2 || error "mv failed $?"
2772 local projid=$(lsattr -p $dir2/2 | awk '{print $1}')
2773 if [ "$projid" != "2" ]; then
2774 error "project id expected 2 not $projid"
2779 run_test 40b "Mv across different project ID"
2782 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
2783 ! is_project_quota_supported &&
2784 skip "Project quota is not supported" && return 0
2786 setup_quota_test || error "setup quota failed with $?"
2787 local dir="$DIR/$tdir/dir"
2789 mkdir -p $dir && chattr +P $dir && chattr -dp 1 $dir
2790 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2791 local projid=$(lsattr -dp $dir/remote_dir | awk '{print $1}')
2792 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2793 touch $dir/remote_dir/file
2794 #verify inherit works file for remote dir.
2795 local projid=$(lsattr -dp $dir/remote_dir/file | awk '{print $1}')
2796 [ "$projid" != "1" ] &&
2797 error "file under remote dir expected 1 not $projid"
2799 #Agent inode should be ignored for project quota
2800 USED=$(getquota -p 1 global curinodes)
2801 [ "$USED" != "3" ] &&
2802 error "file count expected 3 got $USED"
2808 run_test 40c "Remote child Dir inherit project quota properly"
2811 ! is_project_quota_supported &&
2812 skip "Project quota is not supported" && return 0
2814 setup_quota_test || error "setup quota failed with $?"
2815 local dir="$DIR/$tdir/dir"
2817 mkdir $dir && chattr -dp 1 $dir
2818 count=$($LFS find --projid 1 $DIR | wc -l)
2819 [ "$count" != 1 ] && error "expected 1 but got $count"
2824 run_test 50 "Test if lfs find --projid works"
2827 ! is_project_quota_supported &&
2828 skip "Project quota is not supported" && return 0
2829 setup_quota_test || error "setup quota failed with $?"
2830 local dir="$DIR/$tdir/dir"
2832 mkdir $dir && chattr -dp 1 $dir && chattr +P $dir
2833 local used=$(getquota -p 1 global curinodes)
2834 [ $used != "1" ] && error "expected 1 got $used"
2839 used=$(getquota -p 1 global curinodes)
2840 [ $used != "4" ] && error "expected 4 got $used"
2842 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2844 cp $DIR/$tdir/6 $dir/6
2845 used=$(getquota -p 1 global curinodes)
2846 [ $used != "5" ] && error "expected 5 got $used"
2849 mv $DIR/$tdir/6 $dir/7
2850 used=$(getquota -p 1 global curinodes)
2851 [ $used != "6" ] && error "expected 6 got $used"
2856 run_test 51 "Test project accounting with mv/cp"
2859 ! is_project_quota_supported &&
2860 skip "Project quota is not supported" && return 0
2861 setup_quota_test || error "setup quota failed with $?"
2862 local dir="$DIR/$tdir/dir"
2863 mkdir $dir && chattr -dp 1 $dir && chattr +P $dir
2865 touch $DIR/$tdir/file
2866 #Try renaming a file into the project. This should fail.
2867 for num in $(seq 1 2000); do
2868 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2869 error "rename should fail"
2874 run_test 52 "Rename across different project ID"
2878 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2879 disable_project_quota
2885 check_and_cleanup_lustre
2886 export QUOTA_AUTO=$QUOTA_AUTO_OLD