gfs2-utils: master - libgfs2: Fix off-by-one in lgfs2_rgrps_plan

Andrew Price andyp at fedoraproject.org
Mon Apr 7 16:09:16 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=31fcba75fa1fa6651bc7e633f0fc655cd6ba16d6
Commit:        31fcba75fa1fa6651bc7e633f0fc655cd6ba16d6
Parent:        d5b8d681a696c777a3d5b385383242b0d4dc4190
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Thu Apr 3 06:25:17 2014 -0500
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Thu Apr 3 06:25:17 2014 -0500

libgfs2: Fix off-by-one in lgfs2_rgrps_plan

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 <anprice at redhat.com>
---
 gfs2/libgfs2/rgrp.c |    5 +++--
 1 files 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--;


More information about the cluster-commits mailing list