Create ext3 directory and move ext3_truncate_block_on_a_filaed_ext4_write_begin to...
[ext4-patch-queue.git] / ext3 / ext3_truncate_block_allocated_on_a_failed_ext3_write_begin.patch
blob2f19b22fd0c9e5d7ca3960cd72aa7cceaeea9003
1 ext3: truncate block allocated on a failed ext3_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 page
8 locally. This makes sure we don't have blocks outside inode.i_size
9 during ENOSPC.
11 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
12 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
13 Cc: linux-ext4@vger.kernel.org
14 ---
15 fs/ext3/inode.c | 7 +++++++
16 1 files changed, 7 insertions(+), 0 deletions(-)
18 Index: linux-2.6.27-rc5/fs/ext3/inode.c
19 ===================================================================
20 --- linux-2.6.27-rc5.orig/fs/ext3/inode.c 2008-08-28 23:25:04.000000000 -0700
21 +++ linux-2.6.27-rc5/fs/ext3/inode.c 2008-08-28 23:28:48.000000000 -0700
22 @@ -1178,6 +1178,13 @@ write_begin_failed:
23 ext3_journal_stop(handle);
24 unlock_page(page);
25 page_cache_release(page);
26 + /*
27 + * block_write_begin may have instantiated a few blocks
28 + * outside i_size. Trim these off again. Don't need
29 + * i_size_read because we hold i_mutex.
30 + */
31 + if (pos + len > inode->i_size)
32 + vmtruncate(inode, inode->i_size);
34 if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries))
35 goto retry;