btrfs: zoned: fix block group alloc_offset calculation
[sfrench/cifs-2.6.git] / fs / btrfs / free-space-cache.c
index e91440bd0794e18c6d84b0a085d8c35cefb534f8..da0eee7c9e5f38ba00dc7d3290302a6d83bf051d 100644 (file)
@@ -2647,8 +2647,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;
        }