]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: btree_iter_live()
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 21 Feb 2021 03:19:34 +0000 (22:19 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:55 +0000 (17:08 -0400)
New helper to clean things up a bit - also, improve iter->flags
handling.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_iter.h
fs/bcachefs/btree_types.h
fs/bcachefs/btree_update_leaf.c

index 1bd7c92d705ec7cf5f829fbe16ff72893e5d6111..9d3333cd76f9c0b9d20fb83f0fa8099c5c32144d 100644 (file)
@@ -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;
index 12c519ae2a6095fde4ad49817c74a83482d3f365..e2469436f53b5ae31014c7c5b8ef6076b96553d4 100644 (file)
@@ -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);
index ee30ac745ee88d18e42fa567d3622f2d21e29538..b12a4f9dd1d0179558c0045d2fa59f47975a96f3 100644 (file)
@@ -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,
index ad85bc78ea35f82315fffd5501e821267b96abf3..315e2e1e229d7eef465a2f6a9418f921f95596ad 100644 (file)
@@ -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;