aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs
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
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')
-rw-r--r--fs/f2fs/checkpoint.c4
-rw-r--r--fs/f2fs/data.c18
-rw-r--r--fs/f2fs/file.c4
-rw-r--r--fs/f2fs/node.c20
4 files changed, 39 insertions, 7 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 590ea50c80a7..b1de01da1a40 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -65,6 +65,10 @@ repeat:
65 goto repeat; 65 goto repeat;
66 66
67 lock_page(page); 67 lock_page(page);
68 if (page->mapping != mapping) {
69 f2fs_put_page(page, 1);
70 goto repeat;
71 }
68out: 72out:
69 mark_page_accessed(page); 73 mark_page_accessed(page);
70 return page; 74 return page;
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index eba7e84d1ffd..2db9380f5dda 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -240,7 +240,7 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
240 240
241 if (dn.data_blkaddr == NULL_ADDR) 241 if (dn.data_blkaddr == NULL_ADDR)
242 return ERR_PTR(-ENOENT); 242 return ERR_PTR(-ENOENT);
243 243repeat:
244 page = grab_cache_page(mapping, index); 244 page = grab_cache_page(mapping, index);
245 if (!page) 245 if (!page)
246 return ERR_PTR(-ENOMEM); 246 return ERR_PTR(-ENOMEM);
@@ -260,6 +260,10 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
260 f2fs_put_page(page, 1); 260 f2fs_put_page(page, 1);
261 return ERR_PTR(-EIO); 261 return ERR_PTR(-EIO);
262 } 262 }
263 if (page->mapping != mapping) {
264 f2fs_put_page(page, 1);
265 goto repeat;
266 }
263 return page; 267 return page;
264} 268}
265 269
@@ -291,7 +295,7 @@ struct page *get_new_data_page(struct inode *inode, pgoff_t index,
291 } 295 }
292 } 296 }
293 f2fs_put_dnode(&dn); 297 f2fs_put_dnode(&dn);
294 298repeat:
295 page = grab_cache_page(mapping, index); 299 page = grab_cache_page(mapping, index);
296 if (!page) 300 if (!page)
297 return ERR_PTR(-ENOMEM); 301 return ERR_PTR(-ENOMEM);
@@ -311,6 +315,10 @@ struct page *get_new_data_page(struct inode *inode, pgoff_t index,
311 f2fs_put_page(page, 1); 315 f2fs_put_page(page, 1);
312 return ERR_PTR(-EIO); 316 return ERR_PTR(-EIO);
313 } 317 }
318 if (page->mapping != mapping) {
319 f2fs_put_page(page, 1);
320 goto repeat;
321 }
314 } 322 }
315 323
316 if (new_i_size && 324 if (new_i_size &&
@@ -611,7 +619,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
611 *fsdata = NULL; 619 *fsdata = NULL;
612 620
613 f2fs_balance_fs(sbi); 621 f2fs_balance_fs(sbi);
614 622repeat:
615 page = grab_cache_page_write_begin(mapping, index, flags); 623 page = grab_cache_page_write_begin(mapping, index, flags);
616 if (!page) 624 if (!page)
617 return -ENOMEM; 625 return -ENOMEM;
@@ -656,6 +664,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
656 f2fs_put_page(page, 1); 664 f2fs_put_page(page, 1);
657 return -EIO; 665 return -EIO;
658 } 666 }
667 if (page->mapping != mapping) {
668 f2fs_put_page(page, 1);
669 goto repeat;
670 }
659 } 671 }
660out: 672out:
661 SetPageUptodate(page); 673 SetPageUptodate(page);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 9dfcdab5ea7c..3e2c2cbc500c 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -217,6 +217,10 @@ static void truncate_partial_data_page(struct inode *inode, u64 from)
217 return; 217 return;
218 218
219 lock_page(page); 219 lock_page(page);
220 if (page->mapping != inode->i_mapping) {
221 f2fs_put_page(page, 1);
222 return;
223 }
220 wait_on_page_writeback(page); 224 wait_on_page_writeback(page);
221 zero_user(page, offset, PAGE_CACHE_SIZE - offset); 225 zero_user(page, offset, PAGE_CACHE_SIZE - offset);
222 set_page_dirty(page); 226 set_page_dirty(page);
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);