From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Price Date: Thu, 3 Apr 2014 16:12:44 +0100 Subject: [Cluster-devel] [PATCH 11/14] libgfs2: Fix off-by-one in lgfs2_rgrps_plan In-Reply-To: <1396537967-12399-1-git-send-email-anprice@redhat.com> References: <1396537967-12399-1-git-send-email-anprice@redhat.com> Message-ID: <1396537967-12399-12-git-send-email-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit We were making plans based on an extra resource group but not adding the extra one to the count. Make sure the count is incremented appropriately. Signed-off-by: Andrew Price --- gfs2/libgfs2/rgrp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c index cae7a32..d70dfc5 100644 --- a/gfs2/libgfs2/rgrp.c +++ b/gfs2/libgfs2/rgrp.c @@ -299,7 +299,8 @@ uint32_t lgfs2_rgrps_plan(const lgfs2_rgrps_t rgs, uint64_t space, uint32_t tgts /* Spread the adjustment required to fit a new rgrp at the end over all of the rgrps so that we don't end with a single tiny one. */ - while (((rgs->plan[0].len - adj) * (rgs->plan[0].num + 1)) >= space) + rgs->plan[0].num++; + while (((rgs->plan[0].len - adj) * (rgs->plan[0].num)) >= space) rgs->plan[0].len -= adj; /* We've adjusted the size of the rgrps down as far as we can @@ -313,7 +314,7 @@ uint32_t lgfs2_rgrps_plan(const lgfs2_rgrps_t rgs, uint64_t space, uint32_t tgts rgs->plan[1].num = 0; while (((rgs->plan[0].len * rgs->plan[0].num) + - (rgs->plan[1].len * rgs->plan[1].num)) > space) { + (rgs->plan[1].len * rgs->plan[1].num)) >= space) { /* Total number of rgrps stays constant now. We just need to shift some weight around */ rgs->plan[0].num--; -- 1.8.5.3