Skip to content

Commit 09b9c72

Browse files
author
Kent Overstreet
committed
bcachefs: bch_err_throw()
Add a tracepoint for any time we return an error and unwind. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 36a2fdf commit 09b9c72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+459
-405
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "error.h"
2222
#include "lru.h"
2323
#include "recovery.h"
24-
#include "trace.h"
2524
#include "varint.h"
2625

2726
#include <linux/kthread.h>
@@ -866,7 +865,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
866865

867866
struct bch_dev *ca = bch2_dev_bucket_tryget(c, new.k->p);
868867
if (!ca)
869-
return -BCH_ERR_trigger_alloc;
868+
return bch_err_throw(c, trigger_alloc);
870869

871870
struct bch_alloc_v4 old_a_convert;
872871
const struct bch_alloc_v4 *old_a = bch2_alloc_to_v4(old, &old_a_convert);
@@ -1045,7 +1044,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
10451044
invalid_bucket:
10461045
bch2_fs_inconsistent(c, "reference to invalid bucket\n%s",
10471046
(bch2_bkey_val_to_text(&buf, c, new.s_c), buf.buf));
1048-
ret = -BCH_ERR_trigger_alloc;
1047+
ret = bch_err_throw(c, trigger_alloc);
10491048
goto err;
10501049
}
10511050

@@ -1459,7 +1458,7 @@ int bch2_check_discard_freespace_key(struct btree_trans *trans, struct btree_ite
14591458
ret = bch2_btree_bit_mod_iter(trans, iter, false) ?:
14601459
bch2_trans_commit(trans, NULL, NULL,
14611460
BCH_TRANS_COMMIT_no_enospc) ?:
1462-
-BCH_ERR_transaction_restart_commit;
1461+
bch_err_throw(c, transaction_restart_commit);
14631462
goto out;
14641463
} else {
14651464
/*
@@ -1782,13 +1781,14 @@ int bch2_check_alloc_to_lru_refs(struct bch_fs *c)
17821781

17831782
static int discard_in_flight_add(struct bch_dev *ca, u64 bucket, bool in_progress)
17841783
{
1784+
struct bch_fs *c = ca->fs;
17851785
int ret;
17861786

17871787
mutex_lock(&ca->discard_buckets_in_flight_lock);
17881788
struct discard_in_flight *i =
17891789
darray_find_p(ca->discard_buckets_in_flight, i, i->bucket == bucket);
17901790
if (i) {
1791-
ret = -BCH_ERR_EEXIST_discard_in_flight_add;
1791+
ret = bch_err_throw(c, EEXIST_discard_in_flight_add);
17921792
goto out;
17931793
}
17941794

fs/bcachefs/alloc_foreground.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static struct open_bucket *__try_alloc_bucket(struct bch_fs *c,
227227

228228
track_event_change(&c->times[BCH_TIME_blocked_allocate_open_bucket], true);
229229
spin_unlock(&c->freelist_lock);
230-
return ERR_PTR(-BCH_ERR_open_buckets_empty);
230+
return ERR_PTR(bch_err_throw(c, open_buckets_empty));
231231
}
232232

233233
/* Recheck under lock: */
@@ -533,7 +533,7 @@ static struct open_bucket *bch2_bucket_alloc_trans(struct btree_trans *trans,
533533

534534
track_event_change(&c->times[BCH_TIME_blocked_allocate], true);
535535

536-
ob = ERR_PTR(-BCH_ERR_freelist_empty);
536+
ob = ERR_PTR(bch_err_throw(c, freelist_empty));
537537
goto err;
538538
}
539539

@@ -558,7 +558,7 @@ static struct open_bucket *bch2_bucket_alloc_trans(struct btree_trans *trans,
558558
}
559559
err:
560560
if (!ob)
561-
ob = ERR_PTR(-BCH_ERR_no_buckets_found);
561+
ob = ERR_PTR(bch_err_throw(c, no_buckets_found));
562562

563563
if (!IS_ERR(ob))
564564
ob->data_type = req->data_type;
@@ -709,7 +709,7 @@ inline int bch2_bucket_alloc_set_trans(struct btree_trans *trans,
709709
struct closure *cl)
710710
{
711711
struct bch_fs *c = trans->c;
712-
int ret = -BCH_ERR_insufficient_devices;
712+
int ret = 0;
713713

714714
BUG_ON(req->nr_effective >= req->nr_replicas);
715715

@@ -738,13 +738,16 @@ inline int bch2_bucket_alloc_set_trans(struct btree_trans *trans,
738738
continue;
739739
}
740740

741-
if (add_new_bucket(c, req, ob)) {
742-
ret = 0;
741+
ret = add_new_bucket(c, req, ob);
742+
if (ret)
743743
break;
744-
}
745744
}
746745

747-
return ret;
746+
if (ret == 1)
747+
return 0;
748+
if (ret)
749+
return ret;
750+
return bch_err_throw(c, insufficient_devices);
748751
}
749752

750753
/* Allocate from stripes: */
@@ -1373,11 +1376,11 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
13731376
goto retry;
13741377

13751378
if (cl && bch2_err_matches(ret, BCH_ERR_open_buckets_empty))
1376-
ret = -BCH_ERR_bucket_alloc_blocked;
1379+
ret = bch_err_throw(c, bucket_alloc_blocked);
13771380

13781381
if (cl && !(flags & BCH_WRITE_alloc_nowait) &&
13791382
bch2_err_matches(ret, BCH_ERR_freelist_empty))
1380-
ret = -BCH_ERR_bucket_alloc_blocked;
1383+
ret = bch_err_throw(c, bucket_alloc_blocked);
13811384

13821385
return ret;
13831386
}

fs/bcachefs/backpointers.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static noinline int backpointer_mod_err(struct btree_trans *trans,
142142
}
143143

144144
if (!will_check && __bch2_inconsistent_error(c, &buf))
145-
ret = -BCH_ERR_erofs_unfixed_errors;
145+
ret = bch_err_throw(c, erofs_unfixed_errors);
146146

147147
bch_err(c, "%s", buf.buf);
148148
printbuf_exit(&buf);
@@ -295,7 +295,7 @@ static struct btree *__bch2_backpointer_get_node(struct btree_trans *trans,
295295
return b;
296296

297297
if (btree_node_will_make_reachable(b)) {
298-
b = ERR_PTR(-BCH_ERR_backpointer_to_overwritten_btree_node);
298+
b = ERR_PTR(bch_err_throw(c, backpointer_to_overwritten_btree_node));
299299
} else {
300300
int ret = backpointer_target_not_found(trans, bp, bkey_i_to_s_c(&b->key),
301301
last_flushed, commit);
@@ -353,7 +353,7 @@ static struct bkey_s_c __bch2_backpointer_get_key(struct btree_trans *trans,
353353
return ret ? bkey_s_c_err(ret) : bkey_s_c_null;
354354
} else {
355355
struct btree *b = __bch2_backpointer_get_node(trans, bp, iter, last_flushed, commit);
356-
if (b == ERR_PTR(-BCH_ERR_backpointer_to_overwritten_btree_node))
356+
if (b == ERR_PTR(bch_err_throw(c, backpointer_to_overwritten_btree_node)))
357357
return bkey_s_c_null;
358358
if (IS_ERR_OR_NULL(b))
359359
return ((struct bkey_s_c) { .k = ERR_CAST(b) });
@@ -651,7 +651,7 @@ static int check_bp_exists(struct btree_trans *trans,
651651
prt_newline(&buf);
652652
bch2_bkey_val_to_text(&buf, c, other_extent);
653653
bch_err(c, "%s", buf.buf);
654-
ret = -BCH_ERR_fsck_repair_unimplemented;
654+
ret = bch_err_throw(c, fsck_repair_unimplemented);
655655
goto err;
656656
missing:
657657
printbuf_reset(&buf);
@@ -953,7 +953,7 @@ static int check_bucket_backpointer_mismatch(struct btree_trans *trans, struct b
953953
sectors[ALLOC_cached] > a->cached_sectors ||
954954
sectors[ALLOC_stripe] > a->stripe_sectors) {
955955
ret = check_bucket_backpointers_to_extents(trans, ca, alloc_k.k->p) ?:
956-
-BCH_ERR_transaction_restart_nested;
956+
bch_err_throw(c, transaction_restart_nested);
957957
goto err;
958958
}
959959

@@ -1351,7 +1351,7 @@ static int bch2_bucket_bitmap_set(struct bch_dev *ca, struct bucket_bitmap *b, u
13511351
b->buckets = kvcalloc(BITS_TO_LONGS(ca->mi.nbuckets),
13521352
sizeof(unsigned long), GFP_KERNEL);
13531353
if (!b->buckets)
1354-
return -BCH_ERR_ENOMEM_backpointer_mismatches_bitmap;
1354+
return bch_err_throw(ca->fs, ENOMEM_backpointer_mismatches_bitmap);
13551355
}
13561356

13571357
b->nr += !__test_and_set_bit(bit, b->buckets);
@@ -1360,7 +1360,8 @@ static int bch2_bucket_bitmap_set(struct bch_dev *ca, struct bucket_bitmap *b, u
13601360
return 0;
13611361
}
13621362

1363-
int bch2_bucket_bitmap_resize(struct bucket_bitmap *b, u64 old_size, u64 new_size)
1363+
int bch2_bucket_bitmap_resize(struct bch_dev *ca, struct bucket_bitmap *b,
1364+
u64 old_size, u64 new_size)
13641365
{
13651366
scoped_guard(mutex, &b->lock) {
13661367
if (!b->buckets)
@@ -1369,7 +1370,7 @@ int bch2_bucket_bitmap_resize(struct bucket_bitmap *b, u64 old_size, u64 new_siz
13691370
unsigned long *n = kvcalloc(BITS_TO_LONGS(new_size),
13701371
sizeof(unsigned long), GFP_KERNEL);
13711372
if (!n)
1372-
return -BCH_ERR_ENOMEM_backpointer_mismatches_bitmap;
1373+
return bch_err_throw(ca->fs, ENOMEM_backpointer_mismatches_bitmap);
13731374

13741375
memcpy(n, b->buckets,
13751376
BITS_TO_LONGS(min(old_size, new_size)) * sizeof(unsigned long));

fs/bcachefs/backpointers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static inline bool bch2_bucket_bitmap_test(struct bucket_bitmap *b, u64 i)
194194
return bitmap && test_bit(i, bitmap);
195195
}
196196

197-
int bch2_bucket_bitmap_resize(struct bucket_bitmap *, u64, u64);
197+
int bch2_bucket_bitmap_resize(struct bch_dev *, struct bucket_bitmap *, u64, u64);
198198
void bch2_bucket_bitmap_free(struct bucket_bitmap *);
199199

200200
#endif /* _BCACHEFS_BACKPOINTERS_BACKGROUND_H */

fs/bcachefs/bcachefs.h

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@
183183
#define pr_fmt(fmt) "%s() " fmt "\n", __func__
184184
#endif
185185

186+
#ifdef CONFIG_BCACHEFS_DEBUG
187+
#define ENUMERATED_REF_DEBUG
188+
#endif
189+
190+
#ifndef dynamic_fault
191+
#define dynamic_fault(...) 0
192+
#endif
193+
194+
#define race_fault(...) dynamic_fault("bcachefs:race")
195+
186196
#include <linux/backing-dev-defs.h>
187197
#include <linux/bug.h>
188198
#include <linux/bio.h>
@@ -219,15 +229,30 @@
219229
#include "time_stats.h"
220230
#include "util.h"
221231

222-
#ifdef CONFIG_BCACHEFS_DEBUG
223-
#define ENUMERATED_REF_DEBUG
224-
#endif
225-
226-
#ifndef dynamic_fault
227-
#define dynamic_fault(...) 0
228-
#endif
232+
#include "alloc_types.h"
233+
#include "async_objs_types.h"
234+
#include "btree_gc_types.h"
235+
#include "btree_types.h"
236+
#include "btree_node_scan_types.h"
237+
#include "btree_write_buffer_types.h"
238+
#include "buckets_types.h"
239+
#include "buckets_waiting_for_journal_types.h"
240+
#include "clock_types.h"
241+
#include "disk_groups_types.h"
242+
#include "ec_types.h"
243+
#include "enumerated_ref_types.h"
244+
#include "journal_types.h"
245+
#include "keylist_types.h"
246+
#include "quota_types.h"
247+
#include "rebalance_types.h"
248+
#include "recovery_passes_types.h"
249+
#include "replicas_types.h"
250+
#include "sb-members_types.h"
251+
#include "subvolume_types.h"
252+
#include "super_types.h"
253+
#include "thread_with_file_types.h"
229254

230-
#define race_fault(...) dynamic_fault("bcachefs:race")
255+
#include "trace.h"
231256

232257
#define count_event(_c, _name) this_cpu_inc((_c)->counters[BCH_COUNTER_##_name])
233258

@@ -380,6 +405,14 @@ do { \
380405
pr_info(fmt, ##__VA_ARGS__); \
381406
} while (0)
382407

408+
static inline int __bch2_err_trace(struct bch_fs *c, int err)
409+
{
410+
trace_error_throw(c, err, _THIS_IP_);
411+
return err;
412+
}
413+
414+
#define bch_err_throw(_c, _err) __bch2_err_trace(_c, -BCH_ERR_##_err)
415+
383416
/* Parameters that are useful for debugging, but should always be compiled in: */
384417
#define BCH_DEBUG_PARAMS_ALWAYS() \
385418
BCH_DEBUG_PARAM(key_merging_disabled, \
@@ -486,29 +519,6 @@ enum bch_time_stats {
486519
BCH_TIME_STAT_NR
487520
};
488521

489-
#include "alloc_types.h"
490-
#include "async_objs_types.h"
491-
#include "btree_gc_types.h"
492-
#include "btree_types.h"
493-
#include "btree_node_scan_types.h"
494-
#include "btree_write_buffer_types.h"
495-
#include "buckets_types.h"
496-
#include "buckets_waiting_for_journal_types.h"
497-
#include "clock_types.h"
498-
#include "disk_groups_types.h"
499-
#include "ec_types.h"
500-
#include "enumerated_ref_types.h"
501-
#include "journal_types.h"
502-
#include "keylist_types.h"
503-
#include "quota_types.h"
504-
#include "rebalance_types.h"
505-
#include "recovery_passes_types.h"
506-
#include "replicas_types.h"
507-
#include "sb-members_types.h"
508-
#include "subvolume_types.h"
509-
#include "super_types.h"
510-
#include "thread_with_file_types.h"
511-
512522
/* Number of nodes btree coalesce will try to coalesce at once */
513523
#define GC_MERGE_NODES 4U
514524

0 commit comments

Comments
 (0)