Skip to content

Commit 2aee59e

Browse files
author
Kent Overstreet
committed
bcachefs: improve error messages in bch2_ec_read_extent()
Signed-off-by: Kent Overstreet <[email protected]>
1 parent cb771fe commit 2aee59e

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

fs/bcachefs/ec.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,16 @@ static int get_stripe_key_trans(struct btree_trans *trans, u64 idx,
829829
}
830830

831831
/* recovery read path: */
832-
int bch2_ec_read_extent(struct btree_trans *trans, struct bch_read_bio *rbio)
832+
int bch2_ec_read_extent(struct btree_trans *trans, struct bch_read_bio *rbio,
833+
struct bkey_s_c orig_k)
833834
{
834835
struct bch_fs *c = trans->c;
835-
struct ec_stripe_buf *buf;
836+
struct ec_stripe_buf *buf = NULL;
836837
struct closure cl;
837838
struct bch_stripe *v;
838839
unsigned i, offset;
840+
const char *msg = NULL;
841+
struct printbuf msgbuf = PRINTBUF;
839842
int ret = 0;
840843

841844
closure_init_stack(&cl);
@@ -848,42 +851,36 @@ int bch2_ec_read_extent(struct btree_trans *trans, struct bch_read_bio *rbio)
848851

849852
ret = lockrestart_do(trans, get_stripe_key_trans(trans, rbio->pick.ec.idx, buf));
850853
if (ret) {
851-
bch_err_ratelimited(c,
852-
"error doing reconstruct read: error %i looking up stripe", ret);
853-
kfree(buf);
854-
return -BCH_ERR_stripe_reconstruct;
854+
msg = "stripe not found";
855+
goto err;
855856
}
856857

857858
v = &bkey_i_to_stripe(&buf->key)->v;
858859

859860
if (!bch2_ptr_matches_stripe(v, rbio->pick)) {
860-
bch_err_ratelimited(c,
861-
"error doing reconstruct read: pointer doesn't match stripe");
862-
ret = -BCH_ERR_stripe_reconstruct;
861+
msg = "pointer doesn't match stripe";
863862
goto err;
864863
}
865864

866865
offset = rbio->bio.bi_iter.bi_sector - v->ptrs[rbio->pick.ec.block].offset;
867866
if (offset + bio_sectors(&rbio->bio) > le16_to_cpu(v->sectors)) {
868-
bch_err_ratelimited(c,
869-
"error doing reconstruct read: read is bigger than stripe");
870-
ret = -BCH_ERR_stripe_reconstruct;
867+
msg = "read is bigger than stripe";
871868
goto err;
872869
}
873870

874871
ret = ec_stripe_buf_init(buf, offset, bio_sectors(&rbio->bio));
875-
if (ret)
872+
if (ret) {
873+
msg = "-ENOMEM";
876874
goto err;
875+
}
877876

878877
for (i = 0; i < v->nr_blocks; i++)
879878
ec_block_io(c, buf, REQ_OP_READ, i, &cl);
880879

881880
closure_sync(&cl);
882881

883882
if (ec_nr_failed(buf) > v->nr_redundant) {
884-
bch_err_ratelimited(c,
885-
"error doing reconstruct read: unable to read enough blocks");
886-
ret = -BCH_ERR_stripe_reconstruct;
883+
msg = "unable to read enough blocks";
887884
goto err;
888885
}
889886

@@ -895,10 +892,17 @@ int bch2_ec_read_extent(struct btree_trans *trans, struct bch_read_bio *rbio)
895892

896893
memcpy_to_bio(&rbio->bio, rbio->bio.bi_iter,
897894
buf->data[rbio->pick.ec.block] + ((offset - buf->offset) << 9));
898-
err:
895+
out:
899896
ec_stripe_buf_exit(buf);
900897
kfree(buf);
901898
return ret;
899+
err:
900+
bch2_bkey_val_to_text(&msgbuf, c, orig_k);
901+
bch_err_ratelimited(c,
902+
"error doing reconstruct read: %s\n %s", msg, msgbuf.buf);
903+
printbuf_exit(&msgbuf);;
904+
ret = -BCH_ERR_stripe_reconstruct;
905+
goto out;
902906
}
903907

904908
/* stripe bucket accounting: */

fs/bcachefs/ec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct ec_stripe_head {
206206
struct ec_stripe_new *s;
207207
};
208208

209-
int bch2_ec_read_extent(struct btree_trans *, struct bch_read_bio *);
209+
int bch2_ec_read_extent(struct btree_trans *, struct bch_read_bio *, struct bkey_s_c);
210210

211211
void *bch2_writepoint_ec_buf(struct bch_fs *, struct write_point *);
212212

fs/bcachefs/io_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
10921092
trans->notrace_relock_fail = true;
10931093
} else {
10941094
/* Attempting reconstruct read: */
1095-
if (bch2_ec_read_extent(trans, rbio)) {
1095+
if (bch2_ec_read_extent(trans, rbio, k)) {
10961096
bch2_rbio_error(rbio, READ_RETRY_AVOID, BLK_STS_IOERR);
10971097
goto out;
10981098
}

0 commit comments

Comments
 (0)