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: LU-5152
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}
43 require_dsh_mds || exit 0
44 require_dsh_ost || exit 0
46 # Does e2fsprogs support quota feature?
47 if [ "$mds1_FSTYPE" == ldiskfs ] &&
48 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
49 grep -q 'quota'"; then
50 skip_env "e2fsprogs doesn't support quota"
53 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
55 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
60 QUOTA_AUTO_OLD=$QUOTA_AUTO
63 check_and_setup_lustre
65 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
67 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
68 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
69 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
70 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
71 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
72 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
73 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
74 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
79 local fail_val=${3:-0}
83 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
84 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
85 ost) NODES="$(comma_list $(osts_nodes))";;
88 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
94 lfs project $* || error "lfs project $* failed"
97 RUNAS="runas -u $TSTID -g $TSTID"
98 RUNAS2="runas -u $TSTID2 -g $TSTID2"
99 DD="dd if=/dev/zero bs=1M"
103 # clear quota limits for a user or a group
104 # usage: resetquota -u username
105 # resetquota -g groupname
106 # resetquota -p projid
109 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
110 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
111 error "resetquota: wrong specifier $1 passed"
113 if [ $1 == "-p" ]; then
114 is_project_quota_supported || return 0
117 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
118 error "clear quota for [type:$1 name:$2] failed"
119 # give a chance to slave to release space
127 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
128 $LFS quota -v -u $local_id $DIR
129 log "Files for user ($local_id):"
130 ($LFS find --user $local_id $DIR | head -n 4 |
131 xargs stat 2>/dev/null)
134 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
135 $LFS quota -v -g $local_id $DIR
136 log "Files for group ($local_id):"
137 ($LFS find --group $local_id $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
142 $LFS quota -v -p $TSTPRJID $DIR
143 log "Files for project ($TSTPRJID):"
144 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
145 xargs stat 2>/dev/null)
161 # get quota for a user or a group
162 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
163 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
168 sync_all_data > /dev/null 2>&1 || true
170 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
171 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
172 error "getquota: wrong u/g/p specifier $1 passed"
185 *) error "unknown quota parameter $4";;
188 [ "$uuid" = "global" ] && uuid=$DIR
190 $LFS quota -v "$1" "$2" $DIR |
191 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
192 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
197 # usage: set_mdt_qtype ugp|u|g|p|none
201 local mdts=$(get_facets MDS)
203 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
204 qtype=$(tr -d 'p' <<<$qtype)
206 if [[ $PERM_CMD == *"set_param -P"* ]]; then
207 do_facet mgs $PERM_CMD \
208 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
210 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
212 # we have to make sure each MDT received config changes
213 for mdt in ${mdts//,/ }; do
215 cmd="$LCTL get_param -n "
216 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
217 cmd=${cmd}.quota_slave.enabled
219 if $(facet_up $mdt); then
220 wait_update_facet $mdt "$cmd" "$qtype" || return 1
227 # usage: set_ost_qtype ugp|u|g|p|none
231 local osts=$(get_facets OST)
233 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
234 qtype=$(tr -d 'p' <<<$qtype)
236 if [[ $PERM_CMD == *"set_param -P"* ]]; then
237 do_facet mgs $PERM_CMD \
238 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
240 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
242 # we have to make sure each OST received config changes
243 for ost in ${osts//,/ }; do
245 cmd="$LCTL get_param -n "
246 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
247 cmd=${cmd}.quota_slave.enabled
249 if $(facet_up $ost); then
250 wait_update_facet $ost "$cmd" "$qtype" || return 1
256 wait_reintegration() {
260 local result="glb[1],slv[1],reint[0]"
265 if [ $ntype == "mdt" ]; then
266 tgts=$(get_facets MDS)
268 tgts=$(get_facets OST)
271 for tgt in ${tgts//,/ }; do
273 cmd="$LCTL get_param -n "
274 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
275 cmd=${cmd}.quota_slave.info
277 if $(facet_up $tgt); then
278 wait_update_facet $tgt "$cmd |
279 grep "$qtype" | awk '{ print \\\$3 }'" \
280 "$result" $max || return 1
290 if [[ "$qtype" =~ "u" ]]; then
291 wait_reintegration "mdt" "user" $max || return 1
294 if [[ "$qtype" =~ "g" ]]; then
295 wait_reintegration "mdt" "group" $max || return 1
298 if [[ "$qtype" =~ "p" ]]; then
299 ! is_project_quota_supported && return 0
300 wait_reintegration "mdt" "project" $max || return 1
309 if [[ "$qtype" =~ "u" ]]; then
310 wait_reintegration "ost" "user" $max || return 1
313 if [[ "$qtype" =~ "g" ]]; then
314 wait_reintegration "ost" "group" $max || return 1
317 if [[ "$qtype" =~ "p" ]]; then
318 ! is_project_quota_supported && return 0
319 wait_reintegration "ost" "project" $max || return 1
327 local extrasleep=${3:-5}
333 *) error "get_grace_time: Invalid quota type: $qtype"
338 time=$(lfs quota -$qtype $qarg $DIR|
339 awk 'NR == 3{ print $5 }'| sed 's/s$//')
342 time=$(lfs quota -$qtype $qarg $DIR|
343 awk 'NR == 3{ print $9 }'| sed 's/s$//')
346 error "Unknown quota type: $flavour"
350 echo "Sleep through grace ..."
351 [ "$time" == "-" ] &&
352 error "Grace timeout was not set or quota not exceeded"
353 if [ "$time" == "none" ]; then
354 echo "...Grace timeout already expired"
356 let time+=$extrasleep
357 echo "...sleep $time seconds"
363 wait_delete_completed
364 echo "Creating test directory"
365 mkdir $DIR/$tdir || return 1
366 chmod 0777 $DIR/$tdir || return 2
367 # always clear fail_loc in case of fail_loc isn't cleared
368 # properly when previous test failed
369 lustre_fail mds_ost 0
372 cleanup_quota_test() {
374 echo "Delete files..."
376 echo "Wait for unlink objects finished..."
377 wait_delete_completed
378 sync_all_data || true
388 $LFS quota -v -$ugp $qid $DIR
390 if [ "$bf" == "a" -o "$bf" == "b" ]; then
391 usage=$(getquota -$ugp $qid global curspace)
392 if [ -z $usage ]; then
393 quota_error $ugp $qid \
394 "Query block quota failed ($ugp:$qid)."
396 [ $usage -ne 0 ] && quota_log $ugp $qid \
397 "Block quota isn't 0 ($ugp:$qid:$usage)."
401 if [ "$bf" == "a" -o "$bf" == "f" ]; then
402 usage=$(getquota -$ugp $qid global curinodes)
403 if [ -z $usage ]; then
404 quota_error $ugp $qid \
405 "Query file quota failed ($ugp:$qid)."
407 [ $usage -ne 0 ] && quota_log $ugp $qid \
408 "File quota isn't 0 ($ugp:$qid:$usage)."
413 project_quota_enabled () {
415 local zfeat="feature@project_quota"
417 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
418 local facet_fstype=${facet:0:3}1_FSTYPE
421 if [ "${!facet_fstype}" = "zfs" ]; then
422 devname=$(zpool_name ${facet})
423 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
424 grep -wq active || rc=1
426 [ ${facet:0:3} == "mds" ] &&
427 devname=$(mdsdevname ${facet:3}) ||
428 devname=$(ostdevname ${facet:3})
429 do_facet ${facet} $DEBUGFS -R features $devname |
430 grep -q project || rc=1
433 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
437 project_quota_enabled || enable_project_quota
439 reset_quota_settings() {
440 resetquota -u $TSTUSR
441 resetquota -g $TSTUSR
442 resetquota -u $TSTUSR2
443 resetquota -g $TSTUSR2
444 resetquota -p $TSTPRJID
449 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
454 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
455 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
456 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
457 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
459 test_quota_performance() {
460 local TESTFILE="$DIR/$tdir/$tfile-0"
461 local size=$1 # in MB
462 local stime=$(date +%s)
463 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
464 quota_error u $TSTUSR "write failure"
465 local etime=$(date +%s)
466 delta=$((etime - stime))
467 if [ $delta -gt 0 ]; then
468 rate=$((size * 1024 / delta))
469 if [ "$mds1_FSTYPE" = zfs ]; then
470 # LU-2872 - see LU-2887 for fix
472 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
474 [ $rate -gt 1024 ] ||
475 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
481 # test basic quota performance b=21696
484 [ "$SLOW" = "no" ] && MB=10
486 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
487 [ $free_space -le $((MB * 1024)) ] &&
488 skip "not enough space ${free_space} KB, " \
489 "required $((MB * 1024)) KB"
490 setup_quota_test || error "setup quota failed with $?"
491 trap cleanup_quota_test EXIT
493 set_ost_qtype "none" || error "disable ost quota failed"
494 test_quota_performance $MB
496 set_ost_qtype $QTYPE || error "enable ost quota failed"
497 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
498 error "set quota failed"
499 test_quota_performance $MB
503 run_test 0 "Test basic quota performance"
505 # test block hardlimit
508 local TESTFILE="$DIR/$tdir/$tfile-0"
510 setup_quota_test || error "setup quota failed with $?"
511 trap cleanup_quota_test EXIT
514 set_ost_qtype $QTYPE || error "enable ost quota failed"
517 log "User quota (block hardlimit:$LIMIT MB)"
518 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
519 error "set user quota failed"
521 # make sure the system is clean
522 local USED=$(getquota -u $TSTUSR global curspace)
523 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
525 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
526 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
529 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
530 quota_error u $TSTUSR "user write failure, but expect success"
531 log "Write out of block quota ..."
532 # this time maybe cache write, ignore it's failure
533 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
534 # flush cache, ensure noquota flag is set on client
536 sync; sync_all_data || true
537 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
538 quota_error u $TSTUSR "user write success, but expect EDQUOT"
541 wait_delete_completed || error "wait_delete_completed failed"
542 sync_all_data || true
543 USED=$(getquota -u $TSTUSR global curspace)
544 [ $USED -ne 0 ] && quota_error u $TSTUSR \
545 "user quota isn't released after deletion"
546 resetquota -u $TSTUSR
549 log "--------------------------------------"
550 log "Group quota (block hardlimit:$LIMIT MB)"
551 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
552 error "set group quota failed"
554 TESTFILE="$DIR/$tdir/$tfile-1"
555 # make sure the system is clean
556 USED=$(getquota -g $TSTUSR global curspace)
557 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
559 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
560 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
563 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
564 quota_error g $TSTUSR "Group write failure, but expect success"
565 log "Write out of block quota ..."
566 # this time maybe cache write, ignore it's failure
567 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
569 sync; sync_all_data || true
570 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
571 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
573 wait_delete_completed || error "wait_delete_completed failed"
574 sync_all_data || true
575 USED=$(getquota -g $TSTUSR global curspace)
576 [ $USED -ne 0 ] && quota_error g $TSTUSR \
577 "Group quota isn't released after deletion"
578 resetquota -g $TSTUSR
580 if ! is_project_quota_supported; then
581 echo "Project quota is not supported"
586 TESTFILE="$DIR/$tdir/$tfile-2"
587 # make sure the system is clean
588 USED=$(getquota -p $TSTPRJID global curspace)
590 error "used space($USED) for project $TSTPRJID isn't 0"
593 log "--------------------------------------"
594 log "Project quota (block hardlimit:$LIMIT mb)"
595 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
596 error "set project quota failed"
598 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
599 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
600 change_project -p $TSTPRJID $TESTFILE
603 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
604 "project write failure, but expect success"
605 log "write out of block quota ..."
606 # this time maybe cache write, ignore it's failure
607 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
609 sync; sync_all_data || true
610 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
611 $TSTPRJID "project write success, but expect EDQUOT"
616 USED=$(getquota -p $TSTPRJID global curspace)
617 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
618 "project quota isn't released after deletion"
620 run_test 1 "Block hard limit (normal use and out of quota)"
622 # test inode hardlimit
624 local LIMIT=$((1024 * 1024)) # 1M inodes
625 local TESTFILE="$DIR/$tdir/$tfile-0"
627 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
629 local FREE_INODES=$(mdt_free_inodes 0)
630 echo "$FREE_INODES free inodes on master MDT"
631 [ $FREE_INODES -lt $LIMIT ] &&
632 skip "not enough free inodes $FREE_INODES required $LIMIT"
634 setup_quota_test || error "setup quota failed with $?"
635 trap cleanup_quota_test EXIT
638 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
641 log "User quota (inode hardlimit:$LIMIT files)"
642 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
643 error "set user quota failed"
645 # make sure the system is clean
646 local USED=$(getquota -u $TSTUSR global curinodes)
647 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
649 log "Create $LIMIT files ..."
650 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
651 quota_error u $TSTUSR "user create failure, but expect success"
652 log "Create out of file quota ..."
653 $RUNAS touch ${TESTFILE}_xxx &&
654 quota_error u $TSTUSR "user create success, but expect EDQUOT"
657 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
658 rm -f ${TESTFILE}_xxx
659 wait_delete_completed
661 USED=$(getquota -u $TSTUSR global curinodes)
662 [ $USED -ne 0 ] && quota_error u $TSTUSR \
663 "user quota isn't released after deletion"
664 resetquota -u $TSTUSR
667 log "--------------------------------------"
668 log "Group quota (inode hardlimit:$LIMIT files)"
669 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
670 error "set group quota failed"
672 TESTFILE=$DIR/$tdir/$tfile-1
673 # make sure the system is clean
674 USED=$(getquota -g $TSTUSR global curinodes)
675 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
677 log "Create $LIMIT files ..."
678 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
679 quota_error g $TSTUSR "group create failure, but expect success"
680 log "Create out of file quota ..."
681 $RUNAS touch ${TESTFILE}_xxx &&
682 quota_error g $TSTUSR "group create success, but expect EDQUOT"
685 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
686 rm -f ${TESTFILE}_xxx
687 wait_delete_completed
689 USED=$(getquota -g $TSTUSR global curinodes)
690 [ $USED -ne 0 ] && quota_error g $TSTUSR \
691 "user quota isn't released after deletion"
693 resetquota -g $TSTUSR
694 ! is_project_quota_supported && cleanup_quota_test &&
695 echo "Skip project quota is not supported" && return 0
698 log "--------------------------------------"
699 log "Project quota (inode hardlimit:$LIMIT files)"
700 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
701 error "set project quota failed"
703 TESTFILE=$DIR/$tdir/$tfile-1
704 # make sure the system is clean
705 USED=$(getquota -p $TSTPRJID global curinodes)
707 error "Used inodes($USED) for project $TSTPRJID isn't 0"
709 change_project -sp $TSTPRJID $DIR/$tdir
710 log "Create $LIMIT files ..."
711 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
712 $TSTPRJID "project create fail, but expect success"
713 log "Create out of file quota ..."
714 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
715 "project create success, but expect EDQUOT"
716 change_project -C $DIR/$tdir
719 USED=$(getquota -p $TSTPRJID global curinodes)
720 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
721 "project quota isn't released after deletion"
724 run_test 2 "File hard limit (normal use and out of quota)"
734 trap cleanup_quota_test EXIT
736 $LFS setstripe $TESTFILE -c 1 -i 0
737 chown $TSTUSR.$TSTUSR $TESTFILE
738 [ "$qtype" == "p" ] && is_project_quota_supported &&
739 change_project -p $TSTPRJID $TESTFILE
741 echo "Write up to soft limit"
742 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
743 quota_error a $TSTUSR "write failure, but expect success"
744 OFFSET=$((LIMIT * 1024))
747 echo "Write to exceed soft limit"
748 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
749 quota_error a $TSTUSR "write failure, but expect success"
750 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
756 $SHOW_QUOTA_INFO_USER
757 $SHOW_QUOTA_INFO_GROUP
758 $SHOW_QUOTA_INFO_PROJID
760 echo "Write before timer goes off"
761 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
762 quota_error a $TSTUSR "write failure, but expect success"
763 OFFSET=$((OFFSET + 1024))
766 wait_grace_time $qtype "block"
771 $SHOW_QUOTA_INFO_USER
772 $SHOW_QUOTA_INFO_GROUP
773 $SHOW_QUOTA_INFO_PROJID
775 echo "Write after timer goes off"
776 # maybe cache write, ignore.
777 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
778 OFFSET=$((OFFSET + 1024))
780 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
781 quota_error a $TSTUSR "write success, but expect EDQUOT"
786 $SHOW_QUOTA_INFO_USER
787 $SHOW_QUOTA_INFO_GROUP
788 $SHOW_QUOTA_INFO_PROJID
790 echo "Unlink file to stop timer"
792 wait_delete_completed
793 sync_all_data || true
798 $SHOW_QUOTA_INFO_USER
799 $SHOW_QUOTA_INFO_GROUP
800 $SHOW_QUOTA_INFO_PROJID
802 $LFS setstripe $TESTFILE -c 1 -i 0
803 chown $TSTUSR.$TSTUSR $TESTFILE
804 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
807 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
808 quota_error a $TSTUSR "write failure, but expect success"
816 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
819 local TESTFILE=$DIR/$tdir/$tfile-0
821 # get minimum soft qunit size
822 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
823 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
825 set_ost_qtype $QTYPE || error "enable ost quota failed"
827 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
828 # make sure the system is clean
829 local USED=$(getquota -u $TSTUSR global curspace)
830 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
832 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
833 $MAX_IQ_TIME $DIR || error "set user grace time failed"
834 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
835 error "set user quota failed"
837 test_block_soft $TESTFILE $GRACE $LIMIT "u"
839 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
840 TESTFILE=$DIR/$tdir/$tfile-1
841 # make sure the system is clean
842 USED=$(getquota -g $TSTUSR global curspace)
843 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
845 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
846 $MAX_IQ_TIME $DIR || error "set group grace time failed"
847 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
848 error "set group quota failed"
850 test_block_soft $TESTFILE $GRACE $LIMIT "g"
852 if is_project_quota_supported; then
853 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
854 TESTFILE=$DIR/$tdir/$tfile-2
855 # make sure the system is clean
856 USED=$(getquota -p $TSTPRJID global curspace)
857 [ $USED -ne 0 ] && error \
858 "Used space($USED) for project $TSTPRJID isn't 0."
860 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
862 error "set project grace time failed"
863 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
864 $DIR || error "set project quota failed"
866 test_block_soft $TESTFILE $GRACE $LIMIT "p"
867 resetquota -p $TSTPRJID
868 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
870 error "restore project grace time failed"
874 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
875 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
876 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
877 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
879 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
888 trap cleanup_quota_test EXIT
889 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
891 echo "Create files to exceed soft limit"
892 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
893 quota_error a $TSTUSR "create failure, but expect success"
894 local trigger_time=$(date +%s)
896 sync_all_data || true
898 local cur_time=$(date +%s)
899 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
900 error "Passed grace time $grace, $trigger_time, $cur_time"
902 echo "Create file before timer goes off"
903 $RUNAS touch ${TESTFILE}_before ||
904 quota_error a $TSTUSR "failed create before timer expired," \
905 "but expect success. $trigger_time, $cur_time"
906 sync_all_data || true
908 wait_grace_time $qtype "file"
913 $SHOW_QUOTA_INFO_USER
914 $SHOW_QUOTA_INFO_GROUP
915 $SHOW_QUOTA_INFO_PROJID
917 echo "Create file after timer goes off"
918 # There is a window that space is accounted in the quota usage but
919 # hasn't been decreased from the pending write, if we acquire quota
920 # in this window, we'll acquire more than we needed.
921 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
922 sync_all_data || true
923 $RUNAS touch ${TESTFILE}_after_3 &&
924 quota_error a $TSTUSR "create after timer expired," \
926 sync_all_data || true
931 $SHOW_QUOTA_INFO_USER
932 $SHOW_QUOTA_INFO_GROUP
933 $SHOW_QUOTA_INFO_PROJID
935 echo "Unlink files to stop timer"
936 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
937 wait_delete_completed
940 $RUNAS touch ${TESTFILE}_xxx ||
941 quota_error a $TSTUSR "touch after timer stop failure," \
943 sync_all_data || true
951 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
952 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
953 local TESTFILE=$DIR/$tdir/$tfile-0
956 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
958 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
959 # make sure the system is clean
960 local USED=$(getquota -u $TSTUSR global curinodes)
961 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
963 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
964 $GRACE $DIR || error "set user grace time failed"
965 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
966 error "set user quota failed"
968 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
970 test_file_soft $TESTFILE $LIMIT $GRACE "u"
972 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
973 # make sure the system is clean
974 USED=$(getquota -g $TSTUSR global curinodes)
975 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
977 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
978 $GRACE $DIR || error "set group grace time failed"
979 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
980 error "set group quota failed"
981 TESTFILE=$DIR/$tdir/$tfile-1
983 test_file_soft $TESTFILE $LIMIT $GRACE "g"
985 if is_project_quota_supported; then
986 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
987 # make sure the system is clean
988 USED=$(getquota -p $TSTPRJID global curinodes)
989 [ $USED -ne 0 ] && error \
990 "Used space($USED) for project $TSTPRJID isn't 0."
992 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
993 $GRACE $DIR || error "set project grace time failed"
994 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
995 error "set project quota failed"
997 TESTFILE=$DIR/$tdir/$tfile-1
998 # one less than limit, because of parent directory included.
999 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1000 resetquota -p $TSTPRJID
1001 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1002 $MAX_IQ_TIME $DIR ||
1003 error "restore project grace time failed"
1007 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1008 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1009 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1010 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1012 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1015 local GR_STR1="1w3d"
1016 local GR_STR2="1000s"
1018 local GR_STR4="1w2d3h4m5s"
1020 local GR_STR6="18446744073709551615"
1023 wait_delete_completed
1025 # test of valid grace strings handling
1026 echo "Valid grace strings test"
1027 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1028 $GR_STR2 $DIR || error "set user grace time failed"
1029 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1030 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1031 $GR_STR4 $DIR || error "set group grace time quota failed"
1032 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1034 # test of invalid grace strings handling
1035 echo " Invalid grace strings test"
1036 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1037 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1038 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1042 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1043 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1044 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1045 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1047 run_test 4b "Grace time strings handling"
1049 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1051 local BLIMIT=10 # 10M
1052 local ILIMIT=10 # 10 inodes
1054 setup_quota_test || error "setup quota failed with $?"
1055 trap cleanup_quota_test EXIT
1057 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1058 set_ost_qtype $QTYPE || error "enable ost quota failed"
1060 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1061 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1062 error "set user quota failed"
1063 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1064 if is_project_quota_supported; then
1065 error "set group quota failed"
1066 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1067 -I $ILIMIT $DIR || error "set project quota failed"
1070 # make sure the system is clean
1071 local USED=$(getquota -u $TSTUSR global curinodes)
1072 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1073 USED=$(getquota -g $TSTUSR global curinodes)
1074 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1075 USED=$(getquota -u $TSTUSR global curspace)
1076 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1077 USED=$(getquota -g $TSTUSR global curspace)
1078 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1079 if is_project_quota_supported; then
1080 USED=$(getquota -p $TSTPRJID global curinodes)
1082 error "Used inode($USED) for project $TSTPRJID isn't 0."
1083 USED=$(getquota -p $TSTPRJID global curspace)
1085 error "Used block($USED) for project $TSTPRJID isn't 0."
1088 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1089 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1090 error "create failure, expect success"
1091 if is_project_quota_supported; then
1092 touch $DIR/$tdir/$tfile-0_1
1093 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1095 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1096 error "write failure, expect success"
1098 echo "Chown files to $TSTUSR.$TSTUSR ..."
1099 for i in $(seq 0 $ILIMIT); do
1100 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1101 quota_error a $TSTUSR "chown failure, expect success"
1105 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1106 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1109 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1111 # test dropping acquire request on master
1115 # Clear dmesg so watchdog is not triggered by previous
1117 do_facet ost1 dmesg -c > /dev/null
1119 setup_quota_test || error "setup quota failed with $?"
1120 trap cleanup_quota_test EXIT
1122 # make sure the system is clean
1123 local USED=$(getquota -u $TSTUSR global curspace)
1124 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1126 # make sure no granted quota on ost
1127 set_ost_qtype $QTYPE || error "enable ost quota failed"
1128 resetquota -u $TSTUSR
1130 # create file for $TSTUSR
1131 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1132 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1133 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1135 # create file for $TSTUSR2
1136 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1137 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1138 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1140 # cache per-ID lock for $TSTUSR on slave
1141 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1142 error "set quota failed"
1143 $RUNAS $DD of=$TESTFILE count=1 ||
1144 error "write $TESTFILE failure, expect success"
1145 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1146 error "write $TESTFILE2 failure, expect success"
1148 if at_is_enabled; then
1149 at_max_saved=$(at_max_get ost1)
1150 at_max_set $TIMEOUT ost1
1152 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1153 # DQACQ is sent, which makes at_max to take effect
1154 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1157 wait_delete_completed
1161 sync_all_data || true
1163 #define QUOTA_DQACQ 601
1164 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1165 lustre_fail mds 0x513 601
1167 do_facet ost1 $LCTL set_param \
1168 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1170 # write to un-enforced ID ($TSTUSR2) should succeed
1171 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1172 error "write failure, expect success"
1174 # write to enforced ID ($TSTUSR) in background, exceeding limit
1175 # to make sure DQACQ is sent
1176 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1179 # watchdog timer uses a factor of 2
1180 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1181 sleep $((TIMEOUT * 2 + 1))
1183 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1185 # write should be blocked and never finished
1186 if ! ps -p $DDPID > /dev/null 2>&1; then
1188 error "write finished incorrectly!"
1193 # no watchdog is triggered
1194 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1195 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1196 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1197 [ -z "$watchdog" ] || error "$watchdog"
1199 rm -f $TMP/lustre-log-${TESTNAME}.log
1201 # write should continue then fail with EDQUOT
1205 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1206 if [ $count -ge 240 ]; then
1207 quota_error u $TSTUSR "dd not finished in $count secs"
1209 count=$((count + 1))
1210 if [ $((count % 30)) -eq 0 ]; then
1211 c_size=$(stat -c %s $TESTFILE)
1212 echo "Waiting $count secs. $c_size"
1220 run_test 6 "Test dropping acquire request on master"
1222 # quota reintegration (global index)
1224 local TESTFILE=$DIR/$tdir/$tfile
1225 local LIMIT=20 # 20M
1227 [ "$SLOW" = "no" ] && LIMIT=5
1229 setup_quota_test || error "setup quota failed with $?"
1230 trap cleanup_quota_test EXIT
1232 # make sure the system is clean
1233 local USED=$(getquota -u $TSTUSR global curspace)
1234 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1236 # make sure no granted quota on ost1
1237 set_ost_qtype $QTYPE || error "enable ost quota failed"
1238 resetquota -u $TSTUSR
1239 set_ost_qtype "none" || error "disable ost quota failed"
1241 local OSTUUID=$(ostuuid_from_index 0)
1242 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1244 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1247 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1248 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1253 echo "Enable quota & set quota limit for $TSTUSR"
1254 set_ost_qtype $QTYPE || error "enable ost quota failed"
1255 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1256 error "set quota failed"
1258 echo "Start ost1..."
1259 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1262 wait_ost_reint $QTYPE || error "reintegration failed"
1264 # hardlimit should have been fetched by slave during global
1265 # reintegration, write will exceed quota
1266 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1267 quota_error u $TSTUSR "write success, but expect EDQUOT"
1270 wait_delete_completed
1271 sync_all_data || true
1277 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1278 error "clear quota failed"
1280 echo "Start ost1..."
1281 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1284 wait_ost_reint $QTYPE || error "reintegration failed"
1286 # hardlimit should be cleared on slave during reintegration
1287 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1288 quota_error u $TSTUSR "write error, but expect success"
1292 run_test 7a "Quota reintegration (global index)"
1294 # quota reintegration (slave index)
1297 local TESTFILE=$DIR/$tdir/$tfile
1299 setup_quota_test || error "setup quota failed with $?"
1300 trap cleanup_quota_test EXIT
1302 # make sure the system is clean
1303 local USED=$(getquota -u $TSTUSR global curspace)
1304 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1306 # make sure no granted quota on ost1
1307 set_ost_qtype $QTYPE || error "enable ost quota failed"
1308 resetquota -u $TSTUSR
1309 set_ost_qtype "none" || error "disable ost quota failed"
1311 local OSTUUID=$(ostuuid_from_index 0)
1312 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1314 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1317 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1318 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1320 # consume some space to make sure the granted space will not
1321 # be released during reconciliation
1322 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1323 error "consume space failure, expect success"
1325 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1326 lustre_fail mds 0xa02
1328 set_ost_qtype $QTYPE || error "enable ost quota failed"
1329 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1330 error "set quota failed"
1332 # ignore the write error
1333 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1335 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1339 echo "Restart ost to trigger reintegration..."
1341 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1344 wait_ost_reint $QTYPE || error "reintegration failed"
1346 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1347 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1352 run_test 7b "Quota reintegration (slave index)"
1354 # quota reintegration (restart mds during reintegration)
1356 local LIMIT=20 # 20M
1357 local TESTFILE=$DIR/$tdir/$tfile
1359 [ "$SLOW" = "no" ] && LIMIT=5
1361 setup_quota_test || error "setup quota failed with $?"
1362 trap cleanup_quota_test EXIT
1364 # make sure the system is clean
1365 local USED=$(getquota -u $TSTUSR global curspace)
1366 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1368 set_ost_qtype "none" || error "disable ost quota failed"
1369 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1370 error "set quota failed"
1372 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1373 lustre_fail ost 0xa03
1376 set_ost_qtype $QTYPE || error "enable ost quota failed"
1377 # trigger reintegration
1378 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1379 procf=${procf}quota_slave.force_reint
1380 do_facet ost1 $LCTL set_param $procf=1 ||
1381 error "force reintegration failed"
1389 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1392 # wait longer than usual to make sure the reintegration
1393 # is triggered by quota wb thread.
1394 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1396 # hardlimit should have been fetched by slave during global
1397 # reintegration, write will exceed quota
1398 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1399 quota_error u $TSTUSR "write success, but expect EDQUOT"
1403 run_test 7c "Quota reintegration (restart mds during reintegration)"
1405 # Quota reintegration (Transfer index in multiple bulks)
1407 local TESTFILE=$DIR/$tdir/$tfile
1408 local TESTFILE1="$DIR/$tdir/$tfile"-1
1411 setup_quota_test || error "setup quota failed with $?"
1412 trap cleanup_quota_test EXIT
1414 set_ost_qtype "none" || error "disable ost quota failed"
1415 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1416 error "set quota for $TSTUSR failed"
1417 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1418 error "set quota for $TSTUSR2 failed"
1420 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1421 lustre_fail mds 0x608 0
1423 # enable quota to tirgger reintegration
1424 set_ost_qtype "u" || error "enable ost quota failed"
1425 wait_ost_reint "u" || error "reintegration failed"
1429 # hardlimit should have been fetched by slave during global
1430 # reintegration, write will exceed quota
1431 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1432 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1434 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1435 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1439 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1441 # quota reintegration (inode limits)
1443 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1445 # LU-2435: skip this quota test if underlying zfs version has not
1446 # supported native dnode accounting
1447 [ "$mds1_FSTYPE" == zfs ] && {
1448 local F="feature@userobj_accounting"
1449 local pool=$(zpool_name mds1)
1450 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1452 [[ "$feature" != *" active "* ]] &&
1453 skip "requires zpool with active userobj_accounting"
1456 local ilimit=$((1024 * 2)) # 2k inodes
1457 local TESTFILE=$DIR/${tdir}-1/$tfile
1459 setup_quota_test || error "setup quota failed with $?"
1460 trap cleanup_quota_test EXIT
1462 # make sure the system is clean
1463 local USED=$(getquota -u $TSTUSR global curinodes)
1464 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1466 # make sure no granted quota on mdt1
1467 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1468 resetquota -u $TSTUSR
1469 set_mdt_qtype "none" || error "disable mdt quota failed"
1471 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1472 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1473 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1476 echo "Stop mds${MDSCOUNT}..."
1479 echo "Enable quota & set quota limit for $TSTUSR"
1480 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1481 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1482 error "set quota failed"
1484 echo "Start mds${MDSCOUNT}..."
1485 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1488 wait_mdt_reint $QTYPE || error "reintegration failed"
1490 echo "create remote dir"
1491 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1492 error "create remote dir failed"
1493 chmod 0777 $DIR/${tdir}-1
1495 # hardlimit should have been fetched by slave during global
1496 # reintegration, create will exceed quota
1497 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1498 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1500 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1501 wait_delete_completed
1502 sync_all_data || true
1504 echo "Stop mds${MDSCOUNT}..."
1507 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1508 error "clear quota failed"
1510 echo "Start mds${MDSCOUNT}..."
1511 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1514 wait_mdt_reint $QTYPE || error "reintegration failed"
1516 # hardlimit should be cleared on slave during reintegration
1517 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1518 quota_error u $TSTUSR "create failed, expect success"
1520 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1521 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1525 run_test 7e "Quota reintegration (inode limits)"
1527 # run dbench with quota enabled
1529 local BLK_LIMIT="100g" #100G
1530 local FILE_LIMIT=1000000
1532 setup_quota_test || error "setup quota failed with $?"
1533 trap cleanup_quota_test EXIT
1535 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1536 set_ost_qtype $QTYPE || error "enable ost quota failed"
1538 echo "Set enough high limit for user: $TSTUSR"
1539 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1540 error "set user quota failed"
1541 echo "Set enough high limit for group: $TSTUSR"
1542 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1543 error "set group quota failed"
1544 if is_project_quota_supported; then
1545 change_project -sp $TSTPRJID $DIR/$tdir
1546 echo "Set enough high limit for project: $TSTPRJID"
1547 $LFS setquota -p $TSTPRJID -b 0 \
1548 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1549 error "set project quota failed"
1553 [ "$SLOW" = "no" ] && duration=" -t 120"
1554 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1555 quota_error a $TSTUSR "dbench failed!"
1557 is_project_quota_supported && change_project -C $DIR/$tdir
1560 run_test 8 "Run dbench with quota enabled"
1562 # this check is just for test_9
1563 OST0_MIN=4900000 #4.67G
1565 check_whether_skip () {
1566 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1567 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1568 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1569 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1576 # run for fixing bug10707, it needs a big room. test for 64bit
1578 local filesize=$((1024 * 9 / 2)) # 4.5G
1580 check_whether_skip && return 0
1582 setup_quota_test || error "setup quota failed with $?"
1583 trap cleanup_quota_test EXIT
1585 set_ost_qtype "ug" || error "enable ost quota failed"
1587 local TESTFILE="$DIR/$tdir/$tfile-0"
1588 local BLK_LIMIT=100G #100G
1589 local FILE_LIMIT=1000000
1591 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1593 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1595 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1596 error "set user quota failed"
1598 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1599 "for group: $TSTUSR"
1600 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1601 error "set group quota failed"
1603 quota_show_check a u $TSTUSR
1604 quota_show_check a g $TSTUSR
1606 echo "Create test file"
1607 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1608 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1610 log "Write the big file of 4.5G ..."
1611 $RUNAS $DD of=$TESTFILE count=$filesize ||
1612 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1622 run_test 9 "Block limit larger than 4GB (b10707)"
1625 local TESTFILE=$DIR/$tdir/$tfile
1627 setup_quota_test || error "setup quota failed with $?"
1628 trap cleanup_quota_test EXIT
1630 # set limit to root user should fail
1631 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1632 error "set limit for root user successfully, expect failure"
1633 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1634 error "set limit for root group successfully, expect failure"
1635 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1636 error "set limit for project 0 successfully, expect failure"
1638 # root user can overrun quota
1639 set_ost_qtype "ug" || error "enable ost quota failed"
1641 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1642 error "set quota failed"
1643 quota_show_check b u $TSTUSR
1645 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1646 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1648 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1649 error "write failure, expect success"
1653 run_test 10 "Test quota for root user"
1656 local TESTFILE=$DIR/$tdir/$tfile
1657 setup_quota_test || error "setup quota failed with $?"
1658 trap cleanup_quota_test EXIT
1660 set_mdt_qtype "ug" || error "enable mdt quota failed"
1661 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1662 error "set quota failed"
1664 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1665 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1667 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1668 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1671 local USED=$(getquota -u $TSTUSR global curinodes)
1672 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1676 run_test 11 "Chown/chgrp ignores quota"
1679 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1681 local blimit=22 # 22M
1682 local blk_cnt=$((blimit - 5))
1683 local TESTFILE0="$DIR/$tdir/$tfile"-0
1684 local TESTFILE1="$DIR/$tdir/$tfile"-1
1686 setup_quota_test || error "setup quota failed with $?"
1687 trap cleanup_quota_test EXIT
1689 set_ost_qtype "u" || error "enable ost quota failed"
1690 quota_show_check b u $TSTUSR
1692 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1693 error "set quota failed"
1695 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1696 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1697 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1698 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1700 echo "Write to ost0..."
1701 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1702 quota_error a $TSTUSR "dd failed"
1704 echo "Write to ost1..."
1705 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1706 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1708 echo "Free space from ost0..."
1710 wait_delete_completed
1711 sync_all_data || true
1713 echo "Write to ost1 after space freed from ost0..."
1714 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1715 quota_error a $TSTUSR "rebalancing failed"
1719 run_test 12a "Block quota rebalancing"
1722 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1724 local ilimit=$((1024 * 2)) # 2k inodes
1725 local TESTFILE0=$DIR/$tdir/$tfile
1726 local TESTFILE1=$DIR/${tdir}-1/$tfile
1728 setup_quota_test || error "setup quota failed with $?"
1729 trap cleanup_quota_test EXIT
1731 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1732 chmod 0777 $DIR/${tdir}-1
1734 set_mdt_qtype "u" || error "enable mdt quota failed"
1735 quota_show_check f u $TSTUSR
1737 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1738 error "set quota failed"
1740 echo "Create $ilimit files on mdt0..."
1741 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1742 quota_error u $TSTUSR "create failed, but expect success"
1744 echo "Create files on mdt1..."
1745 $RUNAS createmany -m $TESTFILE1 1 &&
1746 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1748 echo "Free space from mdt0..."
1749 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1750 wait_delete_completed
1751 sync_all_data || true
1753 echo "Create files on mdt1 after space freed from mdt0..."
1754 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1755 quota_error a $TSTUSR "rebalancing failed"
1757 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1758 error "unlink mdt1 files failed"
1759 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1763 run_test 12b "Inode quota rebalancing"
1766 local TESTFILE=$DIR/$tdir/$tfile
1767 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1768 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1770 setup_quota_test || error "setup quota failed with $?"
1771 trap cleanup_quota_test EXIT
1773 set_ost_qtype "u" || error "enable ost quota failed"
1774 quota_show_check b u $TSTUSR
1776 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1777 error "set quota failed"
1778 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1779 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1781 # clear the locks in cache first
1782 do_facet ost1 $LCTL set_param -n $procf=clear
1783 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1784 [ $nlock -eq 0 ] || error "$nlock cached locks"
1786 # write to acquire the per-ID lock
1787 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1788 quota_error a $TSTUSR "dd failed"
1790 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1791 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1793 # clear quota doesn't trigger per-ID lock cancellation
1794 resetquota -u $TSTUSR
1795 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1796 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1798 # clear the per-ID lock
1799 do_facet ost1 $LCTL set_param -n $procf=clear
1800 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1801 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1803 # spare quota should be released
1804 local OSTUUID=$(ostuuid_from_index 0)
1805 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1806 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1807 [ $limit -le $space ] ||
1808 error "spare quota isn't released, limit:$limit, space:$space"
1812 run_test 13 "Cancel per-ID lock in the LRU list"
1815 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1817 wait_delete_completed
1818 sync_all_data || true
1821 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1822 error "set user quota failed"
1823 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1824 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1825 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1826 resetquota -u $TSTUSR
1829 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1830 error "set group quota failed"
1831 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1832 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1833 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1834 resetquota -g $TSTUSR
1836 run_test 15 "Set over 4T block quota"
1840 local BLKS=1 # 1M less than limit
1841 local TESTFILE=$DIR/$tdir/$tfile
1843 setup_quota_test || error "setup quota failed with $?"
1844 trap cleanup_quota_test EXIT
1846 # make sure the system is clean
1847 local USED=$(getquota -u $TSTUSR global curspace)
1848 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1850 set_ost_qtype "ug" || error "enable ost quota failed"
1851 # make sure no granted quota on ost
1852 resetquota -u $TSTUSR
1853 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1854 error "set quota failed"
1856 quota_show_check b u $TSTUSR
1858 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1859 lustre_fail mds 0xa04 $err_code
1861 # write in background
1862 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1866 # write should be blocked and never finished
1867 if ! ps -p $DDPID > /dev/null 2>&1; then
1869 quota_error u $TSTUSR "write finished incorrectly!"
1877 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1879 if [ $count -gt $timeout ]; then
1880 quota_error u $TSTUSR "dd is not finished!"
1885 sync; sync_all_data || true
1887 USED=$(getquota -u $TSTUSR global curspace)
1888 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1889 "Used space(${USED}K) is less than ${BLKS}M"
1894 # DQACQ return recoverable error
1896 echo "DQACQ return -ENOLCK"
1898 test_17sub 37 || error "Handle -ENOLCK failed"
1900 echo "DQACQ return -EAGAIN"
1902 test_17sub 11 || error "Handle -EAGAIN failed"
1904 echo "DQACQ return -ETIMEDOUT"
1905 #define ETIMEDOUT 110
1906 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1908 echo "DQACQ return -ENOTCONN"
1909 #define ENOTCONN 107
1910 test_17sub 107 || error "Handle -ENOTCONN failed"
1913 run_test 17 "DQACQ return recoverable error"
1917 local blimit="200m" # 200M
1918 local TESTFILE="$DIR/$tdir/$tfile"
1920 setup_quota_test || error "setup quota failed with $?"
1921 trap cleanup_quota_test EXIT
1923 set_ost_qtype "u" || error "enable ost quota failed"
1924 log "User quota (limit: $blimit)"
1925 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1926 error "set quota failed"
1927 quota_show_check b u $TSTUSR
1929 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1930 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1932 local timeout=$(sysctl -n lustre.timeout)
1934 if [ $io_type = "directio" ]; then
1935 log "Write 100M (directio) ..."
1936 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1938 log "Write 100M (buffered) ..."
1939 $RUNAS $DD of=$TESTFILE count=100 &
1943 replay_barrier $SINGLEMDS
1944 log "Fail mds for $((2 * timeout)) seconds"
1945 fail $SINGLEMDS $((2 * timeout))
1948 if at_is_enabled; then
1949 timeout=$(at_max_get mds)
1951 timeout=$(lctl get_param -n timeout)
1955 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1956 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1957 log "it took $count second"
1962 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1964 cancel_lru_locks mdc
1965 cancel_lru_locks osc
1968 local testfile_size=$(stat -c %s $TESTFILE)
1969 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1970 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1971 "got ${testfile_size}. Verifying file failed!"
1976 # test when mds does failover, the ost still could work well
1977 # this test shouldn't trigger watchdog b=14840
1979 # Clear dmesg so watchdog is not triggered by previous
1981 do_facet ost1 dmesg -c > /dev/null
1984 test_18_sub directio
1986 # check if watchdog is triggered
1987 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1988 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1989 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1990 [ -z "$watchdog" ] || error "$watchdog"
1991 rm -f $TMP/lustre-log-${TESTNAME}.log
1993 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1997 local TESTFILE=$DIR/$tdir/$tfile
1999 setup_quota_test || error "setup quota failed with $?"
2000 trap cleanup_quota_test EXIT
2002 set_ost_qtype $QTYPE || error "enable ost quota failed"
2004 # bind file to a single OST
2005 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2006 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2008 echo "Set user quota (limit: ${blimit}M)"
2009 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2010 error "set user quota failed"
2011 quota_show_check b u $TSTUSR
2012 echo "Update quota limits"
2013 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2014 error "set group quota failed"
2015 quota_show_check b u $TSTUSR
2017 # first wirte might be cached
2018 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2019 cancel_lru_locks osc
2021 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2022 quota_error u $TSTUSR "Write success, expect failure"
2027 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2029 test_20() { # b15754
2030 local LSTR=(2g 1t 4k 3m) # limits strings
2032 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2035 resetquota -u $TSTUSR
2037 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2038 $MOUNT || error "could not set quota limits"
2039 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2040 --inode-softlimit ${LSTR[2]} \
2041 --inode-hardlimit ${LSTR[3]} \
2042 $MOUNT || error "could not set quota limits"
2044 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2045 error "bsoftlimit was not set properly"
2046 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2047 error "bhardlimit was not set properly"
2048 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2049 error "isoftlimit was not set properly"
2050 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2051 error "ihardlimit was not set properly"
2053 resetquota -u $TSTUSR
2055 run_test 20 "Test if setquota specifiers work properly (b15754)"
2062 local time=$(($(date +%s) + seconds))
2063 while [ $(date +%s) -lt $time ]; do
2064 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2068 # run for fixing bug16053, setquota shouldn't fail when writing and
2069 # deleting are happening
2071 local TESTFILE="$DIR/$tdir/$tfile"
2072 local BLIMIT=10 # 10G
2073 local ILIMIT=1000000
2075 setup_quota_test || error "setup quota failed with $?"
2076 trap cleanup_quota_test EXIT
2078 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2080 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2081 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2082 error "set user quota failed"
2083 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2084 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2085 error "set group quota failed"
2086 if is_project_quota_supported; then
2087 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2088 "project: $TSTPRJID"
2089 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2090 $MOUNT || error "set project quota failed"
2093 # repeat writing on a 1M file
2094 test_21_sub ${TESTFILE}_1 1 30 &
2096 # repeat writing on a 128M file
2097 test_21_sub ${TESTFILE}_2 128 30 &
2100 local time=$(($(date +%s) + 30))
2102 while [ $(date +%s) -lt $time ]; do
2103 log "Set quota for $i times"
2104 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2105 -I $((ILIMIT + i)) $MOUNT ||
2106 error "Set user quota failed"
2107 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2108 -I $((ILIMIT + i)) $MOUNT ||
2109 error "Set group quota failed"
2110 if is_project_quota_supported; then
2111 $LFS setquota -p $TSTPRJID -b 0 -B \
2112 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2113 error "Set project quota failed"
2121 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2123 if [ $count -gt 60 ]; then
2124 quota_error a $TSTUSR "dd should be finished!"
2128 echo "(dd_pid=$DDPID1, time=$count)successful"
2132 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2134 if [ $count -gt 60 ]; then
2135 quota_error a $TSTUSR "dd should be finished!"
2139 echo "(dd_pid=$DDPID2, time=$count)successful"
2143 run_test 21 "Setquota while writing & deleting (b16053)"
2145 # enable/disable quota enforcement permanently
2147 echo "Set both mdt & ost quota type as ug"
2149 is_project_quota_supported && qtype=$QTYPE
2150 set_mdt_qtype $qtype || error "enable mdt quota failed"
2151 set_ost_qtype $qtype || error "enable ost quota failed"
2154 stopall || error "failed to stopall (1)"
2158 echo "Verify if quota is enabled"
2159 local qtype1=$(mdt_quota_type)
2160 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2161 qtype=$(ost_quota_type)
2162 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2164 echo "Set both mdt & ost quota type as none"
2165 set_mdt_qtype "none" || error "disable mdt quota failed"
2166 set_ost_qtype "none" || error "disable ost quota failed"
2169 stopall || error "failed to stopall (2)"
2174 echo "Verify if quota is disabled"
2175 qtype=$(mdt_quota_type)
2176 [ $qtype != "none" ] && error "mdt quota setting is lost"
2177 qtype=$(ost_quota_type)
2178 [ $qtype != "none" ] && error "ost quota setting is lost"
2182 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2185 local TESTFILE="$DIR/$tdir/$tfile"
2188 setup_quota_test || error "setup quota failed with $?"
2189 trap cleanup_quota_test EXIT
2191 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2194 log "User quota (limit: $LIMIT MB)"
2195 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2196 error "set quota failed"
2197 quota_show_check b u $TSTUSR
2199 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2200 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2202 log "Step1: trigger EDQUOT with O_DIRECT"
2203 log "Write half of file"
2204 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2205 quota_error u $TSTUSR "(1) Write failure, expect success." \
2207 log "Write out of block quota ..."
2208 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2209 oflag=direct conv=notrunc &&
2210 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2214 log "Step2: rewrite should succeed"
2215 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2216 quota_error u $TSTUSR "(3) Write failure, expect success." \
2222 local OST0_UUID=$(ostuuid_from_index 0)
2223 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2224 [ $OST0_QUOTA_USED -ne 0 ] &&
2225 ($SHOW_QUOTA_USER; \
2226 quota_error u $TSTUSR "quota isn't released")
2231 [ "$ost1_FSTYPE" == zfs ] &&
2232 skip "Overwrite in place is not guaranteed to be " \
2233 "space neutral on ZFS"
2235 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2236 check_whether_skip && return 0
2237 log "run for 4MB test file"
2240 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2241 check_whether_skip && return 0
2242 log "run for 40MB test file"
2245 run_test 23 "Quota should be honored with directIO (b16125)"
2249 local TESTFILE="$DIR/$tdir/$tfile"
2251 setup_quota_test || error "setup quota failed with $?"
2252 trap cleanup_quota_test EXIT
2254 set_ost_qtype $QTYPE || error "enable ost quota failed"
2256 # bind file to a single OST
2257 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2258 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2260 echo "Set user quota (limit: ${blimit}M)"
2261 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2262 error "set quota failed"
2264 # overrun quota by root user
2265 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2266 error "write failure, expect success"
2267 cancel_lru_locks osc
2268 sync_all_data || true
2270 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2274 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2276 test_27a() { # b19612
2277 $LFS quota $TSTUSR $DIR &&
2278 error "lfs succeeded with no type, but should have failed"
2279 $LFS setquota $TSTUSR $DIR &&
2280 error "lfs succeeded with no type, but should have failed"
2283 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2285 test_27b() { # b20200
2286 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2287 error "lfs setquota failed with uid argument"
2288 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2289 error "lfs stequota failed with gid argument"
2290 if is_project_quota_supported; then
2291 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2292 1000 $DIR || error \
2293 "lfs stequota failed with projid argument"
2295 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2296 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2297 if is_project_quota_supported; then
2298 $SHOW_QUOTA_PROJID ||
2299 error "lfs quota failed with projid argument"
2301 resetquota -u $TSTUSR
2302 resetquota -g $TSTUSR
2303 resetquota -p $TSTPRJID
2306 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2311 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2312 error "lfs setquota failed"
2314 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2315 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2316 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2317 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2319 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2320 error "lfs setquota for $TSTID failed"
2322 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2323 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2324 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2325 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2327 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2328 error "total allocated inode/block limit not printed"
2330 resetquota -u $TSTUSR
2332 run_test 27c "lfs quota should support human-readable output"
2339 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2340 error "set fraction block limit failed"
2341 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2342 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2343 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2344 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2346 resetquota -u $TSTUSR
2348 run_test 27d "lfs setquota should support fraction block limit"
2352 local TESTFILE="$DIR/$tdir/$tfile"
2355 setup_quota_test || error "setup quota failed with $?"
2356 trap cleanup_quota_test EXIT
2358 set_ost_qtype "u" || error "enable ost quota failed"
2360 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2361 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2363 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2364 $MAX_IQ_TIME $DIR || error "set grace time failed"
2365 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2366 error "set quota failed"
2367 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2368 cancel_lru_locks osc
2370 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2371 # over-quota flag has not yet settled since we do not trigger async
2372 # events based on grace time period expiration
2374 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2375 cancel_lru_locks osc
2376 # now over-quota flag should be settled and further writes should fail
2378 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2379 error "grace times were reset"
2382 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2383 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2385 run_test 30 "Hard limit updates should not reset grace times"
2387 # basic usage tracking for user & group
2389 local INODES=10 # 10 files
2390 local BLK_CNT=2 # of 2M each
2391 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2393 setup_quota_test || error "setup quota failed with $?"
2394 trap cleanup_quota_test EXIT
2396 # make sure the system is clean
2397 local USED=$(getquota -u $TSTID global curspace)
2399 error "Used space ($USED) for user $TSTID isn't 0."
2400 USED=$(getquota -g $TSTID global curspace)
2402 error "Used space ($USED) for group $TSTID isn't 0."
2403 if is_project_quota_supported; then
2404 USED=$(getquota -p $TSTPRJID global curspace)
2405 [ $USED -ne 0 ] && error \
2406 "Used space ($USED) for project $TSTPRJID isn't 0."
2409 echo "Write files..."
2410 for i in $(seq 0 $INODES); do
2411 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2412 error "write failed"
2413 is_project_quota_supported &&
2414 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2415 echo "Iteration $i/$INODES completed"
2417 cancel_lru_locks osc
2419 echo "Wait for setattr on objects finished..."
2420 wait_delete_completed
2422 sync; sync_all_data || true
2424 echo "Verify disk usage after write"
2425 USED=$(getquota -u $TSTID global curspace)
2426 [ $USED -lt $TOTAL_BLKS ] &&
2427 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2428 USED=$(getquota -g $TSTID global curspace)
2429 [ $USED -lt $TOTAL_BLKS ] &&
2430 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2431 if is_project_quota_supported; then
2432 USED=$(getquota -p $TSTPRJID global curspace)
2433 [ $USED -lt $TOTAL_BLKS ] && error \
2434 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2437 echo "Verify inode usage after write"
2438 USED=$(getquota -u $TSTID global curinodes)
2439 [ $USED -lt $INODES ] &&
2440 error "Used inode for user $TSTID is $USED, expected $INODES"
2441 USED=$(getquota -g $TSTID global curinodes)
2442 [ $USED -lt $INODES ] &&
2443 error "Used inode for group $TSTID is $USED, expected $INODES"
2444 if is_project_quota_supported; then
2445 USED=$(getquota -p $TSTPRJID global curinodes)
2446 [ $USED -lt $INODES ] && error \
2447 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2452 echo "Verify disk usage after delete"
2453 USED=$(getquota -u $TSTID global curspace)
2454 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2455 USED=$(getquota -u $TSTID global curinodes)
2456 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2457 USED=$(getquota -g $TSTID global curspace)
2458 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2459 USED=$(getquota -g $TSTID global curinodes)
2460 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2461 if is_project_quota_supported; then
2462 USED=$(getquota -p $TSTPRJID global curspace)
2464 error "Used space for project $TSTPRJID isn't 0. $USED"
2465 USED=$(getquota -p $TSTPRJID global curinodes)
2467 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2470 run_test 33 "Basic usage tracking for user & group & project"
2472 # usage transfer test for user & group & project
2474 local BLK_CNT=2 # 2MB
2475 local project_supported="no"
2477 is_project_quota_supported && project_supported="yes"
2478 setup_quota_test || error "setup quota failed with $?"
2479 trap cleanup_quota_test EXIT
2481 # make sure the system is clean
2482 local USED=$(getquota -u $TSTID global curspace)
2483 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2484 USED=$(getquota -g $TSTID global curspace)
2485 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2487 local USED=$(getquota -u $TSTID2 global curspace)
2488 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2489 if [ $project_supported == "yes" ]; then
2490 USED=$(getquota -p $TSTPRJID global curspace)
2491 [ $USED -ne 0 ] && error \
2492 "Used space ($USED) for Project $TSTPRJID isn't 0."
2495 echo "Write file..."
2496 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2497 error "write failed"
2498 cancel_lru_locks osc
2499 sync; sync_all_data || true
2501 echo "chown the file to user $TSTID"
2502 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2504 echo "Wait for setattr on objects finished..."
2505 wait_delete_completed
2507 BLK_CNT=$((BLK_CNT * 1024))
2509 echo "Verify disk usage for user $TSTID"
2510 USED=$(getquota -u $TSTID global curspace)
2511 [ $USED -lt $BLK_CNT ] &&
2512 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2513 USED=$(getquota -u $TSTID global curinodes)
2515 error "Used inodes for user $TSTID is $USED, expected 1"
2517 echo "chgrp the file to group $TSTID"
2518 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2520 echo "Wait for setattr on objects finished..."
2521 wait_delete_completed
2523 echo "Verify disk usage for group $TSTID"
2524 USED=$(getquota -g $TSTID global curspace)
2525 [ $USED -ge $BLK_CNT ] ||
2526 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2527 USED=$(getquota -g $TSTID global curinodes)
2529 error "Used inodes for group $TSTID is $USED, expected 1"
2531 # chown won't change the ost object group. LU-4345 */
2532 echo "chown the file to user $TSTID2"
2533 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2535 echo "Wait for setattr on objects finished..."
2536 wait_delete_completed
2538 echo "change_project project id to $TSTPRJID"
2539 [ $project_supported == "yes" ] &&
2540 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2541 echo "Wait for setattr on objects finished..."
2542 wait_delete_completed
2544 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2545 USED=$(getquota -u $TSTID2 global curspace)
2546 [ $USED -lt $BLK_CNT ] &&
2547 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2548 USED=$(getquota -u $TSTID global curspace)
2550 error "Used space for user $TSTID is $USED, expected 0"
2551 USED=$(getquota -g $TSTID global curspace)
2552 [ $USED -lt $BLK_CNT ] &&
2553 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2554 if [ $project_supported == "yes" ]; then
2555 USED=$(getquota -p $TSTPRJID global curspace)
2556 [ $USED -lt $BLK_CNT ] && error \
2557 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2562 run_test 34 "Usage transfer for user & group & project"
2564 # usage is still accessible across restart
2566 local BLK_CNT=2 # 2 MB
2568 setup_quota_test || error "setup quota failed with $?"
2569 trap cleanup_quota_test EXIT
2571 echo "Write file..."
2572 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2573 error "write failed"
2574 is_project_quota_supported &&
2575 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2576 cancel_lru_locks osc
2578 echo "Wait for setattr on objects finished..."
2579 wait_delete_completed
2581 sync; sync_all_data || true
2583 echo "Save disk usage before restart"
2584 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2585 [ $ORIG_USR_SPACE -eq 0 ] &&
2586 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2587 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2588 [ $ORIG_USR_INODES -eq 0 ] &&
2589 error "Used inodes for user $TSTID is 0, expected 1"
2590 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2591 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2592 [ $ORIG_GRP_SPACE -eq 0 ] &&
2593 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2594 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2595 [ $ORIG_GRP_INODES -eq 0 ] &&
2596 error "Used inodes for group $TSTID is 0, expected 1"
2597 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2599 if is_project_quota_supported; then
2600 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2601 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2602 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2603 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2604 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2605 "Used inodes for project $TSTPRJID is 0, expected 1"
2606 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2614 echo "Verify disk usage after restart"
2615 local USED=$(getquota -u $TSTID global curspace)
2616 [ $USED -eq $ORIG_USR_SPACE ] ||
2617 error "Used space for user $TSTID changed from " \
2618 "$ORIG_USR_SPACE to $USED"
2619 USED=$(getquota -u $TSTID global curinodes)
2620 [ $USED -eq $ORIG_USR_INODES ] ||
2621 error "Used inodes for user $TSTID changed from " \
2622 "$ORIG_USR_INODES to $USED"
2623 USED=$(getquota -g $TSTID global curspace)
2624 [ $USED -eq $ORIG_GRP_SPACE ] ||
2625 error "Used space for group $TSTID changed from " \
2626 "$ORIG_GRP_SPACE to $USED"
2627 USED=$(getquota -g $TSTID global curinodes)
2628 [ $USED -eq $ORIG_GRP_INODES ] ||
2629 error "Used inodes for group $TSTID changed from " \
2630 "$ORIG_GRP_INODES to $USED"
2631 if [ $project_supported == "yes" ]; then
2632 USED=$(getquota -p $TSTPRJID global curinodes)
2633 [ $USED -eq $ORIG_PRJ_INODES ] ||
2634 error "Used inodes for project $TSTPRJID " \
2635 "changed from $ORIG_PRJ_INODES to $USED"
2636 USED=$(getquota -p $TSTPRJID global curspace)
2637 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2638 error "Used space for project $TSTPRJID "\
2639 "changed from $ORIG_PRJ_SPACE to $USED"
2642 # check if the vfs_dq_init() is called before writing
2643 echo "Append to the same file..."
2644 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2645 error "write failed"
2646 cancel_lru_locks osc
2647 sync; sync_all_data || true
2649 echo "Verify space usage is increased"
2650 USED=$(getquota -u $TSTID global curspace)
2651 [ $USED -gt $ORIG_USR_SPACE ] ||
2652 error "Used space for user $TSTID isn't increased" \
2653 "orig:$ORIG_USR_SPACE, now:$USED"
2654 USED=$(getquota -g $TSTID global curspace)
2655 [ $USED -gt $ORIG_GRP_SPACE ] ||
2656 error "Used space for group $TSTID isn't increased" \
2657 "orig:$ORIG_GRP_SPACE, now:$USED"
2658 if [ $project_supported == "yes" ]; then
2659 USED=$(getquota -p $TSTPRJID global curspace)
2660 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2661 error "Used space for project $TSTPRJID isn't " \
2662 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2667 run_test 35 "Usage is still accessible across reboot"
2669 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2672 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
2673 skip "Old server doesn't have LU-5006 fix."
2675 setup_quota_test || error "setup quota failed with $?"
2676 trap cleanup_quota_test EXIT
2678 # make sure the system is clean
2679 local USED=$(getquota -u $TSTID global curspace)
2681 error "Used space ($USED) for user $TSTID isn't 0."
2683 # create file with MDS_OPEN_DELAY_CREATE flag
2684 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2685 error "Create file failed"
2687 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2688 oflag=sync || error "Write file failed"
2690 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2692 # wait for setattr on objects finished..."
2693 wait_delete_completed
2695 USED=$(getquota -u $TSTID global curspace)
2696 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2700 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2704 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
2705 skip "Old server doesn't have LU-8801 fix."
2707 [ "$UID" != 0 ] && skip_env "must run as root" && return
2709 setup_quota_test || error "setup quota failed with $?"
2710 trap cleanup_quota_test EXIT
2712 # make sure the system is clean
2713 local USED=$(getquota -u $TSTID global curspace)
2715 error "Used space ($USED) for user $TSTID isn't 0."
2716 USED=$(getquota -u $TSTID2 global curspace)
2718 error "Used space ($USED) for user $TSTID2 isn't 0."
2720 local TESTFILE="$DIR/$tdir/$tfile"
2721 local file_cnt=10000
2723 # Generate id entries in accounting file
2724 echo "Create $file_cnt files..."
2725 for i in `seq $file_cnt`; do
2727 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2728 error "failed to chown $TESTFILE-$i"
2730 cancel_lru_locks osc
2731 sync; sync_all_data || true
2733 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
2734 procf=${procf}.quota_slave.acct_user
2737 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2738 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2739 echo "Found $acct_cnt id entries"
2741 [ $file_cnt -eq $acct_cnt ] || {
2742 do_facet mds1 $LCTL get_param $procf
2743 error "skipped id entries"
2748 run_test 38 "Quota accounting iterator doesn't skip id entries"
2751 local TESTFILE="$DIR/$tdir/project"
2752 ! is_project_quota_supported &&
2753 skip "Project quota is not supported"
2755 setup_quota_test || error "setup quota failed with $?"
2758 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2759 [ $projectid -ne 0 ] &&
2760 error "Project id should be 0 not $projectid"
2761 change_project -p 1024 $TESTFILE
2762 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2763 [ $projectid -ne 1024 ] &&
2764 error "Project id should be 1024 not $projectid"
2766 stopall || error "failed to stopall (1)"
2769 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2770 [ $projectid -ne 1024 ] &&
2771 error "Project id should be 1024 not $projectid"
2775 run_test 39 "Project ID interface works correctly"
2778 ! is_project_quota_supported &&
2779 skip "Project quota is not supported"
2780 local dir1="$DIR/$tdir/dir1"
2781 local dir2="$DIR/$tdir/dir2"
2783 setup_quota_test || error "setup quota failed with $?"
2785 mkdir -p $dir1 $dir2
2786 change_project -sp 1 $dir1 && touch $dir1/1
2787 change_project -sp 2 $dir2
2789 ln $dir1/1 $dir2/1_link &&
2790 error "Hard link across different project quota should fail"
2795 run_test 40a "Hard link across different project ID"
2798 ! is_project_quota_supported &&
2799 skip "Project quota is not supported"
2800 local dir1="$DIR/$tdir/dir1"
2801 local dir2="$DIR/$tdir/dir2"
2803 setup_quota_test || error "setup quota failed with $?"
2804 mkdir -p $dir1 $dir2
2805 change_project -sp 1 $dir1 && touch $dir1/1
2806 change_project -sp 2 $dir2
2808 mv $dir1/1 $dir2/2 || error "mv failed $?"
2809 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2810 if [ "$projid" != "2" ]; then
2811 error "project id expected 2 not $projid"
2816 run_test 40b "Mv across different project ID"
2819 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2820 ! is_project_quota_supported &&
2821 skip "Project quota is not supported"
2823 setup_quota_test || error "setup quota failed with $?"
2824 local dir="$DIR/$tdir/dir"
2826 mkdir -p $dir && change_project -sp 1 $dir
2827 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2828 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2829 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2830 touch $dir/remote_dir/file
2831 #verify inherit works file for remote dir.
2832 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2833 [ "$projid" != "1" ] &&
2834 error "file under remote dir expected 1 not $projid"
2836 #Agent inode should be ignored for project quota
2837 USED=$(getquota -p 1 global curinodes)
2838 [ "$USED" != "3" ] &&
2839 error "file count expected 3 got $USED"
2845 run_test 40c "Remote child Dir inherit project quota properly"
2848 ! is_project_quota_supported &&
2849 skip "Project quota is not supported"
2851 setup_quota_test || error "setup quota failed with $?"
2852 local dir1="$DIR/$tdir/dir1"
2853 local dir2="$DIR/$tdir/dir2"
2855 mkdir -p $dir1 && change_project -sp 1 $dir1
2856 mkdir -p $dir2 && change_project -sp 2 $dir2
2857 for num in $(seq 1 10); do
2858 touch $dir1/file_$num $dir2/file_$num
2859 ln -s $dir1/file_$num $dir1/file_$num"_link"
2860 ln -s $dir2/file_$num $dir2/file_$num"_link"
2863 count=$($LFS find --projid 1 $DIR | wc -l)
2864 [ "$count" != 21 ] && error "expected 21 but got $count"
2866 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2867 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2868 [ "$count" != 22 ] && error "expected 22 but got $count"
2873 run_test 50 "Test if lfs find --projid works"
2876 ! is_project_quota_supported &&
2877 skip "Project quota is not supported"
2878 setup_quota_test || error "setup quota failed with $?"
2879 local dir="$DIR/$tdir/dir"
2881 mkdir $dir && change_project -sp 1 $dir
2882 local used=$(getquota -p 1 global curinodes)
2883 [ $used != "1" ] && error "expected 1 got $used"
2888 used=$(getquota -p 1 global curinodes)
2889 [ $used != "4" ] && error "expected 4 got $used"
2891 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2893 cp $DIR/$tdir/6 $dir/6
2894 used=$(getquota -p 1 global curinodes)
2895 [ $used != "5" ] && error "expected 5 got $used"
2898 mv $DIR/$tdir/6 $dir/7
2899 used=$(getquota -p 1 global curinodes)
2900 [ $used != "6" ] && error "expected 6 got $used"
2905 run_test 51 "Test project accounting with mv/cp"
2908 ! is_project_quota_supported &&
2909 skip "Project quota is not supported"
2910 setup_quota_test || error "setup quota failed with $?"
2911 local dir="$DIR/$tdir/dir"
2912 mkdir $dir && change_project -sp 1 $dir
2914 touch $DIR/$tdir/file
2915 #Try renaming a file into the project. This should fail.
2916 for num in $(seq 1 2000); do
2917 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2918 error "rename should fail"
2923 run_test 52 "Rename across different project ID"
2926 ! is_project_quota_supported &&
2927 skip "Project quota is not supported"
2928 setup_quota_test || error "setup quota failed with $?"
2929 local dir="$DIR/$tdir/dir"
2930 mkdir $dir && change_project -s $dir
2931 lfs project -d $dir | grep P || error "inherit attribute should be set"
2933 change_project -C $dir
2934 lfs project -d $dir | grep P &&
2935 error "inherit attribute should be cleared"
2940 run_test 53 "Project inherit attribute could be cleared"
2943 ! is_project_quota_supported &&
2944 skip "Project quota is not supported"
2945 setup_quota_test || error "setup quota failed with $?"
2946 trap cleanup_quota_test EXIT
2947 local testfile="$DIR/$tdir/$tfile-0"
2949 #set project ID/inherit attribute
2950 change_project -sp $TSTPRJID $DIR/$tdir
2951 $RUNAS createmany -m ${testfile} 100 ||
2952 error "create many files failed"
2954 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2955 # one more count for directory itself */
2959 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2960 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2962 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2963 [ $proj_count1 -eq $proj_count ] ||
2964 error "c2: expected $proj_count got $proj_count1"
2966 #clear project but with kept projid
2967 change_project -rCk $DIR/$tdir
2968 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2969 [ $proj_count1 -eq 1 ] ||
2970 error "c3: expected 1 got $proj_count1"
2972 #verify projid untouched.
2973 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2975 [ $proj_count1 -eq $proj_count ] ||
2976 error "c4: expected $proj_count got $proj_count1"
2979 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2980 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2981 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2983 #this time clear all
2984 change_project -rC $DIR/$tdir
2985 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2986 [ $proj_count1 -eq 0 ] ||
2987 error "c6: expected 0 got $proj_count1"
2989 unlinkmany ${testfile} 100 ||
2990 error "unlink many files failed"
2994 run_test 54 "basic lfs project interface test"
2997 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
2998 skip "Not supported before 2.10.58."
2999 setup_quota_test || error "setup quota failed with $?"
3001 set_ost_qtype $QTYPE || error "enable ost quota failed"
3004 #add second group to TSTUSR
3005 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3008 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3009 error "failed to dd"
3011 cancel_lru_locks osc
3012 sync; sync_all_data || true
3014 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3015 error "failed to setquota on group $TSTUSR2"
3017 $LFS quota -v -g $TSTUSR2 $DIR
3019 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3020 error "chgrp should failed with -EDQUOT"
3022 USED=$(getquota -g $TSTUSR2 global curspace)
3025 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3026 error "failed to setquota on group $TSTUSR2"
3028 $LFS quota -v -g $TSTUSR2 $DIR
3030 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3031 error "chgrp should succeed"
3033 $LFS quota -v -g $TSTUSR2 $DIR
3037 run_test 55 "Chgrp should be affected by group quota"
3040 setup_quota_test || error "setup quota failed with $?"
3042 set_ost_qtype $QTYPE || error "enable ost quota failed"
3045 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3046 erro "failed to set grace time for usr quota"
3047 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3048 awk '{print $4 $8}')
3049 if [ "x$grace_time" != "x10s;10s" ]; then
3050 $LFS quota -t -u $DIR
3051 error "expected grace time: 10s;10s, got:$grace_time"
3056 run_test 56 "lfs quota -t should work well"
3059 setup_quota_test || error "setup quota failed with $?"
3061 local dir="$DIR/$tdir/dir"
3064 #try to change pipe file should not hang and return failure
3065 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3066 awk -F ':' '{ print \\\$2 }'" \
3067 " unable to get xattr for fifo '$dir/pipe'" || return 1
3068 #command can process further if it hit some errors
3069 touch $dir/aaa $dir/bbb
3070 mkdir $dir/subdir -p
3071 touch $dir/subdir/aaa $dir/subdir/bbb
3072 #create one invalid link file
3073 ln -s $dir/not_exist_file $dir/ccc
3074 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3075 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3079 run_test 57 "lfs project could tolerate errors"
3082 [ "$mds1_FSTYPE" != ldiskfs ] &&
3083 skip "ldiskfs only test"
3084 disable_project_quota
3085 setup_quota_test || error "setup quota failed with $?"
3088 local testfile="$DIR/$tdir/$tfile-0"
3089 #make sure it did not crash kernel
3090 touch $testfile && lfs project -sp 1 $testfile
3092 enable_project_quota
3095 run_test 59 "lfs project dosen't crash kernel with project disabled"
3098 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3099 skip "Needs MDS version 2.11.53 or later."
3100 setup_quota_test || error "setup quota failed with $?"
3101 trap cleanup_quota_test EXIT
3103 local testfile=$DIR/$tdir/$tfile
3106 set_mdt_qtype "ug" || error "enable mdt quota failed"
3108 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3109 error "set quota failed"
3110 quota_show_check a g $TSTUSR
3112 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3113 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3114 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3115 error "create many files failed"
3117 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3119 # root user can overrun quota
3120 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3121 error "root user should succeed"
3125 run_test 60 "Test quota for root with setgid"
3127 # test default quota
3128 test_default_quota() {
3129 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3130 skip "Not supported before 2.11.51."
3135 local qprjid=$TSTPRJID
3139 local LIMIT=20480 #20M disk space
3140 local TESTFILE="$DIR/$tdir/$tfile-0"
3142 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3143 echo "Project quota is not supported" && return 0
3145 [ $qtype == "-u" ] && qdtype="-U"
3146 [ $qtype == "-g" ] && qdtype="-G"
3147 [ $qtype == "-p" ] && {
3152 [ $qpool == "meta" ] && {
3153 LIMIT=10240 #10K inodes
3158 setup_quota_test || error "setup quota failed with $?"
3159 trap cleanup_quota_test EXIT
3163 # enable mdt/ost quota
3164 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3165 set_ost_qtype $QTYPE || error "enable ost quota failed"
3167 log "set to use default quota"
3168 $LFS setquota $qtype $qid -d $DIR ||
3169 error "set $qid to use default quota failed"
3171 log "set default quota"
3172 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3173 error "set $qid default quota failed"
3175 log "get default quota"
3176 $LFS quota $qdtype $DIR || error "get default quota failed"
3178 if [ $qpool == "data" ]; then
3179 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3181 [ $SLIMIT -eq $LIMIT ] ||
3182 error "the returned default quota is wrong"
3184 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3186 [ $SLIMIT -eq $LIMIT ] ||
3187 error "the returned default quota is wrong"
3190 # make sure the system is clean
3191 local USED=$(getquota $qtype $qid global curspace)
3192 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3194 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3195 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3197 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3199 log "Test not out of quota"
3200 if [ $qpool == "data" ]; then
3201 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3202 quota_error $qtype $qid "write failed, expect succeed"
3204 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3205 quota_error $qtype $qid "create failed, expect succeed"
3207 unlinkmany $TESTFILE $((LIMIT/2))
3210 log "Test out of quota"
3211 # flush cache, ensure noquota flag is set on client
3212 cancel_lru_locks osc
3213 cancel_lru_locks mdc
3214 sync; sync_all_data || true
3215 if [ $qpool == "data" ]; then
3216 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3217 quota_error $qtype $qid "write succeed, expect EDQUOT"
3219 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3220 quota_error $qtype $qid "create succeed, expect EDQUOT"
3222 unlinkmany $TESTFILE $((LIMIT*2))
3225 log "Increase default quota"
3226 # increase default quota
3227 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3228 error "set default quota failed"
3230 cancel_lru_locks osc
3231 cancel_lru_locks mdc
3232 sync; sync_all_data || true
3233 if [ $qpool == "data" ]; then
3234 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3235 quota_error $qtype $qid "write failed, expect succeed"
3237 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3238 quota_error $qtype $qid "create failed, expect succeed"
3240 unlinkmany $TESTFILE $((LIMIT*2))
3243 log "Set quota to override default quota"
3244 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3245 error "set $qid quota failed"
3247 cancel_lru_locks osc
3248 cancel_lru_locks mdc
3249 sync; sync_all_data || true
3250 if [ $qpool == "data" ]; then
3251 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3252 quota_error $qtype $qid "write succeed, expect EQUOT"
3254 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3255 quota_error $qtype $qid "create succeed, expect EQUOT"
3257 unlinkmany $TESTFILE $((LIMIT*2))
3260 log "Set to use default quota again"
3261 $LFS setquota $qtype $qid -d $DIR ||
3262 error "set $qid to use default quota failed"
3264 cancel_lru_locks osc
3265 cancel_lru_locks mdc
3266 sync; sync_all_data || true
3267 if [ $qpool == "data" ]; then
3268 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3269 quota_error $qtype $qid "write failed, expect succeed"
3271 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3272 quota_error $qtype $qid "create failed, expect succeed"
3274 unlinkmany $TESTFILE $((LIMIT*2))
3279 wait_delete_completed || error "wait_delete_completed failed"
3280 sync_all_data || true
3281 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3282 error "reset default quota failed"
3283 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3284 error "reset quota failed"
3290 test_default_quota "-u" "data"
3291 test_default_quota "-u" "meta"
3292 test_default_quota "-g" "data"
3293 test_default_quota "-g" "meta"
3294 test_default_quota "-p" "data"
3295 test_default_quota "-p" "meta"
3297 run_test 61 "default quota tests"
3300 ! is_project_quota_supported &&
3301 skip "Project quota is not supported"
3302 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3303 skip "chattr did not support project quota"
3304 setup_quota_test || error "setup quota failed with $?"
3305 local testdir=$DIR/$tdir/
3307 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3308 change_project -s $testdir
3309 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3310 error "inherit attribute should be set"
3311 # chattr used FS_IOC_SETFLAGS ioctl
3312 $RUNAS chattr -P $testdir &&
3313 error "regular user clear inherit should fail"
3314 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3315 error "inherit attribute should still be set"
3316 chattr -P $testdir || error "root failed to clear inherit"
3317 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3318 error "inherit attribute should be cleared"
3321 run_test 62 "Project inherit should be only changed by root"
3324 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3325 skip "Not supported before 2.11.55"
3329 local dd_failed=false
3330 local tdir_dom=${tdir}_dom
3331 local LIMIT=20480 #20M
3333 [ $qtype == "p" ] && ! is_project_quota_supported &&
3334 echo "Project quota is not supported" && return 0
3336 [ $qtype == "p" ] && qid=$TSTPRJID
3338 setup_quota_test || error "setup quota failed with $?"
3339 trap cleanup_quota_test EXIT
3343 # enable mdt/ost quota
3344 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3345 set_ost_qtype $QTYPE || error "enable ost quota failed"
3347 # make sure the system is clean
3348 local USED=$(getquota -$qtype $qid global curspace)
3349 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3351 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3353 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3354 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3355 error "setstripe $tdir_dom failed"
3356 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3358 [ $qtype == "p" ] && {
3359 change_project -sp $TSTPRJID $DIR/$tdir
3360 change_project -sp $TSTPRJID $DIR/$tdir_dom
3363 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3364 error "set $qid quota failed"
3366 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3367 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3371 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3373 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3374 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3378 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3380 rm -f $DIR/$tdir_dom/*
3382 # flush cache, ensure noquota flag is set on client
3383 cancel_lru_locks osc
3384 cancel_lru_locks mdc
3385 sync; sync_all_data || true
3389 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3390 quota_error $qtype $qid "write failed, expect succeed"
3392 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3393 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3397 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3400 rm -f $DIR/$tdir_dom/*
3402 # flush cache, ensure noquota flag is set on client
3403 cancel_lru_locks osc
3404 cancel_lru_locks mdc
3405 sync; sync_all_data || true
3409 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3410 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3414 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3416 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3417 quota_error $qtype $qid "write succeed, expect EDQUOT"
3420 rm -fr $DIR/$tdir_dom
3422 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3423 error "reset usr quota failed"
3433 run_test 63 "quota on DoM tests"
3436 ! is_project_quota_supported &&
3437 skip "Project quota is not supported"
3438 setup_quota_test || error "setup quota failed with $?"
3439 local dir1="$DIR/$tdir/"
3442 ln -s $dir1/file $dir1/file_link
3444 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3445 error "set symlink file's project should fail"
3447 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3448 error "get symlink file's project should fail"
3452 run_test 64 "lfs project on symlink files should fail"
3456 local TESTFILE="$DIR/$tdir/$tfile-0"
3458 setup_quota_test || error "setup quota failed with $?"
3459 set_ost_qtype $QTYPE || error "enable ost quota failed"
3463 $RUNAS $DD of=$TESTFILE count=$SIZE ||
3464 error "failed to write"
3465 # flush cache, ensure noquota flag is set on client
3466 cancel_lru_locks osc
3467 sync; sync_all_data || true
3469 local quota_u=$($LFS quota -u $TSTUSR $DIR)
3470 local quota_g=$($LFS quota -g $TSTUSR $DIR)
3471 local quota_all=$($RUNAS $LFS quota $DIR)
3473 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
3474 error "usr quota not match"
3475 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
3476 error "grp quota not match"
3482 run_test 65 "Check lfs quota result"
3486 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3487 if $PQ_CLEANUP; then
3488 disable_project_quota
3491 reset_quota_settings
3496 check_and_cleanup_lustre
3497 export QUOTA_AUTO=$QUOTA_AUTO_OLD