+/* Apply the default quota setting to the specified quota entry
+ *
+ * \param env - is the environment passed by the caller
+ * \param pool - is the quota pool of the quota entry
+ * \param lqe - is the lquota_entry object to apply default quota on
+ * \param create_record - if true, an global quota record will be created and
+ * write to the disk.
+ *
+ * \retval 0 : success
+ * \retval -ve : other appropriate errors
+ */
+int qmt_lqe_set_default(const struct lu_env *env, struct qmt_pool_info *pool,
+ struct lquota_entry *lqe, bool create_record)
+{
+ struct lquota_entry *lqe_def;
+ int rc = 0;
+
+ ENTRY;
+
+ if (lqe->lqe_id.qid_uid == 0)
+ RETURN(0);
+
+ lqe_def = pool->qpi_grace_lqe[lqe->lqe_site->lqs_qtype];
+
+ LQUOTA_DEBUG(lqe, "inherit default quota");
+
+ lqe->lqe_is_default = true;
+ lqe->lqe_hardlimit = lqe_def->lqe_hardlimit;
+ lqe->lqe_softlimit = lqe_def->lqe_softlimit;
+
+ if (create_record) {
+ lqe->lqe_uptodate = true;
+ rc = qmt_set_with_lqe(env, pool->qpi_qmt, lqe, 0, 0,
+ LQUOTA_GRACE_FLAG(0, LQUOTA_FLAG_DEFAULT),
+ QIF_TIMES, true, false);
+
+ if (rc != 0)
+ LQUOTA_ERROR(lqe, "failed to create the global quota"
+ " record: %d", rc);
+ }
+
+ if (lqe->lqe_hardlimit == 0 && lqe->lqe_softlimit == 0)
+ lqe->lqe_enforced = false;
+ else
+ lqe->lqe_enforced = true;
+
+ RETURN(rc);
+}
+