mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-04 09:59:32 +00:00
btrfs: simplify arguments to tree_insert_offset()
For the in-memory component of space caching (free space cache and free space tree), three of the arguments passed to tree_insert_offset() can always be taken from the new free space entry that we are about to add. So simplify tree_insert_offset() to take the new entry instead of the 'offset', 'node' and 'bitmap' arguments. This will also allow to make further changes simpler. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
b77433b144
commit
0d6bac4d30
1 changed files with 16 additions and 21 deletions
|
@ -1598,20 +1598,21 @@ static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl,
|
||||||
return bitmap_start;
|
return bitmap_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tree_insert_offset(struct rb_root *root, u64 offset,
|
static int tree_insert_offset(struct rb_root *root,
|
||||||
struct rb_node *node, int bitmap)
|
struct btrfs_free_space *new_entry)
|
||||||
{
|
{
|
||||||
struct rb_node **p = &root->rb_node;
|
struct rb_node **p = &root->rb_node;
|
||||||
struct rb_node *parent = NULL;
|
struct rb_node *parent = NULL;
|
||||||
struct btrfs_free_space *info;
|
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
|
struct btrfs_free_space *info;
|
||||||
|
|
||||||
parent = *p;
|
parent = *p;
|
||||||
info = rb_entry(parent, struct btrfs_free_space, offset_index);
|
info = rb_entry(parent, struct btrfs_free_space, offset_index);
|
||||||
|
|
||||||
if (offset < info->offset) {
|
if (new_entry->offset < info->offset) {
|
||||||
p = &(*p)->rb_left;
|
p = &(*p)->rb_left;
|
||||||
} else if (offset > info->offset) {
|
} else if (new_entry->offset > info->offset) {
|
||||||
p = &(*p)->rb_right;
|
p = &(*p)->rb_right;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
@ -1627,7 +1628,7 @@ static int tree_insert_offset(struct rb_root *root, u64 offset,
|
||||||
* found a bitmap, we want to go left, or before
|
* found a bitmap, we want to go left, or before
|
||||||
* logically.
|
* logically.
|
||||||
*/
|
*/
|
||||||
if (bitmap) {
|
if (new_entry->bitmap) {
|
||||||
if (info->bitmap) {
|
if (info->bitmap) {
|
||||||
WARN_ON_ONCE(1);
|
WARN_ON_ONCE(1);
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
@ -1643,8 +1644,8 @@ static int tree_insert_offset(struct rb_root *root, u64 offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_link_node(node, parent, p);
|
rb_link_node(&new_entry->offset_index, parent, p);
|
||||||
rb_insert_color(node, root);
|
rb_insert_color(&new_entry->offset_index, root);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1835,8 +1836,7 @@ static int link_free_space(struct btrfs_free_space_ctl *ctl,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
ASSERT(info->bytes || info->bitmap);
|
ASSERT(info->bytes || info->bitmap);
|
||||||
ret = tree_insert_offset(&ctl->free_space_offset, info->offset,
|
ret = tree_insert_offset(&ctl->free_space_offset, info);
|
||||||
&info->offset_index, (info->bitmap != NULL));
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -2973,8 +2973,6 @@ static void __btrfs_return_cluster_to_free_space(
|
||||||
struct btrfs_block_group *block_group,
|
struct btrfs_block_group *block_group,
|
||||||
struct btrfs_free_cluster *cluster)
|
struct btrfs_free_cluster *cluster)
|
||||||
{
|
{
|
||||||
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
|
|
||||||
struct btrfs_free_space *entry;
|
|
||||||
struct rb_node *node;
|
struct rb_node *node;
|
||||||
|
|
||||||
spin_lock(&cluster->lock);
|
spin_lock(&cluster->lock);
|
||||||
|
@ -2989,15 +2987,15 @@ static void __btrfs_return_cluster_to_free_space(
|
||||||
|
|
||||||
node = rb_first(&cluster->root);
|
node = rb_first(&cluster->root);
|
||||||
while (node) {
|
while (node) {
|
||||||
bool bitmap;
|
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
|
||||||
|
struct btrfs_free_space *entry;
|
||||||
|
|
||||||
entry = rb_entry(node, struct btrfs_free_space, offset_index);
|
entry = rb_entry(node, struct btrfs_free_space, offset_index);
|
||||||
node = rb_next(&entry->offset_index);
|
node = rb_next(&entry->offset_index);
|
||||||
rb_erase(&entry->offset_index, &cluster->root);
|
rb_erase(&entry->offset_index, &cluster->root);
|
||||||
RB_CLEAR_NODE(&entry->offset_index);
|
RB_CLEAR_NODE(&entry->offset_index);
|
||||||
|
|
||||||
bitmap = (entry->bitmap != NULL);
|
if (!entry->bitmap) {
|
||||||
if (!bitmap) {
|
|
||||||
/* Merging treats extents as if they were new */
|
/* Merging treats extents as if they were new */
|
||||||
if (!btrfs_free_space_trimmed(entry)) {
|
if (!btrfs_free_space_trimmed(entry)) {
|
||||||
ctl->discardable_extents[BTRFS_STAT_CURR]--;
|
ctl->discardable_extents[BTRFS_STAT_CURR]--;
|
||||||
|
@ -3015,8 +3013,7 @@ static void __btrfs_return_cluster_to_free_space(
|
||||||
entry->bytes;
|
entry->bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tree_insert_offset(&ctl->free_space_offset,
|
tree_insert_offset(&ctl->free_space_offset, entry);
|
||||||
entry->offset, &entry->offset_index, bitmap);
|
|
||||||
rb_add_cached(&entry->bytes_index, &ctl->free_space_bytes,
|
rb_add_cached(&entry->bytes_index, &ctl->free_space_bytes,
|
||||||
entry_less);
|
entry_less);
|
||||||
}
|
}
|
||||||
|
@ -3390,8 +3387,7 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group *block_group,
|
||||||
*/
|
*/
|
||||||
RB_CLEAR_NODE(&entry->bytes_index);
|
RB_CLEAR_NODE(&entry->bytes_index);
|
||||||
|
|
||||||
ret = tree_insert_offset(&cluster->root, entry->offset,
|
ret = tree_insert_offset(&cluster->root, entry);
|
||||||
&entry->offset_index, 1);
|
|
||||||
ASSERT(!ret); /* -EEXIST; Logic error */
|
ASSERT(!ret); /* -EEXIST; Logic error */
|
||||||
|
|
||||||
trace_btrfs_setup_cluster(block_group, cluster,
|
trace_btrfs_setup_cluster(block_group, cluster,
|
||||||
|
@ -3481,8 +3477,7 @@ setup_cluster_no_bitmap(struct btrfs_block_group *block_group,
|
||||||
|
|
||||||
rb_erase(&entry->offset_index, &ctl->free_space_offset);
|
rb_erase(&entry->offset_index, &ctl->free_space_offset);
|
||||||
rb_erase_cached(&entry->bytes_index, &ctl->free_space_bytes);
|
rb_erase_cached(&entry->bytes_index, &ctl->free_space_bytes);
|
||||||
ret = tree_insert_offset(&cluster->root, entry->offset,
|
ret = tree_insert_offset(&cluster->root, entry);
|
||||||
&entry->offset_index, 0);
|
|
||||||
total_size += entry->bytes;
|
total_size += entry->bytes;
|
||||||
ASSERT(!ret); /* -EEXIST; Logic error */
|
ASSERT(!ret); /* -EEXIST; Logic error */
|
||||||
} while (node && entry != last);
|
} while (node && entry != last);
|
||||||
|
|
Loading…
Reference in a new issue