1 ext4: update i_disksize coherently with block allocation
3 From: Dmitry Monakhov <dmonakhov@openvz.org>
5 Writeback call trace looks like follows:
9 ->mpage_map_and_submit_extent -> may alloc some blocks
10 ->mpage_map_one_extent
12 In case of delalloc block i_disksize may be less than i_size. So we have to
13 update i_disksize each time we allocated and submitted some blocks beyond
14 i_disksize. And we MUST update it in the same transaction, otherwise this
15 result in fs-inconsistency in case of upcoming power-failure.
17 Another possible way to fix that issue is to insert inode to orhphan list
18 on ext4_writepages entrance.
20 testcase: xfstest generic/019
22 Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
23 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
24 Cc: stable@vger.kernel.org
26 fs/ext4/inode.c | 10 ++++++++--
27 1 files changed, 8 insertions(+), 2 deletions(-)
29 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
30 index 3919e25..b1d92fb 100644
33 @@ -2077,6 +2077,7 @@ static int mpage_map_and_submit_extent(handle_t *handle,
34 struct ext4_map_blocks *map = &mpd->map;
39 mpd->io_submit.io_end->offset =
40 ((loff_t)map->m_lblk) << inode->i_blkbits;
41 @@ -2093,8 +2094,11 @@ static int mpage_map_and_submit_extent(handle_t *handle,
42 * is non-zero, a commit should free up blocks.
44 if ((err == -ENOMEM) ||
45 - (err == -ENOSPC && ext4_count_free_clusters(sb)))
46 + (err == -ENOSPC && ext4_count_free_clusters(sb))) {
48 + goto update_disksize;
51 ext4_msg(sb, KERN_CRIT,
52 "Delayed block allocation failed for "
53 "inode %lu at logical offset %llu with"
54 @@ -2111,15 +2115,17 @@ static int mpage_map_and_submit_extent(handle_t *handle,
55 *give_up_on_write = true;
60 * Update buffer state, submit mapped pages, and get us new
63 err = mpage_map_and_submit_buffers(mpd);
66 + goto update_disksize;
71 * Update on-disk size after IO is submitted. Races with
72 * truncate are avoided by checking i_size under i_data_sem.
77 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
78 the body of a message to majordomo@vger.kernel.org
79 More majordomo info at http://vger.kernel.org/majordomo-info.html