Commit bd015294 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba
Browse files

btrfs: replace delete argument with EXTENT_CLEAR_ALL_BITS



Instead of taking up a whole argument to indicate we're clearing
everything in a range, simply add another EXTENT bit to control this,
and then update all the callers to drop this argument from the
clear_extent_bit variants.

Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent b71fb16b
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -547,8 +547,7 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
 * This takes the tree lock, and returns 0 on success and < 0 on error.
 */
int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
		       u32 bits, int delete,
		       struct extent_state **cached_state,
		       u32 bits, struct extent_state **cached_state,
		       gfp_t mask, struct extent_changeset *changeset)
{
	struct extent_state *state;
@@ -557,17 +556,19 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
	u64 last_end;
	int err;
	int clear = 0;
	int wake = (bits & EXTENT_LOCKED) ? 1 : 0;
	int wake;
	int delete = (bits & EXTENT_CLEAR_ALL_BITS);

	btrfs_debug_check_extent_io_range(tree, start, end);
	trace_btrfs_clear_extent_bit(tree, start, end - start + 1, bits);

	if (bits & EXTENT_DELALLOC)
		bits |= EXTENT_NORESERVE;

	if (delete)
		bits |= ~EXTENT_CTLBITS;

	if (bits & EXTENT_DELALLOC)
		bits |= EXTENT_NORESERVE;

	wake = (bits & EXTENT_LOCKED) ? 1 : 0;
	if (bits & (EXTENT_LOCKED | EXTENT_BOUNDARY))
		clear = 1;
again:
@@ -1610,7 +1611,7 @@ int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
	 */
	ASSERT(!(bits & EXTENT_LOCKED));

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

@@ -1624,7 +1625,7 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end)
	if (err == -EEXIST) {
		if (failed_start > start)
			clear_extent_bit(tree, start, failed_start - 1,
					 EXTENT_LOCKED, 0, NULL);
					 EXTENT_LOCKED, NULL);
		return 0;
	}
	return 1;
+18 −10
Original line number Diff line number Diff line
@@ -35,10 +35,18 @@ struct io_failure_record;
 * delalloc bytes decremented, in an atomic way to prevent races with stat(2).
 */
#define EXTENT_ADD_INODE_BYTES  (1U << 15)

/*
 * Set during truncate when we're clearing an entire range and we just want the
 * extent states to go away.
 */
#define EXTENT_CLEAR_ALL_BITS	(1U << 16)

#define EXTENT_DO_ACCOUNTING    (EXTENT_CLEAR_META_RESV | \
				 EXTENT_CLEAR_DATA_RESV)
#define EXTENT_CTLBITS		(EXTENT_DO_ACCOUNTING | \
				 EXTENT_ADD_INODE_BYTES)
				 EXTENT_ADD_INODE_BYTES | \
				 EXTENT_CLEAR_ALL_BITS)

/*
 * Redefined bits above which are used only in the device allocation tree,
@@ -114,35 +122,35 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
			     u32 bits, struct extent_changeset *changeset);
int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
		       u32 bits, int delete, struct extent_state **cached,
		       gfp_t mask, struct extent_changeset *changeset);
		       u32 bits, struct extent_state **cached, gfp_t mask,
		       struct extent_changeset *changeset);

static inline int clear_extent_bit(struct extent_io_tree *tree, u64 start,
				   u64 end, u32 bits, int delete,
				   u64 end, u32 bits,
				   struct extent_state **cached)
{
	return __clear_extent_bit(tree, start, end, bits, delete, cached,
	return __clear_extent_bit(tree, start, end, bits, cached,
				  GFP_NOFS, NULL);
}

static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end,
				struct extent_state **cached)
{
	return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached,
	return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, cached,
				  GFP_NOFS, NULL);
}

static inline int unlock_extent_atomic(struct extent_io_tree *tree, u64 start,
				       u64 end, struct extent_state **cached)
{
	return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached,
	return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, cached,
				  GFP_ATOMIC, NULL);
}

static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start,
				    u64 end, u32 bits)
{
	return clear_extent_bit(tree, start, end, bits, 0, NULL);
	return clear_extent_bit(tree, start, end, bits, NULL);
}

int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
@@ -165,7 +173,7 @@ static inline int set_extent_bits(struct extent_io_tree *tree, u64 start,
static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
		u64 end, struct extent_state **cached_state)
{
	return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0,
	return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE,
				  cached_state, GFP_NOFS, NULL);
}

@@ -180,7 +188,7 @@ static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start,
{
	return clear_extent_bit(tree, start, end,
				EXTENT_DIRTY | EXTENT_DELALLOC |
				EXTENT_DO_ACCOUNTING, 0, cached);
				EXTENT_DO_ACCOUNTING, cached);
}

int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
+2 −2
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
				  struct page *locked_page,
				  u32 clear_bits, unsigned long page_ops)
{
	clear_extent_bit(&inode->io_tree, start, end, clear_bits, 0, NULL);
	clear_extent_bit(&inode->io_tree, start, end, clear_bits, NULL);

	__process_pages_contig(inode->vfs_inode.i_mapping, locked_page,
			       start, end, page_ops, NULL);
@@ -3397,7 +3397,7 @@ static int try_release_extent_state(struct extent_io_tree *tree,
		 * The delalloc new bit will be cleared by ordered extent
		 * completion.
		 */
		ret = __clear_extent_bit(tree, start, end, clear_bits, 0, NULL,
		ret = __clear_extent_bit(tree, start, end, clear_bits, NULL,
					 mask, NULL);

		/* if clear_extent_bit failed for enomem reasons,
+1 −1
Original line number Diff line number Diff line
@@ -382,7 +382,7 @@ static void extent_map_device_clear_bits(struct extent_map *em, unsigned bits)

		__clear_extent_bit(&device->alloc_state, stripe->physical,
				   stripe->physical + stripe_size - 1, bits,
				   0, NULL, GFP_NOWAIT, NULL);
				   NULL, GFP_NOWAIT, NULL);
	}
}

+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
	if (btrfs_fs_incompat(inode->root->fs_info, NO_HOLES))
		return 0;
	return clear_extent_bit(&inode->file_extent_tree, start,
				start + len - 1, EXTENT_DIRTY, 0, NULL);
				start + len - 1, EXTENT_DIRTY, NULL);
}

static inline u32 max_ordered_sum_bytes(struct btrfs_fs_info *fs_info,
Loading