ocfs2: fill in the unused portion of the block with zeros by dio_zero_block()
authorjiangyiwen <jiangyiwen@huawei.com>
Fri, 6 Nov 2015 02:43:55 +0000 (18:43 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Nov 2015 03:34:48 +0000 (19:34 -0800)
A simplified test case is (this case from Ryan):
1) dd if=/dev/zero of=/mnt/hello bs=512 count=1 oflag=direct;
2) truncate /mnt/hello -s 2097152
file 'hello' is not exist before test. After this command,
file 'hello' should be all zero. But 512~4096 is some random data.

Setting bh state to new when get a new block, if so,
direct_io_worker()->dio_zero_block() will fill-in the unused portion
of the block with zero.

Signed-off-by: Yiwen Jiang <jiangyiwen@huawei.com>
Reviewed-by: Joseph Qi <joseph.qi@huawei.com>
Cc: Mark Fasheh <mfasheh@suse.de>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/aops.c

index f04914cc19a43f1a5bf0c882ee671435c2cd31de..7f604727f487b3680d7f145161288656dd1aaf80 100644 (file)
@@ -589,6 +589,7 @@ static int ocfs2_direct_IO_get_blocks(struct inode *inode, sector_t iblock,
                        ret = -EIO;
                        goto bail;
                }
+               set_buffer_new(bh_result);
                up_write(&OCFS2_I(inode)->ip_alloc_sem);
        }