Skip to content

Commit 2efbc35

Browse files
author
Kent Overstreet
committed
bcachefs: Improve decompression error messages
Ratelimit them, and use the new bch2_write_op_error() helper that prints path and file offset. Reported-by: koverstreet/bcachefs#819 Signed-off-by: Kent Overstreet <[email protected]>
1 parent c9c8a17 commit 2efbc35

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

fs/bcachefs/compress.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "compress.h"
55
#include "error.h"
66
#include "extents.h"
7+
#include "io_write.h"
78
#include "opts.h"
89
#include "super-io.h"
910

@@ -254,29 +255,41 @@ static int __bio_uncompress(struct bch_fs *c, struct bio *src,
254255
goto out;
255256
}
256257

257-
int bch2_bio_uncompress_inplace(struct bch_fs *c, struct bio *bio,
258-
struct bch_extent_crc_unpacked *crc)
258+
int bch2_bio_uncompress_inplace(struct bch_write_op *op,
259+
struct bio *bio)
259260
{
261+
struct bch_fs *c = op->c;
262+
struct bch_extent_crc_unpacked *crc = &op->crc;
260263
struct bbuf data = { NULL };
261264
size_t dst_len = crc->uncompressed_size << 9;
265+
int ret = 0;
262266

263267
/* bio must own its pages: */
264268
BUG_ON(!bio->bi_vcnt);
265269
BUG_ON(DIV_ROUND_UP(crc->live_size, PAGE_SECTORS) > bio->bi_max_vecs);
266270

267271
if (crc->uncompressed_size << 9 > c->opts.encoded_extent_max ||
268272
crc->compressed_size << 9 > c->opts.encoded_extent_max) {
269-
bch_err(c, "error rewriting existing data: extent too big");
273+
struct printbuf buf = PRINTBUF;
274+
bch2_write_op_error(&buf, op);
275+
prt_printf(&buf, "error rewriting existing data: extent too big");
276+
bch_err_ratelimited(c, "%s", buf.buf);
277+
printbuf_exit(&buf);
270278
return -EIO;
271279
}
272280

273281
data = __bounce_alloc(c, dst_len, WRITE);
274282

275283
if (__bio_uncompress(c, bio, data.b, *crc)) {
276-
if (!c->opts.no_data_io)
277-
bch_err(c, "error rewriting existing data: decompression error");
278-
bio_unmap_or_unbounce(c, data);
279-
return -EIO;
284+
if (!c->opts.no_data_io) {
285+
struct printbuf buf = PRINTBUF;
286+
bch2_write_op_error(&buf, op);
287+
prt_printf(&buf, "error rewriting existing data: decompression error");
288+
bch_err_ratelimited(c, "%s", buf.buf);
289+
printbuf_exit(&buf);
290+
}
291+
ret = -EIO;
292+
goto err;
280293
}
281294

282295
/*
@@ -293,9 +306,9 @@ int bch2_bio_uncompress_inplace(struct bch_fs *c, struct bio *bio,
293306
crc->uncompressed_size = crc->live_size;
294307
crc->offset = 0;
295308
crc->csum = (struct bch_csum) { 0, 0 };
296-
309+
err:
297310
bio_unmap_or_unbounce(c, data);
298-
return 0;
311+
return ret;
299312
}
300313

301314
int bch2_bio_uncompress(struct bch_fs *c, struct bio *src,

fs/bcachefs/compress.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static inline enum bch_compression_type bch2_compression_opt_to_type(unsigned v)
4747
return __bch2_compression_opt_to_type[bch2_compression_decode(v).type];
4848
}
4949

50-
int bch2_bio_uncompress_inplace(struct bch_fs *, struct bio *,
51-
struct bch_extent_crc_unpacked *);
50+
struct bch_write_op;
51+
int bch2_bio_uncompress_inplace(struct bch_write_op *, struct bio *);
5252
int bch2_bio_uncompress(struct bch_fs *, struct bio *, struct bio *,
5353
struct bvec_iter, struct bch_extent_crc_unpacked);
5454
unsigned bch2_bio_compress(struct bch_fs *, struct bio *, size_t *,

fs/bcachefs/io_write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static void __bch2_write_op_error(struct printbuf *out, struct bch_write_op *op,
406406
op->flags & BCH_WRITE_MOVE ? "(internal move)" : "");
407407
}
408408

409-
static void bch2_write_op_error(struct printbuf *out, struct bch_write_op *op)
409+
void bch2_write_op_error(struct printbuf *out, struct bch_write_op *op)
410410
{
411411
__bch2_write_op_error(out, op, op->pos.offset);
412412
}
@@ -873,7 +873,7 @@ static enum prep_encoded_ret {
873873
if (bch2_crc_cmp(op->crc.csum, csum) && !c->opts.no_data_io)
874874
return PREP_ENCODED_CHECKSUM_ERR;
875875

876-
if (bch2_bio_uncompress_inplace(c, bio, &op->crc))
876+
if (bch2_bio_uncompress_inplace(op, bio))
877877
return PREP_ENCODED_ERR;
878878
}
879879

fs/bcachefs/io_write.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ static inline void bch2_latency_acct(struct bch_dev *ca, u64 submit_time, int rw
2020
void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *,
2121
enum bch_data_type, const struct bkey_i *, bool);
2222

23+
void bch2_write_op_error(struct printbuf *out, struct bch_write_op *op);
24+
2325
#define BCH_WRITE_FLAGS() \
2426
x(ALLOC_NOWAIT) \
2527
x(CACHED) \

0 commit comments

Comments
 (0)