gfs2-utils: master - gfs2_grow: Add stripe alignment

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


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=f3743a342836958ea725028ee231171f30576fe2
Commit:        f3743a342836958ea725028ee231171f30576fe2
Parent:        11068c6d81af4e3698ccebf54245b4891dbf53a8
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Thu Apr 3 07:18:08 2014 -0500
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Thu Apr 3 07:21:09 2014 -0500

gfs2_grow: Add stripe alignment

Wrap the calls to lgfs2_rgrps_init() in an rgrps_init() function which
uses libblkid to probe the alignment of the device before calling
lgfs2_rgrps_init().

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/mkfs/main_grow.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 88a7f15..adceeef 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -19,6 +19,7 @@
 #include <stdarg.h>
 #include <linux/types.h>
 #include <linux/falloc.h>
+#include <blkid.h>
 #include <libintl.h>
 #define _(String) gettext(String)
 
@@ -132,6 +133,52 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 	}
 }
 
+static lgfs2_rgrps_t rgrps_init(struct gfs2_sbd *sdp)
+{
+	int ret;
+	int error;
+	uint64_t al_base = 0;
+	uint64_t al_off = 0;
+	struct stat st;
+	blkid_probe pr = blkid_new_probe();
+	if (pr == NULL || blkid_probe_set_device(pr, sdp->device_fd, 0, 0) != 0
+	               || blkid_probe_enable_superblocks(pr, TRUE) != 0
+	               || blkid_probe_enable_partitions(pr, TRUE) != 0) {
+		fprintf(stderr, _("Failed to create probe\n"));
+		return NULL;
+	}
+
+	error = fstat(sdp->device_fd, &st);
+	if (error < 0) {
+		fprintf(stderr, _("fstat failed\n"));
+		return NULL;
+	}
+
+	if (!S_ISREG(st.st_mode) && blkid_probe_enable_topology(pr, TRUE) != 0) {
+		fprintf(stderr, _("Failed to create probe\n"));
+		return NULL;
+	}
+
+	ret = blkid_do_fullprobe(pr);
+	if (ret == 0 && !S_ISREG(st.st_mode)) {
+		blkid_topology tp = blkid_probe_get_topology(pr);
+		if (tp != NULL) {
+			unsigned long min_io_sz = blkid_topology_get_minimum_io_size(tp);
+			unsigned long opt_io_sz = blkid_topology_get_optimal_io_size(tp);
+			unsigned long phy_sector_sz = blkid_topology_get_physical_sector_size(tp);
+			if ((min_io_sz > phy_sector_sz) &&
+			    (opt_io_sz > phy_sector_sz)) {
+					al_base = opt_io_sz / sdp->bsize;
+					al_off = min_io_sz / sdp->bsize;
+			}
+
+		}
+	}
+
+	blkid_free_probe(pr);
+	return lgfs2_rgrps_init(sdp->bsize, sdp->device.length, al_base, al_off);
+}
+
 /**
  * Calculate the size of the filesystem
  * Reads the lists of resource groups in order to work out where the last block
@@ -363,7 +410,7 @@ void main_grow(int argc, char *argv[])
 			perror(_("Could not read master directory"));
 			exit(EXIT_FAILURE);
 		}
-		rgs = lgfs2_rgrps_init(sdp->bsize, sdp->device.length, 0, 0);
+		rgs = rgrps_init(sdp);
 		if (rgs == NULL) {
 			perror(_("Could not initialise resource groups"));
 			error = -1;
@@ -388,7 +435,7 @@ void main_grow(int argc, char *argv[])
 		/* We're done with the old rgs now that we have the fssize and rg count */
 		lgfs2_rgrps_free(&rgs);
 		/* Now lets set up the new ones with alignment and all */
-		rgs = lgfs2_rgrps_init(sdp->bsize, sdp->device.length, 0, 0);
+		rgs = rgrps_init(sdp);
 		if (rgs == NULL) {
 			perror(_("Could not initialise new resource groups"));
 			error = -1;


More information about the cluster-commits mailing list