- lbunit = &lqs->lqs_bunit_sz;
- liunit = &lqs->lqs_iunit_sz;
- lbtune = &lqs->lqs_btune_sz;
- litune = &lqs->lqs_itune_sz;
-
- CDEBUG(D_QUOTA, "before: bunit: %lu, iunit: %lu.\n", *lbunit, *liunit);
- spin_lock(&lqs->lqs_lock);
- /* adjust the slave's block qunit size */
- if (QAQ_IS_ADJBLK(oqaq)) {
- cfs_duration_t sec = cfs_time_seconds(qctxt->lqc_switch_seconds);
-
- b_tmp = *lbunit - oqaq->qaq_bunit_sz;
-
- if (qctxt->lqc_handler && b_tmp > 0)
- lqs->lqs_last_bshrink = cfs_time_current();
-
- if (qctxt->lqc_handler && b_tmp < 0) {
- time_limit = cfs_time_add(lqs->lqs_last_bshrink, sec);
- if (!lqs->lqs_last_bshrink ||
- cfs_time_after(cfs_time_current(), time_limit)) {
- *lbunit = oqaq->qaq_bunit_sz;
- *lbtune = (*lbunit) / 2;
- } else {
- b_tmp = 0;
- }
- } else {
- *lbunit = oqaq->qaq_bunit_sz;
- *lbtune = (*lbunit) / 2;
+ tmp = i ? (lqs->lqs_iunit_sz - oqaq->qaq_iunit_sz) :
+ (lqs->lqs_bunit_sz - oqaq->qaq_bunit_sz);
+ shrink = i ? &lqs->lqs_last_ishrink :
+ &lqs->lqs_last_bshrink;
+ time_limit = cfs_time_add(i ? lqs->lqs_last_ishrink :
+ lqs->lqs_last_bshrink,
+ cfs_time_seconds(qctxt->lqc_switch_seconds));
+ unit = i ? &lqs->lqs_iunit_sz : &lqs->lqs_bunit_sz;
+ tune = i ? &lqs->lqs_itune_sz : &lqs->lqs_btune_sz;
+
+ /* quota master shrinks */
+ if (qctxt->lqc_handler && tmp > 0)
+ *shrink = cfs_time_current();
+
+ /* quota master enlarges */
+ if (qctxt->lqc_handler && tmp < 0) {
+ /* in case of ping-pong effect, don't enlarge lqs
+ * in a short time */
+ if (*shrink &&
+ cfs_time_before(cfs_time_current(), time_limit))
+ tmp = 0;