Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / quota / quota_interface.c
index 60d7038..dff4ce4 100644 (file)
@@ -252,13 +252,12 @@ static int filter_quota_getflag(struct obd_device *obd, struct obdo *oa)
  * check whether the left quota of certain uid and gid can satisfy a block_write
  * or inode_create rpc. When need to acquire quota, return QUOTA_RET_ACQUOTA
  */
-static int quota_check_common(struct obd_device *obd, unsigned int uid,
-                              unsigned int gid, int count, int cycle, int isblk,
-                              struct inode *inode, int frags, int *pending)
+static int quota_check_common(struct obd_device *obd, const unsigned int id[],
+                              int pending[], int count, int cycle, int isblk,
+                              struct inode *inode, int frags)
 {
         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
         int i;
-        __u32 id[MAXQUOTAS] = { uid, gid };
         struct qunit_data qdata[MAXQUOTAS];
         int mb = 0;
         int rc = 0, rc2[2] = { 0, 0 };
@@ -292,16 +291,24 @@ static int quota_check_common(struct obd_device *obd, unsigned int uid,
                 if (!lqs)
                         continue;
 
+                if (IS_ERR(lqs)) {
+                        CERROR("can not find lqs for check_common: "
+                               "[id %u] [%c] [isblk %d] [count %d] [rc %ld]\n",
+                               id[i], i % 2 ? 'g': 'u', isblk, count,
+                               PTR_ERR(lqs));
+                        RETURN(PTR_ERR(lqs));
+                }
+
                 rc2[i] = compute_remquota(obd, qctxt, &qdata[i], isblk);
                 spin_lock(&lqs->lqs_lock);
                 if (!cycle) {
                         if (isblk) {
-                                *pending = count * CFS_PAGE_SIZE;
+                                pending[i] = count * CFS_PAGE_SIZE;
                                 /* in order to complete this write, we need extra
                                  * meta blocks. This function can get it through
                                  * data needed to be written b=16542 */
                                 if (inode) {
-                                        mb = *pending;
+                                        mb = pending[i];
                                         rc = fsfilt_get_mblk(obd, qctxt->lqc_sb,
                                                              &mb, inode,frags);
                                         if (rc)
@@ -309,12 +316,12 @@ static int quota_check_common(struct obd_device *obd, unsigned int uid,
                                                        "can't get extra "
                                                        "meta blocks.\n");
                                         else
-                                                *pending += mb;
+                                                pending[i] += mb;
                                 }
-                                lqs->lqs_bwrite_pending += *pending;
+                                lqs->lqs_bwrite_pending += pending[i];
                         } else {
-                                *pending = count;
-                                lqs->lqs_iwrite_pending += *pending;
+                                pending[i] = count;
+                                lqs->lqs_iwrite_pending += pending[i];
                         }
                 }
 
@@ -335,11 +342,11 @@ static int quota_check_common(struct obd_device *obd, unsigned int uid,
                                 qdata[i].qd_count += lqs->lqs_ino_rec;
                 }
 
-
-                CDEBUG(D_QUOTA, "count: %d, lqs pending: %lu, qd_count: "LPU64
-                       ", metablocks: %d, isblk: %d, pending: %d.\n", count,
+                CDEBUG(D_QUOTA, "[id %u] [%c] [isblk %d] [count %d]"
+                       " [lqs pending: %lu] [qd_count: "LPU64"] [metablocks: %d]"
+                       " [pending: %d]\n", id[i], i % 2 ? 'g': 'u', isblk, count,
                        isblk ? lqs->lqs_bwrite_pending : lqs->lqs_iwrite_pending,
-                       qdata[i].qd_count, mb, isblk, *pending);
+                       qdata[i].qd_count, mb, pending[i]);
                 if (rc2[i] == QUOTA_RET_OK) {
                         if (isblk && qdata[i].qd_count < lqs->lqs_bwrite_pending)
                                 rc2[i] = QUOTA_RET_ACQUOTA;
@@ -371,9 +378,8 @@ static int quota_check_common(struct obd_device *obd, unsigned int uid,
                 RETURN(rc);
 }
 
-static int quota_chk_acq_common(struct obd_device *obd, unsigned int uid,
-                                unsigned int gid, int count, int *pending,
-                                quota_acquire acquire,
+static int quota_chk_acq_common(struct obd_device *obd, const unsigned int id[],
+                                int pending[], int count, quota_acquire acquire,
                                 struct obd_trans_info *oti, int isblk,
                                 struct inode *inode, int frags)
 {
@@ -386,14 +392,14 @@ static int quota_chk_acq_common(struct obd_device *obd, unsigned int uid,
         ENTRY;
 
         CDEBUG(D_QUOTA, "check quota for %s\n", obd->obd_name);
-        *pending = 0;
+        pending[USRQUOTA] = pending[GRPQUOTA] = 0;
         /* Unfortunately, if quota master is too busy to handle the
          * pre-dqacq in time and quota hash on ost is used up, we
          * have to wait for the completion of in flight dqacq/dqrel,
          * in order to get enough quota for write b=12588 */
         do_gettimeofday(&work_start);
-        while ((rc = quota_check_common(obd, uid, gid, count, cycle, isblk,
-                                        inode, frags, pending)) &
+        while ((rc = quota_check_common(obd, id, pending, count, cycle, isblk,
+                                        inode, frags)) &
                QUOTA_RET_ACQUOTA) {
 
                 spin_lock(&qctxt->lqc_lock);
@@ -419,7 +425,7 @@ static int quota_chk_acq_common(struct obd_device *obd, unsigned int uid,
                         OBD_FAIL_TIMEOUT(OBD_FAIL_OST_HOLD_WRITE_RPC, 90);
                 /* after acquire(), we should run quota_check_common again
                  * so that we confirm there are enough quota to finish write */
-                rc = acquire(obd, uid, gid, oti, isblk);
+                rc = acquire(obd, id, oti, isblk);
 
                 /* please reference to dqacq_completion for the below */
                 /* a new request is finished, try again */
@@ -484,15 +490,14 @@ static int quota_chk_acq_common(struct obd_device *obd, unsigned int uid,
  * when a block_write or inode_create rpc is finished, adjust the record for
  * pending blocks and inodes
  */
-static int quota_pending_commit(struct obd_device *obd, unsigned int uid,
-                                unsigned int gid, int pending, int isblk)
+static int quota_pending_commit(struct obd_device *obd, const unsigned int id[],
+                                int pending[], int isblk)
 {
         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
         struct timeval work_start;
         struct timeval work_end;
         long timediff;
         int i;
-        __u32 id[MAXQUOTAS] = { uid, gid };
         struct qunit_data qdata[MAXQUOTAS];
         ENTRY;
 
@@ -505,6 +510,10 @@ static int quota_pending_commit(struct obd_device *obd, unsigned int uid,
         for (i = 0; i < MAXQUOTAS; i++) {
                 struct lustre_qunit_size *lqs = NULL;
 
+                LASSERT(pending[i] >= 0);
+                if (pending[i] == 0)
+                        continue;
+
                 qdata[i].qd_id = id[i];
                 qdata[i].qd_flags = i;
                 if (isblk)
@@ -515,41 +524,43 @@ static int quota_pending_commit(struct obd_device *obd, unsigned int uid,
                         continue;
 
                 quota_search_lqs(&qdata[i], NULL, qctxt, &lqs);
-                if (lqs) {
-                        int flag = 0;
-                        spin_lock(&lqs->lqs_lock);
-                        if (isblk) {
-                                if (lqs->lqs_bwrite_pending >= pending) {
-                                        lqs->lqs_bwrite_pending -= pending;
-                                        spin_unlock(&lqs->lqs_lock);
-                                        flag = 1;
-                                } else {
-                                        spin_unlock(&lqs->lqs_lock);
-                                        CDEBUG(D_ERROR,
-                                               "there are too many blocks!\n");
-                                }
-                        } else {
-                                if (lqs->lqs_iwrite_pending >= pending) {
-                                        lqs->lqs_iwrite_pending -= pending;
-                                        spin_unlock(&lqs->lqs_lock);
-                                        flag = 1;
-                                } else {
-                                        spin_unlock(&lqs->lqs_lock);
-                                        CDEBUG(D_ERROR,
-                                               "there are too many files!\n");
-                                }
-                        }
-                        CDEBUG(D_QUOTA, "lqs pending: %lu, pending: %d, "
-                               "isblk: %d.\n",
-                               isblk ? lqs->lqs_bwrite_pending :
-                               lqs->lqs_iwrite_pending, pending, isblk);
+                if (lqs == NULL || IS_ERR(lqs)) {
+                        CERROR("can not find lqs for pending_commit: "
+                               "[id %u] [%c] [pending %u] [isblk %d] (rc %ld), "
+                               "maybe cause unexpected lqs refcount error!\n",
+                               id[i], i % 2 ? 'g': 'u', pending[i], isblk,
+                               lqs ? PTR_ERR(lqs) : -1);
+                        continue;
+                }
 
-                        lqs_putref(lqs);
-                        /* When lqs_*_pening is changed back, we'll putref lqs
-                         * here b=14784 */
-                        if (flag)
-                                lqs_putref(lqs);
+                spin_lock(&lqs->lqs_lock);
+                if (isblk) {
+                        LASSERTF(lqs->lqs_bwrite_pending >= pending[i],
+                                 "there are too many blocks! [id %u] [%c] "
+                                 "[bwrite_pending %lu] [pending %u]\n",
+                                 id[i], i % 2 ? 'g' : 'u',
+                                 lqs->lqs_bwrite_pending, pending[i]);
+
+                        lqs->lqs_bwrite_pending -= pending[i];
+                } else {
+                        LASSERTF(lqs->lqs_iwrite_pending >= pending[i],
+                                "there are too many files! [id %u] [%c] "
+                                "[iwrite_pending %lu] [pending %u]\n",
+                                id[i], i % 2 ? 'g' : 'u',
+                                lqs->lqs_iwrite_pending, pending[i]);
+
+                        lqs->lqs_iwrite_pending -= pending[i];
                 }
+                CDEBUG(D_QUOTA, "id: %u, %c, lqs pending: %lu, pending: %d, "
+                       "isblk: %d.\n", id[i], i % 2 ? 'g' : 'u',
+                       isblk ? lqs->lqs_bwrite_pending: lqs->lqs_iwrite_pending,
+                       pending[i], isblk);
+                spin_unlock(&lqs->lqs_lock);
+
+                /* for quota_search_lqs in pending_commit */
+                lqs_putref(lqs);
+                /* for quota_search_lqs in quota_check */
+                lqs_putref(lqs);
         }
         do_gettimeofday(&work_end);
         timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
@@ -643,15 +654,14 @@ static int mds_quota_fs_cleanup(struct obd_device *obd)
         RETURN(0);
 }
 
-static int quota_acquire_common(struct obd_device *obd, unsigned int uid,
-                                unsigned int gid, struct obd_trans_info *oti,
-                                int isblk)
+static int quota_acquire_common(struct obd_device *obd, const unsigned int id[],
+                                struct obd_trans_info *oti, int isblk)
 {
         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
         int rc;
         ENTRY;
 
-        rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, isblk, 1, oti);
+        rc = qctxt_adjust_qunit(obd, qctxt, id, isblk, 1, oti);
         RETURN(rc);
 }
 
@@ -738,7 +748,7 @@ static void free_qinfo(struct osc_quota_info *oqi)
         OBD_SLAB_FREE(oqi, qinfo_cachep, sizeof(*oqi));
 }
 
-int osc_quota_chkdq(struct client_obd *cli, unsigned int uid, unsigned int gid)
+int osc_quota_chkdq(struct client_obd *cli, const unsigned int qid[])
 {
         unsigned int id;
         int cnt, rc = QUOTA_OK;
@@ -748,7 +758,7 @@ int osc_quota_chkdq(struct client_obd *cli, unsigned int uid, unsigned int gid)
         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
                 struct osc_quota_info *oqi = NULL;
 
-                id = (cnt == USRQUOTA) ? uid : gid;
+                id = (cnt == USRQUOTA) ? qid[USRQUOTA] : qid[GRPQUOTA];
                 oqi = find_qinfo(cli, id, cnt);
                 if (oqi) {
                         rc = NO_QUOTA;
@@ -760,7 +770,7 @@ int osc_quota_chkdq(struct client_obd *cli, unsigned int uid, unsigned int gid)
         RETURN(rc);
 }
 
-int osc_quota_setdq(struct client_obd *cli, unsigned int uid, unsigned int gid,
+int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
                     obd_flag valid, obd_flag flags)
 {
         unsigned int id;
@@ -776,7 +786,7 @@ int osc_quota_setdq(struct client_obd *cli, unsigned int uid, unsigned int gid,
                     OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA)))
                         continue;
 
-                id = (cnt == USRQUOTA) ? uid : gid;
+                id = (cnt == USRQUOTA) ? qid[USRQUOTA] : qid[GRPQUOTA];
                 noquota = (cnt == USRQUOTA) ?
                     (flags & OBD_FL_NO_USRQUOTA) : (flags & OBD_FL_NO_GRPQUOTA);