aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/support/debug.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2008-12-17 12:27:36 -0500
committerLachlan McIlroy <lachlan@redback.melbourne.sgi.com>2008-12-22 18:02:01 +1100
commitefc557570dc99b46e46a7be51c3c7402b485e829 (patch)
treefaba8c63e6bcf798ab76f7da1fcb035ece445700 /fs/xfs/support/debug.c
parent9f6c92b9cc2fd41d6c7b493be5637cc5b5659880 (diff)
downloadkernel_samsung_smdk4412-efc557570dc99b46e46a7be51c3c7402b485e829.tar.gz
kernel_samsung_smdk4412-efc557570dc99b46e46a7be51c3c7402b485e829.tar.bz2
kernel_samsung_smdk4412-efc557570dc99b46e46a7be51c3c7402b485e829.zip
[XFS] avoid memory allocations in xfs_fs_vcmn_err
xfs_fs_vcmn_err can be called under a spinlock, but does a sleeping memory allocation to create buffer for it's internal sprintf. Fortunately it's the only caller of icmn_err, so we can merge the two and have one single static buffer and spinlock protecting it. While we're at it make sure we proper __attribute__ format annotations so that the compiler can detect mismatched format strings. Reported-by: Alexander Beregalov <a.beregalov@gmail.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Eric Sandeen <sandeen@sandeen.net> Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Diffstat (limited to 'fs/xfs/support/debug.c')
-rw-r--r--fs/xfs/support/debug.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/fs/xfs/support/debug.c b/fs/xfs/support/debug.c
index 636104254cf..ae548296542 100644
--- a/fs/xfs/support/debug.c
+++ b/fs/xfs/support/debug.c
@@ -18,6 +18,13 @@
#include <xfs.h>
#include "debug.h"
+/* xfs_mount.h drags a lot of crap in, sorry.. */
+#include "xfs_sb.h"
+#include "xfs_inum.h"
+#include "xfs_ag.h"
+#include "xfs_dmapi.h"
+#include "xfs_mount.h"
+
static char message[1024]; /* keep it off the stack */
static DEFINE_SPINLOCK(xfs_err_lock);
@@ -55,22 +62,42 @@ cmn_err(register int level, char *fmt, ...)
}
void
-icmn_err(register int level, char *fmt, va_list ap)
+xfs_fs_vcmn_err(
+ int level,
+ struct xfs_mount *mp,
+ char *fmt,
+ va_list ap)
{
- ulong flags;
- int len;
+ unsigned long flags;
+ int len = 0;
level &= XFS_ERR_MASK;
- if(level > XFS_MAX_ERR_LEVEL)
+ if (level > XFS_MAX_ERR_LEVEL)
level = XFS_MAX_ERR_LEVEL;
+
spin_lock_irqsave(&xfs_err_lock,flags);
- len = vsnprintf(message, sizeof(message), fmt, ap);
+
+ if (mp) {
+ len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname);
+
+ /*
+ * Skip the printk if we can't print anything useful
+ * due to an over-long device name.
+ */
+ if (len >= sizeof(message))
+ goto out;
+ }
+
+ len = vsnprintf(message + len, sizeof(message) - len, fmt, ap);
if (len >= sizeof(message))
len = sizeof(message) - 1;
if (message[len-1] == '\n')
message[len-1] = 0;
+
printk("%s%s\n", err_level[level], message);
+ out:
spin_unlock_irqrestore(&xfs_err_lock,flags);
+
BUG_ON(level == CE_PANIC);
}