Skip to contentSkip to conversation

btrfs: fix bytes_may_use leak in do_remap_reloc_trans()

PATCH In review Mark Harmstone 2 participants 2 messages Mar 23 – Apr 7 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix bytes_may_use leak in do_remap_reloc_trans()

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")
---
 fs/btrfs/relocation.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/btrfs/relocation.c +6 -0
index 1c42c5180bddd5..c0bd6db6011965 100644
@@ -5000,6 +5000,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;
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Mark Harmstone

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.

Quoted 25 lines
Fixes fd6594b1446c ("btrfs: replace identity remaps with actual remaps when doing relocations")
---
 fs/btrfs/relocation.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/btrfs/relocation.c +6 -0
index 1c42c5180bddd5..c0bd6db6011965 100644
@@ -5000,6 +5000,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;
Signature · 1 line
2.52.0