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 test_mkdir -p $dir && change_project -sp $projid $dir
3879 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3880 error "set project quota failed"
3885 # check if df output works as expected
3886 echo "== global statfs: $MOUNT =="
3887 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3889 echo "== project statfs (prjid=$projid): $dir =="
3890 df -kP $dir; df -iP $dir
3891 local bused=$(getquota -p $projid global curspace)
3892 local iused=$(getquota -p $projid global curinodes)
3893 local expected="$ilimit$iused"
3895 wait_update $HOSTNAME \
3896 "df -iP $dir | awk \\\"/$FSNAME/\\\"'{print \\\$2 \\\$3}'" \
3898 error "failed to get correct statfs for project quota"
3900 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $2}')
3901 (( expected == blimit )) ||
3902 error "blimit mismatch: $expected != $blimit"
3904 # zfs block size is 4K, while quota is printed in 1K, df result may be
3905 # larger than quota result, but it's no more than 3K
3906 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $3}')
3907 (( expected - bused < 4)) || error "bused mismatch: $expected != $bused"
3909 run_test 41 "df should return projid-specific values"
3917 local osd="osd-ldiskfs"
3919 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3921 rm -f $DIR/$tdir/$tfile
3922 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3923 chmod a+rw $DIR/$tdir/$tfile
3925 $LFS setquota $qtype $qid -B 300M $MOUNT
3926 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3928 do_facet $SINGLEMDS \
3929 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3930 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3933 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3934 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3936 $LFS setquota $qtype $qid --delete $MOUNT
3937 do_facet $SINGLEMDS \
3938 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3939 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3942 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3943 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3945 $LFS setquota $qtype $qid -B 500M $MOUNT
3946 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3947 do_facet $SINGLEMDS \
3948 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3949 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3950 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3952 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3953 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3958 setup_quota_test || error "setup quota failed with $?"
3959 set_ost_qtype $QTYPE || error "enable ost quota failed"
3962 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3963 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3964 is_project_quota_supported &&
3965 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3969 run_test 48 "lfs quota --delete should delete quota project ID"
3972 ! is_project_quota_supported &&
3973 skip "Project quota is not supported"
3975 setup_quota_test || error "setup quota failed with $?"
3976 local dir1="$DIR/$tdir/dir1"
3977 local dir2="$DIR/$tdir/dir2"
3979 mkdir -p $dir1 && change_project -sp 1 $dir1
3980 mkdir -p $dir2 && change_project -sp 2 $dir2
3981 for num in $(seq 1 10); do
3982 touch $dir1/file_$num $dir2/file_$num
3983 ln -s $dir1/file_$num $dir1/file_$num"_link"
3984 ln -s $dir2/file_$num $dir2/file_$num"_link"
3987 count=$($LFS find --projid 1 $DIR | wc -l)
3988 [ "$count" != 21 ] && error "expected 21 but got $count"
3990 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3991 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3992 [ $count -eq 22 ] || error "expected 22 but got $count"
3994 run_test 50 "Test if lfs find --projid works"
3997 ! is_project_quota_supported &&
3998 skip "Project quota is not supported"
3999 setup_quota_test || error "setup quota failed with $?"
4000 local dir="$DIR/$tdir/dir"
4002 mkdir $dir && change_project -sp 1 $dir
4003 local used=$(getquota -p 1 global curinodes)
4004 [ $used != "1" ] && error "expected 1 got $used"
4009 used=$(getquota -p 1 global curinodes)
4010 [ $used != "4" ] && error "expected 4 got $used"
4012 $DD of=$DIR/$tdir/6 count=1
4014 cp $DIR/$tdir/6 $dir/6
4015 used=$(getquota -p 1 global curinodes)
4016 [ $used != "5" ] && error "expected 5 got $used"
4019 mv $DIR/$tdir/6 $dir/7
4020 used=$(getquota -p 1 global curinodes)
4021 [ $used -eq 6 ] || error "expected 6 got $used"
4023 run_test 51 "Test project accounting with mv/cp"
4026 ! is_project_quota_supported &&
4027 skip "Project quota is not supported"
4029 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
4030 skip "Need MDS version at least 2.14.55"
4032 setup_quota_test || error "setup quota failed with $?"
4034 local dir1=$DIR/$tdir/t52_dir1
4035 local dir2=$DIR/$tdir/t52_dir2
4037 mkdir $dir1 || error "failed to mkdir $dir1"
4038 mkdir $dir2 || error "failed to mkdir $dir2"
4040 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
4041 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
4043 $DD of=$dir1/$tfile count=100 ||
4044 error "failed to create and write $dir1/$tfile"
4046 cancel_lru_locks osc
4047 sync; sync_all_data || true
4049 local attrs=($(lsattr -p $dir1/$tfile))
4050 (( ${attrs[0]} == 1000 )) ||
4051 error "project ID on $dir1/$tfile is not inherited"
4053 $LFS quota -p 1000 $DIR
4054 $LFS quota -p 1001 $DIR
4056 local prev_used=$(getquota -p 1000 global curspace)
4057 local prev_used2=$(getquota -p 1001 global curspace)
4059 mrename $dir1 $dir2/tdir || log "rename directory return $?"
4061 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
4062 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
4063 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
4065 attrs=($(lsattr -p $dir2/$tfile))
4066 (( ${attrs[0]} == 1001 )) ||
4067 error "project ID is not updated after rename"
4069 (( $inum_before == $inum_after )) ||
4070 error "inode is changed after rename: $inum_before, $inum_after"
4072 sync_all_data || true
4074 $LFS quota -p 1000 $DIR
4075 $LFS quota -p 1001 $DIR
4077 local new_used=$(getquota -p 1000 global curspace)
4078 local new_used2=$(getquota -p 1001 global curspace)
4080 (( $prev_used >= $new_used + 102400 )) ||
4081 error "quota is not deducted from old project ID"
4082 (( $prev_used2 <= $new_used2 - 102400 )) ||
4083 error "quota is not added for the new project ID"
4085 run_test 52 "Rename normal file across project ID"
4088 ! is_project_quota_supported &&
4089 skip "Project quota is not supported"
4090 setup_quota_test || error "setup quota failed with $?"
4091 local dir="$DIR/$tdir/dir"
4092 mkdir $dir && change_project -s $dir
4093 [[ $($LFS project -d $dir) =~ " P " ]] ||
4094 error "inherit attribute should be set"
4096 change_project -C $dir
4097 [[ $($LFS project -d $dir) =~ " - " ]] ||
4098 error "inherit attribute should be cleared"
4100 run_test 53 "Project inherit attribute could be cleared"
4103 ! is_project_quota_supported &&
4104 skip "Project quota is not supported"
4105 setup_quota_test || error "setup quota failed with $?"
4106 local testfile="$DIR/$tdir/$tfile-0"
4108 #set project ID/inherit attribute
4109 change_project -sp $TSTPRJID $DIR/$tdir
4110 $RUNAS createmany -m ${testfile} 100 ||
4111 error "create many files failed"
4113 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
4114 # one more count for directory itself */
4118 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4119 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
4121 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
4122 [ $proj_count1 -eq $proj_count ] ||
4123 error "c2: expected $proj_count got $proj_count1"
4125 #clear project but with kept projid
4126 change_project -rCk $DIR/$tdir
4127 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4128 [ $proj_count1 -eq 1 ] ||
4129 error "c3: expected 1 got $proj_count1"
4131 #verify projid untouched.
4132 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4134 [ $proj_count1 -eq $proj_count ] ||
4135 error "c4: expected $proj_count got $proj_count1"
4138 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
4139 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4140 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
4142 #this time clear all
4143 change_project -rC $DIR/$tdir
4144 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4145 [ $proj_count1 -eq 0 ] ||
4146 error "c6: expected 0 got $proj_count1"
4148 unlinkmany ${testfile} 100 ||
4149 error "unlink many files failed"
4151 run_test 54 "basic lfs project interface test"
4154 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
4155 skip "Not supported before 2.10.58."
4156 setup_quota_test || error "setup quota failed with $?"
4158 set_ost_qtype $QTYPE || error "enable ost quota failed"
4161 #add second group to TSTUSR
4162 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
4165 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
4166 error "failed to dd"
4168 cancel_lru_locks osc
4169 sync; sync_all_data || true
4171 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
4172 error "failed to setquota on group $TSTUSR2"
4174 $LFS quota -v -g $TSTUSR2 $DIR
4176 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
4177 error "chgrp should failed with -EDQUOT"
4179 USED=$(getquota -g $TSTUSR2 global curspace)
4182 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
4183 error "failed to setquota on group $TSTUSR2"
4185 $LFS quota -v -g $TSTUSR2 $DIR
4187 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
4188 error "chgrp should succeed"
4190 $LFS quota -v -g $TSTUSR2 $DIR
4192 run_test 55 "Chgrp should be affected by group quota"
4195 setup_quota_test || error "setup quota failed with $?"
4197 set_ost_qtype $QTYPE || error "enable ost quota failed"
4200 $LFS setquota -t -u -b 10 -i 10 $DIR ||
4201 erro "failed to set grace time for usr quota"
4202 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4203 awk '{print $4 $8}')
4204 if [ "x$grace_time" != "x10s;10s" ]; then
4205 $LFS quota -t -u $DIR
4206 error "expected grace time: 10s;10s, got:$grace_time"
4209 run_test 56 "lfs quota -t should work well"
4212 setup_quota_test || error "setup quota failed with $?"
4214 local dir="$DIR/$tdir/dir"
4217 #command can process further if it hit some errors
4218 $LFS project -sp 1 $dir/pipe
4219 touch $dir/aaa $dir/bbb
4220 mkdir $dir/subdir -p
4221 touch $dir/subdir/aaa $dir/subdir/bbb
4222 #create one invalid link file
4223 ln -s $dir/not_exist_file $dir/ccc
4224 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4225 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4227 run_test 57 "lfs project could tolerate errors"
4237 $LFS mirror extend -N2 $mirrorfile || error "failed to create mirror"
4239 local mirrors=$($LFS getstripe -N $testfile)
4240 [[ $mirrors == 3 ]] || error "mirror count $mirrors is wrong"
4242 cancel_lru_locks osc
4243 cancel_lru_locks mdc
4244 sync; sync_all_data || true
4246 local prev_usage=$(getquota -p $projid global curspace)
4248 $RUNAS $DD of=$testfile count=50 conv=nocreat oflag=direct ||
4249 quota_error p $projid "write failed, expect succeed"
4251 cancel_lru_locks osc
4252 cancel_lru_locks mdc
4253 sync; sync_all_data || true
4255 $RUNAS $LFS mirror resync $testfile || error "failed to resync mirror"
4257 local usage=$(getquota -p $projid global curspace)
4258 (( usage >= prev_usage + 150*1024 )) ||
4259 error "project quota $usage is wrong"
4261 $RUNAS $DD of=$testfile count=30 conv=nocreat seek=50 oflag=direct ||
4262 quota_error p $projid "write failed, expect succeed"
4264 $RUNAS $LFS mirror resync $testfile &&
4265 error "resync mirror succeed, expect EDQUOT"
4267 $LFS mirror delete --mirror-id 2 $testfile ||
4268 error "failed to delete the second mirror"
4269 $LFS mirror delete --mirror-id 3 $testfile ||
4270 error "failed to delete the third mirror"
4274 (( $MDS1_VERSION >= $(version_code 2.15.56) )) ||
4275 skip "need MDS 2.15.56 or later"
4277 is_project_quota_supported || skip "Project quota is not supported"
4279 local testdir="$DIR/$tdir"
4280 local testfile="$DIR/$tdir/$tfile"
4284 setup_quota_test || error "setup quota failed with $?"
4286 USED=$(getquota -p $projid global curspace)
4287 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid isn't 0"
4289 USED=$(getquota -p $projid2 global curspace)
4290 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid2 isn't 0"
4292 chown $TSTUSR.$TSTUSR $testdir || error "chown $testdir failed"
4294 set_ost_qtype ugp || error "enable ost quota failed"
4296 $LFS project -sp $projid $testdir || error "failed to set project ID"
4297 $LFS setquota -p $projid -B 200M $DIR ||
4298 error "failed to to set prj $projid quota"
4300 $RUNAS touch $testfile
4302 local id=$(lfs project -d $testfile | awk '{print $1}')
4303 [ "$id" != "$projid" ] && error "projid $projid is not inherited $id"
4305 echo "test by mirror created with normal file"
4306 test_mirror $projid $testfile $testfile
4308 $TRUNCATE $testfile 0
4309 wait_delete_completed || error "wait_delete_completed failed"
4310 sync_all_data || true
4312 $LFS project -sp $projid2 $testdir ||
4313 error "failed to set directory project ID"
4314 $LFS project -p $projid2 $testfile ||
4315 error "failed to set file project ID"
4316 $LFS setquota -p $projid -b 0 -B 0 $DIR ||
4317 error "failed to to reset prj quota"
4318 $LFS setquota -p $projid2 -B 200M $DIR ||
4319 error "failed to to set prj $projid2 quota"
4321 local fid=$($LFS path2fid $testfile)
4323 echo "test by mirror created with FID"
4324 test_mirror $projid2 $testfile $MOUNT/.lustre/fid/$fid
4326 run_test 58 "project ID should be kept for new mirrors created by FID"
4329 [ "$mds1_FSTYPE" != ldiskfs ] &&
4330 skip "ldiskfs only test"
4331 disable_project_quota
4332 setup_quota_test || error "setup quota failed with $?"
4335 local testfile="$DIR/$tdir/$tfile-0"
4336 #make sure it did not crash kernel
4337 touch $testfile && lfs project -sp 1 $testfile
4339 enable_project_quota
4341 run_test 59 "lfs project dosen't crash kernel with project disabled"
4344 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4345 skip "Needs MDS version 2.11.53 or later."
4346 setup_quota_test || error "setup quota failed with $?"
4348 local testfile=$DIR/$tdir/$tfile
4351 set_mdt_qtype "ug" || error "enable mdt quota failed"
4353 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4354 error "set quota failed"
4355 quota_show_check a g $TSTUSR
4357 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4358 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4359 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4360 error "create many files failed"
4362 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4364 # root user can overrun quota
4365 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4366 error "root user should succeed"
4368 run_test 60 "Test quota for root with setgid"
4370 # test default quota
4371 test_default_quota() {
4372 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4373 skip "Not supported before 2.11.51."
4378 local qprjid=$TSTPRJID
4382 local LIMIT=20480 #20M disk space
4383 local TESTFILE="$DIR/$tdir/$tfile-0"
4386 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4387 echo "Project quota is not supported" && return 0
4389 [ $qtype == "-u" ] && qdtype="-U"
4390 [ $qtype == "-g" ] && qdtype="-G"
4391 [ $qtype == "-p" ] && {
4396 [ $qres_type == "meta" ] && {
4397 LIMIT=10240 #10K inodes
4402 qpool_cmd="--pool $3"
4403 # pool quotas don't work properly without global limit
4404 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4405 error "set global limit failed"
4408 setup_quota_test || error "setup quota failed with $?"
4412 # enable mdt/ost quota
4413 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4414 set_ost_qtype $QTYPE || error "enable ost quota failed"
4416 log "set to use default quota"
4417 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4418 error "set $qid to use default quota failed"
4420 log "set default quota"
4421 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4422 error "set $qid default quota failed"
4424 log "get default quota"
4425 $LFS quota $qdtype $DIR || error "get default quota failed"
4427 if [ $qres_type == "data" ]; then
4428 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4429 grep "$MOUNT" | awk '{print $2}')
4430 [ $SLIMIT -eq $LIMIT ] ||
4431 error "the returned default quota is wrong"
4433 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4435 [ $SLIMIT -eq $LIMIT ] ||
4436 error "the returned default quota is wrong"
4439 # make sure the system is clean
4440 local USED=$(getquota $qtype $qid global curspace)
4441 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4443 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4444 error "setstripe $TESTFILE failed"
4445 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4447 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4449 log "Test not out of quota"
4450 if [ $qres_type == "data" ]; then
4451 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4452 quota_error $qtype $qid "write failed, expect succeed"
4454 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4455 quota_error $qtype $qid "create failed, expect succeed"
4457 unlinkmany $TESTFILE $((LIMIT/2))
4460 log "Test out of quota"
4461 # flush cache, ensure noquota flag is set on client
4462 cancel_lru_locks osc
4463 cancel_lru_locks mdc
4464 sync; sync_all_data || true
4465 if [ $qres_type == "data" ]; then
4466 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4467 quota_error $qtype $qid "write succeed, expect EDQUOT"
4469 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4470 quota_error $qtype $qid "create succeed, expect EDQUOT"
4472 unlinkmany $TESTFILE $((LIMIT*2))
4476 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4477 error "setstripe $TESTFILE failed"
4478 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4480 log "Increase default quota"
4482 # LU-4505: sleep 5 seconds to enable quota acquire
4485 # increase default quota
4486 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4487 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4489 cancel_lru_locks osc
4490 cancel_lru_locks mdc
4491 sync; sync_all_data || true
4492 if [ $qres_type == "data" ]; then
4493 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4494 quota_error $qtype $qid "write failed, expect succeed"
4496 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4497 quota_error $qtype $qid "create failed, expect succeed"
4499 unlinkmany $TESTFILE $((LIMIT*2))
4502 log "Set quota to override default quota"
4503 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4504 error "set $qid 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 succeed, expect EQUOT"
4513 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4514 quota_error $qtype $qid "create succeed, expect EQUOT"
4516 unlinkmany $TESTFILE $((LIMIT*2))
4519 log "Set to use default quota again"
4521 # LU-4505: sleep 5 seconds to enable quota acquire
4524 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4525 error "set $qid to use default quota failed"
4527 cancel_lru_locks osc
4528 cancel_lru_locks mdc
4529 sync; sync_all_data || true
4530 if [ $qres_type == "data" ]; then
4531 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4532 quota_error $qtype $qid "write failed, expect succeed"
4534 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4535 quota_error $qtype $qid "create failed, expect succeed"
4537 unlinkmany $TESTFILE $((LIMIT*2))
4542 wait_delete_completed || error "wait_delete_completed failed"
4543 sync_all_data || true
4545 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4546 error "reset default quota failed"
4547 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4548 error "reset quota failed"
4553 test_default_quota "-u" "data"
4554 test_default_quota "-u" "meta"
4555 test_default_quota "-g" "data"
4556 test_default_quota "-g" "meta"
4557 test_default_quota "-p" "data"
4558 test_default_quota "-p" "meta"
4560 run_test 61 "default quota tests"
4563 ! is_project_quota_supported &&
4564 skip "Project quota is not supported"
4565 [[ "$(chattr -h 2>&1)" =~ "project" ||
4566 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4567 skip "chattr did not support project quota"
4568 setup_quota_test || error "setup quota failed with $?"
4569 local testdir=$DIR/$tdir/
4571 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4572 change_project -s $testdir
4573 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4574 error "inherit attribute should be set"
4575 # chattr used FS_IOC_SETFLAGS ioctl
4576 $RUNAS chattr -P $testdir &&
4577 error "regular user clear inherit should fail"
4578 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4579 error "inherit attribute should still be set"
4580 chattr -P $testdir || error "root failed to clear inherit"
4581 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4582 error "inherit attribute should be cleared"
4585 run_test 62 "Project inherit should be only changed by root"
4588 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4589 skip "Not supported before 2.11.55"
4593 local dd_failed=false
4594 local tdir_dom=${tdir}_dom
4595 local LIMIT=20480 #20M
4597 [ $qtype == "p" ] && ! is_project_quota_supported &&
4598 echo "Project quota is not supported" && return 0
4600 [ $qtype == "p" ] && qid=$TSTPRJID
4602 setup_quota_test || error "setup quota failed with $?"
4606 # enable mdt/ost quota
4607 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4608 set_ost_qtype $QTYPE || error "enable ost quota failed"
4610 # make sure the system is clean
4611 local USED=$(getquota -$qtype $qid global curspace)
4612 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4614 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4616 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4617 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4618 error "setstripe $tdir_dom failed"
4619 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4621 [ $qtype == "p" ] && {
4622 change_project -sp $TSTPRJID $DIR/$tdir
4623 change_project -sp $TSTPRJID $DIR/$tdir_dom
4626 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4627 error "set $qid quota failed"
4629 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4630 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4634 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4636 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4637 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4641 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4643 rm -f $DIR/$tdir_dom/*
4645 # flush cache, ensure noquota flag is set on client
4646 cancel_lru_locks osc
4647 cancel_lru_locks mdc
4648 sync; sync_all_data || true
4652 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4653 quota_error $qtype $qid "write failed, expect succeed"
4655 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4656 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4660 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4663 rm -f $DIR/$tdir_dom/*
4665 # flush cache, ensure noquota flag is set on client
4666 cancel_lru_locks osc
4667 cancel_lru_locks mdc
4668 sync; sync_all_data || true
4672 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4673 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4677 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4679 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4680 quota_error $qtype $qid "write succeed, expect EDQUOT"
4683 rm -fr $DIR/$tdir_dom
4685 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4686 error "reset usr quota failed"
4694 run_test 63 "quota on DoM tests"
4697 ! is_project_quota_supported &&
4698 skip "Project quota is not supported"
4699 setup_quota_test || error "setup quota failed with $?"
4700 local dir1="$DIR/$tdir/"
4703 ln -s $dir1/file $dir1/file_link
4706 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4707 error "set project should succeed"
4709 used=$(getquota -p $TSTPRJID global curinodes)
4710 [ $used -eq 4 ] || error "expected 4 got $used"
4711 $LFS project -rC $dir1 >&/dev/null ||
4712 error "clear project should succeed"
4714 used=$(getquota -p $TSTPRJID global curinodes)
4715 [ $used -eq 0 ] || error "expected 0 got $used"
4717 run_test 64 "lfs project on non dir/files should succeed"
4721 local TESTFILE="$DIR/$tdir/$tfile-0"
4723 setup_quota_test || error "setup quota failed with $?"
4724 set_ost_qtype $QTYPE || error "enable ost quota failed"
4728 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4729 error "failed to write"
4730 # flush cache, ensure noquota flag is set on client
4731 cancel_lru_locks osc
4732 sync; sync_all_data || true
4734 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4735 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4736 local quota_all=$($RUNAS $LFS quota $DIR)
4738 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4739 error "usr quota not match"
4740 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4741 error "grp quota not match"
4743 run_test 65 "Check lfs quota result"
4746 ! is_project_quota_supported &&
4747 skip "Project quota is not supported"
4748 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4749 skip "Not supported before 2.12.4"
4750 setup_quota_test || error "setup quota failed with $?"
4751 local old=$(do_facet mds1 $LCTL get_param -n \
4752 mdt.*.enable_chprojid_gid | head -1)
4753 local testdir=$DIR/$tdir/foo
4755 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4756 stack_trap "do_facet mds1 $LCTL \
4757 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4759 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4760 chown -R $TSTID:$TSTID $testdir
4761 change_project -sp $TSTPRJID $testdir
4762 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4764 $RUNAS lfs project -p 0 $testdir/foo &&
4765 error "nonroot user should fail to set projid"
4767 $RUNAS lfs project -C $testdir/foo &&
4768 error "nonroot user should fail to clear projid"
4770 change_project -C $testdir/foo || error "failed to clear project"
4772 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4773 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4774 "failed to set projid with normal user when enable_chprojid_gid=-1"
4776 $RUNAS lfs project -rC $testdir/ || error \
4777 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4779 touch $testdir/bar || error "failed touch $testdir/bar"
4780 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4781 "normal user should not be able to set projid on root owned file"
4783 change_project -p $TSTPRJID $testdir/bar || error \
4784 "root should be able to change its own file's projid"
4786 run_test 66 "nonroot user can not change project state in default"
4793 local short_qtype=${qtype:0:1}
4796 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4798 $TSTUSR) _runas=$RUNAS;;
4799 $TSTUSR2) _runas=$RUNAS2;;
4800 *) error "unknown quota parameter $4";;
4805 $_runas $DD of=$file count=$size ||
4806 quota_error $short_qtype $TSTUSR \
4807 "$qtype write failure, but expect success"
4809 cancel_lru_locks osc
4811 sync; sync_all_data || true
4820 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4822 do_facet mds1 $LCTL get_param $param |
4823 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4828 local testfile="$DIR/$tdir/$tfile-0"
4829 local testfile2="$DIR/$tdir/$tfile-1"
4830 local testfile3="$DIR/$tdir/$tfile-2"
4831 local qpool="qpool1"
4837 [ "$ost1_FSTYPE" == zfs ] &&
4838 skip "ZFS grants some block space together with inode"
4840 setup_quota_test || error "setup quota failed with $?"
4843 set_ost_qtype $QTYPE || error "enable ost quota failed"
4846 log "User quota (block hardlimit:$limit MB)"
4847 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4848 error "set user quota failed"
4850 # make sure the system is clean
4851 used=$(getquota -u $TSTUSR global curspace)
4852 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4854 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4855 echo "granted 0x0 before write $granted"
4857 # trigger reintegration
4858 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4859 procf=${procf}quota_slave.force_reint
4860 do_facet ost1 $LCTL set_param $procf=1 ||
4861 error "force reintegration failed"
4862 wait_ost_reint "u" || error "reintegration failed"
4863 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4864 [ $granted -ne 0 ] &&
4865 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4867 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4868 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4870 # write 10 MB to testfile
4871 test_67_write "$testfile" "user" 10 "$TSTUSR"
4873 # create qpool and add OST1
4874 pool_add $qpool || error "pool_add failed"
4875 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4876 # as $TSTUSR hasn't limits, lqe may absent. But it should be
4877 # created after the 1st direct qmt_get.
4878 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4880 # check granted - should be 0, as testfile is located only on OST0
4881 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4882 echo "global granted $granted"
4883 granted=$(getgranted $qpool "dt" $TSTID "usr")
4884 echo "$qpool granted $granted"
4885 [ $granted -ne 0 ] &&
4886 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4888 # add OST0 to qpool and check granted space
4889 pool_add_targets $qpool 0 1 ||
4890 error "pool_add_targets failed"
4891 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4892 echo "Granted $granted_mb MB"
4893 #should be 10M + qunit for each OST
4894 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4895 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4897 $LFS setstripe $testfile2 -c 1 -i 1 ||
4898 error "setstripe $testfile2 failed"
4899 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4900 # Write from another user and check that qpool1
4901 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
4902 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
4903 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4904 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4905 [ $granted -ne 0 ] &&
4906 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4908 # Granted space for $TSTUSR2 in qpool1 should appear only
4909 # when global lqe for this user becomes enforced.
4910 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4911 error "set user quota failed"
4912 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4913 echo "granted_mb $granted_mb"
4914 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4915 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4917 $LFS setstripe $testfile3 -c 1 -i 0 ||
4918 error "setstripe $testfile3 failed"
4919 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4920 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
4921 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4922 echo "$testfile3 granted_mb $granted_mb"
4923 [ $granted_mb -eq $limit ] ||
4924 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4926 # remove OST1 from the qpool1 and check granted space
4927 # should be 0 for TSTUSR and 10M for TSTUSR2
4928 pool_remove_target $qpool 0
4929 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4930 [ $granted_mb -eq 0 ] ||
4931 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4932 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4933 [ $granted_mb -eq 10 ] ||
4934 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4937 wait_delete_completed || error "wait_delete_completed failed"
4938 sync_all_data || true
4939 used=$(getquota -u $TSTUSR global curspace)
4940 [ $used -eq 0 ] || quota_error u $TSTUSR \
4941 "user quota isn't released after deletion"
4943 run_test 67 "quota pools recalculation"
4950 wait_update_facet "--quiet" mds1 \
4951 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4952 >/dev/null 2>&1 || echo foo" "">/dev/null ||
4953 error "mds1: failed to create quota pool $pool"
4955 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4956 awk '/usr/ {getline; print $2}'
4961 local qpool="qpool1"
4964 setup_quota_test || error "setup quota failed with $?"
4967 set_ost_qtype $QTYPE || error "enable ost quota failed"
4969 # check slave number for glbal pool
4970 local nr=$(get_slave_nr "0x0" "usr")
4971 echo "nr result $nr"
4972 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4973 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4975 # create qpool and add OST1
4976 pool_add $qpool || error "pool_add failed"
4977 nr=$(get_slave_nr $qpool "usr")
4978 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4981 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4982 nr=$(get_slave_nr $qpool "usr")
4983 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4986 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4987 nr=$(get_slave_nr $qpool "usr")
4988 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4991 pool_remove_target $qpool 0
4992 nr=$(get_slave_nr $qpool "usr")
4993 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4996 pool_remove_target $qpool 1
4997 nr=$(get_slave_nr $qpool "usr")
4998 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
5000 # Check again that all is fine with global pool
5001 nr=$(get_slave_nr "0x0" "usr")
5002 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
5003 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
5005 run_test 68 "slave number in quota pool changed after each add/remove OST"
5009 local global_limit=200 # MB
5011 local testfile="$DIR/$tdir/$tfile-0"
5012 local dom0="$DIR/$tdir/dom0"
5013 local qpool="qpool1"
5016 setup_quota_test || error "setup quota failed with $?"
5019 set_ost_qtype $QTYPE || error "enable ost quota failed"
5020 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5022 # Save DOM only at MDT0
5023 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
5024 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
5026 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
5028 # create qpool and add OST0
5029 pool_add $qpool || error "pool_add failed"
5030 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5032 log "User quota (block hardlimit:$global_limit MB)"
5033 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5034 error "set user quota failed"
5036 log "User quota (block hardlimit:$limit MB)"
5037 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5038 error "set user quota failed"
5040 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
5041 quota_error u $TSTUSR "write failed"
5043 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5044 oflag=sync || quota_error u $TSTUSR "write failed"
5046 $RUNAS $DD of=$testfile count=$limit || true
5048 # flush cache, ensure noquota flag is set on client
5049 cancel_lru_locks osc
5050 sync; sync_all_data || true
5052 # MDT0 shouldn't get EDQUOT with glimpse.
5053 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
5054 quota_error u $TSTUSR \
5055 "user write success, but expect EDQUOT"
5057 # Now all members of qpool1 should get EDQUOT. Expect success
5058 # when write to DOM on MDT0, as it belongs to global pool.
5059 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
5060 oflag=sync || quota_error u $TSTUSR "write failed"
5062 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5063 oflag=sync || quota_error u $TSTUSR "write failed"
5065 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
5069 local qpool="qpool1"
5074 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
5075 skip "Needs a client >= $VERSION_WITH_QP"
5077 setup_quota_test || error "setup quota failed with $?"
5079 # MDS returns EFAULT for unsupported quotactl command
5080 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
5082 # create qpool and add OST0
5083 pool_add $qpool || error "pool_add failed"
5084 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5086 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
5088 [ $rc -eq $err ] || error "setquota res $rc != $err"
5090 # If MDS supports QP, check that limit was set properly.
5091 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
5092 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
5093 echo "hard limit $bhard limit $limit"
5094 [ $bhard -ne $((limit*1024)) ] &&
5095 error "bhard:$bhard for $qpool!=$((limit*1024))"
5098 $LFS quota -u $TSTUSR --pool $qpool $DIR
5100 [ $rc -eq $err ] || error "quota res $rc != $err"
5102 run_test 70a "check lfs setquota/quota with a pool option"
5106 local glbl_hard=200 # 200M
5107 local glbl_soft=100 # 100M
5108 local pool_hard=10 # 10M
5109 local qpool="qpool1"
5111 pool_add $qpool || error "pool_add failed"
5112 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5114 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
5115 error "set user quota failed"
5116 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
5117 error "set user quota failed"
5119 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5120 [ $tmp -eq $((pool_hard * 1024)) ] ||
5121 error "wrong block hard limit $tmp for $qpool"
5122 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
5123 # soft limit hasn't been set and should be zero
5124 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
5126 run_test 70b "lfs setquota pool works properly"
5131 local global_limit=100 # MB
5132 local testfile="$DIR/$tdir/$tfile-0"
5133 local qpool="qpool1"
5134 local qpool2="qpool2"
5136 [ "$ost1_FSTYPE" == zfs ] &&
5137 skip "ZFS grants some block space together with inode"
5138 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
5140 setup_quota_test || error "setup quota failed with $?"
5143 set_ost_qtype $QTYPE || error "enable ost quota failed"
5146 log "User quota (block hardlimit:$global_limit MB)"
5147 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5148 error "set user quota failed"
5150 pool_add $qpool || error "pool_add failed"
5151 pool_add_targets $qpool 0 1 ||
5152 error "pool_add_targets failed"
5154 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5155 error "set user quota failed"
5157 pool_add $qpool2 || error "pool_add failed"
5158 pool_add_targets $qpool2 1 1 ||
5159 error "pool_add_targets failed"
5161 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
5162 error "set user quota failed"
5164 # make sure the system is clean
5165 local used=$(getquota -u $TSTUSR global curspace)
5168 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5170 # create 1st component 1-10M
5171 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5172 #create 2nd component 10-30M
5173 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5174 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5176 # сheck normal use and out of quota with PFL
5177 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
5178 test_1_check_write $testfile "user" $((limit*2))
5180 wait_delete_completed || error "wait_delete_completed failed"
5181 sync_all_data || true
5182 used=$(getquota -u $TSTUSR global curspace)
5183 [ $used -ne 0 ] && quota_error u $TSTUSR \
5184 "user quota isn't released after deletion"
5186 # create 1st component 1-10M
5187 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5188 # create 2nd component 10-30M
5189 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5190 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5192 # write to the 2nd component
5193 $RUNAS $DD of=$testfile count=$limit seek=10 ||
5194 quota_error u $TSTUSR \
5195 "write failure, but expect success"
5196 # this time maybe cache write, ignore it's failure
5197 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
5198 cancel_lru_locks osc
5199 sync; sync_all_data || true
5200 # write over limit in qpool2(2nd component 10-30M)
5201 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
5202 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5203 # write to the 1st component - OST0 is empty
5204 $RUNAS $DD of=$testfile count=$limit seek=0 ||
5205 quota_error u $TSTUSR "write failed"
5207 run_test 71a "Check PFL with quota pools"
5211 local global_limit=1000 # MB
5212 local limit1=160 # MB
5213 local limit2=10 # MB
5214 local testfile="$DIR/$tdir/$tfile-0"
5215 local qpool="qpool1"
5216 local qpool2="qpool2"
5218 [ "$ost1_FSTYPE" == zfs ] &&
5219 skip "ZFS grants some block space together with inode"
5220 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
5222 setup_quota_test || error "setup quota failed with $?"
5225 set_ost_qtype $QTYPE || error "enable ost quota failed"
5228 log "User quota (block hardlimit:$global_limit MB)"
5229 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5230 error "set user quota failed"
5232 pool_add $qpool || error "pool_add failed"
5233 pool_add_targets $qpool 0 1 ||
5234 error "pool_add_targets failed"
5236 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
5237 error "set user quota failed"
5239 pool_add $qpool2 || error "pool_add failed"
5240 pool_add_targets $qpool2 1 1 ||
5241 error "pool_add_targets failed"
5243 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5244 error "set user quota failed"
5246 # make sure the system is clean
5247 local used=$(getquota -u $TSTUSR global curspace)
5250 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5252 # First component is on OST0, 2nd on OST1
5253 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
5254 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5256 # fill the 1st component on OST0
5257 $RUNAS $DD of=$testfile count=128 ||
5258 quota_error u $TSTUSR "write failed"
5259 # write to the 2nd cmpnt on OST1
5260 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
5261 quota_error u $TSTUSR "write failed"
5262 # this time maybe cache write, ignore it's failure
5263 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
5265 cancel_lru_locks osc
5266 sync; sync_all_data || true
5267 # write over limit in qpool2
5268 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
5269 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5272 run_test 71b "Check SEL with quota pools"
5277 local global_limit=50 # MB
5278 local testfile="$DIR/$tdir/$tfile-0"
5279 local qpool="qpool1"
5282 setup_quota_test || error "setup quota failed with $?"
5285 set_ost_qtype $QTYPE || error "enable ost quota failed"
5288 log "User quota (block hardlimit:$global_limit MB)"
5289 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5290 error "set user quota failed"
5292 pool_add $qpool || error "pool_add failed"
5293 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5295 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5296 error "set user quota failed"
5298 # make sure the system is clean
5299 local used=$(getquota -u $TSTUSR global curspace)
5301 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5303 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5305 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5306 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5307 test_1_check_write $testfile "user" $limit
5308 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5310 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5311 # check that lfs quota -uv --pool prints only OST that
5312 # was added in a pool
5313 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5314 grep "OST\|MDT" && error "$qpool consists wrong targets"
5317 run_test 72 "lfs quota --pool prints only pool's OSTs"
5321 (( $MDS1_VERSION >= $(version_code 2.14.51.158) )) ||
5322 skip "need MDS >= v2_14_51-158-g25a70a88 for default pool quota"
5324 local qpool="qpool1"
5328 pool_add $qpool || error "pool_add failed"
5329 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5330 error "pool_add_targets failed"
5332 test_default_quota "-u" "data" "qpool1"
5334 run_test 73a "default limits at OST Pool Quotas"
5338 (( $MDS1_VERSION >= $(version_code 2.14.52.91) )) ||
5339 skip "need MDS >= v2_14_52-91-g188112fc8 for nested lqe fix"
5341 local TESTFILE1="$DIR/$tdir/$tfile-1"
5343 local qpool="qpool1"
5347 setup_quota_test || error "setup quota failed with $?"
5349 set_ost_qtype $QTYPE || error "enable ost quota failed"
5351 # pool quotas don't work properly without global limit
5352 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5353 error "set global limit failed"
5355 pool_add $qpool || error "pool_add failed"
5356 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5357 error "pool_add_targets failed"
5359 log "set default quota for $qpool"
5360 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5361 error "set default quota failed"
5363 log "Write from user that hasn't lqe"
5364 # Check that it doesn't cause a panic or a deadlock
5365 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5366 # Have to use RUNAS_ID as resetquota creates lqes in
5367 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5368 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5370 cancel_lru_locks osc
5371 sync; sync_all_data || true
5373 run_test 73b "default OST Pool Quotas limit for new user"
5377 (( $MDS1_VERSION >= $(version_code 2.14.52.6) )) ||
5378 skip "need MDS >= v2_14_52-6-g8c19365416 for pool per-user fix"
5380 local global_limit=200 # 200M
5381 local limit=10 # 10M
5382 local limit2=50 # 50M
5383 local qpool="qpool1"
5384 local qpool2="qpool2"
5388 setup_quota_test || error "setup quota failed with $?"
5391 set_ost_qtype $QTYPE || error "enable ost quota failed"
5393 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5394 error "set user quota failed"
5396 pool_add $qpool || error "pool_add failed"
5397 pool_add_targets $qpool 0 1 ||
5398 error "pool_add_targets failed"
5400 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5401 error "set user quota failed"
5403 pool_add $qpool2 || error "pool_add failed"
5404 pool_add_targets $qpool2 1 1 ||
5405 error "pool_add_targets failed"
5407 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5408 error "set user quota failed"
5410 tmp=$(getquota -u $TSTUSR global bhardlimit)
5411 [ $tmp -eq $((global_limit * 1024)) ] ||
5412 error "wrong global limit $global_limit"
5414 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5415 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5417 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5418 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5420 # check limits in pools
5421 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5422 grep -A4 $qpool | awk 'NR == 4{print $4}')
5423 echo "pool limit for $qpool $tmp"
5424 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5425 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5426 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5427 echo "pool limit for $qpool2 $tmp"
5428 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5430 run_test 74 "check quota pools per user"
5432 function cleanup_quota_test_75()
5434 do_facet mgs $LCTL nodemap_modify --name default \
5435 --property admin --value 1
5436 do_facet mgs $LCTL nodemap_modify --name default \
5437 --property trusted --value 1
5438 do_facet mgs $LCTL nodemap_modify --name default \
5439 --property squash_uid --value 99
5440 do_facet mgs $LCTL nodemap_modify --name default \
5441 --property squash_gid --value 99
5443 wait_nm_sync default admin_nodemap
5444 wait_nm_sync default trusted_nodemap
5446 do_facet mgs $LCTL nodemap_activate 0
5449 resetquota -u $TSTUSR
5453 local dd_failed=false
5454 local LIMIT=20480 #20M
5457 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5458 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5459 conv=fsync || dd_failed=true
5462 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5464 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5465 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5466 conv=fsync || dd_failed=true
5469 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5471 rm -f $DIR/$tdir_dom/*
5473 # flush cache, ensure noquota flag is set on client
5475 sync; sync_all_data || true
5479 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) conv=fsync ||
5480 quota_error u $qid "write failed, expect succeed (2)"
5482 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5483 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5484 conv=fsync || dd_failed=true
5487 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5490 rm -f $DIR/$tdir_dom/*
5492 # flush cache, ensure noquota flag is set on client
5494 sync; sync_all_data || true
5498 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5499 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5500 conv=fsync || dd_failed=true
5503 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5505 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=direct &&
5506 quota_error u $qid "write succeed, expect EDQUOT (3)"
5512 (( $MDS1_VERSION >= $(version_code 2.14.52.68) )) ||
5513 skip "need MDS >= v2_14_52-68-ga4fbe7341b for squash root fix"
5515 local soft_limit=10 # MB
5516 local hard_limit=20 # MB
5517 local limit=$soft_limit
5518 local testfile="$DIR/$tdir/$tfile-0"
5519 local grace=20 # seconds
5520 local tdir_dom=${tdir}_dom
5522 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5526 setup_quota_test || error "setup quota failed with $?"
5527 stack_trap cleanup_quota_test_75 EXIT
5530 set_ost_qtype $QTYPE || error "enable ost quota failed"
5531 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5533 local used=$(getquota -u $TSTID global curspace)
5534 $LFS setquota -t -u --block-grace $grace --inode-grace \
5535 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5536 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5537 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5538 error "set user quota failed"
5540 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5541 mkdir $DIR/$tdir_dom
5542 chmod 777 $DIR/$tdir_dom
5543 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5544 error "setstripe $tdir_dom failed"
5546 do_facet mgs $LCTL nodemap_activate 1
5548 do_facet mgs $LCTL nodemap_modify --name default \
5549 --property admin --value 0
5550 do_facet mgs $LCTL nodemap_modify --name default \
5551 --property trusted --value 0
5552 do_facet mgs $LCTL nodemap_modify --name default \
5553 --property deny_unknown --value 0
5554 do_facet mgs $LCTL nodemap_modify --name default \
5555 --property squash_uid --value $TSTID
5556 do_facet mgs $LCTL nodemap_modify --name default \
5557 --property squash_gid --value $TSTID
5558 cancel_lru_locks mdc
5559 wait_nm_sync default admin_nodemap
5560 wait_nm_sync default trusted_nodemap
5561 wait_nm_sync default squash_uid
5563 # mmap write when over soft limit
5565 $DD of=$testfile count=${limit} || quota_error a $TSTUSR \
5566 "root write failure, but expect success (1)"
5567 OFFSET=$((limit * 1024))
5568 cancel_lru_locks osc
5570 echo "Write to exceed soft limit"
5571 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5572 quota_error a $TSTUSR "root write failure, but expect success (2)"
5573 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5574 cancel_lru_locks osc
5576 echo "mmap write when over soft limit"
5577 $MULTIOP $testfile.mmap OT40960SMW ||
5578 quota_error a $TSTUSR "mmap write failure, but expect success"
5579 cancel_lru_locks osc
5581 wait_delete_completed || error "wait_delete_completed failed (1)"
5582 sync_all_data || true
5584 # test for user hard limit
5587 $DD of=$testfile count=$((limit/2)) ||
5588 quota_error u $TSTID \
5589 "root write failure, but expect success (3)"
5591 log "Write out of block quota ..."
5592 # possibly a cache write, ignore failure
5593 $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
5594 # flush cache, ensure noquota flag is set on client
5595 cancel_lru_locks osc
5596 sync; sync_all_data || true
5597 # sync forced cache flush, but did not guarantee that slave
5598 # got new edquot through glimpse, so wait to make sure
5600 $DD of=$testfile count=1 seek=$limit conv=fsync &&
5601 quota_error u $TSTID \
5602 "user write success, but expect EDQUOT"
5604 wait_delete_completed || error "wait_delete_completed failed (2)"
5605 sync_all_data || true
5606 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5607 quota_error u $TSTID "user quota not released after deletion"
5611 run_test 75 "nodemap squashed root respects quota enforcement"
5614 (( $MDS1_VERSION >= $(version_code 2.14.52.109) )) ||
5615 skip "need MDS >= v2_14_52-109-g3ffa5d680f for bad PRJID fix"
5616 ! is_project_quota_supported &&
5617 skip "skip project quota unsupported"
5619 setup_quota_test || error "setup quota failed with $?"
5622 local testfile="$DIR/$tdir/$tfile-0"
5625 $LFS project -p 4294967295 $testfile &&
5626 error "set project ID should fail"
5629 run_test 76 "project ID 4294967295 should be not allowed"
5633 (( $MDS1_VERSION >= $(version_code 2.14.54.33) )) ||
5634 skip "need MDS >= v2_14_54-33-g29e00cecc6 for readonly fix"
5636 mount_client $MOUNT2 "ro"
5637 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5638 error "lfs setquota should fail in read-only Lustre mount"
5641 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5645 (( $OST1_VERSION >= $(version_code 2.14.55.173) )) ||
5646 skip "need OST >= v2_14_55-173-g789038c97a for fallocate fix"
5647 check_set_fallocate_or_skip
5649 setup_quota_test || error "setup quota failed with $?"
5652 set_ost_qtype $QTYPE || error "enable ost quota failed"
5654 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5655 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5658 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5659 error "lfs setquota failed"
5662 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5664 kbytes=$(lfs quota -u $TSTUSR $DIR |
5665 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5666 echo "kbytes returned:$kbytes"
5668 # For file size of 204800. We should be having roughly 200 kbytes
5669 # returned. Anything alarmingly low (50 taken as arbitrary value)
5670 # would bail out this TC. Also this also avoids $kbytes of 0
5671 # to be used in calculation below.
5672 (( $kbytes > 50 )) ||
5673 error "fallocate did not use quota. kbytes returned:$kbytes"
5675 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5676 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5678 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5679 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5680 error "fallocate did not use quota correctly"
5682 run_test 78A "Check fallocate increase quota usage"
5686 (( $CLIENT_VERSION >= $(version_code 2.15.0.37) )) ||
5687 skip "need client >= v2_15_50-37-g5fc934eb for falloc proj fix"
5688 (( $OST1_VERSION >= $(version_code 2.15.0.37) )) ||
5689 skip "need OST >= v2_15_50-37-g5fc934ebbb for falloc proj fix"
5690 check_set_fallocate_or_skip
5692 setup_quota_test || error "setup quota failed with $?"
5695 set_ost_qtype $QTYPE || error "enable ost quota failed"
5697 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5699 local projectid=5200 # Random project id to test
5701 change_project -sp $projectid $DIR/$tdir
5704 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5705 error "lfs setquota project failed"
5708 fallocate -l 204800 $DIR/$tdir/$tfile
5710 # Get curspace (kbytes) for $projectid
5711 local kbytes=$(getquota -p $projectid global curspace)
5713 echo "kbytes returned:$kbytes"
5715 # For file size of 204800. We should be having roughly 200 kbytes
5716 # returned. Anything alarmingly low (50 taken as arbitrary value)
5717 # would bail out this TC. Also this also avoids $kbytes of 0
5718 # to be used in calculation below.
5719 (( $kbytes > 50 )) ||
5720 error "fallocate did not use projectid. kbytes returned:$kbytes"
5722 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5723 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5725 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5726 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5727 error "fallocate did not use quota projectid correctly"
5729 run_test 78a "Check fallocate increase projectid usage"
5733 (( $MDS1_VERSION >= $(version_code 2.14.56.37) )) ||
5734 skip "need MDS >= v2_14_56-37-gc9901b68b4 for pool panic fix"
5736 local qpool="qpool1"
5737 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5738 local stopf=$TMP/$tfile
5740 do_facet mds1 "touch $stopf"
5741 stack_trap "do_facet mds1 'rm -f $stopf'"
5742 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5744 pool_add $qpool || error "pool_add failed"
5745 do_facet mds1 "rm $stopf"
5748 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5752 (( $MDS1_VERSION >= $(version_code 2.14.56.51) )) ||
5753 skip "need MDS >= v2_14_56-51-g61ec1e0f2c for EDQUOT failover"
5755 local dir1="$DIR/$tdir/dir1"
5756 local dir2="$DIR/$tdir/dir2"
5757 local TESTFILE0="$dir1/$tfile-0"
5758 local TESTFILE1="$dir1/$tfile-1"
5759 local TESTFILE2="$dir1/$tfile-2"
5760 local TESTFILE3="$dir2/$tfile-0"
5761 local global_limit=100 # 100M
5762 local limit=10 # 10M
5763 local qpool="qpool1"
5765 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5767 [ "$ost1_FSTYPE" == zfs ] &&
5768 skip "ZFS grants some block space together with inode"
5769 setup_quota_test || error "setup quota failed with $?"
5770 set_ost_qtype $QTYPE || error "enable ost quota failed"
5772 # make sure the system is clean
5773 local used=$(getquota -u $TSTUSR global curspace)
5774 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5776 pool_add $qpool || error "pool_add failed"
5777 pool_add_targets $qpool 0 1 ||
5778 error "pool_add_targets failed"
5780 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5781 error "set user quota failed"
5783 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5784 error "set user quota failed"
5785 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5786 error "set user quota failed"
5788 mkdir -p $dir1 || error "failed to mkdir"
5789 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5790 mkdir -p $dir2 || error "failed to mkdir"
5791 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5793 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5794 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5799 $LFS quota -uv $TSTUSR $DIR
5800 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5801 do_facet mds1 $LCTL set_param fail_loc=0xa06
5802 $RUNAS $DD of=$TESTFILE3 count=3 ||
5803 quota_error u $TSTUSR "write failed"
5804 $RUNAS $DD of=$TESTFILE2 count=7 ||
5805 quota_error u $TSTUSR "write failed"
5806 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5807 quota_error u $TSTUSR "write failed"
5810 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5814 do_facet mds1 $LCTL set_param fail_loc=0
5815 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5816 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5817 # OST0 needs some time to update quota usage after removing TESTFILE2
5819 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5820 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5821 quota_error u $TSTUSR "write failure, but expect success"
5823 run_test 80 "check for EDQUOT after OST failover"
5827 (( $MDS1_VERSION >= $(version_code 2.14.56.52) )) ||
5828 skip "need MDS >= v2_14_56-52-g862f0baa7c for qmt_pool_free fix"
5830 local global_limit=20 # 100M
5831 local testfile="$DIR/$tdir/$tfile-0"
5832 local qpool="qpool1"
5835 setup_quota_test || error "setup quota failed with $?"
5838 set_ost_qtype $QTYPE || error "enable ost quota failed"
5841 log "User quota (block hardlimit:$global_limit MB)"
5842 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5844 pool_add $qpool || error "pool_add failed"
5845 #define OBD_FAIL_QUOTA_RECALC 0xA07
5846 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5847 # added OST casues to start pool recalculation
5848 pool_add_targets $qpool 0 0 1
5849 stop mds1 -f || error "MDS umount failed"
5851 #start mds1 back to destroy created pool
5852 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5855 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5859 (( $MDS1_VERSION >= $(version_code 2.15.50.72) )) ||
5860 skip "need MDS >= v2_15_50-72-g61481796ac for over 8 QIDs fix"
5862 is_project_quota_supported || skip "skip project quota unsupported"
5864 setup_quota_test || error "setup quota failed with $?"
5867 local parent_dir="$DIR/$tdir.parent"
5868 local child_dir="$parent_dir/child"
5871 stack_trap "chown -R 0:0 $parent_dir"
5873 chown $TSTUSR:$TSTUSR $parent_dir ||
5874 error "failed to chown on $parent_dir"
5875 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5876 error "failed to chown on $parent_dir"
5878 $LFS project -p 1000 $parent_dir ||
5879 error "failed to set project id on $parent_dir"
5880 $LFS project -p 1001 $child_dir ||
5881 error "failed to set project id on $child_dir"
5883 rmdir $child_dir || error "cannot remove child dir, test failed"
5885 run_test 82 "verify more than 8 qids for single operation"
5887 test_grace_with_default_quota()
5896 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
5897 error "clear default quota [$qdtype] failed"
5899 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
5900 error "reset quota [$qdtype] grace failed"
5903 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5904 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
5907 $LFS setquota $qdtype -B 10G -i 10k $DIR
5910 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5911 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
5913 [ "$bgrace" == "$bgrace2" ] ||
5914 error "set default quota shouldn't affect block grace"
5915 [ "$igrace" == "$igrace2" ] ||
5916 error "set default quota shouldn't affect inode grace"
5922 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
5923 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
5925 setup_quota_test || error "setup quota failed with $?"
5926 test_grace_with_default_quota "-u" "-U"
5927 test_grace_with_default_quota "-g" "-G"
5929 is_project_quota_supported || return 0
5930 test_grace_with_default_quota "-p" "-P"
5932 run_test 83 "Setting default quota shouldn't affect grace time"
5936 (( $MDS1_VERSION >= $(version_code 2.15.53.115) )) ||
5937 skip "need MDS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
5938 (( $OST1_VERSION >= $(version_code 2.15.53.115) )) ||
5939 skip "need OSS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
5941 local dir1="$DIR/$tdir/dir1"
5942 local TESTFILE1="$dir1/$tfile-1"
5950 setup_quota_test || error "setup quota failed with $?"
5952 set_ost_qtype $QTYPE || error "enable ost quota failed"
5954 pool_add $qp || error "pool_add failed"
5955 pool_add_targets $qp 0 $(($OSTCOUNT - 1)) ||
5956 error "pool_add_targets failed"
5958 $LFS setquota -g $TSTUSR -B 10G $DIR ||
5959 error "failed to set group quota for $TSTUSR"
5960 $LFS setquota -g $TSTUSR -B 5G --pool $qp $DIR ||
5961 error "set user quota failed"
5962 $LFS quota -gv $TSTUSR $DIR
5964 wait_quota_synced "ost1" "OST0000" "grp" $TSTID "hardlimit" "10485760"
5966 mkdir -p $dir1 || error "failed to mkdir"
5967 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5969 $LFS setstripe -c 1 -i 0 $TESTFILE1
5970 $LFS getstripe $TESTFILE1
5971 chown $TSTUSR.$TSTUSR $TESTFILE1
5973 $RUNAS $DD of=$TESTFILE1 count=60 conv=nocreat oflag=direct ||
5974 quota_error g $TSTUSR "write failed"
5976 sync_all_data || true
5978 $LFS quota -gv $TSTUSR $DIR
5979 $LFS quota -gv --pool $qp $TSTUSR $DIR
5981 # the grant quota should be larger than 0
5983 while (( $waited < 60 )); do
5984 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
5985 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
5986 (( ${grant} > 0 && ${grant2} > 0 )) && break
5988 do_facet ost1 $LCTL set_param \
5989 osd-*.*-OST0000.quota_slave.force_reint=1
5991 waited=$((waited + 1))
5994 (( $waited >= 60)) && {
5995 $LFS quota -gv $TSTUSR $DIR
5996 $LFS quota -gv --pool $qp $TSTUSR $DIR
5999 (( ${grant} > 0 )) || error "pool grant is not increased after dd"
6000 (( ${grant2} > 0 )) || error "grant is not increased after dd"
6002 #define OBD_FAIL_QUOTA_GRANT 0xA08
6003 lustre_fail mds 0xa08
6004 lustre_fail ost 0xa08
6007 # clear quota limits to trigger updating grant quota
6008 $LFS setquota -g $TSTUSR -b 0 -B 0 $DIR ||
6009 error "failed to clear the group quota for $TSTUSR"
6010 $LFS quota -gv $TSTUSR $DIR
6011 $LFS quota -gv --pool $qp $TSTUSR $DIR
6013 # the grant quota should be set as insane value
6015 while (( $waited < 60 )); do
6016 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6017 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6018 (( ${#grant} == 20 && ${#grant2} == 20 )) && break
6021 waited=$((waited + 1))
6024 (( $waited >= 60)) && {
6025 $LFS quota -gv $TSTUSR $DIR
6026 $LFS quota -gv --pool $qp $TSTUSR $DIR
6029 (( ${#grant} == 20 )) || error "pool grant is not set as insane value"
6030 (( ${#grant2} == 20 )) || error "grant is not set as insane value"
6032 lustre_fail mds_ost 0
6036 $LFS setquota -g $TSTUSR -r $DIR ||
6037 error "failed to reset group quota for $TSTUSR"
6040 $LFS quota -gv $TSTUSR $DIR
6041 $LFS quota -gv --pool $qp $TSTUSR $DIR
6043 # the grant quota should be reset
6044 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6045 (( ${#grant} == 20 )) && error "grant is not cleared"
6046 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6047 (( ${#grant} == 20 )) && error "pool grant is not cleared"
6049 $LFS quota -gv $TSTUSR --pool $qp $DIR
6050 $LFS quota -gv --pool $qp $TSTUSR $DIR
6051 local hlimit=$(getquota -g $TSTUSR global bhardlimit $qp)
6052 [ $hlimit -eq 5242880 ] || error "pool limit is changed"
6054 # test whether the quota still works
6055 $LFS setquota -g $TSTUSR -B 100M $DIR ||
6056 error "failed to set group quota for $TSTUSR"
6057 $LFS quota -gv $TSTUSR $DIR
6059 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct &&
6060 quota_error g $TSTUSR "dd succeed, expect EDQUOT"
6062 $LFS setquota -g $TSTUSR -B 300M $DIR ||
6063 error "failed to set group quota for $TSTUSR"
6064 $LFS quota -gv $TSTUSR $DIR
6066 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct ||
6067 quota_error g $TSTUSR "dd failed, expect succeed"
6069 run_test 84 "Reset quota should fix the insane granted quota"
6073 (( $MDS1_VERSION >= $(version_code 2.15.55.5) )) ||
6074 skip "need MDS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6075 (( $OST1_VERSION >= $(version_code 2.15.55.5) )) ||
6076 skip "need OSS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6079 local qpool="qpool1"
6080 local qpool2="qpool2"
6081 local tfile1="$DIR/$tdir/$tfile-0"
6083 (( OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
6085 setup_quota_test || error "setup quota failed with $?"
6088 set_ost_qtype $QTYPE || error "enable ost quota failed"
6090 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
6091 error "set user quota failed"
6093 pool_add $qpool || error "pool_add failed"
6094 pool_add_targets $qpool 0 1 ||
6095 error "pool_add_targets failed"
6097 pool_add $qpool2 || error "pool_add failed"
6098 pool_add_targets $qpool2 0 1 ||
6099 error "pool_add_targets failed"
6101 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
6102 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
6103 error "set user quota failed"
6104 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
6105 error "set user quota failed"
6107 # don't care about returned value. Just check we don't hung on write.
6108 $RUNAS $DD of=$tfile1 count=10
6111 run_test 85 "do not hung at write with the least_qunit"
6113 test_preacquired_quota()
6120 [[ "$qtype" == "-p" ]] && change_project -sp $qid $DIR/$tdir
6122 $LFS setquota $qtype $qid -i 100K -I 100K $DIR ||
6123 error "failed to set file [$qtype] quota"
6125 $RUNAS createmany -m $test_dir/tfile- 5000 ||
6126 error "failed to create files, expect succeed"
6128 wait_zfs_commit $SINGLEMDS
6129 $LFS setquota $qtype $qid -i 2K -I 2K $DIR ||
6130 error "failed to decrease file [$qtype] quota"
6132 wait_quota_synced "mds1" "MDT0000" $qtype_name $qid "hardlimit" "2048"
6134 # make sure the lqe->lqe_edquot is set
6135 $RUNAS createmany -m $test_dir/tfile2- 10
6138 $RUNAS createmany -m $test_dir/tfile3- 30 &&
6139 error "succeed to create files, expect failed"
6141 rm -f $test_dir/tfile*
6142 $LFS setquota $qtype $qid -i 0 -I 0 $DIR ||
6143 error "failed to reset file user quota"
6148 (( $MDS1_VERSION >= $(version_code 2.15.57.41) )) ||
6149 skip "need MDS >= 2.15.57.41 for quota over limit release fix"
6151 local test_dir="$DIR/$tdir/test_dir"
6153 setup_quota_test || error "setup quota failed with %?"
6154 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
6156 $LFS setdirstripe -c 1 -i 0 $test_dir || error "setdirstripe failed"
6159 test_preacquired_quota "$test_dir" "-u" "usr" "$TSTID"
6160 test_preacquired_quota "$test_dir" "-g" "grp" "$TSTID"
6162 is_project_quota_supported || return 0
6163 test_preacquired_quota "$test_dir" "-p" "prj" "1000"
6165 run_test 86 "Pre-acquired quota should be released if quota is over limit"
6169 do_nodes $(comma_list $(nodes_list)) \
6170 "lctl set_param -n debug=-quota-trace"
6171 if $PQ_CLEANUP; then
6172 disable_project_quota
6175 reset_quota_settings
6179 complete_test $SECONDS
6180 check_and_cleanup_lustre
6181 export QUOTA_AUTO=$QUOTA_AUTO_OLD