3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 VERSION_WITH_QP="2.13.53"
44 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
45 skip "Needs MDS version $VERSION_WITH_QP or later."
48 require_dsh_mds || exit 0
49 require_dsh_ost || exit 0
51 # Does e2fsprogs support quota feature?
52 if [ "$mds1_FSTYPE" == ldiskfs ] &&
53 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
54 grep -q 'quota'"; then
55 skip_env "e2fsprogs doesn't support quota"
58 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
60 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
65 QUOTA_AUTO_OLD=$QUOTA_AUTO
68 check_and_setup_lustre
70 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
77 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
78 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
79 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
84 local fail_val=${3:-0}
88 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
89 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
90 ost) NODES="$(comma_list $(osts_nodes))";;
93 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
99 lfs project $* || error "lfs project $* failed"
102 RUNAS="runas -u $TSTID -g $TSTID"
103 RUNAS2="runas -u $TSTID2 -g $TSTID2"
104 DD="dd if=/dev/zero bs=1M"
108 # clear quota limits for a user or a group
109 # usage: resetquota -u username
110 # resetquota -g groupname
111 # resetquota -p projid
114 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
115 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
116 error "resetquota: wrong specifier $1 passed"
118 if [ $1 == "-p" ]; then
119 is_project_quota_supported || return 0
122 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
123 error "clear quota for [type:$1 name:$2] failed"
124 # give a chance to slave to release space
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 wait_update_facet $tgt "$cmd |
293 grep "$qtype" | awk '{ print \\\$3 }'" \
294 "$result" $max || return 1
304 if [[ "$qtype" =~ "u" ]]; then
305 wait_reintegration "mdt" "user" $max || return 1
308 if [[ "$qtype" =~ "g" ]]; then
309 wait_reintegration "mdt" "group" $max || return 1
312 if [[ "$qtype" =~ "p" ]]; then
313 ! is_project_quota_supported && return 0
314 wait_reintegration "mdt" "project" $max || return 1
323 if [[ "$qtype" =~ "u" ]]; then
324 wait_reintegration "ost" "user" $max || return 1
327 if [[ "$qtype" =~ "g" ]]; then
328 wait_reintegration "ost" "group" $max || return 1
331 if [[ "$qtype" =~ "p" ]]; then
332 ! is_project_quota_supported && return 0
333 wait_reintegration "ost" "project" $max || return 1
342 local extrasleep=${4:-5}
349 *) error "get_grace_time: Invalid quota type: $qtype"
354 echo "Quota info for $pool:"
355 $LFS quota -$qtype $qarg $parg $DIR
360 time=$(lfs quota -$qtype $qarg $parg $DIR|
361 awk 'NR == 3{ print $5 }')
364 time=$(lfs quota -$qtype $qarg $DIR|
365 awk 'NR == 3{ print $9 }')
368 error "Unknown quota type: $flavour"
372 local sleep_seconds=0
373 local orig_time=$time
375 echo "Grace time is $time"
376 # from lfs.c:__sec2str()
377 # const char spec[] = "smhdw";
378 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
379 [[ $time == *w* ]] && w_time=${time%w*} &&
380 let sleep_seconds+=$((w_time*7*24*60*60));
382 [[ $time == *d* ]] && d_time=${time%d*} &&
383 let sleep_seconds+=$((d_time*24*60*60));
385 [[ $time == *h* ]] && h_time=${time%h*} &&
386 let sleep_seconds+=$((h_time*60*60));
388 [[ $time == *m* ]] && m_time=${time%m*} &&
389 let sleep_seconds+=$((m_time*60));
391 [[ $time == *s* ]] && s_time=${time%s*} &&
392 let sleep_seconds+=$s_time
394 echo "Sleep through grace ..."
395 [ "$orig_time" == "-" ] &&
396 error "Grace timeout was not set or quota not exceeded"
397 if [ "$orig_time" == "none" ]; then
398 echo "...Grace timeout already expired"
400 let sleep_seconds+=$extrasleep
401 echo "...sleep $sleep_seconds seconds"
407 wait_delete_completed
408 echo "Creating test directory"
409 mkdir_on_mdt0 $DIR/$tdir || return 1
410 chmod 0777 $DIR/$tdir || return 2
411 # always clear fail_loc in case of fail_loc isn't cleared
412 # properly when previous test failed
413 lustre_fail mds_ost 0
414 stack_trap cleanup_quota_test EXIT
417 cleanup_quota_test() {
418 echo "Delete files..."
420 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
421 echo "Wait for unlink objects finished..."
422 wait_delete_completed
423 sync_all_data || true
433 $LFS quota -v -$ugp $qid $DIR
435 if [ "$bf" == "a" -o "$bf" == "b" ]; then
436 usage=$(getquota -$ugp $qid global curspace)
437 if [ -z $usage ]; then
438 quota_error $ugp $qid \
439 "Query block quota failed ($ugp:$qid)."
441 [ $usage -ne 0 ] && quota_log $ugp $qid \
442 "Block quota isn't 0 ($ugp:$qid:$usage)."
446 if [ "$bf" == "a" -o "$bf" == "f" ]; then
447 usage=$(getquota -$ugp $qid global curinodes)
448 if [ -z $usage ]; then
449 quota_error $ugp $qid \
450 "Query file quota failed ($ugp:$qid)."
452 [ $usage -ne 0 ] && quota_log $ugp $qid \
453 "File quota isn't 0 ($ugp:$qid:$usage)."
458 project_quota_enabled () {
460 local zfeat="feature@project_quota"
462 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
463 local facet_fstype=${facet:0:3}1_FSTYPE
466 if [ "${!facet_fstype}" = "zfs" ]; then
467 devname=$(zpool_name ${facet})
468 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
469 grep -wq active || rc=1
471 [ ${facet:0:3} == "mds" ] &&
472 devname=$(mdsdevname ${facet:3}) ||
473 devname=$(ostdevname ${facet:3})
474 do_facet ${facet} $DEBUGFS -R features $devname |
475 grep -q project || rc=1
478 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
482 project_quota_enabled || enable_project_quota
484 reset_quota_settings() {
485 resetquota -u $TSTUSR
487 resetquota -g $TSTUSR
489 resetquota -u $TSTUSR2
490 resetquota -u $TSTID2
491 resetquota -g $TSTUSR2
492 resetquota -g $TSTID2
493 resetquota -p $TSTPRJID
498 do_nodes $(comma_list $(nodes_list)) \
499 "$LCTL set_param -n debug=+quota,trace"
504 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
505 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
506 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
507 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
509 test_quota_performance() {
510 local TESTFILE="$DIR/$tdir/$tfile-0"
511 local size=$1 # in MB
512 local stime=$(date +%s)
513 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
514 quota_error u $TSTUSR "write failure"
515 local etime=$(date +%s)
516 delta=$((etime - stime))
517 if [ $delta -gt 0 ]; then
518 rate=$((size * 1024 / delta))
519 if [ "$mds1_FSTYPE" = zfs ]; then
520 # LU-2872 - see LU-2887 for fix
522 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
524 [ $rate -gt 1024 ] ||
525 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
531 # test basic quota performance b=21696
534 [ "$SLOW" = "no" ] && MB=10
536 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
537 [ $free_space -le $((MB * 1024)) ] &&
538 skip "not enough space ${free_space} KB, " \
539 "required $((MB * 1024)) KB"
540 setup_quota_test || error "setup quota failed with $?"
542 set_ost_qtype "none" || error "disable ost quota failed"
543 test_quota_performance $MB
545 set_ost_qtype $QTYPE || error "enable ost quota failed"
546 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
547 error "set quota failed"
548 test_quota_performance $MB
550 run_test 0 "Test basic quota performance"
552 # usage: test_1_check_write tfile user|group|project
553 test_1_check_write() {
557 local short_qtype=${qtype:0:1}
560 $RUNAS $DD of=$testfile count=$((limit/2)) ||
561 quota_error $short_qtype $TSTUSR \
562 "$qtype write failure, but expect success"
563 log "Write out of block quota ..."
564 # this time maybe cache write, ignore it's failure
565 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
566 # flush cache, ensure noquota flag is set on client
568 sync; sync_all_data || true
569 # sync means client wrote all it's cache, but id doesn't
570 # guarantee that slave received new edquot through glimpse.
571 # so wait a little to be sure slave got it.
573 $RUNAS $DD of=$testfile count=1 seek=$limit &&
574 quota_error $short_qtype $TSTUSR \
575 "user write success, but expect EDQUOT"
579 check_write_fallocate() {
583 local short_qtype=${qtype:0:1}
586 log "Write ${count}MiB Using Fallocate"
587 $RUNAS fallocate -l${count}MiB $testfile ||
588 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
591 sync; sync_all_data || true
595 log "Write ${count}MiB Using Fallocate"
596 $RUNAS fallocate -l${count}MiB $testfile &&
597 quota_error $short_qtype $TSTUSR \
598 "Write success, expect EDQUOT" || true
601 # test block hardlimit
604 local testfile="$DIR/$tdir/$tfile-0"
606 setup_quota_test || error "setup quota failed with $?"
609 set_ost_qtype $QTYPE || error "enable ost quota failed"
612 log "User quota (block hardlimit:$limit MB)"
613 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
614 error "set user quota failed"
616 # make sure the system is clean
617 local used=$(getquota -u $TSTUSR global curspace)
618 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
620 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
621 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
623 test_1_check_write $testfile "user" $limit
626 wait_delete_completed || error "wait_delete_completed failed"
627 sync_all_data || true
628 used=$(getquota -u $TSTUSR global curspace)
629 [ $used -ne 0 ] && quota_error u $TSTUSR \
630 "user quota isn't released after deletion"
631 resetquota -u $TSTUSR
634 log "--------------------------------------"
635 log "Group quota (block hardlimit:$limit MB)"
636 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
637 error "set group quota failed"
639 testfile="$DIR/$tdir/$tfile-1"
640 # make sure the system is clean
641 used=$(getquota -g $TSTUSR global curspace)
642 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
644 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
645 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
647 test_1_check_write $testfile "group" $limit
649 wait_delete_completed || error "wait_delete_completed failed"
650 sync_all_data || true
651 used=$(getquota -g $TSTUSR global curspace)
652 [ $used -ne 0 ] && quota_error g $TSTUSR \
653 "Group quota isn't released after deletion"
654 resetquota -g $TSTUSR
656 if ! is_project_quota_supported; then
657 echo "Project quota is not supported"
661 testfile="$DIR/$tdir/$tfile-2"
662 # make sure the system is clean
663 used=$(getquota -p $TSTPRJID global curspace)
665 error "used space($used) for project $TSTPRJID isn't 0"
668 log "--------------------------------------"
669 log "Project quota (block hardlimit:$limit mb)"
670 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
671 error "set project quota failed"
673 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
674 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
675 change_project -p $TSTPRJID $testfile
677 test_1_check_write $testfile "project" $limit
682 used=$(getquota -p $TSTPRJID global curspace)
683 [ $used -ne 0 ] && quota_error p $TSTPRJID \
684 "project quota isn't released after deletion"
686 resetquota -p $TSTPRJID
688 run_test 1a "Block hard limit (normal use and out of quota)"
692 local global_limit=20 # MB
693 local testfile="$DIR/$tdir/$tfile-0"
697 setup_quota_test || error "setup quota failed with $?"
700 set_ost_qtype $QTYPE || error "enable ost quota failed"
703 log "User quota (block hardlimit:$global_limit MB)"
704 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
705 error "set user quota failed"
707 pool_add $qpool || error "pool_add failed"
708 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
709 error "pool_add_targets failed"
711 # check qmt_pool_add dmesg error
712 local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
714 dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
715 [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
717 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
718 error "set user quota failed"
720 # make sure the system is clean
721 local used=$(getquota -u $TSTUSR global curspace)
723 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
725 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
727 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
728 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
730 test_1_check_write $testfile "user" $limit
733 wait_delete_completed || error "wait_delete_completed failed"
734 sync_all_data || true
735 used=$(getquota -u $TSTUSR global curspace $qpool)
736 [ $used -ne 0 ] && quota_error u $TSTUSR \
737 "user quota isn't released after deletion"
738 resetquota -u $TSTUSR
741 log "--------------------------------------"
742 log "Group quota (block hardlimit:$global_limit MB)"
743 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
744 error "set group quota failed"
746 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
747 error "set group quota failed"
749 testfile="$DIR/$tdir/$tfile-1"
750 # make sure the system is clean
751 used=$(getquota -g $TSTUSR global curspace $qpool)
752 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
754 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
755 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
757 test_1_check_write $testfile "group" $limit
760 wait_delete_completed || error "wait_delete_completed failed"
761 sync_all_data || true
762 used=$(getquota -g $TSTUSR global curspace $qpool)
763 [ $used -ne 0 ] && quota_error g $TSTUSR \
764 "Group quota isn't released after deletion"
765 resetquota -g $TSTUSR
767 if ! is_project_quota_supported; then
768 echo "Project quota is not supported"
772 testfile="$DIR/$tdir/$tfile-2"
773 # make sure the system is clean
774 used=$(getquota -p $TSTPRJID global curspace $qpool)
776 error "used space($used) for project $TSTPRJID isn't 0"
779 log "--------------------------------------"
780 log "Project quota (block hardlimit:$global_limit mb)"
781 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
782 error "set project quota failed"
784 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
785 error "set project quota failed"
788 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
789 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
790 change_project -p $TSTPRJID $testfile
792 test_1_check_write $testfile "project" $limit
797 used=$(getquota -p $TSTPRJID global curspace)
798 [ $used -eq 0 ] || quota_error p $TSTPRJID \
799 "project quota isn't released after deletion"
801 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
804 local global_limit=20 # MB
805 local testfile="$DIR/$tdir/$tfile-0"
806 local qpool1="qpool1"
807 local qpool2="qpool2"
810 setup_quota_test || error "setup quota failed with $?"
813 set_ost_qtype $QTYPE || error "enable ost quota failed"
816 log "User quota (block hardlimit:$global_limit MB)"
817 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
818 error "set user quota failed"
820 pool_add $qpool1 || error "pool_add failed"
821 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
822 error "pool_add_targets failed"
824 pool_add $qpool2 || error "pool_add failed"
825 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
826 error "pool_add_targets failed"
828 # create pools without hard limit
829 # initially such case raised several bugs
830 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
831 error "set user quota failed"
833 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
834 error "set user quota failed"
836 # make sure the system is clean
837 local used=$(getquota -u $TSTUSR global curspace)
839 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
841 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
843 test_1_check_write $testfile "user" $global_limit
845 used=$(getquota -u $TSTUSR global curspace $qpool1)
846 echo "qpool1 used $used"
847 used=$(getquota -u $TSTUSR global curspace $qpool2)
848 echo "qpool2 used $used"
851 wait_delete_completed || error "wait_delete_completed failed"
852 sync_all_data || true
854 used=$(getquota -u $TSTUSR global curspace $qpool1)
855 [ $used -eq 0 ] || quota_error u $TSTUSR \
856 "user quota isn't released after deletion"
858 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
863 local global_limit=20 # MB
864 local testfile="$DIR/$tdir/$tfile-0"
865 local qpool1="qpool1"
866 local qpool2="qpool2"
869 setup_quota_test || error "setup quota failed with $?"
872 set_ost_qtype $QTYPE || error "enable ost quota failed"
875 log "User quota (block hardlimit:$global_limit MB)"
876 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
877 error "set user quota failed"
879 pool_add $qpool1 || error "pool_add failed"
880 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
881 error "pool_add_targets failed"
883 pool_add $qpool2 || error "pool_add failed"
884 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
885 error "pool_add_targets failed"
887 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
888 error "set user quota failed"
890 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
891 error "set user quota failed"
893 # make sure the system is clean
894 local used=$(getquota -u $TSTUSR global curspace)
896 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
898 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
900 test_1_check_write $testfile "user" $limit1
902 used=$(getquota -u $TSTUSR global curspace $qpool1)
903 echo "qpool1 used $used"
904 used=$(getquota -u $TSTUSR global curspace $qpool2)
905 echo "qpool2 used $used"
908 wait_delete_completed || error "wait_delete_completed failed"
909 sync_all_data || true
911 used=$(getquota -u $TSTUSR global curspace $qpool1)
912 [ $used -eq 0 ] || quota_error u $TSTUSR \
913 "user quota isn't released after deletion"
915 run_test 1d "Quota pools: check block hardlimit on different pools"
919 local global_limit=53000000 # MB
920 local testfile="$DIR/$tdir/$tfile-0"
921 local testfile2="$DIR/$tdir/$tfile-1"
922 local qpool1="qpool1"
925 setup_quota_test || error "setup quota failed with $?"
928 set_ost_qtype $QTYPE || error "enable ost quota failed"
930 # global_limit is much greater than limit1 to get
931 # different qunit's on osts. Since 1st qunit shrinking
932 # on OST1(that belongs to qpool1), this qunit should
934 log "User quota (block hardlimit:$global_limit MB)"
935 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
936 error "set user quota failed"
938 pool_add $qpool1 || error "pool_add failed"
939 pool_add_targets $qpool1 1 1 ||
940 error "pool_add_targets failed"
942 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
943 error "set user quota failed"
945 # make sure the system is clean
946 local used=$(getquota -u $TSTUSR global curspace)
947 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
949 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
950 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
952 test_1_check_write $testfile "user" $limit1
954 $LFS setstripe $testfile2 -c 1 -i 0 ||
955 error "setstripe $testfile2 failed"
956 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
957 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
959 $RUNAS $DD of=$testfile2 count=20 ||
960 quota_error u $TSTUSR \
961 "$qtype write failure, but expect success"
965 wait_delete_completed || error "wait_delete_completed failed"
966 sync_all_data || true
968 used=$(getquota -u $TSTUSR global curspace $qpool1)
969 [ $used -eq 0 ] || quota_error u $TSTUSR \
970 "user quota isn't released after deletion"
972 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
975 local global_limit=200 # MB
977 local TESTDIR="$DIR/$tdir/"
978 local testfile="$TESTDIR/$tfile-0"
979 local qpool1="qpool1"
982 setup_quota_test || error "setup quota failed with $?"
985 set_ost_qtype $QTYPE || error "enable ost quota failed"
987 log "User quota (block hardlimit:$global_limit MB)"
988 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
989 error "set user quota failed"
991 pool_add $qpool1 || error "pool_add failed"
992 pool_add_targets $qpool1 0 0 ||
993 error "pool_add_targets failed"
995 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
996 error "set user quota failed"
998 # make sure the system is clean
999 local used=$(getquota -u $TSTUSR global curspace)
1000 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1002 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1004 test_1_check_write $testfile "user" $limit1
1006 pool_remove_target $qpool1 0
1008 wait_delete_completed || error "wait_delete_completed failed"
1009 sync_all_data || true
1011 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1012 # qunit for appropriate element in lgd array should be set
1013 # correctly(4096). Earlier it was not changed continuing to be 1024.
1014 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1015 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1016 # as it already was 1024. As flag "need_update" for this qunit was
1017 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1018 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1019 # became > 10M. QMT returned EINPROGRESS in a loop.
1020 # Check that it doesn't hung anymore.
1021 test_1_check_write $testfile "user" $limit1
1023 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1027 local global_limit=40 # MB
1028 local testfile="$DIR/$tdir/$tfile-0"
1029 local qpool="qpool1"
1030 local mdmb_param="osc.*.max_dirty_mb"
1031 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1034 setup_quota_test || error "setup quota failed with $?"
1035 $LCTL set_param $mdmb_param=1
1036 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1039 set_ost_qtype $QTYPE || error "enable ost quota failed"
1042 log "User quota (block hardlimit:$global_limit MB)"
1043 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1044 error "set user quota failed"
1046 pool_add $qpool || error "pool_add failed"
1047 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1048 error "pool_add_targets failed"
1050 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1051 error "set user quota failed"
1053 # make sure the system is clean
1054 local used=$(getquota -u $TSTUSR global curspace)
1056 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1058 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1059 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1062 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1063 quota_error u $TSTUSR \
1064 "$qtype write failure, but expect success"
1065 log "Write out of block quota ..."
1066 # this time maybe cache write, ignore it's failure
1067 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1068 # flush cache, ensure noquota flag is set on client
1069 cancel_lru_locks osc
1070 sync; sync_all_data || true
1072 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1073 quota_error u $TSTUSR \
1074 "user write success, but expect EDQUOT"
1077 wait_delete_completed || error "wait_delete_completed failed"
1078 sync_all_data || true
1080 used=$(getquota -u $TSTUSR global curspace $qpool)
1081 [ $used -ne 0 ] && quota_error u $TSTUSR \
1082 "user quota isn't released after deletion"
1085 run_test 1g "Quota pools: Block hard limit with wide striping"
1089 local testfile="$DIR/$tdir/$tfile-0"
1091 check_set_fallocate_or_skip
1093 setup_quota_test || error "setup quota failed with $?"
1096 set_ost_qtype $QTYPE || error "enable ost quota failed"
1099 log "User quota (block hardlimit:$limit MB)"
1100 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1101 error "set user quota failed"
1103 # make sure the system is clean
1104 local used=$(getquota -u $TSTUSR global curspace)
1105 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1107 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1108 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1110 check_write_fallocate $testfile "user" $limit
1113 wait_delete_completed || error "wait_delete_completed failed"
1114 sync_all_data || true
1115 used=$(getquota -u $TSTUSR global curspace)
1116 [ $used -eq 0 ] || quota_error u $TSTUSR \
1117 "user quota isn't released after deletion"
1119 run_test 1h "Block hard limit test using fallocate"
1122 local global_limit=200 # 200M
1123 local limit1=10 # 10M
1124 local TESTDIR="$DIR/$tdir/"
1125 local testfile="$TESTDIR/$tfile-0"
1126 local testfile1="$TESTDIR/$tfile-1"
1127 local testfile2="$TESTDIR/$tfile-2"
1128 local qpool1="qpool1"
1131 setup_quota_test || error "setup quota failed with $?"
1132 stack_trap cleanup_quota_test EXIT
1135 set_ost_qtype $QTYPE || error "enable ost quota failed"
1137 log "User quota (block hardlimit:$global_limit MB)"
1138 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1139 error "set user quota failed"
1141 pool_add $qpool1 || error "pool_add failed"
1142 pool_add_targets $qpool1 0 0 ||
1143 error "pool_add_targets failed"
1145 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1146 error "set user quota failed"
1148 # make sure the system is clean
1149 local used=$(getquota -u $TSTUSR global curspace)
1150 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1152 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1155 test_1_check_write $testfile "user" $limit1
1156 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1157 error "set user quota failed"
1159 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1160 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1161 quota_error u $TSTUSR "write failure, but expect success"
1165 wait_delete_completed || error "wait_delete_completed failed"
1166 sync_all_data || true
1168 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1169 error "set user quota failed"
1170 test_1_check_write $testfile "user" $limit1
1171 local tmp_limit=$(($limit1*2))
1172 # increase pool limit
1173 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1174 error "set user quota failed"
1175 # now write shouldn't fail
1176 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1177 quota_error u $TSTUSR "write failure, but expect success"
1178 # decrease pool limit
1179 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1180 error "set user quota failed"
1181 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1182 # flush cache, ensure noquota flag is set on client
1183 cancel_lru_locks osc
1184 sync; sync_all_data || true
1185 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1186 quota_error u $TSTUSR "write success, but expect failure"
1189 run_test 1i "Quota pools: different limit and usage relations"
1191 # test inode hardlimit
1193 local testfile="$DIR/$tdir/$tfile-0"
1194 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1195 qmt.$FSNAME-QMT0000.md-0x0.info |
1196 sed -e 's/least qunit/least_qunit/' |
1197 awk '/least_qunit/{ print $2 }')
1200 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1201 limit=$((least_qunit * 1024))
1202 echo "least_qunit: '$least_qunit', limit: '$limit'"
1204 local free_inodes=$(mdt_free_inodes 0)
1205 echo "$free_inodes free inodes on master MDT"
1206 [ $free_inodes -lt $limit ] &&
1207 skip "not enough free inodes $free_inodes required $limit"
1209 setup_quota_test || error "setup quota failed with $?"
1212 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1215 log "User quota (inode hardlimit:$limit files)"
1216 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1217 error "set user quota failed"
1219 # make sure the system is clean
1220 local used=$(getquota -u $TSTUSR global curinodes)
1221 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1223 log "Create $((limit - least_qunit)) files ..."
1224 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1225 quota_error u $TSTUSR "user create failure, but expect success"
1226 # it is ok, if it fails on the last qunit
1227 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1228 log "Create out of file quota ..."
1229 $RUNAS touch ${testfile}_xxx &&
1230 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1233 unlinkmany ${testfile} $((limit - least_qunit)) ||
1234 error "unlinkmany $testfile failed"
1235 # if 2nd createmany got EDQUOT, not all of nodes would be created
1236 unlinkmany ${testfile}_yyy $least_qunit || true
1237 rm -f ${testfile}_xxx
1238 wait_delete_completed
1240 used=$(getquota -u $TSTUSR global curinodes)
1241 [ $used -ne 0 ] && quota_error u $TSTUSR \
1242 "user quota isn't released after deletion"
1243 resetquota -u $TSTUSR
1246 log "--------------------------------------"
1247 log "Group quota (inode hardlimit:$limit files)"
1248 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1249 error "set group quota failed"
1251 testfile=$DIR/$tdir/$tfile-1
1252 # make sure the system is clean
1253 used=$(getquota -g $TSTUSR global curinodes)
1254 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1256 log "Create $limit files ..."
1257 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1258 quota_error g $TSTUSR "group create failure, but expect success"
1259 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1260 log "Create out of file quota ..."
1261 $RUNAS touch ${testfile}_xxx &&
1262 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1265 unlinkmany ${testfile} $((limit - least_qunit)) ||
1266 error "unlinkmany $testfile failed"
1267 unlinkmany ${testfile}_yyy $least_qunit || true
1268 rm -f ${testfile}_xxx
1269 wait_delete_completed
1271 used=$(getquota -g $TSTUSR global curinodes)
1272 [ $used -ne 0 ] && quota_error g $TSTUSR \
1273 "user quota isn't released after deletion"
1275 resetquota -g $TSTUSR
1276 ! is_project_quota_supported &&
1277 echo "Skip project quota is not supported" && return 0
1280 log "--------------------------------------"
1281 log "Project quota (inode hardlimit:$limit files)"
1282 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1283 error "set project quota failed"
1285 testfile=$DIR/$tdir/$tfile-1
1286 # make sure the system is clean
1287 used=$(getquota -p $TSTPRJID global curinodes)
1289 error "Used inodes($used) for project $TSTPRJID isn't 0"
1291 change_project -sp $TSTPRJID $DIR/$tdir
1292 log "Create $limit files ..."
1293 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1294 quota_error p $TSTPRJID \
1295 "project create fail, but expect success"
1296 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1297 log "Create out of file quota ..."
1298 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1299 "project create success, but expect EDQUOT"
1300 change_project -C $DIR/$tdir
1303 used=$(getquota -p $TSTPRJID global curinodes)
1304 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1305 "project quota isn't released after deletion"
1308 run_test 2 "File hard limit (normal use and out of quota)"
1317 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1318 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1322 $LFS setstripe $testfile -c 1 -i 0
1323 chown $TSTUSR.$TSTUSR $testfile
1324 [ "$qtype" == "p" ] && is_project_quota_supported &&
1325 change_project -p $TSTPRJID $testfile
1327 echo "Write up to soft limit"
1328 $RUNAS $DD of=$testfile count=$limit ||
1329 quota_error a $TSTUSR "write failure, but expect success"
1330 OFFSET=$((limit * 1024))
1331 cancel_lru_locks osc
1333 echo "Write to exceed soft limit"
1334 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1335 quota_error a $TSTUSR "write failure, but expect success"
1336 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1337 cancel_lru_locks osc
1339 echo "mmap write when over soft limit"
1340 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1341 quota_error a $TSTUSR "mmap write failure, but expect success"
1342 cancel_lru_locks osc
1347 $SHOW_QUOTA_INFO_USER
1348 $SHOW_QUOTA_INFO_GROUP
1349 $SHOW_QUOTA_INFO_PROJID
1351 echo "Write before timer goes off"
1352 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1353 quota_error a $TSTUSR "write failure, but expect success"
1354 OFFSET=$((OFFSET + 1024))
1355 cancel_lru_locks osc
1357 wait_grace_time $qtype "block" $pool
1362 $SHOW_QUOTA_INFO_USER
1363 $SHOW_QUOTA_INFO_GROUP
1364 $SHOW_QUOTA_INFO_PROJID
1366 log "Write after timer goes off"
1367 # maybe cache write, ignore.
1368 # write up to soft least quint to consume all
1369 # possible slave granted space.
1370 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1371 count=$soft_limit seek=$OFFSET || true
1372 OFFSET=$((OFFSET + soft_limit))
1373 cancel_lru_locks osc
1374 log "Write after cancel lru locks"
1375 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1376 quota_error a $TSTUSR "write success, but expect EDQUOT"
1381 $SHOW_QUOTA_INFO_USER
1382 $SHOW_QUOTA_INFO_GROUP
1383 $SHOW_QUOTA_INFO_PROJID
1385 echo "Unlink file to stop timer"
1387 wait_delete_completed
1388 sync_all_data || true
1393 $SHOW_QUOTA_INFO_USER
1394 $SHOW_QUOTA_INFO_GROUP
1395 $SHOW_QUOTA_INFO_PROJID
1397 $LFS setstripe $testfile -c 1 -i 0
1398 chown $TSTUSR.$TSTUSR $testfile
1399 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1402 $RUNAS $DD of=$testfile count=$limit ||
1403 quota_error a $TSTUSR "write failure, but expect success"
1410 local grace=20 # seconds
1411 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1414 local testfile=$DIR/$tdir/$tfile-0
1416 # get minimum soft qunit size
1417 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1418 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1420 set_ost_qtype $QTYPE || error "enable ost quota failed"
1422 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1423 # make sure the system is clean
1424 local used=$(getquota -u $TSTUSR global curspace)
1425 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1427 $LFS setquota -t -u --block-grace $grace --inode-grace \
1428 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1429 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1430 error "set user quota failed"
1432 test_block_soft $testfile $grace $limit "u"
1434 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1435 testfile=$DIR/$tdir/$tfile-1
1436 # make sure the system is clean
1437 used=$(getquota -g $TSTUSR global curspace)
1438 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1440 $LFS setquota -t -g --block-grace $grace --inode-grace \
1441 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1442 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1443 error "set group quota failed"
1445 test_block_soft $testfile $grace $limit "g"
1447 if is_project_quota_supported; then
1448 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1449 testfile=$DIR/$tdir/$tfile-2
1450 # make sure the system is clean
1451 used=$(getquota -p $TSTPRJID global curspace)
1452 [ $used -ne 0 ] && error \
1453 "Used space($used) for project $TSTPRJID isn't 0."
1455 $LFS setquota -t -p --block-grace $grace --inode-grace \
1456 $MAX_IQ_TIME $DIR ||
1457 error "set project grace time failed"
1458 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1459 $DIR || error "set project quota failed"
1461 test_block_soft $testfile $grace $limit "p"
1462 resetquota -p $TSTPRJID
1463 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1464 $MAX_IQ_TIME $DIR ||
1465 error "restore project grace time failed"
1469 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1470 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1471 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1472 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1474 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1477 local grace=20 # seconds
1478 local qpool="qpool1"
1479 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1482 local testfile=$DIR/$tdir/$tfile-0
1485 # get minimum soft qunit size
1486 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1487 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1488 local glbl_limit=$((2*limit))
1489 local glbl_grace=$((2*grace))
1490 echo "limit $limit glbl_limit $glbl_limit"
1491 echo "grace $grace glbl_grace $glbl_grace"
1493 set_ost_qtype $QTYPE || error "enable ost quota failed"
1495 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1496 # make sure the system is clean
1497 local used=$(getquota -u $TSTUSR global curspace)
1498 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1500 pool_add $qpool || error "pool_add failed"
1501 pool_add_targets $qpool 0 1 ||
1502 error "pool_add_targets failed"
1504 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1505 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1506 $LFS setquota -t -u --block-grace $grace \
1507 --pool $qpool $DIR || error "set user grace time failed"
1509 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1510 error "set user quota failed"
1511 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1512 error "set user quota failed"
1514 test_block_soft $testfile $grace $limit "u" $qpool
1516 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1517 testfile=$DIR/$tdir/$tfile-1
1518 # make sure the system is clean
1519 used=$(getquota -g $TSTUSR global curspace)
1520 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1522 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1523 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1524 $LFS setquota -t -g --block-grace $grace \
1525 --pool $qpool $DIR || error "set group grace time failed"
1527 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1528 error "set group quota failed"
1529 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1530 error "set group quota failed"
1532 test_block_soft $testfile $grace $limit "g" $qpool
1534 if is_project_quota_supported; then
1535 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1536 testfile=$DIR/$tdir/$tfile-2
1537 # make sure the system is clean
1538 used=$(getquota -p $TSTPRJID global curspace)
1539 [ $used -ne 0 ] && error \
1540 "Used space($used) for project $TSTPRJID isn't 0."
1542 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1543 $MAX_IQ_TIME $DIR ||
1544 error "set project grace time failed"
1545 $LFS setquota -t -p --block-grace $grace \
1546 --pool $qpool $DIR ||
1547 error "set project grace time failed"
1549 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1550 $DIR || error "set project quota failed"
1551 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1552 --pool $qpool $DIR || error "set project quota failed"
1554 test_block_soft $testfile $grace $limit "p" $qpool
1555 resetquota -p $TSTPRJID
1556 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1557 $MAX_IQ_TIME $DIR ||
1558 error "restore project grace time failed"
1559 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1560 $DIR || error "set project grace time failed"
1564 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1565 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1566 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1567 --pool $qpool $DIR || error "restore user grace time failed"
1568 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1569 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1570 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1571 --pool $qpool $DIR || error "restore group grace time failed"
1573 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1576 local grace=20 # seconds
1577 local qpool="qpool1"
1578 local qpool2="qpool2"
1579 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1582 local testfile=$DIR/$tdir/$tfile-0
1585 # get minimum soft qunit size
1586 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1587 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1588 local limit2=$((limit+4))
1589 local glbl_limit=$((limit+8))
1590 local grace1=$((grace+10))
1592 local glbl_grace=$((grace+20))
1593 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1594 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1596 set_ost_qtype $QTYPE || error "enable ost quota failed"
1598 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1599 # make sure the system is clean
1600 local used=$(getquota -u $TSTUSR global curspace)
1601 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1603 pool_add $qpool || error "pool_add failed"
1604 pool_add_targets $qpool 0 1 ||
1605 error "pool_add_targets failed"
1607 pool_add $qpool2 || error "pool_add failed"
1608 pool_add_targets $qpool2 0 1 ||
1609 error "pool_add_targets failed"
1612 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1613 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1614 $LFS setquota -t -u --block-grace $grace1 \
1615 --pool $qpool $DIR || error "set user grace time failed"
1616 $LFS setquota -t -u --block-grace $grace2 \
1617 --pool $qpool2 $DIR || error "set user grace time failed"
1619 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1620 error "set user quota failed"
1621 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1622 error "set user quota failed"
1623 # qpool has minimum soft limit, but its grace is greater than
1624 # the grace period of qpool2. Thus write shouldn't fail when
1625 # hit qpool soft limit - only when reaches up qpool2 limit
1626 # after grace2 seconds.
1627 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1628 error "set user quota failed"
1630 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1633 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1634 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1635 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1636 --pool $qpool $DIR || error "restore user grace time failed"
1637 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1638 --pool $qpool2 $DIR || error "restore user grace time failed"
1640 run_test 3c "Quota pools: check block soft limit on different pools"
1647 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1648 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1651 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1653 echo "Create files to exceed soft limit"
1654 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1655 quota_error a $TSTUSR "create failure, but expect success"
1656 local trigger_time=$(date +%s)
1658 sync_all_data || true
1660 local cur_time=$(date +%s)
1661 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1662 error "Passed grace time $grace, $trigger_time, $cur_time"
1664 echo "Create file before timer goes off"
1665 $RUNAS touch ${TESTFILE}_before ||
1666 quota_error a $TSTUSR "failed create before timer expired," \
1667 "but expect success. $trigger_time, $cur_time"
1668 sync_all_data || true
1670 wait_grace_time $qtype "file"
1675 $SHOW_QUOTA_INFO_USER
1676 $SHOW_QUOTA_INFO_GROUP
1677 $SHOW_QUOTA_INFO_PROJID
1679 echo "Create file after timer goes off"
1680 # exceed least soft limit is possible
1681 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1682 quota_error a $TSTUSR "create after timer expired," \
1684 sync_all_data || true
1689 $SHOW_QUOTA_INFO_USER
1690 $SHOW_QUOTA_INFO_GROUP
1691 $SHOW_QUOTA_INFO_PROJID
1693 echo "Unlink files to stop timer"
1694 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1695 wait_delete_completed
1698 $RUNAS touch ${TESTFILE}_xxx ||
1699 quota_error a $TSTUSR "touch after timer stop failure," \
1700 "but expect success"
1701 sync_all_data || true
1709 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1710 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1711 local TESTFILE=$DIR/$tdir/$tfile-0
1714 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1715 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1717 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1718 # make sure the system is clean
1719 local USED=$(getquota -u $TSTUSR global curinodes)
1720 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1722 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1723 $GRACE $DIR || error "set user grace time failed"
1724 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1725 error "set user quota failed"
1727 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1729 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1730 # make sure the system is clean
1731 USED=$(getquota -g $TSTUSR global curinodes)
1732 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1734 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1735 $GRACE $DIR || error "set group grace time failed"
1736 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1737 error "set group quota failed"
1738 TESTFILE=$DIR/$tdir/$tfile-1
1740 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1742 if is_project_quota_supported; then
1743 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1744 # make sure the system is clean
1745 USED=$(getquota -p $TSTPRJID global curinodes)
1746 [ $USED -ne 0 ] && error \
1747 "Used space($USED) for project $TSTPRJID isn't 0."
1749 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1750 $GRACE $DIR || error "set project grace time failed"
1751 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1752 error "set project quota failed"
1754 TESTFILE=$DIR/$tdir/$tfile-1
1755 # one less than limit, because of parent directory included.
1756 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1757 resetquota -p $TSTPRJID
1758 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1759 $MAX_IQ_TIME $DIR ||
1760 error "restore project grace time failed"
1764 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1765 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1766 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1767 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1769 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1772 local GR_STR1="1w3d"
1773 local GR_STR2="1000s"
1775 local GR_STR4="1w2d3h4m5s"
1777 local GR_STR6="18446744073709551615"
1780 wait_delete_completed
1782 # test of valid grace strings handling
1783 echo "Valid grace strings test"
1784 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1785 $GR_STR2 $DIR || error "set user grace time failed"
1786 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1787 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1788 $GR_STR4 $DIR || error "set group grace time quota failed"
1789 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1791 # test of invalid grace strings handling
1792 echo " Invalid grace strings test"
1793 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1794 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1795 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1799 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1800 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1801 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1802 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1804 run_test 4b "Grace time strings handling"
1806 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1808 local BLIMIT=10 # MB
1809 local ILIMIT=10 # inodes
1811 setup_quota_test || error "setup quota failed with $?"
1813 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1814 set_ost_qtype $QTYPE || error "enable ost quota failed"
1816 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1817 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1818 error "set user quota failed"
1819 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1820 if is_project_quota_supported; then
1821 error "set group quota failed"
1822 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1823 -I $ILIMIT $DIR || error "set project quota failed"
1826 # make sure the system is clean
1827 local USED=$(getquota -u $TSTUSR global curinodes)
1828 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1829 USED=$(getquota -g $TSTUSR global curinodes)
1830 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1831 USED=$(getquota -u $TSTUSR global curspace)
1832 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1833 USED=$(getquota -g $TSTUSR global curspace)
1834 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1835 if is_project_quota_supported; then
1836 USED=$(getquota -p $TSTPRJID global curinodes)
1838 error "Used inode($USED) for project $TSTPRJID isn't 0."
1839 USED=$(getquota -p $TSTPRJID global curspace)
1841 error "Used block($USED) for project $TSTPRJID isn't 0."
1844 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1845 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1846 error "create failure, expect success"
1847 if is_project_quota_supported; then
1848 touch $DIR/$tdir/$tfile-0_1
1849 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1851 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1852 error "write failure, expect success"
1854 echo "Chown files to $TSTUSR.$TSTUSR ..."
1855 for i in $(seq 0 $ILIMIT); do
1856 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1857 quota_error a $TSTUSR "chown failure, expect success"
1861 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1862 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1864 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1866 # test dropping acquire request on master
1870 # Clear dmesg so watchdog is not triggered by previous
1872 do_facet ost1 dmesg -c > /dev/null
1874 setup_quota_test || error "setup quota failed with $?"
1876 # make sure the system is clean
1877 local USED=$(getquota -u $TSTUSR global curspace)
1878 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1880 # make sure no granted quota on ost
1881 set_ost_qtype $QTYPE || error "enable ost quota failed"
1882 resetquota -u $TSTUSR
1884 # create file for $TSTUSR
1885 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1886 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1887 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1889 # create file for $TSTUSR2
1890 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1891 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1892 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1894 # cache per-ID lock for $TSTUSR on slave
1895 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1896 error "set quota failed"
1897 $RUNAS $DD of=$TESTFILE count=1 ||
1898 error "write $TESTFILE failure, expect success"
1899 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1900 error "write $TESTFILE2 failure, expect success"
1902 if at_is_enabled; then
1903 at_max_saved=$(at_max_get ost1)
1904 at_max_set $TIMEOUT ost1
1906 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1907 # DQACQ is sent, which makes at_max to take effect
1908 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1911 wait_delete_completed
1915 sync_all_data || true
1917 #define QUOTA_DQACQ 601
1918 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1919 lustre_fail mds 0x513 601
1921 do_facet ost1 $LCTL set_param \
1922 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1924 # write to un-enforced ID ($TSTUSR2) should succeed
1925 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1926 error "write failure, expect success"
1928 # write to enforced ID ($TSTUSR) in background, exceeding limit
1929 # to make sure DQACQ is sent
1930 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1933 # watchdog timer uses a factor of 2
1934 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1935 sleep $((TIMEOUT * 2 + 1))
1937 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1939 # write should be blocked and never finished
1940 if ! ps -p $DDPID > /dev/null 2>&1; then
1942 error "write finished incorrectly!"
1947 # no watchdog is triggered
1948 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1949 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1950 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1951 [ -z "$watchdog" ] || error "$watchdog"
1953 rm -f $TMP/lustre-log-${TESTNAME}.log
1955 # write should continue then fail with EDQUOT
1959 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1960 if [ $count -ge 240 ]; then
1961 quota_error u $TSTUSR "dd not finished in $count secs"
1963 count=$((count + 1))
1964 if [ $((count % 30)) -eq 0 ]; then
1965 c_size=$(stat -c %s $TESTFILE)
1966 echo "Waiting $count secs. $c_size"
1972 run_test 6 "Test dropping acquire request on master"
1974 # quota reintegration (global index)
1976 local TESTFILE=$DIR/$tdir/$tfile
1979 [ "$SLOW" = "no" ] && LIMIT=5
1981 setup_quota_test || error "setup quota failed with $?"
1983 # make sure the system is clean
1984 local USED=$(getquota -u $TSTUSR global curspace)
1985 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1987 # make sure no granted quota on ost1
1988 set_ost_qtype $QTYPE || error "enable ost quota failed"
1989 resetquota -u $TSTUSR
1990 set_ost_qtype "none" || error "disable ost quota failed"
1992 local OSTUUID=$(ostuuid_from_index 0)
1993 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1995 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1998 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1999 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2004 echo "Enable quota & set quota limit for $TSTUSR"
2005 set_ost_qtype $QTYPE || error "enable ost quota failed"
2006 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2007 error "set quota failed"
2009 echo "Start ost1..."
2010 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2013 wait_ost_reint $QTYPE || error "reintegration failed"
2015 # hardlimit should have been fetched by slave during global
2016 # reintegration, write will exceed quota
2017 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2018 quota_error u $TSTUSR "write success, but expect EDQUOT"
2021 wait_delete_completed
2022 sync_all_data || true
2028 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2029 error "clear quota failed"
2031 echo "Start ost1..."
2032 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2035 wait_ost_reint $QTYPE || error "reintegration failed"
2037 # hardlimit should be cleared on slave during reintegration
2038 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2039 quota_error u $TSTUSR "write error, but expect success"
2041 run_test 7a "Quota reintegration (global index)"
2043 # quota reintegration (slave index)
2045 local limit=100000 # MB
2046 local TESTFILE=$DIR/$tdir/$tfile
2048 setup_quota_test || error "setup quota failed with $?"
2050 # make sure the system is clean
2051 local USED=$(getquota -u $TSTUSR global curspace)
2052 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2054 # make sure no granted quota on ost1
2055 set_ost_qtype $QTYPE || error "enable ost quota failed"
2056 resetquota -u $TSTUSR
2057 set_ost_qtype "none" || error "disable ost quota failed"
2059 local OSTUUID=$(ostuuid_from_index 0)
2060 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2062 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2065 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2066 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2068 # consume some space to make sure the granted space will not
2069 # be released during reconciliation
2070 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2071 error "consume space failure, expect success"
2073 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2074 lustre_fail mds 0xa02
2076 set_ost_qtype $QTYPE || error "enable ost quota failed"
2077 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2078 error "set quota failed"
2080 # ignore the write error
2081 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2083 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2087 echo "Restart ost to trigger reintegration..."
2089 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2092 wait_ost_reint $QTYPE || error "reintegration failed"
2094 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2095 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2100 run_test 7b "Quota reintegration (slave index)"
2102 # quota reintegration (restart mds during reintegration)
2105 local TESTFILE=$DIR/$tdir/$tfile
2107 [ "$SLOW" = "no" ] && LIMIT=5
2109 setup_quota_test || error "setup quota failed with $?"
2111 # make sure the system is clean
2112 local USED=$(getquota -u $TSTUSR global curspace)
2113 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2115 set_ost_qtype "none" || error "disable ost quota failed"
2116 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2117 error "set quota failed"
2119 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2120 lustre_fail ost 0xa03
2123 set_ost_qtype $QTYPE || error "enable ost quota failed"
2124 # trigger reintegration
2125 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2126 procf=${procf}quota_slave.force_reint
2127 do_facet ost1 $LCTL set_param $procf=1 ||
2128 error "force reintegration failed"
2136 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2139 # wait longer than usual to make sure the reintegration
2140 # is triggered by quota wb thread.
2141 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2143 # hardlimit should have been fetched by slave during global
2144 # reintegration, write will exceed quota
2145 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2146 quota_error u $TSTUSR "write success, but expect EDQUOT"
2149 run_test 7c "Quota reintegration (restart mds during reintegration)"
2151 # Quota reintegration (Transfer index in multiple bulks)
2153 local TESTFILE=$DIR/$tdir/$tfile
2154 local TESTFILE1="$DIR/$tdir/$tfile"-1
2157 setup_quota_test || error "setup quota failed with $?"
2159 set_ost_qtype "none" || error "disable ost quota failed"
2160 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2161 error "set quota for $TSTUSR failed"
2162 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2163 error "set quota for $TSTUSR2 failed"
2165 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2166 lustre_fail mds 0x608 0
2168 # enable quota to tirgger reintegration
2169 set_ost_qtype "u" || error "enable ost quota failed"
2170 wait_ost_reint "u" || error "reintegration failed"
2174 # hardlimit should have been fetched by slave during global
2175 # reintegration, write will exceed quota
2176 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2177 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2179 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2180 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2183 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2185 # quota reintegration (inode limits)
2187 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2189 # LU-2435: skip this quota test if underlying zfs version has not
2190 # supported native dnode accounting
2191 [ "$mds1_FSTYPE" == zfs ] && {
2192 local F="feature@userobj_accounting"
2193 local pool=$(zpool_name mds1)
2194 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2196 [[ "$feature" != *" active "* ]] &&
2197 skip "requires zpool with active userobj_accounting"
2200 local ilimit=$((1024 * 2)) # inodes
2201 local TESTFILE=$DIR/${tdir}-1/$tfile
2203 setup_quota_test || error "setup quota failed with $?"
2205 # make sure the system is clean
2206 local USED=$(getquota -u $TSTUSR global curinodes)
2207 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2209 # make sure no granted quota on mdt1
2210 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2211 resetquota -u $TSTUSR
2212 set_mdt_qtype "none" || error "disable mdt quota failed"
2214 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2215 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2216 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2219 echo "Stop mds${MDSCOUNT}..."
2222 echo "Enable quota & set quota limit for $TSTUSR"
2223 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2224 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2225 error "set quota failed"
2227 echo "Start mds${MDSCOUNT}..."
2228 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2231 wait_mdt_reint $QTYPE || error "reintegration failed"
2233 echo "create remote dir"
2234 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2235 error "create remote dir failed"
2236 chmod 0777 $DIR/${tdir}-1
2238 # hardlimit should have been fetched by slave during global
2239 # reintegration, create will exceed quota
2240 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2241 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2243 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2244 wait_delete_completed
2245 sync_all_data || true
2247 echo "Stop mds${MDSCOUNT}..."
2250 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2251 error "clear quota failed"
2253 echo "Start mds${MDSCOUNT}..."
2254 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2257 wait_mdt_reint $QTYPE || error "reintegration failed"
2259 # hardlimit should be cleared on slave during reintegration
2260 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2261 quota_error u $TSTUSR "create failed, expect success"
2263 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2264 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2266 run_test 7e "Quota reintegration (inode limits)"
2268 # run dbench with quota enabled
2270 local BLK_LIMIT="100g" #100G
2271 local FILE_LIMIT=1000000
2273 setup_quota_test || error "setup quota failed with $?"
2275 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2276 set_ost_qtype $QTYPE || error "enable ost quota failed"
2278 echo "Set enough high limit for user: $TSTUSR"
2279 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2280 error "set user quota failed"
2281 echo "Set enough high limit for group: $TSTUSR"
2282 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2283 error "set group quota failed"
2284 if is_project_quota_supported; then
2285 change_project -sp $TSTPRJID $DIR/$tdir
2286 echo "Set enough high limit for project: $TSTPRJID"
2287 $LFS setquota -p $TSTPRJID -b 0 \
2288 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2289 error "set project quota failed"
2293 [ "$SLOW" = "no" ] && duration=" -t 120"
2294 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2295 quota_error a $TSTUSR "dbench failed!"
2297 is_project_quota_supported && change_project -C $DIR/$tdir
2300 run_test 8 "Run dbench with quota enabled"
2302 # this check is just for test_9
2303 OST0_MIN=4900000 #4.67G
2305 check_whether_skip () {
2306 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2307 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2308 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2309 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2316 # run for fixing bug10707, it needs a big room. test for 64bit
2318 local filesize=$((1024 * 9 / 2)) # 4.5G
2320 check_whether_skip && return 0
2322 setup_quota_test || error "setup quota failed with $?"
2324 set_ost_qtype "ug" || error "enable ost quota failed"
2326 local TESTFILE="$DIR/$tdir/$tfile-0"
2327 local BLK_LIMIT=100G #100G
2328 local FILE_LIMIT=1000000
2330 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2332 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2334 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2335 error "set user quota failed"
2337 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2338 "for group: $TSTUSR"
2339 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2340 error "set group quota failed"
2342 quota_show_check a u $TSTUSR
2343 quota_show_check a g $TSTUSR
2345 echo "Create test file"
2346 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2347 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2349 log "Write the big file of 4.5G ..."
2350 $RUNAS $DD of=$TESTFILE count=$filesize ||
2351 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2361 run_test 9 "Block limit larger than 4GB (b10707)"
2364 local TESTFILE=$DIR/$tdir/$tfile
2366 setup_quota_test || error "setup quota failed with $?"
2368 # set limit to root user should fail
2369 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2370 error "set limit for root user successfully, expect failure"
2371 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2372 error "set limit for root group successfully, expect failure"
2373 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2374 error "set limit for project 0 successfully, expect failure"
2376 # root user can overrun quota
2377 set_ost_qtype "ug" || error "enable ost quota failed"
2379 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2380 error "set quota failed"
2381 quota_show_check b u $TSTUSR
2383 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2384 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2386 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2387 error "write failure, expect success"
2389 run_test 10 "Test quota for root user"
2392 local TESTFILE=$DIR/$tdir/$tfile
2393 setup_quota_test || error "setup quota failed with $?"
2395 set_mdt_qtype "ug" || error "enable mdt quota failed"
2396 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2397 error "set quota failed"
2399 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2400 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2402 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2403 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2406 local USED=$(getquota -u $TSTUSR global curinodes)
2407 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2409 run_test 11 "Chown/chgrp ignores quota"
2412 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2414 local blimit=22 # MB
2415 local blk_cnt=$((blimit - 5))
2416 local TESTFILE0="$DIR/$tdir/$tfile"-0
2417 local TESTFILE1="$DIR/$tdir/$tfile"-1
2419 setup_quota_test || error "setup quota failed with $?"
2421 set_ost_qtype "u" || error "enable ost quota failed"
2422 quota_show_check b u $TSTUSR
2424 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2425 error "set quota failed"
2427 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2428 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2429 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2430 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2432 echo "Write to ost0..."
2433 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2434 quota_error a $TSTUSR "dd failed"
2436 echo "Write to ost1..."
2437 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2438 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2440 echo "Free space from ost0..."
2442 wait_delete_completed
2443 sync_all_data || true
2445 echo "Write to ost1 after space freed from ost0..."
2446 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2447 quota_error a $TSTUSR "rebalancing failed"
2449 run_test 12a "Block quota rebalancing"
2452 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2454 local ilimit=$((1024 * 2)) # inodes
2455 local TESTFILE0=$DIR/$tdir/$tfile
2456 local TESTFILE1=$DIR/${tdir}-1/$tfile
2458 setup_quota_test || error "setup quota failed with $?"
2460 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2461 chmod 0777 $DIR/${tdir}-1
2463 set_mdt_qtype "u" || error "enable mdt quota failed"
2464 quota_show_check f u $TSTUSR
2466 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2467 error "set quota failed"
2469 echo "Create $ilimit files on mdt0..."
2470 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2471 quota_error u $TSTUSR "create failed, but expect success"
2473 echo "Create files on mdt1..."
2474 $RUNAS createmany -m $TESTFILE1 1 &&
2475 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2477 echo "Free space from mdt0..."
2478 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2479 wait_delete_completed
2480 sync_all_data || true
2482 echo "Create files on mdt1 after space freed from mdt0..."
2483 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2484 quota_error a $TSTUSR "rebalancing failed"
2486 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2487 error "unlink mdt1 files failed"
2488 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2490 run_test 12b "Inode quota rebalancing"
2493 local TESTFILE=$DIR/$tdir/$tfile
2494 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2495 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2497 setup_quota_test || error "setup quota failed with $?"
2499 set_ost_qtype "u" || error "enable ost quota failed"
2500 quota_show_check b u $TSTUSR
2502 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2503 error "set quota failed"
2504 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2505 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2507 # clear the locks in cache first
2508 do_facet ost1 $LCTL set_param -n $procf=clear
2509 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2510 [ $nlock -eq 0 ] || error "$nlock cached locks"
2512 # write to acquire the per-ID lock
2513 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2514 quota_error a $TSTUSR "dd failed"
2516 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2517 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2519 # clear quota doesn't trigger per-ID lock cancellation
2520 resetquota -u $TSTUSR
2521 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2522 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2524 # clear the per-ID lock
2525 do_facet ost1 $LCTL set_param -n $procf=clear
2526 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2527 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2529 # spare quota should be released
2530 local OSTUUID=$(ostuuid_from_index 0)
2531 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2532 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2533 [ $limit -le $space ] ||
2534 error "spare quota isn't released, limit:$limit, space:$space"
2536 run_test 13 "Cancel per-ID lock in the LRU list"
2539 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2541 wait_delete_completed
2542 sync_all_data || true
2545 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2546 error "set user quota failed"
2547 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2548 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2549 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2550 resetquota -u $TSTUSR
2553 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2554 error "set group quota failed"
2555 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2556 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2557 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2558 resetquota -g $TSTUSR
2560 run_test 15 "Set over 4T block quota"
2564 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2565 skip "Not supported Lustre client before 2.14.55"
2567 setup_quota_test || error "setup quota failed with $?"
2569 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2570 error "failed to set quota for user $TSTUSR"
2571 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2572 error "failed to set quota for group $TSTUSR"
2574 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=50 ||
2575 quota_error u $TSTUSR "write failure"
2577 $LFS quota -u $TSTUSR $MOUNT ||
2578 quota_error u $TSTUSR "failed to get quota"
2580 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2582 $LCTL --device %$OSC deactivate
2583 stack_trap "$LCTL --device %$OSC activate"
2585 $LFS quota -v -u $TSTUSR $MOUNT ||
2586 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2587 $LFS quota -v -g $TSTUSR $MOUNT ||
2588 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2590 (( $MDSCOUNT > 1 )) || return 0
2592 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2594 $LCTL --device %$MDC deactivate
2595 stack_trap "$LCTL --device %$MDC activate"
2597 $LFS quota -v -u $TSTUSR $MOUNT ||
2598 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2599 $LFS quota -v -g $TSTUSR $MOUNT ||
2600 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2602 run_test 16a "lfs quota should skip the inactive MDT/OST"
2613 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2614 skip "Not supported Lustre client before 2.14.55"
2616 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2619 if ! combined_mgs_mds ; then
2624 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2625 $(mdsdevname 1) $(mdsvdevname 1)
2626 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2627 $(mdsdevname 2) $(mdsvdevname 2)
2628 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2629 $(mdsdevname 3) $(mdsvdevname 3)
2631 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2632 $(ostdevname 1) $(ostvdevname 1)
2633 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2634 $(ostdevname 2) $(ostvdevname 2)
2636 stack_trap cleanup_16b
2638 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2639 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2640 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2641 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2642 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2644 mount_client $MOUNT || error "Unable to mount client"
2646 setup_quota_test || error "setup quota failed with $?"
2647 stack_trap cleanup_quota_test EXIT
2649 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2650 error "failed to set quota for user $TSTUSR"
2651 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2652 error "failed to set quota for group $TSTUSR"
2654 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=10 ||
2655 quota_error u $TSTUSR "write failure"
2657 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2658 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2659 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2660 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2662 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2666 local BLKS=1 # 1M less than limit
2667 local TESTFILE=$DIR/$tdir/$tfile
2669 setup_quota_test || error "setup quota failed with $?"
2671 # make sure the system is clean
2672 local USED=$(getquota -u $TSTUSR global curspace)
2673 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2675 set_ost_qtype "ug" || error "enable ost quota failed"
2676 # make sure no granted quota on ost
2677 resetquota -u $TSTUSR
2678 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2679 error "set quota failed"
2681 quota_show_check b u $TSTUSR
2683 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2684 lustre_fail mds 0xa04 $err_code
2686 # write in background
2687 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2691 # write should be blocked and never finished
2692 if ! ps -p $DDPID > /dev/null 2>&1; then
2694 quota_error u $TSTUSR "write finished incorrectly!"
2702 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2704 if [ $count -gt $timeout ]; then
2705 quota_error u $TSTUSR "dd is not finished!"
2710 sync; sync_all_data || true
2712 USED=$(getquota -u $TSTUSR global curspace)
2713 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2714 "Used space(${USED}K) is less than ${BLKS}M"
2719 # DQACQ return recoverable error
2721 echo "DQACQ return -ENOLCK"
2723 test_17sub 37 || error "Handle -ENOLCK failed"
2725 echo "DQACQ return -EAGAIN"
2727 test_17sub 11 || error "Handle -EAGAIN failed"
2729 echo "DQACQ return -ETIMEDOUT"
2730 #define ETIMEDOUT 110
2731 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2733 echo "DQACQ return -ENOTCONN"
2734 #define ENOTCONN 107
2735 test_17sub 107 || error "Handle -ENOTCONN failed"
2738 run_test 17 "DQACQ return recoverable error"
2742 local blimit=200 # MB
2743 local TESTFILE="$DIR/$tdir/$tfile"
2745 setup_quota_test || error "setup quota failed with $?"
2747 set_ost_qtype "u" || error "enable ost quota failed"
2748 log "User quota (limit: $blimit)"
2749 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2750 error "set quota failed"
2751 quota_show_check b u $TSTUSR
2753 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2754 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2756 local timeout=$(sysctl -n lustre.timeout)
2758 if [ $io_type = "directio" ]; then
2759 log "Write 100M (directio) ..."
2760 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2762 log "Write 100M (buffered) ..."
2763 $RUNAS $DD of=$TESTFILE count=100 &
2767 replay_barrier $SINGLEMDS
2768 log "Fail mds for $((2 * timeout)) seconds"
2769 fail $SINGLEMDS $((2 * timeout))
2772 if at_is_enabled; then
2773 timeout=$(at_max_get mds)
2775 timeout=$(lctl get_param -n timeout)
2779 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2780 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2781 log "it took $count second"
2786 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2788 cancel_lru_locks mdc
2789 cancel_lru_locks osc
2792 local testfile_size=$(stat -c %s $TESTFILE)
2793 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2794 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2795 "got ${testfile_size}. Verifying file failed!"
2800 # test when mds does failover, the ost still could work well
2801 # this test shouldn't trigger watchdog b=14840
2803 # Clear dmesg so watchdog is not triggered by previous
2805 do_facet ost1 dmesg -c > /dev/null
2808 test_18_sub directio
2810 # check if watchdog is triggered
2811 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2812 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2813 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2814 [ -z "$watchdog" ] || error "$watchdog"
2815 rm -f $TMP/lustre-log-${TESTNAME}.log
2817 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2821 local TESTFILE=$DIR/$tdir/$tfile
2823 setup_quota_test || error "setup quota failed with $?"
2825 set_ost_qtype $QTYPE || error "enable ost quota failed"
2827 # bind file to a single OST
2828 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2829 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2831 echo "Set user quota (limit: ${blimit}M)"
2832 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2833 error "set user quota failed"
2834 quota_show_check b u $TSTUSR
2835 echo "Update quota limits"
2836 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2837 error "set group quota failed"
2838 quota_show_check b u $TSTUSR
2840 # first wirte might be cached
2841 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2842 cancel_lru_locks osc
2844 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2845 quota_error u $TSTUSR "Write success, expect failure"
2848 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2850 test_20() { # b15754
2851 local LSTR=(2g 1t 4k 3m) # limits strings
2853 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2856 resetquota -u $TSTUSR
2858 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2859 $MOUNT || error "could not set quota limits"
2860 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2861 --inode-softlimit ${LSTR[2]} \
2862 --inode-hardlimit ${LSTR[3]} \
2863 $MOUNT || error "could not set quota limits"
2865 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2866 error "bsoftlimit was not set properly"
2867 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2868 error "bhardlimit was not set properly"
2869 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2870 error "isoftlimit was not set properly"
2871 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2872 error "ihardlimit was not set properly"
2874 resetquota -u $TSTUSR
2876 run_test 20 "Test if setquota specifiers work properly (b15754)"
2883 local time=$(($(date +%s) + seconds))
2884 while [ $(date +%s) -lt $time ]; do
2885 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2889 # run for fixing bug16053, setquota shouldn't fail when writing and
2890 # deleting are happening
2892 local TESTFILE="$DIR/$tdir/$tfile"
2893 local BLIMIT=10 # 10G
2894 local ILIMIT=1000000
2896 setup_quota_test || error "setup quota failed with $?"
2898 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2900 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2901 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2902 error "set user quota failed"
2903 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2904 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2905 error "set group quota failed"
2906 if is_project_quota_supported; then
2907 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2908 "project: $TSTPRJID"
2909 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2910 $MOUNT || error "set project quota failed"
2913 # repeat writing on a 1M file
2914 test_21_sub ${TESTFILE}_1 1 30 &
2916 # repeat writing on a 128M file
2917 test_21_sub ${TESTFILE}_2 128 30 &
2920 local time=$(($(date +%s) + 30))
2922 while [ $(date +%s) -lt $time ]; do
2923 log "Set quota for $i times"
2924 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2925 -I $((ILIMIT + i)) $MOUNT ||
2926 error "Set user quota failed"
2927 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2928 -I $((ILIMIT + i)) $MOUNT ||
2929 error "Set group quota failed"
2930 if is_project_quota_supported; then
2931 $LFS setquota -p $TSTPRJID -b 0 -B \
2932 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2933 error "Set project quota failed"
2941 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2943 if [ $count -gt 60 ]; then
2944 quota_error a $TSTUSR "dd should be finished!"
2948 echo "(dd_pid=$DDPID1, time=$count)successful"
2952 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2954 if [ $count -gt 60 ]; then
2955 quota_error a $TSTUSR "dd should be finished!"
2959 echo "(dd_pid=$DDPID2, time=$count)successful"
2961 run_test 21 "Setquota while writing & deleting (b16053)"
2963 # enable/disable quota enforcement permanently
2965 echo "Set both mdt & ost quota type as ug"
2967 is_project_quota_supported && qtype=$QTYPE
2968 set_mdt_qtype $qtype || error "enable mdt quota failed"
2969 set_ost_qtype $qtype || error "enable ost quota failed"
2972 stopall || error "failed to stopall (1)"
2976 echo "Verify if quota is enabled"
2977 local qtype1=$(mdt_quota_type)
2978 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2979 qtype=$(ost_quota_type)
2980 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2982 echo "Set both mdt & ost quota type as none"
2983 set_mdt_qtype "none" || error "disable mdt quota failed"
2984 set_ost_qtype "none" || error "disable ost quota failed"
2987 stopall || error "failed to stopall (2)"
2992 echo "Verify if quota is disabled"
2993 qtype=$(mdt_quota_type)
2994 [ $qtype != "none" ] && error "mdt quota setting is lost"
2995 qtype=$(ost_quota_type)
2996 [ $qtype != "none" ] && error "ost quota setting is lost"
3000 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3003 local TESTFILE="$DIR/$tdir/$tfile"
3006 setup_quota_test || error "setup quota failed with $?"
3008 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3011 log "User quota (limit: $LIMIT MB)"
3012 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3013 error "set quota failed"
3014 quota_show_check b u $TSTUSR
3016 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3017 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3019 log "Step1: trigger EDQUOT with O_DIRECT"
3020 log "Write half of file"
3021 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3022 quota_error u $TSTUSR "(1) Write failure, expect success." \
3024 log "Write out of block quota ..."
3025 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3026 oflag=direct conv=notrunc &&
3027 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3031 log "Step2: rewrite should succeed"
3032 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3033 quota_error u $TSTUSR "(3) Write failure, expect success." \
3039 local OST0_UUID=$(ostuuid_from_index 0)
3040 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3041 [ $OST0_QUOTA_USED -ne 0 ] &&
3042 ($SHOW_QUOTA_USER; \
3043 quota_error u $TSTUSR "quota isn't released")
3048 [ "$ost1_FSTYPE" == zfs ] &&
3049 skip "Overwrite in place is not guaranteed to be " \
3050 "space neutral on ZFS"
3052 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3053 check_whether_skip && return 0
3054 log "run for 4MB test file"
3057 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3058 check_whether_skip && return 0
3059 log "run for 40MB test file"
3062 run_test 23 "Quota should be honored with directIO (b16125)"
3066 local TESTFILE="$DIR/$tdir/$tfile"
3068 setup_quota_test || error "setup quota failed with $?"
3070 set_ost_qtype $QTYPE || error "enable ost quota failed"
3072 # bind file to a single OST
3073 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3074 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3076 echo "Set user quota (limit: ${blimit}M)"
3077 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3078 error "set quota failed"
3080 # overrun quota by root user
3081 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3082 error "write failure, expect success"
3083 cancel_lru_locks osc
3084 sync_all_data || true
3086 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3088 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3090 test_27a() { # b19612
3091 $LFS quota $TSTUSR $DIR &&
3092 error "lfs succeeded with no type, but should have failed"
3093 $LFS setquota $TSTUSR $DIR &&
3094 error "lfs succeeded with no type, but should have failed"
3097 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3099 test_27b() { # b20200
3100 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3101 error "lfs setquota failed with uid argument"
3102 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3103 error "lfs stequota failed with gid argument"
3104 if is_project_quota_supported; then
3105 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3106 1000 $DIR || error \
3107 "lfs stequota failed with projid argument"
3109 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3110 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3111 if is_project_quota_supported; then
3112 $SHOW_QUOTA_PROJID ||
3113 error "lfs quota failed with projid argument"
3115 resetquota -u $TSTID
3116 resetquota -g $TSTID
3117 resetquota -p $TSTPRJID
3120 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3125 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3126 error "lfs setquota failed"
3128 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3129 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3130 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3131 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3133 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3134 error "lfs setquota for $TSTID failed"
3136 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3137 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3138 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3139 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3141 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3142 error "total allocated inode/block limit not printed"
3144 resetquota -u $TSTUSR
3146 run_test 27c "lfs quota should support human-readable output"
3153 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3154 error "set fraction block limit failed"
3155 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3156 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3157 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3158 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3160 resetquota -u $TSTUSR
3162 run_test 27d "lfs setquota should support fraction block limit"
3166 local TESTFILE="$DIR/$tdir/$tfile"
3169 setup_quota_test || error "setup quota failed with $?"
3171 set_ost_qtype "u" || error "enable ost quota failed"
3173 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3174 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3176 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3177 $MAX_IQ_TIME $DIR || error "set grace time failed"
3178 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3179 error "set quota failed"
3180 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3181 cancel_lru_locks osc
3183 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3184 # over-quota flag has not yet settled since we do not trigger async
3185 # events based on grace time period expiration
3187 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3188 cancel_lru_locks osc
3189 # now over-quota flag should be settled and further writes should fail
3191 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3192 error "grace times were reset"
3193 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3194 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3196 run_test 30 "Hard limit updates should not reset grace times"
3198 # basic usage tracking for user & group
3200 local INODES=10 # files
3201 local BLK_CNT=2 # MB each
3202 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3204 setup_quota_test || error "setup quota failed with $?"
3206 # make sure the system is clean
3207 local USED=$(getquota -u $TSTID global curspace)
3209 error "Used space ($USED) for user $TSTID isn't 0."
3210 USED=$(getquota -g $TSTID global curspace)
3212 error "Used space ($USED) for group $TSTID isn't 0."
3213 if is_project_quota_supported; then
3214 USED=$(getquota -p $TSTPRJID global curspace)
3215 [ $USED -ne 0 ] && error \
3216 "Used space ($USED) for project $TSTPRJID isn't 0."
3219 echo "Write files..."
3220 for i in $(seq 0 $INODES); do
3221 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3222 error "write failed"
3223 is_project_quota_supported &&
3224 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3225 echo "Iteration $i/$INODES completed"
3227 cancel_lru_locks osc
3229 echo "Wait for setattr on objects finished..."
3230 wait_delete_completed
3232 sync; sync_all_data || true
3234 echo "Verify disk usage after write"
3235 USED=$(getquota -u $TSTID global curspace)
3236 [ $USED -lt $TOTAL_BLKS ] &&
3237 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3238 USED=$(getquota -g $TSTID global curspace)
3239 [ $USED -lt $TOTAL_BLKS ] &&
3240 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3241 if is_project_quota_supported; then
3242 USED=$(getquota -p $TSTPRJID global curspace)
3243 [ $USED -lt $TOTAL_BLKS ] && error \
3244 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3247 echo "Verify inode usage after write"
3248 USED=$(getquota -u $TSTID global curinodes)
3249 [ $USED -lt $INODES ] &&
3250 error "Used inode for user $TSTID is $USED, expected $INODES"
3251 USED=$(getquota -g $TSTID global curinodes)
3252 [ $USED -lt $INODES ] &&
3253 error "Used inode for group $TSTID is $USED, expected $INODES"
3254 if is_project_quota_supported; then
3255 USED=$(getquota -p $TSTPRJID global curinodes)
3256 [ $USED -lt $INODES ] && error \
3257 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3262 echo "Verify disk usage after delete"
3263 USED=$(getquota -u $TSTID global curspace)
3264 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3265 USED=$(getquota -u $TSTID global curinodes)
3266 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3267 USED=$(getquota -g $TSTID global curspace)
3268 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3269 USED=$(getquota -g $TSTID global curinodes)
3270 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3271 if is_project_quota_supported; then
3272 USED=$(getquota -p $TSTPRJID global curspace)
3274 error "Used space for project $TSTPRJID isn't 0. $USED"
3275 USED=$(getquota -p $TSTPRJID global curinodes)
3277 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3280 run_test 33 "Basic usage tracking for user & group & project"
3282 # usage transfer test for user & group & project
3284 local BLK_CNT=2 # MB
3285 local project_supported="no"
3287 is_project_quota_supported && project_supported="yes"
3288 setup_quota_test || error "setup quota failed with $?"
3290 # make sure the system is clean
3291 local USED=$(getquota -u $TSTID global curspace)
3292 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3293 USED=$(getquota -g $TSTID global curspace)
3294 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3296 local USED=$(getquota -u $TSTID2 global curspace)
3297 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3298 if [ $project_supported == "yes" ]; then
3299 USED=$(getquota -p $TSTPRJID global curspace)
3300 [ $USED -ne 0 ] && error \
3301 "Used space ($USED) for Project $TSTPRJID isn't 0."
3304 echo "Write file..."
3305 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3306 error "write failed"
3307 cancel_lru_locks osc
3308 sync; sync_all_data || true
3310 echo "chown the file to user $TSTID"
3311 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3313 echo "Wait for setattr on objects finished..."
3314 wait_delete_completed
3316 BLK_CNT=$((BLK_CNT * 1024))
3318 echo "Verify disk usage for user $TSTID"
3319 USED=$(getquota -u $TSTID global curspace)
3320 [ $USED -lt $BLK_CNT ] &&
3321 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3322 USED=$(getquota -u $TSTID global curinodes)
3324 error "Used inodes for user $TSTID is $USED, expected 1"
3326 echo "chgrp the file to group $TSTID"
3327 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3329 echo "Wait for setattr on objects finished..."
3330 wait_delete_completed
3332 echo "Verify disk usage for group $TSTID"
3333 USED=$(getquota -g $TSTID global curspace)
3334 [ $USED -ge $BLK_CNT ] ||
3335 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3336 USED=$(getquota -g $TSTID global curinodes)
3338 error "Used inodes for group $TSTID is $USED, expected 1"
3340 # chown won't change the ost object group. LU-4345 */
3341 echo "chown the file to user $TSTID2"
3342 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3344 echo "Wait for setattr on objects finished..."
3345 wait_delete_completed
3347 echo "change_project project id to $TSTPRJID"
3348 [ $project_supported == "yes" ] &&
3349 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3350 echo "Wait for setattr on objects finished..."
3351 wait_delete_completed
3353 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3354 USED=$(getquota -u $TSTID2 global curspace)
3355 [ $USED -lt $BLK_CNT ] &&
3356 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3357 USED=$(getquota -u $TSTID global curspace)
3359 error "Used space for user $TSTID is $USED, expected 0"
3360 USED=$(getquota -g $TSTID global curspace)
3361 [ $USED -lt $BLK_CNT ] &&
3362 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3363 if [ $project_supported == "yes" ]; then
3364 USED=$(getquota -p $TSTPRJID global curspace)
3365 [ $USED -lt $BLK_CNT ] && error \
3366 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3370 run_test 34 "Usage transfer for user & group & project"
3372 # usage is still accessible across restart
3374 local BLK_CNT=2 # MB
3376 setup_quota_test || error "setup quota failed with $?"
3378 echo "Write file..."
3379 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3380 error "write failed"
3381 is_project_quota_supported &&
3382 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3383 cancel_lru_locks osc
3385 echo "Wait for setattr on objects finished..."
3386 wait_delete_completed
3388 sync; sync_all_data || true
3390 echo "Save disk usage before restart"
3391 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3392 [ $ORIG_USR_SPACE -eq 0 ] &&
3393 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3394 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3395 [ $ORIG_USR_INODES -eq 0 ] &&
3396 error "Used inodes for user $TSTID is 0, expected 1"
3397 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3398 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3399 [ $ORIG_GRP_SPACE -eq 0 ] &&
3400 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3401 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3402 [ $ORIG_GRP_INODES -eq 0 ] &&
3403 error "Used inodes for group $TSTID is 0, expected 1"
3404 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3406 if is_project_quota_supported; then
3407 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3408 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3409 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3410 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3411 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3412 "Used inodes for project $TSTPRJID is 0, expected 1"
3413 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3421 echo "Verify disk usage after restart"
3422 local USED=$(getquota -u $TSTID global curspace)
3423 [ $USED -eq $ORIG_USR_SPACE ] ||
3424 error "Used space for user $TSTID changed from " \
3425 "$ORIG_USR_SPACE to $USED"
3426 USED=$(getquota -u $TSTID global curinodes)
3427 [ $USED -eq $ORIG_USR_INODES ] ||
3428 error "Used inodes for user $TSTID changed from " \
3429 "$ORIG_USR_INODES to $USED"
3430 USED=$(getquota -g $TSTID global curspace)
3431 [ $USED -eq $ORIG_GRP_SPACE ] ||
3432 error "Used space for group $TSTID changed from " \
3433 "$ORIG_GRP_SPACE to $USED"
3434 USED=$(getquota -g $TSTID global curinodes)
3435 [ $USED -eq $ORIG_GRP_INODES ] ||
3436 error "Used inodes for group $TSTID changed from " \
3437 "$ORIG_GRP_INODES to $USED"
3438 if [ $project_supported == "yes" ]; then
3439 USED=$(getquota -p $TSTPRJID global curinodes)
3440 [ $USED -eq $ORIG_PRJ_INODES ] ||
3441 error "Used inodes for project $TSTPRJID " \
3442 "changed from $ORIG_PRJ_INODES to $USED"
3443 USED=$(getquota -p $TSTPRJID global curspace)
3444 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3445 error "Used space for project $TSTPRJID "\
3446 "changed from $ORIG_PRJ_SPACE to $USED"
3449 # check if the vfs_dq_init() is called before writing
3450 echo "Append to the same file..."
3451 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3452 error "write failed"
3453 cancel_lru_locks osc
3454 sync; sync_all_data || true
3456 echo "Verify space usage is increased"
3457 USED=$(getquota -u $TSTID global curspace)
3458 [ $USED -gt $ORIG_USR_SPACE ] ||
3459 error "Used space for user $TSTID isn't increased" \
3460 "orig:$ORIG_USR_SPACE, now:$USED"
3461 USED=$(getquota -g $TSTID global curspace)
3462 [ $USED -gt $ORIG_GRP_SPACE ] ||
3463 error "Used space for group $TSTID isn't increased" \
3464 "orig:$ORIG_GRP_SPACE, now:$USED"
3465 if [ $project_supported == "yes" ]; then
3466 USED=$(getquota -p $TSTPRJID global curspace)
3467 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3468 error "Used space for project $TSTPRJID isn't " \
3469 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3472 run_test 35 "Usage is still accessible across reboot"
3474 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3477 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3478 skip "Old server doesn't have LU-5006 fix."
3480 setup_quota_test || error "setup quota failed with $?"
3482 # make sure the system is clean
3483 local USED=$(getquota -u $TSTID global curspace)
3485 error "Used space ($USED) for user $TSTID isn't 0."
3487 # create file with MDS_OPEN_DELAY_CREATE flag
3488 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3489 error "Create file failed"
3491 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3492 oflag=sync || error "Write file failed"
3494 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3496 # wait for setattr on objects finished..."
3497 wait_delete_completed
3499 USED=$(getquota -u $TSTID global curspace)
3500 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3502 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3506 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3507 skip "Old server doesn't have LU-8801 fix."
3509 [ "$UID" != 0 ] && skip_env "must run as root" && return
3511 setup_quota_test || error "setup quota failed with $?"
3513 # make sure the system is clean
3514 local USED=$(getquota -u $TSTID global curspace)
3516 error "Used space ($USED) for user $TSTID isn't 0."
3517 USED=$(getquota -u $TSTID2 global curspace)
3519 error "Used space ($USED) for user $TSTID2 isn't 0."
3521 local TESTFILE="$DIR/$tdir/$tfile"
3522 local file_cnt=10000
3524 # Generate id entries in accounting file
3525 echo "Create $file_cnt files..."
3526 for i in `seq $file_cnt`; do
3528 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3529 error "failed to chown $TESTFILE-$i"
3531 cancel_lru_locks osc
3532 sync; sync_all_data || true
3534 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3535 procf=${procf}.quota_slave.acct_user
3538 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3539 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3540 echo "Found $acct_cnt id entries"
3542 [ $file_cnt -eq $acct_cnt ] || {
3543 do_facet mds1 $LCTL get_param $procf
3544 error "skipped id entries"
3547 run_test 38 "Quota accounting iterator doesn't skip id entries"
3550 local TESTFILE="$DIR/$tdir/project"
3551 ! is_project_quota_supported &&
3552 skip "Project quota is not supported"
3554 setup_quota_test || error "setup quota failed with $?"
3557 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3558 [ $projectid -ne 0 ] &&
3559 error "Project id should be 0 not $projectid"
3560 change_project -p 1024 $TESTFILE
3561 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3562 [ $projectid -ne 1024 ] &&
3563 error "Project id should be 1024 not $projectid"
3565 stopall || error "failed to stopall (1)"
3568 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3569 [ $projectid -eq 1024 ] ||
3570 error "Project id should be 1024 not $projectid"
3572 run_test 39 "Project ID interface works correctly"
3575 ! is_project_quota_supported &&
3576 skip "Project quota is not supported"
3577 local dir1="$DIR/$tdir/dir1"
3578 local dir2="$DIR/$tdir/dir2"
3580 setup_quota_test || error "setup quota failed with $?"
3582 mkdir -p $dir1 $dir2
3583 change_project -sp 1 $dir1 && touch $dir1/1
3584 change_project -sp 2 $dir2
3586 ln $dir1/1 $dir2/1_link &&
3587 error "Hard link across different project quota should fail"
3590 run_test 40a "Hard link across different project ID"
3593 ! is_project_quota_supported &&
3594 skip "Project quota is not supported"
3595 local dir1="$DIR/$tdir/dir1"
3596 local dir2="$DIR/$tdir/dir2"
3598 setup_quota_test || error "setup quota failed with $?"
3599 mkdir -p $dir1 $dir2
3600 change_project -sp 1 $dir1 && touch $dir1/1
3601 change_project -sp 2 $dir2
3603 mv $dir1/1 $dir2/2 || error "mv failed $?"
3604 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3605 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3607 run_test 40b "Mv across different project ID"
3610 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3611 ! is_project_quota_supported &&
3612 skip "Project quota is not supported"
3614 setup_quota_test || error "setup quota failed with $?"
3615 local dir="$DIR/$tdir/dir"
3617 mkdir -p $dir && change_project -sp 1 $dir
3618 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3619 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3620 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3621 touch $dir/remote_dir/file
3622 #verify inherit works file for remote dir.
3623 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3624 [ "$projid" != "1" ] &&
3625 error "file under remote dir expected 1 not $projid"
3627 #Agent inode should be ignored for project quota
3628 local used=$(getquota -p 1 global curinodes)
3630 error "file count expected 3 got $used"
3632 run_test 40c "Remote child Dir inherit project quota properly"
3635 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3636 is_project_quota_supported || skip "Project quota is not supported"
3638 setup_quota_test || error "setup quota failed with $?"
3639 local dir="$DIR/$tdir/dir"
3642 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3643 change_project -sp $TSTPRJID $dir ||
3644 error "change project on $dir failed"
3645 for i in $(seq 5); do
3646 mkdir -p $dir/d$i/d$i ||
3647 error "mkdir $dir/d$i/d$i failed"
3648 local projid=$($LFS project -d $dir/d$i/d$i |
3650 [ "$projid" == "$TSTPRJID" ] ||
3651 error "projid id expected $TSTPRJID not $projid"
3652 touch $dir/d$i/d$i/file
3653 #verify inherit works file for stripe dir.
3654 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3655 [ "$projid" == "$TSTPRJID" ] ||
3656 error "file under remote dir expected 1 not $projid"
3659 # account should be 1 + (2 + 1) *10 + 1 * 5
3660 local used=$(getquota -p $TSTPRJID global curinodes)
3662 error "file count expected 36 got $used"
3664 run_test 40d "Stripe Directory inherit project quota properly"
3667 is_project_quota_supported ||
3668 skip "Project quota is not supported"
3669 setup_quota_test || error "setup quota failed with $?"
3670 local dir="$DIR/$tdir/dir"
3673 local projid=$((testnum * 1000))
3677 # enable mdt/ost quota
3678 set_mdt_qtype ugp || error "enable mdt quota failed"
3679 set_ost_qtype ugp || error "enable ost quota failed"
3681 test_mkdir -p $dir && change_project -sp $projid $dir
3682 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3683 error "set project quota failed"
3688 # check if df output works as expected
3689 echo "== global statfs: $MOUNT =="
3690 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3692 echo "== project statfs (prjid=$projid): $dir =="
3693 df -kP $dir; df -iP $dir
3694 local bused=$(getquota -p $projid global curspace)
3695 local iused=$(getquota -p $projid global curinodes)
3696 # note trailing space to match double printf from awk
3697 local expected="$blimit $bused $ilimit $iused "
3699 wait_update $HOSTNAME \
3700 "{ df -kP $dir; df -iP $dir; } |
3701 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3703 error "failed to get correct statfs for project quota"
3705 run_test 41 "df should return projid-specific values"
3713 local osd="osd-ldiskfs"
3715 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3717 rm -f $DIR/$tdir/$tfile
3718 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3719 chmod a+rw $DIR/$tdir/$tfile
3721 $LFS setquota $qtype $qid -B 300M $MOUNT
3722 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3723 error "failed to dd"
3725 do_facet $SINGLEMDS \
3726 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3727 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3730 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3731 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3733 $LFS setquota $qtype $qid --delete $MOUNT
3734 do_facet $SINGLEMDS \
3735 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3736 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3739 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3740 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3742 $LFS setquota $qtype $qid -B 500M $MOUNT
3743 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3744 error "failed to dd"
3745 do_facet $SINGLEMDS \
3746 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3747 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3748 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3750 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3751 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3756 setup_quota_test || error "setup quota failed with $?"
3757 set_ost_qtype $QTYPE || error "enable ost quota failed"
3760 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3761 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3762 is_project_quota_supported &&
3763 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3767 run_test 48 "lfs quota --delete should delete quota project ID"
3770 ! is_project_quota_supported &&
3771 skip "Project quota is not supported"
3773 setup_quota_test || error "setup quota failed with $?"
3774 local dir1="$DIR/$tdir/dir1"
3775 local dir2="$DIR/$tdir/dir2"
3777 mkdir -p $dir1 && change_project -sp 1 $dir1
3778 mkdir -p $dir2 && change_project -sp 2 $dir2
3779 for num in $(seq 1 10); do
3780 touch $dir1/file_$num $dir2/file_$num
3781 ln -s $dir1/file_$num $dir1/file_$num"_link"
3782 ln -s $dir2/file_$num $dir2/file_$num"_link"
3785 count=$($LFS find --projid 1 $DIR | wc -l)
3786 [ "$count" != 21 ] && error "expected 21 but got $count"
3788 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3789 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3790 [ $count -eq 22 ] || error "expected 22 but got $count"
3792 run_test 50 "Test if lfs find --projid works"
3795 ! is_project_quota_supported &&
3796 skip "Project quota is not supported"
3797 setup_quota_test || error "setup quota failed with $?"
3798 local dir="$DIR/$tdir/dir"
3800 mkdir $dir && change_project -sp 1 $dir
3801 local used=$(getquota -p 1 global curinodes)
3802 [ $used != "1" ] && error "expected 1 got $used"
3807 used=$(getquota -p 1 global curinodes)
3808 [ $used != "4" ] && error "expected 4 got $used"
3810 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3812 cp $DIR/$tdir/6 $dir/6
3813 used=$(getquota -p 1 global curinodes)
3814 [ $used != "5" ] && error "expected 5 got $used"
3817 mv $DIR/$tdir/6 $dir/7
3818 used=$(getquota -p 1 global curinodes)
3819 [ $used -eq 6 ] || error "expected 6 got $used"
3821 run_test 51 "Test project accounting with mv/cp"
3824 ! is_project_quota_supported &&
3825 skip "Project quota is not supported"
3827 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
3828 skip "Need MDS version at least 2.14.55"
3830 setup_quota_test || error "setup quota failed with $?"
3832 local dir1=$DIR/$tdir/t52_dir1
3833 local dir2=$DIR/$tdir/t52_dir2
3835 mkdir $dir1 || error "failed to mkdir $dir1"
3836 mkdir $dir2 || error "failed to mkdir $dir2"
3838 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
3839 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
3841 $DD if=/dev/zero of=/$dir1/$tfile bs=1M count=100 ||
3842 error "failed to create and write $tdir1/$tfile"
3844 cancel_lru_locks osc
3845 sync; sync_all_data || true
3847 local attrs=($(lsattr -p $dir1/$tfile))
3848 (( ${attrs[0]} == 1000 )) ||
3849 error "project ID on $dir1/$tfile is not inherited"
3851 $LFS quota -p 1000 $DIR
3852 $LFS quota -p 1001 $DIR
3854 local prev_used=$(getquota -p 1000 global curspace)
3855 local prev_used2=$(getquota -p 1001 global curspace)
3857 mrename $dir1 $dir2/tdir || log "rename directory return $?"
3859 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
3860 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
3861 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
3863 attrs=($(lsattr -p $dir2/$tfile))
3864 (( ${attrs[0]} == 1001 )) ||
3865 error "project ID is not updated after rename"
3867 (( $inum_before == $inum_after )) ||
3868 error "inode is changed after rename: $inum_before, $inum_after"
3870 sync_all_data || true
3872 $LFS quota -p 1000 $DIR
3873 $LFS quota -p 1001 $DIR
3875 local new_used=$(getquota -p 1000 global curspace)
3876 local new_used2=$(getquota -p 1001 global curspace)
3878 (( $prev_used >= $new_used + 102400 )) ||
3879 error "quota is not deducted from old project ID"
3880 (( $prev_used2 <= $new_used2 - 102400 )) ||
3881 error "quota is not added for the new project ID"
3883 run_test 52 "Rename normal file across project ID"
3886 ! is_project_quota_supported &&
3887 skip "Project quota is not supported"
3888 setup_quota_test || error "setup quota failed with $?"
3889 local dir="$DIR/$tdir/dir"
3890 mkdir $dir && change_project -s $dir
3891 [[ $($LFS project -d $dir) =~ " P " ]] ||
3892 error "inherit attribute should be set"
3894 change_project -C $dir
3895 [[ $($LFS project -d $dir) =~ " - " ]] ||
3896 error "inherit attribute should be cleared"
3898 run_test 53 "Project inherit attribute could be cleared"
3901 ! is_project_quota_supported &&
3902 skip "Project quota is not supported"
3903 setup_quota_test || error "setup quota failed with $?"
3904 local testfile="$DIR/$tdir/$tfile-0"
3906 #set project ID/inherit attribute
3907 change_project -sp $TSTPRJID $DIR/$tdir
3908 $RUNAS createmany -m ${testfile} 100 ||
3909 error "create many files failed"
3911 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3912 # one more count for directory itself */
3916 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3917 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3919 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3920 [ $proj_count1 -eq $proj_count ] ||
3921 error "c2: expected $proj_count got $proj_count1"
3923 #clear project but with kept projid
3924 change_project -rCk $DIR/$tdir
3925 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3926 [ $proj_count1 -eq 1 ] ||
3927 error "c3: expected 1 got $proj_count1"
3929 #verify projid untouched.
3930 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3932 [ $proj_count1 -eq $proj_count ] ||
3933 error "c4: expected $proj_count got $proj_count1"
3936 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3937 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3938 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3940 #this time clear all
3941 change_project -rC $DIR/$tdir
3942 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3943 [ $proj_count1 -eq 0 ] ||
3944 error "c6: expected 0 got $proj_count1"
3946 unlinkmany ${testfile} 100 ||
3947 error "unlink many files failed"
3949 run_test 54 "basic lfs project interface test"
3952 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3953 skip "Not supported before 2.10.58."
3954 setup_quota_test || error "setup quota failed with $?"
3956 set_ost_qtype $QTYPE || error "enable ost quota failed"
3959 #add second group to TSTUSR
3960 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3963 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3964 error "failed to dd"
3966 cancel_lru_locks osc
3967 sync; sync_all_data || true
3969 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3970 error "failed to setquota on group $TSTUSR2"
3972 $LFS quota -v -g $TSTUSR2 $DIR
3974 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3975 error "chgrp should failed with -EDQUOT"
3977 USED=$(getquota -g $TSTUSR2 global curspace)
3980 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3981 error "failed to setquota on group $TSTUSR2"
3983 $LFS quota -v -g $TSTUSR2 $DIR
3985 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3986 error "chgrp should succeed"
3988 $LFS quota -v -g $TSTUSR2 $DIR
3990 run_test 55 "Chgrp should be affected by group quota"
3993 setup_quota_test || error "setup quota failed with $?"
3995 set_ost_qtype $QTYPE || error "enable ost quota failed"
3998 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3999 erro "failed to set grace time for usr quota"
4000 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4001 awk '{print $4 $8}')
4002 if [ "x$grace_time" != "x10s;10s" ]; then
4003 $LFS quota -t -u $DIR
4004 error "expected grace time: 10s;10s, got:$grace_time"
4007 run_test 56 "lfs quota -t should work well"
4010 setup_quota_test || error "setup quota failed with $?"
4012 local dir="$DIR/$tdir/dir"
4015 #command can process further if it hit some errors
4016 $LFS project -sp 1 $dir/pipe
4017 touch $dir/aaa $dir/bbb
4018 mkdir $dir/subdir -p
4019 touch $dir/subdir/aaa $dir/subdir/bbb
4020 #create one invalid link file
4021 ln -s $dir/not_exist_file $dir/ccc
4022 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4023 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4025 run_test 57 "lfs project could tolerate errors"
4028 [ "$mds1_FSTYPE" != ldiskfs ] &&
4029 skip "ldiskfs only test"
4030 disable_project_quota
4031 setup_quota_test || error "setup quota failed with $?"
4034 local testfile="$DIR/$tdir/$tfile-0"
4035 #make sure it did not crash kernel
4036 touch $testfile && lfs project -sp 1 $testfile
4038 enable_project_quota
4040 run_test 59 "lfs project dosen't crash kernel with project disabled"
4043 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4044 skip "Needs MDS version 2.11.53 or later."
4045 setup_quota_test || error "setup quota failed with $?"
4047 local testfile=$DIR/$tdir/$tfile
4050 set_mdt_qtype "ug" || error "enable mdt quota failed"
4052 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4053 error "set quota failed"
4054 quota_show_check a g $TSTUSR
4056 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4057 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4058 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4059 error "create many files failed"
4061 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4063 # root user can overrun quota
4064 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4065 error "root user should succeed"
4067 run_test 60 "Test quota for root with setgid"
4069 # test default quota
4070 test_default_quota() {
4071 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4072 skip "Not supported before 2.11.51."
4077 local qprjid=$TSTPRJID
4081 local LIMIT=20480 #20M disk space
4082 local TESTFILE="$DIR/$tdir/$tfile-0"
4085 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4086 echo "Project quota is not supported" && return 0
4088 [ $qtype == "-u" ] && qdtype="-U"
4089 [ $qtype == "-g" ] && qdtype="-G"
4090 [ $qtype == "-p" ] && {
4095 [ $qres_type == "meta" ] && {
4096 LIMIT=10240 #10K inodes
4101 qpool_cmd="--pool $3"
4102 # pool quotas don't work properly without global limit
4103 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4104 error "set global limit failed"
4107 setup_quota_test || error "setup quota failed with $?"
4111 # enable mdt/ost quota
4112 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4113 set_ost_qtype $QTYPE || error "enable ost quota failed"
4115 log "set to use default quota"
4116 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4117 error "set $qid to use default quota failed"
4119 log "set default quota"
4120 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4121 error "set $qid default quota failed"
4123 log "get default quota"
4124 $LFS quota $qdtype $DIR || error "get default quota failed"
4126 if [ $qres_type == "data" ]; then
4127 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4128 grep "$MOUNT" | awk '{print $2}')
4129 [ $SLIMIT -eq $LIMIT ] ||
4130 error "the returned default quota is wrong"
4132 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4134 [ $SLIMIT -eq $LIMIT ] ||
4135 error "the returned default quota is wrong"
4138 # make sure the system is clean
4139 local USED=$(getquota $qtype $qid global curspace)
4140 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4142 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4143 error "setstripe $TESTFILE failed"
4144 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4146 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4148 log "Test not out of quota"
4149 if [ $qres_type == "data" ]; then
4150 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4151 quota_error $qtype $qid "write failed, expect succeed"
4153 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4154 quota_error $qtype $qid "create failed, expect succeed"
4156 unlinkmany $TESTFILE $((LIMIT/2))
4159 log "Test out of quota"
4160 # flush cache, ensure noquota flag is set on client
4161 cancel_lru_locks osc
4162 cancel_lru_locks mdc
4163 sync; sync_all_data || true
4164 if [ $qres_type == "data" ]; then
4165 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4166 quota_error $qtype $qid "write succeed, expect EDQUOT"
4168 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4169 quota_error $qtype $qid "create succeed, expect EDQUOT"
4171 unlinkmany $TESTFILE $((LIMIT*2))
4175 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4176 error "setstripe $TESTFILE failed"
4177 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4179 log "Increase default quota"
4181 # LU-4505: sleep 5 seconds to enable quota acquire
4184 # increase default quota
4185 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4186 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4188 cancel_lru_locks osc
4189 cancel_lru_locks mdc
4190 sync; sync_all_data || true
4191 if [ $qres_type == "data" ]; then
4192 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4193 quota_error $qtype $qid "write failed, expect succeed"
4195 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4196 quota_error $qtype $qid "create failed, expect succeed"
4198 unlinkmany $TESTFILE $((LIMIT*2))
4201 log "Set quota to override default quota"
4202 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4203 error "set $qid quota failed"
4205 cancel_lru_locks osc
4206 cancel_lru_locks mdc
4207 sync; sync_all_data || true
4208 if [ $qres_type == "data" ]; then
4209 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4210 quota_error $qtype $qid "write succeed, expect EQUOT"
4212 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4213 quota_error $qtype $qid "create succeed, expect EQUOT"
4215 unlinkmany $TESTFILE $((LIMIT*2))
4218 log "Set to use default quota again"
4220 # LU-4505: sleep 5 seconds to enable quota acquire
4223 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4224 error "set $qid to use default quota failed"
4226 cancel_lru_locks osc
4227 cancel_lru_locks mdc
4228 sync; sync_all_data || true
4229 if [ $qres_type == "data" ]; then
4230 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4231 quota_error $qtype $qid "write failed, expect succeed"
4233 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4234 quota_error $qtype $qid "create failed, expect succeed"
4236 unlinkmany $TESTFILE $((LIMIT*2))
4241 wait_delete_completed || error "wait_delete_completed failed"
4242 sync_all_data || true
4244 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4245 error "reset default quota failed"
4246 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4247 error "reset quota failed"
4252 test_default_quota "-u" "data"
4253 test_default_quota "-u" "meta"
4254 test_default_quota "-g" "data"
4255 test_default_quota "-g" "meta"
4256 test_default_quota "-p" "data"
4257 test_default_quota "-p" "meta"
4259 run_test 61 "default quota tests"
4262 ! is_project_quota_supported &&
4263 skip "Project quota is not supported"
4264 [[ "$(chattr -h 2>&1)" =~ "project" ||
4265 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4266 skip "chattr did not support project quota"
4267 setup_quota_test || error "setup quota failed with $?"
4268 local testdir=$DIR/$tdir/
4270 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4271 change_project -s $testdir
4272 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4273 error "inherit attribute should be set"
4274 # chattr used FS_IOC_SETFLAGS ioctl
4275 $RUNAS chattr -P $testdir &&
4276 error "regular user clear inherit should fail"
4277 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4278 error "inherit attribute should still be set"
4279 chattr -P $testdir || error "root failed to clear inherit"
4280 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4281 error "inherit attribute should be cleared"
4284 run_test 62 "Project inherit should be only changed by root"
4287 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4288 skip "Not supported before 2.11.55"
4292 local dd_failed=false
4293 local tdir_dom=${tdir}_dom
4294 local LIMIT=20480 #20M
4296 [ $qtype == "p" ] && ! is_project_quota_supported &&
4297 echo "Project quota is not supported" && return 0
4299 [ $qtype == "p" ] && qid=$TSTPRJID
4301 setup_quota_test || error "setup quota failed with $?"
4305 # enable mdt/ost quota
4306 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4307 set_ost_qtype $QTYPE || error "enable ost quota failed"
4309 # make sure the system is clean
4310 local USED=$(getquota -$qtype $qid global curspace)
4311 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4313 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4315 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4316 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4317 error "setstripe $tdir_dom failed"
4318 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4320 [ $qtype == "p" ] && {
4321 change_project -sp $TSTPRJID $DIR/$tdir
4322 change_project -sp $TSTPRJID $DIR/$tdir_dom
4325 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4326 error "set $qid quota failed"
4328 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4329 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4333 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4335 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4336 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4340 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4342 rm -f $DIR/$tdir_dom/*
4344 # flush cache, ensure noquota flag is set on client
4345 cancel_lru_locks osc
4346 cancel_lru_locks mdc
4347 sync; sync_all_data || true
4351 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4352 quota_error $qtype $qid "write failed, expect succeed"
4354 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4355 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4359 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4362 rm -f $DIR/$tdir_dom/*
4364 # flush cache, ensure noquota flag is set on client
4365 cancel_lru_locks osc
4366 cancel_lru_locks mdc
4367 sync; sync_all_data || true
4371 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4372 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4376 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4378 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4379 quota_error $qtype $qid "write succeed, expect EDQUOT"
4382 rm -fr $DIR/$tdir_dom
4384 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4385 error "reset usr quota failed"
4393 run_test 63 "quota on DoM tests"
4396 ! is_project_quota_supported &&
4397 skip "Project quota is not supported"
4398 setup_quota_test || error "setup quota failed with $?"
4399 local dir1="$DIR/$tdir/"
4402 ln -s $dir1/file $dir1/file_link
4405 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4406 error "set project should succeed"
4408 used=$(getquota -p $TSTPRJID global curinodes)
4409 [ $used -eq 4 ] || error "expected 4 got $used"
4410 $LFS project -rC $dir1 >&/dev/null ||
4411 error "clear project should succeed"
4413 used=$(getquota -p $TSTPRJID global curinodes)
4414 [ $used -eq 0 ] || error "expected 0 got $used"
4416 run_test 64 "lfs project on non dir/files should succeed"
4420 local TESTFILE="$DIR/$tdir/$tfile-0"
4422 setup_quota_test || error "setup quota failed with $?"
4423 set_ost_qtype $QTYPE || error "enable ost quota failed"
4427 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4428 error "failed to write"
4429 # flush cache, ensure noquota flag is set on client
4430 cancel_lru_locks osc
4431 sync; sync_all_data || true
4433 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4434 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4435 local quota_all=$($RUNAS $LFS quota $DIR)
4437 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4438 error "usr quota not match"
4439 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4440 error "grp quota not match"
4442 run_test 65 "Check lfs quota result"
4445 ! is_project_quota_supported &&
4446 skip "Project quota is not supported"
4447 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4448 skip "Not supported before 2.12.4"
4449 setup_quota_test || error "setup quota failed with $?"
4450 local old=$(do_facet mds1 $LCTL get_param -n \
4451 mdt.*.enable_chprojid_gid | head -1)
4452 local testdir=$DIR/$tdir/foo
4454 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4455 stack_trap "do_facet mds1 $LCTL \
4456 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4458 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4459 chown -R $TSTID:$TSTID $testdir
4460 change_project -sp $TSTPRJID $testdir
4461 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4463 $RUNAS lfs project -p 0 $testdir/foo &&
4464 error "nonroot user should fail to set projid"
4466 $RUNAS lfs project -C $testdir/foo &&
4467 error "nonroot user should fail to clear projid"
4469 change_project -C $testdir/foo || error "failed to clear project"
4471 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4472 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4473 "failed to set projid with normal user when enable_chprojid_gid=-1"
4475 $RUNAS lfs project -rC $testdir/ || error \
4476 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4478 touch $testdir/bar || error "failed touch $testdir/bar"
4479 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4480 "normal user should not be able to set projid on root owned file"
4482 change_project -p $TSTPRJID $testdir/bar || error \
4483 "root should be able to change its own file's projid"
4485 run_test 66 "nonroot user can not change project state in default"
4492 local short_qtype=${qtype:0:1}
4495 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4497 quota_usr) _runas=$RUNAS;;
4498 quota_2usr) _runas=$RUNAS2;;
4499 *) error "unknown quota parameter $4";;
4504 $_runas $DD of=$file count=$size ||
4505 quota_error $short_qtype $TSTUSR \
4506 "$qtype write failure, but expect success"
4508 cancel_lru_locks osc
4510 sync; sync_all_data || true
4519 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4521 do_facet mds1 $LCTL get_param $param |
4522 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4527 local testfile="$DIR/$tdir/$tfile-0"
4528 local testfile2="$DIR/$tdir/$tfile-1"
4529 local testfile3="$DIR/$tdir/$tfile-2"
4530 local qpool="qpool1"
4536 [ "$ost1_FSTYPE" == zfs ] &&
4537 skip "ZFS grants some block space together with inode"
4539 setup_quota_test || error "setup quota failed with $?"
4542 set_ost_qtype $QTYPE || error "enable ost quota failed"
4545 log "User quota (block hardlimit:$limit MB)"
4546 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4547 error "set user quota failed"
4549 # make sure the system is clean
4550 used=$(getquota -u $TSTUSR global curspace)
4551 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4553 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4554 echo "granted 0x0 before write $granted"
4556 # trigger reintegration
4557 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4558 procf=${procf}quota_slave.force_reint
4559 do_facet ost1 $LCTL set_param $procf=1 ||
4560 error "force reintegration failed"
4561 wait_ost_reint "u" || error "reintegration failed"
4562 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4563 [ $granted -ne 0 ] &&
4564 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4566 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4567 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4569 # write 10 MB to testfile
4570 test_67_write "$testfile" "user" 10 "quota_usr"
4572 # create qpool and add OST1
4573 pool_add $qpool || error "pool_add failed"
4574 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4575 # as quota_usr hasn't limits, lqe may absent. But it should be
4576 # created after the 1st direct qmt_get.
4577 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4579 # check granted - should be 0, as testfile is located only on OST0
4580 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4581 echo "global granted $granted"
4582 granted=$(getgranted $qpool "dt" $TSTID "usr")
4583 echo "$qpool granted $granted"
4584 [ $granted -ne 0 ] &&
4585 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4587 # add OST0 to qpool and check granted space
4588 pool_add_targets $qpool 0 1 ||
4589 error "pool_add_targets failed"
4590 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4591 echo "Granted $granted_mb MB"
4592 #should be 10M + qunit for each OST
4593 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4594 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4596 $LFS setstripe $testfile2 -c 1 -i 1 ||
4597 error "setstripe $testfile2 failed"
4598 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4599 # Write from another user and check that qpool1
4600 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4601 test_67_write "$testfile2" "user" 10 "quota_2usr"
4602 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4603 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4604 [ $granted -ne 0 ] &&
4605 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4607 # Granted space for quota_2usr in qpool1 should appear only
4608 # when global lqe for this user becomes enforced.
4609 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4610 error "set user quota failed"
4611 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4612 echo "granted_mb $granted_mb"
4613 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4614 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4616 $LFS setstripe $testfile3 -c 1 -i 0 ||
4617 error "setstripe $testfile3 failed"
4618 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4619 test_67_write "$testfile3" "user" 10 "quota_2usr"
4620 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4621 echo "$testfile3 granted_mb $granted_mb"
4622 [ $granted_mb -eq $limit ] ||
4623 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4625 # remove OST1 from the qpool1 and check granted space
4626 # should be 0 for TSTUSR and 10M for TSTUSR2
4627 pool_remove_target $qpool 0
4628 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4629 [ $granted_mb -eq 0 ] ||
4630 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4631 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4632 [ $granted_mb -eq 10 ] ||
4633 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4636 wait_delete_completed || error "wait_delete_completed failed"
4637 sync_all_data || true
4638 used=$(getquota -u $TSTUSR global curspace)
4639 [ $used -eq 0 ] || quota_error u $TSTUSR \
4640 "user quota isn't released after deletion"
4642 run_test 67 "quota pools recalculation"
4649 wait_update_facet mds1 \
4650 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4651 >/dev/null 2>&1 || echo foo" "" ||
4652 error "mds1: failed to create quota pool $pool"
4654 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4655 awk '/usr/ {getline; print $2}'
4660 local qpool="qpool1"
4663 setup_quota_test || error "setup quota failed with $?"
4666 set_ost_qtype $QTYPE || error "enable ost quota failed"
4668 # check slave number for glbal pool
4669 local nr=$(get_slave_nr "0x0" "usr")
4670 echo "nr result $nr"
4671 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4672 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4674 # create qpool and add OST1
4675 pool_add $qpool || error "pool_add failed"
4676 nr=$(get_slave_nr $qpool "usr")
4677 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4680 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4681 nr=$(get_slave_nr $qpool "usr")
4682 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4685 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4686 nr=$(get_slave_nr $qpool "usr")
4687 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4690 pool_remove_target $qpool 0
4691 nr=$(get_slave_nr $qpool "usr")
4692 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4695 pool_remove_target $qpool 1
4696 nr=$(get_slave_nr $qpool "usr")
4697 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4699 # Check again that all is fine with global pool
4700 nr=$(get_slave_nr "0x0" "usr")
4701 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4702 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4704 run_test 68 "slave number in quota pool changed after each add/remove OST"
4708 local global_limit=200 # MB
4710 local testfile="$DIR/$tdir/$tfile-0"
4711 local dom0="$DIR/$tdir/dom0"
4712 local qpool="qpool1"
4715 setup_quota_test || error "setup quota failed with $?"
4718 set_ost_qtype $QTYPE || error "enable ost quota failed"
4719 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4721 # Save DOM only at MDT0
4722 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4723 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4725 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4727 # create qpool and add OST0
4728 pool_add $qpool || error "pool_add failed"
4729 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4731 log "User quota (block hardlimit:$global_limit MB)"
4732 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4733 error "set user quota failed"
4735 log "User quota (block hardlimit:$limit MB)"
4736 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4737 error "set user quota failed"
4739 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4740 quota_error u $TSTUSR "write failed"
4742 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4743 oflag=sync || quota_error u $TSTUSR "write failed"
4745 $RUNAS $DD of=$testfile count=$limit || true
4747 # flush cache, ensure noquota flag is set on client
4748 cancel_lru_locks osc
4749 sync; sync_all_data || true
4751 # MDT0 shouldn't get EDQUOT with glimpse.
4752 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4753 quota_error u $TSTUSR \
4754 "user write success, but expect EDQUOT"
4756 # Now all members of qpool1 should get EDQUOT. Expect success
4757 # when write to DOM on MDT0, as it belongs to global pool.
4758 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4759 oflag=sync || quota_error u $TSTUSR "write failed"
4761 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4762 oflag=sync || quota_error u $TSTUSR "write failed"
4764 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4768 local qpool="qpool1"
4773 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4774 skip "Needs a client >= $VERSION_WITH_QP"
4776 setup_quota_test || error "setup quota failed with $?"
4778 # MDS returns EFAULT for unsupported quotactl command
4779 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4781 # create qpool and add OST0
4782 pool_add $qpool || error "pool_add failed"
4783 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4785 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4787 [ $rc -eq $err ] || error "setquota res $rc != $err"
4789 # If MDS supports QP, check that limit was set properly.
4790 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4791 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4792 echo "hard limit $bhard limit $limit"
4793 [ $bhard -ne $((limit*1024)) ] &&
4794 error "bhard:$bhard for $qpool!=$((limit*1024))"
4797 $LFS quota -u $TSTUSR --pool $qpool $DIR
4799 [ $rc -eq $err ] || error "quota res $rc != $err"
4801 run_test 70a "check lfs setquota/quota with a pool option"
4805 local glbl_hard=200 # 200M
4806 local glbl_soft=100 # 100M
4807 local pool_hard=10 # 10M
4808 local qpool="qpool1"
4810 pool_add $qpool || error "pool_add failed"
4811 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4813 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
4814 error "set user quota failed"
4815 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
4816 error "set user quota failed"
4818 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4819 [ $tmp -eq $((pool_hard * 1024)) ] ||
4820 error "wrong block hard limit $tmp for $qpool"
4821 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
4822 # soft limit hasn't been set and should be zero
4823 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
4825 run_test 70b "lfs setquota pool works properly"
4830 local global_limit=100 # MB
4831 local testfile="$DIR/$tdir/$tfile-0"
4832 local qpool="qpool1"
4833 local qpool2="qpool2"
4835 [ "$ost1_FSTYPE" == zfs ] &&
4836 skip "ZFS grants some block space together with inode"
4837 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4839 setup_quota_test || error "setup quota failed with $?"
4842 set_ost_qtype $QTYPE || error "enable ost quota failed"
4845 log "User quota (block hardlimit:$global_limit MB)"
4846 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4847 error "set user quota failed"
4849 pool_add $qpool || error "pool_add failed"
4850 pool_add_targets $qpool 0 1 ||
4851 error "pool_add_targets failed"
4853 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4854 error "set user quota failed"
4856 pool_add $qpool2 || error "pool_add failed"
4857 pool_add_targets $qpool2 1 1 ||
4858 error "pool_add_targets failed"
4860 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4861 error "set user quota failed"
4863 # make sure the system is clean
4864 local used=$(getquota -u $TSTUSR global curspace)
4867 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4869 # create 1st component 1-10M
4870 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4871 #create 2nd component 10-30M
4872 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4873 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4875 # сheck normal use and out of quota with PFL
4876 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4877 test_1_check_write $testfile "user" $((limit*2))
4879 wait_delete_completed || error "wait_delete_completed failed"
4880 sync_all_data || true
4881 used=$(getquota -u $TSTUSR global curspace)
4882 [ $used -ne 0 ] && quota_error u $TSTUSR \
4883 "user quota isn't released after deletion"
4885 # create 1st component 1-10M
4886 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4887 # create 2nd component 10-30M
4888 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4889 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4891 # write to the 2nd component
4892 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4893 quota_error u $TSTUSR \
4894 "write failure, but expect success"
4895 # this time maybe cache write, ignore it's failure
4896 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4897 cancel_lru_locks osc
4898 sync; sync_all_data || true
4899 # write over limit in qpool2(2nd component 10-30M)
4900 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4901 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4902 # write to the 1st component - OST0 is empty
4903 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4904 quota_error u $TSTUSR "write failed"
4906 run_test 71a "Check PFL with quota pools"
4910 local global_limit=1000 # MB
4911 local limit1=160 # MB
4912 local limit2=10 # MB
4913 local testfile="$DIR/$tdir/$tfile-0"
4914 local qpool="qpool1"
4915 local qpool2="qpool2"
4917 [ "$ost1_FSTYPE" == zfs ] &&
4918 skip "ZFS grants some block space together with inode"
4919 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4921 setup_quota_test || error "setup quota failed with $?"
4924 set_ost_qtype $QTYPE || error "enable ost quota failed"
4927 log "User quota (block hardlimit:$global_limit MB)"
4928 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4929 error "set user quota failed"
4931 pool_add $qpool || error "pool_add failed"
4932 pool_add_targets $qpool 0 1 ||
4933 error "pool_add_targets failed"
4935 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4936 error "set user quota failed"
4938 pool_add $qpool2 || error "pool_add failed"
4939 pool_add_targets $qpool2 1 1 ||
4940 error "pool_add_targets failed"
4942 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4943 error "set user quota failed"
4945 # make sure the system is clean
4946 local used=$(getquota -u $TSTUSR global curspace)
4949 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4951 # First component is on OST0, 2nd on OST1
4952 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4953 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4955 # fill the 1st component on OST0
4956 $RUNAS $DD of=$testfile count=128 ||
4957 quota_error u $TSTUSR "write failed"
4958 # write to the 2nd cmpnt on OST1
4959 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4960 quota_error u $TSTUSR "write failed"
4961 # this time maybe cache write, ignore it's failure
4962 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4964 cancel_lru_locks osc
4965 sync; sync_all_data || true
4966 # write over limit in qpool2
4967 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4968 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4971 run_test 71b "Check SEL with quota pools"
4976 local global_limit=50 # MB
4977 local testfile="$DIR/$tdir/$tfile-0"
4978 local qpool="qpool1"
4981 setup_quota_test || error "setup quota failed with $?"
4984 set_ost_qtype $QTYPE || error "enable ost quota failed"
4987 log "User quota (block hardlimit:$global_limit MB)"
4988 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4989 error "set user quota failed"
4991 pool_add $qpool || error "pool_add failed"
4992 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4994 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4995 error "set user quota failed"
4997 # make sure the system is clean
4998 local used=$(getquota -u $TSTUSR global curspace)
5000 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5002 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5004 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5005 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5006 test_1_check_write $testfile "user" $limit
5007 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5009 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5010 # check that lfs quota -uv --pool prints only OST that
5011 # was added in a pool
5012 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
5013 grep "OST\|MDT" && error "$qpool consists wrong targets"
5016 run_test 72 "lfs quota --pool prints only pool's OSTs"
5020 local qpool="qpool1"
5024 pool_add $qpool || error "pool_add failed"
5025 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5026 error "pool_add_targets failed"
5028 test_default_quota "-u" "data" "qpool1"
5030 run_test 73a "default limits at OST Pool Quotas"
5034 local TESTFILE1="$DIR/$tdir/$tfile-1"
5036 local qpool="qpool1"
5040 setup_quota_test || error "setup quota failed with $?"
5042 set_ost_qtype $QTYPE || error "enable ost quota failed"
5044 # pool quotas don't work properly without global limit
5045 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5046 error "set global limit failed"
5048 pool_add $qpool || error "pool_add failed"
5049 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5050 error "pool_add_targets failed"
5052 log "set default quota for $qpool"
5053 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5054 error "set default quota failed"
5056 log "Write from user that hasn't lqe"
5057 # Check that it doesn't cause a panic or a deadlock
5058 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5059 # Have to use RUNAS_ID as resetquota creates lqes in
5060 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5061 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5063 cancel_lru_locks osc
5064 sync; sync_all_data || true
5066 run_test 73b "default OST Pool Quotas limit for new user"
5070 local global_limit=200 # 200M
5071 local limit=10 # 10M
5072 local limit2=50 # 50M
5073 local qpool="qpool1"
5074 local qpool2="qpool2"
5078 setup_quota_test || error "setup quota failed with $?"
5081 set_ost_qtype $QTYPE || error "enable ost quota failed"
5083 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5084 error "set user quota failed"
5086 pool_add $qpool || error "pool_add failed"
5087 pool_add_targets $qpool 0 1 ||
5088 error "pool_add_targets failed"
5090 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5091 error "set user quota failed"
5093 pool_add $qpool2 || error "pool_add failed"
5094 pool_add_targets $qpool2 1 1 ||
5095 error "pool_add_targets failed"
5097 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5098 error "set user quota failed"
5100 tmp=$(getquota -u $TSTUSR global bhardlimit)
5101 [ $tmp -eq $((global_limit * 1024)) ] ||
5102 error "wrong global limit $global_limit"
5104 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5105 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5107 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5108 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5110 # check limits in pools
5111 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5112 grep -A4 $qpool | awk 'NR == 4{print $4}')
5113 echo "pool limit for $qpool $tmp"
5114 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5115 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5116 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5117 echo "pool limit for $qpool2 $tmp"
5118 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5120 run_test 74 "check quota pools per user"
5122 function cleanup_quota_test_75()
5124 do_facet mgs $LCTL nodemap_modify --name default \
5125 --property admin --value 1
5126 do_facet mgs $LCTL nodemap_modify --name default \
5127 --property trusted --value 1
5128 do_facet mgs $LCTL nodemap_modify --name default \
5129 --property squash_uid --value 99
5130 do_facet mgs $LCTL nodemap_modify --name default \
5131 --property squash_gid --value 99
5133 wait_nm_sync default admin_nodemap
5134 wait_nm_sync default trusted_nodemap
5136 do_facet mgs $LCTL nodemap_activate 0
5139 resetquota -u $TSTUSR
5143 local dd_failed=false
5144 local LIMIT=20480 #20M
5147 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5148 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5149 oflag=sync || dd_failed=true
5152 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5154 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5155 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5156 oflag=sync || dd_failed=true
5159 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5161 rm -f $DIR/$tdir_dom/*
5163 # flush cache, ensure noquota flag is set on client
5165 sync; sync_all_data || true
5169 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
5170 quota_error u $qid "write failed, expect succeed (2)"
5172 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5173 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5174 oflag=sync || dd_failed=true
5177 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5180 rm -f $DIR/$tdir_dom/*
5182 # flush cache, ensure noquota flag is set on client
5184 sync; sync_all_data || true
5188 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5189 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5190 oflag=sync || dd_failed=true
5193 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5195 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
5196 quota_error u $qid "write succeed, expect EDQUOT (3)"
5202 local soft_limit=10 # MB
5203 local hard_limit=20 # MB
5204 local limit=$soft_limit
5205 local testfile="$DIR/$tdir/$tfile-0"
5206 local grace=20 # seconds
5207 local tdir_dom=${tdir}_dom
5209 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5213 setup_quota_test || error "setup quota failed with $?"
5214 stack_trap cleanup_quota_test_75 EXIT
5217 set_ost_qtype $QTYPE || error "enable ost quota failed"
5218 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5220 local used=$(getquota -u $TSTID global curspace)
5221 $LFS setquota -t -u --block-grace $grace --inode-grace \
5222 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5223 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5224 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5225 error "set user quota failed"
5227 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5228 mkdir $DIR/$tdir_dom
5229 chmod 777 $DIR/$tdir_dom
5230 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5231 error "setstripe $tdir_dom failed"
5233 do_facet mgs $LCTL nodemap_activate 1
5235 do_facet mgs $LCTL nodemap_modify --name default \
5236 --property admin --value 0
5237 do_facet mgs $LCTL nodemap_modify --name default \
5238 --property trusted --value 0
5239 do_facet mgs $LCTL nodemap_modify --name default \
5240 --property deny_unknown --value 0
5241 do_facet mgs $LCTL nodemap_modify --name default \
5242 --property squash_uid --value $TSTID
5243 do_facet mgs $LCTL nodemap_modify --name default \
5244 --property squash_gid --value $TSTID
5245 cancel_lru_locks mdc
5246 wait_nm_sync default admin_nodemap
5247 wait_nm_sync default trusted_nodemap
5248 wait_nm_sync default squash_uid
5250 # mmap write when over soft limit
5252 $DD of=$testfile count=${limit} ||
5253 quota_error a "root write failure, but expect success (1)"
5254 OFFSET=$((limit * 1024))
5255 cancel_lru_locks osc
5257 echo "Write to exceed soft limit"
5258 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5259 quota_error a $TSTUSR "root write failure, but expect success (2)"
5260 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5261 cancel_lru_locks osc
5263 echo "mmap write when over soft limit"
5264 $MULTIOP $testfile.mmap OT40960SMW ||
5265 quota_error a $TSTUSR "mmap write failure, but expect success"
5266 cancel_lru_locks osc
5268 wait_delete_completed || error "wait_delete_completed failed (1)"
5269 sync_all_data || true
5271 # test for user hard limit
5274 $DD of=$testfile bs=1M count=$((limit/2)) ||
5275 quota_error u $TSTID \
5276 "root write failure, but expect success (3)"
5278 log "Write out of block quota ..."
5279 # possibly a cache write, ignore failure
5280 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
5281 # flush cache, ensure noquota flag is set on client
5282 cancel_lru_locks osc
5283 sync; sync_all_data || true
5284 # sync forced cache flush, but did not guarantee that slave
5285 # got new edquot through glimpse, so wait to make sure
5287 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
5288 quota_error u $TSTID \
5289 "user write success, but expect EDQUOT"
5291 wait_delete_completed || error "wait_delete_completed failed (2)"
5292 sync_all_data || true
5293 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5294 quota_error u $TSTID "user quota not released after deletion"
5298 run_test 75 "nodemap squashed root respects quota enforcement"
5301 ! is_project_quota_supported &&
5302 skip "skip project quota unsupported"
5304 setup_quota_test || error "setup quota failed with $?"
5307 local testfile="$DIR/$tdir/$tfile-0"
5310 $LFS project -p 4294967295 $testfile &&
5311 error "set project ID should fail"
5314 run_test 76 "project ID 4294967295 should be not allowed"
5318 mount_client $MOUNT2 "ro"
5319 lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5320 error "lfs setquota should fail in read-only Lustre mount"
5323 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5327 (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
5328 skip "need OST at least 2.14.55"
5329 check_set_fallocate_or_skip
5331 setup_quota_test || error "setup quota failed with $?"
5334 set_ost_qtype $QTYPE || error "enable ost quota failed"
5336 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5337 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5340 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5341 error "lfs setquota failed"
5344 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5346 kbytes=$(lfs quota -u $TSTUSR $DIR |
5347 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5348 echo "kbytes returned:$kbytes"
5350 # For file size of 204800. We should be having roughly 200 kbytes
5351 # returned. Anything alarmingly low (50 taken as arbitrary value)
5352 # would bail out this TC. Also this also avoids $kbytes of 0
5353 # to be used in calculation below.
5354 (( $kbytes > 50 )) ||
5355 error "fallocate did not use quota. kbytes returned:$kbytes"
5357 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5358 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5360 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5361 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5362 error "fallocate did not use quota correctly"
5364 run_test 78 "Check fallocate increase quota usage"
5368 (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
5369 skip "need client at least 2.15.0"
5370 (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
5371 skip "need OST at least 2.15.0"
5372 check_set_fallocate_or_skip
5374 setup_quota_test || error "setup quota failed with $?"
5377 set_ost_qtype $QTYPE || error "enable ost quota failed"
5379 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5381 local projectid=5200 # Random project id to test
5383 change_project -sp $projectid $DIR/$tdir
5386 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5387 error "lfs setquota project failed"
5390 fallocate -l 204800 $DIR/$tdir/$tfile
5392 # Get curspace (kbytes) for $projectid
5393 local kbytes=$(getquota -p $projectid global curspace)
5395 echo "kbytes returned:$kbytes"
5397 # For file size of 204800. We should be having roughly 200 kbytes
5398 # returned. Anything alarmingly low (50 taken as arbitrary value)
5399 # would bail out this TC. Also this also avoids $kbytes of 0
5400 # to be used in calculation below.
5401 (( $kbytes > 50 )) ||
5402 error "fallocate did not use projectid. kbytes returned:$kbytes"
5404 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5405 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5407 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5408 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5409 error "fallocate did not use quota projectid correctly"
5411 run_test 78a "Check fallocate increase projectid usage"
5415 local qpool="qpool1"
5416 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5417 local stopf=$TMP/$tfile
5419 do_facet mds1 "touch $stopf"
5420 stack_trap "do_facet mds1 'rm -f $stopf'"
5421 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5423 pool_add $qpool || error "pool_add failed"
5424 do_facet mds1 "rm $stopf"
5427 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5431 local dir1="$DIR/$tdir/dir1"
5432 local dir2="$DIR/$tdir/dir2"
5433 local TESTFILE0="$dir1/$tfile-0"
5434 local TESTFILE1="$dir1/$tfile-1"
5435 local TESTFILE2="$dir1/$tfile-2"
5436 local TESTFILE3="$dir2/$tfile-0"
5437 local global_limit=100 # 100M
5438 local limit=10 # 10M
5439 local qpool="qpool1"
5441 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5443 [ "$ost1_FSTYPE" == zfs ] &&
5444 skip "ZFS grants some block space together with inode"
5445 setup_quota_test || error "setup quota failed with $?"
5446 set_ost_qtype $QTYPE || error "enable ost quota failed"
5448 # make sure the system is clean
5449 local used=$(getquota -u $TSTUSR global curspace)
5450 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5452 pool_add $qpool || error "pool_add failed"
5453 pool_add_targets $qpool 0 1 ||
5454 error "pool_add_targets failed"
5456 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5457 error "set user quota failed"
5459 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5460 error "set user quota failed"
5461 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5462 error "set user quota failed"
5464 mkdir -p $dir1 || error "failed to mkdir"
5465 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5466 mkdir -p $dir2 || error "failed to mkdir"
5467 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5469 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5470 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5475 $LFS quota -uv $TSTUSR $DIR
5476 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5477 do_facet mds1 $LCTL set_param fail_loc=0xa06
5478 $RUNAS $DD of=$TESTFILE3 count=3 ||
5479 quota_error u $TSTUSR "write failed"
5480 $RUNAS $DD of=$TESTFILE2 count=7 ||
5481 quota_error u $TSTUSR "write failed"
5482 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5483 quota_error u $TSTUSR "write failed"
5486 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5490 do_facet mds1 $LCTL set_param fail_loc=0
5491 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5492 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5493 # OST0 needs some time to update quota usage after removing TESTFILE2
5495 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5496 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5497 quota_error u $TSTUSR "write failure, but expect success"
5499 run_test 80 "check for EDQUOT after OST failover"
5502 local global_limit=20 # 100M
5503 local testfile="$DIR/$tdir/$tfile-0"
5504 local qpool="qpool1"
5507 setup_quota_test || error "setup quota failed with $?"
5510 set_ost_qtype $QTYPE || error "enable ost quota failed"
5513 log "User quota (block hardlimit:$global_limit MB)"
5514 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5516 pool_add $qpool || error "pool_add failed"
5517 #define OBD_FAIL_QUOTA_RECALC 0xA07
5518 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5519 # added OST casues to start pool recalculation
5520 pool_add_targets $qpool 0 0 1
5521 stop mds1 -f || error "MDS umount failed"
5523 #start mds1 back to destroy created pool
5524 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5527 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5531 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
5532 skip "need MDS 2.14.55 or later"
5533 is_project_quota_supported ||
5534 skip "skip project quota unsupported"
5536 setup_quota_test || error "setup quota failed with $?"
5537 stack_trap cleanup_quota_test
5540 local parent_dir="$DIR/$tdir.parent"
5541 local child_dir="$parent_dir/child"
5544 stack_trap "chown -R 0:0 $parent_dir"
5546 chown $TSTUSR:$TSTUSR $parent_dir ||
5547 error "failed to chown on $parent_dir"
5548 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5549 error "failed to chown on $parent_dir"
5551 $LFS project -p 1000 $parent_dir ||
5552 error "failed to set project id on $parent_dir"
5553 $LFS project -p 1001 $child_dir ||
5554 error "failed to set project id on $child_dir"
5556 rmdir $child_dir || error "cannot remove child dir, test failed"
5558 run_test 82 "verify more than 8 qids for single operation"
5562 do_nodes $(comma_list $(nodes_list)) \
5563 "lctl set_param -n debug=-quota,trace"
5564 if $PQ_CLEANUP; then
5565 disable_project_quota
5568 reset_quota_settings
5573 check_and_cleanup_lustre
5574 export QUOTA_AUTO=$QUOTA_AUTO_OLD