From: Sahitya Tummala <stummala@codeaurora.org>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <yuchao0@huawei.com>,
linux-f2fs-devel@lists.sourceforge.net
Cc: Sahitya Tummala <stummala@codeaurora.org>, linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] f2fs: fix race between online resize path and allocate new data block path
Date: Tue, 9 Apr 2019 16:06:17 +0530 [thread overview]
Message-ID: <1554806178-32728-3-git-send-email-stummala@codeaurora.org> (raw)
In-Reply-To: <1554806178-32728-1-git-send-email-stummala@codeaurora.org>
There can be a potential race between allocate_segment_for_resize() and
allocate_data_block(), resulting into two issues -
1. The allocate_data_block() can get a data block from a segment which
is currently being resized. This results in data being updated in an
outdated or already resized segment.
2. It also results into these warnings from get_new_segment():
f2fs_bug_on(sbi, secno >= NEW_MAIN_SECS(sbi));
Fix these by using curseg_mutex lock in the resize context to prevent
race with allocate_data_block() path.
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
---
fs/f2fs/segment.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 1c3cc30..e7c411f 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2643,12 +2643,14 @@ void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type)
struct curseg_info *curseg = CURSEG_I(sbi, type);
unsigned int old_segno = curseg->segno;
+ mutex_lock(&curseg->curseg_mutex);
if (f2fs_need_SSR(sbi) && get_ssr_segment(sbi, type))
change_curseg(sbi, type);
else
new_curseg(sbi, type, true);
stat_inc_seg_type(sbi, curseg);
+ mutex_unlock(&curseg->curseg_mutex);
if (get_valid_blocks(sbi, old_segno, false) == 0)
__set_test_and_free(sbi, old_segno);
--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
next prev parent reply other threads:[~2019-04-09 10:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-09 10:36 [PATCH 1/4] f2fs: add F2FS_IOC_RESIZE_FROM_END for compat_ioctl Sahitya Tummala
2019-04-09 10:36 ` [PATCH 2/4] f2fs: fix debugfs status to reflect the online resize changes Sahitya Tummala
2019-04-09 10:36 ` Sahitya Tummala [this message]
2019-04-09 10:36 ` [PATCH 4/4] f2fs: fix potential race between online resize path and gc path Sahitya Tummala
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=1554806178-32728-3-git-send-email-stummala@codeaurora.org \
--to=stummala@codeaurora.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=yuchao0@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).