Skip to content

Commit 4a4000b

Browse files
author
Kent Overstreet
committed
bcachefs: Kill JOURNAL_ERRORS()
Convert these to standard error codes, which means we can pass them outside the journal code, they're easier to pass to tracepoints, etc. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 80be08c commit 4a4000b

5 files changed

Lines changed: 62 additions & 78 deletions

File tree

fs/bcachefs/btree_trans_commit.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -880,32 +880,34 @@ int bch2_trans_commit_error(struct btree_trans *trans, unsigned flags,
880880
struct bch_fs *c = trans->c;
881881
enum bch_watermark watermark = flags & BCH_WATERMARK_MASK;
882882

883-
switch (ret) {
884-
case -BCH_ERR_btree_insert_btree_node_full:
885-
ret = bch2_btree_split_leaf(trans, i->path, flags);
886-
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
887-
trace_and_count(c, trans_restart_btree_node_split, trans,
888-
trace_ip, trans->paths + i->path);
889-
break;
890-
case -BCH_ERR_btree_insert_need_mark_replicas:
891-
ret = drop_locks_do(trans,
892-
bch2_accounting_update_sb(trans));
893-
break;
894-
case -BCH_ERR_journal_res_get_blocked:
883+
if (bch2_err_matches(ret, BCH_ERR_journal_res_blocked)) {
895884
/*
896885
* XXX: this should probably be a separate BTREE_INSERT_NONBLOCK
897886
* flag
898887
*/
899888
if ((flags & BCH_TRANS_COMMIT_journal_reclaim) &&
900889
watermark < BCH_WATERMARK_reclaim) {
901890
ret = -BCH_ERR_journal_reclaim_would_deadlock;
902-
break;
891+
goto out;
903892
}
904893

905894
ret = drop_locks_do(trans,
906895
bch2_trans_journal_res_get(trans,
907896
(flags & BCH_WATERMARK_MASK)|
908897
JOURNAL_RES_GET_CHECK));
898+
goto out;
899+
}
900+
901+
switch (ret) {
902+
case -BCH_ERR_btree_insert_btree_node_full:
903+
ret = bch2_btree_split_leaf(trans, i->path, flags);
904+
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
905+
trace_and_count(c, trans_restart_btree_node_split, trans,
906+
trace_ip, trans->paths + i->path);
907+
break;
908+
case -BCH_ERR_btree_insert_need_mark_replicas:
909+
ret = drop_locks_do(trans,
910+
bch2_accounting_update_sb(trans));
909911
break;
910912
case -BCH_ERR_btree_insert_need_journal_reclaim:
911913
bch2_trans_unlock(trans);
@@ -927,7 +929,7 @@ int bch2_trans_commit_error(struct btree_trans *trans, unsigned flags,
927929
BUG_ON(ret >= 0);
928930
break;
929931
}
930-
932+
out:
931933
BUG_ON(bch2_err_matches(ret, BCH_ERR_transaction_restart) != !!trans->restarted);
932934

933935
bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOSPC) &&

fs/bcachefs/errcode.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,18 @@
218218
x(EROFS, insufficient_devices) \
219219
x(0, operation_blocked) \
220220
x(BCH_ERR_operation_blocked, btree_cache_cannibalize_lock_blocked) \
221-
x(BCH_ERR_operation_blocked, journal_res_get_blocked) \
222-
x(BCH_ERR_operation_blocked, journal_preres_get_blocked) \
223-
x(BCH_ERR_operation_blocked, bucket_alloc_blocked) \
224-
x(BCH_ERR_operation_blocked, stripe_alloc_blocked) \
221+
x(BCH_ERR_operation_blocked, journal_res_blocked) \
222+
x(BCH_ERR_journal_res_blocked, journal_blocked) \
223+
x(BCH_ERR_journal_res_blocked, journal_max_in_flight) \
224+
x(BCH_ERR_journal_res_blocked, journal_max_open) \
225+
x(BCH_ERR_journal_res_blocked, journal_full) \
226+
x(BCH_ERR_journal_res_blocked, journal_pin_full) \
227+
x(BCH_ERR_journal_res_blocked, journal_buf_enomem) \
228+
x(BCH_ERR_journal_res_blocked, journal_stuck) \
229+
x(BCH_ERR_journal_res_blocked, journal_retry_open) \
230+
x(BCH_ERR_journal_res_blocked, journal_preres_get_blocked) \
231+
x(BCH_ERR_journal_res_blocked, bucket_alloc_blocked) \
232+
x(BCH_ERR_journal_res_blocked, stripe_alloc_blocked) \
225233
x(BCH_ERR_invalid, invalid_sb) \
226234
x(BCH_ERR_invalid_sb, invalid_sb_magic) \
227235
x(BCH_ERR_invalid_sb, invalid_sb_version) \

fs/bcachefs/journal.c

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
#include "journal_seq_blacklist.h"
2121
#include "trace.h"
2222

23-
static const char * const bch2_journal_errors[] = {
24-
#define x(n) #n,
25-
JOURNAL_ERRORS()
26-
#undef x
27-
NULL
28-
};
29-
3023
static inline bool journal_seq_unwritten(struct journal *j, u64 seq)
3124
{
3225
return seq > j->seq_ondisk;
@@ -149,8 +142,8 @@ journal_error_check_stuck(struct journal *j, int error, unsigned flags)
149142
bool stuck = false;
150143
struct printbuf buf = PRINTBUF;
151144

152-
if (!(error == JOURNAL_ERR_journal_full ||
153-
error == JOURNAL_ERR_journal_pin_full) ||
145+
if (!(error == -BCH_ERR_journal_full ||
146+
error == -BCH_ERR_journal_pin_full) ||
154147
nr_unwritten_journal_entries(j) ||
155148
(flags & BCH_WATERMARK_MASK) != BCH_WATERMARK_reclaim)
156149
return stuck;
@@ -177,7 +170,7 @@ journal_error_check_stuck(struct journal *j, int error, unsigned flags)
177170
spin_unlock(&j->lock);
178171

179172
bch_err(c, "Journal stuck! Hava a pre-reservation but journal full (error %s)",
180-
bch2_journal_errors[error]);
173+
bch2_err_str(error));
181174
bch2_journal_debug_to_text(&buf, j);
182175
bch_err(c, "%s", buf.buf);
183176

@@ -388,32 +381,33 @@ static int journal_entry_open(struct journal *j)
388381
BUG_ON(BCH_SB_CLEAN(c->disk_sb.sb));
389382

390383
if (j->blocked)
391-
return JOURNAL_ERR_blocked;
384+
return -BCH_ERR_journal_blocked;
392385

393386
if (j->cur_entry_error)
394387
return j->cur_entry_error;
395388

396-
if (bch2_journal_error(j))
397-
return JOURNAL_ERR_insufficient_devices; /* -EROFS */
389+
int ret = bch2_journal_error(j);
390+
if (unlikely(ret))
391+
return ret;
398392

399393
if (!fifo_free(&j->pin))
400-
return JOURNAL_ERR_journal_pin_full;
394+
return -BCH_ERR_journal_pin_full;
401395

402396
if (nr_unwritten_journal_entries(j) == ARRAY_SIZE(j->buf))
403-
return JOURNAL_ERR_max_in_flight;
397+
return -BCH_ERR_journal_max_in_flight;
404398

405399
if (atomic64_read(&j->seq) - j->seq_write_started == JOURNAL_STATE_BUF_NR)
406-
return JOURNAL_ERR_max_open;
400+
return -BCH_ERR_journal_max_open;
407401

408402
if (journal_cur_seq(j) >= JOURNAL_SEQ_MAX) {
409403
bch_err(c, "cannot start: journal seq overflow");
410404
if (bch2_fs_emergency_read_only_locked(c))
411405
bch_err(c, "fatal error - emergency read only");
412-
return JOURNAL_ERR_insufficient_devices; /* -EROFS */
406+
return -BCH_ERR_journal_shutdown;
413407
}
414408

415409
if (!j->free_buf && !buf->data)
416-
return JOURNAL_ERR_enomem; /* will retry after write completion frees up a buf */
410+
return -BCH_ERR_journal_buf_enomem; /* will retry after write completion frees up a buf */
417411

418412
BUG_ON(!j->cur_entry_sectors);
419413

@@ -437,7 +431,7 @@ static int journal_entry_open(struct journal *j)
437431
u64s = clamp_t(int, u64s, 0, JOURNAL_ENTRY_CLOSED_VAL - 1);
438432

439433
if (u64s <= (ssize_t) j->early_journal_entries.nr)
440-
return JOURNAL_ERR_journal_full;
434+
return -BCH_ERR_journal_full;
441435

442436
if (fifo_empty(&j->pin) && j->reclaim_thread)
443437
wake_up_process(j->reclaim_thread);
@@ -574,20 +568,21 @@ static int __journal_res_get(struct journal *j, struct journal_res *res,
574568
if (journal_res_get_fast(j, res, flags))
575569
return 0;
576570

577-
if (bch2_journal_error(j))
578-
return -BCH_ERR_erofs_journal_err;
571+
ret = bch2_journal_error(j);
572+
if (unlikely(ret))
573+
return ret;
579574

580575
if (j->blocked)
581-
return -BCH_ERR_journal_res_get_blocked;
576+
return -BCH_ERR_journal_blocked;
582577

583578
if ((flags & BCH_WATERMARK_MASK) < j->watermark) {
584-
ret = JOURNAL_ERR_journal_full;
579+
ret = -BCH_ERR_journal_full;
585580
can_discard = j->can_discard;
586581
goto out;
587582
}
588583

589584
if (nr_unwritten_journal_entries(j) == ARRAY_SIZE(j->buf) && !journal_entry_is_open(j)) {
590-
ret = JOURNAL_ERR_max_in_flight;
585+
ret = -BCH_ERR_journal_max_in_flight;
591586
goto out;
592587
}
593588

@@ -617,20 +612,20 @@ static int __journal_res_get(struct journal *j, struct journal_res *res,
617612
j->buf_size_want = max(j->buf_size_want, buf->buf_size << 1);
618613

619614
__journal_entry_close(j, JOURNAL_ENTRY_CLOSED_VAL, false);
620-
ret = journal_entry_open(j) ?: JOURNAL_ERR_retry;
615+
ret = journal_entry_open(j) ?: -BCH_ERR_journal_retry_open;
621616
unlock:
622617
can_discard = j->can_discard;
623618
spin_unlock(&j->lock);
624619
out:
625620
if (likely(!ret))
626621
return 0;
627-
if (ret == JOURNAL_ERR_retry)
622+
if (ret == -BCH_ERR_journal_retry_open)
628623
goto retry;
629624

630625
if (journal_error_check_stuck(j, ret, flags))
631-
ret = -BCH_ERR_journal_res_get_blocked;
626+
ret = -BCH_ERR_journal_stuck;
632627

633-
if (ret == JOURNAL_ERR_max_in_flight &&
628+
if (ret == -BCH_ERR_journal_max_in_flight &&
634629
track_event_change(&c->times[BCH_TIME_blocked_journal_max_in_flight], true) &&
635630
trace_journal_entry_full_enabled()) {
636631
struct printbuf buf = PRINTBUF;
@@ -647,7 +642,7 @@ static int __journal_res_get(struct journal *j, struct journal_res *res,
647642
count_event(c, journal_entry_full);
648643
}
649644

650-
if (ret == JOURNAL_ERR_max_open &&
645+
if (ret == -BCH_ERR_journal_max_open &&
651646
track_event_change(&c->times[BCH_TIME_blocked_journal_max_open], true) &&
652647
trace_journal_entry_full_enabled()) {
653648
struct printbuf buf = PRINTBUF;
@@ -668,8 +663,8 @@ static int __journal_res_get(struct journal *j, struct journal_res *res,
668663
* Journal is full - can't rely on reclaim from work item due to
669664
* freezing:
670665
*/
671-
if ((ret == JOURNAL_ERR_journal_full ||
672-
ret == JOURNAL_ERR_journal_pin_full) &&
666+
if ((ret == -BCH_ERR_journal_full ||
667+
ret == -BCH_ERR_journal_pin_full) &&
673668
!(flags & JOURNAL_RES_GET_NONBLOCK)) {
674669
if (can_discard) {
675670
bch2_journal_do_discards(j);
@@ -682,9 +677,7 @@ static int __journal_res_get(struct journal *j, struct journal_res *res,
682677
}
683678
}
684679

685-
return ret == JOURNAL_ERR_insufficient_devices
686-
? -BCH_ERR_erofs_journal_err
687-
: -BCH_ERR_journal_res_get_blocked;
680+
return ret;
688681
}
689682

690683
static unsigned max_dev_latency(struct bch_fs *c)
@@ -714,7 +707,7 @@ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res,
714707
int ret;
715708

716709
if (closure_wait_event_timeout(&j->async_wait,
717-
(ret = __journal_res_get(j, res, flags)) != -BCH_ERR_journal_res_get_blocked ||
710+
!bch2_err_matches(ret = __journal_res_get(j, res, flags), BCH_ERR_operation_blocked) ||
718711
(flags & JOURNAL_RES_GET_NONBLOCK),
719712
HZ))
720713
return ret;
@@ -728,7 +721,7 @@ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res,
728721
remaining_wait = max(0, remaining_wait - HZ);
729722

730723
if (closure_wait_event_timeout(&j->async_wait,
731-
(ret = __journal_res_get(j, res, flags)) != -BCH_ERR_journal_res_get_blocked ||
724+
!bch2_err_matches(ret = __journal_res_get(j, res, flags), BCH_ERR_operation_blocked) ||
732725
(flags & JOURNAL_RES_GET_NONBLOCK),
733726
remaining_wait))
734727
return ret;
@@ -740,7 +733,7 @@ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res,
740733
printbuf_exit(&buf);
741734

742735
closure_wait_event(&j->async_wait,
743-
(ret = __journal_res_get(j, res, flags)) != -BCH_ERR_journal_res_get_blocked ||
736+
!bch2_err_matches(ret = __journal_res_get(j, res, flags), BCH_ERR_operation_blocked) ||
744737
(flags & JOURNAL_RES_GET_NONBLOCK));
745738
return ret;
746739
}
@@ -1647,7 +1640,7 @@ void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
16471640
? jiffies_to_msecs(j->next_reclaim - jiffies) : 0);
16481641
prt_printf(out, "blocked:\t%u\n", j->blocked);
16491642
prt_printf(out, "current entry sectors:\t%u\n", j->cur_entry_sectors);
1650-
prt_printf(out, "current entry error:\t%s\n", bch2_journal_errors[j->cur_entry_error]);
1643+
prt_printf(out, "current entry error:\t%s\n", bch2_err_str(j->cur_entry_error));
16511644
prt_printf(out, "current entry:\t");
16521645

16531646
switch (s.cur_entry_offset) {

fs/bcachefs/journal_reclaim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void bch2_journal_space_available(struct journal *j)
226226

227227
bch_err(c, "%s", buf.buf);
228228
printbuf_exit(&buf);
229-
ret = JOURNAL_ERR_insufficient_devices;
229+
ret = -BCH_ERR_insufficient_journal_devices;
230230
goto out;
231231
}
232232

@@ -240,7 +240,7 @@ void bch2_journal_space_available(struct journal *j)
240240
total = j->space[journal_space_total].total;
241241

242242
if (!j->space[journal_space_discarded].next_entry)
243-
ret = JOURNAL_ERR_journal_full;
243+
ret = -BCH_ERR_journal_full;
244244

245245
if ((j->space[journal_space_clean_ondisk].next_entry <
246246
j->space[journal_space_clean_ondisk].total) &&

fs/bcachefs/journal_types.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,6 @@ enum journal_flags {
151151
#undef x
152152
};
153153

154-
/* Reasons we may fail to get a journal reservation: */
155-
#define JOURNAL_ERRORS() \
156-
x(ok) \
157-
x(retry) \
158-
x(blocked) \
159-
x(max_in_flight) \
160-
x(max_open) \
161-
x(journal_full) \
162-
x(journal_pin_full) \
163-
x(journal_stuck) \
164-
x(enomem) \
165-
x(insufficient_devices)
166-
167-
enum journal_errors {
168-
#define x(n) JOURNAL_ERR_##n,
169-
JOURNAL_ERRORS()
170-
#undef x
171-
};
172-
173154
typedef DARRAY(u64) darray_u64;
174155

175156
struct journal_bio {
@@ -204,7 +185,7 @@ struct journal {
204185
* 0, or -ENOSPC if waiting on journal reclaim, or -EROFS if
205186
* insufficient devices:
206187
*/
207-
enum journal_errors cur_entry_error;
188+
int cur_entry_error;
208189
unsigned cur_entry_offset_if_blocked;
209190

210191
unsigned buf_size_want;

0 commit comments

Comments
 (0)