add patch update-locking-documentation-for-transaction_t
[ext4-patch-queue.git] / archive / add-WARN_ON-with-unmapped-dirty-bh-in-writepage
blob51ea7e0d634ddc57efdb615608e8477608ef0962
1 ext4: add WARN_ON on unmapped dirty buffer_heads in writepage
3 From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
5 Now that block_lock_hole_extend() clears the dirty flag of
6 buffer_heads outside i_size we should not find buffer_heads which are
7 unmapped and dirty in writepage. If we find do a WARN_ON.  We can
8 still continue because block_write_full page look at the mapped flag
9 only.
11 Following sequence of events would result in the above condition.
12 1) truncate(f, 1024)
13 2) mmap(f, 0, 4096)
14 3) a[0] = 'a'
15 4) truncate(f, 4096)
16 5) writepage(...)
18 After step 3 we would have unmapped buffer_heads outside i_size.
19 After step 4 we would have unmapped buffer_heads within i_size.
21 Now that truncate is calling block_lock_hole_extend which in turn
22 is clearing the dirty flag, we can safely assume that we won't
23 find unmapped dirty buffer_heads in write page. If we did find one
24 we should find out why.
26 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
27 Acked-by: Jan Kara <jack@suse.cz>
28 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
29 ---
30  fs/ext4/inode.c |   12 ++++++++++++
31  1 files changed, 12 insertions(+), 0 deletions(-)
33 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
34 index 2219daa..9bba474 100644
35 --- a/fs/ext4/inode.c
36 +++ b/fs/ext4/inode.c
37 @@ -2488,6 +2488,10 @@ static int __ext4_journalled_writepage(struct page *page,
38         return ret;
39  }
41 +static int ext4_bh_unmapped_and_dirty(handle_t *handle, struct buffer_head *bh)
43 +       return !buffer_mapped(bh) && buffer_dirty(bh);
46  /*
47   * Note that we don't need to start a transaction unless we're journaling data
48 @@ -2602,6 +2606,14 @@ static int ext4_writepage(struct page *page,
49                 /* now mark the buffer_heads as dirty and uptodate */
50                 block_commit_write(page, 0, len);
51         }
52 +       /*
53 +        * There should not be any unmapped and dirty
54 +        * buffer_heads at this point. Look at block_lock_hole_extend
55 +        * for more info. If we find one print more info
56 +        */
57 +        WARN(walk_page_buffers(NULL, page_bufs, 0, len, NULL,
58 +                                ext4_bh_unmapped_and_dirty),
59 +                "Unmapped dirty buffer_heads found in %s\n", __func__);
61         if (PageChecked(page) && ext4_should_journal_data(inode)) {
62                 /*
63 -- 
64 1.6.3.1.244.gf9275
67 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
68 the body of a message to majordomo@vger.kernel.org
69 More majordomo info at  http://vger.kernel.org/majordomo-info.html