Commit 3a8d1db3 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba
Browse files

btrfs: unify overwrite_item() and do_overwrite_item()



After commit 193df624 ("btrfs: search for last logged dir index if
it's not cached in the inode"), there are no more callers of
do_overwrite_item(), except overwrite_item().

Originally both used to be the same function, but were split in
commit 086dcbfa ("btrfs: insert items in batches when logging a
directory when possible"), as there was the need to execute all logic
of overwrite_item() but skip the tree search, since in the context of
directory logging we already had a path with a leaf to copy data from.

So unify them again as there is no more need to have them split.

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 63d5429f
Loading
Loading
Loading
Loading
+24 −52
Original line number Diff line number Diff line
@@ -365,7 +365,21 @@ static int process_one_buffer(struct btrfs_root *log,
	return ret;
}

static int do_overwrite_item(struct btrfs_trans_handle *trans,
/*
 * Item overwrite used by replay and tree logging.  eb, slot and key all refer
 * to the src data we are copying out.
 *
 * root is the tree we are copying into, and path is a scratch
 * path for use in this function (it should be released on entry and
 * will be released on exit).
 *
 * If the key is already in the destination tree the existing item is
 * overwritten.  If the existing item isn't big enough, it is extended.
 * If it is too large, it is truncated.
 *
 * If the key isn't in the destination yet, a new item is inserted.
 */
static int overwrite_item(struct btrfs_trans_handle *trans,
			  struct btrfs_root *root,
			  struct btrfs_path *path,
			  struct extent_buffer *eb, int slot,
@@ -386,22 +400,10 @@ static int do_overwrite_item(struct btrfs_trans_handle *trans,
	item_size = btrfs_item_size(eb, slot);
	src_ptr = btrfs_item_ptr_offset(eb, slot);

	/* Our caller must have done a search for the key for us. */
	ASSERT(path->nodes[0] != NULL);

	/*
	 * And the slot must point to the exact key or the slot where the key
	 * should be at (the first item with a key greater than 'key')
	 */
	if (path->slots[0] < btrfs_header_nritems(path->nodes[0])) {
		struct btrfs_key found_key;

		btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
		ret = btrfs_comp_cpu_keys(&found_key, key);
		ASSERT(ret >= 0);
	} else {
		ret = 1;
	}
	/* Look for the key in the destination tree. */
	ret = btrfs_search_slot(NULL, root, key, path, 0, 0);
	if (ret < 0)
		return ret;

	if (ret == 0) {
		char *src_copy;
@@ -579,36 +581,6 @@ static int do_overwrite_item(struct btrfs_trans_handle *trans,
	return 0;
}

/*
 * Item overwrite used by replay and tree logging.  eb, slot and key all refer
 * to the src data we are copying out.
 *
 * root is the tree we are copying into, and path is a scratch
 * path for use in this function (it should be released on entry and
 * will be released on exit).
 *
 * If the key is already in the destination tree the existing item is
 * overwritten.  If the existing item isn't big enough, it is extended.
 * If it is too large, it is truncated.
 *
 * If the key isn't in the destination yet, a new item is inserted.
 */
static int overwrite_item(struct btrfs_trans_handle *trans,
			  struct btrfs_root *root,
			  struct btrfs_path *path,
			  struct extent_buffer *eb, int slot,
			  struct btrfs_key *key)
{
	int ret;

	/* Look for the key in the destination tree. */
	ret = btrfs_search_slot(NULL, root, key, path, 0, 0);
	if (ret < 0)
		return ret;

	return do_overwrite_item(trans, root, path, eb, slot, key);
}

static int read_alloc_one_name(struct extent_buffer *eb, void *start, int len,
			       struct fscrypt_str *name)
{
@@ -5406,7 +5378,7 @@ struct btrfs_dir_list {
 *    has a size that doesn't match the sum of the lengths of all the logged
 *    names - this is ok, not a problem, because at log replay time we set the
 *    directory's i_size to the correct value (see replay_one_name() and
 *    do_overwrite_item()).
 *    overwrite_item()).
 */
static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
				struct btrfs_inode *start_inode,