3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
33 TSTID=${TSTID:-"$(id -u $TSTUSR)"}
34 TSTID2=${TSTID2:-"$(id -u $TSTUSR2)"}
35 TSTPRJID=${TSTPRJID:-1000}
40 VERSION_WITH_QP="2.13.53"
42 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
43 skip "Needs MDS version $VERSION_WITH_QP or later."
46 require_dsh_mds || exit 0
47 require_dsh_ost || exit 0
49 # Does e2fsprogs support quota feature?
50 if [ "$mds1_FSTYPE" == ldiskfs ] &&
51 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
52 grep -q 'quota'"; then
53 skip_env "e2fsprogs doesn't support quota"
56 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
58 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
63 QUOTA_AUTO_OLD=$QUOTA_AUTO
66 check_and_setup_lustre
68 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
70 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
71 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
72 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
73 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
74 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
75 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
76 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
77 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
82 local fail_val=${3:-0}
86 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
87 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
88 ost) NODES="$(comma_list $(osts_nodes))";;
91 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
97 lfs project $* || error "lfs project $* failed"
100 RUNAS="runas -u $TSTID -g $TSTID"
101 RUNAS2="runas -u $TSTID2 -g $TSTID2"
102 DD="dd if=/dev/zero bs=1M"
106 # clear quota limits for a user or a group
107 # usage: resetquota -u username
108 # resetquota -g groupname
109 # resetquota -p projid
112 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
113 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
114 error "resetquota: wrong specifier $1 passed"
116 if [ $1 == "-p" ]; then
117 is_project_quota_supported || return 0
120 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
121 error "clear quota for [type:$1 name:$2] failed"
122 # give a chance to slave to release space
131 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
132 $LFS quota -v -u $local_id $DIR
133 count=$($LFS find --user $local_id $DIR | wc -l)
134 log "Files for user ($local_id), count=$count:"
135 ($LFS find --user $local_id $DIR | head -n 4 |
136 xargs stat 2>/dev/null)
139 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
140 $LFS quota -v -g $local_id $DIR
141 count=$($LFS find --group $local_id $DIR | wc -l)
142 log "Files for group ($local_id), count=$count:"
143 ($LFS find --group $local_id $DIR | head -n 4 |
144 xargs stat 2>/dev/null)
147 is_project_quota_supported || return 0
148 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
149 $LFS quota -v -p $TSTPRJID $DIR
150 count=$($LFS find --projid $TSTPRJID $DIR | wc -l)
151 log "Files for project ($TSTPRJID), count=$count:"
152 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
153 xargs stat 2>/dev/null)
169 # get quota for a user or a group
170 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
171 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
178 sync_all_data > /dev/null 2>&1 || true
180 [ "$#" != 4 -a "$#" != 5 ] &&
181 error "getquota: wrong number of arguments: $#"
182 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
183 error "getquota: wrong u/g/p specifier $1 passed"
196 *) error "unknown quota parameter $4";;
199 [ ! -z "$5" ] && pool_arg="--pool $5 "
200 [ "$uuid" = "global" ] && uuid=$DIR
202 $LFS quota -v "$1" "$2" $pool_arg $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.enabled=$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.enabled=$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
340 local extrasleep=${4:-5}
347 *) error "get_grace_time: Invalid quota type: $qtype"
352 echo "Quota info for $pool:"
353 $LFS quota -$qtype $qarg $parg $DIR
358 time=$(lfs quota -$qtype $qarg $parg $DIR|
359 awk 'NR == 3{ print $5 }')
362 time=$(lfs quota -$qtype $qarg $DIR|
363 awk 'NR == 3{ print $9 }')
366 error "Unknown quota type: $flavour"
370 local sleep_seconds=0
371 local orig_time=$time
373 echo "Grace time is $time"
374 # from lfs.c:__sec2str()
375 # const char spec[] = "smhdw";
376 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
377 [[ $time == *w* ]] && w_time=${time%w*} &&
378 let sleep_seconds+=$((w_time*7*24*60*60));
380 [[ $time == *d* ]] && d_time=${time%d*} &&
381 let sleep_seconds+=$((d_time*24*60*60));
383 [[ $time == *h* ]] && h_time=${time%h*} &&
384 let sleep_seconds+=$((h_time*60*60));
386 [[ $time == *m* ]] && m_time=${time%m*} &&
387 let sleep_seconds+=$((m_time*60));
389 [[ $time == *s* ]] && s_time=${time%s*} &&
390 let sleep_seconds+=$s_time
392 echo "Sleep through grace ..."
393 [ "$orig_time" == "-" ] &&
394 error "Grace timeout was not set or quota not exceeded"
395 if [ "$orig_time" == "expired" -o "$orig_time" == "none" ]; then
396 echo "...Grace timeout already expired"
398 let sleep_seconds+=$extrasleep
399 echo "...sleep $sleep_seconds seconds"
405 wait_delete_completed
406 echo "Creating test directory"
407 mkdir_on_mdt0 $DIR/$tdir || return 1
408 chmod 0777 $DIR/$tdir || return 2
409 # always clear fail_loc in case of fail_loc isn't cleared
410 # properly when previous test failed
411 lustre_fail mds_ost 0
412 stack_trap cleanup_quota_test EXIT
415 cleanup_quota_test() {
416 echo "Delete files..."
418 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
419 echo "Wait for unlink objects finished..."
420 wait_delete_completed
421 sync_all_data || true
431 $LFS quota -v -$ugp $qid $DIR
433 if [ "$bf" == "a" -o "$bf" == "b" ]; then
434 usage=$(getquota -$ugp $qid global curspace)
435 if [ -z $usage ]; then
436 quota_error $ugp $qid \
437 "Query block quota failed ($ugp:$qid)."
439 [ $usage -ne 0 ] && quota_log $ugp $qid \
440 "Block quota isn't 0 ($ugp:$qid:$usage)."
444 if [ "$bf" == "a" -o "$bf" == "f" ]; then
445 usage=$(getquota -$ugp $qid global curinodes)
446 if [ -z $usage ]; then
447 quota_error $ugp $qid \
448 "Query file quota failed ($ugp:$qid)."
450 [ $usage -ne 0 ] && quota_log $ugp $qid \
451 "File quota isn't 0 ($ugp:$qid:$usage)."
456 project_quota_enabled () {
458 local zfeat="feature@project_quota"
460 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
461 local facet_fstype=${facet:0:3}1_FSTYPE
464 if [ "${!facet_fstype}" = "zfs" ]; then
465 devname=$(zpool_name ${facet})
466 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
467 grep -wq active || rc=1
469 [ ${facet:0:3} == "mds" ] &&
470 devname=$(mdsdevname ${facet:3}) ||
471 devname=$(ostdevname ${facet:3})
472 do_facet ${facet} $DEBUGFS -R features $devname |
473 grep -q project || rc=1
476 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
480 project_quota_enabled || enable_project_quota
482 reset_quota_settings() {
483 resetquota -u $TSTUSR
485 resetquota -g $TSTUSR
487 resetquota -u $TSTUSR2
488 resetquota -u $TSTID2
489 resetquota -g $TSTUSR2
490 resetquota -g $TSTID2
491 resetquota -p $TSTPRJID
496 do_nodes $(comma_list $(nodes_list)) \
497 "$LCTL set_param -n debug=+quota+trace"
502 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
503 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
504 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
505 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
507 test_quota_performance() {
508 local TESTFILE="$DIR/$tdir/$tfile-0"
509 local size=$1 # in MB
510 local stime=$(date +%s)
511 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
512 quota_error u $TSTUSR "write failure"
513 local etime=$(date +%s)
514 delta=$((etime - stime))
515 if [ $delta -gt 0 ]; then
516 rate=$((size * 1024 / delta))
517 if [ "$mds1_FSTYPE" = zfs ]; then
518 # LU-2872 - see LU-2887 for fix
520 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
522 [ $rate -gt 1024 ] ||
523 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
529 # test basic quota performance b=21696
532 [ "$SLOW" = "no" ] && MB=10
534 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
535 [ $free_space -le $((MB * 1024)) ] &&
536 skip "not enough space ${free_space} KB, " \
537 "required $((MB * 1024)) KB"
538 setup_quota_test || error "setup quota failed with $?"
540 set_ost_qtype "none" || error "disable ost quota failed"
541 test_quota_performance $MB
543 set_ost_qtype $QTYPE || error "enable ost quota failed"
544 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
545 error "set quota failed"
546 test_quota_performance $MB
548 run_test 0 "Test basic quota performance"
550 # usage: test_1_check_write tfile user|group|project
551 test_1_check_write() {
555 local short_qtype=${qtype:0:1}
558 $RUNAS $DD of=$testfile count=$((limit/2)) ||
559 quota_error $short_qtype $TSTUSR \
560 "$qtype write failure, but expect success"
561 log "Write out of block quota ..."
562 # this time maybe cache write, ignore it's failure
563 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
564 # flush cache, ensure noquota flag is set on client
566 sync; sync_all_data || true
567 # sync means client wrote all it's cache, but id doesn't
568 # guarantee that slave received new edquot through glimpse.
569 # so wait a little to be sure slave got it.
571 $RUNAS $DD of=$testfile count=1 seek=$limit &&
572 quota_error $short_qtype $TSTUSR \
573 "user write success, but expect EDQUOT"
577 check_write_fallocate() {
581 local short_qtype=${qtype:0:1}
584 log "Write ${count}MiB Using Fallocate"
585 $RUNAS fallocate -l${count}MiB $testfile ||
586 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
589 sync; sync_all_data || true
593 log "Write ${count}MiB Using Fallocate"
594 $RUNAS fallocate -l${count}MiB $testfile &&
595 quota_error $short_qtype $TSTUSR \
596 "Write success, expect EDQUOT" || true
599 # test block hardlimit
602 local testfile="$DIR/$tdir/$tfile-0"
604 setup_quota_test || error "setup quota failed with $?"
607 set_ost_qtype $QTYPE || error "enable ost quota failed"
610 log "User quota (block hardlimit:$limit MB)"
611 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
612 error "set user quota failed"
614 # make sure the system is clean
615 local used=$(getquota -u $TSTUSR global curspace)
616 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
618 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
619 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
621 test_1_check_write $testfile "user" $limit
624 wait_delete_completed || error "wait_delete_completed failed"
625 sync_all_data || true
626 used=$(getquota -u $TSTUSR global curspace)
627 [ $used -ne 0 ] && quota_error u $TSTUSR \
628 "user quota isn't released after deletion"
629 resetquota -u $TSTUSR
632 log "--------------------------------------"
633 log "Group quota (block hardlimit:$limit MB)"
634 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
635 error "set group quota failed"
637 testfile="$DIR/$tdir/$tfile-1"
638 # make sure the system is clean
639 used=$(getquota -g $TSTUSR global curspace)
640 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
642 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
643 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
645 test_1_check_write $testfile "group" $limit
647 wait_delete_completed || error "wait_delete_completed failed"
648 sync_all_data || true
649 used=$(getquota -g $TSTUSR global curspace)
650 [ $used -ne 0 ] && quota_error g $TSTUSR \
651 "Group quota isn't released after deletion"
652 resetquota -g $TSTUSR
654 if ! is_project_quota_supported; then
655 echo "Project quota is not supported"
659 testfile="$DIR/$tdir/$tfile-2"
660 # make sure the system is clean
661 used=$(getquota -p $TSTPRJID global curspace)
663 error "used space($used) for project $TSTPRJID isn't 0"
666 log "--------------------------------------"
667 log "Project quota (block hardlimit:$limit mb)"
668 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
669 error "set project quota failed"
671 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
672 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
673 change_project -p $TSTPRJID $testfile
675 test_1_check_write $testfile "project" $limit
680 used=$(getquota -p $TSTPRJID global curspace)
681 [ $used -ne 0 ] && quota_error p $TSTPRJID \
682 "project quota isn't released after deletion"
684 resetquota -p $TSTPRJID
686 run_test 1a "Block hard limit (normal use and out of quota)"
690 local global_limit=20 # MB
691 local testfile="$DIR/$tdir/$tfile-0"
695 setup_quota_test || error "setup quota failed with $?"
698 set_ost_qtype $QTYPE || error "enable ost quota failed"
701 log "User quota (block hardlimit:$global_limit MB)"
702 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
703 error "set user quota failed"
705 pool_add $qpool || error "pool_add failed"
706 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
707 error "pool_add_targets failed"
709 # check qmt_pool_add dmesg error
710 local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
712 dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
713 [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
715 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
716 error "set user quota failed"
718 # make sure the system is clean
719 local used=$(getquota -u $TSTUSR global curspace)
721 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
723 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
725 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
726 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
728 test_1_check_write $testfile "user" $limit
731 wait_delete_completed || error "wait_delete_completed failed"
732 sync_all_data || true
733 used=$(getquota -u $TSTUSR global curspace $qpool)
734 [ $used -ne 0 ] && quota_error u $TSTUSR \
735 "user quota isn't released after deletion"
736 resetquota -u $TSTUSR
739 log "--------------------------------------"
740 log "Group quota (block hardlimit:$global_limit MB)"
741 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
742 error "set group quota failed"
744 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
745 error "set group quota failed"
747 testfile="$DIR/$tdir/$tfile-1"
748 # make sure the system is clean
749 used=$(getquota -g $TSTUSR global curspace $qpool)
750 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
752 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
753 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
755 test_1_check_write $testfile "group" $limit
758 wait_delete_completed || error "wait_delete_completed failed"
759 sync_all_data || true
760 used=$(getquota -g $TSTUSR global curspace $qpool)
761 [ $used -ne 0 ] && quota_error g $TSTUSR \
762 "Group quota isn't released after deletion"
763 resetquota -g $TSTUSR
765 if ! is_project_quota_supported; then
766 echo "Project quota is not supported"
770 testfile="$DIR/$tdir/$tfile-2"
771 # make sure the system is clean
772 used=$(getquota -p $TSTPRJID global curspace $qpool)
774 error "used space($used) for project $TSTPRJID isn't 0"
777 log "--------------------------------------"
778 log "Project quota (block hardlimit:$global_limit mb)"
779 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
780 error "set project quota failed"
782 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
783 error "set project quota failed"
786 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
787 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
788 change_project -p $TSTPRJID $testfile
790 test_1_check_write $testfile "project" $limit
795 used=$(getquota -p $TSTPRJID global curspace)
796 [ $used -eq 0 ] || quota_error p $TSTPRJID \
797 "project quota isn't released after deletion"
799 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
802 local global_limit=20 # MB
803 local testfile="$DIR/$tdir/$tfile-0"
804 local qpool1="qpool1"
805 local qpool2="qpool2"
808 setup_quota_test || error "setup quota failed with $?"
811 set_ost_qtype $QTYPE || error "enable ost quota failed"
814 log "User quota (block hardlimit:$global_limit MB)"
815 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
816 error "set user quota failed"
818 pool_add $qpool1 || error "pool_add failed"
819 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
820 error "pool_add_targets failed"
822 pool_add $qpool2 || error "pool_add failed"
823 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
824 error "pool_add_targets failed"
826 # create pools without hard limit
827 # initially such case raised several bugs
828 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
829 error "set user quota failed"
831 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
832 error "set user quota failed"
834 # make sure the system is clean
835 local used=$(getquota -u $TSTUSR global curspace)
837 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
839 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
841 test_1_check_write $testfile "user" $global_limit
843 used=$(getquota -u $TSTUSR global curspace $qpool1)
844 echo "qpool1 used $used"
845 used=$(getquota -u $TSTUSR global curspace $qpool2)
846 echo "qpool2 used $used"
849 wait_delete_completed || error "wait_delete_completed failed"
850 sync_all_data || true
852 used=$(getquota -u $TSTUSR global curspace $qpool1)
853 [ $used -eq 0 ] || quota_error u $TSTUSR \
854 "user quota isn't released after deletion"
856 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
861 local global_limit=20 # MB
862 local testfile="$DIR/$tdir/$tfile-0"
863 local qpool1="qpool1"
864 local qpool2="qpool2"
867 setup_quota_test || error "setup quota failed with $?"
870 set_ost_qtype $QTYPE || error "enable ost quota failed"
873 log "User quota (block hardlimit:$global_limit MB)"
874 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
875 error "set user quota failed"
877 pool_add $qpool1 || error "pool_add failed"
878 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
879 error "pool_add_targets failed"
881 pool_add $qpool2 || error "pool_add failed"
882 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
883 error "pool_add_targets failed"
885 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
886 error "set user quota failed"
888 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
889 error "set user quota failed"
891 # make sure the system is clean
892 local used=$(getquota -u $TSTUSR global curspace)
894 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
896 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
898 test_1_check_write $testfile "user" $limit1
900 used=$(getquota -u $TSTUSR global curspace $qpool1)
901 echo "qpool1 used $used"
902 used=$(getquota -u $TSTUSR global curspace $qpool2)
903 echo "qpool2 used $used"
906 wait_delete_completed || error "wait_delete_completed failed"
907 sync_all_data || true
909 used=$(getquota -u $TSTUSR global curspace $qpool1)
910 [ $used -eq 0 ] || quota_error u $TSTUSR \
911 "user quota isn't released after deletion"
913 run_test 1d "Quota pools: check block hardlimit on different pools"
917 local global_limit=53000000 # MB
918 local testfile="$DIR/$tdir/$tfile-0"
919 local testfile2="$DIR/$tdir/$tfile-1"
920 local qpool1="qpool1"
923 setup_quota_test || error "setup quota failed with $?"
926 set_ost_qtype $QTYPE || error "enable ost quota failed"
928 # global_limit is much greater than limit1 to get
929 # different qunit's on osts. Since 1st qunit shrinking
930 # on OST1(that belongs to qpool1), this qunit should
932 log "User quota (block hardlimit:$global_limit MB)"
933 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
934 error "set user quota failed"
936 pool_add $qpool1 || error "pool_add failed"
937 pool_add_targets $qpool1 1 1 ||
938 error "pool_add_targets failed"
940 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
941 error "set user quota failed"
943 # make sure the system is clean
944 local used=$(getquota -u $TSTUSR global curspace)
945 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
947 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
948 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
950 test_1_check_write $testfile "user" $limit1
952 $LFS setstripe $testfile2 -c 1 -i 0 ||
953 error "setstripe $testfile2 failed"
954 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
955 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
957 $RUNAS $DD of=$testfile2 count=20 ||
958 quota_error u $TSTUSR \
959 "$qtype write failure, but expect success"
963 wait_delete_completed || error "wait_delete_completed failed"
964 sync_all_data || true
966 used=$(getquota -u $TSTUSR global curspace $qpool1)
967 [ $used -eq 0 ] || quota_error u $TSTUSR \
968 "user quota isn't released after deletion"
970 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
973 local global_limit=200 # MB
975 local TESTDIR="$DIR/$tdir/"
976 local testfile="$TESTDIR/$tfile-0"
977 local qpool1="qpool1"
980 setup_quota_test || error "setup quota failed with $?"
983 set_ost_qtype $QTYPE || error "enable ost quota failed"
985 log "User quota (block hardlimit:$global_limit MB)"
986 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
987 error "set user quota failed"
989 pool_add $qpool1 || error "pool_add failed"
990 pool_add_targets $qpool1 0 0 ||
991 error "pool_add_targets failed"
993 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
994 error "set user quota failed"
996 # make sure the system is clean
997 local used=$(getquota -u $TSTUSR global curspace)
998 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1000 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1002 test_1_check_write $testfile "user" $limit1
1004 pool_remove_target $qpool1 0
1006 wait_delete_completed || error "wait_delete_completed failed"
1007 sync_all_data || true
1009 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1010 # qunit for appropriate element in lgd array should be set
1011 # correctly(4096). Earlier it was not changed continuing to be 1024.
1012 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1013 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1014 # as it already was 1024. As flag "need_update" for this qunit was
1015 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1016 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1017 # became > 10M. QMT returned EINPROGRESS in a loop.
1018 # Check that it doesn't hung anymore.
1019 test_1_check_write $testfile "user" $limit1
1021 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1025 local global_limit=40 # MB
1026 local testfile="$DIR/$tdir/$tfile-0"
1027 local qpool="qpool1"
1028 local mdmb_param="osc.*.max_dirty_mb"
1029 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1032 setup_quota_test || error "setup quota failed with $?"
1033 $LCTL set_param $mdmb_param=1
1034 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1037 set_ost_qtype $QTYPE || error "enable ost quota failed"
1040 log "User quota (block hardlimit:$global_limit MB)"
1041 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1042 error "set user quota failed"
1044 pool_add $qpool || error "pool_add failed"
1045 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1046 error "pool_add_targets failed"
1048 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1049 error "set user quota failed"
1051 # make sure the system is clean
1052 local used=$(getquota -u $TSTUSR global curspace)
1054 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1056 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1057 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1060 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1061 quota_error u $TSTUSR \
1062 "$qtype write failure, but expect success"
1063 log "Write out of block quota ..."
1064 # this time maybe cache write, ignore it's failure
1065 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1066 # flush cache, ensure noquota flag is set on client
1067 cancel_lru_locks osc
1068 sync; sync_all_data || true
1070 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1071 quota_error u $TSTUSR \
1072 "user write success, but expect EDQUOT"
1075 wait_delete_completed || error "wait_delete_completed failed"
1076 sync_all_data || true
1078 used=$(getquota -u $TSTUSR global curspace $qpool)
1079 [ $used -ne 0 ] && quota_error u $TSTUSR \
1080 "user quota isn't released after deletion"
1083 run_test 1g "Quota pools: Block hard limit with wide striping"
1087 local testfile="$DIR/$tdir/$tfile-0"
1089 check_set_fallocate_or_skip
1091 setup_quota_test || error "setup quota failed with $?"
1094 set_ost_qtype $QTYPE || error "enable ost quota failed"
1097 log "User quota (block hardlimit:$limit MB)"
1098 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1099 error "set user quota failed"
1101 # make sure the system is clean
1102 local used=$(getquota -u $TSTUSR global curspace)
1103 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1105 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1106 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1108 check_write_fallocate $testfile "user" $limit
1111 wait_delete_completed || error "wait_delete_completed failed"
1112 sync_all_data || true
1113 used=$(getquota -u $TSTUSR global curspace)
1114 [ $used -eq 0 ] || quota_error u $TSTUSR \
1115 "user quota isn't released after deletion"
1117 run_test 1h "Block hard limit test using fallocate"
1120 local global_limit=200 # 200M
1121 local limit1=10 # 10M
1122 local TESTDIR="$DIR/$tdir/"
1123 local testfile="$TESTDIR/$tfile-0"
1124 local testfile1="$TESTDIR/$tfile-1"
1125 local testfile2="$TESTDIR/$tfile-2"
1126 local qpool1="qpool1"
1129 setup_quota_test || error "setup quota failed with $?"
1130 stack_trap cleanup_quota_test EXIT
1133 set_ost_qtype $QTYPE || error "enable ost quota failed"
1135 log "User quota (block hardlimit:$global_limit MB)"
1136 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1137 error "set user quota failed"
1139 pool_add $qpool1 || error "pool_add failed"
1140 pool_add_targets $qpool1 0 0 ||
1141 error "pool_add_targets failed"
1143 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1144 error "set user quota failed"
1146 # make sure the system is clean
1147 local used=$(getquota -u $TSTUSR global curspace)
1148 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1150 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1153 test_1_check_write $testfile "user" $limit1
1154 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1155 error "set user quota failed"
1157 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1158 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1159 quota_error u $TSTUSR "write failure, but expect success"
1163 wait_delete_completed || error "wait_delete_completed failed"
1164 sync_all_data || true
1166 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1167 error "set user quota failed"
1168 test_1_check_write $testfile "user" $limit1
1169 local tmp_limit=$(($limit1*2))
1170 # increase pool limit
1171 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1172 error "set user quota failed"
1173 # now write shouldn't fail
1174 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1175 quota_error u $TSTUSR "write failure, but expect success"
1176 # decrease pool limit
1177 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1178 error "set user quota failed"
1179 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1180 # flush cache, ensure noquota flag is set on client
1181 cancel_lru_locks osc
1182 sync; sync_all_data || true
1183 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1184 quota_error u $TSTUSR "write success, but expect failure"
1187 run_test 1i "Quota pools: different limit and usage relations"
1189 # test inode hardlimit
1191 local testfile="$DIR/$tdir/$tfile-0"
1192 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1193 qmt.$FSNAME-QMT0000.md-0x0.info |
1194 sed -e 's/least qunit/least_qunit/' |
1195 awk '/least_qunit/{ print $2 }')
1198 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1199 limit=$((least_qunit * 1024))
1200 echo "least_qunit: '$least_qunit', limit: '$limit'"
1202 local free_inodes=$(mdt_free_inodes 0)
1203 echo "$free_inodes free inodes on master MDT"
1204 [ $free_inodes -lt $limit ] &&
1205 skip "not enough free inodes $free_inodes required $limit"
1207 setup_quota_test || error "setup quota failed with $?"
1210 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1213 log "User quota (inode hardlimit:$limit files)"
1214 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1215 error "set user quota failed"
1217 # make sure the system is clean
1218 local used=$(getquota -u $TSTUSR global curinodes)
1219 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1221 log "Create $((limit - least_qunit)) files ..."
1222 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1223 quota_error u $TSTUSR "user create failure, but expect success"
1224 # it is ok, if it fails on the last qunit
1225 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1226 log "Create out of file quota ..."
1227 $RUNAS touch ${testfile}_xxx &&
1228 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1231 unlinkmany ${testfile} $((limit - least_qunit)) ||
1232 error "unlinkmany $testfile failed"
1233 # if 2nd createmany got EDQUOT, not all of nodes would be created
1234 unlinkmany ${testfile}_yyy $least_qunit || true
1235 rm -f ${testfile}_xxx
1236 wait_delete_completed
1238 used=$(getquota -u $TSTUSR global curinodes)
1239 [ $used -ne 0 ] && quota_error u $TSTUSR \
1240 "user quota isn't released after deletion"
1241 resetquota -u $TSTUSR
1244 log "--------------------------------------"
1245 log "Group quota (inode hardlimit:$limit files)"
1246 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1247 error "set group quota failed"
1249 testfile=$DIR/$tdir/$tfile-1
1250 # make sure the system is clean
1251 used=$(getquota -g $TSTUSR global curinodes)
1252 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1254 log "Create $limit files ..."
1255 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1256 quota_error g $TSTUSR "group create failure, but expect success"
1257 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1258 log "Create out of file quota ..."
1259 $RUNAS touch ${testfile}_xxx &&
1260 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1263 unlinkmany ${testfile} $((limit - least_qunit)) ||
1264 error "unlinkmany $testfile failed"
1265 unlinkmany ${testfile}_yyy $least_qunit || true
1266 rm -f ${testfile}_xxx
1267 wait_delete_completed
1269 used=$(getquota -g $TSTUSR global curinodes)
1270 [ $used -ne 0 ] && quota_error g $TSTUSR \
1271 "user quota isn't released after deletion"
1273 resetquota -g $TSTUSR
1274 ! is_project_quota_supported &&
1275 echo "Skip project quota is not supported" && return 0
1278 log "--------------------------------------"
1279 log "Project quota (inode hardlimit:$limit files)"
1280 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1281 error "set project quota failed"
1283 testfile=$DIR/$tdir/$tfile-1
1284 # make sure the system is clean
1285 used=$(getquota -p $TSTPRJID global curinodes)
1287 error "Used inodes($used) for project $TSTPRJID isn't 0"
1289 change_project -sp $TSTPRJID $DIR/$tdir
1290 log "Create $limit files ..."
1291 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1292 quota_error p $TSTPRJID \
1293 "project create fail, but expect success"
1294 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1295 log "Create out of file quota ..."
1296 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1297 "project create success, but expect EDQUOT"
1298 change_project -C $DIR/$tdir
1301 used=$(getquota -p $TSTPRJID global curinodes)
1302 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1303 "project quota isn't released after deletion"
1306 run_test 2 "File hard limit (normal use and out of quota)"
1315 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1316 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1320 $LFS setstripe $testfile -c 1 -i 0
1321 chown $TSTUSR.$TSTUSR $testfile
1322 [ "$qtype" == "p" ] && is_project_quota_supported &&
1323 change_project -p $TSTPRJID $testfile
1325 echo "Write up to soft limit"
1326 $RUNAS $DD of=$testfile count=$limit ||
1327 quota_error a $TSTUSR "write failure, but expect success"
1328 OFFSET=$((limit * 1024))
1329 cancel_lru_locks osc
1331 echo "Write to exceed soft limit"
1332 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1333 quota_error a $TSTUSR "write failure, but expect success"
1334 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1335 cancel_lru_locks osc
1337 echo "mmap write when over soft limit"
1338 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1339 quota_error a $TSTUSR "mmap write failure, but expect success"
1340 cancel_lru_locks osc
1345 $SHOW_QUOTA_INFO_USER
1346 $SHOW_QUOTA_INFO_GROUP
1347 $SHOW_QUOTA_INFO_PROJID
1349 echo "Write before timer goes off"
1350 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1351 quota_error a $TSTUSR "write failure, but expect success"
1352 OFFSET=$((OFFSET + 1024))
1353 cancel_lru_locks osc
1355 wait_grace_time $qtype "block" $pool
1360 $SHOW_QUOTA_INFO_USER
1361 $SHOW_QUOTA_INFO_GROUP
1362 $SHOW_QUOTA_INFO_PROJID
1364 log "Write after timer goes off"
1365 # maybe cache write, ignore.
1366 # write up to soft least quint to consume all
1367 # possible slave granted space.
1368 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1369 count=$soft_limit seek=$OFFSET || true
1370 OFFSET=$((OFFSET + soft_limit))
1371 cancel_lru_locks osc
1372 log "Write after cancel lru locks"
1373 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1374 quota_error a $TSTUSR "write success, but expect EDQUOT"
1379 $SHOW_QUOTA_INFO_USER
1380 $SHOW_QUOTA_INFO_GROUP
1381 $SHOW_QUOTA_INFO_PROJID
1383 echo "Unlink file to stop timer"
1385 wait_delete_completed
1386 sync_all_data || true
1391 $SHOW_QUOTA_INFO_USER
1392 $SHOW_QUOTA_INFO_GROUP
1393 $SHOW_QUOTA_INFO_PROJID
1395 $LFS setstripe $testfile -c 1 -i 0
1396 chown $TSTUSR.$TSTUSR $testfile
1397 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1400 $RUNAS $DD of=$testfile count=$limit ||
1401 quota_error a $TSTUSR "write failure, but expect success"
1408 local grace=20 # seconds
1409 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1412 local testfile=$DIR/$tdir/$tfile-0
1414 # get minimum soft qunit size
1415 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1416 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1418 set_ost_qtype $QTYPE || error "enable ost quota failed"
1420 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1421 # make sure the system is clean
1422 local used=$(getquota -u $TSTUSR global curspace)
1423 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1425 $LFS setquota -t -u --block-grace $grace --inode-grace \
1426 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1427 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1428 error "set user quota failed"
1430 test_block_soft $testfile $grace $limit "u"
1432 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1433 testfile=$DIR/$tdir/$tfile-1
1434 # make sure the system is clean
1435 used=$(getquota -g $TSTUSR global curspace)
1436 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1438 $LFS setquota -t -g --block-grace $grace --inode-grace \
1439 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1440 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1441 error "set group quota failed"
1443 test_block_soft $testfile $grace $limit "g"
1445 if is_project_quota_supported; then
1446 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1447 testfile=$DIR/$tdir/$tfile-2
1448 # make sure the system is clean
1449 used=$(getquota -p $TSTPRJID global curspace)
1450 [ $used -ne 0 ] && error \
1451 "Used space($used) for project $TSTPRJID isn't 0."
1453 $LFS setquota -t -p --block-grace $grace --inode-grace \
1454 $MAX_IQ_TIME $DIR ||
1455 error "set project grace time failed"
1456 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1457 $DIR || error "set project quota failed"
1459 test_block_soft $testfile $grace $limit "p"
1460 resetquota -p $TSTPRJID
1461 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1462 $MAX_IQ_TIME $DIR ||
1463 error "restore project grace time failed"
1467 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1468 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1469 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1470 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1472 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1475 local grace=20 # seconds
1476 local qpool="qpool1"
1477 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1480 local testfile=$DIR/$tdir/$tfile-0
1483 # get minimum soft qunit size
1484 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1485 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1486 local glbl_limit=$((2*limit))
1487 local glbl_grace=$((2*grace))
1488 echo "limit $limit glbl_limit $glbl_limit"
1489 echo "grace $grace glbl_grace $glbl_grace"
1491 set_ost_qtype $QTYPE || error "enable ost quota failed"
1493 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1494 # make sure the system is clean
1495 local used=$(getquota -u $TSTUSR global curspace)
1496 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1498 pool_add $qpool || error "pool_add failed"
1499 pool_add_targets $qpool 0 1 ||
1500 error "pool_add_targets failed"
1502 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1503 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1504 $LFS setquota -t -u --block-grace $grace \
1505 --pool $qpool $DIR || error "set user grace time failed"
1507 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1508 error "set user quota failed"
1509 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1510 error "set user quota failed"
1512 test_block_soft $testfile $grace $limit "u" $qpool
1514 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1515 testfile=$DIR/$tdir/$tfile-1
1516 # make sure the system is clean
1517 used=$(getquota -g $TSTUSR global curspace)
1518 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1520 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1521 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1522 $LFS setquota -t -g --block-grace $grace \
1523 --pool $qpool $DIR || error "set group grace time failed"
1525 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1526 error "set group quota failed"
1527 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1528 error "set group quota failed"
1530 test_block_soft $testfile $grace $limit "g" $qpool
1532 if is_project_quota_supported; then
1533 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1534 testfile=$DIR/$tdir/$tfile-2
1535 # make sure the system is clean
1536 used=$(getquota -p $TSTPRJID global curspace)
1537 [ $used -ne 0 ] && error \
1538 "Used space($used) for project $TSTPRJID isn't 0."
1540 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1541 $MAX_IQ_TIME $DIR ||
1542 error "set project grace time failed"
1543 $LFS setquota -t -p --block-grace $grace \
1544 --pool $qpool $DIR ||
1545 error "set project grace time failed"
1547 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1548 $DIR || error "set project quota failed"
1549 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1550 --pool $qpool $DIR || error "set project quota failed"
1552 test_block_soft $testfile $grace $limit "p" $qpool
1553 resetquota -p $TSTPRJID
1554 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1555 $MAX_IQ_TIME $DIR ||
1556 error "restore project grace time failed"
1557 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1558 $DIR || error "set project grace time failed"
1562 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1563 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1564 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1565 --pool $qpool $DIR || error "restore user grace time failed"
1566 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1567 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1568 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1569 --pool $qpool $DIR || error "restore group grace time failed"
1571 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1574 local grace=20 # seconds
1575 local qpool="qpool1"
1576 local qpool2="qpool2"
1577 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1580 local testfile=$DIR/$tdir/$tfile-0
1583 # get minimum soft qunit size
1584 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1585 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1586 local limit2=$((limit+4))
1587 local glbl_limit=$((limit+8))
1588 local grace1=$((grace+10))
1590 local glbl_grace=$((grace+20))
1591 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1592 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1594 set_ost_qtype $QTYPE || error "enable ost quota failed"
1596 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1597 # make sure the system is clean
1598 local used=$(getquota -u $TSTUSR global curspace)
1599 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1601 pool_add $qpool || error "pool_add failed"
1602 pool_add_targets $qpool 0 1 ||
1603 error "pool_add_targets failed"
1605 pool_add $qpool2 || error "pool_add failed"
1606 pool_add_targets $qpool2 0 1 ||
1607 error "pool_add_targets failed"
1610 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1611 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1612 $LFS setquota -t -u --block-grace $grace1 \
1613 --pool $qpool $DIR || error "set user grace time failed"
1614 $LFS setquota -t -u --block-grace $grace2 \
1615 --pool $qpool2 $DIR || error "set user grace time failed"
1617 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1618 error "set user quota failed"
1619 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1620 error "set user quota failed"
1621 # qpool has minimum soft limit, but its grace is greater than
1622 # the grace period of qpool2. Thus write shouldn't fail when
1623 # hit qpool soft limit - only when reaches up qpool2 limit
1624 # after grace2 seconds.
1625 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1626 error "set user quota failed"
1628 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1631 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1632 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1633 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1634 --pool $qpool $DIR || error "restore user grace time failed"
1635 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1636 --pool $qpool2 $DIR || error "restore user grace time failed"
1638 run_test 3c "Quota pools: check block soft limit on different pools"
1645 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1646 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1649 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1651 echo "Create files to exceed soft limit"
1652 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1653 quota_error a $TSTUSR "create failure, but expect success"
1654 local trigger_time=$(date +%s)
1656 sync_all_data || true
1658 local cur_time=$(date +%s)
1659 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1660 error "Passed grace time $grace, $trigger_time, $cur_time"
1662 echo "Create file before timer goes off"
1663 $RUNAS touch ${TESTFILE}_before ||
1664 quota_error a $TSTUSR "failed create before timer expired," \
1665 "but expect success. $trigger_time, $cur_time"
1666 sync_all_data || true
1668 wait_grace_time $qtype "file"
1673 $SHOW_QUOTA_INFO_USER
1674 $SHOW_QUOTA_INFO_GROUP
1675 $SHOW_QUOTA_INFO_PROJID
1677 echo "Create file after timer goes off"
1678 # exceed least soft limit is possible
1679 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1680 quota_error a $TSTUSR "create after timer expired," \
1682 sync_all_data || true
1687 $SHOW_QUOTA_INFO_USER
1688 $SHOW_QUOTA_INFO_GROUP
1689 $SHOW_QUOTA_INFO_PROJID
1691 echo "Unlink files to stop timer"
1692 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1693 wait_delete_completed
1696 $RUNAS touch ${TESTFILE}_xxx ||
1697 quota_error a $TSTUSR "touch after timer stop failure," \
1698 "but expect success"
1699 sync_all_data || true
1707 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1708 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1709 local TESTFILE=$DIR/$tdir/$tfile-0
1712 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1713 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1715 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1716 # make sure the system is clean
1717 local USED=$(getquota -u $TSTUSR global curinodes)
1718 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1720 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1721 $GRACE $DIR || error "set user grace time failed"
1722 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1723 error "set user quota failed"
1725 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1727 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1728 # make sure the system is clean
1729 USED=$(getquota -g $TSTUSR global curinodes)
1730 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1732 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1733 $GRACE $DIR || error "set group grace time failed"
1734 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1735 error "set group quota failed"
1736 TESTFILE=$DIR/$tdir/$tfile-1
1738 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1740 if is_project_quota_supported; then
1741 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1742 # make sure the system is clean
1743 USED=$(getquota -p $TSTPRJID global curinodes)
1744 [ $USED -ne 0 ] && error \
1745 "Used space($USED) for project $TSTPRJID isn't 0."
1747 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1748 $GRACE $DIR || error "set project grace time failed"
1749 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1750 error "set project quota failed"
1752 TESTFILE=$DIR/$tdir/$tfile-1
1753 # one less than limit, because of parent directory included.
1754 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1755 resetquota -p $TSTPRJID
1756 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1757 $MAX_IQ_TIME $DIR ||
1758 error "restore project grace time failed"
1762 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1763 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1764 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1765 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1767 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1770 local GR_STR1="1w3d"
1771 local GR_STR2="1000s"
1773 local GR_STR4="1w2d3h4m5s"
1775 local GR_STR6="18446744073709551615"
1778 wait_delete_completed
1780 # test of valid grace strings handling
1781 echo "Valid grace strings test"
1782 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1783 $GR_STR2 $DIR || error "set user grace time failed"
1784 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1785 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1786 $GR_STR4 $DIR || error "set group grace time quota failed"
1787 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1789 # test of invalid grace strings handling
1790 echo " Invalid grace strings test"
1791 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1792 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1793 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1797 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1798 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1799 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1800 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1802 run_test 4b "Grace time strings handling"
1804 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1806 local BLIMIT=10 # MB
1807 local ILIMIT=10 # inodes
1809 setup_quota_test || error "setup quota failed with $?"
1811 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1812 set_ost_qtype $QTYPE || error "enable ost quota failed"
1814 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1815 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1816 error "set user quota failed"
1817 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1818 if is_project_quota_supported; then
1819 error "set group quota failed"
1820 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1821 -I $ILIMIT $DIR || error "set project quota failed"
1824 # make sure the system is clean
1825 local USED=$(getquota -u $TSTUSR global curinodes)
1826 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1827 USED=$(getquota -g $TSTUSR global curinodes)
1828 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1829 USED=$(getquota -u $TSTUSR global curspace)
1830 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1831 USED=$(getquota -g $TSTUSR global curspace)
1832 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1833 if is_project_quota_supported; then
1834 USED=$(getquota -p $TSTPRJID global curinodes)
1836 error "Used inode($USED) for project $TSTPRJID isn't 0."
1837 USED=$(getquota -p $TSTPRJID global curspace)
1839 error "Used block($USED) for project $TSTPRJID isn't 0."
1842 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1843 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1844 error "create failure, expect success"
1845 if is_project_quota_supported; then
1846 touch $DIR/$tdir/$tfile-0_1
1847 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1849 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1850 error "write failure, expect success"
1852 echo "Chown files to $TSTUSR.$TSTUSR ..."
1853 for i in $(seq 0 $ILIMIT); do
1854 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1855 quota_error a $TSTUSR "chown failure, expect success"
1859 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1860 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1862 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1864 # test dropping acquire request on master
1868 # Clear dmesg so watchdog is not triggered by previous
1870 do_facet ost1 dmesg -c > /dev/null
1872 setup_quota_test || error "setup quota failed with $?"
1874 # make sure the system is clean
1875 local USED=$(getquota -u $TSTUSR global curspace)
1876 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1878 # make sure no granted quota on ost
1879 set_ost_qtype $QTYPE || error "enable ost quota failed"
1880 resetquota -u $TSTUSR
1882 # create file for $TSTUSR
1883 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1884 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1885 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1887 # create file for $TSTUSR2
1888 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1889 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1890 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1892 # cache per-ID lock for $TSTUSR on slave
1893 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1894 error "set quota failed"
1895 $RUNAS $DD of=$TESTFILE count=1 ||
1896 error "write $TESTFILE failure, expect success"
1897 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1898 error "write $TESTFILE2 failure, expect success"
1900 if at_is_enabled; then
1901 at_max_saved=$(at_max_get ost1)
1902 at_max_set $TIMEOUT ost1
1904 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1905 # DQACQ is sent, which makes at_max to take effect
1906 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1909 wait_delete_completed
1913 sync_all_data || true
1915 #define QUOTA_DQACQ 601
1916 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1917 lustre_fail mds 0x513 601
1919 do_facet ost1 $LCTL set_param \
1920 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1922 # write to un-enforced ID ($TSTUSR2) should succeed
1923 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1924 error "write failure, expect success"
1926 # write to enforced ID ($TSTUSR) in background, exceeding limit
1927 # to make sure DQACQ is sent
1928 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1931 # watchdog timer uses a factor of 2
1932 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1933 sleep $((TIMEOUT * 2 + 1))
1935 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1937 # write should be blocked and never finished
1938 if ! ps -p $DDPID > /dev/null 2>&1; then
1940 error "write finished incorrectly!"
1945 # no watchdog is triggered
1946 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1947 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1948 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1949 [ -z "$watchdog" ] || error "$watchdog"
1951 rm -f $TMP/lustre-log-${TESTNAME}.log
1953 # write should continue then fail with EDQUOT
1957 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1958 if [ $count -ge 240 ]; then
1959 quota_error u $TSTUSR "dd not finished in $count secs"
1961 count=$((count + 1))
1962 if [ $((count % 30)) -eq 0 ]; then
1963 c_size=$(stat -c %s $TESTFILE)
1964 echo "Waiting $count secs. $c_size"
1970 run_test 6 "Test dropping acquire request on master"
1972 # quota reintegration (global index)
1974 local TESTFILE=$DIR/$tdir/$tfile
1977 [ "$SLOW" = "no" ] && LIMIT=5
1979 setup_quota_test || error "setup quota failed with $?"
1981 # make sure the system is clean
1982 local USED=$(getquota -u $TSTUSR global curspace)
1983 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1985 # make sure no granted quota on ost1
1986 set_ost_qtype $QTYPE || error "enable ost quota failed"
1987 resetquota -u $TSTUSR
1988 set_ost_qtype "none" || error "disable ost quota failed"
1990 local OSTUUID=$(ostuuid_from_index 0)
1991 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1993 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1996 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1997 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2002 echo "Enable quota & set quota limit for $TSTUSR"
2003 set_ost_qtype $QTYPE || error "enable ost quota failed"
2004 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2005 error "set quota failed"
2007 echo "Start ost1..."
2008 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2011 wait_ost_reint $QTYPE || error "reintegration failed"
2013 # hardlimit should have been fetched by slave during global
2014 # reintegration, write will exceed quota
2015 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2016 quota_error u $TSTUSR "write success, but expect EDQUOT"
2019 wait_delete_completed
2020 sync_all_data || true
2026 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2027 error "clear quota failed"
2029 echo "Start ost1..."
2030 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2033 wait_ost_reint $QTYPE || error "reintegration failed"
2035 # hardlimit should be cleared on slave during reintegration
2036 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2037 quota_error u $TSTUSR "write error, but expect success"
2039 run_test 7a "Quota reintegration (global index)"
2041 # quota reintegration (slave index)
2043 local limit=100000 # MB
2044 local TESTFILE=$DIR/$tdir/$tfile
2046 setup_quota_test || error "setup quota failed with $?"
2048 # make sure the system is clean
2049 local USED=$(getquota -u $TSTUSR global curspace)
2050 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2052 # make sure no granted quota on ost1
2053 set_ost_qtype $QTYPE || error "enable ost quota failed"
2054 resetquota -u $TSTUSR
2055 set_ost_qtype "none" || error "disable ost quota failed"
2057 local OSTUUID=$(ostuuid_from_index 0)
2058 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2060 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2063 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2064 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2066 # consume some space to make sure the granted space will not
2067 # be released during reconciliation
2068 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2069 error "consume space failure, expect success"
2071 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2072 lustre_fail mds 0xa02
2074 set_ost_qtype $QTYPE || error "enable ost quota failed"
2075 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2076 error "set quota failed"
2078 # ignore the write error
2079 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2081 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2085 echo "Restart ost to trigger reintegration..."
2087 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2090 wait_ost_reint $QTYPE || error "reintegration failed"
2092 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2093 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2098 run_test 7b "Quota reintegration (slave index)"
2100 # quota reintegration (restart mds during reintegration)
2103 local TESTFILE=$DIR/$tdir/$tfile
2105 [ "$SLOW" = "no" ] && LIMIT=5
2107 setup_quota_test || error "setup quota failed with $?"
2109 # make sure the system is clean
2110 local USED=$(getquota -u $TSTUSR global curspace)
2111 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2113 set_ost_qtype "none" || error "disable ost quota failed"
2114 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2115 error "set quota failed"
2117 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2118 lustre_fail ost 0xa03
2121 set_ost_qtype $QTYPE || error "enable ost quota failed"
2122 # trigger reintegration
2123 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2124 procf=${procf}quota_slave.force_reint
2125 do_facet ost1 $LCTL set_param $procf=1 ||
2126 error "force reintegration failed"
2134 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2137 # wait longer than usual to make sure the reintegration
2138 # is triggered by quota wb thread.
2139 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2141 # hardlimit should have been fetched by slave during global
2142 # reintegration, write will exceed quota
2143 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2144 quota_error u $TSTUSR "write success, but expect EDQUOT"
2147 run_test 7c "Quota reintegration (restart mds during reintegration)"
2149 # Quota reintegration (Transfer index in multiple bulks)
2151 local TESTFILE=$DIR/$tdir/$tfile
2152 local TESTFILE1="$DIR/$tdir/$tfile"-1
2155 setup_quota_test || error "setup quota failed with $?"
2157 set_ost_qtype "none" || error "disable ost quota failed"
2158 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2159 error "set quota for $TSTUSR failed"
2160 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2161 error "set quota for $TSTUSR2 failed"
2163 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2164 lustre_fail mds 0x608 0
2166 # enable quota to tirgger reintegration
2167 set_ost_qtype "u" || error "enable ost quota failed"
2168 wait_ost_reint "u" || error "reintegration failed"
2172 # hardlimit should have been fetched by slave during global
2173 # reintegration, write will exceed quota
2174 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2175 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2177 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2178 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2181 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2183 # quota reintegration (inode limits)
2185 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2187 # LU-2435: skip this quota test if underlying zfs version has not
2188 # supported native dnode accounting
2189 [ "$mds1_FSTYPE" == zfs ] && {
2190 local F="feature@userobj_accounting"
2191 local pool=$(zpool_name mds1)
2192 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2194 [[ "$feature" != *" active "* ]] &&
2195 skip "requires zpool with active userobj_accounting"
2198 local ilimit=$((1024 * 2)) # inodes
2199 local TESTFILE=$DIR/${tdir}-1/$tfile
2201 setup_quota_test || error "setup quota failed with $?"
2203 # make sure the system is clean
2204 local USED=$(getquota -u $TSTUSR global curinodes)
2205 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2207 # make sure no granted quota on mdt1
2208 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2209 resetquota -u $TSTUSR
2210 set_mdt_qtype "none" || error "disable mdt quota failed"
2212 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2213 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2214 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2217 echo "Stop mds${MDSCOUNT}..."
2220 echo "Enable quota & set quota limit for $TSTUSR"
2221 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2222 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2223 error "set quota failed"
2225 echo "Start mds${MDSCOUNT}..."
2226 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2229 wait_mdt_reint $QTYPE || error "reintegration failed"
2231 echo "create remote dir"
2232 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2233 error "create remote dir failed"
2234 chmod 0777 $DIR/${tdir}-1
2236 # hardlimit should have been fetched by slave during global
2237 # reintegration, create will exceed quota
2238 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2239 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2241 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2242 wait_delete_completed
2243 sync_all_data || true
2245 echo "Stop mds${MDSCOUNT}..."
2248 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2249 error "clear quota failed"
2251 echo "Start mds${MDSCOUNT}..."
2252 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2255 wait_mdt_reint $QTYPE || error "reintegration failed"
2257 # hardlimit should be cleared on slave during reintegration
2258 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2259 quota_error u $TSTUSR "create failed, expect success"
2261 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2262 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2264 run_test 7e "Quota reintegration (inode limits)"
2266 # run dbench with quota enabled
2268 local BLK_LIMIT="100g" #100G
2269 local FILE_LIMIT=1000000
2271 setup_quota_test || error "setup quota failed with $?"
2273 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2274 set_ost_qtype $QTYPE || error "enable ost quota failed"
2276 echo "Set enough high limit for user: $TSTUSR"
2277 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2278 error "set user quota failed"
2279 echo "Set enough high limit for group: $TSTUSR"
2280 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2281 error "set group quota failed"
2282 if is_project_quota_supported; then
2283 change_project -sp $TSTPRJID $DIR/$tdir
2284 echo "Set enough high limit for project: $TSTPRJID"
2285 $LFS setquota -p $TSTPRJID -b 0 \
2286 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2287 error "set project quota failed"
2291 [ "$SLOW" = "no" ] && duration=" -t 120"
2292 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2293 quota_error a $TSTUSR "dbench failed!"
2295 is_project_quota_supported && change_project -C $DIR/$tdir
2298 run_test 8 "Run dbench with quota enabled"
2300 # this check is just for test_9
2301 OST0_MIN=4900000 #4.67G
2303 check_whether_skip () {
2304 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2305 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2306 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2307 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2314 # run for fixing bug10707, it needs a big room. test for 64bit
2316 local filesize=$((1024 * 9 / 2)) # 4.5G
2318 check_whether_skip && return 0
2320 setup_quota_test || error "setup quota failed with $?"
2322 set_ost_qtype "ug" || error "enable ost quota failed"
2324 local TESTFILE="$DIR/$tdir/$tfile-0"
2325 local BLK_LIMIT=100G #100G
2326 local FILE_LIMIT=1000000
2328 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2330 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2332 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2333 error "set user quota failed"
2335 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2336 "for group: $TSTUSR"
2337 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2338 error "set group quota failed"
2340 quota_show_check a u $TSTUSR
2341 quota_show_check a g $TSTUSR
2343 echo "Create test file"
2344 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2345 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2347 log "Write the big file of 4.5G ..."
2348 $RUNAS $DD of=$TESTFILE count=$filesize ||
2349 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2359 run_test 9 "Block limit larger than 4GB (b10707)"
2362 local TESTFILE=$DIR/$tdir/$tfile
2364 setup_quota_test || error "setup quota failed with $?"
2366 # set limit to root user should fail
2367 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2368 error "set limit for root user successfully, expect failure"
2369 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2370 error "set limit for root group successfully, expect failure"
2371 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2372 error "set limit for project 0 successfully, expect failure"
2374 # root user can overrun quota
2375 set_ost_qtype "ug" || error "enable ost quota failed"
2377 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2378 error "set quota failed"
2379 quota_show_check b u $TSTUSR
2381 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2382 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2384 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2385 error "write failure, expect success"
2387 run_test 10 "Test quota for root user"
2390 local TESTFILE=$DIR/$tdir/$tfile
2391 setup_quota_test || error "setup quota failed with $?"
2393 set_mdt_qtype "ug" || error "enable mdt quota failed"
2394 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2395 error "set quota failed"
2397 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2398 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2400 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2401 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2404 local USED=$(getquota -u $TSTUSR global curinodes)
2405 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2407 run_test 11 "Chown/chgrp ignores quota"
2410 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2412 local blimit=22 # MB
2413 local blk_cnt=$((blimit - 5))
2414 local TESTFILE0="$DIR/$tdir/$tfile"-0
2415 local TESTFILE1="$DIR/$tdir/$tfile"-1
2417 setup_quota_test || error "setup quota failed with $?"
2419 set_ost_qtype "u" || error "enable ost quota failed"
2420 quota_show_check b u $TSTUSR
2422 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2423 error "set quota failed"
2425 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2426 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2427 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2428 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2430 echo "Write to ost0..."
2431 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2432 quota_error a $TSTUSR "dd failed"
2434 echo "Write to ost1..."
2435 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2436 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2438 echo "Free space from ost0..."
2440 wait_delete_completed
2441 sync_all_data || true
2443 echo "Write to ost1 after space freed from ost0..."
2444 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2445 quota_error a $TSTUSR "rebalancing failed"
2447 run_test 12a "Block quota rebalancing"
2450 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2452 local ilimit=$((1024 * 2)) # inodes
2453 local TESTFILE0=$DIR/$tdir/$tfile
2454 local TESTFILE1=$DIR/${tdir}-1/$tfile
2456 setup_quota_test || error "setup quota failed with $?"
2458 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2459 chmod 0777 $DIR/${tdir}-1
2461 set_mdt_qtype "u" || error "enable mdt quota failed"
2462 quota_show_check f u $TSTUSR
2464 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2465 error "set quota failed"
2467 echo "Create $ilimit files on mdt0..."
2468 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2469 quota_error u $TSTUSR "create failed, but expect success"
2471 echo "Create files on mdt1..."
2472 $RUNAS createmany -m $TESTFILE1 1 &&
2473 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2475 echo "Free space from mdt0..."
2476 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2477 wait_delete_completed
2478 sync_all_data || true
2480 echo "Create files on mdt1 after space freed from mdt0..."
2481 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2482 quota_error a $TSTUSR "rebalancing failed"
2484 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2485 error "unlink mdt1 files failed"
2486 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2488 run_test 12b "Inode quota rebalancing"
2491 local TESTFILE=$DIR/$tdir/$tfile
2492 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2493 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2495 setup_quota_test || error "setup quota failed with $?"
2497 set_ost_qtype "u" || error "enable ost quota failed"
2498 quota_show_check b u $TSTUSR
2500 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2501 error "set quota failed"
2502 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2503 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2505 # clear the locks in cache first
2506 do_facet ost1 $LCTL set_param -n $procf=clear
2507 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2508 [ $nlock -eq 0 ] || error "$nlock cached locks"
2510 # write to acquire the per-ID lock
2511 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2512 quota_error a $TSTUSR "dd failed"
2514 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2515 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2517 # clear quota doesn't trigger per-ID lock cancellation
2518 resetquota -u $TSTUSR
2519 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2520 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2522 # clear the per-ID lock
2523 do_facet ost1 $LCTL set_param -n $procf=clear
2524 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2525 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2527 # spare quota should be released
2528 local OSTUUID=$(ostuuid_from_index 0)
2529 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2530 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2531 [ $limit -le $space ] ||
2532 error "spare quota isn't released, limit:$limit, space:$space"
2534 run_test 13 "Cancel per-ID lock in the LRU list"
2537 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2539 wait_delete_completed
2540 sync_all_data || true
2543 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2544 error "set user quota failed"
2545 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2546 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2547 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2548 resetquota -u $TSTUSR
2551 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2552 error "set group quota failed"
2553 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2554 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2555 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2556 resetquota -g $TSTUSR
2558 run_test 15 "Set over 4T block quota"
2562 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2563 skip "Not supported Lustre client before 2.14.55"
2565 setup_quota_test || error "setup quota failed with $?"
2567 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2568 error "failed to set quota for user $TSTUSR"
2569 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2570 error "failed to set quota for group $TSTUSR"
2572 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=50 ||
2573 quota_error u $TSTUSR "write failure"
2575 $LFS quota -u $TSTUSR $MOUNT ||
2576 quota_error u $TSTUSR "failed to get quota"
2578 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2580 $LCTL --device %$OSC deactivate
2581 stack_trap "$LCTL --device %$OSC activate"
2583 $LFS quota -v -u $TSTUSR $MOUNT ||
2584 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2585 $LFS quota -v -g $TSTUSR $MOUNT ||
2586 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2588 (( $MDSCOUNT > 1 )) || return 0
2590 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2592 $LCTL --device %$MDC deactivate
2593 stack_trap "$LCTL --device %$MDC activate"
2595 $LFS quota -v -u $TSTUSR $MOUNT ||
2596 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2597 $LFS quota -v -g $TSTUSR $MOUNT ||
2598 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2600 run_test 16a "lfs quota should skip the inactive MDT/OST"
2611 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2612 skip "Not supported Lustre client before 2.14.55"
2614 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2617 if ! combined_mgs_mds ; then
2622 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2623 $(mdsdevname 1) $(mdsvdevname 1)
2624 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2625 $(mdsdevname 2) $(mdsvdevname 2)
2626 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2627 $(mdsdevname 3) $(mdsvdevname 3)
2629 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2630 $(ostdevname 1) $(ostvdevname 1)
2631 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2632 $(ostdevname 2) $(ostvdevname 2)
2634 stack_trap cleanup_16b
2636 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2637 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2638 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2639 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2640 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2642 mount_client $MOUNT || error "Unable to mount client"
2644 setup_quota_test || error "setup quota failed with $?"
2645 stack_trap cleanup_quota_test EXIT
2647 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2648 error "failed to set quota for user $TSTUSR"
2649 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2650 error "failed to set quota for group $TSTUSR"
2652 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=10 ||
2653 quota_error u $TSTUSR "write failure"
2655 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2656 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2657 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2658 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2660 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2664 local BLKS=1 # 1M less than limit
2665 local TESTFILE=$DIR/$tdir/$tfile
2667 setup_quota_test || error "setup quota failed with $?"
2669 # make sure the system is clean
2670 local USED=$(getquota -u $TSTUSR global curspace)
2671 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2673 set_ost_qtype "ug" || error "enable ost quota failed"
2674 # make sure no granted quota on ost
2675 resetquota -u $TSTUSR
2676 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2677 error "set quota failed"
2679 quota_show_check b u $TSTUSR
2681 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2682 lustre_fail mds 0xa04 $err_code
2684 # write in background
2685 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2689 # write should be blocked and never finished
2690 if ! ps -p $DDPID > /dev/null 2>&1; then
2692 quota_error u $TSTUSR "write finished incorrectly!"
2700 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2702 if [ $count -gt $timeout ]; then
2703 quota_error u $TSTUSR "dd is not finished!"
2708 sync; sync_all_data || true
2710 USED=$(getquota -u $TSTUSR global curspace)
2711 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2712 "Used space(${USED}K) is less than ${BLKS}M"
2717 # DQACQ return recoverable error
2719 echo "DQACQ return -ENOLCK"
2721 test_17sub 37 || error "Handle -ENOLCK failed"
2723 echo "DQACQ return -EAGAIN"
2725 test_17sub 11 || error "Handle -EAGAIN failed"
2727 echo "DQACQ return -ETIMEDOUT"
2728 #define ETIMEDOUT 110
2729 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2731 echo "DQACQ return -ENOTCONN"
2732 #define ENOTCONN 107
2733 test_17sub 107 || error "Handle -ENOTCONN failed"
2736 run_test 17 "DQACQ return recoverable error"
2740 local blimit=200 # MB
2741 local TESTFILE="$DIR/$tdir/$tfile"
2743 setup_quota_test || error "setup quota failed with $?"
2745 set_ost_qtype "u" || error "enable ost quota failed"
2746 log "User quota (limit: $blimit)"
2747 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2748 error "set quota failed"
2749 quota_show_check b u $TSTUSR
2751 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2752 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2754 local timeout=$(sysctl -n lustre.timeout)
2756 if [ $io_type = "directio" ]; then
2757 log "Write 100M (directio) ..."
2758 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2760 log "Write 100M (buffered) ..."
2761 $RUNAS $DD of=$TESTFILE count=100 &
2765 replay_barrier $SINGLEMDS
2766 log "Fail mds for $((2 * timeout)) seconds"
2767 fail $SINGLEMDS $((2 * timeout))
2770 if at_is_enabled; then
2771 timeout=$(at_max_get mds)
2773 timeout=$(lctl get_param -n timeout)
2777 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2778 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2779 log "it took $count second"
2784 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2786 cancel_lru_locks mdc
2787 cancel_lru_locks osc
2790 local testfile_size=$(stat -c %s $TESTFILE)
2791 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2792 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2793 "got ${testfile_size}. Verifying file failed!"
2798 # test when mds does failover, the ost still could work well
2799 # this test shouldn't trigger watchdog b=14840
2801 # Clear dmesg so watchdog is not triggered by previous
2803 do_facet ost1 dmesg -c > /dev/null
2806 test_18_sub directio
2808 # check if watchdog is triggered
2809 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2810 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2811 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2812 [ -z "$watchdog" ] || error "$watchdog"
2813 rm -f $TMP/lustre-log-${TESTNAME}.log
2815 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2819 local TESTFILE=$DIR/$tdir/$tfile
2821 setup_quota_test || error "setup quota failed with $?"
2823 set_ost_qtype $QTYPE || error "enable ost quota failed"
2825 # bind file to a single OST
2826 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2827 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2829 echo "Set user quota (limit: ${blimit}M)"
2830 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2831 error "set user quota failed"
2832 quota_show_check b u $TSTUSR
2833 echo "Update quota limits"
2834 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2835 error "set group quota failed"
2836 quota_show_check b u $TSTUSR
2838 # first wirte might be cached
2839 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2840 cancel_lru_locks osc
2842 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2843 quota_error u $TSTUSR "Write success, expect failure"
2846 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2848 test_20() { # b15754
2849 local LSTR=(2g 1t 4k 3m) # limits strings
2851 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2854 resetquota -u $TSTUSR
2856 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2857 $MOUNT || error "could not set quota limits"
2858 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2859 --inode-softlimit ${LSTR[2]} \
2860 --inode-hardlimit ${LSTR[3]} \
2861 $MOUNT || error "could not set quota limits"
2863 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2864 error "bsoftlimit was not set properly"
2865 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2866 error "bhardlimit was not set properly"
2867 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2868 error "isoftlimit was not set properly"
2869 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2870 error "ihardlimit was not set properly"
2872 resetquota -u $TSTUSR
2874 run_test 20 "Test if setquota specifiers work properly (b15754)"
2881 local time=$(($(date +%s) + seconds))
2882 while [ $(date +%s) -lt $time ]; do
2883 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2887 # run for fixing bug16053, setquota shouldn't fail when writing and
2888 # deleting are happening
2890 local TESTFILE="$DIR/$tdir/$tfile"
2891 local BLIMIT=10 # 10G
2892 local ILIMIT=1000000
2894 setup_quota_test || error "setup quota failed with $?"
2896 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2898 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2899 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2900 error "set user quota failed"
2901 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2902 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2903 error "set group quota failed"
2904 if is_project_quota_supported; then
2905 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2906 "project: $TSTPRJID"
2907 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2908 $MOUNT || error "set project quota failed"
2911 # repeat writing on a 1M file
2912 test_21_sub ${TESTFILE}_1 1 30 &
2914 # repeat writing on a 128M file
2915 test_21_sub ${TESTFILE}_2 128 30 &
2918 local time=$(($(date +%s) + 30))
2920 while [ $(date +%s) -lt $time ]; do
2921 log "Set quota for $i times"
2922 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2923 -I $((ILIMIT + i)) $MOUNT ||
2924 error "Set user quota failed"
2925 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2926 -I $((ILIMIT + i)) $MOUNT ||
2927 error "Set group quota failed"
2928 if is_project_quota_supported; then
2929 $LFS setquota -p $TSTPRJID -b 0 -B \
2930 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2931 error "Set project quota failed"
2939 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2941 if [ $count -gt 60 ]; then
2942 quota_error a $TSTUSR "dd should be finished!"
2946 echo "(dd_pid=$DDPID1, time=$count)successful"
2950 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2952 if [ $count -gt 60 ]; then
2953 quota_error a $TSTUSR "dd should be finished!"
2957 echo "(dd_pid=$DDPID2, time=$count)successful"
2959 run_test 21 "Setquota while writing & deleting (b16053)"
2961 # enable/disable quota enforcement permanently
2963 echo "Set both mdt & ost quota type as ug"
2965 is_project_quota_supported && qtype=$QTYPE
2966 set_mdt_qtype $qtype || error "enable mdt quota failed"
2967 set_ost_qtype $qtype || error "enable ost quota failed"
2970 stopall || error "failed to stopall (1)"
2974 echo "Verify if quota is enabled"
2975 local qtype1=$(mdt_quota_type)
2976 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2977 qtype=$(ost_quota_type)
2978 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2980 echo "Set both mdt & ost quota type as none"
2981 set_mdt_qtype "none" || error "disable mdt quota failed"
2982 set_ost_qtype "none" || error "disable ost quota failed"
2985 stopall || error "failed to stopall (2)"
2990 echo "Verify if quota is disabled"
2991 qtype=$(mdt_quota_type)
2992 [ $qtype != "none" ] && error "mdt quota setting is lost"
2993 qtype=$(ost_quota_type)
2994 [ $qtype != "none" ] && error "ost quota setting is lost"
2998 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3001 local TESTFILE="$DIR/$tdir/$tfile"
3004 setup_quota_test || error "setup quota failed with $?"
3006 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3009 log "User quota (limit: $LIMIT MB)"
3010 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3011 error "set quota failed"
3012 quota_show_check b u $TSTUSR
3014 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3015 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3017 log "Step1: trigger EDQUOT with O_DIRECT"
3018 log "Write half of file"
3019 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3020 quota_error u $TSTUSR "(1) Write failure, expect success." \
3022 log "Write out of block quota ..."
3023 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3024 oflag=direct conv=notrunc &&
3025 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3029 log "Step2: rewrite should succeed"
3030 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3031 quota_error u $TSTUSR "(3) Write failure, expect success." \
3037 local OST0_UUID=$(ostuuid_from_index 0)
3038 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3039 [ $OST0_QUOTA_USED -ne 0 ] &&
3040 ($SHOW_QUOTA_USER; \
3041 quota_error u $TSTUSR "quota isn't released")
3046 [ "$ost1_FSTYPE" == zfs ] &&
3047 skip "Overwrite in place is not guaranteed to be " \
3048 "space neutral on ZFS"
3050 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3051 check_whether_skip && return 0
3052 log "run for 4MB test file"
3055 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3056 check_whether_skip && return 0
3057 log "run for 40MB test file"
3060 run_test 23 "Quota should be honored with directIO (b16125)"
3064 local TESTFILE="$DIR/$tdir/$tfile"
3066 setup_quota_test || error "setup quota failed with $?"
3068 set_ost_qtype $QTYPE || error "enable ost quota failed"
3070 # bind file to a single OST
3071 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3072 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3074 echo "Set user quota (limit: ${blimit}M)"
3075 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3076 error "set quota failed"
3078 # overrun quota by root user
3079 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3080 error "write failure, expect success"
3081 cancel_lru_locks osc
3082 sync_all_data || true
3084 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3086 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3088 test_27a() { # b19612
3089 $LFS quota $TSTUSR $DIR &&
3090 error "lfs succeeded with no type, but should have failed"
3091 $LFS setquota $TSTUSR $DIR &&
3092 error "lfs succeeded with no type, but should have failed"
3095 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3097 test_27b() { # b20200
3098 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3099 error "lfs setquota failed with uid argument"
3100 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3101 error "lfs stequota failed with gid argument"
3102 if is_project_quota_supported; then
3103 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3104 1000 $DIR || error \
3105 "lfs stequota failed with projid argument"
3107 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3108 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3109 if is_project_quota_supported; then
3110 $SHOW_QUOTA_PROJID ||
3111 error "lfs quota failed with projid argument"
3113 resetquota -u $TSTID
3114 resetquota -g $TSTID
3115 resetquota -p $TSTPRJID
3118 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3123 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3124 error "lfs setquota failed"
3126 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3127 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3128 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3129 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3131 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3132 error "lfs setquota for $TSTID failed"
3134 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3135 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3136 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3137 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3139 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3140 error "total allocated inode/block limit not printed"
3142 resetquota -u $TSTUSR
3144 run_test 27c "lfs quota should support human-readable output"
3151 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3152 error "set fraction block limit failed"
3153 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3154 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3155 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3156 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3158 resetquota -u $TSTUSR
3160 run_test 27d "lfs setquota should support fraction block limit"
3164 local TESTFILE="$DIR/$tdir/$tfile"
3167 setup_quota_test || error "setup quota failed with $?"
3169 set_ost_qtype "u" || error "enable ost quota failed"
3171 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3172 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3174 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3175 $MAX_IQ_TIME $DIR || error "set grace time failed"
3176 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3177 error "set quota failed"
3178 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3179 cancel_lru_locks osc
3181 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3182 # over-quota flag has not yet settled since we do not trigger async
3183 # events based on grace time period expiration
3185 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3186 cancel_lru_locks osc
3187 # now over-quota flag should be settled and further writes should fail
3189 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3190 error "grace times were reset"
3191 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3192 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3194 run_test 30 "Hard limit updates should not reset grace times"
3196 # basic usage tracking for user & group
3198 local INODES=10 # files
3199 local BLK_CNT=2 # MB each
3200 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3202 setup_quota_test || error "setup quota failed with $?"
3204 # make sure the system is clean
3205 local USED=$(getquota -u $TSTID global curspace)
3207 error "Used space ($USED) for user $TSTID isn't 0."
3208 USED=$(getquota -g $TSTID global curspace)
3210 error "Used space ($USED) for group $TSTID isn't 0."
3211 if is_project_quota_supported; then
3212 USED=$(getquota -p $TSTPRJID global curspace)
3213 [ $USED -ne 0 ] && error \
3214 "Used space ($USED) for project $TSTPRJID isn't 0."
3217 echo "Write files..."
3218 for i in $(seq 0 $INODES); do
3219 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3220 error "write failed"
3221 is_project_quota_supported &&
3222 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3223 echo "Iteration $i/$INODES completed"
3225 cancel_lru_locks osc
3227 echo "Wait for setattr on objects finished..."
3228 wait_delete_completed
3230 sync; sync_all_data || true
3232 echo "Verify disk usage after write"
3233 USED=$(getquota -u $TSTID global curspace)
3234 [ $USED -lt $TOTAL_BLKS ] &&
3235 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3236 USED=$(getquota -g $TSTID global curspace)
3237 [ $USED -lt $TOTAL_BLKS ] &&
3238 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3239 if is_project_quota_supported; then
3240 USED=$(getquota -p $TSTPRJID global curspace)
3241 [ $USED -lt $TOTAL_BLKS ] && error \
3242 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3245 echo "Verify inode usage after write"
3246 USED=$(getquota -u $TSTID global curinodes)
3247 [ $USED -lt $INODES ] &&
3248 error "Used inode for user $TSTID is $USED, expected $INODES"
3249 USED=$(getquota -g $TSTID global curinodes)
3250 [ $USED -lt $INODES ] &&
3251 error "Used inode for group $TSTID is $USED, expected $INODES"
3252 if is_project_quota_supported; then
3253 USED=$(getquota -p $TSTPRJID global curinodes)
3254 [ $USED -lt $INODES ] && error \
3255 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3260 echo "Verify disk usage after delete"
3261 USED=$(getquota -u $TSTID global curspace)
3262 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3263 USED=$(getquota -u $TSTID global curinodes)
3264 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3265 USED=$(getquota -g $TSTID global curspace)
3266 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3267 USED=$(getquota -g $TSTID global curinodes)
3268 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3269 if is_project_quota_supported; then
3270 USED=$(getquota -p $TSTPRJID global curspace)
3272 error "Used space for project $TSTPRJID isn't 0. $USED"
3273 USED=$(getquota -p $TSTPRJID global curinodes)
3275 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3278 run_test 33 "Basic usage tracking for user & group & project"
3280 # usage transfer test for user & group & project
3282 local BLK_CNT=2 # MB
3283 local project_supported="no"
3285 is_project_quota_supported && project_supported="yes"
3286 setup_quota_test || error "setup quota failed with $?"
3288 # make sure the system is clean
3289 local USED=$(getquota -u $TSTID global curspace)
3290 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3291 USED=$(getquota -g $TSTID global curspace)
3292 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3294 local USED=$(getquota -u $TSTID2 global curspace)
3295 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3296 if [ $project_supported == "yes" ]; then
3297 USED=$(getquota -p $TSTPRJID global curspace)
3298 [ $USED -ne 0 ] && error \
3299 "Used space ($USED) for Project $TSTPRJID isn't 0."
3302 echo "Write file..."
3303 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3304 error "write failed"
3305 cancel_lru_locks osc
3306 sync; sync_all_data || true
3308 echo "chown the file to user $TSTID"
3309 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3311 echo "Wait for setattr on objects finished..."
3312 wait_delete_completed
3314 BLK_CNT=$((BLK_CNT * 1024))
3316 echo "Verify disk usage for user $TSTID"
3317 USED=$(getquota -u $TSTID global curspace)
3318 [ $USED -lt $BLK_CNT ] &&
3319 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3320 USED=$(getquota -u $TSTID global curinodes)
3322 error "Used inodes for user $TSTID is $USED, expected 1"
3324 echo "chgrp the file to group $TSTID"
3325 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3327 echo "Wait for setattr on objects finished..."
3328 wait_delete_completed
3330 echo "Verify disk usage for group $TSTID"
3331 USED=$(getquota -g $TSTID global curspace)
3332 [ $USED -ge $BLK_CNT ] ||
3333 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3334 USED=$(getquota -g $TSTID global curinodes)
3336 error "Used inodes for group $TSTID is $USED, expected 1"
3338 # chown won't change the ost object group. LU-4345 */
3339 echo "chown the file to user $TSTID2"
3340 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3342 echo "Wait for setattr on objects finished..."
3343 wait_delete_completed
3345 echo "change_project project id to $TSTPRJID"
3346 [ $project_supported == "yes" ] &&
3347 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3348 echo "Wait for setattr on objects finished..."
3349 wait_delete_completed
3351 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3352 USED=$(getquota -u $TSTID2 global curspace)
3353 [ $USED -lt $BLK_CNT ] &&
3354 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3355 USED=$(getquota -u $TSTID global curspace)
3357 error "Used space for user $TSTID is $USED, expected 0"
3358 USED=$(getquota -g $TSTID global curspace)
3359 [ $USED -lt $BLK_CNT ] &&
3360 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3361 if [ $project_supported == "yes" ]; then
3362 USED=$(getquota -p $TSTPRJID global curspace)
3363 [ $USED -lt $BLK_CNT ] && error \
3364 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3368 run_test 34 "Usage transfer for user & group & project"
3370 # usage is still accessible across restart
3372 local BLK_CNT=2 # MB
3374 setup_quota_test || error "setup quota failed with $?"
3376 echo "Write file..."
3377 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3378 error "write failed"
3379 is_project_quota_supported &&
3380 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3381 cancel_lru_locks osc
3383 echo "Wait for setattr on objects finished..."
3384 wait_delete_completed
3386 sync; sync_all_data || true
3388 echo "Save disk usage before restart"
3389 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3390 [ $ORIG_USR_SPACE -eq 0 ] &&
3391 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3392 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3393 [ $ORIG_USR_INODES -eq 0 ] &&
3394 error "Used inodes for user $TSTID is 0, expected 1"
3395 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3396 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3397 [ $ORIG_GRP_SPACE -eq 0 ] &&
3398 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3399 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3400 [ $ORIG_GRP_INODES -eq 0 ] &&
3401 error "Used inodes for group $TSTID is 0, expected 1"
3402 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3404 if is_project_quota_supported; then
3405 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3406 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3407 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3408 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3409 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3410 "Used inodes for project $TSTPRJID is 0, expected 1"
3411 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3419 echo "Verify disk usage after restart"
3420 local USED=$(getquota -u $TSTID global curspace)
3421 [ $USED -eq $ORIG_USR_SPACE ] ||
3422 error "Used space for user $TSTID changed from " \
3423 "$ORIG_USR_SPACE to $USED"
3424 USED=$(getquota -u $TSTID global curinodes)
3425 [ $USED -eq $ORIG_USR_INODES ] ||
3426 error "Used inodes for user $TSTID changed from " \
3427 "$ORIG_USR_INODES to $USED"
3428 USED=$(getquota -g $TSTID global curspace)
3429 [ $USED -eq $ORIG_GRP_SPACE ] ||
3430 error "Used space for group $TSTID changed from " \
3431 "$ORIG_GRP_SPACE to $USED"
3432 USED=$(getquota -g $TSTID global curinodes)
3433 [ $USED -eq $ORIG_GRP_INODES ] ||
3434 error "Used inodes for group $TSTID changed from " \
3435 "$ORIG_GRP_INODES to $USED"
3436 if [ $project_supported == "yes" ]; then
3437 USED=$(getquota -p $TSTPRJID global curinodes)
3438 [ $USED -eq $ORIG_PRJ_INODES ] ||
3439 error "Used inodes for project $TSTPRJID " \
3440 "changed from $ORIG_PRJ_INODES to $USED"
3441 USED=$(getquota -p $TSTPRJID global curspace)
3442 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3443 error "Used space for project $TSTPRJID "\
3444 "changed from $ORIG_PRJ_SPACE to $USED"
3447 # check if the vfs_dq_init() is called before writing
3448 echo "Append to the same file..."
3449 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3450 error "write failed"
3451 cancel_lru_locks osc
3452 sync; sync_all_data || true
3454 echo "Verify space usage is increased"
3455 USED=$(getquota -u $TSTID global curspace)
3456 [ $USED -gt $ORIG_USR_SPACE ] ||
3457 error "Used space for user $TSTID isn't increased" \
3458 "orig:$ORIG_USR_SPACE, now:$USED"
3459 USED=$(getquota -g $TSTID global curspace)
3460 [ $USED -gt $ORIG_GRP_SPACE ] ||
3461 error "Used space for group $TSTID isn't increased" \
3462 "orig:$ORIG_GRP_SPACE, now:$USED"
3463 if [ $project_supported == "yes" ]; then
3464 USED=$(getquota -p $TSTPRJID global curspace)
3465 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3466 error "Used space for project $TSTPRJID isn't " \
3467 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3470 run_test 35 "Usage is still accessible across reboot"
3472 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3475 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3476 skip "Old server doesn't have LU-5006 fix."
3478 setup_quota_test || error "setup quota failed with $?"
3480 # make sure the system is clean
3481 local USED=$(getquota -u $TSTID global curspace)
3483 error "Used space ($USED) for user $TSTID isn't 0."
3485 # create file with MDS_OPEN_DELAY_CREATE flag
3486 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3487 error "Create file failed"
3489 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3490 oflag=sync || error "Write file failed"
3492 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3494 # wait for setattr on objects finished..."
3495 wait_delete_completed
3497 USED=$(getquota -u $TSTID global curspace)
3498 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3500 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3504 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3505 skip "Old server doesn't have LU-8801 fix."
3507 [ "$UID" != 0 ] && skip_env "must run as root" && return
3509 setup_quota_test || error "setup quota failed with $?"
3511 # make sure the system is clean
3512 local USED=$(getquota -u $TSTID global curspace)
3514 error "Used space ($USED) for user $TSTID isn't 0."
3515 USED=$(getquota -u $TSTID2 global curspace)
3517 error "Used space ($USED) for user $TSTID2 isn't 0."
3519 local TESTFILE="$DIR/$tdir/$tfile"
3520 local file_cnt=10000
3522 # Generate id entries in accounting file
3523 echo "Create $file_cnt files..."
3524 for i in `seq $file_cnt`; do
3526 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3527 error "failed to chown $TESTFILE-$i"
3529 cancel_lru_locks osc
3530 sync; sync_all_data || true
3532 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3533 procf=${procf}.quota_slave.acct_user
3536 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3537 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3538 echo "Found $acct_cnt id entries"
3540 [ $file_cnt -eq $acct_cnt ] || {
3541 do_facet mds1 $LCTL get_param $procf
3542 error "skipped id entries"
3545 run_test 38 "Quota accounting iterator doesn't skip id entries"
3548 local TESTFILE="$DIR/$tdir/project"
3549 ! is_project_quota_supported &&
3550 skip "Project quota is not supported"
3552 setup_quota_test || error "setup quota failed with $?"
3555 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3556 [ $projectid -ne 0 ] &&
3557 error "Project id should be 0 not $projectid"
3558 change_project -p 1024 $TESTFILE
3559 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3560 [ $projectid -ne 1024 ] &&
3561 error "Project id should be 1024 not $projectid"
3563 stopall || error "failed to stopall (1)"
3566 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3567 [ $projectid -eq 1024 ] ||
3568 error "Project id should be 1024 not $projectid"
3570 run_test 39 "Project ID interface works correctly"
3573 ! is_project_quota_supported &&
3574 skip "Project quota is not supported"
3575 local dir1="$DIR/$tdir/dir1"
3576 local dir2="$DIR/$tdir/dir2"
3578 setup_quota_test || error "setup quota failed with $?"
3580 mkdir -p $dir1 $dir2
3581 change_project -sp 1 $dir1 && touch $dir1/1
3582 change_project -sp 2 $dir2
3584 ln $dir1/1 $dir2/1_link &&
3585 error "Hard link across different project quota should fail"
3588 run_test 40a "Hard link across different project ID"
3591 ! is_project_quota_supported &&
3592 skip "Project quota is not supported"
3593 local dir1="$DIR/$tdir/dir1"
3594 local dir2="$DIR/$tdir/dir2"
3596 setup_quota_test || error "setup quota failed with $?"
3597 mkdir -p $dir1 $dir2
3598 change_project -sp 1 $dir1 && touch $dir1/1
3599 change_project -sp 2 $dir2
3601 mv $dir1/1 $dir2/2 || error "mv failed $?"
3602 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3603 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3605 run_test 40b "Mv across different project ID"
3608 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3609 ! is_project_quota_supported &&
3610 skip "Project quota is not supported"
3612 setup_quota_test || error "setup quota failed with $?"
3613 local dir="$DIR/$tdir/dir"
3615 mkdir -p $dir && change_project -sp 1 $dir
3616 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3617 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3618 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3619 touch $dir/remote_dir/file
3620 #verify inherit works file for remote dir.
3621 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3622 [ "$projid" != "1" ] &&
3623 error "file under remote dir expected 1 not $projid"
3625 #Agent inode should be ignored for project quota
3626 local used=$(getquota -p 1 global curinodes)
3628 error "file count expected 3 got $used"
3630 run_test 40c "Remote child Dir inherit project quota properly"
3633 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3634 is_project_quota_supported || skip "Project quota is not supported"
3636 setup_quota_test || error "setup quota failed with $?"
3637 local dir="$DIR/$tdir/dir"
3640 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3641 change_project -sp $TSTPRJID $dir ||
3642 error "change project on $dir failed"
3643 for i in $(seq 5); do
3644 mkdir -p $dir/d$i/d$i ||
3645 error "mkdir $dir/d$i/d$i failed"
3646 local projid=$($LFS project -d $dir/d$i/d$i |
3648 [ "$projid" == "$TSTPRJID" ] ||
3649 error "projid id expected $TSTPRJID not $projid"
3650 touch $dir/d$i/d$i/file
3651 #verify inherit works file for stripe dir.
3652 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3653 [ "$projid" == "$TSTPRJID" ] ||
3654 error "file under remote dir expected 1 not $projid"
3657 # account should be 1 + (2 + 1) *10 + 1 * 5
3658 local used=$(getquota -p $TSTPRJID global curinodes)
3660 error "file count expected 36 got $used"
3662 run_test 40d "Stripe Directory inherit project quota properly"
3665 is_project_quota_supported ||
3666 skip "Project quota is not supported"
3667 setup_quota_test || error "setup quota failed with $?"
3668 local dir="$DIR/$tdir/dir"
3671 local projid=$((testnum * 1000))
3675 # enable mdt/ost quota
3676 set_mdt_qtype ugp || error "enable mdt quota failed"
3677 set_ost_qtype ugp || error "enable ost quota failed"
3679 test_mkdir -p $dir && change_project -sp $projid $dir
3680 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3681 error "set project quota failed"
3686 # check if df output works as expected
3687 echo "== global statfs: $MOUNT =="
3688 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3690 echo "== project statfs (prjid=$projid): $dir =="
3691 df -kP $dir; df -iP $dir
3692 local bused=$(getquota -p $projid global curspace)
3693 local iused=$(getquota -p $projid global curinodes)
3694 # note trailing space to match double printf from awk
3695 local expected="$blimit $bused $ilimit $iused "
3697 wait_update $HOSTNAME \
3698 "{ df -kP $dir; df -iP $dir; } |
3699 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3701 error "failed to get correct statfs for project quota"
3703 run_test 41 "df should return projid-specific values"
3711 local osd="osd-ldiskfs"
3713 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3715 rm -f $DIR/$tdir/$tfile
3716 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3717 chmod a+rw $DIR/$tdir/$tfile
3719 $LFS setquota $qtype $qid -B 300M $MOUNT
3720 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3721 error "failed to dd"
3723 do_facet $SINGLEMDS \
3724 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3725 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3728 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3729 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3731 $LFS setquota $qtype $qid --delete $MOUNT
3732 do_facet $SINGLEMDS \
3733 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3734 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3737 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3738 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3740 $LFS setquota $qtype $qid -B 500M $MOUNT
3741 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3742 error "failed to dd"
3743 do_facet $SINGLEMDS \
3744 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3745 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3746 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3748 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3749 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3754 setup_quota_test || error "setup quota failed with $?"
3755 set_ost_qtype $QTYPE || error "enable ost quota failed"
3758 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3759 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3760 is_project_quota_supported &&
3761 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3765 run_test 48 "lfs quota --delete should delete quota project ID"
3768 ! is_project_quota_supported &&
3769 skip "Project quota is not supported"
3771 setup_quota_test || error "setup quota failed with $?"
3772 local dir1="$DIR/$tdir/dir1"
3773 local dir2="$DIR/$tdir/dir2"
3775 mkdir -p $dir1 && change_project -sp 1 $dir1
3776 mkdir -p $dir2 && change_project -sp 2 $dir2
3777 for num in $(seq 1 10); do
3778 touch $dir1/file_$num $dir2/file_$num
3779 ln -s $dir1/file_$num $dir1/file_$num"_link"
3780 ln -s $dir2/file_$num $dir2/file_$num"_link"
3783 count=$($LFS find --projid 1 $DIR | wc -l)
3784 [ "$count" != 21 ] && error "expected 21 but got $count"
3786 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3787 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3788 [ $count -eq 22 ] || error "expected 22 but got $count"
3790 run_test 50 "Test if lfs find --projid works"
3793 ! is_project_quota_supported &&
3794 skip "Project quota is not supported"
3795 setup_quota_test || error "setup quota failed with $?"
3796 local dir="$DIR/$tdir/dir"
3798 mkdir $dir && change_project -sp 1 $dir
3799 local used=$(getquota -p 1 global curinodes)
3800 [ $used != "1" ] && error "expected 1 got $used"
3805 used=$(getquota -p 1 global curinodes)
3806 [ $used != "4" ] && error "expected 4 got $used"
3808 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3810 cp $DIR/$tdir/6 $dir/6
3811 used=$(getquota -p 1 global curinodes)
3812 [ $used != "5" ] && error "expected 5 got $used"
3815 mv $DIR/$tdir/6 $dir/7
3816 used=$(getquota -p 1 global curinodes)
3817 [ $used -eq 6 ] || error "expected 6 got $used"
3819 run_test 51 "Test project accounting with mv/cp"
3822 ! is_project_quota_supported &&
3823 skip "Project quota is not supported"
3825 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
3826 skip "Need MDS version at least 2.14.55"
3828 setup_quota_test || error "setup quota failed with $?"
3830 local dir1=$DIR/$tdir/t52_dir1
3831 local dir2=$DIR/$tdir/t52_dir2
3833 mkdir $dir1 || error "failed to mkdir $dir1"
3834 mkdir $dir2 || error "failed to mkdir $dir2"
3836 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
3837 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
3839 $DD if=/dev/zero of=/$dir1/$tfile bs=1M count=100 ||
3840 error "failed to create and write $tdir1/$tfile"
3842 cancel_lru_locks osc
3843 sync; sync_all_data || true
3845 local attrs=($(lsattr -p $dir1/$tfile))
3846 (( ${attrs[0]} == 1000 )) ||
3847 error "project ID on $dir1/$tfile is not inherited"
3849 $LFS quota -p 1000 $DIR
3850 $LFS quota -p 1001 $DIR
3852 local prev_used=$(getquota -p 1000 global curspace)
3853 local prev_used2=$(getquota -p 1001 global curspace)
3855 mrename $dir1 $dir2/tdir || log "rename directory return $?"
3857 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
3858 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
3859 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
3861 attrs=($(lsattr -p $dir2/$tfile))
3862 (( ${attrs[0]} == 1001 )) ||
3863 error "project ID is not updated after rename"
3865 (( $inum_before == $inum_after )) ||
3866 error "inode is changed after rename: $inum_before, $inum_after"
3868 sync_all_data || true
3870 $LFS quota -p 1000 $DIR
3871 $LFS quota -p 1001 $DIR
3873 local new_used=$(getquota -p 1000 global curspace)
3874 local new_used2=$(getquota -p 1001 global curspace)
3876 (( $prev_used >= $new_used + 102400 )) ||
3877 error "quota is not deducted from old project ID"
3878 (( $prev_used2 <= $new_used2 - 102400 )) ||
3879 error "quota is not added for the new project ID"
3881 run_test 52 "Rename normal file across project ID"
3884 ! is_project_quota_supported &&
3885 skip "Project quota is not supported"
3886 setup_quota_test || error "setup quota failed with $?"
3887 local dir="$DIR/$tdir/dir"
3888 mkdir $dir && change_project -s $dir
3889 [[ $($LFS project -d $dir) =~ " P " ]] ||
3890 error "inherit attribute should be set"
3892 change_project -C $dir
3893 [[ $($LFS project -d $dir) =~ " - " ]] ||
3894 error "inherit attribute should be cleared"
3896 run_test 53 "Project inherit attribute could be cleared"
3899 ! is_project_quota_supported &&
3900 skip "Project quota is not supported"
3901 setup_quota_test || error "setup quota failed with $?"
3902 local testfile="$DIR/$tdir/$tfile-0"
3904 #set project ID/inherit attribute
3905 change_project -sp $TSTPRJID $DIR/$tdir
3906 $RUNAS createmany -m ${testfile} 100 ||
3907 error "create many files failed"
3909 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3910 # one more count for directory itself */
3914 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3915 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3917 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3918 [ $proj_count1 -eq $proj_count ] ||
3919 error "c2: expected $proj_count got $proj_count1"
3921 #clear project but with kept projid
3922 change_project -rCk $DIR/$tdir
3923 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3924 [ $proj_count1 -eq 1 ] ||
3925 error "c3: expected 1 got $proj_count1"
3927 #verify projid untouched.
3928 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3930 [ $proj_count1 -eq $proj_count ] ||
3931 error "c4: expected $proj_count got $proj_count1"
3934 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3935 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3936 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3938 #this time clear all
3939 change_project -rC $DIR/$tdir
3940 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3941 [ $proj_count1 -eq 0 ] ||
3942 error "c6: expected 0 got $proj_count1"
3944 unlinkmany ${testfile} 100 ||
3945 error "unlink many files failed"
3947 run_test 54 "basic lfs project interface test"
3950 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3951 skip "Not supported before 2.10.58."
3952 setup_quota_test || error "setup quota failed with $?"
3954 set_ost_qtype $QTYPE || error "enable ost quota failed"
3957 #add second group to TSTUSR
3958 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3961 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3962 error "failed to dd"
3964 cancel_lru_locks osc
3965 sync; sync_all_data || true
3967 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3968 error "failed to setquota on group $TSTUSR2"
3970 $LFS quota -v -g $TSTUSR2 $DIR
3972 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3973 error "chgrp should failed with -EDQUOT"
3975 USED=$(getquota -g $TSTUSR2 global curspace)
3978 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3979 error "failed to setquota on group $TSTUSR2"
3981 $LFS quota -v -g $TSTUSR2 $DIR
3983 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3984 error "chgrp should succeed"
3986 $LFS quota -v -g $TSTUSR2 $DIR
3988 run_test 55 "Chgrp should be affected by group quota"
3991 setup_quota_test || error "setup quota failed with $?"
3993 set_ost_qtype $QTYPE || error "enable ost quota failed"
3996 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3997 erro "failed to set grace time for usr quota"
3998 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3999 awk '{print $4 $8}')
4000 if [ "x$grace_time" != "x10s;10s" ]; then
4001 $LFS quota -t -u $DIR
4002 error "expected grace time: 10s;10s, got:$grace_time"
4005 run_test 56 "lfs quota -t should work well"
4008 setup_quota_test || error "setup quota failed with $?"
4010 local dir="$DIR/$tdir/dir"
4013 #command can process further if it hit some errors
4014 $LFS project -sp 1 $dir/pipe
4015 touch $dir/aaa $dir/bbb
4016 mkdir $dir/subdir -p
4017 touch $dir/subdir/aaa $dir/subdir/bbb
4018 #create one invalid link file
4019 ln -s $dir/not_exist_file $dir/ccc
4020 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4021 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4023 run_test 57 "lfs project could tolerate errors"
4026 [ "$mds1_FSTYPE" != ldiskfs ] &&
4027 skip "ldiskfs only test"
4028 disable_project_quota
4029 setup_quota_test || error "setup quota failed with $?"
4032 local testfile="$DIR/$tdir/$tfile-0"
4033 #make sure it did not crash kernel
4034 touch $testfile && lfs project -sp 1 $testfile
4036 enable_project_quota
4038 run_test 59 "lfs project dosen't crash kernel with project disabled"
4041 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4042 skip "Needs MDS version 2.11.53 or later."
4043 setup_quota_test || error "setup quota failed with $?"
4045 local testfile=$DIR/$tdir/$tfile
4048 set_mdt_qtype "ug" || error "enable mdt quota failed"
4050 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4051 error "set quota failed"
4052 quota_show_check a g $TSTUSR
4054 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4055 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4056 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4057 error "create many files failed"
4059 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4061 # root user can overrun quota
4062 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4063 error "root user should succeed"
4065 run_test 60 "Test quota for root with setgid"
4067 # test default quota
4068 test_default_quota() {
4069 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4070 skip "Not supported before 2.11.51."
4075 local qprjid=$TSTPRJID
4079 local LIMIT=20480 #20M disk space
4080 local TESTFILE="$DIR/$tdir/$tfile-0"
4083 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4084 echo "Project quota is not supported" && return 0
4086 [ $qtype == "-u" ] && qdtype="-U"
4087 [ $qtype == "-g" ] && qdtype="-G"
4088 [ $qtype == "-p" ] && {
4093 [ $qres_type == "meta" ] && {
4094 LIMIT=10240 #10K inodes
4099 qpool_cmd="--pool $3"
4100 # pool quotas don't work properly without global limit
4101 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4102 error "set global limit failed"
4105 setup_quota_test || error "setup quota failed with $?"
4109 # enable mdt/ost quota
4110 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4111 set_ost_qtype $QTYPE || error "enable ost quota failed"
4113 log "set to use default quota"
4114 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4115 error "set $qid to use default quota failed"
4117 log "set default quota"
4118 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4119 error "set $qid default quota failed"
4121 log "get default quota"
4122 $LFS quota $qdtype $DIR || error "get default quota failed"
4124 if [ $qres_type == "data" ]; then
4125 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4126 grep "$MOUNT" | awk '{print $2}')
4127 [ $SLIMIT -eq $LIMIT ] ||
4128 error "the returned default quota is wrong"
4130 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4132 [ $SLIMIT -eq $LIMIT ] ||
4133 error "the returned default quota is wrong"
4136 # make sure the system is clean
4137 local USED=$(getquota $qtype $qid global curspace)
4138 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4140 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4141 error "setstripe $TESTFILE failed"
4142 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4144 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4146 log "Test not out of quota"
4147 if [ $qres_type == "data" ]; then
4148 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4149 quota_error $qtype $qid "write failed, expect succeed"
4151 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4152 quota_error $qtype $qid "create failed, expect succeed"
4154 unlinkmany $TESTFILE $((LIMIT/2))
4157 log "Test out of quota"
4158 # flush cache, ensure noquota flag is set on client
4159 cancel_lru_locks osc
4160 cancel_lru_locks mdc
4161 sync; sync_all_data || true
4162 if [ $qres_type == "data" ]; then
4163 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4164 quota_error $qtype $qid "write succeed, expect EDQUOT"
4166 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4167 quota_error $qtype $qid "create succeed, expect EDQUOT"
4169 unlinkmany $TESTFILE $((LIMIT*2))
4173 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4174 error "setstripe $TESTFILE failed"
4175 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4177 log "Increase default quota"
4179 # LU-4505: sleep 5 seconds to enable quota acquire
4182 # increase default quota
4183 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4184 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4186 cancel_lru_locks osc
4187 cancel_lru_locks mdc
4188 sync; sync_all_data || true
4189 if [ $qres_type == "data" ]; then
4190 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4191 quota_error $qtype $qid "write failed, expect succeed"
4193 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4194 quota_error $qtype $qid "create failed, expect succeed"
4196 unlinkmany $TESTFILE $((LIMIT*2))
4199 log "Set quota to override default quota"
4200 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4201 error "set $qid quota failed"
4203 cancel_lru_locks osc
4204 cancel_lru_locks mdc
4205 sync; sync_all_data || true
4206 if [ $qres_type == "data" ]; then
4207 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4208 quota_error $qtype $qid "write succeed, expect EQUOT"
4210 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4211 quota_error $qtype $qid "create succeed, expect EQUOT"
4213 unlinkmany $TESTFILE $((LIMIT*2))
4216 log "Set to use default quota again"
4218 # LU-4505: sleep 5 seconds to enable quota acquire
4221 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4222 error "set $qid to use default quota failed"
4224 cancel_lru_locks osc
4225 cancel_lru_locks mdc
4226 sync; sync_all_data || true
4227 if [ $qres_type == "data" ]; then
4228 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4229 quota_error $qtype $qid "write failed, expect succeed"
4231 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4232 quota_error $qtype $qid "create failed, expect succeed"
4234 unlinkmany $TESTFILE $((LIMIT*2))
4239 wait_delete_completed || error "wait_delete_completed failed"
4240 sync_all_data || true
4242 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4243 error "reset default quota failed"
4244 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4245 error "reset quota failed"
4250 test_default_quota "-u" "data"
4251 test_default_quota "-u" "meta"
4252 test_default_quota "-g" "data"
4253 test_default_quota "-g" "meta"
4254 test_default_quota "-p" "data"
4255 test_default_quota "-p" "meta"
4257 run_test 61 "default quota tests"
4260 ! is_project_quota_supported &&
4261 skip "Project quota is not supported"
4262 [[ "$(chattr -h 2>&1)" =~ "project" ||
4263 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4264 skip "chattr did not support project quota"
4265 setup_quota_test || error "setup quota failed with $?"
4266 local testdir=$DIR/$tdir/
4268 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4269 change_project -s $testdir
4270 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4271 error "inherit attribute should be set"
4272 # chattr used FS_IOC_SETFLAGS ioctl
4273 $RUNAS chattr -P $testdir &&
4274 error "regular user clear inherit should fail"
4275 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4276 error "inherit attribute should still be set"
4277 chattr -P $testdir || error "root failed to clear inherit"
4278 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4279 error "inherit attribute should be cleared"
4282 run_test 62 "Project inherit should be only changed by root"
4285 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4286 skip "Not supported before 2.11.55"
4290 local dd_failed=false
4291 local tdir_dom=${tdir}_dom
4292 local LIMIT=20480 #20M
4294 [ $qtype == "p" ] && ! is_project_quota_supported &&
4295 echo "Project quota is not supported" && return 0
4297 [ $qtype == "p" ] && qid=$TSTPRJID
4299 setup_quota_test || error "setup quota failed with $?"
4303 # enable mdt/ost quota
4304 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4305 set_ost_qtype $QTYPE || error "enable ost quota failed"
4307 # make sure the system is clean
4308 local USED=$(getquota -$qtype $qid global curspace)
4309 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4311 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4313 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4314 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4315 error "setstripe $tdir_dom failed"
4316 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4318 [ $qtype == "p" ] && {
4319 change_project -sp $TSTPRJID $DIR/$tdir
4320 change_project -sp $TSTPRJID $DIR/$tdir_dom
4323 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4324 error "set $qid quota failed"
4326 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4327 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4331 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4333 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4334 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4338 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4340 rm -f $DIR/$tdir_dom/*
4342 # flush cache, ensure noquota flag is set on client
4343 cancel_lru_locks osc
4344 cancel_lru_locks mdc
4345 sync; sync_all_data || true
4349 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4350 quota_error $qtype $qid "write failed, expect succeed"
4352 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4353 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4357 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4360 rm -f $DIR/$tdir_dom/*
4362 # flush cache, ensure noquota flag is set on client
4363 cancel_lru_locks osc
4364 cancel_lru_locks mdc
4365 sync; sync_all_data || true
4369 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4370 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4374 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4376 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4377 quota_error $qtype $qid "write succeed, expect EDQUOT"
4380 rm -fr $DIR/$tdir_dom
4382 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4383 error "reset usr quota failed"
4391 run_test 63 "quota on DoM tests"
4394 ! is_project_quota_supported &&
4395 skip "Project quota is not supported"
4396 setup_quota_test || error "setup quota failed with $?"
4397 local dir1="$DIR/$tdir/"
4400 ln -s $dir1/file $dir1/file_link
4403 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4404 error "set project should succeed"
4406 used=$(getquota -p $TSTPRJID global curinodes)
4407 [ $used -eq 4 ] || error "expected 4 got $used"
4408 $LFS project -rC $dir1 >&/dev/null ||
4409 error "clear project should succeed"
4411 used=$(getquota -p $TSTPRJID global curinodes)
4412 [ $used -eq 0 ] || error "expected 0 got $used"
4414 run_test 64 "lfs project on non dir/files should succeed"
4418 local TESTFILE="$DIR/$tdir/$tfile-0"
4420 setup_quota_test || error "setup quota failed with $?"
4421 set_ost_qtype $QTYPE || error "enable ost quota failed"
4425 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4426 error "failed to write"
4427 # flush cache, ensure noquota flag is set on client
4428 cancel_lru_locks osc
4429 sync; sync_all_data || true
4431 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4432 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4433 local quota_all=$($RUNAS $LFS quota $DIR)
4435 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4436 error "usr quota not match"
4437 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4438 error "grp quota not match"
4440 run_test 65 "Check lfs quota result"
4443 ! is_project_quota_supported &&
4444 skip "Project quota is not supported"
4445 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4446 skip "Not supported before 2.12.4"
4447 setup_quota_test || error "setup quota failed with $?"
4448 local old=$(do_facet mds1 $LCTL get_param -n \
4449 mdt.*.enable_chprojid_gid | head -1)
4450 local testdir=$DIR/$tdir/foo
4452 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4453 stack_trap "do_facet mds1 $LCTL \
4454 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4456 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4457 chown -R $TSTID:$TSTID $testdir
4458 change_project -sp $TSTPRJID $testdir
4459 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4461 $RUNAS lfs project -p 0 $testdir/foo &&
4462 error "nonroot user should fail to set projid"
4464 $RUNAS lfs project -C $testdir/foo &&
4465 error "nonroot user should fail to clear projid"
4467 change_project -C $testdir/foo || error "failed to clear project"
4469 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4470 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4471 "failed to set projid with normal user when enable_chprojid_gid=-1"
4473 $RUNAS lfs project -rC $testdir/ || error \
4474 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4476 touch $testdir/bar || error "failed touch $testdir/bar"
4477 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4478 "normal user should not be able to set projid on root owned file"
4480 change_project -p $TSTPRJID $testdir/bar || error \
4481 "root should be able to change its own file's projid"
4483 run_test 66 "nonroot user can not change project state in default"
4490 local short_qtype=${qtype:0:1}
4493 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4495 $TSTUSR) _runas=$RUNAS;;
4496 $TSTUSR2) _runas=$RUNAS2;;
4497 *) error "unknown quota parameter $4";;
4502 $_runas $DD of=$file count=$size ||
4503 quota_error $short_qtype $TSTUSR \
4504 "$qtype write failure, but expect success"
4506 cancel_lru_locks osc
4508 sync; sync_all_data || true
4517 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4519 do_facet mds1 $LCTL get_param $param |
4520 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4525 local testfile="$DIR/$tdir/$tfile-0"
4526 local testfile2="$DIR/$tdir/$tfile-1"
4527 local testfile3="$DIR/$tdir/$tfile-2"
4528 local qpool="qpool1"
4534 [ "$ost1_FSTYPE" == zfs ] &&
4535 skip "ZFS grants some block space together with inode"
4537 setup_quota_test || error "setup quota failed with $?"
4540 set_ost_qtype $QTYPE || error "enable ost quota failed"
4543 log "User quota (block hardlimit:$limit MB)"
4544 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4545 error "set user quota failed"
4547 # make sure the system is clean
4548 used=$(getquota -u $TSTUSR global curspace)
4549 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4551 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4552 echo "granted 0x0 before write $granted"
4554 # trigger reintegration
4555 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4556 procf=${procf}quota_slave.force_reint
4557 do_facet ost1 $LCTL set_param $procf=1 ||
4558 error "force reintegration failed"
4559 wait_ost_reint "u" || error "reintegration failed"
4560 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4561 [ $granted -ne 0 ] &&
4562 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4564 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4565 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4567 # write 10 MB to testfile
4568 test_67_write "$testfile" "user" 10 "$TSTUSR"
4570 # create qpool and add OST1
4571 pool_add $qpool || error "pool_add failed"
4572 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4573 # as $TSTUSR hasn't limits, lqe may absent. But it should be
4574 # created after the 1st direct qmt_get.
4575 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4577 # check granted - should be 0, as testfile is located only on OST0
4578 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4579 echo "global granted $granted"
4580 granted=$(getgranted $qpool "dt" $TSTID "usr")
4581 echo "$qpool granted $granted"
4582 [ $granted -ne 0 ] &&
4583 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4585 # add OST0 to qpool and check granted space
4586 pool_add_targets $qpool 0 1 ||
4587 error "pool_add_targets failed"
4588 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4589 echo "Granted $granted_mb MB"
4590 #should be 10M + qunit for each OST
4591 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4592 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4594 $LFS setstripe $testfile2 -c 1 -i 1 ||
4595 error "setstripe $testfile2 failed"
4596 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4597 # Write from another user and check that qpool1
4598 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
4599 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
4600 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4601 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4602 [ $granted -ne 0 ] &&
4603 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4605 # Granted space for $TSTUSR2 in qpool1 should appear only
4606 # when global lqe for this user becomes enforced.
4607 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4608 error "set user quota failed"
4609 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4610 echo "granted_mb $granted_mb"
4611 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4612 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4614 $LFS setstripe $testfile3 -c 1 -i 0 ||
4615 error "setstripe $testfile3 failed"
4616 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4617 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
4618 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4619 echo "$testfile3 granted_mb $granted_mb"
4620 [ $granted_mb -eq $limit ] ||
4621 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4623 # remove OST1 from the qpool1 and check granted space
4624 # should be 0 for TSTUSR and 10M for TSTUSR2
4625 pool_remove_target $qpool 0
4626 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4627 [ $granted_mb -eq 0 ] ||
4628 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4629 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4630 [ $granted_mb -eq 10 ] ||
4631 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4634 wait_delete_completed || error "wait_delete_completed failed"
4635 sync_all_data || true
4636 used=$(getquota -u $TSTUSR global curspace)
4637 [ $used -eq 0 ] || quota_error u $TSTUSR \
4638 "user quota isn't released after deletion"
4640 run_test 67 "quota pools recalculation"
4647 wait_update_facet mds1 \
4648 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4649 >/dev/null 2>&1 || echo foo" "" ||
4650 error "mds1: failed to create quota pool $pool"
4652 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4653 awk '/usr/ {getline; print $2}'
4658 local qpool="qpool1"
4661 setup_quota_test || error "setup quota failed with $?"
4664 set_ost_qtype $QTYPE || error "enable ost quota failed"
4666 # check slave number for glbal pool
4667 local nr=$(get_slave_nr "0x0" "usr")
4668 echo "nr result $nr"
4669 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4670 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4672 # create qpool and add OST1
4673 pool_add $qpool || error "pool_add failed"
4674 nr=$(get_slave_nr $qpool "usr")
4675 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4678 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4679 nr=$(get_slave_nr $qpool "usr")
4680 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4683 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4684 nr=$(get_slave_nr $qpool "usr")
4685 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4688 pool_remove_target $qpool 0
4689 nr=$(get_slave_nr $qpool "usr")
4690 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4693 pool_remove_target $qpool 1
4694 nr=$(get_slave_nr $qpool "usr")
4695 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4697 # Check again that all is fine with global pool
4698 nr=$(get_slave_nr "0x0" "usr")
4699 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4700 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4702 run_test 68 "slave number in quota pool changed after each add/remove OST"
4706 local global_limit=200 # MB
4708 local testfile="$DIR/$tdir/$tfile-0"
4709 local dom0="$DIR/$tdir/dom0"
4710 local qpool="qpool1"
4713 setup_quota_test || error "setup quota failed with $?"
4716 set_ost_qtype $QTYPE || error "enable ost quota failed"
4717 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4719 # Save DOM only at MDT0
4720 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4721 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4723 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4725 # create qpool and add OST0
4726 pool_add $qpool || error "pool_add failed"
4727 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4729 log "User quota (block hardlimit:$global_limit MB)"
4730 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4731 error "set user quota failed"
4733 log "User quota (block hardlimit:$limit MB)"
4734 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4735 error "set user quota failed"
4737 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4738 quota_error u $TSTUSR "write failed"
4740 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4741 oflag=sync || quota_error u $TSTUSR "write failed"
4743 $RUNAS $DD of=$testfile count=$limit || true
4745 # flush cache, ensure noquota flag is set on client
4746 cancel_lru_locks osc
4747 sync; sync_all_data || true
4749 # MDT0 shouldn't get EDQUOT with glimpse.
4750 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4751 quota_error u $TSTUSR \
4752 "user write success, but expect EDQUOT"
4754 # Now all members of qpool1 should get EDQUOT. Expect success
4755 # when write to DOM on MDT0, as it belongs to global pool.
4756 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4757 oflag=sync || quota_error u $TSTUSR "write failed"
4759 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4760 oflag=sync || quota_error u $TSTUSR "write failed"
4762 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4766 local qpool="qpool1"
4771 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4772 skip "Needs a client >= $VERSION_WITH_QP"
4774 setup_quota_test || error "setup quota failed with $?"
4776 # MDS returns EFAULT for unsupported quotactl command
4777 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4779 # create qpool and add OST0
4780 pool_add $qpool || error "pool_add failed"
4781 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4783 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4785 [ $rc -eq $err ] || error "setquota res $rc != $err"
4787 # If MDS supports QP, check that limit was set properly.
4788 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4789 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4790 echo "hard limit $bhard limit $limit"
4791 [ $bhard -ne $((limit*1024)) ] &&
4792 error "bhard:$bhard for $qpool!=$((limit*1024))"
4795 $LFS quota -u $TSTUSR --pool $qpool $DIR
4797 [ $rc -eq $err ] || error "quota res $rc != $err"
4799 run_test 70a "check lfs setquota/quota with a pool option"
4803 local glbl_hard=200 # 200M
4804 local glbl_soft=100 # 100M
4805 local pool_hard=10 # 10M
4806 local qpool="qpool1"
4808 pool_add $qpool || error "pool_add failed"
4809 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4811 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
4812 error "set user quota failed"
4813 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
4814 error "set user quota failed"
4816 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4817 [ $tmp -eq $((pool_hard * 1024)) ] ||
4818 error "wrong block hard limit $tmp for $qpool"
4819 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
4820 # soft limit hasn't been set and should be zero
4821 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
4823 run_test 70b "lfs setquota pool works properly"
4828 local global_limit=100 # MB
4829 local testfile="$DIR/$tdir/$tfile-0"
4830 local qpool="qpool1"
4831 local qpool2="qpool2"
4833 [ "$ost1_FSTYPE" == zfs ] &&
4834 skip "ZFS grants some block space together with inode"
4835 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4837 setup_quota_test || error "setup quota failed with $?"
4840 set_ost_qtype $QTYPE || error "enable ost quota failed"
4843 log "User quota (block hardlimit:$global_limit MB)"
4844 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4845 error "set user quota failed"
4847 pool_add $qpool || error "pool_add failed"
4848 pool_add_targets $qpool 0 1 ||
4849 error "pool_add_targets failed"
4851 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4852 error "set user quota failed"
4854 pool_add $qpool2 || error "pool_add failed"
4855 pool_add_targets $qpool2 1 1 ||
4856 error "pool_add_targets failed"
4858 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4859 error "set user quota failed"
4861 # make sure the system is clean
4862 local used=$(getquota -u $TSTUSR global curspace)
4865 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4867 # create 1st component 1-10M
4868 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4869 #create 2nd component 10-30M
4870 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4871 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4873 # сheck normal use and out of quota with PFL
4874 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4875 test_1_check_write $testfile "user" $((limit*2))
4877 wait_delete_completed || error "wait_delete_completed failed"
4878 sync_all_data || true
4879 used=$(getquota -u $TSTUSR global curspace)
4880 [ $used -ne 0 ] && quota_error u $TSTUSR \
4881 "user quota isn't released after deletion"
4883 # create 1st component 1-10M
4884 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4885 # create 2nd component 10-30M
4886 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4887 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4889 # write to the 2nd component
4890 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4891 quota_error u $TSTUSR \
4892 "write failure, but expect success"
4893 # this time maybe cache write, ignore it's failure
4894 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4895 cancel_lru_locks osc
4896 sync; sync_all_data || true
4897 # write over limit in qpool2(2nd component 10-30M)
4898 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4899 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4900 # write to the 1st component - OST0 is empty
4901 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4902 quota_error u $TSTUSR "write failed"
4904 run_test 71a "Check PFL with quota pools"
4908 local global_limit=1000 # MB
4909 local limit1=160 # MB
4910 local limit2=10 # MB
4911 local testfile="$DIR/$tdir/$tfile-0"
4912 local qpool="qpool1"
4913 local qpool2="qpool2"
4915 [ "$ost1_FSTYPE" == zfs ] &&
4916 skip "ZFS grants some block space together with inode"
4917 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4919 setup_quota_test || error "setup quota failed with $?"
4922 set_ost_qtype $QTYPE || error "enable ost quota failed"
4925 log "User quota (block hardlimit:$global_limit MB)"
4926 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4927 error "set user quota failed"
4929 pool_add $qpool || error "pool_add failed"
4930 pool_add_targets $qpool 0 1 ||
4931 error "pool_add_targets failed"
4933 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4934 error "set user quota failed"
4936 pool_add $qpool2 || error "pool_add failed"
4937 pool_add_targets $qpool2 1 1 ||
4938 error "pool_add_targets failed"
4940 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4941 error "set user quota failed"
4943 # make sure the system is clean
4944 local used=$(getquota -u $TSTUSR global curspace)
4947 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4949 # First component is on OST0, 2nd on OST1
4950 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4951 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4953 # fill the 1st component on OST0
4954 $RUNAS $DD of=$testfile count=128 ||
4955 quota_error u $TSTUSR "write failed"
4956 # write to the 2nd cmpnt on OST1
4957 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4958 quota_error u $TSTUSR "write failed"
4959 # this time maybe cache write, ignore it's failure
4960 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4962 cancel_lru_locks osc
4963 sync; sync_all_data || true
4964 # write over limit in qpool2
4965 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4966 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4969 run_test 71b "Check SEL with quota pools"
4974 local global_limit=50 # MB
4975 local testfile="$DIR/$tdir/$tfile-0"
4976 local qpool="qpool1"
4979 setup_quota_test || error "setup quota failed with $?"
4982 set_ost_qtype $QTYPE || error "enable ost quota failed"
4985 log "User quota (block hardlimit:$global_limit MB)"
4986 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4987 error "set user quota failed"
4989 pool_add $qpool || error "pool_add failed"
4990 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4992 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4993 error "set user quota failed"
4995 # make sure the system is clean
4996 local used=$(getquota -u $TSTUSR global curspace)
4998 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5000 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5002 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5003 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5004 test_1_check_write $testfile "user" $limit
5005 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5007 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5008 # check that lfs quota -uv --pool prints only OST that
5009 # was added in a pool
5010 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5011 grep "OST\|MDT" && error "$qpool consists wrong targets"
5014 run_test 72 "lfs quota --pool prints only pool's OSTs"
5018 local qpool="qpool1"
5022 pool_add $qpool || error "pool_add failed"
5023 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5024 error "pool_add_targets failed"
5026 test_default_quota "-u" "data" "qpool1"
5028 run_test 73a "default limits at OST Pool Quotas"
5032 local TESTFILE1="$DIR/$tdir/$tfile-1"
5034 local qpool="qpool1"
5038 setup_quota_test || error "setup quota failed with $?"
5040 set_ost_qtype $QTYPE || error "enable ost quota failed"
5042 # pool quotas don't work properly without global limit
5043 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5044 error "set global limit failed"
5046 pool_add $qpool || error "pool_add failed"
5047 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5048 error "pool_add_targets failed"
5050 log "set default quota for $qpool"
5051 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5052 error "set default quota failed"
5054 log "Write from user that hasn't lqe"
5055 # Check that it doesn't cause a panic or a deadlock
5056 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5057 # Have to use RUNAS_ID as resetquota creates lqes in
5058 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5059 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5061 cancel_lru_locks osc
5062 sync; sync_all_data || true
5064 run_test 73b "default OST Pool Quotas limit for new user"
5068 local global_limit=200 # 200M
5069 local limit=10 # 10M
5070 local limit2=50 # 50M
5071 local qpool="qpool1"
5072 local qpool2="qpool2"
5076 setup_quota_test || error "setup quota failed with $?"
5079 set_ost_qtype $QTYPE || error "enable ost quota failed"
5081 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5082 error "set user quota failed"
5084 pool_add $qpool || error "pool_add failed"
5085 pool_add_targets $qpool 0 1 ||
5086 error "pool_add_targets failed"
5088 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5089 error "set user quota failed"
5091 pool_add $qpool2 || error "pool_add failed"
5092 pool_add_targets $qpool2 1 1 ||
5093 error "pool_add_targets failed"
5095 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5096 error "set user quota failed"
5098 tmp=$(getquota -u $TSTUSR global bhardlimit)
5099 [ $tmp -eq $((global_limit * 1024)) ] ||
5100 error "wrong global limit $global_limit"
5102 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5103 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5105 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5106 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5108 # check limits in pools
5109 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5110 grep -A4 $qpool | awk 'NR == 4{print $4}')
5111 echo "pool limit for $qpool $tmp"
5112 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5113 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5114 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5115 echo "pool limit for $qpool2 $tmp"
5116 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5118 run_test 74 "check quota pools per user"
5120 function cleanup_quota_test_75()
5122 do_facet mgs $LCTL nodemap_modify --name default \
5123 --property admin --value 1
5124 do_facet mgs $LCTL nodemap_modify --name default \
5125 --property trusted --value 1
5126 do_facet mgs $LCTL nodemap_modify --name default \
5127 --property squash_uid --value 99
5128 do_facet mgs $LCTL nodemap_modify --name default \
5129 --property squash_gid --value 99
5131 wait_nm_sync default admin_nodemap
5132 wait_nm_sync default trusted_nodemap
5134 do_facet mgs $LCTL nodemap_activate 0
5137 resetquota -u $TSTUSR
5141 local dd_failed=false
5142 local LIMIT=20480 #20M
5145 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5146 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5147 oflag=sync || dd_failed=true
5150 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5152 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5153 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5154 oflag=sync || dd_failed=true
5157 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5159 rm -f $DIR/$tdir_dom/*
5161 # flush cache, ensure noquota flag is set on client
5163 sync; sync_all_data || true
5167 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
5168 quota_error u $qid "write failed, expect succeed (2)"
5170 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5171 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5172 oflag=sync || dd_failed=true
5175 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5178 rm -f $DIR/$tdir_dom/*
5180 # flush cache, ensure noquota flag is set on client
5182 sync; sync_all_data || true
5186 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5187 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5188 oflag=sync || dd_failed=true
5191 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5193 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
5194 quota_error u $qid "write succeed, expect EDQUOT (3)"
5200 local soft_limit=10 # MB
5201 local hard_limit=20 # MB
5202 local limit=$soft_limit
5203 local testfile="$DIR/$tdir/$tfile-0"
5204 local grace=20 # seconds
5205 local tdir_dom=${tdir}_dom
5207 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5211 setup_quota_test || error "setup quota failed with $?"
5212 stack_trap cleanup_quota_test_75 EXIT
5215 set_ost_qtype $QTYPE || error "enable ost quota failed"
5216 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5218 local used=$(getquota -u $TSTID global curspace)
5219 $LFS setquota -t -u --block-grace $grace --inode-grace \
5220 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5221 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5222 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5223 error "set user quota failed"
5225 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5226 mkdir $DIR/$tdir_dom
5227 chmod 777 $DIR/$tdir_dom
5228 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5229 error "setstripe $tdir_dom failed"
5231 do_facet mgs $LCTL nodemap_activate 1
5233 do_facet mgs $LCTL nodemap_modify --name default \
5234 --property admin --value 0
5235 do_facet mgs $LCTL nodemap_modify --name default \
5236 --property trusted --value 0
5237 do_facet mgs $LCTL nodemap_modify --name default \
5238 --property deny_unknown --value 0
5239 do_facet mgs $LCTL nodemap_modify --name default \
5240 --property squash_uid --value $TSTID
5241 do_facet mgs $LCTL nodemap_modify --name default \
5242 --property squash_gid --value $TSTID
5243 cancel_lru_locks mdc
5244 wait_nm_sync default admin_nodemap
5245 wait_nm_sync default trusted_nodemap
5246 wait_nm_sync default squash_uid
5248 # mmap write when over soft limit
5250 $DD of=$testfile count=${limit} ||
5251 quota_error a "root write failure, but expect success (1)"
5252 OFFSET=$((limit * 1024))
5253 cancel_lru_locks osc
5255 echo "Write to exceed soft limit"
5256 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5257 quota_error a $TSTUSR "root write failure, but expect success (2)"
5258 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5259 cancel_lru_locks osc
5261 echo "mmap write when over soft limit"
5262 $MULTIOP $testfile.mmap OT40960SMW ||
5263 quota_error a $TSTUSR "mmap write failure, but expect success"
5264 cancel_lru_locks osc
5266 wait_delete_completed || error "wait_delete_completed failed (1)"
5267 sync_all_data || true
5269 # test for user hard limit
5272 $DD of=$testfile bs=1M count=$((limit/2)) ||
5273 quota_error u $TSTID \
5274 "root write failure, but expect success (3)"
5276 log "Write out of block quota ..."
5277 # possibly a cache write, ignore failure
5278 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
5279 # flush cache, ensure noquota flag is set on client
5280 cancel_lru_locks osc
5281 sync; sync_all_data || true
5282 # sync forced cache flush, but did not guarantee that slave
5283 # got new edquot through glimpse, so wait to make sure
5285 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
5286 quota_error u $TSTID \
5287 "user write success, but expect EDQUOT"
5289 wait_delete_completed || error "wait_delete_completed failed (2)"
5290 sync_all_data || true
5291 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5292 quota_error u $TSTID "user quota not released after deletion"
5296 run_test 75 "nodemap squashed root respects quota enforcement"
5299 ! is_project_quota_supported &&
5300 skip "skip project quota unsupported"
5302 setup_quota_test || error "setup quota failed with $?"
5305 local testfile="$DIR/$tdir/$tfile-0"
5308 $LFS project -p 4294967295 $testfile &&
5309 error "set project ID should fail"
5312 run_test 76 "project ID 4294967295 should be not allowed"
5316 mount_client $MOUNT2 "ro"
5317 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5318 error "lfs setquota should fail in read-only Lustre mount"
5321 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5325 (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
5326 skip "need OST at least 2.14.55"
5327 check_set_fallocate_or_skip
5329 setup_quota_test || error "setup quota failed with $?"
5332 set_ost_qtype $QTYPE || error "enable ost quota failed"
5334 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5335 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5338 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5339 error "lfs setquota failed"
5342 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5344 kbytes=$(lfs quota -u $TSTUSR $DIR |
5345 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5346 echo "kbytes returned:$kbytes"
5348 # For file size of 204800. We should be having roughly 200 kbytes
5349 # returned. Anything alarmingly low (50 taken as arbitrary value)
5350 # would bail out this TC. Also this also avoids $kbytes of 0
5351 # to be used in calculation below.
5352 (( $kbytes > 50 )) ||
5353 error "fallocate did not use quota. kbytes returned:$kbytes"
5355 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5356 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5358 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5359 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5360 error "fallocate did not use quota correctly"
5362 run_test 78 "Check fallocate increase quota usage"
5366 (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
5367 skip "need client at least 2.15.0"
5368 (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
5369 skip "need OST at least 2.15.0"
5370 check_set_fallocate_or_skip
5372 setup_quota_test || error "setup quota failed with $?"
5375 set_ost_qtype $QTYPE || error "enable ost quota failed"
5377 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5379 local projectid=5200 # Random project id to test
5381 change_project -sp $projectid $DIR/$tdir
5384 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5385 error "lfs setquota project failed"
5388 fallocate -l 204800 $DIR/$tdir/$tfile
5390 # Get curspace (kbytes) for $projectid
5391 local kbytes=$(getquota -p $projectid global curspace)
5393 echo "kbytes returned:$kbytes"
5395 # For file size of 204800. We should be having roughly 200 kbytes
5396 # returned. Anything alarmingly low (50 taken as arbitrary value)
5397 # would bail out this TC. Also this also avoids $kbytes of 0
5398 # to be used in calculation below.
5399 (( $kbytes > 50 )) ||
5400 error "fallocate did not use projectid. kbytes returned:$kbytes"
5402 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5403 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5405 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5406 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5407 error "fallocate did not use quota projectid correctly"
5409 run_test 78a "Check fallocate increase projectid usage"
5413 local qpool="qpool1"
5414 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5415 local stopf=$TMP/$tfile
5417 do_facet mds1 "touch $stopf"
5418 stack_trap "do_facet mds1 'rm -f $stopf'"
5419 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5421 pool_add $qpool || error "pool_add failed"
5422 do_facet mds1 "rm $stopf"
5425 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5429 local dir1="$DIR/$tdir/dir1"
5430 local dir2="$DIR/$tdir/dir2"
5431 local TESTFILE0="$dir1/$tfile-0"
5432 local TESTFILE1="$dir1/$tfile-1"
5433 local TESTFILE2="$dir1/$tfile-2"
5434 local TESTFILE3="$dir2/$tfile-0"
5435 local global_limit=100 # 100M
5436 local limit=10 # 10M
5437 local qpool="qpool1"
5439 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5441 [ "$ost1_FSTYPE" == zfs ] &&
5442 skip "ZFS grants some block space together with inode"
5443 setup_quota_test || error "setup quota failed with $?"
5444 set_ost_qtype $QTYPE || error "enable ost quota failed"
5446 # make sure the system is clean
5447 local used=$(getquota -u $TSTUSR global curspace)
5448 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5450 pool_add $qpool || error "pool_add failed"
5451 pool_add_targets $qpool 0 1 ||
5452 error "pool_add_targets failed"
5454 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5455 error "set user quota failed"
5457 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5458 error "set user quota failed"
5459 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5460 error "set user quota failed"
5462 mkdir -p $dir1 || error "failed to mkdir"
5463 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5464 mkdir -p $dir2 || error "failed to mkdir"
5465 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5467 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5468 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5473 $LFS quota -uv $TSTUSR $DIR
5474 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5475 do_facet mds1 $LCTL set_param fail_loc=0xa06
5476 $RUNAS $DD of=$TESTFILE3 count=3 ||
5477 quota_error u $TSTUSR "write failed"
5478 $RUNAS $DD of=$TESTFILE2 count=7 ||
5479 quota_error u $TSTUSR "write failed"
5480 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5481 quota_error u $TSTUSR "write failed"
5484 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5488 do_facet mds1 $LCTL set_param fail_loc=0
5489 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5490 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5491 # OST0 needs some time to update quota usage after removing TESTFILE2
5493 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5494 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5495 quota_error u $TSTUSR "write failure, but expect success"
5497 run_test 80 "check for EDQUOT after OST failover"
5500 local global_limit=20 # 100M
5501 local testfile="$DIR/$tdir/$tfile-0"
5502 local qpool="qpool1"
5505 setup_quota_test || error "setup quota failed with $?"
5508 set_ost_qtype $QTYPE || error "enable ost quota failed"
5511 log "User quota (block hardlimit:$global_limit MB)"
5512 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5514 pool_add $qpool || error "pool_add failed"
5515 #define OBD_FAIL_QUOTA_RECALC 0xA07
5516 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5517 # added OST casues to start pool recalculation
5518 pool_add_targets $qpool 0 0 1
5519 stop mds1 -f || error "MDS umount failed"
5521 #start mds1 back to destroy created pool
5522 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5525 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5529 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
5530 skip "need MDS 2.14.55 or later"
5531 is_project_quota_supported ||
5532 skip "skip project quota unsupported"
5534 setup_quota_test || error "setup quota failed with $?"
5535 stack_trap cleanup_quota_test
5538 local parent_dir="$DIR/$tdir.parent"
5539 local child_dir="$parent_dir/child"
5542 stack_trap "chown -R 0:0 $parent_dir"
5544 chown $TSTUSR:$TSTUSR $parent_dir ||
5545 error "failed to chown on $parent_dir"
5546 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5547 error "failed to chown on $parent_dir"
5549 $LFS project -p 1000 $parent_dir ||
5550 error "failed to set project id on $parent_dir"
5551 $LFS project -p 1001 $child_dir ||
5552 error "failed to set project id on $child_dir"
5554 rmdir $child_dir || error "cannot remove child dir, test failed"
5556 run_test 82 "verify more than 8 qids for single operation"
5558 test_grace_with_default_quota()
5567 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
5568 error "clear default quota [$qdtype] failed"
5570 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
5571 error "reset quota [$qdtype] grace failed"
5574 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5575 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
5578 $LFS setquota $qdtype -B 10G -i 10k $DIR
5581 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5582 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
5584 [ "$bgrace" == "$bgrace2" ] ||
5585 error "set default quota shouldn't affect block grace"
5586 [ "$igrace" == "$igrace2" ] ||
5587 error "set default quota shouldn't affect inode grace"
5593 setup_quota_test || error "setup quota failed with $?"
5594 test_grace_with_default_quota "-u" "-U"
5595 test_grace_with_default_quota "-g" "-G"
5597 is_project_quota_supported || return 0
5598 test_grace_with_default_quota "-p" "-P"
5600 run_test 83 "Setting default quota shouldn't affect grace time"
5604 do_nodes $(comma_list $(nodes_list)) \
5605 "lctl set_param -n debug=-quota-trace"
5606 if $PQ_CLEANUP; then
5607 disable_project_quota
5610 reset_quota_settings
5615 check_and_cleanup_lustre
5616 export QUOTA_AUTO=$QUOTA_AUTO_OLD