]> Pileus Git - ~andy/linux/commit
ext4: fix ext4_writepages() in presence of truncate
authorJan Kara <jack@suse.cz>
Sat, 17 Aug 2013 14:02:33 +0000 (10:02 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 17 Aug 2013 14:02:33 +0000 (10:02 -0400)
commit5f1132b2ba8c873f25982cf45917e8455fb6c962
tree91aeeb9c2268a57f9138dc571260b5b3692508ba
parent09930042a2e94cf8ee79d22943915612c1e4ba51
ext4: fix ext4_writepages() in presence of truncate

Inode size can arbitrarily change while writeback is in progress. When
ext4_writepages() has prepared a long extent for mapping and truncate
then reduces i_size, mpage_map_and_submit_buffers() will always map just
one buffer in a page instead of all of them due to lblk < blocks check.
So we end up not using all blocks we've allocated (thus leaking them)
and also delalloc accounting goes wrong manifesting as a warning like:

ext4_da_release_space:1333: ext4_da_release_space: ino 12, to_free 1
with only 0 reserved data blocks

Note that the problem can happen only when blocksize < pagesize because
otherwise we have only a single buffer in the page.

Fix the problem by removing the size check from the mapping loop. We
have an extent allocated so we have to use it all before checking for
i_size. We also rename add_page_bufs_to_extent() to
mpage_process_page_bufs() and make that function submit the page for IO
if all buffers (upto EOF) in it are mapped.

Reported-by: Dave Jones <davej@redhat.com>
Reported-by: Zheng Liu <gnehzuil.liu@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: stable@vger.kernel.org
fs/ext4/inode.c