+
+/*
+ * Wrapper for qsd_op_begin().
+ *
+ * \param env - the environment passed by the caller
+ * \param osd - is the osd_device
+ * \param uid - user id of the inode
+ * \param gid - group id of the inode
+ * \param projid - project id of the inode
+ * \param space - how many blocks/inodes will be consumed/released
+ * \param oh - osd transaction handle
+ * \param flags - if the operation is write, return no user quota, no
+ * group quota, or sync commit flags to the caller
+ * \param osd_qid_declare_flags - indicate this is a inode/block accounting
+ * and whether changes are performed by root user
+ *
+ * \retval 0 - success
+ * \retval -ve - failure
+ */
+int osd_declare_quota(const struct lu_env *env, struct osd_device *osd,
+ qid_t uid, qid_t gid, qid_t projid, long long space,
+ struct osd_thandle *oh,
+ enum osd_quota_local_flags *local_flags,
+ enum osd_qid_declare_flags osd_qid_declare_flags)
+{
+ struct osd_thread_info *info = osd_oti_get(env);
+ struct lquota_id_info *qi = &info->oti_qi;
+ struct qsd_instance *qsd = NULL;
+ int rcu, rcg, rcp = 0; /* user & group & project rc */
+ struct thandle *th = &oh->ot_super;
+ bool force = !!(osd_qid_declare_flags & OSD_QID_FORCE) ||
+ th->th_ignore_quota;
+ ENTRY;
+
+ if (osd_qid_declare_flags & OSD_QID_INODE)
+ qsd = osd->od_quota_slave_md;
+ else if (osd_qid_declare_flags & OSD_QID_BLK)
+ qsd = osd->od_quota_slave_dt;
+ else
+ RETURN(0);
+
+ if (unlikely(qsd == NULL))
+ /* quota slave instance hasn't been allocated yet */
+ RETURN(0);
+
+ /* let's start with user quota */
+ qi->lqi_id.qid_uid = uid;
+ qi->lqi_type = USRQUOTA;
+ qi->lqi_space = space;
+ qi->lqi_is_blk = !!(osd_qid_declare_flags & OSD_QID_BLK);
+ rcu = qsd_op_begin(env, qsd, &oh->ot_quota_trans, qi, local_flags);
+ if (force && (rcu == -EDQUOT || rcu == -EINPROGRESS))
+ /* ignore EDQUOT & EINPROGRESS when changes are done by root */
+ rcu = 0;
+
+ /* For non-fatal error, we want to continue to get the noquota flags
+ * for group id. This is only for commit write, which has @flags passed
+ * in. See osd_declare_write_commit().
+ * When force is set to true, we also want to proceed with the gid */
+ if (rcu && (rcu != -EDQUOT || local_flags == NULL))
+ RETURN(rcu);
+
+ /* and now group quota */
+ qi->lqi_id.qid_gid = gid;
+ qi->lqi_type = GRPQUOTA;
+ rcg = qsd_op_begin(env, qsd, &oh->ot_quota_trans, qi, local_flags);
+ if (force && (rcg == -EDQUOT || rcg == -EINPROGRESS))
+ /* as before, ignore EDQUOT & EINPROGRESS for root */
+ rcg = 0;
+
+#ifdef ZFS_PROJINHERIT
+ if (rcg && (rcg != -EDQUOT || local_flags == NULL))
+ RETURN(rcg);
+
+ /* for project quota */
+ if (osd->od_projectused_dn) {
+ qi->lqi_id.qid_projid = projid;
+ qi->lqi_type = PRJQUOTA;
+ rcp = qsd_op_begin(env, qsd, &oh->ot_quota_trans, qi,
+ local_flags);
+ if (force && (rcp == -EDQUOT || rcp == -EINPROGRESS))
+ rcp = 0;
+ }
+#endif
+
+ RETURN(rcu ? rcu : (rcg ? rcg : rcp));
+}