Commit 9473cff9 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix more lockdep splats in debug.c

Similar to previous fixes, we can't incur page faults while holding
btree locks.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 462f494b
...@@ -286,7 +286,7 @@ __always_inline ...@@ -286,7 +286,7 @@ __always_inline
static inline int btree_trans_restart_nounlock(struct btree_trans *trans, int err) static inline int btree_trans_restart_nounlock(struct btree_trans *trans, int err)
{ {
BUG_ON(err <= 0); BUG_ON(err <= 0);
BUG_ON(!bch2_err_matches(err, BCH_ERR_transaction_restart)); BUG_ON(!bch2_err_matches(-err, BCH_ERR_transaction_restart));
trans->restarted = err; trans->restarted = err;
trans->last_restarted_ip = _THIS_IP_; trans->last_restarted_ip = _THIS_IP_;
......
...@@ -378,26 +378,25 @@ static ssize_t bch2_read_btree(struct file *file, char __user *buf, ...@@ -378,26 +378,25 @@ static ssize_t bch2_read_btree(struct file *file, char __user *buf,
i->size = size; i->size = size;
i->ret = 0; i->ret = 0;
bch2_trans_init(&trans, i->c, 0, 0); ret = flush_buf(i);
if (ret)
return ret;
bch2_trans_init(&trans, i->c, 0, 0);
ret = for_each_btree_key2(&trans, iter, i->id, i->from, ret = for_each_btree_key2(&trans, iter, i->id, i->from,
BTREE_ITER_PREFETCH| BTREE_ITER_PREFETCH|
BTREE_ITER_ALL_SNAPSHOTS, k, ({ BTREE_ITER_ALL_SNAPSHOTS, k, ({
ret = flush_buf(i);
if (ret)
break;
bch2_bkey_val_to_text(&i->buf, i->c, k); bch2_bkey_val_to_text(&i->buf, i->c, k);
prt_newline(&i->buf); prt_newline(&i->buf);
0; drop_locks_do(&trans, flush_buf(i));
})); }));
i->from = iter.pos; i->from = iter.pos;
bch2_trans_exit(&trans);
if (!ret) if (!ret)
ret = flush_buf(i); ret = flush_buf(i);
bch2_trans_exit(&trans);
return ret ?: i->ret; return ret ?: i->ret;
} }
...@@ -429,19 +428,24 @@ static ssize_t bch2_read_btree_formats(struct file *file, char __user *buf, ...@@ -429,19 +428,24 @@ static ssize_t bch2_read_btree_formats(struct file *file, char __user *buf,
return i->ret; return i->ret;
bch2_trans_init(&trans, i->c, 0, 0); bch2_trans_init(&trans, i->c, 0, 0);
retry:
bch2_trans_begin(&trans);
for_each_btree_node(&trans, iter, i->id, i->from, 0, b, ret) { for_each_btree_node(&trans, iter, i->id, i->from, 0, b, ret) {
ret = flush_buf(i);
if (ret)
break;
bch2_btree_node_to_text(&i->buf, i->c, b); bch2_btree_node_to_text(&i->buf, i->c, b);
i->from = !bpos_eq(SPOS_MAX, b->key.k.p) i->from = !bpos_eq(SPOS_MAX, b->key.k.p)
? bpos_successor(b->key.k.p) ? bpos_successor(b->key.k.p)
: b->key.k.p; : b->key.k.p;
ret = drop_locks_do(&trans, flush_buf(i));
if (ret)
break;
} }
bch2_trans_iter_exit(&trans, &iter); bch2_trans_iter_exit(&trans, &iter);
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
goto retry;
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (!ret) if (!ret)
...@@ -483,17 +487,13 @@ static ssize_t bch2_read_bfloat_failed(struct file *file, char __user *buf, ...@@ -483,17 +487,13 @@ static ssize_t bch2_read_bfloat_failed(struct file *file, char __user *buf,
struct bkey_packed *_k = struct bkey_packed *_k =
bch2_btree_node_iter_peek(&l->iter, l->b); bch2_btree_node_iter_peek(&l->iter, l->b);
ret = flush_buf(i);
if (ret)
break;
if (bpos_gt(l->b->key.k.p, i->prev_node)) { if (bpos_gt(l->b->key.k.p, i->prev_node)) {
bch2_btree_node_to_text(&i->buf, i->c, l->b); bch2_btree_node_to_text(&i->buf, i->c, l->b);
i->prev_node = l->b->key.k.p; i->prev_node = l->b->key.k.p;
} }
bch2_bfloat_to_text(&i->buf, l->b, _k); bch2_bfloat_to_text(&i->buf, l->b, _k);
0; drop_locks_do(&trans, flush_buf(i));
})); }));
i->from = iter.pos; i->from = iter.pos;
......
...@@ -224,7 +224,7 @@ bool __bch2_err_matches(int, int); ...@@ -224,7 +224,7 @@ bool __bch2_err_matches(int, int);
static inline bool _bch2_err_matches(int err, int class) static inline bool _bch2_err_matches(int err, int class)
{ {
return err && __bch2_err_matches(err, class); return err < 0 && __bch2_err_matches(err, class);
} }
#define bch2_err_matches(_err, _class) \ #define bch2_err_matches(_err, _class) \
......
...@@ -1645,7 +1645,7 @@ static void bch2_nocow_write(struct bch_write_op *op) ...@@ -1645,7 +1645,7 @@ static void bch2_nocow_write(struct bch_write_op *op)
percpu_ref_put(&bch_dev_bkey_exists(c, buckets[i].b.inode)->io_ref); percpu_ref_put(&bch_dev_bkey_exists(c, buckets[i].b.inode)->io_ref);
/* We can retry this: */ /* We can retry this: */
ret = BCH_ERR_transaction_restart; ret = -BCH_ERR_transaction_restart;
goto out; goto out;
} }
......
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