Goldwyn Rodrigues
2011-Feb-14 06:21 UTC
[Ocfs2-devel] [PATCH] Zero from EOF instead of next block
ocfs2_zero_extend() extends the file from the next page offset rather from the current file size. zero_extend_page() should call ocfs2_zero_partial_cluster() to set zero rest of the cluster when the file size is within the page boundaries. Signed-off-by: Goldwyn Rodrigues <rgoldwyn at suse.de> --- diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index a665195..5a2223e 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -63,6 +63,8 @@ #include "refcounttree.h" #include "buffer_head_io.h" +static int ocfs2_zero_partial_clusters(struct inode *inode, + u64 start, u64 len); static int ocfs2_init_file_private(struct inode *inode, struct file *file) { @@ -960,11 +962,21 @@ int ocfs2_zero_extend(struct inode *inode, struct buffer_head *di_bh, int ret = 0; u64 zero_start, range_start = 0, range_end = 0; struct super_block *sb = inode->i_sb; + u64 current_size = i_size_read(inode), len; zero_start = ocfs2_align_bytes_to_blocks(sb, i_size_read(inode)); mlog(0, "zero_start %llu for i_size %llu\n", (unsigned long long)zero_start, (unsigned long long)i_size_read(inode)); + + len = ocfs2_align_bytes_to_clusters(sb, current_size) - current_size; + if (len) { + ret = ocfs2_zero_partial_clusters(inode, current_size, len); + if (ret) + goto out; + zero_start = ocfs2_align_bytes_to_clusters(sb, current_size); + } + while (zero_start < zero_to_size) { ret = ocfs2_zero_extend_get_range(inode, di_bh, zero_start, zero_to_size, @@ -990,7 +1002,7 @@ int ocfs2_zero_extend(struct inode *inode, struct buffer_head *di_bh, } zero_start = range_end; } - +out: return ret; } -- Goldwyn
Joel Becker
2011-Feb-14 07:25 UTC
[Ocfs2-devel] [PATCH] Zero from EOF instead of next block
On Mon, Feb 14, 2011 at 12:21:41AM -0600, Goldwyn Rodrigues wrote:> ocfs2_zero_extend() extends the file from the next page offset > rather from the current file size. zero_extend_page() should > call ocfs2_zero_partial_cluster() to set zero rest of the cluster > when the file size is within the page boundaries.We just went over this. It is intentional that we start from the next block. Linux code always assumes that the block containing i_size is properly zeroed to its end. Our last set of fixes for this made sure we were doing that correctly. Or so I thought. Your patch description looks like you are worried that we don't zero from EOF to End-Of-Block. Have you proof we've failed that again? Or are you worried that we don't zero from EOB to End-Of-Cluster? We used to zero to EOC, but we now know that to be a mistake. Joel -- "Sometimes one pays most for the things one gets for nothing." - Albert Einstein http://www.jlbec.org/ jlbec at evilplan.org