linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Fan Li <fanofcode.li@samsung.com>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH] f2fs: fix to update cached_en of extent tree properly
Date: Tue, 18 Aug 2015 17:13:13 +0800	[thread overview]
Message-ID: <005101d0d996$3ab708a0$b02519e0$@samsung.com> (raw)

In f2fs_lookup_extent_tree, et->cached_en was read and updated with only
read lock held, 
it could cause __lookup_extent_tree within return entirely wrong
extent_node, if other 
thread update et->cached_en just before __lookup_extent_tree return.

However, there are two things about this patch that need to be noticed:
1. It does no good to arrange the order of concurrent read/write, the result
would still 
be random in such case.
2. It's built on this assumption: the mix up of reads and writes on a single
pointer would 
not make the pointer partially wrong at any time. Please let me know if I'm
wrong, thx.


Signed-off-by: Fan li <fanofcode.li@samsung.com>
---
 fs/f2fs/extent_cache.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index
32fae8a..cea5813 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -85,13 +85,13 @@ static struct extent_node *__lookup_extent_tree(struct
extent_tree *et,
 							unsigned int fofs)
 {
 	struct rb_node *node = et->root.rb_node;
-	struct extent_node *en;
+	struct extent_node *en = et->cached_en;
 
-	if (et->cached_en) {
-		struct extent_info *cei = &et->cached_en->ei;
+	if (en) {
+		struct extent_info *cei = &en->ei;
 
 		if (cei->fofs <= fofs && cei->fofs + cei->len > fofs)
-			return et->cached_en;
+			return en;
 	}
 
 	while (node) {
--
1.7.9.5


------------------------------------------------------------------------------

             reply	other threads:[~2015-08-18  9:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18  9:13 Fan Li [this message]
2015-08-21 12:50 ` [PATCH] f2fs: fix to update cached_en of extent tree properly 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='005101d0d996$3ab708a0$b02519e0$@samsung.com' \
    --to=fanofcode.li@samsung.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /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).