Commit c1227996 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: refactor unlock_up

The purpose of this function is to unlock all nodes in a btrfs path
which are above 'lowest_unlock' and whose slot used is different than 0.
As such it used slightly awkward structure of 'if' as well as somewhat
cryptic "no_skip" control variable which denotes whether we should
check the current level of skipability or no.

This patch does the following (cosmetic) refactorings:

* Renames 'no_skip' to 'check_skip' and makes it a boolean. This
  variable controls whether we are below the lowest_unlock/skip_level
  levels.

* Consolidates the 2 conditions which warrant checking whether the
  current level should be skipped under 1 common if (check_skip) branch,
  this increase indentation level but is not critical.

* Consolidates the 'skip_level < i && i >= lowest_unlock' and
  'i >= lowest_unlock && i > skip_level' condition into a common branch
  since those are identical.

* Eliminates the local extent_buffer variable as in this case it doesn't
  bring anything to function readability.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 1b58ae0e
...@@ -1349,33 +1349,34 @@ static noinline void unlock_up(struct btrfs_path *path, int level, ...@@ -1349,33 +1349,34 @@ static noinline void unlock_up(struct btrfs_path *path, int level,
{ {
int i; int i;
int skip_level = level; int skip_level = level;
int no_skips = 0; bool check_skip = true;
struct extent_buffer *t;
for (i = level; i < BTRFS_MAX_LEVEL; i++) { for (i = level; i < BTRFS_MAX_LEVEL; i++) {
if (!path->nodes[i]) if (!path->nodes[i])
break; break;
if (!path->locks[i]) if (!path->locks[i])
break; break;
if (!no_skips && path->slots[i] == 0) {
if (check_skip) {
if (path->slots[i] == 0) {
skip_level = i + 1; skip_level = i + 1;
continue; continue;
} }
if (!no_skips && path->keep_locks) {
if (path->keep_locks) {
u32 nritems; u32 nritems;
t = path->nodes[i];
nritems = btrfs_header_nritems(t); nritems = btrfs_header_nritems(path->nodes[i]);
if (nritems < 1 || path->slots[i] >= nritems - 1) { if (nritems < 1 || path->slots[i] >= nritems - 1) {
skip_level = i + 1; skip_level = i + 1;
continue; continue;
} }
} }
if (skip_level < i && i >= lowest_unlock) }
no_skips = 1;
t = path->nodes[i];
if (i >= lowest_unlock && i > skip_level) { if (i >= lowest_unlock && i > skip_level) {
btrfs_tree_unlock_rw(t, path->locks[i]); check_skip = false;
btrfs_tree_unlock_rw(path->nodes[i], path->locks[i]);
path->locks[i] = 0; path->locks[i] = 0;
if (write_lock_level && if (write_lock_level &&
i > min_write_lock_level && i > min_write_lock_level &&
......
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