Skip to content

Commit 8459d9c

Browse files
Eric Whitneygregkh
authored andcommitted
ext4: fix partial cluster handling for bigalloc file systems
commit c063449 upstream. Commit 9cb0041, which enables hole punching for bigalloc file systems, exposed a bug introduced by commit 6ae06ff in an earlier release. When run on a bigalloc file system, xfstests generic/013, 068, 075, 083, 091, 100, 112, 127, 263, 269, and 270 fail with e2fsck errors or cause kernel error messages indicating that previously freed blocks are being freed again. The latter commit optimizes the selection of the starting extent in ext4_ext_rm_leaf() when hole punching by beginning with the extent supplied in the path argument rather than with the last extent in the leaf node (as is still done when truncating). However, the code in rm_leaf that initially sets partial_cluster to track cluster sharing on extent boundaries is only guaranteed to run if rm_leaf starts with the last node in the leaf. Consequently, partial_cluster is not correctly initialized when hole punching, and a cluster on the boundary of a punched region that should be retained may instead be deallocated. Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cbe099e commit 8459d9c

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,27 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
25112511
ex_ee_block = le32_to_cpu(ex->ee_block);
25122512
ex_ee_len = ext4_ext_get_actual_len(ex);
25132513

2514+
/*
2515+
* If we're starting with an extent other than the last one in the
2516+
* node, we need to see if it shares a cluster with the extent to
2517+
* the right (towards the end of the file). If its leftmost cluster
2518+
* is this extent's rightmost cluster and it is not cluster aligned,
2519+
* we'll mark it as a partial that is not to be deallocated.
2520+
*/
2521+
2522+
if (ex != EXT_LAST_EXTENT(eh)) {
2523+
ext4_fsblk_t current_pblk, right_pblk;
2524+
long long current_cluster, right_cluster;
2525+
2526+
current_pblk = ext4_ext_pblock(ex) + ex_ee_len - 1;
2527+
current_cluster = (long long)EXT4_B2C(sbi, current_pblk);
2528+
right_pblk = ext4_ext_pblock(ex + 1);
2529+
right_cluster = (long long)EXT4_B2C(sbi, right_pblk);
2530+
if (current_cluster == right_cluster &&
2531+
EXT4_PBLK_COFF(sbi, right_pblk))
2532+
*partial_cluster = -right_cluster;
2533+
}
2534+
25142535
trace_ext4_ext_rm_leaf(inode, start, ex, *partial_cluster);
25152536

25162537
while (ex >= EXT_FIRST_EXTENT(eh) &&

0 commit comments

Comments
 (0)