All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2
@ 2022-01-12 19:26 Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 01/18] libgfs2: Move debugging printf out of build_master() Andrew Price
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This patch set fixes a long-standing issue in libgfs2 where it requires apps linking to it to provide a print_it function, which it uses in lgfs2_(struct)_print() functions defined in libgfs2/ondisk.c. This was the main blocker to it becoming a library in a more meaningful sense.

The approach taken is to remove the responsibility of printing gfs2 structures from libgfs2 altogether. So the first challenge is to remove debugging output from libgfs2 and push it down into the utils, which in turn required returning more context from some libgfs2 functions, mainly the build_* functions in structures.c.

The overall result is more flexibility and control over the way the utils print on-disk structures and improved error/debug messages. Test code is also tidied up as we no longer have to define a print_it() in each of the tests.


Andrew Price (18):
  libgfs2: Move debugging printf out of build_master()
  libgfs2: Rework lgfs2_build_jindex()
  libgfs2: Move build_jindex() into fsck.gfs2
  libgfs2: Push down build_per_node() into the utils
  libgfs2: Return the inode from build_inum_range()
  libgfs2: Return the inode from build_statfs_change()
  libgfs2: Return the inode from build_quota_change()
  libgfs2: Return the inode from build_inum()
  libgfs2: Return the inode from build_statfs()
  libgfs2: Return the inode from build_rindex()
  libgfs2: Return the inode from build_quota()
  libgfs2: Move debugging printf out of build_root()
  libgfs2: Remove debugging printf from do_init_statfs()
  libgfs2: Move debugging output out of do_init_inum()
  libgfs2: Remove debugging printfs from fix_device_geometry()
  libgfs2: Remove config.[ch]
  libgfs2: Move struct printing functions out of libgfs2
  libgfs2: Remove print_it extern requirement

 gfs2/convert/gfs2_convert.c    |  80 +++++---
 gfs2/edit/Makefile.am          |   2 +
 gfs2/edit/extended.c           |  18 +-
 gfs2/edit/gfs2hex.c            | 156 +-------------
 gfs2/edit/hexedit.c            |  36 +---
 gfs2/edit/hexedit.h            |   4 +-
 gfs2/edit/struct_print.c       | 364 +++++++++++++++++++++++++++++++++
 gfs2/edit/struct_print.h       |  23 +++
 gfs2/fsck/fs_recovery.c        |  21 ++
 gfs2/fsck/fs_recovery.h        |   1 +
 gfs2/fsck/fsck.h               |   1 +
 gfs2/fsck/initialize.c         |  75 +++----
 gfs2/fsck/main.c               |  13 +-
 gfs2/fsck/pass1.c              |  86 +++++++-
 gfs2/fsck/pass2.c              |  37 +++-
 gfs2/glocktop/glocktop.c       |   3 +-
 gfs2/libgfs2/Makefile.am       |   2 -
 gfs2/libgfs2/check_libgfs2.c   |   3 -
 gfs2/libgfs2/checks.am         |   1 -
 gfs2/libgfs2/config.c          |   9 -
 gfs2/libgfs2/config.h          |   6 -
 gfs2/libgfs2/device_geometry.c |   7 -
 gfs2/libgfs2/gfs2l.c           |   3 -
 gfs2/libgfs2/libgfs2.h         |  40 +---
 gfs2/libgfs2/ondisk.c          | 199 ------------------
 gfs2/libgfs2/structures.c      | 226 ++++----------------
 gfs2/mkfs/Makefile.am          |   2 +
 gfs2/mkfs/gfs2_mkfs.h          |  11 -
 gfs2/mkfs/main_jadd.c          |   1 -
 gfs2/mkfs/main_mkfs.c          | 152 +++++++++++---
 gfs2/mkfs/struct_print.c       | 218 ++++++++++++++++++++
 gfs2/mkfs/struct_print.h       |  19 ++
 tests/nukerg.c                 |   3 -
 33 files changed, 1067 insertions(+), 755 deletions(-)
 create mode 100644 gfs2/edit/struct_print.c
 create mode 100644 gfs2/edit/struct_print.h
 delete mode 100644 gfs2/libgfs2/config.c
 delete mode 100644 gfs2/libgfs2/config.h
 create mode 100644 gfs2/mkfs/struct_print.c
 create mode 100644 gfs2/mkfs/struct_print.h

-- 
2.34.1



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 01/18] libgfs2: Move debugging printf out of build_master()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 02/18] libgfs2: Rework lgfs2_build_jindex() Andrew Price
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

mkfs.gfs2 is the only place it could ever get printed so move it there
instead.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/libgfs2/structures.c | 4 ----
 gfs2/mkfs/main_mkfs.c     | 4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index a562dc50..95ad3ac9 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -38,10 +38,6 @@ int build_master(struct gfs2_sbd *sdp)
 	if (sdp->master_dir == NULL)
 		return -1;
 
-	if (cfg_debug) {
-		printf("\nMaster dir:\n");
-		lgfs2_dinode_print(bh->b_data);
-	}
 	sdp->master_dir->bh_owned = 1;
 	return 0;
 }
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 6f30b2d3..dbee5cab 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1205,6 +1205,10 @@ int main(int argc, char *argv[])
 		fprintf(stderr, _("Error building '%s': %s\n"), "master", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
+	if (opts.debug) {
+		printf("Metafs inode:\n");
+		lgfs2_dinode_print(sbd.master_dir->i_bh->b_data);
+	}
 	sbd.sd_meta_dir = sbd.master_dir->i_num;
 
 	error = lgfs2_build_jindex(sbd.master_dir, mkfs_journals, opts.journals);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 02/18] libgfs2: Rework lgfs2_build_jindex()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 01/18] libgfs2: Move debugging printf out of build_master() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 03/18] libgfs2: Move build_jindex() into fsck.gfs2 Andrew Price
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Return the inode instead of freeing it and move the debug printfs out of
libgfs2.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/libgfs2/libgfs2.h    |  2 +-
 gfs2/libgfs2/structures.c | 23 ++++++++---------------
 gfs2/mkfs/main_mkfs.c     | 27 ++++++++++++++++++++++-----
 3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 04e6ec0f..990a9d9e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -777,7 +777,7 @@ extern int lgfs2_sb_write(const struct gfs2_sbd *sdp, int fd);
 extern int build_journal(struct gfs2_sbd *sdp, int j,
 			 struct gfs2_inode *jindex);
 extern int build_jindex(struct gfs2_sbd *sdp);
-extern int lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum *jnls, size_t nmemb);
+extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct lgfs2_inum *jnls, size_t nmemb);
 extern int build_per_node(struct gfs2_sbd *sdp);
 extern int build_inum(struct gfs2_sbd *sdp);
 extern int build_statfs(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 95ad3ac9..de36c4e3 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -251,39 +251,32 @@ int build_journal(struct gfs2_sbd *sdp, int j, struct gfs2_inode *jindex)
  * nmemb: The number of entries in the list (number of journals).
  * Returns 0 on success or non-zero on error with errno set.
  */
-int lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum *jnls, size_t nmemb)
+struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_inum *jnls, size_t nmemb)
 {
 	char fname[GFS2_FNAMESIZE + 1];
 	struct gfs2_inode *jindex;
-	unsigned j;
-	int ret;
 
 	if (nmemb == 0 || jnls == NULL) {
 		errno = EINVAL;
-		return 1;
+		return NULL;
 	}
 	jindex = createi(master, "jindex", S_IFDIR | 0700, GFS2_DIF_SYSTEM);
 	if (jindex == NULL)
-		return 1;
+		return NULL;
 
 	fname[GFS2_FNAMESIZE] = '\0';
 
-	for (j = 0; j < nmemb; j++) {
+	for (unsigned j = 0; j < nmemb; j++) {
+		int ret;
+
 		snprintf(fname, GFS2_FNAMESIZE, "journal%u", j);
 		ret = dir_add(jindex, fname, strlen(fname), &jnls[j], IF2DT(S_IFREG | 0600));
 		if (ret) {
 			inode_put(&jindex);
-			return 1;
+			return NULL;
 		}
 	}
-
-	if (cfg_debug) {
-		printf("\nJindex:\n");
-		lgfs2_dinode_print(jindex->i_bh->b_data);
-	}
-
-	inode_put(&jindex);
-	return 0;
+	return jindex;
 }
 
 int build_jindex(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index dbee5cab..17284976 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -941,6 +941,24 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, uint64_t *rgaddr
 	return 0;
 }
 
+static int create_jindex(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct lgfs2_inum *jnls)
+{
+	struct gfs2_inode *jindex;
+
+	jindex = lgfs2_build_jindex(sdp->master_dir, jnls, opts->journals);
+	if (jindex == NULL) {
+		fprintf(stderr, _("Error building '%s': %s\n"), "jindex", strerror(errno));
+		return 1;
+	}
+	if (opts->debug) {
+		printf("Jindex:\n");
+		lgfs2_dinode_print(jindex->i_bh->b_data);
+	}
+	inode_put(&jindex);
+	return 0;
+}
+
+
 /*
  * Find a reasonable journal file size (in blocks) given the number of blocks
  * in the filesystem.  For very small filesystems, it is not reasonable to
@@ -1211,12 +1229,11 @@ int main(int argc, char *argv[])
 	}
 	sbd.sd_meta_dir = sbd.master_dir->i_num;
 
-	error = lgfs2_build_jindex(sbd.master_dir, mkfs_journals, opts.journals);
-	if (error) {
-		fprintf(stderr, _("Error building '%s': %s\n"), "jindex", strerror(errno));
-		exit(EXIT_FAILURE);
-	}
+	error = create_jindex(&sbd, &opts, mkfs_journals);
 	free(mkfs_journals);
+	if (error != 0)
+		exit(1);
+
 	error = build_per_node(&sbd);
 	if (error) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "per_node", strerror(errno));
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 03/18] libgfs2: Move build_jindex() into fsck.gfs2
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 01/18] libgfs2: Move debugging printf out of build_master() Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 02/18] libgfs2: Rework lgfs2_build_jindex() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 04/18] libgfs2: Push down build_per_node() into the utils Andrew Price
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

fsck.gfs2 is the only remaining util that builds journals this way so
move it out of libgfs2. The debug printfs can be removed because
fsck.gfs2 doesn't enable libgfs2's cfg_debug.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/fsck/fs_recovery.c   | 21 +++++++++++++++++++++
 gfs2/fsck/fs_recovery.h   |  1 +
 gfs2/fsck/pass2.c         |  1 +
 gfs2/libgfs2/libgfs2.h    |  1 -
 gfs2/libgfs2/structures.c | 29 -----------------------------
 5 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 48d98626..e5cde051 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -848,6 +848,27 @@ static struct metawalk_fxns jindex_check_fxns = {
 	.check_dentry = check_jindex_dent,
 };
 
+int build_jindex(struct gfs2_sbd *sdp)
+{
+	struct gfs2_inode *jindex;
+
+	jindex = createi(sdp->master_dir, "jindex", S_IFDIR | 0700,
+			 GFS2_DIF_SYSTEM);
+	if (jindex == NULL) {
+		return errno;
+	}
+	sdp->md.journal = malloc(sdp->md.journals * sizeof(struct gfs2_inode *));
+	for (unsigned j = 0; j < sdp->md.journals; j++) {
+		int ret = build_journal(sdp, j, jindex);
+		if (ret)
+			return ret;
+		inode_put(&sdp->md.journal[j]);
+	}
+	free(sdp->md.journal);
+	inode_put(&jindex);
+	return 0;
+}
+
 /**
  * init_jindex - read in the rindex file
  */
diff --git a/gfs2/fsck/fs_recovery.h b/gfs2/fsck/fs_recovery.h
index d6876274..884d3c43 100644
--- a/gfs2/fsck/fs_recovery.h
+++ b/gfs2/fsck/fs_recovery.h
@@ -8,6 +8,7 @@ extern int replay_journals(struct gfs2_sbd *sdp, int preen, int force_check,
 extern int preen_is_safe(struct gfs2_sbd *sdp, int preen, int force_check);
 
 extern int ji_update(struct gfs2_sbd *sdp);
+extern int build_jindex(struct gfs2_sbd *sdp);
 extern int init_jindex(struct gfs2_sbd *sdp, int allow_ji_rebuild);
 #endif /* __FS_RECOVERY_H__ */
 
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 998b0c96..0ab35b55 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -18,6 +18,7 @@
 #include "lost_n_found.h"
 #include "inode_hash.h"
 #include "afterpass1_common.h"
+#include "fs_recovery.h"
 
 #define MAX_FILENAME 256
 
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 990a9d9e..9a66b5b3 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -776,7 +776,6 @@ extern int build_master(struct gfs2_sbd *sdp);
 extern int lgfs2_sb_write(const struct gfs2_sbd *sdp, int fd);
 extern int build_journal(struct gfs2_sbd *sdp, int j,
 			 struct gfs2_inode *jindex);
-extern int build_jindex(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct lgfs2_inum *jnls, size_t nmemb);
 extern int build_per_node(struct gfs2_sbd *sdp);
 extern int build_inum(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index de36c4e3..09d7041e 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -279,35 +279,6 @@ struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_in
 	return jindex;
 }
 
-int build_jindex(struct gfs2_sbd *sdp)
-{
-	struct gfs2_inode *jindex;
-	unsigned int j;
-	int ret;
-
-	jindex = createi(sdp->master_dir, "jindex", S_IFDIR | 0700,
-			 GFS2_DIF_SYSTEM);
-	if (jindex == NULL) {
-		return errno;
-	}
-	sdp->md.journal = malloc(sdp->md.journals *
-				 sizeof(struct gfs2_inode *));
-	for (j = 0; j < sdp->md.journals; j++) {
-		ret = build_journal(sdp, j, jindex);
-		if (ret)
-			return ret;
-		inode_put(&sdp->md.journal[j]);
-	}
-	if (cfg_debug) {
-		printf("\nJindex:\n");
-		lgfs2_dinode_print(jindex->i_bh->b_data);
-	}
-
-	free(sdp->md.journal);
-	inode_put(&jindex);
-	return 0;
-}
-
 int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 {
 	char name[256];
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 04/18] libgfs2: Push down build_per_node() into the utils
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (2 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 03/18] libgfs2: Move build_jindex() into fsck.gfs2 Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 05/18] libgfs2: Return the inode from build_inum_range() Andrew Price
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

The trouble with having this function in libgfs2 is that it creates
per_node and everything inside it, which means that it's difficult to
know where an error occurred and we don't have any control over how
debug/error messages are printed. It's also not necessarily the order
that we want to create the inodes in all utilities. Move
build_per_node() down into the utils and add error reporting to match.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c | 36 +++++++++++++++++++++++++++
 gfs2/fsck/fsck.h            |  1 +
 gfs2/fsck/pass1.c           | 36 +++++++++++++++++++++++++++
 gfs2/libgfs2/libgfs2.h      |  1 -
 gfs2/libgfs2/structures.c   | 36 ---------------------------
 gfs2/mkfs/main_mkfs.c       | 49 +++++++++++++++++++++++++++++++++----
 6 files changed, 117 insertions(+), 42 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 237160af..9a326e7f 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2099,6 +2099,42 @@ static int check_fit(struct gfs2_sbd *sdp)
 	return blks_avail > blks_need;
 }
 
+static int build_per_node(struct gfs2_sbd *sdp)
+{
+	struct gfs2_inode *per_node;
+	unsigned int j;
+	int err;
+
+	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
+			   GFS2_DIF_SYSTEM);
+	if (per_node == NULL) {
+		log_crit(_("Error building '%s': %s\n"), "per_node", strerror(errno));
+		return -1;
+	}
+	for (j = 0; j < sdp->md.journals; j++) {
+		err = build_inum_range(per_node, j);
+		if (err) {
+			log_crit(_("Error building '%s': %s\n"), "inum_range",
+			         strerror(errno));
+			return err;
+		}
+		err = build_statfs_change(per_node, j);
+		if (err) {
+			log_crit(_("Error building '%s': %s\n"), "statfs_change",
+			         strerror(errno));
+			return err;
+		}
+		err = build_quota_change(per_node, j);
+		if (err) {
+			log_crit(_("Error building '%s': %s\n"), "quota_change",
+			         strerror(errno));
+			return err;
+		}
+	}
+	inode_put(&per_node);
+	return 0;
+}
+
 /* We fetch the old quota inode block and copy the contents of the block
  * (minus the struct gfs2_dinode) into the new quota block. We update the 
  * inode height/size of the new quota file to that of the old one and set the 
diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h
index f6c7d1dd..7b991614 100644
--- a/gfs2/fsck/fsck.h
+++ b/gfs2/fsck/fsck.h
@@ -200,5 +200,6 @@ extern struct special_blocks *blockfind(struct special_blocks *blist, uint64_t n
 extern void gfs2_special_set(struct special_blocks *blocklist, uint64_t block);
 extern void gfs2_special_free(struct special_blocks *blist);
 extern int sb_fixed;
+extern int build_per_node(struct gfs2_sbd *sdp);
 
 #endif /* _FSCK_H */
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index e976149c..38da46a6 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1577,6 +1577,42 @@ static int build_a_journal(struct gfs2_sbd *sdp)
 	return 0;
 }
 
+int build_per_node(struct gfs2_sbd *sdp)
+{
+	struct gfs2_inode *per_node;
+	unsigned int j;
+	int err;
+
+	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
+			   GFS2_DIF_SYSTEM);
+	if (per_node == NULL) {
+		log_err(_("Error building '%s': %s\n"), "per_node", strerror(errno));
+		return -1;
+	}
+	for (j = 0; j < sdp->md.journals; j++) {
+		err = build_inum_range(per_node, j);
+		if (err) {
+			log_err(_("Error building '%s': %s\n"), "inum_range",
+			        strerror(errno));
+			return err;
+		}
+		err = build_statfs_change(per_node, j);
+		if (err) {
+			log_err(_("Error building '%s': %s\n"), "statfs_change",
+			        strerror(errno));
+			return err;
+		}
+		err = build_quota_change(per_node, j);
+		if (err) {
+			log_err(_("Error building '%s': %s\n"), "quota_change",
+			        strerror(errno));
+			return err;
+		}
+	}
+	inode_put(&per_node);
+	return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
 	int journal_count;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 9a66b5b3..863b84e6 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -777,7 +777,6 @@ extern int lgfs2_sb_write(const struct gfs2_sbd *sdp, int fd);
 extern int build_journal(struct gfs2_sbd *sdp, int j,
 			 struct gfs2_inode *jindex);
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct lgfs2_inum *jnls, size_t nmemb);
-extern int build_per_node(struct gfs2_sbd *sdp);
 extern int build_inum(struct gfs2_sbd *sdp);
 extern int build_statfs(struct gfs2_sbd *sdp);
 extern int build_rindex(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 09d7041e..c9c31dd2 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -370,42 +370,6 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
 	return 0;
 }
 
-int build_per_node(struct gfs2_sbd *sdp)
-{
-	struct gfs2_inode *per_node;
-	unsigned int j;
-	int err;
-
-	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
-			   GFS2_DIF_SYSTEM);
-	if (per_node == NULL) {
-		return errno;
-	}
-
-	for (j = 0; j < sdp->md.journals; j++) {
-		err = build_inum_range(per_node, j);
-		if (err) {
-			return err;
-		}
-		err = build_statfs_change(per_node, j);
-		if (err) {
-			return err;
-		}
-		err = build_quota_change(per_node, j);
-		if (err) {
-			return err;
-		}
-	}
-
-	if (cfg_debug) {
-		printf("\nper_node:\n");
-		lgfs2_dinode_print(per_node->i_bh->b_data);
-	}
-
-	inode_put(&per_node);
-	return 0;
-}
-
 int build_inum(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *ip;
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 17284976..9c9c3752 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -681,6 +681,46 @@ static int warn_of_destruction(const char *path)
 	return 0;
 }
 
+static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
+{
+	struct gfs2_inode *per_node;
+	unsigned int j;
+	int err;
+
+	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
+			   GFS2_DIF_SYSTEM);
+	if (per_node == NULL) {
+		fprintf(stderr, _("Error building '%s': %s\n"), "per_node", strerror(errno));
+		return -1;
+	}
+	for (j = 0; j < sdp->md.journals; j++) {
+		err = build_inum_range(per_node, j);
+		if (err) {
+			fprintf(stderr, _("Error building '%s': %s\n"), "inum_range",
+			        strerror(errno));
+			return err;
+		}
+		err = build_statfs_change(per_node, j);
+		if (err) {
+			fprintf(stderr, _("Error building '%s': %s\n"), "statfs_change",
+			        strerror(errno));
+			return err;
+		}
+		err = build_quota_change(per_node, j);
+		if (err) {
+			fprintf(stderr, _("Error building '%s': %s\n"), "quota_change",
+			        strerror(errno));
+			return err;
+		}
+	}
+	if (opts->debug) {
+		printf("\nper_node:\n");
+		lgfs2_dinode_print(per_node->i_bh->b_data);
+	}
+	inode_put(&per_node);
+	return 0;
+}
+
 static int zero_gap(struct gfs2_sbd *sdp, uint64_t addr, size_t blocks)
 {
 	struct iovec *iov;
@@ -1234,11 +1274,10 @@ int main(int argc, char *argv[])
 	if (error != 0)
 		exit(1);
 
-	error = build_per_node(&sbd);
-	if (error) {
-		fprintf(stderr, _("Error building '%s': %s\n"), "per_node", strerror(errno));
-		exit(EXIT_FAILURE);
-	}
+	error = build_per_node(&sbd, &opts);
+	if (error != 0)
+		exit(1);
+
 	error = build_inum(&sbd);
 	if (error) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "inum", strerror(errno));
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 05/18] libgfs2: Return the inode from build_inum_range()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (3 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 04/18] libgfs2: Push down build_per_node() into the utils Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 06/18] libgfs2: Return the inode from build_statfs_change() Andrew Price
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c | 10 +++++++---
 gfs2/fsck/pass1.c           | 10 +++++++---
 gfs2/fsck/pass2.c           | 12 +++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 16 +++++-----------
 gfs2/mkfs/main_mkfs.c       | 14 +++++++++++---
 6 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9a326e7f..dd809e48 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2112,12 +2112,16 @@ static int build_per_node(struct gfs2_sbd *sdp)
 		return -1;
 	}
 	for (j = 0; j < sdp->md.journals; j++) {
-		err = build_inum_range(per_node, j);
-		if (err) {
+		struct gfs2_inode *ip;
+
+		ip = build_inum_range(per_node, j);
+		if (ip == NULL) {
 			log_crit(_("Error building '%s': %s\n"), "inum_range",
 			         strerror(errno));
-			return err;
+			return 1;
 		}
+		inode_put(&ip);
+
 		err = build_statfs_change(per_node, j);
 		if (err) {
 			log_crit(_("Error building '%s': %s\n"), "statfs_change",
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 38da46a6..8f576fe2 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1590,12 +1590,16 @@ int build_per_node(struct gfs2_sbd *sdp)
 		return -1;
 	}
 	for (j = 0; j < sdp->md.journals; j++) {
-		err = build_inum_range(per_node, j);
-		if (err) {
+		struct gfs2_inode *ip;
+
+		ip = build_inum_range(per_node, j);
+		if (ip == NULL) {
 			log_err(_("Error building '%s': %s\n"), "inum_range",
 			        strerror(errno));
-			return err;
+			return 1;
 		}
+		inode_put(&ip);
+
 		err = build_statfs_change(per_node, j);
 		if (err) {
 			log_err(_("Error building '%s': %s\n"), "statfs_change",
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 0ab35b55..229667fb 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1875,6 +1875,16 @@ build_it:
 	goto out_good;
 }
 
+static int fsck_build_inum_range(struct gfs2_inode *per_node, unsigned int n)
+{
+	struct gfs2_inode *ip = build_inum_range(per_node, n);
+
+	if (ip == NULL)
+		return 1;
+	inode_put(&ip);
+	return 0;
+}
+
 /* Check system directory inode                                           */
 /* Should work for all system directories: root, master, jindex, per_node */
 static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
@@ -1959,7 +1969,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
 		for (j = 0; j < sysinode->i_sbd->md.journals; j++) {
 			sprintf(fn, "inum_range%d", j);
 			error += check_pernode_for(j, sysinode, fn, 16, 0,
-						   NULL, build_inum_range);
+						   NULL, fsck_build_inum_range);
 			sprintf(fn, "statfs_change%d", j);
 			error += check_pernode_for(j, sysinode, fn, 24, 0,
 						   NULL, build_statfs_change);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 863b84e6..e9c51054 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -787,7 +787,7 @@ extern int do_init_statfs(struct gfs2_sbd *sdp);
 extern int gfs2_check_meta(const char *buf, int type);
 extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
 			      uint64_t *buf, uint8_t state);
-extern int build_inum_range(struct gfs2_inode *per_node, unsigned int j);
+extern struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, unsigned int n);
 extern int build_statfs_change(struct gfs2_inode *per_node, unsigned int j);
 extern int build_quota_change(struct gfs2_inode *per_node, unsigned int j);
 
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index c9c31dd2..96a62475 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -279,7 +279,7 @@ struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *master, struct lgfs2_in
 	return jindex;
 }
 
-int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
+struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 {
 	char name[256];
 	struct gfs2_inode *ip;
@@ -287,19 +287,13 @@ int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 	sprintf(name, "inum_range%u", j);
 	ip = createi(per_node, name, S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-	if (ip == NULL) {
-		return errno;
-	}
+	if (ip == NULL)
+		return NULL;
+
 	ip->i_size = sizeof(struct gfs2_inum_range);
 	lgfs2_dinode_out(ip, ip->i_bh->b_data);
 	bmodified(ip->i_bh);
-	if (cfg_debug) {
-		printf("\nInum Range %u:\n", j);
-		lgfs2_dinode_print(ip->i_bh->b_data);
-	}
-
-	inode_put(&ip);
-	return 0;
+	return ip;
 }
 
 int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 9c9c3752..ea4a653f 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -694,12 +694,20 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
 		return -1;
 	}
 	for (j = 0; j < sdp->md.journals; j++) {
-		err = build_inum_range(per_node, j);
-		if (err) {
+		struct gfs2_inode *ip;
+
+		ip = build_inum_range(per_node, j);
+		if (ip == NULL) {
 			fprintf(stderr, _("Error building '%s': %s\n"), "inum_range",
 			        strerror(errno));
-			return err;
+			return 1;
+		}
+		if (opts->debug) {
+			printf("\nInum Range %u:\n", j);
+			lgfs2_dinode_print(ip->i_bh->b_data);
 		}
+		inode_put(&ip);
+
 		err = build_statfs_change(per_node, j);
 		if (err) {
 			fprintf(stderr, _("Error building '%s': %s\n"), "statfs_change",
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 06/18] libgfs2: Return the inode from build_statfs_change()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (4 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 05/18] libgfs2: Return the inode from build_inum_range() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 07/18] libgfs2: Return the inode from build_quota_change() Andrew Price
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  8 +++++---
 gfs2/fsck/pass1.c           |  8 +++++---
 gfs2/fsck/pass2.c           | 12 +++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 16 +++++-----------
 gfs2/mkfs/main_mkfs.c       | 12 +++++++++---
 6 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index dd809e48..1cb2d6fa 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2122,12 +2122,14 @@ static int build_per_node(struct gfs2_sbd *sdp)
 		}
 		inode_put(&ip);
 
-		err = build_statfs_change(per_node, j);
-		if (err) {
+		ip = build_statfs_change(per_node, j);
+		if (ip == NULL) {
 			log_crit(_("Error building '%s': %s\n"), "statfs_change",
 			         strerror(errno));
-			return err;
+			return 1;
 		}
+		inode_put(&ip);
+
 		err = build_quota_change(per_node, j);
 		if (err) {
 			log_crit(_("Error building '%s': %s\n"), "quota_change",
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 8f576fe2..3df64de7 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1600,12 +1600,14 @@ int build_per_node(struct gfs2_sbd *sdp)
 		}
 		inode_put(&ip);
 
-		err = build_statfs_change(per_node, j);
-		if (err) {
+		ip = build_statfs_change(per_node, j);
+		if (ip == NULL) {
 			log_err(_("Error building '%s': %s\n"), "statfs_change",
 			        strerror(errno));
-			return err;
+			return 1;
 		}
+		inode_put(&ip);
+
 		err = build_quota_change(per_node, j);
 		if (err) {
 			log_err(_("Error building '%s': %s\n"), "quota_change",
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 229667fb..2e0c1bb7 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1885,6 +1885,16 @@ static int fsck_build_inum_range(struct gfs2_inode *per_node, unsigned int n)
 	return 0;
 }
 
+static int fsck_build_statfs_change(struct gfs2_inode *per_node, unsigned int n)
+{
+	struct gfs2_inode *ip = build_statfs_change(per_node, n);
+
+	if (ip == NULL)
+		return 1;
+	inode_put(&ip);
+	return 0;
+}
+
 /* Check system directory inode                                           */
 /* Should work for all system directories: root, master, jindex, per_node */
 static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
@@ -1972,7 +1982,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
 						   NULL, fsck_build_inum_range);
 			sprintf(fn, "statfs_change%d", j);
 			error += check_pernode_for(j, sysinode, fn, 24, 0,
-						   NULL, build_statfs_change);
+						   NULL, fsck_build_statfs_change);
 			sprintf(fn, "quota_change%d", j);
 			error += check_pernode_for(j, sysinode, fn, 1048576, 1,
 						   &quota_change_fxns,
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e9c51054..0c702df0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -788,7 +788,7 @@ extern int gfs2_check_meta(const char *buf, int type);
 extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
 			      uint64_t *buf, uint8_t state);
 extern struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, unsigned int n);
-extern int build_statfs_change(struct gfs2_inode *per_node, unsigned int j);
+extern struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, unsigned int j);
 extern int build_quota_change(struct gfs2_inode *per_node, unsigned int j);
 
 /* super.c */
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 96a62475..bd226e6d 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -296,7 +296,7 @@ struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 	return ip;
 }
 
-int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
+struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
 {
 	char name[256];
 	struct gfs2_inode *ip;
@@ -304,19 +304,13 @@ int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
 	sprintf(name, "statfs_change%u", j);
 	ip = createi(per_node, name, S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-	if (ip == NULL) {
-		return errno;
-	}
+	if (ip == NULL)
+		return NULL;
+
 	ip->i_size = sizeof(struct gfs2_statfs_change);
 	lgfs2_dinode_out(ip, ip->i_bh->b_data);
 	bmodified(ip->i_bh);
-	if (cfg_debug) {
-		printf("\nStatFS Change %u:\n", j);
-		lgfs2_dinode_print(ip->i_bh->b_data);
-	}
-
-	inode_put(&ip);
-	return 0;
+	return ip;
 }
 
 int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index ea4a653f..e0f42c5a 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -708,12 +708,18 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
 		}
 		inode_put(&ip);
 
-		err = build_statfs_change(per_node, j);
-		if (err) {
+		ip = build_statfs_change(per_node, j);
+		if (ip == NULL) {
 			fprintf(stderr, _("Error building '%s': %s\n"), "statfs_change",
 			        strerror(errno));
-			return err;
+			return 1;
 		}
+		if (opts->debug) {
+			printf("\nStatFS Change %u:\n", j);
+			lgfs2_dinode_print(ip->i_bh->b_data);
+		}
+		inode_put(&ip);
+
 		err = build_quota_change(per_node, j);
 		if (err) {
 			fprintf(stderr, _("Error building '%s': %s\n"), "quota_change",
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 07/18] libgfs2: Return the inode from build_quota_change()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (5 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 06/18] libgfs2: Return the inode from build_statfs_change() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 08/18] libgfs2: Return the inode from build_inum() Andrew Price
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  8 ++++----
 gfs2/fsck/pass1.c           |  8 ++++----
 gfs2/fsck/pass2.c           | 12 +++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 18 +++++-------------
 gfs2/mkfs/main_mkfs.c       | 12 ++++++++----
 6 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 1cb2d6fa..0953d2a7 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2103,7 +2103,6 @@ static int build_per_node(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *per_node;
 	unsigned int j;
-	int err;
 
 	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
 			   GFS2_DIF_SYSTEM);
@@ -2130,12 +2129,13 @@ static int build_per_node(struct gfs2_sbd *sdp)
 		}
 		inode_put(&ip);
 
-		err = build_quota_change(per_node, j);
-		if (err) {
+		ip = build_quota_change(per_node, j);
+		if (ip == NULL) {
 			log_crit(_("Error building '%s': %s\n"), "quota_change",
 			         strerror(errno));
-			return err;
+			return 1;
 		}
+		inode_put(&ip);
 	}
 	inode_put(&per_node);
 	return 0;
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 3df64de7..a016f2a4 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1581,7 +1581,6 @@ int build_per_node(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *per_node;
 	unsigned int j;
-	int err;
 
 	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
 			   GFS2_DIF_SYSTEM);
@@ -1608,12 +1607,13 @@ int build_per_node(struct gfs2_sbd *sdp)
 		}
 		inode_put(&ip);
 
-		err = build_quota_change(per_node, j);
-		if (err) {
+		ip = build_quota_change(per_node, j);
+		if (ip == NULL) {
 			log_err(_("Error building '%s': %s\n"), "quota_change",
 			        strerror(errno));
-			return err;
+			return 1;
 		}
+		inode_put(&ip);
 	}
 	inode_put(&per_node);
 	return 0;
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 2e0c1bb7..d82380a1 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1895,6 +1895,16 @@ static int fsck_build_statfs_change(struct gfs2_inode *per_node, unsigned int n)
 	return 0;
 }
 
+static int fsck_build_quota_change(struct gfs2_inode *per_node, unsigned int n)
+{
+	struct gfs2_inode *ip = build_quota_change(per_node, n);
+
+	if (ip == NULL)
+		return 1;
+	inode_put(&ip);
+	return 0;
+}
+
 /* Check system directory inode                                           */
 /* Should work for all system directories: root, master, jindex, per_node */
 static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
@@ -1986,7 +1996,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
 			sprintf(fn, "quota_change%d", j);
 			error += check_pernode_for(j, sysinode, fn, 1048576, 1,
 						   &quota_change_fxns,
-						   build_quota_change);
+						   fsck_build_quota_change);
 		}
 	}
 	return error;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 0c702df0..a928e1ab 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -789,7 +789,7 @@ extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
 			      uint64_t *buf, uint8_t state);
 extern struct gfs2_inode *build_inum_range(struct gfs2_inode *per_node, unsigned int n);
 extern struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, unsigned int j);
-extern int build_quota_change(struct gfs2_inode *per_node, unsigned int j);
+extern struct gfs2_inode *build_quota_change(struct gfs2_inode *per_node, unsigned int j);
 
 /* super.c */
 extern int check_sb(void *sbp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index bd226e6d..1d4635ab 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -313,7 +313,7 @@ struct gfs2_inode *build_statfs_change(struct gfs2_inode *per_node, unsigned int
 	return ip;
 }
 
-int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
+struct gfs2_inode *build_quota_change(struct gfs2_inode *per_node, unsigned int j)
 {
 	struct gfs2_sbd *sdp = per_node->i_sbd;
 	struct gfs2_meta_header mh;
@@ -331,9 +331,8 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
 
 	sprintf(name, "quota_change%u", j);
 	ip = createi(per_node, name, S_IFREG | 0600, GFS2_DIF_SYSTEM);
-	if (ip == NULL) {
-		return errno;
-	}
+	if (ip == NULL)
+		return NULL;
 
 	hgt = calc_tree_height(ip, (blocks + 1) * sdp->sd_bsize);
 	build_height(ip, hgt);
@@ -341,21 +340,14 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
 	for (x = 0; x < blocks; x++) {
 		bh = get_file_buf(ip, x, 0);
 		if (!bh)
-			return -1;
+			return NULL;
 
 		memset(bh->b_data, 0, sdp->sd_bsize);
 		memcpy(bh->b_data, &mh, sizeof(mh));
 		bmodified(bh);
 		brelse(bh);
 	}
-
-	if (cfg_debug) {
-		printf("\nQuota Change %u:\n", j);
-		lgfs2_dinode_print(ip->i_bh->b_data);
-	}
-
-	inode_put(&ip);
-	return 0;
+	return ip;
 }
 
 int build_inum(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e0f42c5a..c4415ee3 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -685,7 +685,6 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
 {
 	struct gfs2_inode *per_node;
 	unsigned int j;
-	int err;
 
 	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
 			   GFS2_DIF_SYSTEM);
@@ -720,12 +719,17 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
 		}
 		inode_put(&ip);
 
-		err = build_quota_change(per_node, j);
-		if (err) {
+		ip = build_quota_change(per_node, j);
+		if (ip == NULL) {
 			fprintf(stderr, _("Error building '%s': %s\n"), "quota_change",
 			        strerror(errno));
-			return err;
+			return 1;
+		}
+		if (opts->debug) {
+			printf("\nQuota Change %u:\n", j);
+			lgfs2_dinode_print(ip->i_bh->b_data);
 		}
+		inode_put(&ip);
 	}
 	if (opts->debug) {
 		printf("\nper_node:\n");
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 08/18] libgfs2: Return the inode from build_inum()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (6 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 07/18] libgfs2: Return the inode from build_quota_change() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 09/18] libgfs2: Return the inode from build_statfs() Andrew Price
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  5 ++---
 gfs2/fsck/initialize.c      | 25 ++++++++++++-------------
 gfs2/fsck/pass1.c           | 11 ++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 14 ++------------
 gfs2/mkfs/main_mkfs.c       |  9 ++++++---
 6 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 0953d2a7..210528c9 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2343,13 +2343,12 @@ int main(int argc, char **argv)
 			exit(-1);
 		}
 		/* Create the empty inode number file */
-		error = build_inum(&sb2); /* Does not do inode_put */
-		if (error) {
+		sb2.md.inum = build_inum(&sb2); /* Does not do inode_put */
+		if (sb2.md.inum == NULL) {
 			log_crit(_("Error building inum inode: %s\n"),
 			         strerror(error));
 			exit(-1);
 		}
-		gfs2_lookupi(sb2.master_dir, "inum", 4, &sb2.md.inum);
 		/* Create the statfs file */
 		error = build_statfs(&sb2); /* Does not do inode_put */
 		if (error) {
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index b9db79b0..a46d3ecb 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -504,12 +504,14 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 			exit(FSCK_ERROR);
 		}
 	} else {
-		err = build_inum(sdp);
-		if (err) {
-			log_crit(_("Error %d building inum inode\n"), err);
+		sdp->md.inum = build_inum(sdp);
+		if (sdp->md.inum == NULL) {
+			log_crit(_("Error building inum inode: %s\n"), strerror(errno));
 			exit(FSCK_ERROR);
 		}
-		gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
+		/* Write the inode but don't free it, to avoid doing an extra lookup */
+		lgfs2_dinode_out(sdp->md.inum, sdp->md.inum->i_bh->b_data);
+		bwrite(sdp->md.inum->i_bh);
 	}
 
 	if (fix_md.statfs) {
@@ -798,17 +800,14 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 					   "a valid inum file; aborting.\n"));
 				goto fail;
 			}
-			err = build_inum(sdp);
-			if (err) {
-				log_crit(_("Error %d rebuilding inum inode\n"),
-					 err);
+			sdp->md.inum = build_inum(sdp);
+			if (sdp->md.inum == NULL) {
+				log_crit(_("Error rebuilding inum inode: %s\n"), strerror(errno));
 				exit(FSCK_ERROR);
 			}
-			gfs2_lookupi(sdp->master_dir, "inum", 4,
-				     &sdp->md.inum);
-			if (!sdp->md.inum) {
-				log_crit(_("System inum inode was not rebuilt."
-					   " Aborting.\n"));
+			lgfs2_dinode_out(sdp->md.inum, sdp->md.inum->i_bh->b_data);
+			if (bwrite(sdp->md.inum->i_bh) != 0) {
+				log_crit(_("System inum inode was not rebuilt. Aborting.\n"));
 				goto fail;
 			}
 		}
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index a016f2a4..acd9929f 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1619,6 +1619,15 @@ int build_per_node(struct gfs2_sbd *sdp)
 	return 0;
 }
 
+static int fsck_build_inum(struct gfs2_sbd *sdp)
+{
+	struct gfs2_inode *ip = build_inum(sdp);
+	if (ip == NULL)
+		return -1;
+	inode_put(&ip);
+	return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
 	int journal_count;
@@ -1648,7 +1657,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
 		return -1;
 	}
 	if (!sdp->gfs1 &&
-	    check_system_inode(sdp, &sdp->md.inum, "inum", build_inum, 0,
+	    check_system_inode(sdp, &sdp->md.inum, "inum", fsck_build_inum, 0,
 			       sdp->master_dir, 1)) {
 		stack;
 		return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index a928e1ab..aea2b676 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -777,7 +777,7 @@ extern int lgfs2_sb_write(const struct gfs2_sbd *sdp, int fd);
 extern int build_journal(struct gfs2_sbd *sdp, int j,
 			 struct gfs2_inode *jindex);
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct lgfs2_inum *jnls, size_t nmemb);
-extern int build_inum(struct gfs2_sbd *sdp);
+extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
 extern int build_statfs(struct gfs2_sbd *sdp);
 extern int build_rindex(struct gfs2_sbd *sdp);
 extern int build_quota(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 1d4635ab..69cce676 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -350,23 +350,13 @@ struct gfs2_inode *build_quota_change(struct gfs2_inode *per_node, unsigned int
 	return ip;
 }
 
-int build_inum(struct gfs2_sbd *sdp)
+struct gfs2_inode *build_inum(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *ip;
 
 	ip = createi(sdp->master_dir, "inum", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-	if (ip == NULL) {
-		return errno;
-	}
-
-	if (cfg_debug) {
-		printf("\nInum Inode:\n");
-		lgfs2_dinode_print(ip->i_bh->b_data);
-	}
-
-	inode_put(&ip);
-	return 0;
+	return ip;
 }
 
 int build_statfs(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index c4415ee3..0aff266f 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1296,12 +1296,15 @@ int main(int argc, char *argv[])
 	if (error != 0)
 		exit(1);
 
-	error = build_inum(&sbd);
-	if (error) {
+	sbd.md.inum = build_inum(&sbd);
+	if (sbd.md.inum == NULL) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "inum", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
-	gfs2_lookupi(sbd.master_dir, "inum", 4, &sbd.md.inum);
+	if (opts.debug) {
+		printf("\nInum Inode:\n");
+		lgfs2_dinode_print(sbd.md.inum->i_bh->b_data);
+	}
 	error = build_statfs(&sbd);
 	if (error) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "statfs", strerror(errno));
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 09/18] libgfs2: Return the inode from build_statfs()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (7 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 08/18] libgfs2: Return the inode from build_inum() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 10/18] libgfs2: Return the inode from build_rindex() Andrew Price
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  5 ++---
 gfs2/fsck/initialize.c      | 16 +++++++++-------
 gfs2/fsck/pass1.c           | 11 ++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 14 ++------------
 gfs2/mkfs/main_mkfs.c       |  9 ++++++---
 6 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 210528c9..93c9755b 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2350,13 +2350,12 @@ int main(int argc, char **argv)
 			exit(-1);
 		}
 		/* Create the statfs file */
-		error = build_statfs(&sb2); /* Does not do inode_put */
-		if (error) {
+		sb2.md.statfs = build_statfs(&sb2); /* Does not do inode_put */
+		if (sb2.md.statfs == NULL) {
 			log_crit(_("Error building statfs inode: %s\n"),
 			         strerror(error));
 			exit(-1);
 		}
-		gfs2_lookupi(sb2.master_dir, "statfs", 6, &sb2.md.statfs);
 		do_init_statfs(&sb2);
 
 		/* Create the resource group index file */
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index a46d3ecb..bb2bcfb7 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -524,12 +524,14 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 			exit(FSCK_ERROR);
 		}
 	} else {
-		err = build_statfs(sdp);
-		if (err) {
+		sdp->md.statfs = build_statfs(sdp);
+		if (sdp->md.statfs == NULL) {
 			log_crit(_("Error %d building statfs inode\n"), err);
 			exit(FSCK_ERROR);
 		}
-		gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
+		/* Write the inode but don't free it, to avoid doing an extra lookup */
+		lgfs2_dinode_out(sdp->md.statfs, sdp->md.statfs->i_bh->b_data);
+		bwrite(sdp->md.statfs->i_bh);
 	}
 
 	if (fix_md.riinode) {
@@ -851,13 +853,13 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 				   "statfs file; aborting.\n"));
 			goto fail;
 		}
-		err = build_statfs(sdp);
-		if (err) {
+		sdp->md.statfs = build_statfs(sdp);
+		if (sdp->md.statfs == NULL) {
 			log_crit(_("Error %d rebuilding statfs inode\n"), err);
 			exit(FSCK_ERROR);
 		}
-		gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
-		if (!sdp->md.statfs) {
+		lgfs2_dinode_out(sdp->md.statfs, sdp->md.statfs->i_bh->b_data);
+		if (bwrite(sdp->md.statfs->i_bh) != 0) {
 			log_err( _("Rebuild of statfs system file failed."));
 			log_err( _("fsck.gfs2 cannot continue without "
 				   "a valid statfs file; aborting.\n"));
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index acd9929f..b19292eb 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1628,6 +1628,15 @@ static int fsck_build_inum(struct gfs2_sbd *sdp)
 	return 0;
 }
 
+static int fsck_build_statfs(struct gfs2_sbd *sdp)
+{
+	struct gfs2_inode *ip = build_statfs(sdp);
+	if (ip == NULL)
+		return -1;
+	inode_put(&ip);
+	return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
 	int journal_count;
@@ -1662,7 +1671,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
 		stack;
 		return -1;
 	}
-	if (check_system_inode(sdp, &sdp->md.statfs, "statfs", build_statfs, 0,
+	if (check_system_inode(sdp, &sdp->md.statfs, "statfs", fsck_build_statfs, 0,
 			       sdp->master_dir, !sdp->gfs1)) {
 		stack;
 		return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index aea2b676..83fc90ce 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -778,7 +778,7 @@ extern int build_journal(struct gfs2_sbd *sdp, int j,
 			 struct gfs2_inode *jindex);
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct lgfs2_inum *jnls, size_t nmemb);
 extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
-extern int build_statfs(struct gfs2_sbd *sdp);
+extern struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp);
 extern int build_rindex(struct gfs2_sbd *sdp);
 extern int build_quota(struct gfs2_sbd *sdp);
 extern int build_root(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 69cce676..f790adcc 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -359,23 +359,13 @@ struct gfs2_inode *build_inum(struct gfs2_sbd *sdp)
 	return ip;
 }
 
-int build_statfs(struct gfs2_sbd *sdp)
+struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *ip;
 
 	ip = createi(sdp->master_dir, "statfs", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-	if (ip == NULL) {
-		return errno;
-	}
-
-	if (cfg_debug) {
-		printf("\nStatFS Inode:\n");
-		lgfs2_dinode_print(ip->i_bh->b_data);
-	}
-
-	inode_put(&ip);
-	return 0;
+	return ip;
 }
 
 int build_rindex(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 0aff266f..647c969b 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1305,12 +1305,15 @@ int main(int argc, char *argv[])
 		printf("\nInum Inode:\n");
 		lgfs2_dinode_print(sbd.md.inum->i_bh->b_data);
 	}
-	error = build_statfs(&sbd);
-	if (error) {
+	sbd.md.statfs = build_statfs(&sbd);
+	if (sbd.md.statfs == NULL) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "statfs", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
-	gfs2_lookupi(sbd.master_dir, "statfs", 6, &sbd.md.statfs);
+	if (opts.debug) {
+		printf("\nStatFS Inode:\n");
+		lgfs2_dinode_print(sbd.md.statfs->i_bh->b_data);
+	}
 	error = build_rindex(&sbd);
 	if (error) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "rindex", strerror(errno));
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 10/18] libgfs2: Return the inode from build_rindex()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (8 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 09/18] libgfs2: Return the inode from build_statfs() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 11/18] libgfs2: Return the inode from build_quota() Andrew Price
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  8 +++++---
 gfs2/fsck/initialize.c      | 15 +++++++++------
 gfs2/fsck/pass1.c           | 11 ++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 20 +++++++-------------
 gfs2/mkfs/main_mkfs.c       | 10 ++++++++--
 6 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 93c9755b..5a542e29 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2308,6 +2308,7 @@ int main(int argc, char **argv)
 	/* Create our system files and directories.       */
 	/* ---------------------------------------------- */
 	if (!error) {
+		struct gfs2_inode *ip;
 		int jreduce = 0;
 
 		/* Now we've got to treat it as a gfs2 file system */
@@ -2359,12 +2360,13 @@ int main(int argc, char **argv)
 		do_init_statfs(&sb2);
 
 		/* Create the resource group index file */
-		error = build_rindex(&sb2);
-		if (error) {
+		ip = build_rindex(&sb2);
+		if (ip == NULL) {
 			log_crit(_("Error building rindex inode: %s\n"),
-			         strerror(error));
+			         strerror(errno));
 			exit(-1);
 		}
+		inode_put(&ip);
 		/* Create the quota file */
 		error = build_quota(&sb2);
 		if (error) {
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index bb2bcfb7..e1c71fc8 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -544,11 +544,12 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 			exit(FSCK_ERROR);
 		}
 	} else {
-		err = build_rindex(sdp);
-		if (err) {
-			log_crit(_("Error %d building rindex inode\n"), err);
+		struct gfs2_inode *rip = build_rindex(sdp);
+		if (rip == NULL) {
+			log_crit(_("Error building rindex inode: %s\n"), strerror(errno));
 			exit(FSCK_ERROR);
 		}
+		inode_put(&rip);
 	}
 
 	if (fix_md.qinode) {
@@ -1514,7 +1515,7 @@ static int reconstruct_journals(struct gfs2_sbd *sdp)
  */
 static int init_rindex(struct gfs2_sbd *sdp)
 {
-	int err;
+	struct gfs2_inode *ip;
 
 	if (sdp->gfs1)
 		sdp->md.riinode = lgfs2_inode_read(sdp, sdp->sd_rindex_di.in_addr);
@@ -1529,10 +1530,12 @@ static int init_rindex(struct gfs2_sbd *sdp)
 		log_crit(_("Error: Cannot proceed without a valid rindex.\n"));
 		return -1;
 	}
-	if ((err = build_rindex(sdp))) {
-		log_crit(_("Error %d rebuilding rindex\n"), err);
+	ip = build_rindex(sdp);
+	if (ip == NULL) {
+		log_crit(_("Error rebuilding rindex: %s\n"), strerror(errno));
 		return -1;
 	}
+	inode_put(&ip);
 	return 0;
 }
 
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index b19292eb..389cfbe5 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1637,6 +1637,15 @@ static int fsck_build_statfs(struct gfs2_sbd *sdp)
 	return 0;
 }
 
+static int fsck_build_rindex(struct gfs2_sbd *sdp)
+{
+	struct gfs2_inode *ip = build_rindex(sdp);
+	if (ip == NULL)
+		return -1;
+	inode_put(&ip);
+	return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
 	int journal_count;
@@ -1682,7 +1691,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
 		stack;
 		return -1;
 	}
-	if (check_system_inode(sdp, &sdp->md.riinode, "rindex", build_rindex,
+	if (check_system_inode(sdp, &sdp->md.riinode, "rindex", fsck_build_rindex,
 			       0, sdp->master_dir, !sdp->gfs1)) {
 		stack;
 		return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 83fc90ce..3c1ec9b2 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -779,7 +779,7 @@ extern int build_journal(struct gfs2_sbd *sdp, int j,
 extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct lgfs2_inum *jnls, size_t nmemb);
 extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp);
-extern int build_rindex(struct gfs2_sbd *sdp);
+extern struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp);
 extern int build_quota(struct gfs2_sbd *sdp);
 extern int build_root(struct gfs2_sbd *sdp);
 extern int do_init_inum(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index f790adcc..eb4bbe01 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -368,7 +368,7 @@ struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp)
 	return ip;
 }
 
-int build_rindex(struct gfs2_sbd *sdp)
+struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *ip;
 	struct osi_node *n, *next = NULL;
@@ -378,9 +378,9 @@ int build_rindex(struct gfs2_sbd *sdp)
 
 	ip = createi(sdp->master_dir, "rindex", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-	if (ip == NULL) {
-		return errno;
-	}
+	if (ip == NULL)
+		return NULL;
+
 	ip->i_payload_format = GFS2_FORMAT_RI;
 	bmodified(ip->i_bh);
 
@@ -392,20 +392,14 @@ int build_rindex(struct gfs2_sbd *sdp)
 
 		count = gfs2_writei(ip, buf, ip->i_size, sizeof(struct gfs2_rindex));
 		if (count != sizeof(struct gfs2_rindex))
-			return -1;
+			return NULL;
 	}
 	memset(buf, 0, sizeof(struct gfs2_rindex));
 	count = __gfs2_writei(ip, buf, ip->i_size, sizeof(struct gfs2_rindex), 0);
 	if (count != sizeof(struct gfs2_rindex))
-		return -1;
-
-	if (cfg_debug) {
-		printf("\nResource Index:\n");
-		lgfs2_dinode_print(ip->i_bh->b_data);
-	}
+		return NULL;
 
-	inode_put(&ip);
-	return 0;
+	return ip;
 }
 
 int build_quota(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 647c969b..23d9f1ec 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1198,6 +1198,7 @@ int main(int argc, char *argv[])
 {
 	struct gfs2_sbd sbd;
 	struct mkfs_opts opts;
+	struct gfs2_inode *ip;
 	lgfs2_rgrps_t rgs;
 	uint64_t rgaddr;
 	int error;
@@ -1314,11 +1315,16 @@ int main(int argc, char *argv[])
 		printf("\nStatFS Inode:\n");
 		lgfs2_dinode_print(sbd.md.statfs->i_bh->b_data);
 	}
-	error = build_rindex(&sbd);
-	if (error) {
+	ip = build_rindex(&sbd);
+	if (ip == NULL) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "rindex", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
+	if (opts.debug) {
+		printf("\nResource Index:\n");
+		lgfs2_dinode_print(ip->i_bh->b_data);
+	}
+	inode_put(&ip);
 	if (!opts.quiet) {
 		printf("%s", _("Creating quota file: "));
 		fflush(stdout);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 11/18] libgfs2: Return the inode from build_quota()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (9 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 10/18] libgfs2: Return the inode from build_rindex() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 12/18] libgfs2: Move debugging printf out of build_root() Andrew Price
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This allows the caller to call inode_put() when it's convenient and also
allows the debug message printing to be moved out of the function.
fsck.gfs2 passes the function by reference so it needs a shim until the
other builder functions can be given the same signature.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c |  5 +++--
 gfs2/fsck/initialize.c      | 17 +++++++++--------
 gfs2/fsck/pass1.c           | 11 ++++++++++-
 gfs2/libgfs2/libgfs2.h      |  2 +-
 gfs2/libgfs2/structures.c   | 20 +++++++-------------
 gfs2/mkfs/main_mkfs.c       |  9 +++++++--
 6 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 5a542e29..8667d8fb 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2368,12 +2368,13 @@ int main(int argc, char **argv)
 		}
 		inode_put(&ip);
 		/* Create the quota file */
-		error = build_quota(&sb2);
-		if (error) {
+		ip = build_quota(&sb2);
+		if (ip == NULL) {
 			log_crit(_("Error building quota inode: %s\n"),
 			         strerror(error));
 			exit(-1);
 		}
+		inode_put(&ip);
 
 		/* Copy out the master dinode */
 		if (sb2.master_dir->i_bh->b_modified)
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index e1c71fc8..a2bc44c0 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -562,11 +562,12 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 			exit(FSCK_ERROR);
 		}
 	} else {
-		err = build_quota(sdp);
-		if (err) {
-			log_crit(_("Error %d building quota inode\n"), err);
+		struct gfs2_inode *qip = build_quota(sdp);
+		if (qip == NULL) {
+			log_crit(_("Error building quota inode: %s\n"), strerror(errno));
 			exit(FSCK_ERROR);
 		}
+		inode_put(&qip);
 	}
 
 	log_err(_("Master directory rebuilt.\n"));
@@ -911,13 +912,13 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 				   "rebuilt.  Aborting.\n"));
 			goto fail;
 		}
-		err = build_quota(sdp);
-		if (err) {
-			log_crit(_("Error %d rebuilding quota inode\n"), err);
+		sdp->md.qinode = build_quota(sdp);
+		if (sdp->md.qinode == NULL) {
+			log_crit(_("Error rebuilding quota inode: %s\n"), strerror(errno));
 			exit(FSCK_ERROR);
 		}
-		gfs2_lookupi(sdp->master_dir, "quota", 5, &sdp->md.qinode);
-		if (!sdp->md.qinode) {
+		lgfs2_dinode_out(sdp->md.qinode, sdp->md.qinode->i_bh->b_data);
+		if (bwrite(sdp->md.qinode->i_bh) != 0) {
 			log_crit(_("Unable to rebuild system quota file "
 				   "inode.  Aborting.\n"));
 			goto fail;
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 389cfbe5..ad16971e 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1646,6 +1646,15 @@ static int fsck_build_rindex(struct gfs2_sbd *sdp)
 	return 0;
 }
 
+static int fsck_build_quota(struct gfs2_sbd *sdp)
+{
+	struct gfs2_inode *ip = build_quota(sdp);
+	if (ip == NULL)
+		return -1;
+	inode_put(&ip);
+	return 0;
+}
+
 static int check_system_inodes(struct gfs2_sbd *sdp)
 {
 	int journal_count;
@@ -1696,7 +1705,7 @@ static int check_system_inodes(struct gfs2_sbd *sdp)
 		stack;
 		return -1;
 	}
-	if (check_system_inode(sdp, &sdp->md.qinode, "quota", build_quota,
+	if (check_system_inode(sdp, &sdp->md.qinode, "quota", fsck_build_quota,
 			       0, sdp->master_dir, !sdp->gfs1)) {
 		stack;
 		return -1;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 3c1ec9b2..3396ddb0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -780,7 +780,7 @@ extern struct gfs2_inode *lgfs2_build_jindex(struct gfs2_inode *metafs, struct l
 extern struct gfs2_inode *build_inum(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_statfs(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp);
-extern int build_quota(struct gfs2_sbd *sdp);
+extern struct gfs2_inode *build_quota(struct gfs2_sbd *sdp);
 extern int build_root(struct gfs2_sbd *sdp);
 extern int do_init_inum(struct gfs2_sbd *sdp);
 extern int do_init_statfs(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index eb4bbe01..6cc0a8dd 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -402,7 +402,7 @@ struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp)
 	return ip;
 }
 
-int build_quota(struct gfs2_sbd *sdp)
+struct gfs2_inode *build_quota(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *ip;
 	struct gfs2_quota qu;
@@ -410,9 +410,9 @@ int build_quota(struct gfs2_sbd *sdp)
 
 	ip = createi(sdp->master_dir, "quota", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
-	if (ip == NULL) {
-		return errno;
-	}
+	if (ip == NULL)
+		return NULL;
+
 	ip->i_payload_format = GFS2_FORMAT_QU;
 	bmodified(ip->i_bh);
 
@@ -421,18 +421,12 @@ int build_quota(struct gfs2_sbd *sdp)
 
 	count = gfs2_writei(ip, &qu, ip->i_size, sizeof(struct gfs2_quota));
 	if (count != sizeof(struct gfs2_quota))
-		return -1;
+		return NULL;
 	count = gfs2_writei(ip, &qu, ip->i_size, sizeof(struct gfs2_quota));
 	if (count != sizeof(struct gfs2_quota))
-		return -1;
-
-	if (cfg_debug) {
-		printf("\nRoot quota:\n");
-		lgfs2_quota_print(&qu);
-	}
+		return NULL;
 
-	inode_put(&ip);
-	return 0;
+	return ip;
 }
 
 int build_root(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 23d9f1ec..56a3b7d2 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1329,11 +1329,16 @@ int main(int argc, char *argv[])
 		printf("%s", _("Creating quota file: "));
 		fflush(stdout);
 	}
-	error = build_quota(&sbd);
-	if (error) {
+	ip = build_quota(&sbd);
+	if (ip == NULL) {
 		fprintf(stderr, _("Error building '%s': %s\n"), "quota", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
+	if (opts.debug) {
+		printf("\nQuota:\n");
+		lgfs2_dinode_print(ip->i_bh->b_data);
+	}
+	inode_put(&ip);
 	if (!opts.quiet)
 		printf("%s", _("Done\n"));
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 12/18] libgfs2: Move debugging printf out of build_root()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (10 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 11/18] libgfs2: Return the inode from build_quota() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 13/18] libgfs2: Remove debugging printf from do_init_statfs() Andrew Price
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

mkfs.gfs2 is the only place it could ever get printed so move it there
instead.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/libgfs2/structures.c | 4 ----
 gfs2/mkfs/main_mkfs.c     | 4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 6cc0a8dd..7ac38f92 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -450,10 +450,6 @@ int build_root(struct gfs2_sbd *sdp)
 	if (sdp->md.rooti == NULL)
 		return -1;
 
-	if (cfg_debug) {
-		printf("\nRoot directory:\n");
-		lgfs2_dinode_print(bh->b_data);
-	}
 	sdp->md.rooti->bh_owned = 1;
 	return 0;
 }
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 56a3b7d2..9a73ff7b 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1343,6 +1343,10 @@ int main(int argc, char *argv[])
 		printf("%s", _("Done\n"));
 
 	build_root(&sbd);
+	if (opts.debug) {
+		printf("\nRoot directory:\n");
+		lgfs2_dinode_print(sbd.md.rooti->i_bh->b_data);
+	}
 	sbd.sd_root_dir = sbd.md.rooti->i_num;
 
 	strncpy(sbd.sd_lockproto, opts.lockproto, GFS2_LOCKNAME_LEN - 1);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 13/18] libgfs2: Remove debugging printf from do_init_statfs()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (11 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 12/18] libgfs2: Move debugging printf out of build_root() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 14/18] libgfs2: Move debugging output out of do_init_inum() Andrew Price
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Allow the caller to provide a pointer to a statfs change structure so
that it can do its own debug message printing. This is only used by
mkfs.gfs2.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c | 2 +-
 gfs2/fsck/initialize.c      | 2 +-
 gfs2/fsck/main.c            | 2 +-
 gfs2/libgfs2/libgfs2.h      | 2 +-
 gfs2/libgfs2/structures.c   | 8 +++-----
 gfs2/mkfs/main_mkfs.c       | 8 ++++++--
 6 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 8667d8fb..5bfc616b 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2357,7 +2357,7 @@ int main(int argc, char **argv)
 			         strerror(error));
 			exit(-1);
 		}
-		do_init_statfs(&sb2);
+		do_init_statfs(&sb2, NULL);
 
 		/* Create the resource group index file */
 		ip = build_rindex(&sb2);
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index a2bc44c0..fab9a1e7 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -867,7 +867,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 				   "a valid statfs file; aborting.\n"));
 			goto fail;
 		}
-		do_init_statfs(sdp);
+		do_init_statfs(sdp, NULL);
 	}
 	if (sdp->md.statfs->i_size) {
 		buf = malloc(sdp->md.statfs->i_size);
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index 35b13950..cb667815 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -228,7 +228,7 @@ static int check_statfs(struct gfs2_sbd *sdp)
 		return 0;
 	}
 
-	do_init_statfs(sdp);
+	do_init_statfs(sdp, NULL);
 	log_err( _("The statfs file was fixed.\n"));
 	errors_corrected++;
 	return 0;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 3396ddb0..fa710a6c 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -783,7 +783,7 @@ extern struct gfs2_inode *build_rindex(struct gfs2_sbd *sdp);
 extern struct gfs2_inode *build_quota(struct gfs2_sbd *sdp);
 extern int build_root(struct gfs2_sbd *sdp);
 extern int do_init_inum(struct gfs2_sbd *sdp);
-extern int do_init_statfs(struct gfs2_sbd *sdp);
+extern int do_init_statfs(struct gfs2_sbd *sdp, struct gfs2_statfs_change *res);
 extern int gfs2_check_meta(const char *buf, int type);
 extern unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx,
 			      uint64_t *buf, uint8_t state);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 7ac38f92..d4a08c43 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -471,7 +471,7 @@ int do_init_inum(struct gfs2_sbd *sdp)
 	return 0;
 }
 
-int do_init_statfs(struct gfs2_sbd *sdp)
+int do_init_statfs(struct gfs2_sbd *sdp, struct gfs2_statfs_change *res)
 {
 	struct gfs2_inode *ip = sdp->md.statfs;
 	struct gfs2_statfs_change sc;
@@ -485,10 +485,8 @@ int do_init_statfs(struct gfs2_sbd *sdp)
 	if (count != sizeof(sc))
 		return -1;
 
-	if (cfg_debug) {
-		printf("\nStatfs:\n");
-		lgfs2_statfs_change_print(&sc);
-	}
+	if (res)
+		*res = sc;
 	return 0;
 }
 
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 9a73ff7b..36341d99 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1196,6 +1196,7 @@ static int open_dev(struct mkfs_dev *dev, int withprobe)
 #ifndef UNITTESTS
 int main(int argc, char *argv[])
 {
+	struct gfs2_statfs_change sc;
 	struct gfs2_sbd sbd;
 	struct mkfs_opts opts;
 	struct gfs2_inode *ip;
@@ -1355,8 +1356,11 @@ int main(int argc, char *argv[])
 	sbd.sd_locktable[GFS2_LOCKNAME_LEN - 1] = '\0';
 
 	do_init_inum(&sbd);
-	do_init_statfs(&sbd);
-
+	do_init_statfs(&sbd, &sc);
+	if (opts.debug) {
+		printf("\nStatfs:\n");
+		lgfs2_statfs_change_print(&sc);
+	}
 	inode_put(&sbd.md.rooti);
 	inode_put(&sbd.master_dir);
 	inode_put(&sbd.md.inum);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 14/18] libgfs2: Move debugging output out of do_init_inum()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (12 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 13/18] libgfs2: Remove debugging printf from do_init_statfs() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 15/18] libgfs2: Remove debugging printfs from fix_device_geometry() Andrew Price
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/libgfs2/structures.c | 3 ---
 gfs2/mkfs/main_mkfs.c     | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index d4a08c43..9b78ed51 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -465,9 +465,6 @@ int do_init_inum(struct gfs2_sbd *sdp)
 	if (count != sizeof(uint64_t))
 		return -1;
 
-	if (cfg_debug)
-		printf("\nNext Inum: %"PRIu64"\n",
-		       sdp->md.next_inum);
 	return 0;
 }
 
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 36341d99..ae192bd4 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -1356,6 +1356,9 @@ int main(int argc, char *argv[])
 	sbd.sd_locktable[GFS2_LOCKNAME_LEN - 1] = '\0';
 
 	do_init_inum(&sbd);
+	if (opts.debug)
+		printf("\nNext Inum: %"PRIu64"\n", sbd.md.next_inum);
+
 	do_init_statfs(&sbd, &sc);
 	if (opts.debug) {
 		printf("\nStatfs:\n");
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 15/18] libgfs2: Remove debugging printfs from fix_device_geometry()
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (13 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 14/18] libgfs2: Move debugging output out of do_init_inum() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 16/18] libgfs2: Remove config.[ch] Andrew Price
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This block never gets executed as the only utils that enable cfg_debug
don't call the function.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/libgfs2/device_geometry.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index 4a0aeab2..b149d2c0 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -98,10 +98,4 @@ void fix_device_geometry(struct gfs2_sbd *sdp)
 	struct device *device = &sdp->device;
 
 	device->length = sdp->dinfo.size / sdp->sd_bsize;
-
-	if (cfg_debug) {
-		printf("\nDevice Geometry:  (in FS blocks)\n");
-		printf("  length = %"PRIu64"\n", device->length);
-		printf("\nDevice Size: %"PRIu64"\n", sdp->dinfo.size);
-	}
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 16/18] libgfs2: Remove config.[ch]
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (14 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 15/18] libgfs2: Remove debugging printfs from fix_device_geometry() Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 17/18] libgfs2: Move struct printing functions out of libgfs2 Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 18/18] libgfs2: Remove print_it extern requirement Andrew Price
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

The cfg_debug bits are no longer used.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/libgfs2/Makefile.am       | 2 --
 gfs2/libgfs2/checks.am         | 1 -
 gfs2/libgfs2/config.c          | 9 ---------
 gfs2/libgfs2/config.h          | 6 ------
 gfs2/libgfs2/device_geometry.c | 1 -
 gfs2/libgfs2/libgfs2.h         | 3 ---
 gfs2/libgfs2/structures.c      | 1 -
 gfs2/mkfs/main_jadd.c          | 1 -
 gfs2/mkfs/main_mkfs.c          | 1 -
 9 files changed, 25 deletions(-)
 delete mode 100644 gfs2/libgfs2/config.c
 delete mode 100644 gfs2/libgfs2/config.h

diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index c3f2425d..123b85b7 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -23,7 +23,6 @@ noinst_HEADERS = \
 	libgfs2.h \
 	crc32c.h \
 	lang.h \
-	config.h \
 	rgrp.h
 
 noinst_LTLIBRARIES = libgfs2.la
@@ -40,7 +39,6 @@ libgfs2_la_SOURCES = \
 	buf.c \
 	gfs2_disk_hash.c \
 	ondisk.c \
-	config.c \
 	device_geometry.c \
 	fs_ops.c \
 	recovery.c \
diff --git a/gfs2/libgfs2/checks.am b/gfs2/libgfs2/checks.am
index 18d719ab..d1aa7189 100644
--- a/gfs2/libgfs2/checks.am
+++ b/gfs2/libgfs2/checks.am
@@ -12,7 +12,6 @@ check_libgfs2_SOURCES = \
 	device_geometry.c \
 	fs_ops.c \
 	structures.c \
-	config.c \
 	fs_bits.c \
 	gfs1.c \
 	misc.c \
diff --git a/gfs2/libgfs2/config.c b/gfs2/libgfs2/config.c
deleted file mode 100644
index d2431e43..00000000
--- a/gfs2/libgfs2/config.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "libgfs2.h"
-#include "config.h"
-
-int cfg_debug = 0;
-
-void lgfs2_set_debug(int enable)
-{
-	cfg_debug = enable;
-}
diff --git a/gfs2/libgfs2/config.h b/gfs2/libgfs2/config.h
deleted file mode 100644
index 7c1eb3c3..00000000
--- a/gfs2/libgfs2/config.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __LGFS2_CONFIG_H__
-#define __LGFS2_CONFIG_H__
-
-extern int cfg_debug;
-
-#endif /* __LGFS2_CONFIG_H__ */
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index b149d2c0..cb1ed6d5 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -14,7 +14,6 @@
 #include <linux/fs.h>
 
 #include "libgfs2.h"
-#include "config.h"
 
 #ifndef BLKSSZGET
 #define BLKSSZGET _IO(0x12,104)   /* logical_block_size */
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index fa710a6c..20d8d57e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -471,9 +471,6 @@ extern uint32_t lgfs2_get_block_type(const char *buf);
 #define bread(bl, num) __bread(bl, num, __LINE__, __FUNCTION__)
 #define breadm(bl, bhs, n, block) __breadm(bl, bhs, n, block, __LINE__, __FUNCTION__)
 
-/* config.c */
-extern void lgfs2_set_debug(int enable);
-
 /* device_geometry.c */
 extern int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i);
 extern void fix_device_geometry(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 9b78ed51..d7b7f4e1 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -14,7 +14,6 @@
 #include <uuid.h>
 
 #include "libgfs2.h"
-#include "config.h"
 #include "crc32c.h"
 
 int build_master(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 2648b980..0a7f1f33 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -158,7 +158,6 @@ static int decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp, struct
 			break;
 		case 'D':
 			opts->debug = 1;
-			lgfs2_set_debug(1);
 			break;
 		case 'h':
 			print_usage(argv[0]);
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index ae192bd4..8f8d8f04 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -366,7 +366,6 @@ static int opts_get(int argc, char *argv[], struct mkfs_opts *opts)
 			break;
 		case 'D':
 			opts->debug = 1;
-			lgfs2_set_debug(1);
 			break;
 		case 'h':
 			print_usage(argv[0]);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 17/18] libgfs2: Move struct printing functions out of libgfs2
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (15 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 16/18] libgfs2: Remove config.[ch] Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 18/18] libgfs2: Remove print_it extern requirement Andrew Price
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Now that libgfs2 itself doesn't use these functions, they can be moved
into the two utils that use them. This does duplicate the code but that
means the utils are free to change the way that they're printed to suit
their interfaces. We're still using the "print_it" extern that libgfs2.h
requires but that can be removed next.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/edit/Makefile.am    |   2 +
 gfs2/edit/extended.c     |  11 ++-
 gfs2/edit/gfs2hex.c      |  33 ++++---
 gfs2/edit/hexedit.c      |   9 +-
 gfs2/edit/struct_print.c | 206 +++++++++++++++++++++++++++++++++++++++
 gfs2/edit/struct_print.h |  19 ++++
 gfs2/libgfs2/libgfs2.h   |  15 ---
 gfs2/libgfs2/ondisk.c    | 199 -------------------------------------
 gfs2/mkfs/Makefile.am    |   2 +
 gfs2/mkfs/main_mkfs.c    |  27 ++---
 gfs2/mkfs/struct_print.c | 206 +++++++++++++++++++++++++++++++++++++++
 gfs2/mkfs/struct_print.h |  19 ++++
 12 files changed, 496 insertions(+), 252 deletions(-)
 create mode 100644 gfs2/edit/struct_print.c
 create mode 100644 gfs2/edit/struct_print.h
 create mode 100644 gfs2/mkfs/struct_print.c
 create mode 100644 gfs2/mkfs/struct_print.h

diff --git a/gfs2/edit/Makefile.am b/gfs2/edit/Makefile.am
index cee327a9..28a8908c 100644
--- a/gfs2/edit/Makefile.am
+++ b/gfs2/edit/Makefile.am
@@ -6,6 +6,7 @@ noinst_HEADERS = \
 	gfs2hex.h \
 	hexedit.h \
 	extended.h \
+	struct_print.h \
 	journal.h
 
 gfs2_edit_SOURCES = \
@@ -13,6 +14,7 @@ gfs2_edit_SOURCES = \
 	hexedit.c \
 	savemeta.c \
 	extended.c \
+	struct_print.c \
 	journal.c
 
 gfs2_edit_CPPFLAGS = \
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 8d914681..8ba3da3b 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -17,13 +17,14 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <dirent.h>
+#include <libgfs2.h>
 
 #include "copyright.cf"
 
 #include "hexedit.h"
-#include "libgfs2.h"
 #include "extended.h"
 #include "gfs2hex.h"
+#include "struct_print.h"
 
 static void print_block_details(struct iinfo *ind, int level, int cur_height,
 				int pndx, uint64_t file_offset);
@@ -534,7 +535,7 @@ static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
 			if (edit_row[dmode] == print_entry_ndx)
 				COLORS_NORMAL;
 			if (print_rindex)
-				lgfs2_rindex_print(&ri);
+				rindex_print(&ri);
 			else {
 				struct gfs2_rgrp r = {0};
 				ssize_t ret;
@@ -545,7 +546,7 @@ static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
 				} else if (sbd.gfs1) {
 					gfs_rgrp_print(&r);
 				} else {
-					lgfs2_rgrp_print(&r);
+					rgrp_print(&r);
 				}
 			}
 			last_entry_onscreen[dmode] = print_entry_ndx;
@@ -597,7 +598,7 @@ static int print_statfs(struct gfs2_inode *dis)
 	}
 	print_gfs2("statfs file contents:");
 	eol(0);
-	lgfs2_statfs_change_print(&sc);
+	statfs_change_print(&sc);
 	return 0;
 }
 
@@ -621,7 +622,7 @@ static int print_quota(struct gfs2_inode *diq)
 		}
 		print_gfs2("Entry #%d", i + 1);
 		eol(0);
-		lgfs2_quota_print(&q);
+		quota_print(&q);
 	}
 	return 0;
 }
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 219a20ea..9c71ac60 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -11,11 +11,12 @@
 #include <errno.h>
 #include <curses.h>
 #include <uuid.h>
+#include <libgfs2.h>
 
 #include "hexedit.h"
 #include "extended.h"
 #include "gfs2hex.h"
-#include "libgfs2.h"
+#include "struct_print.h"
 
 #define pv(struct, member, fmt, fmt2) do {				\
 		print_it("  "#member, fmt, fmt2, struct->member);	\
@@ -364,7 +365,7 @@ static void do_eattr_extended(char *buf)
 		eol(0);
 		buf += x;
 		ea = (struct gfs2_ea_header *)buf;
-		lgfs2_ea_header_print(ea);
+		ea_header_print(ea);
 		rec_len = be32_to_cpu(ea->ea_rec_len);
 	}
 }
@@ -377,20 +378,20 @@ static void gfs_sb_print(void *sbp)
 {
 	struct gfs_sb *sb = sbp;
 
-	lgfs2_meta_header_print(&sb->sb_header);
+	meta_header_print(&sb->sb_header);
 	printbe32(sb, sb_fs_format);
 	printbe32(sb, sb_multihost_format);
 	printbe32(sb, sb_flags);
 	printbe32(sb, sb_bsize);
 	printbe32(sb, sb_bsize_shift);
 	printbe32(sb, sb_seg_size);
-	lgfs2_inum_print(&sb->sb_jindex_di);
-	lgfs2_inum_print(&sb->sb_rindex_di);
-	lgfs2_inum_print(&sb->sb_root_di);
+	inum_print(&sb->sb_jindex_di);
+	inum_print(&sb->sb_rindex_di);
+	inum_print(&sb->sb_root_di);
 	pv(sb, sb_lockproto, "%.64s", NULL);
 	pv(sb, sb_locktable, "%.64s", NULL);
-	lgfs2_inum_print(&sb->sb_quota_di);
-	lgfs2_inum_print(&sb->sb_license_di);
+	inum_print(&sb->sb_quota_di);
+	inum_print(&sb->sb_license_di);
 }
 
 void display_gfs2(void *buf)
@@ -418,41 +419,41 @@ void display_gfs2(void *buf)
 		if (sbd.gfs1)
 			gfs_sb_print(buf);
 		else
-			lgfs2_sb_print(buf);
+			sb_print(buf);
 		break;
 	case GFS2_METATYPE_RG:
 		if (sbd.gfs1)
 			gfs_rgrp_print(buf);
 		else
-			lgfs2_rgrp_print(buf);
+			rgrp_print(buf);
 		break;
 	case GFS2_METATYPE_DI:
-		lgfs2_dinode_print(di);
+		dinode_print(di);
 		break;
 	case GFS2_METATYPE_LF:
-		lgfs2_leaf_print(buf);
+		leaf_print(buf);
 		break;
 	case GFS2_METATYPE_LH:
 		if (sbd.gfs1)
 			gfs_log_header_print(buf);
 		else
-			lgfs2_log_header_print(buf);
+			log_header_print(buf);
 		break;
 	case GFS2_METATYPE_LD:
-		lgfs2_log_descriptor_print(buf);
+		log_descriptor_print(buf);
 		break;
 	case GFS2_METATYPE_EA:
 		do_eattr_extended(buf);
 		break;
 	case GFS2_METATYPE_QC:
-		lgfs2_quota_change_print(buf);
+		quota_change_print(buf);
 		break;
 	case GFS2_METATYPE_RB:
 	case GFS2_METATYPE_IN:
 	case GFS2_METATYPE_JD:
 	case GFS2_METATYPE_ED:
 	case GFS2_METATYPE_LB:
-		lgfs2_meta_header_print(mh);
+		meta_header_print(mh);
 		break;
 	default:
 		print_gfs2("Unknown block type");
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 0662fc3f..d88bfcfe 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -25,6 +25,7 @@
 #include "gfs2hex.h"
 #include "extended.h"
 #include "journal.h"
+#include "struct_print.h"
 
 #define printbe32(struct, member) do { \
 		print_it("  "#member, "%"PRIu32, "0x%"PRIx32, be32_to_cpu(struct->member)); \
@@ -733,12 +734,12 @@ void gfs_rgrp_print(void *rgp)
 {
 	struct gfs_rgrp *rg = rgp;
 
-	lgfs2_meta_header_print(&rg->rg_header);
+	meta_header_print(&rg->rg_header);
 	printbe32(rg, rg_flags);
 	printbe32(rg, rg_free);
 	printbe32(rg, rg_useddi);
 	printbe32(rg, rg_freedi);
-	lgfs2_inum_print(&rg->rg_freedi_list);
+	inum_print(&rg->rg_freedi_list);
 	printbe32(rg, rg_usedmeta);
 	printbe32(rg, rg_freemeta);
 }
@@ -799,7 +800,7 @@ static void set_rgrp_flags(int rgnum, uint32_t new_flags, int modify, int full)
 			if (sbd.gfs1)
 				gfs_rgrp_print(rg);
 			else
-				lgfs2_rgrp_print(rg);
+				rgrp_print(rg);
 		}
 		else
 			printf("RG #%d (block %"PRIu64" / 0x%"PRIx64") rg_flags = 0x%08x\n",
@@ -2034,7 +2035,7 @@ void gfs_log_header_print(void *lhp)
 {
 	struct gfs_log_header *lh = lhp;
 
-	lgfs2_meta_header_print(&lh->lh_header);
+	meta_header_print(&lh->lh_header);
 	print_it("  lh_flags", "%"PRIu32, "0x%.8"PRIx32, be32_to_cpu(lh->lh_flags));
 	print_it("  lh_pad", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(lh->lh_pad));
 	print_it("  lh_first", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_first));
diff --git a/gfs2/edit/struct_print.c b/gfs2/edit/struct_print.c
new file mode 100644
index 00000000..88c9c609
--- /dev/null
+++ b/gfs2/edit/struct_print.c
@@ -0,0 +1,206 @@
+#include <stddef.h>
+#include <string.h>
+#include <inttypes.h>
+#include <uuid.h>
+#include <libgfs2.h>
+
+#include "struct_print.h"
+
+#define printbe16(struct, member) do { \
+		print_it("  "#member, "%"PRIu16, "0x%"PRIx16, be16_to_cpu(struct->member)); \
+	} while(0)
+#define printbe32(struct, member) do { \
+		print_it("  "#member, "%"PRIu32, "0x%"PRIx32, be32_to_cpu(struct->member)); \
+	} while(0)
+#define printbe64(struct, member) do { \
+		print_it("  "#member, "%"PRIu64, "0x%"PRIx64, be64_to_cpu(struct->member)); \
+	} while(0)
+#define print8(struct, member) do { \
+		print_it("  "#member, "%"PRIu8, "0x%"PRIx8, struct->member); \
+	} while(0)
+
+void inum_print(void *nop)
+{
+	struct gfs2_inum *no = nop;
+
+	printbe64(no, no_formal_ino);
+	printbe64(no, no_addr);
+}
+
+void meta_header_print(void *mhp)
+{
+	struct gfs2_meta_header *mh = mhp;
+
+	print_it("  mh_magic", "0x%08"PRIX32, NULL, be32_to_cpu(mh->mh_magic));
+	printbe32(mh, mh_type);
+	printbe32(mh, mh_format);
+}
+
+void sb_print(void *sbp)
+{
+	struct gfs2_sb *sb = sbp;
+	char readable_uuid[36+1];
+
+	meta_header_print(&sb->sb_header);
+	printbe32(sb, sb_fs_format);
+	printbe32(sb, sb_multihost_format);
+	printbe32(sb, sb_bsize);
+	printbe32(sb, sb_bsize_shift);
+	inum_print(&sb->sb_master_dir);
+	inum_print(&sb->sb_root_dir);
+	print_it("  sb_lockproto", "%.64s", NULL, sb->sb_lockproto);
+	print_it("  sb_locktable", "%.64s", NULL, sb->sb_locktable);
+	uuid_unparse(sb->sb_uuid, readable_uuid);
+	print_it("  uuid", "%36s", NULL, readable_uuid);
+}
+
+void rindex_print(void *rip)
+{
+	struct gfs2_rindex *ri = rip;
+
+	printbe64(ri, ri_addr);
+	printbe32(ri, ri_length);
+	printbe64(ri, ri_data0);
+	printbe32(ri, ri_data);
+	printbe32(ri, ri_bitbytes);
+}
+
+void rgrp_print(void *rgp)
+{
+	struct gfs2_rgrp *rg = rgp;
+
+	meta_header_print(&rg->rg_header);
+	printbe32(rg, rg_flags);
+	printbe32(rg, rg_free);
+	printbe32(rg, rg_dinodes);
+	printbe32(rg, rg_skip);
+	printbe64(rg, rg_igeneration);
+	printbe64(rg, rg_data0);
+	printbe32(rg, rg_data);
+	printbe32(rg, rg_bitbytes);
+	printbe32(rg, rg_crc);
+}
+
+void quota_print(void *qp)
+{
+	struct gfs2_quota *q = qp;
+
+	printbe64(q, qu_limit);
+	printbe64(q, qu_warn);
+	printbe64(q, qu_value);
+}
+
+void dinode_print(void *dip)
+{
+	struct gfs2_dinode *di = dip;
+
+	meta_header_print(&di->di_header);
+	inum_print(&di->di_num);
+
+	print_it("  di_mode", "0%"PRIo32, NULL, be32_to_cpu(di->di_mode));
+	printbe32(di, di_uid);
+	printbe32(di, di_gid);
+	printbe32(di, di_nlink);
+	printbe64(di, di_size);
+	printbe64(di, di_blocks);
+	printbe64(di, di_atime);
+	printbe64(di, di_mtime);
+	printbe64(di, di_ctime);
+	printbe32(di, di_major);
+	printbe32(di, di_minor);
+	printbe64(di, di_goal_meta);
+	printbe64(di, di_goal_data);
+	print_it("  di_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(di->di_flags));
+	printbe32(di, di_payload_format);
+	printbe16(di, di_height);
+	printbe16(di, di_depth);
+	printbe32(di, di_entries);
+	printbe64(di, di_eattr);
+}
+
+void leaf_print(void *lfp)
+{
+	struct gfs2_leaf *lf = lfp;
+
+	meta_header_print(&lf->lf_header);
+	printbe16(lf, lf_depth);
+	printbe16(lf, lf_entries);
+	printbe32(lf, lf_dirent_format);
+	printbe64(lf, lf_next);
+	printbe64(lf, lf_inode);
+	printbe32(lf, lf_dist);
+	printbe32(lf, lf_nsec);
+	printbe64(lf, lf_sec);
+}
+
+void ea_header_print(void *eap)
+{
+	char buf[GFS2_EA_MAX_NAME_LEN + 1];
+	struct gfs2_ea_header *ea = eap;
+	unsigned len = ea->ea_name_len;
+
+	printbe32(ea, ea_rec_len);
+	printbe32(ea, ea_data_len);
+	print8(ea, ea_name_len);
+	print8(ea, ea_type);
+	print8(ea, ea_flags);
+	print8(ea, ea_num_ptrs);
+
+	if (len > GFS2_EA_MAX_NAME_LEN)
+		len = GFS2_EA_MAX_NAME_LEN;
+	memcpy(buf, ea + 1, len);
+	buf[len] = '\0';
+	print_it("  name", "%s", NULL, buf);
+}
+
+void log_header_print(void *lhp)
+{
+	struct gfs2_log_header *lh = lhp;
+
+	meta_header_print(&lh->lh_header);
+	printbe64(lh, lh_sequence);
+	print_it("  lh_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_flags));
+	printbe32(lh, lh_tail);
+	printbe32(lh, lh_blkno);
+	print_it("  lh_hash", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_hash));
+	print_it("  lh_crc", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_crc));
+	printbe32(lh, lh_nsec);
+	printbe64(lh, lh_sec);
+	printbe64(lh, lh_addr);
+	printbe64(lh, lh_jinode);
+	printbe64(lh, lh_statfs_addr);
+	printbe64(lh, lh_quota_addr);
+	print_it("  lh_local_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_total));
+	print_it("  lh_local_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_free));
+	print_it("  lh_local_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_dinodes));
+}
+
+void log_descriptor_print(void *ldp)
+{
+	struct gfs2_log_descriptor *ld = ldp;
+
+	meta_header_print(&ld->ld_header);
+	printbe32(ld, ld_type);
+	printbe32(ld, ld_length);
+	printbe32(ld, ld_data1);
+	printbe32(ld, ld_data2);
+}
+
+void statfs_change_print(void *scp)
+{
+	struct gfs2_statfs_change *sc = scp;
+
+	print_it("  sc_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_total));
+	print_it("  sc_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_free));
+	print_it("  sc_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_dinodes));
+}
+
+void quota_change_print(void *qcp)
+{
+	struct gfs2_quota_change *qc = qcp;
+
+	print_it("  qc_change", "%"PRId64, "0x%"PRIx64, be64_to_cpu(qc->qc_change));
+	print_it("  qc_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(qc->qc_flags));
+	printbe32(qc, qc_id);
+}
+
diff --git a/gfs2/edit/struct_print.h b/gfs2/edit/struct_print.h
new file mode 100644
index 00000000..784c130d
--- /dev/null
+++ b/gfs2/edit/struct_print.h
@@ -0,0 +1,19 @@
+#ifndef STRUCT_PRINT_H
+#define STRUCT_PRINT_H
+
+/* Printing functions. These expect on-disk data */
+extern void inum_print(void *nop);
+extern void meta_header_print(void *mhp);
+extern void sb_print(void *sbp);
+extern void dinode_print(void *dip);
+extern void log_header_print(void *lhp);
+extern void log_descriptor_print(void *ldp);
+extern void quota_print(void *qp);
+extern void quota_change_print(void *qcp);
+extern void statfs_change_print(void *scp);
+extern void ea_header_print(void *eap);
+extern void leaf_print(void *lfp);
+extern void rindex_print(void *rip);
+extern void rgrp_print(void *rgp);
+
+#endif /* STRUCT_PRINT_H */
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 20d8d57e..81fe5983 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -816,21 +816,6 @@ extern void lgfs2_dirent_out(struct lgfs2_dirent *d, void *dep);
 extern void lgfs2_leaf_in(struct lgfs2_leaf *lf, void *lfp);
 extern void lgfs2_leaf_out(struct lgfs2_leaf *lf, void *lfp);
 
-/* Printing functions. These expect on-disk data */
-extern void lgfs2_inum_print(void *nop);
-extern void lgfs2_meta_header_print(void *mhp);
-extern void lgfs2_sb_print(void *sbp);
-extern void lgfs2_dinode_print(void *dip);
-extern void lgfs2_log_header_print(void *lhp);
-extern void lgfs2_log_descriptor_print(void *ldp);
-extern void lgfs2_quota_print(void *qp);
-extern void lgfs2_quota_change_print(void *qcp);
-extern void lgfs2_statfs_change_print(void *scp);
-extern void lgfs2_ea_header_print(void *eap);
-extern void lgfs2_leaf_print(void *lfp);
-extern void lgfs2_rindex_print(void *rip);
-extern void lgfs2_rgrp_print(void *rgp);
-
 __END_DECLS
 
 #endif /* __LIBGFS2_DOT_H__ */
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index 4daf1be1..8cddfec9 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -9,19 +9,6 @@
 #include <uuid.h>
 #include "libgfs2.h"
 
-#define printbe16(struct, member) do { \
-		print_it("  "#member, "%"PRIu16, "0x%"PRIx16, be16_to_cpu(struct->member)); \
-	} while(0)
-#define printbe32(struct, member) do { \
-		print_it("  "#member, "%"PRIu32, "0x%"PRIx32, be32_to_cpu(struct->member)); \
-	} while(0)
-#define printbe64(struct, member) do { \
-		print_it("  "#member, "%"PRIu64, "0x%"PRIx64, be64_to_cpu(struct->member)); \
-	} while(0)
-#define print8(struct, member) do { \
-		print_it("  "#member, "%"PRIu8, "0x%"PRIx8, struct->member); \
-	} while(0)
-
 void lgfs2_inum_in(struct lgfs2_inum *i, void *inp)
 {
 	struct gfs2_inum *in = inp;
@@ -38,23 +25,6 @@ void lgfs2_inum_out(const struct lgfs2_inum *i, void *inp)
 	in->no_addr = cpu_to_be64(i->in_addr);
 }
 
-void lgfs2_inum_print(void *nop)
-{
-	struct gfs2_inum *no = nop;
-
-	printbe64(no, no_formal_ino);
-	printbe64(no, no_addr);
-}
-
-void lgfs2_meta_header_print(void *mhp)
-{
-	struct gfs2_meta_header *mh = mhp;
-
-	print_it("  mh_magic", "0x%08"PRIX32, NULL, be32_to_cpu(mh->mh_magic));
-	printbe32(mh, mh_type);
-	printbe32(mh, mh_format);
-}
-
 void lgfs2_sb_in(struct gfs2_sbd *sdp, void *buf)
 {
 	struct gfs2_sb *sb = buf;
@@ -100,24 +70,6 @@ void lgfs2_sb_out(const struct gfs2_sbd *sdp, void *buf)
 	memcpy(sb->sb_uuid, sdp->sd_uuid, 16);
 }
 
-void lgfs2_sb_print(void *sbp)
-{
-	struct gfs2_sb *sb = sbp;
-	char readable_uuid[36+1];
-
-	lgfs2_meta_header_print(&sb->sb_header);
-	printbe32(sb, sb_fs_format);
-	printbe32(sb, sb_multihost_format);
-	printbe32(sb, sb_bsize);
-	printbe32(sb, sb_bsize_shift);
-	lgfs2_inum_print(&sb->sb_master_dir);
-	lgfs2_inum_print(&sb->sb_root_dir);
-	print_it("  sb_lockproto", "%.64s", NULL, sb->sb_lockproto);
-	print_it("  sb_locktable", "%.64s", NULL, sb->sb_locktable);
-	uuid_unparse(sb->sb_uuid, readable_uuid);
-	print_it("  uuid", "%36s", NULL, readable_uuid);
-}
-
 void lgfs2_rindex_in(lgfs2_rgrp_t rg, void *buf)
 {
 	struct gfs2_rindex *ri = buf;
@@ -140,17 +92,6 @@ void lgfs2_rindex_out(const lgfs2_rgrp_t rg, void *buf)
 	ri->ri_bitbytes = cpu_to_be32(rg->rt_bitbytes);
 }
 
-void lgfs2_rindex_print(void *rip)
-{
-	struct gfs2_rindex *ri = rip;
-
-	printbe64(ri, ri_addr);
-	printbe32(ri, ri_length);
-	printbe64(ri, ri_data0);
-	printbe32(ri, ri_data);
-	printbe32(ri, ri_bitbytes);
-}
-
 void lgfs2_rgrp_in(lgfs2_rgrp_t rg, void *buf)
 {
 	struct gfs2_rgrp *r = buf;
@@ -183,31 +124,6 @@ void lgfs2_rgrp_out(const lgfs2_rgrp_t rg, void *buf)
 	lgfs2_rgrp_crc_set(buf);
 }
 
-void lgfs2_rgrp_print(void *rgp)
-{
-	struct gfs2_rgrp *rg = rgp;
-
-	lgfs2_meta_header_print(&rg->rg_header);
-	printbe32(rg, rg_flags);
-	printbe32(rg, rg_free);
-	printbe32(rg, rg_dinodes);
-	printbe32(rg, rg_skip);
-	printbe64(rg, rg_igeneration);
-	printbe64(rg, rg_data0);
-	printbe32(rg, rg_data);
-	printbe32(rg, rg_bitbytes);
-	printbe32(rg, rg_crc);
-}
-
-void lgfs2_quota_print(void *qp)
-{
-	struct gfs2_quota *q = qp;
-
-	printbe64(q, qu_limit);
-	printbe64(q, qu_warn);
-	printbe64(q, qu_value);
-}
-
 void lgfs2_dinode_in(struct gfs2_inode *ip, char *buf)
 {
 	struct gfs2_dinode *di = (struct gfs2_dinode *)buf;
@@ -274,34 +190,6 @@ void lgfs2_dinode_out(struct gfs2_inode *ip, char *buf)
 	di->di_ctime_nsec = cpu_to_be32(ip->i_ctime_nsec);
 }
 
-void lgfs2_dinode_print(void *dip)
-{
-	struct gfs2_dinode *di = dip;
-
-	lgfs2_meta_header_print(&di->di_header);
-	lgfs2_inum_print(&di->di_num);
-
-	print_it("  di_mode", "0%"PRIo32, NULL, be32_to_cpu(di->di_mode));
-	printbe32(di, di_uid);
-	printbe32(di, di_gid);
-	printbe32(di, di_nlink);
-	printbe64(di, di_size);
-	printbe64(di, di_blocks);
-	printbe64(di, di_atime);
-	printbe64(di, di_mtime);
-	printbe64(di, di_ctime);
-	printbe32(di, di_major);
-	printbe32(di, di_minor);
-	printbe64(di, di_goal_meta);
-	printbe64(di, di_goal_data);
-	print_it("  di_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(di->di_flags));
-	printbe32(di, di_payload_format);
-	printbe16(di, di_height);
-	printbe16(di, di_depth);
-	printbe32(di, di_entries);
-	printbe64(di, di_eattr);
-}
-
 void lgfs2_dirent_in(struct lgfs2_dirent *d, void *dep)
 {
 	struct gfs2_dirent *de = dep;
@@ -353,90 +241,3 @@ void lgfs2_leaf_out(struct lgfs2_leaf *lf, void *lfp)
 	l->lf_nsec = cpu_to_be32(lf->lf_nsec);
 	l->lf_sec = cpu_to_be64(lf->lf_sec);
 }
-
-void lgfs2_leaf_print(void *lfp)
-{
-	struct gfs2_leaf *lf = lfp;
-
-	lgfs2_meta_header_print(&lf->lf_header);
-	printbe16(lf, lf_depth);
-	printbe16(lf, lf_entries);
-	printbe32(lf, lf_dirent_format);
-	printbe64(lf, lf_next);
-	printbe64(lf, lf_inode);
-	printbe32(lf, lf_dist);
-	printbe32(lf, lf_nsec);
-	printbe64(lf, lf_sec);
-}
-
-void lgfs2_ea_header_print(void *eap)
-{
-	char buf[GFS2_EA_MAX_NAME_LEN + 1];
-	struct gfs2_ea_header *ea = eap;
-	unsigned len = ea->ea_name_len;
-
-	printbe32(ea, ea_rec_len);
-	printbe32(ea, ea_data_len);
-	print8(ea, ea_name_len);
-	print8(ea, ea_type);
-	print8(ea, ea_flags);
-	print8(ea, ea_num_ptrs);
-
-	if (len > GFS2_EA_MAX_NAME_LEN)
-		len = GFS2_EA_MAX_NAME_LEN;
-	memcpy(buf, ea + 1, len);
-	buf[len] = '\0';
-	print_it("  name", "%s", NULL, buf);
-}
-
-void lgfs2_log_header_print(void *lhp)
-{
-	struct gfs2_log_header *lh = lhp;
-
-	lgfs2_meta_header_print(&lh->lh_header);
-	printbe64(lh, lh_sequence);
-	print_it("  lh_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_flags));
-	printbe32(lh, lh_tail);
-	printbe32(lh, lh_blkno);
-	print_it("  lh_hash", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_hash));
-	print_it("  lh_crc", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_crc));
-	printbe32(lh, lh_nsec);
-	printbe64(lh, lh_sec);
-	printbe64(lh, lh_addr);
-	printbe64(lh, lh_jinode);
-	printbe64(lh, lh_statfs_addr);
-	printbe64(lh, lh_quota_addr);
-	print_it("  lh_local_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_total));
-	print_it("  lh_local_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_free));
-	print_it("  lh_local_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_dinodes));
-}
-
-void lgfs2_log_descriptor_print(void *ldp)
-{
-	struct gfs2_log_descriptor *ld = ldp;
-
-	lgfs2_meta_header_print(&ld->ld_header);
-	printbe32(ld, ld_type);
-	printbe32(ld, ld_length);
-	printbe32(ld, ld_data1);
-	printbe32(ld, ld_data2);
-}
-
-void lgfs2_statfs_change_print(void *scp)
-{
-	struct gfs2_statfs_change *sc = scp;
-
-	print_it("  sc_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_total));
-	print_it("  sc_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_free));
-	print_it("  sc_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_dinodes));
-}
-
-void lgfs2_quota_change_print(void *qcp)
-{
-	struct gfs2_quota_change *qc = qcp;
-
-	print_it("  qc_change", "%"PRId64, "0x%"PRIx64, be64_to_cpu(qc->qc_change));
-	print_it("  qc_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(qc->qc_flags));
-	printbe32(qc, qc_id);
-}
-
diff --git a/gfs2/mkfs/Makefile.am b/gfs2/mkfs/Makefile.am
index fd00fdd5..41c535c0 100644
--- a/gfs2/mkfs/Makefile.am
+++ b/gfs2/mkfs/Makefile.am
@@ -14,10 +14,12 @@ sbin_PROGRAMS = \
 
 noinst_HEADERS = \
 	gfs2_mkfs.h \
+	struct_print.h \
 	metafs.h
 
 mkfs_gfs2_SOURCES = \
 	main_mkfs.c \
+	struct_print.c \
 	progress.c \
 	progress.h
 
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 8f8d8f04..435ea0a7 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -29,6 +29,7 @@
 #include "libgfs2.h"
 #include "gfs2_mkfs.h"
 #include "progress.h"
+#include "struct_print.h"
 
 static void print_usage(const char *prog_name)
 {
@@ -702,7 +703,7 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
 		}
 		if (opts->debug) {
 			printf("\nInum Range %u:\n", j);
-			lgfs2_dinode_print(ip->i_bh->b_data);
+			dinode_print(ip->i_bh->b_data);
 		}
 		inode_put(&ip);
 
@@ -714,7 +715,7 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
 		}
 		if (opts->debug) {
 			printf("\nStatFS Change %u:\n", j);
-			lgfs2_dinode_print(ip->i_bh->b_data);
+			dinode_print(ip->i_bh->b_data);
 		}
 		inode_put(&ip);
 
@@ -726,13 +727,13 @@ static int build_per_node(struct gfs2_sbd *sdp, struct mkfs_opts *opts)
 		}
 		if (opts->debug) {
 			printf("\nQuota Change %u:\n", j);
-			lgfs2_dinode_print(ip->i_bh->b_data);
+			dinode_print(ip->i_bh->b_data);
 		}
 		inode_put(&ip);
 	}
 	if (opts->debug) {
 		printf("\nper_node:\n");
-		lgfs2_dinode_print(per_node->i_bh->b_data);
+		dinode_print(per_node->i_bh->b_data);
 	}
 	inode_put(&per_node);
 	return 0;
@@ -856,7 +857,7 @@ static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrp_t rg, int debug)
 		return -1;
 	}
 	if (debug) {
-		lgfs2_rindex_print(&ri);
+		rindex_print(&ri);
 		printf("\n");
 	}
 	sdp->blks_total += be32_to_cpu(ri.ri_data);
@@ -1009,7 +1010,7 @@ static int create_jindex(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct lg
 	}
 	if (opts->debug) {
 		printf("Jindex:\n");
-		lgfs2_dinode_print(jindex->i_bh->b_data);
+		dinode_print(jindex->i_bh->b_data);
 	}
 	inode_put(&jindex);
 	return 0;
@@ -1284,7 +1285,7 @@ int main(int argc, char *argv[])
 	}
 	if (opts.debug) {
 		printf("Metafs inode:\n");
-		lgfs2_dinode_print(sbd.master_dir->i_bh->b_data);
+		dinode_print(sbd.master_dir->i_bh->b_data);
 	}
 	sbd.sd_meta_dir = sbd.master_dir->i_num;
 
@@ -1304,7 +1305,7 @@ int main(int argc, char *argv[])
 	}
 	if (opts.debug) {
 		printf("\nInum Inode:\n");
-		lgfs2_dinode_print(sbd.md.inum->i_bh->b_data);
+		dinode_print(sbd.md.inum->i_bh->b_data);
 	}
 	sbd.md.statfs = build_statfs(&sbd);
 	if (sbd.md.statfs == NULL) {
@@ -1313,7 +1314,7 @@ int main(int argc, char *argv[])
 	}
 	if (opts.debug) {
 		printf("\nStatFS Inode:\n");
-		lgfs2_dinode_print(sbd.md.statfs->i_bh->b_data);
+		dinode_print(sbd.md.statfs->i_bh->b_data);
 	}
 	ip = build_rindex(&sbd);
 	if (ip == NULL) {
@@ -1322,7 +1323,7 @@ int main(int argc, char *argv[])
 	}
 	if (opts.debug) {
 		printf("\nResource Index:\n");
-		lgfs2_dinode_print(ip->i_bh->b_data);
+		dinode_print(ip->i_bh->b_data);
 	}
 	inode_put(&ip);
 	if (!opts.quiet) {
@@ -1336,7 +1337,7 @@ int main(int argc, char *argv[])
 	}
 	if (opts.debug) {
 		printf("\nQuota:\n");
-		lgfs2_dinode_print(ip->i_bh->b_data);
+		dinode_print(ip->i_bh->b_data);
 	}
 	inode_put(&ip);
 	if (!opts.quiet)
@@ -1345,7 +1346,7 @@ int main(int argc, char *argv[])
 	build_root(&sbd);
 	if (opts.debug) {
 		printf("\nRoot directory:\n");
-		lgfs2_dinode_print(sbd.md.rooti->i_bh->b_data);
+		dinode_print(sbd.md.rooti->i_bh->b_data);
 	}
 	sbd.sd_root_dir = sbd.md.rooti->i_num;
 
@@ -1361,7 +1362,7 @@ int main(int argc, char *argv[])
 	do_init_statfs(&sbd, &sc);
 	if (opts.debug) {
 		printf("\nStatfs:\n");
-		lgfs2_statfs_change_print(&sc);
+		statfs_change_print(&sc);
 	}
 	inode_put(&sbd.md.rooti);
 	inode_put(&sbd.master_dir);
diff --git a/gfs2/mkfs/struct_print.c b/gfs2/mkfs/struct_print.c
new file mode 100644
index 00000000..88c9c609
--- /dev/null
+++ b/gfs2/mkfs/struct_print.c
@@ -0,0 +1,206 @@
+#include <stddef.h>
+#include <string.h>
+#include <inttypes.h>
+#include <uuid.h>
+#include <libgfs2.h>
+
+#include "struct_print.h"
+
+#define printbe16(struct, member) do { \
+		print_it("  "#member, "%"PRIu16, "0x%"PRIx16, be16_to_cpu(struct->member)); \
+	} while(0)
+#define printbe32(struct, member) do { \
+		print_it("  "#member, "%"PRIu32, "0x%"PRIx32, be32_to_cpu(struct->member)); \
+	} while(0)
+#define printbe64(struct, member) do { \
+		print_it("  "#member, "%"PRIu64, "0x%"PRIx64, be64_to_cpu(struct->member)); \
+	} while(0)
+#define print8(struct, member) do { \
+		print_it("  "#member, "%"PRIu8, "0x%"PRIx8, struct->member); \
+	} while(0)
+
+void inum_print(void *nop)
+{
+	struct gfs2_inum *no = nop;
+
+	printbe64(no, no_formal_ino);
+	printbe64(no, no_addr);
+}
+
+void meta_header_print(void *mhp)
+{
+	struct gfs2_meta_header *mh = mhp;
+
+	print_it("  mh_magic", "0x%08"PRIX32, NULL, be32_to_cpu(mh->mh_magic));
+	printbe32(mh, mh_type);
+	printbe32(mh, mh_format);
+}
+
+void sb_print(void *sbp)
+{
+	struct gfs2_sb *sb = sbp;
+	char readable_uuid[36+1];
+
+	meta_header_print(&sb->sb_header);
+	printbe32(sb, sb_fs_format);
+	printbe32(sb, sb_multihost_format);
+	printbe32(sb, sb_bsize);
+	printbe32(sb, sb_bsize_shift);
+	inum_print(&sb->sb_master_dir);
+	inum_print(&sb->sb_root_dir);
+	print_it("  sb_lockproto", "%.64s", NULL, sb->sb_lockproto);
+	print_it("  sb_locktable", "%.64s", NULL, sb->sb_locktable);
+	uuid_unparse(sb->sb_uuid, readable_uuid);
+	print_it("  uuid", "%36s", NULL, readable_uuid);
+}
+
+void rindex_print(void *rip)
+{
+	struct gfs2_rindex *ri = rip;
+
+	printbe64(ri, ri_addr);
+	printbe32(ri, ri_length);
+	printbe64(ri, ri_data0);
+	printbe32(ri, ri_data);
+	printbe32(ri, ri_bitbytes);
+}
+
+void rgrp_print(void *rgp)
+{
+	struct gfs2_rgrp *rg = rgp;
+
+	meta_header_print(&rg->rg_header);
+	printbe32(rg, rg_flags);
+	printbe32(rg, rg_free);
+	printbe32(rg, rg_dinodes);
+	printbe32(rg, rg_skip);
+	printbe64(rg, rg_igeneration);
+	printbe64(rg, rg_data0);
+	printbe32(rg, rg_data);
+	printbe32(rg, rg_bitbytes);
+	printbe32(rg, rg_crc);
+}
+
+void quota_print(void *qp)
+{
+	struct gfs2_quota *q = qp;
+
+	printbe64(q, qu_limit);
+	printbe64(q, qu_warn);
+	printbe64(q, qu_value);
+}
+
+void dinode_print(void *dip)
+{
+	struct gfs2_dinode *di = dip;
+
+	meta_header_print(&di->di_header);
+	inum_print(&di->di_num);
+
+	print_it("  di_mode", "0%"PRIo32, NULL, be32_to_cpu(di->di_mode));
+	printbe32(di, di_uid);
+	printbe32(di, di_gid);
+	printbe32(di, di_nlink);
+	printbe64(di, di_size);
+	printbe64(di, di_blocks);
+	printbe64(di, di_atime);
+	printbe64(di, di_mtime);
+	printbe64(di, di_ctime);
+	printbe32(di, di_major);
+	printbe32(di, di_minor);
+	printbe64(di, di_goal_meta);
+	printbe64(di, di_goal_data);
+	print_it("  di_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(di->di_flags));
+	printbe32(di, di_payload_format);
+	printbe16(di, di_height);
+	printbe16(di, di_depth);
+	printbe32(di, di_entries);
+	printbe64(di, di_eattr);
+}
+
+void leaf_print(void *lfp)
+{
+	struct gfs2_leaf *lf = lfp;
+
+	meta_header_print(&lf->lf_header);
+	printbe16(lf, lf_depth);
+	printbe16(lf, lf_entries);
+	printbe32(lf, lf_dirent_format);
+	printbe64(lf, lf_next);
+	printbe64(lf, lf_inode);
+	printbe32(lf, lf_dist);
+	printbe32(lf, lf_nsec);
+	printbe64(lf, lf_sec);
+}
+
+void ea_header_print(void *eap)
+{
+	char buf[GFS2_EA_MAX_NAME_LEN + 1];
+	struct gfs2_ea_header *ea = eap;
+	unsigned len = ea->ea_name_len;
+
+	printbe32(ea, ea_rec_len);
+	printbe32(ea, ea_data_len);
+	print8(ea, ea_name_len);
+	print8(ea, ea_type);
+	print8(ea, ea_flags);
+	print8(ea, ea_num_ptrs);
+
+	if (len > GFS2_EA_MAX_NAME_LEN)
+		len = GFS2_EA_MAX_NAME_LEN;
+	memcpy(buf, ea + 1, len);
+	buf[len] = '\0';
+	print_it("  name", "%s", NULL, buf);
+}
+
+void log_header_print(void *lhp)
+{
+	struct gfs2_log_header *lh = lhp;
+
+	meta_header_print(&lh->lh_header);
+	printbe64(lh, lh_sequence);
+	print_it("  lh_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_flags));
+	printbe32(lh, lh_tail);
+	printbe32(lh, lh_blkno);
+	print_it("  lh_hash", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_hash));
+	print_it("  lh_crc", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_crc));
+	printbe32(lh, lh_nsec);
+	printbe64(lh, lh_sec);
+	printbe64(lh, lh_addr);
+	printbe64(lh, lh_jinode);
+	printbe64(lh, lh_statfs_addr);
+	printbe64(lh, lh_quota_addr);
+	print_it("  lh_local_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_total));
+	print_it("  lh_local_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_free));
+	print_it("  lh_local_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_dinodes));
+}
+
+void log_descriptor_print(void *ldp)
+{
+	struct gfs2_log_descriptor *ld = ldp;
+
+	meta_header_print(&ld->ld_header);
+	printbe32(ld, ld_type);
+	printbe32(ld, ld_length);
+	printbe32(ld, ld_data1);
+	printbe32(ld, ld_data2);
+}
+
+void statfs_change_print(void *scp)
+{
+	struct gfs2_statfs_change *sc = scp;
+
+	print_it("  sc_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_total));
+	print_it("  sc_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_free));
+	print_it("  sc_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_dinodes));
+}
+
+void quota_change_print(void *qcp)
+{
+	struct gfs2_quota_change *qc = qcp;
+
+	print_it("  qc_change", "%"PRId64, "0x%"PRIx64, be64_to_cpu(qc->qc_change));
+	print_it("  qc_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(qc->qc_flags));
+	printbe32(qc, qc_id);
+}
+
diff --git a/gfs2/mkfs/struct_print.h b/gfs2/mkfs/struct_print.h
new file mode 100644
index 00000000..784c130d
--- /dev/null
+++ b/gfs2/mkfs/struct_print.h
@@ -0,0 +1,19 @@
+#ifndef STRUCT_PRINT_H
+#define STRUCT_PRINT_H
+
+/* Printing functions. These expect on-disk data */
+extern void inum_print(void *nop);
+extern void meta_header_print(void *mhp);
+extern void sb_print(void *sbp);
+extern void dinode_print(void *dip);
+extern void log_header_print(void *lhp);
+extern void log_descriptor_print(void *ldp);
+extern void quota_print(void *qp);
+extern void quota_change_print(void *qcp);
+extern void statfs_change_print(void *scp);
+extern void ea_header_print(void *eap);
+extern void leaf_print(void *lfp);
+extern void rindex_print(void *rip);
+extern void rgrp_print(void *rgp);
+
+#endif /* STRUCT_PRINT_H */
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Cluster-devel] [PATCH 18/18] libgfs2: Remove print_it extern requirement
  2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
                   ` (16 preceding siblings ...)
  2022-01-12 19:26 ` [Cluster-devel] [PATCH 17/18] libgfs2: Move struct printing functions out of libgfs2 Andrew Price
@ 2022-01-12 19:26 ` Andrew Price
  17 siblings, 0 replies; 19+ messages in thread
From: Andrew Price @ 2022-01-12 19:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Now that libgfs2 doesn't depend on a print_it() function being provided
by the utils, the extern declaration can be removed from libgfs2.h. The
print_it functions in mkfs.gfs2 and gfs2_edit are moved into their
struct_print.c files and made static. All other print_it definitions are
removed or made static.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/convert/gfs2_convert.c  |  13 ---
 gfs2/edit/extended.c         |   7 --
 gfs2/edit/gfs2hex.c          | 135 -----------------------
 gfs2/edit/hexedit.c          |  33 ------
 gfs2/edit/hexedit.h          |   4 +-
 gfs2/edit/struct_print.c     | 200 +++++++++++++++++++++++++++++++----
 gfs2/edit/struct_print.h     |   4 +
 gfs2/fsck/main.c             |  11 --
 gfs2/glocktop/glocktop.c     |   3 +-
 gfs2/libgfs2/check_libgfs2.c |   3 -
 gfs2/libgfs2/gfs2l.c         |   3 -
 gfs2/libgfs2/libgfs2.h       |   2 -
 gfs2/mkfs/gfs2_mkfs.h        |  11 --
 gfs2/mkfs/struct_print.c     |  12 +++
 tests/nukerg.c               |   3 -
 15 files changed, 198 insertions(+), 246 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 5bfc616b..dc011d05 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -114,19 +114,6 @@ static unsigned orig_journals = 0;
 
 int print_level = MSG_NOTICE;
 
-/* ------------------------------------------------------------------------- */
-/* This function is for libgfs'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);
-}
-
 /* ------------------------------------------------------------------------- */
 /* convert_bitmaps - Convert gfs1 bitmaps to gfs2 bitmaps.                   */
 /*                   Fixes all unallocated metadata bitmap states (which are */
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 8ba3da3b..6e2e16db 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -421,13 +421,6 @@ static void print_block_details(struct iinfo *ind, int level, int cur_height,
 	free(more_indir);
 }
 
-static void gfs_jindex_print(struct gfs_jindex *ji)
-{
-	print_it("  ji_addr", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(ji->ji_addr));
-	print_it("  ji_nsegment", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(ji->ji_nsegment));
-	print_it("  ji_pad", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(ji->ji_pad));
-}
-
 static int print_gfs_jindex(struct gfs2_inode *dij)
 {
 	int error, start_line;
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 9c71ac60..610c7d2a 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -18,16 +18,6 @@
 #include "gfs2hex.h"
 #include "struct_print.h"
 
-#define pv(struct, member, fmt, fmt2) do {				\
-		print_it("  "#member, fmt, fmt2, struct->member);	\
-	} while (FALSE);
-#define pv2(struct, member, fmt, fmt2) do {				\
-		print_it("  ", fmt, fmt2, struct->member);		\
-	} while (FALSE);
-#define printbe32(struct, member) do { \
-		print_it("  "#member, "%"PRIu32, "0x%"PRIx32, be32_to_cpu(struct->member)); \
-	} while(0)
-
 struct gfs2_dinode *di;
 int line, termlines;
 char edit_fmt[80];
@@ -107,107 +97,6 @@ void print_gfs2(const char *fmt, ...)
 	va_end(args);
 }
 
-static void check_highlight(int highlight)
-{
-	if (!termlines || line >= termlines) /* If printing or out of bounds */
-		return;
-	if (dmode == HEX_MODE) {
-		if (line == (edit_row[dmode] * lines_per_row[dmode]) + 4) {
-			if (highlight) {
-				COLORS_HIGHLIGHT;
-				last_entry_onscreen[dmode] = print_entry_ndx;
-			} else
-				COLORS_NORMAL;
-		}
-	} else {
-		if ((line * lines_per_row[dmode]) - 4 == 
-			(edit_row[dmode] - start_row[dmode]) * lines_per_row[dmode]) {
-			if (highlight) {
-				COLORS_HIGHLIGHT;
-				last_entry_onscreen[dmode] = print_entry_ndx;
-			}
-			else
-				COLORS_NORMAL;
-		}
-	}
-}
-
-void print_it(const char *label, const char *fmt, const char *fmt2, ...)
-{
-	va_list args;
-	char tmp_string[NAME_MAX];
-	const char *fmtstring;
-	int decimalsize;
-
-	if (!termlines || line < termlines) {
-		va_start(args, fmt2);
-		check_highlight(TRUE);
-		if (termlines) {
-			move(line,0);
-			printw("%s", label);
-			move(line,24);
-		} else {
-			if (!strcmp(label, "  "))
-				printf("%-11s", label);
-			else
-				printf("%-24s", label);
-		}
-		vsprintf(tmp_string, fmt, args);
-
-		if (termlines)
-			printw("%s", tmp_string);
-		else
-			printf("%s", tmp_string);
-		check_highlight(FALSE);
-
-		if (fmt2) {
-			decimalsize = strlen(tmp_string);
-			va_end(args);
-			va_start(args, fmt2);
-			vsprintf(tmp_string, fmt2, args);
-			check_highlight(TRUE);
-			if (termlines) {
-				move(line, 50);
-				printw("%s", tmp_string);
-			} else {
-				int i;
-				for (i=20 - decimalsize; i > 0; i--)
-					printf(" ");
-				printf("%s", tmp_string);
-			}
-			check_highlight(FALSE);
-		} else {
-			if (strstr(fmt,"X") || strstr(fmt,"x"))
-				fmtstring="(hex)";
-			else if (strstr(fmt,"s"))
-				fmtstring="";
-			else
-				fmtstring="(decimal)";
-			if (termlines) {
-				move(line, 50);
-				printw("%s", fmtstring);
-			}
-			else
-				printf("%s", fmtstring);
-		}
-		if (termlines) {
-			refresh();
-			if (line == (edit_row[dmode] * lines_per_row[dmode]) + 4) {
-				strncpy(efield, label + 2, 63); /* it's indented */
-				efield[63] = '\0';
-				strcpy(estring, tmp_string);
-				strncpy(edit_fmt, fmt, 79);
-				edit_fmt[79] = '\0';
-				edit_size[dmode] = strlen(estring);
-				COLORS_NORMAL;
-			}
-			last_entry_onscreen[dmode] = (line / lines_per_row[dmode]) - 4;
-		}
-		eol(0);
-		va_end(args);
-	}
-}
-
 void idirent_in(struct idirent *id, void *dep)
 {
 	struct gfs2_dirent *de = dep;
@@ -370,30 +259,6 @@ static void do_eattr_extended(char *buf)
 	}
 }
 
-/**
- * gfs_sb_print - Print out a gfs1 superblock
- * @sbp: the big-endian buffer
- */
-static void gfs_sb_print(void *sbp)
-{
-	struct gfs_sb *sb = sbp;
-
-	meta_header_print(&sb->sb_header);
-	printbe32(sb, sb_fs_format);
-	printbe32(sb, sb_multihost_format);
-	printbe32(sb, sb_flags);
-	printbe32(sb, sb_bsize);
-	printbe32(sb, sb_bsize_shift);
-	printbe32(sb, sb_seg_size);
-	inum_print(&sb->sb_jindex_di);
-	inum_print(&sb->sb_rindex_di);
-	inum_print(&sb->sb_root_di);
-	pv(sb, sb_lockproto, "%.64s", NULL);
-	pv(sb, sb_locktable, "%.64s", NULL);
-	inum_print(&sb->sb_quota_di);
-	inum_print(&sb->sb_license_di);
-}
-
 void display_gfs2(void *buf)
 {
 	struct gfs2_meta_header *mh = buf;
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index d88bfcfe..13af4007 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -727,23 +727,6 @@ static uint64_t find_rgrp_block(struct gfs2_inode *dif, int rg)
 	return be64_to_cpu(ri.ri_addr);
 }
 
-/* ------------------------------------------------------------------------ */
-/* gfs_rgrp_print - print a gfs1 resource group                             */
-/* ------------------------------------------------------------------------ */
-void gfs_rgrp_print(void *rgp)
-{
-	struct gfs_rgrp *rg = rgp;
-
-	meta_header_print(&rg->rg_header);
-	printbe32(rg, rg_flags);
-	printbe32(rg, rg_free);
-	printbe32(rg, rg_useddi);
-	printbe32(rg, rg_freedi);
-	inum_print(&rg->rg_freedi_list);
-	printbe32(rg, rg_usedmeta);
-	printbe32(rg, rg_freemeta);
-}
-
 /* ------------------------------------------------------------------------ */
 /* get_rg_addr                                                              */
 /* ------------------------------------------------------------------------ */
@@ -2028,22 +2011,6 @@ static void interactive_mode(void)
     endwin();
 }/* interactive_mode */
 
-/* ------------------------------------------------------------------------ */
-/* gfs_log_header_print - print a gfs1-style log header                     */
-/* ------------------------------------------------------------------------ */
-void gfs_log_header_print(void *lhp)
-{
-	struct gfs_log_header *lh = lhp;
-
-	meta_header_print(&lh->lh_header);
-	print_it("  lh_flags", "%"PRIu32, "0x%.8"PRIx32, be32_to_cpu(lh->lh_flags));
-	print_it("  lh_pad", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(lh->lh_pad));
-	print_it("  lh_first", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_first));
-	print_it("  lh_sequence", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_sequence));
-	print_it("  lh_tail", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_tail));
-	print_it("  lh_last_dump", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_last_dump));
-}
-
 /* ------------------------------------------------------------------------ */
 /* usage - print command line usage                                         */
 /* ------------------------------------------------------------------------ */
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index 29f465a0..156874da 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -5,6 +5,7 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <string.h>
+#include <ncurses.h>
 
 #include "libgfs2.h"
 #include "copyright.cf"
@@ -20,9 +21,6 @@
 enum dsp_mode { HEX_MODE = 0, GFS2_MODE = 1, EXTENDED_MODE = 2, INIT_MODE = 3 };
 #define BLOCK_STACK_SIZE 256
 
-#define pv(struct, member, fmt, fmt2) do {				\
-		print_it("  "#member, fmt, fmt2, struct->member);	\
-	} while (FALSE);
 #define RGLIST_DUMMY_BLOCK -2
 #define JOURNALS_DUMMY_BLOCK -3
 
diff --git a/gfs2/edit/struct_print.c b/gfs2/edit/struct_print.c
index 88c9c609..896f648b 100644
--- a/gfs2/edit/struct_print.c
+++ b/gfs2/edit/struct_print.c
@@ -1,11 +1,116 @@
 #include <stddef.h>
+#include <stdarg.h>
 #include <string.h>
 #include <inttypes.h>
 #include <uuid.h>
 #include <libgfs2.h>
 
+#include "hexedit.h"
+#include "gfs2hex.h"
 #include "struct_print.h"
 
+static void check_highlight(int highlight)
+{
+	if (!termlines || line >= termlines) /* If printing or out of bounds */
+		return;
+	if (dmode == HEX_MODE) {
+		if (line == (edit_row[dmode] * lines_per_row[dmode]) + 4) {
+			if (highlight) {
+				COLORS_HIGHLIGHT;
+				last_entry_onscreen[dmode] = print_entry_ndx;
+			} else
+				COLORS_NORMAL;
+		}
+	} else {
+		if ((line * lines_per_row[dmode]) - 4 ==
+			(edit_row[dmode] - start_row[dmode]) * lines_per_row[dmode]) {
+			if (highlight) {
+				COLORS_HIGHLIGHT;
+				last_entry_onscreen[dmode] = print_entry_ndx;
+			}
+			else
+				COLORS_NORMAL;
+		}
+	}
+}
+
+__attribute__((format(printf,2,4)))
+static void print_it(const char *label, const char *fmt, const char *fmt2, ...)
+{
+	va_list args;
+	char tmp_string[NAME_MAX];
+	const char *fmtstring;
+	int decimalsize;
+
+	if (!termlines || line < termlines) {
+		va_start(args, fmt2);
+		check_highlight(TRUE);
+		if (termlines) {
+			move(line,0);
+			printw("%s", label);
+			move(line,24);
+		} else {
+			if (!strcmp(label, "  "))
+				printf("%-11s", label);
+			else
+				printf("%-24s", label);
+		}
+		vsprintf(tmp_string, fmt, args);
+
+		if (termlines)
+			printw("%s", tmp_string);
+		else
+			printf("%s", tmp_string);
+		check_highlight(FALSE);
+
+		if (fmt2) {
+			decimalsize = strlen(tmp_string);
+			va_end(args);
+			va_start(args, fmt2);
+			vsprintf(tmp_string, fmt2, args);
+			check_highlight(TRUE);
+			if (termlines) {
+				move(line, 50);
+				printw("%s", tmp_string);
+			} else {
+				int i;
+				for (i=20 - decimalsize; i > 0; i--)
+					printf(" ");
+				printf("%s", tmp_string);
+			}
+			check_highlight(FALSE);
+		} else {
+			if (strstr(fmt,"X") || strstr(fmt,"x"))
+				fmtstring="(hex)";
+			else if (strstr(fmt,"s"))
+				fmtstring="";
+			else
+				fmtstring="(decimal)";
+			if (termlines) {
+				move(line, 50);
+				printw("%s", fmtstring);
+			}
+			else
+				printf("%s", fmtstring);
+		}
+		if (termlines) {
+			refresh();
+			if (line == (edit_row[dmode] * lines_per_row[dmode]) + 4) {
+				strncpy(efield, label + 2, 63); /* it's indented */
+				efield[63] = '\0';
+				strcpy(estring, tmp_string);
+				strncpy(edit_fmt, fmt, 79);
+				edit_fmt[79] = '\0';
+				edit_size[dmode] = strlen(estring);
+				COLORS_NORMAL;
+			}
+			last_entry_onscreen[dmode] = (line / lines_per_row[dmode]) - 4;
+		}
+		eol(0);
+		va_end(args);
+	}
+}
+
 #define printbe16(struct, member) do { \
 		print_it("  "#member, "%"PRIu16, "0x%"PRIx16, be16_to_cpu(struct->member)); \
 	} while(0)
@@ -54,6 +159,26 @@ void sb_print(void *sbp)
 	print_it("  uuid", "%36s", NULL, readable_uuid);
 }
 
+void gfs_sb_print(void *sbp)
+{
+	struct gfs_sb *sb = sbp;
+
+	meta_header_print(&sb->sb_header);
+	printbe32(sb, sb_fs_format);
+	printbe32(sb, sb_multihost_format);
+	printbe32(sb, sb_flags);
+	printbe32(sb, sb_bsize);
+	printbe32(sb, sb_bsize_shift);
+	printbe32(sb, sb_seg_size);
+	inum_print(&sb->sb_jindex_di);
+	inum_print(&sb->sb_rindex_di);
+	inum_print(&sb->sb_root_di);
+	print_it("  sb_lockproto", "%.64s", NULL, sb->sb_lockproto);
+	print_it("  sb_locktable", "%.64s", NULL, sb->sb_locktable);
+	inum_print(&sb->sb_quota_di);
+	inum_print(&sb->sb_license_di);
+}
+
 void rindex_print(void *rip)
 {
 	struct gfs2_rindex *ri = rip;
@@ -81,6 +206,20 @@ void rgrp_print(void *rgp)
 	printbe32(rg, rg_crc);
 }
 
+void gfs_rgrp_print(void *rgp)
+{
+	struct gfs_rgrp *rg = rgp;
+
+	meta_header_print(&rg->rg_header);
+	printbe32(rg, rg_flags);
+	printbe32(rg, rg_free);
+	printbe32(rg, rg_useddi);
+	printbe32(rg, rg_freedi);
+	inum_print(&rg->rg_freedi_list);
+	printbe32(rg, rg_usedmeta);
+	printbe32(rg, rg_freemeta);
+}
+
 void quota_print(void *qp)
 {
 	struct gfs2_quota *q = qp;
@@ -92,30 +231,30 @@ void quota_print(void *qp)
 
 void dinode_print(void *dip)
 {
-	struct gfs2_dinode *di = dip;
+	struct gfs2_dinode *_di = dip;
 
-	meta_header_print(&di->di_header);
-	inum_print(&di->di_num);
+	meta_header_print(&_di->di_header);
+	inum_print(&_di->di_num);
 
 	print_it("  di_mode", "0%"PRIo32, NULL, be32_to_cpu(di->di_mode));
-	printbe32(di, di_uid);
-	printbe32(di, di_gid);
-	printbe32(di, di_nlink);
-	printbe64(di, di_size);
-	printbe64(di, di_blocks);
-	printbe64(di, di_atime);
-	printbe64(di, di_mtime);
-	printbe64(di, di_ctime);
-	printbe32(di, di_major);
-	printbe32(di, di_minor);
-	printbe64(di, di_goal_meta);
-	printbe64(di, di_goal_data);
-	print_it("  di_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(di->di_flags));
-	printbe32(di, di_payload_format);
-	printbe16(di, di_height);
-	printbe16(di, di_depth);
-	printbe32(di, di_entries);
-	printbe64(di, di_eattr);
+	printbe32(_di, di_uid);
+	printbe32(_di, di_gid);
+	printbe32(_di, di_nlink);
+	printbe64(_di, di_size);
+	printbe64(_di, di_blocks);
+	printbe64(_di, di_atime);
+	printbe64(_di, di_mtime);
+	printbe64(_di, di_ctime);
+	printbe32(_di, di_major);
+	printbe32(_di, di_minor);
+	printbe64(_di, di_goal_meta);
+	printbe64(_di, di_goal_data);
+	print_it("  di_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(_di->di_flags));
+	printbe32(_di, di_payload_format);
+	printbe16(_di, di_height);
+	printbe16(_di, di_depth);
+	printbe32(_di, di_entries);
+	printbe64(_di, di_eattr);
 }
 
 void leaf_print(void *lfp)
@@ -175,6 +314,19 @@ void log_header_print(void *lhp)
 	print_it("  lh_local_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_dinodes));
 }
 
+void gfs_log_header_print(void *lhp)
+{
+	struct gfs_log_header *lh = lhp;
+
+	meta_header_print(&lh->lh_header);
+	print_it("  lh_flags", "%"PRIu32, "0x%.8"PRIx32, be32_to_cpu(lh->lh_flags));
+	print_it("  lh_pad", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(lh->lh_pad));
+	print_it("  lh_first", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_first));
+	print_it("  lh_sequence", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_sequence));
+	print_it("  lh_tail", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_tail));
+	print_it("  lh_last_dump", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(lh->lh_last_dump));
+}
+
 void log_descriptor_print(void *ldp)
 {
 	struct gfs2_log_descriptor *ld = ldp;
@@ -204,3 +356,9 @@ void quota_change_print(void *qcp)
 	printbe32(qc, qc_id);
 }
 
+void gfs_jindex_print(struct gfs_jindex *ji)
+{
+	print_it("  ji_addr", "%"PRIu64, "0x%"PRIx64, be64_to_cpu(ji->ji_addr));
+	print_it("  ji_nsegment", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(ji->ji_nsegment));
+	print_it("  ji_pad", "%"PRIu32, "0x%"PRIx32, be32_to_cpu(ji->ji_pad));
+}
diff --git a/gfs2/edit/struct_print.h b/gfs2/edit/struct_print.h
index 784c130d..be5bb1cb 100644
--- a/gfs2/edit/struct_print.h
+++ b/gfs2/edit/struct_print.h
@@ -5,8 +5,10 @@
 extern void inum_print(void *nop);
 extern void meta_header_print(void *mhp);
 extern void sb_print(void *sbp);
+extern void gfs_sb_print(void *sbp);
 extern void dinode_print(void *dip);
 extern void log_header_print(void *lhp);
+extern void gfs_log_header_print(void *lhp);
 extern void log_descriptor_print(void *ldp);
 extern void quota_print(void *qp);
 extern void quota_change_print(void *qcp);
@@ -15,5 +17,7 @@ extern void ea_header_print(void *eap);
 extern void leaf_print(void *lfp);
 extern void rindex_print(void *rip);
 extern void rgrp_print(void *rgp);
+extern void gfs_rgrp_print(void *rgp);
+extern void gfs_jindex_print(struct gfs_jindex *ji);
 
 #endif /* STRUCT_PRINT_H */
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index cb667815..82408245 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -45,17 +45,6 @@ static int preen = 0;
 static int force_check = 0;
 static const char *pass_name = "";
 
-/* 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 usage(char *name)
 {
 	printf("Usage: %s [-afhnpqvVy] <device> \n", basename(name));
diff --git a/gfs2/glocktop/glocktop.c b/gfs2/glocktop/glocktop.c
index 1eb84c21..9fc7bc64 100644
--- a/gfs2/glocktop/glocktop.c
+++ b/gfs2/glocktop/glocktop.c
@@ -550,7 +550,8 @@ static void eol(int col) /* end of line */
 	}
 }
 
-void print_it(const char *label, const char *fmt, const char *fmt2, ...)
+__attribute__((format(printf,2,4)))
+static void print_it(const char *label, const char *fmt, const char *fmt2, ...)
 {
 	va_list args;
 	char tmp_string[128];
diff --git a/gfs2/libgfs2/check_libgfs2.c b/gfs2/libgfs2/check_libgfs2.c
index a5d9df52..2ee5895d 100644
--- a/gfs2/libgfs2/check_libgfs2.c
+++ b/gfs2/libgfs2/check_libgfs2.c
@@ -1,9 +1,6 @@
 #include <check.h>
 #include "libgfs2.h"
 
-// TODO: Remove this when the extern is removed from libgfs2
-void print_it(const char *label, const char *fmt, const char *fmt2, ...) {}
-
 extern Suite *suite_meta(void);
 extern Suite *suite_ondisk(void);
 extern Suite *suite_rgrp(void);
diff --git a/gfs2/libgfs2/gfs2l.c b/gfs2/libgfs2/gfs2l.c
index 6fc6cd37..cc4f94fc 100644
--- a/gfs2/libgfs2/gfs2l.c
+++ b/gfs2/libgfs2/gfs2l.c
@@ -197,6 +197,3 @@ int main(int argc, char *argv[])
 	free(opts.fspath);
 	return 0;
 }
-
-// libgfs2 still requires an external print_it function
-void print_it(const char *label, const char *fmt, const char *fmt2, ...) { return; }
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 81fe5983..cf7ecf3f 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -796,8 +796,6 @@ extern int write_sb(struct gfs2_sbd *sdp);
 
 /* ondisk.c */
 extern uint32_t gfs2_disk_hash(const char *data, int len);
-extern void print_it(const char *label, const char *fmt, const char *fmt2, ...)
-	__attribute__((format(printf,2,4)));
 
 /* Translation functions */
 
diff --git a/gfs2/mkfs/gfs2_mkfs.h b/gfs2/mkfs/gfs2_mkfs.h
index 6237cd04..f3ff9b16 100644
--- a/gfs2/mkfs/gfs2_mkfs.h
+++ b/gfs2/mkfs/gfs2_mkfs.h
@@ -4,17 +4,6 @@
 #include <stdarg.h>
 #include "copyright.cf"
 
-/* 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/struct_print.c b/gfs2/mkfs/struct_print.c
index 88c9c609..d038f27c 100644
--- a/gfs2/mkfs/struct_print.c
+++ b/gfs2/mkfs/struct_print.c
@@ -2,10 +2,22 @@
 #include <string.h>
 #include <inttypes.h>
 #include <uuid.h>
+#include <stdarg.h>
 #include <libgfs2.h>
 
 #include "struct_print.h"
 
+__attribute__((format(printf,2,4)))
+static 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);
+}
+
 #define printbe16(struct, member) do { \
 		print_it("  "#member, "%"PRIu16, "0x%"PRIx16, be16_to_cpu(struct->member)); \
 	} while(0)
diff --git a/tests/nukerg.c b/tests/nukerg.c
index 74b65abb..a831e459 100644
--- a/tests/nukerg.c
+++ b/tests/nukerg.c
@@ -343,6 +343,3 @@ int main(int argc, char **argv)
 	close(sbd.device_fd);
 	exit(0);
 }
-
-/* This function is for libgfs2's sake. */
-void print_it(const char *label, const char *fmt, const char *fmt2, ...) {}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-01-12 19:26 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 19:26 [Cluster-devel] [PATCH 00/18] gfs2-utils: Don't require an external print_it() in libgfs2 Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 01/18] libgfs2: Move debugging printf out of build_master() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 02/18] libgfs2: Rework lgfs2_build_jindex() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 03/18] libgfs2: Move build_jindex() into fsck.gfs2 Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 04/18] libgfs2: Push down build_per_node() into the utils Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 05/18] libgfs2: Return the inode from build_inum_range() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 06/18] libgfs2: Return the inode from build_statfs_change() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 07/18] libgfs2: Return the inode from build_quota_change() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 08/18] libgfs2: Return the inode from build_inum() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 09/18] libgfs2: Return the inode from build_statfs() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 10/18] libgfs2: Return the inode from build_rindex() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 11/18] libgfs2: Return the inode from build_quota() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 12/18] libgfs2: Move debugging printf out of build_root() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 13/18] libgfs2: Remove debugging printf from do_init_statfs() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 14/18] libgfs2: Move debugging output out of do_init_inum() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 15/18] libgfs2: Remove debugging printfs from fix_device_geometry() Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 16/18] libgfs2: Remove config.[ch] Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 17/18] libgfs2: Move struct printing functions out of libgfs2 Andrew Price
2022-01-12 19:26 ` [Cluster-devel] [PATCH 18/18] libgfs2: Remove print_it extern requirement Andrew Price

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.