Skip to contentSkip to conversation

gfs2_grow: fix and move figure_out_rgsize() to libgfs2

PATCH New Carlos Maiolino 1 participant 2 messages Sep 2, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gfs2_grow: fix and move figure_out_rgsize() to libgfs2

This patch fix the rgsize calculation into the figure_out_rgsize() function, and move the function to libgfs2, since there is more than one place into gfs2 which needs to calculate the rgsize, so, it's useful to have this function available to any other part of gfs2-utils.

---
 gfs2/libgfs2/libgfs2.h |    1 +
 gfs2/libgfs2/rgrp.c    |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 gfs2/mkfs/main_grow.c  |   19 +-------------
 3 files changed, 66 insertions(+), 18 deletions(-)
gfs2/libgfs2/libgfs2.h +1 -0
index 53df6cd..c8d7758 100644
@@ -708,6 +708,7 @@ extern void gfs2_rgrp_relse(struct rgrp_tree *rgd);
 extern struct rgrp_tree *rgrp_insert(struct osi_root *rgtree,
 				     uint64_t rgblock);
 extern void gfs2_rgrp_free(struct osi_root *rgrp_tree);
+extern unsigned int figure_out_rgsize(struct gfs2_sbd *sdp);
 
 /* structures.c */
 extern int build_master(struct gfs2_sbd *sdp);
gfs2/libgfs2/rgrp.c +64 -0

67 lines not on this page · raw message

gfs2/mkfs/main_grow.c +1 -18
index dc092ee..48bd2da 100644
@@ -122,23 +122,6 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 }
 
 /**
- * figure_out_rgsize
- */
-static void figure_out_rgsize(struct gfs2_sbd *sdp, unsigned int *orgsize)
-{
-	struct osi_node *n = osi_first(&sdp->rgtree), *next = NULL;
-	struct rgrp_tree *r1, *r2;
-
-	sdp->rgsize = GFS2_DEFAULT_RGSIZE;
-	next = osi_next(n);
-	r1 = (struct rgrp_tree *)next;
-	next = osi_next(next);
-	r2 = (struct rgrp_tree *)next;
-
-	*orgsize = r2->ri.ri_addr - r1->ri.ri_addr;
-}
-
-/**
  * filesystem_size - Calculate the size of the filesystem
  *
  * Reads the lists of resource groups in order to
@@ -391,7 +374,7 @@ main_grow(int argc, char *argv[])
 		/* the existing RGs, and only write to the index at EOF.    */
 		ri_update(sdp, rindex_fd, &rgcount, &sane);
 		fssize = filesystem_size(sdp);
-		figure_out_rgsize(sdp, &rgsize);
+		rgsize = figure_out_rgsize(sdp);
 		fsgrowth = ((sdp->device.length - fssize) * sdp->bsize);
 		if (fsgrowth < rgsize * sdp->bsize) {
 			log_err( _("Error: The device has grown by less than "
Signature · 1 line
1.7.6
#1 lore raw

PATCH 2/2 libgfs2: fix compute_rgrp_layout

The function uses the same buggy trick as gfs2_grow to calculate rgsize, which cause a segmentation fault if there is only one RG into the filesystem.
This patch makes compute_rgrp_layout() to use figure_out_rgsize() function.

---
 gfs2/libgfs2/fs_geometry.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
gfs2/libgfs2/fs_geometry.c +3 -3
index 2b70f11..bdc8225 100644
@@ -80,8 +80,8 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
 	struct device *dev;
 	struct rgrp_tree *rl, *rlast = NULL, *rlast2 = NULL;
 	struct osi_node *n, *next = NULL;
-	unsigned int rgrp = 0, nrgrp;
-	uint64_t rglength, rgaddr;
+	unsigned int rgrp = 0, nrgrp, rglength;
+	uint64_t rgaddr;
 
 	sdp->new_rgrps = 0;
 	dev = &sdp->device;
@@ -113,7 +113,7 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
 			rlast = rl;
 		}
 		rlast->start = rlast->ri.ri_addr;
-		rglength = rlast->ri.ri_addr - rlast2->ri.ri_addr;
+		rglength = figure_out_rgsize(sdp);
 		rlast->length = rglength;
 		old_length = rlast->ri.ri_addr + rglength;
 		new_chunk = dev->length - old_length;
Signature · 1 line
1.7.6