btrfs: calculate the right space for a single delayed ref when refilling
authorFilipe Manana <fdmanana@suse.com>
Tue, 21 Mar 2023 11:13:51 +0000 (11:13 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Apr 2023 16:01:19 +0000 (18:01 +0200)
When refilling the delayed block reserve we are incorrectly computing the
amount of bytes for a single delayed reference if the free space tree is
being used. In that case we should double the calculated amount.
Everywhere else we compute the correct amount, like when updating the
delayed block reserve, at btrfs_update_delayed_refs_rsv(), or when
releasing space from the delayed block reserve, at
btrfs_delayed_refs_rsv_release().

So fix btrfs_delayed_refs_rsv_refill() to multiply the amount of bytes for
a single delayed reference by two in case the free space tree is used.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/delayed-ref.c

index bf2ce51e5086ebf3e08b383f9deeea6548f16b06..b58a7e30d37c4821a20534444472e9bd99dd94f6 100644 (file)
@@ -186,6 +186,17 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
        u64 num_bytes = 0;
        int ret = -ENOSPC;
 
+       /*
+        * We have to check the mount option here because we could be enabling
+        * the free space tree for the first time and don't have the compat_ro
+        * option set yet.
+        *
+        * We need extra reservations if we have the free space tree because
+        * we'll have to modify that tree as well.
+        */
+       if (btrfs_test_opt(fs_info, FREE_SPACE_TREE))
+               limit *= 2;
+
        spin_lock(&block_rsv->lock);
        if (block_rsv->reserved < block_rsv->size) {
                num_bytes = block_rsv->size - block_rsv->reserved;