From eb763a85f048cdc03d1bdb4eac5b321ca8486230 Mon Sep 17 00:00:00 2001 From: Maximilian Attems Date: Wed, 28 Apr 2010 23:30:49 +0000 Subject: [PATCH] ext4 Issue the discard operation *before* releasing the blocks to be reused as we now support TRIM this can trigger.. svn path=/dists/sid/linux-2.6/; revision=15578 --- debian/changelog | 2 + ...rd-operation-before-releasing-blocks.patch | 62 +++++++++++++++++++ debian/patches/series/12 | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 debian/patches/bugfix/all/ext4-issue-discard-operation-before-releasing-blocks.patch diff --git a/debian/changelog b/debian/changelog index df81ad203..307799c4f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -54,6 +54,8 @@ linux-2.6 (2.6.32-12) UNRELEASED; urgency=low * Backport KVM: Xen PV-on-HVM guest support. * Backport KVM: x86: Add KVM_GET/SET_VCPU_EVENTS. (closes: #578005) * hugetlb: fix infinite loop in get_futex_key() when backed by huge pages + * ext4: Issue the discard operation *before* releasing the blocks to be + reused. [ dann frazier ] * Add DRBD backport diff --git a/debian/patches/bugfix/all/ext4-issue-discard-operation-before-releasing-blocks.patch b/debian/patches/bugfix/all/ext4-issue-discard-operation-before-releasing-blocks.patch new file mode 100644 index 000000000..aa103bdda --- /dev/null +++ b/debian/patches/bugfix/all/ext4-issue-discard-operation-before-releasing-blocks.patch @@ -0,0 +1,62 @@ +From: Theodore Ts'o +Date: Tue, 20 Apr 2010 20:51:59 +0000 (-0400) +Subject: ext4: Issue the discard operation *before* releasing the blocks to be reused +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=b90f687018e6d6c77d981b09203780f7001407e5 + +ext4: Issue the discard operation *before* releasing the blocks to be reused + +[ backported to 2.6.3[23] ] + +Otherwise, we can end up having data corruption because the blocks +could get reused and then discarded! + +https://bugzilla.kernel.org/show_bug.cgi?id=15579 + +Signed-off-by: "Theodore Ts'o" +--- + +diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c +index 54df209..e5ab41b 100644 +--- a/fs/ext4/mballoc.c ++++ b/fs/ext4/mballoc.c +@@ -2534,6 +2534,20 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn) + mb_debug(1, "gonna free %u blocks in group %u (0x%p):", + entry->count, entry->group, entry); + ++ if (test_opt(sb, DISCARD)) { ++ ext4_fsblk_t discard_block; ++ struct ext4_super_block *es = EXT4_SB(sb)->s_es; ++ ++ discard_block = (ext4_fsblk_t)entry->group * ++ EXT4_BLOCKS_PER_GROUP(sb) ++ + entry->start_blk ++ + le32_to_cpu(es->s_first_data_block); ++ trace_ext4_discard_blocks(sb, ++ (unsigned long long)discard_block, ++ entry->count); ++ sb_issue_discard(sb, discard_block, entry->count); ++ } ++ + err = ext4_mb_load_buddy(sb, entry->group, &e4b); + /* we expect to find existing buddy because it's pinned */ + BUG_ON(err != 0); +@@ -2555,19 +2566,6 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn) + page_cache_release(e4b.bd_bitmap_page); + } + ext4_unlock_group(sb, entry->group); +- if (test_opt(sb, DISCARD)) { +- ext4_fsblk_t discard_block; +- struct ext4_super_block *es = EXT4_SB(sb)->s_es; +- +- discard_block = (ext4_fsblk_t)entry->group * +- EXT4_BLOCKS_PER_GROUP(sb) +- + entry->start_blk +- + le32_to_cpu(es->s_first_data_block); +- trace_ext4_discard_blocks(sb, +- (unsigned long long)discard_block, +- entry->count); +- sb_issue_discard(sb, discard_block, entry->count); +- } + kmem_cache_free(ext4_free_ext_cachep, entry); + ext4_mb_release_desc(&e4b); + } diff --git a/debian/patches/series/12 b/debian/patches/series/12 index dcae4c0b5..53da9b217 100644 --- a/debian/patches/series/12 +++ b/debian/patches/series/12 @@ -54,4 +54,4 @@ + debian/sd-libata-set-capacity-abi-changes.patch + bugfix/all/core-x86-make-list_poison-less-deadly.patch + bugfix/all/hugetlb-fix-infinite-loop-in-get_futex_key-when-backed-by-huge-pages.patch - ++ bugfix/all/ext4-issue-discard-operation-before-releasing-blocks.patch