diff options
| author | Christoph Hellwig <hch@infradead.org> | 2008-12-17 12:27:36 -0500 |
|---|---|---|
| committer | Lachlan McIlroy <lachlan@redback.melbourne.sgi.com> | 2008-12-22 02:02:01 -0500 |
| commit | efc557570dc99b46e46a7be51c3c7402b485e829 (patch) | |
| tree | faba8c63e6bcf798ab76f7da1fcb035ece445700 | |
| parent | 9f6c92b9cc2fd41d6c7b493be5637cc5b5659880 (diff) | |
[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>
| -rw-r--r-- | fs/xfs/support/debug.c | 37 | ||||
| -rw-r--r-- | fs/xfs/support/debug.h | 2 | ||||
| -rw-r--r-- | fs/xfs/xfs_error.c | 15 | ||||
| -rw-r--r-- | fs/xfs/xfs_error.h | 12 |
4 files changed, 40 insertions, 26 deletions
diff --git a/fs/xfs/support/debug.c b/fs/xfs/support/debug.c index 636104254cfd..ae5482965424 100644 --- a/fs/xfs/support/debug.c +++ b/fs/xfs/support/debug.c | |||
| @@ -18,6 +18,13 @@ | |||
| 18 | #include <xfs.h> | 18 | #include <xfs.h> |
| 19 | #include "debug.h" | 19 | #include "debug.h" |
| 20 | 20 | ||
| 21 | /* xfs_mount.h drags a lot of crap in, sorry.. */ | ||
| 22 | #include "xfs_sb.h" | ||
| 23 | #include "xfs_inum.h" | ||
| 24 | #include "xfs_ag.h" | ||
| 25 | #include "xfs_dmapi.h" | ||
| 26 | #include "xfs_mount.h" | ||
| 27 | |||
| 21 | static char message[1024]; /* keep it off the stack */ | 28 | static char message[1024]; /* keep it off the stack */ |
| 22 | static DEFINE_SPINLOCK(xfs_err_lock); | 29 | static DEFINE_SPINLOCK(xfs_err_lock); |
| 23 | 30 | ||
| @@ -55,22 +62,42 @@ cmn_err(register int level, char *fmt, ...) | |||
| 55 | } | 62 | } |
| 56 | 63 | ||
| 57 | void | 64 | void |
| 58 | icmn_err(register int level, char *fmt, va_list ap) | 65 | xfs_fs_vcmn_err( |
| 66 | int level, | ||
| 67 | struct xfs_mount *mp, | ||
| 68 | char *fmt, | ||
| 69 | va_list ap) | ||
| 59 | { | 70 | { |
| 60 | ulong flags; | 71 | unsigned long flags; |
| 61 | int len; | 72 | int len = 0; |
| 62 | 73 | ||
| 63 | level &= XFS_ERR_MASK; | 74 | level &= XFS_ERR_MASK; |
| 64 | if(level > XFS_MAX_ERR_LEVEL) | 75 | if (level > XFS_MAX_ERR_LEVEL) |
| 65 | level = XFS_MAX_ERR_LEVEL; | 76 | level = XFS_MAX_ERR_LEVEL; |
| 77 | |||
| 66 | spin_lock_irqsave(&xfs_err_lock,flags); | 78 | spin_lock_irqsave(&xfs_err_lock,flags); |
| 67 | len = vsnprintf(message, sizeof(message), fmt, ap); | 79 | |
| 80 | if (mp) { | ||
| 81 | len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname); | ||
| 82 | |||
| 83 | /* | ||
| 84 | * Skip the printk if we can't print anything useful | ||
| 85 | * due to an over-long device name. | ||
| 86 | */ | ||
| 87 | if (len >= sizeof(message)) | ||
| 88 | goto out; | ||
| 89 | } | ||
| 90 | |||
| 91 | len = vsnprintf(message + len, sizeof(message) - len, fmt, ap); | ||
| 68 | if (len >= sizeof(message)) | 92 | if (len >= sizeof(message)) |
| 69 | len = sizeof(message) - 1; | 93 | len = sizeof(message) - 1; |
| 70 | if (message[len-1] == '\n') | 94 | if (message[len-1] == '\n') |
| 71 | message[len-1] = 0; | 95 | message[len-1] = 0; |
| 96 | |||
| 72 | printk("%s%s\n", err_level[level], message); | 97 | printk("%s%s\n", err_level[level], message); |
| 98 | out: | ||
| 73 | spin_unlock_irqrestore(&xfs_err_lock,flags); | 99 | spin_unlock_irqrestore(&xfs_err_lock,flags); |
| 100 | |||
| 74 | BUG_ON(level == CE_PANIC); | 101 | BUG_ON(level == CE_PANIC); |
| 75 | } | 102 | } |
| 76 | 103 | ||
diff --git a/fs/xfs/support/debug.h b/fs/xfs/support/debug.h index 75845f950814..6f4fd37c67af 100644 --- a/fs/xfs/support/debug.h +++ b/fs/xfs/support/debug.h | |||
| @@ -27,8 +27,6 @@ | |||
| 27 | #define CE_ALERT 1 /* alert */ | 27 | #define CE_ALERT 1 /* alert */ |
| 28 | #define CE_PANIC 0 /* panic */ | 28 | #define CE_PANIC 0 /* panic */ |
| 29 | 29 | ||
| 30 | extern void icmn_err(int, char *, va_list) | ||
| 31 | __attribute__ ((format (printf, 2, 0))); | ||
| 32 | extern void cmn_err(int, char *, ...) | 30 | extern void cmn_err(int, char *, ...) |
| 33 | __attribute__ ((format (printf, 2, 3))); | 31 | __attribute__ ((format (printf, 2, 3))); |
| 34 | extern void assfail(char *expr, char *f, int l); | 32 | extern void assfail(char *expr, char *f, int l); |
diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index f227ecd1a294..92d5cd5bf4f2 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c | |||
| @@ -153,21 +153,6 @@ xfs_errortag_clearall(xfs_mount_t *mp, int loud) | |||
| 153 | } | 153 | } |
| 154 | #endif /* DEBUG */ | 154 | #endif /* DEBUG */ |
| 155 | 155 | ||
| 156 | static void | ||
| 157 | xfs_fs_vcmn_err(int level, xfs_mount_t *mp, char *fmt, va_list ap) | ||
| 158 | { | ||
| 159 | if (mp != NULL) { | ||
| 160 | char *newfmt; | ||
| 161 | int len = 16 + mp->m_fsname_len + strlen(fmt); | ||
| 162 | |||
| 163 | newfmt = kmem_alloc(len, KM_SLEEP); | ||
| 164 | sprintf(newfmt, "Filesystem \"%s\": %s", mp->m_fsname, fmt); | ||
| 165 | icmn_err(level, newfmt, ap); | ||
| 166 | kmem_free(newfmt); | ||
| 167 | } else { | ||
| 168 | icmn_err(level, fmt, ap); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | 156 | ||
| 172 | void | 157 | void |
| 173 | xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...) | 158 | xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...) |
diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h index 11543f10b0c6..0c93051c4651 100644 --- a/fs/xfs/xfs_error.h +++ b/fs/xfs/xfs_error.h | |||
| @@ -159,11 +159,15 @@ extern int xfs_errortag_clearall(xfs_mount_t *mp, int loud); | |||
| 159 | #define XFS_PTAG_FSBLOCK_ZERO 0x00000080 | 159 | #define XFS_PTAG_FSBLOCK_ZERO 0x00000080 |
| 160 | 160 | ||
| 161 | struct xfs_mount; | 161 | struct xfs_mount; |
| 162 | /* PRINTFLIKE4 */ | 162 | |
| 163 | extern void xfs_fs_vcmn_err(int level, struct xfs_mount *mp, | ||
| 164 | char *fmt, va_list ap) | ||
| 165 | __attribute__ ((format (printf, 3, 0))); | ||
| 163 | extern void xfs_cmn_err(int panic_tag, int level, struct xfs_mount *mp, | 166 | extern void xfs_cmn_err(int panic_tag, int level, struct xfs_mount *mp, |
| 164 | char *fmt, ...); | 167 | char *fmt, ...) |
| 165 | /* PRINTFLIKE3 */ | 168 | __attribute__ ((format (printf, 4, 5))); |
| 166 | extern void xfs_fs_cmn_err(int level, struct xfs_mount *mp, char *fmt, ...); | 169 | extern void xfs_fs_cmn_err(int level, struct xfs_mount *mp, char *fmt, ...) |
| 170 | __attribute__ ((format (printf, 3, 4))); | ||
| 167 | 171 | ||
| 168 | extern void xfs_hex_dump(void *p, int length); | 172 | extern void xfs_hex_dump(void *p, int length); |
| 169 | 173 | ||
