Whamcloud - gitweb
LU-12758 quota: clear default flag for new ID
[fs/lustre-release.git] / lustre / quota / qmt_handler.c
index 4621682..9d2a4cc 100644 (file)
@@ -38,7 +38,6 @@
  *
  * \param env     - is the environment passed by the caller
  * \param qmt     - is the quota master target
- * \param pool_id - is the 16-bit pool identifier
  * \param restype - is the pool type, either block (i.e. LQUOTA_RES_DT) or inode
  *                  (i.e. LQUOTA_RES_MD)
  * \param qtype   - is the quota type
@@ -49,7 +48,7 @@
  * \param time    - is the output variable where to copy the grace time
  */
 static int qmt_get(const struct lu_env *env, struct qmt_device *qmt,
-                  __u16 pool_id, __u8 restype, __u8 qtype, union lquota_id *id,
+                  __u8 restype, __u8 qtype, union lquota_id *id,
                   __u64 *hard, __u64 *soft, __u64 *time, bool is_default)
 {
        struct lquota_entry     *lqe;
@@ -58,7 +57,7 @@ static int qmt_get(const struct lu_env *env, struct qmt_device *qmt,
        LASSERT(!is_default || id->qid_uid == 0);
 
        /* look-up lqe structure containing quota settings */
-       lqe = qmt_pool_lqe_lookup(env, qmt, pool_id, restype, qtype, id);
+       lqe = qmt_pool_lqe_lookup(env, qmt, restype, qtype, id);
        if (IS_ERR(lqe))
                RETURN(PTR_ERR(lqe));
 
@@ -192,15 +191,16 @@ quota_set:
                dirtied = true;
        }
 
-       if (dirtied) {
-               if (!is_default && lqe->lqe_is_default) {
-                       LQUOTA_DEBUG(lqe, "the qid %llu has been set quota"
-                                    " explicitly, clear the default flag",
-                                    lqe->lqe_id.qid_uid);
+       if (!is_default && lqe->lqe_is_default) {
+               LQUOTA_DEBUG(lqe, "the qid %llu has been set quota"
+                            " explicitly, clear the default flag",
+                            lqe->lqe_id.qid_uid);
 
-                       qmt_lqe_clear_default(lqe);
-               }
+               qmt_lqe_clear_default(lqe);
+               dirtied = true;
+       }
 
+       if (dirtied) {
                if (!is_updated) {
                        /* write new quota settings to disk */
                        rc = qmt_glb_write(env, th, lqe, LQUOTA_BUMP_VER, &ver);
@@ -209,6 +209,8 @@ quota_set:
                                qmt_restore(lqe, &qti->qti_restore);
                                GOTO(out, rc);
                        }
+               } else {
+                       ver = dt_version_get(env, LQE_GLB_OBJ(lqe));
                }
 
                /* compute new qunit value now that we have modified the quota
@@ -247,7 +249,6 @@ out_nolock:
  *
  * \param env        - is the environment passed by the caller
  * \param qmt        - is the quota master target
- * \param pool_id    - is the 16-bit pool identifier
  * \param restype    - is the pool type, either block (i.e. LQUOTA_RES_DT) or
  *                     inode (i.e. LQUOTA_RES_MD)
  * \param qtype      - is the quota type
@@ -261,16 +262,16 @@ out_nolock:
  * \param is_updated - true if the lqe is updated and no need to write back
  */
 static int qmt_set(const struct lu_env *env, struct qmt_device *qmt,
-                  __u16 pool_id, __u8 restype, __u8 qtype,
-                  union lquota_id *id, __u64 hard, __u64 soft, __u64 time,
-                  __u32 valid, bool is_default, bool is_updated)
+                  __u8 restype, __u8 qtype, union lquota_id *id,
+                  __u64 hard, __u64 soft, __u64 time, __u32 valid,
+                  bool is_default, bool is_updated)
 {
        struct lquota_entry *lqe;
        int rc;
        ENTRY;
 
        /* look-up quota entry associated with this ID */
-       lqe = qmt_pool_lqe_lookup(env, qmt, pool_id, restype, qtype, id);
+       lqe = qmt_pool_lqe_lookup(env, qmt, restype, qtype, id);
        if (IS_ERR(lqe))
                        RETURN(PTR_ERR(lqe));
 
@@ -312,13 +313,13 @@ static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
                id->qid_uid = 0;
 
                /* read inode grace time */
-               rc = qmt_get(env, qmt, 0, LQUOTA_RES_MD, oqctl->qc_type, id,
+               rc = qmt_get(env, qmt, LQUOTA_RES_MD, oqctl->qc_type, id,
                             NULL, NULL, &oqctl->qc_dqinfo.dqi_igrace, false);
                if (rc)
                        break;
 
                /* read block grace time */
-               rc = qmt_get(env, qmt, 0, LQUOTA_RES_DT, oqctl->qc_type, id,
+               rc = qmt_get(env, qmt, LQUOTA_RES_DT, oqctl->qc_type, id,
                             NULL, NULL, &oqctl->qc_dqinfo.dqi_bgrace, false);
                break;
 
@@ -332,7 +333,7 @@ static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
 
                if ((dqb->dqb_valid & QIF_ITIME) != 0) {
                        /* set inode grace time */
-                       rc = qmt_set(env, qmt, 0, LQUOTA_RES_MD, oqctl->qc_type,
+                       rc = qmt_set(env, qmt, LQUOTA_RES_MD, oqctl->qc_type,
                                     id, 0, 0, oqctl->qc_dqinfo.dqi_igrace,
                                     QIF_TIMES, false, false);
                        if (rc)
@@ -341,20 +342,21 @@ static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
 
                if ((dqb->dqb_valid & QIF_BTIME) != 0)
                        /* set block grace time */
-                       rc = qmt_set(env, qmt, 0, LQUOTA_RES_DT, oqctl->qc_type,
+                       rc = qmt_set(env, qmt, LQUOTA_RES_DT, oqctl->qc_type,
                                     id, 0, 0, oqctl->qc_dqinfo.dqi_bgrace,
                                     QIF_TIMES, false, false);
                break;
 
        case LUSTRE_Q_GETDEFAULT:
                is_default = true;
+               /* fallthrough */
 
        case Q_GETQUOTA: /* consult quota limit */
                /* extract quota ID from quotactl request */
                id->qid_uid = oqctl->qc_id;
 
                /* look-up inode quota settings */
-               rc = qmt_get(env, qmt, 0, LQUOTA_RES_MD, oqctl->qc_type, id,
+               rc = qmt_get(env, qmt, LQUOTA_RES_MD, oqctl->qc_type, id,
                             &dqb->dqb_ihardlimit, &dqb->dqb_isoftlimit,
                             &dqb->dqb_itime, is_default);
                if (rc)
@@ -365,7 +367,7 @@ static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
                dqb->dqb_curinodes = 0;
 
                /* look-up block quota settings */
-               rc = qmt_get(env, qmt, 0, LQUOTA_RES_DT, oqctl->qc_type, id,
+               rc = qmt_get(env, qmt, LQUOTA_RES_DT, oqctl->qc_type, id,
                             &dqb->dqb_bhardlimit, &dqb->dqb_bsoftlimit,
                             &dqb->dqb_btime, is_default);
                if (rc)
@@ -378,6 +380,7 @@ static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
 
        case LUSTRE_Q_SETDEFAULT:
                is_default = true;
+               /* fallthrough */
 
        case Q_SETQUOTA: /* change quota limits */
                /* extract quota ID from quotactl request */
@@ -385,7 +388,7 @@ static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
 
                if ((dqb->dqb_valid & QIF_IFLAGS) != 0) {
                        /* update inode quota settings */
-                       rc = qmt_set(env, qmt, 0, LQUOTA_RES_MD, oqctl->qc_type,
+                       rc = qmt_set(env, qmt, LQUOTA_RES_MD, oqctl->qc_type,
                                     id, dqb->dqb_ihardlimit,
                                     dqb->dqb_isoftlimit, dqb->dqb_itime,
                                     dqb->dqb_valid & QIF_IFLAGS, is_default,
@@ -396,7 +399,7 @@ static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
 
                if ((dqb->dqb_valid & QIF_BFLAGS) != 0)
                        /* update block quota settings */
-                       rc = qmt_set(env, qmt, 0, LQUOTA_RES_DT, oqctl->qc_type,
+                       rc = qmt_set(env, qmt, LQUOTA_RES_DT, oqctl->qc_type,
                                     id, dqb->dqb_bhardlimit,
                                     dqb->dqb_bsoftlimit, dqb->dqb_btime,
                                     dqb->dqb_valid & QIF_BFLAGS, is_default,
@@ -676,7 +679,7 @@ static int qmt_dqacq(const struct lu_env *env, struct lu_device *ld,
        struct obd_uuid         *uuid;
        struct ldlm_lock        *lock;
        struct lquota_entry     *lqe;
-       int                      pool_id, pool_type, qtype;
+       int                      pool_type, qtype;
        int                      rc;
        ENTRY;
 
@@ -741,14 +744,14 @@ static int qmt_dqacq(const struct lu_env *env, struct lu_device *ld,
                LDLM_LOCK_PUT(lock);
        }
 
-       /* extract pool & quota information from global index FID packed in the
+       /* extract quota information from global index FID packed in the
         * request */
-       rc = lquota_extract_fid(&qbody->qb_fid, &pool_id, &pool_type, &qtype);
+       rc = lquota_extract_fid(&qbody->qb_fid, &pool_type, &qtype);
        if (rc)
                RETURN(-EINVAL);
 
        /* Find the quota entry associated with the quota id */
-       lqe = qmt_pool_lqe_lookup(env, qmt, pool_id, pool_type, qtype,
+       lqe = qmt_pool_lqe_lookup(env, qmt, pool_type, qtype,
                                  &qbody->qb_id);
        if (IS_ERR(lqe))
                RETURN(PTR_ERR(lqe));