提交 f28b3434 编写于 作者: C Chao Yu 提交者: Jaegeuk Kim

f2fs: introduce f2fs_update_data_blkaddr for cleanup

Add a new help f2fs_update_data_blkaddr to clean up redundant codes.
Signed-off-by: NChao Yu <chao2.yu@samsung.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 4356e48e
...@@ -300,6 +300,13 @@ void set_data_blkaddr(struct dnode_of_data *dn) ...@@ -300,6 +300,13 @@ void set_data_blkaddr(struct dnode_of_data *dn)
dn->node_changed = true; dn->node_changed = true;
} }
void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
{
dn->data_blkaddr = blkaddr;
set_data_blkaddr(dn);
f2fs_update_extent_cache(dn);
}
int reserve_new_block(struct dnode_of_data *dn) int reserve_new_block(struct dnode_of_data *dn)
{ {
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
...@@ -1110,8 +1117,6 @@ int do_write_data_page(struct f2fs_io_info *fio) ...@@ -1110,8 +1117,6 @@ int do_write_data_page(struct f2fs_io_info *fio)
trace_f2fs_do_write_data_page(page, IPU); trace_f2fs_do_write_data_page(page, IPU);
} else { } else {
write_data_page(&dn, fio); write_data_page(&dn, fio);
set_data_blkaddr(&dn);
f2fs_update_extent_cache(&dn);
trace_f2fs_do_write_data_page(page, OPU); trace_f2fs_do_write_data_page(page, OPU);
set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE); set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
if (page->index == 0) if (page->index == 0)
......
...@@ -674,17 +674,20 @@ bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, ...@@ -674,17 +674,20 @@ bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
void f2fs_update_extent_cache(struct dnode_of_data *dn) void f2fs_update_extent_cache(struct dnode_of_data *dn)
{ {
pgoff_t fofs; pgoff_t fofs;
block_t blkaddr;
if (!f2fs_may_extent_tree(dn->inode)) if (!f2fs_may_extent_tree(dn->inode))
return; return;
f2fs_bug_on(F2FS_I_SB(dn->inode), dn->data_blkaddr == NEW_ADDR); if (dn->data_blkaddr == NEW_ADDR)
blkaddr = NULL_ADDR;
else
blkaddr = dn->data_blkaddr;
fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) + fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) +
dn->ofs_in_node; dn->ofs_in_node;
if (f2fs_update_extent_tree_range(dn->inode, fofs, dn->data_blkaddr, 1)) if (f2fs_update_extent_tree_range(dn->inode, fofs, blkaddr, 1))
sync_inode_page(dn); sync_inode_page(dn);
} }
......
...@@ -1910,6 +1910,7 @@ void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *, ...@@ -1910,6 +1910,7 @@ void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *,
int f2fs_submit_page_bio(struct f2fs_io_info *); int f2fs_submit_page_bio(struct f2fs_io_info *);
void f2fs_submit_page_mbio(struct f2fs_io_info *); void f2fs_submit_page_mbio(struct f2fs_io_info *);
void set_data_blkaddr(struct dnode_of_data *); void set_data_blkaddr(struct dnode_of_data *);
void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t);
int reserve_new_block(struct dnode_of_data *); int reserve_new_block(struct dnode_of_data *);
int f2fs_get_block(struct dnode_of_data *, pgoff_t); int f2fs_get_block(struct dnode_of_data *, pgoff_t);
ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *); ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
......
...@@ -857,10 +857,8 @@ static int __exchange_data_block(struct inode *inode, pgoff_t src, ...@@ -857,10 +857,8 @@ static int __exchange_data_block(struct inode *inode, pgoff_t src,
} else { } else {
new_addr = dn.data_blkaddr; new_addr = dn.data_blkaddr;
if (!is_checkpointed_data(sbi, new_addr)) { if (!is_checkpointed_data(sbi, new_addr)) {
dn.data_blkaddr = NULL_ADDR;
/* do not invalidate this block address */ /* do not invalidate this block address */
set_data_blkaddr(&dn); f2fs_update_data_blkaddr(&dn, NULL_ADDR);
f2fs_update_extent_cache(&dn);
do_replace = true; do_replace = true;
} }
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
...@@ -911,9 +909,7 @@ static int __exchange_data_block(struct inode *inode, pgoff_t src, ...@@ -911,9 +909,7 @@ static int __exchange_data_block(struct inode *inode, pgoff_t src,
err_out: err_out:
if (!get_dnode_of_data(&dn, src, LOOKUP_NODE)) { if (!get_dnode_of_data(&dn, src, LOOKUP_NODE)) {
dn.data_blkaddr = new_addr; f2fs_update_data_blkaddr(&dn, new_addr);
set_data_blkaddr(&dn);
f2fs_update_extent_cache(&dn);
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
} }
return ret; return ret;
...@@ -1053,12 +1049,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, ...@@ -1053,12 +1049,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
if (dn.data_blkaddr != NEW_ADDR) { if (dn.data_blkaddr != NEW_ADDR) {
invalidate_blocks(sbi, dn.data_blkaddr); invalidate_blocks(sbi, dn.data_blkaddr);
f2fs_update_data_blkaddr(&dn, NEW_ADDR);
dn.data_blkaddr = NEW_ADDR;
set_data_blkaddr(&dn);
dn.data_blkaddr = NULL_ADDR;
f2fs_update_extent_cache(&dn);
} }
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
f2fs_unlock_op(sbi); f2fs_unlock_op(sbi);
......
...@@ -624,9 +624,7 @@ static void move_encrypted_block(struct inode *inode, block_t bidx) ...@@ -624,9 +624,7 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
fio.new_blkaddr = newaddr; fio.new_blkaddr = newaddr;
f2fs_submit_page_mbio(&fio); f2fs_submit_page_mbio(&fio);
dn.data_blkaddr = fio.new_blkaddr; f2fs_update_data_blkaddr(&dn, newaddr);
set_data_blkaddr(&dn);
f2fs_update_extent_cache(&dn);
set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE); set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
if (page->index == 0) if (page->index == 0)
set_inode_flag(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); set_inode_flag(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
......
...@@ -133,8 +133,6 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) ...@@ -133,8 +133,6 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
set_page_writeback(page); set_page_writeback(page);
fio.old_blkaddr = dn->data_blkaddr; fio.old_blkaddr = dn->data_blkaddr;
write_data_page(dn, &fio); write_data_page(dn, &fio);
set_data_blkaddr(dn);
f2fs_update_extent_cache(dn);
f2fs_wait_on_page_writeback(page, DATA, true); f2fs_wait_on_page_writeback(page, DATA, true);
if (dirty) if (dirty)
inode_dec_dirty_pages(dn->inode); inode_dec_dirty_pages(dn->inode);
......
...@@ -1429,7 +1429,7 @@ void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio) ...@@ -1429,7 +1429,7 @@ void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio)
get_node_info(sbi, dn->nid, &ni); get_node_info(sbi, dn->nid, &ni);
set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
do_write_page(&sum, fio); do_write_page(&sum, fio);
dn->data_blkaddr = fio->new_blkaddr; f2fs_update_data_blkaddr(dn, fio->new_blkaddr);
} }
void rewrite_data_page(struct f2fs_io_info *fio) void rewrite_data_page(struct f2fs_io_info *fio)
...@@ -1518,9 +1518,7 @@ void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, ...@@ -1518,9 +1518,7 @@ void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
__f2fs_replace_block(sbi, &sum, old_addr, new_addr, __f2fs_replace_block(sbi, &sum, old_addr, new_addr,
recover_curseg, recover_newaddr); recover_curseg, recover_newaddr);
dn->data_blkaddr = new_addr; f2fs_update_data_blkaddr(dn, new_addr);
set_data_blkaddr(dn);
f2fs_update_extent_cache(dn);
} }
void f2fs_wait_on_page_writeback(struct page *page, void f2fs_wait_on_page_writeback(struct page *page,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册