+/* Using least_qunit when over block softlimit will seriously impact the
+ * write performance, we need to do some special tweaking on that. */
+static __u64 qmt_calc_softlimit(struct lquota_entry *lqe, bool *oversoft)
+{
+ struct qmt_pool_info *pool = lqe2qpi(lqe);
+
+ LASSERT(lqe->lqe_softlimit != 0);
+ *oversoft = false;
+ /* No need to do special tweaking for inode limit */
+ if (pool->qpi_key >> 16 == LQUOTA_RES_MD)
+ return lqe->lqe_softlimit;
+
+ /* Added (least_qunit * 4) as margin */
+ if (lqe->lqe_granted <= lqe->lqe_softlimit +
+ (pool->qpi_least_qunit << 2)) {
+ return lqe->lqe_softlimit;
+ } else if (lqe->lqe_hardlimit != 0) {
+ *oversoft = true;
+ return lqe->lqe_hardlimit;
+ } else {
+ *oversoft = true;
+ return 0;
+ }
+}
+