Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nilfs2: ensure proper cache clearing for gc-inodes

A gc-inode is a pseudo inode used to buffer the blocks to be moved by
garbage collection.

Block caches of gc-inodes must be cleared every time a garbage collection
function (nilfs_clean_segments) completes. Otherwise, stale blocks
buffered in the caches may be wrongly reused in successive calls of the GC
function.

For user files, this is not a problem because their gc-inodes are
distinguished by a checkpoint number as well as an inode number. They
never buffer different blocks if either an inode number, a checkpoint
number, or a block offset differs.

However, gc-inodes of sufile, cpfile and DAT file can store different data
for the same block offset. Thus, the nilfs_clean_segments function can
move incorrect block for these meta-data files if an old block is cached.
I found this is really causing meta-data corruption in nilfs.

This fixes the issue by ensuring cache clear of gc-inodes and resolves
reported GC problems including checkpoint file corruption, b-tree
corruption, and the following warning during GC.

nilfs_palloc_freev: entry number 307234 already freed.
...

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Tested-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: <stable@vger.kernel.org> [2.6.37+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ryusuke Konishi and committed by
Linus Torvalds
fbb24a3a e4eed03f

+4
+2
fs/nilfs2/gcinode.c
··· 191 191 while (!list_empty(head)) { 192 192 ii = list_first_entry(head, struct nilfs_inode_info, i_dirty); 193 193 list_del_init(&ii->i_dirty); 194 + truncate_inode_pages(&ii->vfs_inode.i_data, 0); 195 + nilfs_btnode_cache_clear(&ii->i_btnode_cache); 194 196 iput(&ii->vfs_inode); 195 197 } 196 198 }
+2
fs/nilfs2/segment.c
··· 2309 2309 if (!test_bit(NILFS_I_UPDATED, &ii->i_state)) 2310 2310 continue; 2311 2311 list_del_init(&ii->i_dirty); 2312 + truncate_inode_pages(&ii->vfs_inode.i_data, 0); 2313 + nilfs_btnode_cache_clear(&ii->i_btnode_cache); 2312 2314 iput(&ii->vfs_inode); 2313 2315 } 2314 2316 }