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 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
502 quota_error u $TSTUSR "user write success, but expect EDQUOT"
505 wait_delete_completed || error "wait_delete_completed failed"
506 sync_all_data || true
507 USED=$(getquota -u $TSTUSR global curspace)
508 [ $USED -ne 0 ] && quota_error u $TSTUSR \
509 "user quota isn't released after deletion"
510 resetquota -u $TSTUSR
513 log "--------------------------------------"
514 log "Group quota (block hardlimit:$LIMIT MB)"
515 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
516 error "set group quota failed"
518 TESTFILE="$DIR/$tdir/$tfile-1"
519 # make sure the system is clean
520 USED=$(getquota -g $TSTUSR global curspace)
521 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
523 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
524 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
527 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
528 quota_error g $TSTUSR "Group write failure, but expect success"
529 log "Write out of block quota ..."
530 # this time maybe cache write, ignore it's failure
531 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
533 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
534 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
536 wait_delete_completed || error "wait_delete_completed failed"
537 sync_all_data || true
538 USED=$(getquota -g $TSTUSR global curspace)
539 [ $USED -ne 0 ] && quota_error g $TSTUSR \
540 "Group quota isn't released after deletion"
541 resetquota -g $TSTUSR
543 if ! is_project_quota_supported; then
544 echo "Project quota is not supported"
549 TESTFILE="$DIR/$tdir/$tfile-2"
550 # make sure the system is clean
551 USED=$(getquota -p $TSTPRJID global curspace)
553 error "used space($USED) for project $TSTPRJID isn't 0"
556 log "--------------------------------------"
557 log "project quota (block hardlimit:$LIMIT mb)"
558 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
559 error "set project quota failed"
561 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
562 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
563 chattr -p $TSTPRJID $TESTFILE
566 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
567 "project write failure, but expect success"
568 log "write out of block quota ..."
569 # this time maybe cache write, ignore it's failure
570 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
572 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
573 $TSTPRJID "project write success, but expect edquot"
578 USED=$(getquota -p $TSTPRJID global curspace)
579 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
580 "project quota isn't released after deletion"
582 resetquota -p $TSTPRJID
584 run_test 1 "Block hard limit (normal use and out of quota)"
586 # test inode hardlimit
588 local LIMIT=$((1024 * 1024)) # 1M inodes
589 local TESTFILE="$DIR/$tdir/$tfile-0"
591 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
593 local FREE_INODES=$(mdt_free_inodes 0)
594 echo "$FREE_INODES free inodes on master MDT"
595 [ $FREE_INODES -lt $LIMIT ] &&
596 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
599 setup_quota_test || error "setup quota failed with $?"
600 trap cleanup_quota_test EXIT
603 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
606 log "User quota (inode hardlimit:$LIMIT files)"
607 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
608 error "set user quota failed"
610 # make sure the system is clean
611 local USED=$(getquota -u $TSTUSR global curinodes)
612 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
614 log "Create $LIMIT files ..."
615 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
616 quota_error u $TSTUSR "user create failure, but expect success"
617 log "Create out of file quota ..."
618 $RUNAS touch ${TESTFILE}_xxx &&
619 quota_error u $TSTUSR "user create success, but expect EDQUOT"
622 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
623 rm -f ${TESTFILE}_xxx
624 wait_delete_completed
626 USED=$(getquota -u $TSTUSR global curinodes)
627 [ $USED -ne 0 ] && quota_error u $TSTUSR \
628 "user quota isn't released after deletion"
629 resetquota -u $TSTUSR
632 log "--------------------------------------"
633 log "Group quota (inode hardlimit:$LIMIT files)"
634 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
635 error "set group quota failed"
637 TESTFILE=$DIR/$tdir/$tfile-1
638 # make sure the system is clean
639 USED=$(getquota -g $TSTUSR global curinodes)
640 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
642 log "Create $LIMIT files ..."
643 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
644 quota_error g $TSTUSR "group create failure, but expect success"
645 log "Create out of file quota ..."
646 $RUNAS touch ${TESTFILE}_xxx &&
647 quota_error g $TSTUSR "group create success, but expect EDQUOT"
650 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
651 rm -f ${TESTFILE}_xxx
652 wait_delete_completed
654 USED=$(getquota -g $TSTUSR global curinodes)
655 [ $USED -ne 0 ] && quota_error g $TSTUSR \
656 "user quota isn't released after deletion"
658 resetquota -g $TSTUSR
659 ! is_project_quota_supported && cleanup_quota_test &&
660 echo "Skip project quota is not supported" && return 0
663 log "--------------------------------------"
664 log "Project quota (inode hardlimit:$LIMIT files)"
665 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
666 error "set project quota failed"
668 TESTFILE=$DIR/$tdir/$tfile-1
669 # make sure the system is clean
670 USED=$(getquota -p $TSTPRJID global curinodes)
672 error "Used inodes($USED) for project $TSTPRJID isn't 0"
674 chattr +P $DIR/$tdir/
675 chattr -p $TSTPRJID -d $DIR/$tdir
676 log "Create $LIMIT files ..."
677 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
678 $TSTPRJID "project create fail, but expect success"
679 log "Create out of file quota ..."
680 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
681 "project create success, but expect EDQUOT"
683 chattr -p 0 -d $DIR/$tdir
686 USED=$(getquota -p $TSTPRJID global curinodes)
687 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
688 "project quota isn't released after deletion"
690 resetquota -p $TSTPRJID
693 run_test 2 "File hard limit (normal use and out of quota)"
697 local TIMER=$(($2 * 3 / 2))
703 trap cleanup_quota_test EXIT
705 $SETSTRIPE $TESTFILE -c 1 -i 0
706 chown $TSTUSR.$TSTUSR $TESTFILE
707 [ "$qtype" == "p" ] && is_project_quota_supported &&
708 chattr -p $TSTPRJID $TESTFILE
710 echo "Write up to soft limit"
711 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
712 quota_error a $TSTUSR "write failure, but expect success"
713 OFFSET=$((LIMIT * 1024))
716 echo "Write to exceed soft limit"
717 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
718 quota_error a $TSTUSR "write failure, but expect success"
719 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
725 $SHOW_QUOTA_INFO_USER
726 $SHOW_QUOTA_INFO_GROUP
727 $SHOW_QUOTA_INFO_PROJID
729 echo "Write before timer goes off"
730 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
731 quota_error a $TSTUSR "write failure, but expect success"
732 OFFSET=$((OFFSET + 1024))
735 echo "Sleep $TIMER seconds ..."
741 $SHOW_QUOTA_INFO_USER
742 $SHOW_QUOTA_INFO_GROUP
743 $SHOW_QUOTA_INFO_PROJID
745 echo "Write after timer goes off"
746 # maybe cache write, ignore.
747 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
748 OFFSET=$((OFFSET + 1024))
750 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
751 quota_error a $TSTUSR "write success, but expect EDQUOT"
756 $SHOW_QUOTA_INFO_USER
757 $SHOW_QUOTA_INFO_GROUP
758 $SHOW_QUOTA_INFO_PROJID
760 echo "Unlink file to stop timer"
762 wait_delete_completed
763 sync_all_data || true
768 $SHOW_QUOTA_INFO_USER
769 $SHOW_QUOTA_INFO_GROUP
770 $SHOW_QUOTA_INFO_PROJID
772 $SETSTRIPE $TESTFILE -c 1 -i 0
773 chown $TSTUSR.$TSTUSR $TESTFILE
774 [ "$qtype" == "p" ] && chattr -p $TSTPRJID $TESTFILE
777 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
778 quota_error a $TSTUSR "write failure, but expect success"
787 local TESTFILE=$DIR/$tdir/$tfile-0
789 set_ost_qtype $QTYPE || error "enable ost quota failed"
791 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
792 # make sure the system is clean
793 local USED=$(getquota -u $TSTUSR global curspace)
794 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
796 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
797 $MAX_IQ_TIME $DIR || error "set user grace time failed"
798 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
799 error "set user quota failed"
801 test_block_soft $TESTFILE $GRACE $LIMIT "u"
802 resetquota -u $TSTUSR
804 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
805 TESTFILE=$DIR/$tdir/$tfile-1
806 # make sure the system is clean
807 USED=$(getquota -g $TSTUSR global curspace)
808 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
810 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
811 $MAX_IQ_TIME $DIR || error "set group grace time failed"
812 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
813 error "set group quota failed"
815 test_block_soft $TESTFILE $GRACE $LIMIT "g"
816 resetquota -g $TSTUSR
818 if is_project_quota_supported; then
819 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
820 TESTFILE=$DIR/$tdir/$tfile-2
821 # make sure the system is clean
822 USED=$(getquota -p $TSTPRJID global curspace)
823 [ $USED -ne 0 ] && error \
824 "Used space($USED) for project $TSTPROJID isn't 0."
826 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
828 error "set project grace time failed"
829 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
830 $DIR || error "set project quota failed"
832 test_block_soft $TESTFILE $GRACE $LIMIT "p"
833 resetquota -p $TSTPRJID
834 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
836 error "restore project grace time failed"
840 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
841 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
842 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
843 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
845 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
851 local TIMER=$(($grace * 3 / 2))
854 trap cleanup_quota_test EXIT
855 is_project_quota_supported && chattr +P $DIR/$tdir/ &&
856 chattr -p $TSTPRJID -d $DIR/$tdir
858 echo "Create files to exceed soft limit"
859 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
860 quota_error a $TSTUSR "create failure, but expect success"
861 local trigger_time=$(date +%s)
863 sync_all_data || true
865 local cur_time=$(date +%s)
866 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
867 error "Passed grace time $grace, $trigger_time, $cur_time"
869 echo "Create file before timer goes off"
870 $RUNAS touch ${TESTFILE}_before ||
871 quota_error a $TSTUSR "failed create before timer expired," \
872 "but expect success. $trigger_time, $cur_time"
873 sync_all_data || true
875 echo "Sleep $TIMER seconds ..."
881 $SHOW_QUOTA_INFO_USER
882 $SHOW_QUOTA_INFO_GROUP
883 $SHOW_QUOTA_INFO_PROJID
885 echo "Create file after timer goes off"
886 # There is a window that space is accounted in the quota usage but
887 # hasn't been decreased from the pending write, if we acquire quota
888 # in this window, we'll acquire more than we needed.
889 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
890 sync_all_data || true
891 $RUNAS touch ${TESTFILE}_after_3 &&
892 quota_error a $TSTUSR "create after timer expired," \
894 sync_all_data || true
899 $SHOW_QUOTA_INFO_USER
900 $SHOW_QUOTA_INFO_GROUP
901 $SHOW_QUOTA_INFO_PROJID
903 echo "Unlink files to stop timer"
904 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
905 wait_delete_completed
908 $RUNAS touch ${TESTFILE}_xxx ||
909 quota_error a $TSTUSR "touch after timer stop failure," \
911 sync_all_data || true
919 local LIMIT=10 # inodes
920 local TESTFILE=$DIR/$tdir/$tfile-0
923 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
925 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
926 # make sure the system is clean
927 local USED=$(getquota -u $TSTUSR global curinodes)
928 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
930 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
931 $GRACE $DIR || error "set user grace time failed"
932 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
933 error "set user quota failed"
935 test_file_soft $TESTFILE $LIMIT $GRACE
936 resetquota -u $TSTUSR
938 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
939 # make sure the system is clean
940 USED=$(getquota -g $TSTUSR global curinodes)
941 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
943 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
944 $GRACE $DIR || error "set group grace time failed"
945 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
946 error "set group quota failed"
947 TESTFILE=$DIR/$tdir/$tfile-1
949 test_file_soft $TESTFILE $LIMIT $GRACE
950 resetquota -g $TSTUSR
952 if is_project_quota_supported; then
953 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
954 # make sure the system is clean
955 USED=$(getquota -p $TSTPRJID global curinodes)
956 [ $USED -ne 0 ] && error \
957 "Used space($USED) for project $TSTPRJID isn't 0."
959 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
960 $GRACE $DIR || error "set project grace time failed"
961 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
962 error "set project quota failed"
964 TESTFILE=$DIR/$tdir/$tfile-1
965 # one less than limit, because of parent directory included.
966 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
967 resetquota -p $TSTPRJID
968 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
970 error "restore project grace time failed"
974 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
975 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
976 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
977 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
979 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
983 local GR_STR2="1000s"
985 local GR_STR4="1w2d3h4m5s"
987 local GR_STR6="18446744073709551615"
990 wait_delete_completed
992 # test of valid grace strings handling
993 echo "Valid grace strings test"
994 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
995 $GR_STR2 $DIR || error "set user grace time failed"
996 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
997 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
998 $GR_STR4 $DIR || error "set group grace time quota failed"
999 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1001 # test of invalid grace strings handling
1002 echo " Invalid grace strings test"
1003 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1004 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1005 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1009 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1010 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1011 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1012 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1014 run_test 4b "Grace time strings handling"
1016 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1018 local BLIMIT=10 # 10M
1019 local ILIMIT=10 # 10 inodes
1021 setup_quota_test || error "setup quota failed with $?"
1022 trap cleanup_quota_test EXIT
1024 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1025 set_ost_qtype $QTYPE || error "enable ost quota failed"
1027 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1028 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1029 error "set user quota failed"
1030 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1031 if is_project_quota_supported; then
1032 error "set group quota failed"
1033 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1034 -I $ILIMIT $DIR || error "set project quota failed"
1037 # make sure the system is clean
1038 local USED=$(getquota -u $TSTUSR global curinodes)
1039 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1040 USED=$(getquota -g $TSTUSR global curinodes)
1041 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1042 USED=$(getquota -u $TSTUSR global curspace)
1043 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1044 USED=$(getquota -g $TSTUSR global curspace)
1045 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1046 if is_project_quota_supported; then
1047 USED=$(getquota -p $TSTPRJID global curspace)
1049 error "Used block($USED) for project $TSTPRJID isn't 0."
1052 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1053 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1054 error "create failure, expect success"
1055 if [ "$(facet_fstype $singlemds)" == "ldiskfs" ]; then
1056 touch $DIR/$tdir/$tfile-0_1
1057 chattr -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1059 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1060 error "write failure, expect success"
1062 echo "Chown files to $TSTUSR.$TSTUSR ..."
1063 for i in $(seq 0 $ILIMIT); do
1064 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1065 quota_error a $TSTUSR "chown failure, expect success"
1069 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1070 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1073 resetquota -u $TSTUSR
1074 resetquota -g $TSTUSR
1075 resetquota -p $TSTPRJID
1077 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1079 # test dropping acquire request on master
1083 # Clear dmesg so watchdog is not triggered by previous
1085 do_facet ost1 dmesg -c > /dev/null
1087 setup_quota_test || error "setup quota failed with $?"
1088 trap cleanup_quota_test EXIT
1090 # make sure the system is clean
1091 local USED=$(getquota -u $TSTUSR global curspace)
1092 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1094 # make sure no granted quota on ost
1095 set_ost_qtype $QTYPE || error "enable ost quota failed"
1096 resetquota -u $TSTUSR
1098 # create file for $TSTUSR
1099 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1100 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1101 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1103 # create file for $TSTUSR2
1104 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1105 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1106 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1108 # cache per-ID lock for $TSTUSR on slave
1109 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1110 error "set quota failed"
1111 $RUNAS $DD of=$TESTFILE count=1 ||
1112 error "write $TESTFILE failure, expect success"
1113 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1114 error "write $TESTFILE2 failure, expect success"
1116 sync_all_data || true
1118 #define QUOTA_DQACQ 601
1119 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1120 lustre_fail mds 0x513 601
1122 # write to un-enforced ID ($TSTUSR2) should succeed
1123 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1124 error "write failure, expect success"
1126 # write to enforced ID ($TSTUSR) in background, exceeding limit
1127 # to make sure DQACQ is sent
1128 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1131 # watchdog timer uses a factor of 2
1132 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1133 sleep $((TIMEOUT * 2 + 1))
1135 # write should be blocked and never finished
1136 if ! ps -p $DDPID > /dev/null 2>&1; then
1138 error "write finished incorrectly!"
1143 # no watchdog is triggered
1144 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1145 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1146 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1147 [ -z "$watchdog" ] || error "$watchdog"
1149 rm -f $TMP/lustre-log-${TESTNAME}.log
1151 # write should continue then fail with EDQUOT
1155 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1156 if [ $count -ge 240 ]; then
1157 quota_error u $TSTUSR "dd not finished in $count secs"
1159 count=$((count + 1))
1160 if [ $((count % 30)) -eq 0 ]; then
1161 c_size=$(stat -c %s $TESTFILE)
1162 echo "Waiting $count secs. $c_size"
1169 resetquota -u $TSTUSR
1171 run_test 6 "Test dropping acquire request on master"
1173 # quota reintegration (global index)
1175 local TESTFILE=$DIR/$tdir/$tfile
1176 local LIMIT=20 # 20M
1178 [ "$SLOW" = "no" ] && LIMIT=5
1180 setup_quota_test || error "setup quota failed with $?"
1181 trap cleanup_quota_test EXIT
1183 # make sure the system is clean
1184 local USED=$(getquota -u $TSTUSR global curspace)
1185 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1187 # make sure no granted quota on ost1
1188 set_ost_qtype $QTYPE || error "enable ost quota failed"
1189 resetquota -u $TSTUSR
1190 set_ost_qtype "none" || error "disable ost quota failed"
1192 local OSTUUID=$(ostuuid_from_index 0)
1193 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1195 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1198 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1199 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1204 echo "Enable quota & set quota limit for $TSTUSR"
1205 set_ost_qtype $QTYPE || error "enable ost quota failed"
1206 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1207 error "set quota failed"
1209 echo "Start ost1..."
1210 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1213 wait_ost_reint $QTYPE || error "reintegration failed"
1215 # hardlimit should have been fetched by slave during global
1216 # reintegration, write will exceed quota
1217 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1218 quota_error u $TSTUSR "write success, but expect EDQUOT"
1221 wait_delete_completed
1222 sync_all_data || true
1228 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1229 error "clear quota failed"
1231 echo "Start ost1..."
1232 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1235 wait_ost_reint $QTYPE || error "reintegration failed"
1237 # hardlimit should be cleared on slave during reintegration
1238 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1239 quota_error u $TSTUSR "write error, but expect success"
1242 resetquota -u $TSTUSR
1244 run_test 7a "Quota reintegration (global index)"
1246 # quota reintegration (slave index)
1249 local TESTFILE=$DIR/$tdir/$tfile
1251 setup_quota_test || error "setup quota failed with $?"
1252 trap cleanup_quota_test EXIT
1254 # make sure the system is clean
1255 local USED=$(getquota -u $TSTUSR global curspace)
1256 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1258 # make sure no granted quota on ost1
1259 set_ost_qtype $QTYPE || error "enable ost quota failed"
1260 resetquota -u $TSTUSR
1261 set_ost_qtype "none" || error "disable ost quota failed"
1263 local OSTUUID=$(ostuuid_from_index 0)
1264 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1266 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1269 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1270 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1272 # consume some space to make sure the granted space will not
1273 # be released during reconciliation
1274 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1275 error "consume space failure, expect success"
1277 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1278 lustre_fail mds 0xa02
1280 set_ost_qtype $QTYPE || error "enable ost quota failed"
1281 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1282 error "set quota failed"
1284 # ignore the write error
1285 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1287 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1291 echo "Restart ost to trigger reintegration..."
1293 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1296 wait_ost_reint $QTYPE || error "reintegration failed"
1298 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1299 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1302 resetquota -u $TSTUSR
1305 run_test 7b "Quota reintegration (slave index)"
1307 # quota reintegration (restart mds during reintegration)
1309 local LIMIT=20 # 20M
1310 local TESTFILE=$DIR/$tdir/$tfile
1312 [ "$SLOW" = "no" ] && LIMIT=5
1314 setup_quota_test || error "setup quota failed with $?"
1315 trap cleanup_quota_test EXIT
1317 # make sure the system is clean
1318 local USED=$(getquota -u $TSTUSR global curspace)
1319 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1321 set_ost_qtype "none" || error "disable ost quota failed"
1322 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1323 error "set quota failed"
1325 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1326 lustre_fail ost 0xa03
1329 set_ost_qtype $QTYPE || error "enable ost quota failed"
1330 # trigger reintegration
1331 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1332 procf=${procf}quota_slave.force_reint
1333 do_facet ost1 $LCTL set_param $procf=1 ||
1334 error "force reintegration failed"
1342 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1345 # wait longer than usual to make sure the reintegration
1346 # is triggered by quota wb thread.
1347 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1349 # hardlimit should have been fetched by slave during global
1350 # reintegration, write will exceed quota
1351 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1352 quota_error u $TSTUSR "write success, but expect EDQUOT"
1355 resetquota -u $TSTUSR
1357 run_test 7c "Quota reintegration (restart mds during reintegration)"
1359 # Quota reintegration (Transfer index in multiple bulks)
1361 local TESTFILE=$DIR/$tdir/$tfile
1362 local TESTFILE1="$DIR/$tdir/$tfile"-1
1365 setup_quota_test || error "setup quota failed with $?"
1366 trap cleanup_quota_test EXIT
1368 set_ost_qtype "none" || error "disable ost quota failed"
1369 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1370 error "set quota for $TSTUSR failed"
1371 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1372 error "set quota for $TSTUSR2 failed"
1374 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1375 lustre_fail mds 0x608 0
1377 # enable quota to tirgger reintegration
1378 set_ost_qtype "u" || error "enable ost quota failed"
1379 wait_ost_reint "u" || error "reintegration failed"
1383 # hardlimit should have been fetched by slave during global
1384 # reintegration, write will exceed quota
1385 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1386 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1388 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1389 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1392 resetquota -u $TSTUSR
1393 resetquota -u $TSTUSR2
1395 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1397 # quota reintegration (inode limits)
1399 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1401 # LU-2435: skip this quota test if underlying zfs version has not
1402 # supported native dnode accounting
1403 [ "$(facet_fstype mds1)" == "zfs" ] && {
1404 local zfs_version=$(do_facet mds1 cat /sys/module/zfs/version)
1406 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] &&
1407 skip "requires zfs version at least 0.7.0" && return
1410 local ilimit=$((1024 * 2)) # 2k inodes
1411 local TESTFILE=$DIR/${tdir}-1/$tfile
1413 setup_quota_test || error "setup quota failed with $?"
1414 trap cleanup_quota_test EXIT
1416 # make sure the system is clean
1417 local USED=$(getquota -u $TSTUSR global curinodes)
1418 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1420 # make sure no granted quota on mdt1
1421 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1422 resetquota -u $TSTUSR
1423 set_mdt_qtype "none" || error "disable mdt quota failed"
1425 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1426 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1427 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1430 echo "Stop mds${MDSCOUNT}..."
1433 echo "Enable quota & set quota limit for $TSTUSR"
1434 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1435 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1436 error "set quota failed"
1438 echo "Start mds${MDSCOUNT}..."
1439 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1442 wait_mdt_reint $QTYPE || error "reintegration failed"
1444 echo "create remote dir"
1445 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1446 error "create remote dir failed"
1447 chmod 0777 $DIR/${tdir}-1
1449 # hardlimit should have been fetched by slave during global
1450 # reintegration, create will exceed quota
1451 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1452 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1454 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1455 wait_delete_completed
1456 sync_all_data || true
1458 echo "Stop mds${MDSCOUNT}..."
1461 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1462 error "clear quota failed"
1464 echo "Start mds${MDSCOUNT}..."
1465 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1468 wait_mdt_reint $QTYPE || error "reintegration failed"
1470 # hardlimit should be cleared on slave during reintegration
1471 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1472 quota_error -u $TSTUSR "create failed, expect success"
1474 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1475 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1478 resetquota -u $TSTUSR
1480 run_test 7e "Quota reintegration (inode limits)"
1482 # run dbench with quota enabled
1484 local BLK_LIMIT="100g" #100G
1485 local FILE_LIMIT=1000000
1487 setup_quota_test || error "setup quota failed with $?"
1488 trap cleanup_quota_test EXIT
1490 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1491 set_ost_qtype $QTYPE || error "enable ost quota failed"
1493 echo "Set enough high limit for user: $TSTUSR"
1494 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1495 error "set user quota failed"
1496 echo "Set enough high limit for group: $TSTUSR"
1497 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1498 error "set group quota failed"
1499 if is_project_quota_supported; then
1500 chattr +P $DIR/$tdir && chattr -p $TSTPRJID -d $DIR/$tdir
1501 echo "Set enough high limit for project: $TSTPRJID"
1502 $LFS setquota -p $TSTPRJID -b 0 \
1503 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1504 error "set project quota failed"
1508 [ "$SLOW" = "no" ] && duration=" -t 120"
1509 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1510 quota_error a $TSTUSR "dbench failed!"
1512 is_project_quota_supported && chattr -P $DIR/$tdir &&
1513 chattr -dp 0 $DIR/$tdir
1515 resetquota -u $TSTUSR
1516 resetquota -g $TSTUSR
1517 resetquota -p $TSTPRJID
1519 run_test 8 "Run dbench with quota enabled"
1521 # this check is just for test_9
1522 OST0_MIN=4900000 #4.67G
1524 check_whether_skip () {
1525 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1526 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1527 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1528 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1535 # run for fixing bug10707, it needs a big room. test for 64bit
1537 local filesize=$((1024 * 9 / 2)) # 4.5G
1539 check_whether_skip && return 0
1541 setup_quota_test || error "setup quota failed with $?"
1542 trap cleanup_quota_test EXIT
1544 set_ost_qtype "ug" || error "enable ost quota failed"
1546 local TESTFILE="$DIR/$tdir/$tfile-0"
1547 local BLK_LIMIT=100G #100G
1548 local FILE_LIMIT=1000000
1550 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1552 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1554 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1555 error "set user quota failed"
1557 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1558 "for group: $TSTUSR"
1559 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1560 error "set group quota failed"
1562 quota_show_check a u $TSTUSR
1563 quota_show_check a g $TSTUSR
1565 echo "Create test file"
1566 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1567 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1569 log "Write the big file of 4.5G ..."
1570 $RUNAS $DD of=$TESTFILE count=$filesize ||
1571 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1577 resetquota -u $TSTUSR
1578 resetquota -g $TSTUSR
1583 run_test 9 "Block limit larger than 4GB (b10707)"
1586 local TESTFILE=$DIR/$tdir/$tfile
1588 setup_quota_test || error "setup quota failed with $?"
1589 trap cleanup_quota_test EXIT
1591 # set limit to root user should fail
1592 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1593 error "set limit for root user successfully, expect failure"
1594 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1595 error "set limit for root group successfully, expect failure"
1596 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1597 error "set limit for project 0 successfully, expect failure"
1599 # root user can overrun quota
1600 set_ost_qtype "ug" || error "enable ost quota failed"
1602 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1603 error "set quota failed"
1604 quota_show_check b u $TSTUSR
1606 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1607 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1609 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1610 error "write failure, expect success"
1613 resetquota -u $TSTUSR
1615 run_test 10 "Test quota for root user"
1618 local TESTFILE=$DIR/$tdir/$tfile
1619 setup_quota_test || error "setup quota failed with $?"
1620 trap cleanup_quota_test EXIT
1622 set_mdt_qtype "ug" || error "enable mdt quota failed"
1623 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1624 error "set quota failed"
1626 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1627 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1629 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1630 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1633 local USED=$(getquota -u $TSTUSR global curinodes)
1634 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1637 resetquota -u $TSTUSR
1639 run_test 11 "Chown/chgrp ignores quota"
1642 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1644 local blimit=22 # 22M
1645 local blk_cnt=$((blimit - 5))
1646 local TESTFILE0="$DIR/$tdir/$tfile"-0
1647 local TESTFILE1="$DIR/$tdir/$tfile"-1
1649 setup_quota_test || error "setup quota failed with $?"
1650 trap cleanup_quota_test EXIT
1652 set_ost_qtype "u" || error "enable ost quota failed"
1653 quota_show_check b u $TSTUSR
1655 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1656 error "set quota failed"
1658 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1659 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1660 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1661 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1663 echo "Write to ost0..."
1664 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1665 quota_error a $TSTUSR "dd failed"
1667 echo "Write to ost1..."
1668 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1669 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1671 echo "Free space from ost0..."
1673 wait_delete_completed
1674 sync_all_data || true
1676 echo "Write to ost1 after space freed from ost0..."
1677 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1678 quota_error a $TSTUSR "rebalancing failed"
1681 resetquota -u $TSTUSR
1683 run_test 12a "Block quota rebalancing"
1686 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1688 local ilimit=$((1024 * 2)) # 2k inodes
1689 local TESTFILE0=$DIR/$tdir/$tfile
1690 local TESTFILE1=$DIR/${tdir}-1/$tfile
1692 setup_quota_test || error "setup quota failed with $?"
1693 trap cleanup_quota_test EXIT
1695 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1696 chmod 0777 $DIR/${tdir}-1
1698 set_mdt_qtype "u" || error "enable mdt quota failed"
1699 quota_show_check f u $TSTUSR
1701 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1702 error "set quota failed"
1704 echo "Create $ilimit files on mdt0..."
1705 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1706 quota_error u $TSTUSR "create failed, but expect success"
1708 echo "Create files on mdt1..."
1709 $RUNAS createmany -m $TESTFILE1 1 &&
1710 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1712 echo "Free space from mdt0..."
1713 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1714 wait_delete_completed
1715 sync_all_data || true
1717 echo "Create files on mdt1 after space freed from mdt0..."
1718 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1719 quota_error a $TSTUSR "rebalancing failed"
1721 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1722 error "unlink mdt1 files failed"
1723 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1726 resetquota -u $TSTUSR
1728 run_test 12b "Inode quota rebalancing"
1731 local TESTFILE=$DIR/$tdir/$tfile
1732 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1733 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1735 setup_quota_test || error "setup quota failed with $?"
1736 trap cleanup_quota_test EXIT
1738 set_ost_qtype "u" || error "enable ost quota failed"
1739 quota_show_check b u $TSTUSR
1741 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1742 error "set quota failed"
1743 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1744 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1746 # clear the locks in cache first
1747 do_facet ost1 $LCTL set_param -n $procf=clear
1748 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1749 [ $nlock -eq 0 ] || error "$nlock cached locks"
1751 # write to acquire the per-ID lock
1752 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1753 quota_error a $TSTUSR "dd failed"
1755 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1756 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1758 # clear quota doesn't trigger per-ID lock cancellation
1759 resetquota -u $TSTUSR
1760 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1761 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1763 # clear the per-ID lock
1764 do_facet ost1 $LCTL set_param -n $procf=clear
1765 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1766 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1768 # spare quota should be released
1769 local OSTUUID=$(ostuuid_from_index 0)
1770 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1771 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1772 [ $limit -le $space ] ||
1773 error "spare quota isn't released, limit:$limit, space:$space"
1777 run_test 13 "Cancel per-ID lock in the LRU list"
1780 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1782 wait_delete_completed
1783 sync_all_data || true
1786 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1787 error "set user quota failed"
1788 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1789 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1790 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1791 resetquota -u $TSTUSR
1794 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1795 error "set group quota failed"
1796 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1797 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1798 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1799 resetquota -g $TSTUSR
1801 run_test 15 "Set over 4T block quota"
1805 local BLKS=1 # 1M less than limit
1806 local TESTFILE=$DIR/$tdir/$tfile
1808 setup_quota_test || error "setup quota failed with $?"
1809 trap cleanup_quota_test EXIT
1811 # make sure the system is clean
1812 local USED=$(getquota -u $TSTUSR global curspace)
1813 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1815 set_ost_qtype "ug" || error "enable ost quota failed"
1816 # make sure no granted quota on ost
1817 resetquota -u $TSTUSR
1818 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1819 error "set quota failed"
1821 quota_show_check b u $TSTUSR
1823 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1824 lustre_fail mds 0xa04 $err_code
1826 # write in background
1827 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1831 # write should be blocked and never finished
1832 if ! ps -p $DDPID > /dev/null 2>&1; then
1834 quota_error u $TSTUSR "write finished incorrectly!"
1842 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1844 if [ $count -gt $timeout ]; then
1845 quota_error u $TSTUSR "dd is not finished!"
1850 sync; sync_all_data || true
1852 USED=$(getquota -u $TSTUSR global curspace)
1853 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1854 "Used space(${USED}K) is less than ${BLKS}M"
1857 resetquota -u $TSTUSR
1860 # DQACQ return recoverable error
1862 echo "DQACQ return -ENOLCK"
1864 test_17sub 37 || error "Handle -ENOLCK failed"
1866 echo "DQACQ return -EAGAIN"
1868 test_17sub 11 || error "Handle -EAGAIN failed"
1870 echo "DQACQ return -ETIMEDOUT"
1871 #define ETIMEDOUT 110
1872 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1874 echo "DQACQ return -ENOTCONN"
1875 #define ENOTCONN 107
1876 test_17sub 107 || error "Handle -ENOTCONN failed"
1879 run_test 17 "DQACQ return recoverable error"
1883 local blimit="200m" # 200M
1884 local TESTFILE="$DIR/$tdir/$tfile"
1886 setup_quota_test || error "setup quota failed with $?"
1887 trap cleanup_quota_test EXIT
1889 set_ost_qtype "u" || error "enable ost quota failed"
1890 log "User quota (limit: $blimit)"
1891 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1892 error "set quota failed"
1893 quota_show_check b u $TSTUSR
1895 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1896 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1898 local timeout=$(sysctl -n lustre.timeout)
1900 if [ $io_type = "directio" ]; then
1901 log "Write 100M (directio) ..."
1902 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1904 log "Write 100M (buffered) ..."
1905 $RUNAS $DD of=$TESTFILE count=100 &
1909 replay_barrier $SINGLEMDS
1910 log "Fail mds for $((2 * timeout)) seconds"
1911 fail $SINGLEMDS $((2 * timeout))
1914 if at_is_enabled; then
1915 timeout=$(at_max_get mds)
1917 timeout=$(lctl get_param -n timeout)
1921 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1922 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1923 log "it took $count second"
1928 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1930 cancel_lru_locks mdc
1931 cancel_lru_locks osc
1934 local testfile_size=$(stat -c %s $TESTFILE)
1935 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1936 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1937 "got ${testfile_size}. Verifying file failed!"
1940 resetquota -u $TSTUSR
1943 # test when mds does failover, the ost still could work well
1944 # this test shouldn't trigger watchdog b=14840
1946 # Clear dmesg so watchdog is not triggered by previous
1948 do_facet ost1 dmesg -c > /dev/null
1951 test_18_sub directio
1953 # check if watchdog is triggered
1954 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1955 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1956 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1957 [ -z "$watchdog" ] || error "$watchdog"
1958 rm -f $TMP/lustre-log-${TESTNAME}.log
1960 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1964 local TESTFILE=$DIR/$tdir/$tfile
1966 setup_quota_test || error "setup quota failed with $?"
1967 trap cleanup_quota_test EXIT
1969 set_ost_qtype $QTYPE || error "enable ost quota failed"
1971 # bind file to a single OST
1972 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1973 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1975 echo "Set user quota (limit: ${blimit}M)"
1976 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1977 error "set user quota failed"
1978 quota_show_check b u $TSTUSR
1979 echo "Update quota limits"
1980 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1981 error "set group quota failed"
1982 quota_show_check b u $TSTUSR
1984 # first wirte might be cached
1985 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1986 cancel_lru_locks osc
1988 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1989 quota_error u $TSTUSR "Write success, expect failure"
1993 resetquota -u $TSTUSR
1995 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1997 test_20() { # b15754
1998 local LSTR=(2g 1t 4k 3m) # limits strings
2000 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2003 resetquota -u $TSTUSR
2005 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2006 $MOUNT || error "could not set quota limits"
2007 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2008 --inode-softlimit ${LSTR[2]} \
2009 --inode-hardlimit ${LSTR[3]} \
2010 $MOUNT || error "could not set quota limits"
2012 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2013 error "bsoftlimit was not set properly"
2014 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2015 error "bhardlimit was not set properly"
2016 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2017 error "isoftlimit was not set properly"
2018 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2019 error "ihardlimit was not set properly"
2021 resetquota -u $TSTUSR
2023 run_test 20 "Test if setquota specifiers work properly (b15754)"
2030 local time=$(($(date +%s) + seconds))
2031 while [ $(date +%s) -lt $time ]; do
2032 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2036 # run for fixing bug16053, setquota shouldn't fail when writing and
2037 # deleting are happening
2039 local TESTFILE="$DIR/$tdir/$tfile"
2040 local BLIMIT=10 # 10G
2041 local ILIMIT=1000000
2043 setup_quota_test || error "setup quota failed with $?"
2044 trap cleanup_quota_test EXIT
2046 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2048 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2049 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2050 error "set user quota failed"
2051 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2052 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2053 error "set group quota failed"
2054 if is_project_quota_supported; then
2055 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2056 "project: $TSTPRJID"
2057 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2058 $MOUNT || error "set project quota failed"
2061 # repeat writing on a 1M file
2062 test_21_sub ${TESTFILE}_1 1 30 &
2064 # repeat writing on a 128M file
2065 test_21_sub ${TESTFILE}_2 128 30 &
2068 local time=$(($(date +%s) + 30))
2070 while [ $(date +%s) -lt $time ]; do
2071 log "Set quota for $i times"
2072 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2073 -I $((ILIMIT + i)) $MOUNT ||
2074 error "Set user quota failed"
2075 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2076 -I $((ILIMIT + i)) $MOUNT ||
2077 error "Set group quota failed"
2078 if is_project_quota_supported; then
2079 $LFS setquota -p $TSTPRJID -b 0 -B \
2080 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2081 error "Set project quota failed"
2089 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2091 if [ $count -gt 60 ]; then
2092 quota_error a $TSTUSR "dd should be finished!"
2096 echo "(dd_pid=$DDPID1, time=$count)successful"
2100 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2102 if [ $count -gt 60 ]; then
2103 quota_error a $TSTUSR "dd should be finished!"
2107 echo "(dd_pid=$DDPID2, time=$count)successful"
2110 resetquota -u $TSTUSR
2111 resetquota -g $TSTUSR
2112 resetquota -p $TSTPRJID
2114 run_test 21 "Setquota while writing & deleting (b16053)"
2116 # enable/disable quota enforcement permanently
2118 echo "Set both mdt & ost quota type as ug"
2120 is_project_quota_supported && qtype=$QTYPE
2121 set_mdt_qtype $qtype || error "enable mdt quota failed"
2122 set_ost_qtype $qtype || error "enable ost quota failed"
2125 stopall || error "failed to stopall (1)"
2129 echo "Verify if quota is enabled"
2130 local qtype1=$(mdt_quota_type)
2131 [ $qtype1 != $qtype] && error "mdt quota setting is lost"
2132 qtype=$(ost_quota_type)
2133 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2135 echo "Set both mdt & ost quota type as none"
2136 set_mdt_qtype "none" || error "disable mdt quota failed"
2137 set_ost_qtype "none" || error "disable ost quota failed"
2140 stopall || error "failed to stopall (2)"
2145 echo "Verify if quota is disabled"
2146 qtype=$(mdt_quota_type)
2147 [ $qtype != "none" ] && error "mdt quota setting is lost"
2148 qtype=$(ost_quota_type)
2149 [ $qtype != "none" ] && error "ost quota setting is lost"
2153 run_test 22 "enable/disable quota by 'lctl conf_param'"
2156 local TESTFILE="$DIR/$tdir/$tfile"
2159 setup_quota_test || error "setup quota failed with $?"
2160 trap cleanup_quota_test EXIT
2162 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2165 log "User quota (limit: $LIMIT MB)"
2166 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2167 error "set quota failed"
2168 quota_show_check b u $TSTUSR
2170 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2171 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2173 log "Step1: trigger EDQUOT with O_DIRECT"
2174 log "Write half of file"
2175 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2176 quota_error u $TSTUSR "(1) Write failure, expect success." \
2178 log "Write out of block quota ..."
2179 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2180 oflag=direct conv=notrunc &&
2181 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2185 log "Step2: rewrite should succeed"
2186 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2187 quota_error u $TSTUSR "(3) Write failure, expect success." \
2193 local OST0_UUID=$(ostuuid_from_index 0)
2194 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2195 [ $OST0_QUOTA_USED -ne 0 ] &&
2196 ($SHOW_QUOTA_USER; \
2197 quota_error u $TSTUSR "quota isn't released")
2199 resetquota -u $TSTUSR
2203 [ $(facet_fstype ost1) == "zfs" ] &&
2204 skip "Overwrite in place is not guaranteed to be " \
2205 "space neutral on ZFS" && return
2207 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2208 check_whether_skip && return 0
2209 log "run for 4MB test file"
2212 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2213 check_whether_skip && return 0
2214 log "run for 40MB test file"
2217 run_test 23 "Quota should be honored with directIO (b16125)"
2221 local TESTFILE="$DIR/$tdir/$tfile"
2223 setup_quota_test || error "setup quota failed with $?"
2224 trap cleanup_quota_test EXIT
2226 set_ost_qtype $QTYPE || error "enable ost quota failed"
2228 # bind file to a single OST
2229 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2230 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2232 echo "Set user quota (limit: ${blimit}M)"
2233 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2234 error "set quota failed"
2236 # overrun quota by root user
2237 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2238 error "write failure, expect success"
2239 cancel_lru_locks osc
2240 sync_all_data || true
2242 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2245 resetquota -u $TSTUSR
2247 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2249 test_27a() { # b19612
2250 $LFS quota $TSTUSR $DIR &&
2251 error "lfs succeeded with no type, but should have failed"
2252 $LFS setquota $TSTUSR $DIR &&
2253 error "lfs succeeded with no type, but should have failed"
2256 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2258 test_27b() { # b20200
2259 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2260 error "lfs setquota failed with uid argument"
2261 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2262 error "lfs stequota failed with gid argument"
2263 if is_project_quota_supported; then
2264 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2265 1000 $DIR || error \
2266 "lfs stequota failed with projid argument"
2268 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2269 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2270 if is_project_quota_supported; then
2271 $SHOW_QUOTA_PROJID ||
2272 error "lfs quota failed with projid argument"
2274 resetquota -u $TSTUSR
2275 resetquota -g $TSTUSR
2276 resetquota -p $TSTPRJID
2279 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2284 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2285 error "lfs setquota failed"
2287 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2288 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2289 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2290 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2292 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2293 error "lfs setquota for $TSTID failed"
2295 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2296 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2297 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2298 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2300 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2301 error "total allocated inode/block limit not printed"
2303 resetquota -u $TSTUSR
2305 run_test 27c "lfs quota should support human-readable output"
2312 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2313 error "set fraction block limit failed"
2314 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2315 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2316 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2317 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2319 resetquota -u $TSTUSR
2321 run_test 27d "lfs setquota should support fraction block limit"
2325 local TESTFILE="$DIR/$tdir/$tfile"
2328 setup_quota_test || error "setup quota failed with $?"
2329 trap cleanup_quota_test EXIT
2331 set_ost_qtype "u" || error "enable ost quota failed"
2333 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2334 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2336 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2337 $MAX_IQ_TIME $DIR || error "set grace time failed"
2338 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2339 error "set quota failed"
2340 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2341 cancel_lru_locks osc
2343 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2344 # over-quota flag has not yet settled since we do not trigger async
2345 # events based on grace time period expiration
2347 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2348 cancel_lru_locks osc
2349 # now over-quota flag should be settled and further writes should fail
2351 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2352 error "grace times were reset"
2355 resetquota -u $TSTUSR
2356 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2357 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2359 run_test 30 "Hard limit updates should not reset grace times"
2361 # basic usage tracking for user & group
2363 local INODES=10 # 10 files
2364 local BLK_CNT=2 # of 2M each
2365 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2367 setup_quota_test || error "setup quota failed with $?"
2368 trap cleanup_quota_test EXIT
2370 # make sure the system is clean
2371 local USED=$(getquota -u $TSTID global curspace)
2373 error "Used space ($USED) for user $TSTID isn't 0."
2374 USED=$(getquota -g $TSTID global curspace)
2376 error "Used space ($USED) for group $TSTID isn't 0."
2377 if is_project_quota_supported; then
2378 USED=$(getquota -p $TSTPRJID global curspace)
2379 [ $USED -ne 0 ] && error \
2380 "Used space ($USED) for project $TSTPRJID isn't 0."
2383 echo "Write files..."
2384 for i in $(seq 0 $INODES); do
2385 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2386 error "write failed"
2387 is_project_quota_supported &&
2388 chattr -p $TSTPRJID $DIR/$tdir/$tfile-$i
2389 echo "Iteration $i/$INODES completed"
2391 cancel_lru_locks osc
2392 sync; sync_all_data || true
2394 echo "Verify disk usage after write"
2395 USED=$(getquota -u $TSTID global curspace)
2396 [ $USED -lt $TOTAL_BLKS ] &&
2397 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2398 USED=$(getquota -g $TSTID global curspace)
2399 [ $USED -lt $TOTAL_BLKS ] &&
2400 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2401 if is_project_quota_supported; then
2402 USED=$(getquota -p $TSTPRJID global curspace)
2403 [ $USED -lt $TOTAL_BLKS ] && error \
2404 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2407 echo "Verify inode usage after write"
2408 USED=$(getquota -u $TSTID global curinodes)
2409 [ $USED -lt $INODES ] &&
2410 error "Used inode for user $TSTID is $USED, expected $INODES"
2411 USED=$(getquota -g $TSTID global curinodes)
2412 [ $USED -lt $INODES ] &&
2413 error "Used inode for group $TSTID is $USED, expected $INODES"
2414 if is_project_quota_supported; then
2415 USED=$(getquota -p $TSTPRJID global curinodes)
2416 [ $USED -lt $INODES ] && error \
2417 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2422 echo "Verify disk usage after delete"
2423 USED=$(getquota -u $TSTID global curspace)
2424 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2425 USED=$(getquota -u $TSTID global curinodes)
2426 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2427 USED=$(getquota -g $TSTID global curspace)
2428 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2429 USED=$(getquota -g $TSTID global curinodes)
2430 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2431 if is_project_quota_supported; then
2432 USED=$(getquota -p $TSTPRJID global curinodes)
2434 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2437 run_test 33 "Basic usage tracking for user & group & project"
2439 # usage transfer test for user & group & project
2441 local BLK_CNT=2 # 2MB
2442 local project_supported="no"
2444 is_project_quota_supported && project_supported="yes"
2445 setup_quota_test || error "setup quota failed with $?"
2446 trap cleanup_quota_test EXIT
2448 # make sure the system is clean
2449 local USED=$(getquota -u $TSTID global curspace)
2450 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2451 USED=$(getquota -g $TSTID global curspace)
2452 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2454 local USED=$(getquota -u $TSTID2 global curspace)
2455 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2456 if [ $project_supported == "yes" ]; then
2457 USED=$(getquota -p $TSTPRJID global curspace)
2458 [ $USED -ne 0 ] && error \
2459 "Used space ($USED) for Project $TSTPRJID isn't 0."
2462 echo "Write file..."
2463 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2464 error "write failed"
2465 cancel_lru_locks osc
2466 sync; sync_all_data || true
2468 echo "chown the file to user $TSTID"
2469 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2471 echo "Wait for setattr on objects finished..."
2472 wait_delete_completed
2474 BLK_CNT=$((BLK_CNT * 1024))
2476 echo "Verify disk usage for user $TSTID"
2477 USED=$(getquota -u $TSTID global curspace)
2478 [ $USED -lt $BLK_CNT ] &&
2479 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2480 USED=$(getquota -u $TSTID global curinodes)
2482 error "Used inodes for user $TSTID is $USED, expected 1"
2484 echo "chgrp the file to group $TSTID"
2485 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2487 echo "Wait for setattr on objects finished..."
2488 wait_delete_completed
2490 echo "Verify disk usage for group $TSTID"
2491 USED=$(getquota -g $TSTID global curspace)
2492 [ $USED -ge $BLK_CNT ] ||
2493 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2494 USED=$(getquota -g $TSTID global curinodes)
2496 error "Used inodes for group $TSTID is $USED, expected 1"
2498 # chown won't change the ost object group. LU-4345 */
2499 echo "chown the file to user $TSTID2"
2500 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2502 echo "Wait for setattr on objects finished..."
2503 wait_delete_completed
2505 echo "chattr project id to $TSTPRJID"
2506 [ $project_supported == "yes" ] &&
2507 chattr -p $TSTPRJID $DIR/$tdir/$tfile
2508 echo "Wait for setattr on objects finished..."
2509 wait_delete_completed
2511 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2512 USED=$(getquota -u $TSTID2 global curspace)
2513 [ $USED -lt $BLK_CNT ] &&
2514 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2515 USED=$(getquota -u $TSTID global curspace)
2517 error "Used space for user $TSTID is $USED, expected 0"
2518 USED=$(getquota -g $TSTID global curspace)
2519 [ $USED -lt $BLK_CNT ] &&
2520 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2521 if [ $project_supported == "yes" ]; then
2522 USED=$(getquota -p $TSTPRJID global curspace)
2523 [ $USED -lt $BLK_CNT ] && error \
2524 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2529 run_test 34 "Usage transfer for user & group & project"
2531 # usage is still accessible across restart
2533 local BLK_CNT=2 # 2 MB
2535 setup_quota_test || error "setup quota failed with $?"
2536 trap cleanup_quota_test EXIT
2538 echo "Write file..."
2539 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2540 error "write failed"
2541 is_project_quota_supported &&
2542 chattr -p $TSTPRJID $DIR/$tdir/$tfile
2543 cancel_lru_locks osc
2544 sync; sync_all_data || true
2546 echo "Save disk usage before restart"
2547 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2548 [ $ORIG_USR_SPACE -eq 0 ] &&
2549 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2550 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2551 [ $ORIG_USR_INODES -eq 0 ] &&
2552 error "Used inodes for user $TSTID is 0, expected 1"
2553 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2554 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2555 [ $ORIG_GRP_SPACE -eq 0 ] &&
2556 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2557 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2558 [ $ORIG_GRP_INODES -eq 0 ] &&
2559 error "Used inodes for group $TSTID is 0, expected 1"
2560 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2562 if is_project_quota_supported; then
2563 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2564 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2565 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2566 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2567 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2568 "Used inodes for project $TSTPRJID is 0, expected 1"
2569 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2573 local ORIG_REFORMAT=$REFORMAT
2575 cleanup_and_setup_lustre
2576 REFORMAT=$ORIG_REFORMAT
2579 echo "Verify disk usage after restart"
2580 local USED=$(getquota -u $TSTID global curspace)
2581 [ $USED -eq $ORIG_USR_SPACE ] ||
2582 error "Used space for user $TSTID changed from " \
2583 "$ORIG_USR_SPACE to $USED"
2584 USED=$(getquota -u $TSTID global curinodes)
2585 [ $USED -eq $ORIG_USR_INODES ] ||
2586 error "Used inodes for user $TSTID changed from " \
2587 "$ORIG_USR_INODES to $USED"
2588 USED=$(getquota -g $TSTID global curspace)
2589 [ $USED -eq $ORIG_GRP_SPACE ] ||
2590 error "Used space for group $TSTID changed from " \
2591 "$ORIG_GRP_SPACE to $USED"
2592 USED=$(getquota -g $TSTID global curinodes)
2593 [ $USED -eq $ORIG_GRP_INODES ] ||
2594 error "Used inodes for group $TSTID changed from " \
2595 "$ORIG_GRP_INODES to $USED"
2596 if [ $project_supported == "yes" ]; then
2597 USED=$(getquota -p $TSTPRJID global curinodes)
2598 [ $USED -eq $ORIG_PRJ_INODES ] ||
2599 error "Used inodes for project $TSTPRJID " \
2600 "changed from $ORIG_PRJ_INODES to $USED"
2601 USED=$(getquota -p $TSTPRJID global curspace)
2602 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2603 error "Used space for project $TSTPRJID "\
2604 "changed from $ORIG_PRJ_SPACE to $USED"
2607 # check if the vfs_dq_init() is called before writing
2608 echo "Append to the same file..."
2609 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2610 error "write failed"
2611 cancel_lru_locks osc
2612 sync; sync_all_data || true
2614 echo "Verify space usage is increased"
2615 USED=$(getquota -u $TSTID global curspace)
2616 [ $USED -gt $ORIG_USR_SPACE ] ||
2617 error "Used space for user $TSTID isn't increased" \
2618 "orig:$ORIG_USR_SPACE, now:$USED"
2619 USED=$(getquota -g $TSTID global curspace)
2620 [ $USED -gt $ORIG_GRP_SPACE ] ||
2621 error "Used space for group $TSTID isn't increased" \
2622 "orig:$ORIG_GRP_SPACE, now:$USED"
2623 if [ $project_supported == "yes" ]; then
2624 USED=$(getquota -p $TSTPRJID global curspace)
2625 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2626 error "Used space for project $TSTPRJID isn't " \
2627 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2632 run_test 35 "Usage is still accessible across reboot"
2634 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2637 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2638 skip "Old server doesn't have LU-5006 fix." && return
2640 setup_quota_test || error "setup quota failed with $?"
2641 trap cleanup_quota_test EXIT
2643 # make sure the system is clean
2644 local USED=$(getquota -u $TSTID global curspace)
2646 error "Used space ($USED) for user $TSTID isn't 0."
2648 # create file with MDS_OPEN_DELAY_CREATE flag
2649 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2650 error "Create file failed"
2652 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2653 oflag=sync || error "Write file failed"
2655 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2657 # wait for setattr on objects finished..."
2658 wait_delete_completed
2660 USED=$(getquota -u $TSTID global curspace)
2661 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2665 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2669 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2670 skip "Old server doesn't have LU-8801 fix." && return
2672 [ "$UID" != 0 ] && skip_env "must run as root" && return
2674 setup_quota_test || error "setup quota failed with $?"
2675 trap cleanup_quota_test EXIT
2677 # make sure the system is clean
2678 local USED=$(getquota -u $TSTID global curspace)
2680 error "Used space ($USED) for user $TSTID isn't 0."
2681 USED=$(getquota -u $TSTID2 global curspace)
2683 error "Used space ($USED) for user $TSTID2 isn't 0."
2685 local TESTFILE="$DIR/$tdir/$tfile"
2686 local file_cnt=10000
2688 # Generate id entries in accounting file
2689 echo "Create $file_cnt files..."
2690 for i in `seq $file_cnt`; do
2692 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i
2694 cancel_lru_locks osc
2695 sync; sync_all_data || true
2697 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2698 procf=${procf}.quota_slave.acct_user
2701 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
2702 echo "Found $acct_cnt id entries"
2704 [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
2708 run_test 38 "Quota accounting iterator doesn't skip id entries"
2711 local TESTFILE="$DIR/$tdir/project"
2712 ! is_project_quota_supported &&
2713 skip "Project quota is not supported" && return 0
2715 setup_quota_test || error "setup quota failed with $?"
2718 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2719 [ $projectid -ne 0 ] &&
2720 error "Project id should be 0 not $projectid"
2721 chattr -p 1024 $TESTFILE
2722 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2723 [ $projectid -ne 1024 ] &&
2724 error "Project id should be 1024 not $projectid"
2726 stopall || error "failed to stopall (1)"
2729 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2730 [ $projectid -ne 1024 ] &&
2731 error "Project id should be 1024 not $projectid"
2735 run_test 39 "Project ID interface works correctly"
2738 ! is_project_quota_supported &&
2739 skip "Project quota is not supported" && return 0
2740 local dir1="$DIR/$tdir/dir1"
2741 local dir2="$DIR/$tdir/dir2"
2743 setup_quota_test || error "setup quota failed with $?"
2745 mkdir -p $dir1 $dir2
2746 chattr +P $dir1 && chattr -p 1 -d $dir1 && touch $dir1/1
2747 chattr +P $dir2 && chattr -p 2 -d $dir2
2749 ln $dir1/1 $dir2/1_link &&
2750 error "Hard link across different project quota should fail"
2755 run_test 40a "Hard link across different project ID"
2758 ! is_project_quota_supported &&
2759 skip "Project quota is not supported" && return 0
2760 local dir1="$DIR/$tdir/dir1"
2761 local dir2="$DIR/$tdir/dir2"
2763 setup_quota_test || error "setup quota failed with $?"
2764 mkdir -p $dir1 $dir2
2765 chattr +P $dir1 && chattr -p 1 -d $dir1 && touch $dir1/1
2766 chattr +P $dir2 && chattr -p 2 -d $dir2
2768 mv $dir1/1 $dir2/2 || error "mv failed $?"
2769 local projid=$(lsattr -p $dir2/2 | awk '{print $1}')
2770 if [ "$projid" != "2" ]; then
2771 error "project id expected 2 not $projid"
2776 run_test 40b "Mv across different project ID"
2779 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
2780 ! is_project_quota_supported &&
2781 skip "Project quota is not supported" && return 0
2783 setup_quota_test || error "setup quota failed with $?"
2784 local dir="$DIR/$tdir/dir"
2786 mkdir -p $dir && chattr +P $dir && chattr -dp 1 $dir
2787 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2788 local projid=$(lsattr -dp $dir/remote_dir | awk '{print $1}')
2789 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2790 touch $dir/remote_dir/file
2791 #verify inherit works file for remote dir.
2792 local projid=$(lsattr -dp $dir/remote_dir/file | awk '{print $1}')
2793 [ "$projid" != "1" ] &&
2794 error "file under remote dir expected 1 not $projid"
2796 #Agent inode should be ignored for project quota
2797 USED=$(getquota -p 1 global curinodes)
2798 [ "$USED" != "3" ] &&
2799 error "file count expected 3 got $USED"
2805 run_test 40c "Remote child Dir inherit project quota properly"
2808 ! is_project_quota_supported &&
2809 skip "Project quota is not supported" && return 0
2811 setup_quota_test || error "setup quota failed with $?"
2812 local dir="$DIR/$tdir/dir"
2814 mkdir $dir && chattr -dp 1 $dir
2815 count=$($LFS find --projid 1 $DIR | wc -l)
2816 [ "$count" != 1 ] && error "expected 1 but got $count"
2821 run_test 50 "Test if lfs find --projid works"
2824 ! is_project_quota_supported &&
2825 skip "Project quota is not supported" && return 0
2826 setup_quota_test || error "setup quota failed with $?"
2827 local dir="$DIR/$tdir/dir"
2829 mkdir $dir && chattr -dp 1 $dir && chattr +P $dir
2830 local used=$(getquota -p 1 global curinodes)
2831 [ $used != "1" ] && error "expected 1 got $used"
2836 used=$(getquota -p 1 global curinodes)
2837 [ $used != "4" ] && error "expected 4 got $used"
2839 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2841 cp $DIR/$tdir/6 $dir/6
2842 used=$(getquota -p 1 global curinodes)
2843 [ $used != "5" ] && error "expected 5 got $used"
2846 mv $DIR/$tdir/6 $dir/7
2847 used=$(getquota -p 1 global curinodes)
2848 [ $used != "6" ] && error "expected 6 got $used"
2853 run_test 51 "Test project accounting with mv/cp"
2856 ! is_project_quota_supported &&
2857 skip "Project quota is not supported" && return 0
2858 setup_quota_test || error "setup quota failed with $?"
2859 local dir="$DIR/$tdir/dir"
2860 mkdir $dir && chattr -dp 1 $dir && chattr +P $dir
2862 touch $DIR/$tdir/file
2863 #Try renaming a file into the project. This should fail.
2864 for num in $(seq 1 2000); do
2865 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2866 error "rename should fail"
2871 run_test 52 "Rename across different project ID"
2875 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2876 disable_project_quota
2882 check_and_cleanup_lustre
2883 export QUOTA_AUTO=$QUOTA_AUTO_OLD