add patch fix-infinite-loop-when-recovering-corrupt-journal
[ext4-patch-queue.git] / update-i_disksize-coherently-with-block-allocation
blobf42d8f25ccc5c4c8b0bff874045e25ea3f77b116
1 ext4: update i_disksize coherently with block allocation
3 From: Dmitry Monakhov <dmonakhov@openvz.org>
5 Writeback call trace looks like follows:
6 ext4_writepages
7  while(nr_pages)
8  ->journal_start
9  ->mpage_map_and_submit_extent -> may alloc some blocks
10    ->mpage_map_one_extent
11  ->journal_stop
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
25 ---
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
31 --- a/fs/ext4/inode.c
32 +++ b/fs/ext4/inode.c
33 @@ -2077,6 +2077,7 @@ static int mpage_map_and_submit_extent(handle_t *handle,
34         struct ext4_map_blocks *map = &mpd->map;
35         int err;
36         loff_t disksize;
37 +       int progress = 0;
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.
43                          */
44                         if ((err == -ENOMEM) ||
45 -                           (err == -ENOSPC && ext4_count_free_clusters(sb)))
46 +                           (err == -ENOSPC && ext4_count_free_clusters(sb))) {
47 +                               if (progress)
48 +                                       goto update_disksize;
49                                 return err;
50 +                       }
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;
56                         return err;
57                 }
58 +               progress = 1;
59                 /*
60                  * Update buffer state, submit mapped pages, and get us new
61                  * extent to map
62                  */
63                 err = mpage_map_and_submit_buffers(mpd);
64                 if (err < 0)
65 -                       return err;
66 +                       goto update_disksize;
67         } while (map->m_len);
69 +update_disksize:
70         /*
71          * Update on-disk size after IO is submitted.  Races with
72          * truncate are avoided by checking i_size under i_data_sem.
73 -- 
74 1.7.1
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