ext4: Pass line numbers to ext4_error() and friends

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Theodore Ts'o 2010-07-27 11:56:40 -04:00
parent 60fd4da34d
commit c398eda0e4
8 changed files with 98 additions and 80 deletions

View File

@ -84,11 +84,10 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
error_msg = "inode out of bounds"; error_msg = "inode out of bounds";
if (error_msg != NULL) if (error_msg != NULL)
ext4_error_inode(function, dir, ext4_error_inode(dir, function, line, bh->b_blocknr,
"bad entry in directory: %s - block=%llu" "bad entry in directory: %s - "
"offset=%u(%u), inode=%u, rec_len=%d, name_len=%d", "offset=%u(%u), inode=%u, rec_len=%d, name_len=%d",
error_msg, (unsigned long long) bh->b_blocknr, error_msg, (unsigned) (offset%bh->b_size), offset,
(unsigned) (offset%bh->b_size), offset,
le32_to_cpu(de->inode), le32_to_cpu(de->inode),
rlen, de->name_len); rlen, de->name_len);
return error_msg == NULL ? 1 : 0; return error_msg == NULL ? 1 : 0;

View File

@ -57,10 +57,13 @@
#endif #endif
#define EXT4_ERROR_INODE(inode, fmt, a...) \ #define EXT4_ERROR_INODE(inode, fmt, a...) \
ext4_error_inode(__func__, (inode), (fmt), ## a) ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a)
#define EXT4_ERROR_INODE_BLOCK(inode, block, fmt, a...) \
ext4_error_inode((inode), __func__, __LINE__, (block), (fmt), ## a)
#define EXT4_ERROR_FILE(file, fmt, a...) \ #define EXT4_ERROR_FILE(file, fmt, a...) \
ext4_error_file(__func__, (file), (fmt), ## a) ext4_error_file(__func__, __LINE__, (file), (fmt), ## a)
/* data type for block offset of block group */ /* data type for block offset of block group */
typedef int ext4_grpblk_t; typedef int ext4_grpblk_t;
@ -1623,22 +1626,29 @@ extern int ext4_group_extend(struct super_block *sb,
ext4_fsblk_t n_blocks_count); ext4_fsblk_t n_blocks_count);
/* super.c */ /* super.c */
extern void __ext4_error(struct super_block *, const char *, const char *, ...) extern void __ext4_error(struct super_block *, const char *, unsigned int,
__attribute__ ((format (printf, 3, 4))); const char *, ...)
#define ext4_error(sb, message...) __ext4_error(sb, __func__, ## message) __attribute__ ((format (printf, 4, 5)));
extern void ext4_error_inode(const char *, struct inode *, const char *, ...) #define ext4_error(sb, message...) __ext4_error(sb, __func__, \
__attribute__ ((format (printf, 3, 4))); __LINE__, ## message)
extern void ext4_error_file(const char *, struct file *, const char *, ...) extern void ext4_error_inode(struct inode *, const char *, unsigned int,
__attribute__ ((format (printf, 3, 4))); ext4_fsblk_t, const char *, ...)
extern void __ext4_std_error(struct super_block *, const char *, int); __attribute__ ((format (printf, 5, 6)));
extern void __ext4_abort(struct super_block *, const char *, const char *, ...) extern void ext4_error_file(struct file *, const char *, unsigned int,
__attribute__ ((format (printf, 3, 4))); const char *, ...)
__attribute__ ((format (printf, 4, 5)));
extern void __ext4_std_error(struct super_block *, const char *,
unsigned int, int);
extern void __ext4_abort(struct super_block *, const char *, unsigned int,
const char *, ...)
__attribute__ ((format (printf, 4, 5)));
#define ext4_abort(sb, message...) __ext4_abort(sb, __func__, \ #define ext4_abort(sb, message...) __ext4_abort(sb, __func__, \
## message) __LINE__, ## message)
extern void __ext4_warning(struct super_block *, const char *, extern void __ext4_warning(struct super_block *, const char *, unsigned int,
const char *, ...) const char *, ...)
__attribute__ ((format (printf, 3, 4))); __attribute__ ((format (printf, 4, 5)));
#define ext4_warning(sb, message...) __ext4_warning(sb, __func__, ## message) #define ext4_warning(sb, message...) __ext4_warning(sb, __func__, \
__LINE__, ## message)
extern void ext4_msg(struct super_block *, const char *, const char *, ...) extern void ext4_msg(struct super_block *, const char *, const char *, ...)
__attribute__ ((format (printf, 3, 4))); __attribute__ ((format (printf, 3, 4)));
extern void __ext4_grp_locked_error(const char *, unsigned int, \ extern void __ext4_grp_locked_error(const char *, unsigned int, \
@ -1781,7 +1791,7 @@ static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
#define ext4_std_error(sb, errno) \ #define ext4_std_error(sb, errno) \
do { \ do { \
if ((errno)) \ if ((errno)) \
__ext4_std_error((sb), __func__, (errno)); \ __ext4_std_error((sb), __func__, __LINE__, (errno)); \
} while (0) } while (0)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP

View File

@ -94,8 +94,8 @@ int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
if (err) { if (err) {
ext4_journal_abort_handle(where, line, __func__, ext4_journal_abort_handle(where, line, __func__,
bh, handle, err); bh, handle, err);
__ext4_abort(inode->i_sb, where, __ext4_abort(inode->i_sb, where, line,
"error %d when attempting revoke", err); "error %d when attempting revoke", err);
} }
BUFFER_TRACE(bh, "exit"); BUFFER_TRACE(bh, "exit");
return err; return err;
@ -134,11 +134,9 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
if (inode && inode_needs_sync(inode)) { if (inode && inode_needs_sync(inode)) {
sync_dirty_buffer(bh); sync_dirty_buffer(bh);
if (buffer_req(bh) && !buffer_uptodate(bh)) { if (buffer_req(bh) && !buffer_uptodate(bh)) {
ext4_error(inode->i_sb, ext4_error_inode(inode, where, line,
"IO error syncing inode, " bh->b_blocknr,
"inode=%lu, block=%llu", "IO error syncing itable block");
inode->i_ino,
(unsigned long long) bh->b_blocknr);
err = -EIO; err = -EIO;
} }
} }

View File

@ -162,7 +162,7 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line,
__ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb)) __ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb))
handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks); handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks);
int __ext4_journal_stop(const char *where, handle_t *handle); int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle);
#define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096) #define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096)
@ -215,7 +215,7 @@ static inline handle_t *ext4_journal_start(struct inode *inode, int nblocks)
} }
#define ext4_journal_stop(handle) \ #define ext4_journal_stop(handle) \
__ext4_journal_stop(__func__, (handle)) __ext4_journal_stop(__func__, __LINE__, (handle))
static inline handle_t *ext4_journal_current_handle(void) static inline handle_t *ext4_journal_current_handle(void)
{ {

View File

@ -401,9 +401,9 @@ static int ext4_valid_extent_entries(struct inode *inode,
return 1; return 1;
} }
static int __ext4_ext_check(const char *function, struct inode *inode, static int __ext4_ext_check(const char *function, unsigned int line,
struct ext4_extent_header *eh, struct inode *inode, struct ext4_extent_header *eh,
int depth) int depth)
{ {
const char *error_msg; const char *error_msg;
int max = 0; int max = 0;
@ -436,7 +436,7 @@ static int __ext4_ext_check(const char *function, struct inode *inode,
return 0; return 0;
corrupted: corrupted:
ext4_error_inode(function, inode, ext4_error_inode(inode, function, line, 0,
"bad header/extent: %s - magic %x, " "bad header/extent: %s - magic %x, "
"entries %u, max %u(%u), depth %u(%u)", "entries %u, max %u(%u), depth %u(%u)",
error_msg, le16_to_cpu(eh->eh_magic), error_msg, le16_to_cpu(eh->eh_magic),
@ -447,7 +447,7 @@ corrupted:
} }
#define ext4_ext_check(inode, eh, depth) \ #define ext4_ext_check(inode, eh, depth) \
__ext4_ext_check(__func__, inode, eh, depth) __ext4_ext_check(__func__, __LINE__, inode, eh, depth)
int ext4_ext_check_inode(struct inode *inode) int ext4_ext_check_inode(struct inode *inode)
{ {

View File

@ -337,7 +337,8 @@ static int ext4_block_to_path(struct inode *inode,
return n; return n;
} }
static int __ext4_check_blockref(const char *function, struct inode *inode, static int __ext4_check_blockref(const char *function, unsigned int line,
struct inode *inode,
__le32 *p, unsigned int max) __le32 *p, unsigned int max)
{ {
__le32 *bref = p; __le32 *bref = p;
@ -348,8 +349,8 @@ static int __ext4_check_blockref(const char *function, struct inode *inode,
if (blk && if (blk &&
unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb), unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb),
blk, 1))) { blk, 1))) {
ext4_error_inode(function, inode, ext4_error_inode(inode, function, line, blk,
"invalid block reference %u", blk); "invalid block");
return -EIO; return -EIO;
} }
} }
@ -358,11 +359,13 @@ static int __ext4_check_blockref(const char *function, struct inode *inode,
#define ext4_check_indirect_blockref(inode, bh) \ #define ext4_check_indirect_blockref(inode, bh) \
__ext4_check_blockref(__func__, inode, (__le32 *)(bh)->b_data, \ __ext4_check_blockref(__func__, __LINE__, inode, \
(__le32 *)(bh)->b_data, \
EXT4_ADDR_PER_BLOCK((inode)->i_sb)) EXT4_ADDR_PER_BLOCK((inode)->i_sb))
#define ext4_check_inode_blockref(inode) \ #define ext4_check_inode_blockref(inode) \
__ext4_check_blockref(__func__, inode, EXT4_I(inode)->i_data, \ __ext4_check_blockref(__func__, __LINE__, inode, \
EXT4_I(inode)->i_data, \
EXT4_NDIR_BLOCKS) EXT4_NDIR_BLOCKS)
/** /**
@ -1129,21 +1132,22 @@ void ext4_da_update_reserve_space(struct inode *inode,
} }
static int __check_block_validity(struct inode *inode, const char *func, static int __check_block_validity(struct inode *inode, const char *func,
struct ext4_map_blocks *map) unsigned int line,
struct ext4_map_blocks *map)
{ {
if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk, if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk,
map->m_len)) { map->m_len)) {
ext4_error_inode(func, inode, ext4_error_inode(inode, func, line, map->m_pblk,
"lblock %lu mapped to illegal pblock %llu " "lblock %lu mapped to illegal pblock "
"(length %d)", (unsigned long) map->m_lblk, "(length %d)", (unsigned long) map->m_lblk,
map->m_pblk, map->m_len); map->m_len);
return -EIO; return -EIO;
} }
return 0; return 0;
} }
#define check_block_validity(inode, map) \ #define check_block_validity(inode, map) \
__check_block_validity((inode), __func__, (map)) __check_block_validity((inode), __func__, __LINE__, (map))
/* /*
* Return the number of contiguous dirty pages in a given inode * Return the number of contiguous dirty pages in a given inode
@ -4471,9 +4475,8 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
* (should be rare). * (should be rare).
*/ */
if (!bh) { if (!bh) {
EXT4_ERROR_INODE(inode, EXT4_ERROR_INODE_BLOCK(inode, nr,
"Read failure block=%llu", "Read failure");
(unsigned long long) nr);
continue; continue;
} }
@ -4788,8 +4791,8 @@ static int __ext4_get_inode_loc(struct inode *inode,
bh = sb_getblk(sb, block); bh = sb_getblk(sb, block);
if (!bh) { if (!bh) {
EXT4_ERROR_INODE(inode, "unable to read inode block - " EXT4_ERROR_INODE_BLOCK(inode, block,
"block %llu", block); "unable to read itable block");
return -EIO; return -EIO;
} }
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
@ -4887,8 +4890,8 @@ make_io:
submit_bh(READ_META, bh); submit_bh(READ_META, bh);
wait_on_buffer(bh); wait_on_buffer(bh);
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
EXT4_ERROR_INODE(inode, "unable to read inode " EXT4_ERROR_INODE_BLOCK(inode, block,
"block %llu", block); "unable to read itable block");
brelse(bh); brelse(bh);
return -EIO; return -EIO;
} }
@ -5389,9 +5392,8 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
if (wbc->sync_mode == WB_SYNC_ALL) if (wbc->sync_mode == WB_SYNC_ALL)
sync_dirty_buffer(iloc.bh); sync_dirty_buffer(iloc.bh);
if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) { if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
EXT4_ERROR_INODE(inode, EXT4_ERROR_INODE_BLOCK(inode, iloc.bh->b_blocknr,
"IO error syncing inode (block=%llu)", "IO error syncing inode");
(unsigned long long) iloc.bh->b_blocknr);
err = -EIO; err = -EIO;
} }
brelse(iloc.bh); brelse(iloc.bh);

View File

@ -148,17 +148,17 @@ mext_next_extent(struct inode *inode, struct ext4_ext_path *path,
*/ */
static int static int
mext_check_null_inode(struct inode *inode1, struct inode *inode2, mext_check_null_inode(struct inode *inode1, struct inode *inode2,
const char *function) const char *function, unsigned int line)
{ {
int ret = 0; int ret = 0;
if (inode1 == NULL) { if (inode1 == NULL) {
__ext4_error(inode2->i_sb, function, __ext4_error(inode2->i_sb, function, line,
"Both inodes should not be NULL: " "Both inodes should not be NULL: "
"inode1 NULL inode2 %lu", inode2->i_ino); "inode1 NULL inode2 %lu", inode2->i_ino);
ret = -EIO; ret = -EIO;
} else if (inode2 == NULL) { } else if (inode2 == NULL) {
__ext4_error(inode1->i_sb, function, __ext4_error(inode1->i_sb, function, line,
"Both inodes should not be NULL: " "Both inodes should not be NULL: "
"inode1 %lu inode2 NULL", inode1->i_ino); "inode1 %lu inode2 NULL", inode1->i_ino);
ret = -EIO; ret = -EIO;
@ -1084,7 +1084,7 @@ mext_inode_double_lock(struct inode *inode1, struct inode *inode2)
BUG_ON(inode1 == NULL && inode2 == NULL); BUG_ON(inode1 == NULL && inode2 == NULL);
ret = mext_check_null_inode(inode1, inode2, __func__); ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__);
if (ret < 0) if (ret < 0)
goto out; goto out;
@ -1121,7 +1121,7 @@ mext_inode_double_unlock(struct inode *inode1, struct inode *inode2)
BUG_ON(inode1 == NULL && inode2 == NULL); BUG_ON(inode1 == NULL && inode2 == NULL);
ret = mext_check_null_inode(inode1, inode2, __func__); ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__);
if (ret < 0) if (ret < 0)
goto out; goto out;

View File

@ -262,7 +262,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
* that sync() will call the filesystem's write_super callback if * that sync() will call the filesystem's write_super callback if
* appropriate. * appropriate.
*/ */
int __ext4_journal_stop(const char *where, handle_t *handle) int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
{ {
struct super_block *sb; struct super_block *sb;
int err; int err;
@ -279,7 +279,7 @@ int __ext4_journal_stop(const char *where, handle_t *handle)
if (!err) if (!err)
err = rc; err = rc;
if (err) if (err)
__ext4_std_error(sb, where, err); __ext4_std_error(sb, where, line, err);
return err; return err;
} }
@ -350,12 +350,13 @@ static void ext4_handle_error(struct super_block *sb)
} }
void __ext4_error(struct super_block *sb, const char *function, void __ext4_error(struct super_block *sb, const char *function,
const char *fmt, ...) unsigned int line, const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: ",
sb->s_id, function, line, current->comm);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
@ -363,14 +364,18 @@ void __ext4_error(struct super_block *sb, const char *function,
ext4_handle_error(sb); ext4_handle_error(sb);
} }
void ext4_error_inode(const char *function, struct inode *inode, void ext4_error_inode(struct inode *inode, const char *function,
unsigned int line, ext4_fsblk_t block,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printk(KERN_CRIT "EXT4-fs error (device %s): %s: inode #%lu: (comm %s) ", printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: inode #%lu: ",
inode->i_sb->s_id, function, inode->i_ino, current->comm); inode->i_sb->s_id, function, line, inode->i_ino);
if (block)
printk("block %llu: ", block);
printk("comm %s: ", current->comm);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
@ -378,8 +383,8 @@ void ext4_error_inode(const char *function, struct inode *inode,
ext4_handle_error(inode->i_sb); ext4_handle_error(inode->i_sb);
} }
void ext4_error_file(const char *function, struct file *file, void ext4_error_file(struct file *file, const char *function,
const char *fmt, ...) unsigned int line, const char *fmt, ...)
{ {
va_list args; va_list args;
struct inode *inode = file->f_dentry->d_inode; struct inode *inode = file->f_dentry->d_inode;
@ -390,8 +395,10 @@ void ext4_error_file(const char *function, struct file *file,
if (!path) if (!path)
path = "(unknown)"; path = "(unknown)";
printk(KERN_CRIT printk(KERN_CRIT
"EXT4-fs error (device %s): %s: inode #%lu (comm %s path %s): ", "EXT4-fs error (device %s): %s:%d: inode #%lu "
inode->i_sb->s_id, function, inode->i_ino, current->comm, path); "(comm %s path %s): ",
inode->i_sb->s_id, function, line, inode->i_ino,
current->comm, path);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
@ -436,7 +443,8 @@ static const char *ext4_decode_error(struct super_block *sb, int errno,
/* __ext4_std_error decodes expected errors from journaling functions /* __ext4_std_error decodes expected errors from journaling functions
* automatically and invokes the appropriate error response. */ * automatically and invokes the appropriate error response. */
void __ext4_std_error(struct super_block *sb, const char *function, int errno) void __ext4_std_error(struct super_block *sb, const char *function,
unsigned int line, int errno)
{ {
char nbuf[16]; char nbuf[16];
const char *errstr; const char *errstr;
@ -449,8 +457,8 @@ void __ext4_std_error(struct super_block *sb, const char *function, int errno)
return; return;
errstr = ext4_decode_error(sb, errno, nbuf); errstr = ext4_decode_error(sb, errno, nbuf);
printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n", printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
sb->s_id, function, errstr); sb->s_id, function, line, errstr);
ext4_handle_error(sb); ext4_handle_error(sb);
} }
@ -466,12 +474,13 @@ void __ext4_std_error(struct super_block *sb, const char *function, int errno)
*/ */
void __ext4_abort(struct super_block *sb, const char *function, void __ext4_abort(struct super_block *sb, const char *function,
const char *fmt, ...) unsigned int line, const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: ", sb->s_id,
function, line);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
@ -503,13 +512,13 @@ void ext4_msg (struct super_block * sb, const char *prefix,
} }
void __ext4_warning(struct super_block *sb, const char *function, void __ext4_warning(struct super_block *sb, const char *function,
const char *fmt, ...) unsigned int line, const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ", printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: ",
sb->s_id, function); sb->s_id, function, line);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);