From ef9f95ba41b7685fc27ca73753bbfa4467555b79 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 25 Sep 2019 15:57:56 -0400 Subject: [PATCH] bcachefs: Improve error handling for for_each_btree_key_continue() Change it to match for_each_btree_key() Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.h | 14 +++++++------- fs/bcachefs/fsck.c | 12 ++++++------ fs/bcachefs/str_hash.h | 6 ++++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 7f76db5bb8bc..9b5e3de68487 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -246,6 +246,11 @@ static inline struct bkey_s_c __bch2_btree_iter_next(struct btree_iter *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, \ _start, _flags, _k, _ret) \ 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, (_ret) = PTR_ERR_OR_ZERO(((_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); \ - !IS_ERR_OR_NULL((_k).k); \ + !((_ret) = bkey_err(_k)) && (_k).k; \ (_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: */ int bch2_trans_iter_put(struct btree_trans *, struct btree_iter *); diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index 162563b809fb..b806284c0517 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -248,7 +248,7 @@ static int hash_check_duplicates(struct btree_trans *trans, iter = bch2_trans_copy_iter(trans, h->chain); 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) break; @@ -458,7 +458,7 @@ static int check_extents(struct bch_fs *c) iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, POS(BCACHEFS_ROOT_INO, 0), 0); 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); if (ret) break; @@ -553,7 +553,7 @@ static int check_dirents(struct bch_fs *c) iter = bch2_trans_get_iter(&trans, BTREE_ID_DIRENTS, POS(BCACHEFS_ROOT_INO, 0), 0); 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 bch_inode_unpacked target; bool have_target; @@ -707,7 +707,7 @@ static int check_xattrs(struct bch_fs *c) iter = bch2_trans_get_iter(&trans, BTREE_ID_XATTRS, POS(BCACHEFS_ROOT_INO, 0), 0); 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); if (ret) break; @@ -995,7 +995,7 @@ up: iter = bch2_trans_get_iter(&trans, BTREE_ID_INODES, POS_MIN, 0); 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) continue; @@ -1021,7 +1021,7 @@ retry: had_unreachable = true; } } - ret = bch2_trans_iter_free(&trans, iter); + bch2_trans_iter_free(&trans, iter); if (ret) goto err; diff --git a/fs/bcachefs/str_hash.h b/fs/bcachefs/str_hash.h index df3f19055d1e..31b278e71051 100644 --- a/fs/bcachefs/str_hash.h +++ b/fs/bcachefs/str_hash.h @@ -187,6 +187,7 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans, { struct btree_iter *iter; struct bkey_s_c k; + int ret; iter = bch2_trans_copy_iter(trans, start); if (IS_ERR(iter)) @@ -194,7 +195,7 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans, 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 && k.k->type != KEY_TYPE_whiteout) break; @@ -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 -- 2.39.5