Turn fs_info member 'buffer_radix' into an XArray
PATCH 1/1 Turn fs_info member 'buffer_radix' into an XArray
… named 'extent_buffers'. Also adjust all usages of this object to use the XArray API, which greatly simplifies the code as it takes care of locking and is generally easier to use and understand, providing notionally simpler array semantics.
Also perform some light refactoring.
Signed-off-by Gabriel Niebler <[email protected]>
--- fs/btrfs/ctree.h | 4 +- fs/btrfs/disk-io.c | 4 +- fs/btrfs/extent_io.c | 118 ++++++++++++++--------------------- fs/btrfs/tests/btrfs-tests.c | 22 +------ 4 files changed, 55 insertions(+), 93 deletions(-)
fs/btrfs/ctree.h +2 -2
@@ -994,10 +994,10 @@ struct btrfs_fs_info {struct btrfs_delayed_root *delayed_root; -/* Extent buffer radix tree */ +/* Extent buffer xarray */ spinlock_t buffer_lock;/* Entries are eb->start / sectorsize */ -struct radix_tree_root buffer_radix; +struct xarray extent_buffers;/* next backup root to be overwritten */ int backup_root_index;
fs/btrfs/disk-io.c +2 -2
@@ -486,7 +486,7 @@ static int csum_dirty_subpage_buffers(struct btrfs_fs_info *fs_info, uptodate =btrfs_subpage_test_uptodate (fs_info, page, cur, fs_info->nodesize); -/* A dirty eb shouldn't disappear from buffer_radix */ +/* A dirty eb shouldn't disappear from extent_buffers */ if (WARN_ON (!eb))return -EUCLEAN ;
@@ -3133,7 +3133,7 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info)void btrfs_init_fs_info (struct btrfs_fs_info *fs_info) {INIT_RADIX_TREE (&fs_info->fs_roots_radix,GFP_ATOMIC ); -INIT_RADIX_TREE (&fs_info->buffer_radix,GFP_ATOMIC ); +xa_init_flags (&fs_info->extent_buffers,GFP_ATOMIC );INIT_LIST_HEAD (&fs_info->trans_list);INIT_LIST_HEAD (&fs_info->dead_roots);INIT_LIST_HEAD (&fs_info->delayed_iputs);
fs/btrfs/extent_io.c +48 -70
174 lines not on this page · raw message
fs/btrfs/tests/btrfs-tests.c +3 -19
@@ -150,8 +150,8 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)void btrfs_free_dummy_fs_info (struct btrfs_fs_info *fs_info) { -struct radix_tree_iter iter; -void **slot; +unsigned long index; +struct extent_buffer *eb;struct btrfs_device *dev, *tmp;if (!fs_info)
@@ -163,25 +163,9 @@ void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info) test_mnt->mnt_sb->s_fs_info =NULL ; -spin_lock (&fs_info->buffer_lock); -radix_tree_for_each_slot (slot, &fs_info->buffer_radix, &iter,0 ) { -struct extent_buffer *eb; - - eb =radix_tree_deref_slot_protected (slot, &fs_info->buffer_lock); -if (!eb) -continue ; -/* Shouldn't happen but that kind of thinking creates CVE's */ -if (radix_tree_exception (eb)) { -if (radix_tree_deref_retry (eb)) - slot =radix_tree_iter_retry (&iter); -continue ; - } - slot =radix_tree_iter_resume (slot, &iter); -spin_unlock (&fs_info->buffer_lock); +xa_for_each (&fs_info->extent_buffers, index, eb) {free_extent_buffer_stale (eb); -spin_lock (&fs_info->buffer_lock); } -spin_unlock (&fs_info->buffer_lock);btrfs_mapping_tree_free (&fs_info->mapping_tree); list_for_each_entry_safe(dev, tmp, &fs_info->fs_devices->devices,
Signature · 1 line
2.35.3
First line of commit message doesn't start with "btrfs: ".
Resubmitting...
Sorry for the inconvenience!