Commit b3047a42 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: send: directly return from will_overwrite_ref() and simplify it

There are no resources to release before will_overwrite_ref() returns, so
we don't really need the 'out' label and jumping to it when conditions are
met - we can directly return and get rid of the label and jumps. Also we
can deal with -ENOENT and other errors in a single if-else logic, as it's
more straightforward.

This helps the next patch in the series to be more simple as well.

This patch is part of a larger patchset and the changelog of the last
patch in the series contains a sample performance test and results.
The patches that comprise the patchset are the following:

  btrfs: send: directly return from did_overwrite_ref() and simplify it
  btrfs: send: avoid unnecessary generation search at did_overwrite_ref()
  btrfs: send: directly return from will_overwrite_ref() and simplify it
  btrfs: send: avoid extra b+tree searches when checking reference overrides
  btrfs: send: remove send_progress argument from can_rmdir()
  btrfs: send: avoid duplicated orphan dir allocation and initialization
  btrfs: send: avoid unnecessary orphan dir rbtree search at can_rmdir()
  btrfs: send: reduce searches on parent root when checking if dir can be removed
  btrfs: send: iterate waiting dir move rbtree only once when processing refs
  btrfs: send: initialize all the red black trees earlier
  btrfs: send: genericize the backref cache to allow it to be reused
  btrfs: adapt lru cache to allow for 64 bits keys on 32 bits systems
  btrfs: send: cache information about created directories
  btrfs: allow a generation number to be associated with lru cache entries
  btrfs: add an api to delete a specific entry from the lru cache
  btrfs: send: use the lru cache to implement the name cache
  btrfs: send: update size of roots array for backref cache entries
  btrfs: send: cache utimes operations for directories if possible
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 cb689481
...@@ -2119,17 +2119,17 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen, ...@@ -2119,17 +2119,17 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen,
const char *name, int name_len, const char *name, int name_len,
u64 *who_ino, u64 *who_gen, u64 *who_mode) u64 *who_ino, u64 *who_gen, u64 *who_mode)
{ {
int ret = 0; int ret;
u64 gen; u64 gen;
u64 other_inode = 0; u64 other_inode = 0;
struct btrfs_inode_info info; struct btrfs_inode_info info;
if (!sctx->parent_root) if (!sctx->parent_root)
goto out; return 0;
ret = is_inode_existent(sctx, dir, dir_gen); ret = is_inode_existent(sctx, dir, dir_gen);
if (ret <= 0) if (ret <= 0)
goto out; return 0;
/* /*
* If we have a parent root we need to verify that the parent dir was * If we have a parent root we need to verify that the parent dir was
...@@ -2138,24 +2138,21 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen, ...@@ -2138,24 +2138,21 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen,
*/ */
if (sctx->parent_root && dir != BTRFS_FIRST_FREE_OBJECTID) { if (sctx->parent_root && dir != BTRFS_FIRST_FREE_OBJECTID) {
ret = get_inode_gen(sctx->parent_root, dir, &gen); ret = get_inode_gen(sctx->parent_root, dir, &gen);
if (ret < 0 && ret != -ENOENT) if (ret == -ENOENT)
goto out; return 0;
if (ret) { else if (ret < 0)
ret = 0; return ret;
goto out;
}
if (gen != dir_gen) if (gen != dir_gen)
goto out; return 0;
} }
ret = lookup_dir_item_inode(sctx->parent_root, dir, name, name_len, ret = lookup_dir_item_inode(sctx->parent_root, dir, name, name_len,
&other_inode); &other_inode);
if (ret < 0 && ret != -ENOENT) if (ret == -ENOENT)
goto out; return 0;
if (ret) { else if (ret < 0)
ret = 0; return ret;
goto out;
}
/* /*
* Check if the overwritten ref was already processed. If yes, the ref * Check if the overwritten ref was already processed. If yes, the ref
...@@ -2166,18 +2163,15 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen, ...@@ -2166,18 +2163,15 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen,
is_waiting_for_move(sctx, other_inode)) { is_waiting_for_move(sctx, other_inode)) {
ret = get_inode_info(sctx->parent_root, other_inode, &info); ret = get_inode_info(sctx->parent_root, other_inode, &info);
if (ret < 0) if (ret < 0)
goto out; return ret;
ret = 1;
*who_ino = other_inode; *who_ino = other_inode;
*who_gen = info.gen; *who_gen = info.gen;
*who_mode = info.mode; *who_mode = info.mode;
} else { return 1;
ret = 0;
} }
out: return 0;
return ret;
} }
/* /*
......
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