1 ext4: truncate block allocated on a failed ext4_write_begin
3 From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
5 For blocksize < pagesize we need to remove blocks that got allocated in
6 block_write_begin() if we fail with ENOSPC for later blocks.
7 block_write_begin() internally does this if it allocated pages locally.
8 This makes sure we don't have blocks outside inode.i_size during ENOSPC.
10 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
11 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
12 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
13 index 5a595af..a1e235d 100644
16 @@ -1391,6 +1391,13 @@ retry:
18 ext4_journal_stop(handle);
19 page_cache_release(page);
21 + * block_write_begin may have instantiated a few blocks
22 + * outside i_size. Trim these off again. Don't need
23 + * i_size_read because we hold i_mutex.
25 + if (pos + len > inode->i_size)
26 + vmtruncate(inode, inode->i_size);
29 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
30 @@ -2560,6 +2567,13 @@ retry:
32 ext4_journal_stop(handle);
33 page_cache_release(page);
35 + * block_write_begin may have instantiated a few blocks
36 + * outside i_size. Trim these off again. Don't need
37 + * i_size_read because we hold i_mutex.
39 + if (pos + len > inode->i_size)
40 + vmtruncate(inode, inode->i_size);
43 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))