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 $?"
1132 set_ost_qtype $QTYPE || error "enable ost quota failed"
1134 log "User quota (block hardlimit:$global_limit MB)"
1135 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1136 error "set user quota failed"
1138 pool_add $qpool1 || error "pool_add failed"
1139 pool_add_targets $qpool1 0 0 ||
1140 error "pool_add_targets failed"
1142 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1143 error "set user quota failed"
1145 # make sure the system is clean
1146 local used=$(getquota -u $TSTUSR global curspace)
1147 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1149 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1152 test_1_check_write $testfile "user" $limit1
1153 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1154 error "set user quota failed"
1156 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1157 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1158 quota_error u $TSTUSR "write failure, but expect success"
1162 wait_delete_completed || error "wait_delete_completed failed"
1163 sync_all_data || true
1165 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1166 error "set user quota failed"
1167 test_1_check_write $testfile "user" $limit1
1168 local tmp_limit=$(($limit1*2))
1169 # increase pool limit
1170 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1171 error "set user quota failed"
1172 # now write shouldn't fail
1173 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1174 quota_error u $TSTUSR "write failure, but expect success"
1175 # decrease pool limit
1176 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1177 error "set user quota failed"
1178 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1179 # flush cache, ensure noquota flag is set on client
1180 cancel_lru_locks osc
1181 sync; sync_all_data || true
1182 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1183 quota_error u $TSTUSR "write success, but expect failure"
1186 run_test 1i "Quota pools: different limit and usage relations"
1190 local testfile="$DIR/$tdir/$tfile-0"
1192 (( $OST1_VERSION >= $(version_code 2.15.52.206) )) ||
1193 skip "need OST at least 2.15.52.206"
1195 is_project_quota_supported ||
1196 skip "skip project quota unsupported"
1198 setup_quota_test || error "setup quota failed with $?"
1201 set_ost_qtype $QTYPE || error "enable ost quota failed"
1204 log "--------------------------------------"
1205 log "Project quota (block hardlimit:$limit mb)"
1206 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1207 error "set project quota failed"
1209 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
1210 change_project -p $TSTPRJID $testfile
1212 local procf=osd-$ost1_FSTYPE.$FSNAME-OST0000.quota_slave.root_prj_enable
1213 do_facet ost1 $LCTL set_param $procf=1 ||
1214 error "enable root quotas for project failed"
1215 stack_trap "do_facet ost1 $LCTL set_param $procf=0"
1217 runas -u 0 -g 0 $DD of=$testfile count=$limit oflag=direct || true
1218 runas -u 0 -g 0 $DD of=$testfile count=$((limit/2)) seek=$limit oflag=direct &&
1219 quota_error "project" $TSTPRJID "root write to project success"
1221 do_facet ost1 $LCTL set_param $procf=0 ||
1222 error "disable root quotas for project failed"
1224 runas -u 0 -g 0 $DD of=$testfile count=$limit seek=$limit oflag=direct ||
1225 quota_error "project" $TSTPRJID "root write to project failed"
1230 used=$(getquota -p $TSTPRJID global curspace)
1231 (( $used == 0 )) || quota_error p $TSTPRJID \
1232 "project quota isn't released after deletion"
1234 run_test 1j "Enable project quota enforcement for root"
1236 # test inode hardlimit
1238 local testfile="$DIR/$tdir/$tfile-0"
1239 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1240 qmt.$FSNAME-QMT0000.md-0x0.info |
1241 sed -e 's/least qunit/least_qunit/' |
1242 awk '/least_qunit/{ print $2 }')
1245 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1246 limit=$((least_qunit * 1024))
1247 echo "least_qunit: '$least_qunit', limit: '$limit'"
1249 local free_inodes=$(mdt_free_inodes 0)
1250 echo "$free_inodes free inodes on master MDT"
1251 [ $free_inodes -lt $limit ] &&
1252 skip "not enough free inodes $free_inodes required $limit"
1254 setup_quota_test || error "setup quota failed with $?"
1257 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1260 log "User quota (inode hardlimit:$limit files)"
1261 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1262 error "set user quota failed"
1264 # make sure the system is clean
1265 local used=$(getquota -u $TSTUSR global curinodes)
1266 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1268 log "Create $((limit - least_qunit)) files ..."
1269 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1270 quota_error u $TSTUSR "user create failure, but expect success"
1271 # it is ok, if it fails on the last qunit
1272 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1273 log "Create out of file quota ..."
1274 $RUNAS touch ${testfile}_xxx &&
1275 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1278 unlinkmany ${testfile} $((limit - least_qunit)) ||
1279 error "unlinkmany $testfile failed"
1280 # if 2nd createmany got EDQUOT, not all of nodes would be created
1281 unlinkmany ${testfile}_yyy $least_qunit || true
1282 rm -f ${testfile}_xxx
1283 wait_delete_completed
1285 used=$(getquota -u $TSTUSR global curinodes)
1286 [ $used -ne 0 ] && quota_error u $TSTUSR \
1287 "user quota isn't released after deletion"
1288 resetquota -u $TSTUSR
1291 log "--------------------------------------"
1292 log "Group quota (inode hardlimit:$limit files)"
1293 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1294 error "set group quota failed"
1296 testfile=$DIR/$tdir/$tfile-1
1297 # make sure the system is clean
1298 used=$(getquota -g $TSTUSR global curinodes)
1299 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1301 log "Create $limit files ..."
1302 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1303 quota_error g $TSTUSR "group create failure, but expect success"
1304 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1305 log "Create out of file quota ..."
1306 $RUNAS touch ${testfile}_xxx &&
1307 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1310 unlinkmany ${testfile} $((limit - least_qunit)) ||
1311 error "unlinkmany $testfile failed"
1312 unlinkmany ${testfile}_yyy $least_qunit || true
1313 rm -f ${testfile}_xxx
1314 wait_delete_completed
1316 used=$(getquota -g $TSTUSR global curinodes)
1317 [ $used -ne 0 ] && quota_error g $TSTUSR \
1318 "user quota isn't released after deletion"
1320 resetquota -g $TSTUSR
1321 ! is_project_quota_supported &&
1322 echo "Skip project quota is not supported" && return 0
1325 log "--------------------------------------"
1326 log "Project quota (inode hardlimit:$limit files)"
1327 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1328 error "set project quota failed"
1330 testfile=$DIR/$tdir/$tfile-1
1331 # make sure the system is clean
1332 used=$(getquota -p $TSTPRJID global curinodes)
1334 error "Used inodes($used) for project $TSTPRJID isn't 0"
1336 change_project -sp $TSTPRJID $DIR/$tdir
1337 log "Create $limit files ..."
1338 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1339 quota_error p $TSTPRJID \
1340 "project create fail, but expect success"
1341 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1342 log "Create out of file quota ..."
1343 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1344 "project create success, but expect EDQUOT"
1345 change_project -C $DIR/$tdir
1348 used=$(getquota -p $TSTPRJID global curinodes)
1349 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1350 "project quota isn't released after deletion"
1353 run_test 2 "File hard limit (normal use and out of quota)"
1362 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1363 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1367 $LFS setstripe $testfile -c 1 -i 0
1368 chown $TSTUSR.$TSTUSR $testfile
1369 [ "$qtype" == "p" ] && is_project_quota_supported &&
1370 change_project -p $TSTPRJID $testfile
1372 echo "Write up to soft limit"
1373 $RUNAS $DD of=$testfile count=$limit ||
1374 quota_error a $TSTUSR "write failure, but expect success"
1375 OFFSET=$((limit * 1024))
1376 cancel_lru_locks osc
1378 echo "Write to exceed soft limit"
1379 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1380 quota_error a $TSTUSR "write failure, but expect success"
1381 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1382 cancel_lru_locks osc
1384 echo "mmap write when over soft limit"
1385 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1386 quota_error a $TSTUSR "mmap write failure, but expect success"
1387 cancel_lru_locks osc
1392 $SHOW_QUOTA_INFO_USER
1393 $SHOW_QUOTA_INFO_GROUP
1394 $SHOW_QUOTA_INFO_PROJID
1396 echo "Write before timer goes off"
1397 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1398 quota_error a $TSTUSR "write failure, but expect success"
1399 OFFSET=$((OFFSET + 1024))
1400 cancel_lru_locks osc
1402 wait_grace_time $qtype "block" $pool
1407 $SHOW_QUOTA_INFO_USER
1408 $SHOW_QUOTA_INFO_GROUP
1409 $SHOW_QUOTA_INFO_PROJID
1411 log "Write after timer goes off"
1412 # maybe cache write, ignore.
1413 # write up to soft least quint to consume all
1414 # possible slave granted space.
1415 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1416 count=$soft_limit seek=$OFFSET || true
1417 OFFSET=$((OFFSET + soft_limit))
1418 cancel_lru_locks osc
1419 log "Write after cancel lru locks"
1420 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1421 quota_error a $TSTUSR "write success, but expect EDQUOT"
1426 $SHOW_QUOTA_INFO_USER
1427 $SHOW_QUOTA_INFO_GROUP
1428 $SHOW_QUOTA_INFO_PROJID
1430 echo "Unlink file to stop timer"
1432 wait_delete_completed
1433 sync_all_data || true
1438 $SHOW_QUOTA_INFO_USER
1439 $SHOW_QUOTA_INFO_GROUP
1440 $SHOW_QUOTA_INFO_PROJID
1442 $LFS setstripe $testfile -c 1 -i 0
1443 chown $TSTUSR.$TSTUSR $testfile
1444 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1447 $RUNAS $DD of=$testfile count=$limit ||
1448 quota_error a $TSTUSR "write failure, but expect success"
1455 local grace=20 # seconds
1456 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1459 local testfile=$DIR/$tdir/$tfile-0
1461 # get minimum soft qunit size
1462 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1463 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1465 set_ost_qtype $QTYPE || error "enable ost quota failed"
1467 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1468 # make sure the system is clean
1469 local used=$(getquota -u $TSTUSR global curspace)
1470 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1472 $LFS setquota -t -u --block-grace $grace --inode-grace \
1473 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1474 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1475 error "set user quota failed"
1477 test_block_soft $testfile $grace $limit "u"
1479 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1480 testfile=$DIR/$tdir/$tfile-1
1481 # make sure the system is clean
1482 used=$(getquota -g $TSTUSR global curspace)
1483 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1485 $LFS setquota -t -g --block-grace $grace --inode-grace \
1486 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1487 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1488 error "set group quota failed"
1490 test_block_soft $testfile $grace $limit "g"
1492 if is_project_quota_supported; then
1493 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1494 testfile=$DIR/$tdir/$tfile-2
1495 # make sure the system is clean
1496 used=$(getquota -p $TSTPRJID global curspace)
1497 [ $used -ne 0 ] && error \
1498 "Used space($used) for project $TSTPRJID isn't 0."
1500 $LFS setquota -t -p --block-grace $grace --inode-grace \
1501 $MAX_IQ_TIME $DIR ||
1502 error "set project grace time failed"
1503 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1504 $DIR || error "set project quota failed"
1506 test_block_soft $testfile $grace $limit "p"
1507 resetquota -p $TSTPRJID
1508 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1509 $MAX_IQ_TIME $DIR ||
1510 error "restore project grace time failed"
1514 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1515 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1516 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1517 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1519 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1522 local grace=20 # seconds
1523 local qpool="qpool1"
1524 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1527 local testfile=$DIR/$tdir/$tfile-0
1530 # get minimum soft qunit size
1531 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1532 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1533 local glbl_limit=$((2*limit))
1534 local glbl_grace=$((2*grace))
1535 echo "limit $limit glbl_limit $glbl_limit"
1536 echo "grace $grace glbl_grace $glbl_grace"
1538 set_ost_qtype $QTYPE || error "enable ost quota failed"
1540 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1541 # make sure the system is clean
1542 local used=$(getquota -u $TSTUSR global curspace)
1543 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1545 pool_add $qpool || error "pool_add failed"
1546 pool_add_targets $qpool 0 1 ||
1547 error "pool_add_targets failed"
1549 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1550 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1551 $LFS setquota -t -u --block-grace $grace \
1552 --pool $qpool $DIR || error "set user grace time failed"
1554 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1555 error "set user quota failed"
1556 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1557 error "set user quota failed"
1559 test_block_soft $testfile $grace $limit "u" $qpool
1561 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1562 testfile=$DIR/$tdir/$tfile-1
1563 # make sure the system is clean
1564 used=$(getquota -g $TSTUSR global curspace)
1565 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1567 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1568 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1569 $LFS setquota -t -g --block-grace $grace \
1570 --pool $qpool $DIR || error "set group grace time failed"
1572 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1573 error "set group quota failed"
1574 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1575 error "set group quota failed"
1577 test_block_soft $testfile $grace $limit "g" $qpool
1579 if is_project_quota_supported; then
1580 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1581 testfile=$DIR/$tdir/$tfile-2
1582 # make sure the system is clean
1583 used=$(getquota -p $TSTPRJID global curspace)
1584 [ $used -ne 0 ] && error \
1585 "Used space($used) for project $TSTPRJID isn't 0."
1587 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1588 $MAX_IQ_TIME $DIR ||
1589 error "set project grace time failed"
1590 $LFS setquota -t -p --block-grace $grace \
1591 --pool $qpool $DIR ||
1592 error "set project grace time failed"
1594 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1595 $DIR || error "set project quota failed"
1596 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1597 --pool $qpool $DIR || error "set project quota failed"
1599 test_block_soft $testfile $grace $limit "p" $qpool
1600 resetquota -p $TSTPRJID
1601 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1602 $MAX_IQ_TIME $DIR ||
1603 error "restore project grace time failed"
1604 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1605 $DIR || error "set project grace time failed"
1609 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1610 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1611 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1612 --pool $qpool $DIR || error "restore user grace time failed"
1613 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1614 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1615 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1616 --pool $qpool $DIR || error "restore group grace time failed"
1618 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1621 local grace=20 # seconds
1622 local qpool="qpool1"
1623 local qpool2="qpool2"
1624 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1627 local testfile=$DIR/$tdir/$tfile-0
1630 # get minimum soft qunit size
1631 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1632 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1633 local limit2=$((limit+4))
1634 local glbl_limit=$((limit+8))
1635 local grace1=$((grace+10))
1637 local glbl_grace=$((grace+20))
1638 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1639 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1641 set_ost_qtype $QTYPE || error "enable ost quota failed"
1643 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1644 # make sure the system is clean
1645 local used=$(getquota -u $TSTUSR global curspace)
1646 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1648 pool_add $qpool || error "pool_add failed"
1649 pool_add_targets $qpool 0 1 ||
1650 error "pool_add_targets failed"
1652 pool_add $qpool2 || error "pool_add failed"
1653 pool_add_targets $qpool2 0 1 ||
1654 error "pool_add_targets failed"
1657 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1658 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1659 $LFS setquota -t -u --block-grace $grace1 \
1660 --pool $qpool $DIR || error "set user grace time failed"
1661 $LFS setquota -t -u --block-grace $grace2 \
1662 --pool $qpool2 $DIR || error "set user grace time failed"
1664 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1665 error "set user quota failed"
1666 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1667 error "set user quota failed"
1668 # qpool has minimum soft limit, but its grace is greater than
1669 # the grace period of qpool2. Thus write shouldn't fail when
1670 # hit qpool soft limit - only when reaches up qpool2 limit
1671 # after grace2 seconds.
1672 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1673 error "set user quota failed"
1675 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1678 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1679 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1680 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1681 --pool $qpool $DIR || error "restore user grace time failed"
1682 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1683 --pool $qpool2 $DIR || error "restore user grace time failed"
1685 run_test 3c "Quota pools: check block soft limit on different pools"
1692 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1693 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1696 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1698 echo "Create files to exceed soft limit"
1699 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1700 quota_error a $TSTUSR "create failure, but expect success"
1701 local trigger_time=$(date +%s)
1703 sync_all_data || true
1705 local cur_time=$(date +%s)
1706 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1707 error "Passed grace time $grace, $trigger_time, $cur_time"
1709 echo "Create file before timer goes off"
1710 $RUNAS touch ${TESTFILE}_before ||
1711 quota_error a $TSTUSR "failed create before timer expired," \
1712 "but expect success. $trigger_time, $cur_time"
1713 sync_all_data || true
1715 wait_grace_time $qtype "file"
1720 $SHOW_QUOTA_INFO_USER
1721 $SHOW_QUOTA_INFO_GROUP
1722 $SHOW_QUOTA_INFO_PROJID
1724 echo "Create file after timer goes off"
1725 # exceed least soft limit is possible
1726 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1727 quota_error a $TSTUSR "create after timer expired," \
1729 sync_all_data || true
1734 $SHOW_QUOTA_INFO_USER
1735 $SHOW_QUOTA_INFO_GROUP
1736 $SHOW_QUOTA_INFO_PROJID
1738 echo "Unlink files to stop timer"
1739 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1740 wait_delete_completed
1743 $RUNAS touch ${TESTFILE}_xxx ||
1744 quota_error a $TSTUSR "touch after timer stop failure," \
1745 "but expect success"
1746 sync_all_data || true
1754 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1755 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1756 local TESTFILE=$DIR/$tdir/$tfile-0
1759 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1760 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1762 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1763 # make sure the system is clean
1764 local USED=$(getquota -u $TSTUSR global curinodes)
1765 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1767 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1768 $GRACE $DIR || error "set user grace time failed"
1769 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1770 error "set user quota failed"
1772 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1774 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1775 # make sure the system is clean
1776 USED=$(getquota -g $TSTUSR global curinodes)
1777 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1779 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1780 $GRACE $DIR || error "set group grace time failed"
1781 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1782 error "set group quota failed"
1783 TESTFILE=$DIR/$tdir/$tfile-1
1785 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1787 if is_project_quota_supported; then
1788 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1789 # make sure the system is clean
1790 USED=$(getquota -p $TSTPRJID global curinodes)
1791 [ $USED -ne 0 ] && error \
1792 "Used space($USED) for project $TSTPRJID isn't 0."
1794 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1795 $GRACE $DIR || error "set project grace time failed"
1796 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1797 error "set project quota failed"
1799 TESTFILE=$DIR/$tdir/$tfile-1
1800 # one less than limit, because of parent directory included.
1801 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1802 resetquota -p $TSTPRJID
1803 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1804 $MAX_IQ_TIME $DIR ||
1805 error "restore project grace time failed"
1809 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1810 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1811 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1812 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1814 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1817 local GR_STR1="1w3d"
1818 local GR_STR2="1000s"
1820 local GR_STR4="1w2d3h4m5s"
1822 local GR_STR6="18446744073709551615"
1825 wait_delete_completed
1827 # test of valid grace strings handling
1828 echo "Valid grace strings test"
1829 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1830 $GR_STR2 $DIR || error "set user grace time failed"
1831 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1832 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1833 $GR_STR4 $DIR || error "set group grace time quota failed"
1834 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1836 # test of invalid grace strings handling
1837 echo " Invalid grace strings test"
1838 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1839 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1840 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1844 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1845 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1846 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1847 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1849 run_test 4b "Grace time strings handling"
1851 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1853 local BLIMIT=10 # MB
1854 local ILIMIT=10 # inodes
1856 setup_quota_test || error "setup quota failed with $?"
1858 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1859 set_ost_qtype $QTYPE || error "enable ost quota failed"
1861 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1862 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1863 error "set user quota failed"
1864 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1865 if is_project_quota_supported; then
1866 error "set group quota failed"
1867 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1868 -I $ILIMIT $DIR || error "set project quota failed"
1871 # make sure the system is clean
1872 local USED=$(getquota -u $TSTUSR global curinodes)
1873 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1874 USED=$(getquota -g $TSTUSR global curinodes)
1875 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1876 USED=$(getquota -u $TSTUSR global curspace)
1877 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1878 USED=$(getquota -g $TSTUSR global curspace)
1879 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1880 if is_project_quota_supported; then
1881 USED=$(getquota -p $TSTPRJID global curinodes)
1883 error "Used inode($USED) for project $TSTPRJID isn't 0."
1884 USED=$(getquota -p $TSTPRJID global curspace)
1886 error "Used block($USED) for project $TSTPRJID isn't 0."
1889 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1890 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1891 error "create failure, expect success"
1892 if is_project_quota_supported; then
1893 touch $DIR/$tdir/$tfile-0_1
1894 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1896 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1897 error "write failure, expect success"
1899 echo "Chown files to $TSTUSR.$TSTUSR ..."
1900 for i in $(seq 0 $ILIMIT); do
1901 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1902 quota_error a $TSTUSR "chown failure, expect success"
1906 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1907 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1909 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1911 # test dropping acquire request on master
1915 # Clear dmesg so watchdog is not triggered by previous
1917 do_facet ost1 dmesg -c > /dev/null
1919 setup_quota_test || error "setup quota failed with $?"
1921 # make sure the system is clean
1922 local USED=$(getquota -u $TSTUSR global curspace)
1923 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1925 # make sure no granted quota on ost
1926 set_ost_qtype $QTYPE || error "enable ost quota failed"
1927 resetquota -u $TSTUSR
1929 # create file for $TSTUSR
1930 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1931 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1932 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1934 # create file for $TSTUSR2
1935 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1936 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1937 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1939 # cache per-ID lock for $TSTUSR on slave
1940 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1941 error "set quota failed"
1942 $RUNAS $DD of=$TESTFILE count=1 ||
1943 error "write $TESTFILE failure, expect success"
1944 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1945 error "write $TESTFILE2 failure, expect success"
1947 if at_is_enabled; then
1948 at_max_saved=$(at_max_get ost1)
1949 at_max_set $TIMEOUT ost1
1951 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1952 # DQACQ is sent, which makes at_max to take effect
1953 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1956 wait_delete_completed
1960 sync_all_data || true
1962 #define QUOTA_DQACQ 601
1963 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1964 lustre_fail mds 0x513 601
1966 do_facet ost1 $LCTL set_param \
1967 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1969 # write to un-enforced ID ($TSTUSR2) should succeed
1970 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1971 error "write failure, expect success"
1973 # write to enforced ID ($TSTUSR) in background, exceeding limit
1974 # to make sure DQACQ is sent
1975 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1978 # watchdog timer uses a factor of 2
1979 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1980 sleep $((TIMEOUT * 2 + 1))
1982 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1984 # write should be blocked and never finished
1985 if ! ps -p $DDPID > /dev/null 2>&1; then
1987 error "write finished incorrectly!"
1992 # no watchdog is triggered
1993 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1994 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1995 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1996 [ -z "$watchdog" ] || error "$watchdog"
1998 rm -f $TMP/lustre-log-${TESTNAME}.log
2000 # write should continue then fail with EDQUOT
2004 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2005 if [ $count -ge 240 ]; then
2006 quota_error u $TSTUSR "dd not finished in $count secs"
2008 count=$((count + 1))
2009 if [ $((count % 30)) -eq 0 ]; then
2010 c_size=$(stat -c %s $TESTFILE)
2011 echo "Waiting $count secs. $c_size"
2017 run_test 6 "Test dropping acquire request on master"
2019 # quota reintegration (global index)
2021 local TESTFILE=$DIR/$tdir/$tfile
2024 [ "$SLOW" = "no" ] && LIMIT=5
2026 setup_quota_test || error "setup quota failed with $?"
2028 # make sure the system is clean
2029 local USED=$(getquota -u $TSTUSR global curspace)
2030 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2032 # make sure no granted quota on ost1
2033 set_ost_qtype $QTYPE || error "enable ost quota failed"
2034 resetquota -u $TSTUSR
2035 set_ost_qtype "none" || error "disable ost quota failed"
2037 local OSTUUID=$(ostuuid_from_index 0)
2038 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2040 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2043 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2044 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2049 echo "Enable quota & set quota limit for $TSTUSR"
2050 set_ost_qtype $QTYPE || error "enable ost quota failed"
2051 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2052 error "set quota failed"
2054 echo "Start ost1..."
2055 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2058 wait_ost_reint $QTYPE || error "reintegration failed"
2060 # hardlimit should have been fetched by slave during global
2061 # reintegration, write will exceed quota
2062 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2063 quota_error u $TSTUSR "write success, but expect EDQUOT"
2066 wait_delete_completed
2067 sync_all_data || true
2073 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2074 error "clear quota failed"
2076 echo "Start ost1..."
2077 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2080 wait_ost_reint $QTYPE || error "reintegration failed"
2082 # hardlimit should be cleared on slave during reintegration
2083 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2084 quota_error u $TSTUSR "write error, but expect success"
2086 run_test 7a "Quota reintegration (global index)"
2088 # quota reintegration (slave index)
2090 local limit=100000 # MB
2091 local TESTFILE=$DIR/$tdir/$tfile
2093 setup_quota_test || error "setup quota failed with $?"
2095 # make sure the system is clean
2096 local USED=$(getquota -u $TSTUSR global curspace)
2097 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2099 # make sure no granted quota on ost1
2100 set_ost_qtype $QTYPE || error "enable ost quota failed"
2101 resetquota -u $TSTUSR
2102 set_ost_qtype "none" || error "disable ost quota failed"
2104 local OSTUUID=$(ostuuid_from_index 0)
2105 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2107 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2110 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2111 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2113 # consume some space to make sure the granted space will not
2114 # be released during reconciliation
2115 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2116 error "consume space failure, expect success"
2118 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2119 lustre_fail mds 0xa02
2121 set_ost_qtype $QTYPE || error "enable ost quota failed"
2122 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2123 error "set quota failed"
2125 # ignore the write error
2126 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2128 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2132 echo "Restart ost to trigger reintegration..."
2134 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2137 wait_ost_reint $QTYPE || error "reintegration failed"
2139 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2140 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2145 run_test 7b "Quota reintegration (slave index)"
2147 # quota reintegration (restart mds during reintegration)
2150 local TESTFILE=$DIR/$tdir/$tfile
2152 [ "$SLOW" = "no" ] && LIMIT=5
2154 setup_quota_test || error "setup quota failed with $?"
2156 # make sure the system is clean
2157 local USED=$(getquota -u $TSTUSR global curspace)
2158 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2160 set_ost_qtype "none" || error "disable ost quota failed"
2161 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2162 error "set quota failed"
2164 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2165 lustre_fail ost 0xa03
2168 set_ost_qtype $QTYPE || error "enable ost quota failed"
2169 # trigger reintegration
2170 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2171 procf=${procf}quota_slave.force_reint
2172 do_facet ost1 $LCTL set_param $procf=1 ||
2173 error "force reintegration failed"
2181 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2184 # wait longer than usual to make sure the reintegration
2185 # is triggered by quota wb thread.
2186 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2188 # hardlimit should have been fetched by slave during global
2189 # reintegration, write will exceed quota
2190 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2191 quota_error u $TSTUSR "write success, but expect EDQUOT"
2194 run_test 7c "Quota reintegration (restart mds during reintegration)"
2196 # Quota reintegration (Transfer index in multiple bulks)
2198 local TESTFILE=$DIR/$tdir/$tfile
2199 local TESTFILE1="$DIR/$tdir/$tfile"-1
2202 setup_quota_test || error "setup quota failed with $?"
2204 set_ost_qtype "none" || error "disable ost quota failed"
2205 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2206 error "set quota for $TSTUSR failed"
2207 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2208 error "set quota for $TSTUSR2 failed"
2210 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2211 lustre_fail mds 0x608 0
2213 # enable quota to tirgger reintegration
2214 set_ost_qtype "u" || error "enable ost quota failed"
2215 wait_ost_reint "u" || error "reintegration failed"
2219 # hardlimit should have been fetched by slave during global
2220 # reintegration, write will exceed quota
2221 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2222 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2224 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2225 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2228 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2230 # quota reintegration (inode limits)
2232 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2234 # LU-2435: skip this quota test if underlying zfs version has not
2235 # supported native dnode accounting
2236 [ "$mds1_FSTYPE" == zfs ] && {
2237 local F="feature@userobj_accounting"
2238 local pool=$(zpool_name mds1)
2239 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2241 [[ "$feature" != *" active "* ]] &&
2242 skip "requires zpool with active userobj_accounting"
2245 local ilimit=$((1024 * 2)) # inodes
2246 local TESTFILE=$DIR/${tdir}-1/$tfile
2248 setup_quota_test || error "setup quota failed with $?"
2250 # make sure the system is clean
2251 local USED=$(getquota -u $TSTUSR global curinodes)
2252 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2254 # make sure no granted quota on mdt1
2255 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2256 resetquota -u $TSTUSR
2257 set_mdt_qtype "none" || error "disable mdt quota failed"
2259 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2260 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2261 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2264 echo "Stop mds${MDSCOUNT}..."
2267 echo "Enable quota & set quota limit for $TSTUSR"
2268 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2269 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2270 error "set quota failed"
2272 echo "Start mds${MDSCOUNT}..."
2273 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2276 wait_mdt_reint $QTYPE || error "reintegration failed"
2278 echo "create remote dir"
2279 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2280 error "create remote dir failed"
2281 chmod 0777 $DIR/${tdir}-1
2283 # hardlimit should have been fetched by slave during global
2284 # reintegration, create will exceed quota
2285 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2286 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2288 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2289 wait_delete_completed
2290 sync_all_data || true
2292 echo "Stop mds${MDSCOUNT}..."
2295 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2296 error "clear quota failed"
2298 echo "Start mds${MDSCOUNT}..."
2299 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2302 wait_mdt_reint $QTYPE || error "reintegration failed"
2304 # hardlimit should be cleared on slave during reintegration
2305 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2306 quota_error u $TSTUSR "create failed, expect success"
2308 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2309 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2311 run_test 7e "Quota reintegration (inode limits)"
2313 # run dbench with quota enabled
2315 local BLK_LIMIT="100g" #100G
2316 local FILE_LIMIT=1000000
2318 setup_quota_test || error "setup quota failed with $?"
2320 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2321 set_ost_qtype $QTYPE || error "enable ost quota failed"
2323 echo "Set enough high limit for user: $TSTUSR"
2324 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2325 error "set user quota failed"
2326 echo "Set enough high limit for group: $TSTUSR"
2327 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2328 error "set group quota failed"
2329 if is_project_quota_supported; then
2330 change_project -sp $TSTPRJID $DIR/$tdir
2331 echo "Set enough high limit for project: $TSTPRJID"
2332 $LFS setquota -p $TSTPRJID -b 0 \
2333 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2334 error "set project quota failed"
2338 [ "$SLOW" = "no" ] && duration=" -t 120"
2339 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2340 quota_error a $TSTUSR "dbench failed!"
2342 is_project_quota_supported && change_project -C $DIR/$tdir
2345 run_test 8 "Run dbench with quota enabled"
2347 # this check is just for test_9
2348 OST0_MIN=4900000 #4.67G
2350 check_whether_skip () {
2351 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2352 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2353 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2354 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2361 # run for fixing bug10707, it needs a big room. test for 64bit
2363 local filesize=$((1024 * 9 / 2)) # 4.5G
2365 check_whether_skip && return 0
2367 setup_quota_test || error "setup quota failed with $?"
2369 set_ost_qtype "ug" || error "enable ost quota failed"
2371 local TESTFILE="$DIR/$tdir/$tfile-0"
2372 local BLK_LIMIT=100G #100G
2373 local FILE_LIMIT=1000000
2375 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2377 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2379 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2380 error "set user quota failed"
2382 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2383 "for group: $TSTUSR"
2384 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2385 error "set group quota failed"
2387 quota_show_check a u $TSTUSR
2388 quota_show_check a g $TSTUSR
2390 echo "Create test file"
2391 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2392 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2394 log "Write the big file of 4.5G ..."
2395 $RUNAS $DD of=$TESTFILE count=$filesize ||
2396 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2406 run_test 9 "Block limit larger than 4GB (b10707)"
2409 local TESTFILE=$DIR/$tdir/$tfile
2411 setup_quota_test || error "setup quota failed with $?"
2413 # set limit to root user should fail
2414 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2415 error "set limit for root user successfully, expect failure"
2416 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2417 error "set limit for root group successfully, expect failure"
2418 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2419 error "set limit for project 0 successfully, expect failure"
2421 # root user can overrun quota
2422 set_ost_qtype "ug" || error "enable ost quota failed"
2424 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2425 error "set quota failed"
2426 quota_show_check b u $TSTUSR
2428 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2429 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2431 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2432 error "write failure, expect success"
2434 run_test 10 "Test quota for root user"
2437 local TESTFILE=$DIR/$tdir/$tfile
2438 setup_quota_test || error "setup quota failed with $?"
2440 set_mdt_qtype "ug" || error "enable mdt quota failed"
2441 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2442 error "set quota failed"
2444 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2445 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2447 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2448 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2451 local USED=$(getquota -u $TSTUSR global curinodes)
2452 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2454 run_test 11 "Chown/chgrp ignores quota"
2457 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2459 local blimit=22 # MB
2460 local blk_cnt=$((blimit - 5))
2461 local TESTFILE0="$DIR/$tdir/$tfile"-0
2462 local TESTFILE1="$DIR/$tdir/$tfile"-1
2464 setup_quota_test || error "setup quota failed with $?"
2466 set_ost_qtype "u" || error "enable ost quota failed"
2467 quota_show_check b u $TSTUSR
2469 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2470 error "set quota failed"
2472 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2473 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2474 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2475 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2477 echo "Write to ost0..."
2478 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2479 quota_error a $TSTUSR "dd failed"
2481 echo "Write to ost1..."
2482 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2483 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2485 echo "Free space from ost0..."
2487 wait_delete_completed
2488 sync_all_data || true
2490 echo "Write to ost1 after space freed from ost0..."
2491 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2492 quota_error a $TSTUSR "rebalancing failed"
2494 run_test 12a "Block quota rebalancing"
2497 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2499 local ilimit=$((1024 * 2)) # inodes
2500 local TESTFILE0=$DIR/$tdir/$tfile
2501 local TESTFILE1=$DIR/${tdir}-1/$tfile
2503 setup_quota_test || error "setup quota failed with $?"
2505 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2506 chmod 0777 $DIR/${tdir}-1
2508 set_mdt_qtype "u" || error "enable mdt quota failed"
2509 quota_show_check f u $TSTUSR
2511 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2512 error "set quota failed"
2514 echo "Create $ilimit files on mdt0..."
2515 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2516 quota_error u $TSTUSR "create failed, but expect success"
2518 echo "Create files on mdt1..."
2519 $RUNAS createmany -m $TESTFILE1 1 &&
2520 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2522 echo "Free space from mdt0..."
2523 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2524 wait_delete_completed
2525 sync_all_data || true
2527 echo "Create files on mdt1 after space freed from mdt0..."
2528 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2529 quota_error a $TSTUSR "rebalancing failed"
2531 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2532 error "unlink mdt1 files failed"
2533 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2535 run_test 12b "Inode quota rebalancing"
2538 local TESTFILE=$DIR/$tdir/$tfile
2539 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2540 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2542 setup_quota_test || error "setup quota failed with $?"
2544 set_ost_qtype "u" || error "enable ost quota failed"
2545 quota_show_check b u $TSTUSR
2547 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2548 error "set quota failed"
2549 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2550 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2552 # clear the locks in cache first
2553 do_facet ost1 $LCTL set_param -n $procf=clear
2554 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2555 [ $nlock -eq 0 ] || error "$nlock cached locks"
2557 # write to acquire the per-ID lock
2558 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2559 quota_error a $TSTUSR "dd failed"
2561 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2562 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2564 # clear quota doesn't trigger per-ID lock cancellation
2565 resetquota -u $TSTUSR
2566 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2567 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2569 # clear the per-ID lock
2570 do_facet ost1 $LCTL set_param -n $procf=clear
2571 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2572 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2574 # spare quota should be released
2575 local OSTUUID=$(ostuuid_from_index 0)
2576 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2577 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2578 [ $limit -le $space ] ||
2579 error "spare quota isn't released, limit:$limit, space:$space"
2581 run_test 13 "Cancel per-ID lock in the LRU list"
2584 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2586 wait_delete_completed
2587 sync_all_data || true
2590 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2591 error "set user quota failed"
2592 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2593 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2594 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2595 resetquota -u $TSTUSR
2598 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2599 error "set group quota failed"
2600 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2601 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2602 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2603 resetquota -g $TSTUSR
2605 run_test 15 "Set over 4T block quota"
2609 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2610 skip "Not supported Lustre client before 2.14.55"
2612 setup_quota_test || error "setup quota failed with $?"
2614 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2615 error "failed to set quota for user $TSTUSR"
2616 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2617 error "failed to set quota for group $TSTUSR"
2619 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=50 ||
2620 quota_error u $TSTUSR "write failure"
2622 $LFS quota -u $TSTUSR $MOUNT ||
2623 quota_error u $TSTUSR "failed to get quota"
2625 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2627 $LCTL --device %$OSC deactivate
2628 stack_trap "$LCTL --device %$OSC activate"
2630 $LFS quota -v -u $TSTUSR $MOUNT ||
2631 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2632 $LFS quota -v -g $TSTUSR $MOUNT ||
2633 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2635 (( $MDSCOUNT > 1 )) || return 0
2637 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2639 $LCTL --device %$MDC deactivate
2640 stack_trap "$LCTL --device %$MDC activate"
2642 $LFS quota -v -u $TSTUSR $MOUNT ||
2643 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2644 $LFS quota -v -g $TSTUSR $MOUNT ||
2645 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2647 run_test 16a "lfs quota should skip the inactive MDT/OST"
2658 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2659 skip "Not supported Lustre client before 2.14.55"
2661 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2664 if ! combined_mgs_mds ; then
2669 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2670 $(mdsdevname 1) $(mdsvdevname 1)
2671 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2672 $(mdsdevname 2) $(mdsvdevname 2)
2673 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2674 $(mdsdevname 3) $(mdsvdevname 3)
2676 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2677 $(ostdevname 1) $(ostvdevname 1)
2678 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2679 $(ostdevname 2) $(ostvdevname 2)
2681 stack_trap cleanup_16b
2683 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2684 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2685 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2686 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2687 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2689 mount_client $MOUNT || error "Unable to mount client"
2691 setup_quota_test || error "setup quota failed with $?"
2693 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2694 error "failed to set quota for user $TSTUSR"
2695 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2696 error "failed to set quota for group $TSTUSR"
2698 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=10 ||
2699 quota_error u $TSTUSR "write failure"
2701 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2702 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2703 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2704 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2706 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2710 local BLKS=1 # 1M less than limit
2711 local TESTFILE=$DIR/$tdir/$tfile
2713 setup_quota_test || error "setup quota failed with $?"
2715 # make sure the system is clean
2716 local USED=$(getquota -u $TSTUSR global curspace)
2717 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2719 set_ost_qtype "ug" || error "enable ost quota failed"
2720 # make sure no granted quota on ost
2721 resetquota -u $TSTUSR
2722 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2723 error "set quota failed"
2725 quota_show_check b u $TSTUSR
2727 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2728 lustre_fail mds 0xa04 $err_code
2730 # write in background
2731 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2735 # write should be blocked and never finished
2736 if ! ps -p $DDPID > /dev/null 2>&1; then
2738 quota_error u $TSTUSR "write finished incorrectly!"
2746 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2748 if [ $count -gt $timeout ]; then
2749 quota_error u $TSTUSR "dd is not finished!"
2754 sync; sync_all_data || true
2756 USED=$(getquota -u $TSTUSR global curspace)
2757 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2758 "Used space(${USED}K) is less than ${BLKS}M"
2763 # DQACQ return recoverable error
2765 echo "DQACQ return -ENOLCK"
2767 test_17sub 37 || error "Handle -ENOLCK failed"
2769 echo "DQACQ return -EAGAIN"
2771 test_17sub 11 || error "Handle -EAGAIN failed"
2773 echo "DQACQ return -ETIMEDOUT"
2774 #define ETIMEDOUT 110
2775 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2777 echo "DQACQ return -ENOTCONN"
2778 #define ENOTCONN 107
2779 test_17sub 107 || error "Handle -ENOTCONN failed"
2782 run_test 17 "DQACQ return recoverable error"
2786 local blimit=200 # MB
2787 local TESTFILE="$DIR/$tdir/$tfile"
2789 setup_quota_test || error "setup quota failed with $?"
2791 set_ost_qtype "u" || error "enable ost quota failed"
2792 log "User quota (limit: $blimit)"
2793 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2794 error "set quota failed"
2795 quota_show_check b u $TSTUSR
2797 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2798 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2800 local timeout=$(sysctl -n lustre.timeout)
2802 if [ $io_type = "directio" ]; then
2803 log "Write 100M (directio) ..."
2804 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2806 log "Write 100M (buffered) ..."
2807 $RUNAS $DD of=$TESTFILE count=100 &
2811 replay_barrier $SINGLEMDS
2812 log "Fail mds for $((2 * timeout)) seconds"
2813 fail $SINGLEMDS $((2 * timeout))
2816 if at_is_enabled; then
2817 timeout=$(at_max_get mds)
2819 timeout=$(lctl get_param -n timeout)
2823 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2824 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2825 log "it took $count second"
2830 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2832 cancel_lru_locks mdc
2833 cancel_lru_locks osc
2836 local testfile_size=$(stat -c %s $TESTFILE)
2837 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2838 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2839 "got ${testfile_size}. Verifying file failed!"
2844 # test when mds does failover, the ost still could work well
2845 # this test shouldn't trigger watchdog b=14840
2847 # Clear dmesg so watchdog is not triggered by previous
2849 do_facet ost1 dmesg -c > /dev/null
2852 test_18_sub directio
2854 # check if watchdog is triggered
2855 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2856 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2857 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2858 [ -z "$watchdog" ] || error "$watchdog"
2859 rm -f $TMP/lustre-log-${TESTNAME}.log
2861 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2865 local TESTFILE=$DIR/$tdir/$tfile
2867 setup_quota_test || error "setup quota failed with $?"
2869 set_ost_qtype $QTYPE || error "enable ost quota failed"
2871 # bind file to a single OST
2872 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2873 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2875 echo "Set user quota (limit: ${blimit}M)"
2876 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2877 error "set user quota failed"
2878 quota_show_check b u $TSTUSR
2879 echo "Update quota limits"
2880 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2881 error "set group quota failed"
2882 quota_show_check b u $TSTUSR
2884 # first wirte might be cached
2885 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2886 cancel_lru_locks osc
2888 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2889 quota_error u $TSTUSR "Write success, expect failure"
2892 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2894 test_20() { # b15754
2895 local LSTR=(2g 1t 4k 3m) # limits strings
2897 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2900 resetquota -u $TSTUSR
2902 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2903 $MOUNT || error "could not set quota limits"
2904 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2905 --inode-softlimit ${LSTR[2]} \
2906 --inode-hardlimit ${LSTR[3]} \
2907 $MOUNT || error "could not set quota limits"
2909 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2910 error "bsoftlimit was not set properly"
2911 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2912 error "bhardlimit was not set properly"
2913 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2914 error "isoftlimit was not set properly"
2915 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2916 error "ihardlimit was not set properly"
2918 resetquota -u $TSTUSR
2920 run_test 20 "Test if setquota specifiers work properly (b15754)"
2927 local time=$(($(date +%s) + seconds))
2928 while [ $(date +%s) -lt $time ]; do
2929 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2933 # run for fixing bug16053, setquota shouldn't fail when writing and
2934 # deleting are happening
2936 local TESTFILE="$DIR/$tdir/$tfile"
2937 local BLIMIT=10 # 10G
2938 local ILIMIT=1000000
2940 setup_quota_test || error "setup quota failed with $?"
2942 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2944 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2945 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2946 error "set user quota failed"
2947 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2948 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2949 error "set group quota failed"
2950 if is_project_quota_supported; then
2951 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2952 "project: $TSTPRJID"
2953 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2954 $MOUNT || error "set project quota failed"
2957 # repeat writing on a 1M file
2958 test_21_sub ${TESTFILE}_1 1 30 &
2960 # repeat writing on a 128M file
2961 test_21_sub ${TESTFILE}_2 128 30 &
2964 local time=$(($(date +%s) + 30))
2966 while [ $(date +%s) -lt $time ]; do
2967 log "Set quota for $i times"
2968 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2969 -I $((ILIMIT + i)) $MOUNT ||
2970 error "Set user quota failed"
2971 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2972 -I $((ILIMIT + i)) $MOUNT ||
2973 error "Set group quota failed"
2974 if is_project_quota_supported; then
2975 $LFS setquota -p $TSTPRJID -b 0 -B \
2976 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2977 error "Set project quota failed"
2985 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2987 if [ $count -gt 60 ]; then
2988 quota_error a $TSTUSR "dd should be finished!"
2992 echo "(dd_pid=$DDPID1, time=$count)successful"
2996 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2998 if [ $count -gt 60 ]; then
2999 quota_error a $TSTUSR "dd should be finished!"
3003 echo "(dd_pid=$DDPID2, time=$count)successful"
3005 run_test 21 "Setquota while writing & deleting (b16053)"
3007 # enable/disable quota enforcement permanently
3009 echo "Set both mdt & ost quota type as ug"
3011 is_project_quota_supported && qtype=$QTYPE
3012 set_mdt_qtype $qtype || error "enable mdt quota failed"
3013 set_ost_qtype $qtype || error "enable ost quota failed"
3016 stopall || error "failed to stopall (1)"
3020 echo "Verify if quota is enabled"
3021 local qtype1=$(mdt_quota_type)
3022 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
3023 qtype=$(ost_quota_type)
3024 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
3026 echo "Set both mdt & ost quota type as none"
3027 set_mdt_qtype "none" || error "disable mdt quota failed"
3028 set_ost_qtype "none" || error "disable ost quota failed"
3031 stopall || error "failed to stopall (2)"
3036 echo "Verify if quota is disabled"
3037 qtype=$(mdt_quota_type)
3038 [ $qtype != "none" ] && error "mdt quota setting is lost"
3039 qtype=$(ost_quota_type)
3040 [ $qtype != "none" ] && error "ost quota setting is lost"
3044 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3047 local TESTFILE="$DIR/$tdir/$tfile"
3050 setup_quota_test || error "setup quota failed with $?"
3052 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3055 log "User quota (limit: $LIMIT MB)"
3056 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3057 error "set quota failed"
3058 quota_show_check b u $TSTUSR
3060 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3061 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3063 log "Step1: trigger EDQUOT with O_DIRECT"
3064 log "Write half of file"
3065 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3066 quota_error u $TSTUSR "(1) Write failure, expect success." \
3068 log "Write out of block quota ..."
3069 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3070 oflag=direct conv=notrunc &&
3071 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3075 log "Step2: rewrite should succeed"
3076 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3077 quota_error u $TSTUSR "(3) Write failure, expect success." \
3083 local OST0_UUID=$(ostuuid_from_index 0)
3084 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3085 [ $OST0_QUOTA_USED -ne 0 ] &&
3086 ($SHOW_QUOTA_USER; \
3087 quota_error u $TSTUSR "quota isn't released")
3092 [ "$ost1_FSTYPE" == zfs ] &&
3093 skip "Overwrite in place is not guaranteed to be " \
3094 "space neutral on ZFS"
3096 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3097 check_whether_skip && return 0
3098 log "run for 4MB test file"
3101 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3102 check_whether_skip && return 0
3103 log "run for 40MB test file"
3106 run_test 23 "Quota should be honored with directIO (b16125)"
3110 local TESTFILE="$DIR/$tdir/$tfile"
3112 setup_quota_test || error "setup quota failed with $?"
3114 set_ost_qtype $QTYPE || error "enable ost quota failed"
3116 # bind file to a single OST
3117 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3118 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3120 echo "Set user quota (limit: ${blimit}M)"
3121 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3122 error "set quota failed"
3124 # overrun quota by root user
3125 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3126 error "write failure, expect success"
3127 cancel_lru_locks osc
3128 sync_all_data || true
3130 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3132 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3134 test_27a() { # b19612
3135 $LFS quota $TSTUSR $DIR &&
3136 error "lfs succeeded with no type, but should have failed"
3137 $LFS setquota $TSTUSR $DIR &&
3138 error "lfs succeeded with no type, but should have failed"
3141 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3143 test_27b() { # b20200
3144 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3145 error "lfs setquota failed with uid argument"
3146 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3147 error "lfs stequota failed with gid argument"
3148 if is_project_quota_supported; then
3149 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3150 1000 $DIR || error \
3151 "lfs stequota failed with projid argument"
3153 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3154 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3155 if is_project_quota_supported; then
3156 $SHOW_QUOTA_PROJID ||
3157 error "lfs quota failed with projid argument"
3159 resetquota -u $TSTID
3160 resetquota -g $TSTID
3161 resetquota -p $TSTPRJID
3164 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3169 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3170 error "lfs setquota failed"
3172 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3173 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3174 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3175 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3177 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3178 error "lfs setquota for $TSTID failed"
3180 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3181 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3182 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3183 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3185 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3186 error "total allocated inode/block limit not printed"
3188 resetquota -u $TSTUSR
3190 run_test 27c "lfs quota should support human-readable output"
3197 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3198 error "set fraction block limit failed"
3199 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3200 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3201 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3202 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3204 resetquota -u $TSTUSR
3206 run_test 27d "lfs setquota should support fraction block limit"
3210 local TESTFILE="$DIR/$tdir/$tfile"
3213 setup_quota_test || error "setup quota failed with $?"
3215 set_ost_qtype "u" || error "enable ost quota failed"
3217 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3218 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3220 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3221 $MAX_IQ_TIME $DIR || error "set grace time failed"
3222 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3223 error "set quota failed"
3224 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3225 cancel_lru_locks osc
3227 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3228 # over-quota flag has not yet settled since we do not trigger async
3229 # events based on grace time period expiration
3231 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3232 cancel_lru_locks osc
3233 # now over-quota flag should be settled and further writes should fail
3235 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3236 error "grace times were reset"
3237 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3238 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3240 run_test 30 "Hard limit updates should not reset grace times"
3242 # basic usage tracking for user & group
3244 local INODES=10 # files
3245 local BLK_CNT=2 # MB each
3246 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3248 setup_quota_test || error "setup quota failed with $?"
3250 # make sure the system is clean
3251 local USED=$(getquota -u $TSTID global curspace)
3253 error "Used space ($USED) for user $TSTID isn't 0."
3254 USED=$(getquota -g $TSTID global curspace)
3256 error "Used space ($USED) for group $TSTID isn't 0."
3257 if is_project_quota_supported; then
3258 USED=$(getquota -p $TSTPRJID global curspace)
3259 [ $USED -ne 0 ] && error \
3260 "Used space ($USED) for project $TSTPRJID isn't 0."
3263 echo "Write files..."
3264 for i in $(seq 0 $INODES); do
3265 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3266 error "write failed"
3267 is_project_quota_supported &&
3268 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3269 echo "Iteration $i/$INODES completed"
3271 cancel_lru_locks osc
3273 echo "Wait for setattr on objects finished..."
3274 wait_delete_completed
3276 sync; sync_all_data || true
3278 echo "Verify disk usage after write"
3279 USED=$(getquota -u $TSTID global curspace)
3280 [ $USED -lt $TOTAL_BLKS ] &&
3281 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3282 USED=$(getquota -g $TSTID global curspace)
3283 [ $USED -lt $TOTAL_BLKS ] &&
3284 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3285 if is_project_quota_supported; then
3286 USED=$(getquota -p $TSTPRJID global curspace)
3287 [ $USED -lt $TOTAL_BLKS ] && error \
3288 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3291 echo "Verify inode usage after write"
3292 USED=$(getquota -u $TSTID global curinodes)
3293 [ $USED -lt $INODES ] &&
3294 error "Used inode for user $TSTID is $USED, expected $INODES"
3295 USED=$(getquota -g $TSTID global curinodes)
3296 [ $USED -lt $INODES ] &&
3297 error "Used inode for group $TSTID is $USED, expected $INODES"
3298 if is_project_quota_supported; then
3299 USED=$(getquota -p $TSTPRJID global curinodes)
3300 [ $USED -lt $INODES ] && error \
3301 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3306 echo "Verify disk usage after delete"
3307 USED=$(getquota -u $TSTID global curspace)
3308 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3309 USED=$(getquota -u $TSTID global curinodes)
3310 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3311 USED=$(getquota -g $TSTID global curspace)
3312 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3313 USED=$(getquota -g $TSTID global curinodes)
3314 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3315 if is_project_quota_supported; then
3316 USED=$(getquota -p $TSTPRJID global curspace)
3318 error "Used space for project $TSTPRJID isn't 0. $USED"
3319 USED=$(getquota -p $TSTPRJID global curinodes)
3321 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3324 run_test 33 "Basic usage tracking for user & group & project"
3326 # usage transfer test for user & group & project
3328 local BLK_CNT=2 # MB
3329 local project_supported="no"
3331 is_project_quota_supported && project_supported="yes"
3332 setup_quota_test || error "setup quota failed with $?"
3334 # make sure the system is clean
3335 local USED=$(getquota -u $TSTID global curspace)
3336 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3337 USED=$(getquota -g $TSTID global curspace)
3338 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3340 local USED=$(getquota -u $TSTID2 global curspace)
3341 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3342 if [ $project_supported == "yes" ]; then
3343 USED=$(getquota -p $TSTPRJID global curspace)
3344 [ $USED -ne 0 ] && error \
3345 "Used space ($USED) for Project $TSTPRJID isn't 0."
3348 echo "Write file..."
3349 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3350 error "write failed"
3351 cancel_lru_locks osc
3352 sync; sync_all_data || true
3354 echo "chown the file to user $TSTID"
3355 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3357 echo "Wait for setattr on objects finished..."
3358 wait_delete_completed
3360 BLK_CNT=$((BLK_CNT * 1024))
3362 echo "Verify disk usage for user $TSTID"
3363 USED=$(getquota -u $TSTID global curspace)
3364 [ $USED -lt $BLK_CNT ] &&
3365 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3366 USED=$(getquota -u $TSTID global curinodes)
3368 error "Used inodes for user $TSTID is $USED, expected 1"
3370 echo "chgrp the file to group $TSTID"
3371 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3373 echo "Wait for setattr on objects finished..."
3374 wait_delete_completed
3376 echo "Verify disk usage for group $TSTID"
3377 USED=$(getquota -g $TSTID global curspace)
3378 [ $USED -ge $BLK_CNT ] ||
3379 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3380 USED=$(getquota -g $TSTID global curinodes)
3382 error "Used inodes for group $TSTID is $USED, expected 1"
3384 # chown won't change the ost object group. LU-4345 */
3385 echo "chown the file to user $TSTID2"
3386 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3388 echo "Wait for setattr on objects finished..."
3389 wait_delete_completed
3391 echo "change_project project id to $TSTPRJID"
3392 [ $project_supported == "yes" ] &&
3393 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3394 echo "Wait for setattr on objects finished..."
3395 wait_delete_completed
3397 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3398 USED=$(getquota -u $TSTID2 global curspace)
3399 [ $USED -lt $BLK_CNT ] &&
3400 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3401 USED=$(getquota -u $TSTID global curspace)
3403 error "Used space for user $TSTID is $USED, expected 0"
3404 USED=$(getquota -g $TSTID global curspace)
3405 [ $USED -lt $BLK_CNT ] &&
3406 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3407 if [ $project_supported == "yes" ]; then
3408 USED=$(getquota -p $TSTPRJID global curspace)
3409 [ $USED -lt $BLK_CNT ] && error \
3410 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3414 run_test 34 "Usage transfer for user & group & project"
3416 # usage is still accessible across restart
3418 local BLK_CNT=2 # MB
3420 setup_quota_test || error "setup quota failed with $?"
3422 echo "Write file..."
3423 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3424 error "write failed"
3425 is_project_quota_supported &&
3426 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3427 cancel_lru_locks osc
3429 echo "Wait for setattr on objects finished..."
3430 wait_delete_completed
3432 sync; sync_all_data || true
3434 echo "Save disk usage before restart"
3435 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3436 [ $ORIG_USR_SPACE -eq 0 ] &&
3437 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3438 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3439 [ $ORIG_USR_INODES -eq 0 ] &&
3440 error "Used inodes for user $TSTID is 0, expected 1"
3441 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3442 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3443 [ $ORIG_GRP_SPACE -eq 0 ] &&
3444 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3445 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3446 [ $ORIG_GRP_INODES -eq 0 ] &&
3447 error "Used inodes for group $TSTID is 0, expected 1"
3448 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3450 if is_project_quota_supported; then
3451 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3452 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3453 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3454 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3455 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3456 "Used inodes for project $TSTPRJID is 0, expected 1"
3457 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3465 echo "Verify disk usage after restart"
3466 local USED=$(getquota -u $TSTID global curspace)
3467 [ $USED -eq $ORIG_USR_SPACE ] ||
3468 error "Used space for user $TSTID changed from " \
3469 "$ORIG_USR_SPACE to $USED"
3470 USED=$(getquota -u $TSTID global curinodes)
3471 [ $USED -eq $ORIG_USR_INODES ] ||
3472 error "Used inodes for user $TSTID changed from " \
3473 "$ORIG_USR_INODES to $USED"
3474 USED=$(getquota -g $TSTID global curspace)
3475 [ $USED -eq $ORIG_GRP_SPACE ] ||
3476 error "Used space for group $TSTID changed from " \
3477 "$ORIG_GRP_SPACE to $USED"
3478 USED=$(getquota -g $TSTID global curinodes)
3479 [ $USED -eq $ORIG_GRP_INODES ] ||
3480 error "Used inodes for group $TSTID changed from " \
3481 "$ORIG_GRP_INODES to $USED"
3482 if [ $project_supported == "yes" ]; then
3483 USED=$(getquota -p $TSTPRJID global curinodes)
3484 [ $USED -eq $ORIG_PRJ_INODES ] ||
3485 error "Used inodes for project $TSTPRJID " \
3486 "changed from $ORIG_PRJ_INODES to $USED"
3487 USED=$(getquota -p $TSTPRJID global curspace)
3488 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3489 error "Used space for project $TSTPRJID "\
3490 "changed from $ORIG_PRJ_SPACE to $USED"
3493 # check if the vfs_dq_init() is called before writing
3494 echo "Append to the same file..."
3495 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3496 error "write failed"
3497 cancel_lru_locks osc
3498 sync; sync_all_data || true
3500 echo "Verify space usage is increased"
3501 USED=$(getquota -u $TSTID global curspace)
3502 [ $USED -gt $ORIG_USR_SPACE ] ||
3503 error "Used space for user $TSTID isn't increased" \
3504 "orig:$ORIG_USR_SPACE, now:$USED"
3505 USED=$(getquota -g $TSTID global curspace)
3506 [ $USED -gt $ORIG_GRP_SPACE ] ||
3507 error "Used space for group $TSTID isn't increased" \
3508 "orig:$ORIG_GRP_SPACE, now:$USED"
3509 if [ $project_supported == "yes" ]; then
3510 USED=$(getquota -p $TSTPRJID global curspace)
3511 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3512 error "Used space for project $TSTPRJID isn't " \
3513 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3516 run_test 35 "Usage is still accessible across reboot"
3518 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3521 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3522 skip "Old server doesn't have LU-5006 fix."
3524 setup_quota_test || error "setup quota failed with $?"
3526 # make sure the system is clean
3527 local USED=$(getquota -u $TSTID global curspace)
3529 error "Used space ($USED) for user $TSTID isn't 0."
3531 # create file with MDS_OPEN_DELAY_CREATE flag
3532 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3533 error "Create file failed"
3535 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3536 oflag=sync || error "Write file failed"
3538 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3540 # wait for setattr on objects finished..."
3541 wait_delete_completed
3543 USED=$(getquota -u $TSTID global curspace)
3544 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3546 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3550 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3551 skip "Old server doesn't have LU-8801 fix."
3553 [ "$UID" != 0 ] && skip_env "must run as root" && return
3555 setup_quota_test || error "setup quota failed with $?"
3557 # make sure the system is clean
3558 local USED=$(getquota -u $TSTID global curspace)
3560 error "Used space ($USED) for user $TSTID isn't 0."
3561 USED=$(getquota -u $TSTID2 global curspace)
3563 error "Used space ($USED) for user $TSTID2 isn't 0."
3565 local TESTFILE="$DIR/$tdir/$tfile"
3566 local file_cnt=10000
3568 # Generate id entries in accounting file
3569 echo "Create $file_cnt files..."
3570 for i in `seq $file_cnt`; do
3572 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3573 error "failed to chown $TESTFILE-$i"
3575 cancel_lru_locks osc
3576 sync; sync_all_data || true
3578 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3579 procf=${procf}.quota_slave.acct_user
3582 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3583 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3584 echo "Found $acct_cnt id entries"
3586 [ $file_cnt -eq $acct_cnt ] || {
3587 do_facet mds1 $LCTL get_param $procf
3588 error "skipped id entries"
3591 run_test 38 "Quota accounting iterator doesn't skip id entries"
3594 local TESTFILE="$DIR/$tdir/project"
3595 ! is_project_quota_supported &&
3596 skip "Project quota is not supported"
3598 setup_quota_test || error "setup quota failed with $?"
3601 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3602 [ $projectid -ne 0 ] &&
3603 error "Project id should be 0 not $projectid"
3604 change_project -p 1024 $TESTFILE
3605 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3606 [ $projectid -ne 1024 ] &&
3607 error "Project id should be 1024 not $projectid"
3609 stopall || error "failed to stopall (1)"
3612 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3613 [ $projectid -eq 1024 ] ||
3614 error "Project id should be 1024 not $projectid"
3616 run_test 39 "Project ID interface works correctly"
3619 ! is_project_quota_supported &&
3620 skip "Project quota is not supported"
3621 local dir1="$DIR/$tdir/dir1"
3622 local dir2="$DIR/$tdir/dir2"
3624 setup_quota_test || error "setup quota failed with $?"
3626 mkdir -p $dir1 $dir2
3627 change_project -sp 1 $dir1 && touch $dir1/1
3628 change_project -sp 2 $dir2
3630 ln $dir1/1 $dir2/1_link &&
3631 error "Hard link across different project quota should fail"
3634 run_test 40a "Hard link across different project ID"
3637 ! is_project_quota_supported &&
3638 skip "Project quota is not supported"
3639 local dir1="$DIR/$tdir/dir1"
3640 local dir2="$DIR/$tdir/dir2"
3642 setup_quota_test || error "setup quota failed with $?"
3643 mkdir -p $dir1 $dir2
3644 change_project -sp 1 $dir1 && touch $dir1/1
3645 change_project -sp 2 $dir2
3647 mv $dir1/1 $dir2/2 || error "mv failed $?"
3648 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3649 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3651 run_test 40b "Mv across different project ID"
3654 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3655 ! is_project_quota_supported &&
3656 skip "Project quota is not supported"
3658 setup_quota_test || error "setup quota failed with $?"
3659 local dir="$DIR/$tdir/dir"
3661 mkdir -p $dir && change_project -sp 1 $dir
3662 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3663 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3664 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3665 touch $dir/remote_dir/file
3666 #verify inherit works file for remote dir.
3667 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3668 [ "$projid" != "1" ] &&
3669 error "file under remote dir expected 1 not $projid"
3671 #Agent inode should be ignored for project quota
3672 local used=$(getquota -p 1 global curinodes)
3674 error "file count expected 3 got $used"
3676 run_test 40c "Remote child Dir inherit project quota properly"
3679 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3680 is_project_quota_supported || skip "Project quota is not supported"
3682 setup_quota_test || error "setup quota failed with $?"
3683 local dir="$DIR/$tdir/dir"
3686 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3687 change_project -sp $TSTPRJID $dir ||
3688 error "change project on $dir failed"
3689 for i in $(seq 5); do
3690 mkdir -p $dir/d$i/d$i ||
3691 error "mkdir $dir/d$i/d$i failed"
3692 local projid=$($LFS project -d $dir/d$i/d$i |
3694 [ "$projid" == "$TSTPRJID" ] ||
3695 error "projid id expected $TSTPRJID not $projid"
3696 touch $dir/d$i/d$i/file
3697 #verify inherit works file for stripe dir.
3698 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3699 [ "$projid" == "$TSTPRJID" ] ||
3700 error "file under remote dir expected 1 not $projid"
3703 # account should be 1 + (2 + 1) *10 + 1 * 5
3704 local used=$(getquota -p $TSTPRJID global curinodes)
3706 error "file count expected 36 got $used"
3708 run_test 40d "Stripe Directory inherit project quota properly"
3711 is_project_quota_supported ||
3712 skip "Project quota is not supported"
3713 setup_quota_test || error "setup quota failed with $?"
3714 local dir="$DIR/$tdir/dir"
3717 local projid=$((testnum * 1000))
3721 # enable mdt/ost quota
3722 set_mdt_qtype ugp || error "enable mdt quota failed"
3723 set_ost_qtype ugp || error "enable ost quota failed"
3725 test_mkdir -p $dir && change_project -sp $projid $dir
3726 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3727 error "set project quota failed"
3732 # check if df output works as expected
3733 echo "== global statfs: $MOUNT =="
3734 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3736 echo "== project statfs (prjid=$projid): $dir =="
3737 df -kP $dir; df -iP $dir
3738 local bused=$(getquota -p $projid global curspace)
3739 local iused=$(getquota -p $projid global curinodes)
3740 # note trailing space to match double printf from awk
3741 local expected="$blimit $bused $ilimit $iused "
3743 wait_update $HOSTNAME \
3744 "{ df -kP $dir; df -iP $dir; } |
3745 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3747 error "failed to get correct statfs for project quota"
3749 run_test 41 "df should return projid-specific values"
3757 local osd="osd-ldiskfs"
3759 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3761 rm -f $DIR/$tdir/$tfile
3762 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3763 chmod a+rw $DIR/$tdir/$tfile
3765 $LFS setquota $qtype $qid -B 300M $MOUNT
3766 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3767 error "failed to dd"
3769 do_facet $SINGLEMDS \
3770 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3771 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3774 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3775 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3777 $LFS setquota $qtype $qid --delete $MOUNT
3778 do_facet $SINGLEMDS \
3779 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3780 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3783 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3784 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3786 $LFS setquota $qtype $qid -B 500M $MOUNT
3787 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3788 error "failed to dd"
3789 do_facet $SINGLEMDS \
3790 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3791 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3792 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3794 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3795 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3800 setup_quota_test || error "setup quota failed with $?"
3801 set_ost_qtype $QTYPE || error "enable ost quota failed"
3804 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3805 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3806 is_project_quota_supported &&
3807 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3811 run_test 48 "lfs quota --delete should delete quota project ID"
3814 ! is_project_quota_supported &&
3815 skip "Project quota is not supported"
3817 setup_quota_test || error "setup quota failed with $?"
3818 local dir1="$DIR/$tdir/dir1"
3819 local dir2="$DIR/$tdir/dir2"
3821 mkdir -p $dir1 && change_project -sp 1 $dir1
3822 mkdir -p $dir2 && change_project -sp 2 $dir2
3823 for num in $(seq 1 10); do
3824 touch $dir1/file_$num $dir2/file_$num
3825 ln -s $dir1/file_$num $dir1/file_$num"_link"
3826 ln -s $dir2/file_$num $dir2/file_$num"_link"
3829 count=$($LFS find --projid 1 $DIR | wc -l)
3830 [ "$count" != 21 ] && error "expected 21 but got $count"
3832 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3833 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3834 [ $count -eq 22 ] || error "expected 22 but got $count"
3836 run_test 50 "Test if lfs find --projid works"
3839 ! is_project_quota_supported &&
3840 skip "Project quota is not supported"
3841 setup_quota_test || error "setup quota failed with $?"
3842 local dir="$DIR/$tdir/dir"
3844 mkdir $dir && change_project -sp 1 $dir
3845 local used=$(getquota -p 1 global curinodes)
3846 [ $used != "1" ] && error "expected 1 got $used"
3851 used=$(getquota -p 1 global curinodes)
3852 [ $used != "4" ] && error "expected 4 got $used"
3854 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3856 cp $DIR/$tdir/6 $dir/6
3857 used=$(getquota -p 1 global curinodes)
3858 [ $used != "5" ] && error "expected 5 got $used"
3861 mv $DIR/$tdir/6 $dir/7
3862 used=$(getquota -p 1 global curinodes)
3863 [ $used -eq 6 ] || error "expected 6 got $used"
3865 run_test 51 "Test project accounting with mv/cp"
3868 ! is_project_quota_supported &&
3869 skip "Project quota is not supported"
3871 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
3872 skip "Need MDS version at least 2.14.55"
3874 setup_quota_test || error "setup quota failed with $?"
3876 local dir1=$DIR/$tdir/t52_dir1
3877 local dir2=$DIR/$tdir/t52_dir2
3879 mkdir $dir1 || error "failed to mkdir $dir1"
3880 mkdir $dir2 || error "failed to mkdir $dir2"
3882 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
3883 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
3885 $DD if=/dev/zero of=/$dir1/$tfile bs=1M count=100 ||
3886 error "failed to create and write $tdir1/$tfile"
3888 cancel_lru_locks osc
3889 sync; sync_all_data || true
3891 local attrs=($(lsattr -p $dir1/$tfile))
3892 (( ${attrs[0]} == 1000 )) ||
3893 error "project ID on $dir1/$tfile is not inherited"
3895 $LFS quota -p 1000 $DIR
3896 $LFS quota -p 1001 $DIR
3898 local prev_used=$(getquota -p 1000 global curspace)
3899 local prev_used2=$(getquota -p 1001 global curspace)
3901 mrename $dir1 $dir2/tdir || log "rename directory return $?"
3903 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
3904 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
3905 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
3907 attrs=($(lsattr -p $dir2/$tfile))
3908 (( ${attrs[0]} == 1001 )) ||
3909 error "project ID is not updated after rename"
3911 (( $inum_before == $inum_after )) ||
3912 error "inode is changed after rename: $inum_before, $inum_after"
3914 sync_all_data || true
3916 $LFS quota -p 1000 $DIR
3917 $LFS quota -p 1001 $DIR
3919 local new_used=$(getquota -p 1000 global curspace)
3920 local new_used2=$(getquota -p 1001 global curspace)
3922 (( $prev_used >= $new_used + 102400 )) ||
3923 error "quota is not deducted from old project ID"
3924 (( $prev_used2 <= $new_used2 - 102400 )) ||
3925 error "quota is not added for the new project ID"
3927 run_test 52 "Rename normal file across project ID"
3930 ! is_project_quota_supported &&
3931 skip "Project quota is not supported"
3932 setup_quota_test || error "setup quota failed with $?"
3933 local dir="$DIR/$tdir/dir"
3934 mkdir $dir && change_project -s $dir
3935 [[ $($LFS project -d $dir) =~ " P " ]] ||
3936 error "inherit attribute should be set"
3938 change_project -C $dir
3939 [[ $($LFS project -d $dir) =~ " - " ]] ||
3940 error "inherit attribute should be cleared"
3942 run_test 53 "Project inherit attribute could be cleared"
3945 ! is_project_quota_supported &&
3946 skip "Project quota is not supported"
3947 setup_quota_test || error "setup quota failed with $?"
3948 local testfile="$DIR/$tdir/$tfile-0"
3950 #set project ID/inherit attribute
3951 change_project -sp $TSTPRJID $DIR/$tdir
3952 $RUNAS createmany -m ${testfile} 100 ||
3953 error "create many files failed"
3955 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3956 # one more count for directory itself */
3960 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3961 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3963 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3964 [ $proj_count1 -eq $proj_count ] ||
3965 error "c2: expected $proj_count got $proj_count1"
3967 #clear project but with kept projid
3968 change_project -rCk $DIR/$tdir
3969 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3970 [ $proj_count1 -eq 1 ] ||
3971 error "c3: expected 1 got $proj_count1"
3973 #verify projid untouched.
3974 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3976 [ $proj_count1 -eq $proj_count ] ||
3977 error "c4: expected $proj_count got $proj_count1"
3980 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3981 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3982 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3984 #this time clear all
3985 change_project -rC $DIR/$tdir
3986 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3987 [ $proj_count1 -eq 0 ] ||
3988 error "c6: expected 0 got $proj_count1"
3990 unlinkmany ${testfile} 100 ||
3991 error "unlink many files failed"
3993 run_test 54 "basic lfs project interface test"
3996 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3997 skip "Not supported before 2.10.58."
3998 setup_quota_test || error "setup quota failed with $?"
4000 set_ost_qtype $QTYPE || error "enable ost quota failed"
4003 #add second group to TSTUSR
4004 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
4007 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
4008 error "failed to dd"
4010 cancel_lru_locks osc
4011 sync; sync_all_data || true
4013 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
4014 error "failed to setquota on group $TSTUSR2"
4016 $LFS quota -v -g $TSTUSR2 $DIR
4018 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
4019 error "chgrp should failed with -EDQUOT"
4021 USED=$(getquota -g $TSTUSR2 global curspace)
4024 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
4025 error "failed to setquota on group $TSTUSR2"
4027 $LFS quota -v -g $TSTUSR2 $DIR
4029 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
4030 error "chgrp should succeed"
4032 $LFS quota -v -g $TSTUSR2 $DIR
4034 run_test 55 "Chgrp should be affected by group quota"
4037 setup_quota_test || error "setup quota failed with $?"
4039 set_ost_qtype $QTYPE || error "enable ost quota failed"
4042 $LFS setquota -t -u -b 10 -i 10 $DIR ||
4043 erro "failed to set grace time for usr quota"
4044 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4045 awk '{print $4 $8}')
4046 if [ "x$grace_time" != "x10s;10s" ]; then
4047 $LFS quota -t -u $DIR
4048 error "expected grace time: 10s;10s, got:$grace_time"
4051 run_test 56 "lfs quota -t should work well"
4054 setup_quota_test || error "setup quota failed with $?"
4056 local dir="$DIR/$tdir/dir"
4059 #command can process further if it hit some errors
4060 $LFS project -sp 1 $dir/pipe
4061 touch $dir/aaa $dir/bbb
4062 mkdir $dir/subdir -p
4063 touch $dir/subdir/aaa $dir/subdir/bbb
4064 #create one invalid link file
4065 ln -s $dir/not_exist_file $dir/ccc
4066 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4067 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4069 run_test 57 "lfs project could tolerate errors"
4072 [ "$mds1_FSTYPE" != ldiskfs ] &&
4073 skip "ldiskfs only test"
4074 disable_project_quota
4075 setup_quota_test || error "setup quota failed with $?"
4078 local testfile="$DIR/$tdir/$tfile-0"
4079 #make sure it did not crash kernel
4080 touch $testfile && lfs project -sp 1 $testfile
4082 enable_project_quota
4084 run_test 59 "lfs project dosen't crash kernel with project disabled"
4087 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4088 skip "Needs MDS version 2.11.53 or later."
4089 setup_quota_test || error "setup quota failed with $?"
4091 local testfile=$DIR/$tdir/$tfile
4094 set_mdt_qtype "ug" || error "enable mdt quota failed"
4096 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4097 error "set quota failed"
4098 quota_show_check a g $TSTUSR
4100 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4101 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4102 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4103 error "create many files failed"
4105 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4107 # root user can overrun quota
4108 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4109 error "root user should succeed"
4111 run_test 60 "Test quota for root with setgid"
4113 # test default quota
4114 test_default_quota() {
4115 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4116 skip "Not supported before 2.11.51."
4121 local qprjid=$TSTPRJID
4125 local LIMIT=20480 #20M disk space
4126 local TESTFILE="$DIR/$tdir/$tfile-0"
4129 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4130 echo "Project quota is not supported" && return 0
4132 [ $qtype == "-u" ] && qdtype="-U"
4133 [ $qtype == "-g" ] && qdtype="-G"
4134 [ $qtype == "-p" ] && {
4139 [ $qres_type == "meta" ] && {
4140 LIMIT=10240 #10K inodes
4145 qpool_cmd="--pool $3"
4146 # pool quotas don't work properly without global limit
4147 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4148 error "set global limit failed"
4151 setup_quota_test || error "setup quota failed with $?"
4155 # enable mdt/ost quota
4156 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4157 set_ost_qtype $QTYPE || error "enable ost quota failed"
4159 log "set to use default quota"
4160 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4161 error "set $qid to use default quota failed"
4163 log "set default quota"
4164 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4165 error "set $qid default quota failed"
4167 log "get default quota"
4168 $LFS quota $qdtype $DIR || error "get default quota failed"
4170 if [ $qres_type == "data" ]; then
4171 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4172 grep "$MOUNT" | awk '{print $2}')
4173 [ $SLIMIT -eq $LIMIT ] ||
4174 error "the returned default quota is wrong"
4176 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4178 [ $SLIMIT -eq $LIMIT ] ||
4179 error "the returned default quota is wrong"
4182 # make sure the system is clean
4183 local USED=$(getquota $qtype $qid global curspace)
4184 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4186 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4187 error "setstripe $TESTFILE failed"
4188 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4190 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4192 log "Test not out of quota"
4193 if [ $qres_type == "data" ]; then
4194 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4195 quota_error $qtype $qid "write failed, expect succeed"
4197 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4198 quota_error $qtype $qid "create failed, expect succeed"
4200 unlinkmany $TESTFILE $((LIMIT/2))
4203 log "Test out of quota"
4204 # flush cache, ensure noquota flag is set on client
4205 cancel_lru_locks osc
4206 cancel_lru_locks mdc
4207 sync; sync_all_data || true
4208 if [ $qres_type == "data" ]; then
4209 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4210 quota_error $qtype $qid "write succeed, expect EDQUOT"
4212 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4213 quota_error $qtype $qid "create succeed, expect EDQUOT"
4215 unlinkmany $TESTFILE $((LIMIT*2))
4219 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4220 error "setstripe $TESTFILE failed"
4221 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4223 log "Increase default quota"
4225 # LU-4505: sleep 5 seconds to enable quota acquire
4228 # increase default quota
4229 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4230 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4232 cancel_lru_locks osc
4233 cancel_lru_locks mdc
4234 sync; sync_all_data || true
4235 if [ $qres_type == "data" ]; then
4236 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4237 quota_error $qtype $qid "write failed, expect succeed"
4239 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4240 quota_error $qtype $qid "create failed, expect succeed"
4242 unlinkmany $TESTFILE $((LIMIT*2))
4245 log "Set quota to override default quota"
4246 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4247 error "set $qid quota failed"
4249 cancel_lru_locks osc
4250 cancel_lru_locks mdc
4251 sync; sync_all_data || true
4252 if [ $qres_type == "data" ]; then
4253 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4254 quota_error $qtype $qid "write succeed, expect EQUOT"
4256 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4257 quota_error $qtype $qid "create succeed, expect EQUOT"
4259 unlinkmany $TESTFILE $((LIMIT*2))
4262 log "Set to use default quota again"
4264 # LU-4505: sleep 5 seconds to enable quota acquire
4267 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4268 error "set $qid to use default quota failed"
4270 cancel_lru_locks osc
4271 cancel_lru_locks mdc
4272 sync; sync_all_data || true
4273 if [ $qres_type == "data" ]; then
4274 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4275 quota_error $qtype $qid "write failed, expect succeed"
4277 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4278 quota_error $qtype $qid "create failed, expect succeed"
4280 unlinkmany $TESTFILE $((LIMIT*2))
4285 wait_delete_completed || error "wait_delete_completed failed"
4286 sync_all_data || true
4288 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4289 error "reset default quota failed"
4290 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4291 error "reset quota failed"
4296 test_default_quota "-u" "data"
4297 test_default_quota "-u" "meta"
4298 test_default_quota "-g" "data"
4299 test_default_quota "-g" "meta"
4300 test_default_quota "-p" "data"
4301 test_default_quota "-p" "meta"
4303 run_test 61 "default quota tests"
4306 ! is_project_quota_supported &&
4307 skip "Project quota is not supported"
4308 [[ "$(chattr -h 2>&1)" =~ "project" ||
4309 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4310 skip "chattr did not support project quota"
4311 setup_quota_test || error "setup quota failed with $?"
4312 local testdir=$DIR/$tdir/
4314 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4315 change_project -s $testdir
4316 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4317 error "inherit attribute should be set"
4318 # chattr used FS_IOC_SETFLAGS ioctl
4319 $RUNAS chattr -P $testdir &&
4320 error "regular user clear inherit should fail"
4321 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4322 error "inherit attribute should still be set"
4323 chattr -P $testdir || error "root failed to clear inherit"
4324 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4325 error "inherit attribute should be cleared"
4328 run_test 62 "Project inherit should be only changed by root"
4331 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4332 skip "Not supported before 2.11.55"
4336 local dd_failed=false
4337 local tdir_dom=${tdir}_dom
4338 local LIMIT=20480 #20M
4340 [ $qtype == "p" ] && ! is_project_quota_supported &&
4341 echo "Project quota is not supported" && return 0
4343 [ $qtype == "p" ] && qid=$TSTPRJID
4345 setup_quota_test || error "setup quota failed with $?"
4349 # enable mdt/ost quota
4350 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4351 set_ost_qtype $QTYPE || error "enable ost quota failed"
4353 # make sure the system is clean
4354 local USED=$(getquota -$qtype $qid global curspace)
4355 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4357 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4359 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4360 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4361 error "setstripe $tdir_dom failed"
4362 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4364 [ $qtype == "p" ] && {
4365 change_project -sp $TSTPRJID $DIR/$tdir
4366 change_project -sp $TSTPRJID $DIR/$tdir_dom
4369 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4370 error "set $qid quota failed"
4372 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4373 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4377 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4379 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4380 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4384 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4386 rm -f $DIR/$tdir_dom/*
4388 # flush cache, ensure noquota flag is set on client
4389 cancel_lru_locks osc
4390 cancel_lru_locks mdc
4391 sync; sync_all_data || true
4395 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4396 quota_error $qtype $qid "write failed, expect succeed"
4398 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4399 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4403 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4406 rm -f $DIR/$tdir_dom/*
4408 # flush cache, ensure noquota flag is set on client
4409 cancel_lru_locks osc
4410 cancel_lru_locks mdc
4411 sync; sync_all_data || true
4415 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4416 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4420 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4422 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4423 quota_error $qtype $qid "write succeed, expect EDQUOT"
4426 rm -fr $DIR/$tdir_dom
4428 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4429 error "reset usr quota failed"
4437 run_test 63 "quota on DoM tests"
4440 ! is_project_quota_supported &&
4441 skip "Project quota is not supported"
4442 setup_quota_test || error "setup quota failed with $?"
4443 local dir1="$DIR/$tdir/"
4446 ln -s $dir1/file $dir1/file_link
4449 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4450 error "set project should succeed"
4452 used=$(getquota -p $TSTPRJID global curinodes)
4453 [ $used -eq 4 ] || error "expected 4 got $used"
4454 $LFS project -rC $dir1 >&/dev/null ||
4455 error "clear project should succeed"
4457 used=$(getquota -p $TSTPRJID global curinodes)
4458 [ $used -eq 0 ] || error "expected 0 got $used"
4460 run_test 64 "lfs project on non dir/files should succeed"
4464 local TESTFILE="$DIR/$tdir/$tfile-0"
4466 setup_quota_test || error "setup quota failed with $?"
4467 set_ost_qtype $QTYPE || error "enable ost quota failed"
4471 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4472 error "failed to write"
4473 # flush cache, ensure noquota flag is set on client
4474 cancel_lru_locks osc
4475 sync; sync_all_data || true
4477 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4478 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4479 local quota_all=$($RUNAS $LFS quota $DIR)
4481 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4482 error "usr quota not match"
4483 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4484 error "grp quota not match"
4486 run_test 65 "Check lfs quota result"
4489 ! is_project_quota_supported &&
4490 skip "Project quota is not supported"
4491 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4492 skip "Not supported before 2.12.4"
4493 setup_quota_test || error "setup quota failed with $?"
4494 local old=$(do_facet mds1 $LCTL get_param -n \
4495 mdt.*.enable_chprojid_gid | head -1)
4496 local testdir=$DIR/$tdir/foo
4498 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4499 stack_trap "do_facet mds1 $LCTL \
4500 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4502 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4503 chown -R $TSTID:$TSTID $testdir
4504 change_project -sp $TSTPRJID $testdir
4505 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4507 $RUNAS lfs project -p 0 $testdir/foo &&
4508 error "nonroot user should fail to set projid"
4510 $RUNAS lfs project -C $testdir/foo &&
4511 error "nonroot user should fail to clear projid"
4513 change_project -C $testdir/foo || error "failed to clear project"
4515 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4516 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4517 "failed to set projid with normal user when enable_chprojid_gid=-1"
4519 $RUNAS lfs project -rC $testdir/ || error \
4520 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4522 touch $testdir/bar || error "failed touch $testdir/bar"
4523 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4524 "normal user should not be able to set projid on root owned file"
4526 change_project -p $TSTPRJID $testdir/bar || error \
4527 "root should be able to change its own file's projid"
4529 run_test 66 "nonroot user can not change project state in default"
4536 local short_qtype=${qtype:0:1}
4539 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4541 $TSTUSR) _runas=$RUNAS;;
4542 $TSTUSR2) _runas=$RUNAS2;;
4543 *) error "unknown quota parameter $4";;
4548 $_runas $DD of=$file count=$size ||
4549 quota_error $short_qtype $TSTUSR \
4550 "$qtype write failure, but expect success"
4552 cancel_lru_locks osc
4554 sync; sync_all_data || true
4563 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4565 do_facet mds1 $LCTL get_param $param |
4566 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4571 local testfile="$DIR/$tdir/$tfile-0"
4572 local testfile2="$DIR/$tdir/$tfile-1"
4573 local testfile3="$DIR/$tdir/$tfile-2"
4574 local qpool="qpool1"
4580 [ "$ost1_FSTYPE" == zfs ] &&
4581 skip "ZFS grants some block space together with inode"
4583 setup_quota_test || error "setup quota failed with $?"
4586 set_ost_qtype $QTYPE || error "enable ost quota failed"
4589 log "User quota (block hardlimit:$limit MB)"
4590 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4591 error "set user quota failed"
4593 # make sure the system is clean
4594 used=$(getquota -u $TSTUSR global curspace)
4595 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4597 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4598 echo "granted 0x0 before write $granted"
4600 # trigger reintegration
4601 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4602 procf=${procf}quota_slave.force_reint
4603 do_facet ost1 $LCTL set_param $procf=1 ||
4604 error "force reintegration failed"
4605 wait_ost_reint "u" || error "reintegration failed"
4606 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4607 [ $granted -ne 0 ] &&
4608 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4610 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4611 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4613 # write 10 MB to testfile
4614 test_67_write "$testfile" "user" 10 "$TSTUSR"
4616 # create qpool and add OST1
4617 pool_add $qpool || error "pool_add failed"
4618 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4619 # as $TSTUSR hasn't limits, lqe may absent. But it should be
4620 # created after the 1st direct qmt_get.
4621 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4623 # check granted - should be 0, as testfile is located only on OST0
4624 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4625 echo "global granted $granted"
4626 granted=$(getgranted $qpool "dt" $TSTID "usr")
4627 echo "$qpool granted $granted"
4628 [ $granted -ne 0 ] &&
4629 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4631 # add OST0 to qpool and check granted space
4632 pool_add_targets $qpool 0 1 ||
4633 error "pool_add_targets failed"
4634 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4635 echo "Granted $granted_mb MB"
4636 #should be 10M + qunit for each OST
4637 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4638 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4640 $LFS setstripe $testfile2 -c 1 -i 1 ||
4641 error "setstripe $testfile2 failed"
4642 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4643 # Write from another user and check that qpool1
4644 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
4645 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
4646 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4647 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4648 [ $granted -ne 0 ] &&
4649 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4651 # Granted space for $TSTUSR2 in qpool1 should appear only
4652 # when global lqe for this user becomes enforced.
4653 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4654 error "set user quota failed"
4655 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4656 echo "granted_mb $granted_mb"
4657 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4658 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4660 $LFS setstripe $testfile3 -c 1 -i 0 ||
4661 error "setstripe $testfile3 failed"
4662 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4663 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
4664 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4665 echo "$testfile3 granted_mb $granted_mb"
4666 [ $granted_mb -eq $limit ] ||
4667 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4669 # remove OST1 from the qpool1 and check granted space
4670 # should be 0 for TSTUSR and 10M for TSTUSR2
4671 pool_remove_target $qpool 0
4672 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4673 [ $granted_mb -eq 0 ] ||
4674 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4675 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4676 [ $granted_mb -eq 10 ] ||
4677 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4680 wait_delete_completed || error "wait_delete_completed failed"
4681 sync_all_data || true
4682 used=$(getquota -u $TSTUSR global curspace)
4683 [ $used -eq 0 ] || quota_error u $TSTUSR \
4684 "user quota isn't released after deletion"
4686 run_test 67 "quota pools recalculation"
4693 wait_update_facet mds1 \
4694 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4695 >/dev/null 2>&1 || echo foo" "" ||
4696 error "mds1: failed to create quota pool $pool"
4698 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4699 awk '/usr/ {getline; print $2}'
4704 local qpool="qpool1"
4707 setup_quota_test || error "setup quota failed with $?"
4710 set_ost_qtype $QTYPE || error "enable ost quota failed"
4712 # check slave number for glbal pool
4713 local nr=$(get_slave_nr "0x0" "usr")
4714 echo "nr result $nr"
4715 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4716 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4718 # create qpool and add OST1
4719 pool_add $qpool || error "pool_add failed"
4720 nr=$(get_slave_nr $qpool "usr")
4721 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4724 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4725 nr=$(get_slave_nr $qpool "usr")
4726 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4729 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4730 nr=$(get_slave_nr $qpool "usr")
4731 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4734 pool_remove_target $qpool 0
4735 nr=$(get_slave_nr $qpool "usr")
4736 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4739 pool_remove_target $qpool 1
4740 nr=$(get_slave_nr $qpool "usr")
4741 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4743 # Check again that all is fine with global pool
4744 nr=$(get_slave_nr "0x0" "usr")
4745 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4746 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4748 run_test 68 "slave number in quota pool changed after each add/remove OST"
4752 local global_limit=200 # MB
4754 local testfile="$DIR/$tdir/$tfile-0"
4755 local dom0="$DIR/$tdir/dom0"
4756 local qpool="qpool1"
4759 setup_quota_test || error "setup quota failed with $?"
4762 set_ost_qtype $QTYPE || error "enable ost quota failed"
4763 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4765 # Save DOM only at MDT0
4766 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4767 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4769 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4771 # create qpool and add OST0
4772 pool_add $qpool || error "pool_add failed"
4773 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4775 log "User quota (block hardlimit:$global_limit MB)"
4776 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4777 error "set user quota failed"
4779 log "User quota (block hardlimit:$limit MB)"
4780 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4781 error "set user quota failed"
4783 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4784 quota_error u $TSTUSR "write failed"
4786 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4787 oflag=sync || quota_error u $TSTUSR "write failed"
4789 $RUNAS $DD of=$testfile count=$limit || true
4791 # flush cache, ensure noquota flag is set on client
4792 cancel_lru_locks osc
4793 sync; sync_all_data || true
4795 # MDT0 shouldn't get EDQUOT with glimpse.
4796 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4797 quota_error u $TSTUSR \
4798 "user write success, but expect EDQUOT"
4800 # Now all members of qpool1 should get EDQUOT. Expect success
4801 # when write to DOM on MDT0, as it belongs to global pool.
4802 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4803 oflag=sync || quota_error u $TSTUSR "write failed"
4805 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4806 oflag=sync || quota_error u $TSTUSR "write failed"
4808 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4812 local qpool="qpool1"
4817 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4818 skip "Needs a client >= $VERSION_WITH_QP"
4820 setup_quota_test || error "setup quota failed with $?"
4822 # MDS returns EFAULT for unsupported quotactl command
4823 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4825 # create qpool and add OST0
4826 pool_add $qpool || error "pool_add failed"
4827 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4829 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4831 [ $rc -eq $err ] || error "setquota res $rc != $err"
4833 # If MDS supports QP, check that limit was set properly.
4834 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4835 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4836 echo "hard limit $bhard limit $limit"
4837 [ $bhard -ne $((limit*1024)) ] &&
4838 error "bhard:$bhard for $qpool!=$((limit*1024))"
4841 $LFS quota -u $TSTUSR --pool $qpool $DIR
4843 [ $rc -eq $err ] || error "quota res $rc != $err"
4845 run_test 70a "check lfs setquota/quota with a pool option"
4849 local glbl_hard=200 # 200M
4850 local glbl_soft=100 # 100M
4851 local pool_hard=10 # 10M
4852 local qpool="qpool1"
4854 pool_add $qpool || error "pool_add failed"
4855 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4857 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
4858 error "set user quota failed"
4859 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
4860 error "set user quota failed"
4862 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4863 [ $tmp -eq $((pool_hard * 1024)) ] ||
4864 error "wrong block hard limit $tmp for $qpool"
4865 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
4866 # soft limit hasn't been set and should be zero
4867 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
4869 run_test 70b "lfs setquota pool works properly"
4874 local global_limit=100 # MB
4875 local testfile="$DIR/$tdir/$tfile-0"
4876 local qpool="qpool1"
4877 local qpool2="qpool2"
4879 [ "$ost1_FSTYPE" == zfs ] &&
4880 skip "ZFS grants some block space together with inode"
4881 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4883 setup_quota_test || error "setup quota failed with $?"
4886 set_ost_qtype $QTYPE || error "enable ost quota failed"
4889 log "User quota (block hardlimit:$global_limit MB)"
4890 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4891 error "set user quota failed"
4893 pool_add $qpool || error "pool_add failed"
4894 pool_add_targets $qpool 0 1 ||
4895 error "pool_add_targets failed"
4897 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4898 error "set user quota failed"
4900 pool_add $qpool2 || error "pool_add failed"
4901 pool_add_targets $qpool2 1 1 ||
4902 error "pool_add_targets failed"
4904 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4905 error "set user quota failed"
4907 # make sure the system is clean
4908 local used=$(getquota -u $TSTUSR global curspace)
4911 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4913 # create 1st component 1-10M
4914 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4915 #create 2nd component 10-30M
4916 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4917 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4919 # сheck normal use and out of quota with PFL
4920 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4921 test_1_check_write $testfile "user" $((limit*2))
4923 wait_delete_completed || error "wait_delete_completed failed"
4924 sync_all_data || true
4925 used=$(getquota -u $TSTUSR global curspace)
4926 [ $used -ne 0 ] && quota_error u $TSTUSR \
4927 "user quota isn't released after deletion"
4929 # create 1st component 1-10M
4930 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4931 # create 2nd component 10-30M
4932 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4933 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4935 # write to the 2nd component
4936 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4937 quota_error u $TSTUSR \
4938 "write failure, but expect success"
4939 # this time maybe cache write, ignore it's failure
4940 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4941 cancel_lru_locks osc
4942 sync; sync_all_data || true
4943 # write over limit in qpool2(2nd component 10-30M)
4944 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4945 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4946 # write to the 1st component - OST0 is empty
4947 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4948 quota_error u $TSTUSR "write failed"
4950 run_test 71a "Check PFL with quota pools"
4954 local global_limit=1000 # MB
4955 local limit1=160 # MB
4956 local limit2=10 # MB
4957 local testfile="$DIR/$tdir/$tfile-0"
4958 local qpool="qpool1"
4959 local qpool2="qpool2"
4961 [ "$ost1_FSTYPE" == zfs ] &&
4962 skip "ZFS grants some block space together with inode"
4963 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4965 setup_quota_test || error "setup quota failed with $?"
4968 set_ost_qtype $QTYPE || error "enable ost quota failed"
4971 log "User quota (block hardlimit:$global_limit MB)"
4972 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4973 error "set user quota failed"
4975 pool_add $qpool || error "pool_add failed"
4976 pool_add_targets $qpool 0 1 ||
4977 error "pool_add_targets failed"
4979 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4980 error "set user quota failed"
4982 pool_add $qpool2 || error "pool_add failed"
4983 pool_add_targets $qpool2 1 1 ||
4984 error "pool_add_targets failed"
4986 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4987 error "set user quota failed"
4989 # make sure the system is clean
4990 local used=$(getquota -u $TSTUSR global curspace)
4993 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4995 # First component is on OST0, 2nd on OST1
4996 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4997 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4999 # fill the 1st component on OST0
5000 $RUNAS $DD of=$testfile count=128 ||
5001 quota_error u $TSTUSR "write failed"
5002 # write to the 2nd cmpnt on OST1
5003 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
5004 quota_error u $TSTUSR "write failed"
5005 # this time maybe cache write, ignore it's failure
5006 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
5008 cancel_lru_locks osc
5009 sync; sync_all_data || true
5010 # write over limit in qpool2
5011 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
5012 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5015 run_test 71b "Check SEL with quota pools"
5020 local global_limit=50 # MB
5021 local testfile="$DIR/$tdir/$tfile-0"
5022 local qpool="qpool1"
5025 setup_quota_test || error "setup quota failed with $?"
5028 set_ost_qtype $QTYPE || error "enable ost quota failed"
5031 log "User quota (block hardlimit:$global_limit MB)"
5032 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5033 error "set user quota failed"
5035 pool_add $qpool || error "pool_add failed"
5036 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5038 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5039 error "set user quota failed"
5041 # make sure the system is clean
5042 local used=$(getquota -u $TSTUSR global curspace)
5044 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5046 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5048 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5049 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5050 test_1_check_write $testfile "user" $limit
5051 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5053 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5054 # check that lfs quota -uv --pool prints only OST that
5055 # was added in a pool
5056 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5057 grep "OST\|MDT" && error "$qpool consists wrong targets"
5060 run_test 72 "lfs quota --pool prints only pool's OSTs"
5064 local qpool="qpool1"
5068 pool_add $qpool || error "pool_add failed"
5069 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5070 error "pool_add_targets failed"
5072 test_default_quota "-u" "data" "qpool1"
5074 run_test 73a "default limits at OST Pool Quotas"
5078 local TESTFILE1="$DIR/$tdir/$tfile-1"
5080 local qpool="qpool1"
5084 setup_quota_test || error "setup quota failed with $?"
5086 set_ost_qtype $QTYPE || error "enable ost quota failed"
5088 # pool quotas don't work properly without global limit
5089 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5090 error "set global limit failed"
5092 pool_add $qpool || error "pool_add failed"
5093 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5094 error "pool_add_targets failed"
5096 log "set default quota for $qpool"
5097 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5098 error "set default quota failed"
5100 log "Write from user that hasn't lqe"
5101 # Check that it doesn't cause a panic or a deadlock
5102 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5103 # Have to use RUNAS_ID as resetquota creates lqes in
5104 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5105 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5107 cancel_lru_locks osc
5108 sync; sync_all_data || true
5110 run_test 73b "default OST Pool Quotas limit for new user"
5114 local global_limit=200 # 200M
5115 local limit=10 # 10M
5116 local limit2=50 # 50M
5117 local qpool="qpool1"
5118 local qpool2="qpool2"
5122 setup_quota_test || error "setup quota failed with $?"
5125 set_ost_qtype $QTYPE || error "enable ost quota failed"
5127 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5128 error "set user quota failed"
5130 pool_add $qpool || error "pool_add failed"
5131 pool_add_targets $qpool 0 1 ||
5132 error "pool_add_targets failed"
5134 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5135 error "set user quota failed"
5137 pool_add $qpool2 || error "pool_add failed"
5138 pool_add_targets $qpool2 1 1 ||
5139 error "pool_add_targets failed"
5141 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5142 error "set user quota failed"
5144 tmp=$(getquota -u $TSTUSR global bhardlimit)
5145 [ $tmp -eq $((global_limit * 1024)) ] ||
5146 error "wrong global limit $global_limit"
5148 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5149 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5151 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5152 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5154 # check limits in pools
5155 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5156 grep -A4 $qpool | awk 'NR == 4{print $4}')
5157 echo "pool limit for $qpool $tmp"
5158 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5159 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5160 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5161 echo "pool limit for $qpool2 $tmp"
5162 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5164 run_test 74 "check quota pools per user"
5166 function cleanup_quota_test_75()
5168 do_facet mgs $LCTL nodemap_modify --name default \
5169 --property admin --value 1
5170 do_facet mgs $LCTL nodemap_modify --name default \
5171 --property trusted --value 1
5172 do_facet mgs $LCTL nodemap_modify --name default \
5173 --property squash_uid --value 99
5174 do_facet mgs $LCTL nodemap_modify --name default \
5175 --property squash_gid --value 99
5177 wait_nm_sync default admin_nodemap
5178 wait_nm_sync default trusted_nodemap
5180 do_facet mgs $LCTL nodemap_activate 0
5183 resetquota -u $TSTUSR
5187 local dd_failed=false
5188 local LIMIT=20480 #20M
5191 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5192 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5193 oflag=sync || dd_failed=true
5196 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5198 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5199 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5200 oflag=sync || dd_failed=true
5203 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5205 rm -f $DIR/$tdir_dom/*
5207 # flush cache, ensure noquota flag is set on client
5209 sync; sync_all_data || true
5213 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
5214 quota_error u $qid "write failed, expect succeed (2)"
5216 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5217 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5218 oflag=sync || dd_failed=true
5221 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5224 rm -f $DIR/$tdir_dom/*
5226 # flush cache, ensure noquota flag is set on client
5228 sync; sync_all_data || true
5232 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5233 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5234 oflag=sync || dd_failed=true
5237 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5239 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
5240 quota_error u $qid "write succeed, expect EDQUOT (3)"
5246 local soft_limit=10 # MB
5247 local hard_limit=20 # MB
5248 local limit=$soft_limit
5249 local testfile="$DIR/$tdir/$tfile-0"
5250 local grace=20 # seconds
5251 local tdir_dom=${tdir}_dom
5253 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5257 setup_quota_test || error "setup quota failed with $?"
5258 stack_trap cleanup_quota_test_75 EXIT
5261 set_ost_qtype $QTYPE || error "enable ost quota failed"
5262 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5264 local used=$(getquota -u $TSTID global curspace)
5265 $LFS setquota -t -u --block-grace $grace --inode-grace \
5266 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5267 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5268 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5269 error "set user quota failed"
5271 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5272 mkdir $DIR/$tdir_dom
5273 chmod 777 $DIR/$tdir_dom
5274 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5275 error "setstripe $tdir_dom failed"
5277 do_facet mgs $LCTL nodemap_activate 1
5279 do_facet mgs $LCTL nodemap_modify --name default \
5280 --property admin --value 0
5281 do_facet mgs $LCTL nodemap_modify --name default \
5282 --property trusted --value 0
5283 do_facet mgs $LCTL nodemap_modify --name default \
5284 --property deny_unknown --value 0
5285 do_facet mgs $LCTL nodemap_modify --name default \
5286 --property squash_uid --value $TSTID
5287 do_facet mgs $LCTL nodemap_modify --name default \
5288 --property squash_gid --value $TSTID
5289 cancel_lru_locks mdc
5290 wait_nm_sync default admin_nodemap
5291 wait_nm_sync default trusted_nodemap
5292 wait_nm_sync default squash_uid
5294 # mmap write when over soft limit
5296 $DD of=$testfile count=${limit} ||
5297 quota_error a "root write failure, but expect success (1)"
5298 OFFSET=$((limit * 1024))
5299 cancel_lru_locks osc
5301 echo "Write to exceed soft limit"
5302 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5303 quota_error a $TSTUSR "root write failure, but expect success (2)"
5304 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5305 cancel_lru_locks osc
5307 echo "mmap write when over soft limit"
5308 $MULTIOP $testfile.mmap OT40960SMW ||
5309 quota_error a $TSTUSR "mmap write failure, but expect success"
5310 cancel_lru_locks osc
5312 wait_delete_completed || error "wait_delete_completed failed (1)"
5313 sync_all_data || true
5315 # test for user hard limit
5318 $DD of=$testfile bs=1M count=$((limit/2)) ||
5319 quota_error u $TSTID \
5320 "root write failure, but expect success (3)"
5322 log "Write out of block quota ..."
5323 # possibly a cache write, ignore failure
5324 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
5325 # flush cache, ensure noquota flag is set on client
5326 cancel_lru_locks osc
5327 sync; sync_all_data || true
5328 # sync forced cache flush, but did not guarantee that slave
5329 # got new edquot through glimpse, so wait to make sure
5331 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
5332 quota_error u $TSTID \
5333 "user write success, but expect EDQUOT"
5335 wait_delete_completed || error "wait_delete_completed failed (2)"
5336 sync_all_data || true
5337 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5338 quota_error u $TSTID "user quota not released after deletion"
5342 run_test 75 "nodemap squashed root respects quota enforcement"
5345 ! is_project_quota_supported &&
5346 skip "skip project quota unsupported"
5348 setup_quota_test || error "setup quota failed with $?"
5351 local testfile="$DIR/$tdir/$tfile-0"
5354 $LFS project -p 4294967295 $testfile &&
5355 error "set project ID should fail"
5358 run_test 76 "project ID 4294967295 should be not allowed"
5362 mount_client $MOUNT2 "ro"
5363 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5364 error "lfs setquota should fail in read-only Lustre mount"
5367 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5371 (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
5372 skip "need OST at least 2.14.55"
5373 check_set_fallocate_or_skip
5375 setup_quota_test || error "setup quota failed with $?"
5378 set_ost_qtype $QTYPE || error "enable ost quota failed"
5380 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5381 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5384 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5385 error "lfs setquota failed"
5388 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5390 kbytes=$(lfs quota -u $TSTUSR $DIR |
5391 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5392 echo "kbytes returned:$kbytes"
5394 # For file size of 204800. We should be having roughly 200 kbytes
5395 # returned. Anything alarmingly low (50 taken as arbitrary value)
5396 # would bail out this TC. Also this also avoids $kbytes of 0
5397 # to be used in calculation below.
5398 (( $kbytes > 50 )) ||
5399 error "fallocate did not use quota. kbytes returned:$kbytes"
5401 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5402 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5404 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5405 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5406 error "fallocate did not use quota correctly"
5408 run_test 78 "Check fallocate increase quota usage"
5412 (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
5413 skip "need client at least 2.15.0"
5414 (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
5415 skip "need OST at least 2.15.0"
5416 check_set_fallocate_or_skip
5418 setup_quota_test || error "setup quota failed with $?"
5421 set_ost_qtype $QTYPE || error "enable ost quota failed"
5423 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5425 local projectid=5200 # Random project id to test
5427 change_project -sp $projectid $DIR/$tdir
5430 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5431 error "lfs setquota project failed"
5434 fallocate -l 204800 $DIR/$tdir/$tfile
5436 # Get curspace (kbytes) for $projectid
5437 local kbytes=$(getquota -p $projectid global curspace)
5439 echo "kbytes returned:$kbytes"
5441 # For file size of 204800. We should be having roughly 200 kbytes
5442 # returned. Anything alarmingly low (50 taken as arbitrary value)
5443 # would bail out this TC. Also this also avoids $kbytes of 0
5444 # to be used in calculation below.
5445 (( $kbytes > 50 )) ||
5446 error "fallocate did not use projectid. kbytes returned:$kbytes"
5448 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5449 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5451 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5452 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5453 error "fallocate did not use quota projectid correctly"
5455 run_test 78a "Check fallocate increase projectid usage"
5459 local qpool="qpool1"
5460 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5461 local stopf=$TMP/$tfile
5463 do_facet mds1 "touch $stopf"
5464 stack_trap "do_facet mds1 'rm -f $stopf'"
5465 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5467 pool_add $qpool || error "pool_add failed"
5468 do_facet mds1 "rm $stopf"
5471 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5475 local dir1="$DIR/$tdir/dir1"
5476 local dir2="$DIR/$tdir/dir2"
5477 local TESTFILE0="$dir1/$tfile-0"
5478 local TESTFILE1="$dir1/$tfile-1"
5479 local TESTFILE2="$dir1/$tfile-2"
5480 local TESTFILE3="$dir2/$tfile-0"
5481 local global_limit=100 # 100M
5482 local limit=10 # 10M
5483 local qpool="qpool1"
5485 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5487 [ "$ost1_FSTYPE" == zfs ] &&
5488 skip "ZFS grants some block space together with inode"
5489 setup_quota_test || error "setup quota failed with $?"
5490 set_ost_qtype $QTYPE || error "enable ost quota failed"
5492 # make sure the system is clean
5493 local used=$(getquota -u $TSTUSR global curspace)
5494 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5496 pool_add $qpool || error "pool_add failed"
5497 pool_add_targets $qpool 0 1 ||
5498 error "pool_add_targets failed"
5500 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5501 error "set user quota failed"
5503 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5504 error "set user quota failed"
5505 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5506 error "set user quota failed"
5508 mkdir -p $dir1 || error "failed to mkdir"
5509 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5510 mkdir -p $dir2 || error "failed to mkdir"
5511 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5513 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5514 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5519 $LFS quota -uv $TSTUSR $DIR
5520 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5521 do_facet mds1 $LCTL set_param fail_loc=0xa06
5522 $RUNAS $DD of=$TESTFILE3 count=3 ||
5523 quota_error u $TSTUSR "write failed"
5524 $RUNAS $DD of=$TESTFILE2 count=7 ||
5525 quota_error u $TSTUSR "write failed"
5526 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5527 quota_error u $TSTUSR "write failed"
5530 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5534 do_facet mds1 $LCTL set_param fail_loc=0
5535 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5536 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5537 # OST0 needs some time to update quota usage after removing TESTFILE2
5539 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5540 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5541 quota_error u $TSTUSR "write failure, but expect success"
5543 run_test 80 "check for EDQUOT after OST failover"
5546 local global_limit=20 # 100M
5547 local testfile="$DIR/$tdir/$tfile-0"
5548 local qpool="qpool1"
5551 setup_quota_test || error "setup quota failed with $?"
5554 set_ost_qtype $QTYPE || error "enable ost quota failed"
5557 log "User quota (block hardlimit:$global_limit MB)"
5558 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5560 pool_add $qpool || error "pool_add failed"
5561 #define OBD_FAIL_QUOTA_RECALC 0xA07
5562 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5563 # added OST casues to start pool recalculation
5564 pool_add_targets $qpool 0 0 1
5565 stop mds1 -f || error "MDS umount failed"
5567 #start mds1 back to destroy created pool
5568 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5571 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5575 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
5576 skip "need MDS 2.14.55 or later"
5577 is_project_quota_supported ||
5578 skip "skip project quota unsupported"
5580 setup_quota_test || error "setup quota failed with $?"
5583 local parent_dir="$DIR/$tdir.parent"
5584 local child_dir="$parent_dir/child"
5587 stack_trap "chown -R 0:0 $parent_dir"
5589 chown $TSTUSR:$TSTUSR $parent_dir ||
5590 error "failed to chown on $parent_dir"
5591 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5592 error "failed to chown on $parent_dir"
5594 $LFS project -p 1000 $parent_dir ||
5595 error "failed to set project id on $parent_dir"
5596 $LFS project -p 1001 $child_dir ||
5597 error "failed to set project id on $child_dir"
5599 rmdir $child_dir || error "cannot remove child dir, test failed"
5601 run_test 82 "verify more than 8 qids for single operation"
5603 test_grace_with_default_quota()
5612 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
5613 error "clear default quota [$qdtype] failed"
5615 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
5616 error "reset quota [$qdtype] grace failed"
5619 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5620 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
5623 $LFS setquota $qdtype -B 10G -i 10k $DIR
5626 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5627 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
5629 [ "$bgrace" == "$bgrace2" ] ||
5630 error "set default quota shouldn't affect block grace"
5631 [ "$igrace" == "$igrace2" ] ||
5632 error "set default quota shouldn't affect inode grace"
5638 setup_quota_test || error "setup quota failed with $?"
5639 test_grace_with_default_quota "-u" "-U"
5640 test_grace_with_default_quota "-g" "-G"
5642 is_project_quota_supported || return 0
5643 test_grace_with_default_quota "-p" "-P"
5645 run_test 83 "Setting default quota shouldn't affect grace time"
5649 do_nodes $(comma_list $(nodes_list)) \
5650 "lctl set_param -n debug=-quota-trace"
5651 if $PQ_CLEANUP; then
5652 disable_project_quota
5655 reset_quota_settings
5660 check_and_cleanup_lustre
5661 export QUOTA_AUTO=$QUOTA_AUTO_OLD