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}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 VERSION_WITH_QP="2.13.53"
44 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
45 skip "Needs MDS version $VERSION_WITH_QP or later."
48 require_dsh_mds || exit 0
49 require_dsh_ost || exit 0
51 # Does e2fsprogs support quota feature?
52 if [ "$mds1_FSTYPE" == ldiskfs ] &&
53 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
54 grep -q 'quota'"; then
55 skip_env "e2fsprogs doesn't support quota"
58 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
60 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
65 QUOTA_AUTO_OLD=$QUOTA_AUTO
68 check_and_setup_lustre
70 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
77 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
78 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
79 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
84 local fail_val=${3:-0}
88 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
89 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
90 ost) NODES="$(comma_list $(osts_nodes))";;
93 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
99 lfs project $* || error "lfs project $* failed"
102 RUNAS="runas -u $TSTID -g $TSTID"
103 RUNAS2="runas -u $TSTID2 -g $TSTID2"
104 DD="dd if=/dev/zero bs=1M"
108 # clear quota limits for a user or a group
109 # usage: resetquota -u username
110 # resetquota -g groupname
111 # resetquota -p projid
114 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
115 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
116 error "resetquota: wrong specifier $1 passed"
118 if [ $1 == "-p" ]; then
119 is_project_quota_supported || return 0
122 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
123 error "clear quota for [type:$1 name:$2] failed"
124 # give a chance to slave to release space
132 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
133 $LFS quota -v -u $local_id $DIR
134 log "Files for user ($local_id):"
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 log "Files for group ($local_id):"
142 ($LFS find --group $local_id $DIR | head -n 4 |
143 xargs stat 2>/dev/null)
146 is_project_quota_supported || return 0
147 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
148 $LFS quota -v -p $TSTPRJID $DIR
149 log "Files for project ($TSTPRJID):"
150 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
151 xargs stat 2>/dev/null)
167 # get quota for a user or a group
168 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
169 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
176 sync_all_data > /dev/null 2>&1 || true
178 [ "$#" != 4 -a "$#" != 5 ] &&
179 error "getquota: wrong number of arguments: $#"
180 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
181 error "getquota: wrong u/g/p specifier $1 passed"
194 *) error "unknown quota parameter $4";;
197 [ ! -z "$5" ] && pool_arg="--pool $5 "
198 [ "$uuid" = "global" ] && uuid=$DIR
200 $LFS quota -v "$1" "$2" $pool_arg $DIR |
201 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
202 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
207 # usage: set_mdt_qtype ugp|u|g|p|none
211 local mdts=$(get_facets MDS)
213 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
214 qtype=$(tr -d 'p' <<<$qtype)
216 if [[ $PERM_CMD == *"set_param -P"* ]]; then
217 do_facet mgs $PERM_CMD \
218 osd-*.$FSNAME-MDT*.quota_slave.enabled=$qtype
220 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
222 # we have to make sure each MDT received config changes
223 for mdt in ${mdts//,/ }; do
225 cmd="$LCTL get_param -n "
226 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
227 cmd=${cmd}.quota_slave.enabled
229 if $(facet_up $mdt); then
230 wait_update_facet $mdt "$cmd" "$qtype" || return 1
237 # usage: set_ost_qtype ugp|u|g|p|none
241 local osts=$(get_facets OST)
243 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
244 qtype=$(tr -d 'p' <<<$qtype)
246 if [[ $PERM_CMD == *"set_param -P"* ]]; then
247 do_facet mgs $PERM_CMD \
248 osd-*.$FSNAME-OST*.quota_slave.enabled=$qtype
250 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
252 # we have to make sure each OST received config changes
253 for ost in ${osts//,/ }; do
255 cmd="$LCTL get_param -n "
256 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
257 cmd=${cmd}.quota_slave.enabled
259 if $(facet_up $ost); then
260 wait_update_facet $ost "$cmd" "$qtype" || return 1
266 wait_reintegration() {
270 local result="glb[1],slv[1],reint[0]"
275 if [ $ntype == "mdt" ]; then
276 tgts=$(get_facets MDS)
278 tgts=$(get_facets OST)
281 for tgt in ${tgts//,/ }; do
283 cmd="$LCTL get_param -n "
284 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
285 cmd=${cmd}.quota_slave.info
287 if $(facet_up $tgt); then
288 wait_update_facet $tgt "$cmd |
289 grep "$qtype" | awk '{ print \\\$3 }'" \
290 "$result" $max || return 1
300 if [[ "$qtype" =~ "u" ]]; then
301 wait_reintegration "mdt" "user" $max || return 1
304 if [[ "$qtype" =~ "g" ]]; then
305 wait_reintegration "mdt" "group" $max || return 1
308 if [[ "$qtype" =~ "p" ]]; then
309 ! is_project_quota_supported && return 0
310 wait_reintegration "mdt" "project" $max || return 1
319 if [[ "$qtype" =~ "u" ]]; then
320 wait_reintegration "ost" "user" $max || return 1
323 if [[ "$qtype" =~ "g" ]]; then
324 wait_reintegration "ost" "group" $max || return 1
327 if [[ "$qtype" =~ "p" ]]; then
328 ! is_project_quota_supported && return 0
329 wait_reintegration "ost" "project" $max || return 1
338 local extrasleep=${4:-5}
345 *) error "get_grace_time: Invalid quota type: $qtype"
350 echo "Quota info for $pool:"
351 $LFS quota -$qtype $qarg $parg $DIR
356 time=$(lfs quota -$qtype $qarg $parg $DIR|
357 awk 'NR == 3{ print $5 }')
360 time=$(lfs quota -$qtype $qarg $DIR|
361 awk 'NR == 3{ print $9 }')
364 error "Unknown quota type: $flavour"
368 local sleep_seconds=0
369 local orig_time=$time
371 echo "Grace time is $time"
372 # from lfs.c:__sec2str()
373 # const char spec[] = "smhdw";
374 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
375 [[ $time == *w* ]] && w_time=${time%w*} &&
376 let sleep_seconds+=$((w_time*7*24*60*60));
378 [[ $time == *d* ]] && d_time=${time%d*} &&
379 let sleep_seconds+=$((d_time*24*60*60));
381 [[ $time == *h* ]] && h_time=${time%h*} &&
382 let sleep_seconds+=$((h_time*60*60));
384 [[ $time == *m* ]] && m_time=${time%m*} &&
385 let sleep_seconds+=$((m_time*60));
387 [[ $time == *s* ]] && s_time=${time%s*} &&
388 let sleep_seconds+=$s_time
390 echo "Sleep through grace ..."
391 [ "$orig_time" == "-" ] &&
392 error "Grace timeout was not set or quota not exceeded"
393 if [ "$orig_time" == "none" ]; then
394 echo "...Grace timeout already expired"
396 let sleep_seconds+=$extrasleep
397 echo "...sleep $sleep_seconds seconds"
403 wait_delete_completed
404 echo "Creating test directory"
405 mkdir_on_mdt0 $DIR/$tdir || return 1
406 chmod 0777 $DIR/$tdir || return 2
407 # always clear fail_loc in case of fail_loc isn't cleared
408 # properly when previous test failed
409 lustre_fail mds_ost 0
410 stack_trap cleanup_quota_test EXIT
413 cleanup_quota_test() {
414 echo "Delete files..."
416 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
417 echo "Wait for unlink objects finished..."
418 wait_delete_completed
419 sync_all_data || true
429 $LFS quota -v -$ugp $qid $DIR
431 if [ "$bf" == "a" -o "$bf" == "b" ]; then
432 usage=$(getquota -$ugp $qid global curspace)
433 if [ -z $usage ]; then
434 quota_error $ugp $qid \
435 "Query block quota failed ($ugp:$qid)."
437 [ $usage -ne 0 ] && quota_log $ugp $qid \
438 "Block quota isn't 0 ($ugp:$qid:$usage)."
442 if [ "$bf" == "a" -o "$bf" == "f" ]; then
443 usage=$(getquota -$ugp $qid global curinodes)
444 if [ -z $usage ]; then
445 quota_error $ugp $qid \
446 "Query file quota failed ($ugp:$qid)."
448 [ $usage -ne 0 ] && quota_log $ugp $qid \
449 "File quota isn't 0 ($ugp:$qid:$usage)."
454 project_quota_enabled () {
456 local zfeat="feature@project_quota"
458 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
459 local facet_fstype=${facet:0:3}1_FSTYPE
462 if [ "${!facet_fstype}" = "zfs" ]; then
463 devname=$(zpool_name ${facet})
464 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
465 grep -wq active || rc=1
467 [ ${facet:0:3} == "mds" ] &&
468 devname=$(mdsdevname ${facet:3}) ||
469 devname=$(ostdevname ${facet:3})
470 do_facet ${facet} $DEBUGFS -R features $devname |
471 grep -q project || rc=1
474 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
478 project_quota_enabled || enable_project_quota
480 reset_quota_settings() {
481 resetquota -u $TSTUSR
483 resetquota -g $TSTUSR
485 resetquota -u $TSTUSR2
486 resetquota -u $TSTID2
487 resetquota -g $TSTUSR2
488 resetquota -g $TSTID2
489 resetquota -p $TSTPRJID
494 do_nodes $(comma_list $(nodes_list)) \
495 "$LCTL set_param -n debug=+quota,trace"
500 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
501 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
502 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
503 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
505 test_quota_performance() {
506 local TESTFILE="$DIR/$tdir/$tfile-0"
507 local size=$1 # in MB
508 local stime=$(date +%s)
509 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
510 quota_error u $TSTUSR "write failure"
511 local etime=$(date +%s)
512 delta=$((etime - stime))
513 if [ $delta -gt 0 ]; then
514 rate=$((size * 1024 / delta))
515 if [ "$mds1_FSTYPE" = zfs ]; then
516 # LU-2872 - see LU-2887 for fix
518 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
520 [ $rate -gt 1024 ] ||
521 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
527 # test basic quota performance b=21696
530 [ "$SLOW" = "no" ] && MB=10
532 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
533 [ $free_space -le $((MB * 1024)) ] &&
534 skip "not enough space ${free_space} KB, " \
535 "required $((MB * 1024)) KB"
536 setup_quota_test || error "setup quota failed with $?"
538 set_ost_qtype "none" || error "disable ost quota failed"
539 test_quota_performance $MB
541 set_ost_qtype $QTYPE || error "enable ost quota failed"
542 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
543 error "set quota failed"
544 test_quota_performance $MB
546 run_test 0 "Test basic quota performance"
548 # usage: test_1_check_write tfile user|group|project
549 test_1_check_write() {
553 local short_qtype=${qtype:0:1}
556 $RUNAS $DD of=$testfile count=$((limit/2)) ||
557 quota_error $short_qtype $TSTUSR \
558 "$qtype write failure, but expect success"
559 log "Write out of block quota ..."
560 # this time maybe cache write, ignore it's failure
561 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
562 # flush cache, ensure noquota flag is set on client
564 sync; sync_all_data || true
565 # sync means client wrote all it's cache, but id doesn't
566 # guarantee that slave received new edquot through glimpse.
567 # so wait a little to be sure slave got it.
569 $RUNAS $DD of=$testfile count=1 seek=$limit &&
570 quota_error $short_qtype $TSTUSR \
571 "user write success, but expect EDQUOT"
575 check_write_fallocate() {
579 local short_qtype=${qtype:0:1}
582 log "Write ${count}MiB Using Fallocate"
583 $RUNAS fallocate -l${count}MiB $testfile ||
584 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
587 sync; sync_all_data || true
591 log "Write ${count}MiB Using Fallocate"
592 $RUNAS fallocate -l${count}MiB $testfile &&
593 quota_error $short_qtype $TSTUSR \
594 "Write success, expect EDQUOT" || true
597 # test block hardlimit
600 local testfile="$DIR/$tdir/$tfile-0"
602 setup_quota_test || error "setup quota failed with $?"
605 set_ost_qtype $QTYPE || error "enable ost quota failed"
608 log "User quota (block hardlimit:$limit MB)"
609 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
610 error "set user quota failed"
612 # make sure the system is clean
613 local used=$(getquota -u $TSTUSR global curspace)
614 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
616 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
617 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
619 test_1_check_write $testfile "user" $limit
622 wait_delete_completed || error "wait_delete_completed failed"
623 sync_all_data || true
624 used=$(getquota -u $TSTUSR global curspace)
625 [ $used -ne 0 ] && quota_error u $TSTUSR \
626 "user quota isn't released after deletion"
627 resetquota -u $TSTUSR
630 log "--------------------------------------"
631 log "Group quota (block hardlimit:$limit MB)"
632 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
633 error "set group quota failed"
635 testfile="$DIR/$tdir/$tfile-1"
636 # make sure the system is clean
637 used=$(getquota -g $TSTUSR global curspace)
638 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
640 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
641 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
643 test_1_check_write $testfile "group" $limit
645 wait_delete_completed || error "wait_delete_completed failed"
646 sync_all_data || true
647 used=$(getquota -g $TSTUSR global curspace)
648 [ $used -ne 0 ] && quota_error g $TSTUSR \
649 "Group quota isn't released after deletion"
650 resetquota -g $TSTUSR
652 if ! is_project_quota_supported; then
653 echo "Project quota is not supported"
657 testfile="$DIR/$tdir/$tfile-2"
658 # make sure the system is clean
659 used=$(getquota -p $TSTPRJID global curspace)
661 error "used space($used) for project $TSTPRJID isn't 0"
664 log "--------------------------------------"
665 log "Project quota (block hardlimit:$limit mb)"
666 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
667 error "set project quota failed"
669 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
670 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
671 change_project -p $TSTPRJID $testfile
673 test_1_check_write $testfile "project" $limit
678 used=$(getquota -p $TSTPRJID global curspace)
679 [ $used -ne 0 ] && quota_error p $TSTPRJID \
680 "project quota isn't released after deletion"
682 resetquota -p $TSTPRJID
684 run_test 1a "Block hard limit (normal use and out of quota)"
688 local global_limit=20 # MB
689 local testfile="$DIR/$tdir/$tfile-0"
693 setup_quota_test || error "setup quota failed with $?"
696 set_ost_qtype $QTYPE || error "enable ost quota failed"
699 log "User quota (block hardlimit:$global_limit MB)"
700 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
701 error "set user quota failed"
703 pool_add $qpool || error "pool_add failed"
704 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
705 error "pool_add_targets failed"
707 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
708 error "set user quota failed"
710 # make sure the system is clean
711 local used=$(getquota -u $TSTUSR global curspace)
713 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
715 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
717 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
718 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
720 test_1_check_write $testfile "user" $limit
723 wait_delete_completed || error "wait_delete_completed failed"
724 sync_all_data || true
725 used=$(getquota -u $TSTUSR global curspace $qpool)
726 [ $used -ne 0 ] && quota_error u $TSTUSR \
727 "user quota isn't released after deletion"
728 resetquota -u $TSTUSR
731 log "--------------------------------------"
732 log "Group quota (block hardlimit:$global_limit MB)"
733 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
734 error "set group quota failed"
736 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
737 error "set group quota failed"
739 testfile="$DIR/$tdir/$tfile-1"
740 # make sure the system is clean
741 used=$(getquota -g $TSTUSR global curspace $qpool)
742 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
744 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
745 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
747 test_1_check_write $testfile "group" $limit
750 wait_delete_completed || error "wait_delete_completed failed"
751 sync_all_data || true
752 used=$(getquota -g $TSTUSR global curspace $qpool)
753 [ $used -ne 0 ] && quota_error g $TSTUSR \
754 "Group quota isn't released after deletion"
755 resetquota -g $TSTUSR
757 if ! is_project_quota_supported; then
758 echo "Project quota is not supported"
762 testfile="$DIR/$tdir/$tfile-2"
763 # make sure the system is clean
764 used=$(getquota -p $TSTPRJID global curspace $qpool)
766 error "used space($used) for project $TSTPRJID isn't 0"
769 log "--------------------------------------"
770 log "Project quota (block hardlimit:$global_limit mb)"
771 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
772 error "set project quota failed"
774 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
775 error "set project quota failed"
778 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
779 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
780 change_project -p $TSTPRJID $testfile
782 test_1_check_write $testfile "project" $limit
787 used=$(getquota -p $TSTPRJID global curspace)
788 [ $used -eq 0 ] || quota_error p $TSTPRJID \
789 "project quota isn't released after deletion"
791 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
794 local global_limit=20 # MB
795 local testfile="$DIR/$tdir/$tfile-0"
796 local qpool1="qpool1"
797 local qpool2="qpool2"
800 setup_quota_test || error "setup quota failed with $?"
803 set_ost_qtype $QTYPE || error "enable ost quota failed"
806 log "User quota (block hardlimit:$global_limit MB)"
807 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
808 error "set user quota failed"
810 pool_add $qpool1 || error "pool_add failed"
811 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
812 error "pool_add_targets failed"
814 pool_add $qpool2 || error "pool_add failed"
815 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
816 error "pool_add_targets failed"
818 # create pools without hard limit
819 # initially such case raised several bugs
820 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
821 error "set user quota failed"
823 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
824 error "set user quota failed"
826 # make sure the system is clean
827 local used=$(getquota -u $TSTUSR global curspace)
829 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
831 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
833 test_1_check_write $testfile "user" $global_limit
835 used=$(getquota -u $TSTUSR global curspace $qpool1)
836 echo "qpool1 used $used"
837 used=$(getquota -u $TSTUSR global curspace $qpool2)
838 echo "qpool2 used $used"
841 wait_delete_completed || error "wait_delete_completed failed"
842 sync_all_data || true
844 used=$(getquota -u $TSTUSR global curspace $qpool1)
845 [ $used -eq 0 ] || quota_error u $TSTUSR \
846 "user quota isn't released after deletion"
848 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
853 local global_limit=20 # MB
854 local testfile="$DIR/$tdir/$tfile-0"
855 local qpool1="qpool1"
856 local qpool2="qpool2"
859 setup_quota_test || error "setup quota failed with $?"
862 set_ost_qtype $QTYPE || error "enable ost quota failed"
865 log "User quota (block hardlimit:$global_limit MB)"
866 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
867 error "set user quota failed"
869 pool_add $qpool1 || error "pool_add failed"
870 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
871 error "pool_add_targets failed"
873 pool_add $qpool2 || error "pool_add failed"
874 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
875 error "pool_add_targets failed"
877 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
878 error "set user quota failed"
880 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
881 error "set user quota failed"
883 # make sure the system is clean
884 local used=$(getquota -u $TSTUSR global curspace)
886 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
888 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
890 test_1_check_write $testfile "user" $limit1
892 used=$(getquota -u $TSTUSR global curspace $qpool1)
893 echo "qpool1 used $used"
894 used=$(getquota -u $TSTUSR global curspace $qpool2)
895 echo "qpool2 used $used"
898 wait_delete_completed || error "wait_delete_completed failed"
899 sync_all_data || true
901 used=$(getquota -u $TSTUSR global curspace $qpool1)
902 [ $used -eq 0 ] || quota_error u $TSTUSR \
903 "user quota isn't released after deletion"
905 run_test 1d "Quota pools: check block hardlimit on different pools"
909 local global_limit=53000000 # MB
910 local testfile="$DIR/$tdir/$tfile-0"
911 local testfile2="$DIR/$tdir/$tfile-1"
912 local qpool1="qpool1"
915 setup_quota_test || error "setup quota failed with $?"
918 set_ost_qtype $QTYPE || error "enable ost quota failed"
920 # global_limit is much greater than limit1 to get
921 # different qunit's on osts. Since 1st qunit shrinking
922 # on OST1(that belongs to qpool1), this qunit should
924 log "User quota (block hardlimit:$global_limit MB)"
925 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
926 error "set user quota failed"
928 pool_add $qpool1 || error "pool_add failed"
929 pool_add_targets $qpool1 1 1 ||
930 error "pool_add_targets failed"
932 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
933 error "set user quota failed"
935 # make sure the system is clean
936 local used=$(getquota -u $TSTUSR global curspace)
937 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
939 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
940 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
942 test_1_check_write $testfile "user" $limit1
944 $LFS setstripe $testfile2 -c 1 -i 0 ||
945 error "setstripe $testfile2 failed"
946 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
947 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
949 $RUNAS $DD of=$testfile2 count=20 ||
950 quota_error u $TSTUSR \
951 "$qtype write failure, but expect success"
955 wait_delete_completed || error "wait_delete_completed failed"
956 sync_all_data || true
958 used=$(getquota -u $TSTUSR global curspace $qpool1)
959 [ $used -eq 0 ] || quota_error u $TSTUSR \
960 "user quota isn't released after deletion"
962 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
965 local global_limit=200 # MB
967 local TESTDIR="$DIR/$tdir/"
968 local testfile="$TESTDIR/$tfile-0"
969 local qpool1="qpool1"
972 setup_quota_test || error "setup quota failed with $?"
975 set_ost_qtype $QTYPE || error "enable ost quota failed"
977 log "User quota (block hardlimit:$global_limit MB)"
978 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
979 error "set user quota failed"
981 pool_add $qpool1 || error "pool_add failed"
982 pool_add_targets $qpool1 0 0 ||
983 error "pool_add_targets failed"
985 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
986 error "set user quota failed"
988 # make sure the system is clean
989 local used=$(getquota -u $TSTUSR global curspace)
990 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
992 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
994 test_1_check_write $testfile "user" $limit1
996 pool_remove_target $qpool1 0
998 wait_delete_completed || error "wait_delete_completed failed"
999 sync_all_data || true
1001 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1002 # qunit for appropriate element in lgd array should be set
1003 # correctly(4096). Earlier it was not changed continuing to be 1024.
1004 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1005 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1006 # as it already was 1024. As flag "need_update" for this qunit was
1007 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1008 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1009 # became > 10M. QMT returned EINPROGRESS in a loop.
1010 # Check that it doesn't hung anymore.
1011 test_1_check_write $testfile "user" $limit1
1013 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1017 local global_limit=40 # MB
1018 local testfile="$DIR/$tdir/$tfile-0"
1019 local qpool="qpool1"
1020 local mdmb_param="osc.*.max_dirty_mb"
1021 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1024 setup_quota_test || error "setup quota failed with $?"
1025 $LCTL set_param $mdmb_param=1
1026 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1029 set_ost_qtype $QTYPE || error "enable ost quota failed"
1032 log "User quota (block hardlimit:$global_limit MB)"
1033 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1034 error "set user quota failed"
1036 pool_add $qpool || error "pool_add failed"
1037 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1038 error "pool_add_targets failed"
1040 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1041 error "set user quota failed"
1043 # make sure the system is clean
1044 local used=$(getquota -u $TSTUSR global curspace)
1046 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1048 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1049 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1052 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1053 quota_error u $TSTUSR \
1054 "$qtype write failure, but expect success"
1055 log "Write out of block quota ..."
1056 # this time maybe cache write, ignore it's failure
1057 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1058 # flush cache, ensure noquota flag is set on client
1059 cancel_lru_locks osc
1060 sync; sync_all_data || true
1062 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1063 quota_error u $TSTUSR \
1064 "user write success, but expect EDQUOT"
1067 wait_delete_completed || error "wait_delete_completed failed"
1068 sync_all_data || true
1070 used=$(getquota -u $TSTUSR global curspace $qpool)
1071 [ $used -ne 0 ] && quota_error u $TSTUSR \
1072 "user quota isn't released after deletion"
1075 run_test 1g "Quota pools: Block hard limit with wide striping"
1079 local testfile="$DIR/$tdir/$tfile-0"
1081 check_set_fallocate_or_skip
1083 setup_quota_test || error "setup quota failed with $?"
1086 set_ost_qtype $QTYPE || error "enable ost quota failed"
1089 log "User quota (block hardlimit:$limit MB)"
1090 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1091 error "set user quota failed"
1093 # make sure the system is clean
1094 local used=$(getquota -u $TSTUSR global curspace)
1095 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1097 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1098 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1100 check_write_fallocate $testfile "user" $limit
1103 wait_delete_completed || error "wait_delete_completed failed"
1104 sync_all_data || true
1105 used=$(getquota -u $TSTUSR global curspace)
1106 [ $used -eq 0 ] || quota_error u $TSTUSR \
1107 "user quota isn't released after deletion"
1109 run_test 1h "Block hard limit test using fallocate"
1112 local global_limit=200 # 200M
1113 local limit1=10 # 10M
1114 local TESTDIR="$DIR/$tdir/"
1115 local testfile="$TESTDIR/$tfile-0"
1116 local testfile1="$TESTDIR/$tfile-1"
1117 local testfile2="$TESTDIR/$tfile-2"
1118 local qpool1="qpool1"
1121 setup_quota_test || error "setup quota failed with $?"
1122 stack_trap cleanup_quota_test EXIT
1125 set_ost_qtype $QTYPE || error "enable ost quota failed"
1127 log "User quota (block hardlimit:$global_limit MB)"
1128 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1129 error "set user quota failed"
1131 pool_add $qpool1 || error "pool_add failed"
1132 pool_add_targets $qpool1 0 0 ||
1133 error "pool_add_targets failed"
1135 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1136 error "set user quota failed"
1138 # make sure the system is clean
1139 local used=$(getquota -u $TSTUSR global curspace)
1140 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1142 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1145 test_1_check_write $testfile "user" $limit1
1146 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1147 error "set user quota failed"
1149 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1150 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1151 quota_error u $TSTUSR "write failure, but expect success"
1155 wait_delete_completed || error "wait_delete_completed failed"
1156 sync_all_data || true
1158 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1159 error "set user quota failed"
1160 test_1_check_write $testfile "user" $limit1
1161 local tmp_limit=$(($limit1*2))
1162 # increase pool limit
1163 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1164 error "set user quota failed"
1165 # now write shouldn't fail
1166 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1167 quota_error u $TSTUSR "write failure, but expect success"
1168 # decrease pool limit
1169 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1170 error "set user quota failed"
1171 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1172 # flush cache, ensure noquota flag is set on client
1173 cancel_lru_locks osc
1174 sync; sync_all_data || true
1175 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1176 quota_error u $TSTUSR "write success, but expect failure"
1179 run_test 1i "Quota pools: different limit and usage relations"
1181 # test inode hardlimit
1183 local testfile="$DIR/$tdir/$tfile-0"
1184 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1185 qmt.$FSNAME-QMT0000.md-0x0.info |
1186 awk '/least qunit/{ print $3 }')
1189 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1190 limit=$((least_qunit * 1024))
1192 local free_inodes=$(mdt_free_inodes 0)
1193 echo "$free_inodes free inodes on master MDT"
1194 [ $free_inodes -lt $limit ] &&
1195 skip "not enough free inodes $free_inodes required $limit"
1197 setup_quota_test || error "setup quota failed with $?"
1200 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1203 log "User quota (inode hardlimit:$limit files)"
1204 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1205 error "set user quota failed"
1207 # make sure the system is clean
1208 local used=$(getquota -u $TSTUSR global curinodes)
1209 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1211 log "Create $((limit - least_qunit)) files ..."
1212 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1213 quota_error u $TSTUSR "user create failure, but expect success"
1214 # it is ok, if it fails on the last qunit
1215 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1216 log "Create out of file quota ..."
1217 $RUNAS touch ${testfile}_xxx &&
1218 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1221 unlinkmany ${testfile} $((limit - least_qunit)) ||
1222 error "unlinkmany $testfile failed"
1223 # if 2nd createmany got EDQUOT, not all of nodes would be created
1224 unlinkmany ${testfile}_yyy $least_qunit || true
1225 rm -f ${testfile}_xxx
1226 wait_delete_completed
1228 used=$(getquota -u $TSTUSR global curinodes)
1229 [ $used -ne 0 ] && quota_error u $TSTUSR \
1230 "user quota isn't released after deletion"
1231 resetquota -u $TSTUSR
1234 log "--------------------------------------"
1235 log "Group quota (inode hardlimit:$limit files)"
1236 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1237 error "set group quota failed"
1239 testfile=$DIR/$tdir/$tfile-1
1240 # make sure the system is clean
1241 used=$(getquota -g $TSTUSR global curinodes)
1242 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1244 log "Create $limit files ..."
1245 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1246 quota_error g $TSTUSR "group create failure, but expect success"
1247 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1248 log "Create out of file quota ..."
1249 $RUNAS touch ${testfile}_xxx &&
1250 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1253 unlinkmany ${testfile} $((limit - least_qunit)) ||
1254 error "unlinkmany $testfile failed"
1255 unlinkmany ${testfile}_yyy $least_qunit || true
1256 rm -f ${testfile}_xxx
1257 wait_delete_completed
1259 used=$(getquota -g $TSTUSR global curinodes)
1260 [ $used -ne 0 ] && quota_error g $TSTUSR \
1261 "user quota isn't released after deletion"
1263 resetquota -g $TSTUSR
1264 ! is_project_quota_supported &&
1265 echo "Skip project quota is not supported" && return 0
1268 log "--------------------------------------"
1269 log "Project quota (inode hardlimit:$limit files)"
1270 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1271 error "set project quota failed"
1273 testfile=$DIR/$tdir/$tfile-1
1274 # make sure the system is clean
1275 used=$(getquota -p $TSTPRJID global curinodes)
1277 error "Used inodes($used) for project $TSTPRJID isn't 0"
1279 change_project -sp $TSTPRJID $DIR/$tdir
1280 log "Create $limit files ..."
1281 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1282 quota_error p $TSTPRJID \
1283 "project create fail, but expect success"
1284 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1285 log "Create out of file quota ..."
1286 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1287 "project create success, but expect EDQUOT"
1288 change_project -C $DIR/$tdir
1291 used=$(getquota -p $TSTPRJID global curinodes)
1292 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1293 "project quota isn't released after deletion"
1296 run_test 2 "File hard limit (normal use and out of quota)"
1305 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1306 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1310 $LFS setstripe $testfile -c 1 -i 0
1311 chown $TSTUSR.$TSTUSR $testfile
1312 [ "$qtype" == "p" ] && is_project_quota_supported &&
1313 change_project -p $TSTPRJID $testfile
1315 echo "Write up to soft limit"
1316 $RUNAS $DD of=$testfile count=$limit ||
1317 quota_error a $TSTUSR "write failure, but expect success"
1318 OFFSET=$((limit * 1024))
1319 cancel_lru_locks osc
1321 echo "Write to exceed soft limit"
1322 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1323 quota_error a $TSTUSR "write failure, but expect success"
1324 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1325 cancel_lru_locks osc
1327 echo "mmap write when over soft limit"
1328 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1329 quota_error a $TSTUSR "mmap write failure, but expect success"
1330 cancel_lru_locks osc
1335 $SHOW_QUOTA_INFO_USER
1336 $SHOW_QUOTA_INFO_GROUP
1337 $SHOW_QUOTA_INFO_PROJID
1339 echo "Write before timer goes off"
1340 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1341 quota_error a $TSTUSR "write failure, but expect success"
1342 OFFSET=$((OFFSET + 1024))
1343 cancel_lru_locks osc
1345 wait_grace_time $qtype "block" $pool
1350 $SHOW_QUOTA_INFO_USER
1351 $SHOW_QUOTA_INFO_GROUP
1352 $SHOW_QUOTA_INFO_PROJID
1354 log "Write after timer goes off"
1355 # maybe cache write, ignore.
1356 # write up to soft least quint to consume all
1357 # possible slave granted space.
1358 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1359 count=$soft_limit seek=$OFFSET || true
1360 OFFSET=$((OFFSET + soft_limit))
1361 cancel_lru_locks osc
1362 log "Write after cancel lru locks"
1363 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1364 quota_error a $TSTUSR "write success, but expect EDQUOT"
1369 $SHOW_QUOTA_INFO_USER
1370 $SHOW_QUOTA_INFO_GROUP
1371 $SHOW_QUOTA_INFO_PROJID
1373 echo "Unlink file to stop timer"
1375 wait_delete_completed
1376 sync_all_data || true
1381 $SHOW_QUOTA_INFO_USER
1382 $SHOW_QUOTA_INFO_GROUP
1383 $SHOW_QUOTA_INFO_PROJID
1385 $LFS setstripe $testfile -c 1 -i 0
1386 chown $TSTUSR.$TSTUSR $testfile
1387 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1390 $RUNAS $DD of=$testfile count=$limit ||
1391 quota_error a $TSTUSR "write failure, but expect success"
1398 local grace=20 # seconds
1399 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1402 local testfile=$DIR/$tdir/$tfile-0
1404 # get minimum soft qunit size
1405 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1406 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1408 set_ost_qtype $QTYPE || error "enable ost quota failed"
1410 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1411 # make sure the system is clean
1412 local used=$(getquota -u $TSTUSR global curspace)
1413 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1415 $LFS setquota -t -u --block-grace $grace --inode-grace \
1416 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1417 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1418 error "set user quota failed"
1420 test_block_soft $testfile $grace $limit "u"
1422 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1423 testfile=$DIR/$tdir/$tfile-1
1424 # make sure the system is clean
1425 used=$(getquota -g $TSTUSR global curspace)
1426 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1428 $LFS setquota -t -g --block-grace $grace --inode-grace \
1429 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1430 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1431 error "set group quota failed"
1433 test_block_soft $testfile $grace $limit "g"
1435 if is_project_quota_supported; then
1436 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1437 testfile=$DIR/$tdir/$tfile-2
1438 # make sure the system is clean
1439 used=$(getquota -p $TSTPRJID global curspace)
1440 [ $used -ne 0 ] && error \
1441 "Used space($used) for project $TSTPRJID isn't 0."
1443 $LFS setquota -t -p --block-grace $grace --inode-grace \
1444 $MAX_IQ_TIME $DIR ||
1445 error "set project grace time failed"
1446 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1447 $DIR || error "set project quota failed"
1449 test_block_soft $testfile $grace $limit "p"
1450 resetquota -p $TSTPRJID
1451 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1452 $MAX_IQ_TIME $DIR ||
1453 error "restore project grace time failed"
1457 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1458 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1459 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1460 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1462 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1465 local grace=20 # seconds
1466 local qpool="qpool1"
1467 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1470 local testfile=$DIR/$tdir/$tfile-0
1473 # get minimum soft qunit size
1474 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1475 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1476 local glbl_limit=$((2*limit))
1477 local glbl_grace=$((2*grace))
1478 echo "limit $limit glbl_limit $glbl_limit"
1479 echo "grace $grace glbl_grace $glbl_grace"
1481 set_ost_qtype $QTYPE || error "enable ost quota failed"
1483 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1484 # make sure the system is clean
1485 local used=$(getquota -u $TSTUSR global curspace)
1486 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1488 pool_add $qpool || error "pool_add failed"
1489 pool_add_targets $qpool 0 1 ||
1490 error "pool_add_targets failed"
1492 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1493 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1494 $LFS setquota -t -u --block-grace $grace \
1495 --pool $qpool $DIR || error "set user grace time failed"
1497 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1498 error "set user quota failed"
1499 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1500 error "set user quota failed"
1502 test_block_soft $testfile $grace $limit "u" $qpool
1504 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1505 testfile=$DIR/$tdir/$tfile-1
1506 # make sure the system is clean
1507 used=$(getquota -g $TSTUSR global curspace)
1508 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1510 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1511 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1512 $LFS setquota -t -g --block-grace $grace \
1513 --pool $qpool $DIR || error "set group grace time failed"
1515 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1516 error "set group quota failed"
1517 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1518 error "set group quota failed"
1520 test_block_soft $testfile $grace $limit "g" $qpool
1522 if is_project_quota_supported; then
1523 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1524 testfile=$DIR/$tdir/$tfile-2
1525 # make sure the system is clean
1526 used=$(getquota -p $TSTPRJID global curspace)
1527 [ $used -ne 0 ] && error \
1528 "Used space($used) for project $TSTPRJID isn't 0."
1530 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1531 $MAX_IQ_TIME $DIR ||
1532 error "set project grace time failed"
1533 $LFS setquota -t -p --block-grace $grace \
1534 --pool $qpool $DIR ||
1535 error "set project grace time failed"
1537 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1538 $DIR || error "set project quota failed"
1539 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1540 --pool $qpool $DIR || error "set project quota failed"
1542 test_block_soft $testfile $grace $limit "p" $qpool
1543 resetquota -p $TSTPRJID
1544 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1545 $MAX_IQ_TIME $DIR ||
1546 error "restore project grace time failed"
1547 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1548 $DIR || error "set project grace time failed"
1552 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1553 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1554 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1555 --pool $qpool $DIR || error "restore user grace time failed"
1556 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1557 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1558 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1559 --pool $qpool $DIR || error "restore group grace time failed"
1561 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1564 local grace=20 # seconds
1565 local qpool="qpool1"
1566 local qpool2="qpool2"
1567 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1570 local testfile=$DIR/$tdir/$tfile-0
1573 # get minimum soft qunit size
1574 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1575 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1576 local limit2=$((limit+4))
1577 local glbl_limit=$((limit+8))
1578 local grace1=$((grace+10))
1580 local glbl_grace=$((grace+20))
1581 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1582 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1584 set_ost_qtype $QTYPE || error "enable ost quota failed"
1586 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1587 # make sure the system is clean
1588 local used=$(getquota -u $TSTUSR global curspace)
1589 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1591 pool_add $qpool || error "pool_add failed"
1592 pool_add_targets $qpool 0 1 ||
1593 error "pool_add_targets failed"
1595 pool_add $qpool2 || error "pool_add failed"
1596 pool_add_targets $qpool2 0 1 ||
1597 error "pool_add_targets failed"
1600 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1601 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1602 $LFS setquota -t -u --block-grace $grace1 \
1603 --pool $qpool $DIR || error "set user grace time failed"
1604 $LFS setquota -t -u --block-grace $grace2 \
1605 --pool $qpool2 $DIR || error "set user grace time failed"
1607 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1608 error "set user quota failed"
1609 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1610 error "set user quota failed"
1611 # qpool has minimum soft limit, but its grace is greater than
1612 # the grace period of qpool2. Thus write shouldn't fail when
1613 # hit qpool soft limit - only when reaches up qpool2 limit
1614 # after grace2 seconds.
1615 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1616 error "set user quota failed"
1618 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1621 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1622 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1623 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1624 --pool $qpool $DIR || error "restore user grace time failed"
1625 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1626 --pool $qpool2 $DIR || error "restore user grace time failed"
1628 run_test 3c "Quota pools: check block soft limit on different pools"
1635 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1636 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1639 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1641 echo "Create files to exceed soft limit"
1642 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1643 quota_error a $TSTUSR "create failure, but expect success"
1644 local trigger_time=$(date +%s)
1646 sync_all_data || true
1648 local cur_time=$(date +%s)
1649 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1650 error "Passed grace time $grace, $trigger_time, $cur_time"
1652 echo "Create file before timer goes off"
1653 $RUNAS touch ${TESTFILE}_before ||
1654 quota_error a $TSTUSR "failed create before timer expired," \
1655 "but expect success. $trigger_time, $cur_time"
1656 sync_all_data || true
1658 wait_grace_time $qtype "file"
1663 $SHOW_QUOTA_INFO_USER
1664 $SHOW_QUOTA_INFO_GROUP
1665 $SHOW_QUOTA_INFO_PROJID
1667 echo "Create file after timer goes off"
1668 # exceed least soft limit is possible
1669 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1670 quota_error a $TSTUSR "create after timer expired," \
1672 sync_all_data || true
1677 $SHOW_QUOTA_INFO_USER
1678 $SHOW_QUOTA_INFO_GROUP
1679 $SHOW_QUOTA_INFO_PROJID
1681 echo "Unlink files to stop timer"
1682 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1683 wait_delete_completed
1686 $RUNAS touch ${TESTFILE}_xxx ||
1687 quota_error a $TSTUSR "touch after timer stop failure," \
1688 "but expect success"
1689 sync_all_data || true
1697 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1698 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1699 local TESTFILE=$DIR/$tdir/$tfile-0
1702 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1704 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1705 # make sure the system is clean
1706 local USED=$(getquota -u $TSTUSR global curinodes)
1707 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1709 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1710 $GRACE $DIR || error "set user grace time failed"
1711 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1712 error "set user quota failed"
1714 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1716 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1718 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1719 # make sure the system is clean
1720 USED=$(getquota -g $TSTUSR global curinodes)
1721 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1723 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1724 $GRACE $DIR || error "set group grace time failed"
1725 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1726 error "set group quota failed"
1727 TESTFILE=$DIR/$tdir/$tfile-1
1729 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1731 if is_project_quota_supported; then
1732 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1733 # make sure the system is clean
1734 USED=$(getquota -p $TSTPRJID global curinodes)
1735 [ $USED -ne 0 ] && error \
1736 "Used space($USED) for project $TSTPRJID isn't 0."
1738 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1739 $GRACE $DIR || error "set project grace time failed"
1740 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1741 error "set project quota failed"
1743 TESTFILE=$DIR/$tdir/$tfile-1
1744 # one less than limit, because of parent directory included.
1745 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1746 resetquota -p $TSTPRJID
1747 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1748 $MAX_IQ_TIME $DIR ||
1749 error "restore project grace time failed"
1753 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1754 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1755 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1756 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1758 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1761 local GR_STR1="1w3d"
1762 local GR_STR2="1000s"
1764 local GR_STR4="1w2d3h4m5s"
1766 local GR_STR6="18446744073709551615"
1769 wait_delete_completed
1771 # test of valid grace strings handling
1772 echo "Valid grace strings test"
1773 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1774 $GR_STR2 $DIR || error "set user grace time failed"
1775 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1776 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1777 $GR_STR4 $DIR || error "set group grace time quota failed"
1778 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1780 # test of invalid grace strings handling
1781 echo " Invalid grace strings test"
1782 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1783 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1784 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1788 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1789 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1790 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1791 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1793 run_test 4b "Grace time strings handling"
1795 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1797 local BLIMIT=10 # MB
1798 local ILIMIT=10 # inodes
1800 setup_quota_test || error "setup quota failed with $?"
1802 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1803 set_ost_qtype $QTYPE || error "enable ost quota failed"
1805 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1806 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1807 error "set user quota failed"
1808 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1809 if is_project_quota_supported; then
1810 error "set group quota failed"
1811 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1812 -I $ILIMIT $DIR || error "set project quota failed"
1815 # make sure the system is clean
1816 local USED=$(getquota -u $TSTUSR global curinodes)
1817 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1818 USED=$(getquota -g $TSTUSR global curinodes)
1819 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1820 USED=$(getquota -u $TSTUSR global curspace)
1821 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1822 USED=$(getquota -g $TSTUSR global curspace)
1823 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1824 if is_project_quota_supported; then
1825 USED=$(getquota -p $TSTPRJID global curinodes)
1827 error "Used inode($USED) for project $TSTPRJID isn't 0."
1828 USED=$(getquota -p $TSTPRJID global curspace)
1830 error "Used block($USED) for project $TSTPRJID isn't 0."
1833 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1834 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1835 error "create failure, expect success"
1836 if is_project_quota_supported; then
1837 touch $DIR/$tdir/$tfile-0_1
1838 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1840 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1841 error "write failure, expect success"
1843 echo "Chown files to $TSTUSR.$TSTUSR ..."
1844 for i in $(seq 0 $ILIMIT); do
1845 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1846 quota_error a $TSTUSR "chown failure, expect success"
1850 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1851 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1853 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1855 # test dropping acquire request on master
1859 # Clear dmesg so watchdog is not triggered by previous
1861 do_facet ost1 dmesg -c > /dev/null
1863 setup_quota_test || error "setup quota failed with $?"
1865 # make sure the system is clean
1866 local USED=$(getquota -u $TSTUSR global curspace)
1867 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1869 # make sure no granted quota on ost
1870 set_ost_qtype $QTYPE || error "enable ost quota failed"
1871 resetquota -u $TSTUSR
1873 # create file for $TSTUSR
1874 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1875 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1876 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1878 # create file for $TSTUSR2
1879 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1880 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1881 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1883 # cache per-ID lock for $TSTUSR on slave
1884 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1885 error "set quota failed"
1886 $RUNAS $DD of=$TESTFILE count=1 ||
1887 error "write $TESTFILE failure, expect success"
1888 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1889 error "write $TESTFILE2 failure, expect success"
1891 if at_is_enabled; then
1892 at_max_saved=$(at_max_get ost1)
1893 at_max_set $TIMEOUT ost1
1895 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1896 # DQACQ is sent, which makes at_max to take effect
1897 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1900 wait_delete_completed
1904 sync_all_data || true
1906 #define QUOTA_DQACQ 601
1907 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1908 lustre_fail mds 0x513 601
1910 do_facet ost1 $LCTL set_param \
1911 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1913 # write to un-enforced ID ($TSTUSR2) should succeed
1914 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1915 error "write failure, expect success"
1917 # write to enforced ID ($TSTUSR) in background, exceeding limit
1918 # to make sure DQACQ is sent
1919 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1922 # watchdog timer uses a factor of 2
1923 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1924 sleep $((TIMEOUT * 2 + 1))
1926 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1928 # write should be blocked and never finished
1929 if ! ps -p $DDPID > /dev/null 2>&1; then
1931 error "write finished incorrectly!"
1936 # no watchdog is triggered
1937 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1938 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1939 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1940 [ -z "$watchdog" ] || error "$watchdog"
1942 rm -f $TMP/lustre-log-${TESTNAME}.log
1944 # write should continue then fail with EDQUOT
1948 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1949 if [ $count -ge 240 ]; then
1950 quota_error u $TSTUSR "dd not finished in $count secs"
1952 count=$((count + 1))
1953 if [ $((count % 30)) -eq 0 ]; then
1954 c_size=$(stat -c %s $TESTFILE)
1955 echo "Waiting $count secs. $c_size"
1961 run_test 6 "Test dropping acquire request on master"
1963 # quota reintegration (global index)
1965 local TESTFILE=$DIR/$tdir/$tfile
1968 [ "$SLOW" = "no" ] && LIMIT=5
1970 setup_quota_test || error "setup quota failed with $?"
1972 # make sure the system is clean
1973 local USED=$(getquota -u $TSTUSR global curspace)
1974 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1976 # make sure no granted quota on ost1
1977 set_ost_qtype $QTYPE || error "enable ost quota failed"
1978 resetquota -u $TSTUSR
1979 set_ost_qtype "none" || error "disable ost quota failed"
1981 local OSTUUID=$(ostuuid_from_index 0)
1982 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1984 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1987 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1988 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1993 echo "Enable quota & set quota limit for $TSTUSR"
1994 set_ost_qtype $QTYPE || error "enable ost quota failed"
1995 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1996 error "set quota failed"
1998 echo "Start ost1..."
1999 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2002 wait_ost_reint $QTYPE || error "reintegration failed"
2004 # hardlimit should have been fetched by slave during global
2005 # reintegration, write will exceed quota
2006 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2007 quota_error u $TSTUSR "write success, but expect EDQUOT"
2010 wait_delete_completed
2011 sync_all_data || true
2017 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2018 error "clear quota failed"
2020 echo "Start ost1..."
2021 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2024 wait_ost_reint $QTYPE || error "reintegration failed"
2026 # hardlimit should be cleared on slave during reintegration
2027 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2028 quota_error u $TSTUSR "write error, but expect success"
2030 run_test 7a "Quota reintegration (global index)"
2032 # quota reintegration (slave index)
2034 local limit=100000 # MB
2035 local TESTFILE=$DIR/$tdir/$tfile
2037 setup_quota_test || error "setup quota failed with $?"
2039 # make sure the system is clean
2040 local USED=$(getquota -u $TSTUSR global curspace)
2041 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2043 # make sure no granted quota on ost1
2044 set_ost_qtype $QTYPE || error "enable ost quota failed"
2045 resetquota -u $TSTUSR
2046 set_ost_qtype "none" || error "disable ost quota failed"
2048 local OSTUUID=$(ostuuid_from_index 0)
2049 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2051 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2054 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2055 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2057 # consume some space to make sure the granted space will not
2058 # be released during reconciliation
2059 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2060 error "consume space failure, expect success"
2062 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2063 lustre_fail mds 0xa02
2065 set_ost_qtype $QTYPE || error "enable ost quota failed"
2066 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2067 error "set quota failed"
2069 # ignore the write error
2070 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2072 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2076 echo "Restart ost to trigger reintegration..."
2078 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2081 wait_ost_reint $QTYPE || error "reintegration failed"
2083 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2084 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2089 run_test 7b "Quota reintegration (slave index)"
2091 # quota reintegration (restart mds during reintegration)
2094 local TESTFILE=$DIR/$tdir/$tfile
2096 [ "$SLOW" = "no" ] && LIMIT=5
2098 setup_quota_test || error "setup quota failed with $?"
2100 # make sure the system is clean
2101 local USED=$(getquota -u $TSTUSR global curspace)
2102 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2104 set_ost_qtype "none" || error "disable ost quota failed"
2105 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2106 error "set quota failed"
2108 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2109 lustre_fail ost 0xa03
2112 set_ost_qtype $QTYPE || error "enable ost quota failed"
2113 # trigger reintegration
2114 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2115 procf=${procf}quota_slave.force_reint
2116 do_facet ost1 $LCTL set_param $procf=1 ||
2117 error "force reintegration failed"
2125 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2128 # wait longer than usual to make sure the reintegration
2129 # is triggered by quota wb thread.
2130 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2132 # hardlimit should have been fetched by slave during global
2133 # reintegration, write will exceed quota
2134 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2135 quota_error u $TSTUSR "write success, but expect EDQUOT"
2138 run_test 7c "Quota reintegration (restart mds during reintegration)"
2140 # Quota reintegration (Transfer index in multiple bulks)
2142 local TESTFILE=$DIR/$tdir/$tfile
2143 local TESTFILE1="$DIR/$tdir/$tfile"-1
2146 setup_quota_test || error "setup quota failed with $?"
2148 set_ost_qtype "none" || error "disable ost quota failed"
2149 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2150 error "set quota for $TSTUSR failed"
2151 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2152 error "set quota for $TSTUSR2 failed"
2154 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2155 lustre_fail mds 0x608 0
2157 # enable quota to tirgger reintegration
2158 set_ost_qtype "u" || error "enable ost quota failed"
2159 wait_ost_reint "u" || error "reintegration failed"
2163 # hardlimit should have been fetched by slave during global
2164 # reintegration, write will exceed quota
2165 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2166 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2168 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2169 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2172 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2174 # quota reintegration (inode limits)
2176 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2178 # LU-2435: skip this quota test if underlying zfs version has not
2179 # supported native dnode accounting
2180 [ "$mds1_FSTYPE" == zfs ] && {
2181 local F="feature@userobj_accounting"
2182 local pool=$(zpool_name mds1)
2183 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2185 [[ "$feature" != *" active "* ]] &&
2186 skip "requires zpool with active userobj_accounting"
2189 local ilimit=$((1024 * 2)) # inodes
2190 local TESTFILE=$DIR/${tdir}-1/$tfile
2192 setup_quota_test || error "setup quota failed with $?"
2194 # make sure the system is clean
2195 local USED=$(getquota -u $TSTUSR global curinodes)
2196 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2198 # make sure no granted quota on mdt1
2199 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2200 resetquota -u $TSTUSR
2201 set_mdt_qtype "none" || error "disable mdt quota failed"
2203 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2204 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2205 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2208 echo "Stop mds${MDSCOUNT}..."
2211 echo "Enable quota & set quota limit for $TSTUSR"
2212 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2213 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2214 error "set quota failed"
2216 echo "Start mds${MDSCOUNT}..."
2217 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2220 wait_mdt_reint $QTYPE || error "reintegration failed"
2222 echo "create remote dir"
2223 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2224 error "create remote dir failed"
2225 chmod 0777 $DIR/${tdir}-1
2227 # hardlimit should have been fetched by slave during global
2228 # reintegration, create will exceed quota
2229 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2230 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2232 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2233 wait_delete_completed
2234 sync_all_data || true
2236 echo "Stop mds${MDSCOUNT}..."
2239 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2240 error "clear quota failed"
2242 echo "Start mds${MDSCOUNT}..."
2243 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2246 wait_mdt_reint $QTYPE || error "reintegration failed"
2248 # hardlimit should be cleared on slave during reintegration
2249 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2250 quota_error u $TSTUSR "create failed, expect success"
2252 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2253 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2255 run_test 7e "Quota reintegration (inode limits)"
2257 # run dbench with quota enabled
2259 local BLK_LIMIT="100g" #100G
2260 local FILE_LIMIT=1000000
2262 setup_quota_test || error "setup quota failed with $?"
2264 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2265 set_ost_qtype $QTYPE || error "enable ost quota failed"
2267 echo "Set enough high limit for user: $TSTUSR"
2268 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2269 error "set user quota failed"
2270 echo "Set enough high limit for group: $TSTUSR"
2271 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2272 error "set group quota failed"
2273 if is_project_quota_supported; then
2274 change_project -sp $TSTPRJID $DIR/$tdir
2275 echo "Set enough high limit for project: $TSTPRJID"
2276 $LFS setquota -p $TSTPRJID -b 0 \
2277 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2278 error "set project quota failed"
2282 [ "$SLOW" = "no" ] && duration=" -t 120"
2283 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2284 quota_error a $TSTUSR "dbench failed!"
2286 is_project_quota_supported && change_project -C $DIR/$tdir
2288 run_test 8 "Run dbench with quota enabled"
2290 # this check is just for test_9
2291 OST0_MIN=4900000 #4.67G
2293 check_whether_skip () {
2294 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2295 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2296 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2297 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2304 # run for fixing bug10707, it needs a big room. test for 64bit
2306 local filesize=$((1024 * 9 / 2)) # 4.5G
2308 check_whether_skip && return 0
2310 setup_quota_test || error "setup quota failed with $?"
2312 set_ost_qtype "ug" || error "enable ost quota failed"
2314 local TESTFILE="$DIR/$tdir/$tfile-0"
2315 local BLK_LIMIT=100G #100G
2316 local FILE_LIMIT=1000000
2318 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2320 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2322 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2323 error "set user quota failed"
2325 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2326 "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"
2330 quota_show_check a u $TSTUSR
2331 quota_show_check a g $TSTUSR
2333 echo "Create test file"
2334 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2335 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2337 log "Write the big file of 4.5G ..."
2338 $RUNAS $DD of=$TESTFILE count=$filesize ||
2339 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2349 run_test 9 "Block limit larger than 4GB (b10707)"
2352 local TESTFILE=$DIR/$tdir/$tfile
2354 setup_quota_test || error "setup quota failed with $?"
2356 # set limit to root user should fail
2357 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2358 error "set limit for root user successfully, expect failure"
2359 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2360 error "set limit for root group successfully, expect failure"
2361 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2362 error "set limit for project 0 successfully, expect failure"
2364 # root user can overrun quota
2365 set_ost_qtype "ug" || error "enable ost quota failed"
2367 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2368 error "set quota failed"
2369 quota_show_check b u $TSTUSR
2371 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2372 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2374 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2375 error "write failure, expect success"
2377 run_test 10 "Test quota for root user"
2380 local TESTFILE=$DIR/$tdir/$tfile
2381 setup_quota_test || error "setup quota failed with $?"
2383 set_mdt_qtype "ug" || error "enable mdt quota failed"
2384 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2385 error "set quota failed"
2387 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2388 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2390 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2391 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2394 local USED=$(getquota -u $TSTUSR global curinodes)
2395 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2397 run_test 11 "Chown/chgrp ignores quota"
2400 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2402 local blimit=22 # MB
2403 local blk_cnt=$((blimit - 5))
2404 local TESTFILE0="$DIR/$tdir/$tfile"-0
2405 local TESTFILE1="$DIR/$tdir/$tfile"-1
2407 setup_quota_test || error "setup quota failed with $?"
2409 set_ost_qtype "u" || error "enable ost quota failed"
2410 quota_show_check b u $TSTUSR
2412 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2413 error "set quota failed"
2415 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2416 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2417 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2418 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2420 echo "Write to ost0..."
2421 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2422 quota_error a $TSTUSR "dd failed"
2424 echo "Write to ost1..."
2425 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2426 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2428 echo "Free space from ost0..."
2430 wait_delete_completed
2431 sync_all_data || true
2433 echo "Write to ost1 after space freed from ost0..."
2434 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2435 quota_error a $TSTUSR "rebalancing failed"
2437 run_test 12a "Block quota rebalancing"
2440 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2442 local ilimit=$((1024 * 2)) # inodes
2443 local TESTFILE0=$DIR/$tdir/$tfile
2444 local TESTFILE1=$DIR/${tdir}-1/$tfile
2446 setup_quota_test || error "setup quota failed with $?"
2448 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2449 chmod 0777 $DIR/${tdir}-1
2451 set_mdt_qtype "u" || error "enable mdt quota failed"
2452 quota_show_check f u $TSTUSR
2454 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2455 error "set quota failed"
2457 echo "Create $ilimit files on mdt0..."
2458 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2459 quota_error u $TSTUSR "create failed, but expect success"
2461 echo "Create files on mdt1..."
2462 $RUNAS createmany -m $TESTFILE1 1 &&
2463 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2465 echo "Free space from mdt0..."
2466 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2467 wait_delete_completed
2468 sync_all_data || true
2470 echo "Create files on mdt1 after space freed from mdt0..."
2471 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2472 quota_error a $TSTUSR "rebalancing failed"
2474 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2475 error "unlink mdt1 files failed"
2476 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2478 run_test 12b "Inode quota rebalancing"
2481 local TESTFILE=$DIR/$tdir/$tfile
2482 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2483 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2485 setup_quota_test || error "setup quota failed with $?"
2487 set_ost_qtype "u" || error "enable ost quota failed"
2488 quota_show_check b u $TSTUSR
2490 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2491 error "set quota failed"
2492 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2493 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2495 # clear the locks in cache first
2496 do_facet ost1 $LCTL set_param -n $procf=clear
2497 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2498 [ $nlock -eq 0 ] || error "$nlock cached locks"
2500 # write to acquire the per-ID lock
2501 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2502 quota_error a $TSTUSR "dd failed"
2504 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2505 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2507 # clear quota doesn't trigger per-ID lock cancellation
2508 resetquota -u $TSTUSR
2509 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2510 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2512 # clear the per-ID lock
2513 do_facet ost1 $LCTL set_param -n $procf=clear
2514 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2515 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2517 # spare quota should be released
2518 local OSTUUID=$(ostuuid_from_index 0)
2519 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2520 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2521 [ $limit -le $space ] ||
2522 error "spare quota isn't released, limit:$limit, space:$space"
2524 run_test 13 "Cancel per-ID lock in the LRU list"
2527 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2529 wait_delete_completed
2530 sync_all_data || true
2533 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2534 error "set user quota failed"
2535 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2536 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2537 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2538 resetquota -u $TSTUSR
2541 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2542 error "set group quota failed"
2543 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2544 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2545 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2546 resetquota -g $TSTUSR
2548 run_test 15 "Set over 4T block quota"
2552 local BLKS=1 # 1M less than limit
2553 local TESTFILE=$DIR/$tdir/$tfile
2555 setup_quota_test || error "setup quota failed with $?"
2557 # make sure the system is clean
2558 local USED=$(getquota -u $TSTUSR global curspace)
2559 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2561 set_ost_qtype "ug" || error "enable ost quota failed"
2562 # make sure no granted quota on ost
2563 resetquota -u $TSTUSR
2564 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2565 error "set quota failed"
2567 quota_show_check b u $TSTUSR
2569 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2570 lustre_fail mds 0xa04 $err_code
2572 # write in background
2573 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2577 # write should be blocked and never finished
2578 if ! ps -p $DDPID > /dev/null 2>&1; then
2580 quota_error u $TSTUSR "write finished incorrectly!"
2588 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2590 if [ $count -gt $timeout ]; then
2591 quota_error u $TSTUSR "dd is not finished!"
2596 sync; sync_all_data || true
2598 USED=$(getquota -u $TSTUSR global curspace)
2599 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2600 "Used space(${USED}K) is less than ${BLKS}M"
2605 # DQACQ return recoverable error
2607 echo "DQACQ return -ENOLCK"
2609 test_17sub 37 || error "Handle -ENOLCK failed"
2611 echo "DQACQ return -EAGAIN"
2613 test_17sub 11 || error "Handle -EAGAIN failed"
2615 echo "DQACQ return -ETIMEDOUT"
2616 #define ETIMEDOUT 110
2617 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2619 echo "DQACQ return -ENOTCONN"
2620 #define ENOTCONN 107
2621 test_17sub 107 || error "Handle -ENOTCONN failed"
2624 run_test 17 "DQACQ return recoverable error"
2628 local blimit=200 # MB
2629 local TESTFILE="$DIR/$tdir/$tfile"
2631 setup_quota_test || error "setup quota failed with $?"
2633 set_ost_qtype "u" || error "enable ost quota failed"
2634 log "User quota (limit: $blimit)"
2635 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2636 error "set quota failed"
2637 quota_show_check b u $TSTUSR
2639 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2640 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2642 local timeout=$(sysctl -n lustre.timeout)
2644 if [ $io_type = "directio" ]; then
2645 log "Write 100M (directio) ..."
2646 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2648 log "Write 100M (buffered) ..."
2649 $RUNAS $DD of=$TESTFILE count=100 &
2653 replay_barrier $SINGLEMDS
2654 log "Fail mds for $((2 * timeout)) seconds"
2655 fail $SINGLEMDS $((2 * timeout))
2658 if at_is_enabled; then
2659 timeout=$(at_max_get mds)
2661 timeout=$(lctl get_param -n timeout)
2665 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2666 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2667 log "it took $count second"
2672 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2674 cancel_lru_locks mdc
2675 cancel_lru_locks osc
2678 local testfile_size=$(stat -c %s $TESTFILE)
2679 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2680 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2681 "got ${testfile_size}. Verifying file failed!"
2686 # test when mds does failover, the ost still could work well
2687 # this test shouldn't trigger watchdog b=14840
2689 # Clear dmesg so watchdog is not triggered by previous
2691 do_facet ost1 dmesg -c > /dev/null
2694 test_18_sub directio
2696 # check if watchdog is triggered
2697 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2698 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2699 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2700 [ -z "$watchdog" ] || error "$watchdog"
2701 rm -f $TMP/lustre-log-${TESTNAME}.log
2703 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2707 local TESTFILE=$DIR/$tdir/$tfile
2709 setup_quota_test || error "setup quota failed with $?"
2711 set_ost_qtype $QTYPE || error "enable ost quota failed"
2713 # bind file to a single OST
2714 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2715 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2717 echo "Set user quota (limit: ${blimit}M)"
2718 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2719 error "set user quota failed"
2720 quota_show_check b u $TSTUSR
2721 echo "Update quota limits"
2722 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2723 error "set group quota failed"
2724 quota_show_check b u $TSTUSR
2726 # first wirte might be cached
2727 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2728 cancel_lru_locks osc
2730 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2731 quota_error u $TSTUSR "Write success, expect failure"
2734 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2736 test_20() { # b15754
2737 local LSTR=(2g 1t 4k 3m) # limits strings
2739 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2742 resetquota -u $TSTUSR
2744 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2745 $MOUNT || error "could not set quota limits"
2746 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2747 --inode-softlimit ${LSTR[2]} \
2748 --inode-hardlimit ${LSTR[3]} \
2749 $MOUNT || error "could not set quota limits"
2751 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2752 error "bsoftlimit was not set properly"
2753 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2754 error "bhardlimit was not set properly"
2755 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2756 error "isoftlimit was not set properly"
2757 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2758 error "ihardlimit was not set properly"
2760 resetquota -u $TSTUSR
2762 run_test 20 "Test if setquota specifiers work properly (b15754)"
2769 local time=$(($(date +%s) + seconds))
2770 while [ $(date +%s) -lt $time ]; do
2771 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2775 # run for fixing bug16053, setquota shouldn't fail when writing and
2776 # deleting are happening
2778 local TESTFILE="$DIR/$tdir/$tfile"
2779 local BLIMIT=10 # 10G
2780 local ILIMIT=1000000
2782 setup_quota_test || error "setup quota failed with $?"
2784 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2786 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2787 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2788 error "set user quota failed"
2789 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2790 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2791 error "set group quota failed"
2792 if is_project_quota_supported; then
2793 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2794 "project: $TSTPRJID"
2795 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2796 $MOUNT || error "set project quota failed"
2799 # repeat writing on a 1M file
2800 test_21_sub ${TESTFILE}_1 1 30 &
2802 # repeat writing on a 128M file
2803 test_21_sub ${TESTFILE}_2 128 30 &
2806 local time=$(($(date +%s) + 30))
2808 while [ $(date +%s) -lt $time ]; do
2809 log "Set quota for $i times"
2810 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2811 -I $((ILIMIT + i)) $MOUNT ||
2812 error "Set user quota failed"
2813 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2814 -I $((ILIMIT + i)) $MOUNT ||
2815 error "Set group quota failed"
2816 if is_project_quota_supported; then
2817 $LFS setquota -p $TSTPRJID -b 0 -B \
2818 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2819 error "Set project quota failed"
2827 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2829 if [ $count -gt 60 ]; then
2830 quota_error a $TSTUSR "dd should be finished!"
2834 echo "(dd_pid=$DDPID1, time=$count)successful"
2838 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2840 if [ $count -gt 60 ]; then
2841 quota_error a $TSTUSR "dd should be finished!"
2845 echo "(dd_pid=$DDPID2, time=$count)successful"
2847 run_test 21 "Setquota while writing & deleting (b16053)"
2849 # enable/disable quota enforcement permanently
2851 echo "Set both mdt & ost quota type as ug"
2853 is_project_quota_supported && qtype=$QTYPE
2854 set_mdt_qtype $qtype || error "enable mdt quota failed"
2855 set_ost_qtype $qtype || error "enable ost quota failed"
2858 stopall || error "failed to stopall (1)"
2862 echo "Verify if quota is enabled"
2863 local qtype1=$(mdt_quota_type)
2864 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2865 qtype=$(ost_quota_type)
2866 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2868 echo "Set both mdt & ost quota type as none"
2869 set_mdt_qtype "none" || error "disable mdt quota failed"
2870 set_ost_qtype "none" || error "disable ost quota failed"
2873 stopall || error "failed to stopall (2)"
2878 echo "Verify if quota is disabled"
2879 qtype=$(mdt_quota_type)
2880 [ $qtype != "none" ] && error "mdt quota setting is lost"
2881 qtype=$(ost_quota_type)
2882 [ $qtype != "none" ] && error "ost quota setting is lost"
2886 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2889 local TESTFILE="$DIR/$tdir/$tfile"
2892 setup_quota_test || error "setup quota failed with $?"
2894 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2897 log "User quota (limit: $LIMIT MB)"
2898 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2899 error "set quota failed"
2900 quota_show_check b u $TSTUSR
2902 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2903 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2905 log "Step1: trigger EDQUOT with O_DIRECT"
2906 log "Write half of file"
2907 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2908 quota_error u $TSTUSR "(1) Write failure, expect success." \
2910 log "Write out of block quota ..."
2911 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2912 oflag=direct conv=notrunc &&
2913 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2917 log "Step2: rewrite should succeed"
2918 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2919 quota_error u $TSTUSR "(3) Write failure, expect success." \
2925 local OST0_UUID=$(ostuuid_from_index 0)
2926 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2927 [ $OST0_QUOTA_USED -ne 0 ] &&
2928 ($SHOW_QUOTA_USER; \
2929 quota_error u $TSTUSR "quota isn't released")
2934 [ "$ost1_FSTYPE" == zfs ] &&
2935 skip "Overwrite in place is not guaranteed to be " \
2936 "space neutral on ZFS"
2938 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2939 check_whether_skip && return 0
2940 log "run for 4MB test file"
2943 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2944 check_whether_skip && return 0
2945 log "run for 40MB test file"
2948 run_test 23 "Quota should be honored with directIO (b16125)"
2952 local TESTFILE="$DIR/$tdir/$tfile"
2954 setup_quota_test || error "setup quota failed with $?"
2956 set_ost_qtype $QTYPE || error "enable ost quota failed"
2958 # bind file to a single OST
2959 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2960 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2962 echo "Set user quota (limit: ${blimit}M)"
2963 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2964 error "set quota failed"
2966 # overrun quota by root user
2967 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2968 error "write failure, expect success"
2969 cancel_lru_locks osc
2970 sync_all_data || true
2972 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2974 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2976 test_27a() { # b19612
2977 $LFS quota $TSTUSR $DIR &&
2978 error "lfs succeeded with no type, but should have failed"
2979 $LFS setquota $TSTUSR $DIR &&
2980 error "lfs succeeded with no type, but should have failed"
2983 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2985 test_27b() { # b20200
2986 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2987 error "lfs setquota failed with uid argument"
2988 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2989 error "lfs stequota failed with gid argument"
2990 if is_project_quota_supported; then
2991 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2992 1000 $DIR || error \
2993 "lfs stequota failed with projid argument"
2995 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2996 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2997 if is_project_quota_supported; then
2998 $SHOW_QUOTA_PROJID ||
2999 error "lfs quota failed with projid argument"
3001 resetquota -u $TSTID
3002 resetquota -g $TSTID
3003 resetquota -p $TSTPRJID
3006 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3011 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3012 error "lfs setquota failed"
3014 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3015 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3016 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3017 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3019 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3020 error "lfs setquota for $TSTID failed"
3022 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3023 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3024 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3025 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3027 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3028 error "total allocated inode/block limit not printed"
3030 resetquota -u $TSTUSR
3032 run_test 27c "lfs quota should support human-readable output"
3039 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3040 error "set fraction block limit failed"
3041 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3042 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3043 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3044 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3046 resetquota -u $TSTUSR
3048 run_test 27d "lfs setquota should support fraction block limit"
3052 local TESTFILE="$DIR/$tdir/$tfile"
3055 setup_quota_test || error "setup quota failed with $?"
3057 set_ost_qtype "u" || error "enable ost quota failed"
3059 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3060 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3062 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3063 $MAX_IQ_TIME $DIR || error "set grace time failed"
3064 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3065 error "set quota failed"
3066 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3067 cancel_lru_locks osc
3069 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3070 # over-quota flag has not yet settled since we do not trigger async
3071 # events based on grace time period expiration
3073 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3074 cancel_lru_locks osc
3075 # now over-quota flag should be settled and further writes should fail
3077 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3078 error "grace times were reset"
3079 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3080 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3082 run_test 30 "Hard limit updates should not reset grace times"
3084 # basic usage tracking for user & group
3086 local INODES=10 # files
3087 local BLK_CNT=2 # MB each
3088 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3090 setup_quota_test || error "setup quota failed with $?"
3092 # make sure the system is clean
3093 local USED=$(getquota -u $TSTID global curspace)
3095 error "Used space ($USED) for user $TSTID isn't 0."
3096 USED=$(getquota -g $TSTID global curspace)
3098 error "Used space ($USED) for group $TSTID isn't 0."
3099 if is_project_quota_supported; then
3100 USED=$(getquota -p $TSTPRJID global curspace)
3101 [ $USED -ne 0 ] && error \
3102 "Used space ($USED) for project $TSTPRJID isn't 0."
3105 echo "Write files..."
3106 for i in $(seq 0 $INODES); do
3107 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3108 error "write failed"
3109 is_project_quota_supported &&
3110 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3111 echo "Iteration $i/$INODES completed"
3113 cancel_lru_locks osc
3115 echo "Wait for setattr on objects finished..."
3116 wait_delete_completed
3118 sync; sync_all_data || true
3120 echo "Verify disk usage after write"
3121 USED=$(getquota -u $TSTID global curspace)
3122 [ $USED -lt $TOTAL_BLKS ] &&
3123 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3124 USED=$(getquota -g $TSTID global curspace)
3125 [ $USED -lt $TOTAL_BLKS ] &&
3126 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3127 if is_project_quota_supported; then
3128 USED=$(getquota -p $TSTPRJID global curspace)
3129 [ $USED -lt $TOTAL_BLKS ] && error \
3130 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3133 echo "Verify inode usage after write"
3134 USED=$(getquota -u $TSTID global curinodes)
3135 [ $USED -lt $INODES ] &&
3136 error "Used inode for user $TSTID is $USED, expected $INODES"
3137 USED=$(getquota -g $TSTID global curinodes)
3138 [ $USED -lt $INODES ] &&
3139 error "Used inode for group $TSTID is $USED, expected $INODES"
3140 if is_project_quota_supported; then
3141 USED=$(getquota -p $TSTPRJID global curinodes)
3142 [ $USED -lt $INODES ] && error \
3143 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3148 echo "Verify disk usage after delete"
3149 USED=$(getquota -u $TSTID global curspace)
3150 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3151 USED=$(getquota -u $TSTID global curinodes)
3152 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3153 USED=$(getquota -g $TSTID global curspace)
3154 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3155 USED=$(getquota -g $TSTID global curinodes)
3156 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3157 if is_project_quota_supported; then
3158 USED=$(getquota -p $TSTPRJID global curspace)
3160 error "Used space for project $TSTPRJID isn't 0. $USED"
3161 USED=$(getquota -p $TSTPRJID global curinodes)
3163 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3166 run_test 33 "Basic usage tracking for user & group & project"
3168 # usage transfer test for user & group & project
3170 local BLK_CNT=2 # MB
3171 local project_supported="no"
3173 is_project_quota_supported && project_supported="yes"
3174 setup_quota_test || error "setup quota failed with $?"
3176 # make sure the system is clean
3177 local USED=$(getquota -u $TSTID global curspace)
3178 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3179 USED=$(getquota -g $TSTID global curspace)
3180 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3182 local USED=$(getquota -u $TSTID2 global curspace)
3183 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3184 if [ $project_supported == "yes" ]; then
3185 USED=$(getquota -p $TSTPRJID global curspace)
3186 [ $USED -ne 0 ] && error \
3187 "Used space ($USED) for Project $TSTPRJID isn't 0."
3190 echo "Write file..."
3191 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3192 error "write failed"
3193 cancel_lru_locks osc
3194 sync; sync_all_data || true
3196 echo "chown the file to user $TSTID"
3197 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3199 echo "Wait for setattr on objects finished..."
3200 wait_delete_completed
3202 BLK_CNT=$((BLK_CNT * 1024))
3204 echo "Verify disk usage for user $TSTID"
3205 USED=$(getquota -u $TSTID global curspace)
3206 [ $USED -lt $BLK_CNT ] &&
3207 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3208 USED=$(getquota -u $TSTID global curinodes)
3210 error "Used inodes for user $TSTID is $USED, expected 1"
3212 echo "chgrp the file to group $TSTID"
3213 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3215 echo "Wait for setattr on objects finished..."
3216 wait_delete_completed
3218 echo "Verify disk usage for group $TSTID"
3219 USED=$(getquota -g $TSTID global curspace)
3220 [ $USED -ge $BLK_CNT ] ||
3221 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3222 USED=$(getquota -g $TSTID global curinodes)
3224 error "Used inodes for group $TSTID is $USED, expected 1"
3226 # chown won't change the ost object group. LU-4345 */
3227 echo "chown the file to user $TSTID2"
3228 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3230 echo "Wait for setattr on objects finished..."
3231 wait_delete_completed
3233 echo "change_project project id to $TSTPRJID"
3234 [ $project_supported == "yes" ] &&
3235 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3236 echo "Wait for setattr on objects finished..."
3237 wait_delete_completed
3239 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3240 USED=$(getquota -u $TSTID2 global curspace)
3241 [ $USED -lt $BLK_CNT ] &&
3242 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3243 USED=$(getquota -u $TSTID global curspace)
3245 error "Used space for user $TSTID is $USED, expected 0"
3246 USED=$(getquota -g $TSTID global curspace)
3247 [ $USED -lt $BLK_CNT ] &&
3248 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3249 if [ $project_supported == "yes" ]; then
3250 USED=$(getquota -p $TSTPRJID global curspace)
3251 [ $USED -lt $BLK_CNT ] && error \
3252 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3256 run_test 34 "Usage transfer for user & group & project"
3258 # usage is still accessible across restart
3260 local BLK_CNT=2 # MB
3262 setup_quota_test || error "setup quota failed with $?"
3264 echo "Write file..."
3265 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3266 error "write failed"
3267 is_project_quota_supported &&
3268 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3269 cancel_lru_locks osc
3271 echo "Wait for setattr on objects finished..."
3272 wait_delete_completed
3274 sync; sync_all_data || true
3276 echo "Save disk usage before restart"
3277 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3278 [ $ORIG_USR_SPACE -eq 0 ] &&
3279 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3280 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3281 [ $ORIG_USR_INODES -eq 0 ] &&
3282 error "Used inodes for user $TSTID is 0, expected 1"
3283 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3284 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3285 [ $ORIG_GRP_SPACE -eq 0 ] &&
3286 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3287 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3288 [ $ORIG_GRP_INODES -eq 0 ] &&
3289 error "Used inodes for group $TSTID is 0, expected 1"
3290 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3292 if is_project_quota_supported; then
3293 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3294 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3295 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3296 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3297 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3298 "Used inodes for project $TSTPRJID is 0, expected 1"
3299 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3307 echo "Verify disk usage after restart"
3308 local USED=$(getquota -u $TSTID global curspace)
3309 [ $USED -eq $ORIG_USR_SPACE ] ||
3310 error "Used space for user $TSTID changed from " \
3311 "$ORIG_USR_SPACE to $USED"
3312 USED=$(getquota -u $TSTID global curinodes)
3313 [ $USED -eq $ORIG_USR_INODES ] ||
3314 error "Used inodes for user $TSTID changed from " \
3315 "$ORIG_USR_INODES to $USED"
3316 USED=$(getquota -g $TSTID global curspace)
3317 [ $USED -eq $ORIG_GRP_SPACE ] ||
3318 error "Used space for group $TSTID changed from " \
3319 "$ORIG_GRP_SPACE to $USED"
3320 USED=$(getquota -g $TSTID global curinodes)
3321 [ $USED -eq $ORIG_GRP_INODES ] ||
3322 error "Used inodes for group $TSTID changed from " \
3323 "$ORIG_GRP_INODES to $USED"
3324 if [ $project_supported == "yes" ]; then
3325 USED=$(getquota -p $TSTPRJID global curinodes)
3326 [ $USED -eq $ORIG_PRJ_INODES ] ||
3327 error "Used inodes for project $TSTPRJID " \
3328 "changed from $ORIG_PRJ_INODES to $USED"
3329 USED=$(getquota -p $TSTPRJID global curspace)
3330 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3331 error "Used space for project $TSTPRJID "\
3332 "changed from $ORIG_PRJ_SPACE to $USED"
3335 # check if the vfs_dq_init() is called before writing
3336 echo "Append to the same file..."
3337 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3338 error "write failed"
3339 cancel_lru_locks osc
3340 sync; sync_all_data || true
3342 echo "Verify space usage is increased"
3343 USED=$(getquota -u $TSTID global curspace)
3344 [ $USED -gt $ORIG_USR_SPACE ] ||
3345 error "Used space for user $TSTID isn't increased" \
3346 "orig:$ORIG_USR_SPACE, now:$USED"
3347 USED=$(getquota -g $TSTID global curspace)
3348 [ $USED -gt $ORIG_GRP_SPACE ] ||
3349 error "Used space for group $TSTID isn't increased" \
3350 "orig:$ORIG_GRP_SPACE, now:$USED"
3351 if [ $project_supported == "yes" ]; then
3352 USED=$(getquota -p $TSTPRJID global curspace)
3353 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3354 error "Used space for project $TSTPRJID isn't " \
3355 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3358 run_test 35 "Usage is still accessible across reboot"
3360 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3363 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3364 skip "Old server doesn't have LU-5006 fix."
3366 setup_quota_test || error "setup quota failed with $?"
3368 # make sure the system is clean
3369 local USED=$(getquota -u $TSTID global curspace)
3371 error "Used space ($USED) for user $TSTID isn't 0."
3373 # create file with MDS_OPEN_DELAY_CREATE flag
3374 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3375 error "Create file failed"
3377 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3378 oflag=sync || error "Write file failed"
3380 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3382 # wait for setattr on objects finished..."
3383 wait_delete_completed
3385 USED=$(getquota -u $TSTID global curspace)
3386 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3388 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3392 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3393 skip "Old server doesn't have LU-8801 fix."
3395 [ "$UID" != 0 ] && skip_env "must run as root" && return
3397 setup_quota_test || error "setup quota failed with $?"
3399 # make sure the system is clean
3400 local USED=$(getquota -u $TSTID global curspace)
3402 error "Used space ($USED) for user $TSTID isn't 0."
3403 USED=$(getquota -u $TSTID2 global curspace)
3405 error "Used space ($USED) for user $TSTID2 isn't 0."
3407 local TESTFILE="$DIR/$tdir/$tfile"
3408 local file_cnt=10000
3410 # Generate id entries in accounting file
3411 echo "Create $file_cnt files..."
3412 for i in `seq $file_cnt`; do
3414 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3415 error "failed to chown $TESTFILE-$i"
3417 cancel_lru_locks osc
3418 sync; sync_all_data || true
3420 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3421 procf=${procf}.quota_slave.acct_user
3424 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3425 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3426 echo "Found $acct_cnt id entries"
3428 [ $file_cnt -eq $acct_cnt ] || {
3429 do_facet mds1 $LCTL get_param $procf
3430 error "skipped id entries"
3433 run_test 38 "Quota accounting iterator doesn't skip id entries"
3436 local TESTFILE="$DIR/$tdir/project"
3437 ! is_project_quota_supported &&
3438 skip "Project quota is not supported"
3440 setup_quota_test || error "setup quota failed with $?"
3443 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3444 [ $projectid -ne 0 ] &&
3445 error "Project id should be 0 not $projectid"
3446 change_project -p 1024 $TESTFILE
3447 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3448 [ $projectid -ne 1024 ] &&
3449 error "Project id should be 1024 not $projectid"
3451 stopall || error "failed to stopall (1)"
3454 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3455 [ $projectid -eq 1024 ] ||
3456 error "Project id should be 1024 not $projectid"
3458 run_test 39 "Project ID interface works correctly"
3461 ! is_project_quota_supported &&
3462 skip "Project quota is not supported"
3463 local dir1="$DIR/$tdir/dir1"
3464 local dir2="$DIR/$tdir/dir2"
3466 setup_quota_test || error "setup quota failed with $?"
3468 mkdir -p $dir1 $dir2
3469 change_project -sp 1 $dir1 && touch $dir1/1
3470 change_project -sp 2 $dir2
3472 ln $dir1/1 $dir2/1_link &&
3473 error "Hard link across different project quota should fail"
3476 run_test 40a "Hard link across different project ID"
3479 ! is_project_quota_supported &&
3480 skip "Project quota is not supported"
3481 local dir1="$DIR/$tdir/dir1"
3482 local dir2="$DIR/$tdir/dir2"
3484 setup_quota_test || error "setup quota failed with $?"
3485 mkdir -p $dir1 $dir2
3486 change_project -sp 1 $dir1 && touch $dir1/1
3487 change_project -sp 2 $dir2
3489 mv $dir1/1 $dir2/2 || error "mv failed $?"
3490 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3491 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3493 run_test 40b "Mv across different project ID"
3496 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3497 ! is_project_quota_supported &&
3498 skip "Project quota is not supported"
3500 setup_quota_test || error "setup quota failed with $?"
3501 local dir="$DIR/$tdir/dir"
3503 mkdir -p $dir && change_project -sp 1 $dir
3504 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3505 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3506 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3507 touch $dir/remote_dir/file
3508 #verify inherit works file for remote dir.
3509 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3510 [ "$projid" != "1" ] &&
3511 error "file under remote dir expected 1 not $projid"
3513 #Agent inode should be ignored for project quota
3514 local used=$(getquota -p 1 global curinodes)
3516 error "file count expected 3 got $used"
3518 run_test 40c "Remote child Dir inherit project quota properly"
3521 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3522 is_project_quota_supported || skip "Project quota is not supported"
3524 setup_quota_test || error "setup quota failed with $?"
3525 local dir="$DIR/$tdir/dir"
3528 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3529 change_project -sp $TSTPRJID $dir ||
3530 error "change project on $dir failed"
3531 for i in $(seq 5); do
3532 mkdir -p $dir/d$i/d$i ||
3533 error "mkdir $dir/d$i/d$i failed"
3534 local projid=$($LFS project -d $dir/d$i/d$i |
3536 [ "$projid" == "$TSTPRJID" ] ||
3537 error "projid id expected $TSTPRJID not $projid"
3538 touch $dir/d$i/d$i/file
3539 #verify inherit works file for stripe dir.
3540 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3541 [ "$projid" == "$TSTPRJID" ] ||
3542 error "file under remote dir expected 1 not $projid"
3545 # account should be 1 + (2 + 1) *10 + 1 * 5
3546 local used=$(getquota -p $TSTPRJID global curinodes)
3548 error "file count expected 36 got $used"
3550 run_test 40d "Stripe Directory inherit project quota properly"
3553 is_project_quota_supported ||
3554 skip "Project quota is not supported"
3555 setup_quota_test || error "setup quota failed with $?"
3556 local dir="$DIR/$tdir/dir"
3559 local projid=$((testnum * 1000))
3563 # enable mdt/ost quota
3564 set_mdt_qtype ugp || error "enable mdt quota failed"
3565 set_ost_qtype ugp || error "enable ost quota failed"
3567 test_mkdir -p $dir && change_project -sp $projid $dir
3568 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3569 error "set project quota failed"
3574 # check if df output works as expected
3575 echo "== global statfs: $MOUNT =="
3576 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3578 echo "== project statfs (prjid=$projid): $dir =="
3579 df -kP $dir; df -iP $dir
3580 local bused=$(getquota -p $projid global curspace)
3581 local iused=$(getquota -p $projid global curinodes)
3582 # note trailing space to match double printf from awk
3583 local expected="$blimit $bused $ilimit $iused "
3585 wait_update $HOSTNAME \
3586 "{ df -kP $dir; df -iP $dir; } |
3587 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3589 error "failed to get correct statfs for project quota"
3591 run_test 41 "df should return projid-specific values"
3599 local osd="osd-ldiskfs"
3601 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3603 rm -f $DIR/$tdir/$tfile
3604 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3605 chmod a+rw $DIR/$tdir/$tfile
3607 $LFS setquota $qtype $qid -B 300M $MOUNT
3608 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3609 error "failed to dd"
3611 do_facet $SINGLEMDS \
3612 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3613 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3616 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3617 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3619 $LFS setquota $qtype $qid --delete $MOUNT
3620 do_facet $SINGLEMDS \
3621 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3622 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3625 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3626 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3628 $LFS setquota $qtype $qid -B 500M $MOUNT
3629 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3630 error "failed to dd"
3631 do_facet $SINGLEMDS \
3632 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3633 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3634 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3636 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3637 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3642 setup_quota_test || error "setup quota failed with $?"
3643 set_ost_qtype $QTYPE || error "enable ost quota failed"
3646 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3647 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3648 is_project_quota_supported &&
3649 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3653 run_test 48 "lfs quota --delete should delete quota project ID"
3656 ! is_project_quota_supported &&
3657 skip "Project quota is not supported"
3659 setup_quota_test || error "setup quota failed with $?"
3660 local dir1="$DIR/$tdir/dir1"
3661 local dir2="$DIR/$tdir/dir2"
3663 mkdir -p $dir1 && change_project -sp 1 $dir1
3664 mkdir -p $dir2 && change_project -sp 2 $dir2
3665 for num in $(seq 1 10); do
3666 touch $dir1/file_$num $dir2/file_$num
3667 ln -s $dir1/file_$num $dir1/file_$num"_link"
3668 ln -s $dir2/file_$num $dir2/file_$num"_link"
3671 count=$($LFS find --projid 1 $DIR | wc -l)
3672 [ "$count" != 21 ] && error "expected 21 but got $count"
3674 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3675 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3676 [ $count -eq 22 ] || error "expected 22 but got $count"
3678 run_test 50 "Test if lfs find --projid works"
3681 ! is_project_quota_supported &&
3682 skip "Project quota is not supported"
3683 setup_quota_test || error "setup quota failed with $?"
3684 local dir="$DIR/$tdir/dir"
3686 mkdir $dir && change_project -sp 1 $dir
3687 local used=$(getquota -p 1 global curinodes)
3688 [ $used != "1" ] && error "expected 1 got $used"
3693 used=$(getquota -p 1 global curinodes)
3694 [ $used != "4" ] && error "expected 4 got $used"
3696 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3698 cp $DIR/$tdir/6 $dir/6
3699 used=$(getquota -p 1 global curinodes)
3700 [ $used != "5" ] && error "expected 5 got $used"
3703 mv $DIR/$tdir/6 $dir/7
3704 used=$(getquota -p 1 global curinodes)
3705 [ $used -eq 6 ] || error "expected 6 got $used"
3707 run_test 51 "Test project accounting with mv/cp"
3710 ! is_project_quota_supported &&
3711 skip "Project quota is not supported"
3713 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
3714 skip "Need MDS version at least 2.14.55"
3716 setup_quota_test || error "setup quota failed with $?"
3718 local dir1=$DIR/$tdir/t52_dir1
3719 local dir2=$DIR/$tdir/t52_dir2
3721 mkdir $dir1 || error "failed to mkdir $dir1"
3722 mkdir $dir2 || error "failed to mkdir $dir2"
3724 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
3725 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
3727 $DD if=/dev/zero of=/$dir1/$tfile bs=1M count=100 ||
3728 error "failed to create and write $tdir1/$tfile"
3730 cancel_lru_locks osc
3731 sync; sync_all_data || true
3733 local attrs=($(lsattr -p $dir1/$tfile))
3734 (( ${attrs[0]} == 1000 )) ||
3735 error "project ID on $dir1/$tfile is not inherited"
3737 $LFS quota -p 1000 $DIR
3738 $LFS quota -p 1001 $DIR
3740 local prev_used=$(getquota -p 1000 global curspace)
3741 local prev_used2=$(getquota -p 1001 global curspace)
3743 mrename $dir1 $dir2/tdir || log "rename directory return $?"
3745 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
3746 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
3747 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
3749 attrs=($(lsattr -p $dir2/$tfile))
3750 (( ${attrs[0]} == 1001 )) ||
3751 error "project ID is not updated after rename"
3753 (( $inum_before == $inum_after )) ||
3754 error "inode is changed after rename: $inum_before, $inum_after"
3756 sync_all_data || true
3758 $LFS quota -p 1000 $DIR
3759 $LFS quota -p 1001 $DIR
3761 local new_used=$(getquota -p 1000 global curspace)
3762 local new_used2=$(getquota -p 1001 global curspace)
3764 (( $prev_used >= $new_used + 102400 )) ||
3765 error "quota is not deducted from old project ID"
3766 (( $prev_used2 <= $new_used2 - 102400 )) ||
3767 error "quota is not added for the new project ID"
3769 run_test 52 "Rename normal file across project ID"
3772 ! is_project_quota_supported &&
3773 skip "Project quota is not supported"
3774 setup_quota_test || error "setup quota failed with $?"
3775 local dir="$DIR/$tdir/dir"
3776 mkdir $dir && change_project -s $dir
3777 [[ $($LFS project -d $dir) =~ " P " ]] ||
3778 error "inherit attribute should be set"
3780 change_project -C $dir
3781 [[ $($LFS project -d $dir) =~ " - " ]] ||
3782 error "inherit attribute should be cleared"
3784 run_test 53 "Project inherit attribute could be cleared"
3787 ! is_project_quota_supported &&
3788 skip "Project quota is not supported"
3789 setup_quota_test || error "setup quota failed with $?"
3790 local testfile="$DIR/$tdir/$tfile-0"
3792 #set project ID/inherit attribute
3793 change_project -sp $TSTPRJID $DIR/$tdir
3794 $RUNAS createmany -m ${testfile} 100 ||
3795 error "create many files failed"
3797 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3798 # one more count for directory itself */
3802 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3803 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3805 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3806 [ $proj_count1 -eq $proj_count ] ||
3807 error "c2: expected $proj_count got $proj_count1"
3809 #clear project but with kept projid
3810 change_project -rCk $DIR/$tdir
3811 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3812 [ $proj_count1 -eq 1 ] ||
3813 error "c3: expected 1 got $proj_count1"
3815 #verify projid untouched.
3816 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3818 [ $proj_count1 -eq $proj_count ] ||
3819 error "c4: expected $proj_count got $proj_count1"
3822 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3823 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3824 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3826 #this time clear all
3827 change_project -rC $DIR/$tdir
3828 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3829 [ $proj_count1 -eq 0 ] ||
3830 error "c6: expected 0 got $proj_count1"
3832 unlinkmany ${testfile} 100 ||
3833 error "unlink many files failed"
3835 run_test 54 "basic lfs project interface test"
3838 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3839 skip "Not supported before 2.10.58."
3840 setup_quota_test || error "setup quota failed with $?"
3842 set_ost_qtype $QTYPE || error "enable ost quota failed"
3845 #add second group to TSTUSR
3846 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3849 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3850 error "failed to dd"
3852 cancel_lru_locks osc
3853 sync; sync_all_data || true
3855 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3856 error "failed to setquota on group $TSTUSR2"
3858 $LFS quota -v -g $TSTUSR2 $DIR
3860 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3861 error "chgrp should failed with -EDQUOT"
3863 USED=$(getquota -g $TSTUSR2 global curspace)
3866 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3867 error "failed to setquota on group $TSTUSR2"
3869 $LFS quota -v -g $TSTUSR2 $DIR
3871 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3872 error "chgrp should succeed"
3874 $LFS quota -v -g $TSTUSR2 $DIR
3876 run_test 55 "Chgrp should be affected by group quota"
3879 setup_quota_test || error "setup quota failed with $?"
3881 set_ost_qtype $QTYPE || error "enable ost quota failed"
3884 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3885 erro "failed to set grace time for usr quota"
3886 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3887 awk '{print $4 $8}')
3888 if [ "x$grace_time" != "x10s;10s" ]; then
3889 $LFS quota -t -u $DIR
3890 error "expected grace time: 10s;10s, got:$grace_time"
3893 run_test 56 "lfs quota -t should work well"
3896 setup_quota_test || error "setup quota failed with $?"
3898 local dir="$DIR/$tdir/dir"
3901 #command can process further if it hit some errors
3902 $LFS project -sp 1 $dir/pipe
3903 touch $dir/aaa $dir/bbb
3904 mkdir $dir/subdir -p
3905 touch $dir/subdir/aaa $dir/subdir/bbb
3906 #create one invalid link file
3907 ln -s $dir/not_exist_file $dir/ccc
3908 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3909 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
3911 run_test 57 "lfs project could tolerate errors"
3914 [ "$mds1_FSTYPE" != ldiskfs ] &&
3915 skip "ldiskfs only test"
3916 disable_project_quota
3917 setup_quota_test || error "setup quota failed with $?"
3920 local testfile="$DIR/$tdir/$tfile-0"
3921 #make sure it did not crash kernel
3922 touch $testfile && lfs project -sp 1 $testfile
3924 enable_project_quota
3926 run_test 59 "lfs project dosen't crash kernel with project disabled"
3929 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3930 skip "Needs MDS version 2.11.53 or later."
3931 setup_quota_test || error "setup quota failed with $?"
3933 local testfile=$DIR/$tdir/$tfile
3936 set_mdt_qtype "ug" || error "enable mdt quota failed"
3938 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3939 error "set quota failed"
3940 quota_show_check a g $TSTUSR
3942 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3943 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3944 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3945 error "create many files failed"
3947 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3949 # root user can overrun quota
3950 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3951 error "root user should succeed"
3953 run_test 60 "Test quota for root with setgid"
3955 # test default quota
3956 test_default_quota() {
3957 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3958 skip "Not supported before 2.11.51."
3963 local qprjid=$TSTPRJID
3967 local LIMIT=20480 #20M disk space
3968 local TESTFILE="$DIR/$tdir/$tfile-0"
3971 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3972 echo "Project quota is not supported" && return 0
3974 [ $qtype == "-u" ] && qdtype="-U"
3975 [ $qtype == "-g" ] && qdtype="-G"
3976 [ $qtype == "-p" ] && {
3981 [ $qres_type == "meta" ] && {
3982 LIMIT=10240 #10K inodes
3987 qpool_cmd="--pool $3"
3988 # pool quotas don't work properly without global limit
3989 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
3990 error "set global limit failed"
3993 setup_quota_test || error "setup quota failed with $?"
3997 # enable mdt/ost quota
3998 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3999 set_ost_qtype $QTYPE || error "enable ost quota failed"
4001 log "set to use default quota"
4002 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4003 error "set $qid to use default quota failed"
4005 log "set default quota"
4006 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4007 error "set $qid default quota failed"
4009 log "get default quota"
4010 $LFS quota $qdtype $DIR || error "get default quota failed"
4012 if [ $qres_type == "data" ]; then
4013 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4014 grep "$MOUNT" | awk '{print $2}')
4015 [ $SLIMIT -eq $LIMIT ] ||
4016 error "the returned default quota is wrong"
4018 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4020 [ $SLIMIT -eq $LIMIT ] ||
4021 error "the returned default quota is wrong"
4024 # make sure the system is clean
4025 local USED=$(getquota $qtype $qid global curspace)
4026 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4028 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4029 error "setstripe $TESTFILE failed"
4030 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4032 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4034 log "Test not out of quota"
4035 if [ $qres_type == "data" ]; then
4036 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4037 quota_error $qtype $qid "write failed, expect succeed"
4039 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4040 quota_error $qtype $qid "create failed, expect succeed"
4042 unlinkmany $TESTFILE $((LIMIT/2))
4045 log "Test out of quota"
4046 # flush cache, ensure noquota flag is set on client
4047 cancel_lru_locks osc
4048 cancel_lru_locks mdc
4049 sync; sync_all_data || true
4050 if [ $qres_type == "data" ]; then
4051 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4052 quota_error $qtype $qid "write succeed, expect EDQUOT"
4054 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4055 quota_error $qtype $qid "create succeed, expect EDQUOT"
4057 unlinkmany $TESTFILE $((LIMIT*2))
4061 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4062 error "setstripe $TESTFILE failed"
4063 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4065 log "Increase default quota"
4067 # LU-4505: sleep 5 seconds to enable quota acquire
4070 # increase default quota
4071 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4072 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4074 cancel_lru_locks osc
4075 cancel_lru_locks mdc
4076 sync; sync_all_data || true
4077 if [ $qres_type == "data" ]; then
4078 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4079 quota_error $qtype $qid "write failed, expect succeed"
4081 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4082 quota_error $qtype $qid "create failed, expect succeed"
4084 unlinkmany $TESTFILE $((LIMIT*2))
4087 log "Set quota to override default quota"
4088 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4089 error "set $qid quota failed"
4091 cancel_lru_locks osc
4092 cancel_lru_locks mdc
4093 sync; sync_all_data || true
4094 if [ $qres_type == "data" ]; then
4095 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4096 quota_error $qtype $qid "write succeed, expect EQUOT"
4098 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4099 quota_error $qtype $qid "create succeed, expect EQUOT"
4101 unlinkmany $TESTFILE $((LIMIT*2))
4104 log "Set to use default quota again"
4106 # LU-4505: sleep 5 seconds to enable quota acquire
4109 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4110 error "set $qid to use default quota failed"
4112 cancel_lru_locks osc
4113 cancel_lru_locks mdc
4114 sync; sync_all_data || true
4115 if [ $qres_type == "data" ]; then
4116 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4117 quota_error $qtype $qid "write failed, expect succeed"
4119 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4120 quota_error $qtype $qid "create failed, expect succeed"
4122 unlinkmany $TESTFILE $((LIMIT*2))
4127 wait_delete_completed || error "wait_delete_completed failed"
4128 sync_all_data || true
4130 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4131 error "reset default quota failed"
4132 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4133 error "reset quota failed"
4138 test_default_quota "-u" "data"
4139 test_default_quota "-u" "meta"
4140 test_default_quota "-g" "data"
4141 test_default_quota "-g" "meta"
4142 test_default_quota "-p" "data"
4143 test_default_quota "-p" "meta"
4145 run_test 61 "default quota tests"
4148 ! is_project_quota_supported &&
4149 skip "Project quota is not supported"
4150 [[ "$(chattr -h 2>&1)" =~ "project" ||
4151 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4152 skip "chattr did not support project quota"
4153 setup_quota_test || error "setup quota failed with $?"
4154 local testdir=$DIR/$tdir/
4156 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4157 change_project -s $testdir
4158 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4159 error "inherit attribute should be set"
4160 # chattr used FS_IOC_SETFLAGS ioctl
4161 $RUNAS chattr -P $testdir &&
4162 error "regular user clear inherit should fail"
4163 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4164 error "inherit attribute should still be set"
4165 chattr -P $testdir || error "root failed to clear inherit"
4166 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4167 error "inherit attribute should be cleared"
4170 run_test 62 "Project inherit should be only changed by root"
4173 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4174 skip "Not supported before 2.11.55"
4178 local dd_failed=false
4179 local tdir_dom=${tdir}_dom
4180 local LIMIT=20480 #20M
4182 [ $qtype == "p" ] && ! is_project_quota_supported &&
4183 echo "Project quota is not supported" && return 0
4185 [ $qtype == "p" ] && qid=$TSTPRJID
4187 setup_quota_test || error "setup quota failed with $?"
4191 # enable mdt/ost quota
4192 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4193 set_ost_qtype $QTYPE || error "enable ost quota failed"
4195 # make sure the system is clean
4196 local USED=$(getquota -$qtype $qid global curspace)
4197 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4199 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4201 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4202 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4203 error "setstripe $tdir_dom failed"
4204 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4206 [ $qtype == "p" ] && {
4207 change_project -sp $TSTPRJID $DIR/$tdir
4208 change_project -sp $TSTPRJID $DIR/$tdir_dom
4211 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4212 error "set $qid quota failed"
4214 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4215 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4219 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4221 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4222 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4226 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4228 rm -f $DIR/$tdir_dom/*
4230 # flush cache, ensure noquota flag is set on client
4231 cancel_lru_locks osc
4232 cancel_lru_locks mdc
4233 sync; sync_all_data || true
4237 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4238 quota_error $qtype $qid "write failed, expect succeed"
4240 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4241 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4245 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4248 rm -f $DIR/$tdir_dom/*
4250 # flush cache, ensure noquota flag is set on client
4251 cancel_lru_locks osc
4252 cancel_lru_locks mdc
4253 sync; sync_all_data || true
4257 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4258 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4262 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4264 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4265 quota_error $qtype $qid "write succeed, expect EDQUOT"
4268 rm -fr $DIR/$tdir_dom
4270 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4271 error "reset usr quota failed"
4279 run_test 63 "quota on DoM tests"
4282 ! is_project_quota_supported &&
4283 skip "Project quota is not supported"
4284 setup_quota_test || error "setup quota failed with $?"
4285 local dir1="$DIR/$tdir/"
4288 ln -s $dir1/file $dir1/file_link
4291 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4292 error "set project should succeed"
4294 used=$(getquota -p $TSTPRJID global curinodes)
4295 [ $used -eq 4 ] || error "expected 4 got $used"
4296 $LFS project -rC $dir1 >&/dev/null ||
4297 error "clear project should succeed"
4299 used=$(getquota -p $TSTPRJID global curinodes)
4300 [ $used -eq 0 ] || error "expected 0 got $used"
4302 run_test 64 "lfs project on non dir/files should succeed"
4306 local TESTFILE="$DIR/$tdir/$tfile-0"
4308 setup_quota_test || error "setup quota failed with $?"
4309 set_ost_qtype $QTYPE || error "enable ost quota failed"
4313 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4314 error "failed to write"
4315 # flush cache, ensure noquota flag is set on client
4316 cancel_lru_locks osc
4317 sync; sync_all_data || true
4319 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4320 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4321 local quota_all=$($RUNAS $LFS quota $DIR)
4323 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4324 error "usr quota not match"
4325 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4326 error "grp quota not match"
4328 run_test 65 "Check lfs quota result"
4331 ! is_project_quota_supported &&
4332 skip "Project quota is not supported"
4333 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4334 skip "Not supported before 2.12.4"
4335 setup_quota_test || error "setup quota failed with $?"
4336 local old=$(do_facet mds1 $LCTL get_param -n \
4337 mdt.*.enable_chprojid_gid | head -1)
4338 local testdir=$DIR/$tdir/foo
4340 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4341 stack_trap "do_facet mds1 $LCTL \
4342 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4344 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4345 chown -R $TSTID:$TSTID $testdir
4346 change_project -sp $TSTPRJID $testdir
4347 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4349 $RUNAS lfs project -p 0 $testdir/foo &&
4350 error "nonroot user should fail to set projid"
4352 $RUNAS lfs project -C $testdir/foo &&
4353 error "nonroot user should fail to clear projid"
4355 change_project -C $testdir/foo || error "failed to clear project"
4357 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4358 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4359 "failed to set projid with normal user when enable_chprojid_gid=-1"
4361 $RUNAS lfs project -rC $testdir/ || error \
4362 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4364 touch $testdir/bar || error "failed touch $testdir/bar"
4365 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4366 "normal user should not be able to set projid on root owned file"
4368 change_project -p $TSTPRJID $testdir/bar || error \
4369 "root should be able to change its own file's projid"
4371 run_test 66 "nonroot user can not change project state in default"
4378 local short_qtype=${qtype:0:1}
4381 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4383 quota_usr) _runas=$RUNAS;;
4384 quota_2usr) _runas=$RUNAS2;;
4385 *) error "unknown quota parameter $4";;
4390 $_runas $DD of=$file count=$size ||
4391 quota_error $short_qtype $TSTUSR \
4392 "$qtype write failure, but expect success"
4394 cancel_lru_locks osc
4396 sync; sync_all_data || true
4405 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4407 do_facet mds1 $LCTL get_param $param |
4408 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4413 local testfile="$DIR/$tdir/$tfile-0"
4414 local testfile2="$DIR/$tdir/$tfile-1"
4415 local testfile3="$DIR/$tdir/$tfile-2"
4416 local qpool="qpool1"
4422 [ "$ost1_FSTYPE" == zfs ] &&
4423 skip "ZFS grants some block space together with inode"
4425 setup_quota_test || error "setup quota failed with $?"
4428 set_ost_qtype $QTYPE || error "enable ost quota failed"
4431 log "User quota (block hardlimit:$limit MB)"
4432 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4433 error "set user quota failed"
4435 # make sure the system is clean
4436 used=$(getquota -u $TSTUSR global curspace)
4437 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4439 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4440 echo "granted 0x0 before write $granted"
4442 # trigger reintegration
4443 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4444 procf=${procf}quota_slave.force_reint
4445 do_facet ost1 $LCTL set_param $procf=1 ||
4446 error "force reintegration failed"
4447 wait_ost_reint "u" || error "reintegration failed"
4448 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4449 [ $granted -ne 0 ] &&
4450 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4452 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4453 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4455 # write 10 MB to testfile
4456 test_67_write "$testfile" "user" 10 "quota_usr"
4458 # create qpool and add OST1
4459 pool_add $qpool || error "pool_add failed"
4460 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4461 # as quota_usr hasn't limits, lqe may absent. But it should be
4462 # created after the 1st direct qmt_get.
4463 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4465 # check granted - should be 0, as testfile is located only on OST0
4466 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4467 echo "global granted $granted"
4468 granted=$(getgranted $qpool "dt" $TSTID "usr")
4469 echo "$qpool granted $granted"
4470 [ $granted -ne 0 ] &&
4471 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4473 # add OST0 to qpool and check granted space
4474 pool_add_targets $qpool 0 1 ||
4475 error "pool_add_targets failed"
4476 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4477 echo "Granted $granted_mb MB"
4478 #should be 10M + qunit for each OST
4479 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4480 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4482 $LFS setstripe $testfile2 -c 1 -i 1 ||
4483 error "setstripe $testfile2 failed"
4484 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4485 # Write from another user and check that qpool1
4486 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4487 test_67_write "$testfile2" "user" 10 "quota_2usr"
4488 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4489 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4490 [ $granted -ne 0 ] &&
4491 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4493 # Granted space for quota_2usr in qpool1 should appear only
4494 # when global lqe for this user becomes enforced.
4495 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4496 error "set user quota failed"
4497 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4498 echo "granted_mb $granted_mb"
4499 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4500 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4502 $LFS setstripe $testfile3 -c 1 -i 0 ||
4503 error "setstripe $testfile3 failed"
4504 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4505 test_67_write "$testfile3" "user" 10 "quota_2usr"
4506 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4507 echo "$testfile3 granted_mb $granted_mb"
4508 [ $granted_mb -eq $limit ] ||
4509 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4511 # remove OST1 from the qpool1 and check granted space
4512 # should be 0 for TSTUSR and 10M for TSTUSR2
4513 pool_remove_target $qpool 0
4514 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4515 [ $granted_mb -eq 0 ] ||
4516 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4517 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4518 [ $granted_mb -eq 10 ] ||
4519 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4522 wait_delete_completed || error "wait_delete_completed failed"
4523 sync_all_data || true
4524 used=$(getquota -u $TSTUSR global curspace)
4525 [ $used -eq 0 ] || quota_error u $TSTUSR \
4526 "user quota isn't released after deletion"
4528 run_test 67 "quota pools recalculation"
4535 wait_update_facet mds1 \
4536 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4537 >/dev/null 2>&1 || echo foo" "" ||
4538 error "mds1: failed to create quota pool $pool"
4540 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4541 awk '/usr/ {getline; print $2}'
4546 local qpool="qpool1"
4549 setup_quota_test || error "setup quota failed with $?"
4552 set_ost_qtype $QTYPE || error "enable ost quota failed"
4554 # check slave number for glbal pool
4555 local nr=$(get_slave_nr "0x0" "usr")
4556 echo "nr result $nr"
4557 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4558 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4560 # create qpool and add OST1
4561 pool_add $qpool || error "pool_add failed"
4562 nr=$(get_slave_nr $qpool "usr")
4563 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4566 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4567 nr=$(get_slave_nr $qpool "usr")
4568 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4571 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4572 nr=$(get_slave_nr $qpool "usr")
4573 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4576 pool_remove_target $qpool 0
4577 nr=$(get_slave_nr $qpool "usr")
4578 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4581 pool_remove_target $qpool 1
4582 nr=$(get_slave_nr $qpool "usr")
4583 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4585 # Check again that all is fine with global pool
4586 nr=$(get_slave_nr "0x0" "usr")
4587 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4588 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4590 run_test 68 "slave number in quota pool changed after each add/remove OST"
4594 local global_limit=200 # MB
4596 local testfile="$DIR/$tdir/$tfile-0"
4597 local dom0="$DIR/$tdir/dom0"
4598 local qpool="qpool1"
4601 setup_quota_test || error "setup quota failed with $?"
4604 set_ost_qtype $QTYPE || error "enable ost quota failed"
4605 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4607 # Save DOM only at MDT0
4608 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4609 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4611 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4613 # create qpool and add OST0
4614 pool_add $qpool || error "pool_add failed"
4615 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4617 log "User quota (block hardlimit:$global_limit MB)"
4618 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4619 error "set user quota failed"
4621 log "User quota (block hardlimit:$limit MB)"
4622 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4623 error "set user quota failed"
4625 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4626 quota_error u $TSTUSR "write failed"
4628 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4629 oflag=sync || quota_error u $TSTUSR "write failed"
4631 $RUNAS $DD of=$testfile count=$limit || true
4633 # flush cache, ensure noquota flag is set on client
4634 cancel_lru_locks osc
4635 sync; sync_all_data || true
4637 # MDT0 shouldn't get EDQUOT with glimpse.
4638 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4639 quota_error u $TSTUSR \
4640 "user write success, but expect EDQUOT"
4642 # Now all members of qpool1 should get EDQUOT. Expect success
4643 # when write to DOM on MDT0, as it belongs to global pool.
4644 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4645 oflag=sync || quota_error u $TSTUSR "write failed"
4647 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4648 oflag=sync || quota_error u $TSTUSR "write failed"
4650 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4654 local qpool="qpool1"
4659 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4660 skip "Needs a client >= $VERSION_WITH_QP"
4662 setup_quota_test || error "setup quota failed with $?"
4664 # MDS returns EFAULT for unsupported quotactl command
4665 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4667 # create qpool and add OST0
4668 pool_add $qpool || error "pool_add failed"
4669 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4671 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4673 [ $rc -eq $err ] || error "setquota res $rc != $err"
4675 # If MDS supports QP, check that limit was set properly.
4676 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4677 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4678 echo "hard limit $bhard limit $limit"
4679 [ $bhard -ne $((limit*1024)) ] &&
4680 error "bhard:$bhard for $qpool!=$((limit*1024))"
4683 $LFS quota -u $TSTUSR --pool $qpool $DIR
4685 [ $rc -eq $err ] || error "quota res $rc != $err"
4687 run_test 70a "check lfs setquota/quota with a pool option"
4691 local glbl_hard=200 # 200M
4692 local glbl_soft=100 # 100M
4693 local pool_hard=10 # 10M
4694 local qpool="qpool1"
4696 pool_add $qpool || error "pool_add failed"
4697 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4699 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
4700 error "set user quota failed"
4701 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
4702 error "set user quota failed"
4704 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4705 [ $tmp -eq $((pool_hard * 1024)) ] ||
4706 error "wrong block hard limit $tmp for $qpool"
4707 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
4708 # soft limit hasn't been set and should be zero
4709 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
4711 run_test 70b "lfs setquota pool works properly"
4716 local global_limit=100 # MB
4717 local testfile="$DIR/$tdir/$tfile-0"
4718 local qpool="qpool1"
4719 local qpool2="qpool2"
4721 [ "$ost1_FSTYPE" == zfs ] &&
4722 skip "ZFS grants some block space together with inode"
4723 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4725 setup_quota_test || error "setup quota failed with $?"
4728 set_ost_qtype $QTYPE || error "enable ost quota failed"
4731 log "User quota (block hardlimit:$global_limit MB)"
4732 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4733 error "set user quota failed"
4735 pool_add $qpool || error "pool_add failed"
4736 pool_add_targets $qpool 0 1 ||
4737 error "pool_add_targets failed"
4739 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4740 error "set user quota failed"
4742 pool_add $qpool2 || error "pool_add failed"
4743 pool_add_targets $qpool2 1 1 ||
4744 error "pool_add_targets failed"
4746 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4747 error "set user quota failed"
4749 # make sure the system is clean
4750 local used=$(getquota -u $TSTUSR global curspace)
4753 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4755 # create 1st component 1-10M
4756 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4757 #create 2nd component 10-30M
4758 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4759 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4761 # сheck normal use and out of quota with PFL
4762 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4763 test_1_check_write $testfile "user" $((limit*2))
4765 wait_delete_completed || error "wait_delete_completed failed"
4766 sync_all_data || true
4767 used=$(getquota -u $TSTUSR global curspace)
4768 [ $used -ne 0 ] && quota_error u $TSTUSR \
4769 "user quota isn't released after deletion"
4771 # create 1st component 1-10M
4772 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4773 # create 2nd component 10-30M
4774 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4775 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4777 # write to the 2nd component
4778 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4779 quota_error u $TSTUSR \
4780 "write failure, but expect success"
4781 # this time maybe cache write, ignore it's failure
4782 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4783 cancel_lru_locks osc
4784 sync; sync_all_data || true
4785 # write over limit in qpool2(2nd component 10-30M)
4786 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4787 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4788 # write to the 1st component - OST0 is empty
4789 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4790 quota_error u $TSTUSR "write failed"
4792 run_test 71a "Check PFL with quota pools"
4796 local global_limit=1000 # MB
4797 local limit1=160 # MB
4798 local limit2=10 # MB
4799 local testfile="$DIR/$tdir/$tfile-0"
4800 local qpool="qpool1"
4801 local qpool2="qpool2"
4803 [ "$ost1_FSTYPE" == zfs ] &&
4804 skip "ZFS grants some block space together with inode"
4805 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4807 setup_quota_test || error "setup quota failed with $?"
4810 set_ost_qtype $QTYPE || error "enable ost quota failed"
4813 log "User quota (block hardlimit:$global_limit MB)"
4814 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4815 error "set user quota failed"
4817 pool_add $qpool || error "pool_add failed"
4818 pool_add_targets $qpool 0 1 ||
4819 error "pool_add_targets failed"
4821 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4822 error "set user quota failed"
4824 pool_add $qpool2 || error "pool_add failed"
4825 pool_add_targets $qpool2 1 1 ||
4826 error "pool_add_targets failed"
4828 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4829 error "set user quota failed"
4831 # make sure the system is clean
4832 local used=$(getquota -u $TSTUSR global curspace)
4835 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4837 # First component is on OST0, 2nd on OST1
4838 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4839 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4841 # fill the 1st component on OST0
4842 $RUNAS $DD of=$testfile count=128 ||
4843 quota_error u $TSTUSR "write failed"
4844 # write to the 2nd cmpnt on OST1
4845 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4846 quota_error u $TSTUSR "write failed"
4847 # this time maybe cache write, ignore it's failure
4848 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4850 cancel_lru_locks osc
4851 sync; sync_all_data || true
4852 # write over limit in qpool2
4853 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4854 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4857 run_test 71b "Check SEL with quota pools"
4862 local global_limit=50 # MB
4863 local testfile="$DIR/$tdir/$tfile-0"
4864 local qpool="qpool1"
4867 setup_quota_test || error "setup quota failed with $?"
4870 set_ost_qtype $QTYPE || error "enable ost quota failed"
4873 log "User quota (block hardlimit:$global_limit MB)"
4874 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4875 error "set user quota failed"
4877 pool_add $qpool || error "pool_add failed"
4878 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4880 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4881 error "set user quota failed"
4883 # make sure the system is clean
4884 local used=$(getquota -u $TSTUSR global curspace)
4886 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4888 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4890 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4891 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4892 test_1_check_write $testfile "user" $limit
4893 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4895 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4896 # check that lfs quota -uv --pool prints only OST that
4897 # was added in a pool
4898 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4899 grep "OST\|MDT" && error "$qpool consists wrong targets"
4902 run_test 72 "lfs quota --pool prints only pool's OSTs"
4906 local qpool="qpool1"
4910 pool_add $qpool || error "pool_add failed"
4911 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4912 error "pool_add_targets failed"
4914 test_default_quota "-u" "data" "qpool1"
4916 run_test 73a "default limits at OST Pool Quotas"
4920 local TESTFILE1="$DIR/$tdir/$tfile-1"
4922 local qpool="qpool1"
4926 setup_quota_test || error "setup quota failed with $?"
4928 set_ost_qtype $QTYPE || error "enable ost quota failed"
4930 # pool quotas don't work properly without global limit
4931 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4932 error "set global limit failed"
4934 pool_add $qpool || error "pool_add failed"
4935 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4936 error "pool_add_targets failed"
4938 log "set default quota for $qpool"
4939 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
4940 error "set default quota failed"
4942 log "Write from user that hasn't lqe"
4943 # Check that it doesn't cause a panic or a deadlock
4944 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
4945 # Have to use RUNAS_ID as resetquota creates lqes in
4946 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
4947 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
4949 cancel_lru_locks osc
4950 sync; sync_all_data || true
4952 run_test 73b "default OST Pool Quotas limit for new user"
4956 local global_limit=200 # 200M
4957 local limit=10 # 10M
4958 local limit2=50 # 50M
4959 local qpool="qpool1"
4960 local qpool2="qpool2"
4964 setup_quota_test || error "setup quota failed with $?"
4967 set_ost_qtype $QTYPE || error "enable ost quota failed"
4969 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4970 error "set user quota failed"
4972 pool_add $qpool || error "pool_add failed"
4973 pool_add_targets $qpool 0 1 ||
4974 error "pool_add_targets failed"
4976 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4977 error "set user quota failed"
4979 pool_add $qpool2 || error "pool_add failed"
4980 pool_add_targets $qpool2 1 1 ||
4981 error "pool_add_targets failed"
4983 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4984 error "set user quota failed"
4986 tmp=$(getquota -u $TSTUSR global bhardlimit)
4987 [ $tmp -eq $((global_limit * 1024)) ] ||
4988 error "wrong global limit $global_limit"
4990 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4991 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
4993 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
4994 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
4996 # check limits in pools
4997 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4998 grep -A4 $qpool | awk 'NR == 4{print $4}')
4999 echo "pool limit for $qpool $tmp"
5000 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5001 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5002 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5003 echo "pool limit for $qpool2 $tmp"
5004 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5006 run_test 74 "check quota pools per user"
5008 function cleanup_quota_test_75()
5010 do_facet mgs $LCTL nodemap_modify --name default \
5011 --property admin --value 1
5012 do_facet mgs $LCTL nodemap_modify --name default \
5013 --property trusted --value 1
5014 do_facet mgs $LCTL nodemap_modify --name default \
5015 --property squash_uid --value 99
5016 do_facet mgs $LCTL nodemap_modify --name default \
5017 --property squash_gid --value 99
5019 wait_nm_sync default admin_nodemap
5020 wait_nm_sync default trusted_nodemap
5022 do_facet mgs $LCTL nodemap_activate 0
5025 resetquota -u $TSTUSR
5029 local dd_failed=false
5030 local LIMIT=20480 #20M
5033 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5034 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5035 oflag=sync || dd_failed=true
5038 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5040 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5041 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5042 oflag=sync || dd_failed=true
5045 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5047 rm -f $DIR/$tdir_dom/*
5049 # flush cache, ensure noquota flag is set on client
5051 sync; sync_all_data || true
5055 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
5056 quota_error u $qid "write failed, expect succeed (2)"
5058 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5059 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5060 oflag=sync || dd_failed=true
5063 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5066 rm -f $DIR/$tdir_dom/*
5068 # flush cache, ensure noquota flag is set on client
5070 sync; sync_all_data || true
5074 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5075 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5076 oflag=sync || dd_failed=true
5079 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5081 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
5082 quota_error u $qid "write succeed, expect EDQUOT (3)"
5088 local soft_limit=10 # MB
5089 local hard_limit=20 # MB
5090 local limit=$soft_limit
5091 local testfile="$DIR/$tdir/$tfile-0"
5092 local grace=20 # seconds
5093 local tdir_dom=${tdir}_dom
5095 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5099 setup_quota_test || error "setup quota failed with $?"
5100 stack_trap cleanup_quota_test_75 EXIT
5103 set_ost_qtype $QTYPE || error "enable ost quota failed"
5104 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5106 local used=$(getquota -u $TSTID global curspace)
5107 $LFS setquota -t -u --block-grace $grace --inode-grace \
5108 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5109 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5110 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5111 error "set user quota failed"
5113 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5114 mkdir $DIR/$tdir_dom
5115 chmod 777 $DIR/$tdir_dom
5116 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5117 error "setstripe $tdir_dom failed"
5119 do_facet mgs $LCTL nodemap_activate 1
5121 do_facet mgs $LCTL nodemap_modify --name default \
5122 --property admin --value 0
5123 do_facet mgs $LCTL nodemap_modify --name default \
5124 --property trusted --value 0
5125 do_facet mgs $LCTL nodemap_modify --name default \
5126 --property deny_unknown --value 0
5127 do_facet mgs $LCTL nodemap_modify --name default \
5128 --property squash_uid --value $TSTID
5129 do_facet mgs $LCTL nodemap_modify --name default \
5130 --property squash_gid --value $TSTID
5131 cancel_lru_locks mdc
5132 wait_nm_sync default admin_nodemap
5133 wait_nm_sync default trusted_nodemap
5134 wait_nm_sync default squash_uid
5136 # mmap write when over soft limit
5138 $DD of=$testfile count=${limit} ||
5139 quota_error a "root write failure, but expect success (1)"
5140 OFFSET=$((limit * 1024))
5141 cancel_lru_locks osc
5143 echo "Write to exceed soft limit"
5144 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5145 quota_error a $TSTUSR "root write failure, but expect success (2)"
5146 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5147 cancel_lru_locks osc
5149 echo "mmap write when over soft limit"
5150 $MULTIOP $testfile.mmap OT40960SMW ||
5151 quota_error a $TSTUSR "mmap write failure, but expect success"
5152 cancel_lru_locks osc
5154 wait_delete_completed || error "wait_delete_completed failed (1)"
5155 sync_all_data || true
5157 # test for user hard limit
5160 $DD of=$testfile bs=1M count=$((limit/2)) ||
5161 quota_error u $TSTID \
5162 "root write failure, but expect success (3)"
5164 log "Write out of block quota ..."
5165 # possibly a cache write, ignore failure
5166 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
5167 # flush cache, ensure noquota flag is set on client
5168 cancel_lru_locks osc
5169 sync; sync_all_data || true
5170 # sync forced cache flush, but did not guarantee that slave
5171 # got new edquot through glimpse, so wait to make sure
5173 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
5174 quota_error u $TSTID \
5175 "user write success, but expect EDQUOT"
5177 wait_delete_completed || error "wait_delete_completed failed (2)"
5178 sync_all_data || true
5179 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5180 quota_error u $TSTID "user quota not released after deletion"
5184 run_test 75 "nodemap squashed root respects quota enforcement"
5187 ! is_project_quota_supported &&
5188 skip "skip project quota unsupported"
5190 setup_quota_test || error "setup quota failed with $?"
5193 local testfile="$DIR/$tdir/$tfile-0"
5196 $LFS project -p 4294967295 $testfile &&
5197 error "set project ID should fail"
5200 run_test 76 "project ID 4294967295 should be not allowed"
5204 mount_client $MOUNT2 "ro"
5205 lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5206 error "lfs setquota should fail in read-only Lustre mount"
5209 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5213 (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
5214 skip "need OST at least 2.14.55"
5215 check_set_fallocate_or_skip
5217 setup_quota_test || error "setup quota failed with $?"
5220 set_ost_qtype $QTYPE || error "enable ost quota failed"
5222 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5223 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5226 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5227 error "lfs setquota failed"
5230 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5232 kbytes=$(lfs quota -u $TSTUSR $DIR |
5233 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5234 echo "kbytes returned:$kbytes"
5236 # For file size of 204800. We should be having roughly 200 kbytes
5237 # returned. Anything alarmingly low (50 taken as arbitrary value)
5238 # would bail out this TC. Also this also avoids $kbytes of 0
5239 # to be used in calculation below.
5240 (( $kbytes > 50 )) ||
5241 error "fallocate did not use quota. kbytes returned:$kbytes"
5243 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5244 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5246 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5247 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5248 error "fallocate did not use quota correctly"
5250 run_test 78 "Check fallocate increase quota usage"
5254 (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
5255 skip "need client at least 2.15.0"
5256 (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
5257 skip "need OST at least 2.15.0"
5258 check_set_fallocate_or_skip
5260 setup_quota_test || error "setup quota failed with $?"
5263 set_ost_qtype $QTYPE || error "enable ost quota failed"
5265 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5267 local projectid=5200 # Random project id to test
5269 change_project -sp $projectid $DIR/$tdir
5272 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5273 error "lfs setquota project failed"
5276 fallocate -l 204800 $DIR/$tdir/$tfile
5278 # Get curspace (kbytes) for $projectid
5279 local kbytes=$(getquota -p $projectid global curspace)
5281 echo "kbytes returned:$kbytes"
5283 # For file size of 204800. We should be having roughly 200 kbytes
5284 # returned. Anything alarmingly low (50 taken as arbitrary value)
5285 # would bail out this TC. Also this also avoids $kbytes of 0
5286 # to be used in calculation below.
5287 (( $kbytes > 50 )) ||
5288 error "fallocate did not use projectid. kbytes returned:$kbytes"
5290 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5291 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5293 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5294 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5295 error "fallocate did not use quota projectid correctly"
5297 run_test 78a "Check fallocate increase projectid usage"
5301 local qpool="qpool1"
5302 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5303 local stopf=$TMP/$tfile
5305 do_facet mds1 "touch $stopf"
5306 stack_trap "do_facet mds1 'rm -f $stopf'"
5307 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5309 pool_add $qpool || error "pool_add failed"
5310 do_facet mds1 "rm $stopf"
5313 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5317 local dir1="$DIR/$tdir/dir1"
5318 local dir2="$DIR/$tdir/dir2"
5319 local TESTFILE0="$dir1/$tfile-0"
5320 local TESTFILE1="$dir1/$tfile-1"
5321 local TESTFILE2="$dir1/$tfile-2"
5322 local TESTFILE3="$dir2/$tfile-0"
5323 local global_limit=100 # 100M
5324 local limit=10 # 10M
5325 local qpool="qpool1"
5327 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5329 [ "$ost1_FSTYPE" == zfs ] &&
5330 skip "ZFS grants some block space together with inode"
5331 setup_quota_test || error "setup quota failed with $?"
5332 set_ost_qtype $QTYPE || error "enable ost quota failed"
5334 # make sure the system is clean
5335 local used=$(getquota -u $TSTUSR global curspace)
5336 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5338 pool_add $qpool || error "pool_add failed"
5339 pool_add_targets $qpool 0 1 ||
5340 error "pool_add_targets failed"
5342 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5343 error "set user quota failed"
5345 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5346 error "set user quota failed"
5347 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5348 error "set user quota failed"
5350 mkdir -p $dir1 || error "failed to mkdir"
5351 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5352 mkdir -p $dir2 || error "failed to mkdir"
5353 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5355 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5356 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5361 $LFS quota -uv $TSTUSR $DIR
5362 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5363 do_facet mds1 $LCTL set_param fail_loc=0xa06
5364 $RUNAS $DD of=$TESTFILE3 count=3 ||
5365 quota_error u $TSTUSR "write failed"
5366 $RUNAS $DD of=$TESTFILE2 count=7 ||
5367 quota_error u $TSTUSR "write failed"
5368 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5369 quota_error u $TSTUSR "write failed"
5372 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5376 do_facet mds1 $LCTL set_param fail_loc=0
5377 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5378 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5379 # OST0 needs some time to update quota usage after removing TESTFILE2
5381 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5382 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5383 quota_error u $TSTUSR "write failure, but expect success"
5385 run_test 80 "check for EDQUOT after OST failover"
5388 local global_limit=20 # 100M
5389 local testfile="$DIR/$tdir/$tfile-0"
5390 local qpool="qpool1"
5393 setup_quota_test || error "setup quota failed with $?"
5396 set_ost_qtype $QTYPE || error "enable ost quota failed"
5399 log "User quota (block hardlimit:$global_limit MB)"
5400 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5402 pool_add $qpool || error "pool_add failed"
5403 #define OBD_FAIL_QUOTA_RECALC 0xA07
5404 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5405 # added OST casues to start pool recalculation
5406 pool_add_targets $qpool 0 0 1
5407 stop mds1 -f || error "MDS umount failed"
5409 #start mds1 back to destroy created pool
5410 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5413 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5417 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
5418 skip "need MDS 2.14.55 or later"
5419 is_project_quota_supported ||
5420 skip "skip project quota unsupported"
5422 setup_quota_test || error "setup quota failed with $?"
5423 stack_trap cleanup_quota_test
5426 local parent_dir="$DIR/$tdir.parent"
5427 local child_dir="$parent_dir/child"
5430 stack_trap "chown -R 0:0 $parent_dir"
5432 chown $TSTUSR:$TSTUSR $parent_dir ||
5433 error "failed to chown on $parent_dir"
5434 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5435 error "failed to chown on $parent_dir"
5437 $LFS project -p 1000 $parent_dir ||
5438 error "failed to set project id on $parent_dir"
5439 $LFS project -p 1001 $child_dir ||
5440 error "failed to set project id on $child_dir"
5442 rmdir $child_dir || error "cannot remove child dir, test failed"
5444 run_test 82 "verify more than 8 qids for single operation"
5448 do_nodes $(comma_list $(nodes_list)) \
5449 "lctl set_param -n debug=-quota,trace"
5450 if $PQ_CLEANUP; then
5451 disable_project_quota
5454 reset_quota_settings
5459 check_and_cleanup_lustre
5460 export QUOTA_AUTO=$QUOTA_AUTO_OLD