Skip to content

Commit c398eda

Browse files
committed
ext4: Pass line numbers to ext4_error() and friends
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 60fd4da commit c398eda

8 files changed

Lines changed: 98 additions & 80 deletions

File tree

‎fs/ext4/dir.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
8484
error_msg = "inode out of bounds";
8585

8686
if (error_msg != NULL)
87-
ext4_error_inode(function, dir,
88-
"bad entry in directory: %s - block=%llu"
87+
ext4_error_inode(dir, function, line, bh->b_blocknr,
88+
"bad entry in directory: %s - "
8989
"offset=%u(%u), inode=%u, rec_len=%d, name_len=%d",
90-
error_msg, (unsigned long long) bh->b_blocknr,
91-
(unsigned) (offset%bh->b_size), offset,
90+
error_msg, (unsigned) (offset%bh->b_size), offset,
9291
le32_to_cpu(de->inode),
9392
rlen, de->name_len);
9493
return error_msg == NULL ? 1 : 0;

‎fs/ext4/ext4.h‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@
5757
#endif
5858

5959
#define EXT4_ERROR_INODE(inode, fmt, a...) \
60-
ext4_error_inode(__func__, (inode), (fmt), ## a)
60+
ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a)
61+
62+
#define EXT4_ERROR_INODE_BLOCK(inode, block, fmt, a...) \
63+
ext4_error_inode((inode), __func__, __LINE__, (block), (fmt), ## a)
6164

6265
#define EXT4_ERROR_FILE(file, fmt, a...) \
63-
ext4_error_file(__func__, (file), (fmt), ## a)
66+
ext4_error_file(__func__, __LINE__, (file), (fmt), ## a)
6467

6568
/* data type for block offset of block group */
6669
typedef int ext4_grpblk_t;
@@ -1623,22 +1626,29 @@ extern int ext4_group_extend(struct super_block *sb,
16231626
ext4_fsblk_t n_blocks_count);
16241627

16251628
/* super.c */
1626-
extern void __ext4_error(struct super_block *, const char *, const char *, ...)
1627-
__attribute__ ((format (printf, 3, 4)));
1628-
#define ext4_error(sb, message...) __ext4_error(sb, __func__, ## message)
1629-
extern void ext4_error_inode(const char *, struct inode *, const char *, ...)
1630-
__attribute__ ((format (printf, 3, 4)));
1631-
extern void ext4_error_file(const char *, struct file *, const char *, ...)
1632-
__attribute__ ((format (printf, 3, 4)));
1633-
extern void __ext4_std_error(struct super_block *, const char *, int);
1634-
extern void __ext4_abort(struct super_block *, const char *, const char *, ...)
1635-
__attribute__ ((format (printf, 3, 4)));
1629+
extern void __ext4_error(struct super_block *, const char *, unsigned int,
1630+
const char *, ...)
1631+
__attribute__ ((format (printf, 4, 5)));
1632+
#define ext4_error(sb, message...) __ext4_error(sb, __func__, \
1633+
__LINE__, ## message)
1634+
extern void ext4_error_inode(struct inode *, const char *, unsigned int,
1635+
ext4_fsblk_t, const char *, ...)
1636+
__attribute__ ((format (printf, 5, 6)));
1637+
extern void ext4_error_file(struct file *, const char *, unsigned int,
1638+
const char *, ...)
1639+
__attribute__ ((format (printf, 4, 5)));
1640+
extern void __ext4_std_error(struct super_block *, const char *,
1641+
unsigned int, int);
1642+
extern void __ext4_abort(struct super_block *, const char *, unsigned int,
1643+
const char *, ...)
1644+
__attribute__ ((format (printf, 4, 5)));
16361645
#define ext4_abort(sb, message...) __ext4_abort(sb, __func__, \
1637-
## message)
1638-
extern void __ext4_warning(struct super_block *, const char *,
1646+
__LINE__, ## message)
1647+
extern void __ext4_warning(struct super_block *, const char *, unsigned int,
16391648
const char *, ...)
1640-
__attribute__ ((format (printf, 3, 4)));
1641-
#define ext4_warning(sb, message...) __ext4_warning(sb, __func__, ## message)
1649+
__attribute__ ((format (printf, 4, 5)));
1650+
#define ext4_warning(sb, message...) __ext4_warning(sb, __func__, \
1651+
__LINE__, ## message)
16421652
extern void ext4_msg(struct super_block *, const char *, const char *, ...)
16431653
__attribute__ ((format (printf, 3, 4)));
16441654
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)
17811791
#define ext4_std_error(sb, errno) \
17821792
do { \
17831793
if ((errno)) \
1784-
__ext4_std_error((sb), __func__, (errno)); \
1794+
__ext4_std_error((sb), __func__, __LINE__, (errno)); \
17851795
} while (0)
17861796

17871797
#ifdef CONFIG_SMP

‎fs/ext4/ext4_jbd2.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
9494
if (err) {
9595
ext4_journal_abort_handle(where, line, __func__,
9696
bh, handle, err);
97-
__ext4_abort(inode->i_sb, where,
98-
"error %d when attempting revoke", err);
97+
__ext4_abort(inode->i_sb, where, line,
98+
"error %d when attempting revoke", err);
9999
}
100100
BUFFER_TRACE(bh, "exit");
101101
return err;
@@ -134,11 +134,9 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
134134
if (inode && inode_needs_sync(inode)) {
135135
sync_dirty_buffer(bh);
136136
if (buffer_req(bh) && !buffer_uptodate(bh)) {
137-
ext4_error(inode->i_sb,
138-
"IO error syncing inode, "
139-
"inode=%lu, block=%llu",
140-
inode->i_ino,
141-
(unsigned long long) bh->b_blocknr);
137+
ext4_error_inode(inode, where, line,
138+
bh->b_blocknr,
139+
"IO error syncing itable block");
142140
err = -EIO;
143141
}
144142
}

‎fs/ext4/ext4_jbd2.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line,
162162
__ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb))
163163

164164
handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks);
165-
int __ext4_journal_stop(const char *where, handle_t *handle);
165+
int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle);
166166

167167
#define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096)
168168

@@ -215,7 +215,7 @@ static inline handle_t *ext4_journal_start(struct inode *inode, int nblocks)
215215
}
216216

217217
#define ext4_journal_stop(handle) \
218-
__ext4_journal_stop(__func__, (handle))
218+
__ext4_journal_stop(__func__, __LINE__, (handle))
219219

220220
static inline handle_t *ext4_journal_current_handle(void)
221221
{

‎fs/ext4/extents.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ static int ext4_valid_extent_entries(struct inode *inode,
401401
return 1;
402402
}
403403

404-
static int __ext4_ext_check(const char *function, struct inode *inode,
405-
struct ext4_extent_header *eh,
406-
int depth)
404+
static int __ext4_ext_check(const char *function, unsigned int line,
405+
struct inode *inode, struct ext4_extent_header *eh,
406+
int depth)
407407
{
408408
const char *error_msg;
409409
int max = 0;
@@ -436,7 +436,7 @@ static int __ext4_ext_check(const char *function, struct inode *inode,
436436
return 0;
437437

438438
corrupted:
439-
ext4_error_inode(function, inode,
439+
ext4_error_inode(inode, function, line, 0,
440440
"bad header/extent: %s - magic %x, "
441441
"entries %u, max %u(%u), depth %u(%u)",
442442
error_msg, le16_to_cpu(eh->eh_magic),
@@ -447,7 +447,7 @@ static int __ext4_ext_check(const char *function, struct inode *inode,
447447
}
448448

449449
#define ext4_ext_check(inode, eh, depth) \
450-
__ext4_ext_check(__func__, inode, eh, depth)
450+
__ext4_ext_check(__func__, __LINE__, inode, eh, depth)
451451

452452
int ext4_ext_check_inode(struct inode *inode)
453453
{

‎fs/ext4/inode.c‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ static int ext4_block_to_path(struct inode *inode,
337337
return n;
338338
}
339339

340-
static int __ext4_check_blockref(const char *function, struct inode *inode,
340+
static int __ext4_check_blockref(const char *function, unsigned int line,
341+
struct inode *inode,
341342
__le32 *p, unsigned int max)
342343
{
343344
__le32 *bref = p;
@@ -348,8 +349,8 @@ static int __ext4_check_blockref(const char *function, struct inode *inode,
348349
if (blk &&
349350
unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb),
350351
blk, 1))) {
351-
ext4_error_inode(function, inode,
352-
"invalid block reference %u", blk);
352+
ext4_error_inode(inode, function, line, blk,
353+
"invalid block");
353354
return -EIO;
354355
}
355356
}
@@ -358,11 +359,13 @@ static int __ext4_check_blockref(const char *function, struct inode *inode,
358359

359360

360361
#define ext4_check_indirect_blockref(inode, bh) \
361-
__ext4_check_blockref(__func__, inode, (__le32 *)(bh)->b_data, \
362+
__ext4_check_blockref(__func__, __LINE__, inode, \
363+
(__le32 *)(bh)->b_data, \
362364
EXT4_ADDR_PER_BLOCK((inode)->i_sb))
363365

364366
#define ext4_check_inode_blockref(inode) \
365-
__ext4_check_blockref(__func__, inode, EXT4_I(inode)->i_data, \
367+
__ext4_check_blockref(__func__, __LINE__, inode, \
368+
EXT4_I(inode)->i_data, \
366369
EXT4_NDIR_BLOCKS)
367370

368371
/**
@@ -1129,21 +1132,22 @@ void ext4_da_update_reserve_space(struct inode *inode,
11291132
}
11301133

11311134
static int __check_block_validity(struct inode *inode, const char *func,
1132-
struct ext4_map_blocks *map)
1135+
unsigned int line,
1136+
struct ext4_map_blocks *map)
11331137
{
11341138
if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk,
11351139
map->m_len)) {
1136-
ext4_error_inode(func, inode,
1137-
"lblock %lu mapped to illegal pblock %llu "
1138-
"(length %d)", (unsigned long) map->m_lblk,
1139-
map->m_pblk, map->m_len);
1140+
ext4_error_inode(inode, func, line, map->m_pblk,
1141+
"lblock %lu mapped to illegal pblock "
1142+
"(length %d)", (unsigned long) map->m_lblk,
1143+
map->m_len);
11401144
return -EIO;
11411145
}
11421146
return 0;
11431147
}
11441148

11451149
#define check_block_validity(inode, map) \
1146-
__check_block_validity((inode), __func__, (map))
1150+
__check_block_validity((inode), __func__, __LINE__, (map))
11471151

11481152
/*
11491153
* 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,
44714475
* (should be rare).
44724476
*/
44734477
if (!bh) {
4474-
EXT4_ERROR_INODE(inode,
4475-
"Read failure block=%llu",
4476-
(unsigned long long) nr);
4478+
EXT4_ERROR_INODE_BLOCK(inode, nr,
4479+
"Read failure");
44774480
continue;
44784481
}
44794482

@@ -4788,8 +4791,8 @@ static int __ext4_get_inode_loc(struct inode *inode,
47884791

47894792
bh = sb_getblk(sb, block);
47904793
if (!bh) {
4791-
EXT4_ERROR_INODE(inode, "unable to read inode block - "
4792-
"block %llu", block);
4794+
EXT4_ERROR_INODE_BLOCK(inode, block,
4795+
"unable to read itable block");
47934796
return -EIO;
47944797
}
47954798
if (!buffer_uptodate(bh)) {
@@ -4887,8 +4890,8 @@ static int __ext4_get_inode_loc(struct inode *inode,
48874890
submit_bh(READ_META, bh);
48884891
wait_on_buffer(bh);
48894892
if (!buffer_uptodate(bh)) {
4890-
EXT4_ERROR_INODE(inode, "unable to read inode "
4891-
"block %llu", block);
4893+
EXT4_ERROR_INODE_BLOCK(inode, block,
4894+
"unable to read itable block");
48924895
brelse(bh);
48934896
return -EIO;
48944897
}
@@ -5389,9 +5392,8 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
53895392
if (wbc->sync_mode == WB_SYNC_ALL)
53905393
sync_dirty_buffer(iloc.bh);
53915394
if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
5392-
EXT4_ERROR_INODE(inode,
5393-
"IO error syncing inode (block=%llu)",
5394-
(unsigned long long) iloc.bh->b_blocknr);
5395+
EXT4_ERROR_INODE_BLOCK(inode, iloc.bh->b_blocknr,
5396+
"IO error syncing inode");
53955397
err = -EIO;
53965398
}
53975399
brelse(iloc.bh);

‎fs/ext4/move_extent.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ mext_next_extent(struct inode *inode, struct ext4_ext_path *path,
148148
*/
149149
static int
150150
mext_check_null_inode(struct inode *inode1, struct inode *inode2,
151-
const char *function)
151+
const char *function, unsigned int line)
152152
{
153153
int ret = 0;
154154

155155
if (inode1 == NULL) {
156-
__ext4_error(inode2->i_sb, function,
156+
__ext4_error(inode2->i_sb, function, line,
157157
"Both inodes should not be NULL: "
158158
"inode1 NULL inode2 %lu", inode2->i_ino);
159159
ret = -EIO;
160160
} else if (inode2 == NULL) {
161-
__ext4_error(inode1->i_sb, function,
161+
__ext4_error(inode1->i_sb, function, line,
162162
"Both inodes should not be NULL: "
163163
"inode1 %lu inode2 NULL", inode1->i_ino);
164164
ret = -EIO;
@@ -1084,7 +1084,7 @@ mext_inode_double_lock(struct inode *inode1, struct inode *inode2)
10841084

10851085
BUG_ON(inode1 == NULL && inode2 == NULL);
10861086

1087-
ret = mext_check_null_inode(inode1, inode2, __func__);
1087+
ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__);
10881088
if (ret < 0)
10891089
goto out;
10901090

@@ -1121,7 +1121,7 @@ mext_inode_double_unlock(struct inode *inode1, struct inode *inode2)
11211121

11221122
BUG_ON(inode1 == NULL && inode2 == NULL);
11231123

1124-
ret = mext_check_null_inode(inode1, inode2, __func__);
1124+
ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__);
11251125
if (ret < 0)
11261126
goto out;
11271127

0 commit comments

Comments
 (0)