Commit e29136f8 authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: Enhance ext4_grp_locked_error() to take block and function numbers

Also use a macro definition so that __func__ and __LINE__ is implicit.
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent c67d859e
...@@ -1639,9 +1639,13 @@ extern void __ext4_warning(struct super_block *, const char *, ...@@ -1639,9 +1639,13 @@ extern void __ext4_warning(struct super_block *, const char *,
#define ext4_warning(sb, message...) __ext4_warning(sb, __func__, ## message) #define ext4_warning(sb, message...) __ext4_warning(sb, __func__, ## 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(struct super_block *, ext4_group_t, extern void __ext4_grp_locked_error(const char *, unsigned int, \
const char *, const char *, ...) struct super_block *, ext4_group_t, \
__attribute__ ((format (printf, 4, 5))); unsigned long, ext4_fsblk_t, \
const char *, ...)
__attribute__ ((format (printf, 7, 8)));
#define ext4_grp_locked_error(sb, grp, message...) \
__ext4_grp_locked_error(__func__, __LINE__, (sb), (grp), ## message)
extern void ext4_update_dynamic_rev(struct super_block *sb); extern void ext4_update_dynamic_rev(struct super_block *sb);
extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb, extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb,
__u32 compat); __u32 compat);
......
...@@ -1128,8 +1128,8 @@ void ext4_da_update_reserve_space(struct inode *inode, ...@@ -1128,8 +1128,8 @@ void ext4_da_update_reserve_space(struct inode *inode,
ext4_discard_preallocations(inode); ext4_discard_preallocations(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) 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)) {
...@@ -1142,6 +1142,9 @@ static int check_block_validity(struct inode *inode, const char *func, ...@@ -1142,6 +1142,9 @@ static int check_block_validity(struct inode *inode, const char *func,
return 0; return 0;
} }
#define check_block_validity(inode, map) \
__check_block_validity((inode), __func__, (map))
/* /*
* Return the number of contiguous dirty pages in a given inode * Return the number of contiguous dirty pages in a given inode
* starting at page frame idx. * starting at page frame idx.
...@@ -1244,7 +1247,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -1244,7 +1247,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
up_read((&EXT4_I(inode)->i_data_sem)); up_read((&EXT4_I(inode)->i_data_sem));
if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
int ret = check_block_validity(inode, __func__, map); int ret = check_block_validity(inode, map);
if (ret != 0) if (ret != 0)
return ret; return ret;
} }
...@@ -1324,9 +1327,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -1324,9 +1327,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
up_write((&EXT4_I(inode)->i_data_sem)); up_write((&EXT4_I(inode)->i_data_sem));
if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
int ret = check_block_validity(inode, int ret = check_block_validity(inode, map);
"ext4_map_blocks_after_alloc",
map);
if (ret != 0) if (ret != 0)
return ret; return ret;
} }
......
...@@ -446,10 +446,11 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b, ...@@ -446,10 +446,11 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
blocknr = ext4_group_first_block_no(sb, e4b->bd_group); blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
blocknr += first + i; blocknr += first + i;
ext4_grp_locked_error(sb, e4b->bd_group, ext4_grp_locked_error(sb, e4b->bd_group,
__func__, "double-free of inode" inode ? inode->i_ino : 0,
" %lu's block %llu(bit %u in group %u)", blocknr,
inode ? inode->i_ino : 0, blocknr, "freeing block already freed "
first + i, e4b->bd_group); "(bit %u)",
first + i);
} }
mb_clear_bit(first + i, e4b->bd_info->bb_bitmap); mb_clear_bit(first + i, e4b->bd_info->bb_bitmap);
} }
...@@ -712,9 +713,9 @@ void ext4_mb_generate_buddy(struct super_block *sb, ...@@ -712,9 +713,9 @@ void ext4_mb_generate_buddy(struct super_block *sb,
grp->bb_fragments = fragments; grp->bb_fragments = fragments;
if (free != grp->bb_free) { if (free != grp->bb_free) {
ext4_grp_locked_error(sb, group, __func__, ext4_grp_locked_error(sb, group, 0, 0,
"EXT4-fs: group %u: %u blocks in bitmap, %u in gd", "%u blocks in bitmap, %u in gd",
group, free, grp->bb_free); free, grp->bb_free);
/* /*
* If we intent to continue, we consider group descritor * If we intent to continue, we consider group descritor
* corrupt and update bb_free using bitmap value * corrupt and update bb_free using bitmap value
...@@ -1296,10 +1297,10 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, ...@@ -1296,10 +1297,10 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
blocknr = ext4_group_first_block_no(sb, e4b->bd_group); blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
blocknr += block; blocknr += block;
ext4_grp_locked_error(sb, e4b->bd_group, ext4_grp_locked_error(sb, e4b->bd_group,
__func__, "double-free of inode" inode ? inode->i_ino : 0,
" %lu's block %llu(bit %u in group %u)", blocknr,
inode ? inode->i_ino : 0, blocknr, block, "freeing already freed block "
e4b->bd_group); "(bit %u)", block);
} }
mb_clear_bit(block, EXT4_MB_BITMAP(e4b)); mb_clear_bit(block, EXT4_MB_BITMAP(e4b));
e4b->bd_info->bb_counters[order]++; e4b->bd_info->bb_counters[order]++;
...@@ -1788,8 +1789,8 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac, ...@@ -1788,8 +1789,8 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
* free blocks even though group info says we * free blocks even though group info says we
* we have free blocks * we have free blocks
*/ */
ext4_grp_locked_error(sb, e4b->bd_group, ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
__func__, "%d free blocks as per " "%d free blocks as per "
"group info. But bitmap says 0", "group info. But bitmap says 0",
free); free);
break; break;
...@@ -1798,8 +1799,8 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac, ...@@ -1798,8 +1799,8 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex);
BUG_ON(ex.fe_len <= 0); BUG_ON(ex.fe_len <= 0);
if (free < ex.fe_len) { if (free < ex.fe_len) {
ext4_grp_locked_error(sb, e4b->bd_group, ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
__func__, "%d free blocks as per " "%d free blocks as per "
"group info. But got %d blocks", "group info. But got %d blocks",
free, ex.fe_len); free, ex.fe_len);
/* /*
...@@ -3584,8 +3585,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh, ...@@ -3584,8 +3585,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
pa, (unsigned long) pa->pa_lstart, pa, (unsigned long) pa->pa_lstart,
(unsigned long) pa->pa_pstart, (unsigned long) pa->pa_pstart,
(unsigned long) pa->pa_len); (unsigned long) pa->pa_len);
ext4_grp_locked_error(sb, group, ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
__func__, "free %u, pa_free %u",
free, pa->pa_free); free, pa->pa_free);
/* /*
* pa is already deleted so we use the value obtained * pa is already deleted so we use the value obtained
...@@ -4395,6 +4395,7 @@ static noinline_for_stack int ...@@ -4395,6 +4395,7 @@ static noinline_for_stack int
ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b, ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
struct ext4_free_data *new_entry) struct ext4_free_data *new_entry)
{ {
ext4_group_t group = e4b->bd_group;
ext4_grpblk_t block; ext4_grpblk_t block;
struct ext4_free_data *entry; struct ext4_free_data *entry;
struct ext4_group_info *db = e4b->bd_info; struct ext4_group_info *db = e4b->bd_info;
...@@ -4427,9 +4428,9 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b, ...@@ -4427,9 +4428,9 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
else if (block >= (entry->start_blk + entry->count)) else if (block >= (entry->start_blk + entry->count))
n = &(*n)->rb_right; n = &(*n)->rb_right;
else { else {
ext4_grp_locked_error(sb, e4b->bd_group, __func__, ext4_grp_locked_error(sb, group, 0,
"Double free of blocks %d (%d %d)", ext4_group_first_block_no(sb, group) + block,
block, entry->start_blk, entry->count); "Block already on to-be-freed list");
return 0; return 0;
} }
} }
......
...@@ -514,8 +514,10 @@ void __ext4_warning(struct super_block *sb, const char *function, ...@@ -514,8 +514,10 @@ void __ext4_warning(struct super_block *sb, const char *function,
va_end(args); va_end(args);
} }
void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, void __ext4_grp_locked_error(const char *function, unsigned int line,
const char *function, const char *fmt, ...) struct super_block *sb, ext4_group_t grp,
unsigned long ino, ext4_fsblk_t block,
const char *fmt, ...)
__releases(bitlock) __releases(bitlock)
__acquires(bitlock) __acquires(bitlock)
{ {
...@@ -523,7 +525,12 @@ __acquires(bitlock) ...@@ -523,7 +525,12 @@ __acquires(bitlock)
struct ext4_super_block *es = EXT4_SB(sb)->s_es; struct ext4_super_block *es = EXT4_SB(sb)->s_es;
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: group %u",
sb->s_id, function, line, grp);
if (ino)
printk("inode %lu: ", ino);
if (block)
printk("block %llu:", (unsigned long long) block);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment