gfs2-utils: RHEL7 - libgfs2: Remove debug field from gfs2_sbd

Andrew Price andyp at fedoraproject.org
Mon Sep 8 17:33:46 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=8dfe0251aa7c2ac39784f1a75735fedb353e372b
Commit:        8dfe0251aa7c2ac39784f1a75735fedb353e372b
Parent:        26b7af3357ba6d81fad5096a0e594302502bcd5d
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Wed May 7 14:25:58 2014 +0100
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Thu Jul 24 17:15:39 2014 +0100

libgfs2: Remove debug field from gfs2_sbd

The utils were using the debug field to store their debug printing
options.  Hide the debug field in a libgfs2-internal header to allow
switching on libgfs2 debugging output separately and switch the apps to
use their own debug options. In cases where apps were using sdp->debug
but not actually setting it, remove the code which depends on it being
set.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/convert/gfs2_convert.c    |    5 -----
 gfs2/fsck/rgrepair.c           |   19 -------------------
 gfs2/libgfs2/Makefile.am       |    4 ++--
 gfs2/libgfs2/config.c          |    9 +++++++++
 gfs2/libgfs2/config.h          |    6 ++++++
 gfs2/libgfs2/device_geometry.c |    3 ++-
 gfs2/libgfs2/fs_geometry.c     |    5 +++--
 gfs2/libgfs2/libgfs2.h         |    5 +++--
 gfs2/libgfs2/misc.c            |    7 ++++---
 gfs2/libgfs2/structures.c      |   31 +++++++++++++++----------------
 gfs2/mkfs/main_grow.c          |   21 ---------------------
 gfs2/mkfs/main_jadd.c          |    8 +++++---
 gfs2/mkfs/main_mkfs.c          |   10 +++++-----
 13 files changed, 54 insertions(+), 79 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9f7fa17..15a16ef 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1981,11 +1981,6 @@ static int conv_build_jindex(struct gfs2_sbd *sdp)
 	}
 
 	free(sdp->md.journal);
-	if (sdp->debug) {
-		printf("\nJindex:\n");
-		gfs2_dinode_print(&sdp->md.jiinode->i_di);
-	}
-
 	inode_put(&sdp->md.jiinode);
 	return 0;
 }
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 4fdbcf7..cb39541 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -589,24 +589,6 @@ static int gfs2_rindex_rebuild(struct gfs2_sbd *sdp, int *num_rgs,
 	return 0;
 }
 
-static void debug_print_rgrps(struct gfs2_sbd *sdp, struct osi_root *rgtree)
-{
-	struct osi_node *n, *next;
-	struct rgrp_tree *rl;
-
-	if (sdp->debug) {
-		log_info("\n");
-
-		for (n = osi_first(rgtree); n; n = next) {
-			next = osi_next(n);
-			rl = (struct rgrp_tree *)n;
-			log_info("rg_o = %llu, rg_l = %llu\n",
-				 (unsigned long long)rl->start,
-				 (unsigned long long)rl->length);
-		}
-	}
-}
-
 /*
  * gfs2_rindex_calculate - calculate what the rindex should look like
  *                          in a perfect world (trust_lvl == open_minded)
@@ -649,7 +631,6 @@ static int gfs2_rindex_calculate(struct gfs2_sbd *sdp, int *num_rgs)
 	}
 	/* Compute the default resource group layout as mkfs would have done */
 	compute_rgrp_layout(sdp, &sdp->rgcalc, TRUE);
-	debug_print_rgrps(sdp, &sdp->rgcalc);
 	if (build_rgrps(sdp, FALSE)) { /* FALSE = calc but don't write to disk. */
 		fprintf(stderr, _("Failed to build resource groups\n"));
 		exit(-1);
diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index c5cb288..2d197f0 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -5,14 +5,14 @@ BUILT_SOURCES		= parser.h lexer.h
 AM_LFLAGS		= --header-file=lexer.h
 AM_YFLAGS		= -d
 
-noinst_HEADERS		= libgfs2.h lang.h
+noinst_HEADERS		= libgfs2.h lang.h config.h
 
 noinst_LTLIBRARIES	= libgfs2.la
 
 noinst_PROGRAMS		= gfs2l
 
 libgfs2_la_SOURCES	= block_list.c fs_bits.c gfs1.c misc.c rgrp.c super.c \
-			  buf.c fs_geometry.c gfs2_disk_hash.c ondisk.c \
+			  buf.c fs_geometry.c gfs2_disk_hash.c ondisk.c config.c \
 			  device_geometry.c fs_ops.c gfs2_log.c recovery.c \
 			  structures.c meta.c lang.c parser.y lexer.l
 
diff --git a/gfs2/libgfs2/config.c b/gfs2/libgfs2/config.c
new file mode 100644
index 0000000..d2431e4
--- /dev/null
+++ b/gfs2/libgfs2/config.c
@@ -0,0 +1,9 @@
+#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
new file mode 100644
index 0000000..7c1eb3c
--- /dev/null
+++ b/gfs2/libgfs2/config.h
@@ -0,0 +1,6 @@
+#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 1bee9c2..27e846d 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -15,6 +15,7 @@
 #include <linux/fs.h>
 
 #include "libgfs2.h"
+#include "config.h"
 
 #ifndef BLKSSZGET
 #define BLKSSZGET _IO(0x12,104)   /* logical_block_size */
@@ -99,7 +100,7 @@ void fix_device_geometry(struct gfs2_sbd *sdp)
 
 	device->length = sdp->dinfo.size / sdp->bsize;
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nDevice Geometry:  (in FS blocks)\n");
 		printf("  length = %"PRIu64"\n", device->length);
 		printf("\nDevice Size: %"PRIu64"\n", sdp->dinfo.size);
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index 4bdb64a..9c9085f 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -13,6 +13,7 @@
 
 #include <linux/types.h>
 #include "libgfs2.h"
+#include "config.h"
 
 #define DIV_RU(x, y) (((x) + (y) - 1) / (y))
 
@@ -59,7 +60,7 @@ uint64_t how_many_rgrps(struct gfs2_sbd *sdp, struct device *dev, int rgsize_spe
 		sdp->rgsize += GFS2_DEFAULT_RGSIZE; /* bigger rgs */
 	}
 
-	if (sdp->debug)
+	if (cfg_debug)
 		printf("  rg sz = %"PRIu32"\n  nrgrp = %"PRIu64"\n",
 		       sdp->rgsize, nrgrp);
 
@@ -220,7 +221,7 @@ int build_rgrps(struct gfs2_sbd *sdp, int do_write)
 			}
 		}
 
-		if (sdp->debug) {
+		if (cfg_debug) {
 			printf("\n");
 			gfs2_rindex_print(ri);
 		}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 5fdf9af..b269357 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -276,8 +276,6 @@ struct gfs2_sbd {
 	unsigned int rgsize;     /* Size of resource groups (in MB) */
 	unsigned int qcsize;     /* Size of quota change files (in MB) */
 
-	int debug;
-
 	char device_name[PATH_MAX];
 	char *path_name;
 
@@ -401,6 +399,9 @@ extern uint32_t lgfs2_get_block_type(const struct gfs2_buffer_head *lbh);
 #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/misc.c b/gfs2/libgfs2/misc.c
index 4cdd6e0..9eca24c 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -20,6 +20,7 @@
 #include <signal.h>
 
 #include "libgfs2.h"
+#include "config.h"
 
 #define PAGE_SIZE (4096)
 #define DIV_RU(x, y) (((x) + (y) - 1) / (y))
@@ -198,17 +199,17 @@ static int lock_for_admin(struct gfs2_sbd *sdp)
 {
 	int error;
 
-	if (sdp->debug)
+	if (cfg_debug)
 		printf("\nTrying to get admin lock...\n");
 
 	sdp->metafs_fd = open(sdp->metafs_path, O_RDONLY | O_NOFOLLOW);
 	if (sdp->metafs_fd < 0)
 		return -1;
-	
+
 	error = flock(sdp->metafs_fd, LOCK_EX);
 	if (error)
 		return -1;
-	if (sdp->debug)
+	if (cfg_debug)
 		printf("Got it.\n");
 	return 0;
 }
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 2cc9a98..ee49dce 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -14,6 +14,7 @@
 #include <sys/time.h>
 
 #include "libgfs2.h"
+#include "config.h"
 
 int build_master(struct gfs2_sbd *sdp)
 {
@@ -29,12 +30,12 @@ int build_master(struct gfs2_sbd *sdp)
 	inum.no_addr = bn;
 
 	bh = init_dinode(sdp, &inum, S_IFDIR | 0755, GFS2_DIF_SYSTEM, &inum);
-	
+
 	sdp->master_dir = lgfs2_inode_get(sdp, bh);
 	if (sdp->master_dir == NULL)
 		return -1;
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nMaster dir:\n");
 		gfs2_dinode_print(&sdp->master_dir->i_di);
 	}
@@ -223,7 +224,7 @@ int build_jindex(struct gfs2_sbd *sdp)
 			return ret;
 		inode_put(&sdp->md.journal[j]);
 	}
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nJindex:\n");
 		gfs2_dinode_print(&jindex->i_di);
 	}
@@ -235,7 +236,6 @@ int build_jindex(struct gfs2_sbd *sdp)
 
 int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 {
-	struct gfs2_sbd *sdp = per_node->i_sbd;
 	char name[256];
 	struct gfs2_inode *ip;
 
@@ -248,7 +248,7 @@ int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 	ip->i_di.di_size = sizeof(struct gfs2_inum_range);
 	gfs2_dinode_out(&ip->i_di, ip->i_bh);
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nInum Range %u:\n", j);
 		gfs2_dinode_print(&ip->i_di);
 	}
@@ -259,7 +259,6 @@ int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 
 int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
 {
-	struct gfs2_sbd *sdp = per_node->i_sbd;
 	char name[256];
 	struct gfs2_inode *ip;
 
@@ -272,7 +271,7 @@ int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
 	ip->i_di.di_size = sizeof(struct gfs2_statfs_change);
 	gfs2_dinode_out(&ip->i_di, ip->i_bh);
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nStatFS Change %u:\n", j);
 		gfs2_dinode_print(&ip->i_di);
 	}
@@ -316,7 +315,7 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
 		brelse(bh);
 	}
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nQuota Change %u:\n", j);
 		gfs2_dinode_print(&ip->i_di);
 	}
@@ -352,7 +351,7 @@ int build_per_node(struct gfs2_sbd *sdp)
 		}
 	}
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nper_node:\n");
 		gfs2_dinode_print(&per_node->i_di);
 	}
@@ -371,7 +370,7 @@ int build_inum(struct gfs2_sbd *sdp)
 		return errno;
 	}
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nInum Inode:\n");
 		gfs2_dinode_print(&ip->i_di);
 	}
@@ -390,7 +389,7 @@ int build_statfs(struct gfs2_sbd *sdp)
 		return errno;
 	}
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nStatFS Inode:\n");
 		gfs2_dinode_print(&ip->i_di);
 	}
@@ -432,7 +431,7 @@ int build_rindex(struct gfs2_sbd *sdp)
 	if (count != sizeof(struct gfs2_rindex))
 		return -1;
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nResource Index:\n");
 		gfs2_dinode_print(&ip->i_di);
 	}
@@ -467,7 +466,7 @@ int build_quota(struct gfs2_sbd *sdp)
 	if (count != sizeof(struct gfs2_quota))
 		return -1;
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nRoot quota:\n");
 		gfs2_quota_print(&qu);
 	}
@@ -494,7 +493,7 @@ int build_root(struct gfs2_sbd *sdp)
 	if (sdp->md.rooti == NULL)
 		return -1;
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nRoot directory:\n");
 		gfs2_dinode_print(&sdp->md.rooti->i_di);
 	}
@@ -513,7 +512,7 @@ int do_init_inum(struct gfs2_sbd *sdp)
 	if (count != sizeof(uint64_t))
 		return -1;
 
-	if (sdp->debug)
+	if (cfg_debug)
 		printf("\nNext Inum: %"PRIu64"\n",
 		       sdp->md.next_inum);
 	return 0;
@@ -535,7 +534,7 @@ int do_init_statfs(struct gfs2_sbd *sdp)
 	if (count != sizeof(struct gfs2_statfs_change))
 		return -1;
 
-	if (sdp->debug) {
+	if (cfg_debug) {
 		printf("\nStatfs:\n");
 		gfs2_statfs_change_print(&sc);
 	}
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index adceeef..7e005e9 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -216,9 +216,6 @@ static unsigned initialize_new_portion(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs)
 		}
 		if (metafs_interrupted)
 			return 0;
-		if (sdp->debug)
-			printf(_("Writing resource group at %llu with size %"PRIu32"\n"),
-			       ri.ri_addr, ri.ri_length + ri.ri_data);
 		if (!test)
 			err = lgfs2_rgrp_write(rgs, sdp->device_fd, rg);
 		if (err != 0) {
@@ -322,22 +319,6 @@ static void print_info(struct gfs2_sbd *sdp)
 		   (unsigned long long)(fsgrowth * sdp->bsize) / MB);
 }
 
-static void debug_print_rgrps(const char *banner, struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs)
-{
-	lgfs2_rgrp_t r;
-
-	if (sdp->debug) {
-		log_info("%s\n", banner);
-
-		for (r = lgfs2_rgrp_first(rgs); r; r = lgfs2_rgrp_next(r)) {
-			const struct gfs2_rindex *ri = lgfs2_rgrp_index(r);
-			log_info("ri_addr = %llu, size = %llu\n",
-				 (unsigned long long)ri->ri_addr,
-				 (unsigned long long)(ri->ri_data0 + ri->ri_data - ri->ri_addr));
-		}
-	}
-}
-
 void main_grow(int argc, char *argv[])
 {
 	struct gfs2_sbd sbd, *sdp = &sbd;
@@ -431,7 +412,6 @@ void main_grow(int argc, char *argv[])
 		if (metafs_interrupted)
 			goto out;
 		fssize = lgfs2_rgrp_align_addr(rgs, filesystem_size(rgs) + 1);
-		debug_print_rgrps(_("Existing resource groups"), sdp, rgs);
 		/* We're done with the old rgs now that we have the fssize and rg count */
 		lgfs2_rgrps_free(&rgs);
 		/* Now lets set up the new ones with alignment and all */
@@ -453,7 +433,6 @@ void main_grow(int argc, char *argv[])
 		rgcount = initialize_new_portion(sdp, rgs);
 		if (rgcount == 0 || metafs_interrupted)
 			goto out;
-		debug_print_rgrps(_("New resource groups"), sdp, rgs);
 		fsync(sdp->device_fd);
 		fix_rindex(rindex_fd, rgs, old_rg_count, rgcount);
 	out:
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index d01e3b3..4338e8d 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -28,6 +28,7 @@
 #define RANDOM(values) ((values) * (random() / (RAND_MAX + 1.0)))
 
 static int quiet = 0;
+static int debug = 0;
 
 static void
 make_jdata(int fd, const char *value)
@@ -128,7 +129,8 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 			sdp->qcsize = atoi(optarg);
 			break;
 		case 'D':
-			sdp->debug = TRUE;
+			debug = 1;
+			lgfs2_set_debug(1);
 			break;
 		case 'h':
 			print_usage(argv[0]);
@@ -172,7 +174,7 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 	if (optind < argc)
 		die( _("Unrecognized argument: %s\n"), argv[optind]);
 
-	if (sdp->debug) {
+	if (debug) {
 		printf( _("Command Line Arguments:\n"));
 		printf("  qcsize = %u\n", sdp->qcsize);
 		printf("  jsize = %u\n", sdp->jsize);
@@ -200,7 +202,7 @@ static void verify_arguments(struct gfs2_sbd *sdp)
 
 static void print_results(struct gfs2_sbd *sdp)
 {
-	if (sdp->debug)
+	if (debug)
 		printf("\n");
 	else if (quiet)
 		return;
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 31b1e62..f778e8d 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -308,6 +308,7 @@ static void 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]);
@@ -616,7 +617,7 @@ static lgfs2_rgrps_t rgs_init(struct mkfs_opts *opts, struct gfs2_sbd *sdp)
 	return rgs;
 }
 
-static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct gfs2_rindex *ri)
+static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct gfs2_rindex *ri, int debug)
 {
 	int err = 0;
 	lgfs2_rgrp_t rg = NULL;
@@ -631,7 +632,7 @@ static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct gfs2_rinde
 		perror(_("Failed to write resource group"));
 		return -1;
 	}
-	if (sdp->debug) {
+	if (debug) {
 		gfs2_rindex_print(ri);
 		printf("\n");
 	}
@@ -665,7 +666,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct mkfs_opts
 		rgaddr = lgfs2_rindex_entry_new(rgs, &ri, rgaddr, jrgsize);
 		if (rgaddr == 0) /* Reached the end when we still have journals to write */
 			return 1;
-		result = place_rgrp(sdp, rgs, &ri);
+		result = place_rgrp(sdp, rgs, &ri, opts->debug);
 		if (result != 0)
 			return result;
 	}
@@ -678,7 +679,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct mkfs_opts
 		rgaddr = lgfs2_rindex_entry_new(rgs, &ri, rgaddr, 0);
 		if (rgaddr == 0)
 			break; /* Done */
-		result = place_rgrp(sdp, rgs, &ri);
+		result = place_rgrp(sdp, rgs, &ri, opts->debug);
 		if (result)
 			return result;
 	}
@@ -696,7 +697,6 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, unsigned bsiz
 	sdp->md.journals = opts->journals;
 	sdp->device_fd = opts->dev.fd;
 	sdp->bsize = bsize;
-	sdp->debug = opts->debug;
 
 	if (compute_constants(sdp)) {
 		perror(_("Failed to compute file system constants"));


More information about the cluster-commits mailing list