[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 11/14] 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 redhat com>
---
 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]