bcachefs: Convert EAGAIN errors to private error codes
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 13 Dec 2022 20:17:40 +0000 (15:17 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:49 +0000 (17:09 -0400)
More error code cleanup, for better error messages and debugability.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_foreground.c
fs/bcachefs/btree_cache.c
fs/bcachefs/btree_update_interior.c
fs/bcachefs/btree_update_leaf.c
fs/bcachefs/errcode.h
fs/bcachefs/io.c
fs/bcachefs/journal.c
fs/bcachefs/journal.h

index c4aee0022fab2e34a6f55d49c0fbe0cefe98b2a0..3219c37d92629fc61e92276cf104181de551858c 100644 (file)
@@ -1219,7 +1219,7 @@ err:
        if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty) ||
            bch2_err_matches(ret, BCH_ERR_freelist_empty))
                return cl
-                       ? -EAGAIN
+                       ? -BCH_ERR_bucket_alloc_blocked
                        : -BCH_ERR_ENOSPC_bucket_alloc;
 
        return ret;
index 0ac8636edba2a9e73d24828bcef8bc53c5dc5936..7868536d7581bc230f795b55dd6e3cfcaf6d073b 100644 (file)
@@ -531,7 +531,7 @@ int bch2_btree_cache_cannibalize_lock(struct bch_fs *c, struct closure *cl)
        }
 
        trace_and_count(c, btree_cache_cannibalize_lock_fail, c);
-       return -EAGAIN;
+       return -BCH_ERR_btree_cache_cannibalize_lock_blocked;
 
 success:
        trace_and_count(c, btree_cache_cannibalize_lock, c);
@@ -906,8 +906,6 @@ retry:
  * bch_btree_node_get - find a btree node in the cache and lock it, reading it
  * in from disk if necessary.
  *
- * If IO is necessary and running under generic_make_request, returns -EAGAIN.
- *
  * The btree node will have either a read or a write lock held, depending on
  * the @write parameter.
  */
index cb1e7dbf5440c5622dab03d32ef72e48cb514c87..d2e785b9c835e799b2a7c2625ab9fd3d784a0d36 100644 (file)
@@ -1163,7 +1163,7 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
 
                        bch2_trans_unlock(trans);
                        closure_sync(&cl);
-               } while (ret == -EAGAIN);
+               } while (bch2_err_matches(ret, BCH_ERR_operation_blocked));
        }
 
        if (ret) {
index f44abb3fe469bea9e1011c1d60a25a2ac5c47406..61b61acef7a88e16c86dcd20328096cfc1edf929 100644 (file)
@@ -332,15 +332,10 @@ bch2_trans_journal_preres_get_cold(struct btree_trans *trans, unsigned u64s,
 static __always_inline int bch2_trans_journal_res_get(struct btree_trans *trans,
                                             unsigned flags)
 {
-       struct bch_fs *c = trans->c;
-       int ret;
-
-       ret = bch2_journal_res_get(&c->journal, &trans->journal_res,
-                                  trans->journal_u64s,
-                                  flags|
-                                  (trans->flags & JOURNAL_WATERMARK_MASK));
-
-       return ret == -EAGAIN ? -BCH_ERR_btree_insert_need_journal_res : ret;
+       return bch2_journal_res_get(&trans->c->journal, &trans->journal_res,
+                                   trans->journal_u64s,
+                                   flags|
+                                   (trans->flags & JOURNAL_WATERMARK_MASK));
 }
 
 #define JSET_ENTRY_LOG_U64s            4
@@ -864,7 +859,7 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans,
                        &trans->journal_preres, trans->journal_preres_u64s,
                        JOURNAL_RES_GET_NONBLOCK|
                        (trans->flags & JOURNAL_WATERMARK_MASK));
-       if (unlikely(ret == -EAGAIN))
+       if (unlikely(ret == -BCH_ERR_journal_preres_get_blocked))
                ret = bch2_trans_journal_preres_get_cold(trans,
                                                trans->journal_preres_u64s, trace_ip);
        if (unlikely(ret))
@@ -936,7 +931,7 @@ int bch2_trans_commit_error(struct btree_trans *trans,
                if (ret)
                        trace_and_count(c, trans_restart_mark_replicas, trans, trace_ip);
                break;
-       case -BCH_ERR_btree_insert_need_journal_res:
+       case -BCH_ERR_journal_res_get_blocked:
                bch2_trans_unlock(trans);
 
                if ((trans->flags & BTREE_INSERT_JOURNAL_RECLAIM) &&
index 96ee72c125d6f7279659317ab6e5c0a2740819be..bb296edcf4f7cc492f0a4ede946879d0aac70957 100644 (file)
        x(EROFS,                        erofs_journal_err)                      \
        x(EROFS,                        erofs_sb_err)                           \
        x(EROFS,                        insufficient_devices)                   \
+       x(0,                            operation_blocked)                      \
+       x(BCH_ERR_operation_blocked,    btree_cache_cannibalize_lock_blocked)   \
+       x(BCH_ERR_operation_blocked,    journal_res_get_blocked)                \
+       x(BCH_ERR_operation_blocked,    journal_preres_get_blocked)             \
+       x(BCH_ERR_operation_blocked,    bucket_alloc_blocked)                   \
        x(BCH_ERR_invalid,              invalid_sb)                             \
        x(BCH_ERR_invalid_sb,           invalid_sb_magic)                       \
        x(BCH_ERR_invalid_sb,           invalid_sb_version)                     \
index 44f3719d4b71305351caa048521e7ba4bd179618..c39f00f9ebd89b6f9c2ce63796aa0f0d7fe354c3 100644 (file)
@@ -1264,7 +1264,7 @@ again:
                                              BCH_WRITE_ONLY_SPECIFIED_DEVS))
                                ? NULL : &op->cl, &wp));
                if (unlikely(ret)) {
-                       if (ret == -EAGAIN)
+                       if (bch2_err_matches(ret, BCH_ERR_operation_blocked))
                                break;
 
                        goto err;
index 9daa99f3732a8dfc4501b775d31eed915309aa1a..66bd0a72c77472416ba05570bc88c291dcac5714 100644 (file)
@@ -198,12 +198,6 @@ static bool journal_entry_close(struct journal *j)
 /*
  * should _only_ called from journal_res_get() - when we actually want a
  * journal reservation - journal entry is open means journal is dirty:
- *
- * returns:
- * 0:          success
- * -ENOSPC:    journal currently full, must invoke reclaim
- * -EAGAIN:    journal blocked, must wait
- * -EROFS:     insufficient rw devices or journal error
  */
 static int journal_entry_open(struct journal *j)
 {
@@ -455,7 +449,9 @@ unlock:
                }
        }
 
-       return ret == JOURNAL_ERR_insufficient_devices ? -EROFS : -EAGAIN;
+       return ret == JOURNAL_ERR_insufficient_devices
+               ? -EROFS
+               : -BCH_ERR_journal_res_get_blocked;
 }
 
 /*
@@ -474,7 +470,8 @@ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res,
        int ret;
 
        closure_wait_event(&j->async_wait,
-                  (ret = __journal_res_get(j, res, flags)) != -EAGAIN ||
+                  (ret = __journal_res_get(j, res, flags)) !=
+                  -BCH_ERR_journal_res_get_blocked||
                   (flags & JOURNAL_RES_GET_NONBLOCK));
        return ret;
 }
@@ -792,12 +789,9 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
                } else {
                        ob[nr_got] = bch2_bucket_alloc(c, ca, RESERVE_none,
                                               false, cl);
-                       if (IS_ERR(ob[nr_got])) {
-                               ret = cl
-                                       ? -EAGAIN
-                                       : -BCH_ERR_ENOSPC_bucket_alloc;
+                       ret = PTR_ERR_OR_ZERO(ob[nr_got]);
+                       if (ret)
                                break;
-                       }
 
                        bu[nr_got] = ob[nr_got]->bucket;
                }
@@ -907,7 +901,7 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca,
 
        closure_init_stack(&cl);
 
-       while (ja->nr != nr && (ret == 0 || ret == -EAGAIN)) {
+       while (ja->nr != nr && (ret == 0 || ret == -BCH_ERR_bucket_alloc_blocked)) {
                struct disk_reservation disk_res = { 0, 0 };
 
                closure_sync(&cl);
index 1c750833343208ba7c40494c7c56901efc38708e..024cea9f5902e7b0be7475d9b73b48d9b8b76956 100644 (file)
@@ -460,7 +460,7 @@ static inline int bch2_journal_preres_get(struct journal *j,
                return 0;
 
        if (flags & JOURNAL_RES_GET_NONBLOCK)
-               return -EAGAIN;
+               return -BCH_ERR_journal_preres_get_blocked;
 
        return __bch2_journal_preres_get(j, res, new_u64s, flags);
 }