diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-07-25 17:19:52 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:09 -0400 |
commit | e5af273fcefb13cdd9e3c27d9ee6c52ee6b12264 (patch) | |
tree | 327c6ec4946a2b6ba92702a1b55db28ed731f8a2 /fs/bcachefs/btree_key_cache.c | |
parent | 3cc5288a62f2657b99faab428f993673ca9d033f (diff) | |
download | lwn-e5af273fcefb13cdd9e3c27d9ee6c52ee6b12264.tar.gz lwn-e5af273fcefb13cdd9e3c27d9ee6c52ee6b12264.zip |
bcachefs: trans->restarted
Start tracking when btree transactions have been restarted - and assert
that we're always calling bch2_trans_begin() immediately after
transaction restart.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/btree_key_cache.c')
-rw-r--r-- | fs/bcachefs/btree_key_cache.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c index cb71fe0dd742..8fb18ad2e1ae 100644 --- a/fs/bcachefs/btree_key_cache.c +++ b/fs/bcachefs/btree_key_cache.c @@ -215,7 +215,7 @@ static int btree_key_cache_fill(struct btree_trans *trans, if (!bch2_btree_node_relock(ck_iter, 0)) { trace_transaction_restart_ip(trans->ip, _THIS_IP_); - ret = -EINTR; + ret = btree_trans_restart(trans); goto err; } @@ -234,6 +234,10 @@ static int btree_key_cache_fill(struct btree_trans *trans, } } + /* + * XXX: not allowed to be holding read locks when we take a write lock, + * currently + */ bch2_btree_node_lock_write(ck_iter->l[0].b, ck_iter); if (new_k) { kfree(ck->k); @@ -300,10 +304,8 @@ retry: if (!btree_node_lock((void *) ck, iter->pos, 0, iter, lock_want, bkey_cached_check_fn, iter, _THIS_IP_)) { - if (ck->key.btree_id != iter->btree_id || - bpos_cmp(ck->key.pos, iter->pos)) { + if (!trans->restarted) goto retry; - } trace_transaction_restart_ip(trans->ip, _THIS_IP_); ret = -EINTR; @@ -323,10 +325,10 @@ retry: iter->l[0].b = (void *) ck; fill: if (!ck->valid && !(iter->flags & BTREE_ITER_CACHED_NOFILL)) { - if (!btree_node_intent_locked(iter, 0)) - bch2_btree_iter_upgrade(iter, 1); - if (!btree_node_intent_locked(iter, 0)) { + if (!iter->locks_want && + !!__bch2_btree_iter_upgrade(iter, 1)) { trace_transaction_restart_ip(trans->ip, _THIS_IP_); + BUG_ON(!trans->restarted); ret = -EINTR; goto err; } @@ -342,9 +344,12 @@ fill: iter->uptodate = BTREE_ITER_NEED_PEEK; if ((iter->flags & BTREE_ITER_INTENT) && - !iter->locks_want && - __bch2_btree_iter_upgrade(iter, 1)) + !bch2_btree_iter_upgrade(iter, 1)) { + BUG_ON(!trans->restarted); ret = -EINTR; + } + + BUG_ON(!ret && !btree_node_locked(iter, 0)); return ret; err: |