f2fs: clean up with is_valid_blkaddr()

- rename is_valid_blkaddr() to is_valid_meta_blkaddr() for readability.
- introduce is_valid_blkaddr() for cleanup.

No logic change in this patch.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chao Yu 2018-05-23 22:25:08 +08:00 committed by Jaegeuk Kim
parent 5ad25442b6
commit 7b525dd013
9 changed files with 25 additions and 27 deletions

View File

@ -119,7 +119,7 @@ struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index)
return __get_meta_page(sbi, index, false); return __get_meta_page(sbi, index, false);
} }
bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type) bool is_valid_meta_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type)
{ {
switch (type) { switch (type) {
case META_NAT: case META_NAT:
@ -175,7 +175,7 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
blk_start_plug(&plug); blk_start_plug(&plug);
for (; nrpages-- > 0; blkno++) { for (; nrpages-- > 0; blkno++) {
if (!is_valid_blkaddr(sbi, blkno, type)) if (!is_valid_meta_blkaddr(sbi, blkno, type))
goto out; goto out;
switch (type) { switch (type) {

View File

@ -486,7 +486,7 @@ int f2fs_submit_page_write(struct f2fs_io_info *fio)
spin_unlock(&io->io_lock); spin_unlock(&io->io_lock);
} }
if (fio->old_blkaddr != NEW_ADDR) if (is_valid_blkaddr(fio->old_blkaddr))
verify_block_addr(fio, fio->old_blkaddr); verify_block_addr(fio, fio->old_blkaddr);
verify_block_addr(fio, fio->new_blkaddr); verify_block_addr(fio, fio->new_blkaddr);
@ -1046,7 +1046,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
next_block: next_block:
blkaddr = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node); blkaddr = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node);
if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) { if (!is_valid_blkaddr(blkaddr)) {
if (create) { if (create) {
if (unlikely(f2fs_cp_error(sbi))) { if (unlikely(f2fs_cp_error(sbi))) {
err = -EIO; err = -EIO;
@ -1681,15 +1681,6 @@ static inline bool need_inplace_update(struct f2fs_io_info *fio)
return should_update_inplace(inode, fio); return should_update_inplace(inode, fio);
} }
static inline bool valid_ipu_blkaddr(struct f2fs_io_info *fio)
{
if (fio->old_blkaddr == NEW_ADDR)
return false;
if (fio->old_blkaddr == NULL_ADDR)
return false;
return true;
}
int do_write_data_page(struct f2fs_io_info *fio) int do_write_data_page(struct f2fs_io_info *fio)
{ {
struct page *page = fio->page; struct page *page = fio->page;
@ -1704,7 +1695,7 @@ int do_write_data_page(struct f2fs_io_info *fio)
f2fs_lookup_extent_cache(inode, page->index, &ei)) { f2fs_lookup_extent_cache(inode, page->index, &ei)) {
fio->old_blkaddr = ei.blk + page->index - ei.fofs; fio->old_blkaddr = ei.blk + page->index - ei.fofs;
if (valid_ipu_blkaddr(fio)) { if (is_valid_blkaddr(fio->old_blkaddr)) {
ipu_force = true; ipu_force = true;
fio->need_lock = LOCK_DONE; fio->need_lock = LOCK_DONE;
goto got_it; goto got_it;
@ -1731,7 +1722,8 @@ int do_write_data_page(struct f2fs_io_info *fio)
* If current allocation needs SSR, * If current allocation needs SSR,
* it had better in-place writes for updated data. * it had better in-place writes for updated data.
*/ */
if (ipu_force || (valid_ipu_blkaddr(fio) && need_inplace_update(fio))) { if (ipu_force || (is_valid_blkaddr(fio->old_blkaddr) &&
need_inplace_update(fio))) {
err = encrypt_one_page(fio); err = encrypt_one_page(fio);
if (err) if (err)
goto out_writepage; goto out_writepage;

View File

@ -2644,6 +2644,13 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
spin_unlock(&sbi->iostat_lock); spin_unlock(&sbi->iostat_lock);
} }
static inline bool is_valid_blkaddr(block_t blkaddr)
{
if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR)
return false;
return true;
}
/* /*
* file.c * file.c
*/ */
@ -2862,7 +2869,7 @@ void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); bool is_valid_meta_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type);
int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
int type, bool sync); int type, bool sync);
void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index);

View File

@ -352,7 +352,7 @@ static bool __found_offset(block_t blkaddr, pgoff_t dirty, pgoff_t pgofs,
switch (whence) { switch (whence) {
case SEEK_DATA: case SEEK_DATA:
if ((blkaddr == NEW_ADDR && dirty == pgofs) || if ((blkaddr == NEW_ADDR && dirty == pgofs) ||
(blkaddr != NEW_ADDR && blkaddr != NULL_ADDR)) is_valid_blkaddr(blkaddr))
return true; return true;
break; break;
case SEEK_HOLE: case SEEK_HOLE:

View File

@ -72,7 +72,7 @@ static bool __written_first_block(struct f2fs_inode *ri)
{ {
block_t addr = le32_to_cpu(ri->i_addr[offset_in_addr(ri)]); block_t addr = le32_to_cpu(ri->i_addr[offset_in_addr(ri)]);
if (addr != NEW_ADDR && addr != NULL_ADDR) if (is_valid_blkaddr(addr))
return true; return true;
return false; return false;
} }

View File

@ -379,8 +379,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
new_blkaddr == NULL_ADDR); new_blkaddr == NULL_ADDR);
f2fs_bug_on(sbi, nat_get_blkaddr(e) == NEW_ADDR && f2fs_bug_on(sbi, nat_get_blkaddr(e) == NEW_ADDR &&
new_blkaddr == NEW_ADDR); new_blkaddr == NEW_ADDR);
f2fs_bug_on(sbi, nat_get_blkaddr(e) != NEW_ADDR && f2fs_bug_on(sbi, is_valid_blkaddr(nat_get_blkaddr(e)) &&
nat_get_blkaddr(e) != NULL_ADDR &&
new_blkaddr == NEW_ADDR); new_blkaddr == NEW_ADDR);
/* increment version no as node is removed */ /* increment version no as node is removed */
@ -391,7 +390,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
/* change address */ /* change address */
nat_set_blkaddr(e, new_blkaddr); nat_set_blkaddr(e, new_blkaddr);
if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR) if (!is_valid_blkaddr(new_blkaddr))
set_nat_flag(e, IS_CHECKPOINTED, false); set_nat_flag(e, IS_CHECKPOINTED, false);
__set_nat_cache_dirty(nm_i, e); __set_nat_cache_dirty(nm_i, e);

View File

@ -252,7 +252,7 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
while (1) { while (1) {
struct fsync_inode_entry *entry; struct fsync_inode_entry *entry;
if (!is_valid_blkaddr(sbi, blkaddr, META_POR)) if (!is_valid_meta_blkaddr(sbi, blkaddr, META_POR))
return 0; return 0;
page = get_tmp_page(sbi, blkaddr); page = get_tmp_page(sbi, blkaddr);
@ -506,7 +506,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
} }
/* dest is valid block, try to recover from src to dest */ /* dest is valid block, try to recover from src to dest */
if (is_valid_blkaddr(sbi, dest, META_POR)) { if (is_valid_meta_blkaddr(sbi, dest, META_POR)) {
if (src == NULL_ADDR) { if (src == NULL_ADDR) {
err = reserve_new_block(&dn); err = reserve_new_block(&dn);
@ -567,7 +567,7 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
while (1) { while (1) {
struct fsync_inode_entry *entry; struct fsync_inode_entry *entry;
if (!is_valid_blkaddr(sbi, blkaddr, META_POR)) if (!is_valid_meta_blkaddr(sbi, blkaddr, META_POR))
break; break;
ra_meta_pages_cond(sbi, blkaddr); ra_meta_pages_cond(sbi, blkaddr);

View File

@ -1895,7 +1895,7 @@ bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr)
struct seg_entry *se; struct seg_entry *se;
bool is_cp = false; bool is_cp = false;
if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) if (!is_valid_blkaddr(blkaddr))
return true; return true;
down_read(&sit_i->sentry_lock); down_read(&sit_i->sentry_lock);
@ -2959,7 +2959,7 @@ void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr)
{ {
struct page *cpage; struct page *cpage;
if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) if (!is_valid_blkaddr(blkaddr))
return; return;
cpage = find_lock_page(META_MAPPING(sbi), blkaddr); cpage = find_lock_page(META_MAPPING(sbi), blkaddr);

View File

@ -85,7 +85,7 @@
(GET_SEGOFF_FROM_SEG0(sbi, blk_addr) & ((sbi)->blocks_per_seg - 1)) (GET_SEGOFF_FROM_SEG0(sbi, blk_addr) & ((sbi)->blocks_per_seg - 1))
#define GET_SEGNO(sbi, blk_addr) \ #define GET_SEGNO(sbi, blk_addr) \
((((blk_addr) == NULL_ADDR) || ((blk_addr) == NEW_ADDR)) ? \ ((!is_valid_blkaddr(blk_addr)) ? \
NULL_SEGNO : GET_L2R_SEGNO(FREE_I(sbi), \ NULL_SEGNO : GET_L2R_SEGNO(FREE_I(sbi), \
GET_SEGNO_FROM_SEG0(sbi, blk_addr))) GET_SEGNO_FROM_SEG0(sbi, blk_addr)))
#define BLKS_PER_SEC(sbi) \ #define BLKS_PER_SEC(sbi) \