btrfs: Mark pinned log extents as excluded
authorNikolay Borisov <nborisov@suse.com>
Mon, 20 Jan 2020 14:09:16 +0000 (16:09 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Mar 2020 16:01:37 +0000 (17:01 +0100)
In preparation to making pinned extents per-transaction ensure that log
such extents are always excluded from caching. To achieve this in
addition to marking them via btrfs_pin_extent_for_log_replay they also
need to be marked with btrfs_add_excluded_extent to prevent log tree
extent buffer being loaded by the free space caching thread. That's
required since log tree blocks are not recorded in the extent tree, hence
they always look free.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index 425eefeaacf8443fbc305afa00fd2f72ee27e36f..f97e631aaca5c25aa48a84cffcbcad34c36fb89a 100644 (file)
@@ -2633,6 +2633,8 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
        struct btrfs_block_group *cache;
        int ret;
 
+       btrfs_add_excluded_extent(trans->fs_info, bytenr, num_bytes);
+
        cache = btrfs_lookup_block_group(trans->fs_info, bytenr);
        if (!cache)
                return -EINVAL;
@@ -2919,6 +2921,12 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
                        mutex_unlock(&fs_info->unused_bg_unpin_mutex);
                        break;
                }
+               if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) {
+                       clear_extent_bits(&fs_info->freed_extents[0], start,
+                                         end, EXTENT_UPTODATE);
+                       clear_extent_bits(&fs_info->freed_extents[1], start,
+                                         end, EXTENT_UPTODATE);
+               }
 
                if (btrfs_test_opt(fs_info, DISCARD_SYNC))
                        ret = btrfs_discard_extent(fs_info, start,