From: Kent Overstreet Date: Sun, 21 Feb 2021 03:19:34 +0000 (-0500) Subject: bcachefs: btree_iter_live() X-Git-Tag: Ubuntu-6.8.0-17.17~2238^2~1756 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=1f7fdc0abd743076dac6bc91b293a4ae1bb70e61;p=mirror_ubuntu-kernels.git bcachefs: btree_iter_live() New helper to clean things up a bit - also, improve iter->flags handling. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 1bd7c92d705e..9d3333cd76f9 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -1701,7 +1701,8 @@ struct bkey_s_c bch2_btree_iter_peek_with_updates(struct btree_iter *iter) k = __bch2_btree_iter_peek_with_updates(iter); if (k.k && bkey_deleted(k.k)) { - bch2_btree_iter_advance_pos(iter); + if (!bch2_btree_iter_advance_pos(iter)) + return bkey_s_c_null; continue; } @@ -2008,7 +2009,7 @@ static void btree_trans_iter_alloc_fail(struct btree_trans *trans) bch2_btree_ids[iter->btree_id], iter->pos.inode, iter->pos.offset, - (trans->iters_live & (1ULL << iter->idx)) ? " live" : "", + btree_iter_live(trans, iter) ? " live" : "", (trans->iters_touched & (1ULL << iter->idx)) ? " touched" : "", iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT ? " keep" : "", (void *) iter->ip_allocated); @@ -2089,31 +2090,20 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans, if (!best) { iter = btree_trans_iter_alloc(trans); bch2_btree_iter_init(trans, iter, btree_id, pos, flags); - } else if ((trans->iters_live & (1ULL << best->idx)) || - (best->flags & BTREE_ITER_KEEP_UNTIL_COMMIT)) { + } else if (btree_iter_keep(trans, best)) { iter = btree_trans_iter_alloc(trans); btree_iter_copy(iter, best); } else { iter = best; } - iter->flags &= ~BTREE_ITER_KEEP_UNTIL_COMMIT; - iter->flags &= ~BTREE_ITER_USER_FLAGS; - iter->flags |= flags & BTREE_ITER_USER_FLAGS; + flags |= iter->flags & BTREE_ITER_ERROR; + iter->flags = flags; - if (iter->flags & BTREE_ITER_INTENT) { - if (!iter->locks_want) { - __bch2_btree_iter_unlock(iter); - iter->locks_want = 1; - } - } else + if (!(iter->flags & BTREE_ITER_INTENT)) bch2_btree_iter_downgrade(iter); - - BUG_ON(iter->btree_id != btree_id); - BUG_ON((iter->flags ^ flags) & BTREE_ITER_TYPE); - BUG_ON(iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT); - BUG_ON(iter->flags & BTREE_ITER_SET_POS_AFTER_COMMIT); - BUG_ON(trans->iters_live & (1ULL << iter->idx)); + else if (!iter->locks_want) + __bch2_btree_iter_upgrade_nounlock(iter, 1); trans->iters_live |= 1ULL << iter->idx; trans->iters_touched |= 1ULL << iter->idx; diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 12c519ae2a60..e2469436f53b 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -289,6 +289,17 @@ struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *, enum btree_id, struct bpos, unsigned, unsigned, unsigned); +static inline bool btree_iter_live(struct btree_trans *trans, struct btree_iter *iter) +{ + return (trans->iters_live & (1ULL << iter->idx)) != 0; +} + +static inline bool btree_iter_keep(struct btree_trans *trans, struct btree_iter *iter) +{ + return btree_iter_live(trans, iter) || + (iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT); +} + #define TRANS_RESET_NOTRAVERSE (1 << 0) void bch2_trans_reset(struct btree_trans *, unsigned); diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h index ee30ac745ee8..b12a4f9dd1d0 100644 --- a/fs/bcachefs/btree_types.h +++ b/fs/bcachefs/btree_types.h @@ -216,13 +216,6 @@ enum btree_iter_type { #define BTREE_ITER_CACHED_NOFILL (1 << 9) #define BTREE_ITER_CACHED_NOCREATE (1 << 10) -#define BTREE_ITER_USER_FLAGS \ - (BTREE_ITER_SLOTS \ - |BTREE_ITER_INTENT \ - |BTREE_ITER_PREFETCH \ - |BTREE_ITER_CACHED_NOFILL \ - |BTREE_ITER_CACHED_NOCREATE) - enum btree_iter_uptodate { BTREE_ITER_UPTODATE = 0, BTREE_ITER_NEED_PEEK = 1, diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c index ad85bc78ea35..315e2e1e229d 100644 --- a/fs/bcachefs/btree_update_leaf.c +++ b/fs/bcachefs/btree_update_leaf.c @@ -512,8 +512,7 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, */ trans_for_each_iter(trans, iter) { if (iter->nodes_locked != iter->nodes_intent_locked) { - if ((iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT) || - (trans->iters_live & (1ULL << iter->idx))) { + if (btree_iter_keep(trans, iter)) { if (!bch2_btree_iter_upgrade(iter, 1)) { trace_trans_restart_upgrade(trans->ip); return -EINTR; @@ -945,7 +944,7 @@ retry: goto err; trans_for_each_iter(trans, iter) - if ((trans->iters_live & (1ULL << iter->idx)) && + if (btree_iter_live(trans, iter) && (iter->flags & BTREE_ITER_SET_POS_AFTER_COMMIT)) bch2_btree_iter_set_pos(iter, iter->pos_after_commit); out: @@ -1049,7 +1048,7 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, * the iterator pos if some other code is using it, so we may * need to clone it: */ - if (trans->iters_live & (1ULL << i->iter->idx)) { + if (btree_iter_live(trans, i->iter)) { i->iter = bch2_trans_copy_iter(trans, i->iter); i->iter->flags |= BTREE_ITER_KEEP_UNTIL_COMMIT;