gfs2-utils: master - Build gfs2_grow, gfs2_jadd and mkfs.gfs2 separately

Andrew Price andyp at fedoraproject.org
Mon Nov 3 20:02:04 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=1be9a5c934cb239e3374d093c3ff0ad9857945aa
Commit:        1be9a5c934cb239e3374d093c3ff0ad9857945aa
Parent:        db04fb6e6a9825dc4ea45d8fd4bd1a8741881c23
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Sat Nov 1 13:22:43 2014 +0000
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Sat Nov 1 13:22:43 2014 +0000

Build gfs2_grow, gfs2_jadd and mkfs.gfs2 separately

Previously gfs2_jadd and gfs2_grow were just symlinks to mkfs.gfs2
created on installation, and mkfs.gfs2's main() function called the
appropriate main_* function depending on argv[0]. This had many
drawbacks:

- The lack of separate binaries complicated build testing and manual
  linking was needed
- A perl snippet was needed to find the relative path to the mkfs.gfs2
  binary on installation, making gfs2-utils build-dependent on perl
- This approach actually required more lines of code as the amount of
  shared code was minimal
- It meant copying mkfs.gfs2 to, say, mkfs.gfs2.old caused it to die
  with "Unknown mode"

This patch removes mkfs/main.c and gives each tool its own main(),
adding back locale setup code and #includes where needed. It also
removes the perl dependency and gives each tool its build target. The
above drawbacks are now solved, with the only overhead being a slightly
increased installed size. The tools can easily share more code in
future, but sharing main() is not the right way to do that.

Some code has been removed from Makefile.am in order to honour the
configure script's --sbindir option. An obsolete mkfs/README is also
removed.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 .gitignore            |    2 +
 gfs2/mkfs/Makefile.am |   53 +++++++++++++++++++---------------------------
 gfs2/mkfs/README      |   25 ---------------------
 gfs2/mkfs/gfs2_mkfs.h |   11 +++++++++
 gfs2/mkfs/main.c      |   56 -------------------------------------------------
 gfs2/mkfs/main_grow.c |    9 ++++++-
 gfs2/mkfs/main_jadd.c |    9 +++++++-
 gfs2/mkfs/main_mkfs.c |   22 +++++++------------
 po/POTFILES.in        |    1 -
 9 files changed, 58 insertions(+), 130 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4ffdb71..60ea971 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,8 @@ gfs2/libgfs2/lexer.c
 gfs2/libgfs2/lexer.h
 gfs2/fsck/fsck.gfs2
 gfs2/mkfs/mkfs.gfs2
+gfs2/mkfs/gfs2_grow
+gfs2/mkfs/gfs2_jadd
 gfs2/tune/tunegfs2
 test-driver
 tests/check_meta
diff --git a/gfs2/mkfs/Makefile.am b/gfs2/mkfs/Makefile.am
index 6ed89fa..822b41e 100644
--- a/gfs2/mkfs/Makefile.am
+++ b/gfs2/mkfs/Makefile.am
@@ -1,38 +1,29 @@
-MAINTAINERCLEANFILES	= Makefile.in
+MAINTAINERCLEANFILES = Makefile.in
 
-# When an exec_prefix setting would have us install into /usr/sbin,
-# use /sbin instead.
-# Accept an existing sbindir value of /usr/sbin (probably for older automake),
-# or an empty value, for automake-1.11 and newer.
-sbindir := $(shell rpl=0; test '$(exec_prefix):$(sbindir)' = /usr:/usr/sbin \
-		       || test '$(exec_prefix):$(sbindir)' = /usr: && rpl=1; \
-	     test $$rpl = 1 && echo /sbin || echo '$(exec_prefix)/sbin')
+COMMON_CPPFLAGS = \
+	-D_FILE_OFFSET_BITS=64 \
+	-D_LARGEFILE64_SOURCE \
+	-D_GNU_SOURCE \
+	-I$(top_srcdir)/gfs2/include \
+	-I$(top_srcdir)/gfs2/libgfs2
 
+sbin_PROGRAMS = mkfs.gfs2 gfs2_jadd gfs2_grow
 
-sbin_PROGRAMS		= mkfs.gfs2
+noinst_HEADERS = gfs2_mkfs.h
 
-noinst_HEADERS		= gfs2_mkfs.h
+mkfs_gfs2_SOURCES = main_mkfs.c
+mkfs_gfs2_CPPFLAGS = $(COMMON_CPPFLAGS)
+mkfs_gfs2_CFLAGS = $(blkid_CFLAGS)
+mkfs_gfs2_LDFLAGS = $(blkid_LIBS)
+mkfs_gfs2_LDADD	= $(top_builddir)/gfs2/libgfs2/libgfs2.la
 
-mkfs_gfs2_SOURCES	= main.c main_grow.c main_jadd.c main_mkfs.c
+gfs2_grow_SOURCES = main_grow.c
+gfs2_grow_CPPFLAGS = $(COMMON_CPPFLAGS)
+gfs2_grow_CFLAGS = $(blkid_CFLAGS)
+gfs2_grow_LDFLAGS = $(blkid_LIBS)
+gfs2_grow_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
 
-mkfs_gfs2_CPPFLAGS	= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE \
-			  -D_GNU_SOURCE \
-			  -I$(top_srcdir)/gfs2/include \
-			  -I$(top_srcdir)/gfs2/libgfs2
+gfs2_jadd_SOURCES = main_jadd.c
+gfs2_jadd_CPPFLAGS = $(COMMON_CPPFLAGS)
+gfs2_jadd_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
 
-mkfs_gfs2_CFLAGS	= $(blkid_CFLAGS)
-mkfs_gfs2_LDFLAGS	= $(blkid_LIBS)
-
-mkfs_gfs2_LDADD		= $(top_builddir)/gfs2/libgfs2/libgfs2.la
-
-relative_sbin		= $(shell perl -MFile::Spec -le 'print File::Spec->abs2rel("/sbin", "$(sbindir)")')
-
-install-exec-hook:
-	$(INSTALL) -d $(DESTDIR)/$(sbindir)
-	cd $(DESTDIR)/$(sbindir) && \
-		rm -f gfs2_grow gfs2_jadd && \
-		$(LN_S) $(relative_sbin)/mkfs.gfs2 gfs2_grow && \
-		$(LN_S) $(relative_sbin)/mkfs.gfs2 gfs2_jadd
-
-uninstall-hook:
-	cd $(DESTDIR)/$(sbindir) && rm -f gfs2_jadd gfs2_grow
diff --git a/gfs2/mkfs/README b/gfs2/mkfs/README
deleted file mode 100644
index 784df7d..0000000
--- a/gfs2/mkfs/README
+++ /dev/null
@@ -1,25 +0,0 @@
-
-#
-# mkfs for GFS2 filesystem
-#
-
-To install:
-
- 1. Edit the Makefile to point at your local copy of the kernel source
-with GFS2 included in it, for my set up that means:
-
-INCLUDEPATH=-I/home/steve/linux-2.6/include/
-
- 2. make
- 3. make install
-
-
-You can then use it just like other mkfs programs (for example):
-
-/sbin/mkfs -t gfs2 -j 1 -p lock_nolock /dev/sdb1
-
-This will create a filesystem with one journal (i.e. mountable by a
-maximum of one node at a time) with the nolock module (single node
-use only) on /dev/sdb1. Running mkfs -f gfs2 -h will produce help
-information.
-
diff --git a/gfs2/mkfs/gfs2_mkfs.h b/gfs2/mkfs/gfs2_mkfs.h
index 3c63858..377c14b 100644
--- a/gfs2/mkfs/gfs2_mkfs.h
+++ b/gfs2/mkfs/gfs2_mkfs.h
@@ -29,6 +29,17 @@ void die(const char *fmt, ...)
 	exit(-1);
 }
 
+/* This function is for libgfs2's sake. */
+void print_it(const char *label, const char *fmt, const char *fmt2, ...)
+{
+	va_list args;
+
+	va_start(args, fmt2);
+	printf("%s: ", label);
+	vprintf(fmt, args);
+	va_end(args);
+}
+
 /*
  * The following inode IOCTL macros and inode flags 
  * are copied from linux/fs.h, because we have duplicate 
diff --git a/gfs2/mkfs/main.c b/gfs2/mkfs/main.c
deleted file mode 100644
index c0be01e..0000000
--- a/gfs2/mkfs/main.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "clusterautoconfig.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <time.h>
-#include <errno.h>
-#include <libgen.h>
-#include <libintl.h>
-#include <locale.h>
-#define _(String) gettext(String)
-
-#include <linux/types.h>
-#include "libgfs2.h"
-#include "gfs2_mkfs.h"
-
-/**
- * main - do everything
- * @argc:
- * @argv:
- *
- * Returns: 0 on success, non-0 on failure
- */
-
-int
-main(int argc, char *argv[])
-{
-	char *p, *whoami;
-
-	setlocale(LC_ALL, "");
-	textdomain("gfs2-utils");
-
-	srandom(time(NULL) ^ getpid());
-
-	p = strdup(argv[0]);
-	whoami = basename(p);
-	
-	if (!strcmp(whoami, "gfs2_jadd"))
-		main_jadd(argc, argv);
-	else if (!strcmp(whoami, "gfs2_mkfs") || !strcmp(whoami, "mkfs.gfs2"))
-		main_mkfs(argc, argv);
-	else if (!strcmp(whoami, "gfs2_grow"))
-		main_grow(argc, argv);
-	else
-		die( _("Unknown mode\n"));
-
-	free(p);
-
-	return 0;
-}
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 33618de..3ab8e72 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -21,6 +21,7 @@
 #include <linux/falloc.h>
 #include <blkid.h>
 #include <libintl.h>
+#include <locale.h>
 #define _(String) gettext(String)
 
 #include <logging.h>
@@ -338,13 +339,17 @@ static int open_rindex(char *metafs_path, int mode)
 	return fd;
 }
 
-void main_grow(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
 	struct gfs2_sbd sbd, *sdp = &sbd;
 	int rindex_fd;
 	int error = EXIT_SUCCESS;
 	int devflags = (test ? O_RDONLY : O_RDWR) | O_CLOEXEC;
 
+	setlocale(LC_ALL, "");
+	textdomain("gfs2-utils");
+	srandom(time(NULL) ^ getpid());
+
 	memset(sdp, 0, sizeof(struct gfs2_sbd));
 	sdp->bsize = GFS2_DEFAULT_BSIZE;
 	sdp->rgsize = -1;
@@ -464,5 +469,5 @@ void main_grow(int argc, char *argv[])
 		exit(1);
 	}
 	log_notice( _("gfs2_grow complete.\n"));
-	exit(error);
+	return error;
 }
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 6507e03..fea474a 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <libintl.h>
+#include <locale.h>
 #define _(String) gettext(String)
 
 #include <linux/types.h>
@@ -486,13 +487,17 @@ static void add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
 	}
 }
 
-void main_jadd(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
 	struct jadd_opts opts = {0};
 	struct gfs2_sbd sbd, *sdp = &sbd;
 	struct mntent *mnt;
 	unsigned int total;
 
+	setlocale(LC_ALL, "");
+	textdomain("gfs2-utils");
+	srandom(time(NULL) ^ getpid());
+
 	memset(sdp, 0, sizeof(struct gfs2_sbd));
 	sdp->jsize = GFS2_DEFAULT_JSIZE;
 	sdp->qcsize = GFS2_DEFAULT_QCSIZE;
@@ -549,4 +554,6 @@ void main_jadd(int argc, char *argv[])
 	cleanup_metafs(sdp);
 	sync();
 	print_results(&opts);
+
+	return 0;
 }
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 90ad4d9..b6353dd 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -21,6 +21,7 @@
 #include <sys/ioctl.h>
 #include <limits.h>
 #include <blkid.h>
+#include <locale.h>
 
 #define _(String) gettext(String)
 
@@ -28,19 +29,6 @@
 #include "libgfs2.h"
 #include "gfs2_mkfs.h"
 
-/**
- * This function is for libgfs2's sake.
- */
-void print_it(const char *label, const char *fmt, const char *fmt2, ...)
-{
-	va_list args;
-
-	va_start(args, fmt2);
-	printf("%s: ", label);
-	vprintf(fmt, args);
-	va_end(args);
-}
-
 static void print_usage(const char *prog_name)
 {
 	int i;
@@ -871,7 +859,7 @@ static void open_dev(struct mkfs_dev *dev)
 		exit(1);
 }
 
-void main_mkfs(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
 	struct gfs2_sbd sbd;
 	struct gfs2_sb sb;
@@ -880,6 +868,10 @@ void main_mkfs(int argc, char *argv[])
 	int error;
 	unsigned bsize;
 
+	setlocale(LC_ALL, "");
+	textdomain("gfs2-utils");
+	srandom(time(NULL) ^ getpid());
+
 	opts_init(&opts);
 	opts_get(argc, argv, &opts);
 	opts_check(&opts);
@@ -1001,4 +993,6 @@ void main_mkfs(int argc, char *argv[])
 
 	if (!opts.quiet)
 		print_results(&sb, &opts, sbd.rgrps, sbd.fssize);
+
+	return 0;
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 579ff4b..0e5f57e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,5 @@
 gfs2/mkfs/main_mkfs.c
 gfs2/mkfs/gfs2_mkfs.h
-gfs2/mkfs/main.c
 gfs2/mkfs/main_grow.c
 gfs2/mkfs/main_jadd.c
 gfs2/tune/main.c


More information about the cluster-commits mailing list