aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/node.c
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk.kim@samsung.com>2013-04-25 22:55:17 -0400
committerJaegeuk Kim <jaegeuk.kim@samsung.com>2013-04-28 22:19:32 -0400
commitafcb7ca01f47b0481e0b248d1542d0934fa70767 (patch)
tree2834b57b958d2b444d40aa8144ac60ee739507ac /fs/f2fs/node.c
parent55008d845d233396ed374473da4613cee691aa03 (diff)
f2fs: check truncation of mapping after lock_page
We call lock_page when we need to update a page after readpage. Between grab and lock page, the page can be truncated by other thread. So, we should check the page after lock_page whether it was truncated or not. Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'fs/f2fs/node.c')
-rw-r--r--fs/f2fs/node.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index aede91071f71..6ff017245522 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -674,6 +674,7 @@ fail:
674int truncate_inode_blocks(struct inode *inode, pgoff_t from) 674int truncate_inode_blocks(struct inode *inode, pgoff_t from)
675{ 675{
676 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 676 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
677 struct address_space *node_mapping = sbi->node_inode->i_mapping;
677 int err = 0, cont = 1; 678 int err = 0, cont = 1;
678 int level, offset[4], noffset[4]; 679 int level, offset[4], noffset[4];
679 unsigned int nofs = 0; 680 unsigned int nofs = 0;
@@ -684,7 +685,7 @@ int truncate_inode_blocks(struct inode *inode, pgoff_t from)
684 trace_f2fs_truncate_inode_blocks_enter(inode, from); 685 trace_f2fs_truncate_inode_blocks_enter(inode, from);
685 686
686 level = get_node_path(from, offset, noffset); 687 level = get_node_path(from, offset, noffset);
687 688restart:
688 page = get_node_page(sbi, inode->i_ino); 689 page = get_node_page(sbi, inode->i_ino);
689 if (IS_ERR(page)) { 690 if (IS_ERR(page)) {
690 trace_f2fs_truncate_inode_blocks_exit(inode, PTR_ERR(page)); 691 trace_f2fs_truncate_inode_blocks_exit(inode, PTR_ERR(page));
@@ -748,6 +749,10 @@ skip_partial:
748 if (offset[1] == 0 && 749 if (offset[1] == 0 &&
749 rn->i.i_nid[offset[0] - NODE_DIR1_BLOCK]) { 750 rn->i.i_nid[offset[0] - NODE_DIR1_BLOCK]) {
750 lock_page(page); 751 lock_page(page);
752 if (page->mapping != node_mapping) {
753 f2fs_put_page(page, 1);
754 goto restart;
755 }
751 wait_on_page_writeback(page); 756 wait_on_page_writeback(page);
752 rn->i.i_nid[offset[0] - NODE_DIR1_BLOCK] = 0; 757 rn->i.i_nid[offset[0] - NODE_DIR1_BLOCK] = 0;
753 set_page_dirty(page); 758 set_page_dirty(page);
@@ -916,7 +921,7 @@ struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
916 struct address_space *mapping = sbi->node_inode->i_mapping; 921 struct address_space *mapping = sbi->node_inode->i_mapping;
917 struct page *page; 922 struct page *page;
918 int err; 923 int err;
919 924repeat:
920 page = grab_cache_page(mapping, nid); 925 page = grab_cache_page(mapping, nid);
921 if (!page) 926 if (!page)
922 return ERR_PTR(-ENOMEM); 927 return ERR_PTR(-ENOMEM);
@@ -932,6 +937,10 @@ struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
932 f2fs_put_page(page, 1); 937 f2fs_put_page(page, 1);
933 return ERR_PTR(-EIO); 938 return ERR_PTR(-EIO);
934 } 939 }
940 if (page->mapping != mapping) {
941 f2fs_put_page(page, 1);
942 goto repeat;
943 }
935got_it: 944got_it:
936 BUG_ON(nid != nid_of_node(page)); 945 BUG_ON(nid != nid_of_node(page));
937 mark_page_accessed(page); 946 mark_page_accessed(page);
@@ -955,7 +964,7 @@ struct page *get_node_page_ra(struct page *parent, int start)
955 nid = get_nid(parent, start, false); 964 nid = get_nid(parent, start, false);
956 if (!nid) 965 if (!nid)
957 return ERR_PTR(-ENOENT); 966 return ERR_PTR(-ENOENT);
958 967repeat:
959 page = grab_cache_page(mapping, nid); 968 page = grab_cache_page(mapping, nid);
960 if (!page) 969 if (!page)
961 return ERR_PTR(-ENOMEM); 970 return ERR_PTR(-ENOMEM);
@@ -981,7 +990,10 @@ struct page *get_node_page_ra(struct page *parent, int start)
981 blk_finish_plug(&plug); 990 blk_finish_plug(&plug);
982 991
983 lock_page(page); 992 lock_page(page);
984 993 if (page->mapping != mapping) {
994 f2fs_put_page(page, 1);
995 goto repeat;
996 }
985page_hit: 997page_hit:
986 if (!PageUptodate(page)) { 998 if (!PageUptodate(page)) {
987 f2fs_put_page(page, 1); 999 f2fs_put_page(page, 1);