Commit 235e1c7b authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: use a single variable to track return value for log_dir_items()

We currently use 'ret' and 'err' to track the return value for
log_dir_items(), which is confusing and likely the cause for previous
bugs where log_dir_items() did not return an error when it should, fixed
in previous patches.

So change this and use only a single variable, 'ret', to track the return
value. This is simpler and makes it similar to most of the existing code.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 5cce1780
...@@ -3793,7 +3793,6 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3793,7 +3793,6 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
struct btrfs_key min_key; struct btrfs_key min_key;
struct btrfs_root *root = inode->root; struct btrfs_root *root = inode->root;
struct btrfs_root *log = root->log_root; struct btrfs_root *log = root->log_root;
int err = 0;
int ret; int ret;
u64 last_old_dentry_offset = min_offset - 1; u64 last_old_dentry_offset = min_offset - 1;
u64 last_offset = (u64)-1; u64 last_offset = (u64)-1;
...@@ -3834,8 +3833,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3834,8 +3833,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
path->slots[0]); path->slots[0]);
if (tmp.type == BTRFS_DIR_INDEX_KEY) if (tmp.type == BTRFS_DIR_INDEX_KEY)
last_old_dentry_offset = tmp.offset; last_old_dentry_offset = tmp.offset;
} else if (ret < 0) { } else if (ret > 0) {
err = ret; ret = 0;
} }
goto done; goto done;
...@@ -3858,7 +3857,6 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3858,7 +3857,6 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
if (tmp.type == BTRFS_DIR_INDEX_KEY) if (tmp.type == BTRFS_DIR_INDEX_KEY)
last_old_dentry_offset = tmp.offset; last_old_dentry_offset = tmp.offset;
} else if (ret < 0) { } else if (ret < 0) {
err = ret;
goto done; goto done;
} }
...@@ -3880,12 +3878,15 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3880,12 +3878,15 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
*/ */
search: search:
ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0);
if (ret > 0) if (ret > 0) {
ret = btrfs_next_item(root, path); ret = btrfs_next_item(root, path);
if (ret > 0) {
/* There are no more keys in the inode's root. */
ret = 0;
goto done;
}
}
if (ret < 0) if (ret < 0)
err = ret;
/* If ret is 1, there are no more keys in the inode's root. */
if (ret != 0)
goto done; goto done;
/* /*
...@@ -3896,8 +3897,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3896,8 +3897,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
ret = process_dir_items_leaf(trans, inode, path, dst_path, ctx, ret = process_dir_items_leaf(trans, inode, path, dst_path, ctx,
&last_old_dentry_offset); &last_old_dentry_offset);
if (ret != 0) { if (ret != 0) {
if (ret < 0) if (ret > 0)
err = ret; ret = 0;
goto done; goto done;
} }
path->slots[0] = btrfs_header_nritems(path->nodes[0]); path->slots[0] = btrfs_header_nritems(path->nodes[0]);
...@@ -3908,10 +3909,10 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3908,10 +3909,10 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
*/ */
ret = btrfs_next_leaf(root, path); ret = btrfs_next_leaf(root, path);
if (ret) { if (ret) {
if (ret == 1) if (ret == 1) {
last_offset = (u64)-1; last_offset = (u64)-1;
else ret = 0;
err = ret; }
goto done; goto done;
} }
btrfs_item_key_to_cpu(path->nodes[0], &min_key, path->slots[0]); btrfs_item_key_to_cpu(path->nodes[0], &min_key, path->slots[0]);
...@@ -3942,7 +3943,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3942,7 +3943,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
btrfs_release_path(path); btrfs_release_path(path);
btrfs_release_path(dst_path); btrfs_release_path(dst_path);
if (err == 0) { if (ret == 0) {
*last_offset_ret = last_offset; *last_offset_ret = last_offset;
/* /*
* In case the leaf was changed in the current transaction but * In case the leaf was changed in the current transaction but
...@@ -3953,15 +3954,13 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3953,15 +3954,13 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
* a range, last_old_dentry_offset is == to last_offset. * a range, last_old_dentry_offset is == to last_offset.
*/ */
ASSERT(last_old_dentry_offset <= last_offset); ASSERT(last_old_dentry_offset <= last_offset);
if (last_old_dentry_offset < last_offset) { if (last_old_dentry_offset < last_offset)
ret = insert_dir_log_key(trans, log, path, ino, ret = insert_dir_log_key(trans, log, path, ino,
last_old_dentry_offset + 1, last_old_dentry_offset + 1,
last_offset); last_offset);
if (ret)
err = ret;
}
} }
return err;
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