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: LU-5152
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
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}
39 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
41 require_dsh_mds || exit 0
42 require_dsh_ost || exit 0
44 # Does e2fsprogs support quota feature?
45 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
46 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
47 grep -q 'quota'"; then
48 skip_env "e2fsprogs doesn't support quota" && exit 0
51 # Test duration: 30 min
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test:
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
59 # Test duration: 21 9 min"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
77 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
78 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
79 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
80 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
81 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
82 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
83 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
84 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
91 local fail_val=${3:-0}
95 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
96 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
97 ost) NODES="$(comma_list $(osts_nodes))";;
100 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
105 echo "lfs project $*"
106 lfs project $* || error "lfs project $* failed"
109 RUNAS="runas -u $TSTID -g $TSTID"
110 RUNAS2="runas -u $TSTID2 -g $TSTID2"
111 DD="dd if=/dev/zero bs=1M"
115 # clear quota limits for a user or a group
116 # usage: resetquota -u username
117 # resetquota -g groupname
118 # resetquota -p projid
121 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
122 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
123 error "resetquota: wrong specifier $1 passed"
125 if [ $1 == "-p" ]; then
126 is_project_quota_supported || return 0
129 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
130 error "clear quota for [type:$1 name:$2] failed"
131 # give a chance to slave to release space
139 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
140 $LFS quota -v -u $local_id $DIR
141 log "Files for user ($local_id):"
142 ($LFS find --user $local_id $DIR | head -n 4 |
143 xargs stat 2>/dev/null)
146 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
147 $LFS quota -v -g $local_id $DIR
148 log "Files for group ($local_id):"
149 ($LFS find --group $local_id $DIR | head -n 4 |
150 xargs stat 2>/dev/null)
153 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
154 $LFS quota -v -p $TSTPRJID $DIR
155 log "Files for project ($TSTPRJID):"
156 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
157 xargs stat 2>/dev/null)
173 # get quota for a user or a group
174 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
175 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
180 sync_all_data > /dev/null 2>&1 || true
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)
218 if [[ $PERM_CMD == *"set_param -P"* ]]; then
219 do_facet mgs $PERM_CMD \
220 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
222 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
224 # we have to make sure each MDT received config changes
225 for mdt in ${mdts//,/ }; do
227 cmd="$LCTL get_param -n "
228 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
229 cmd=${cmd}.quota_slave.enabled
231 if $(facet_up $mdt); then
232 wait_update_facet $mdt "$cmd" "$qtype" || return 1
239 # usage: set_ost_qtype ugp|u|g|p|none
243 local osts=$(get_facets OST)
245 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
246 qtype=$(tr -d 'p' <<<$qtype)
248 if [[ $PERM_CMD == *"set_param -P"* ]]; then
249 do_facet mgs $PERM_CMD \
250 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
252 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
254 # we have to make sure each OST received config changes
255 for ost in ${osts//,/ }; do
257 cmd="$LCTL get_param -n "
258 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
259 cmd=${cmd}.quota_slave.enabled
261 if $(facet_up $ost); then
262 wait_update_facet $ost "$cmd" "$qtype" || return 1
268 wait_reintegration() {
272 local result="glb[1],slv[1],reint[0]"
277 if [ $ntype == "mdt" ]; then
278 tgts=$(get_facets MDS)
280 tgts=$(get_facets OST)
283 for tgt in ${tgts//,/ }; do
285 cmd="$LCTL get_param -n "
286 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
287 cmd=${cmd}.quota_slave.info
289 if $(facet_up $tgt); then
290 wait_update_facet $tgt "$cmd |
291 grep "$qtype" | awk '{ print \\\$3 }'" \
292 "$result" $max || return 1
302 if [[ "$qtype" =~ "u" ]]; then
303 wait_reintegration "mdt" "user" $max || return 1
306 if [[ "$qtype" =~ "g" ]]; then
307 wait_reintegration "mdt" "group" $max || return 1
310 if [[ "$qtype" =~ "p" ]]; then
311 ! is_project_quota_supported && return 0
312 wait_reintegration "mdt" "project" $max || return 1
321 if [[ "$qtype" =~ "u" ]]; then
322 wait_reintegration "ost" "user" $max || return 1
325 if [[ "$qtype" =~ "g" ]]; then
326 wait_reintegration "ost" "group" $max || return 1
329 if [[ "$qtype" =~ "p" ]]; then
330 ! is_project_quota_supported && return 0
331 wait_reintegration "ost" "project" $max || return 1
337 wait_delete_completed
338 echo "Creating test directory"
339 mkdir $DIR/$tdir || return 1
340 chmod 0777 $DIR/$tdir || return 2
341 # always clear fail_loc in case of fail_loc isn't cleared
342 # properly when previous test failed
343 lustre_fail mds_ost 0
346 cleanup_quota_test() {
348 echo "Delete files..."
350 echo "Wait for unlink objects finished..."
351 wait_delete_completed
352 sync_all_data || true
362 $LFS quota -v -$ugp $qid $DIR
364 if [ "$bf" == "a" -o "$bf" == "b" ]; then
365 usage=$(getquota -$ugp $qid global curspace)
366 if [ -z $usage ]; then
367 quota_error $ugp $qid \
368 "Query block quota failed ($ugp:$qid)."
370 [ $usage -ne 0 ] && quota_log $ugp $qid \
371 "Block quota isn't 0 ($ugp:$qid:$usage)."
375 if [ "$bf" == "a" -o "$bf" == "f" ]; then
376 usage=$(getquota -$ugp $qid global curinodes)
377 if [ -z $usage ]; then
378 quota_error $ugp $qid \
379 "Query file quota failed ($ugp:$qid)."
381 [ $usage -ne 0 ] && quota_log $ugp $qid \
382 "File quota isn't 0 ($ugp:$qid:$usage)."
387 project_quota_enabled () {
389 for num in $(seq $MDSCOUNT); do
390 do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
391 grep -q project || rc=1
393 for num in $(seq $OSTCOUNT); do
394 do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
395 grep -q project || rc=1
397 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
401 project_quota_enabled || enable_project_quota
403 reset_quota_settings() {
404 resetquota -u $TSTUSR
405 resetquota -g $TSTUSR
406 resetquota -u $TSTUSR2
407 resetquota -g $TSTUSR2
408 resetquota -p $TSTPRJID
413 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
418 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
419 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
420 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
421 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
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"
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
467 run_test 0 "Test basic quota performance"
469 # test block hardlimit
472 local TESTFILE="$DIR/$tdir/$tfile-0"
474 setup_quota_test || error "setup quota failed with $?"
475 trap cleanup_quota_test EXIT
478 set_ost_qtype $QTYPE || error "enable ost quota failed"
481 log "User quota (block hardlimit:$LIMIT MB)"
482 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
483 error "set user quota failed"
485 # make sure the system is clean
486 local USED=$(getquota -u $TSTUSR global curspace)
487 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
489 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
490 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
493 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
494 quota_error u $TSTUSR "user write failure, but expect success"
495 log "Write out of block quota ..."
496 # this time maybe cache write, ignore it's failure
497 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
498 # flush cache, ensure noquota flag is set on client
500 sync; sync_all_data || true
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 $LFS 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 sync; sync_all_data || true
534 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
535 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
537 wait_delete_completed || error "wait_delete_completed failed"
538 sync_all_data || true
539 USED=$(getquota -g $TSTUSR global curspace)
540 [ $USED -ne 0 ] && quota_error g $TSTUSR \
541 "Group quota isn't released after deletion"
542 resetquota -g $TSTUSR
544 if ! is_project_quota_supported; then
545 echo "Project quota is not supported"
550 TESTFILE="$DIR/$tdir/$tfile-2"
551 # make sure the system is clean
552 USED=$(getquota -p $TSTPRJID global curspace)
554 error "used space($USED) for project $TSTPRJID isn't 0"
557 log "--------------------------------------"
558 log "Project quota (block hardlimit:$LIMIT mb)"
559 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
560 error "set project quota failed"
562 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
563 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
564 change_project -p $TSTPRJID $TESTFILE
567 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
568 "project write failure, but expect success"
569 log "write out of block quota ..."
570 # this time maybe cache write, ignore it's failure
571 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
573 sync; sync_all_data || true
574 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
575 $TSTPRJID "project write success, but expect EDQUOT"
580 USED=$(getquota -p $TSTPRJID global curspace)
581 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
582 "project quota isn't released after deletion"
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"
598 setup_quota_test || error "setup quota failed with $?"
599 trap cleanup_quota_test EXIT
602 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
605 log "User quota (inode hardlimit:$LIMIT files)"
606 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
607 error "set user quota failed"
609 # make sure the system is clean
610 local USED=$(getquota -u $TSTUSR global curinodes)
611 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
613 log "Create $LIMIT files ..."
614 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
615 quota_error u $TSTUSR "user create failure, but expect success"
616 log "Create out of file quota ..."
617 $RUNAS touch ${TESTFILE}_xxx &&
618 quota_error u $TSTUSR "user create success, but expect EDQUOT"
621 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
622 rm -f ${TESTFILE}_xxx
623 wait_delete_completed
625 USED=$(getquota -u $TSTUSR global curinodes)
626 [ $USED -ne 0 ] && quota_error u $TSTUSR \
627 "user quota isn't released after deletion"
628 resetquota -u $TSTUSR
631 log "--------------------------------------"
632 log "Group quota (inode hardlimit:$LIMIT files)"
633 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
634 error "set group quota failed"
636 TESTFILE=$DIR/$tdir/$tfile-1
637 # make sure the system is clean
638 USED=$(getquota -g $TSTUSR global curinodes)
639 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
641 log "Create $LIMIT files ..."
642 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
643 quota_error g $TSTUSR "group create failure, but expect success"
644 log "Create out of file quota ..."
645 $RUNAS touch ${TESTFILE}_xxx &&
646 quota_error g $TSTUSR "group create success, but expect EDQUOT"
649 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
650 rm -f ${TESTFILE}_xxx
651 wait_delete_completed
653 USED=$(getquota -g $TSTUSR global curinodes)
654 [ $USED -ne 0 ] && quota_error g $TSTUSR \
655 "user quota isn't released after deletion"
657 resetquota -g $TSTUSR
658 ! is_project_quota_supported && cleanup_quota_test &&
659 echo "Skip project quota is not supported" && return 0
662 log "--------------------------------------"
663 log "Project quota (inode hardlimit:$LIMIT files)"
664 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
665 error "set project quota failed"
667 TESTFILE=$DIR/$tdir/$tfile-1
668 # make sure the system is clean
669 USED=$(getquota -p $TSTPRJID global curinodes)
671 error "Used inodes($USED) for project $TSTPRJID isn't 0"
673 change_project -sp $TSTPRJID $DIR/$tdir
674 log "Create $LIMIT files ..."
675 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
676 $TSTPRJID "project create fail, but expect success"
677 log "Create out of file quota ..."
678 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
679 "project create success, but expect EDQUOT"
680 change_project -C $DIR/$tdir
683 USED=$(getquota -p $TSTPRJID global curinodes)
684 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
685 "project quota isn't released after deletion"
688 run_test 2 "File hard limit (normal use and out of quota)"
692 local TIMER=$(($2 * 3 / 2))
698 trap cleanup_quota_test EXIT
700 $LFS setstripe $TESTFILE -c 1 -i 0
701 chown $TSTUSR.$TSTUSR $TESTFILE
702 [ "$qtype" == "p" ] && is_project_quota_supported &&
703 change_project -p $TSTPRJID $TESTFILE
705 echo "Write up to soft limit"
706 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
707 quota_error a $TSTUSR "write failure, but expect success"
708 OFFSET=$((LIMIT * 1024))
711 echo "Write to exceed soft limit"
712 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
713 quota_error a $TSTUSR "write failure, but expect success"
714 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
720 $SHOW_QUOTA_INFO_USER
721 $SHOW_QUOTA_INFO_GROUP
722 $SHOW_QUOTA_INFO_PROJID
724 echo "Write before timer goes off"
725 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
726 quota_error a $TSTUSR "write failure, but expect success"
727 OFFSET=$((OFFSET + 1024))
730 echo "Sleep $TIMER seconds ..."
736 $SHOW_QUOTA_INFO_USER
737 $SHOW_QUOTA_INFO_GROUP
738 $SHOW_QUOTA_INFO_PROJID
740 echo "Write after timer goes off"
741 # maybe cache write, ignore.
742 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
743 OFFSET=$((OFFSET + 1024))
745 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
746 quota_error a $TSTUSR "write success, but expect EDQUOT"
751 $SHOW_QUOTA_INFO_USER
752 $SHOW_QUOTA_INFO_GROUP
753 $SHOW_QUOTA_INFO_PROJID
755 echo "Unlink file to stop timer"
757 wait_delete_completed
758 sync_all_data || true
763 $SHOW_QUOTA_INFO_USER
764 $SHOW_QUOTA_INFO_GROUP
765 $SHOW_QUOTA_INFO_PROJID
767 $LFS setstripe $TESTFILE -c 1 -i 0
768 chown $TSTUSR.$TSTUSR $TESTFILE
769 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
772 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
773 quota_error a $TSTUSR "write failure, but expect success"
782 local TESTFILE=$DIR/$tdir/$tfile-0
784 set_ost_qtype $QTYPE || error "enable ost quota failed"
786 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
787 # make sure the system is clean
788 local USED=$(getquota -u $TSTUSR global curspace)
789 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
791 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
792 $MAX_IQ_TIME $DIR || error "set user grace time failed"
793 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
794 error "set user quota failed"
796 test_block_soft $TESTFILE $GRACE $LIMIT "u"
798 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
799 TESTFILE=$DIR/$tdir/$tfile-1
800 # make sure the system is clean
801 USED=$(getquota -g $TSTUSR global curspace)
802 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
804 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
805 $MAX_IQ_TIME $DIR || error "set group grace time failed"
806 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
807 error "set group quota failed"
809 test_block_soft $TESTFILE $GRACE $LIMIT "g"
811 if is_project_quota_supported; then
812 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
813 TESTFILE=$DIR/$tdir/$tfile-2
814 # make sure the system is clean
815 USED=$(getquota -p $TSTPRJID global curspace)
816 [ $USED -ne 0 ] && error \
817 "Used space($USED) for project $TSTPRJID isn't 0."
819 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
821 error "set project grace time failed"
822 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
823 $DIR || error "set project quota failed"
825 test_block_soft $TESTFILE $GRACE $LIMIT "p"
826 resetquota -p $TSTPRJID
827 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
829 error "restore project grace time failed"
833 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
834 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
835 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
836 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
838 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
844 local TIMER=$(($grace * 3 / 2))
847 trap cleanup_quota_test EXIT
848 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
850 echo "Create files to exceed soft limit"
851 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
852 quota_error a $TSTUSR "create failure, but expect success"
853 local trigger_time=$(date +%s)
855 sync_all_data || true
857 local cur_time=$(date +%s)
858 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
859 error "Passed grace time $grace, $trigger_time, $cur_time"
861 echo "Create file before timer goes off"
862 $RUNAS touch ${TESTFILE}_before ||
863 quota_error a $TSTUSR "failed create before timer expired," \
864 "but expect success. $trigger_time, $cur_time"
865 sync_all_data || true
867 echo "Sleep $TIMER seconds ..."
873 $SHOW_QUOTA_INFO_USER
874 $SHOW_QUOTA_INFO_GROUP
875 $SHOW_QUOTA_INFO_PROJID
877 echo "Create file after timer goes off"
878 # There is a window that space is accounted in the quota usage but
879 # hasn't been decreased from the pending write, if we acquire quota
880 # in this window, we'll acquire more than we needed.
881 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
882 sync_all_data || true
883 $RUNAS touch ${TESTFILE}_after_3 &&
884 quota_error a $TSTUSR "create after timer expired," \
886 sync_all_data || true
891 $SHOW_QUOTA_INFO_USER
892 $SHOW_QUOTA_INFO_GROUP
893 $SHOW_QUOTA_INFO_PROJID
895 echo "Unlink files to stop timer"
896 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
897 wait_delete_completed
900 $RUNAS touch ${TESTFILE}_xxx ||
901 quota_error a $TSTUSR "touch after timer stop failure," \
903 sync_all_data || true
911 local LIMIT=10 # inodes
912 local TESTFILE=$DIR/$tdir/$tfile-0
915 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
917 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
918 # make sure the system is clean
919 local USED=$(getquota -u $TSTUSR global curinodes)
920 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
922 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
923 $GRACE $DIR || error "set user grace time failed"
924 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
925 error "set user quota failed"
927 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && GRACE=20
929 test_file_soft $TESTFILE $LIMIT $GRACE
931 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
932 # make sure the system is clean
933 USED=$(getquota -g $TSTUSR global curinodes)
934 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
936 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
937 $GRACE $DIR || error "set group grace time failed"
938 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
939 error "set group quota failed"
940 TESTFILE=$DIR/$tdir/$tfile-1
942 test_file_soft $TESTFILE $LIMIT $GRACE
944 if is_project_quota_supported; then
945 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
946 # make sure the system is clean
947 USED=$(getquota -p $TSTPRJID global curinodes)
948 [ $USED -ne 0 ] && error \
949 "Used space($USED) for project $TSTPRJID isn't 0."
951 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
952 $GRACE $DIR || error "set project grace time failed"
953 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
954 error "set project quota failed"
956 TESTFILE=$DIR/$tdir/$tfile-1
957 # one less than limit, because of parent directory included.
958 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
959 resetquota -p $TSTPRJID
960 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
962 error "restore project grace time failed"
966 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
967 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
968 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
969 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
971 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
975 local GR_STR2="1000s"
977 local GR_STR4="1w2d3h4m5s"
979 local GR_STR6="18446744073709551615"
982 wait_delete_completed
984 # test of valid grace strings handling
985 echo "Valid grace strings test"
986 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
987 $GR_STR2 $DIR || error "set user grace time failed"
988 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
989 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
990 $GR_STR4 $DIR || error "set group grace time quota failed"
991 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
993 # test of invalid grace strings handling
994 echo " Invalid grace strings test"
995 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
996 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
997 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1001 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1002 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1003 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1004 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1006 run_test 4b "Grace time strings handling"
1008 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1010 local BLIMIT=10 # 10M
1011 local ILIMIT=10 # 10 inodes
1013 setup_quota_test || error "setup quota failed with $?"
1014 trap cleanup_quota_test EXIT
1016 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1017 set_ost_qtype $QTYPE || error "enable ost quota failed"
1019 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1020 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1021 error "set user quota failed"
1022 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1023 if is_project_quota_supported; then
1024 error "set group quota failed"
1025 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1026 -I $ILIMIT $DIR || error "set project quota failed"
1029 # make sure the system is clean
1030 local USED=$(getquota -u $TSTUSR global curinodes)
1031 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1032 USED=$(getquota -g $TSTUSR global curinodes)
1033 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1034 USED=$(getquota -u $TSTUSR global curspace)
1035 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1036 USED=$(getquota -g $TSTUSR global curspace)
1037 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1038 if is_project_quota_supported; then
1039 USED=$(getquota -p $TSTPRJID global curinodes)
1041 error "Used inode($USED) for project $TSTPRJID isn't 0."
1042 USED=$(getquota -p $TSTPRJID global curspace)
1044 error "Used block($USED) for project $TSTPRJID isn't 0."
1047 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1048 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1049 error "create failure, expect success"
1050 if is_project_quota_supported; then
1051 touch $DIR/$tdir/$tfile-0_1
1052 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1054 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1055 error "write failure, expect success"
1057 echo "Chown files to $TSTUSR.$TSTUSR ..."
1058 for i in $(seq 0 $ILIMIT); do
1059 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1060 quota_error a $TSTUSR "chown failure, expect success"
1064 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1065 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1068 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1070 # test dropping acquire request on master
1074 # Clear dmesg so watchdog is not triggered by previous
1076 do_facet ost1 dmesg -c > /dev/null
1078 setup_quota_test || error "setup quota failed with $?"
1079 trap cleanup_quota_test EXIT
1081 # make sure the system is clean
1082 local USED=$(getquota -u $TSTUSR global curspace)
1083 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1085 # make sure no granted quota on ost
1086 set_ost_qtype $QTYPE || error "enable ost quota failed"
1087 resetquota -u $TSTUSR
1089 # create file for $TSTUSR
1090 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1091 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1092 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1094 # create file for $TSTUSR2
1095 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1096 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1097 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1099 # cache per-ID lock for $TSTUSR on slave
1100 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1101 error "set quota failed"
1102 $RUNAS $DD of=$TESTFILE count=1 ||
1103 error "write $TESTFILE failure, expect success"
1104 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1105 error "write $TESTFILE2 failure, expect success"
1107 sync_all_data || true
1109 #define QUOTA_DQACQ 601
1110 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1111 lustre_fail mds 0x513 601
1113 do_facet ost1 $LCTL set_param \
1114 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1116 # write to un-enforced ID ($TSTUSR2) should succeed
1117 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1118 error "write failure, expect success"
1120 # write to enforced ID ($TSTUSR) in background, exceeding limit
1121 # to make sure DQACQ is sent
1122 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1125 # watchdog timer uses a factor of 2
1126 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1127 sleep $((TIMEOUT * 2 + 1))
1129 # write should be blocked and never finished
1130 if ! ps -p $DDPID > /dev/null 2>&1; then
1132 error "write finished incorrectly!"
1137 # no watchdog is triggered
1138 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1139 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1140 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1141 [ -z "$watchdog" ] || error "$watchdog"
1143 rm -f $TMP/lustre-log-${TESTNAME}.log
1145 # write should continue then fail with EDQUOT
1149 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1150 if [ $count -ge 240 ]; then
1151 quota_error u $TSTUSR "dd not finished in $count secs"
1153 count=$((count + 1))
1154 if [ $((count % 30)) -eq 0 ]; then
1155 c_size=$(stat -c %s $TESTFILE)
1156 echo "Waiting $count secs. $c_size"
1164 run_test 6 "Test dropping acquire request on master"
1166 # quota reintegration (global index)
1168 local TESTFILE=$DIR/$tdir/$tfile
1169 local LIMIT=20 # 20M
1171 [ "$SLOW" = "no" ] && LIMIT=5
1173 setup_quota_test || error "setup quota failed with $?"
1174 trap cleanup_quota_test EXIT
1176 # make sure the system is clean
1177 local USED=$(getquota -u $TSTUSR global curspace)
1178 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1180 # make sure no granted quota on ost1
1181 set_ost_qtype $QTYPE || error "enable ost quota failed"
1182 resetquota -u $TSTUSR
1183 set_ost_qtype "none" || error "disable ost quota failed"
1185 local OSTUUID=$(ostuuid_from_index 0)
1186 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1188 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1191 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1192 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1197 echo "Enable quota & set quota limit for $TSTUSR"
1198 set_ost_qtype $QTYPE || error "enable ost quota failed"
1199 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1200 error "set quota failed"
1202 echo "Start ost1..."
1203 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1206 wait_ost_reint $QTYPE || error "reintegration failed"
1208 # hardlimit should have been fetched by slave during global
1209 # reintegration, write will exceed quota
1210 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1211 quota_error u $TSTUSR "write success, but expect EDQUOT"
1214 wait_delete_completed
1215 sync_all_data || true
1221 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1222 error "clear quota failed"
1224 echo "Start ost1..."
1225 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1228 wait_ost_reint $QTYPE || error "reintegration failed"
1230 # hardlimit should be cleared on slave during reintegration
1231 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1232 quota_error u $TSTUSR "write error, but expect success"
1236 run_test 7a "Quota reintegration (global index)"
1238 # quota reintegration (slave index)
1241 local TESTFILE=$DIR/$tdir/$tfile
1243 setup_quota_test || error "setup quota failed with $?"
1244 trap cleanup_quota_test EXIT
1246 # make sure the system is clean
1247 local USED=$(getquota -u $TSTUSR global curspace)
1248 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1250 # make sure no granted quota on ost1
1251 set_ost_qtype $QTYPE || error "enable ost quota failed"
1252 resetquota -u $TSTUSR
1253 set_ost_qtype "none" || error "disable ost quota failed"
1255 local OSTUUID=$(ostuuid_from_index 0)
1256 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1258 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1261 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1262 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1264 # consume some space to make sure the granted space will not
1265 # be released during reconciliation
1266 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1267 error "consume space failure, expect success"
1269 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1270 lustre_fail mds 0xa02
1272 set_ost_qtype $QTYPE || error "enable ost quota failed"
1273 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1274 error "set quota failed"
1276 # ignore the write error
1277 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1279 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1283 echo "Restart ost to trigger reintegration..."
1285 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1288 wait_ost_reint $QTYPE || error "reintegration failed"
1290 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1291 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1296 run_test 7b "Quota reintegration (slave index)"
1298 # quota reintegration (restart mds during reintegration)
1300 local LIMIT=20 # 20M
1301 local TESTFILE=$DIR/$tdir/$tfile
1303 [ "$SLOW" = "no" ] && LIMIT=5
1305 setup_quota_test || error "setup quota failed with $?"
1306 trap cleanup_quota_test EXIT
1308 # make sure the system is clean
1309 local USED=$(getquota -u $TSTUSR global curspace)
1310 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1312 set_ost_qtype "none" || error "disable ost quota failed"
1313 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1314 error "set quota failed"
1316 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1317 lustre_fail ost 0xa03
1320 set_ost_qtype $QTYPE || error "enable ost quota failed"
1321 # trigger reintegration
1322 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1323 procf=${procf}quota_slave.force_reint
1324 do_facet ost1 $LCTL set_param $procf=1 ||
1325 error "force reintegration failed"
1333 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1336 # wait longer than usual to make sure the reintegration
1337 # is triggered by quota wb thread.
1338 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1340 # hardlimit should have been fetched by slave during global
1341 # reintegration, write will exceed quota
1342 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1343 quota_error u $TSTUSR "write success, but expect EDQUOT"
1347 run_test 7c "Quota reintegration (restart mds during reintegration)"
1349 # Quota reintegration (Transfer index in multiple bulks)
1351 local TESTFILE=$DIR/$tdir/$tfile
1352 local TESTFILE1="$DIR/$tdir/$tfile"-1
1355 setup_quota_test || error "setup quota failed with $?"
1356 trap cleanup_quota_test EXIT
1358 set_ost_qtype "none" || error "disable ost quota failed"
1359 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1360 error "set quota for $TSTUSR failed"
1361 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1362 error "set quota for $TSTUSR2 failed"
1364 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1365 lustre_fail mds 0x608 0
1367 # enable quota to tirgger reintegration
1368 set_ost_qtype "u" || error "enable ost quota failed"
1369 wait_ost_reint "u" || error "reintegration failed"
1373 # hardlimit should have been fetched by slave during global
1374 # reintegration, write will exceed quota
1375 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1376 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1378 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1379 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1383 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1385 # quota reintegration (inode limits)
1387 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1389 # LU-2435: skip this quota test if underlying zfs version has not
1390 # supported native dnode accounting
1391 [ "$(facet_fstype mds1)" == "zfs" ] && {
1392 local F="feature@userobj_accounting"
1393 local pool=$(zpool_name mds1)
1394 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1396 [[ "$feature" != *" active "* ]] &&
1397 skip "requires zpool with active userobj_accounting"
1400 local ilimit=$((1024 * 2)) # 2k inodes
1401 local TESTFILE=$DIR/${tdir}-1/$tfile
1403 setup_quota_test || error "setup quota failed with $?"
1404 trap cleanup_quota_test EXIT
1406 # make sure the system is clean
1407 local USED=$(getquota -u $TSTUSR global curinodes)
1408 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1410 # make sure no granted quota on mdt1
1411 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1412 resetquota -u $TSTUSR
1413 set_mdt_qtype "none" || error "disable mdt quota failed"
1415 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1416 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1417 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1420 echo "Stop mds${MDSCOUNT}..."
1423 echo "Enable quota & set quota limit for $TSTUSR"
1424 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1425 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1426 error "set quota failed"
1428 echo "Start mds${MDSCOUNT}..."
1429 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1432 wait_mdt_reint $QTYPE || error "reintegration failed"
1434 echo "create remote dir"
1435 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1436 error "create remote dir failed"
1437 chmod 0777 $DIR/${tdir}-1
1439 # hardlimit should have been fetched by slave during global
1440 # reintegration, create will exceed quota
1441 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1442 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1444 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1445 wait_delete_completed
1446 sync_all_data || true
1448 echo "Stop mds${MDSCOUNT}..."
1451 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1452 error "clear quota failed"
1454 echo "Start mds${MDSCOUNT}..."
1455 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1458 wait_mdt_reint $QTYPE || error "reintegration failed"
1460 # hardlimit should be cleared on slave during reintegration
1461 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1462 quota_error u $TSTUSR "create failed, expect success"
1464 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1465 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1469 run_test 7e "Quota reintegration (inode limits)"
1471 # run dbench with quota enabled
1473 local BLK_LIMIT="100g" #100G
1474 local FILE_LIMIT=1000000
1476 setup_quota_test || error "setup quota failed with $?"
1477 trap cleanup_quota_test EXIT
1479 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1480 set_ost_qtype $QTYPE || error "enable ost quota failed"
1482 echo "Set enough high limit for user: $TSTUSR"
1483 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1484 error "set user quota failed"
1485 echo "Set enough high limit for group: $TSTUSR"
1486 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1487 error "set group quota failed"
1488 if is_project_quota_supported; then
1489 change_project -sp $TSTPRJID $DIR/$tdir
1490 echo "Set enough high limit for project: $TSTPRJID"
1491 $LFS setquota -p $TSTPRJID -b 0 \
1492 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1493 error "set project quota failed"
1497 [ "$SLOW" = "no" ] && duration=" -t 120"
1498 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1499 quota_error a $TSTUSR "dbench failed!"
1501 is_project_quota_supported && change_project -C $DIR/$tdir
1504 run_test 8 "Run dbench with quota enabled"
1506 # this check is just for test_9
1507 OST0_MIN=4900000 #4.67G
1509 check_whether_skip () {
1510 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1511 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1512 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1513 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1520 # run for fixing bug10707, it needs a big room. test for 64bit
1522 local filesize=$((1024 * 9 / 2)) # 4.5G
1524 check_whether_skip && return 0
1526 setup_quota_test || error "setup quota failed with $?"
1527 trap cleanup_quota_test EXIT
1529 set_ost_qtype "ug" || error "enable ost quota failed"
1531 local TESTFILE="$DIR/$tdir/$tfile-0"
1532 local BLK_LIMIT=100G #100G
1533 local FILE_LIMIT=1000000
1535 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1537 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1539 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1540 error "set user quota failed"
1542 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1543 "for group: $TSTUSR"
1544 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1545 error "set group quota failed"
1547 quota_show_check a u $TSTUSR
1548 quota_show_check a g $TSTUSR
1550 echo "Create test file"
1551 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1552 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1554 log "Write the big file of 4.5G ..."
1555 $RUNAS $DD of=$TESTFILE count=$filesize ||
1556 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1566 run_test 9 "Block limit larger than 4GB (b10707)"
1569 local TESTFILE=$DIR/$tdir/$tfile
1571 setup_quota_test || error "setup quota failed with $?"
1572 trap cleanup_quota_test EXIT
1574 # set limit to root user should fail
1575 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1576 error "set limit for root user successfully, expect failure"
1577 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1578 error "set limit for root group successfully, expect failure"
1579 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1580 error "set limit for project 0 successfully, expect failure"
1582 # root user can overrun quota
1583 set_ost_qtype "ug" || error "enable ost quota failed"
1585 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1586 error "set quota failed"
1587 quota_show_check b u $TSTUSR
1589 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1590 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1592 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1593 error "write failure, expect success"
1597 run_test 10 "Test quota for root user"
1600 local TESTFILE=$DIR/$tdir/$tfile
1601 setup_quota_test || error "setup quota failed with $?"
1602 trap cleanup_quota_test EXIT
1604 set_mdt_qtype "ug" || error "enable mdt quota failed"
1605 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1606 error "set quota failed"
1608 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1609 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1611 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1612 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1615 local USED=$(getquota -u $TSTUSR global curinodes)
1616 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1620 run_test 11 "Chown/chgrp ignores quota"
1623 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1625 local blimit=22 # 22M
1626 local blk_cnt=$((blimit - 5))
1627 local TESTFILE0="$DIR/$tdir/$tfile"-0
1628 local TESTFILE1="$DIR/$tdir/$tfile"-1
1630 setup_quota_test || error "setup quota failed with $?"
1631 trap cleanup_quota_test EXIT
1633 set_ost_qtype "u" || error "enable ost quota failed"
1634 quota_show_check b u $TSTUSR
1636 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1637 error "set quota failed"
1639 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1640 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1641 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1642 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1644 echo "Write to ost0..."
1645 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1646 quota_error a $TSTUSR "dd failed"
1648 echo "Write to ost1..."
1649 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1650 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1652 echo "Free space from ost0..."
1654 wait_delete_completed
1655 sync_all_data || true
1657 echo "Write to ost1 after space freed from ost0..."
1658 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1659 quota_error a $TSTUSR "rebalancing failed"
1663 run_test 12a "Block quota rebalancing"
1666 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1668 local ilimit=$((1024 * 2)) # 2k inodes
1669 local TESTFILE0=$DIR/$tdir/$tfile
1670 local TESTFILE1=$DIR/${tdir}-1/$tfile
1672 setup_quota_test || error "setup quota failed with $?"
1673 trap cleanup_quota_test EXIT
1675 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1676 chmod 0777 $DIR/${tdir}-1
1678 set_mdt_qtype "u" || error "enable mdt quota failed"
1679 quota_show_check f u $TSTUSR
1681 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1682 error "set quota failed"
1684 echo "Create $ilimit files on mdt0..."
1685 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1686 quota_error u $TSTUSR "create failed, but expect success"
1688 echo "Create files on mdt1..."
1689 $RUNAS createmany -m $TESTFILE1 1 &&
1690 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1692 echo "Free space from mdt0..."
1693 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1694 wait_delete_completed
1695 sync_all_data || true
1697 echo "Create files on mdt1 after space freed from mdt0..."
1698 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1699 quota_error a $TSTUSR "rebalancing failed"
1701 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1702 error "unlink mdt1 files failed"
1703 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1707 run_test 12b "Inode quota rebalancing"
1710 local TESTFILE=$DIR/$tdir/$tfile
1711 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1712 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1714 setup_quota_test || error "setup quota failed with $?"
1715 trap cleanup_quota_test EXIT
1717 set_ost_qtype "u" || error "enable ost quota failed"
1718 quota_show_check b u $TSTUSR
1720 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1721 error "set quota failed"
1722 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1723 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1725 # clear the locks in cache first
1726 do_facet ost1 $LCTL set_param -n $procf=clear
1727 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1728 [ $nlock -eq 0 ] || error "$nlock cached locks"
1730 # write to acquire the per-ID lock
1731 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1732 quota_error a $TSTUSR "dd failed"
1734 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1735 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1737 # clear quota doesn't trigger per-ID lock cancellation
1738 resetquota -u $TSTUSR
1739 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1740 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1742 # clear the per-ID lock
1743 do_facet ost1 $LCTL set_param -n $procf=clear
1744 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1745 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1747 # spare quota should be released
1748 local OSTUUID=$(ostuuid_from_index 0)
1749 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1750 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1751 [ $limit -le $space ] ||
1752 error "spare quota isn't released, limit:$limit, space:$space"
1756 run_test 13 "Cancel per-ID lock in the LRU list"
1759 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1761 wait_delete_completed
1762 sync_all_data || true
1765 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1766 error "set user quota failed"
1767 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1768 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1769 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1770 resetquota -u $TSTUSR
1773 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1774 error "set group quota failed"
1775 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1776 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1777 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1778 resetquota -g $TSTUSR
1780 run_test 15 "Set over 4T block quota"
1784 local BLKS=1 # 1M less than limit
1785 local TESTFILE=$DIR/$tdir/$tfile
1787 setup_quota_test || error "setup quota failed with $?"
1788 trap cleanup_quota_test EXIT
1790 # make sure the system is clean
1791 local USED=$(getquota -u $TSTUSR global curspace)
1792 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1794 set_ost_qtype "ug" || error "enable ost quota failed"
1795 # make sure no granted quota on ost
1796 resetquota -u $TSTUSR
1797 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1798 error "set quota failed"
1800 quota_show_check b u $TSTUSR
1802 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1803 lustre_fail mds 0xa04 $err_code
1805 # write in background
1806 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1810 # write should be blocked and never finished
1811 if ! ps -p $DDPID > /dev/null 2>&1; then
1813 quota_error u $TSTUSR "write finished incorrectly!"
1821 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1823 if [ $count -gt $timeout ]; then
1824 quota_error u $TSTUSR "dd is not finished!"
1829 sync; sync_all_data || true
1831 USED=$(getquota -u $TSTUSR global curspace)
1832 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1833 "Used space(${USED}K) is less than ${BLKS}M"
1838 # DQACQ return recoverable error
1840 echo "DQACQ return -ENOLCK"
1842 test_17sub 37 || error "Handle -ENOLCK failed"
1844 echo "DQACQ return -EAGAIN"
1846 test_17sub 11 || error "Handle -EAGAIN failed"
1848 echo "DQACQ return -ETIMEDOUT"
1849 #define ETIMEDOUT 110
1850 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1852 echo "DQACQ return -ENOTCONN"
1853 #define ENOTCONN 107
1854 test_17sub 107 || error "Handle -ENOTCONN failed"
1857 run_test 17 "DQACQ return recoverable error"
1861 local blimit="200m" # 200M
1862 local TESTFILE="$DIR/$tdir/$tfile"
1864 setup_quota_test || error "setup quota failed with $?"
1865 trap cleanup_quota_test EXIT
1867 set_ost_qtype "u" || error "enable ost quota failed"
1868 log "User quota (limit: $blimit)"
1869 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1870 error "set quota failed"
1871 quota_show_check b u $TSTUSR
1873 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1874 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1876 local timeout=$(sysctl -n lustre.timeout)
1878 if [ $io_type = "directio" ]; then
1879 log "Write 100M (directio) ..."
1880 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1882 log "Write 100M (buffered) ..."
1883 $RUNAS $DD of=$TESTFILE count=100 &
1887 replay_barrier $SINGLEMDS
1888 log "Fail mds for $((2 * timeout)) seconds"
1889 fail $SINGLEMDS $((2 * timeout))
1892 if at_is_enabled; then
1893 timeout=$(at_max_get mds)
1895 timeout=$(lctl get_param -n timeout)
1899 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1900 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1901 log "it took $count second"
1906 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1908 cancel_lru_locks mdc
1909 cancel_lru_locks osc
1912 local testfile_size=$(stat -c %s $TESTFILE)
1913 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1914 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1915 "got ${testfile_size}. Verifying file failed!"
1920 # test when mds does failover, the ost still could work well
1921 # this test shouldn't trigger watchdog b=14840
1923 # Clear dmesg so watchdog is not triggered by previous
1925 do_facet ost1 dmesg -c > /dev/null
1928 test_18_sub directio
1930 # check if watchdog is triggered
1931 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1932 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1933 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1934 [ -z "$watchdog" ] || error "$watchdog"
1935 rm -f $TMP/lustre-log-${TESTNAME}.log
1937 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1941 local TESTFILE=$DIR/$tdir/$tfile
1943 setup_quota_test || error "setup quota failed with $?"
1944 trap cleanup_quota_test EXIT
1946 set_ost_qtype $QTYPE || error "enable ost quota failed"
1948 # bind file to a single OST
1949 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1950 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1952 echo "Set user quota (limit: ${blimit}M)"
1953 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1954 error "set user quota failed"
1955 quota_show_check b u $TSTUSR
1956 echo "Update quota limits"
1957 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1958 error "set group quota failed"
1959 quota_show_check b u $TSTUSR
1961 # first wirte might be cached
1962 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1963 cancel_lru_locks osc
1965 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1966 quota_error u $TSTUSR "Write success, expect failure"
1971 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1973 test_20() { # b15754
1974 local LSTR=(2g 1t 4k 3m) # limits strings
1976 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
1979 resetquota -u $TSTUSR
1981 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1982 $MOUNT || error "could not set quota limits"
1983 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1984 --inode-softlimit ${LSTR[2]} \
1985 --inode-hardlimit ${LSTR[3]} \
1986 $MOUNT || error "could not set quota limits"
1988 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1989 error "bsoftlimit was not set properly"
1990 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1991 error "bhardlimit was not set properly"
1992 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1993 error "isoftlimit was not set properly"
1994 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1995 error "ihardlimit was not set properly"
1997 resetquota -u $TSTUSR
1999 run_test 20 "Test if setquota specifiers work properly (b15754)"
2006 local time=$(($(date +%s) + seconds))
2007 while [ $(date +%s) -lt $time ]; do
2008 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2012 # run for fixing bug16053, setquota shouldn't fail when writing and
2013 # deleting are happening
2015 local TESTFILE="$DIR/$tdir/$tfile"
2016 local BLIMIT=10 # 10G
2017 local ILIMIT=1000000
2019 setup_quota_test || error "setup quota failed with $?"
2020 trap cleanup_quota_test EXIT
2022 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2024 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2025 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2026 error "set user quota failed"
2027 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2028 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2029 error "set group quota failed"
2030 if is_project_quota_supported; then
2031 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2032 "project: $TSTPRJID"
2033 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2034 $MOUNT || error "set project quota failed"
2037 # repeat writing on a 1M file
2038 test_21_sub ${TESTFILE}_1 1 30 &
2040 # repeat writing on a 128M file
2041 test_21_sub ${TESTFILE}_2 128 30 &
2044 local time=$(($(date +%s) + 30))
2046 while [ $(date +%s) -lt $time ]; do
2047 log "Set quota for $i times"
2048 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2049 -I $((ILIMIT + i)) $MOUNT ||
2050 error "Set user quota failed"
2051 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2052 -I $((ILIMIT + i)) $MOUNT ||
2053 error "Set group quota failed"
2054 if is_project_quota_supported; then
2055 $LFS setquota -p $TSTPRJID -b 0 -B \
2056 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2057 error "Set project quota failed"
2065 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2067 if [ $count -gt 60 ]; then
2068 quota_error a $TSTUSR "dd should be finished!"
2072 echo "(dd_pid=$DDPID1, time=$count)successful"
2076 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2078 if [ $count -gt 60 ]; then
2079 quota_error a $TSTUSR "dd should be finished!"
2083 echo "(dd_pid=$DDPID2, time=$count)successful"
2087 run_test 21 "Setquota while writing & deleting (b16053)"
2089 # enable/disable quota enforcement permanently
2091 echo "Set both mdt & ost quota type as ug"
2093 is_project_quota_supported && qtype=$QTYPE
2094 set_mdt_qtype $qtype || error "enable mdt quota failed"
2095 set_ost_qtype $qtype || error "enable ost quota failed"
2098 stopall || error "failed to stopall (1)"
2102 echo "Verify if quota is enabled"
2103 local qtype1=$(mdt_quota_type)
2104 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2105 qtype=$(ost_quota_type)
2106 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2108 echo "Set both mdt & ost quota type as none"
2109 set_mdt_qtype "none" || error "disable mdt quota failed"
2110 set_ost_qtype "none" || error "disable ost quota failed"
2113 stopall || error "failed to stopall (2)"
2118 echo "Verify if quota is disabled"
2119 qtype=$(mdt_quota_type)
2120 [ $qtype != "none" ] && error "mdt quota setting is lost"
2121 qtype=$(ost_quota_type)
2122 [ $qtype != "none" ] && error "ost quota setting is lost"
2126 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2129 local TESTFILE="$DIR/$tdir/$tfile"
2132 setup_quota_test || error "setup quota failed with $?"
2133 trap cleanup_quota_test EXIT
2135 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2138 log "User quota (limit: $LIMIT MB)"
2139 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2140 error "set quota failed"
2141 quota_show_check b u $TSTUSR
2143 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2144 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2146 log "Step1: trigger EDQUOT with O_DIRECT"
2147 log "Write half of file"
2148 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2149 quota_error u $TSTUSR "(1) Write failure, expect success." \
2151 log "Write out of block quota ..."
2152 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2153 oflag=direct conv=notrunc &&
2154 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2158 log "Step2: rewrite should succeed"
2159 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2160 quota_error u $TSTUSR "(3) Write failure, expect success." \
2166 local OST0_UUID=$(ostuuid_from_index 0)
2167 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2168 [ $OST0_QUOTA_USED -ne 0 ] &&
2169 ($SHOW_QUOTA_USER; \
2170 quota_error u $TSTUSR "quota isn't released")
2175 [ $(facet_fstype ost1) == "zfs" ] &&
2176 skip "Overwrite in place is not guaranteed to be " \
2177 "space neutral on ZFS"
2179 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2180 check_whether_skip && return 0
2181 log "run for 4MB test file"
2184 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2185 check_whether_skip && return 0
2186 log "run for 40MB test file"
2189 run_test 23 "Quota should be honored with directIO (b16125)"
2193 local TESTFILE="$DIR/$tdir/$tfile"
2195 setup_quota_test || error "setup quota failed with $?"
2196 trap cleanup_quota_test EXIT
2198 set_ost_qtype $QTYPE || error "enable ost quota failed"
2200 # bind file to a single OST
2201 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2202 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2204 echo "Set user quota (limit: ${blimit}M)"
2205 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2206 error "set quota failed"
2208 # overrun quota by root user
2209 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2210 error "write failure, expect success"
2211 cancel_lru_locks osc
2212 sync_all_data || true
2214 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2218 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2220 test_27a() { # b19612
2221 $LFS quota $TSTUSR $DIR &&
2222 error "lfs succeeded with no type, but should have failed"
2223 $LFS setquota $TSTUSR $DIR &&
2224 error "lfs succeeded with no type, but should have failed"
2227 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2229 test_27b() { # b20200
2230 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2231 error "lfs setquota failed with uid argument"
2232 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2233 error "lfs stequota failed with gid argument"
2234 if is_project_quota_supported; then
2235 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2236 1000 $DIR || error \
2237 "lfs stequota failed with projid argument"
2239 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2240 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2241 if is_project_quota_supported; then
2242 $SHOW_QUOTA_PROJID ||
2243 error "lfs quota failed with projid argument"
2245 resetquota -u $TSTUSR
2246 resetquota -g $TSTUSR
2247 resetquota -p $TSTPRJID
2250 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2255 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2256 error "lfs setquota failed"
2258 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2259 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2260 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2261 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2263 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2264 error "lfs setquota for $TSTID failed"
2266 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2267 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2268 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2269 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2271 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2272 error "total allocated inode/block limit not printed"
2274 resetquota -u $TSTUSR
2276 run_test 27c "lfs quota should support human-readable output"
2283 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2284 error "set fraction block limit failed"
2285 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2286 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2287 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2288 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2290 resetquota -u $TSTUSR
2292 run_test 27d "lfs setquota should support fraction block limit"
2296 local TESTFILE="$DIR/$tdir/$tfile"
2299 setup_quota_test || error "setup quota failed with $?"
2300 trap cleanup_quota_test EXIT
2302 set_ost_qtype "u" || error "enable ost quota failed"
2304 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2305 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2307 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2308 $MAX_IQ_TIME $DIR || error "set grace time failed"
2309 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2310 error "set quota failed"
2311 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2312 cancel_lru_locks osc
2314 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2315 # over-quota flag has not yet settled since we do not trigger async
2316 # events based on grace time period expiration
2318 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2319 cancel_lru_locks osc
2320 # now over-quota flag should be settled and further writes should fail
2322 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2323 error "grace times were reset"
2326 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2327 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2329 run_test 30 "Hard limit updates should not reset grace times"
2331 # basic usage tracking for user & group
2333 local INODES=10 # 10 files
2334 local BLK_CNT=2 # of 2M each
2335 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2337 setup_quota_test || error "setup quota failed with $?"
2338 trap cleanup_quota_test EXIT
2340 # make sure the system is clean
2341 local USED=$(getquota -u $TSTID global curspace)
2343 error "Used space ($USED) for user $TSTID isn't 0."
2344 USED=$(getquota -g $TSTID global curspace)
2346 error "Used space ($USED) for group $TSTID isn't 0."
2347 if is_project_quota_supported; then
2348 USED=$(getquota -p $TSTPRJID global curspace)
2349 [ $USED -ne 0 ] && error \
2350 "Used space ($USED) for project $TSTPRJID isn't 0."
2353 echo "Write files..."
2354 for i in $(seq 0 $INODES); do
2355 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2356 error "write failed"
2357 is_project_quota_supported &&
2358 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2359 echo "Iteration $i/$INODES completed"
2361 cancel_lru_locks osc
2363 echo "Wait for setattr on objects finished..."
2364 wait_delete_completed
2366 sync; sync_all_data || true
2368 echo "Verify disk usage after write"
2369 USED=$(getquota -u $TSTID global curspace)
2370 [ $USED -lt $TOTAL_BLKS ] &&
2371 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2372 USED=$(getquota -g $TSTID global curspace)
2373 [ $USED -lt $TOTAL_BLKS ] &&
2374 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2375 if is_project_quota_supported; then
2376 USED=$(getquota -p $TSTPRJID global curspace)
2377 [ $USED -lt $TOTAL_BLKS ] && error \
2378 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2381 echo "Verify inode usage after write"
2382 USED=$(getquota -u $TSTID global curinodes)
2383 [ $USED -lt $INODES ] &&
2384 error "Used inode for user $TSTID is $USED, expected $INODES"
2385 USED=$(getquota -g $TSTID global curinodes)
2386 [ $USED -lt $INODES ] &&
2387 error "Used inode for group $TSTID is $USED, expected $INODES"
2388 if is_project_quota_supported; then
2389 USED=$(getquota -p $TSTPRJID global curinodes)
2390 [ $USED -lt $INODES ] && error \
2391 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2396 echo "Verify disk usage after delete"
2397 USED=$(getquota -u $TSTID global curspace)
2398 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2399 USED=$(getquota -u $TSTID global curinodes)
2400 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2401 USED=$(getquota -g $TSTID global curspace)
2402 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2403 USED=$(getquota -g $TSTID global curinodes)
2404 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2405 if is_project_quota_supported; then
2406 USED=$(getquota -p $TSTPRJID global curspace)
2408 error "Used space for project $TSTPRJID isn't 0. $USED"
2409 USED=$(getquota -p $TSTPRJID global curinodes)
2411 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2414 run_test 33 "Basic usage tracking for user & group & project"
2416 # usage transfer test for user & group & project
2418 local BLK_CNT=2 # 2MB
2419 local project_supported="no"
2421 is_project_quota_supported && project_supported="yes"
2422 setup_quota_test || error "setup quota failed with $?"
2423 trap cleanup_quota_test EXIT
2425 # make sure the system is clean
2426 local USED=$(getquota -u $TSTID global curspace)
2427 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2428 USED=$(getquota -g $TSTID global curspace)
2429 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2431 local USED=$(getquota -u $TSTID2 global curspace)
2432 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2433 if [ $project_supported == "yes" ]; then
2434 USED=$(getquota -p $TSTPRJID global curspace)
2435 [ $USED -ne 0 ] && error \
2436 "Used space ($USED) for Project $TSTPRJID isn't 0."
2439 echo "Write file..."
2440 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2441 error "write failed"
2442 cancel_lru_locks osc
2443 sync; sync_all_data || true
2445 echo "chown the file to user $TSTID"
2446 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2448 echo "Wait for setattr on objects finished..."
2449 wait_delete_completed
2451 BLK_CNT=$((BLK_CNT * 1024))
2453 echo "Verify disk usage for user $TSTID"
2454 USED=$(getquota -u $TSTID global curspace)
2455 [ $USED -lt $BLK_CNT ] &&
2456 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2457 USED=$(getquota -u $TSTID global curinodes)
2459 error "Used inodes for user $TSTID is $USED, expected 1"
2461 echo "chgrp the file to group $TSTID"
2462 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2464 echo "Wait for setattr on objects finished..."
2465 wait_delete_completed
2467 echo "Verify disk usage for group $TSTID"
2468 USED=$(getquota -g $TSTID global curspace)
2469 [ $USED -ge $BLK_CNT ] ||
2470 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2471 USED=$(getquota -g $TSTID global curinodes)
2473 error "Used inodes for group $TSTID is $USED, expected 1"
2475 # chown won't change the ost object group. LU-4345 */
2476 echo "chown the file to user $TSTID2"
2477 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2479 echo "Wait for setattr on objects finished..."
2480 wait_delete_completed
2482 echo "change_project project id to $TSTPRJID"
2483 [ $project_supported == "yes" ] &&
2484 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2485 echo "Wait for setattr on objects finished..."
2486 wait_delete_completed
2488 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2489 USED=$(getquota -u $TSTID2 global curspace)
2490 [ $USED -lt $BLK_CNT ] &&
2491 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2492 USED=$(getquota -u $TSTID global curspace)
2494 error "Used space for user $TSTID is $USED, expected 0"
2495 USED=$(getquota -g $TSTID global curspace)
2496 [ $USED -lt $BLK_CNT ] &&
2497 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2498 if [ $project_supported == "yes" ]; then
2499 USED=$(getquota -p $TSTPRJID global curspace)
2500 [ $USED -lt $BLK_CNT ] && error \
2501 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2506 run_test 34 "Usage transfer for user & group & project"
2508 # usage is still accessible across restart
2510 local BLK_CNT=2 # 2 MB
2512 setup_quota_test || error "setup quota failed with $?"
2513 trap cleanup_quota_test EXIT
2515 echo "Write file..."
2516 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2517 error "write failed"
2518 is_project_quota_supported &&
2519 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2520 cancel_lru_locks osc
2522 echo "Wait for setattr on objects finished..."
2523 wait_delete_completed
2525 sync; sync_all_data || true
2527 echo "Save disk usage before restart"
2528 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2529 [ $ORIG_USR_SPACE -eq 0 ] &&
2530 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2531 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2532 [ $ORIG_USR_INODES -eq 0 ] &&
2533 error "Used inodes for user $TSTID is 0, expected 1"
2534 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2535 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2536 [ $ORIG_GRP_SPACE -eq 0 ] &&
2537 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2538 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2539 [ $ORIG_GRP_INODES -eq 0 ] &&
2540 error "Used inodes for group $TSTID is 0, expected 1"
2541 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2543 if is_project_quota_supported; then
2544 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2545 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2546 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2547 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2548 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2549 "Used inodes for project $TSTPRJID is 0, expected 1"
2550 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2558 echo "Verify disk usage after restart"
2559 local USED=$(getquota -u $TSTID global curspace)
2560 [ $USED -eq $ORIG_USR_SPACE ] ||
2561 error "Used space for user $TSTID changed from " \
2562 "$ORIG_USR_SPACE to $USED"
2563 USED=$(getquota -u $TSTID global curinodes)
2564 [ $USED -eq $ORIG_USR_INODES ] ||
2565 error "Used inodes for user $TSTID changed from " \
2566 "$ORIG_USR_INODES to $USED"
2567 USED=$(getquota -g $TSTID global curspace)
2568 [ $USED -eq $ORIG_GRP_SPACE ] ||
2569 error "Used space for group $TSTID changed from " \
2570 "$ORIG_GRP_SPACE to $USED"
2571 USED=$(getquota -g $TSTID global curinodes)
2572 [ $USED -eq $ORIG_GRP_INODES ] ||
2573 error "Used inodes for group $TSTID changed from " \
2574 "$ORIG_GRP_INODES to $USED"
2575 if [ $project_supported == "yes" ]; then
2576 USED=$(getquota -p $TSTPRJID global curinodes)
2577 [ $USED -eq $ORIG_PRJ_INODES ] ||
2578 error "Used inodes for project $TSTPRJID " \
2579 "changed from $ORIG_PRJ_INODES to $USED"
2580 USED=$(getquota -p $TSTPRJID global curspace)
2581 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2582 error "Used space for project $TSTPRJID "\
2583 "changed from $ORIG_PRJ_SPACE to $USED"
2586 # check if the vfs_dq_init() is called before writing
2587 echo "Append to the same file..."
2588 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2589 error "write failed"
2590 cancel_lru_locks osc
2591 sync; sync_all_data || true
2593 echo "Verify space usage is increased"
2594 USED=$(getquota -u $TSTID global curspace)
2595 [ $USED -gt $ORIG_USR_SPACE ] ||
2596 error "Used space for user $TSTID isn't increased" \
2597 "orig:$ORIG_USR_SPACE, now:$USED"
2598 USED=$(getquota -g $TSTID global curspace)
2599 [ $USED -gt $ORIG_GRP_SPACE ] ||
2600 error "Used space for group $TSTID isn't increased" \
2601 "orig:$ORIG_GRP_SPACE, now:$USED"
2602 if [ $project_supported == "yes" ]; then
2603 USED=$(getquota -p $TSTPRJID global curspace)
2604 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2605 error "Used space for project $TSTPRJID isn't " \
2606 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2611 run_test 35 "Usage is still accessible across reboot"
2613 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2616 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2617 skip "Old server doesn't have LU-5006 fix."
2619 setup_quota_test || error "setup quota failed with $?"
2620 trap cleanup_quota_test EXIT
2622 # make sure the system is clean
2623 local USED=$(getquota -u $TSTID global curspace)
2625 error "Used space ($USED) for user $TSTID isn't 0."
2627 # create file with MDS_OPEN_DELAY_CREATE flag
2628 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2629 error "Create file failed"
2631 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2632 oflag=sync || error "Write file failed"
2634 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2636 # wait for setattr on objects finished..."
2637 wait_delete_completed
2639 USED=$(getquota -u $TSTID global curspace)
2640 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2644 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2648 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2649 skip "Old server doesn't have LU-8801 fix."
2651 [ "$UID" != 0 ] && skip_env "must run as root" && return
2653 setup_quota_test || error "setup quota failed with $?"
2654 trap cleanup_quota_test EXIT
2656 # make sure the system is clean
2657 local USED=$(getquota -u $TSTID global curspace)
2659 error "Used space ($USED) for user $TSTID isn't 0."
2660 USED=$(getquota -u $TSTID2 global curspace)
2662 error "Used space ($USED) for user $TSTID2 isn't 0."
2664 local TESTFILE="$DIR/$tdir/$tfile"
2665 local file_cnt=10000
2667 # Generate id entries in accounting file
2668 echo "Create $file_cnt files..."
2669 for i in `seq $file_cnt`; do
2671 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2672 error "failed to chown $TESTFILE-$i"
2674 cancel_lru_locks osc
2675 sync; sync_all_data || true
2677 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2678 procf=${procf}.quota_slave.acct_user
2681 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2682 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2683 echo "Found $acct_cnt id entries"
2685 [ $file_cnt -eq $acct_cnt ] || {
2686 do_facet mds1 $LCTL get_param $procf
2687 error "skipped id entries"
2692 run_test 38 "Quota accounting iterator doesn't skip id entries"
2695 local TESTFILE="$DIR/$tdir/project"
2696 ! is_project_quota_supported &&
2697 skip "Project quota is not supported"
2699 setup_quota_test || error "setup quota failed with $?"
2702 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2703 [ $projectid -ne 0 ] &&
2704 error "Project id should be 0 not $projectid"
2705 change_project -p 1024 $TESTFILE
2706 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2707 [ $projectid -ne 1024 ] &&
2708 error "Project id should be 1024 not $projectid"
2710 stopall || error "failed to stopall (1)"
2713 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2714 [ $projectid -ne 1024 ] &&
2715 error "Project id should be 1024 not $projectid"
2719 run_test 39 "Project ID interface works correctly"
2722 ! is_project_quota_supported &&
2723 skip "Project quota is not supported"
2724 local dir1="$DIR/$tdir/dir1"
2725 local dir2="$DIR/$tdir/dir2"
2727 setup_quota_test || error "setup quota failed with $?"
2729 mkdir -p $dir1 $dir2
2730 change_project -sp 1 $dir1 && touch $dir1/1
2731 change_project -sp 2 $dir2
2733 ln $dir1/1 $dir2/1_link &&
2734 error "Hard link across different project quota should fail"
2739 run_test 40a "Hard link across different project ID"
2742 ! is_project_quota_supported &&
2743 skip "Project quota is not supported"
2744 local dir1="$DIR/$tdir/dir1"
2745 local dir2="$DIR/$tdir/dir2"
2747 setup_quota_test || error "setup quota failed with $?"
2748 mkdir -p $dir1 $dir2
2749 change_project -sp 1 $dir1 && touch $dir1/1
2750 change_project -sp 2 $dir2
2752 mv $dir1/1 $dir2/2 || error "mv failed $?"
2753 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2754 if [ "$projid" != "2" ]; then
2755 error "project id expected 2 not $projid"
2760 run_test 40b "Mv across different project ID"
2763 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2764 ! is_project_quota_supported &&
2765 skip "Project quota is not supported"
2767 setup_quota_test || error "setup quota failed with $?"
2768 local dir="$DIR/$tdir/dir"
2770 mkdir -p $dir && change_project -sp 1 $dir
2771 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2772 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2773 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2774 touch $dir/remote_dir/file
2775 #verify inherit works file for remote dir.
2776 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2777 [ "$projid" != "1" ] &&
2778 error "file under remote dir expected 1 not $projid"
2780 #Agent inode should be ignored for project quota
2781 USED=$(getquota -p 1 global curinodes)
2782 [ "$USED" != "3" ] &&
2783 error "file count expected 3 got $USED"
2789 run_test 40c "Remote child Dir inherit project quota properly"
2792 ! is_project_quota_supported &&
2793 skip "Project quota is not supported"
2795 setup_quota_test || error "setup quota failed with $?"
2796 local dir1="$DIR/$tdir/dir1"
2797 local dir2="$DIR/$tdir/dir2"
2799 mkdir -p $dir1 && change_project -sp 1 $dir1
2800 mkdir -p $dir2 && change_project -sp 2 $dir2
2801 for num in $(seq 1 10); do
2802 touch $dir1/file_$num $dir2/file_$num
2803 ln -s $dir1/file_$num $dir1/file_$num"_link"
2804 ln -s $dir2/file_$num $dir2/file_$num"_link"
2807 count=$($LFS find --projid 1 $DIR | wc -l)
2808 [ "$count" != 21 ] && error "expected 21 but got $count"
2810 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2811 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2812 [ "$count" != 22 ] && error "expected 22 but got $count"
2817 run_test 50 "Test if lfs find --projid works"
2820 ! is_project_quota_supported &&
2821 skip "Project quota is not supported"
2822 setup_quota_test || error "setup quota failed with $?"
2823 local dir="$DIR/$tdir/dir"
2825 mkdir $dir && change_project -sp 1 $dir
2826 local used=$(getquota -p 1 global curinodes)
2827 [ $used != "1" ] && error "expected 1 got $used"
2832 used=$(getquota -p 1 global curinodes)
2833 [ $used != "4" ] && error "expected 4 got $used"
2835 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2837 cp $DIR/$tdir/6 $dir/6
2838 used=$(getquota -p 1 global curinodes)
2839 [ $used != "5" ] && error "expected 5 got $used"
2842 mv $DIR/$tdir/6 $dir/7
2843 used=$(getquota -p 1 global curinodes)
2844 [ $used != "6" ] && error "expected 6 got $used"
2849 run_test 51 "Test project accounting with mv/cp"
2852 ! is_project_quota_supported &&
2853 skip "Project quota is not supported"
2854 setup_quota_test || error "setup quota failed with $?"
2855 local dir="$DIR/$tdir/dir"
2856 mkdir $dir && change_project -sp 1 $dir
2858 touch $DIR/$tdir/file
2859 #Try renaming a file into the project. This should fail.
2860 for num in $(seq 1 2000); do
2861 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2862 error "rename should fail"
2867 run_test 52 "Rename across different project ID"
2870 ! is_project_quota_supported &&
2871 skip "Project quota is not supported"
2872 setup_quota_test || error "setup quota failed with $?"
2873 local dir="$DIR/$tdir/dir"
2874 mkdir $dir && change_project -s $dir
2875 lfs project -d $dir | grep P || error "inherit attribute should be set"
2877 change_project -C $dir
2878 lfs project -d $dir | grep P &&
2879 error "inherit attribute should be cleared"
2884 run_test 53 "Project inherit attribute could be cleared"
2887 ! is_project_quota_supported &&
2888 skip "Project quota is not supported"
2889 setup_quota_test || error "setup quota failed with $?"
2890 trap cleanup_quota_test EXIT
2891 local testfile="$DIR/$tdir/$tfile-0"
2893 #set project ID/inherit attribute
2894 change_project -sp $TSTPRJID $DIR/$tdir
2895 $RUNAS createmany -m ${testfile} 100 ||
2896 error "create many files failed"
2898 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2899 # one more count for directory itself */
2903 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2904 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2906 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2907 [ $proj_count1 -eq $proj_count ] ||
2908 error "c2: expected $proj_count got $proj_count1"
2910 #clear project but with kept projid
2911 change_project -rCk $DIR/$tdir
2912 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2913 [ $proj_count1 -eq $proj_count ] ||
2914 error "c3: expected $proj_count got $proj_count1"
2916 #verify projid untouched.
2917 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2919 [ $proj_count1 -eq $proj_count ] ||
2920 error "c4: expected $proj_count got $proj_count1"
2923 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2924 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2925 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2927 #this time clear all
2928 change_project -rC $DIR/$tdir
2929 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2930 [ $proj_count1 -eq 0 ] ||
2931 error "c6: expected 0 got $proj_count1"
2933 unlinkmany ${testfile} 100 ||
2934 error "unlink many files failed"
2938 run_test 54 "basic lfs project interface test"
2941 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
2942 skip "Not supported before 2.10.58."
2943 setup_quota_test || error "setup quota failed with $?"
2945 set_ost_qtype $QTYPE || error "enable ost quota failed"
2948 #add second group to TSTUSR
2949 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
2952 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
2953 error "failed to dd"
2955 cancel_lru_locks osc
2956 sync; sync_all_data || true
2958 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
2959 error "failed to setquota on group $TSTUSR2"
2961 $LFS quota -v -g $TSTUSR2 $DIR
2963 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
2964 error "chgrp should failed with -EDQUOT"
2966 USED=$(getquota -g $TSTUSR2 global curspace)
2969 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
2970 error "failed to setquota on group $TSTUSR2"
2972 $LFS quota -v -g $TSTUSR2 $DIR
2974 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
2975 error "chgrp should succeed"
2977 $LFS quota -v -g $TSTUSR2 $DIR
2981 run_test 55 "Chgrp should be affected by group quota"
2984 setup_quota_test || error "setup quota failed with $?"
2986 set_ost_qtype $QTYPE || error "enable ost quota failed"
2989 $LFS setquota -t -u -b 10 -i 10 $DIR ||
2990 erro "failed to set grace time for usr quota"
2991 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
2992 awk '{print $4 $8}')
2993 if [ "x$grace_time" != "x10s;10s" ]; then
2994 $LFS quota -t -u $DIR
2995 error "expected grace time: 10s;10s, got:$grace_time"
3000 run_test 56 "lfs quota -t should work well"
3003 setup_quota_test || error "setup quota failed with $?"
3005 local dir="$DIR/$tdir/dir"
3008 #try to change pipe file should not hang and return failure
3009 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3010 awk -F ':' '{ print \\\$2 }'" \
3011 " unable to get xattr for fifo '$dir/pipe'" || return 1
3012 #command can process further if it hit some errors
3013 touch $dir/aaa $dir/bbb
3014 mkdir $dir/subdir -p
3015 touch $dir/subdir/aaa $dir/subdir/bbb
3016 #create one invalid link file
3017 ln -s $dir/not_exist_file $dir/ccc
3018 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3019 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3023 run_test 57 "lfs project could tolerate errors"
3026 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3027 skip "ldiskfs only test"
3028 disable_project_quota
3029 setup_quota_test || error "setup quota failed with $?"
3032 local testfile="$DIR/$tdir/$tfile-0"
3033 #make sure it did not crash kernel
3034 touch $testfile && lfs project -sp 1 $testfile
3036 enable_project_quota
3039 run_test 59 "lfs project dosen't crash kernel with project disabled"
3042 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3043 skip "Needs MDS version 2.11.53 or later."
3044 setup_quota_test || error "setup quota failed with $?"
3045 trap cleanup_quota_test EXIT
3047 local testfile=$DIR/$tdir/$tfile
3050 set_mdt_qtype "ug" || error "enable mdt quota failed"
3052 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3053 error "set quota failed"
3054 quota_show_check a g $TSTUSR
3056 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3057 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3058 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3059 error "create many files failed"
3061 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3063 # root user can overrun quota
3064 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3065 error "root user should succeed"
3069 run_test 60 "Test quota for root with setgid"
3071 # test default quota
3072 test_default_quota() {
3073 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3074 skip "Not supported before 2.11.51."
3079 local qprjid=$TSTPRJID
3083 local LIMIT=20480 #20M disk space
3084 local TESTFILE="$DIR/$tdir/$tfile-0"
3086 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3087 echo "Project quota is not supported" && return 0
3089 [ $qtype == "-u" ] && qdtype="-U"
3090 [ $qtype == "-g" ] && qdtype="-G"
3091 [ $qtype == "-p" ] && {
3096 [ $qpool == "meta" ] && {
3097 LIMIT=10240 #10K inodes
3102 setup_quota_test || error "setup quota failed with $?"
3103 trap cleanup_quota_test EXIT
3107 # enable mdt/ost quota
3108 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3109 set_ost_qtype $QTYPE || error "enable ost quota failed"
3111 log "set to use default quota"
3112 $LFS setquota $qtype $qid -d $DIR ||
3113 error "set $qid to use default quota failed"
3115 log "set default quota"
3116 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3117 error "set $qid default quota failed"
3119 log "get default quota"
3120 $LFS quota $qdtype $DIR || error "get default quota failed"
3122 if [ $qpool == "data" ]; then
3123 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3125 [ $SLIMIT -eq $LIMIT ] ||
3126 error "the returned default quota is wrong"
3128 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3130 [ $SLIMIT -eq $LIMIT ] ||
3131 error "the returned default quota is wrong"
3134 # make sure the system is clean
3135 local USED=$(getquota $qtype $qid global curspace)
3136 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3138 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3139 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3141 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3143 log "Test not out of quota"
3144 if [ $qpool == "data" ]; then
3145 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3146 quota_error $qtype $qid "write failed, expect succeed"
3148 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3149 quota_error $qtype $qid "create failed, expect succeed"
3151 unlinkmany $TESTFILE $((LIMIT/2))
3154 log "Test out of quota"
3155 # flush cache, ensure noquota flag is set on client
3156 cancel_lru_locks osc
3157 cancel_lru_locks mdc
3158 sync; sync_all_data || true
3159 if [ $qpool == "data" ]; then
3160 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3161 quota_error $qtype $qid "write succeed, expect EDQUOT"
3163 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3164 quota_error $qtype $qid "create succeed, expect EDQUOT"
3166 unlinkmany $TESTFILE $((LIMIT*2))
3169 log "Increase default quota"
3170 # increase default quota
3171 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3172 error "set default quota failed"
3174 cancel_lru_locks osc
3175 cancel_lru_locks mdc
3176 sync; sync_all_data || true
3177 if [ $qpool == "data" ]; then
3178 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3179 quota_error $qtype $qid "write failed, expect succeed"
3181 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3182 quota_error $qtype $qid "create failed, expect succeed"
3184 unlinkmany $TESTFILE $((LIMIT*2))
3187 log "Set quota to override default quota"
3188 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3189 error "set $qid quota failed"
3191 cancel_lru_locks osc
3192 cancel_lru_locks mdc
3193 sync; sync_all_data || true
3194 if [ $qpool == "data" ]; then
3195 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3196 quota_error $qtype $qid "write succeed, expect EQUOT"
3198 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3199 quota_error $qtype $qid "create succeed, expect EQUOT"
3201 unlinkmany $TESTFILE $((LIMIT*2))
3204 log "Set to use default quota again"
3205 $LFS setquota $qtype $qid -d $DIR ||
3206 error "set $qid to use default quota failed"
3208 cancel_lru_locks osc
3209 cancel_lru_locks mdc
3210 sync; sync_all_data || true
3211 if [ $qpool == "data" ]; then
3212 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3213 quota_error $qtype $qid "write failed, expect succeed"
3215 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3216 quota_error $qtype $qid "create failed, expect succeed"
3218 unlinkmany $TESTFILE $((LIMIT*2))
3223 wait_delete_completed || error "wait_delete_completed failed"
3224 sync_all_data || true
3225 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3226 error "reset default quota failed"
3227 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3228 error "reset quota failed"
3234 test_default_quota "-u" "data"
3235 test_default_quota "-u" "meta"
3236 test_default_quota "-g" "data"
3237 test_default_quota "-g" "meta"
3238 test_default_quota "-p" "data"
3239 test_default_quota "-p" "meta"
3241 run_test 61 "default quota tests"
3244 ! is_project_quota_supported &&
3245 skip "Project quota is not supported"
3246 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3247 skip "chattr did not support project quota"
3248 setup_quota_test || error "setup quota failed with $?"
3249 local testdir=$DIR/$tdir/
3251 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3252 change_project -s $testdir
3253 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3254 error "inherit attribute should be set"
3255 # chattr used FS_IOC_SETFLAGS ioctl
3256 $RUNAS chattr -P $testdir &&
3257 error "regular user clear inherit should fail"
3258 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3259 error "inherit attribute should still be set"
3260 chattr -P $testdir || error "root failed to clear inherit"
3261 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3262 error "inherit attribute should be cleared"
3265 run_test 62 "Project inherit should be only changed by root"
3268 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3269 skip "Not supported before 2.11.55" && return
3273 local dd_failed=false
3274 local tdir_dom=${tdir}_dom
3275 local LIMIT=20480 #20M
3277 [ $qtype == "p" ] && ! is_project_quota_supported &&
3278 echo "Project quota is not supported" && return 0
3280 [ $qtype == "p" ] && qid=$TSTPRJID
3282 setup_quota_test || error "setup quota failed with $?"
3283 trap cleanup_quota_test EXIT
3287 # enable mdt/ost quota
3288 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3289 set_ost_qtype $QTYPE || error "enable ost quota failed"
3291 # make sure the system is clean
3292 local USED=$(getquota -$qtype $qid global curspace)
3293 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3295 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3297 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3298 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3299 error "setstripe $tdir_dom failed"
3300 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3302 [ $qtype == "p" ] && {
3303 change_project -sp $TSTPRJID $DIR/$tdir
3304 change_project -sp $TSTPRJID $DIR/$tdir_dom
3307 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3308 error "set $qid quota failed"
3310 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3311 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3315 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3317 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3318 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3322 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3324 rm -f $DIR/$tdir_dom/*
3326 # flush cache, ensure noquota flag is set on client
3327 cancel_lru_locks osc
3328 cancel_lru_locks mdc
3329 sync; sync_all_data || true
3333 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3334 quota_error $qtype $qid "write failed, expect succeed"
3336 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3337 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3341 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3344 rm -f $DIR/$tdir_dom/*
3346 # flush cache, ensure noquota flag is set on client
3347 cancel_lru_locks osc
3348 cancel_lru_locks mdc
3349 sync; sync_all_data || true
3353 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3354 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3358 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3360 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3361 quota_error $qtype $qid "write succeed, expect EDQUOT"
3364 rm -fr $DIR/$tdir_dom
3366 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3367 error "reset usr quota failed"
3377 run_test 63 "quota on DoM tests"
3380 ! is_project_quota_supported &&
3381 skip "Project quota is not supported"
3382 setup_quota_test || error "setup quota failed with $?"
3383 local dir1="$DIR/$tdir/"
3386 ln -s $dir1/file $dir1/file_link
3388 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3389 error "set symlink file's project should fail"
3391 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3392 error "get symlink file's project should fail"
3396 run_test 64 "lfs project on symlink files should fail"
3400 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3401 if $PQ_CLEANUP; then
3402 disable_project_quota
3405 reset_quota_settings
3410 check_and_cleanup_lustre
3411 export QUOTA_AUTO=$QUOTA_AUTO_OLD