3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test:
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
31 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
32 . $LUSTRE/tests/test-framework.sh
34 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
36 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
38 require_dsh_mds || exit 0
39 require_dsh_ost || exit 0
41 # Does e2fsprogs support quota feature?
42 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
43 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
44 grep -q 'quota'"; then
45 skip_env "e2fsprogs doesn't support quota" && exit 0
48 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
49 # bug number for skipped test: LU-2836 LU-6836 LU-2836 LU-2059
50 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6 7d"
51 # bug number for skipped test: LU-5638
52 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
58 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW"
60 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
62 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
67 QUOTA_AUTO_OLD=$QUOTA_AUTO
70 check_and_setup_lustre
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
77 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
84 local fail_val=${3:-0}
88 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
89 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
90 ost) NODES="$(comma_list $(osts_nodes))";;
93 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
96 RUNAS="runas -u $TSTID -g $TSTID"
97 RUNAS2="runas -u $TSTID2 -g $TSTID2"
98 DD="dd if=/dev/zero bs=1M"
102 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
103 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
104 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
105 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
107 # clear quota limits for a user or a group
108 # usage: resetquota -u username
109 # resetquota -g groupname
112 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
113 [ "$1" != "-u" -a "$1" != "-g" ] &&
114 error "resetquota: wrong specifier $1 passed"
116 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
117 error "clear quota for [type:$1 name:$2] failed"
118 # give a chance to slave to release space
126 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
127 $LFS quota -v -u $LOCAL_ID $DIR
128 log "Files for user ($LOCAL_ID):"
129 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
130 xargs stat 2>/dev/null)
133 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
134 $LFS quota -v -g $LOCAL_ID $DIR
135 log "Files for group ($LOCAL_ID):"
136 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
153 # get quota for a user or a group
154 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
155 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
160 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
161 [ "$1" != "-u" -a "$1" != "-g" ] &&
162 error "getquota: wrong u/g specifier $1 passed"
175 *) error "unknown quota parameter $4";;
178 [ "$uuid" = "global" ] && uuid=$DIR
180 $LFS quota -v "$1" "$2" $DIR |
181 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
182 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
187 # usage: set_mdt_qtype ug|u|g|none
191 local mdts=$(get_facets MDS)
193 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
194 # we have to make sure each MDT received config changes
195 for mdt in ${mdts//,/ }; do
197 cmd="$LCTL get_param -n "
198 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
199 cmd=${cmd}.quota_slave.enabled
201 if $(facet_up $mdt); then
202 wait_update_facet $mdt "$cmd" "$qtype" || return 1
209 # usage: set_ost_qtype ug|u|g|none
213 local osts=$(get_facets OST)
215 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
216 # we have to make sure each OST received config changes
217 for ost in ${osts//,/ }; do
219 cmd="$LCTL get_param -n "
220 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
221 cmd=${cmd}.quota_slave.enabled
223 if $(facet_up $ost); then
224 wait_update_facet $ost "$cmd" "$qtype" || return 1
230 wait_reintegration() {
234 local result="glb[1],slv[1],reint[0]"
239 if [ $ntype == "mdt" ]; then
240 tgts=$(get_facets MDS)
242 tgts=$(get_facets OST)
245 for tgt in ${tgts//,/ }; do
247 cmd="$LCTL get_param -n "
248 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
249 cmd=${cmd}.quota_slave.info
251 if $(facet_up $tgt); then
252 wait_update_facet $tgt "$cmd |
253 grep "$qtype" | awk '{ print \\\$3 }'" \
254 "$result" $max || return 1
264 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
265 wait_reintegration "mdt" "user" $max || return 1
268 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
269 wait_reintegration "mdt" "group" $max || return 1
278 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
279 wait_reintegration "ost" "user" $max || return 1
282 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
283 wait_reintegration "ost" "group" $max || return 1
289 wait_delete_completed
290 echo "Creating test directory"
291 mkdir $DIR/$tdir || return 1
292 chmod 0777 $DIR/$tdir || return 2
293 # always clear fail_loc in case of fail_loc isn't cleared
294 # properly when previous test failed
295 lustre_fail mds_ost 0
298 cleanup_quota_test() {
300 echo "Delete files..."
302 echo "Wait for unlink objects finished..."
303 wait_delete_completed
304 sync_all_data || true
313 $LFS quota -v -$ug $qid $DIR
315 if [ "$bf" == "a" -o "$bf" == "b" ]; then
316 usage=$(getquota -$ug $qid global curspace)
317 if [ -z $usage ]; then
318 quota_error $ug $qid \
319 "Query block quota failed ($ug:$qid)."
321 [ $usage -ne 0 ] && quota_log $ug $qid \
322 "Block quota isn't 0 ($ug:$qid:$usage)."
326 if [ "$bf" == "a" -o "$bf" == "f" ]; then
327 usage=$(getquota -$ug $qid global curinodes)
328 if [ -z $usage ]; then
329 quota_error $ug $qid \
330 "Query file quota failed ($ug:$qid)."
332 [ $usage -ne 0 ] && quota_log $ug $qid \
333 "File quota isn't 0 ($ug:$qid:$usage)."
340 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
344 resetquota -u $TSTUSR
345 resetquota -g $TSTUSR
346 resetquota -u $TSTUSR2
347 resetquota -g $TSTUSR2
349 test_quota_performance() {
350 local TESTFILE="$DIR/$tdir/$tfile-0"
351 local size=$1 # in MB
352 local stime=$(date +%s)
353 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
354 quota_error u $TSTUSR "write failure"
355 local etime=$(date +%s)
356 delta=$((etime - stime))
357 if [ $delta -gt 0 ]; then
358 rate=$((size * 1024 / delta))
359 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
360 # LU-2872 - see LU-2887 for fix
362 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
364 [ $rate -gt 1024 ] ||
365 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
371 # test basic quota performance b=21696
374 [ "$SLOW" = "no" ] && MB=10
376 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
377 [ $free_space -le $((MB * 1024)) ] &&
378 skip "not enough space ${free_space} KB, " \
379 "required $((MB * 1024)) KB" && return
380 setup_quota_test || error "setup quota failed with $?"
381 trap cleanup_quota_test EXIT
383 set_ost_qtype "none" || error "disable ost quota failed"
384 test_quota_performance $MB
386 set_ost_qtype "ug" || error "enable ost quota failed"
387 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
388 error "set quota failed"
389 test_quota_performance $MB
392 resetquota -u $TSTUSR
394 run_test 0 "Test basic quota performance"
396 # test block hardlimit
399 local TESTFILE="$DIR/$tdir/$tfile-0"
401 setup_quota_test || error "setup quota failed with $?"
402 trap cleanup_quota_test EXIT
405 set_ost_qtype "ug" || error "enable ost quota failed"
408 log "User quota (block hardlimit:$LIMIT MB)"
409 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
410 error "set user quota failed"
412 # make sure the system is clean
413 local USED=$(getquota -u $TSTUSR global curspace)
414 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
416 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
417 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
420 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
421 quota_error u $TSTUSR "user write failure, but expect success"
422 log "Write out of block quota ..."
423 # this time maybe cache write, ignore it's failure
424 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
425 # flush cache, ensure noquota flag is set on client
427 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
428 quota_error u $TSTUSR "user write success, but expect EDQUOT"
431 wait_delete_completed || error "wait_delete_completed failed"
432 sync_all_data || true
433 USED=$(getquota -u $TSTUSR global curspace)
434 [ $USED -ne 0 ] && quota_error u $TSTUSR \
435 "user quota isn't released after deletion"
436 resetquota -u $TSTUSR
439 log "--------------------------------------"
440 log "Group quota (block hardlimit:$LIMIT MB)"
441 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
442 error "set group quota failed"
444 TESTFILE="$DIR/$tdir/$tfile-1"
445 # make sure the system is clean
446 USED=$(getquota -g $TSTUSR global curspace)
447 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
449 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
450 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
453 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
454 quota_error g $TSTUSR "group write failure, but expect success"
455 log "Write out of block quota ..."
456 # this time maybe cache write, ignore it's failure
457 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
459 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
460 quota_error g $TSTUSR "group write success, but expect EDQUOT"
465 USED=$(getquota -g $TSTUSR global curspace)
466 [ $USED -ne 0 ] && quota_error g $TSTUSR \
467 "group quota isn't released after deletion"
469 resetquota -g $TSTUSR
471 run_test 1 "Block hard limit (normal use and out of quota)"
473 # test inode hardlimit
475 local LIMIT=$((1024 * 1024)) # 1M inodes
476 local TESTFILE="$DIR/$tdir/$tfile-0"
478 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
480 local FREE_INODES=$(mdt_free_inodes 0)
481 echo "$FREE_INODES free inodes on master MDT"
482 [ $FREE_INODES -lt $LIMIT ] &&
483 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
486 setup_quota_test || error "setup quota failed with $?"
487 trap cleanup_quota_test EXIT
490 set_mdt_qtype "ug" || error "enable mdt quota failed"
493 log "User quota (inode hardlimit:$LIMIT files)"
494 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
495 error "set user quota failed"
497 # make sure the system is clean
498 local USED=$(getquota -u $TSTUSR global curinodes)
499 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
501 log "Create $LIMIT files ..."
502 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
503 quota_error u $TSTUSR "user create failure, but expect success"
504 log "Create out of file quota ..."
505 $RUNAS touch ${TESTFILE}_xxx &&
506 quota_error u $TSTUSR "user create success, but expect EDQUOT"
509 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
510 rm -f ${TESTFILE}_xxx
511 wait_delete_completed
513 USED=$(getquota -u $TSTUSR global curinodes)
514 [ $USED -ne 0 ] && quota_error u $TSTUSR \
515 "user quota isn't released after deletion"
516 resetquota -u $TSTUSR
519 log "--------------------------------------"
520 log "Group quota (inode hardlimit:$LIMIT files)"
521 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
522 error "set group quota failed"
524 TESTFILE=$DIR/$tdir/$tfile-1
525 # make sure the system is clean
526 USED=$(getquota -g $TSTUSR global curinodes)
527 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
529 log "Create $LIMIT files ..."
530 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
531 quota_error g $TSTUSR "group create failure, but expect success"
532 log "Create out of file quota ..."
533 $RUNAS touch ${TESTFILE}_xxx &&
534 quota_error g $TSTUSR "group create success, but expect EDQUOT"
537 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
538 rm -f ${TESTFILE}_xxx
539 wait_delete_completed
541 USED=$(getquota -g $TSTUSR global curinodes)
542 [ $USED -ne 0 ] && quota_error g $TSTUSR \
543 "user quota isn't released after deletion"
546 resetquota -g $TSTUSR
548 run_test 2 "File hard limit (normal use and out of quota)"
552 local TIMER=$(($2 * 3 / 2))
557 trap cleanup_quota_test EXIT
559 $SETSTRIPE $TESTFILE -c 1 -i 0
560 chown $TSTUSR.$TSTUSR $TESTFILE
562 echo "Write up to soft limit"
563 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
564 quota_error a $TSTUSR "write failure, but expect success"
565 OFFSET=$((LIMIT * 1024))
568 echo "Write to exceed soft limit"
569 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
570 quota_error a $TSTUSR "write failure, but expect success"
571 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
576 $SHOW_QUOTA_INFO_USER
577 $SHOW_QUOTA_INFO_GROUP
579 echo "Write before timer goes off"
580 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
581 quota_error a $TSTUSR "write failure, but expect success"
582 OFFSET=$((OFFSET + 1024))
585 echo "Sleep $TIMER seconds ..."
590 $SHOW_QUOTA_INFO_USER
591 $SHOW_QUOTA_INFO_GROUP
593 echo "Write after timer goes off"
594 # maybe cache write, ignore.
595 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
596 OFFSET=$((OFFSET + 1024))
598 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
599 quota_error a $TSTUSR "write success, but expect EDQUOT"
603 $SHOW_QUOTA_INFO_USER
604 $SHOW_QUOTA_INFO_GROUP
606 echo "Unlink file to stop timer"
608 wait_delete_completed
609 sync_all_data || true
613 $SHOW_QUOTA_INFO_USER
614 $SHOW_QUOTA_INFO_GROUP
616 $SETSTRIPE $TESTFILE -c 1 -i 0
617 chown $TSTUSR.$TSTUSR $TESTFILE
620 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
621 quota_error a $TSTUSR "write failure, but expect success"
630 local TESTFILE=$DIR/$tdir/$tfile-0
632 set_ost_qtype "ug" || error "enable ost quota failed"
634 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
635 # make sure the system is clean
636 local USED=$(getquota -u $TSTUSR global curspace)
637 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
639 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
640 $MAX_IQ_TIME $DIR || error "set user grace time failed"
641 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
642 error "set user quota failed"
644 test_block_soft $TESTFILE $GRACE $LIMIT
645 resetquota -u $TSTUSR
647 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
648 TESTFILE=$DIR/$tdir/$tfile-1
649 # make sure the system is clean
650 USED=$(getquota -g $TSTUSR global curspace)
651 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
653 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
654 $MAX_IQ_TIME $DIR || error "set group grace time failed"
655 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
656 error "set group quota failed"
658 test_block_soft $TESTFILE $GRACE $LIMIT
659 resetquota -g $TSTUSR
662 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
663 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
664 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
665 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
667 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
673 local TIMER=$(($grace * 3 / 2))
676 trap cleanup_quota_test EXIT
678 echo "Create files to exceed soft limit"
679 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
680 quota_error a $TSTUSR "create failure, but expect success"
681 local trigger_time=$(date +%s)
683 sync_all_data || true
685 local cur_time=$(date +%s)
686 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
687 error "Passed grace time $grace, $trigger_time, $cur_time"
689 echo "Create file before timer goes off"
690 $RUNAS touch ${TESTFILE}_before ||
691 quota_error a $TSTUSR "failed create before timer expired," \
692 "but expect success. $trigger_time, $cur_time"
693 sync_all_data || true
695 echo "Sleep $TIMER seconds ..."
700 $SHOW_QUOTA_INFO_USER
701 $SHOW_QUOTA_INFO_GROUP
703 echo "Create file after timer goes off"
704 # There is a window that space is accounted in the quota usage but
705 # hasn't been decreased from the pending write, if we acquire quota
706 # in this window, we'll acquire more than we needed.
707 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
708 sync_all_data || true
709 $RUNAS touch ${TESTFILE}_after_3 &&
710 quota_error a $TSTUSR "create after timer expired," \
712 sync_all_data || true
716 $SHOW_QUOTA_INFO_USER
717 $SHOW_QUOTA_INFO_GROUP
719 echo "Unlink files to stop timer"
720 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
721 wait_delete_completed
724 $RUNAS touch ${TESTFILE}_xxx ||
725 quota_error a $TSTUSR "touch after timer stop failure," \
727 sync_all_data || true
735 local LIMIT=10 # inodes
736 local TESTFILE=$DIR/$tdir/$tfile-0
739 set_mdt_qtype "ug" || error "enable mdt quota failed"
741 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
742 # make sure the system is clean
743 local USED=$(getquota -u $TSTUSR global curinodes)
744 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
746 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
747 $GRACE $DIR || error "set user grace time failed"
748 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
749 error "set user quota failed"
751 test_file_soft $TESTFILE $LIMIT $GRACE
752 resetquota -u $TSTUSR
754 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
755 # make sure the system is clean
756 USED=$(getquota -g $TSTUSR global curinodes)
757 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
759 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
760 $GRACE $DIR || error "set group grace time failed"
761 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
762 error "set group quota failed"
763 TESTFILE=$DIR/$tdir/$tfile-1
765 test_file_soft $TESTFILE $LIMIT $GRACE
766 resetquota -g $TSTUSR
769 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
770 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
771 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
772 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
774 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
778 local GR_STR2="1000s"
780 local GR_STR4="1w2d3h4m5s"
782 local GR_STR6="18446744073709551615"
785 wait_delete_completed
787 # test of valid grace strings handling
788 echo "Valid grace strings test"
789 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
790 $GR_STR2 $DIR || error "set user grace time failed"
791 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
792 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
793 $GR_STR4 $DIR || error "set group grace time quota failed"
794 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
796 # test of invalid grace strings handling
797 echo " Invalid grace strings test"
798 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
799 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
800 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
804 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
805 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
806 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
807 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
809 run_test 4b "Grace time strings handling"
811 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
813 local BLIMIT=10 # 10M
814 local ILIMIT=10 # 10 inodes
816 setup_quota_test || error "setup quota failed with $?"
817 trap cleanup_quota_test EXIT
819 set_mdt_qtype "ug" || error "enable mdt quota failed"
820 set_ost_qtype "ug" || error "enable ost quota failed"
822 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
823 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
824 error "set user quota failed"
825 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
826 error "set group quota failed"
828 # make sure the system is clean
829 local USED=$(getquota -u $TSTUSR global curinodes)
830 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
831 USED=$(getquota -g $TSTUSR global curinodes)
832 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
833 USED=$(getquota -u $TSTUSR global curspace)
834 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
835 USED=$(getquota -g $TSTUSR global curspace)
836 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
838 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
839 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
840 error "create failure, expect success"
841 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
842 error "write failure, expect success"
844 echo "Chown files to $TSTUSR.$TSTUSR ..."
845 for i in $(seq 0 $ILIMIT); do
846 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
847 quota_error a $TSTUSR "chown failure, expect success"
851 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
852 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
855 resetquota -u $TSTUSR
856 resetquota -g $TSTUSR
858 run_test 5 "Chown & chgrp successfully even out of block/file quota"
860 # test dropping acquire request on master
864 # Clear dmesg so watchdog is not triggered by previous
866 do_facet ost1 dmesg -c > /dev/null
868 setup_quota_test || error "setup quota failed with $?"
869 trap cleanup_quota_test EXIT
871 # make sure the system is clean
872 local USED=$(getquota -u $TSTUSR global curspace)
873 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
875 # make sure no granted quota on ost
876 set_ost_qtype "ug" || error "enable ost quota failed"
877 resetquota -u $TSTUSR
879 # create file for $TSTUSR
880 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
881 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
882 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
884 # create file for $TSTUSR2
885 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
886 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
887 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
889 # cache per-ID lock for $TSTUSR on slave
890 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
891 error "set quota failed"
892 $RUNAS $DD of=$TESTFILE count=1 ||
893 error "write $TESTFILE failure, expect success"
894 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
895 error "write $TESTFILE2 failure, expect success"
897 sync_all_data || true
899 #define QUOTA_DQACQ 601
900 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
901 lustre_fail mds 0x513 601
903 # write to un-enforced ID ($TSTUSR2) should succeed
904 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
905 error "write failure, expect success"
907 # write to enforced ID ($TSTUSR) in background, exceeding limit
908 # to make sure DQACQ is sent
909 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
912 # watchdog timer uses a factor of 2
913 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
914 sleep $((TIMEOUT * 2 + 1))
916 # write should be blocked and never finished
917 if ! ps -p $DDPID > /dev/null 2>&1; then
919 error "write finished incorrectly!"
924 # no watchdog is triggered
925 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
926 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
927 { print; }' $TMP/lustre-log-${TESTNAME}.log)
928 [ -z "$watchdog" ] || error "$watchdog"
930 rm -f $TMP/lustre-log-${TESTNAME}.log
932 # write should continue then fail with EDQUOT
936 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
937 if [ $count -ge 240 ]; then
938 quota_error u $TSTUSR "dd not finished in $count secs"
941 if [ $((count % 30)) -eq 0 ]; then
942 c_size=$(stat -c %s $TESTFILE)
943 echo "Waiting $count secs. $c_size"
950 resetquota -u $TSTUSR
952 run_test 6 "Test dropping acquire request on master"
954 # quota reintegration (global index)
956 local TESTFILE=$DIR/$tdir/$tfile
959 [ "$SLOW" = "no" ] && LIMIT=5
961 setup_quota_test || error "setup quota failed with $?"
962 trap cleanup_quota_test EXIT
964 # make sure the system is clean
965 local USED=$(getquota -u $TSTUSR global curspace)
966 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
968 # make sure no granted quota on ost1
969 set_ost_qtype "ug" || error "enable ost quota failed"
970 resetquota -u $TSTUSR
971 set_ost_qtype "none" || error "disable ost quota failed"
973 local OSTUUID=$(ostuuid_from_index 0)
974 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
976 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
979 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
980 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
985 echo "Enable quota & set quota limit for $TSTUSR"
986 set_ost_qtype "ug" || error "enable ost quota failed"
987 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
988 error "set quota failed"
991 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
994 wait_ost_reint "ug" || error "reintegration failed"
996 # hardlimit should have been fetched by slave during global
997 # reintegration, write will exceed quota
998 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
999 quota_error u $TSTUSR "write success, but expect EDQUOT"
1002 wait_delete_completed
1003 sync_all_data || true
1009 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1010 error "clear quota failed"
1012 echo "Start ost1..."
1013 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1016 wait_ost_reint "ug" || error "reintegration failed"
1018 # hardlimit should be cleared on slave during reintegration
1019 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1020 quota_error u $TSTUSR "write error, but expect success"
1023 resetquota -u $TSTUSR
1025 run_test 7a "Quota reintegration (global index)"
1027 # quota reintegration (slave index)
1030 local TESTFILE=$DIR/$tdir/$tfile
1032 setup_quota_test || error "setup quota failed with $?"
1033 trap cleanup_quota_test EXIT
1035 # make sure the system is clean
1036 local USED=$(getquota -u $TSTUSR global curspace)
1037 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1039 # make sure no granted quota on ost1
1040 set_ost_qtype "ug" || error "enable ost quota failed"
1041 resetquota -u $TSTUSR
1042 set_ost_qtype "none" || error "disable ost quota failed"
1044 local OSTUUID=$(ostuuid_from_index 0)
1045 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1047 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1050 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1051 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1053 # consume some space to make sure the granted space will not
1054 # be released during reconciliation
1055 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1056 error "consume space failure, expect success"
1058 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1059 lustre_fail mds 0xa02
1061 set_ost_qtype "ug" || error "enable ost quota failed"
1062 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1063 error "set quota failed"
1065 # ignore the write error
1066 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1068 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1072 echo "Restart ost to trigger reintegration..."
1074 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1077 wait_ost_reint "ug" || error "reintegration failed"
1079 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1080 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1083 resetquota -u $TSTUSR
1086 run_test 7b "Quota reintegration (slave index)"
1088 # quota reintegration (restart mds during reintegration)
1090 local LIMIT=20 # 20M
1091 local TESTFILE=$DIR/$tdir/$tfile
1093 [ "$SLOW" = "no" ] && LIMIT=5
1095 setup_quota_test || error "setup quota failed with $?"
1096 trap cleanup_quota_test EXIT
1098 # make sure the system is clean
1099 local USED=$(getquota -u $TSTUSR global curspace)
1100 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1102 set_ost_qtype "none" || error "disable ost quota failed"
1103 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1104 error "set quota failed"
1106 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1107 lustre_fail ost 0xa03
1110 set_ost_qtype "ug" || error "enable ost quota failed"
1111 # trigger reintegration
1112 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1113 procf=${procf}quota_slave.force_reint
1114 do_facet ost1 $LCTL set_param $procf=1 ||
1115 error "force reintegration failed"
1123 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1126 # wait longer than usual to make sure the reintegration
1127 # is triggered by quota wb thread.
1128 wait_ost_reint "ug" 200 || error "reintegration failed"
1130 # hardlimit should have been fetched by slave during global
1131 # reintegration, write will exceed quota
1132 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1133 quota_error u $TSTUSR "write success, but expect EDQUOT"
1136 resetquota -u $TSTUSR
1138 run_test 7c "Quota reintegration (restart mds during reintegration)"
1140 # Quota reintegration (Transfer index in multiple bulks)
1142 local TESTFILE=$DIR/$tdir/$tfile
1143 local TESTFILE1="$DIR/$tdir/$tfile"-1
1146 setup_quota_test || error "setup quota failed with $?"
1147 trap cleanup_quota_test EXIT
1149 set_ost_qtype "none" || error "disable ost quota failed"
1150 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1151 error "set quota for $TSTUSR failed"
1152 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1153 error "set quota for $TSTUSR2 failed"
1155 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1156 lustre_fail mds 0x608 0
1158 # enable quota to tirgger reintegration
1159 set_ost_qtype "u" || error "enable ost quota failed"
1160 wait_ost_reint "u" || error "reintegration failed"
1164 # hardlimit should have been fetched by slave during global
1165 # reintegration, write will exceed quota
1166 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1167 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1169 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1170 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1173 resetquota -u $TSTUSR
1174 resetquota -u $TSTUSR2
1176 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1178 # quota reintegration (inode limits)
1180 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1182 local ilimit=$((1024 * 2)) # 2k inodes
1183 local TESTFILE=$DIR/${tdir}-1/$tfile
1185 setup_quota_test || error "setup quota failed with $?"
1186 trap cleanup_quota_test EXIT
1188 # make sure the system is clean
1189 local USED=$(getquota -u $TSTUSR global curinodes)
1190 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1192 # make sure no granted quota on mdt1
1193 set_mdt_qtype "ug" || error "enable mdt quota failed"
1194 resetquota -u $TSTUSR
1195 set_mdt_qtype "none" || error "disable mdt quota failed"
1197 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1198 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1199 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1202 echo "Stop mds${MDSCOUNT}..."
1205 echo "Enable quota & set quota limit for $TSTUSR"
1206 set_mdt_qtype "ug" || error "enable mdt quota failed"
1207 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1208 error "set quota failed"
1210 echo "Start mds${MDSCOUNT}..."
1211 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1214 wait_mdt_reint "ug" || error "reintegration failed"
1216 echo "create remote dir"
1217 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1218 error "create remote dir failed"
1219 chmod 0777 $DIR/${tdir}-1
1221 # hardlimit should have been fetched by slave during global
1222 # reintegration, create will exceed quota
1223 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1224 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1226 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1227 wait_delete_completed
1228 sync_all_data || true
1230 echo "Stop mds${MDSCOUNT}..."
1233 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1234 error "clear quota failed"
1236 echo "Start mds${MDSCOUNT}..."
1237 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1240 wait_mdt_reint "ug" || error "reintegration failed"
1242 # hardlimit should be cleared on slave during reintegration
1243 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1244 quota_error -u $TSTUSR "create failed, expect success"
1246 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1247 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1250 resetquota -u $TSTUSR
1252 run_test 7e "Quota reintegration (inode limits)"
1254 # run dbench with quota enabled
1256 local BLK_LIMIT="100g" #100G
1257 local FILE_LIMIT=1000000
1259 setup_quota_test || error "setup quota failed with $?"
1260 trap cleanup_quota_test EXIT
1262 set_mdt_qtype "ug" || error "enable mdt quota failed"
1263 set_ost_qtype "ug" || error "enable ost quota failed"
1265 echo "Set enough high limit for user: $TSTUSR"
1266 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1267 error "set user quota failed"
1268 echo "Set enough high limit for group: $TSTUSR"
1269 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1270 error "set group quota failed"
1273 [ "$SLOW" = "no" ] && duration=" -t 120"
1274 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1275 quota_error a $TSTUSR "dbench failed!"
1278 resetquota -u $TSTUSR
1279 resetquota -g $TSTUSR
1281 run_test 8 "Run dbench with quota enabled"
1283 # this check is just for test_9
1284 OST0_MIN=4900000 #4.67G
1286 check_whether_skip () {
1287 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1288 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1289 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1290 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1297 # run for fixing bug10707, it needs a big room. test for 64bit
1299 local filesize=$((1024 * 9 / 2)) # 4.5G
1301 check_whether_skip && return 0
1303 setup_quota_test || error "setup quota failed with $?"
1304 trap cleanup_quota_test EXIT
1306 set_ost_qtype "ug" || error "enable ost quota failed"
1308 local TESTFILE="$DIR/$tdir/$tfile-0"
1309 local BLK_LIMIT=100G #100G
1310 local FILE_LIMIT=1000000
1312 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1314 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1316 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1317 error "set user quota failed"
1319 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1320 "for group: $TSTUSR"
1321 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1322 error "set group quota failed"
1324 quota_show_check a u $TSTUSR
1325 quota_show_check a g $TSTUSR
1327 echo "Create test file"
1328 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1329 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1331 log "Write the big file of 4.5G ..."
1332 $RUNAS $DD of=$TESTFILE count=$filesize ||
1333 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1339 resetquota -u $TSTUSR
1340 resetquota -g $TSTUSR
1345 run_test 9 "Block limit larger than 4GB (b10707)"
1348 local TESTFILE=$DIR/$tdir/$tfile
1350 setup_quota_test || error "setup quota failed with $?"
1351 trap cleanup_quota_test EXIT
1353 # set limit to root user should fail
1354 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1355 error "set limit for root user successfully, expect failure"
1356 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1357 error "set limit for root group successfully, expect failure"
1359 # root user can overrun quota
1360 set_ost_qtype "ug" || error "enable ost quota failed"
1362 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1363 error "set quota failed"
1364 quota_show_check b u $TSTUSR
1366 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1367 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1369 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1370 error "write failure, expect success"
1373 resetquota -u $TSTUSR
1375 run_test 10 "Test quota for root user"
1378 local TESTFILE=$DIR/$tdir/$tfile
1379 setup_quota_test || error "setup quota failed with $?"
1380 trap cleanup_quota_test EXIT
1382 set_mdt_qtype "ug" || error "enable mdt quota failed"
1383 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1384 error "set quota failed"
1386 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1387 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1389 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1390 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1393 local USED=$(getquota -u $TSTUSR global curinodes)
1394 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1397 resetquota -u $TSTUSR
1399 run_test 11 "Chown/chgrp ignores quota"
1402 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1404 local blimit=22 # 22M
1405 local blk_cnt=$((blimit - 5))
1406 local TESTFILE0="$DIR/$tdir/$tfile"-0
1407 local TESTFILE1="$DIR/$tdir/$tfile"-1
1409 setup_quota_test || error "setup quota failed with $?"
1410 trap cleanup_quota_test EXIT
1412 set_ost_qtype "u" || error "enable ost quota failed"
1413 quota_show_check b u $TSTUSR
1415 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1416 error "set quota failed"
1418 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1419 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1420 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1421 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1423 echo "Write to ost0..."
1424 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1425 quota_error a $TSTUSR "dd failed"
1427 echo "Write to ost1..."
1428 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1429 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1431 echo "Free space from ost0..."
1433 wait_delete_completed
1434 sync_all_data || true
1436 echo "Write to ost1 after space freed from ost0..."
1437 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1438 quota_error a $TSTUSR "rebalancing failed"
1441 resetquota -u $TSTUSR
1443 run_test 12a "Block quota rebalancing"
1446 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1448 local ilimit=$((1024 * 2)) # 2k inodes
1449 local TESTFILE0=$DIR/$tdir/$tfile
1450 local TESTFILE1=$DIR/${tdir}-1/$tfile
1452 setup_quota_test || error "setup quota failed with $?"
1453 trap cleanup_quota_test EXIT
1455 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1456 chmod 0777 $DIR/${tdir}-1
1458 set_mdt_qtype "u" || error "enable mdt quota failed"
1459 quota_show_check f u $TSTUSR
1461 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1462 error "set quota failed"
1464 echo "Create $ilimit files on mdt0..."
1465 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1466 quota_error u $TSTUSR "create failed, but expect success"
1468 echo "Create files on mdt1..."
1469 $RUNAS createmany -m $TESTFILE1 1 &&
1470 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1472 echo "Free space from mdt0..."
1473 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1474 wait_delete_completed
1475 sync_all_data || true
1477 echo "Create files on mdt1 after space freed from mdt0..."
1478 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1479 quota_error a $TSTUSR "rebalancing failed"
1481 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1482 error "unlink mdt1 files failed"
1483 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1486 resetquota -u $TSTUSR
1488 run_test 12b "Inode quota rebalancing"
1491 local TESTFILE=$DIR/$tdir/$tfile
1492 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1493 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1495 setup_quota_test || error "setup quota failed with $?"
1496 trap cleanup_quota_test EXIT
1498 set_ost_qtype "u" || error "enable ost quota failed"
1499 quota_show_check b u $TSTUSR
1501 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1502 error "set quota failed"
1503 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1504 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1506 # clear the locks in cache first
1507 do_facet ost1 $LCTL set_param -n $procf=clear
1508 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1509 [ $nlock -eq 0 ] || error "$nlock cached locks"
1511 # write to acquire the per-ID lock
1512 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1513 quota_error a $TSTUSR "dd failed"
1515 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1516 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1518 # clear quota doesn't trigger per-ID lock cancellation
1519 resetquota -u $TSTUSR
1520 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1521 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1523 # clear the per-ID lock
1524 do_facet ost1 $LCTL set_param -n $procf=clear
1525 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1526 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1528 # spare quota should be released
1529 local OSTUUID=$(ostuuid_from_index 0)
1530 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1531 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1532 [ $limit -le $space ] ||
1533 error "spare quota isn't released, limit:$limit, space:$space"
1537 run_test 13 "Cancel per-ID lock in the LRU list"
1540 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1542 wait_delete_completed
1543 sync_all_data || true
1546 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1547 error "set user quota failed"
1548 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1549 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1550 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1551 resetquota -u $TSTUSR
1554 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1555 error "set group quota failed"
1556 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1557 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1558 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1559 resetquota -g $TSTUSR
1561 run_test 15 "Set over 4T block quota"
1565 local BLKS=1 # 1M less than limit
1566 local TESTFILE=$DIR/$tdir/$tfile
1568 setup_quota_test || error "setup quota failed with $?"
1569 trap cleanup_quota_test EXIT
1571 # make sure the system is clean
1572 local USED=$(getquota -u $TSTUSR global curspace)
1573 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1575 set_ost_qtype "ug" || error "enable ost quota failed"
1576 # make sure no granted quota on ost
1577 resetquota -u $TSTUSR
1578 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1579 error "set quota failed"
1581 quota_show_check b u $TSTUSR
1583 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1584 lustre_fail mds 0xa04 $err_code
1586 # write in background
1587 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1591 # write should be blocked and never finished
1592 if ! ps -p $DDPID > /dev/null 2>&1; then
1594 quota_error u $TSTUSR "write finished incorrectly!"
1602 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1604 if [ $count -gt $timeout ]; then
1605 quota_error u $TSTUSR "dd is not finished!"
1610 sync; sync_all_data || true
1612 USED=$(getquota -u $TSTUSR global curspace)
1613 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1614 "Used space(${USED}K) is less than ${BLKS}M"
1617 resetquota -u $TSTUSR
1620 # DQACQ return recoverable error
1622 echo "DQACQ return -ENOLCK"
1624 test_17sub 37 || error "Handle -ENOLCK failed"
1626 echo "DQACQ return -EAGAIN"
1628 test_17sub 11 || error "Handle -EAGAIN failed"
1630 echo "DQACQ return -ETIMEDOUT"
1631 #define ETIMEDOUT 110
1632 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1634 echo "DQACQ return -ENOTCONN"
1635 #define ENOTCONN 107
1636 test_17sub 107 || error "Handle -ENOTCONN failed"
1639 run_test 17 "DQACQ return recoverable error"
1643 local blimit="200m" # 200M
1644 local TESTFILE="$DIR/$tdir/$tfile"
1646 setup_quota_test || error "setup quota failed with $?"
1647 trap cleanup_quota_test EXIT
1649 set_ost_qtype "u" || error "enable ost quota failed"
1650 log "User quota (limit: $blimit)"
1651 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1652 error "set quota failed"
1653 quota_show_check b u $TSTUSR
1655 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1656 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1658 local timeout=$(sysctl -n lustre.timeout)
1660 if [ $io_type = "directio" ]; then
1661 log "Write 100M (directio) ..."
1662 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1664 log "Write 100M (buffered) ..."
1665 $RUNAS $DD of=$TESTFILE count=100 &
1669 replay_barrier $SINGLEMDS
1670 log "Fail mds for $((2 * timeout)) seconds"
1671 fail $SINGLEMDS $((2 * timeout))
1674 if at_is_enabled; then
1675 timeout=$(at_max_get mds)
1677 timeout=$(lctl get_param -n timeout)
1681 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1682 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1683 log "it took $count second"
1688 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1690 cancel_lru_locks mdc
1691 cancel_lru_locks osc
1694 local testfile_size=$(stat -c %s $TESTFILE)
1695 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1696 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1697 "got ${testfile_size}. Verifying file failed!"
1700 resetquota -u $TSTUSR
1703 # test when mds does failover, the ost still could work well
1704 # this test shouldn't trigger watchdog b=14840
1706 # Clear dmesg so watchdog is not triggered by previous
1708 do_facet ost1 dmesg -c > /dev/null
1711 test_18_sub directio
1713 # check if watchdog is triggered
1714 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1715 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1716 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1717 [ -z "$watchdog" ] || error "$watchdog"
1718 rm -f $TMP/lustre-log-${TESTNAME}.log
1720 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1724 local TESTFILE=$DIR/$tdir/$tfile
1726 setup_quota_test || error "setup quota failed with $?"
1727 trap cleanup_quota_test EXIT
1729 set_ost_qtype "ug" || error "enable ost quota failed"
1731 # bind file to a single OST
1732 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1733 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1735 echo "Set user quota (limit: ${blimit}M)"
1736 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1737 error "set user quota failed"
1738 quota_show_check b u $TSTUSR
1739 echo "Update quota limits"
1740 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1741 error "set group quota failed"
1742 quota_show_check b u $TSTUSR
1744 # first wirte might be cached
1745 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1746 cancel_lru_locks osc
1748 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1749 quota_error u $TSTUSR "Write success, expect failure"
1753 resetquota -u $TSTUSR
1755 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1757 test_20() { # b15754
1758 local LSTR=(2g 1t 4k 3m) # limits strings
1760 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
1763 resetquota -u $TSTUSR
1765 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1766 $MOUNT || error "could not set quota limits"
1767 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1768 --inode-softlimit ${LSTR[2]} \
1769 --inode-hardlimit ${LSTR[3]} \
1770 $MOUNT || error "could not set quota limits"
1772 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1773 error "bsoftlimit was not set properly"
1774 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1775 error "bhardlimit was not set properly"
1776 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1777 error "isoftlimit was not set properly"
1778 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1779 error "ihardlimit was not set properly"
1781 resetquota -u $TSTUSR
1783 run_test 20 "Test if setquota specifiers work properly (b15754)"
1790 local time=$(($(date +%s) + seconds))
1791 while [ $(date +%s) -lt $time ]; do
1792 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1796 # run for fixing bug16053, setquota shouldn't fail when writing and
1797 # deleting are happening
1799 local TESTFILE="$DIR/$tdir/$tfile"
1800 local BLIMIT=10 # 10G
1801 local ILIMIT=1000000
1803 setup_quota_test || error "setup quota failed with $?"
1804 trap cleanup_quota_test EXIT
1806 set_ost_qtype "ug" || error "Enable ost quota failed"
1808 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1809 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1810 error "set user quota failed"
1811 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1812 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1813 error "set group quota failed"
1815 # repeat writing on a 1M file
1816 test_21_sub ${TESTFILE}_1 1 30 &
1818 # repeat writing on a 128M file
1819 test_21_sub ${TESTFILE}_2 128 30 &
1822 local time=$(($(date +%s) + 30))
1824 while [ $(date +%s) -lt $time ]; do
1825 log "Set quota for $i times"
1826 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1827 -I $((ILIMIT + i)) $MOUNT ||
1828 error "Set user quota failed"
1829 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1830 -I $((ILIMIT + i)) $MOUNT ||
1831 error "Set group quota failed"
1838 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1840 if [ $count -gt 60 ]; then
1841 quota_error a $TSTUSR "dd should be finished!"
1845 echo "(dd_pid=$DDPID1, time=$count)successful"
1849 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1851 if [ $count -gt 60 ]; then
1852 quota_error a $TSTUSR "dd should be finished!"
1856 echo "(dd_pid=$DDPID2, time=$count)successful"
1859 resetquota -u $TSTUSR
1860 resetquota -g $TSTUSR
1862 run_test 21 "Setquota while writing & deleting (b16053)"
1864 # enable/disable quota enforcement permanently
1866 echo "Set both mdt & ost quota type as ug"
1867 set_mdt_qtype "ug" || error "enable mdt quota failed"
1868 set_ost_qtype "ug" || error "enable ost quota failed"
1871 stopall || error "failed to stopall (1)"
1875 echo "Verify if quota is enabled"
1876 local qtype=$(mdt_quota_type)
1877 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1878 qtype=$(ost_quota_type)
1879 [ $qtype != "ug" ] && error "ost quota setting is lost"
1881 echo "Set both mdt & ost quota type as none"
1882 set_mdt_qtype "none" || error "disable mdt quota failed"
1883 set_ost_qtype "none" || error "disable ost quota failed"
1886 stopall || error "failed to stopall (2)"
1891 echo "Verify if quota is disabled"
1892 qtype=$(mdt_quota_type)
1893 [ $qtype != "none" ] && error "mdt quota setting is lost"
1894 qtype=$(ost_quota_type)
1895 [ $qtype != "none" ] && error "ost quota setting is lost"
1899 run_test 22 "enable/disable quota by 'lctl conf_param'"
1902 local TESTFILE="$DIR/$tdir/$tfile"
1905 setup_quota_test || error "setup quota failed with $?"
1906 trap cleanup_quota_test EXIT
1908 set_ost_qtype "ug" || error "Enable ost quota failed"
1911 log "User quota (limit: $LIMIT MB)"
1912 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1913 error "set quota failed"
1914 quota_show_check b u $TSTUSR
1916 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1917 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1919 log "Step1: trigger EDQUOT with O_DIRECT"
1920 log "Write half of file"
1921 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1922 quota_error u $TSTUSR "(1) Write failure, expect success." \
1924 log "Write out of block quota ..."
1925 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1926 oflag=direct conv=notrunc &&
1927 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1931 log "Step2: rewrite should succeed"
1932 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1933 quota_error u $TSTUSR "(3) Write failure, expect success." \
1939 local OST0_UUID=$(ostuuid_from_index 0)
1940 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1941 [ $OST0_QUOTA_USED -ne 0 ] &&
1942 ($SHOW_QUOTA_USER; \
1943 quota_error u $TSTUSR "quota isn't released")
1945 resetquota -u $TSTUSR
1949 [ $(facet_fstype ost1) == "zfs" ] &&
1950 skip "Overwrite in place is not guaranteed to be " \
1951 "space neutral on ZFS" && return
1953 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1954 check_whether_skip && return 0
1955 log "run for 4MB test file"
1958 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1959 check_whether_skip && return 0
1960 log "run for 40MB test file"
1963 run_test 23 "Quota should be honored with directIO (b16125)"
1967 local TESTFILE="$DIR/$tdir/$tfile"
1969 setup_quota_test || error "setup quota failed with $?"
1970 trap cleanup_quota_test EXIT
1972 set_ost_qtype "ug" || error "enable ost quota failed"
1974 # bind file to a single OST
1975 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1976 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1978 echo "Set user quota (limit: ${blimit}M)"
1979 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1980 error "set quota failed"
1982 # overrun quota by root user
1983 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1984 error "write failure, expect success"
1985 cancel_lru_locks osc
1986 sync_all_data || true
1988 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1991 resetquota -u $TSTUSR
1993 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1995 test_27a() { # b19612
1996 $LFS quota $TSTUSR $DIR &&
1997 error "lfs succeeded with no type, but should have failed"
1998 $LFS setquota $TSTUSR $DIR &&
1999 error "lfs succeeded with no type, but should have failed"
2002 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2004 test_27b() { # b20200
2005 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2006 error "lfs setquota failed with uid argument"
2007 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2008 error "lfs stequota failed with gid argument"
2009 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2010 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2011 resetquota -u $TSTUSR
2012 resetquota -g $TSTUSR
2015 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2020 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2021 error "lfs setquota failed"
2023 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2024 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2025 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2026 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2028 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2029 error "lfs setquota for $TSTID failed"
2031 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2032 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2033 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2034 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2036 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2037 error "total allocated inode/block limit not printed"
2039 resetquota -u $TSTUSR
2041 run_test 27c "lfs quota should support human-readable output"
2048 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2049 error "set fraction block limit failed"
2050 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2051 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2052 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2053 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2055 resetquota -u $TSTUSR
2057 run_test 27d "lfs setquota should support fraction block limit"
2061 local TESTFILE="$DIR/$tdir/$tfile"
2064 setup_quota_test || error "setup quota failed with $?"
2065 trap cleanup_quota_test EXIT
2067 set_ost_qtype "u" || error "enable ost quota failed"
2069 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2070 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2072 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2073 $MAX_IQ_TIME $DIR || error "set grace time failed"
2074 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2075 error "set quota failed"
2076 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2077 cancel_lru_locks osc
2079 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2080 # over-quota flag has not yet settled since we do not trigger async
2081 # events based on grace time period expiration
2083 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2084 cancel_lru_locks osc
2085 # now over-quota flag should be settled and further writes should fail
2087 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2088 error "grace times were reset"
2091 resetquota -u $TSTUSR
2092 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2093 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2095 run_test 30 "Hard limit updates should not reset grace times"
2097 # basic usage tracking for user & group
2099 local INODES=10 # 10 files
2100 local BLK_CNT=2 # of 2M each
2101 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2103 setup_quota_test || error "setup quota failed with $?"
2104 trap cleanup_quota_test EXIT
2106 # make sure the system is clean
2107 local USED=$(getquota -u $TSTID global curspace)
2109 error "Used space ($USED) for user $TSTID isn't 0."
2110 USED=$(getquota -g $TSTID global curspace)
2112 error "Used space ($USED) for group $TSTID isn't 0."
2114 echo "Write files..."
2115 for i in $(seq 0 $INODES); do
2116 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2117 error "write failed"
2118 echo "Iteration $i/$INODES completed"
2120 cancel_lru_locks osc
2121 sync; sync_all_data || true
2123 echo "Verify disk usage after write"
2124 USED=$(getquota -u $TSTID global curspace)
2125 [ $USED -lt $TOTAL_BLKS ] &&
2126 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2127 USED=$(getquota -g $TSTID global curspace)
2128 [ $USED -lt $TOTAL_BLKS ] &&
2129 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2131 echo "Verify inode usage after write"
2132 USED=$(getquota -u $TSTID global curinodes)
2133 [ $USED -lt $INODES ] &&
2134 error "Used inode for user $TSTID is $USED, expected $INODES"
2135 USED=$(getquota -g $TSTID global curinodes)
2136 [ $USED -lt $INODES ] &&
2137 error "Used inode for group $TSTID is $USED, expected $INODES"
2141 echo "Verify disk usage after delete"
2142 USED=$(getquota -u $TSTID global curspace)
2143 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2144 USED=$(getquota -u $TSTID global curinodes)
2145 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2146 USED=$(getquota -g $TSTID global curspace)
2147 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2148 USED=$(getquota -g $TSTID global curinodes)
2149 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2151 run_test 33 "Basic usage tracking for user & group"
2153 # usage transfer test for user & group
2155 local BLK_CNT=2 # 2MB
2157 setup_quota_test || error "setup quota failed with $?"
2158 trap cleanup_quota_test EXIT
2160 # make sure the system is clean
2161 local USED=$(getquota -u $TSTID global curspace)
2162 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2163 USED=$(getquota -g $TSTID global curspace)
2164 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2166 local USED=$(getquota -u $TSTID2 global curspace)
2167 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2169 echo "Write file..."
2170 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2171 error "write failed"
2172 cancel_lru_locks osc
2173 sync; sync_all_data || true
2175 echo "chown the file to user $TSTID"
2176 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2178 echo "Wait for setattr on objects finished..."
2179 wait_delete_completed
2181 BLK_CNT=$((BLK_CNT * 1024))
2183 echo "Verify disk usage for user $TSTID"
2184 USED=$(getquota -u $TSTID global curspace)
2185 [ $USED -lt $BLK_CNT ] &&
2186 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2187 USED=$(getquota -u $TSTID global curinodes)
2189 error "Used inodes for user $TSTID is $USED, expected 1"
2191 echo "chgrp the file to group $TSTID"
2192 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2194 echo "Wait for setattr on objects finished..."
2195 wait_delete_completed
2197 echo "Verify disk usage for group $TSTID"
2198 USED=$(getquota -g $TSTID global curspace)
2199 [ $USED -ge $BLK_CNT ] ||
2200 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2201 USED=$(getquota -g $TSTID global curinodes)
2203 error "Used inodes for group $TSTID is $USED, expected 1"
2205 # chown won't change the ost object group. LU-4345 */
2206 echo "chown the file to user $TSTID2"
2207 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2209 echo "Wait for setattr on objects finished..."
2210 wait_delete_completed
2212 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2213 USED=$(getquota -u $TSTID2 global curspace)
2214 [ $USED -lt $BLK_CNT ] &&
2215 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2216 USED=$(getquota -u $TSTID global curspace)
2218 error "Used space for user $TSTID is $USED, expected 0"
2219 USED=$(getquota -g $TSTID global curspace)
2220 [ $USED -lt $BLK_CNT ] &&
2221 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2225 run_test 34 "Usage transfer for user & group"
2227 # usage is still accessible across restart
2229 local BLK_CNT=2 # 2 MB
2231 setup_quota_test || error "setup quota failed with $?"
2232 trap cleanup_quota_test EXIT
2234 echo "Write file..."
2235 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2236 error "write failed"
2237 cancel_lru_locks osc
2238 sync; sync_all_data || true
2240 echo "Save disk usage before restart"
2241 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2242 [ $ORIG_USR_SPACE -eq 0 ] &&
2243 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2244 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2245 [ $ORIG_USR_INODES -eq 0 ] &&
2246 error "Used inodes for user $TSTID is 0, expected 1"
2247 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2248 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2249 [ $ORIG_GRP_SPACE -eq 0 ] &&
2250 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2251 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2252 [ $ORIG_GRP_INODES -eq 0 ] &&
2253 error "Used inodes for group $TSTID is 0, expected 1"
2254 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2257 local ORIG_REFORMAT=$REFORMAT
2259 cleanup_and_setup_lustre
2260 REFORMAT=$ORIG_REFORMAT
2263 echo "Verify disk usage after restart"
2264 local USED=$(getquota -u $TSTID global curspace)
2265 [ $USED -eq $ORIG_USR_SPACE ] ||
2266 error "Used space for user $TSTID changed from " \
2267 "$ORIG_USR_SPACE to $USED"
2268 USED=$(getquota -u $TSTID global curinodes)
2269 [ $USED -eq $ORIG_USR_INODES ] ||
2270 error "Used inodes for user $TSTID changed from " \
2271 "$ORIG_USR_INODES to $USED"
2272 USED=$(getquota -g $TSTID global curspace)
2273 [ $USED -eq $ORIG_GRP_SPACE ] ||
2274 error "Used space for group $TSTID changed from " \
2275 "$ORIG_GRP_SPACE to $USED"
2276 USED=$(getquota -g $TSTID global curinodes)
2277 [ $USED -eq $ORIG_GRP_INODES ] ||
2278 error "Used inodes for group $TSTID changed from " \
2279 "$ORIG_GRP_INODES to $USED"
2281 # check if the vfs_dq_init() is called before writing
2282 echo "Append to the same file..."
2283 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2284 error "write failed"
2285 cancel_lru_locks osc
2286 sync; sync_all_data || true
2288 echo "Verify space usage is increased"
2289 USED=$(getquota -u $TSTID global curspace)
2290 [ $USED -gt $ORIG_USR_SPACE ] ||
2291 error "Used space for user $TSTID isn't increased" \
2292 "orig:$ORIG_USR_SPACE, now:$USED"
2293 USED=$(getquota -g $TSTID global curspace)
2294 [ $USED -gt $ORIG_GRP_SPACE ] ||
2295 error "Used space for group $TSTID isn't increased" \
2296 "orig:$ORIG_GRP_SPACE, now:$USED"
2300 run_test 35 "Usage is still accessible across reboot"
2302 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2305 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2306 skip "Old server doesn't have LU-5006 fix." && return
2308 setup_quota_test || error "setup quota failed with $?"
2309 trap cleanup_quota_test EXIT
2311 # make sure the system is clean
2312 local USED=$(getquota -u $TSTID global curspace)
2314 error "Used space ($USED) for user $TSTID isn't 0."
2316 # create file with MDS_OPEN_DELAY_CREATE flag
2317 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2318 error "Create file failed"
2320 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2321 oflag=sync || error "Write file failed"
2323 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2325 # wait for setattr on objects finished..."
2326 wait_delete_completed
2328 USED=$(getquota -u $TSTID global curspace)
2329 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2333 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2337 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2343 check_and_cleanup_lustre
2344 export QUOTA_AUTO=$QUOTA_AUTO_OLD