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-
3023static 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 ;
621616unlock :
622617 can_discard = j -> can_discard ;
623618 spin_unlock (& j -> lock );
624619out :
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
690683static 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 ) {
0 commit comments