ext4: fix warning when submitting superblock in ext4_commit_super()
We have already check the io_error and uptodate flag before submitting the superblock buffer, and re-set the uptodate flag if it has been failed to write out. But it was lockless and could be raced by another ext4_commit_super(), and finally trigger '!uptodate' WARNING when marking buffer dirty. Fix it by submit buffer directly. Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ritesh Harjani <ritesh.list@gmail.com> Link: https://lore.kernel.org/r/20220520023216.3065073-1-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
3103084afc
commit
15baa7dcad
@ -5898,7 +5898,6 @@ static void ext4_update_super(struct super_block *sb)
|
|||||||
static int ext4_commit_super(struct super_block *sb)
|
static int ext4_commit_super(struct super_block *sb)
|
||||||
{
|
{
|
||||||
struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
|
struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
if (!sbh)
|
if (!sbh)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -5907,6 +5906,13 @@ static int ext4_commit_super(struct super_block *sb)
|
|||||||
|
|
||||||
ext4_update_super(sb);
|
ext4_update_super(sb);
|
||||||
|
|
||||||
|
lock_buffer(sbh);
|
||||||
|
/* Buffer got discarded which means block device got invalidated */
|
||||||
|
if (!buffer_mapped(sbh)) {
|
||||||
|
unlock_buffer(sbh);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
if (buffer_write_io_error(sbh) || !buffer_uptodate(sbh)) {
|
if (buffer_write_io_error(sbh) || !buffer_uptodate(sbh)) {
|
||||||
/*
|
/*
|
||||||
* Oh, dear. A previous attempt to write the
|
* Oh, dear. A previous attempt to write the
|
||||||
@ -5921,17 +5927,21 @@ static int ext4_commit_super(struct super_block *sb)
|
|||||||
clear_buffer_write_io_error(sbh);
|
clear_buffer_write_io_error(sbh);
|
||||||
set_buffer_uptodate(sbh);
|
set_buffer_uptodate(sbh);
|
||||||
}
|
}
|
||||||
BUFFER_TRACE(sbh, "marking dirty");
|
get_bh(sbh);
|
||||||
mark_buffer_dirty(sbh);
|
/* Clear potential dirty bit if it was journalled update */
|
||||||
error = __sync_dirty_buffer(sbh,
|
clear_buffer_dirty(sbh);
|
||||||
REQ_SYNC | (test_opt(sb, BARRIER) ? REQ_FUA : 0));
|
sbh->b_end_io = end_buffer_write_sync;
|
||||||
|
submit_bh(REQ_OP_WRITE,
|
||||||
|
REQ_SYNC | (test_opt(sb, BARRIER) ? REQ_FUA : 0), sbh);
|
||||||
|
wait_on_buffer(sbh);
|
||||||
if (buffer_write_io_error(sbh)) {
|
if (buffer_write_io_error(sbh)) {
|
||||||
ext4_msg(sb, KERN_ERR, "I/O error while writing "
|
ext4_msg(sb, KERN_ERR, "I/O error while writing "
|
||||||
"superblock");
|
"superblock");
|
||||||
clear_buffer_write_io_error(sbh);
|
clear_buffer_write_io_error(sbh);
|
||||||
set_buffer_uptodate(sbh);
|
set_buffer_uptodate(sbh);
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
return error;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user