3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
33 TSTID=${TSTID:-"$(id -u $TSTUSR)"}
34 TSTID2=${TSTID2:-"$(id -u $TSTUSR2)"}
35 TSTPRJID=${TSTPRJID:-1000}
40 VERSION_WITH_QP="2.13.53"
42 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
43 skip "Needs MDS version $VERSION_WITH_QP or later."
46 require_dsh_mds || exit 0
47 require_dsh_ost || exit 0
49 # Does e2fsprogs support quota feature?
50 if [ "$mds1_FSTYPE" == ldiskfs ] &&
51 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
52 grep -q 'quota'"; then
53 skip_env "e2fsprogs doesn't support quota"
56 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
58 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
63 QUOTA_AUTO_OLD=$QUOTA_AUTO
66 check_and_setup_lustre
68 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
69 is_project_quota_supported || echo "project quota not supported/enabled"
71 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
72 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
73 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
74 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
75 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
76 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
77 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
78 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
83 local fail_val=${3:-0}
87 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
88 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
89 ost) NODES="$(comma_list $(osts_nodes))";;
92 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
98 lfs project $* || error "lfs project $* failed"
101 RUNAS="runas -u $TSTID -g $TSTID"
102 RUNAS2="runas -u $TSTID2 -g $TSTID2"
103 DD="dd if=/dev/zero bs=1M"
107 # clear quota limits for a user or a group
108 # usage: resetquota -u username
109 # resetquota -g groupname
110 # resetquota -p projid
113 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
114 error "clear quota for [type:$1 name:$2] failed"
118 (( "$#" == 2 )) || error "resetquota: wrong number of arguments: '$*'"
119 [[ "$1" == "-u" || "$1" == "-g" || "$1" == "-p" ]] ||
120 error "resetquota: wrong quota type '$1' passed"
122 resetquota_one "$1" "$2"
124 # give a chance to slave to release space
133 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
134 $LFS quota -v -u $local_id $DIR
135 count=$($LFS find --user $local_id $DIR | wc -l)
136 log "Files for user ($local_id), count=$count:"
137 ($LFS find --user $local_id $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
142 $LFS quota -v -g $local_id $DIR
143 count=$($LFS find --group $local_id $DIR | wc -l)
144 log "Files for group ($local_id), count=$count:"
145 ($LFS find --group $local_id $DIR | head -n 4 |
146 xargs stat 2>/dev/null)
149 is_project_quota_supported || return 0
150 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
151 $LFS quota -v -p $TSTPRJID $DIR
152 count=$($LFS find --projid $TSTPRJID $DIR | wc -l)
153 log "Files for project ($TSTPRJID), count=$count:"
154 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
155 xargs stat 2>/dev/null)
171 # get quota for a user or a group
172 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
173 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
180 sync_all_data > /dev/null 2>&1 || true
182 [ "$#" != 4 -a "$#" != 5 ] &&
183 error "getquota: wrong number of arguments: $#"
184 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
185 error "getquota: wrong u/g/p specifier $1 passed"
198 *) error "unknown quota parameter $4";;
201 [ ! -z "$5" ] && pool_arg="--pool $5 "
202 [ "$uuid" = "global" ] && uuid=$DIR
204 $LFS quota -v "$1" "$2" $pool_arg $DIR |
205 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
206 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
211 # usage: set_mdt_qtype ugp|u|g|p|none
215 local mdts=$(get_facets MDS)
217 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
218 qtype=$(tr -d 'p' <<<$qtype)
220 if [[ $PERM_CMD == *"set_param -P"* ]]; then
221 do_facet mgs $PERM_CMD \
222 osd-*.$FSNAME-MDT*.quota_slave.enabled=$qtype
224 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
226 # we have to make sure each MDT received config changes
227 for mdt in ${mdts//,/ }; do
229 cmd="$LCTL get_param -n "
230 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
231 cmd=${cmd}.quota_slave.enabled
233 if $(facet_up $mdt); then
234 wait_update_facet $mdt "$cmd" "$qtype" || return 1
241 # usage: set_ost_qtype ugp|u|g|p|none
245 local osts=$(get_facets OST)
247 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
248 qtype=$(tr -d 'p' <<<$qtype)
250 if [[ $PERM_CMD == *"set_param -P"* ]]; then
251 do_facet mgs $PERM_CMD \
252 osd-*.$FSNAME-OST*.quota_slave.enabled=$qtype
254 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
256 # we have to make sure each OST received config changes
257 for ost in ${osts//,/ }; do
259 cmd="$LCTL get_param -n "
260 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
261 cmd=${cmd}.quota_slave.enabled
263 if $(facet_up $ost); then
264 wait_update_facet $ost "$cmd" "$qtype" || return 1
270 wait_reintegration() {
274 local result="glb[1],slv[1],reint[0]"
279 if [ $ntype == "mdt" ]; then
280 tgts=$(get_facets MDS)
282 tgts=$(get_facets OST)
285 for tgt in ${tgts//,/ }; do
287 cmd="$LCTL get_param -n "
288 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
289 cmd=${cmd}.quota_slave.info
291 if $(facet_up $tgt); then
292 # reintegration starts after recovery completion
293 wait_recovery_complete $tgt
294 wait_update_facet $tgt "$cmd |
295 grep "$qtype" | awk '{ print \\\$3 }'" \
296 "$result" $max || return 1
306 if [[ "$qtype" =~ "u" ]]; then
307 wait_reintegration "mdt" "user" $max || return 1
310 if [[ "$qtype" =~ "g" ]]; then
311 wait_reintegration "mdt" "group" $max || return 1
314 if [[ "$qtype" =~ "p" ]]; then
315 ! is_project_quota_supported && return 0
316 wait_reintegration "mdt" "project" $max || return 1
325 if [[ "$qtype" =~ "u" ]]; then
326 wait_reintegration "ost" "user" $max || return 1
329 if [[ "$qtype" =~ "g" ]]; then
330 wait_reintegration "ost" "group" $max || return 1
333 if [[ "$qtype" =~ "p" ]]; then
334 ! is_project_quota_supported && return 0
335 wait_reintegration "ost" "project" $max || return 1
344 local extrasleep=${4:-5}
351 *) error "get_grace_time: Invalid quota type: $qtype"
356 echo "Quota info for $pool:"
357 $LFS quota -$qtype $qarg $parg $DIR
362 time=$(lfs quota -$qtype $qarg $parg $DIR|
363 awk 'NR == 3{ print $5 }')
366 time=$(lfs quota -$qtype $qarg $DIR|
367 awk 'NR == 3{ print $9 }')
370 error "Unknown quota type: $flavour"
374 local sleep_seconds=0
375 local orig_time=$time
377 echo "Grace time is $time"
378 # from lfs.c:__sec2str()
379 # const char spec[] = "smhdw";
380 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
381 [[ $time == *w* ]] && w_time=${time%w*} &&
382 let sleep_seconds+=$((w_time*7*24*60*60));
384 [[ $time == *d* ]] && d_time=${time%d*} &&
385 let sleep_seconds+=$((d_time*24*60*60));
387 [[ $time == *h* ]] && h_time=${time%h*} &&
388 let sleep_seconds+=$((h_time*60*60));
390 [[ $time == *m* ]] && m_time=${time%m*} &&
391 let sleep_seconds+=$((m_time*60));
393 [[ $time == *s* ]] && s_time=${time%s*} &&
394 let sleep_seconds+=$s_time
396 echo "Sleep through grace ..."
397 [ "$orig_time" == "-" ] &&
398 error "Grace timeout was not set or quota not exceeded"
399 if [ "$orig_time" == "expired" -o "$orig_time" == "none" ]; then
400 echo "...Grace timeout already expired"
402 let sleep_seconds+=$extrasleep
403 echo "...sleep $sleep_seconds seconds"
409 wait_delete_completed
410 echo "Creating test directory"
411 mkdir_on_mdt0 $DIR/$tdir || return 1
412 chmod 0777 $DIR/$tdir || return 2
413 # always clear fail_loc in case of fail_loc isn't cleared
414 # properly when previous test failed
415 lustre_fail mds_ost 0
416 stack_trap cleanup_quota_test EXIT
419 cleanup_quota_test() {
420 echo "Delete files..."
422 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
423 echo "Wait for unlink objects finished..."
424 wait_delete_completed
425 sync_all_data || true
435 $LFS quota -v -$ugp $qid $DIR
437 if [ "$bf" == "a" -o "$bf" == "b" ]; then
438 usage=$(getquota -$ugp $qid global curspace)
439 if [ -z $usage ]; then
440 quota_error $ugp $qid \
441 "Query block quota failed ($ugp:$qid)."
443 [ $usage -ne 0 ] && quota_log $ugp $qid \
444 "Block quota isn't 0 ($ugp:$qid:$usage)."
448 if [ "$bf" == "a" -o "$bf" == "f" ]; then
449 usage=$(getquota -$ugp $qid global curinodes)
450 if [ -z $usage ]; then
451 quota_error $ugp $qid \
452 "Query file quota failed ($ugp:$qid)."
454 [ $usage -ne 0 ] && quota_log $ugp $qid \
455 "File quota isn't 0 ($ugp:$qid:$usage)."
460 project_quota_enabled () {
462 local zfeat="feature@project_quota"
464 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
465 local facet_fstype=${facet:0:3}1_FSTYPE
468 if [ "${!facet_fstype}" = "zfs" ]; then
469 devname=$(zpool_name ${facet})
470 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
471 grep -wq active || rc=1
473 [ ${facet:0:3} == "mds" ] &&
474 devname=$(mdsdevname ${facet:3}) ||
475 devname=$(ostdevname ${facet:3})
476 do_facet ${facet} $DEBUGFS -R features $devname |
477 grep -q project || rc=1
480 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
484 project_quota_enabled || enable_project_quota
486 reset_quota_settings() {
487 resetquota_one -u $TSTUSR
488 [[ $(id -u $TSTUSR) == $TSTID ]] || resetquota_one -u $TSTID
489 resetquota_one -g $TSTUSR
490 [[ $(id -g $TSTUSR) == $TSTID ]] || resetquota_one -g $TSTID
491 resetquota_one -u $TSTUSR2
492 [[ $(id -u $TSTUSR2) == $TSTID2 ]] || resetquota_one -u $TSTID2
493 resetquota_one -g $TSTUSR2
494 [[ $(id -g $TSTUSR2) == $TSTID2 ]] || resetquota_one -g $TSTID2
495 is_project_quota_supported && resetquota_one -p $TSTPRJID
511 usr) qtype="limit_user";;
512 grp) qtype="limit_group";;
513 prj) qtype="limit_project";;
514 *) error "unknown quota parameter $3";;
521 *) error "unknown quota parameter $5";;
524 do_facet $facet $LCTL get_param osd-*.*-${device}.quota_slave.$qtype |
525 awk '($3 == '$qid') {getline; print $'$spec'; exit;}' | tr -d ,
528 wait_quota_synced() {
538 value=$(get_quota_on_qsd $facet $device $qtype $qid $limit_type)
539 while [[ $value != $limit_val ]]; do
540 (( interval != 0 )) ||
541 do_facet $facet $LCTL set_param \
542 osd-*.*-${device}.quota_slave.force_reint=1
545 (( interval <= 20 )) ||
546 error "quota ($value) don't update on QSD, $limit_val"
548 interval=$((interval + 1))
551 value=$(get_quota_on_qsd $facet $device $qtype $qid $limit_type)
557 do_nodes $(comma_list $(nodes_list)) \
558 "$LCTL set_param -n debug=+quota+trace"
563 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
564 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
565 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
566 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
568 test_quota_performance() {
569 local TESTFILE="$DIR/$tdir/$tfile-0"
570 local size=$1 # in MB
571 local stime=$(date +%s)
572 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
573 quota_error u $TSTUSR "write failure"
574 local etime=$(date +%s)
575 delta=$((etime - stime))
576 if [ $delta -gt 0 ]; then
577 rate=$((size * 1024 / delta))
578 if [ "$mds1_FSTYPE" = zfs ]; then
579 # LU-2872 - see LU-2887 for fix
581 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
583 [ $rate -gt 1024 ] ||
584 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
590 # test basic quota performance b=21696
593 [ "$SLOW" = "no" ] && MB=10
595 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
596 [ $free_space -le $((MB * 1024)) ] &&
597 skip "not enough space ${free_space} KB, " \
598 "required $((MB * 1024)) KB"
599 setup_quota_test || error "setup quota failed with $?"
601 set_ost_qtype "none" || error "disable ost quota failed"
602 test_quota_performance $MB
604 set_ost_qtype $QTYPE || error "enable ost quota failed"
605 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
606 error "set quota failed"
607 test_quota_performance $MB
609 run_test 0 "Test basic quota performance"
611 # usage: test_1_check_write tfile user|group|project
612 test_1_check_write() {
616 local short_qtype=${qtype:0:1}
619 $RUNAS $DD of=$testfile count=$((limit/2)) ||
620 quota_error $short_qtype $TSTUSR \
621 "$qtype write failure, but expect success"
622 log "Write out of block quota ..."
623 # this time maybe cache write, ignore it's failure
624 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
625 # flush cache, ensure noquota flag is set on client
627 sync; sync_all_data || true
628 # sync means client wrote all it's cache, but id doesn't
629 # guarantee that slave received new edquot through glimpse.
630 # so wait a little to be sure slave got it.
632 $RUNAS $DD of=$testfile count=1 seek=$limit &&
633 quota_error $short_qtype $TSTUSR \
634 "user write success, but expect EDQUOT"
638 check_write_fallocate() {
642 local short_qtype=${qtype:0:1}
645 log "Write ${count}MiB Using Fallocate"
646 $RUNAS fallocate -l${count}MiB $testfile ||
647 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
650 sync; sync_all_data || true
654 log "Write ${count}MiB Using Fallocate"
655 $RUNAS fallocate -l${count}MiB $testfile &&
656 quota_error $short_qtype $TSTUSR \
657 "Write success, expect EDQUOT" || true
660 # test block hardlimit
663 local testfile="$DIR/$tdir/$tfile-0"
665 setup_quota_test || error "setup quota failed with $?"
668 set_ost_qtype $QTYPE || error "enable ost quota failed"
671 log "User quota (block hardlimit:$limit MB)"
672 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
673 error "set user quota failed"
675 # make sure the system is clean
676 local used=$(getquota -u $TSTUSR global curspace)
677 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
679 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
680 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
682 test_1_check_write $testfile "user" $limit
685 wait_delete_completed || error "wait_delete_completed failed"
686 sync_all_data || true
687 used=$(getquota -u $TSTUSR global curspace)
688 [ $used -ne 0 ] && quota_error u $TSTUSR \
689 "user quota isn't released after deletion"
690 resetquota -u $TSTUSR
693 log "--------------------------------------"
694 log "Group quota (block hardlimit:$limit MB)"
695 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
696 error "set group quota failed"
698 testfile="$DIR/$tdir/$tfile-1"
699 # make sure the system is clean
700 used=$(getquota -g $TSTUSR global curspace)
701 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
703 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
704 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
706 test_1_check_write $testfile "group" $limit
708 wait_delete_completed || error "wait_delete_completed failed"
709 sync_all_data || true
710 used=$(getquota -g $TSTUSR global curspace)
711 [ $used -ne 0 ] && quota_error g $TSTUSR \
712 "Group quota isn't released after deletion"
713 resetquota -g $TSTUSR
715 if ! is_project_quota_supported; then
716 echo "Project quota is not supported"
720 testfile="$DIR/$tdir/$tfile-2"
721 # make sure the system is clean
722 used=$(getquota -p $TSTPRJID global curspace)
724 error "used space($used) for project $TSTPRJID isn't 0"
727 log "--------------------------------------"
728 log "Project quota (block hardlimit:$limit mb)"
729 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
730 error "set project quota failed"
732 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
733 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
734 change_project -p $TSTPRJID $testfile
736 test_1_check_write $testfile "project" $limit
741 used=$(getquota -p $TSTPRJID global curspace)
742 [ $used -ne 0 ] && quota_error p $TSTPRJID \
743 "project quota isn't released after deletion"
745 resetquota -p $TSTPRJID
747 run_test 1a "Block hard limit (normal use and out of quota)"
750 (( MDS1_VERSION >= $(version_code 2.15.55) )) ||
751 skip "Need MDS version at least 2.15.55"
754 local global_limit=20 # MB
755 local testfile="$DIR/$tdir/$tfile-0"
759 setup_quota_test || error "setup quota failed with $?"
762 set_ost_qtype $QTYPE || error "enable ost quota failed"
765 log "User quota (block hardlimit:$global_limit MB)"
766 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
767 error "set user quota failed"
769 pool_add $qpool || error "pool_add failed"
770 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
771 error "pool_add_targets failed"
773 # check qmt_pool_add dmesg error
774 local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
776 dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
777 [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
779 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
780 error "set user quota failed"
782 # make sure the system is clean
783 local used=$(getquota -u $TSTUSR global curspace)
785 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
787 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
789 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
790 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
792 test_1_check_write $testfile "user" $limit
795 wait_delete_completed || error "wait_delete_completed failed"
796 sync_all_data || true
797 used=$(getquota -u $TSTUSR global curspace $qpool)
798 [ $used -ne 0 ] && quota_error u $TSTUSR \
799 "user quota isn't released after deletion"
800 resetquota -u $TSTUSR
803 log "--------------------------------------"
804 log "Group quota (block hardlimit:$global_limit MB)"
805 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
806 error "set group quota failed"
808 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
809 error "set group quota failed"
811 testfile="$DIR/$tdir/$tfile-1"
812 # make sure the system is clean
813 used=$(getquota -g $TSTUSR global curspace $qpool)
814 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
816 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
817 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
819 test_1_check_write $testfile "group" $limit
822 wait_delete_completed || error "wait_delete_completed failed"
823 sync_all_data || true
824 used=$(getquota -g $TSTUSR global curspace $qpool)
825 [ $used -ne 0 ] && quota_error g $TSTUSR \
826 "Group quota isn't released after deletion"
827 resetquota -g $TSTUSR
829 if ! is_project_quota_supported; then
830 echo "Project quota is not supported"
834 testfile="$DIR/$tdir/$tfile-2"
835 # make sure the system is clean
836 used=$(getquota -p $TSTPRJID global curspace $qpool)
838 error "used space($used) for project $TSTPRJID isn't 0"
841 log "--------------------------------------"
842 log "Project quota (block hardlimit:$global_limit mb)"
843 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
844 error "set project quota failed"
846 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
847 error "set project quota failed"
850 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
851 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
852 change_project -p $TSTPRJID $testfile
854 test_1_check_write $testfile "project" $limit
859 used=$(getquota -p $TSTPRJID global curspace)
860 [ $used -eq 0 ] || quota_error p $TSTPRJID \
861 "project quota isn't released after deletion"
863 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
866 local global_limit=20 # MB
867 local testfile="$DIR/$tdir/$tfile-0"
868 local qpool1="qpool1"
869 local qpool2="qpool2"
872 setup_quota_test || error "setup quota failed with $?"
875 set_ost_qtype $QTYPE || error "enable ost quota failed"
878 log "User quota (block hardlimit:$global_limit MB)"
879 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
880 error "set user quota failed"
882 pool_add $qpool1 || error "pool_add failed"
883 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
884 error "pool_add_targets failed"
886 pool_add $qpool2 || error "pool_add failed"
887 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
888 error "pool_add_targets failed"
890 # create pools without hard limit
891 # initially such case raised several bugs
892 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
893 error "set user quota failed"
895 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
896 error "set user quota failed"
898 # make sure the system is clean
899 local used=$(getquota -u $TSTUSR global curspace)
901 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
903 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
905 test_1_check_write $testfile "user" $global_limit
907 used=$(getquota -u $TSTUSR global curspace $qpool1)
908 echo "qpool1 used $used"
909 used=$(getquota -u $TSTUSR global curspace $qpool2)
910 echo "qpool2 used $used"
913 wait_delete_completed || error "wait_delete_completed failed"
914 sync_all_data || true
916 used=$(getquota -u $TSTUSR global curspace $qpool1)
917 [ $used -eq 0 ] || quota_error u $TSTUSR \
918 "user quota isn't released after deletion"
920 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
925 local global_limit=20 # MB
926 local testfile="$DIR/$tdir/$tfile-0"
927 local qpool1="qpool1"
928 local qpool2="qpool2"
931 setup_quota_test || error "setup quota failed with $?"
934 set_ost_qtype $QTYPE || error "enable ost quota failed"
937 log "User quota (block hardlimit:$global_limit MB)"
938 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
939 error "set user quota failed"
941 pool_add $qpool1 || error "pool_add failed"
942 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
943 error "pool_add_targets failed"
945 pool_add $qpool2 || error "pool_add failed"
946 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
947 error "pool_add_targets failed"
949 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
950 error "set user quota failed"
952 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
953 error "set user quota failed"
955 # make sure the system is clean
956 local used=$(getquota -u $TSTUSR global curspace)
958 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
960 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
962 test_1_check_write $testfile "user" $limit1
964 used=$(getquota -u $TSTUSR global curspace $qpool1)
965 echo "qpool1 used $used"
966 used=$(getquota -u $TSTUSR global curspace $qpool2)
967 echo "qpool2 used $used"
970 wait_delete_completed || error "wait_delete_completed failed"
971 sync_all_data || true
973 used=$(getquota -u $TSTUSR global curspace $qpool1)
974 [ $used -eq 0 ] || quota_error u $TSTUSR \
975 "user quota isn't released after deletion"
977 run_test 1d "Quota pools: check block hardlimit on different pools"
981 local global_limit=53000000 # MB
982 local testfile="$DIR/$tdir/$tfile-0"
983 local testfile2="$DIR/$tdir/$tfile-1"
984 local qpool1="qpool1"
987 setup_quota_test || error "setup quota failed with $?"
990 set_ost_qtype $QTYPE || error "enable ost quota failed"
992 # global_limit is much greater than limit1 to get
993 # different qunit's on osts. Since 1st qunit shrinking
994 # on OST1(that belongs to qpool1), this qunit should
996 log "User quota (block hardlimit:$global_limit MB)"
997 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
998 error "set user quota failed"
1000 pool_add $qpool1 || error "pool_add failed"
1001 pool_add_targets $qpool1 1 1 ||
1002 error "pool_add_targets failed"
1004 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1005 error "set user quota failed"
1007 # make sure the system is clean
1008 local used=$(getquota -u $TSTUSR global curspace)
1009 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1011 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
1012 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1014 test_1_check_write $testfile "user" $limit1
1016 $LFS setstripe $testfile2 -c 1 -i 0 ||
1017 error "setstripe $testfile2 failed"
1018 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
1019 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
1021 $RUNAS $DD of=$testfile2 count=20 ||
1022 quota_error u $TSTUSR \
1023 "$qtype write failure, but expect success"
1027 wait_delete_completed || error "wait_delete_completed failed"
1028 sync_all_data || true
1030 used=$(getquota -u $TSTUSR global curspace $qpool1)
1031 [ $used -eq 0 ] || quota_error u $TSTUSR \
1032 "user quota isn't released after deletion"
1034 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
1037 local global_limit=200 # MB
1038 local limit1=10 # MB
1039 local TESTDIR="$DIR/$tdir/"
1040 local testfile="$TESTDIR/$tfile-0"
1041 local qpool1="qpool1"
1044 setup_quota_test || error "setup quota failed with $?"
1047 set_ost_qtype $QTYPE || error "enable ost quota failed"
1049 log "User quota (block hardlimit:$global_limit MB)"
1050 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1051 error "set user quota failed"
1053 pool_add $qpool1 || error "pool_add failed"
1054 pool_add_targets $qpool1 0 0 ||
1055 error "pool_add_targets failed"
1057 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1058 error "set user quota failed"
1060 # make sure the system is clean
1061 local used=$(getquota -u $TSTUSR global curspace)
1062 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1064 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1066 test_1_check_write $testfile "user" $limit1
1068 pool_remove_target $qpool1 0
1070 wait_delete_completed || error "wait_delete_completed failed"
1071 sync_all_data || true
1073 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1074 # qunit for appropriate element in lgd array should be set
1075 # correctly(4096). Earlier it was not changed continuing to be 1024.
1076 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1077 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1078 # as it already was 1024. As flag "need_update" for this qunit was
1079 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1080 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1081 # became > 10M. QMT returned EINPROGRESS in a loop.
1082 # Check that it doesn't hung anymore.
1083 test_1_check_write $testfile "user" $limit1
1085 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1089 local global_limit=40 # MB
1090 local testfile="$DIR/$tdir/$tfile-0"
1091 local qpool="qpool1"
1092 local mdmb_param="osc.*.max_dirty_mb"
1093 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1096 setup_quota_test || error "setup quota failed with $?"
1097 $LCTL set_param $mdmb_param=1
1098 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1101 set_ost_qtype $QTYPE || error "enable ost quota failed"
1104 log "User quota (block hardlimit:$global_limit MB)"
1105 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1106 error "set user quota failed"
1108 pool_add $qpool || error "pool_add failed"
1109 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1110 error "pool_add_targets failed"
1112 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1113 error "set user quota failed"
1115 # make sure the system is clean
1116 local used=$(getquota -u $TSTUSR global curspace)
1118 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1120 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1121 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1124 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1125 quota_error u $TSTUSR \
1126 "$qtype write failure, but expect success"
1127 log "Write out of block quota ..."
1128 # this time maybe cache write, ignore it's failure
1129 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1130 # flush cache, ensure noquota flag is set on client
1131 cancel_lru_locks osc
1132 sync; sync_all_data || true
1134 $RUNAS $DD of=$testfile count=$((OSTCOUNT*3)) seek=$limit &&
1135 quota_error u $TSTUSR \
1136 "user write success, but expect EDQUOT"
1139 wait_delete_completed || error "wait_delete_completed failed"
1140 sync_all_data || true
1142 used=$(getquota -u $TSTUSR global curspace $qpool)
1143 [ $used -ne 0 ] && quota_error u $TSTUSR \
1144 "user quota isn't released after deletion"
1147 run_test 1g "Quota pools: Block hard limit with wide striping"
1151 local testfile="$DIR/$tdir/$tfile-0"
1153 check_set_fallocate_or_skip
1155 setup_quota_test || error "setup quota failed with $?"
1158 set_ost_qtype $QTYPE || error "enable ost quota failed"
1161 log "User quota (block hardlimit:$limit MB)"
1162 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1163 error "set user quota failed"
1165 # make sure the system is clean
1166 local used=$(getquota -u $TSTUSR global curspace)
1167 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1169 $LFS setstripe $testfile -i 0 -c 1 || error "setstripe $testfile failed"
1170 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1172 wait_quota_synced ost1 OST0000 usr $TSTID hardlimit $((limit*1024))
1174 check_write_fallocate $testfile "user" $limit
1177 wait_delete_completed || error "wait_delete_completed failed"
1178 sync_all_data || true
1179 used=$(getquota -u $TSTUSR global curspace)
1180 [ $used -eq 0 ] || quota_error u $TSTUSR \
1181 "user quota isn't released after deletion"
1183 run_test 1h "Block hard limit test using fallocate"
1186 local global_limit=200 # 200M
1187 local limit1=10 # 10M
1188 local TESTDIR="$DIR/$tdir/"
1189 local testfile="$TESTDIR/$tfile-0"
1190 local testfile1="$TESTDIR/$tfile-1"
1191 local testfile2="$TESTDIR/$tfile-2"
1192 local qpool1="qpool1"
1195 setup_quota_test || error "setup quota failed with $?"
1198 set_ost_qtype $QTYPE || error "enable ost quota failed"
1200 log "User quota (block hardlimit:$global_limit MB)"
1201 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1202 error "set user quota failed"
1204 pool_add $qpool1 || error "pool_add failed"
1205 pool_add_targets $qpool1 0 0 ||
1206 error "pool_add_targets failed"
1208 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1209 error "set user quota failed"
1211 # make sure the system is clean
1212 local used=$(getquota -u $TSTUSR global curspace)
1213 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1215 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1218 test_1_check_write $testfile "user" $limit1
1219 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1220 error "set user quota failed"
1222 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1223 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1224 quota_error u $TSTUSR "write failure, but expect success"
1228 wait_delete_completed || error "wait_delete_completed failed"
1229 sync_all_data || true
1231 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1232 error "set user quota failed"
1233 test_1_check_write $testfile "user" $limit1
1234 local tmp_limit=$(($limit1*2))
1235 # increase pool limit
1236 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1237 error "set user quota failed"
1238 # now write shouldn't fail
1239 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1240 quota_error u $TSTUSR "write failure, but expect success"
1241 # decrease pool limit
1242 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1243 error "set user quota failed"
1244 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1245 # flush cache, ensure noquota flag is set on client
1246 cancel_lru_locks osc
1247 sync; sync_all_data || true
1248 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1249 quota_error u $TSTUSR "write success, but expect failure"
1252 run_test 1i "Quota pools: different limit and usage relations"
1256 local testfile="$DIR/$tdir/$tfile-0"
1258 (( $OST1_VERSION >= $(version_code 2.15.52.206) )) ||
1259 skip "need OST at least 2.15.52.206"
1261 is_project_quota_supported ||
1262 skip "skip project quota unsupported"
1264 setup_quota_test || error "setup quota failed with $?"
1267 set_ost_qtype $QTYPE || error "enable ost quota failed"
1270 log "--------------------------------------"
1271 log "Project quota (block hardlimit:$limit mb)"
1272 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1273 error "set project quota failed"
1275 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
1276 change_project -p $TSTPRJID $testfile
1278 local procf=osd-$ost1_FSTYPE.$FSNAME-OST0000.quota_slave.root_prj_enable
1279 do_facet ost1 $LCTL set_param $procf=1 ||
1280 error "enable root quotas for project failed"
1281 stack_trap "do_facet ost1 $LCTL set_param $procf=0"
1283 runas -u 0 -g 0 $DD of=$testfile count=$limit oflag=direct || true
1284 runas -u 0 -g 0 $DD of=$testfile count=$((limit/2)) seek=$limit oflag=direct &&
1285 quota_error "project" $TSTPRJID "root write to project success"
1287 do_facet ost1 $LCTL set_param $procf=0 ||
1288 error "disable root quotas for project failed"
1290 runas -u 0 -g 0 $DD of=$testfile count=$limit seek=$limit oflag=direct ||
1291 quota_error "project" $TSTPRJID "root write to project failed"
1296 used=$(getquota -p $TSTPRJID global curspace)
1297 (( $used == 0 )) || quota_error p $TSTPRJID \
1298 "project quota isn't released after deletion"
1300 run_test 1j "Enable project quota enforcement for root"
1302 # test inode hardlimit
1304 local testfile="$DIR/$tdir/$tfile-0"
1305 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1306 qmt.$FSNAME-QMT0000.md-0x0.info |
1307 sed -e 's/least qunit/least_qunit/' |
1308 awk '/least_qunit/{ print $2 }')
1311 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1312 limit=$((least_qunit * 1024))
1313 echo "least_qunit: '$least_qunit', limit: '$limit'"
1315 local free_inodes=$(mdt_free_inodes 0)
1316 echo "$free_inodes free inodes on master MDT"
1317 [ $free_inodes -lt $limit ] &&
1318 skip "not enough free inodes $free_inodes required $limit"
1320 setup_quota_test || error "setup quota failed with $?"
1323 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1326 log "User quota (inode hardlimit:$limit files)"
1327 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1328 error "set user quota failed"
1330 # make sure the system is clean
1331 local used=$(getquota -u $TSTUSR global curinodes)
1332 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1334 log "Create $((limit - least_qunit)) files ..."
1335 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1336 quota_error u $TSTUSR "user create failure, but expect success"
1337 # it is ok, if it fails on the last qunit
1338 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1339 log "Create out of file quota ..."
1340 $RUNAS touch ${testfile}_xxx &&
1341 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1344 unlinkmany ${testfile} $((limit - least_qunit)) ||
1345 error "unlinkmany $testfile failed"
1346 # if 2nd createmany got EDQUOT, not all of nodes would be created
1347 unlinkmany ${testfile}_yyy $least_qunit || true
1348 rm -f ${testfile}_xxx
1349 wait_delete_completed
1351 used=$(getquota -u $TSTUSR global curinodes)
1352 [ $used -ne 0 ] && quota_error u $TSTUSR \
1353 "user quota isn't released after deletion"
1354 resetquota -u $TSTUSR
1357 log "--------------------------------------"
1358 log "Group quota (inode hardlimit:$limit files)"
1359 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1360 error "set group quota failed"
1362 testfile=$DIR/$tdir/$tfile-1
1363 # make sure the system is clean
1364 used=$(getquota -g $TSTUSR global curinodes)
1365 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1367 log "Create $limit files ..."
1368 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1369 quota_error g $TSTUSR "group create failure, but expect success"
1370 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1371 log "Create out of file quota ..."
1372 $RUNAS touch ${testfile}_xxx &&
1373 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1376 unlinkmany ${testfile} $((limit - least_qunit)) ||
1377 error "unlinkmany $testfile failed"
1378 unlinkmany ${testfile}_yyy $least_qunit || true
1379 rm -f ${testfile}_xxx
1380 wait_delete_completed
1382 used=$(getquota -g $TSTUSR global curinodes)
1383 [ $used -ne 0 ] && quota_error g $TSTUSR \
1384 "user quota isn't released after deletion"
1386 resetquota -g $TSTUSR
1387 ! is_project_quota_supported &&
1388 echo "Skip project quota is not supported" && return 0
1391 log "--------------------------------------"
1392 log "Project quota (inode hardlimit:$limit files)"
1393 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1394 error "set project quota failed"
1396 testfile=$DIR/$tdir/$tfile-1
1397 # make sure the system is clean
1398 used=$(getquota -p $TSTPRJID global curinodes)
1400 error "Used inodes($used) for project $TSTPRJID isn't 0"
1402 change_project -sp $TSTPRJID $DIR/$tdir
1403 log "Create $limit files ..."
1404 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1405 quota_error p $TSTPRJID \
1406 "project create fail, but expect success"
1407 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1408 log "Create out of file quota ..."
1409 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1410 "project create success, but expect EDQUOT"
1411 change_project -C $DIR/$tdir
1414 used=$(getquota -p $TSTPRJID global curinodes)
1415 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1416 "project quota isn't released after deletion"
1419 run_test 2 "File hard limit (normal use and out of quota)"
1428 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1429 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1433 $LFS setstripe $testfile -c 1 -i 0
1434 chown $TSTUSR.$TSTUSR $testfile
1435 [ "$qtype" == "p" ] && is_project_quota_supported &&
1436 change_project -p $TSTPRJID $testfile
1438 echo "Write up to soft limit"
1439 $RUNAS $DD of=$testfile count=$limit ||
1440 quota_error a $TSTUSR "write failure, but expect success"
1441 OFFSET=$((limit * 1024))
1442 cancel_lru_locks osc
1444 echo "Write to exceed soft limit"
1445 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1446 quota_error a $TSTUSR "write failure, but expect success"
1447 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1448 cancel_lru_locks osc
1450 echo "mmap write when over soft limit"
1451 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1452 quota_error a $TSTUSR "mmap write failure, but expect success"
1453 cancel_lru_locks osc
1458 $SHOW_QUOTA_INFO_USER
1459 $SHOW_QUOTA_INFO_GROUP
1460 $SHOW_QUOTA_INFO_PROJID
1462 echo "Write before timer goes off"
1463 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1464 quota_error a $TSTUSR "write failure, but expect success"
1465 OFFSET=$((OFFSET + 1024))
1466 cancel_lru_locks osc
1468 wait_grace_time $qtype "block" $pool
1473 $SHOW_QUOTA_INFO_USER
1474 $SHOW_QUOTA_INFO_GROUP
1475 $SHOW_QUOTA_INFO_PROJID
1477 log "Write after timer goes off"
1478 # maybe cache write, ignore.
1479 # write up to soft least quint to consume all
1480 # possible slave granted space.
1481 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1482 count=$soft_limit seek=$OFFSET || true
1483 OFFSET=$((OFFSET + soft_limit))
1484 cancel_lru_locks osc
1485 log "Write after cancel lru locks"
1486 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1487 quota_error a $TSTUSR "write success, but expect EDQUOT"
1492 $SHOW_QUOTA_INFO_USER
1493 $SHOW_QUOTA_INFO_GROUP
1494 $SHOW_QUOTA_INFO_PROJID
1496 echo "Unlink file to stop timer"
1498 wait_delete_completed
1499 sync_all_data || true
1504 $SHOW_QUOTA_INFO_USER
1505 $SHOW_QUOTA_INFO_GROUP
1506 $SHOW_QUOTA_INFO_PROJID
1508 $LFS setstripe $testfile -c 1 -i 0
1509 chown $TSTUSR.$TSTUSR $testfile
1510 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1513 $RUNAS $DD of=$testfile count=$limit ||
1514 quota_error a $TSTUSR "write failure, but expect success"
1521 local grace=20 # seconds
1522 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1525 local testfile=$DIR/$tdir/$tfile-0
1527 # get minimum soft qunit size
1528 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1529 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1531 set_ost_qtype $QTYPE || error "enable ost quota failed"
1533 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1534 # make sure the system is clean
1535 local used=$(getquota -u $TSTUSR global curspace)
1536 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1538 $LFS setquota -t -u --block-grace $grace --inode-grace \
1539 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1540 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1541 error "set user quota failed"
1543 test_block_soft $testfile $grace $limit "u"
1545 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1546 testfile=$DIR/$tdir/$tfile-1
1547 # make sure the system is clean
1548 used=$(getquota -g $TSTUSR global curspace)
1549 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1551 $LFS setquota -t -g --block-grace $grace --inode-grace \
1552 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1553 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1554 error "set group quota failed"
1556 test_block_soft $testfile $grace $limit "g"
1558 if is_project_quota_supported; then
1559 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1560 testfile=$DIR/$tdir/$tfile-2
1561 # make sure the system is clean
1562 used=$(getquota -p $TSTPRJID global curspace)
1563 [ $used -ne 0 ] && error \
1564 "Used space($used) for project $TSTPRJID isn't 0."
1566 $LFS setquota -t -p --block-grace $grace --inode-grace \
1567 $MAX_IQ_TIME $DIR ||
1568 error "set project grace time failed"
1569 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1570 $DIR || error "set project quota failed"
1572 test_block_soft $testfile $grace $limit "p"
1573 resetquota -p $TSTPRJID
1574 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1575 $MAX_IQ_TIME $DIR ||
1576 error "restore project grace time failed"
1580 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1581 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1582 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1583 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1585 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1588 local grace=20 # seconds
1589 local qpool="qpool1"
1590 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1593 local testfile=$DIR/$tdir/$tfile-0
1596 # get minimum soft qunit size
1597 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1598 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1599 local glbl_limit=$((2*limit))
1600 local glbl_grace=$((2*grace))
1601 echo "limit $limit glbl_limit $glbl_limit"
1602 echo "grace $grace glbl_grace $glbl_grace"
1604 set_ost_qtype $QTYPE || error "enable ost quota failed"
1606 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1607 # make sure the system is clean
1608 local used=$(getquota -u $TSTUSR global curspace)
1609 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1611 pool_add $qpool || error "pool_add failed"
1612 pool_add_targets $qpool 0 1 ||
1613 error "pool_add_targets failed"
1615 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1616 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1617 $LFS setquota -t -u --block-grace $grace \
1618 --pool $qpool $DIR || error "set user grace time failed"
1620 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1621 error "set user quota failed"
1622 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1623 error "set user quota failed"
1625 test_block_soft $testfile $grace $limit "u" $qpool
1627 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1628 testfile=$DIR/$tdir/$tfile-1
1629 # make sure the system is clean
1630 used=$(getquota -g $TSTUSR global curspace)
1631 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1633 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1634 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1635 $LFS setquota -t -g --block-grace $grace \
1636 --pool $qpool $DIR || error "set group grace time failed"
1638 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1639 error "set group quota failed"
1640 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1641 error "set group quota failed"
1643 test_block_soft $testfile $grace $limit "g" $qpool
1645 if is_project_quota_supported; then
1646 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1647 testfile=$DIR/$tdir/$tfile-2
1648 # make sure the system is clean
1649 used=$(getquota -p $TSTPRJID global curspace)
1650 [ $used -ne 0 ] && error \
1651 "Used space($used) for project $TSTPRJID isn't 0."
1653 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1654 $MAX_IQ_TIME $DIR ||
1655 error "set project grace time failed"
1656 $LFS setquota -t -p --block-grace $grace \
1657 --pool $qpool $DIR ||
1658 error "set project grace time failed"
1660 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1661 $DIR || error "set project quota failed"
1662 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1663 --pool $qpool $DIR || error "set project quota failed"
1665 test_block_soft $testfile $grace $limit "p" $qpool
1666 resetquota -p $TSTPRJID
1667 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1668 $MAX_IQ_TIME $DIR ||
1669 error "restore project grace time failed"
1670 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1671 $DIR || error "set project grace time failed"
1675 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1676 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1677 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1678 --pool $qpool $DIR || error "restore user grace time failed"
1679 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1680 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1681 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1682 --pool $qpool $DIR || error "restore group grace time failed"
1684 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1687 local grace=20 # seconds
1688 local qpool="qpool1"
1689 local qpool2="qpool2"
1690 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1693 local testfile=$DIR/$tdir/$tfile-0
1696 # get minimum soft qunit size
1697 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1698 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1699 local limit2=$((limit+4))
1700 local glbl_limit=$((limit+8))
1701 local grace1=$((grace+10))
1703 local glbl_grace=$((grace+20))
1704 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1705 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1707 set_ost_qtype $QTYPE || error "enable ost quota failed"
1709 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1710 # make sure the system is clean
1711 local used=$(getquota -u $TSTUSR global curspace)
1712 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1714 pool_add $qpool || error "pool_add failed"
1715 pool_add_targets $qpool 0 1 ||
1716 error "pool_add_targets failed"
1718 pool_add $qpool2 || error "pool_add failed"
1719 pool_add_targets $qpool2 0 1 ||
1720 error "pool_add_targets failed"
1722 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1723 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1724 $LFS setquota -t -u --block-grace $grace1 \
1725 --pool $qpool $DIR || error "set user grace time failed"
1726 $LFS setquota -t -u --block-grace $grace2 \
1727 --pool $qpool2 $DIR || error "set user grace time failed"
1729 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1730 error "set user quota failed"
1731 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1732 error "set user quota failed"
1733 # qpool has minimum soft limit, but its grace is greater than
1734 # the grace period of qpool2. Thus write shouldn't fail when
1735 # hit qpool soft limit - only when reaches up qpool2 limit
1736 # after grace2 seconds.
1737 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1738 error "set user quota failed"
1740 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1743 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1744 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1745 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1746 --pool $qpool $DIR || error "restore user grace time failed"
1747 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1748 --pool $qpool2 $DIR || error "restore user grace time failed"
1750 run_test 3c "Quota pools: check block soft limit on different pools"
1757 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1758 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1761 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1763 echo "Create files to exceed soft limit"
1764 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1765 quota_error a $TSTUSR "create failure, but expect success"
1766 local trigger_time=$(date +%s)
1768 sync_all_data || true
1770 local cur_time=$(date +%s)
1771 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1772 error "Passed grace time $grace, $trigger_time, $cur_time"
1774 echo "Create file before timer goes off"
1775 $RUNAS touch ${TESTFILE}_before ||
1776 quota_error a $TSTUSR "failed create before timer expired," \
1777 "but expect success. $trigger_time, $cur_time"
1778 sync_all_data || true
1780 wait_grace_time $qtype "file"
1785 $SHOW_QUOTA_INFO_USER
1786 $SHOW_QUOTA_INFO_GROUP
1787 $SHOW_QUOTA_INFO_PROJID
1789 echo "Create file after timer goes off"
1790 # exceed least soft limit is possible
1791 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1792 quota_error a $TSTUSR "create after timer expired," \
1794 sync_all_data || true
1799 $SHOW_QUOTA_INFO_USER
1800 $SHOW_QUOTA_INFO_GROUP
1801 $SHOW_QUOTA_INFO_PROJID
1803 echo "Unlink files to stop timer"
1804 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1805 wait_delete_completed
1808 $RUNAS touch ${TESTFILE}_xxx ||
1809 quota_error a $TSTUSR "touch after timer stop failure," \
1810 "but expect success"
1811 sync_all_data || true
1819 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1820 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1821 local TESTFILE=$DIR/$tdir/$tfile-0
1824 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1825 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1827 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1828 # make sure the system is clean
1829 local USED=$(getquota -u $TSTUSR global curinodes)
1830 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1832 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1833 $GRACE $DIR || error "set user grace time failed"
1834 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1835 error "set user quota failed"
1837 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1839 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1840 # make sure the system is clean
1841 USED=$(getquota -g $TSTUSR global curinodes)
1842 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1844 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1845 $GRACE $DIR || error "set group grace time failed"
1846 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1847 error "set group quota failed"
1848 TESTFILE=$DIR/$tdir/$tfile-1
1850 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1852 if is_project_quota_supported; then
1853 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1854 # make sure the system is clean
1855 USED=$(getquota -p $TSTPRJID global curinodes)
1856 [ $USED -ne 0 ] && error \
1857 "Used space($USED) for project $TSTPRJID isn't 0."
1859 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1860 $GRACE $DIR || error "set project grace time failed"
1861 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1862 error "set project quota failed"
1864 TESTFILE=$DIR/$tdir/$tfile-1
1865 # one less than limit, because of parent directory included.
1866 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1867 resetquota -p $TSTPRJID
1868 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1869 $MAX_IQ_TIME $DIR ||
1870 error "restore project grace time failed"
1874 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1875 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1876 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1877 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1879 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1882 local GR_STR1="1w3d"
1883 local GR_STR2="1000s"
1885 local GR_STR4="1w2d3h4m5s"
1887 local GR_STR6="18446744073709551615"
1890 wait_delete_completed
1892 # test of valid grace strings handling
1893 echo "Valid grace strings test"
1894 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1895 $GR_STR2 $DIR || error "set user grace time failed"
1896 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1897 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1898 $GR_STR4 $DIR || error "set group grace time quota failed"
1899 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1901 # test of invalid grace strings handling
1902 echo " Invalid grace strings test"
1903 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1904 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1905 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1909 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1910 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1911 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1912 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1914 run_test 4b "Grace time strings handling"
1916 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1918 local BLIMIT=10 # MB
1919 local ILIMIT=10 # inodes
1921 setup_quota_test || error "setup quota failed with $?"
1923 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1924 set_ost_qtype $QTYPE || error "enable ost quota failed"
1926 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1927 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1928 error "set user quota failed"
1929 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1930 if is_project_quota_supported; then
1931 error "set group quota failed"
1932 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1933 -I $ILIMIT $DIR || error "set project quota failed"
1936 # make sure the system is clean
1937 local USED=$(getquota -u $TSTUSR global curinodes)
1938 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1939 USED=$(getquota -g $TSTUSR global curinodes)
1940 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1941 USED=$(getquota -u $TSTUSR global curspace)
1942 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1943 USED=$(getquota -g $TSTUSR global curspace)
1944 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1945 if is_project_quota_supported; then
1946 USED=$(getquota -p $TSTPRJID global curinodes)
1948 error "Used inode($USED) for project $TSTPRJID isn't 0."
1949 USED=$(getquota -p $TSTPRJID global curspace)
1951 error "Used block($USED) for project $TSTPRJID isn't 0."
1954 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1955 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1956 error "create failure, expect success"
1957 if is_project_quota_supported; then
1958 touch $DIR/$tdir/$tfile-0_1
1959 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1961 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1962 error "write failure, expect success"
1964 echo "Chown files to $TSTUSR.$TSTUSR ..."
1965 for i in $(seq 0 $ILIMIT); do
1966 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1967 quota_error a $TSTUSR "chown failure, expect success"
1971 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1972 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1974 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1976 # test dropping acquire request on master
1980 # Clear dmesg so watchdog is not triggered by previous
1982 do_facet ost1 dmesg -c > /dev/null
1984 setup_quota_test || error "setup quota failed with $?"
1986 # make sure the system is clean
1987 local USED=$(getquota -u $TSTUSR global curspace)
1988 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1990 # make sure no granted quota on ost
1991 set_ost_qtype $QTYPE || error "enable ost quota failed"
1992 resetquota -u $TSTUSR
1994 # create file for $TSTUSR
1995 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1996 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1997 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1999 # create file for $TSTUSR2
2000 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
2001 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
2002 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
2004 # cache per-ID lock for $TSTUSR on slave
2005 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2006 error "set quota failed"
2007 $RUNAS $DD of=$TESTFILE count=1 ||
2008 error "write $TESTFILE failure, expect success"
2009 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
2010 error "write $TESTFILE2 failure, expect success"
2012 if at_is_enabled; then
2013 at_max_saved=$(at_max_get ost1)
2014 at_max_set $TIMEOUT ost1
2016 # write to enforced ID ($TSTUSR) to exceed limit to make sure
2017 # DQACQ is sent, which makes at_max to take effect
2018 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
2021 wait_delete_completed
2025 sync_all_data || true
2027 #define QUOTA_DQACQ 601
2028 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
2029 lustre_fail mds 0x513 601
2031 do_facet ost1 $LCTL set_param \
2032 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
2034 # write to un-enforced ID ($TSTUSR2) should succeed
2035 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
2036 error "write failure, expect success"
2038 # write to enforced ID ($TSTUSR) in background, exceeding limit
2039 # to make sure DQACQ is sent
2040 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
2043 # watchdog timer uses a factor of 2
2044 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
2045 sleep $((TIMEOUT * 2 + 1))
2047 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
2049 # write should be blocked and never finished
2050 if ! ps -p $DDPID > /dev/null 2>&1; then
2052 error "write finished incorrectly!"
2057 # no watchdog is triggered
2058 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2059 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2060 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2061 [ -z "$watchdog" ] || error "$watchdog"
2063 rm -f $TMP/lustre-log-${TESTNAME}.log
2065 # write should continue then fail with EDQUOT
2069 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2070 if [ $count -ge 240 ]; then
2071 quota_error u $TSTUSR "dd not finished in $count secs"
2073 count=$((count + 1))
2074 if [ $((count % 30)) -eq 0 ]; then
2075 c_size=$(stat -c %s $TESTFILE)
2076 echo "Waiting $count secs. $c_size"
2082 run_test 6 "Test dropping acquire request on master"
2084 # quota reintegration (global index)
2086 local TESTFILE=$DIR/$tdir/$tfile
2089 [ "$SLOW" = "no" ] && LIMIT=5
2091 setup_quota_test || error "setup quota failed with $?"
2093 # make sure the system is clean
2094 local USED=$(getquota -u $TSTUSR global curspace)
2095 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2097 # make sure no granted quota on ost1
2098 set_ost_qtype $QTYPE || error "enable ost quota failed"
2099 resetquota -u $TSTUSR
2100 set_ost_qtype "none" || error "disable ost quota failed"
2102 local OSTUUID=$(ostuuid_from_index 0)
2103 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2105 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2108 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2109 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2114 echo "Enable quota & set quota limit for $TSTUSR"
2115 set_ost_qtype $QTYPE || error "enable ost quota failed"
2116 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2117 error "set quota failed"
2119 echo "Start ost1..."
2120 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2123 wait_ost_reint $QTYPE || error "reintegration failed"
2125 # hardlimit should have been fetched by slave during global
2126 # reintegration, write will exceed quota
2127 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2128 quota_error u $TSTUSR "write success, but expect EDQUOT"
2131 wait_delete_completed
2132 sync_all_data || true
2138 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2139 error "clear quota failed"
2141 echo "Start ost1..."
2142 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2145 wait_ost_reint $QTYPE || error "reintegration failed"
2147 # hardlimit should be cleared on slave during reintegration
2148 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2149 quota_error u $TSTUSR "write error, but expect success"
2151 run_test 7a "Quota reintegration (global index)"
2153 # quota reintegration (slave index)
2155 local limit=100000 # MB
2156 local TESTFILE=$DIR/$tdir/$tfile
2158 setup_quota_test || error "setup quota failed with $?"
2160 # make sure the system is clean
2161 local USED=$(getquota -u $TSTUSR global curspace)
2162 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2164 # make sure no granted quota on ost1
2165 set_ost_qtype $QTYPE || error "enable ost quota failed"
2166 resetquota -u $TSTUSR
2167 set_ost_qtype "none" || error "disable ost quota failed"
2169 local OSTUUID=$(ostuuid_from_index 0)
2170 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2172 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2175 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2176 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2178 # consume some space to make sure the granted space will not
2179 # be released during reconciliation
2180 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2181 error "consume space failure, expect success"
2183 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2184 lustre_fail mds 0xa02
2186 set_ost_qtype $QTYPE || error "enable ost quota failed"
2187 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2188 error "set quota failed"
2190 # ignore the write error
2191 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2193 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2197 echo "Restart ost to trigger reintegration..."
2199 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2202 wait_ost_reint $QTYPE || error "reintegration failed"
2204 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2205 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2210 run_test 7b "Quota reintegration (slave index)"
2212 # quota reintegration (restart mds during reintegration)
2215 local TESTFILE=$DIR/$tdir/$tfile
2217 [ "$SLOW" = "no" ] && LIMIT=5
2219 setup_quota_test || error "setup quota failed with $?"
2221 # make sure the system is clean
2222 local USED=$(getquota -u $TSTUSR global curspace)
2223 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2225 set_ost_qtype "none" || error "disable ost quota failed"
2226 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2227 error "set quota failed"
2229 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2230 lustre_fail ost 0xa03
2233 set_ost_qtype $QTYPE || error "enable ost quota failed"
2234 # trigger reintegration
2235 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2236 procf=${procf}quota_slave.force_reint
2237 do_facet ost1 $LCTL set_param $procf=1 ||
2238 error "force reintegration failed"
2246 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2249 # wait longer than usual to make sure the reintegration
2250 # is triggered by quota wb thread.
2251 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2253 # hardlimit should have been fetched by slave during global
2254 # reintegration, write will exceed quota
2255 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2256 quota_error u $TSTUSR "write success, but expect EDQUOT"
2259 run_test 7c "Quota reintegration (restart mds during reintegration)"
2261 # Quota reintegration (Transfer index in multiple bulks)
2263 local TESTFILE=$DIR/$tdir/$tfile
2264 local TESTFILE1="$DIR/$tdir/$tfile"-1
2267 setup_quota_test || error "setup quota failed with $?"
2269 set_ost_qtype "none" || error "disable ost quota failed"
2270 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2271 error "set quota for $TSTUSR failed"
2272 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2273 error "set quota for $TSTUSR2 failed"
2275 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2276 lustre_fail mds 0x608 0
2278 # enable quota to tirgger reintegration
2279 set_ost_qtype "u" || error "enable ost quota failed"
2280 wait_ost_reint "u" || error "reintegration failed"
2284 # hardlimit should have been fetched by slave during global
2285 # reintegration, write will exceed quota
2286 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2287 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2289 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2290 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2293 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2295 # quota reintegration (inode limits)
2297 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2299 # LU-2435: skip this quota test if underlying zfs version has not
2300 # supported native dnode accounting
2301 [ "$mds1_FSTYPE" == zfs ] && {
2302 local F="feature@userobj_accounting"
2303 local pool=$(zpool_name mds1)
2304 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2306 [[ "$feature" != *" active "* ]] &&
2307 skip "requires zpool with active userobj_accounting"
2310 local ilimit=$((1024 * 2)) # inodes
2311 local TESTFILE=$DIR/${tdir}-1/$tfile
2313 setup_quota_test || error "setup quota failed with $?"
2315 # make sure the system is clean
2316 local USED=$(getquota -u $TSTUSR global curinodes)
2317 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2319 # make sure no granted quota on mdt1
2320 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2321 resetquota -u $TSTUSR
2322 set_mdt_qtype "none" || error "disable mdt quota failed"
2324 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2325 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2326 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2329 echo "Stop mds${MDSCOUNT}..."
2332 echo "Enable quota & set quota limit for $TSTUSR"
2333 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2334 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2335 error "set quota failed"
2337 echo "Start mds${MDSCOUNT}..."
2338 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2341 wait_mdt_reint $QTYPE || error "reintegration failed"
2343 echo "create remote dir"
2344 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2345 error "create remote dir failed"
2346 chmod 0777 $DIR/${tdir}-1
2348 # hardlimit should have been fetched by slave during global
2349 # reintegration, create will exceed quota
2350 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2351 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2353 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2354 wait_delete_completed
2355 sync_all_data || true
2357 echo "Stop mds${MDSCOUNT}..."
2360 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2361 error "clear quota failed"
2363 echo "Start mds${MDSCOUNT}..."
2364 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2367 wait_mdt_reint $QTYPE || error "reintegration failed"
2369 # hardlimit should be cleared on slave during reintegration
2370 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2371 quota_error u $TSTUSR "create failed, expect success"
2373 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2374 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2376 run_test 7e "Quota reintegration (inode limits)"
2378 # run dbench with quota enabled
2380 local BLK_LIMIT="100g" #100G
2381 local FILE_LIMIT=1000000
2383 setup_quota_test || error "setup quota failed with $?"
2385 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2386 set_ost_qtype $QTYPE || error "enable ost quota failed"
2388 echo "Set enough high limit for user: $TSTUSR"
2389 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2390 error "set user quota failed"
2391 echo "Set enough high limit for group: $TSTUSR"
2392 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2393 error "set group quota failed"
2394 if is_project_quota_supported; then
2395 change_project -sp $TSTPRJID $DIR/$tdir
2396 echo "Set enough high limit for project: $TSTPRJID"
2397 $LFS setquota -p $TSTPRJID -b 0 \
2398 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2399 error "set project quota failed"
2403 [ "$SLOW" = "no" ] && duration=" -t 120"
2404 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2405 quota_error a $TSTUSR "dbench failed!"
2407 is_project_quota_supported && change_project -C $DIR/$tdir
2410 run_test 8 "Run dbench with quota enabled"
2412 # this check is just for test_9
2413 OST0_MIN=4900000 #4.67G
2415 check_whether_skip () {
2416 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2417 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2418 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2419 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2426 # run for fixing bug10707, it needs a big room. test for 64bit
2428 local filesize=$((1024 * 9 / 2)) # 4.5G
2430 check_whether_skip && return 0
2432 setup_quota_test || error "setup quota failed with $?"
2434 set_ost_qtype "ug" || error "enable ost quota failed"
2436 local TESTFILE="$DIR/$tdir/$tfile-0"
2437 local BLK_LIMIT=100G #100G
2438 local FILE_LIMIT=1000000
2440 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2442 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2444 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2445 error "set user quota failed"
2447 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2448 "for group: $TSTUSR"
2449 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2450 error "set group quota failed"
2452 quota_show_check a u $TSTUSR
2453 quota_show_check a g $TSTUSR
2455 echo "Create test file"
2456 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2457 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2459 log "Write the big file of 4.5G ..."
2460 $RUNAS $DD of=$TESTFILE count=$filesize ||
2461 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2471 run_test 9 "Block limit larger than 4GB (b10707)"
2474 local TESTFILE=$DIR/$tdir/$tfile
2476 setup_quota_test || error "setup quota failed with $?"
2478 # set limit to root user should fail
2479 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2480 error "set limit for root user successfully, expect failure"
2481 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2482 error "set limit for root group successfully, expect failure"
2483 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2484 error "set limit for project 0 successfully, expect failure"
2486 # root user can overrun quota
2487 set_ost_qtype "ug" || error "enable ost quota failed"
2489 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2490 error "set quota failed"
2491 quota_show_check b u $TSTUSR
2493 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2494 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2496 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2497 error "write failure, expect success"
2499 run_test 10 "Test quota for root user"
2502 local TESTFILE=$DIR/$tdir/$tfile
2503 setup_quota_test || error "setup quota failed with $?"
2505 set_mdt_qtype "ug" || error "enable mdt quota failed"
2506 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2507 error "set quota failed"
2509 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2510 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2512 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2513 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2516 local USED=$(getquota -u $TSTUSR global curinodes)
2517 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2519 run_test 11 "Chown/chgrp ignores quota"
2522 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2524 local blimit=22 # MB
2525 local blk_cnt=$((blimit - 5))
2526 local TESTFILE0="$DIR/$tdir/$tfile"-0
2527 local TESTFILE1="$DIR/$tdir/$tfile"-1
2529 setup_quota_test || error "setup quota failed with $?"
2531 set_ost_qtype "u" || error "enable ost quota failed"
2532 quota_show_check b u $TSTUSR
2534 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2535 error "set quota failed"
2537 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2538 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2539 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2540 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2542 echo "Write to ost0..."
2543 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2544 quota_error a $TSTUSR "dd failed"
2546 echo "Write to ost1..."
2547 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2548 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2550 echo "Free space from ost0..."
2552 wait_delete_completed
2553 sync_all_data || true
2555 echo "Write to ost1 after space freed from ost0..."
2556 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2557 quota_error a $TSTUSR "rebalancing failed"
2559 run_test 12a "Block quota rebalancing"
2562 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2564 local ilimit=$((1024 * 2)) # inodes
2565 local TESTFILE0=$DIR/$tdir/$tfile
2566 local TESTFILE1=$DIR/${tdir}-1/$tfile
2568 setup_quota_test || error "setup quota failed with $?"
2570 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2571 chmod 0777 $DIR/${tdir}-1
2573 set_mdt_qtype "u" || error "enable mdt quota failed"
2574 quota_show_check f u $TSTUSR
2576 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2577 error "set quota failed"
2579 echo "Create $ilimit files on mdt0..."
2580 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2581 quota_error u $TSTUSR "create failed, but expect success"
2583 echo "Create files on mdt1..."
2584 $RUNAS createmany -m $TESTFILE1 1 &&
2585 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2587 echo "Free space from mdt0..."
2588 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2589 wait_delete_completed
2590 sync_all_data || true
2592 echo "Create files on mdt1 after space freed from mdt0..."
2593 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2594 quota_error a $TSTUSR "rebalancing failed"
2596 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2597 error "unlink mdt1 files failed"
2598 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2600 run_test 12b "Inode quota rebalancing"
2603 local TESTFILE=$DIR/$tdir/$tfile
2604 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2605 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2607 setup_quota_test || error "setup quota failed with $?"
2609 set_ost_qtype "u" || error "enable ost quota failed"
2610 quota_show_check b u $TSTUSR
2612 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2613 error "set quota failed"
2614 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2615 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2617 # clear the locks in cache first
2618 do_facet ost1 $LCTL set_param -n $procf=clear
2619 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2620 [ $nlock -eq 0 ] || error "$nlock cached locks"
2622 # write to acquire the per-ID lock
2623 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2624 quota_error a $TSTUSR "dd failed"
2626 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2627 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2629 # clear quota doesn't trigger per-ID lock cancellation
2630 resetquota -u $TSTUSR
2631 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2632 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2634 # clear the per-ID lock
2635 do_facet ost1 $LCTL set_param -n $procf=clear
2636 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2637 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2639 # spare quota should be released
2640 local OSTUUID=$(ostuuid_from_index 0)
2641 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2642 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2643 [ $limit -le $space ] ||
2644 error "spare quota isn't released, limit:$limit, space:$space"
2646 run_test 13 "Cancel per-ID lock in the LRU list"
2650 (( $MDS1_VERSION >= $(version_code 2.15.54.67) )) ||
2651 skip "Need MDS >= v2_15_54-67-gdfe7d for qmt_site_recalc_cb fix"
2653 local qpool="qpool1"
2654 local tfile1="$DIR/$tdir/$tfile-0"
2657 setup_quota_test || error "setup quota failed with $?"
2659 set_ost_qtype $QTYPE || error "enable ost quota failed"
2661 $LFS setquota -u $TSTUSR -b 0 -B 100M -i 0 -I 0 $DIR ||
2662 error "set user quota failed"
2663 pool_add $qpool || error "pool_add failed"
2664 pool_add_targets $qpool 0 ||
2665 error "pool_add_targets failed"
2666 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
2667 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
2668 error "set user quota failed"
2670 # don't care about returned value
2671 $RUNAS $DD of=$tfile1 count=10 oflag=direct
2675 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2676 error "set user quota failed"
2678 # no panic after removing OST0000 from the pool
2679 pool_remove_target $qpool 0
2680 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2682 run_test 14 "check panic in qmt_site_recalc_cb"
2685 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2687 wait_delete_completed
2688 sync_all_data || true
2691 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2692 error "set user quota failed"
2693 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2694 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2695 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2696 resetquota -u $TSTUSR
2699 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2700 error "set group quota failed"
2701 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2702 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2703 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2704 resetquota -g $TSTUSR
2706 run_test 15 "Set over 4T block quota"
2710 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2711 skip "Not supported Lustre client before 2.14.55"
2713 setup_quota_test || error "setup quota failed with $?"
2715 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2716 error "failed to set quota for user $TSTUSR"
2717 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2718 error "failed to set quota for group $TSTUSR"
2720 $RUNAS $DD of=$DIR/$tdir/$tfile count=50 ||
2721 quota_error u $TSTUSR "write failure"
2723 $LFS quota -u $TSTUSR $MOUNT ||
2724 quota_error u $TSTUSR "failed to get quota"
2726 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2728 $LCTL --device %$OSC deactivate
2729 stack_trap "$LCTL --device %$OSC activate"
2731 $LFS quota -v -u $TSTUSR $MOUNT ||
2732 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2733 $LFS quota -v -g $TSTUSR $MOUNT ||
2734 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2736 (( $MDSCOUNT > 1 )) || return 0
2738 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2740 $LCTL --device %$MDC deactivate
2741 stack_trap "$LCTL --device %$MDC activate"
2743 $LFS quota -v -u $TSTUSR $MOUNT ||
2744 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2745 $LFS quota -v -g $TSTUSR $MOUNT ||
2746 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2748 run_test 16a "lfs quota should skip the inactive MDT/OST"
2759 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2760 skip "Not supported Lustre client before 2.14.55"
2762 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2765 if ! combined_mgs_mds ; then
2770 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2771 $(mdsdevname 1) $(mdsvdevname 1)
2772 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2773 $(mdsdevname 2) $(mdsvdevname 2)
2774 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2775 $(mdsdevname 3) $(mdsvdevname 3)
2777 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2778 $(ostdevname 1) $(ostvdevname 1)
2779 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2780 $(ostdevname 2) $(ostvdevname 2)
2782 stack_trap cleanup_16b
2784 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2785 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2786 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2787 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2788 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2790 mount_client $MOUNT || error "Unable to mount client"
2792 setup_quota_test || error "setup quota failed with $?"
2794 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2795 error "failed to set quota for user $TSTUSR"
2796 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2797 error "failed to set quota for group $TSTUSR"
2799 $RUNAS $DD of=$DIR/$tdir/$tfile count=10 ||
2800 quota_error u $TSTUSR "write failure"
2802 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2803 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2804 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2805 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2807 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2811 local BLKS=1 # 1M less than limit
2812 local TESTFILE=$DIR/$tdir/$tfile
2814 setup_quota_test || error "setup quota failed with $?"
2816 # make sure the system is clean
2817 local USED=$(getquota -u $TSTUSR global curspace)
2818 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2820 set_ost_qtype "ug" || error "enable ost quota failed"
2821 # make sure no granted quota on ost
2822 resetquota -u $TSTUSR
2823 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2824 error "set quota failed"
2826 quota_show_check b u $TSTUSR
2828 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2829 lustre_fail mds 0xa04 $err_code
2831 # write in background
2832 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2836 # write should be blocked and never finished
2837 if ! ps -p $DDPID > /dev/null 2>&1; then
2839 quota_error u $TSTUSR "write finished incorrectly!"
2847 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2849 if [ $count -gt $timeout ]; then
2850 quota_error u $TSTUSR "dd is not finished!"
2855 sync; sync_all_data || true
2857 USED=$(getquota -u $TSTUSR global curspace)
2858 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2859 "Used space(${USED}K) is less than ${BLKS}M"
2864 # DQACQ return recoverable error
2866 echo "DQACQ return -ENOLCK"
2868 test_17sub 37 || error "Handle -ENOLCK failed"
2870 echo "DQACQ return -EAGAIN"
2872 test_17sub 11 || error "Handle -EAGAIN failed"
2874 echo "DQACQ return -ETIMEDOUT"
2875 #define ETIMEDOUT 110
2876 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2878 echo "DQACQ return -ENOTCONN"
2879 #define ENOTCONN 107
2880 test_17sub 107 || error "Handle -ENOTCONN failed"
2883 run_test 17 "DQACQ return recoverable error"
2887 local blimit=200 # MB
2888 local TESTFILE="$DIR/$tdir/$tfile"
2890 setup_quota_test || error "setup quota failed with $?"
2892 set_ost_qtype "u" || error "enable ost quota failed"
2893 log "User quota (limit: $blimit)"
2894 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2895 error "set quota failed"
2896 quota_show_check b u $TSTUSR
2898 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2899 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2901 local timeout=$($LCTL get_param -n timeout)
2903 if [ $io_type = "directio" ]; then
2904 log "Write 100M (directio) ..."
2905 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2907 log "Write 100M (buffered) ..."
2908 $RUNAS $DD of=$TESTFILE count=100 &
2912 replay_barrier $SINGLEMDS
2913 log "Fail mds for $((2 * timeout)) seconds"
2914 fail $SINGLEMDS $((2 * timeout))
2917 if at_is_enabled; then
2918 timeout=$(at_max_get mds)
2920 timeout=$($LCTL get_param -n timeout)
2924 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2925 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2926 log "it took $count second"
2931 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2933 cancel_lru_locks mdc
2934 cancel_lru_locks osc
2937 local testfile_size=$(stat -c %s $TESTFILE)
2938 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2939 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2940 "got ${testfile_size}. Verifying file failed!"
2945 # test when mds does failover, the ost still could work well
2946 # this test shouldn't trigger watchdog b=14840
2948 # Clear dmesg so watchdog is not triggered by previous
2950 do_facet ost1 dmesg -c > /dev/null
2953 test_18_sub directio
2955 # check if watchdog is triggered
2956 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2957 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2958 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2959 [ -z "$watchdog" ] || error "$watchdog"
2960 rm -f $TMP/lustre-log-${TESTNAME}.log
2962 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2966 local TESTFILE=$DIR/$tdir/$tfile
2968 setup_quota_test || error "setup quota failed with $?"
2970 set_ost_qtype $QTYPE || error "enable ost quota failed"
2972 # bind file to a single OST
2973 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2974 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2976 echo "Set user quota (limit: ${blimit}M)"
2977 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2978 error "set user quota failed"
2979 quota_show_check b u $TSTUSR
2980 echo "Update quota limits"
2981 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2982 error "set group quota failed"
2983 quota_show_check b u $TSTUSR
2985 # first wirte might be cached
2986 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2987 cancel_lru_locks osc
2989 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2990 quota_error u $TSTUSR "Write success, expect failure"
2993 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2995 test_20() { # b15754
2996 local LSTR=(2g 1t 4k 3m) # limits strings
2998 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
3001 resetquota -u $TSTUSR
3003 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
3004 $MOUNT || error "could not set quota limits"
3005 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
3006 --inode-softlimit ${LSTR[2]} \
3007 --inode-hardlimit ${LSTR[3]} \
3008 $MOUNT || error "could not set quota limits"
3010 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
3011 error "bsoftlimit was not set properly"
3012 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
3013 error "bhardlimit was not set properly"
3014 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
3015 error "isoftlimit was not set properly"
3016 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
3017 error "ihardlimit was not set properly"
3019 resetquota -u $TSTUSR
3021 run_test 20 "Test if setquota specifiers work properly (b15754)"
3028 local time=$(($(date +%s) + seconds))
3029 while [ $(date +%s) -lt $time ]; do
3030 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
3034 # run for fixing bug16053, setquota shouldn't fail when writing and
3035 # deleting are happening
3037 local TESTFILE="$DIR/$tdir/$tfile"
3038 local BLIMIT=10 # 10G
3039 local ILIMIT=1000000
3041 setup_quota_test || error "setup quota failed with $?"
3043 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3045 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
3046 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
3047 error "set user quota failed"
3048 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
3049 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
3050 error "set group quota failed"
3051 if is_project_quota_supported; then
3052 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
3053 "project: $TSTPRJID"
3054 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
3055 $MOUNT || error "set project quota failed"
3058 # repeat writing on a 1M file
3059 test_21_sub ${TESTFILE}_1 1 30 &
3061 # repeat writing on a 128M file
3062 test_21_sub ${TESTFILE}_2 128 30 &
3065 local time=$(($(date +%s) + 30))
3067 while [ $(date +%s) -lt $time ]; do
3068 log "Set quota for $i times"
3069 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3070 -I $((ILIMIT + i)) $MOUNT ||
3071 error "Set user quota failed"
3072 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3073 -I $((ILIMIT + i)) $MOUNT ||
3074 error "Set group quota failed"
3075 if is_project_quota_supported; then
3076 $LFS setquota -p $TSTPRJID -b 0 -B \
3077 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
3078 error "Set project quota failed"
3086 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
3088 if [ $count -gt 60 ]; then
3089 quota_error a $TSTUSR "dd should be finished!"
3093 echo "(dd_pid=$DDPID1, time=$count)successful"
3097 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
3099 if [ $count -gt 60 ]; then
3100 quota_error a $TSTUSR "dd should be finished!"
3104 echo "(dd_pid=$DDPID2, time=$count)successful"
3106 run_test 21 "Setquota while writing & deleting (b16053)"
3108 # enable/disable quota enforcement permanently
3110 echo "Set both mdt & ost quota type as ug"
3112 is_project_quota_supported && qtype=$QTYPE
3113 set_mdt_qtype $qtype || error "enable mdt quota failed"
3114 set_ost_qtype $qtype || error "enable ost quota failed"
3117 stopall || error "failed to stopall (1)"
3121 echo "Verify if quota is enabled"
3122 local qtype1=$(mdt_quota_type)
3123 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
3124 qtype=$(ost_quota_type)
3125 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
3127 echo "Set both mdt & ost quota type as none"
3128 set_mdt_qtype "none" || error "disable mdt quota failed"
3129 set_ost_qtype "none" || error "disable ost quota failed"
3132 stopall || error "failed to stopall (2)"
3137 echo "Verify if quota is disabled"
3138 qtype=$(mdt_quota_type)
3139 [ $qtype != "none" ] && error "mdt quota setting is lost"
3140 qtype=$(ost_quota_type)
3141 [ $qtype != "none" ] && error "ost quota setting is lost"
3145 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3148 local TESTFILE="$DIR/$tdir/$tfile"
3151 setup_quota_test || error "setup quota failed with $?"
3153 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3156 log "User quota (limit: $LIMIT MB)"
3157 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3158 error "set quota failed"
3159 quota_show_check b u $TSTUSR
3161 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3162 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3164 log "Step1: trigger EDQUOT with O_DIRECT"
3165 log "Write half of file"
3166 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3167 quota_error u $TSTUSR "(1) Write failure, expect success." \
3169 log "Write out of block quota ..."
3170 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3171 oflag=direct conv=notrunc &&
3172 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3176 log "Step2: rewrite should succeed"
3177 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3178 quota_error u $TSTUSR "(3) Write failure, expect success." \
3184 local OST0_UUID=$(ostuuid_from_index 0)
3185 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3186 [ $OST0_QUOTA_USED -ne 0 ] &&
3187 ($SHOW_QUOTA_USER; \
3188 quota_error u $TSTUSR "quota isn't released")
3193 [ "$ost1_FSTYPE" == zfs ] &&
3194 skip "Overwrite in place is not guaranteed to be " \
3195 "space neutral on ZFS"
3197 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3198 check_whether_skip && return 0
3199 log "run for 4MB test file"
3202 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3203 check_whether_skip && return 0
3204 log "run for 40MB test file"
3207 run_test 23 "Quota should be honored with directIO (b16125)"
3211 local TESTFILE="$DIR/$tdir/$tfile"
3213 setup_quota_test || error "setup quota failed with $?"
3215 set_ost_qtype $QTYPE || error "enable ost quota failed"
3217 # bind file to a single OST
3218 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3219 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3221 echo "Set user quota (limit: ${blimit}M)"
3222 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3223 error "set quota failed"
3225 # overrun quota by root user
3226 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3227 error "write failure, expect success"
3228 cancel_lru_locks osc
3229 sync_all_data || true
3231 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3233 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3237 (( $MDS1_VERSION >= $(version_code 2.15.55.145) )) ||
3238 skip "need MDS >= v2_15_55-145-g513b1cdbc for index version fix"
3240 local limit=10 # 10M
3241 local testfile="$DIR/$tdir/$tfile-0"
3242 local qpool="qpool1"
3245 setup_quota_test || error "setup quota failed with $?"
3248 set_ost_qtype $QTYPE || error "enable ost quota failed"
3250 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
3251 error "set user quota failed"
3253 pool_add $qpool || error "pool_add failed"
3254 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
3255 error "pool_add_targets failed"
3257 # increase ost index version to +200
3258 for i in {1..200}; do
3259 $LFS setquota -u $TSTUSR -B ${i}G --pool $qpool $DIR ||
3260 error "set user quota failed"
3262 $LFS setquota -u $TSTUSR -b 0 -B 0 --pool $qpool $DIR ||
3263 error "set user quota failed"
3265 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
3266 error "set user quota failed"
3268 local used=$(getquota -u $TSTUSR global curspace)
3269 (( used == 0)) || error "Used space($used) for user $TSTUSR isn't 0."
3271 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
3272 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
3274 test_1_check_write $testfile "user" $limit
3277 run_test 25 "check indexes versions"
3279 test_27a() { # b19612
3280 $LFS quota $TSTUSR $DIR &&
3281 error "lfs succeeded with no type, but should have failed"
3282 $LFS setquota $TSTUSR $DIR &&
3283 error "lfs succeeded with no type, but should have failed"
3286 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3288 test_27b() { # b20200
3289 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3290 error "lfs setquota failed with uid argument"
3291 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3292 error "lfs stequota failed with gid argument"
3293 if is_project_quota_supported; then
3294 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3295 1000 $DIR || error \
3296 "lfs stequota failed with projid argument"
3298 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3299 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3300 if is_project_quota_supported; then
3301 $SHOW_QUOTA_PROJID ||
3302 error "lfs quota failed with projid argument"
3303 resetquota_one -p $TSTPRJID
3305 resetquota -u $TSTID
3306 resetquota -g $TSTID
3309 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3314 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3315 error "lfs setquota failed"
3317 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3318 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3319 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3320 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3322 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3323 error "lfs setquota for $TSTID failed"
3325 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3326 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3327 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3328 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3330 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3331 error "total allocated inode/block limit not printed"
3333 resetquota -u $TSTUSR
3335 run_test 27c "lfs quota should support human-readable output"
3342 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3343 error "set fraction block limit failed"
3344 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3345 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3346 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3347 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3349 resetquota -u $TSTUSR
3351 run_test 27d "lfs setquota should support fraction block limit"
3355 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
3356 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
3359 local TESTFILE="$DIR/$tdir/$tfile"
3362 setup_quota_test || error "setup quota failed with $?"
3364 set_ost_qtype "u" || error "enable ost quota failed"
3366 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3367 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3369 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3370 $MAX_IQ_TIME $DIR || error "set grace time failed"
3371 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3372 error "set quota failed"
3373 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3374 cancel_lru_locks osc
3376 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3377 # over-quota flag has not yet settled since we do not trigger async
3378 # events based on grace time period expiration
3380 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3381 cancel_lru_locks osc
3382 # now over-quota flag should be settled and further writes should fail
3384 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3385 error "grace times were reset"
3386 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3387 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3389 run_test 30 "Hard limit updates should not reset grace times"
3391 # basic usage tracking for user & group
3393 local INODES=10 # files
3394 local BLK_CNT=2 # MB each
3395 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
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 -g $TSTID global curspace)
3405 error "Used space ($USED) for group $TSTID isn't 0."
3406 if is_project_quota_supported; then
3407 USED=$(getquota -p $TSTPRJID global curspace)
3408 [ $USED -ne 0 ] && error \
3409 "Used space ($USED) for project $TSTPRJID isn't 0."
3412 echo "Write files..."
3413 for i in $(seq 0 $INODES); do
3414 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3415 error "write failed"
3416 is_project_quota_supported &&
3417 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3418 echo "Iteration $i/$INODES completed"
3420 cancel_lru_locks osc
3422 echo "Wait for setattr on objects finished..."
3423 wait_delete_completed
3425 sync; sync_all_data || true
3427 echo "Verify disk usage after write"
3428 USED=$(getquota -u $TSTID global curspace)
3429 [ $USED -lt $TOTAL_BLKS ] &&
3430 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3431 USED=$(getquota -g $TSTID global curspace)
3432 [ $USED -lt $TOTAL_BLKS ] &&
3433 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3434 if is_project_quota_supported; then
3435 USED=$(getquota -p $TSTPRJID global curspace)
3436 [ $USED -lt $TOTAL_BLKS ] && error \
3437 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3440 echo "Verify inode usage after write"
3441 USED=$(getquota -u $TSTID global curinodes)
3442 [ $USED -lt $INODES ] &&
3443 error "Used inode for user $TSTID is $USED, expected $INODES"
3444 USED=$(getquota -g $TSTID global curinodes)
3445 [ $USED -lt $INODES ] &&
3446 error "Used inode for group $TSTID is $USED, expected $INODES"
3447 if is_project_quota_supported; then
3448 USED=$(getquota -p $TSTPRJID global curinodes)
3449 [ $USED -lt $INODES ] && error \
3450 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3455 echo "Verify disk usage after delete"
3456 USED=$(getquota -u $TSTID global curspace)
3457 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3458 USED=$(getquota -u $TSTID global curinodes)
3459 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3460 USED=$(getquota -g $TSTID global curspace)
3461 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3462 USED=$(getquota -g $TSTID global curinodes)
3463 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3464 if is_project_quota_supported; then
3465 USED=$(getquota -p $TSTPRJID global curspace)
3467 error "Used space for project $TSTPRJID isn't 0. $USED"
3468 USED=$(getquota -p $TSTPRJID global curinodes)
3470 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3473 run_test 33 "Basic usage tracking for user & group & project"
3475 # usage transfer test for user & group & project
3477 local BLK_CNT=2 # MB
3478 local project_supported="no"
3480 is_project_quota_supported && project_supported="yes"
3481 setup_quota_test || error "setup quota failed with $?"
3483 # make sure the system is clean
3484 local USED=$(getquota -u $TSTID global curspace)
3485 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3486 USED=$(getquota -g $TSTID global curspace)
3487 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3489 local USED=$(getquota -u $TSTID2 global curspace)
3490 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3491 if [ $project_supported == "yes" ]; then
3492 USED=$(getquota -p $TSTPRJID global curspace)
3493 [ $USED -ne 0 ] && error \
3494 "Used space ($USED) for Project $TSTPRJID isn't 0."
3497 echo "Write file..."
3498 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3499 error "write failed"
3500 cancel_lru_locks osc
3501 sync; sync_all_data || true
3503 echo "chown the file to user $TSTID"
3504 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3506 echo "Wait for setattr on objects finished..."
3507 wait_delete_completed
3509 BLK_CNT=$((BLK_CNT * 1024))
3511 echo "Verify disk usage for user $TSTID"
3512 USED=$(getquota -u $TSTID global curspace)
3513 [ $USED -lt $BLK_CNT ] &&
3514 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3515 USED=$(getquota -u $TSTID global curinodes)
3517 error "Used inodes for user $TSTID is $USED, expected 1"
3519 echo "chgrp the file to group $TSTID"
3520 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3522 echo "Wait for setattr on objects finished..."
3523 wait_delete_completed
3525 echo "Verify disk usage for group $TSTID"
3526 USED=$(getquota -g $TSTID global curspace)
3527 [ $USED -ge $BLK_CNT ] ||
3528 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3529 USED=$(getquota -g $TSTID global curinodes)
3531 error "Used inodes for group $TSTID is $USED, expected 1"
3533 # chown won't change the ost object group. LU-4345 */
3534 echo "chown the file to user $TSTID2"
3535 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3537 echo "Wait for setattr on objects finished..."
3538 wait_delete_completed
3540 echo "change_project project id to $TSTPRJID"
3541 [ $project_supported == "yes" ] &&
3542 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3543 echo "Wait for setattr on objects finished..."
3544 wait_delete_completed
3546 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3547 USED=$(getquota -u $TSTID2 global curspace)
3548 [ $USED -lt $BLK_CNT ] &&
3549 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3550 USED=$(getquota -u $TSTID global curspace)
3552 error "Used space for user $TSTID is $USED, expected 0"
3553 USED=$(getquota -g $TSTID global curspace)
3554 [ $USED -lt $BLK_CNT ] &&
3555 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3556 if [ $project_supported == "yes" ]; then
3557 USED=$(getquota -p $TSTPRJID global curspace)
3558 [ $USED -lt $BLK_CNT ] && error \
3559 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3563 run_test 34 "Usage transfer for user & group & project"
3565 # usage is still accessible across restart
3567 local BLK_CNT=2 # MB
3569 setup_quota_test || error "setup quota failed with $?"
3571 echo "Write file..."
3572 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3573 error "write failed"
3574 is_project_quota_supported &&
3575 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3578 echo "Wait for setattr on objects finished..."
3579 wait_delete_completed
3581 sync; sync_all_data || true
3583 echo "Save disk usage before restart"
3584 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3585 [ $ORIG_USR_SPACE -eq 0 ] &&
3586 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3587 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3588 [ $ORIG_USR_INODES -eq 0 ] &&
3589 error "Used inodes for user $TSTID is 0, expected 1"
3590 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3591 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3592 [ $ORIG_GRP_SPACE -eq 0 ] &&
3593 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3594 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3595 [ $ORIG_GRP_INODES -eq 0 ] &&
3596 error "Used inodes for group $TSTID is 0, expected 1"
3597 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3599 if is_project_quota_supported; then
3600 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3601 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3602 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3603 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3604 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3605 "Used inodes for project $TSTPRJID is 0, expected 1"
3606 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3612 wait_recovery_complete
3615 echo "Verify disk usage after restart"
3616 local USED=$(getquota -u $TSTID global curspace)
3617 (( $USED == $ORIG_USR_SPACE )) || {
3618 ls -al $DIR/$tdir/$tfile
3619 $LFS quota -v -u $TSTID $DIR
3620 error "Used space for user $TSTID changed from " \
3621 "$ORIG_USR_SPACE to $USED"
3623 USED=$(getquota -u $TSTID global curinodes)
3624 [ $USED -eq $ORIG_USR_INODES ] ||
3625 error "Used inodes for user $TSTID changed from " \
3626 "$ORIG_USR_INODES to $USED"
3627 USED=$(getquota -g $TSTID global curspace)
3628 [ $USED -eq $ORIG_GRP_SPACE ] ||
3629 error "Used space for group $TSTID changed from " \
3630 "$ORIG_GRP_SPACE to $USED"
3631 USED=$(getquota -g $TSTID global curinodes)
3632 [ $USED -eq $ORIG_GRP_INODES ] ||
3633 error "Used inodes for group $TSTID changed from " \
3634 "$ORIG_GRP_INODES to $USED"
3635 if [[ $project_supported == "yes" ]]; then
3636 USED=$(getquota -p $TSTPRJID global curinodes)
3637 (( $USED == $ORIG_PRJ_INODES )) ||
3638 error "Used inodes for project $TSTPRJID " \
3639 "changed from $ORIG_PRJ_INODES to $USED"
3640 USED=$(getquota -p $TSTPRJID global curspace)
3641 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3642 error "Used space for project $TSTPRJID "\
3643 "changed from $ORIG_PRJ_SPACE to $USED"
3646 # check if the vfs_dq_init() is called before writing
3647 echo "Append to the same file..."
3648 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3649 error "write failed"
3650 cancel_lru_locks osc
3651 sync; sync_all_data || true
3653 echo "Verify space usage is increased"
3654 USED=$(getquota -u $TSTID global curspace)
3655 [ $USED -gt $ORIG_USR_SPACE ] ||
3656 error "Used space for user $TSTID isn't increased" \
3657 "orig:$ORIG_USR_SPACE, now:$USED"
3658 USED=$(getquota -g $TSTID global curspace)
3659 [ $USED -gt $ORIG_GRP_SPACE ] ||
3660 error "Used space for group $TSTID isn't increased" \
3661 "orig:$ORIG_GRP_SPACE, now:$USED"
3662 if [[ $project_supported == "yes" ]]; then
3663 USED=$(getquota -p $TSTPRJID global curspace)
3664 (( $USED > $ORIG_PRJ_SPACE )) ||
3665 error "Used space for project $TSTPRJID isn't " \
3666 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3669 run_test 35 "Usage is still accessible across reboot"
3671 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3674 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3675 skip "Old server doesn't have LU-5006 fix."
3677 setup_quota_test || error "setup quota failed with $?"
3679 # make sure the system is clean
3680 local USED=$(getquota -u $TSTID global curspace)
3682 error "Used space ($USED) for user $TSTID isn't 0."
3684 # create file with MDS_OPEN_DELAY_CREATE flag
3685 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3686 error "Create file failed"
3688 $DD of=$DIR/$tdir/$tfile count=1 conv=notrunc \
3689 oflag=sync || error "Write file failed"
3691 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3693 # wait for setattr on objects finished..."
3694 wait_delete_completed
3696 USED=$(getquota -u $TSTID global curspace)
3697 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3699 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3703 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3704 skip "Old server doesn't have LU-8801 fix."
3706 [ "$UID" != 0 ] && skip_env "must run as root" && return
3708 setup_quota_test || error "setup quota failed with $?"
3710 # make sure the system is clean
3711 local USED=$(getquota -u $TSTID global curspace)
3713 error "Used space ($USED) for user $TSTID isn't 0."
3714 USED=$(getquota -u $TSTID2 global curspace)
3716 error "Used space ($USED) for user $TSTID2 isn't 0."
3718 local TESTFILE="$DIR/$tdir/$tfile"
3719 local file_cnt=10000
3721 # Generate id entries in accounting file
3722 echo "Create $file_cnt files..."
3723 for i in `seq $file_cnt`; do
3725 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3726 error "failed to chown $TESTFILE-$i"
3728 cancel_lru_locks osc
3729 sync; sync_all_data || true
3731 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3732 procf=${procf}.quota_slave.acct_user
3735 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3736 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3737 echo "Found $acct_cnt id entries"
3739 [ $file_cnt -eq $acct_cnt ] || {
3740 do_facet mds1 $LCTL get_param $procf
3741 error "skipped id entries"
3744 run_test 38 "Quota accounting iterator doesn't skip id entries"
3747 local TESTFILE="$DIR/$tdir/project"
3748 ! is_project_quota_supported &&
3749 skip "Project quota is not supported"
3751 setup_quota_test || error "setup quota failed with $?"
3754 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3755 [ $projectid -ne 0 ] &&
3756 error "Project id should be 0 not $projectid"
3757 change_project -p 1024 $TESTFILE
3758 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3759 [ $projectid -ne 1024 ] &&
3760 error "Project id should be 1024 not $projectid"
3762 stopall || error "failed to stopall (1)"
3765 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3766 [ $projectid -eq 1024 ] ||
3767 error "Project id should be 1024 not $projectid"
3769 run_test 39 "Project ID interface works correctly"
3772 ! is_project_quota_supported &&
3773 skip "Project quota is not supported"
3774 local dir1="$DIR/$tdir/dir1"
3775 local dir2="$DIR/$tdir/dir2"
3777 setup_quota_test || error "setup quota failed with $?"
3779 mkdir -p $dir1 $dir2
3780 change_project -sp 1 $dir1 && touch $dir1/1
3781 change_project -sp 2 $dir2
3783 ln $dir1/1 $dir2/1_link &&
3784 error "Hard link across different project quota should fail"
3787 run_test 40a "Hard link across different project ID"
3790 ! is_project_quota_supported &&
3791 skip "Project quota is not supported"
3792 local dir1="$DIR/$tdir/dir1"
3793 local dir2="$DIR/$tdir/dir2"
3795 setup_quota_test || error "setup quota failed with $?"
3796 mkdir -p $dir1 $dir2
3797 change_project -sp 1 $dir1 && touch $dir1/1
3798 change_project -sp 2 $dir2
3800 mv $dir1/1 $dir2/2 || error "mv failed $?"
3801 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3802 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3804 run_test 40b "Mv across different project ID"
3807 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3808 ! is_project_quota_supported &&
3809 skip "Project quota is not supported"
3811 setup_quota_test || error "setup quota failed with $?"
3812 local dir="$DIR/$tdir/dir"
3814 mkdir -p $dir && change_project -sp 1 $dir
3815 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3816 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3817 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3818 touch $dir/remote_dir/file
3819 #verify inherit works file for remote dir.
3820 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3821 [ "$projid" != "1" ] &&
3822 error "file under remote dir expected 1 not $projid"
3824 #Agent inode should be ignored for project quota
3825 local used=$(getquota -p 1 global curinodes)
3827 error "file count expected 3 got $used"
3829 run_test 40c "Remote child Dir inherit project quota properly"
3832 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3833 is_project_quota_supported || skip "Project quota is not supported"
3835 setup_quota_test || error "setup quota failed with $?"
3836 local dir="$DIR/$tdir/dir"
3839 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3840 change_project -sp $TSTPRJID $dir ||
3841 error "change project on $dir failed"
3842 for i in $(seq 5); do
3843 mkdir -p $dir/d$i/d$i ||
3844 error "mkdir $dir/d$i/d$i failed"
3845 local projid=$($LFS project -d $dir/d$i/d$i |
3847 [ "$projid" == "$TSTPRJID" ] ||
3848 error "projid id expected $TSTPRJID not $projid"
3849 touch $dir/d$i/d$i/file
3850 #verify inherit works file for stripe dir.
3851 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3852 [ "$projid" == "$TSTPRJID" ] ||
3853 error "file under remote dir expected 1 not $projid"
3856 # account should be 1 + (2 + 1) *10 + 1 * 5
3857 local used=$(getquota -p $TSTPRJID global curinodes)
3859 error "file count expected 36 got $used"
3861 run_test 40d "Stripe Directory inherit project quota properly"
3864 is_project_quota_supported ||
3865 skip "Project quota is not supported"
3866 setup_quota_test || error "setup quota failed with $?"
3867 local dir="$DIR/$tdir/dir"
3870 local projid=$((testnum * 1000))
3874 # enable mdt/ost quota
3875 set_mdt_qtype ugp || error "enable mdt quota failed"
3876 set_ost_qtype ugp || error "enable ost quota failed"
3878 local statfs_prj_orig=$($LCTL get_param -n llite.*.statfs_project)
3879 (( statfs_prj_orig == 1 )) ||
3880 $LCTL set_param llite.*.statfs_project=1
3881 stack_trap "$LCTL set_param llite.*.statfs_project=$statfs_prj_orig"
3883 test_mkdir -p $dir && change_project -sp $projid $dir
3884 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3885 error "set project quota failed"
3890 # check if df output works as expected
3891 echo "== global statfs: $MOUNT =="
3892 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3894 echo "== project statfs (prjid=$projid): $dir =="
3895 df -kP $dir; df -iP $dir
3896 local bused=$(getquota -p $projid global curspace)
3897 local iused=$(getquota -p $projid global curinodes)
3898 local expected="$ilimit$iused"
3900 wait_update $HOSTNAME \
3901 "df -iP $dir | awk \\\"/$FSNAME/\\\"'{print \\\$2 \\\$3}'" \
3903 error "failed to get correct statfs for project quota"
3905 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $2}')
3906 (( expected == blimit )) ||
3907 error "blimit mismatch: $expected != $blimit"
3909 # zfs block size is 4K, while quota is printed in 1K, df result may be
3910 # larger than quota result, but it's no more than 3K
3911 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $3}')
3912 (( expected - bused < 4)) || error "bused mismatch: $expected != $bused"
3914 # disable statfs_project and check again
3915 $LCTL set_param llite.*.statfs_project=0
3917 expected=$({ df -kP $MOUNT; df -iP $MOUNT; } | \
3918 awk '/'$FSNAME'/ { printf "%d %d ", $2,$3 }')
3920 wait_update $HOSTNAME \
3921 "{ df -kP $dir; df -iP $dir; } |
3922 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3924 error "failed to get correct statfs when statfs_project=0"
3926 run_test 41 "df should return projid-specific values"
3934 local osd="osd-ldiskfs"
3936 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3938 rm -f $DIR/$tdir/$tfile
3939 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3940 chmod a+rw $DIR/$tdir/$tfile
3942 $LFS setquota $qtype $qid -B 300M $MOUNT
3943 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3945 do_facet $SINGLEMDS \
3946 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3947 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3950 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3951 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3953 $LFS setquota $qtype $qid --delete $MOUNT
3954 do_facet $SINGLEMDS \
3955 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3956 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3959 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3960 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3962 $LFS setquota $qtype $qid -B 500M $MOUNT
3963 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3964 do_facet $SINGLEMDS \
3965 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3966 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3967 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3969 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3970 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3975 setup_quota_test || error "setup quota failed with $?"
3976 set_ost_qtype $QTYPE || error "enable ost quota failed"
3979 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3980 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3981 is_project_quota_supported &&
3982 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3986 run_test 48 "lfs quota --delete should delete quota project ID"
3989 ! is_project_quota_supported &&
3990 skip "Project quota is not supported"
3992 setup_quota_test || error "setup quota failed with $?"
3993 local dir1="$DIR/$tdir/dir1"
3994 local dir2="$DIR/$tdir/dir2"
3996 mkdir -p $dir1 && change_project -sp 1 $dir1
3997 mkdir -p $dir2 && change_project -sp 2 $dir2
3998 for num in $(seq 1 10); do
3999 touch $dir1/file_$num $dir2/file_$num
4000 ln -s $dir1/file_$num $dir1/file_$num"_link"
4001 ln -s $dir2/file_$num $dir2/file_$num"_link"
4004 count=$($LFS find --projid 1 $DIR | wc -l)
4005 [ "$count" != 21 ] && error "expected 21 but got $count"
4007 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
4008 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
4009 [ $count -eq 22 ] || error "expected 22 but got $count"
4011 run_test 50 "Test if lfs find --projid works"
4014 ! is_project_quota_supported &&
4015 skip "Project quota is not supported"
4016 setup_quota_test || error "setup quota failed with $?"
4017 local dir="$DIR/$tdir/dir"
4019 mkdir $dir && change_project -sp 1 $dir
4020 local used=$(getquota -p 1 global curinodes)
4021 [ $used != "1" ] && error "expected 1 got $used"
4026 used=$(getquota -p 1 global curinodes)
4027 [ $used != "4" ] && error "expected 4 got $used"
4029 $DD of=$DIR/$tdir/6 count=1
4031 cp $DIR/$tdir/6 $dir/6
4032 used=$(getquota -p 1 global curinodes)
4033 [ $used != "5" ] && error "expected 5 got $used"
4036 mv $DIR/$tdir/6 $dir/7
4037 used=$(getquota -p 1 global curinodes)
4038 [ $used -eq 6 ] || error "expected 6 got $used"
4040 run_test 51 "Test project accounting with mv/cp"
4043 ! is_project_quota_supported &&
4044 skip "Project quota is not supported"
4046 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
4047 skip "Need MDS version at least 2.14.55"
4049 setup_quota_test || error "setup quota failed with $?"
4051 local dir1=$DIR/$tdir/t52_dir1
4052 local dir2=$DIR/$tdir/t52_dir2
4054 mkdir $dir1 || error "failed to mkdir $dir1"
4055 mkdir $dir2 || error "failed to mkdir $dir2"
4057 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
4058 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
4060 $DD of=$dir1/$tfile count=100 ||
4061 error "failed to create and write $dir1/$tfile"
4063 cancel_lru_locks osc
4064 sync; sync_all_data || true
4066 local attrs=($(lsattr -p $dir1/$tfile))
4067 (( ${attrs[0]} == 1000 )) ||
4068 error "project ID on $dir1/$tfile is not inherited"
4070 $LFS quota -p 1000 $DIR
4071 $LFS quota -p 1001 $DIR
4073 local prev_used=$(getquota -p 1000 global curspace)
4074 local prev_used2=$(getquota -p 1001 global curspace)
4076 mrename $dir1 $dir2/tdir || log "rename directory return $?"
4078 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
4079 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
4080 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
4082 attrs=($(lsattr -p $dir2/$tfile))
4083 (( ${attrs[0]} == 1001 )) ||
4084 error "project ID is not updated after rename"
4086 (( $inum_before == $inum_after )) ||
4087 error "inode is changed after rename: $inum_before, $inum_after"
4089 sync_all_data || true
4091 $LFS quota -p 1000 $DIR
4092 $LFS quota -p 1001 $DIR
4094 local new_used=$(getquota -p 1000 global curspace)
4095 local new_used2=$(getquota -p 1001 global curspace)
4097 (( $prev_used >= $new_used + 102400 )) ||
4098 error "quota is not deducted from old project ID"
4099 (( $prev_used2 <= $new_used2 - 102400 )) ||
4100 error "quota is not added for the new project ID"
4102 run_test 52 "Rename normal file across project ID"
4105 ! is_project_quota_supported &&
4106 skip "Project quota is not supported"
4107 setup_quota_test || error "setup quota failed with $?"
4108 local dir="$DIR/$tdir/dir"
4109 mkdir $dir && change_project -s $dir
4110 [[ $($LFS project -d $dir) =~ " P " ]] ||
4111 error "inherit attribute should be set"
4113 change_project -C $dir
4114 [[ $($LFS project -d $dir) =~ " - " ]] ||
4115 error "inherit attribute should be cleared"
4117 run_test 53 "Project inherit attribute could be cleared"
4120 ! is_project_quota_supported &&
4121 skip "Project quota is not supported"
4122 setup_quota_test || error "setup quota failed with $?"
4123 local testfile="$DIR/$tdir/$tfile-0"
4125 #set project ID/inherit attribute
4126 change_project -sp $TSTPRJID $DIR/$tdir
4127 $RUNAS createmany -m ${testfile} 100 ||
4128 error "create many files failed"
4130 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
4131 # one more count for directory itself */
4135 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4136 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
4138 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
4139 [ $proj_count1 -eq $proj_count ] ||
4140 error "c2: expected $proj_count got $proj_count1"
4142 #clear project but with kept projid
4143 change_project -rCk $DIR/$tdir
4144 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4145 [ $proj_count1 -eq 1 ] ||
4146 error "c3: expected 1 got $proj_count1"
4148 #verify projid untouched.
4149 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4151 [ $proj_count1 -eq $proj_count ] ||
4152 error "c4: expected $proj_count got $proj_count1"
4155 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
4156 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4157 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
4159 #this time clear all
4160 change_project -rC $DIR/$tdir
4161 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4162 [ $proj_count1 -eq 0 ] ||
4163 error "c6: expected 0 got $proj_count1"
4165 unlinkmany ${testfile} 100 ||
4166 error "unlink many files failed"
4168 run_test 54 "basic lfs project interface test"
4171 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
4172 skip "Not supported before 2.10.58."
4173 setup_quota_test || error "setup quota failed with $?"
4175 set_ost_qtype $QTYPE || error "enable ost quota failed"
4178 #add second group to TSTUSR
4179 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
4182 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
4183 error "failed to dd"
4185 cancel_lru_locks osc
4186 sync; sync_all_data || true
4188 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
4189 error "failed to setquota on group $TSTUSR2"
4191 $LFS quota -v -g $TSTUSR2 $DIR
4193 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
4194 error "chgrp should failed with -EDQUOT"
4196 USED=$(getquota -g $TSTUSR2 global curspace)
4199 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
4200 error "failed to setquota on group $TSTUSR2"
4202 $LFS quota -v -g $TSTUSR2 $DIR
4204 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
4205 error "chgrp should succeed"
4207 $LFS quota -v -g $TSTUSR2 $DIR
4209 run_test 55 "Chgrp should be affected by group quota"
4212 setup_quota_test || error "setup quota failed with $?"
4214 set_ost_qtype $QTYPE || error "enable ost quota failed"
4217 $LFS setquota -t -u -b 10 -i 10 $DIR ||
4218 erro "failed to set grace time for usr quota"
4219 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4220 awk '{print $4 $8}')
4221 if [ "x$grace_time" != "x10s;10s" ]; then
4222 $LFS quota -t -u $DIR
4223 error "expected grace time: 10s;10s, got:$grace_time"
4226 run_test 56 "lfs quota -t should work well"
4229 setup_quota_test || error "setup quota failed with $?"
4231 local dir="$DIR/$tdir/dir"
4234 #command can process further if it hit some errors
4235 $LFS project -sp 1 $dir/pipe
4236 touch $dir/aaa $dir/bbb
4237 mkdir $dir/subdir -p
4238 touch $dir/subdir/aaa $dir/subdir/bbb
4239 #create one invalid link file
4240 ln -s $dir/not_exist_file $dir/ccc
4241 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4242 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4244 run_test 57 "lfs project could tolerate errors"
4254 $LFS mirror extend -N2 $mirrorfile || error "failed to create mirror"
4256 local mirrors=$($LFS getstripe -N $testfile)
4257 [[ $mirrors == 3 ]] || error "mirror count $mirrors is wrong"
4259 cancel_lru_locks osc
4260 cancel_lru_locks mdc
4261 sync; sync_all_data || true
4263 local prev_usage=$(getquota -p $projid global curspace)
4265 $RUNAS $DD of=$testfile count=50 conv=nocreat oflag=direct ||
4266 quota_error p $projid "write failed, expect succeed"
4268 cancel_lru_locks osc
4269 cancel_lru_locks mdc
4270 sync; sync_all_data || true
4272 $RUNAS $LFS mirror resync $testfile || error "failed to resync mirror"
4274 local usage=$(getquota -p $projid global curspace)
4275 (( usage >= prev_usage + 150*1024 )) ||
4276 error "project quota $usage is wrong"
4278 $RUNAS $DD of=$testfile count=30 conv=nocreat seek=50 oflag=direct ||
4279 quota_error p $projid "write failed, expect succeed"
4281 $RUNAS $LFS mirror resync $testfile &&
4282 error "resync mirror succeed, expect EDQUOT"
4284 $LFS mirror delete --mirror-id 2 $testfile ||
4285 error "failed to delete the second mirror"
4286 $LFS mirror delete --mirror-id 3 $testfile ||
4287 error "failed to delete the third mirror"
4291 (( $MDS1_VERSION >= $(version_code 2.15.56) )) ||
4292 skip "need MDS 2.15.56 or later"
4294 is_project_quota_supported || skip "Project quota is not supported"
4296 local testdir="$DIR/$tdir"
4297 local testfile="$DIR/$tdir/$tfile"
4301 setup_quota_test || error "setup quota failed with $?"
4303 USED=$(getquota -p $projid global curspace)
4304 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid isn't 0"
4306 USED=$(getquota -p $projid2 global curspace)
4307 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid2 isn't 0"
4309 chown $TSTUSR.$TSTUSR $testdir || error "chown $testdir failed"
4311 set_ost_qtype ugp || error "enable ost quota failed"
4313 $LFS project -sp $projid $testdir || error "failed to set project ID"
4314 $LFS setquota -p $projid -B 200M $DIR ||
4315 error "failed to to set prj $projid quota"
4317 $RUNAS touch $testfile
4319 local id=$(lfs project -d $testfile | awk '{print $1}')
4320 [ "$id" != "$projid" ] && error "projid $projid is not inherited $id"
4322 echo "test by mirror created with normal file"
4323 test_mirror $projid $testfile $testfile
4325 $TRUNCATE $testfile 0
4326 wait_delete_completed || error "wait_delete_completed failed"
4327 sync_all_data || true
4329 $LFS project -sp $projid2 $testdir ||
4330 error "failed to set directory project ID"
4331 $LFS project -p $projid2 $testfile ||
4332 error "failed to set file project ID"
4333 $LFS setquota -p $projid -b 0 -B 0 $DIR ||
4334 error "failed to to reset prj quota"
4335 $LFS setquota -p $projid2 -B 200M $DIR ||
4336 error "failed to to set prj $projid2 quota"
4338 local fid=$($LFS path2fid $testfile)
4340 echo "test by mirror created with FID"
4341 test_mirror $projid2 $testfile $MOUNT/.lustre/fid/$fid
4343 run_test 58 "project ID should be kept for new mirrors created by FID"
4346 [ "$mds1_FSTYPE" != ldiskfs ] &&
4347 skip "ldiskfs only test"
4348 disable_project_quota
4349 setup_quota_test || error "setup quota failed with $?"
4352 local testfile="$DIR/$tdir/$tfile-0"
4353 #make sure it did not crash kernel
4354 touch $testfile && lfs project -sp 1 $testfile
4356 enable_project_quota
4358 run_test 59 "lfs project dosen't crash kernel with project disabled"
4361 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4362 skip "Needs MDS version 2.11.53 or later."
4363 setup_quota_test || error "setup quota failed with $?"
4365 local testfile=$DIR/$tdir/$tfile
4368 set_mdt_qtype "ug" || error "enable mdt quota failed"
4370 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4371 error "set quota failed"
4372 quota_show_check a g $TSTUSR
4374 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4375 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4376 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4377 error "create many files failed"
4379 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4381 # root user can overrun quota
4382 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4383 error "root user should succeed"
4385 run_test 60 "Test quota for root with setgid"
4387 # test default quota
4388 test_default_quota() {
4389 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4390 skip "Not supported before 2.11.51."
4395 local qprjid=$TSTPRJID
4399 local LIMIT=20480 #20M disk space
4400 local TESTFILE="$DIR/$tdir/$tfile-0"
4403 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4404 echo "Project quota is not supported" && return 0
4406 [ $qtype == "-u" ] && qdtype="-U"
4407 [ $qtype == "-g" ] && qdtype="-G"
4408 [ $qtype == "-p" ] && {
4413 [ $qres_type == "meta" ] && {
4414 LIMIT=10240 #10K inodes
4419 qpool_cmd="--pool $3"
4420 # pool quotas don't work properly without global limit
4421 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4422 error "set global limit failed"
4425 setup_quota_test || error "setup quota failed with $?"
4429 # enable mdt/ost quota
4430 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4431 set_ost_qtype $QTYPE || error "enable ost quota failed"
4433 log "set to use default quota"
4434 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4435 error "set $qid to use default quota failed"
4437 log "set default quota"
4438 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4439 error "set $qid default quota failed"
4441 log "get default quota"
4442 $LFS quota $qdtype $DIR || error "get default quota failed"
4444 if [ $qres_type == "data" ]; then
4445 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4446 grep "$MOUNT" | awk '{print $2}')
4447 [ $SLIMIT -eq $LIMIT ] ||
4448 error "the returned default quota is wrong"
4450 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4452 [ $SLIMIT -eq $LIMIT ] ||
4453 error "the returned default quota is wrong"
4456 # make sure the system is clean
4457 local USED=$(getquota $qtype $qid global curspace)
4458 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4460 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4461 error "setstripe $TESTFILE failed"
4462 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4464 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4466 log "Test not out of quota"
4467 if [ $qres_type == "data" ]; then
4468 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4469 quota_error $qtype $qid "write failed, expect succeed"
4471 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4472 quota_error $qtype $qid "create failed, expect succeed"
4474 unlinkmany $TESTFILE $((LIMIT/2))
4477 log "Test out of quota"
4478 # flush cache, ensure noquota flag is set on client
4479 cancel_lru_locks osc
4480 cancel_lru_locks mdc
4481 sync; sync_all_data || true
4482 if [ $qres_type == "data" ]; then
4483 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4484 quota_error $qtype $qid "write succeed, expect EDQUOT"
4486 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4487 quota_error $qtype $qid "create succeed, expect EDQUOT"
4489 unlinkmany $TESTFILE $((LIMIT*2))
4493 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4494 error "setstripe $TESTFILE failed"
4495 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4497 log "Increase default quota"
4499 # LU-4505: sleep 5 seconds to enable quota acquire
4502 # increase default quota
4503 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4504 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4506 cancel_lru_locks osc
4507 cancel_lru_locks mdc
4508 sync; sync_all_data || true
4509 if [ $qres_type == "data" ]; then
4510 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4511 quota_error $qtype $qid "write failed, expect succeed"
4513 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4514 quota_error $qtype $qid "create failed, expect succeed"
4516 unlinkmany $TESTFILE $((LIMIT*2))
4519 log "Set quota to override default quota"
4520 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4521 error "set $qid quota failed"
4523 cancel_lru_locks osc
4524 cancel_lru_locks mdc
4525 sync; sync_all_data || true
4526 if [ $qres_type == "data" ]; then
4527 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4528 quota_error $qtype $qid "write succeed, expect EQUOT"
4530 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4531 quota_error $qtype $qid "create succeed, expect EQUOT"
4533 unlinkmany $TESTFILE $((LIMIT*2))
4536 log "Set to use default quota again"
4538 # LU-4505: sleep 5 seconds to enable quota acquire
4541 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4542 error "set $qid to use default quota failed"
4544 cancel_lru_locks osc
4545 cancel_lru_locks mdc
4546 sync; sync_all_data || true
4547 if [ $qres_type == "data" ]; then
4548 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4549 quota_error $qtype $qid "write failed, expect succeed"
4551 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4552 quota_error $qtype $qid "create failed, expect succeed"
4554 unlinkmany $TESTFILE $((LIMIT*2))
4559 wait_delete_completed || error "wait_delete_completed failed"
4560 sync_all_data || true
4562 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4563 error "reset default quota failed"
4564 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4565 error "reset quota failed"
4570 test_default_quota "-u" "data"
4571 test_default_quota "-u" "meta"
4572 test_default_quota "-g" "data"
4573 test_default_quota "-g" "meta"
4574 test_default_quota "-p" "data"
4575 test_default_quota "-p" "meta"
4577 run_test 61 "default quota tests"
4580 ! is_project_quota_supported &&
4581 skip "Project quota is not supported"
4582 [[ "$(chattr -h 2>&1)" =~ "project" ||
4583 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4584 skip "chattr did not support project quota"
4585 setup_quota_test || error "setup quota failed with $?"
4586 local testdir=$DIR/$tdir/
4588 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4589 change_project -s $testdir
4590 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4591 error "inherit attribute should be set"
4592 # chattr used FS_IOC_SETFLAGS ioctl
4593 $RUNAS chattr -P $testdir &&
4594 error "regular user clear inherit should fail"
4595 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4596 error "inherit attribute should still be set"
4597 chattr -P $testdir || error "root failed to clear inherit"
4598 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4599 error "inherit attribute should be cleared"
4602 run_test 62 "Project inherit should be only changed by root"
4605 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4606 skip "Not supported before 2.11.55"
4610 local dd_failed=false
4611 local tdir_dom=${tdir}_dom
4612 local LIMIT=20480 #20M
4614 [ $qtype == "p" ] && ! is_project_quota_supported &&
4615 echo "Project quota is not supported" && return 0
4617 [ $qtype == "p" ] && qid=$TSTPRJID
4619 setup_quota_test || error "setup quota failed with $?"
4623 # enable mdt/ost quota
4624 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4625 set_ost_qtype $QTYPE || error "enable ost quota failed"
4627 # make sure the system is clean
4628 local USED=$(getquota -$qtype $qid global curspace)
4629 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4631 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4633 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4634 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4635 error "setstripe $tdir_dom failed"
4636 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4638 [ $qtype == "p" ] && {
4639 change_project -sp $TSTPRJID $DIR/$tdir
4640 change_project -sp $TSTPRJID $DIR/$tdir_dom
4643 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4644 error "set $qid quota failed"
4646 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4647 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4651 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4653 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4654 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4658 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4660 rm -f $DIR/$tdir_dom/*
4662 # flush cache, ensure noquota flag is set on client
4663 cancel_lru_locks osc
4664 cancel_lru_locks mdc
4665 sync; sync_all_data || true
4669 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4670 quota_error $qtype $qid "write failed, expect succeed"
4672 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4673 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4677 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4680 rm -f $DIR/$tdir_dom/*
4682 # flush cache, ensure noquota flag is set on client
4683 cancel_lru_locks osc
4684 cancel_lru_locks mdc
4685 sync; sync_all_data || true
4689 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4690 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4694 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4696 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4697 quota_error $qtype $qid "write succeed, expect EDQUOT"
4700 rm -fr $DIR/$tdir_dom
4702 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4703 error "reset usr quota failed"
4711 run_test 63 "quota on DoM tests"
4714 ! is_project_quota_supported &&
4715 skip "Project quota is not supported"
4716 setup_quota_test || error "setup quota failed with $?"
4717 local dir1="$DIR/$tdir/"
4720 ln -s $dir1/file $dir1/file_link
4723 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4724 error "set project should succeed"
4726 used=$(getquota -p $TSTPRJID global curinodes)
4727 [ $used -eq 4 ] || error "expected 4 got $used"
4728 $LFS project -rC $dir1 >&/dev/null ||
4729 error "clear project should succeed"
4731 used=$(getquota -p $TSTPRJID global curinodes)
4732 [ $used -eq 0 ] || error "expected 0 got $used"
4734 run_test 64 "lfs project on non dir/files should succeed"
4738 local TESTFILE="$DIR/$tdir/$tfile-0"
4740 setup_quota_test || error "setup quota failed with $?"
4741 set_ost_qtype $QTYPE || error "enable ost quota failed"
4745 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4746 error "failed to write"
4747 # flush cache, ensure noquota flag is set on client
4748 cancel_lru_locks osc
4749 sync; sync_all_data || true
4751 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4752 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4753 local quota_all=$($RUNAS $LFS quota $DIR)
4755 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4756 error "usr quota not match"
4757 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4758 error "grp quota not match"
4760 run_test 65 "Check lfs quota result"
4763 ! is_project_quota_supported &&
4764 skip "Project quota is not supported"
4765 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4766 skip "Not supported before 2.12.4"
4767 setup_quota_test || error "setup quota failed with $?"
4768 local old=$(do_facet mds1 $LCTL get_param -n \
4769 mdt.*.enable_chprojid_gid | head -1)
4770 local testdir=$DIR/$tdir/foo
4772 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4773 stack_trap "do_facet mds1 $LCTL \
4774 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4776 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4777 chown -R $TSTID:$TSTID $testdir
4778 change_project -sp $TSTPRJID $testdir
4779 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4781 $RUNAS lfs project -p 0 $testdir/foo &&
4782 error "nonroot user should fail to set projid"
4784 $RUNAS lfs project -C $testdir/foo &&
4785 error "nonroot user should fail to clear projid"
4787 change_project -C $testdir/foo || error "failed to clear project"
4789 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4790 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4791 "failed to set projid with normal user when enable_chprojid_gid=-1"
4793 $RUNAS lfs project -rC $testdir/ || error \
4794 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4796 touch $testdir/bar || error "failed touch $testdir/bar"
4797 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4798 "normal user should not be able to set projid on root owned file"
4800 change_project -p $TSTPRJID $testdir/bar || error \
4801 "root should be able to change its own file's projid"
4803 run_test 66 "nonroot user can not change project state in default"
4810 local short_qtype=${qtype:0:1}
4813 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4815 $TSTUSR) _runas=$RUNAS;;
4816 $TSTUSR2) _runas=$RUNAS2;;
4817 *) error "unknown quota parameter $4";;
4822 $_runas $DD of=$file count=$size ||
4823 quota_error $short_qtype $TSTUSR \
4824 "$qtype write failure, but expect success"
4826 cancel_lru_locks osc
4828 sync; sync_all_data || true
4837 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4839 do_facet mds1 $LCTL get_param $param |
4840 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4845 local testfile="$DIR/$tdir/$tfile-0"
4846 local testfile2="$DIR/$tdir/$tfile-1"
4847 local testfile3="$DIR/$tdir/$tfile-2"
4848 local qpool="qpool1"
4854 [ "$ost1_FSTYPE" == zfs ] &&
4855 skip "ZFS grants some block space together with inode"
4857 setup_quota_test || error "setup quota failed with $?"
4860 set_ost_qtype $QTYPE || error "enable ost quota failed"
4863 log "User quota (block hardlimit:$limit MB)"
4864 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4865 error "set user quota failed"
4867 # make sure the system is clean
4868 used=$(getquota -u $TSTUSR global curspace)
4869 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4871 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4872 echo "granted 0x0 before write $granted"
4874 # trigger reintegration
4875 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4876 procf=${procf}quota_slave.force_reint
4877 do_facet ost1 $LCTL set_param $procf=1 ||
4878 error "force reintegration failed"
4879 wait_ost_reint "u" || error "reintegration failed"
4880 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4881 [ $granted -ne 0 ] &&
4882 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4884 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4885 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4887 # write 10 MB to testfile
4888 test_67_write "$testfile" "user" 10 "$TSTUSR"
4890 # create qpool and add OST1
4891 pool_add $qpool || error "pool_add failed"
4892 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4893 # as $TSTUSR hasn't limits, lqe may absent. But it should be
4894 # created after the 1st direct qmt_get.
4895 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4897 # check granted - should be 0, as testfile is located only on OST0
4898 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4899 echo "global granted $granted"
4900 granted=$(getgranted $qpool "dt" $TSTID "usr")
4901 echo "$qpool granted $granted"
4902 [ $granted -ne 0 ] &&
4903 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4905 # add OST0 to qpool and check granted space
4906 pool_add_targets $qpool 0 1 ||
4907 error "pool_add_targets failed"
4908 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4909 echo "Granted $granted_mb MB"
4910 #should be 10M + qunit for each OST
4911 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4912 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4914 $LFS setstripe $testfile2 -c 1 -i 1 ||
4915 error "setstripe $testfile2 failed"
4916 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4917 # Write from another user and check that qpool1
4918 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
4919 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
4920 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4921 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4922 [ $granted -ne 0 ] &&
4923 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4925 # Granted space for $TSTUSR2 in qpool1 should appear only
4926 # when global lqe for this user becomes enforced.
4927 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4928 error "set user quota failed"
4929 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4930 echo "granted_mb $granted_mb"
4931 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4932 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4934 $LFS setstripe $testfile3 -c 1 -i 0 ||
4935 error "setstripe $testfile3 failed"
4936 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4937 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
4938 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4939 echo "$testfile3 granted_mb $granted_mb"
4940 [ $granted_mb -eq $limit ] ||
4941 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4943 # remove OST1 from the qpool1 and check granted space
4944 # should be 0 for TSTUSR and 10M for TSTUSR2
4945 pool_remove_target $qpool 0
4946 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4947 [ $granted_mb -eq 0 ] ||
4948 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4949 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4950 [ $granted_mb -eq 10 ] ||
4951 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4954 wait_delete_completed || error "wait_delete_completed failed"
4955 sync_all_data || true
4956 used=$(getquota -u $TSTUSR global curspace)
4957 [ $used -eq 0 ] || quota_error u $TSTUSR \
4958 "user quota isn't released after deletion"
4960 run_test 67 "quota pools recalculation"
4967 wait_update_facet "--quiet" mds1 \
4968 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4969 >/dev/null 2>&1 || echo foo" "">/dev/null ||
4970 error "mds1: failed to create quota pool $pool"
4972 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4973 awk '/usr/ {getline; print $2}'
4978 local qpool="qpool1"
4981 setup_quota_test || error "setup quota failed with $?"
4984 set_ost_qtype $QTYPE || error "enable ost quota failed"
4986 # check slave number for glbal pool
4987 local nr=$(get_slave_nr "0x0" "usr")
4988 echo "nr result $nr"
4989 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4990 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4992 # create qpool and add OST1
4993 pool_add $qpool || error "pool_add failed"
4994 nr=$(get_slave_nr $qpool "usr")
4995 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4998 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4999 nr=$(get_slave_nr $qpool "usr")
5000 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
5003 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5004 nr=$(get_slave_nr $qpool "usr")
5005 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
5008 pool_remove_target $qpool 0
5009 nr=$(get_slave_nr $qpool "usr")
5010 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
5013 pool_remove_target $qpool 1
5014 nr=$(get_slave_nr $qpool "usr")
5015 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
5017 # Check again that all is fine with global pool
5018 nr=$(get_slave_nr "0x0" "usr")
5019 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
5020 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
5022 run_test 68 "slave number in quota pool changed after each add/remove OST"
5026 local global_limit=200 # MB
5028 local testfile="$DIR/$tdir/$tfile-0"
5029 local dom0="$DIR/$tdir/dom0"
5030 local qpool="qpool1"
5033 setup_quota_test || error "setup quota failed with $?"
5036 set_ost_qtype $QTYPE || error "enable ost quota failed"
5037 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5039 # Save DOM only at MDT0
5040 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
5041 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
5043 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
5045 # create qpool and add OST0
5046 pool_add $qpool || error "pool_add failed"
5047 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5049 log "User quota (block hardlimit:$global_limit MB)"
5050 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5051 error "set user quota failed"
5053 log "User quota (block hardlimit:$limit MB)"
5054 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5055 error "set user quota failed"
5057 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
5058 quota_error u $TSTUSR "write failed"
5060 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5061 oflag=sync || quota_error u $TSTUSR "write failed"
5063 $RUNAS $DD of=$testfile count=$limit || true
5065 # flush cache, ensure noquota flag is set on client
5066 cancel_lru_locks osc
5067 sync; sync_all_data || true
5069 # MDT0 shouldn't get EDQUOT with glimpse.
5070 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
5071 quota_error u $TSTUSR \
5072 "user write success, but expect EDQUOT"
5074 # Now all members of qpool1 should get EDQUOT. Expect success
5075 # when write to DOM on MDT0, as it belongs to global pool.
5076 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
5077 oflag=sync || quota_error u $TSTUSR "write failed"
5079 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5080 oflag=sync || quota_error u $TSTUSR "write failed"
5082 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
5086 local qpool="qpool1"
5091 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
5092 skip "Needs a client >= $VERSION_WITH_QP"
5094 setup_quota_test || error "setup quota failed with $?"
5096 # MDS returns EFAULT for unsupported quotactl command
5097 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
5099 # create qpool and add OST0
5100 pool_add $qpool || error "pool_add failed"
5101 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5103 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
5105 [ $rc -eq $err ] || error "setquota res $rc != $err"
5107 # If MDS supports QP, check that limit was set properly.
5108 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
5109 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
5110 echo "hard limit $bhard limit $limit"
5111 [ $bhard -ne $((limit*1024)) ] &&
5112 error "bhard:$bhard for $qpool!=$((limit*1024))"
5115 $LFS quota -u $TSTUSR --pool $qpool $DIR
5117 [ $rc -eq $err ] || error "quota res $rc != $err"
5119 run_test 70a "check lfs setquota/quota with a pool option"
5123 local glbl_hard=200 # 200M
5124 local glbl_soft=100 # 100M
5125 local pool_hard=10 # 10M
5126 local qpool="qpool1"
5128 pool_add $qpool || error "pool_add failed"
5129 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5131 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
5132 error "set user quota failed"
5133 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
5134 error "set user quota failed"
5136 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5137 [ $tmp -eq $((pool_hard * 1024)) ] ||
5138 error "wrong block hard limit $tmp for $qpool"
5139 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
5140 # soft limit hasn't been set and should be zero
5141 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
5143 run_test 70b "lfs setquota pool works properly"
5148 local global_limit=100 # MB
5149 local testfile="$DIR/$tdir/$tfile-0"
5150 local qpool="qpool1"
5151 local qpool2="qpool2"
5153 [ "$ost1_FSTYPE" == zfs ] &&
5154 skip "ZFS grants some block space together with inode"
5155 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
5157 setup_quota_test || error "setup quota failed with $?"
5160 set_ost_qtype $QTYPE || error "enable ost quota failed"
5163 log "User quota (block hardlimit:$global_limit MB)"
5164 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5165 error "set user quota failed"
5167 pool_add $qpool || error "pool_add failed"
5168 pool_add_targets $qpool 0 1 ||
5169 error "pool_add_targets failed"
5171 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5172 error "set user quota failed"
5174 pool_add $qpool2 || error "pool_add failed"
5175 pool_add_targets $qpool2 1 1 ||
5176 error "pool_add_targets failed"
5178 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
5179 error "set user quota failed"
5181 # make sure the system is clean
5182 local used=$(getquota -u $TSTUSR global curspace)
5185 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5187 # create 1st component 1-10M
5188 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5189 #create 2nd component 10-30M
5190 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5191 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5193 # сheck normal use and out of quota with PFL
5194 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
5195 test_1_check_write $testfile "user" $((limit*2))
5197 wait_delete_completed || error "wait_delete_completed failed"
5198 sync_all_data || true
5199 used=$(getquota -u $TSTUSR global curspace)
5200 [ $used -ne 0 ] && quota_error u $TSTUSR \
5201 "user quota isn't released after deletion"
5203 # create 1st component 1-10M
5204 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5205 # create 2nd component 10-30M
5206 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5207 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5209 # write to the 2nd component
5210 $RUNAS $DD of=$testfile count=$limit seek=10 ||
5211 quota_error u $TSTUSR \
5212 "write failure, but expect success"
5213 # this time maybe cache write, ignore it's failure
5214 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
5215 cancel_lru_locks osc
5216 sync; sync_all_data || true
5217 # write over limit in qpool2(2nd component 10-30M)
5218 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
5219 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5220 # write to the 1st component - OST0 is empty
5221 $RUNAS $DD of=$testfile count=$limit seek=0 ||
5222 quota_error u $TSTUSR "write failed"
5224 run_test 71a "Check PFL with quota pools"
5228 local global_limit=1000 # MB
5229 local limit1=160 # MB
5230 local limit2=10 # MB
5231 local testfile="$DIR/$tdir/$tfile-0"
5232 local qpool="qpool1"
5233 local qpool2="qpool2"
5235 [ "$ost1_FSTYPE" == zfs ] &&
5236 skip "ZFS grants some block space together with inode"
5237 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
5239 setup_quota_test || error "setup quota failed with $?"
5242 set_ost_qtype $QTYPE || error "enable ost quota failed"
5245 log "User quota (block hardlimit:$global_limit MB)"
5246 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5247 error "set user quota failed"
5249 pool_add $qpool || error "pool_add failed"
5250 pool_add_targets $qpool 0 1 ||
5251 error "pool_add_targets failed"
5253 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
5254 error "set user quota failed"
5256 pool_add $qpool2 || error "pool_add failed"
5257 pool_add_targets $qpool2 1 1 ||
5258 error "pool_add_targets failed"
5260 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5261 error "set user quota failed"
5263 # make sure the system is clean
5264 local used=$(getquota -u $TSTUSR global curspace)
5267 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5269 # First component is on OST0, 2nd on OST1
5270 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
5271 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5273 # fill the 1st component on OST0
5274 $RUNAS $DD of=$testfile count=128 ||
5275 quota_error u $TSTUSR "write failed"
5276 # write to the 2nd cmpnt on OST1
5277 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
5278 quota_error u $TSTUSR "write failed"
5279 # this time maybe cache write, ignore it's failure
5280 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
5282 cancel_lru_locks osc
5283 sync; sync_all_data || true
5284 # write over limit in qpool2
5285 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
5286 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5289 run_test 71b "Check SEL with quota pools"
5294 local global_limit=50 # MB
5295 local testfile="$DIR/$tdir/$tfile-0"
5296 local qpool="qpool1"
5299 setup_quota_test || error "setup quota failed with $?"
5302 set_ost_qtype $QTYPE || error "enable ost quota failed"
5305 log "User quota (block hardlimit:$global_limit MB)"
5306 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5307 error "set user quota failed"
5309 pool_add $qpool || error "pool_add failed"
5310 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5312 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5313 error "set user quota failed"
5315 # make sure the system is clean
5316 local used=$(getquota -u $TSTUSR global curspace)
5318 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5320 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5322 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5323 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5324 test_1_check_write $testfile "user" $limit
5325 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5327 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5328 # check that lfs quota -uv --pool prints only OST that
5329 # was added in a pool
5330 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5331 grep "OST\|MDT" && error "$qpool consists wrong targets"
5334 run_test 72 "lfs quota --pool prints only pool's OSTs"
5338 (( $MDS1_VERSION >= $(version_code 2.14.51.158) )) ||
5339 skip "need MDS >= v2_14_51-158-g25a70a88 for default pool quota"
5341 local qpool="qpool1"
5345 pool_add $qpool || error "pool_add failed"
5346 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5347 error "pool_add_targets failed"
5349 test_default_quota "-u" "data" "qpool1"
5351 run_test 73a "default limits at OST Pool Quotas"
5355 (( $MDS1_VERSION >= $(version_code 2.14.52.91) )) ||
5356 skip "need MDS >= v2_14_52-91-g188112fc8 for nested lqe fix"
5358 local TESTFILE1="$DIR/$tdir/$tfile-1"
5360 local qpool="qpool1"
5364 setup_quota_test || error "setup quota failed with $?"
5366 set_ost_qtype $QTYPE || error "enable ost quota failed"
5368 # pool quotas don't work properly without global limit
5369 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5370 error "set global limit failed"
5372 pool_add $qpool || error "pool_add failed"
5373 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5374 error "pool_add_targets failed"
5376 log "set default quota for $qpool"
5377 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5378 error "set default quota failed"
5380 log "Write from user that hasn't lqe"
5381 # Check that it doesn't cause a panic or a deadlock
5382 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5383 # Have to use RUNAS_ID as resetquota creates lqes in
5384 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5385 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5387 cancel_lru_locks osc
5388 sync; sync_all_data || true
5390 run_test 73b "default OST Pool Quotas limit for new user"
5394 (( $MDS1_VERSION >= $(version_code 2.14.52.6) )) ||
5395 skip "need MDS >= v2_14_52-6-g8c19365416 for pool per-user fix"
5397 local global_limit=200 # 200M
5398 local limit=10 # 10M
5399 local limit2=50 # 50M
5400 local qpool="qpool1"
5401 local qpool2="qpool2"
5405 setup_quota_test || error "setup quota failed with $?"
5408 set_ost_qtype $QTYPE || error "enable ost quota failed"
5410 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5411 error "set user quota failed"
5413 pool_add $qpool || error "pool_add failed"
5414 pool_add_targets $qpool 0 1 ||
5415 error "pool_add_targets failed"
5417 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5418 error "set user quota failed"
5420 pool_add $qpool2 || error "pool_add failed"
5421 pool_add_targets $qpool2 1 1 ||
5422 error "pool_add_targets failed"
5424 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5425 error "set user quota failed"
5427 tmp=$(getquota -u $TSTUSR global bhardlimit)
5428 [ $tmp -eq $((global_limit * 1024)) ] ||
5429 error "wrong global limit $global_limit"
5431 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5432 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5434 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5435 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5437 # check limits in pools
5438 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5439 grep -A4 $qpool | awk 'NR == 4{print $4}')
5440 echo "pool limit for $qpool $tmp"
5441 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5442 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5443 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5444 echo "pool limit for $qpool2 $tmp"
5445 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5447 run_test 74 "check quota pools per user"
5449 function cleanup_quota_test_75()
5451 do_facet mgs $LCTL nodemap_modify --name default \
5452 --property admin --value 1
5453 do_facet mgs $LCTL nodemap_modify --name default \
5454 --property trusted --value 1
5455 do_facet mgs $LCTL nodemap_modify --name default \
5456 --property squash_uid --value 99
5457 do_facet mgs $LCTL nodemap_modify --name default \
5458 --property squash_gid --value 99
5460 wait_nm_sync default admin_nodemap
5461 wait_nm_sync default trusted_nodemap
5463 do_facet mgs $LCTL nodemap_activate 0
5466 resetquota -u $TSTUSR
5470 local dd_failed=false
5471 local LIMIT=20480 #20M
5474 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5475 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5476 conv=fsync || dd_failed=true
5479 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5481 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5482 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5483 conv=fsync || dd_failed=true
5486 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5488 rm -f $DIR/$tdir_dom/*
5490 # flush cache, ensure noquota flag is set on client
5492 sync; sync_all_data || true
5496 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) conv=fsync ||
5497 quota_error u $qid "write failed, expect succeed (2)"
5499 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5500 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5501 conv=fsync || dd_failed=true
5504 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5507 rm -f $DIR/$tdir_dom/*
5509 # flush cache, ensure noquota flag is set on client
5511 sync; sync_all_data || true
5515 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5516 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5517 conv=fsync || dd_failed=true
5520 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5522 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=direct &&
5523 quota_error u $qid "write succeed, expect EDQUOT (3)"
5529 (( $MDS1_VERSION >= $(version_code 2.14.52.68) )) ||
5530 skip "need MDS >= v2_14_52-68-ga4fbe7341b for squash root fix"
5532 local soft_limit=10 # MB
5533 local hard_limit=20 # MB
5534 local limit=$soft_limit
5535 local testfile="$DIR/$tdir/$tfile-0"
5536 local grace=20 # seconds
5537 local tdir_dom=${tdir}_dom
5539 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5543 setup_quota_test || error "setup quota failed with $?"
5544 stack_trap cleanup_quota_test_75 EXIT
5547 set_ost_qtype $QTYPE || error "enable ost quota failed"
5548 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5550 local used=$(getquota -u $TSTID global curspace)
5551 $LFS setquota -t -u --block-grace $grace --inode-grace \
5552 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5553 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5554 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5555 error "set user quota failed"
5557 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5558 mkdir $DIR/$tdir_dom
5559 chmod 777 $DIR/$tdir_dom
5560 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5561 error "setstripe $tdir_dom failed"
5563 do_facet mgs $LCTL nodemap_activate 1
5565 do_facet mgs $LCTL nodemap_modify --name default \
5566 --property admin --value 0
5567 do_facet mgs $LCTL nodemap_modify --name default \
5568 --property trusted --value 0
5569 do_facet mgs $LCTL nodemap_modify --name default \
5570 --property deny_unknown --value 0
5571 do_facet mgs $LCTL nodemap_modify --name default \
5572 --property squash_uid --value $TSTID
5573 do_facet mgs $LCTL nodemap_modify --name default \
5574 --property squash_gid --value $TSTID
5575 cancel_lru_locks mdc
5576 wait_nm_sync default admin_nodemap
5577 wait_nm_sync default trusted_nodemap
5578 wait_nm_sync default squash_uid
5580 # mmap write when over soft limit
5582 $DD of=$testfile count=${limit} || quota_error a $TSTUSR \
5583 "root write failure, but expect success (1)"
5584 OFFSET=$((limit * 1024))
5585 cancel_lru_locks osc
5587 echo "Write to exceed soft limit"
5588 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5589 quota_error a $TSTUSR "root write failure, but expect success (2)"
5590 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5591 cancel_lru_locks osc
5593 echo "mmap write when over soft limit"
5594 $MULTIOP $testfile.mmap OT40960SMW ||
5595 quota_error a $TSTUSR "mmap write failure, but expect success"
5596 cancel_lru_locks osc
5598 wait_delete_completed || error "wait_delete_completed failed (1)"
5599 sync_all_data || true
5601 # test for user hard limit
5604 $DD of=$testfile count=$((limit/2)) ||
5605 quota_error u $TSTID \
5606 "root write failure, but expect success (3)"
5608 log "Write out of block quota ..."
5609 # possibly a cache write, ignore failure
5610 $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
5611 # flush cache, ensure noquota flag is set on client
5612 cancel_lru_locks osc
5613 sync; sync_all_data || true
5614 # sync forced cache flush, but did not guarantee that slave
5615 # got new edquot through glimpse, so wait to make sure
5617 $DD of=$testfile count=1 seek=$limit conv=fsync &&
5618 quota_error u $TSTID \
5619 "user write success, but expect EDQUOT"
5621 wait_delete_completed || error "wait_delete_completed failed (2)"
5622 sync_all_data || true
5623 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5624 quota_error u $TSTID "user quota not released after deletion"
5628 run_test 75 "nodemap squashed root respects quota enforcement"
5631 (( $MDS1_VERSION >= $(version_code 2.14.52.109) )) ||
5632 skip "need MDS >= v2_14_52-109-g3ffa5d680f for bad PRJID fix"
5633 ! is_project_quota_supported &&
5634 skip "skip project quota unsupported"
5636 setup_quota_test || error "setup quota failed with $?"
5639 local testfile="$DIR/$tdir/$tfile-0"
5642 $LFS project -p 4294967295 $testfile &&
5643 error "set project ID should fail"
5646 run_test 76 "project ID 4294967295 should be not allowed"
5650 (( $MDS1_VERSION >= $(version_code 2.14.54.33) )) ||
5651 skip "need MDS >= v2_14_54-33-g29e00cecc6 for readonly fix"
5653 mount_client $MOUNT2 "ro"
5654 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5655 error "lfs setquota should fail in read-only Lustre mount"
5658 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5662 (( $OST1_VERSION >= $(version_code 2.14.55.173) )) ||
5663 skip "need OST >= v2_14_55-173-g789038c97a for fallocate fix"
5664 check_set_fallocate_or_skip
5666 setup_quota_test || error "setup quota failed with $?"
5669 set_ost_qtype $QTYPE || error "enable ost quota failed"
5671 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5672 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5675 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5676 error "lfs setquota failed"
5679 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5681 kbytes=$(lfs quota -u $TSTUSR $DIR |
5682 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5683 echo "kbytes returned:$kbytes"
5685 # For file size of 204800. We should be having roughly 200 kbytes
5686 # returned. Anything alarmingly low (50 taken as arbitrary value)
5687 # would bail out this TC. Also this also avoids $kbytes of 0
5688 # to be used in calculation below.
5689 (( $kbytes > 50 )) ||
5690 error "fallocate did not use quota. kbytes returned:$kbytes"
5692 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5693 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5695 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5696 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5697 error "fallocate did not use quota correctly"
5699 run_test 78A "Check fallocate increase quota usage"
5703 (( $CLIENT_VERSION >= $(version_code 2.15.0.37) )) ||
5704 skip "need client >= v2_15_50-37-g5fc934eb for falloc proj fix"
5705 (( $OST1_VERSION >= $(version_code 2.15.0.37) )) ||
5706 skip "need OST >= v2_15_50-37-g5fc934ebbb for falloc proj fix"
5707 check_set_fallocate_or_skip
5709 setup_quota_test || error "setup quota failed with $?"
5712 set_ost_qtype $QTYPE || error "enable ost quota failed"
5714 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5716 local projectid=5200 # Random project id to test
5718 change_project -sp $projectid $DIR/$tdir
5721 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5722 error "lfs setquota project failed"
5725 fallocate -l 204800 $DIR/$tdir/$tfile
5727 # Get curspace (kbytes) for $projectid
5728 local kbytes=$(getquota -p $projectid global curspace)
5730 echo "kbytes returned:$kbytes"
5732 # For file size of 204800. We should be having roughly 200 kbytes
5733 # returned. Anything alarmingly low (50 taken as arbitrary value)
5734 # would bail out this TC. Also this also avoids $kbytes of 0
5735 # to be used in calculation below.
5736 (( $kbytes > 50 )) ||
5737 error "fallocate did not use projectid. kbytes returned:$kbytes"
5739 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5740 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5742 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5743 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5744 error "fallocate did not use quota projectid correctly"
5746 run_test 78a "Check fallocate increase projectid usage"
5750 (( $MDS1_VERSION >= $(version_code 2.14.56.37) )) ||
5751 skip "need MDS >= v2_14_56-37-gc9901b68b4 for pool panic fix"
5753 local qpool="qpool1"
5754 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5755 local stopf=$TMP/$tfile
5757 do_facet mds1 "touch $stopf"
5758 stack_trap "do_facet mds1 'rm -f $stopf'"
5759 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5761 pool_add $qpool || error "pool_add failed"
5762 do_facet mds1 "rm $stopf"
5765 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5769 (( $MDS1_VERSION >= $(version_code 2.14.56.51) )) ||
5770 skip "need MDS >= v2_14_56-51-g61ec1e0f2c for EDQUOT failover"
5772 local dir1="$DIR/$tdir/dir1"
5773 local dir2="$DIR/$tdir/dir2"
5774 local TESTFILE0="$dir1/$tfile-0"
5775 local TESTFILE1="$dir1/$tfile-1"
5776 local TESTFILE2="$dir1/$tfile-2"
5777 local TESTFILE3="$dir2/$tfile-0"
5778 local global_limit=100 # 100M
5779 local limit=10 # 10M
5780 local qpool="qpool1"
5782 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5784 [ "$ost1_FSTYPE" == zfs ] &&
5785 skip "ZFS grants some block space together with inode"
5786 setup_quota_test || error "setup quota failed with $?"
5787 set_ost_qtype $QTYPE || error "enable ost quota failed"
5789 # make sure the system is clean
5790 local used=$(getquota -u $TSTUSR global curspace)
5791 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5793 pool_add $qpool || error "pool_add failed"
5794 pool_add_targets $qpool 0 1 ||
5795 error "pool_add_targets failed"
5797 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5798 error "set user quota failed"
5800 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5801 error "set user quota failed"
5802 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5803 error "set user quota failed"
5805 mkdir -p $dir1 || error "failed to mkdir"
5806 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5807 mkdir -p $dir2 || error "failed to mkdir"
5808 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5810 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5811 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5816 $LFS quota -uv $TSTUSR $DIR
5817 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5818 do_facet mds1 $LCTL set_param fail_loc=0xa06
5819 $RUNAS $DD of=$TESTFILE3 count=3 ||
5820 quota_error u $TSTUSR "write failed"
5821 $RUNAS $DD of=$TESTFILE2 count=7 ||
5822 quota_error u $TSTUSR "write failed"
5823 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5824 quota_error u $TSTUSR "write failed"
5827 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5831 do_facet mds1 $LCTL set_param fail_loc=0
5832 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5833 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5834 # OST0 needs some time to update quota usage after removing TESTFILE2
5836 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5837 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5838 quota_error u $TSTUSR "write failure, but expect success"
5840 run_test 80 "check for EDQUOT after OST failover"
5844 (( $MDS1_VERSION >= $(version_code 2.14.56.52) )) ||
5845 skip "need MDS >= v2_14_56-52-g862f0baa7c for qmt_pool_free fix"
5847 local global_limit=20 # 100M
5848 local testfile="$DIR/$tdir/$tfile-0"
5849 local qpool="qpool1"
5852 setup_quota_test || error "setup quota failed with $?"
5855 set_ost_qtype $QTYPE || error "enable ost quota failed"
5858 log "User quota (block hardlimit:$global_limit MB)"
5859 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5861 pool_add $qpool || error "pool_add failed"
5862 #define OBD_FAIL_QUOTA_RECALC 0xA07
5863 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=10
5864 # added OST casues to start pool recalculation
5865 pool_add_targets $qpool 0 0 1
5866 stop mds1 -f || error "MDS umount failed"
5868 #start mds1 back to destroy created pool
5869 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5872 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5876 (( $MDS1_VERSION >= $(version_code 2.15.50.72) )) ||
5877 skip "need MDS >= v2_15_50-72-g61481796ac for over 8 QIDs fix"
5879 is_project_quota_supported || skip "skip project quota unsupported"
5881 setup_quota_test || error "setup quota failed with $?"
5884 local parent_dir="$DIR/$tdir.parent"
5885 local child_dir="$parent_dir/child"
5888 stack_trap "chown -R 0:0 $parent_dir"
5890 chown $TSTUSR:$TSTUSR $parent_dir ||
5891 error "failed to chown on $parent_dir"
5892 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5893 error "failed to chown on $parent_dir"
5895 $LFS project -p 1000 $parent_dir ||
5896 error "failed to set project id on $parent_dir"
5897 $LFS project -p 1001 $child_dir ||
5898 error "failed to set project id on $child_dir"
5900 rmdir $child_dir || error "cannot remove child dir, test failed"
5902 run_test 82 "verify more than 8 qids for single operation"
5904 test_grace_with_default_quota()
5913 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
5914 error "clear default quota [$qdtype] failed"
5916 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
5917 error "reset quota [$qdtype] grace failed"
5920 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5921 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
5924 $LFS setquota $qdtype -B 10G -i 10k $DIR
5927 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5928 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
5930 [ "$bgrace" == "$bgrace2" ] ||
5931 error "set default quota shouldn't affect block grace"
5932 [ "$igrace" == "$igrace2" ] ||
5933 error "set default quota shouldn't affect inode grace"
5939 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
5940 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
5942 setup_quota_test || error "setup quota failed with $?"
5943 test_grace_with_default_quota "-u" "-U"
5944 test_grace_with_default_quota "-g" "-G"
5946 is_project_quota_supported || return 0
5947 test_grace_with_default_quota "-p" "-P"
5949 run_test 83 "Setting default quota shouldn't affect grace time"
5953 (( $MDS1_VERSION >= $(version_code 2.15.53.115) )) ||
5954 skip "need MDS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
5955 (( $OST1_VERSION >= $(version_code 2.15.53.115) )) ||
5956 skip "need OSS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
5958 local dir1="$DIR/$tdir/dir1"
5959 local TESTFILE1="$dir1/$tfile-1"
5967 setup_quota_test || error "setup quota failed with $?"
5969 set_ost_qtype $QTYPE || error "enable ost quota failed"
5971 pool_add $qp || error "pool_add failed"
5972 pool_add_targets $qp 0 $(($OSTCOUNT - 1)) ||
5973 error "pool_add_targets failed"
5975 $LFS setquota -g $TSTUSR -B 10G $DIR ||
5976 error "failed to set group quota for $TSTUSR"
5977 $LFS setquota -g $TSTUSR -B 5G --pool $qp $DIR ||
5978 error "set user quota failed"
5979 $LFS quota -gv $TSTUSR $DIR
5981 wait_quota_synced "ost1" "OST0000" "grp" $TSTID "hardlimit" "10485760"
5983 mkdir -p $dir1 || error "failed to mkdir"
5984 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5986 $LFS setstripe -c 1 -i 0 $TESTFILE1
5987 $LFS getstripe $TESTFILE1
5988 chown $TSTUSR.$TSTUSR $TESTFILE1
5990 $RUNAS $DD of=$TESTFILE1 count=60 conv=nocreat oflag=direct ||
5991 quota_error g $TSTUSR "write failed"
5993 sync_all_data || true
5995 $LFS quota -gv $TSTUSR $DIR
5996 $LFS quota -gv --pool $qp $TSTUSR $DIR
5998 # the grant quota should be larger than 0
6000 while (( $waited < 60 )); do
6001 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6002 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6003 (( ${grant} > 0 && ${grant2} > 0 )) && break
6005 do_facet ost1 $LCTL set_param \
6006 osd-*.*-OST0000.quota_slave.force_reint=1
6008 waited=$((waited + 1))
6011 (( $waited >= 60)) && {
6012 $LFS quota -gv $TSTUSR $DIR
6013 $LFS quota -gv --pool $qp $TSTUSR $DIR
6016 (( ${grant} > 0 )) || error "pool grant is not increased after dd"
6017 (( ${grant2} > 0 )) || error "grant is not increased after dd"
6019 #define OBD_FAIL_QUOTA_GRANT 0xA08
6020 lustre_fail mds 0xa08
6021 lustre_fail ost 0xa08
6024 # clear quota limits to trigger updating grant quota
6025 $LFS setquota -g $TSTUSR -b 0 -B 0 $DIR ||
6026 error "failed to clear the group quota for $TSTUSR"
6027 $LFS quota -gv $TSTUSR $DIR
6028 $LFS quota -gv --pool $qp $TSTUSR $DIR
6030 # the grant quota should be set as insane value
6032 while (( $waited < 60 )); do
6033 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6034 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6035 (( ${#grant} == 20 && ${#grant2} == 20 )) && break
6038 waited=$((waited + 1))
6041 (( $waited >= 60)) && {
6042 $LFS quota -gv $TSTUSR $DIR
6043 $LFS quota -gv --pool $qp $TSTUSR $DIR
6046 (( ${#grant} == 20 )) || error "pool grant is not set as insane value"
6047 (( ${#grant2} == 20 )) || error "grant is not set as insane value"
6049 lustre_fail mds_ost 0
6053 $LFS setquota -g $TSTUSR -r $DIR ||
6054 error "failed to reset group quota for $TSTUSR"
6057 $LFS quota -gv $TSTUSR $DIR
6058 $LFS quota -gv --pool $qp $TSTUSR $DIR
6060 # the grant quota should be reset
6061 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6062 (( ${#grant} == 20 )) && error "grant is not cleared"
6063 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6064 (( ${#grant} == 20 )) && error "pool grant is not cleared"
6066 $LFS quota -gv $TSTUSR --pool $qp $DIR
6067 $LFS quota -gv --pool $qp $TSTUSR $DIR
6068 local hlimit=$(getquota -g $TSTUSR global bhardlimit $qp)
6069 [ $hlimit -eq 5242880 ] || error "pool limit is changed"
6071 # test whether the quota still works
6072 $LFS setquota -g $TSTUSR -B 100M $DIR ||
6073 error "failed to set group quota for $TSTUSR"
6074 $LFS quota -gv $TSTUSR $DIR
6076 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct &&
6077 quota_error g $TSTUSR "dd succeed, expect EDQUOT"
6079 $LFS setquota -g $TSTUSR -B 300M $DIR ||
6080 error "failed to set group quota for $TSTUSR"
6081 $LFS quota -gv $TSTUSR $DIR
6083 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct ||
6084 quota_error g $TSTUSR "dd failed, expect succeed"
6086 run_test 84 "Reset quota should fix the insane granted quota"
6090 (( $MDS1_VERSION >= $(version_code 2.15.55.5) )) ||
6091 skip "need MDS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6092 (( $OST1_VERSION >= $(version_code 2.15.55.5) )) ||
6093 skip "need OSS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6096 local qpool="qpool1"
6097 local qpool2="qpool2"
6098 local tfile1="$DIR/$tdir/$tfile-0"
6100 (( OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
6102 setup_quota_test || error "setup quota failed with $?"
6105 set_ost_qtype $QTYPE || error "enable ost quota failed"
6107 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
6108 error "set user quota failed"
6110 pool_add $qpool || error "pool_add failed"
6111 pool_add_targets $qpool 0 1 ||
6112 error "pool_add_targets failed"
6114 pool_add $qpool2 || error "pool_add failed"
6115 pool_add_targets $qpool2 0 1 ||
6116 error "pool_add_targets failed"
6118 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
6119 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
6120 error "set user quota failed"
6121 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
6122 error "set user quota failed"
6124 # don't care about returned value. Just check we don't hung on write.
6125 $RUNAS $DD of=$tfile1 count=10
6128 run_test 85 "do not hung at write with the least_qunit"
6130 test_preacquired_quota()
6137 [[ "$qtype" == "-p" ]] && change_project -sp $qid $DIR/$tdir
6139 $LFS setquota $qtype $qid -i 100K -I 100K $DIR ||
6140 error "failed to set file [$qtype] quota"
6142 $RUNAS createmany -m $test_dir/tfile- 5000 ||
6143 error "failed to create files, expect succeed"
6145 wait_zfs_commit $SINGLEMDS
6146 $LFS setquota $qtype $qid -i 2K -I 2K $DIR ||
6147 error "failed to decrease file [$qtype] quota"
6149 wait_quota_synced "mds1" "MDT0000" $qtype_name $qid "hardlimit" "2048"
6151 # make sure the lqe->lqe_edquot is set
6152 $RUNAS createmany -m $test_dir/tfile2- 10
6155 $RUNAS createmany -m $test_dir/tfile3- 30 &&
6156 error "succeed to create files, expect failed"
6158 rm -f $test_dir/tfile*
6159 $LFS setquota $qtype $qid -i 0 -I 0 $DIR ||
6160 error "failed to reset file user quota"
6165 (( $MDS1_VERSION >= $(version_code 2.15.57.41) )) ||
6166 skip "need MDS >= 2.15.57.41 for quota over limit release fix"
6168 local test_dir="$DIR/$tdir/test_dir"
6170 setup_quota_test || error "setup quota failed with %?"
6171 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
6173 $LFS setdirstripe -c 1 -i 0 $test_dir || error "setdirstripe failed"
6176 test_preacquired_quota "$test_dir" "-u" "usr" "$TSTID"
6177 test_preacquired_quota "$test_dir" "-g" "grp" "$TSTID"
6179 is_project_quota_supported || return 0
6180 test_preacquired_quota "$test_dir" "-p" "prj" "1000"
6182 run_test 86 "Pre-acquired quota should be released if quota is over limit"
6186 do_nodes $(comma_list $(nodes_list)) \
6187 "lctl set_param -n debug=-quota-trace"
6188 if $PQ_CLEANUP; then
6189 disable_project_quota
6192 reset_quota_settings
6196 complete_test $SECONDS
6197 check_and_cleanup_lustre
6198 export QUOTA_AUTO=$QUOTA_AUTO_OLD