]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: fix bytes_may_use leak in do_remap_reloc_trans()
authorMark Harmstone <mark@harmstone.com>
Mon, 23 Mar 2026 12:59:57 +0000 (12:59 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 21 Apr 2026 02:00:39 +0000 (04:00 +0200)
If the call to btrfs_reserve_extent() in do_remap_reloc_trans() returns
a smaller extent than we asked for, currently we're not undoing the
bytes_may_use change that we made. Fix this by calling
btrfs_space_info_update_bytes_may_use() again for the difference.

Fixes: fd6594b1446c ("btrfs: replace identity remaps with actual remaps when doing relocations")
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Mark Harmstone <mark@harmstone.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/relocation.c

index 3d1756b611624614ad0a7aeb646c51f3d252ecc6..ad433b7ca919aaa4357bfab8ce823359faae7984 100644 (file)
@@ -5006,6 +5006,12 @@ static int do_remap_reloc_trans(struct btrfs_fs_info *fs_info,
                return ret;
        }
 
+       if (ins.offset < remap_length) {
+               spin_lock(&sinfo->lock);
+               btrfs_space_info_update_bytes_may_use(sinfo, ins.offset - remap_length);
+               spin_unlock(&sinfo->lock);
+       }
+
        made_reservation = true;
 
        new_addr = ins.objectid;