ext4: Issue the discard operation *before* releasing the blocks to be reused
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" <tytso@mit.edu>
This commit is contained in:
@@ -2534,6 +2534,17 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
|
|||||||
mb_debug(1, "gonna free %u blocks in group %u (0x%p):",
|
mb_debug(1, "gonna free %u blocks in group %u (0x%p):",
|
||||||
entry->count, entry->group, entry);
|
entry->count, entry->group, entry);
|
||||||
|
|
||||||
|
if (test_opt(sb, DISCARD)) {
|
||||||
|
ext4_fsblk_t discard_block;
|
||||||
|
|
||||||
|
discard_block = entry->start_blk +
|
||||||
|
ext4_group_first_block_no(sb, entry->group);
|
||||||
|
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);
|
err = ext4_mb_load_buddy(sb, entry->group, &e4b);
|
||||||
/* we expect to find existing buddy because it's pinned */
|
/* we expect to find existing buddy because it's pinned */
|
||||||
BUG_ON(err != 0);
|
BUG_ON(err != 0);
|
||||||
@@ -2555,16 +2566,6 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
|
|||||||
page_cache_release(e4b.bd_bitmap_page);
|
page_cache_release(e4b.bd_bitmap_page);
|
||||||
}
|
}
|
||||||
ext4_unlock_group(sb, entry->group);
|
ext4_unlock_group(sb, entry->group);
|
||||||
if (test_opt(sb, DISCARD)) {
|
|
||||||
ext4_fsblk_t discard_block;
|
|
||||||
|
|
||||||
discard_block = entry->start_blk +
|
|
||||||
ext4_group_first_block_no(sb, entry->group);
|
|
||||||
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);
|
kmem_cache_free(ext4_free_ext_cachep, entry);
|
||||||
ext4_mb_release_desc(&e4b);
|
ext4_mb_release_desc(&e4b);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user