Commit ef9f95ba authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Improve error handling for for_each_btree_key_continue()

Change it to match for_each_btree_key()
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b43a0f60
...@@ -246,6 +246,11 @@ static inline struct bkey_s_c __bch2_btree_iter_next(struct btree_iter *iter, ...@@ -246,6 +246,11 @@ static inline struct bkey_s_c __bch2_btree_iter_next(struct btree_iter *iter,
: bch2_btree_iter_next(iter); : bch2_btree_iter_next(iter);
} }
static inline int bkey_err(struct bkey_s_c k)
{
return PTR_ERR_OR_ZERO(k.k);
}
#define for_each_btree_key(_trans, _iter, _btree_id, \ #define for_each_btree_key(_trans, _iter, _btree_id, \
_start, _flags, _k, _ret) \ _start, _flags, _k, _ret) \
for ((_ret) = PTR_ERR_OR_ZERO((_iter) = \ for ((_ret) = PTR_ERR_OR_ZERO((_iter) = \
...@@ -257,16 +262,11 @@ static inline struct bkey_s_c __bch2_btree_iter_next(struct btree_iter *iter, ...@@ -257,16 +262,11 @@ static inline struct bkey_s_c __bch2_btree_iter_next(struct btree_iter *iter,
(_ret) = PTR_ERR_OR_ZERO(((_k) = \ (_ret) = PTR_ERR_OR_ZERO(((_k) = \
__bch2_btree_iter_next(_iter, _flags)).k)) __bch2_btree_iter_next(_iter, _flags)).k))
#define for_each_btree_key_continue(_iter, _flags, _k) \ #define for_each_btree_key_continue(_iter, _flags, _k, _ret) \
for ((_k) = __bch2_btree_iter_peek(_iter, _flags); \ for ((_k) = __bch2_btree_iter_peek(_iter, _flags); \
!IS_ERR_OR_NULL((_k).k); \ !((_ret) = bkey_err(_k)) && (_k).k; \
(_k) = __bch2_btree_iter_next(_iter, _flags)) (_k) = __bch2_btree_iter_next(_iter, _flags))
static inline int bkey_err(struct bkey_s_c k)
{
return PTR_ERR_OR_ZERO(k.k);
}
/* new multiple iterator interface: */ /* new multiple iterator interface: */
int bch2_trans_iter_put(struct btree_trans *, struct btree_iter *); int bch2_trans_iter_put(struct btree_trans *, struct btree_iter *);
......
...@@ -248,7 +248,7 @@ static int hash_check_duplicates(struct btree_trans *trans, ...@@ -248,7 +248,7 @@ static int hash_check_duplicates(struct btree_trans *trans,
iter = bch2_trans_copy_iter(trans, h->chain); iter = bch2_trans_copy_iter(trans, h->chain);
BUG_ON(IS_ERR(iter)); BUG_ON(IS_ERR(iter));
for_each_btree_key_continue(iter, 0, k2) { for_each_btree_key_continue(iter, 0, k2, ret) {
if (bkey_cmp(k2.k->p, k.k->p) >= 0) if (bkey_cmp(k2.k->p, k.k->p) >= 0)
break; break;
...@@ -458,7 +458,7 @@ static int check_extents(struct bch_fs *c) ...@@ -458,7 +458,7 @@ static int check_extents(struct bch_fs *c)
iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
POS(BCACHEFS_ROOT_INO, 0), 0); POS(BCACHEFS_ROOT_INO, 0), 0);
retry: retry:
for_each_btree_key_continue(iter, 0, k) { for_each_btree_key_continue(iter, 0, k, ret) {
ret = walk_inode(&trans, &w, k.k->p.inode); ret = walk_inode(&trans, &w, k.k->p.inode);
if (ret) if (ret)
break; break;
...@@ -553,7 +553,7 @@ static int check_dirents(struct bch_fs *c) ...@@ -553,7 +553,7 @@ static int check_dirents(struct bch_fs *c)
iter = bch2_trans_get_iter(&trans, BTREE_ID_DIRENTS, iter = bch2_trans_get_iter(&trans, BTREE_ID_DIRENTS,
POS(BCACHEFS_ROOT_INO, 0), 0); POS(BCACHEFS_ROOT_INO, 0), 0);
retry: retry:
for_each_btree_key_continue(iter, 0, k) { for_each_btree_key_continue(iter, 0, k, ret) {
struct bkey_s_c_dirent d; struct bkey_s_c_dirent d;
struct bch_inode_unpacked target; struct bch_inode_unpacked target;
bool have_target; bool have_target;
...@@ -707,7 +707,7 @@ static int check_xattrs(struct bch_fs *c) ...@@ -707,7 +707,7 @@ static int check_xattrs(struct bch_fs *c)
iter = bch2_trans_get_iter(&trans, BTREE_ID_XATTRS, iter = bch2_trans_get_iter(&trans, BTREE_ID_XATTRS,
POS(BCACHEFS_ROOT_INO, 0), 0); POS(BCACHEFS_ROOT_INO, 0), 0);
retry: retry:
for_each_btree_key_continue(iter, 0, k) { for_each_btree_key_continue(iter, 0, k, ret) {
ret = walk_inode(&trans, &w, k.k->p.inode); ret = walk_inode(&trans, &w, k.k->p.inode);
if (ret) if (ret)
break; break;
...@@ -995,7 +995,7 @@ static int check_directory_structure(struct bch_fs *c, ...@@ -995,7 +995,7 @@ static int check_directory_structure(struct bch_fs *c,
iter = bch2_trans_get_iter(&trans, BTREE_ID_INODES, POS_MIN, 0); iter = bch2_trans_get_iter(&trans, BTREE_ID_INODES, POS_MIN, 0);
retry: retry:
for_each_btree_key_continue(iter, 0, k) { for_each_btree_key_continue(iter, 0, k, ret) {
if (k.k->type != KEY_TYPE_inode) if (k.k->type != KEY_TYPE_inode)
continue; continue;
...@@ -1021,7 +1021,7 @@ static int check_directory_structure(struct bch_fs *c, ...@@ -1021,7 +1021,7 @@ static int check_directory_structure(struct bch_fs *c,
had_unreachable = true; had_unreachable = true;
} }
} }
ret = bch2_trans_iter_free(&trans, iter); bch2_trans_iter_free(&trans, iter);
if (ret) if (ret)
goto err; goto err;
......
...@@ -187,6 +187,7 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans, ...@@ -187,6 +187,7 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans,
{ {
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
int ret;
iter = bch2_trans_copy_iter(trans, start); iter = bch2_trans_copy_iter(trans, start);
if (IS_ERR(iter)) if (IS_ERR(iter))
...@@ -194,7 +195,7 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans, ...@@ -194,7 +195,7 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans,
bch2_btree_iter_next_slot(iter); bch2_btree_iter_next_slot(iter);
for_each_btree_key_continue(iter, BTREE_ITER_SLOTS, k) { for_each_btree_key_continue(iter, BTREE_ITER_SLOTS, k, ret) {
if (k.k->type != desc.key_type && if (k.k->type != desc.key_type &&
k.k->type != KEY_TYPE_whiteout) k.k->type != KEY_TYPE_whiteout)
break; break;
...@@ -206,7 +207,8 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans, ...@@ -206,7 +207,8 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans,
} }
} }
return bch2_trans_iter_free(trans, iter); bch2_trans_iter_free(trans, iter);
return ret;
} }
static __always_inline static __always_inline
......
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