Commit 1cab5e72 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba
Browse files

btrfs: merge __set_extent_bit and set_extent_bit



There are only 2 direct calls to set_extent_bit outside of extent-io -
in btrfs_find_new_delalloc_bytes and btrfs_truncate_block, the rest are
thin wrappers around __set_extent_bit. This adds unnecessary indirection
and just makes it more annoying when looking at the various extent bit
manipulation functions.  This patch renames __set_extent_bit to
set_extent_bit effectively removing a level of indirection. No
functional changes.

Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
[ reformat and remove __must_check ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 729f7961
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -168,14 +168,17 @@ static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start,
int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
			   unsigned bits, struct extent_changeset *changeset);
int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
		   unsigned bits, struct extent_state **cached_state, gfp_t mask);
		   unsigned bits, unsigned exclusive_bits, u64 *failed_start,
		   struct extent_state **cached_state, gfp_t mask,
		   struct extent_changeset *changeset);
int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end,
			   unsigned bits);

static inline int set_extent_bits(struct extent_io_tree *tree, u64 start,
		u64 end, unsigned bits)
{
	return set_extent_bit(tree, start, end, bits, NULL, GFP_NOFS);
	return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS,
			      NULL);
}

static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
@@ -188,7 +191,8 @@ static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
static inline int set_extent_dirty(struct extent_io_tree *tree, u64 start,
		u64 end, gfp_t mask)
{
	return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL, mask);
	return set_extent_bit(tree, start, end, EXTENT_DIRTY, 0, NULL, NULL,
			      mask, NULL);
}

static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start,
@@ -209,7 +213,7 @@ static inline int set_extent_delalloc(struct extent_io_tree *tree, u64 start,
{
	return set_extent_bit(tree, start, end,
			      EXTENT_DELALLOC | EXTENT_UPTODATE | extra_bits,
			      cached_state, GFP_NOFS);
			      0, NULL, cached_state, GFP_NOFS, NULL);
}

static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start,
@@ -217,20 +221,21 @@ static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start,
{
	return set_extent_bit(tree, start, end,
			      EXTENT_DELALLOC | EXTENT_UPTODATE | EXTENT_DEFRAG,
			      cached_state, GFP_NOFS);
			      0, NULL, cached_state, GFP_NOFS, NULL);
}

static inline int set_extent_new(struct extent_io_tree *tree, u64 start,
		u64 end)
{
	return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, GFP_NOFS);
	return set_extent_bit(tree, start, end, EXTENT_NEW, 0, NULL, NULL,
			      GFP_NOFS, NULL);
}

static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start,
		u64 end, struct extent_state **cached_state, gfp_t mask)
{
	return set_extent_bit(tree, start, end, EXTENT_UPTODATE,
			      cached_state, mask);
	return set_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, NULL,
			      cached_state, mask, NULL);
}

int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
+13 −23
Original line number Diff line number Diff line
@@ -961,12 +961,10 @@ static void cache_state(struct extent_state *state,
 *
 * [start, end] is inclusive This takes the tree lock.
 */

static int __must_check
__set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
		 unsigned bits, unsigned exclusive_bits,
		 u64 *failed_start, struct extent_state **cached_state,
		 gfp_t mask, struct extent_changeset *changeset)
int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, unsigned bits,
		   unsigned exclusive_bits, u64 *failed_start,
		   struct extent_state **cached_state, gfp_t mask,
		   struct extent_changeset *changeset)
{
	struct extent_state *state;
	struct extent_state *prealloc = NULL;
@@ -1183,14 +1181,6 @@ __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,

}

int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
		   unsigned bits, struct extent_state **cached_state, gfp_t mask)
{
	return __set_extent_bit(tree, start, end, bits, 0, NULL, cached_state,
			        mask, NULL);
}


/**
 * convert_extent_bit - convert all bits in a given range from one bit to
 * 			another
@@ -1421,14 +1411,14 @@ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
	 */
	BUG_ON(bits & EXTENT_LOCKED);

	return __set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS,
	return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS,
			      changeset);
}

int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end,
			   unsigned bits)
{
	return __set_extent_bit(tree, start, end, bits, 0, NULL, NULL,
	return set_extent_bit(tree, start, end, bits, 0, NULL, NULL,
			      GFP_NOWAIT, NULL);
}

@@ -1464,7 +1454,7 @@ int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
	u64 failed_start;

	while (1) {
		err = __set_extent_bit(tree, start, end, EXTENT_LOCKED,
		err = set_extent_bit(tree, start, end, EXTENT_LOCKED,
				     EXTENT_LOCKED, &failed_start,
				     cached_state, GFP_NOFS, NULL);
		if (err == -EEXIST) {
@@ -1482,7 +1472,7 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end)
	int err;
	u64 failed_start;

	err = __set_extent_bit(tree, start, end, EXTENT_LOCKED, EXTENT_LOCKED,
	err = set_extent_bit(tree, start, end, EXTENT_LOCKED, EXTENT_LOCKED,
			     &failed_start, NULL, GFP_NOFS, NULL);
	if (err == -EEXIST) {
		if (failed_start > start)
+3 −3
Original line number Diff line number Diff line
@@ -2340,8 +2340,8 @@ static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode,

		ret = set_extent_bit(&inode->io_tree, search_start,
				     search_start + em_len - 1,
				     EXTENT_DELALLOC_NEW,
				     NULL, cached_state, GFP_NOFS);
				     EXTENT_DELALLOC_NEW, 0, NULL, cached_state,
				     GFP_NOFS, NULL);
next:
		search_start = extent_map_end(em);
		free_extent_map(em);
@@ -4769,7 +4769,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,

	if (only_release_metadata)
		set_extent_bit(&inode->io_tree, block_start, block_end,
			       EXTENT_NORESERVE, NULL, GFP_NOFS);
			       EXTENT_NORESERVE, 0, NULL, NULL, GFP_NOFS, NULL);

out_unlock:
	if (ret) {