Skip to content

Commit

Permalink
f2fs: fix unlocked nat set cache operation
Browse files Browse the repository at this point in the history
nm_i->nat_tree_lock is used to sync both the operations of nat entry
cache tree and nat set cache tree, however, it isn't held when flush
nat entries during checkpoint which lead to potential race, this patch
fix it by holding the lock when gang lookup nat set cache and delete
item from nat set cache.

Signed-off-by: Wanpeng Li <wanpeng.li@linux.intel.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
Wanpeng Li authored and Jaegeuk Kim committed Apr 10, 2015
1 parent e015039 commit 57ed1e9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fs/f2fs/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
struct f2fs_nat_block *nat_blk;
struct nat_entry *ne, *cur;
struct page *page = NULL;
struct f2fs_nm_info *nm_i = NM_I(sbi);

/*
* there are two steps to flush nat entries:
Expand Down Expand Up @@ -1883,7 +1884,9 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,

f2fs_bug_on(sbi, set->entry_cnt);

down_write(&nm_i->nat_tree_lock);
radix_tree_delete(&NM_I(sbi)->nat_set_root, set->set);
up_write(&nm_i->nat_tree_lock);
kmem_cache_free(nat_entry_set_slab, set);
}

Expand Down Expand Up @@ -1911,6 +1914,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
if (!__has_cursum_space(sum, nm_i->dirty_nat_cnt, NAT_JOURNAL))
remove_nats_in_journal(sbi);

down_write(&nm_i->nat_tree_lock);
while ((found = __gang_lookup_nat_set(nm_i,
set_idx, SETVEC_SIZE, setvec))) {
unsigned idx;
Expand All @@ -1919,6 +1923,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
__adjust_nat_entry_set(setvec[idx], &sets,
MAX_NAT_JENTRIES(sum));
}
up_write(&nm_i->nat_tree_lock);

/* flush dirty nats in nat entry set */
list_for_each_entry_safe(set, tmp, &sets, set_list)
Expand Down

0 comments on commit 57ed1e9

Please sign in to comment.