From 82b79742c8e86650d1441828ef727c21e88faff8 Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Mon, 19 Dec 2011 02:01:36 -0800 Subject: [PATCH 1/1] 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: Iea02143dae5542f1a9f9cc823a684a18031b8a03 Reviewed-on: http://review.whamcloud.com/1889 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: Johann Lombardi Reviewed-by: Oleg Drokin --- lustre/quota/quota_context.c | 2 +- lustre/quota/quota_interface.c | 2 ++ lustre/quota/quota_master.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lustre/quota/quota_context.c b/lustre/quota/quota_context.c index 05179ec..f1be4f8 100644 --- a/lustre/quota/quota_context.c +++ b/lustre/quota/quota_context.c @@ -325,7 +325,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 fbf6ee5..01dc6ac 100644 --- a/lustre/quota/quota_interface.c +++ b/lustre/quota/quota_interface.c @@ -333,6 +333,8 @@ static int quota_check_common(struct obd_device *obd, const unsigned int id[], 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; diff --git a/lustre/quota/quota_master.c b/lustre/quota/quota_master.c index eac45d3..05a8dac 100644 --- a/lustre/quota/quota_master.c +++ b/lustre/quota/quota_master.c @@ -454,7 +454,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