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] f2fs: protect free nid operation with cp_rwsem
Date: Fri, 17 Mar 2017 18:46:23 +0800 [thread overview]
Message-ID: <20170317104623.90116-1-yuchao0@huawei.com> (raw)
- f2fs_balance_fs_bg
- build_free_nids
- __build_free_nids
- scan_nat_page
- add_free_nid
- f2fs_create
- f2fs_new_inode
- alloc_nid
- remove_free_nid
This patch uses cp_rwsem to protect free nid allocation/initialization
to avoid reusing allocated nid in above scenario.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/inode.c | 2 ++
fs/f2fs/segment.c | 5 ++++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 2520fa72b23f..f941410f994a 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -423,7 +423,9 @@ void f2fs_evict_inode(struct inode *inode)
add_ino_entry(sbi, inode->i_ino, UPDATE_INO);
}
if (is_inode_flag_set(inode, FI_FREE_NID)) {
+ f2fs_lock_op(sbi);
alloc_nid_failed(sbi, inode->i_ino);
+ f2fs_unlock_op(sbi);
clear_inode_flag(inode, FI_FREE_NID);
}
f2fs_bug_on(sbi, err &&
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 0bf024f62330..f85e1f443c99 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -426,8 +426,11 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
if (!available_free_memory(sbi, FREE_NIDS))
try_to_free_nids(sbi, MAX_FREE_NIDS);
- else
+ else {
+ f2fs_lock_op(sbi);
build_free_nids(sbi, false, false);
+ f2fs_unlock_op(sbi);
+ }
if (!is_idle(sbi))
return;
--
2.8.2.295.g3f1c1d0
next reply other threads:[~2017-03-17 10:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-17 10:46 Chao Yu [this message]
2017-03-19 22:44 ` Jaegeuk Kim
2017-03-20 11:06 ` 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=20170317104623.90116-1-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®