From: Chao Yu <yuchao0@huawei.com>
To: <jaegeuk@kernel.org>
Cc: <linux-f2fs-devel@lists.sourceforge.net>,
<linux-kernel@vger.kernel.org>, <chao@kernel.org>,
Chao Yu <yuchao0@huawei.com>
Subject: [PATCH 3/3] f2fs: wait IO writeback in commit_inmem_pages()
Date: Mon, 23 Apr 2018 10:36:15 +0800 [thread overview]
Message-ID: <20180423023615.33247-3-yuchao0@huawei.com> (raw)
In-Reply-To: <20180423023615.33247-1-yuchao0@huawei.com>
Thread A Thread B
- f2fs_ioc_commit_atomic_write
- commit_inmem_pages
- f2fs_submit_merged_write_cond
: write data
- write_checkpoint
- do_checkpoint
: commit all node within CP
-> SPO
- f2fs_do_sync_file
- file_write_and_wait_range
: wait data writeback
In above race condition, data/node can be flushed in reversed order when
coming a checkpoint before f2fs_do_sync_file, after SPOR, it results in
atomic written data being corrupted.
This patch adds filemap_fdatawait() in commit_inmem_pages() to keep data
and node of atomic file being flushed orderly.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/file.c | 21 ++++++++++++---------
fs/f2fs/segment.c | 2 ++
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 5d710f7f2684..4ea418cbd189 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -217,15 +217,18 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
trace_f2fs_sync_file_enter(inode);
- /* if fdatasync is triggered, let's do in-place-update */
- if (datasync || get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks)
- set_inode_flag(inode, FI_NEED_IPU);
- ret = file_write_and_wait_range(file, start, end);
- clear_inode_flag(inode, FI_NEED_IPU);
-
- if (ret) {
- trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret);
- return ret;
+ if (!atomic) {
+ /* if fdatasync is triggered, let's do in-place-update */
+ if (datasync || get_dirty_pages(inode) <=
+ SM_I(sbi)->min_fsync_blocks)
+ set_inode_flag(inode, FI_NEED_IPU);
+ ret = file_write_and_wait_range(file, start, end);
+ clear_inode_flag(inode, FI_NEED_IPU);
+
+ if (ret) {
+ trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret);
+ return ret;
+ }
}
/* if the inode is dirty, let's recover all the time */
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index dcb4fcb8b1b0..3b66c4aa04a6 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -420,6 +420,8 @@ static int __commit_inmem_pages(struct inode *inode)
__revoke_inmem_pages(inode, &fi->inmem_pages, true, false);
} else {
__revoke_inmem_pages(inode, &revoke_list, false, false);
+
+ err = filemap_fdatawait(inode->i_mapping);
}
return err;
--
2.15.0.55.gc2ece9dc4de6
next prev parent reply other threads:[~2018-04-23 2:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-23 2:36 [PATCH 1/3] f2fs: fix to wait page writeback during revoking atomic write Chao Yu
2018-04-23 2:36 ` [PATCH 2/3] f2fs: clean up commit_inmem_pages() Chao Yu
2018-04-23 2:36 ` Chao Yu [this message]
2018-04-23 15:01 ` [PATCH 3/3] f2fs: wait IO writeback in commit_inmem_pages() Jaegeuk Kim
2018-05-18 1:26 ` [PATCH 1/3] f2fs: fix to wait page writeback during revoking atomic write Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180423023615.33247-3-yuchao0@huawei.com \
--to=yuchao0@huawei.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®