Skip to content

Commit 6e1116a

Browse files
Liu Bogregkh
authored andcommitted
Btrfs: fix truncate down when no_holes feature is enabled
[ Upstream commit 91298eec05cd8d4e828cf7ee5d4a6334f70cf69a ] For such a file mapping, [0-4k][hole][8k-12k] In NO_HOLES mode, we don't have the [hole] extent any more. Commit c1aa457 ("Btrfs: fix shrinking truncate when the no_holes feature is enabled") fixed disk isize not being updated in NO_HOLES mode when data is not flushed. However, even if data has been flushed, we can still have trouble in updating disk isize since we updated disk isize to 'start' of the last evicted extent. Reviewed-by: Chris Mason <clm@fb.com> Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 961efcd commit 6e1116a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

fs/btrfs/inode.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4397,8 +4397,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
43974397
if (found_type > min_type) {
43984398
del_item = 1;
43994399
} else {
4400-
if (item_end < new_size)
4400+
if (item_end < new_size) {
4401+
/*
4402+
* With NO_HOLES mode, for the following mapping
4403+
*
4404+
* [0-4k][hole][8k-12k]
4405+
*
4406+
* if truncating isize down to 6k, it ends up
4407+
* isize being 8k.
4408+
*/
4409+
if (btrfs_fs_incompat(root->fs_info, NO_HOLES))
4410+
last_size = new_size;
44014411
break;
4412+
}
44024413
if (found_key.offset >= new_size)
44034414
del_item = 1;
44044415
else

0 commit comments

Comments
 (0)