Skip to content

Commit 8a9f3d0

Browse files
author
Kent Overstreet
committed
bcachefs: EIO cleanup
Replace these with proper private error codes, so that when we get an error message we're not sifting through the entire codebase to see where it came from. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 127d90d commit 8a9f3d0

13 files changed

Lines changed: 73 additions & 59 deletions

fs/bcachefs/alloc_background.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
837837

838838
struct bch_dev *ca = bch2_dev_bucket_tryget(c, new.k->p);
839839
if (!ca)
840-
return -EIO;
840+
return -BCH_ERR_trigger_alloc;
841841

842842
struct bch_alloc_v4 old_a_convert;
843843
const struct bch_alloc_v4 *old_a = bch2_alloc_to_v4(old, &old_a_convert);
@@ -1031,7 +1031,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
10311031
invalid_bucket:
10321032
bch2_fs_inconsistent(c, "reference to invalid bucket\n %s",
10331033
(bch2_bkey_val_to_text(&buf, c, new.s_c), buf.buf));
1034-
ret = -EIO;
1034+
ret = -BCH_ERR_trigger_alloc;
10351035
goto err;
10361036
}
10371037

fs/bcachefs/alloc_foreground.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ void __bch2_open_bucket_put(struct bch_fs *c, struct open_bucket *ob)
127127

128128
void bch2_open_bucket_write_error(struct bch_fs *c,
129129
struct open_buckets *obs,
130-
unsigned dev)
130+
unsigned dev, int err)
131131
{
132132
struct open_bucket *ob;
133133
unsigned i;
134134

135135
open_bucket_for_each(c, obs, ob, i)
136136
if (ob->dev == dev && ob->ec)
137-
bch2_ec_bucket_cancel(c, ob);
137+
bch2_ec_bucket_cancel(c, ob, err);
138138
}
139139

140140
static struct open_bucket *bch2_open_bucket_alloc(struct bch_fs *c)

fs/bcachefs/alloc_foreground.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static inline struct open_bucket *ec_open_bucket(struct bch_fs *c,
8282
}
8383

8484
void bch2_open_bucket_write_error(struct bch_fs *,
85-
struct open_buckets *, unsigned);
85+
struct open_buckets *, unsigned, int);
8686

8787
void __bch2_open_bucket_put(struct bch_fs *, struct open_bucket *);
8888

fs/bcachefs/checksum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ int bch2_rechecksum_bio(struct bch_fs *c, struct bio *bio,
466466
prt_str(&buf, ")");
467467
WARN_RATELIMIT(1, "%s", buf.buf);
468468
printbuf_exit(&buf);
469-
return -EIO;
469+
return -BCH_ERR_recompute_checksum;
470470
}
471471

472472
for (i = splits; i < splits + ARRAY_SIZE(splits); i++) {

fs/bcachefs/compress.c

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int __bio_uncompress(struct bch_fs *c, struct bio *src,
177177
size_t src_len = src->bi_iter.bi_size;
178178
size_t dst_len = crc.uncompressed_size << 9;
179179
void *workspace;
180-
int ret;
180+
int ret = 0, ret2;
181181

182182
enum bch_compression_opts opt = bch2_compression_type_to_opt(crc.compression_type);
183183
mempool_t *workspace_pool = &c->compress_workspace[opt];
@@ -189,18 +189,18 @@ static int __bio_uncompress(struct bch_fs *c, struct bio *src,
189189
else
190190
ret = -BCH_ERR_compression_workspace_not_initialized;
191191
if (ret)
192-
goto out;
192+
goto err;
193193
}
194194

195195
src_data = bio_map_or_bounce(c, src, READ);
196196

197197
switch (crc.compression_type) {
198198
case BCH_COMPRESSION_TYPE_lz4_old:
199199
case BCH_COMPRESSION_TYPE_lz4:
200-
ret = LZ4_decompress_safe_partial(src_data.b, dst_data,
201-
src_len, dst_len, dst_len);
202-
if (ret != dst_len)
203-
goto err;
200+
ret2 = LZ4_decompress_safe_partial(src_data.b, dst_data,
201+
src_len, dst_len, dst_len);
202+
if (ret2 != dst_len)
203+
ret = -BCH_ERR_decompress_lz4;
204204
break;
205205
case BCH_COMPRESSION_TYPE_gzip: {
206206
z_stream strm = {
@@ -214,45 +214,43 @@ static int __bio_uncompress(struct bch_fs *c, struct bio *src,
214214

215215
zlib_set_workspace(&strm, workspace);
216216
zlib_inflateInit2(&strm, -MAX_WBITS);
217-
ret = zlib_inflate(&strm, Z_FINISH);
217+
ret2 = zlib_inflate(&strm, Z_FINISH);
218218

219219
mempool_free(workspace, workspace_pool);
220220

221-
if (ret != Z_STREAM_END)
222-
goto err;
221+
if (ret2 != Z_STREAM_END)
222+
ret = -BCH_ERR_decompress_gzip;
223223
break;
224224
}
225225
case BCH_COMPRESSION_TYPE_zstd: {
226226
ZSTD_DCtx *ctx;
227227
size_t real_src_len = le32_to_cpup(src_data.b);
228228

229-
if (real_src_len > src_len - 4)
229+
if (real_src_len > src_len - 4) {
230+
ret = -BCH_ERR_decompress_zstd_src_len_bad;
230231
goto err;
232+
}
231233

232234
workspace = mempool_alloc(workspace_pool, GFP_NOFS);
233235
ctx = zstd_init_dctx(workspace, zstd_dctx_workspace_bound());
234236

235-
ret = zstd_decompress_dctx(ctx,
237+
ret2 = zstd_decompress_dctx(ctx,
236238
dst_data, dst_len,
237239
src_data.b + 4, real_src_len);
238240

239241
mempool_free(workspace, workspace_pool);
240242

241-
if (ret != dst_len)
242-
goto err;
243+
if (ret2 != dst_len)
244+
ret = -BCH_ERR_decompress_zstd;
243245
break;
244246
}
245247
default:
246248
BUG();
247249
}
248-
ret = 0;
250+
err:
249251
fsck_err:
250-
out:
251252
bio_unmap_or_unbounce(c, src_data);
252253
return ret;
253-
err:
254-
ret = -EIO;
255-
goto out;
256254
}
257255

258256
int bch2_bio_uncompress_inplace(struct bch_write_op *op,
@@ -268,18 +266,22 @@ int bch2_bio_uncompress_inplace(struct bch_write_op *op,
268266
BUG_ON(!bio->bi_vcnt);
269267
BUG_ON(DIV_ROUND_UP(crc->live_size, PAGE_SECTORS) > bio->bi_max_vecs);
270268

271-
if (crc->uncompressed_size << 9 > c->opts.encoded_extent_max ||
272-
crc->compressed_size << 9 > c->opts.encoded_extent_max) {
273-
bch2_write_op_error(op, op->pos.offset, "extent too big to decompress");
274-
return -EIO;
269+
if (crc->uncompressed_size << 9 > c->opts.encoded_extent_max) {
270+
bch2_write_op_error(op, op->pos.offset,
271+
"extent too big to decompress (%u > %u)",
272+
crc->uncompressed_size << 9, c->opts.encoded_extent_max);
273+
return -BCH_ERR_decompress_exceeded_max_encoded_extent;
275274
}
276275

277276
data = __bounce_alloc(c, dst_len, WRITE);
278277

279-
if (__bio_uncompress(c, bio, data.b, *crc)) {
280-
if (!c->opts.no_data_io)
281-
bch2_write_op_error(op, op->pos.offset, "decompression error");
282-
ret = -EIO;
278+
ret = __bio_uncompress(c, bio, data.b, *crc);
279+
280+
if (c->opts.no_data_io)
281+
ret = 0;
282+
283+
if (ret) {
284+
bch2_write_op_error(op, op->pos.offset, "%s", bch2_err_str(ret));
283285
goto err;
284286
}
285287

@@ -312,7 +314,7 @@ int bch2_bio_uncompress(struct bch_fs *c, struct bio *src,
312314

313315
if (crc.uncompressed_size << 9 > c->opts.encoded_extent_max ||
314316
crc.compressed_size << 9 > c->opts.encoded_extent_max)
315-
return -EIO;
317+
return -BCH_ERR_decompress_exceeded_max_encoded_extent;
316318

317319
dst_data = dst_len == dst_iter.bi_size
318320
? __bio_map_or_bounce(c, dst, dst_iter, WRITE)

fs/bcachefs/data_update.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
354354
printbuf_exit(&buf);
355355

356356
bch2_fatal_error(c);
357-
ret = -EIO;
357+
ret = -BCH_ERR_invalid_bkey;
358358
goto out;
359359
}
360360

fs/bcachefs/ec.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ static int ec_stripe_update_extent(struct btree_trans *trans,
11241124

11251125
bch2_fs_inconsistent(c, "%s", buf.buf);
11261126
printbuf_exit(&buf);
1127-
return -EIO;
1127+
return -BCH_ERR_erasure_coding_found_btree_node;
11281128
}
11291129

11301130
k = bch2_backpointer_get_key(trans, bp, &iter, BTREE_ITER_intent, last_flushed);
@@ -1190,7 +1190,7 @@ static int ec_stripe_update_bucket(struct btree_trans *trans, struct ec_stripe_b
11901190

11911191
struct bch_dev *ca = bch2_dev_tryget(c, ptr.dev);
11921192
if (!ca)
1193-
return -EIO;
1193+
return -BCH_ERR_ENOENT_dev_not_found;
11941194

11951195
struct bpos bucket_pos = PTR_BUCKET_POS(ca, &ptr);
11961196

@@ -1227,21 +1227,19 @@ static int ec_stripe_update_extents(struct bch_fs *c, struct ec_stripe_buf *s)
12271227
{
12281228
struct btree_trans *trans = bch2_trans_get(c);
12291229
struct bch_stripe *v = &bkey_i_to_stripe(&s->key)->v;
1230-
unsigned i, nr_data = v->nr_blocks - v->nr_redundant;
1231-
int ret = 0;
1230+
unsigned nr_data = v->nr_blocks - v->nr_redundant;
12321231

1233-
ret = bch2_btree_write_buffer_flush_sync(trans);
1232+
int ret = bch2_btree_write_buffer_flush_sync(trans);
12341233
if (ret)
12351234
goto err;
12361235

1237-
for (i = 0; i < nr_data; i++) {
1236+
for (unsigned i = 0; i < nr_data; i++) {
12381237
ret = ec_stripe_update_bucket(trans, s, i);
12391238
if (ret)
12401239
break;
12411240
}
12421241
err:
12431242
bch2_trans_put(trans);
1244-
12451243
return ret;
12461244
}
12471245

@@ -1451,11 +1449,11 @@ static void ec_stripe_new_cancel(struct bch_fs *c, struct ec_stripe_head *h, int
14511449
ec_stripe_new_set_pending(c, h);
14521450
}
14531451

1454-
void bch2_ec_bucket_cancel(struct bch_fs *c, struct open_bucket *ob)
1452+
void bch2_ec_bucket_cancel(struct bch_fs *c, struct open_bucket *ob, int err)
14551453
{
14561454
struct ec_stripe_new *s = ob->ec;
14571455

1458-
s->err = -EIO;
1456+
s->err = err;
14591457
}
14601458

14611459
void *bch2_writepoint_ec_buf(struct bch_fs *c, struct write_point *wp)

fs/bcachefs/ec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int bch2_ec_read_extent(struct btree_trans *, struct bch_read_bio *, struct bkey
249249

250250
void *bch2_writepoint_ec_buf(struct bch_fs *, struct write_point *);
251251

252-
void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *);
252+
void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *, int);
253253

254254
int bch2_ec_stripe_new_alloc(struct bch_fs *, struct ec_stripe_head *);
255255

fs/bcachefs/errcode.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
x(ENOENT, ENOENT_snapshot_tree) \
117117
x(ENOENT, ENOENT_dirent_doesnt_match_inode) \
118118
x(ENOENT, ENOENT_dev_not_found) \
119+
x(ENOENT, ENOENT_dev_bucket_not_found) \
119120
x(ENOENT, ENOENT_dev_idx_not_found) \
120121
x(ENOENT, ENOENT_inode_no_backpointer) \
121122
x(ENOENT, ENOENT_no_snapshot_tree_subvol) \
@@ -207,6 +208,7 @@
207208
x(EINVAL, no_resize_with_buckets_nouse) \
208209
x(EINVAL, inode_unpack_error) \
209210
x(EINVAL, varint_decode_error) \
211+
x(EINVAL, erasure_coding_found_btree_node) \
210212
x(EOPNOTSUPP, may_not_use_incompat_feature) \
211213
x(EROFS, erofs_trans_commit) \
212214
x(EROFS, erofs_no_writes) \
@@ -267,6 +269,7 @@
267269
x(BCH_ERR_operation_blocked, nocow_lock_blocked) \
268270
x(EIO, journal_shutdown) \
269271
x(EIO, journal_flush_err) \
272+
x(EIO, journal_write_err) \
270273
x(EIO, btree_node_read_err) \
271274
x(BCH_ERR_btree_node_read_err, btree_node_read_err_cached) \
272275
x(EIO, sb_not_downgraded) \
@@ -275,6 +278,7 @@
275278
x(EIO, btree_node_read_validate_error) \
276279
x(EIO, btree_need_topology_repair) \
277280
x(EIO, bucket_ref_update) \
281+
x(EIO, trigger_alloc) \
278282
x(EIO, trigger_pointer) \
279283
x(EIO, trigger_stripe_pointer) \
280284
x(EIO, metadata_bucket_inconsistency) \
@@ -290,7 +294,19 @@
290294
x(EIO, EIO_fault_injected) \
291295
x(EIO, ec_block_read) \
292296
x(EIO, ec_block_write) \
293-
x(EIO, data_read) \
297+
x(EIO, recompute_checksum) \
298+
x(EIO, decompress) \
299+
x(BCH_ERR_decompress, decompress_exceeded_max_encoded_extent) \
300+
x(BCH_ERR_decompress, decompress_lz4) \
301+
x(BCH_ERR_decompress, decompress_gzip) \
302+
x(BCH_ERR_decompress, decompress_zstd_src_len_bad) \
303+
x(BCH_ERR_decompress, decompress_zstd) \
304+
x(EIO, data_write) \
305+
x(BCH_ERR_data_write, data_write_io) \
306+
x(BCH_ERR_data_write, data_write_csum) \
307+
x(BCH_ERR_data_write, data_write_invalid_ptr) \
308+
x(BCH_ERR_data_write, data_write_misaligned) \
309+
x(BCH_ERR_decompress, data_read) \
294310
x(BCH_ERR_data_read, no_device_to_read_from) \
295311
x(BCH_ERR_data_read, data_read_io_err) \
296312
x(BCH_ERR_data_read, data_read_csum_err) \

fs/bcachefs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ int bch2_inode_rm(struct bch_fs *c, subvol_inum inum)
10791079
bch2_fs_inconsistent(c,
10801080
"inode %llu:%u not found when deleting",
10811081
inum.inum, snapshot);
1082-
ret = -EIO;
1082+
ret = -BCH_ERR_ENOENT_inode;
10831083
goto err;
10841084
}
10851085

@@ -1243,7 +1243,7 @@ static noinline int __bch2_inode_rm_snapshot(struct btree_trans *trans, u64 inum
12431243
bch2_fs_inconsistent(c,
12441244
"inode %llu:%u not found when deleting",
12451245
inum, snapshot);
1246-
ret = -EIO;
1246+
ret = -BCH_ERR_ENOENT_inode;
12471247
goto err;
12481248
}
12491249

0 commit comments

Comments
 (0)