Skip to content

Commit 01e8600

Browse files
morbidrsakdave
authored andcommitted
btrfs: zoned: reset zones of relocated block groups
When relocating a block group the freed up space is not discarded in one big block, but each extent is discarded on its own with -odisard=sync. For a zoned filesystem we need to discard the whole block group at once, so btrfs_discard_extent() will translate the discard into a REQ_OP_ZONE_RESET operation, which then resets the device's zone. Failure to reset the zone is not fatal error. Discussion about the approach and regarding transaction blocking: https://lore.kernel.org/linux-btrfs/CAL3q7H4SjS_d5rBepfTMhU8Th3bJzdmyYd0g4Z60yUgC_rC_ZA@mail.gmail.com/ Reviewed-by: Josef Bacik <[email protected]> Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e9306ad commit 01e8600

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs/btrfs/volumes.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,7 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
31033103
struct btrfs_root *root = fs_info->chunk_root;
31043104
struct btrfs_trans_handle *trans;
31053105
struct btrfs_block_group *block_group;
3106+
u64 length;
31063107
int ret;
31073108

31083109
/*
@@ -3130,8 +3131,23 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
31303131
if (!block_group)
31313132
return -ENOENT;
31323133
btrfs_discard_cancel_work(&fs_info->discard_ctl, block_group);
3134+
length = block_group->length;
31333135
btrfs_put_block_group(block_group);
31343136

3137+
/*
3138+
* On a zoned file system, discard the whole block group, this will
3139+
* trigger a REQ_OP_ZONE_RESET operation on the device zone. If
3140+
* resetting the zone fails, don't treat it as a fatal problem from the
3141+
* filesystem's point of view.
3142+
*/
3143+
if (btrfs_is_zoned(fs_info)) {
3144+
ret = btrfs_discard_extent(fs_info, chunk_offset, length, NULL);
3145+
if (ret)
3146+
btrfs_info(fs_info,
3147+
"failed to reset zone %llu after relocation",
3148+
chunk_offset);
3149+
}
3150+
31353151
trans = btrfs_start_trans_remove_block_group(root->fs_info,
31363152
chunk_offset);
31373153
if (IS_ERR(trans)) {

0 commit comments

Comments
 (0)