Commit 4ef51a8f authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: introduce NODE_MAPPING for code consistency

This patch adds NODE_MAPPING which is similar as META_MAPPING introduced by
Gu Zheng.

Cc: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
parent 63f5384c
...@@ -771,7 +771,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) ...@@ -771,7 +771,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
/* wait for previous submitted node/meta pages writeback */ /* wait for previous submitted node/meta pages writeback */
wait_on_all_pages_writeback(sbi); wait_on_all_pages_writeback(sbi);
filemap_fdatawait_range(sbi->node_inode->i_mapping, 0, LONG_MAX); filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LONG_MAX);
filemap_fdatawait_range(META_MAPPING(sbi), 0, LONG_MAX); filemap_fdatawait_range(META_MAPPING(sbi), 0, LONG_MAX);
/* update user_block_counts */ /* update user_block_counts */
......
...@@ -52,7 +52,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) ...@@ -52,7 +52,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
si->free_secs = free_sections(sbi); si->free_secs = free_sections(sbi);
si->prefree_count = prefree_segments(sbi); si->prefree_count = prefree_segments(sbi);
si->dirty_count = dirty_segments(sbi); si->dirty_count = dirty_segments(sbi);
si->node_pages = sbi->node_inode->i_mapping->nrpages; si->node_pages = NODE_MAPPING(sbi)->nrpages;
si->meta_pages = META_MAPPING(sbi)->nrpages; si->meta_pages = META_MAPPING(sbi)->nrpages;
si->nats = NM_I(sbi)->nat_cnt; si->nats = NM_I(sbi)->nat_cnt;
si->sits = SIT_I(sbi)->dirty_sentries; si->sits = SIT_I(sbi)->dirty_sentries;
...@@ -166,7 +166,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) ...@@ -166,7 +166,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
/* free nids */ /* free nids */
si->cache_mem = NM_I(sbi)->fcnt; si->cache_mem = NM_I(sbi)->fcnt;
si->cache_mem += NM_I(sbi)->nat_cnt; si->cache_mem += NM_I(sbi)->nat_cnt;
npages = sbi->node_inode->i_mapping->nrpages; npages = NODE_MAPPING(sbi)->nrpages;
si->cache_mem += npages << PAGE_CACHE_SHIFT; si->cache_mem += npages << PAGE_CACHE_SHIFT;
npages = META_MAPPING(sbi)->nrpages; npages = META_MAPPING(sbi)->nrpages;
si->cache_mem += npages << PAGE_CACHE_SHIFT; si->cache_mem += npages << PAGE_CACHE_SHIFT;
......
...@@ -538,6 +538,11 @@ static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) ...@@ -538,6 +538,11 @@ static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
return sbi->meta_inode->i_mapping; return sbi->meta_inode->i_mapping;
} }
static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
{
return sbi->node_inode->i_mapping;
}
static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi) static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
{ {
sbi->s_dirty = 1; sbi->s_dirty = 1;
......
...@@ -681,7 +681,6 @@ static int truncate_partial_nodes(struct dnode_of_data *dn, ...@@ -681,7 +681,6 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
int truncate_inode_blocks(struct inode *inode, pgoff_t from) int truncate_inode_blocks(struct inode *inode, pgoff_t from)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct address_space *node_mapping = sbi->node_inode->i_mapping;
int err = 0, cont = 1; int err = 0, cont = 1;
int level, offset[4], noffset[4]; int level, offset[4], noffset[4];
unsigned int nofs = 0; unsigned int nofs = 0;
...@@ -756,7 +755,7 @@ int truncate_inode_blocks(struct inode *inode, pgoff_t from) ...@@ -756,7 +755,7 @@ int truncate_inode_blocks(struct inode *inode, pgoff_t from)
if (offset[1] == 0 && if (offset[1] == 0 &&
ri->i_nid[offset[0] - NODE_DIR1_BLOCK]) { ri->i_nid[offset[0] - NODE_DIR1_BLOCK]) {
lock_page(page); lock_page(page);
if (unlikely(page->mapping != node_mapping)) { if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
goto restart; goto restart;
} }
...@@ -842,7 +841,6 @@ struct page *new_node_page(struct dnode_of_data *dn, ...@@ -842,7 +841,6 @@ struct page *new_node_page(struct dnode_of_data *dn,
unsigned int ofs, struct page *ipage) unsigned int ofs, struct page *ipage)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(dn->inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(dn->inode->i_sb);
struct address_space *mapping = sbi->node_inode->i_mapping;
struct node_info old_ni, new_ni; struct node_info old_ni, new_ni;
struct page *page; struct page *page;
int err; int err;
...@@ -850,7 +848,7 @@ struct page *new_node_page(struct dnode_of_data *dn, ...@@ -850,7 +848,7 @@ struct page *new_node_page(struct dnode_of_data *dn,
if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC))) if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC)))
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
page = grab_cache_page(mapping, dn->nid); page = grab_cache_page(NODE_MAPPING(sbi), dn->nid);
if (!page) if (!page)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -920,18 +918,17 @@ static int read_node_page(struct page *page, int rw) ...@@ -920,18 +918,17 @@ static int read_node_page(struct page *page, int rw)
*/ */
void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid) void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid)
{ {
struct address_space *mapping = sbi->node_inode->i_mapping;
struct page *apage; struct page *apage;
int err; int err;
apage = find_get_page(mapping, nid); apage = find_get_page(NODE_MAPPING(sbi), nid);
if (apage && PageUptodate(apage)) { if (apage && PageUptodate(apage)) {
f2fs_put_page(apage, 0); f2fs_put_page(apage, 0);
return; return;
} }
f2fs_put_page(apage, 0); f2fs_put_page(apage, 0);
apage = grab_cache_page(mapping, nid); apage = grab_cache_page(NODE_MAPPING(sbi), nid);
if (!apage) if (!apage)
return; return;
...@@ -944,11 +941,10 @@ void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid) ...@@ -944,11 +941,10 @@ void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid)
struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
{ {
struct address_space *mapping = sbi->node_inode->i_mapping;
struct page *page; struct page *page;
int err; int err;
repeat: repeat:
page = grab_cache_page(mapping, nid); page = grab_cache_page(NODE_MAPPING(sbi), nid);
if (!page) if (!page)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -963,7 +959,7 @@ struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) ...@@ -963,7 +959,7 @@ struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
if (unlikely(page->mapping != mapping)) { if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
goto repeat; goto repeat;
} }
...@@ -980,7 +976,6 @@ struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) ...@@ -980,7 +976,6 @@ struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
struct page *get_node_page_ra(struct page *parent, int start) struct page *get_node_page_ra(struct page *parent, int start)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(parent->mapping->host->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(parent->mapping->host->i_sb);
struct address_space *mapping = sbi->node_inode->i_mapping;
struct blk_plug plug; struct blk_plug plug;
struct page *page; struct page *page;
int err, i, end; int err, i, end;
...@@ -991,7 +986,7 @@ struct page *get_node_page_ra(struct page *parent, int start) ...@@ -991,7 +986,7 @@ struct page *get_node_page_ra(struct page *parent, int start)
if (!nid) if (!nid)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
repeat: repeat:
page = grab_cache_page(mapping, nid); page = grab_cache_page(NODE_MAPPING(sbi), nid);
if (!page) if (!page)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -1016,7 +1011,7 @@ struct page *get_node_page_ra(struct page *parent, int start) ...@@ -1016,7 +1011,7 @@ struct page *get_node_page_ra(struct page *parent, int start)
blk_finish_plug(&plug); blk_finish_plug(&plug);
lock_page(page); lock_page(page);
if (unlikely(page->mapping != mapping)) { if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
goto repeat; goto repeat;
} }
...@@ -1047,7 +1042,6 @@ void sync_inode_page(struct dnode_of_data *dn) ...@@ -1047,7 +1042,6 @@ void sync_inode_page(struct dnode_of_data *dn)
int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino, int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
struct writeback_control *wbc) struct writeback_control *wbc)
{ {
struct address_space *mapping = sbi->node_inode->i_mapping;
pgoff_t index, end; pgoff_t index, end;
struct pagevec pvec; struct pagevec pvec;
int step = ino ? 2 : 0; int step = ino ? 2 : 0;
...@@ -1061,7 +1055,7 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino, ...@@ -1061,7 +1055,7 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
while (index <= end) { while (index <= end) {
int i, nr_pages; int i, nr_pages;
nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
PAGECACHE_TAG_DIRTY, PAGECACHE_TAG_DIRTY,
min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1); min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
if (nr_pages == 0) if (nr_pages == 0)
...@@ -1094,7 +1088,7 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino, ...@@ -1094,7 +1088,7 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
else if (!trylock_page(page)) else if (!trylock_page(page))
continue; continue;
if (unlikely(page->mapping != mapping)) { if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
continue_unlock: continue_unlock:
unlock_page(page); unlock_page(page);
continue; continue;
...@@ -1121,7 +1115,7 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino, ...@@ -1121,7 +1115,7 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
set_fsync_mark(page, 0); set_fsync_mark(page, 0);
set_dentry_mark(page, 0); set_dentry_mark(page, 0);
} }
mapping->a_ops->writepage(page, wbc); NODE_MAPPING(sbi)->a_ops->writepage(page, wbc);
wrote++; wrote++;
if (--wbc->nr_to_write == 0) if (--wbc->nr_to_write == 0)
...@@ -1148,18 +1142,19 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino, ...@@ -1148,18 +1142,19 @@ int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino) int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino)
{ {
struct address_space *mapping = sbi->node_inode->i_mapping;
pgoff_t index = 0, end = LONG_MAX; pgoff_t index = 0, end = LONG_MAX;
struct pagevec pvec; struct pagevec pvec;
int nr_pages;
int ret2 = 0, ret = 0; int ret2 = 0, ret = 0;
pagevec_init(&pvec, 0); pagevec_init(&pvec, 0);
while ((index <= end) &&
(nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, while (index <= end) {
int i, nr_pages;
nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
PAGECACHE_TAG_WRITEBACK, PAGECACHE_TAG_WRITEBACK,
min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1)) != 0) { min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
unsigned i; if (nr_pages == 0)
break;
for (i = 0; i < nr_pages; i++) { for (i = 0; i < nr_pages; i++) {
struct page *page = pvec.pages[i]; struct page *page = pvec.pages[i];
...@@ -1178,9 +1173,9 @@ int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino) ...@@ -1178,9 +1173,9 @@ int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino)
cond_resched(); cond_resched();
} }
if (unlikely(test_and_clear_bit(AS_ENOSPC, &mapping->flags))) if (unlikely(test_and_clear_bit(AS_ENOSPC, &NODE_MAPPING(sbi)->flags)))
ret2 = -ENOSPC; ret2 = -ENOSPC;
if (unlikely(test_and_clear_bit(AS_EIO, &mapping->flags))) if (unlikely(test_and_clear_bit(AS_EIO, &NODE_MAPPING(sbi)->flags)))
ret2 = -EIO; ret2 = -EIO;
if (!ret) if (!ret)
ret = ret2; ret = ret2;
...@@ -1538,13 +1533,12 @@ void recover_node_page(struct f2fs_sb_info *sbi, struct page *page, ...@@ -1538,13 +1533,12 @@ void recover_node_page(struct f2fs_sb_info *sbi, struct page *page,
int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
{ {
struct address_space *mapping = sbi->node_inode->i_mapping;
struct f2fs_inode *src, *dst; struct f2fs_inode *src, *dst;
nid_t ino = ino_of_node(page); nid_t ino = ino_of_node(page);
struct node_info old_ni, new_ni; struct node_info old_ni, new_ni;
struct page *ipage; struct page *ipage;
ipage = grab_cache_page(mapping, ino); ipage = grab_cache_page(NODE_MAPPING(sbi), ino);
if (!ipage) if (!ipage)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment