From: Shifei Ge <shifei10.ge@samsung.com>
To: jaegeuk.kim@samsung.com
Cc: ?? <shu.tan@samsung.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] f2fs:fix truncate_partial_nodes bug
Date: Mon, 28 Oct 2013 08:15:17 +0000 (GMT) [thread overview]
Message-ID: <27929860.72301382948116848.JavaMail.weblogic@epml07> (raw)
truncate_partial_nodes puts pages incorrectly in two cases.note that the value for argc 'depth' can only be 2 or 3(see truncate_inode_blocks --->truncate_partial_nodes ).
first case:err happened in the first 'for' loop
assume depth is 2,when err happened,pages[0] is invalid,so this page don't need to be put when func return,there is no problem.
but when depth is 3 ,pages isn't put correctly when pages[0] is valid and pages[1] is invalid.in this case,depth is set to 2(ref to statemnt depth = i + 1) ,and then 'goto fail'.
in label 'fail', for (i = depth - 3; i >= 0; i--) cann't meet the condition because i=-1,so pages[0] cann't be put when func return.
second case:err happened in the second 'for' loop
now,we've got pages[0] with argc 'depth' is 2 ,or we've got pages[0] and pages[1] with depth is 3.when err happend,we need 'goto fail' to put pages we've got.
when depth is 2,in label 'fail',for (i = depth - 3; i >= 0; i--) cann't meet the condition because i=-1,so pages[0] cann't be put.
when depth is 3,in label 'fail',for (i = depth - 3; i >= 0; i--) can only put pages[0],pages[1] also cann't be put.
notes 'depth' has been changed before first 'goto fail'(ref to statemnt depth = i + 1),so pass this modified 'depth' to trace_f2fs_truncate_partial_nodes is also incorrectly.
From 9de8efa31759ce86a032f5ad092d337b686ede06 Mon Sep 17 00:00:00 2001
Signed-off-by: Shifei Ge <shifei10.ge@samsung.com>
---
fs/f2fs/node.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 304d5ce..9986930 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -625,6 +625,7 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
int err = 0;
int i;
int idx = depth - 2;
+ int dep = depth;
nid[0] = le32_to_cpu(ri->i_nid[offset[0] - NODE_DIR1_BLOCK]);
if (!nid[0])
@@ -663,11 +664,12 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
}
offset[idx]++;
offset[depth - 1] = 0;
+ depth--;
fail:
- for (i = depth - 3; i >= 0; i--)
+ for (i = depth - 2; i >= 0; i--)
f2fs_put_page(pages[i], 1);
- trace_f2fs_truncate_partial_nodes(dn->inode, nid, depth, err);
+ trace_f2fs_truncate_partial_nodes(dn->inode, nid, dep, err);
return err;
}
--
1.7.9.5
next reply other threads:[~2013-10-28 8:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-28 8:15 Shifei Ge [this message]
2013-10-28 10:21 ` [f2fs-dev] [PATCH] f2fs:fix truncate_partial_nodes bug Jaegeuk Kim
2013-10-29 7:32 ` shifei10.ge
2013-10-29 7:43 ` Jaegeuk Kim
2013-10-29 8:07 ` shifei10.ge
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=27929860.72301382948116848.JavaMail.weblogic@epml07 \
--to=shifei10.ge@samsung.com \
--cc=jaegeuk.kim@samsung.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shu.tan@samsung.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).