cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] libgfs2 cleanups
@ 2011-11-30 15:04 Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 1/6] libgfs2: Move generic_interrupt() into utils Steven Whitehouse
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Steven Whitehouse @ 2011-11-30 15:04 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi,

This patch set is working towards removing all the user interface code
from libgfs2. There will be more patches to follow. Once all of the
log_xxx() functions are moved out from libgfs2 then we can move the
macros into the individual utilities which should more or less
complete the job,

Steve.



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

* [Cluster-devel] [PATCH 1/6] libgfs2: Move generic_interrupt() into utils
  2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
@ 2011-11-30 15:04 ` Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 2/6] libgfs2: Move gfs2_getch " Steven Whitehouse
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Steven Whitehouse @ 2011-11-30 15:04 UTC (permalink / raw)
  To: cluster-devel.redhat.com

First patch moving user interface code out of the library

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 gfs2/convert/gfs2_convert.c |   48 +++++++++++++++++++++++++++++++++++++++++++
 gfs2/fsck/util.c            |   48 +++++++++++++++++++++++++++++++++++++++++++
 gfs2/fsck/util.h            |    4 +++
 gfs2/libgfs2/gfs2_log.c     |   48 -------------------------------------------
 gfs2/libgfs2/libgfs2.h      |    3 --
 5 files changed, 100 insertions(+), 51 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 396e899..f79b4a4 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2057,6 +2057,54 @@ static void copy_quotas(struct gfs2_sbd *sdp)
 	inode_put(&oq_ip);
 }
 
+
+static char generic_interrupt(const char *caller, const char *where,
+		       const char *progress, const char *question,
+		       const char *answers)
+{
+	fd_set rfds;
+	struct timeval tv;
+	char response;
+	int err, i;
+
+	FD_ZERO(&rfds);
+	FD_SET(STDIN_FILENO, &rfds);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 0;
+	/* Make sure there isn't extraneous input before asking the
+	 * user the question */
+	while((err = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv))) {
+		if(err < 0) {
+			log_debug("Error in select() on stdin\n");
+			break;
+		}
+		if(read(STDIN_FILENO, &response, sizeof(char)) < 0) {
+			log_debug("Error in read() on stdin\n");
+			break;
+		}
+	}
+	while (TRUE) {
+		printf("\n%s interrupted during %s:  ", caller, where);
+		if (progress)
+			printf("%s.\n", progress);
+		printf("%s", question);
+
+		/* Make sure query is printed out */
+		fflush(NULL);
+		response = gfs2_getch();
+		printf("\n");
+		fflush(NULL);
+		if (strchr(answers, response))
+			break;
+		printf("Bad response, please type ");
+		for (i = 0; i < strlen(answers) - 1; i++)
+			printf("'%c', ", answers[i]);
+		printf(" or '%c'.\n", answers[i]);
+	}
+	return response;
+}
+
 static int __attribute__((format(printf, 3, 4))) gfs2_query(int *setonabort,
                            struct gfs2_options *opts, const char *format, ...)
 {
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index 0d243e0..ddbc757 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -87,6 +87,54 @@ void warm_fuzzy_stuff(uint64_t block)
 	}
 }
 
+
+char generic_interrupt(const char *caller, const char *where,
+		       const char *progress, const char *question,
+		       const char *answers)
+{
+	fd_set rfds;
+	struct timeval tv;
+	char response;
+	int err, i;
+
+	FD_ZERO(&rfds);
+	FD_SET(STDIN_FILENO, &rfds);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 0;
+	/* Make sure there isn't extraneous input before asking the
+	 * user the question */
+	while((err = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv))) {
+		if(err < 0) {
+			log_debug("Error in select() on stdin\n");
+			break;
+		}
+		if(read(STDIN_FILENO, &response, sizeof(char)) < 0) {
+			log_debug("Error in read() on stdin\n");
+			break;
+		}
+	}
+	while (TRUE) {
+		printf("\n%s interrupted during %s:  ", caller, where);
+		if (progress)
+			printf("%s.\n", progress);
+		printf("%s", question);
+
+		/* Make sure query is printed out */
+		fflush(NULL);
+		response = gfs2_getch();
+		printf("\n");
+		fflush(NULL);
+		if (strchr(answers, response))
+			break;
+		printf("Bad response, please type ");
+		for (i = 0; i < strlen(answers) - 1; i++)
+			printf("'%c', ", answers[i]);
+		printf(" or '%c'.\n", answers[i]);
+	}
+	return response;
+}
+
 /* fsck_query: Same as gfs2_query except it adjusts errors_found and
    errors_corrected. */
 int fsck_query(const char *format, ...)
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index b56fe69..7c32404 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -180,4 +180,8 @@ extern void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il);
 extern int gfs2_blockmap_set(struct gfs2_bmap *il, uint64_t block,
 			     enum gfs2_mark_block mark);
 extern int set_ip_blockmap(struct gfs2_inode *ip, int instree);
+extern char generic_interrupt(const char *caller, const char *where,
+                       const char *progress, const char *question,
+                       const char *answers);
+
 #endif /* __UTIL_H__ */
diff --git a/gfs2/libgfs2/gfs2_log.c b/gfs2/libgfs2/gfs2_log.c
index aa5ca73..39b09c7 100644
--- a/gfs2/libgfs2/gfs2_log.c
+++ b/gfs2/libgfs2/gfs2_log.c
@@ -84,51 +84,3 @@ char gfs2_getch(void)
 	tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
 	return ch;
 }
-
-char generic_interrupt(const char *caller, const char *where,
-		       const char *progress, const char *question,
-		       const char *answers)
-{
-	fd_set rfds;
-	struct timeval tv;
-	char response;
-	int err, i;
-
-	FD_ZERO(&rfds);
-	FD_SET(STDIN_FILENO, &rfds);
-
-	tv.tv_sec = 0;
-	tv.tv_usec = 0;
-	/* Make sure there isn't extraneous input before asking the
-	 * user the question */
-	while((err = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv))) {
-		if(err < 0) {
-			log_debug("Error in select() on stdin\n");
-			break;
-		}
-		if(read(STDIN_FILENO, &response, sizeof(char)) < 0) {
-			log_debug("Error in read() on stdin\n");
-			break;
-		}
-	}
-	while (TRUE) {
-		printf("\n%s interrupted during %s:  ", caller, where);
-		if (progress)
-			printf("%s.\n", progress);
-		printf("%s", question);
-
-		/* Make sure query is printed out */
-		fflush(NULL);
-		response = gfs2_getch();
-		printf("\n");
-		fflush(NULL);
-		if (strchr(answers, response))
-			break;
-		printf("Bad response, please type ");
-		for (i = 0; i < strlen(answers) - 1; i++)
-			printf("'%c', ", answers[i]);
-		printf(" or '%c'.\n", answers[i]);
-	}
-	return response;
-}
-
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 95fd2b4..80c84fa 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -662,9 +662,6 @@ extern void decrease_verbosity(void);
 extern void print_fsck_log(int priority, const char *file, int line,
 			   const char *format, ...)
 	__attribute__((format(printf,4,5)));
-extern char generic_interrupt(const char *caller, const char *where,
-			      const char *progress, const char *question,
-			      const char *answers);
 /* misc.c */
 
 extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
-- 
1.7.4.4



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

* [Cluster-devel] [PATCH 2/6] libgfs2: Move gfs2_getch into utils
  2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 1/6] libgfs2: Move generic_interrupt() into utils Steven Whitehouse
@ 2011-11-30 15:04 ` Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 3/6] libgfs2: Prepare to remove log_xxx() macros from library Steven Whitehouse
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Steven Whitehouse @ 2011-11-30 15:04 UTC (permalink / raw)
  To: cluster-devel.redhat.com

More UI code being moved out of the library.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 gfs2/convert/gfs2_convert.c |   36 ++++++++++++++++++++++++++++++++----
 gfs2/fsck/util.c            |   28 ++++++++++++++++++++++++++++
 gfs2/fsck/util.h            |    1 +
 gfs2/libgfs2/gfs2_log.c     |   28 ----------------------------
 gfs2/libgfs2/libgfs2.h      |    1 -
 5 files changed, 61 insertions(+), 33 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index f79b4a4..9f24137 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -23,6 +23,7 @@
 #include <sys/time.h>
 #include <errno.h>
 #include <ctype.h>
+#include <termios.h>
 #include <libintl.h>
 #include <locale.h>
 #define _(String) gettext(String)
@@ -2057,24 +2058,51 @@ static void copy_quotas(struct gfs2_sbd *sdp)
 	inode_put(&oq_ip);
 }
 
+static char gfs2_getch(void)
+{
+	struct termios termattr, savetermattr;
+	char ch;
+	ssize_t size;
+
+	tcgetattr (STDIN_FILENO, &termattr);
+	savetermattr = termattr;
+	termattr.c_lflag &= ~(ICANON | IEXTEN | ISIG);
+	termattr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+	termattr.c_cflag &= ~(CSIZE | PARENB);
+	termattr.c_cflag |= CS8;
+	termattr.c_oflag &= ~(OPOST);
+   	termattr.c_cc[VMIN] = 0;
+	termattr.c_cc[VTIME] = 0;
+
+	tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
+	do {
+		size = read(STDIN_FILENO, &ch, 1);
+		if (size)
+			break;
+		usleep(50000);
+	} while (!size);
+
+	tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
+	return ch;
+}
 
 static char generic_interrupt(const char *caller, const char *where,
 		       const char *progress, const char *question,
 		       const char *answers)
 {
 	fd_set rfds;
-	struct timeval tv;
+	struct timeval stv;
 	char response;
 	int err, i;
 
 	FD_ZERO(&rfds);
 	FD_SET(STDIN_FILENO, &rfds);
 
-	tv.tv_sec = 0;
-	tv.tv_usec = 0;
+	stv.tv_sec = 0;
+	stv.tv_usec = 0;
 	/* Make sure there isn't extraneous input before asking the
 	 * user the question */
-	while((err = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv))) {
+	while((err = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &stv))) {
 		if(err < 0) {
 			log_debug("Error in select() on stdin\n");
 			break;
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index ddbc757..d912920 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -6,6 +6,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <stdio.h>
+#include <termios.h>
 #include <libintl.h>
 #include <ctype.h>
 #define _(String) gettext(String)
@@ -87,6 +88,33 @@ void warm_fuzzy_stuff(uint64_t block)
 	}
 }
 
+char gfs2_getch(void)
+{
+	struct termios termattr, savetermattr;
+	char ch;
+	ssize_t size;
+
+	tcgetattr (STDIN_FILENO, &termattr);
+	savetermattr = termattr;
+	termattr.c_lflag &= ~(ICANON | IEXTEN | ISIG);
+	termattr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+	termattr.c_cflag &= ~(CSIZE | PARENB);
+	termattr.c_cflag |= CS8;
+	termattr.c_oflag &= ~(OPOST);
+   	termattr.c_cc[VMIN] = 0;
+	termattr.c_cc[VTIME] = 0;
+
+	tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
+	do {
+		size = read(STDIN_FILENO, &ch, 1);
+		if (size)
+			break;
+		usleep(50000);
+	} while (!size);
+
+	tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
+	return ch;
+}
 
 char generic_interrupt(const char *caller, const char *where,
 		       const char *progress, const char *question,
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 7c32404..6de61e2 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -183,5 +183,6 @@ extern int set_ip_blockmap(struct gfs2_inode *ip, int instree);
 extern char generic_interrupt(const char *caller, const char *where,
                        const char *progress, const char *question,
                        const char *answers);
+extern char gfs2_getch(void);
 
 #endif /* __UTIL_H__ */
diff --git a/gfs2/libgfs2/gfs2_log.c b/gfs2/libgfs2/gfs2_log.c
index 39b09c7..a1ceaeb 100644
--- a/gfs2/libgfs2/gfs2_log.c
+++ b/gfs2/libgfs2/gfs2_log.c
@@ -56,31 +56,3 @@ void print_fsck_log(int priority, const char *file, int line,
 	print_msg(priority, file, line, format, args);
 	va_end(args);
 }
-
-char gfs2_getch(void)
-{
-	struct termios termattr, savetermattr;
-	char ch;
-	ssize_t size;
-
-	tcgetattr (STDIN_FILENO, &termattr);
-	savetermattr = termattr;
-	termattr.c_lflag &= ~(ICANON | IEXTEN | ISIG);
-	termattr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
-	termattr.c_cflag &= ~(CSIZE | PARENB);
-	termattr.c_cflag |= CS8;
-	termattr.c_oflag &= ~(OPOST);
-   	termattr.c_cc[VMIN] = 0;
-	termattr.c_cc[VTIME] = 0;
-
-	tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
-	do {
-		size = read(STDIN_FILENO, &ch, 1);
-		if (size)
-			break;
-		usleep(50000);
-	} while (!size);
-
-	tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
-	return ch;
-}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 80c84fa..d02d63e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -656,7 +656,6 @@ extern int print_level;
 
 #define stack log_debug("<backtrace> - %s()\n", __func__)
 
-extern char gfs2_getch(void);
 extern void increase_verbosity(void);
 extern void decrease_verbosity(void);
 extern void print_fsck_log(int priority, const char *file, int line,
-- 
1.7.4.4



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

* [Cluster-devel] [PATCH 3/6] libgfs2: Prepare to remove log_xxx() macros from library
  2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 1/6] libgfs2: Move generic_interrupt() into utils Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 2/6] libgfs2: Move gfs2_getch " Steven Whitehouse
@ 2011-11-30 15:04 ` Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 4/6] libgfs2: Move some debug messages out into mkfs/fsck Steven Whitehouse
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Steven Whitehouse @ 2011-11-30 15:04 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This will need to be done in stages. The first stage is to
clean up what is there. There are calls to the log_ functions
in the library itself, and those will need to be removed
in later patches.

This patch moves the gfs2_options structure into the two
utils which actually require it, removes the print_fsck_log
function, replacing the 3 calls to it from fsck with
the equivalent printf functions - it looks like those could
be merged in future as they all look very similar.

The log_ macros are also updated, so that they will do excatly
the same as before, but now don't depend on any code in libgfs2
itself.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 gfs2/convert/gfs2_convert.c |    7 +++++++
 gfs2/fsck/fsck.h            |    7 +++++++
 gfs2/fsck/metawalk.c        |   40 ++++++++++++++++++----------------------
 gfs2/fsck/util.h            |    1 +
 gfs2/libgfs2/gfs2_log.c     |   34 ----------------------------------
 gfs2/libgfs2/libgfs2.h      |   29 +++++++++--------------------
 gfs2/libgfs2/super.c        |    2 +-
 7 files changed, 43 insertions(+), 77 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9f24137..09a689c 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -139,6 +139,13 @@ struct blocklist {
 	char *ptrbuf;
 };
 
+struct gfs2_options {
+	char *device;
+	unsigned int yes:1;
+	unsigned int no:1;
+	unsigned int query:1;
+};
+
 struct gfs1_sb  raw_gfs1_ondisk_sb;
 struct gfs2_sbd sb2;
 char device[256];
diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h
index edd73d7..70fc3d7 100644
--- a/gfs2/fsck/fsck.h
+++ b/gfs2/fsck/fsck.h
@@ -124,6 +124,13 @@ extern void dirtree_delete(struct dir_info *b);
  * of pass1 and put somewhere else... */
 struct dir_info *dirtree_insert(uint64_t dblock);
 
+struct gfs2_options {
+	char *device;
+	unsigned int yes:1;
+	unsigned int no:1;
+	unsigned int query:1;
+};
+
 extern struct gfs2_options opts;
 extern struct gfs2_inode *lf_dip; /* Lost and found directory inode */
 extern struct gfs2_bmap *bl;
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index ef7f05d..d78df72 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -129,38 +129,34 @@ int _fsck_blockmap_set(struct gfs2_inode *ip, uint64_t bblock,
 				log_info("\n");
 				prevcount = 0;
 			}
-			print_fsck_log(MSG_DEBUG, caller, fline,
-				       _("%s inode found at block "
-					 "(0x%llx): marking as '%s'\n"),
-				       btype, (unsigned long long)
-				       ip->i_di.di_num.no_addr,
-				       block_type_string(mark));
+			printf( _("(%s:%d) %s inode found at block "
+				  "(0x%llx): marking as '%s'\n"), caller, fline,
+			       btype,
+			       (unsigned long long)ip->i_di.di_num.no_addr,
+			       block_type_string(mark));
+
 		} else if (mark == gfs2_bad_block || mark == gfs2_meta_inval) {
 			if (prevcount) {
 				log_info("\n");
 				prevcount = 0;
 			}
-			print_fsck_log(MSG_DEBUG, caller, fline,
-				       _("inode (0x%llx) references "
-					 "%s block (0x%llx): "
-					 "marking as '%s'\n"),
-				       (unsigned long long)
-				       ip->i_di.di_num.no_addr,
-				       btype, (unsigned long long)bblock,
-				       block_type_string(mark));
+			printf( _("(%s:%d) inode (0x%llx) references %s block"
+				  " (0x%llx): marking as '%s'\n"),
+			       caller, fline,
+			       (unsigned long long)ip->i_di.di_num.no_addr,
+			       btype, (unsigned long long)bblock,
+			       block_type_string(mark));
 		} else {
 			if (prevcount) {
 				log_info("\n");
 				prevcount = 0;
 			}
-			print_fsck_log(MSG_DEBUG, caller, fline,
-				       _("inode (0x%llx) references "
-					 "%s block (0x%llx): "
-					 "marking as '%s'\n"),
-				       (unsigned long long)
-				       ip->i_di.di_num.no_addr, btype,
-				       (unsigned long long)bblock,
-				       block_type_string(mark));
+			printf( _("(%s:%d) inode (0x%llx) references %s block"
+				  " (0x%llx): marking as '%s'\n"),
+			       caller, fline,
+			       (unsigned long long)ip->i_di.di_num.no_addr,
+			       btype, (unsigned long long)bblock,
+			       block_type_string(mark));
 		}
 		prev_ino_addr = ip->i_di.di_num.no_addr;
 		prev_mark = mark;
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 6de61e2..80ed0c4 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -184,5 +184,6 @@ extern char generic_interrupt(const char *caller, const char *where,
                        const char *progress, const char *question,
                        const char *answers);
 extern char gfs2_getch(void);
+#define stack log_debug("<backtrace> - %s()\n", __func__)
 
 #endif /* __UTIL_H__ */
diff --git a/gfs2/libgfs2/gfs2_log.c b/gfs2/libgfs2/gfs2_log.c
index a1ceaeb..da5f489 100644
--- a/gfs2/libgfs2/gfs2_log.c
+++ b/gfs2/libgfs2/gfs2_log.c
@@ -22,37 +22,3 @@ void decrease_verbosity(void)
 {
 	print_level--;
 }
-
-static __attribute__((format (printf, 4, 0)))
-void print_msg(int priority, const char *file, int line,
-	       const char *format, va_list args) {
-
-	switch (priority) {
-
-	case MSG_DEBUG:
-		printf("(%s:%d) ", file, line);
-		vprintf(format, args);
-		break;
-	case MSG_INFO:
-	case MSG_NOTICE:
-	case MSG_WARN:
-		vprintf(format, args);
-		fflush(NULL);
-		break;
-	case MSG_ERROR:
-	case MSG_CRITICAL:
-	default:
-		vfprintf(stderr, format, args);
-		break;
-	}
-}
-
-
-void print_fsck_log(int priority, const char *file, int line,
-		    const char *format, ...)
-{
-	va_list args;
-	va_start(args, format);
-	print_msg(priority, file, line, format, args);
-	va_end(args);
-}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d02d63e..04169bf 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -617,12 +617,6 @@ extern void gfs_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx,
 			    uint64_t leaf_out);
 
 /* gfs2_log.c */
-struct gfs2_options {
-	char *device;
-	unsigned int yes:1;
-	unsigned int no:1;
-	unsigned int query:1;
-};
 
 extern int print_level;
 
@@ -634,33 +628,28 @@ extern int print_level;
 #define MSG_CRITICAL    2
 #define MSG_NULL        1
 
-#define print_log(priority, format...) \
-	do { print_fsck_log(priority, __FUNCTION__, __LINE__, ## format); } while(0)
-
 #define log_debug(format...) \
-	do { if(print_level >= MSG_DEBUG) print_log(MSG_DEBUG, format); } while(0)
+	do { if (print_level >= MSG_DEBUG) { \
+		printf("(%s:%d) ", __FUNCTION__, __LINE__); \
+		printf(format); } } while(0)
+
 #define log_info(format...) \
-	do { if(print_level >= MSG_INFO) print_log(MSG_INFO, format); } while(0)
+	do { if (print_level >= MSG_INFO) printf(format); } while(0)
 
 #define log_notice(format...) \
-	do { if(print_level >= MSG_NOTICE) print_log(MSG_NOTICE, format); } while(0)
+	do { if (print_level >= MSG_NOTICE) printf(format); } while(0)
 
 #define log_warn(format...) \
-	do { if(print_level >= MSG_WARN) print_log(MSG_WARN, format); } while(0)
+	do { if (print_level >= MSG_WARN) printf(format); } while(0)
 
 #define log_err(format...) \
-	do { if(print_level >= MSG_ERROR) print_log(MSG_ERROR, format); } while(0)
+	do { if (print_level >= MSG_ERROR) fprintf(stderr, format); } while(0)
 
 #define log_crit(format...) \
-	do { if(print_level >= MSG_CRITICAL) print_log(MSG_CRITICAL, format); } while(0)
-
-#define stack log_debug("<backtrace> - %s()\n", __func__)
+	do { if (print_level >= MSG_CRITICAL) fprintf(stderr, format); } while(0)
 
 extern void increase_verbosity(void);
 extern void decrease_verbosity(void);
-extern void print_fsck_log(int priority, const char *file, int line,
-			   const char *format, ...)
-	__attribute__((format(printf,4,5)));
 /* misc.c */
 
 extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index c844287..2f544ab 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -28,7 +28,7 @@ int check_sb(struct gfs2_sb *sb, int allow_gfs)
 	    sb->sb_header.mh_type != GFS2_METATYPE_SB) {
 		log_crit("Either the super block is corrupted, or this "
 				 "is not a GFS2 filesystem\n");
-		log_debug("Header magic: %X Header Type: %X\n",
+		log_crit("Header magic: %X Header Type: %X\n",
 				  sb->sb_header.mh_magic,
 				  sb->sb_header.mh_type);
 		return -EINVAL;
-- 
1.7.4.4



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

* [Cluster-devel] [PATCH 4/6] libgfs2: Move some debug messages out into mkfs/fsck
  2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
                   ` (2 preceding siblings ...)
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 3/6] libgfs2: Prepare to remove log_xxx() macros from library Steven Whitehouse
@ 2011-11-30 15:04 ` Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 5/6] libgfs2: Clean up sb read/check functions Steven Whitehouse
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Steven Whitehouse @ 2011-11-30 15:04 UTC (permalink / raw)
  To: cluster-devel.redhat.com

We don't need to print these messages from the function which
calculates the resource group layout, we can do it afterwards.
There are still some other messages which need to be relocated
from this function, but that is a more tricky operation.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 gfs2/fsck/rgrepair.c       |   19 +++++++++++++++++++
 gfs2/libgfs2/fs_geometry.c |   12 ------------
 gfs2/mkfs/gfs2_mkfs.h      |    9 +++++----
 gfs2/mkfs/main_grow.c      |   19 +++++++++++++++++++
 gfs2/mkfs/main_mkfs.c      |    1 +
 5 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 1ffa2c0..c11558b 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -593,6 +593,24 @@ 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)
@@ -643,6 +661,7 @@ 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);
 	build_rgrps(sdp, FALSE); /* FALSE = calc but don't write to disk. */
 	log_debug( _("fs_total_size = 0x%llx blocks.\n"),
 		  (unsigned long long)sdp->device.length);
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index 4278bbf..5ff9813 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -142,18 +142,6 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
 	}
 
 	sdp->rgrps = nrgrp;
-
-	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);
-		}
-	}
 }
 
 /**
diff --git a/gfs2/mkfs/gfs2_mkfs.h b/gfs2/mkfs/gfs2_mkfs.h
index 14bf4f6..6f0ac2b 100644
--- a/gfs2/mkfs/gfs2_mkfs.h
+++ b/gfs2/mkfs/gfs2_mkfs.h
@@ -6,16 +6,17 @@
 #include "copyright.cf"
 
 /* main_grow */
-void main_grow(int argc, char *argv[]);
+extern void main_grow(int argc, char *argv[]);
+extern void debug_print_rgrps(struct gfs2_sbd *sdp, struct osi_root *rgtree);
 
 /* main_jadd */
-void main_jadd(int argc, char *argv[]);
+extern void main_jadd(int argc, char *argv[]);
 
 /* main_mkfs */
-void main_mkfs(int argc, char *argv[]);
+extern void main_mkfs(int argc, char *argv[]);
 
 /* main_shrink */
-void main_shrink(int argc, char *argv[]);
+extern void main_shrink(int argc, char *argv[]);
 
 /*
  * The following inode IOCTL macros and inode flags 
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index f6d7bf0..1dc911a 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -284,6 +284,24 @@ static void print_info(struct gfs2_sbd *sdp)
 		   (unsigned long long)fsgrowth / MB);
 }
 
+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);
+		}
+	}
+}
+
 /**
  * main_grow - do everything
  * @argc:
@@ -391,6 +409,7 @@ main_grow(int argc, char *argv[])
 			int old_rg_count;
 
 			compute_rgrp_layout(sdp, &sdp->rgtree, TRUE);
+			debug_print_rgrps(sdp, &sdp->rgtree);
 			print_info(sdp);
 			initialize_new_portion(sdp, &old_rg_count);
 			fix_rindex(sdp, rindex_fd, old_rg_count);
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index eeff47b..700b434 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -629,6 +629,7 @@ void main_mkfs(int argc, char *argv[])
 	/* Compute the resource group layouts */
 
 	compute_rgrp_layout(sdp, &sdp->rgtree, rgsize_specified);
+	debug_print_rgrps(sdp, &sdp->rgtree);
 
 	/* Generate a random uuid */
 	get_random_bytes(uuid, sizeof(uuid));
-- 
1.7.4.4



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

* [Cluster-devel] [PATCH 5/6] libgfs2: Clean up sb read/check functions
  2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
                   ` (3 preceding siblings ...)
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 4/6] libgfs2: Move some debug messages out into mkfs/fsck Steven Whitehouse
@ 2011-11-30 15:04 ` Steven Whitehouse
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 6/6] libgfs2: Remove some more log_xxx calls Steven Whitehouse
  2011-11-30 15:55 ` [Cluster-devel] libgfs2 cleanups Bob Peterson
  6 siblings, 0 replies; 8+ messages in thread
From: Steven Whitehouse @ 2011-11-30 15:04 UTC (permalink / raw)
  To: cluster-devel.redhat.com

There is no need to specify in advance whether we want to accept
gfs1 format super blocks or not. We can simply return that info
and let the caller decide if gfs1 format is acceptable or not.

We can also remove the message regarding the magic number of the
superblock, since the caller prints out a message anyway if
the check fails.

That removes some more of the log_ messages from libgfs2 as a
result.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 gfs2/edit/savemeta.c   |    4 ++--
 gfs2/fsck/initialize.c |    4 ++--
 gfs2/libgfs2/libgfs2.h |    4 ++--
 gfs2/libgfs2/super.c   |   23 ++++++-----------------
 gfs2/mkfs/main_grow.c  |    6 ++++--
 5 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 31af23d..9d790fe 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -670,7 +670,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 			fprintf(stderr, "Bad constants (1)\n");
 			exit(-1);
 		}
-		ret = read_sb(&sbd, 1);
+		ret = read_sb(&sbd);
 		if (ret < 0) {
 			slow = TRUE;
 			sbd.gfs1 = 0;
@@ -911,7 +911,7 @@ static int restore_data(int fd, gzFile *gzin_fd, int printblocksonly,
 			memcpy(&bufsb, savedata->buf, sizeof(bufsb));
 			gfs2_sb_in(&sbd.sd_sb, &dummy_bh);
 			sbd1 = (struct gfs_sb *)&sbd.sd_sb;
-			ret = check_sb(&sbd.sd_sb, 1);
+			ret = check_sb(&sbd.sd_sb);
 			if (ret < 0) {
 				fprintf(stderr,"Error: Invalid superblock data.\n");
 				return -1;
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index ba0df41..132d65a 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1227,12 +1227,12 @@ static int fill_super_block(struct gfs2_sbd *sdp)
 		log_crit(_("Bad constants (1)\n"));
 		exit(FSCK_ERROR);
 	}
-	ret = read_sb(sdp, 1);
+	ret = read_sb(sdp);
 	if (ret < 0) {
 		if (sb_repair(sdp) != 0)
 			return -1; /* unrepairable, so exit */
 		/* Now that we've tried to repair it, re-read it. */
-		ret = read_sb(sdp, 1);
+		ret = read_sb(sdp);
 		if (ret < 0)
 			return -1;
 	}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 04169bf..b24e555 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -722,8 +722,8 @@ extern int gfs2_next_rg_freemeta(struct rgrp_tree *rgd, uint64_t *block,
 				 int first);
 
 /* super.c */
-extern int check_sb(struct gfs2_sb *sb, int allow_gfs);
-extern int read_sb(struct gfs2_sbd *sdp, int allow_gfs);
+extern int check_sb(struct gfs2_sb *sb);
+extern int read_sb(struct gfs2_sbd *sdp);
 extern int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane);
 extern int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane);
 extern int write_sb(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 2f544ab..c9a9ad3 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -13,7 +13,6 @@
 
 /**
  * check_sb - Check superblock
- * @sdp: the filesystem
  * @sb: The superblock
  *
  * Checks the version code of the FS is one that we understand how to
@@ -22,25 +21,17 @@
  *
  * Returns: -1 on failure, 1 if this is gfs (gfs1), 2 if this is gfs2
  */
-int check_sb(struct gfs2_sb *sb, int allow_gfs)
+int check_sb(struct gfs2_sb *sb)
 {
 	if (sb->sb_header.mh_magic != GFS2_MAGIC ||
 	    sb->sb_header.mh_type != GFS2_METATYPE_SB) {
-		log_crit("Either the super block is corrupted, or this "
-				 "is not a GFS2 filesystem\n");
-		log_crit("Header magic: %X Header Type: %X\n",
-				  sb->sb_header.mh_magic,
-				  sb->sb_header.mh_type);
-		return -EINVAL;
+		errno = -EIO;
+		return -1;
 	}
 	if (sb->sb_fs_format == GFS_FORMAT_FS &&
 	    sb->sb_header.mh_format == GFS_FORMAT_SB &&
 	    sb->sb_multihost_format == GFS_FORMAT_MULTI) {
-		if (allow_gfs)
-			return 1;
-
-		log_crit("Old gfs1 file system detected.\n");
-		return -EINVAL;
+		return 1;
 	}
 	return 2;
 }
@@ -54,12 +45,10 @@ int check_sb(struct gfs2_sb *sb, int allow_gfs)
  * initializes various constants maintained in the super
  * block
  *
- * allow_gfs - passed in as 1 if we're allowed to accept gfs1 file systems
- *
  * Returns: 0 on success, -1 on failure
  * sdp->gfs1 will be set if this is gfs (gfs1)
  */
-int read_sb(struct gfs2_sbd *sdp, int allow_gfs)
+int read_sb(struct gfs2_sbd *sdp)
 {
 	struct gfs2_buffer_head *bh;
 	uint64_t space = 0;
@@ -70,7 +59,7 @@ int read_sb(struct gfs2_sbd *sdp, int allow_gfs)
 	gfs2_sb_in(&sdp->sd_sb, bh);
 	brelse(bh);
 
-	ret = check_sb(&sdp->sd_sb, allow_gfs);
+	ret = check_sb(&sdp->sd_sb);
 	if (ret < 0)
 		return ret;
 	if (ret == 1)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 1dc911a..5ed5a2d 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -358,9 +358,11 @@ main_grow(int argc, char *argv[])
 			perror(_("Bad constants (1)"));
 			exit(EXIT_FAILURE);
 		}
-		if (read_sb(sdp, 0) < 0)
+		if (read_sb(sdp) < 0)
 			die( _("gfs: Error reading superblock.\n"));
-
+		if (sdp->gfs1) {
+			die( _("cannot grow gfs1 filesystem\n"));
+		}
 		if (fix_device_geometry(sdp)) {
 			fprintf(stderr, _("Device is too small (%llu bytes)\n"),
 				(unsigned long long)sdp->device.length << GFS2_BASIC_BLOCK_SHIFT);
-- 
1.7.4.4



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

* [Cluster-devel] [PATCH 6/6] libgfs2: Remove some more log_xxx calls
  2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
                   ` (4 preceding siblings ...)
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 5/6] libgfs2: Clean up sb read/check functions Steven Whitehouse
@ 2011-11-30 15:04 ` Steven Whitehouse
  2011-11-30 15:55 ` [Cluster-devel] libgfs2 cleanups Bob Peterson
  6 siblings, 0 replies; 8+ messages in thread
From: Steven Whitehouse @ 2011-11-30 15:04 UTC (permalink / raw)
  To: cluster-devel.redhat.com

One is changed to fprintf, on a temporary basis - really it should
be removed. The others are removed and an error code returned.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 gfs2/libgfs2/structures.c |    2 +-
 gfs2/libgfs2/super.c      |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 8733444..0c22b01 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -511,7 +511,7 @@ static int __gfs2_next_rg_meta(struct rgrp_tree *rgd, uint64_t *block,
 	int i;
 
 	if (!first && (*block < rgd->ri.ri_data0)) {
-		log_err("next_rg_meta:  Start block is outside rgrp bounds.\n");
+		fprintf(stderr, "next_rg_meta:  Start block is outside rgrp bounds.\n");
 		exit(1);
 	}
 	for (i = 0; i < length; i++){
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index c9a9ad3..37152c2 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -96,7 +96,7 @@ int read_sb(struct gfs2_sbd *sdp)
 		sdp->sd_heightsize[x] = space;
 	}
 	if (x > GFS2_MAX_META_HEIGHT){
-		log_err("Bad max metadata height.\n");
+		errno = E2BIG;
 		return -1;
 	}
 
@@ -111,7 +111,7 @@ int read_sb(struct gfs2_sbd *sdp)
 	}
 	sdp->sd_max_jheight = x;
 	if(sdp->sd_max_jheight > GFS2_MAX_META_HEIGHT) {
-		log_err("Bad max jheight.\n");
+		errno = E2BIG;
 		return -1;
 	}
 	sdp->fssize = lseek(sdp->device_fd, 0, SEEK_END) / sdp->sd_sb.sb_bsize;
-- 
1.7.4.4



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

* [Cluster-devel] libgfs2 cleanups
  2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
                   ` (5 preceding siblings ...)
  2011-11-30 15:04 ` [Cluster-devel] [PATCH 6/6] libgfs2: Remove some more log_xxx calls Steven Whitehouse
@ 2011-11-30 15:55 ` Bob Peterson
  6 siblings, 0 replies; 8+ messages in thread
From: Bob Peterson @ 2011-11-30 15:55 UTC (permalink / raw)
  To: cluster-devel.redhat.com

----- Original Message -----
| Hi,
| 
| This patch set is working towards removing all the user interface
| code
| from libgfs2. There will be more patches to follow. Once all of the
| log_xxx() functions are moved out from libgfs2 then we can move the
| macros into the individual utilities which should more or less
| complete the job,
| 
| Steve.

Hi,

ACK on all six patches.

Regards,

Bob Peterson
Red Hat File Systems



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

end of thread, other threads:[~2011-11-30 15:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 1/6] libgfs2: Move generic_interrupt() into utils Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 2/6] libgfs2: Move gfs2_getch " Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 3/6] libgfs2: Prepare to remove log_xxx() macros from library Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 4/6] libgfs2: Move some debug messages out into mkfs/fsck Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 5/6] libgfs2: Clean up sb read/check functions Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 6/6] libgfs2: Remove some more log_xxx calls Steven Whitehouse
2011-11-30 15:55 ` [Cluster-devel] libgfs2 cleanups Bob Peterson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).