Skip to content

Commit c122799

Browse files
lorddoskiaskdave
authored andcommitted
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: Josef Bacik <[email protected]> Signed-off-by: Nikolay Borisov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1b58ae0 commit c122799

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

fs/btrfs/ctree.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,33 +1349,34 @@ static noinline void unlock_up(struct btrfs_path *path, int level,
13491349
{
13501350
int i;
13511351
int skip_level = level;
1352-
int no_skips = 0;
1353-
struct extent_buffer *t;
1352+
bool check_skip = true;
13541353

13551354
for (i = level; i < BTRFS_MAX_LEVEL; i++) {
13561355
if (!path->nodes[i])
13571356
break;
13581357
if (!path->locks[i])
13591358
break;
1360-
if (!no_skips && path->slots[i] == 0) {
1361-
skip_level = i + 1;
1362-
continue;
1363-
}
1364-
if (!no_skips && path->keep_locks) {
1365-
u32 nritems;
1366-
t = path->nodes[i];
1367-
nritems = btrfs_header_nritems(t);
1368-
if (nritems < 1 || path->slots[i] >= nritems - 1) {
1359+
1360+
if (check_skip) {
1361+
if (path->slots[i] == 0) {
13691362
skip_level = i + 1;
13701363
continue;
13711364
}
1365+
1366+
if (path->keep_locks) {
1367+
u32 nritems;
1368+
1369+
nritems = btrfs_header_nritems(path->nodes[i]);
1370+
if (nritems < 1 || path->slots[i] >= nritems - 1) {
1371+
skip_level = i + 1;
1372+
continue;
1373+
}
1374+
}
13721375
}
1373-
if (skip_level < i && i >= lowest_unlock)
1374-
no_skips = 1;
13751376

1376-
t = path->nodes[i];
13771377
if (i >= lowest_unlock && i > skip_level) {
1378-
btrfs_tree_unlock_rw(t, path->locks[i]);
1378+
check_skip = false;
1379+
btrfs_tree_unlock_rw(path->nodes[i], path->locks[i]);
13791380
path->locks[i] = 0;
13801381
if (write_lock_level &&
13811382
i > min_write_lock_level &&

0 commit comments

Comments
 (0)