Commit 5d909cdb authored by Jaegeuk Kim's avatar Jaegeuk Kim
Browse files

f2fs: refactor f2fs_commit_super



Previously, f2fs_commit_super hacks the bh->blocknr to write the broken
alternate superblock.
Instead of it, we should use the correct logic to retrieve its buffer head
with locking it appropriately.
Reviewed-by: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 80609448
...@@ -1099,27 +1099,35 @@ static int read_raw_super_block(struct super_block *sb, ...@@ -1099,27 +1099,35 @@ static int read_raw_super_block(struct super_block *sb,
int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
{ {
struct buffer_head *sbh = sbi->raw_super_buf; struct buffer_head *sbh = sbi->raw_super_buf;
sector_t block = sbh->b_blocknr; struct buffer_head *bh;
int err; int err;
/* write back-up superblock first */ /* write back-up superblock first */
sbh->b_blocknr = block ? 0 : 1; bh = sb_getblk(sbi->sb, sbh->b_blocknr ? 0 : 1);
mark_buffer_dirty(sbh); if (!bh)
err = sync_dirty_buffer(sbh); return -EIO;
sbh->b_blocknr = block; lock_buffer(bh);
memcpy(bh->b_data, sbh->b_data, sbh->b_size);
WARN_ON(sbh->b_size != F2FS_BLKSIZE);
set_buffer_uptodate(bh);
set_buffer_dirty(bh);
unlock_buffer(bh);
/* it's rare case, we can do fua all the time */
err = __sync_dirty_buffer(bh, WRITE_FLUSH_FUA);
brelse(bh);
/* if we are in recovery path, skip writing valid superblock */ /* if we are in recovery path, skip writing valid superblock */
if (recover || err) if (recover || err)
goto out; return err;
/* write current valid superblock */ /* write current valid superblock */
mark_buffer_dirty(sbh); lock_buffer(sbh);
err = sync_dirty_buffer(sbh); set_buffer_dirty(sbh);
out: unlock_buffer(sbh);
clear_buffer_write_io_error(sbh);
set_buffer_uptodate(sbh); return __sync_dirty_buffer(sbh, WRITE_FLUSH_FUA);
return err;
} }
static int f2fs_fill_super(struct super_block *sb, void *data, int silent) static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
......
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