Skip to content

Commit

Permalink
f2fs: introduce f2fs_update_data_blkaddr for cleanup
Browse files Browse the repository at this point in the history
Add a new help f2fs_update_data_blkaddr to clean up redundant codes.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
Chao Yu authored and Jaegeuk Kim committed Feb 26, 2016
1 parent 4356e48 commit f28b343
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 26 deletions.
9 changes: 7 additions & 2 deletions fs/f2fs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ void set_data_blkaddr(struct dnode_of_data *dn)
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)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
Expand Down Expand Up @@ -1110,8 +1117,6 @@ int do_write_data_page(struct f2fs_io_info *fio)
trace_f2fs_do_write_data_page(page, IPU);
} else {
write_data_page(&dn, fio);
set_data_blkaddr(&dn);
f2fs_update_extent_cache(&dn);
trace_f2fs_do_write_data_page(page, OPU);
set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
if (page->index == 0)
Expand Down
9 changes: 6 additions & 3 deletions fs/f2fs/extent_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
pgoff_t fofs;
block_t blkaddr;

if (!f2fs_may_extent_tree(dn->inode))
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) +
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);
}

Expand Down
1 change: 1 addition & 0 deletions fs/f2fs/f2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
void f2fs_submit_page_mbio(struct f2fs_io_info *);
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 f2fs_get_block(struct dnode_of_data *, pgoff_t);
ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
Expand Down
15 changes: 3 additions & 12 deletions fs/f2fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,8 @@ static int __exchange_data_block(struct inode *inode, pgoff_t src,
} else {
new_addr = dn.data_blkaddr;
if (!is_checkpointed_data(sbi, new_addr)) {
dn.data_blkaddr = NULL_ADDR;
/* do not invalidate this block address */
set_data_blkaddr(&dn);
f2fs_update_extent_cache(&dn);
f2fs_update_data_blkaddr(&dn, NULL_ADDR);
do_replace = true;
}
f2fs_put_dnode(&dn);
Expand Down Expand Up @@ -911,9 +909,7 @@ static int __exchange_data_block(struct inode *inode, pgoff_t src,

err_out:
if (!get_dnode_of_data(&dn, src, LOOKUP_NODE)) {
dn.data_blkaddr = new_addr;
set_data_blkaddr(&dn);
f2fs_update_extent_cache(&dn);
f2fs_update_data_blkaddr(&dn, new_addr);
f2fs_put_dnode(&dn);
}
return ret;
Expand Down Expand Up @@ -1053,12 +1049,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,

if (dn.data_blkaddr != NEW_ADDR) {
invalidate_blocks(sbi, dn.data_blkaddr);

dn.data_blkaddr = NEW_ADDR;
set_data_blkaddr(&dn);

dn.data_blkaddr = NULL_ADDR;
f2fs_update_extent_cache(&dn);
f2fs_update_data_blkaddr(&dn, NEW_ADDR);
}
f2fs_put_dnode(&dn);
f2fs_unlock_op(sbi);
Expand Down
4 changes: 1 addition & 3 deletions fs/f2fs/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,7 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
fio.new_blkaddr = newaddr;
f2fs_submit_page_mbio(&fio);

dn.data_blkaddr = fio.new_blkaddr;
set_data_blkaddr(&dn);
f2fs_update_extent_cache(&dn);
f2fs_update_data_blkaddr(&dn, newaddr);
set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
if (page->index == 0)
set_inode_flag(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
Expand Down
2 changes: 0 additions & 2 deletions fs/f2fs/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
set_page_writeback(page);
fio.old_blkaddr = dn->data_blkaddr;
write_data_page(dn, &fio);
set_data_blkaddr(dn);
f2fs_update_extent_cache(dn);
f2fs_wait_on_page_writeback(page, DATA, true);
if (dirty)
inode_dec_dirty_pages(dn->inode);
Expand Down
6 changes: 2 additions & 4 deletions fs/f2fs/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
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)
Expand Down Expand Up @@ -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,
recover_curseg, recover_newaddr);

dn->data_blkaddr = new_addr;
set_data_blkaddr(dn);
f2fs_update_extent_cache(dn);
f2fs_update_data_blkaddr(dn, new_addr);
}

void f2fs_wait_on_page_writeback(struct page *page,
Expand Down

0 comments on commit f28b343

Please sign in to comment.