From: Yunlei He <heyunlei@huawei.com>
To: jaegeuk@kernel.org, yuchao0@huawei.com,
linux-f2fs-devel@lists.sourceforge.net
Cc: ning.jia@huawei.com, heyunlei@huawei.com
Subject: [PATCH] f2fs: check block reserve strictly a little bit
Date: Tue, 7 Nov 2017 17:56:50 +0800 [thread overview]
Message-ID: <1510048610-17771-1-git-send-email-heyunlei@huawei.com> (raw)
This patch check new block reserve strictly, in case of
garbage data of node page.
Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
fs/f2fs/data.c | 9 +++++++--
fs/f2fs/file.c | 13 +++++--------
fs/f2fs/segment.c | 1 +
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index b0781ed..3017a87 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -558,13 +558,18 @@ int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)
f2fs_wait_on_page_writeback(dn->node_page, NODE, true);
- for (; count > 0; dn->ofs_in_node++) {
+ for (; count > 0; dn->ofs_in_node++, count--) {
block_t blkaddr = datablock_addr(dn->inode,
dn->node_page, dn->ofs_in_node);
if (blkaddr == NULL_ADDR) {
dn->data_blkaddr = NEW_ADDR;
__set_data_blkaddr(dn);
- count--;
+ } else {
+ f2fs_msg(sbi->sb, KERN_ERR, "reserve non NULL block, "
+ "blkaddr:%u, ino:%lu, nid:%u, ofs_in_node:%u",
+ blkaddr, dn->inode->i_ino, dn->nid,
+ dn->ofs_in_node);
+ f2fs_bug_on(sbi, 1);
}
}
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index cee0f36..dfc23c2 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1218,19 +1218,16 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
pgoff_t index = start;
unsigned int ofs_in_node = dn->ofs_in_node;
- blkcnt_t count = 0;
- int ret;
+ int ret = 0;
for (; index < end; index++, dn->ofs_in_node++) {
if (datablock_addr(dn->inode, dn->node_page,
dn->ofs_in_node) == NULL_ADDR)
- count++;
- }
+ ret = reserve_new_blocks(dn, 1);
- dn->ofs_in_node = ofs_in_node;
- ret = reserve_new_blocks(dn, count);
- if (ret)
- return ret;
+ if (ret)
+ return ret;
+ }
dn->ofs_in_node = ofs_in_node;
for (index = start; index < end; index++, dn->ofs_in_node++) {
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 20722b2..e670967 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1815,6 +1815,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
bool mir_exist;
#endif
+ verify_block_addr(sbi, blkaddr);
segno = GET_SEGNO(sbi, blkaddr);
se = get_seg_entry(sbi, segno);
--
1.9.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
next reply other threads:[~2017-11-07 10:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-07 9:56 Yunlei He [this message]
2017-11-09 17:55 ` [PATCH] f2fs: check block reserve strictly a little bit Jaegeuk Kim
2017-11-10 2:30 ` heyunlei
2017-11-10 19:55 ` Jaegeuk Kim
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=1510048610-17771-1-git-send-email-heyunlei@huawei.com \
--to=heyunlei@huawei.com \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=ning.jia@huawei.com \
--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).