Skip to contentSkip to conversation

f2fs: fix to update cached_en of extent tree properly

PATCH In review Fan Li 2 participants 2 messages Aug 18, 2015 – Aug 21, 2015 F2FS file system

lore
Share & tools
lore

Fan Li

author
#0 lore raw

PATCH 1/1 f2fs: fix to update cached_en of extent tree properly

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.

---
 fs/f2fs/extent_cache.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/extent_cache.c index renamed from fs/f2fs/extent_cache.c +0 -0

32fae8a..cea5813 100644

fs/f2fs/extent_cache.c +0 -0
@@ -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

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