From 7f6c853f301248b274cc6e32eaaa0dbb448d5e7e Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Sun, 3 Jul 2016 22:05:12 +0800 Subject: f2fs: fix to detect truncation prior rather than EIO during read In procedure of synchonized read, after sending out the read request, reader will try to lock the page for waiting device to finish the read jobs and unlock the page, but meanwhile, truncater will race with reader, so after reader get lock of the page, it should check page's mapping to detect whether someone has truncated the page in advance, then reader has the chance to do the retry if truncation was done, otherwise read can be failed due to previous condition check. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 16 ++++++++-------- fs/f2fs/gc.c | 4 ++-- fs/f2fs/node.c | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'fs') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index cf9cf4ed0..5687edefe 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -501,14 +501,14 @@ repeat: /* wait for read completion */ lock_page(page); - if (unlikely(!PageUptodate(page))) { - f2fs_put_page(page, 1); - return ERR_PTR(-EIO); - } if (unlikely(page->mapping != mapping)) { f2fs_put_page(page, 1); goto repeat; } + if (unlikely(!PageUptodate(page))) { + f2fs_put_page(page, 1); + return ERR_PTR(-EIO); + } return page; } @@ -1647,14 +1647,14 @@ repeat: __submit_bio(sbi, READ_SYNC, bio, DATA); lock_page(page); - if (unlikely(!PageUptodate(page))) { - err = -EIO; - goto fail; - } if (unlikely(page->mapping != mapping)) { f2fs_put_page(page, 1); goto repeat; } + if (unlikely(!PageUptodate(page))) { + err = -EIO; + goto fail; + } } out_update: SetPageUptodate(page); diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 583d6b425..2773f79dd 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -593,11 +593,11 @@ static void move_encrypted_block(struct inode *inode, block_t bidx) /* write page */ lock_page(fio.encrypted_page); - if (unlikely(!PageUptodate(fio.encrypted_page))) { + if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) { err = -EIO; goto put_page_out; } - if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) { + if (unlikely(!PageUptodate(fio.encrypted_page))) { err = -EIO; goto put_page_out; } diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 4ba312a59..a9195cb16 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1156,13 +1156,13 @@ repeat: lock_page(page); - if (unlikely(!PageUptodate(page))) - goto out_err; - if (unlikely(page->mapping != NODE_MAPPING(sbi))) { f2fs_put_page(page, 1); goto repeat; } + + if (unlikely(!PageUptodate(page))) + goto out_err; page_hit: mark_page_accessed(page); -- cgit v1.2.3