mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
f2fs: fix to read source block before invalidating it
f2fs_allocate_data_block() invalidates old block address and enable new block address. Then, if we try to read old block by f2fs_submit_page_bio(), it will give WARN due to reading invalid blocks. Let's make the order sanely back. Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
d5e5efa250
commit
543b8c468f
70
fs/f2fs/gc.c
70
fs/f2fs/gc.c
@ -796,6 +796,29 @@ static int move_data_block(struct inode *inode, block_t bidx,
|
||||
if (lfs_mode)
|
||||
down_write(&fio.sbi->io_order_lock);
|
||||
|
||||
mpage = f2fs_grab_cache_page(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, false);
|
||||
if (!mpage)
|
||||
goto up_out;
|
||||
|
||||
fio.encrypted_page = mpage;
|
||||
|
||||
/* read source block in mpage */
|
||||
if (!PageUptodate(mpage)) {
|
||||
err = f2fs_submit_page_bio(&fio);
|
||||
if (err) {
|
||||
f2fs_put_page(mpage, 1);
|
||||
goto up_out;
|
||||
}
|
||||
lock_page(mpage);
|
||||
if (unlikely(mpage->mapping != META_MAPPING(fio.sbi) ||
|
||||
!PageUptodate(mpage))) {
|
||||
err = -EIO;
|
||||
f2fs_put_page(mpage, 1);
|
||||
goto up_out;
|
||||
}
|
||||
}
|
||||
|
||||
f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr,
|
||||
&sum, CURSEG_COLD_DATA, NULL, false);
|
||||
|
||||
@ -803,44 +826,18 @@ static int move_data_block(struct inode *inode, block_t bidx,
|
||||
newaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS);
|
||||
if (!fio.encrypted_page) {
|
||||
err = -ENOMEM;
|
||||
f2fs_put_page(mpage, 1);
|
||||
goto recover_block;
|
||||
}
|
||||
|
||||
mpage = f2fs_pagecache_get_page(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, FGP_LOCK, GFP_NOFS);
|
||||
if (mpage) {
|
||||
bool updated = false;
|
||||
|
||||
if (PageUptodate(mpage)) {
|
||||
memcpy(page_address(fio.encrypted_page),
|
||||
page_address(mpage), PAGE_SIZE);
|
||||
updated = true;
|
||||
}
|
||||
f2fs_put_page(mpage, 1);
|
||||
invalidate_mapping_pages(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, fio.old_blkaddr);
|
||||
if (updated)
|
||||
goto write_page;
|
||||
}
|
||||
|
||||
err = f2fs_submit_page_bio(&fio);
|
||||
if (err)
|
||||
goto put_page_out;
|
||||
|
||||
/* write page */
|
||||
lock_page(fio.encrypted_page);
|
||||
|
||||
if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) {
|
||||
err = -EIO;
|
||||
goto put_page_out;
|
||||
}
|
||||
if (unlikely(!PageUptodate(fio.encrypted_page))) {
|
||||
err = -EIO;
|
||||
goto put_page_out;
|
||||
}
|
||||
|
||||
write_page:
|
||||
/* write target block */
|
||||
f2fs_wait_on_page_writeback(fio.encrypted_page, DATA, true, true);
|
||||
memcpy(page_address(fio.encrypted_page),
|
||||
page_address(mpage), PAGE_SIZE);
|
||||
f2fs_put_page(mpage, 1);
|
||||
invalidate_mapping_pages(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, fio.old_blkaddr);
|
||||
|
||||
set_page_dirty(fio.encrypted_page);
|
||||
if (clear_page_dirty_for_io(fio.encrypted_page))
|
||||
dec_page_count(fio.sbi, F2FS_DIRTY_META);
|
||||
@ -871,11 +868,12 @@ write_page:
|
||||
put_page_out:
|
||||
f2fs_put_page(fio.encrypted_page, 1);
|
||||
recover_block:
|
||||
if (lfs_mode)
|
||||
up_write(&fio.sbi->io_order_lock);
|
||||
if (err)
|
||||
f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr,
|
||||
true, true);
|
||||
up_out:
|
||||
if (lfs_mode)
|
||||
up_write(&fio.sbi->io_order_lock);
|
||||
put_out:
|
||||
f2fs_put_dnode(&dn);
|
||||
out:
|
||||
|
Loading…
Reference in New Issue
Block a user