From a1b7b5520612943178570237b5b0462b0395d726 Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Mon, 28 Nov 2011 20:59:38 -0800 Subject: [PATCH] LU-882 quota: Quota code compares unsigned < 0 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 Signed-off-by: Niu Yawei Change-Id: Ibe1d643ea3b310b2e55c05a8c200ba5e0137ee27 Reviewed-on: http://review.whamcloud.com/1750 Tested-by: Hudson Reviewed-by: Fan Yong Reviewed-by: Johann Lombardi --- lustre/quota/quota_context.c | 2 +- lustre/quota/quota_interface.c | 3 +++ lustre/quota/quota_master.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lustre/quota/quota_context.c b/lustre/quota/quota_context.c index 6c2505e..255dbd0 100644 --- a/lustre/quota/quota_context.c +++ b/lustre/quota/quota_context.c @@ -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; diff --git a/lustre/quota/quota_interface.c b/lustre/quota/quota_interface.c index 59244a5..f0ed393 100644 --- a/lustre/quota/quota_interface.c +++ b/lustre/quota/quota_interface.c @@ -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 { diff --git a/lustre/quota/quota_master.c b/lustre/quota/quota_master.c index effd13b..89175d9 100644 --- a/lustre/quota/quota_master.c +++ b/lustre/quota/quota_master.c @@ -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; -- 1.8.3.1