]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/2.6.32.17/0028-ext4-Issue-the-discard-operation-before-releasing-th.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.32.17 / 0028-ext4-Issue-the-discard-operation-before-releasing-th.patch
1 From 462d9c2b296ce81bf4c6a6899e256ae6188f9a5a Mon Sep 17 00:00:00 2001
2 From: Theodore Ts'o <tytso@mit.edu>
3 Date: Sun, 30 May 2010 22:49:42 -0400
4 Subject: ext4: Issue the discard operation *before* releasing the blocks to be reused
5
6 commit b90f687018e6d6c77d981b09203780f7001407e5 upstream (as of v2.6.34-rc6)
7
8 Otherwise, we can end up having data corruption because the blocks
9 could get reused and then discarded!
10
11 https://bugzilla.kernel.org/show_bug.cgi?id=15579
12
13 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
14 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
15 ---
16 fs/ext4/mballoc.c | 24 +++++++++++-------------
17 1 file changed, 11 insertions(+), 13 deletions(-)
18
19 --- a/fs/ext4/mballoc.c
20 +++ b/fs/ext4/mballoc.c
21 @@ -2537,6 +2537,17 @@ static void release_blocks_on_commit(jou
22 mb_debug(1, "gonna free %u blocks in group %u (0x%p):",
23 entry->count, entry->group, entry);
24
25 + if (test_opt(sb, DISCARD)) {
26 + ext4_fsblk_t discard_block;
27 +
28 + discard_block = entry->start_blk +
29 + ext4_group_first_block_no(sb, entry->group);
30 + trace_ext4_discard_blocks(sb,
31 + (unsigned long long)discard_block,
32 + entry->count);
33 + sb_issue_discard(sb, discard_block, entry->count);
34 + }
35 +
36 err = ext4_mb_load_buddy(sb, entry->group, &e4b);
37 /* we expect to find existing buddy because it's pinned */
38 BUG_ON(err != 0);
39 @@ -2558,19 +2569,6 @@ static void release_blocks_on_commit(jou
40 page_cache_release(e4b.bd_bitmap_page);
41 }
42 ext4_unlock_group(sb, entry->group);
43 - if (test_opt(sb, DISCARD)) {
44 - ext4_fsblk_t discard_block;
45 - struct ext4_super_block *es = EXT4_SB(sb)->s_es;
46 -
47 - discard_block = (ext4_fsblk_t)entry->group *
48 - EXT4_BLOCKS_PER_GROUP(sb)
49 - + entry->start_blk
50 - + le32_to_cpu(es->s_first_data_block);
51 - trace_ext4_discard_blocks(sb,
52 - (unsigned long long)discard_block,
53 - entry->count);
54 - sb_issue_discard(sb, discard_block, entry->count);
55 - }
56 kmem_cache_free(ext4_free_ext_cachep, entry);
57 ext4_mb_release_desc(&e4b);
58 }