Skip to content

Commit

Permalink
f2fs: use f2fs_io_info to clean up messy parameters during IO path
Browse files Browse the repository at this point in the history
This patch cleans up parameters on IO paths.
The key idea is to use f2fs_io_info adding a parameter, block address, and then
use this structure as parameters.

Reviewed-by: Chao Yu <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
  • Loading branch information
Jaegeuk Kim authored and Jaegeuk Kim committed Jan 12, 2015
1 parent a862a28 commit fc5e466
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 66 deletions.
24 changes: 13 additions & 11 deletions fs/f2fs/checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
{
struct address_space *mapping = META_MAPPING(sbi);
struct page *page;
struct f2fs_io_info fio = {
.type = META,
.rw = READ_SYNC | REQ_META | REQ_PRIO,
.blk_addr = index,
};
repeat:
page = grab_cache_page(mapping, index);
if (!page) {
Expand All @@ -59,8 +64,7 @@ struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
if (PageUptodate(page))
goto out;

if (f2fs_submit_page_bio(sbi, page, index,
READ_SYNC | REQ_META | REQ_PRIO))
if (f2fs_submit_page_bio(sbi, page, &fio))
goto repeat;

lock_page(page);
Expand Down Expand Up @@ -113,14 +117,12 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int type
block_t prev_blk_addr = 0;
struct page *page;
block_t blkno = start;

struct f2fs_io_info fio = {
.type = META,
.rw = READ_SYNC | REQ_META | REQ_PRIO
};

for (; nrpages-- > 0; blkno++) {
block_t blk_addr;

if (!is_valid_blkaddr(sbi, blkno, type))
goto out;
Expand All @@ -131,35 +133,35 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int type
NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid)))
blkno = 0;
/* get nat block addr */
blk_addr = current_nat_addr(sbi,
fio.blk_addr = current_nat_addr(sbi,
blkno * NAT_ENTRY_PER_BLOCK);
break;
case META_SIT:
/* get sit block addr */
blk_addr = current_sit_addr(sbi,
fio.blk_addr = current_sit_addr(sbi,
blkno * SIT_ENTRY_PER_BLOCK);
if (blkno != start && prev_blk_addr + 1 != blk_addr)
if (blkno != start && prev_blk_addr + 1 != fio.blk_addr)
goto out;
prev_blk_addr = blk_addr;
prev_blk_addr = fio.blk_addr;
break;
case META_SSA:
case META_CP:
case META_POR:
blk_addr = blkno;
fio.blk_addr = blkno;
break;
default:
BUG();
}

page = grab_cache_page(META_MAPPING(sbi), blk_addr);
page = grab_cache_page(META_MAPPING(sbi), fio.blk_addr);
if (!page)
continue;
if (PageUptodate(page)) {
f2fs_put_page(page, 1);
continue;
}

f2fs_submit_page_mbio(sbi, page, blk_addr, &fio);
f2fs_submit_page_mbio(sbi, page, &fio);
f2fs_put_page(page, 0);
}
out:
Expand Down
66 changes: 40 additions & 26 deletions fs/f2fs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,49 +132,49 @@ void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi,
* Return unlocked page.
*/
int f2fs_submit_page_bio(struct f2fs_sb_info *sbi, struct page *page,
block_t blk_addr, int rw)
struct f2fs_io_info *fio)
{
struct bio *bio;

trace_f2fs_submit_page_bio(page, blk_addr, rw);
trace_f2fs_submit_page_bio(page, fio->blk_addr, fio->rw);

/* Allocate a new bio */
bio = __bio_alloc(sbi, blk_addr, 1, is_read_io(rw));
bio = __bio_alloc(sbi, fio->blk_addr, 1, is_read_io(fio->rw));

if (bio_add_page(bio, page, PAGE_CACHE_SIZE, 0) < PAGE_CACHE_SIZE) {
bio_put(bio);
f2fs_put_page(page, 1);
return -EFAULT;
}

submit_bio(rw, bio);
submit_bio(fio->rw, bio);
return 0;
}

void f2fs_submit_page_mbio(struct f2fs_sb_info *sbi, struct page *page,
block_t blk_addr, struct f2fs_io_info *fio)
struct f2fs_io_info *fio)
{
enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
struct f2fs_bio_info *io;
bool is_read = is_read_io(fio->rw);

io = is_read ? &sbi->read_io : &sbi->write_io[btype];

verify_block_addr(sbi, blk_addr);
verify_block_addr(sbi, fio->blk_addr);

down_write(&io->io_rwsem);

if (!is_read)
inc_page_count(sbi, F2FS_WRITEBACK);

if (io->bio && (io->last_block_in_bio != blk_addr - 1 ||
if (io->bio && (io->last_block_in_bio != fio->blk_addr - 1 ||
io->fio.rw != fio->rw))
__submit_merged_bio(io);
alloc_new:
if (io->bio == NULL) {
int bio_blocks = MAX_BIO_BLOCKS(sbi);

io->bio = __bio_alloc(sbi, blk_addr, bio_blocks, is_read);
io->bio = __bio_alloc(sbi, fio->blk_addr, bio_blocks, is_read);
io->fio = *fio;
}

Expand All @@ -184,10 +184,10 @@ void f2fs_submit_page_mbio(struct f2fs_sb_info *sbi, struct page *page,
goto alloc_new;
}

io->last_block_in_bio = blk_addr;
io->last_block_in_bio = fio->blk_addr;

up_write(&io->io_rwsem);
trace_f2fs_submit_page_mbio(page, fio->rw, fio->type, blk_addr);
trace_f2fs_submit_page_mbio(page, fio->rw, fio->type, fio->blk_addr);
}

/*
Expand Down Expand Up @@ -376,6 +376,10 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync)
struct dnode_of_data dn;
struct page *page;
int err;
struct f2fs_io_info fio = {
.type = DATA,
.rw = sync ? READ_SYNC : READA,
};

page = find_get_page(mapping, index);
if (page && PageUptodate(page))
Expand Down Expand Up @@ -404,8 +408,8 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync)
return page;
}

err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, dn.data_blkaddr,
sync ? READ_SYNC : READA);
fio.blk_addr = dn.data_blkaddr;
err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, &fio);
if (err)
return ERR_PTR(err);

Expand All @@ -430,7 +434,10 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
struct dnode_of_data dn;
struct page *page;
int err;

struct f2fs_io_info fio = {
.type = DATA,
.rw = READ_SYNC,
};
repeat:
page = grab_cache_page(mapping, index);
if (!page)
Expand Down Expand Up @@ -464,8 +471,8 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
return page;
}

err = f2fs_submit_page_bio(F2FS_I_SB(inode), page,
dn.data_blkaddr, READ_SYNC);
fio.blk_addr = dn.data_blkaddr;
err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, &fio);
if (err)
return ERR_PTR(err);

Expand Down Expand Up @@ -515,8 +522,12 @@ struct page *get_new_data_page(struct inode *inode,
zero_user_segment(page, 0, PAGE_CACHE_SIZE);
SetPageUptodate(page);
} else {
err = f2fs_submit_page_bio(F2FS_I_SB(inode), page,
dn.data_blkaddr, READ_SYNC);
struct f2fs_io_info fio = {
.type = DATA,
.rw = READ_SYNC,
.blk_addr = dn.data_blkaddr,
};
err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, &fio);
if (err)
goto put_err;

Expand Down Expand Up @@ -745,7 +756,6 @@ static int f2fs_read_data_pages(struct file *file,
int do_write_data_page(struct page *page, struct f2fs_io_info *fio)
{
struct inode *inode = page->mapping->host;
block_t old_blkaddr, new_blkaddr;
struct dnode_of_data dn;
int err = 0;

Expand All @@ -754,10 +764,10 @@ int do_write_data_page(struct page *page, struct f2fs_io_info *fio)
if (err)
return err;

old_blkaddr = dn.data_blkaddr;
fio->blk_addr = dn.data_blkaddr;

/* This page is already truncated */
if (old_blkaddr == NULL_ADDR)
if (fio->blk_addr == NULL_ADDR)
goto out_writepage;

set_page_writeback(page);
Expand All @@ -766,14 +776,14 @@ int do_write_data_page(struct page *page, struct f2fs_io_info *fio)
* If current allocation needs SSR,
* it had better in-place writes for updated data.
*/
if (unlikely(old_blkaddr != NEW_ADDR &&
if (unlikely(fio->blk_addr != NEW_ADDR &&
!is_cold_data(page) &&
need_inplace_update(inode))) {
rewrite_data_page(page, old_blkaddr, fio);
rewrite_data_page(page, fio);
set_inode_flag(F2FS_I(inode), FI_UPDATE_WRITE);
} else {
write_data_page(page, &dn, &new_blkaddr, fio);
update_extent_cache(new_blkaddr, &dn);
write_data_page(page, &dn, fio);
update_extent_cache(fio->blk_addr, &dn);
set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
}
out_writepage:
Expand Down Expand Up @@ -1007,8 +1017,12 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
if (dn.data_blkaddr == NEW_ADDR) {
zero_user_segment(page, 0, PAGE_CACHE_SIZE);
} else {
err = f2fs_submit_page_bio(sbi, page, dn.data_blkaddr,
READ_SYNC);
struct f2fs_io_info fio = {
.type = DATA,
.rw = READ_SYNC,
.blk_addr = dn.data_blkaddr,
};
err = f2fs_submit_page_bio(sbi, page, &fio);
if (err)
goto fail;

Expand Down
14 changes: 8 additions & 6 deletions fs/f2fs/f2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ enum page_type {
struct f2fs_io_info {
enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
block_t blk_addr; /* block address to be written */
};

#define is_read_io(rw) (((rw) & 1) == READ)
Expand Down Expand Up @@ -1413,10 +1414,10 @@ int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
void write_meta_page(struct f2fs_sb_info *, struct page *);
void write_node_page(struct f2fs_sb_info *, struct page *,
struct f2fs_io_info *, unsigned int, block_t, block_t *);
void write_data_page(struct page *, struct dnode_of_data *, block_t *,
struct f2fs_io_info *);
void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *);
unsigned int, struct f2fs_io_info *);
void write_data_page(struct page *, struct dnode_of_data *,
struct f2fs_io_info *);
void rewrite_data_page(struct page *, struct f2fs_io_info *);
void recover_data_page(struct f2fs_sb_info *, struct page *,
struct f2fs_summary *, block_t, block_t);
void allocate_data_block(struct f2fs_sb_info *, struct page *,
Expand Down Expand Up @@ -1463,8 +1464,9 @@ void destroy_checkpoint_caches(void);
* data.c
*/
void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *, block_t, int);
void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *, block_t,
int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *,
struct f2fs_io_info *);
void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *,
struct f2fs_io_info *);
int reserve_new_block(struct dnode_of_data *);
int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
Expand Down
7 changes: 3 additions & 4 deletions fs/f2fs/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ int f2fs_read_inline_data(struct inode *inode, struct page *page)
int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
{
void *src_addr, *dst_addr;
block_t new_blk_addr;
struct f2fs_io_info fio = {
.type = DATA,
.rw = WRITE_SYNC | REQ_PRIO,
Expand Down Expand Up @@ -115,9 +114,9 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)

/* write data page to try to make data consistent */
set_page_writeback(page);

write_data_page(page, dn, &new_blk_addr, &fio);
update_extent_cache(new_blk_addr, dn);
fio.blk_addr = dn->data_blkaddr;
write_data_page(page, dn, &fio);
update_extent_cache(fio.blk_addr, dn);
f2fs_wait_on_page_writeback(page, DATA);
if (dirty)
inode_dec_dirty_pages(dn->inode);
Expand Down
14 changes: 10 additions & 4 deletions fs/f2fs/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ static int read_node_page(struct page *page, int rw)
{
struct f2fs_sb_info *sbi = F2FS_P_SB(page);
struct node_info ni;
struct f2fs_io_info fio = {
.type = NODE,
.rw = rw,
};

get_node_info(sbi, page->index, &ni);

Expand All @@ -988,7 +992,8 @@ static int read_node_page(struct page *page, int rw)
if (PageUptodate(page))
return LOCKED_PAGE;

return f2fs_submit_page_bio(sbi, page, ni.blk_addr, rw);
fio.blk_addr = ni.blk_addr;
return f2fs_submit_page_bio(sbi, page, &fio);
}

/*
Expand Down Expand Up @@ -1271,7 +1276,6 @@ static int f2fs_write_node_page(struct page *page,
{
struct f2fs_sb_info *sbi = F2FS_P_SB(page);
nid_t nid;
block_t new_addr;
struct node_info ni;
struct f2fs_io_info fio = {
.type = NODE,
Expand Down Expand Up @@ -1306,9 +1310,11 @@ static int f2fs_write_node_page(struct page *page,
} else {
down_read(&sbi->node_write);
}

set_page_writeback(page);
write_node_page(sbi, page, &fio, nid, ni.blk_addr, &new_addr);
set_node_addr(sbi, &ni, new_addr, is_fsync_dnode(page));
fio.blk_addr = ni.blk_addr;
write_node_page(sbi, page, nid, &fio);
set_node_addr(sbi, &ni, fio.blk_addr, is_fsync_dnode(page));
dec_page_count(sbi, F2FS_DIRTY_NODES);
up_read(&sbi->node_write);
unlock_page(page);
Expand Down
Loading

0 comments on commit fc5e466

Please sign in to comment.