[PATCH 3/4] reiserfs: replace prepare_error_buf with reiserfs_snprintf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jeff Mahoney <jeffm@xxxxxxxx>

This patch cleans up the reiserfs print formatting code by getting
rid of the do_reiserfs_warning macro.  We push the va_list handling
and error_buf locking into the caller, which makes prepare_error_buf
more like a snprintf routine, so we'll call it that: reiserfs_snprintf.

Signed-off-by: Jeff Mahoney <jeffm@xxxxxxxx>
---
 fs/reiserfs/prints.c | 145 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 101 insertions(+), 44 deletions(-)

diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c
index a097ece64789..aead27d11e45 100644
--- a/fs/reiserfs/prints.c
+++ b/fs/reiserfs/prints.c
@@ -10,9 +10,6 @@
 
 #include <stdarg.h>
 
-static char error_buf[2048];
-static char fmt_buf[1024];
-
 static size_t snprintf_cpu_offset(char *buf, size_t size, struct cpu_key *key)
 {
 	u64 offset = cpu_key_k_offset(key);
@@ -225,60 +222,69 @@ static char *is_there_reiserfs_struct(char *fmt, int *what)
  * instead of
  * printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid,
  *         key->k_offset, key->k_uniqueness);
+ *
+ * in addition to usual conversion specifiers this accepts reiserfs
+ * specific conversion specifiers:
+ * %k to print little endian key,
+ * %K to print cpu key,
+ * %h to print item_head,
+ * %t to print directory entry
+ * %z to print block head (arg must be struct buffer_head *
+ * %b to print buffer_head
  */
-static DEFINE_SPINLOCK(error_lock);
-static void prepare_error_buf(const char *fmt, va_list args)
+static DEFINE_SPINLOCK(fmt_lock);
+static char fmt_buf[1024];
+static int reiserfs_snprintf(char *p, size_t left, const char *fmt,
+			     va_list *args)
 {
+	char *start = p;
 	char *fmt1 = fmt_buf;
 	char *k;
-	char *p = error_buf;
 	int what;
-	size_t left = sizeof(error_buf);
 	size_t len;
 
-	spin_lock(&error_lock);
-
+	spin_lock(&fmt_lock);
 	strncpy(fmt1, fmt, sizeof(fmt_buf));
 
 	while ((k = is_there_reiserfs_struct(fmt1, &what)) != NULL) {
 		*k = 0;
 
-		len = vsnprintf(p, left, fmt1, args);
+		len = vsnprintf(p, left, fmt1, *args);
 		p += len;
 		left -= len;
 
 		switch (what) {
 		case 'k':
 			len = snprintf_le_key(p, left,
-				     va_arg(args, struct reiserfs_key *));
+				     va_arg(*args, struct reiserfs_key *));
 			break;
 		case 'K':
 			len = snprintf_cpu_key(p, left,
-				     va_arg(args, struct cpu_key *));
+				     va_arg(*args, struct cpu_key *));
 			break;
 		case 'h':
 			len = snprintf_item_head(p, left,
-				     va_arg(args, struct item_head *));
+				     va_arg(*args, struct item_head *));
 			break;
 		case 't':
 			len = snprintf_direntry(p, left,
-				    va_arg(args, struct reiserfs_dir_entry *));
+				    va_arg(*args, struct reiserfs_dir_entry *));
 			break;
 		case 'y':
 			len = snprintf_disk_child(p, left,
-				    va_arg(args, struct disk_child *));
+				    va_arg(*args, struct disk_child *));
 			break;
 		case 'z':
 			len = snprintf_block_head(p, left,
-				    va_arg(args, struct buffer_head *));
+				    va_arg(*args, struct buffer_head *));
 			break;
 		case 'b':
 			len = snprintf_buffer_head(p, left,
-				    va_arg(args, struct buffer_head *));
+				    va_arg(*args, struct buffer_head *));
 			break;
 		case 'a':
 			len = snprintf_de_head(p, left,
-				    va_arg(args, struct reiserfs_de_head *));
+				    va_arg(*args, struct reiserfs_de_head *));
 			break;
 		}
 
@@ -286,33 +292,30 @@ static void prepare_error_buf(const char *fmt, va_list args)
 		left -= len;
 		fmt1 = k + 2;
 	}
-	vsnprintf(p, left, fmt1, args);
-	spin_unlock(&error_lock);
-}
 
-/*
- * in addition to usual conversion specifiers this accepts reiserfs
- * specific conversion specifiers:
- * %k to print little endian key,
- * %K to print cpu key,
- * %h to print item_head,
- * %t to print directory entry
- * %z to print block head (arg must be struct buffer_head *
- * %b to print buffer_head
- */
+	len = vsnprintf(p, left, fmt1, *args);
+	p += len;
+	left -= len;
+
+	spin_unlock(&fmt_lock);
 
-#define do_reiserfs_warning(fmt)\
-{\
-    va_list args;\
-    va_start( args, fmt );\
-    prepare_error_buf( fmt, args );\
-    va_end( args );\
+	return p - start;
 }
 
+static DEFINE_SPINLOCK(error_lock);
+static char error_buf[2048];
+
 void __reiserfs_warning(struct super_block *sb, const char *id,
 			 const char *function, const char *fmt, ...)
 {
-	do_reiserfs_warning(fmt);
+	va_list args;
+
+	va_start(args, fmt);
+
+	spin_lock(&error_lock);
+	reiserfs_snprintf(error_buf, sizeof(error_buf) - 1, fmt, &args);
+	spin_unlock(&error_lock);
+
 	if (sb)
 		pr_warn("REISERFS warning (device %s): %s%s%s: %s\n",
 			sb->s_id, id ? id : "", id ? " " : "",
@@ -320,34 +323,63 @@ void __reiserfs_warning(struct super_block *sb, const char *id,
 	else
 		pr_warn("REISERFS warning: %s%s%s: %s\n",
 		       id ? id : "", id ? " " : "", function, error_buf);
+
+	va_end(args);
 }
 
 /* No newline.. reiserfs_info calls can be followed by printk's */
 void reiserfs_info(struct super_block *sb, const char *fmt, ...)
 {
-	do_reiserfs_warning(fmt);
+	va_list args;
+
+	va_start(args, fmt);
+
+	spin_lock(&error_lock);
+	reiserfs_snprintf(error_buf, sizeof(error_buf) - 1, fmt, &args);
+	spin_unlock(&error_lock);
+
 	if (sb)
 		pr_notice("REISERFS (device %s): %s", sb->s_id, error_buf);
 	else
 		pr_notice("REISERFS %s:", error_buf);
+
+	va_end(args);
 }
 
 /* No newline.. reiserfs_printk calls can be followed by printk's */
 static void reiserfs_printk(const char *fmt, ...)
 {
-	do_reiserfs_warning(fmt);
+	va_list args;
+
+	va_start(args, fmt);
+
+	spin_lock(&error_lock);
+	reiserfs_snprintf(error_buf, sizeof(error_buf) - 1, fmt, &args);
+	spin_unlock(&error_lock);
+
 	printk(error_buf);
+
+	va_end(args);
 }
 
 void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
 {
 #ifdef CONFIG_REISERFS_CHECK
-	do_reiserfs_warning(fmt);
+	va_list args;
+
+	va_start(args, fmt);
+
+	spin_lock(&error_lock);
+	reiserfs_snprintf(error_buf, sizeof(error_buf) - 1, fmt, &args);
+	spin_unlock(&error_lock);
+
 	if (s)
 		pr_debug("REISERFS debug (device %s): %s\n",
 		       s->s_id, error_buf);
 	else
 		pr_debug("REISERFS debug: %s\n", error_buf);
+
+	va_end(args);
 #endif
 }
 
@@ -401,7 +433,13 @@ void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
 void __reiserfs_panic(struct super_block *sb, const char *id,
 		      const char *function, const char *fmt, ...)
 {
-	do_reiserfs_warning(fmt);
+	va_list args;
+
+	va_start(args, fmt);
+
+	spin_lock(&error_lock);
+	reiserfs_snprintf(error_buf, sizeof(error_buf) - 1, fmt, &args);
+	spin_unlock(&error_lock);
 
 #ifdef CONFIG_REISERFS_CHECK
 	dump_stack();
@@ -413,13 +451,22 @@ void __reiserfs_panic(struct super_block *sb, const char *id,
 	else
 		pr_crit("REISERFS panic: %s%s%s: %s\n",
 			id ? id : "", id ? " " : "", function, error_buf);
+
 	BUG();
+
+	va_end(args);
 }
 
 void __reiserfs_error(struct super_block *sb, const char *id,
 		      const char *function, const char *fmt, ...)
 {
-	do_reiserfs_warning(fmt);
+	va_list args;
+
+	va_start(args, fmt);
+
+	spin_lock(&error_lock);
+	reiserfs_snprintf(error_buf, sizeof(error_buf) - 1, fmt, &args);
+	spin_unlock(&error_lock);
 
 	BUG_ON(sb == NULL);
 
@@ -439,11 +486,19 @@ void __reiserfs_error(struct super_block *sb, const char *id,
 	reiserfs_info(sb, "Remounting filesystem read-only\n");
 	sb->s_flags |= SB_RDONLY;
 	reiserfs_abort_journal(sb, -EIO);
+
+	va_end(args);
 }
 
 void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
 {
-	do_reiserfs_warning(fmt);
+	va_list args;
+
+	va_start(args, fmt);
+
+	spin_lock(&error_lock);
+	reiserfs_snprintf(error_buf, sizeof(error_buf) - 1, fmt, &args);
+	spin_unlock(&error_lock);
 
 	if (reiserfs_error_panic(sb)) {
 		panic("REISERFS panic (device %s): %s\n", sb->s_id, error_buf);
@@ -456,6 +511,8 @@ void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
 
 	sb->s_flags |= SB_RDONLY;
 	reiserfs_abort_journal(sb, errno);
+
+	va_end(args);
 }
 
 /*
-- 
2.12.3

--
To unsubscribe from this list: send the line "unsubscribe reiserfs-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux File System Development]     [Linux BTRFS]     [Linux NFS]     [Linux Filesystems]     [Ext4 Filesystem]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Resources]

  Powered by Linux