bcachefs: Convert EROFS errors to private error codes
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 12 Dec 2022 01:37:11 +0000 (20:37 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:49 +0000 (17:09 -0400)
More error code improvements - this gets us more useful error messages.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
12 files changed:
fs/bcachefs/alloc_foreground.c
fs/bcachefs/btree_gc.c
fs/bcachefs/btree_update_leaf.c
fs/bcachefs/ec.c
fs/bcachefs/errcode.h
fs/bcachefs/io.c
fs/bcachefs/journal.c
fs/bcachefs/move.c
fs/bcachefs/movinggc.c
fs/bcachefs/recovery.c
fs/bcachefs/reflink.c
fs/bcachefs/super-io.c

index dd47eeb..c4aee00 100644 (file)
@@ -1222,9 +1222,6 @@ err:
                        ? -EAGAIN
                        : -BCH_ERR_ENOSPC_bucket_alloc;
 
-       if (bch2_err_matches(ret, BCH_ERR_insufficient_devices))
-               return -EROFS;
-
        return ret;
 }
 
index fdc9de6..e43ccf8 100644 (file)
@@ -1988,7 +1988,7 @@ int bch2_gc_gens(struct bch_fs *c)
                                        NULL, NULL,
                                        BTREE_INSERT_NOFAIL,
                                gc_btree_gens_key(&trans, &iter, k));
-                       if (ret && ret != -EROFS)
+                       if (ret && !bch2_err_matches(ret, EROFS))
                                bch_err(c, "error recalculating oldest_gen: %s", bch2_err_str(ret));
                        if (ret)
                                goto err;
@@ -2001,7 +2001,7 @@ int bch2_gc_gens(struct bch_fs *c)
                        NULL, NULL,
                        BTREE_INSERT_NOFAIL,
                bch2_alloc_write_oldest_gen(&trans, &iter, k));
-       if (ret && ret != -EROFS)
+       if (ret && !bch2_err_matches(ret, EROFS))
                bch_err(c, "error writing oldest_gen: %s", bch2_err_str(ret));
        if (ret)
                goto err;
index 7a95649..f44abb3 100644 (file)
@@ -990,7 +990,7 @@ bch2_trans_commit_get_rw_cold(struct btree_trans *trans)
 
        if (likely(!(trans->flags & BTREE_INSERT_LAZY_RW)) ||
            test_bit(BCH_FS_STARTED, &c->flags))
-               return -EROFS;
+               return -BCH_ERR_erofs_trans_commit;
 
        bch2_trans_unlock(trans);
 
index 65da4a1..0d33dee 100644 (file)
@@ -891,7 +891,7 @@ static void ec_stripe_create(struct ec_stripe_new *s)
        closure_sync(&s->iodone);
 
        if (s->err) {
-               if (s->err != -EROFS)
+               if (!bch2_err_matches(s->err, EROFS))
                        bch_err(c, "error creating stripe: error writing data buckets");
                goto err;
        }
index 5f0f757..96ee72c 100644 (file)
@@ -20,7 +20,6 @@
        x(0,                            open_buckets_empty)                     \
        x(0,                            freelist_empty)                         \
        x(BCH_ERR_freelist_empty,       no_buckets_found)                       \
-       x(0,                            insufficient_devices)                   \
        x(0,                            transaction_restart)                    \
        x(BCH_ERR_transaction_restart,  transaction_restart_fault_inject)       \
        x(BCH_ERR_transaction_restart,  transaction_restart_relock)             \
        x(EINVAL,                       device_already_online)                  \
        x(EINVAL,                       insufficient_devices_to_start)          \
        x(EINVAL,                       invalid)                                \
+       x(EROFS,                        erofs_trans_commit)                     \
+       x(EROFS,                        erofs_no_writes)                        \
+       x(EROFS,                        erofs_journal_err)                      \
+       x(EROFS,                        erofs_sb_err)                           \
+       x(EROFS,                        insufficient_devices)                   \
        x(BCH_ERR_invalid,              invalid_sb)                             \
        x(BCH_ERR_invalid_sb,           invalid_sb_magic)                       \
        x(BCH_ERR_invalid_sb,           invalid_sb_version)                     \
index 27265ba..44f3719 100644 (file)
@@ -1417,7 +1417,7 @@ void bch2_write(struct closure *cl)
 
        if (c->opts.nochanges ||
            !percpu_ref_tryget_live(&c->writes)) {
-               op->error = -EROFS;
+               op->error = -BCH_ERR_erofs_no_writes;
                goto err;
        }
 
index c7a7b9c..9daa99f 100644 (file)
@@ -363,7 +363,7 @@ retry:
                return 0;
 
        if (bch2_journal_error(j))
-               return -EROFS;
+               return -BCH_ERR_erofs_journal_err;
 
        spin_lock(&j->lock);
 
index 4d6fd30..848a415 100644 (file)
@@ -251,7 +251,7 @@ static int bch2_move_extent(struct btree_trans *trans,
        }
 
        if (!percpu_ref_tryget_live(&c->writes))
-               return -EROFS;
+               return -BCH_ERR_erofs_no_writes;
 
        /* write path might have to decompress data: */
        bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
index 66f18f7..9c55a88 100644 (file)
@@ -319,7 +319,7 @@ static int bch2_copygc(struct bch_fs *c)
                             writepoint_ptr(&c->copygc_write_point),
                             false,
                             copygc_pred, NULL);
-       if (ret < 0 && ret != -EROFS)
+       if (ret < 0 && !bch2_err_matches(ret, EROFS))
                bch_err(c, "error from bch2_move_data() in copygc: %s", bch2_err_str(ret));
        if (ret)
                return ret;
index d054e83..80736be 100644 (file)
@@ -631,8 +631,8 @@ static int bch2_journal_replay(struct bch_fs *c, u64 start_seq, u64 end_seq)
                                     : 0),
                             bch2_journal_replay_key(&trans, k));
                if (ret) {
-                       bch_err(c, "journal replay: error %d while replaying key at btree %s level %u",
-                               ret, bch2_btree_ids[k->btree_id], k->level);
+                       bch_err(c, "journal replay: error while replaying key at btree %s level %u: %s",
+                               bch2_btree_ids[k->btree_id], k->level, bch2_err_str(ret));
                        goto err;
                }
        }
index 8c426d6..08c98ac 100644 (file)
@@ -283,7 +283,7 @@ s64 bch2_remap_range(struct bch_fs *c,
        int ret = 0, ret2 = 0;
 
        if (!percpu_ref_tryget_live(&c->writes))
-               return -EROFS;
+               return -BCH_ERR_erofs_no_writes;
 
        bch2_check_set_feature(c, BCH_FEATURE_reflink);
 
index 8dfe92d..ff27ae1 100644 (file)
@@ -868,7 +868,7 @@ int bch2_write_super(struct bch_fs *c)
                                le64_to_cpu(ca->sb_read_scratch->seq),
                                ca->disk_sb.seq);
                        percpu_ref_put(&ca->io_ref);
-                       ret = -EROFS;
+                       ret = -BCH_ERR_erofs_sb_err;
                        goto out;
                }
 
@@ -878,7 +878,7 @@ int bch2_write_super(struct bch_fs *c)
                                le64_to_cpu(ca->sb_read_scratch->seq),
                                ca->disk_sb.seq);
                        percpu_ref_put(&ca->io_ref);
-                       ret = -EROFS;
+                       ret = -BCH_ERR_erofs_sb_err;
                        goto out;
                }
        }