Commit 2279a270 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: make get_state_failrec return failrec directly

Only failure that get_state_failrec can get is if there is no failure
for the given address. There is no reason why the function should return
a status code and use a separate parameter for returning the actual
failure rec (if one is found). Simplify it by making the return type
a pointer and return ERR_PTR value in case of errors.
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 b90a4ab6
...@@ -233,8 +233,7 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, ...@@ -233,8 +233,7 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start,
struct extent_state **cached_state); struct extent_state **cached_state);
/* This should be reworked in the future and put elsewhere. */ /* This should be reworked in the future and put elsewhere. */
int get_state_failrec(struct extent_io_tree *tree, u64 start, struct io_failure_record *get_state_failrec(struct extent_io_tree *tree, u64 start);
struct io_failure_record **failrec);
int set_state_failrec(struct extent_io_tree *tree, u64 start, int set_state_failrec(struct extent_io_tree *tree, u64 start,
struct io_failure_record *failrec); struct io_failure_record *failrec);
void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start,
......
...@@ -2122,12 +2122,11 @@ int set_state_failrec(struct extent_io_tree *tree, u64 start, ...@@ -2122,12 +2122,11 @@ int set_state_failrec(struct extent_io_tree *tree, u64 start,
return ret; return ret;
} }
int get_state_failrec(struct extent_io_tree *tree, u64 start, struct io_failure_record *get_state_failrec(struct extent_io_tree *tree, u64 start)
struct io_failure_record **failrec)
{ {
struct rb_node *node; struct rb_node *node;
struct extent_state *state; struct extent_state *state;
int ret = 0; struct io_failure_record *failrec;
spin_lock(&tree->lock); spin_lock(&tree->lock);
/* /*
...@@ -2136,18 +2135,19 @@ int get_state_failrec(struct extent_io_tree *tree, u64 start, ...@@ -2136,18 +2135,19 @@ int get_state_failrec(struct extent_io_tree *tree, u64 start,
*/ */
node = tree_search(tree, start); node = tree_search(tree, start);
if (!node) { if (!node) {
ret = -ENOENT; failrec = ERR_PTR(-ENOENT);
goto out; goto out;
} }
state = rb_entry(node, struct extent_state, rb_node); state = rb_entry(node, struct extent_state, rb_node);
if (state->start != start) { if (state->start != start) {
ret = -ENOENT; failrec = ERR_PTR(-ENOENT);
goto out; goto out;
} }
*failrec = state->failrec;
failrec = state->failrec;
out: out:
spin_unlock(&tree->lock); spin_unlock(&tree->lock);
return ret; return failrec;
} }
/* /*
...@@ -2377,8 +2377,8 @@ int clean_io_failure(struct btrfs_fs_info *fs_info, ...@@ -2377,8 +2377,8 @@ int clean_io_failure(struct btrfs_fs_info *fs_info,
if (!ret) if (!ret)
return 0; return 0;
ret = get_state_failrec(failure_tree, start, &failrec); failrec = get_state_failrec(failure_tree, start);
if (ret) if (IS_ERR(failrec))
return 0; return 0;
BUG_ON(!failrec->this_mirror); BUG_ON(!failrec->this_mirror);
...@@ -2462,8 +2462,8 @@ int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end, ...@@ -2462,8 +2462,8 @@ int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end,
int ret; int ret;
u64 logical; u64 logical;
ret = get_state_failrec(failure_tree, start, &failrec); failrec = get_state_failrec(failure_tree, start);
if (ret) { if (IS_ERR(failrec)) {
failrec = kzalloc(sizeof(*failrec), GFP_NOFS); failrec = kzalloc(sizeof(*failrec), GFP_NOFS);
if (!failrec) if (!failrec)
return -ENOMEM; return -ENOMEM;
......
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