Commit 6c566def authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: pass the extent map tree's inode to add_extent_mapping()

Extent maps are always added to an inode's extent map tree, so there's no
need to pass the extent map tree explicitly to add_extent_mapping().

In order to facilitate an upcoming change that adds a shrinker for extent
maps, change add_extent_mapping() to receive the inode instead of its
extent map tree.
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e094f480
...@@ -355,21 +355,22 @@ static inline void setup_extent_mapping(struct extent_map_tree *tree, ...@@ -355,21 +355,22 @@ static inline void setup_extent_mapping(struct extent_map_tree *tree,
} }
/* /*
* Add new extent map to the extent tree * Add a new extent map to an inode's extent map tree.
* *
* @tree: tree to insert new map in * @inode: the target inode
* @em: map to insert * @em: map to insert
* @modified: indicate whether the given @em should be added to the * @modified: indicate whether the given @em should be added to the
* modified list, which indicates the extent needs to be logged * modified list, which indicates the extent needs to be logged
* *
* Insert @em into @tree or perform a simple forward/backward merge with * Insert @em into the @inode's extent map tree or perform a simple
* existing mappings. The extent_map struct passed in will be inserted * forward/backward merge with existing mappings. The extent_map struct passed
* into the tree directly, with an additional reference taken, or a * in will be inserted into the tree directly, with an additional reference
* reference dropped if the merge attempt was successful. * taken, or a reference dropped if the merge attempt was successful.
*/ */
static int add_extent_mapping(struct extent_map_tree *tree, static int add_extent_mapping(struct btrfs_inode *inode,
struct extent_map *em, int modified) struct extent_map *em, int modified)
{ {
struct extent_map_tree *tree = &inode->extent_tree;
int ret; int ret;
lockdep_assert_held_write(&tree->lock); lockdep_assert_held_write(&tree->lock);
...@@ -508,7 +509,7 @@ static struct extent_map *prev_extent_map(struct extent_map *em) ...@@ -508,7 +509,7 @@ static struct extent_map *prev_extent_map(struct extent_map *em)
* and an extent that you want to insert, deal with overlap and insert * and an extent that you want to insert, deal with overlap and insert
* the best fitted new extent into the tree. * the best fitted new extent into the tree.
*/ */
static noinline int merge_extent_mapping(struct extent_map_tree *em_tree, static noinline int merge_extent_mapping(struct btrfs_inode *inode,
struct extent_map *existing, struct extent_map *existing,
struct extent_map *em, struct extent_map *em,
u64 map_start) u64 map_start)
...@@ -542,7 +543,7 @@ static noinline int merge_extent_mapping(struct extent_map_tree *em_tree, ...@@ -542,7 +543,7 @@ static noinline int merge_extent_mapping(struct extent_map_tree *em_tree,
em->block_start += start_diff; em->block_start += start_diff;
em->block_len = em->len; em->block_len = em->len;
} }
return add_extent_mapping(em_tree, em, 0); return add_extent_mapping(inode, em, 0);
} }
/* /*
...@@ -570,7 +571,6 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode, ...@@ -570,7 +571,6 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode,
{ {
int ret; int ret;
struct extent_map *em = *em_in; struct extent_map *em = *em_in;
struct extent_map_tree *em_tree = &inode->extent_tree;
struct btrfs_fs_info *fs_info = inode->root->fs_info; struct btrfs_fs_info *fs_info = inode->root->fs_info;
/* /*
...@@ -580,7 +580,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode, ...@@ -580,7 +580,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode,
if (em->block_start == EXTENT_MAP_INLINE) if (em->block_start == EXTENT_MAP_INLINE)
ASSERT(em->start == 0); ASSERT(em->start == 0);
ret = add_extent_mapping(em_tree, em, 0); ret = add_extent_mapping(inode, em, 0);
/* it is possible that someone inserted the extent into the tree /* it is possible that someone inserted the extent into the tree
* while we had the lock dropped. It is also possible that * while we had the lock dropped. It is also possible that
* an overlapping map exists in the tree * an overlapping map exists in the tree
...@@ -588,7 +588,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode, ...@@ -588,7 +588,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode,
if (ret == -EEXIST) { if (ret == -EEXIST) {
struct extent_map *existing; struct extent_map *existing;
existing = search_extent_mapping(em_tree, start, len); existing = search_extent_mapping(&inode->extent_tree, start, len);
trace_btrfs_handle_em_exist(fs_info, existing, em, start, len); trace_btrfs_handle_em_exist(fs_info, existing, em, start, len);
...@@ -609,8 +609,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode, ...@@ -609,8 +609,7 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode,
* The existing extent map is the one nearest to * The existing extent map is the one nearest to
* the [start, start + len) range which overlaps * the [start, start + len) range which overlaps
*/ */
ret = merge_extent_mapping(em_tree, existing, ret = merge_extent_mapping(inode, existing, em, start);
em, start);
if (WARN_ON(ret)) { if (WARN_ON(ret)) {
free_extent_map(em); free_extent_map(em);
*em_in = NULL; *em_in = NULL;
...@@ -818,8 +817,7 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end, ...@@ -818,8 +817,7 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end,
} else { } else {
int ret; int ret;
ret = add_extent_mapping(em_tree, split, ret = add_extent_mapping(inode, split, modified);
modified);
/* Logic error, shouldn't happen. */ /* Logic error, shouldn't happen. */
ASSERT(ret == 0); ASSERT(ret == 0);
if (WARN_ON(ret != 0) && modified) if (WARN_ON(ret != 0) && modified)
...@@ -909,7 +907,7 @@ int btrfs_replace_extent_map_range(struct btrfs_inode *inode, ...@@ -909,7 +907,7 @@ int btrfs_replace_extent_map_range(struct btrfs_inode *inode,
do { do {
btrfs_drop_extent_map_range(inode, new_em->start, end, false); btrfs_drop_extent_map_range(inode, new_em->start, end, false);
write_lock(&tree->lock); write_lock(&tree->lock);
ret = add_extent_mapping(tree, new_em, modified); ret = add_extent_mapping(inode, new_em, modified);
write_unlock(&tree->lock); write_unlock(&tree->lock);
} while (ret == -EEXIST); } while (ret == -EEXIST);
...@@ -990,7 +988,7 @@ int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre, ...@@ -990,7 +988,7 @@ int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre,
split_mid->ram_bytes = split_mid->len; split_mid->ram_bytes = split_mid->len;
split_mid->flags = flags; split_mid->flags = flags;
split_mid->generation = em->generation; split_mid->generation = em->generation;
add_extent_mapping(em_tree, split_mid, 1); add_extent_mapping(inode, split_mid, 1);
/* Once for us */ /* Once for us */
free_extent_map(em); free_extent_map(em);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment