Commit 14351104 authored by Ryusuke Konishi's avatar Ryusuke Konishi
Browse files

nilfs2: always lookup disk block address before reading metadata block



The current metadata file code skips disk address lookup for its data
block if the buffer has a mapped flag.

This has a potential risk to cause read request to be performed
against the stale block address that GC moved, and it may lead to meta
data corruption.  The mapped flag is safe if the buffer has an
uptodate flag, otherwise it may prevent necessary update of disk
address in the next read.

This will avoid the potential problem by ensuring disk address lookup
before reading metadata block even for buffers with the mapped flag.
Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
parent 027d6404
...@@ -103,15 +103,12 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block, ...@@ -103,15 +103,12 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block,
goto failed_unlock; goto failed_unlock;
err = -EEXIST; err = -EEXIST;
if (buffer_uptodate(bh) || buffer_mapped(bh)) if (buffer_uptodate(bh))
goto failed_bh; goto failed_bh;
#if 0
/* The uptodate flag is not protected by the page lock, but
the mapped flag is. Thus, we don't have to wait the buffer. */
wait_on_buffer(bh); wait_on_buffer(bh);
if (buffer_uptodate(bh)) if (buffer_uptodate(bh))
goto failed_bh; goto failed_bh;
#endif
bh->b_bdev = nilfs->ns_bdev; bh->b_bdev = nilfs->ns_bdev;
err = nilfs_mdt_insert_new_block(inode, block, bh, init_block); err = nilfs_mdt_insert_new_block(inode, block, bh, init_block);
...@@ -162,17 +159,15 @@ nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, ...@@ -162,17 +159,15 @@ nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff,
unlock_buffer(bh); unlock_buffer(bh);
goto out; goto out;
} }
if (!buffer_mapped(bh)) { /* unused buffer */
ret = nilfs_bmap_lookup(NILFS_I(inode)->i_bmap, blkoff, ret = nilfs_bmap_lookup(NILFS_I(inode)->i_bmap, blkoff, &blknum);
&blknum); if (unlikely(ret)) {
if (unlikely(ret)) { unlock_buffer(bh);
unlock_buffer(bh); goto failed_bh;
goto failed_bh;
}
bh->b_bdev = NILFS_MDT(inode)->mi_nilfs->ns_bdev;
bh->b_blocknr = blknum;
set_buffer_mapped(bh);
} }
bh->b_bdev = NILFS_MDT(inode)->mi_nilfs->ns_bdev;
bh->b_blocknr = blknum;
set_buffer_mapped(bh);
bh->b_end_io = end_buffer_read_sync; bh->b_end_io = end_buffer_read_sync;
get_bh(bh); get_bh(bh);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment