Skip to content

Commit

Permalink
btrfs: zoned: fix block group alloc_offset calculation
Browse files Browse the repository at this point in the history
commit 0ae79c6 upstream.

alloc_offset is offset from the start of a block group and @offset is
actually an address in logical space. Thus, we need to consider
block_group->start when calculating them.

Fixes: 011b41b ("btrfs: zoned: advance allocation pointer after tree log node")
CC: stable@vger.kernel.org # 5.12+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
naota authored and gregkh committed Sep 18, 2021
1 parent 802a090 commit 2a9f99a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fs/btrfs/free-space-cache.c
Expand Up @@ -2652,8 +2652,11 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group,
* btrfs_pin_extent_for_log_replay() when replaying the log.
* Advance the pointer not to overwrite the tree-log nodes.
*/
if (block_group->alloc_offset < offset + bytes)
block_group->alloc_offset = offset + bytes;
if (block_group->start + block_group->alloc_offset <
offset + bytes) {
block_group->alloc_offset =
offset + bytes - block_group->start;
}
return 0;
}

Expand Down

0 comments on commit 2a9f99a

Please sign in to comment.