Whamcloud - gitweb
LU-882 quota: Quota code compares unsigned < 0
authorNiu Yawei <niu@whamcloud.com>
Tue, 29 Nov 2011 04:59:38 +0000 (20:59 -0800)
committerJohann Lombardi <johann@whamcloud.com>
Wed, 4 Jan 2012 17:10:17 +0000 (12:10 -0500)
Port from b23858.

In check_cur_qunit(), it checks "if (limit + record < 0)", however,
the limit is unsigned, so this check will be always false, and when
limit is smaller than -record, following "limit += record" will make
limit a unreasonable large value.

This patch also fixed a similar defect in dqacq_handler().

Signed-off-by: Vladimir Saveliev <vladimir.saveliev@oracle.com>
Signed-off-by: Niu Yawei <niu@whamcloud.com>
Change-Id: Ibe1d643ea3b310b2e55c05a8c200ba5e0137ee27
Reviewed-on: http://review.whamcloud.com/1750
Tested-by: Hudson
Reviewed-by: Fan Yong <yong.fan@whamcloud.com>
Reviewed-by: Johann Lombardi <johann@whamcloud.com>
lustre/quota/quota_context.c
lustre/quota/quota_interface.c
lustre/quota/quota_master.c

index 6c2505e..255dbd0 100644 (file)
@@ -310,7 +310,7 @@ check_cur_qunit(struct obd_device *obd,
         limit_org = limit;
         /* when a releasing quota req is sent, before it returned
            limit is assigned a small value. limit will overflow */
-        if (limit + record < 0)
+        if (record < 0)
                 usage -= record;
         else
                 limit += record;
index 59244a5..f0ed393 100644 (file)
@@ -313,6 +313,8 @@ static int quota_check_common(struct obd_device *obd, unsigned int uid,
                                                "blocks\n", obd->obd_name);
                                 else
                                         pending[i] += mb;
+                                LASSERTF(pending[i] >= 0, "pending is not valid,"
+                                         " count=%d, mb=%d\n", count, mb);
                                 lqs->lqs_bwrite_pending += pending[i];
                         } else {
                                 pending[i] = count;
@@ -564,6 +566,7 @@ static int quota_pending_commit(struct obd_device *obd, unsigned int uid,
                 spin_lock(&lqs->lqs_lock);
                 if (isblk) {
                         if (lqs->lqs_bwrite_pending >= pending[i]) {
+                                LASSERT(pending[i] >= 0);
                                 lqs->lqs_bwrite_pending -= pending[i];
                                 flag = 1;
                         } else {
index effd13b..89175d9 100644 (file)
@@ -415,7 +415,7 @@ int dqacq_handler(struct obd_device *obd, struct qunit_data *qdata, int opc)
         case QUOTA_DQREL:
                 /* The usage in administrative file might be incorrect before
                  * recovery done */
-                if (*usage - qdata->qd_count < 0)
+                if (*usage < qdata->qd_count)
                         *usage = 0;
                 else
                         *usage -= qdata->qd_count;