Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 920bbbfb authored by Yan, Zheng's avatar Yan, Zheng Committed by Chris Mason
Browse files

Btrfs: Rewrite btrfs_drop_extents



Rewrite btrfs_drop_extents by using btrfs_duplicate_item, so we can
avoid calling lock_extent within transaction.

Signed-off-by: default avatarYan Zheng <zheng.yan@oracle.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent ad48fd75
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -2349,12 +2349,9 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
			    int skip_pinned);
int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
extern const struct file_operations btrfs_file_operations;
int btrfs_drop_extents(struct btrfs_trans_handle *trans,
		       struct btrfs_root *root, struct inode *inode,
		       u64 start, u64 end, u64 locked_end,
		       u64 inline_limit, u64 *hint_block, int drop_cache);
int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
		       u64 start, u64 end, u64 *hint_byte, int drop_cache);
int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
			      struct btrfs_root *root,
			      struct inode *inode, u64 start, u64 end);
int btrfs_release_file(struct inode *inode, struct file *file);

+263 −396

File changed.

Preview size limit exceeded, changes collapsed.

+9 −18
Original line number Diff line number Diff line
@@ -230,8 +230,7 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans,
		return 1;
	}

	ret = btrfs_drop_extents(trans, root, inode, start,
				 aligned_end, aligned_end, start,
	ret = btrfs_drop_extents(trans, inode, start, aligned_end,
				 &hint_byte, 1);
	BUG_ON(ret);

@@ -1596,7 +1595,6 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
				       struct inode *inode, u64 file_pos,
				       u64 disk_bytenr, u64 disk_num_bytes,
				       u64 num_bytes, u64 ram_bytes,
				       u64 locked_end,
				       u8 compression, u8 encryption,
				       u16 other_encoding, int extent_type)
{
@@ -1622,9 +1620,8 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
	 * the caller is expected to unpin it and allow it to be merged
	 * with the others.
	 */
	ret = btrfs_drop_extents(trans, root, inode, file_pos,
				 file_pos + num_bytes, locked_end,
				 file_pos, &hint, 0);
	ret = btrfs_drop_extents(trans, inode, file_pos, file_pos + num_bytes,
				 &hint, 0);
	BUG_ON(ret);

	ins.objectid = inode->i_ino;
@@ -1746,7 +1743,7 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
		compressed = 1;
	if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
		BUG_ON(compressed);
		ret = btrfs_mark_extent_written(trans, root, inode,
		ret = btrfs_mark_extent_written(trans, inode,
						ordered_extent->file_offset,
						ordered_extent->file_offset +
						ordered_extent->len);
@@ -1758,8 +1755,6 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
						ordered_extent->disk_len,
						ordered_extent->len,
						ordered_extent->len,
						ordered_extent->file_offset +
						ordered_extent->len,
						compressed, 0, 0,
						BTRFS_FILE_EXTENT_REG);
		unpin_extent_cache(&BTRFS_I(inode)->extent_tree,
@@ -3209,11 +3204,9 @@ int btrfs_cont_expand(struct inode *inode, loff_t size)
		if (test_bit(EXTENT_FLAG_VACANCY, &em->flags)) {
			u64 hint_byte = 0;
			hole_size = last_byte - cur_offset;
			err = btrfs_drop_extents(trans, root, inode,
						 cur_offset,
			err = btrfs_drop_extents(trans, inode, cur_offset,
						 cur_offset + hole_size,
						 block_end,
						 cur_offset, &hint_byte, 1);
						 &hint_byte, 1);
			if (err)
				break;

@@ -5643,7 +5636,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,

static int prealloc_file_range(struct btrfs_trans_handle *trans,
			       struct inode *inode, u64 start, u64 end,
			       u64 locked_end, u64 alloc_hint, int mode)
			       u64 alloc_hint, int mode)
{
	struct btrfs_root *root = BTRFS_I(inode)->root;
	struct btrfs_key ins;
@@ -5669,8 +5662,7 @@ static int prealloc_file_range(struct btrfs_trans_handle *trans,
		ret = insert_reserved_file_extent(trans, inode,
						  cur_offset, ins.objectid,
						  ins.offset, ins.offset,
						  ins.offset, locked_end,
						  0, 0, 0,
						  ins.offset, 0, 0, 0,
						  BTRFS_FILE_EXTENT_PREALLOC);
		BUG_ON(ret);
		btrfs_drop_extent_cache(inode, cur_offset,
@@ -5779,8 +5771,7 @@ static long btrfs_fallocate(struct inode *inode, int mode,
		last_byte = (last_byte + mask) & ~mask;
		if (em->block_start == EXTENT_MAP_HOLE) {
			ret = prealloc_file_range(trans, inode, cur_offset,
					last_byte, locked_end + 1,
					alloc_hint, mode);
						last_byte, alloc_hint, mode);
			if (ret < 0) {
				free_extent_map(em);
				break;
+1 −2
Original line number Diff line number Diff line
@@ -1027,8 +1027,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
	BUG_ON(!trans);

	/* punch hole in destination first */
	btrfs_drop_extents(trans, root, inode, off, off + len,
			   off + len, 0, &hint_byte, 1);
	btrfs_drop_extents(trans, inode, off, off + len, &hint_byte, 1);

	/* clone data */
	key.objectid = src->i_ino;
+2 −2
Original line number Diff line number Diff line
@@ -542,8 +542,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,

	saved_nbytes = inode_get_bytes(inode);
	/* drop any overlapping extents */
	ret = btrfs_drop_extents(trans, root, inode,
			 start, extent_end, extent_end, start, &alloc_hint, 1);
	ret = btrfs_drop_extents(trans, inode, start, extent_end,
				 &alloc_hint, 1);
	BUG_ON(ret);

	if (found_type == BTRFS_FILE_EXTENT_REG ||