]> www.infradead.org Git - users/hch/block.git/commitdiff
bcachefs: bch_err_(fn|msg) check if should print
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 17 Dec 2023 03:43:41 +0000 (22:43 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:41 +0000 (11:47 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
23 files changed:
fs/bcachefs/alloc_background.c
fs/bcachefs/backpointers.c
fs/bcachefs/bcachefs.h
fs/bcachefs/btree_gc.c
fs/bcachefs/btree_update_interior.c
fs/bcachefs/buckets.c
fs/bcachefs/ec.c
fs/bcachefs/fs.c
fs/bcachefs/fsck.c
fs/bcachefs/inode.c
fs/bcachefs/journal.c
fs/bcachefs/journal_reclaim.c
fs/bcachefs/logged_ops.c
fs/bcachefs/lru.c
fs/bcachefs/migrate.c
fs/bcachefs/move.c
fs/bcachefs/movinggc.c
fs/bcachefs/quota.c
fs/bcachefs/rebalance.c
fs/bcachefs/recovery.c
fs/bcachefs/snapshot.c
fs/bcachefs/subvolume.c
fs/bcachefs/super.c

index 5e7ec368b16f9f7c41fc836c31519dc3add78d2a..006ac48ec102805a28407b510711c558dba4d240 100644 (file)
@@ -1470,8 +1470,7 @@ bkey_err:
                bch2_check_bucket_gens_key(trans, &iter, k));
 err:
        bch2_trans_put(trans);
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
index d0299361e8d2c070911e45f21e42c4e0b71f2fd5..b0a933d04337aaf50061b142bc1f4b9dd9c1219a 100644 (file)
@@ -393,15 +393,13 @@ int bch2_check_btree_backpointers(struct bch_fs *c)
 {
        struct btree_iter iter;
        struct bkey_s_c k;
-       int ret;
 
-       ret = bch2_trans_run(c,
+       int ret = bch2_trans_run(c,
                for_each_btree_key_commit(trans, iter,
                        BTREE_ID_backpointers, POS_MIN, 0, k,
                        NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
                  bch2_check_btree_backpointer(trans, &iter, k)));
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -769,8 +767,7 @@ int bch2_check_extents_to_backpointers(struct bch_fs *c)
        }
        bch2_trans_put(trans);
 
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -877,7 +874,6 @@ int bch2_check_backpointers_to_extents(struct bch_fs *c)
        }
        bch2_trans_put(trans);
 
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
index f6b621412ee43cba0a365b3c91e11466cde3308e..fe65dfea0780a184038b8ebfab7a4dea092bb363 100644 (file)
@@ -315,15 +315,20 @@ do {                                                                      \
 #define bch_err_inum_offset_ratelimited(c, _inum, _offset, fmt, ...) \
        bch2_print_ratelimited(c, KERN_ERR bch2_fmt_inum_offset(c, _inum, _offset, fmt), ##__VA_ARGS__)
 
+static inline bool should_print_err(int err)
+{
+       return err && !bch2_err_matches(err, BCH_ERR_transaction_restart);
+}
+
 #define bch_err_fn(_c, _ret)                                           \
 do {                                                                   \
-       if (_ret && !bch2_err_matches(_ret, BCH_ERR_transaction_restart))\
+       if (should_print_err(_ret))                                     \
                bch_err(_c, "%s(): error %s", __func__, bch2_err_str(_ret));\
 } while (0)
 
 #define bch_err_msg(_c, _ret, _msg, ...)                               \
 do {                                                                   \
-       if (_ret && !bch2_err_matches(_ret, BCH_ERR_transaction_restart))\
+       if (should_print_err(_ret))                                     \
                bch_err(_c, "%s(): error " _msg " %s", __func__,        \
                        ##__VA_ARGS__, bch2_err_str(_ret));             \
 } while (0)
index ae880661fddbae0aede6623f231dea358ec1cecc..f0951c17a27acb2bed2c871c8ee363b42b6e26b6 100644 (file)
@@ -414,10 +414,9 @@ again:
                        continue;
                }
 
-               if (ret) {
-                       bch_err_msg(c, ret, "getting btree node");
+               bch_err_msg(c, ret, "getting btree node");
+               if (ret)
                        break;
-               }
 
                ret = btree_repair_node_boundaries(c, b, prev, cur);
 
@@ -482,10 +481,9 @@ again:
                                        false);
                ret = PTR_ERR_OR_ZERO(cur);
 
-               if (ret) {
-                       bch_err_msg(c, ret, "getting btree node");
+               bch_err_msg(c, ret, "getting btree node");
+               if (ret)
                        goto err;
-               }
 
                ret = bch2_btree_repair_topology_recurse(trans, cur);
                six_unlock_read(&cur->c.lock);
@@ -707,8 +705,8 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
 
                new = kmalloc(bkey_bytes(k->k), GFP_KERNEL);
                if (!new) {
-                       bch_err_msg(c, ret, "allocating new key");
                        ret = -BCH_ERR_ENOMEM_gc_repair_key;
+                       bch_err_msg(c, ret, "allocating new key");
                        goto err;
                }
 
@@ -834,8 +832,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
                        bch2_mark_key(trans, btree_id, level, old, *k, flags));
 fsck_err:
 err:
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -1068,8 +1065,7 @@ static int bch2_gc_btree_init(struct btree_trans *trans,
 fsck_err:
        six_unlock_read(&b->c.lock);
 
-       if (ret < 0)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        printbuf_exit(&buf);
        return ret;
 }
@@ -1105,10 +1101,8 @@ static int bch2_gc_btrees(struct bch_fs *c, bool initial, bool metadata_only)
                        : bch2_gc_btree(trans, i, initial, metadata_only);
        }
 
-       if (ret < 0)
-               bch_err_fn(c, ret);
-
        bch2_trans_put(trans);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -1304,8 +1298,7 @@ static int bch2_gc_done(struct bch_fs *c,
 fsck_err:
        if (ca)
                percpu_ref_put(&ca->ref);
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
 
        percpu_up_write(&c->mark_lock);
        printbuf_exit(&buf);
@@ -1563,8 +1556,7 @@ static int bch2_gc_alloc_start(struct bch_fs *c, bool metadata_only)
        }));
 err:
        bch2_trans_put(trans);
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -1659,6 +1651,7 @@ static int bch2_gc_reflink_done(struct bch_fs *c, bool metadata_only)
 
        c->reflink_gc_nr = 0;
        bch2_trans_put(trans);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -1896,9 +1889,7 @@ out:
         * allocator thread - issue wakeup in case they blocked on gc_lock:
         */
        closure_wake_up(&c->freelist_wait);
-
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -2015,7 +2006,7 @@ int bch2_gc_gens(struct bch_fs *c)
                                        NULL, NULL,
                                        BCH_TRANS_COMMIT_no_enospc,
                                gc_btree_gens_key(trans, &iter, k));
-                       if (ret && !bch2_err_matches(ret, EROFS))
+                       if (!bch2_err_matches(ret, EROFS))
                                bch_err_fn(c, ret);
                        if (ret)
                                goto err;
@@ -2028,7 +2019,7 @@ int bch2_gc_gens(struct bch_fs *c)
                        NULL, NULL,
                        BCH_TRANS_COMMIT_no_enospc,
                bch2_alloc_write_oldest_gen(trans, &iter, k));
-       if (ret && !bch2_err_matches(ret, EROFS))
+       if (!bch2_err_matches(ret, EROFS))
                bch_err_fn(c, ret);
        if (ret)
                goto err;
@@ -2058,7 +2049,6 @@ static int bch2_gc_thread(void *arg)
        struct io_clock *clock = &c->io_clock[WRITE];
        unsigned long last = atomic64_read(&clock->now);
        unsigned last_kick = atomic_read(&c->kick_gc);
-       int ret;
 
        set_freezable();
 
@@ -2098,11 +2088,8 @@ static int bch2_gc_thread(void *arg)
 #if 0
                ret = bch2_gc(c, false, false);
 #else
-               ret = bch2_gc_gens(c);
+               bch2_gc_gens(c);
 #endif
-               if (ret < 0)
-                       bch_err_fn(c, ret);
-
                debug_check_no_locks_held();
        }
 
index cffc66cd481ffd940b7571b37bd6e3694edc823d..6350c661ce095ddc3a3ef7ca75b73cd107c68cff 100644 (file)
@@ -2054,8 +2054,7 @@ static void async_btree_node_rewrite_work(struct work_struct *work)
 
        ret = bch2_trans_do(c, NULL, NULL, 0,
                      async_btree_node_rewrite_trans(trans, a));
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        bch2_write_ref_put(c, BCH_WRITE_REF_node_rewrite);
        kfree(a);
 }
@@ -2093,8 +2092,8 @@ void bch2_btree_node_rewrite_async(struct bch_fs *c, struct btree *b)
                }
 
                ret = bch2_fs_read_write_early(c);
+               bch_err_msg(c, ret, "going read-write");
                if (ret) {
-                       bch_err_msg(c, ret, "going read-write");
                        kfree(a);
                        return;
                }
index 27c743882b63b423216c06e37f482296c915913f..31b7f0ba7d9ede660f946c505570024149812b95 100644 (file)
@@ -1760,8 +1760,7 @@ int bch2_trans_mark_dev_sb(struct bch_fs *c, struct bch_dev *ca)
 {
        int ret = bch2_trans_run(c, __bch2_trans_mark_dev_sb(trans, ca));
 
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
index 76163c2ea3b3d2d747f0bc8a508c127263303679..6cbc1d8a3ab5cffa7b197a0c7b4e2684751f4fe3 100644 (file)
@@ -791,28 +791,22 @@ static void ec_stripe_delete_work(struct work_struct *work)
 {
        struct bch_fs *c =
                container_of(work, struct bch_fs, ec_stripe_delete_work);
-       struct btree_trans *trans = bch2_trans_get(c);
-       int ret;
-       u64 idx;
 
        while (1) {
                mutex_lock(&c->ec_stripes_heap_lock);
-               idx = stripe_idx_to_delete(c);
+               u64 idx = stripe_idx_to_delete(c);
                mutex_unlock(&c->ec_stripes_heap_lock);
 
                if (!idx)
                        break;
 
-               ret = commit_do(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
-                               ec_stripe_delete(trans, idx));
-               if (ret) {
-                       bch_err_fn(c, ret);
+               int ret = bch2_trans_do(c, NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
+                                       ec_stripe_delete(trans, idx));
+               bch_err_fn(c, ret);
+               if (ret)
                        break;
-               }
        }
 
-       bch2_trans_put(trans);
-
        bch2_write_ref_put(c, BCH_WRITE_REF_stripe_delete);
 }
 
@@ -1126,16 +1120,15 @@ static void ec_stripe_create(struct ec_stripe_new *s)
                            ec_stripe_key_update(trans,
                                        bkey_i_to_stripe(&s->new_stripe.key),
                                        !s->have_existing_stripe));
+       bch_err_msg(c, ret, "creating stripe key");
        if (ret) {
-               bch_err(c, "error creating stripe: error creating stripe key");
                goto err;
        }
 
        ret = ec_stripe_update_extents(c, &s->new_stripe);
-       if (ret) {
-               bch_err_msg(c, ret, "creating stripe: error updating pointers");
+       bch_err_msg(c, ret, "error updating extents");
+       if (ret)
                goto err;
-       }
 err:
        bch2_disk_reservation_put(c, &s->res);
 
@@ -1865,7 +1858,6 @@ int bch2_stripes_read(struct bch_fs *c)
                        bch2_stripes_heap_insert(c, m, k.k->p.offset);
                        0;
                })));
-
        bch_err_fn(c, ret);
        return ret;
 }
index 886c0f30e681be7c49f0927b7800f531c5629358..4c35df1230b5a01c2d0e465fcb8b854122a43b0c 100644 (file)
@@ -1012,15 +1012,13 @@ static int bch2_vfs_readdir(struct file *file, struct dir_context *ctx)
 {
        struct bch_inode_info *inode = file_bch_inode(file);
        struct bch_fs *c = inode->v.i_sb->s_fs_info;
-       int ret;
 
        if (!dir_emit_dots(file, ctx))
                return 0;
 
-       ret = bch2_readdir(c, inode_inum(inode), ctx);
-       if (ret)
-               bch_err_fn(c, ret);
+       int ret = bch2_readdir(c, inode_inum(inode), ctx);
 
+       bch_err_fn(c, ret);
        return bch2_err_class(ret);
 }
 
@@ -1944,10 +1942,9 @@ got_sb:
 
        vinode = bch2_vfs_inode_get(c, BCACHEFS_ROOT_SUBVOL_INUM);
        ret = PTR_ERR_OR_ZERO(vinode);
-       if (ret) {
-               bch_err_msg(c, ret, "mounting: error getting root inode");
+       bch_err_msg(c, ret, "mounting: error getting root inode");
+       if (ret)
                goto err_put_super;
-       }
 
        sb->s_root = d_make_root(vinode);
        if (!sb->s_root) {
index d0cd6020bd9a12455297dfaa2d39fe39b7fa4ef8..7023c2800d59d9f7159903535bbfb5a0e4c2e78a 100644 (file)
@@ -209,8 +209,7 @@ static int fsck_write_inode(struct btree_trans *trans,
 {
        int ret = commit_do(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
                            __write_inode(trans, inode, snapshot));
-       if (ret)
-               bch_err_fn(trans->c, ret);
+       bch_err_fn(trans->c, ret);
        return ret;
 }
 
@@ -2427,7 +2426,6 @@ static int fix_reflink_p_key(struct btree_trans *trans, struct btree_iter *iter,
 {
        struct bkey_s_c_reflink_p p;
        struct bkey_i_reflink_p *u;
-       int ret;
 
        if (k.k->type != KEY_TYPE_reflink_p)
                return 0;
@@ -2438,7 +2436,7 @@ static int fix_reflink_p_key(struct btree_trans *trans, struct btree_iter *iter,
                return 0;
 
        u = bch2_trans_kmalloc(trans, sizeof(*u));
-       ret = PTR_ERR_OR_ZERO(u);
+       int ret = PTR_ERR_OR_ZERO(u);
        if (ret)
                return ret;
 
index 7ee9ac5e447960b2f66fd1e9a9a59650b1944de5..e75c6bc2bc2835e44934213eee82f8e3cfc902ce 100644 (file)
@@ -1200,6 +1200,6 @@ again:
        }
 err:
        bch2_trans_put(trans);
-
+       bch_err_fn(c, ret);
        return ret;
 }
index 8294d7fd6632be802b4fb43302ca0407231fbedd..5883fc38b4f5e3df7be026655b656242f56c9505 100644 (file)
@@ -993,8 +993,7 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca,
                        break;
        }
 
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
 unlock:
        up_write(&c->state_lock);
        return ret;
@@ -1024,8 +1023,7 @@ int bch2_dev_journal_alloc(struct bch_dev *ca)
 
        ret = __bch2_set_nr_journal_buckets(ca, nr, true, NULL);
 err:
-       if (ret)
-               bch_err_fn(ca, ret);
+       bch_err_fn(ca, ret);
        return ret;
 }
 
index 60b9d357238754b5d1162570a593c26b690562f5..794c10ec01b66d1ac63214ef6c8e2550aa39a39f 100644 (file)
@@ -793,10 +793,9 @@ int bch2_journal_reclaim_start(struct journal *j)
        p = kthread_create(bch2_journal_reclaim_thread, j,
                           "bch-reclaim/%s", c->name);
        ret = PTR_ERR_OR_ZERO(p);
-       if (ret) {
-               bch_err_msg(c, ret, "creating journal reclaim thread");
+       bch_err_msg(c, ret, "creating journal reclaim thread");
+       if (ret)
                return ret;
-       }
 
        get_task_struct(p);
        j->reclaim_thread = p;
index 4b603746063cc1284677c8d59f68c64c66cfe469..80fcea641e77fd6be673f528b1a5a12891145b55 100644 (file)
@@ -63,8 +63,7 @@ int bch2_resume_logged_ops(struct bch_fs *c)
                                   BTREE_ID_logged_ops, POS_MIN,
                                   BTREE_ITER_PREFETCH, k,
                        resume_logged_op(trans, &iter, k)));
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
index e6d081c0592c81bb1db26db6c3d08aafce8bc7d9..4de1bc242660b2dd6a741ab99be8531b1cec4130 100644 (file)
@@ -157,8 +157,7 @@ int bch2_check_lrus(struct bch_fs *c)
                                BTREE_ID_lru, POS_MIN, BTREE_ITER_PREFETCH, k,
                                NULL, NULL, BCH_TRANS_COMMIT_no_enospc|BCH_TRANS_COMMIT_lazy_rw,
                        bch2_check_lru_key(trans, &iter, k, &last_flushed_pos)));
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 
 }
index 8e5688d0a8ca6af79b9b98c11efdef88c67645e1..a2d998dbcc883b2cc3e507ed87443619879a3f90 100644 (file)
@@ -145,10 +145,9 @@ retry:
                                continue;
                        }
 
-                       if (ret) {
-                               bch_err_msg(c, ret, "updating btree node key");
+                       bch_err_msg(c, ret, "updating btree node key");
+                       if (ret)
                                break;
-                       }
 next:
                        bch2_btree_iter_next_node(&iter);
                }
index 9be421e2a5771b9c7ec5483d14d6b5cce977b721..b1b9566c7a6186229a0c2f021a71ad522d16e298 100644 (file)
@@ -669,10 +669,9 @@ int bch2_evacuate_bucket(struct moving_context *ctxt,
                        bkey_err(k = bch2_btree_iter_peek_slot(&iter)));
        bch2_trans_iter_exit(trans, &iter);
 
-       if (ret) {
-               bch_err_msg(c, ret, "looking up alloc key");
+       bch_err_msg(c, ret, "looking up alloc key");
+       if (ret)
                goto err;
-       }
 
        a = bch2_alloc_to_v4(k, &a_convert);
        dirty_sectors = bch2_bucket_sectors_dirty(*a);
index fd239a261aca054b22072716e6d2ef7d49791e6a..963191a2f4e0f3d28276acd9099b2ec045b94221 100644 (file)
@@ -324,9 +324,9 @@ static int bch2_copygc_thread(void *arg)
        if (!buckets)
                return -ENOMEM;
        ret = rhashtable_init(&buckets->table, &bch_move_bucket_params);
+       bch_err_msg(c, ret, "allocating copygc buckets in flight");
        if (ret) {
                kfree(buckets);
-               bch_err_msg(c, ret, "allocating copygc buckets in flight");
                return ret;
        }
 
@@ -423,10 +423,9 @@ int bch2_copygc_start(struct bch_fs *c)
 
        t = kthread_create(bch2_copygc_thread, c, "bch-copygc/%s", c->name);
        ret = PTR_ERR_OR_ZERO(t);
-       if (ret) {
-               bch_err_msg(c, ret, "creating copygc thread");
+       bch_err_msg(c, ret, "creating copygc thread");
+       if (ret)
                return ret;
-       }
 
        get_task_struct(t);
 
index 79724a7aaab094184d1fe1cd1fe74b58c3f86635..a33f370e1fc7b92103cb661245ca47164ca50e84 100644 (file)
@@ -626,8 +626,7 @@ int bch2_fs_quota_read(struct bch_fs *c)
 
        bch2_trans_put(trans);
 
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
index 9c415e14ff9cf35e06de9ffe6f9555ee58741815..95f46cb3b5bdfd820e845a8cceda2b3c2fb67cf4 100644 (file)
@@ -470,10 +470,9 @@ int bch2_rebalance_start(struct bch_fs *c)
 
        p = kthread_create(bch2_rebalance_thread, c, "bch-rebalance/%s", c->name);
        ret = PTR_ERR_OR_ZERO(p);
-       if (ret) {
-               bch_err_msg(c, ret, "creating rebalance thread");
+       bch_err_msg(c, ret, "creating rebalance thread");
+       if (ret)
                return ret;
-       }
 
        get_task_struct(p);
        rcu_assign_pointer(c->rebalance.thread, p);
index 1099b2f51252d69af7640a95023bc2da4e14a98b..3b84c4ab2c4f8afa20bc4463913bb908a4686759 100644 (file)
@@ -463,8 +463,7 @@ static int bch2_initialize_subvolumes(struct bch_fs *c)
        ret =   bch2_btree_insert(c, BTREE_ID_snapshot_trees,   &root_tree.k_i, NULL, 0) ?:
                bch2_btree_insert(c, BTREE_ID_snapshots,        &root_snapshot.k_i, NULL, 0) ?:
                bch2_btree_insert(c, BTREE_ID_subvolumes,       &root_volume.k_i, NULL, 0);
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -504,8 +503,7 @@ static int bch2_fs_upgrade_for_subvolumes(struct bch_fs *c)
 {
        int ret = bch2_trans_do(c, NULL, NULL, BCH_TRANS_COMMIT_lazy_rw,
                                __bch2_fs_upgrade_for_subvolumes(trans));
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -1087,8 +1085,7 @@ out:
                bch2_delete_dead_snapshots_async(c);
        }
 
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 err:
 fsck_err:
@@ -1179,10 +1176,9 @@ int bch2_fs_initialize(struct bch_fs *c)
        packed_inode.inode.k.p.snapshot = U32_MAX;
 
        ret = bch2_btree_insert(c, BTREE_ID_inodes, &packed_inode.inode.k_i, NULL, 0);
-       if (ret) {
-               bch_err_msg(c, ret, "creating root directory");
+       bch_err_msg(c, ret, "creating root directory");
+       if (ret)
                goto err;
-       }
 
        bch2_inode_init_early(c, &lostfound_inode);
 
@@ -1193,10 +1189,9 @@ int bch2_fs_initialize(struct bch_fs *c)
                                  &lostfound,
                                  0, 0, S_IFDIR|0700, 0,
                                  NULL, NULL, (subvol_inum) { 0 }, 0));
-       if (ret) {
-               bch_err_msg(c, ret, "creating lost+found");
+       bch_err_msg(c, ret, "creating lost+found");
+       if (ret)
                goto err;
-       }
 
        c->recovery_pass_done = ARRAY_SIZE(recovery_pass_fns) - 1;
 
@@ -1207,10 +1202,9 @@ int bch2_fs_initialize(struct bch_fs *c)
        }
 
        ret = bch2_journal_flush(&c->journal);
-       if (ret) {
-               bch_err_msg(c, ret, "writing first journal entry");
+       bch_err_msg(c, ret, "writing first journal entry");
+       if (ret)
                goto err;
-       }
 
        mutex_lock(&c->sb_lock);
        SET_BCH_SB_INITIALIZED(c->disk_sb.sb, true);
index 8d1800ef22b568648f7fa21c742aa3bd06bc33f3..b0ef415914dcefa041c022874245f6713e6b921a 100644 (file)
@@ -459,7 +459,6 @@ static int bch2_snapshot_tree_master_subvol(struct btree_trans *trans,
        struct bch_fs *c = trans->c;
        struct btree_iter iter;
        struct bkey_s_c k;
-       struct bkey_s_c_subvolume s;
        bool found = false;
        int ret;
 
@@ -468,7 +467,7 @@ static int bch2_snapshot_tree_master_subvol(struct btree_trans *trans,
                if (k.k->type != KEY_TYPE_subvolume)
                        continue;
 
-               s = bkey_s_c_to_subvolume(k);
+               struct bkey_s_c_subvolume s = bkey_s_c_to_subvolume(k);
                if (!bch2_snapshot_is_ancestor(c, le32_to_cpu(s.v->snapshot), snapshot_root))
                        continue;
                if (!BCH_SUBVOLUME_SNAP(s.v)) {
@@ -592,9 +591,7 @@ int bch2_check_snapshot_trees(struct bch_fs *c)
                        BTREE_ITER_PREFETCH, k,
                        NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
                check_snapshot_tree(trans, &iter, k)));
-
-       if (ret)
-               bch_err(c, "error %i checking snapshot trees", ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -866,12 +863,11 @@ int bch2_check_snapshots(struct bch_fs *c)
         */
        ret = bch2_trans_run(c,
                for_each_btree_key_reverse_commit(trans, iter,
-                       BTREE_ID_snapshots, POS_MAX,
-                       BTREE_ITER_PREFETCH, k,
-                       NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
-               check_snapshot(trans, &iter, k)));
-       if (ret)
-               bch_err_fn(c, ret);
+                               BTREE_ID_snapshots, POS_MAX,
+                               BTREE_ITER_PREFETCH, k,
+                               NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
+                       check_snapshot(trans, &iter, k)));
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -1381,10 +1377,9 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
 
        if (!test_bit(BCH_FS_started, &c->flags)) {
                ret = bch2_fs_read_write_early(c);
-               if (ret) {
-                       bch_err_msg(c, ret, "deleting dead snapshots: error going rw");
+               bch_err_msg(c, ret, "deleting dead snapshots: error going rw");
+               if (ret)
                        return ret;
-               }
        }
 
        trans = bch2_trans_get(c);
@@ -1397,18 +1392,16 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
                        POS_MIN, 0, k,
                        NULL, NULL, 0,
                bch2_delete_redundant_snapshot(trans, k));
-       if (ret) {
-               bch_err_msg(c, ret, "deleting redundant snapshots");
+       bch_err_msg(c, ret, "deleting redundant snapshots");
+       if (ret)
                goto err;
-       }
 
        ret = for_each_btree_key(trans, iter, BTREE_ID_snapshots,
                                 POS_MIN, 0, k,
                bch2_snapshot_set_equiv(trans, k));
-       if (ret) {
-               bch_err_msg(c, ret, "in bch2_snapshots_set_equiv");
+       bch_err_msg(c, ret, "in bch2_snapshots_set_equiv");
+       if (ret)
                goto err;
-       }
 
        ret = for_each_btree_key(trans, iter, BTREE_ID_snapshots,
                                 POS_MIN, 0, k, ({
@@ -1420,11 +1413,9 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
                        ? snapshot_list_add(c, &deleted, k.k->p.offset)
                        : 0;
        }));
-
-       if (ret) {
-               bch_err_msg(c, ret, "walking snapshots");
+       bch_err_msg(c, ret, "walking snapshots");
+       if (ret)
                goto err;
-       }
 
        for (id = 0; id < BTREE_ID_NR; id++) {
                struct bpos last_pos = POS_MIN;
@@ -1457,10 +1448,9 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
                bch2_disk_reservation_put(c, &res);
                darray_exit(&equiv_seen);
 
-               if (ret) {
-                       bch_err_msg(c, ret, "deleting keys from dying snapshots");
+               bch_err_msg(c, ret, "deleting keys from dying snapshots");
+               if (ret)
                        goto err;
-               }
        }
 
        bch2_trans_unlock(trans);
@@ -1476,10 +1466,9 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
                        : 0;
        }));
 
-       if (ret) {
-               bch_err_msg(c, ret, "walking snapshots");
+       bch_err_msg(c, ret, "walking snapshots");
+       if (ret)
                goto err_create_lock;
-       }
 
        /*
         * Fixing children of deleted snapshots can't be done completely
@@ -1496,19 +1485,17 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
        darray_for_each(deleted, i) {
                ret = commit_do(trans, NULL, NULL, 0,
                        bch2_snapshot_node_delete(trans, *i));
-               if (ret) {
-                       bch_err_msg(c, ret, "deleting snapshot %u", *i);
+               bch_err_msg(c, ret, "deleting snapshot %u", *i);
+               if (ret)
                        goto err_create_lock;
-               }
        }
 
        darray_for_each(deleted_interior, i) {
                ret = commit_do(trans, NULL, NULL, 0,
                        bch2_snapshot_node_delete(trans, *i));
-               if (ret) {
-                       bch_err_msg(c, ret, "deleting snapshot %u", *i);
+               bch_err_msg(c, ret, "deleting snapshot %u", *i);
+               if (ret)
                        goto err_create_lock;
-               }
        }
 err_create_lock:
        up_write(&c->snapshot_create_lock);
@@ -1516,8 +1503,7 @@ err:
        darray_exit(&deleted_interior);
        darray_exit(&deleted);
        bch2_trans_put(trans);
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -1701,8 +1687,7 @@ int bch2_snapshots_read(struct bch_fs *c)
                for_each_btree_key(trans, iter, BTREE_ID_snapshots,
                                   POS_MIN, 0, k,
                           (set_is_ancestor_bitmap(c, k.k->p.offset), 0)));
-       if (ret)
-               bch_err_fn(c, ret);
+       bch_err_fn(c, ret);
        return ret;
 }
 
index f0f91211f757caa42b60b64561853feadb8d6005..be0de4f030a4742d5320fe77831aa9366dc5a138 100644 (file)
@@ -38,8 +38,7 @@ static int check_subvol(struct btree_trans *trans,
 
        if (BCH_SUBVOLUME_UNLINKED(subvol.v)) {
                ret = bch2_subvolume_delete(trans, iter->pos.offset);
-               if (ret)
-                       bch_err_msg(c, ret, "deleting subvolume %llu", iter->pos.offset);
+               bch_err_msg(c, ret, "deleting subvolume %llu", iter->pos.offset);
                return ret ?: -BCH_ERR_transaction_restart_nested;
        }
 
@@ -86,11 +85,10 @@ int bch2_check_subvols(struct bch_fs *c)
 
        ret = bch2_trans_run(c,
                for_each_btree_key_commit(trans, iter,
-                       BTREE_ID_subvolumes, POS_MIN, BTREE_ITER_PREFETCH, k,
-                       NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
-               check_subvol(trans, &iter, k)));
-       if (ret)
-               bch_err_fn(c, ret);
+                               BTREE_ID_subvolumes, POS_MIN, BTREE_ITER_PREFETCH, k,
+                               NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
+                       check_subvol(trans, &iter, k)));
+       bch_err_fn(c, ret);
        return ret;
 }
 
@@ -297,10 +295,9 @@ static void bch2_subvolume_wait_for_pagecache_and_delete(struct work_struct *wor
 
                for (id = s.data; id < s.data + s.nr; id++) {
                        ret = bch2_trans_run(c, bch2_subvolume_delete(trans, *id));
-                       if (ret) {
-                               bch_err_msg(c, ret, "deleting subvolume %u", *id);
+                       bch_err_msg(c, ret, "deleting subvolume %u", *id);
+                       if (ret)
                                break;
-                       }
                }
 
                darray_exit(&s);
index 88a762bce7dadd37f8788bbcdfdbf4ccc899b6e0..c04d425c872fa66fb7d89fe60bf9ea9d6da9d2cb 100644 (file)
@@ -1522,9 +1522,7 @@ static int bch2_dev_remove_alloc(struct bch_fs *c, struct bch_dev *ca)
                                        BTREE_TRIGGER_NORUN, NULL) ?:
                bch2_btree_delete_range(c, BTREE_ID_bucket_gens, start, end,
                                        BTREE_TRIGGER_NORUN, NULL);
-       if (ret)
-               bch_err_msg(c, ret, "removing dev alloc info");
-
+       bch_err_msg(c, ret, "removing dev alloc info");
        return ret;
 }
 
@@ -1551,34 +1549,29 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
        __bch2_dev_read_only(c, ca);
 
        ret = bch2_dev_data_drop(c, ca->dev_idx, flags);
-       if (ret) {
-               bch_err_msg(ca, ret, "dropping data");
+       bch_err_msg(ca, ret, "dropping data");
+       if (ret)
                goto err;
-       }
 
        ret = bch2_dev_remove_alloc(c, ca);
-       if (ret) {
-               bch_err_msg(ca, ret, "deleting alloc info");
+       bch_err_msg(ca, ret, "deleting alloc info");
+       if (ret)
                goto err;
-       }
 
        ret = bch2_journal_flush_device_pins(&c->journal, ca->dev_idx);
-       if (ret) {
-               bch_err_msg(ca, ret, "flushing journal");
+       bch_err_msg(ca, ret, "flushing journal");
+       if (ret)
                goto err;
-       }
 
        ret = bch2_journal_flush(&c->journal);
-       if (ret) {
-               bch_err(ca, "journal error");
+       bch_err(ca, "journal error");
+       if (ret)
                goto err;
-       }
 
        ret = bch2_replicas_gc2(c);
-       if (ret) {
-               bch_err_msg(ca, ret, "in replicas_gc2()");
+       bch_err_msg(ca, ret, "in replicas_gc2()");
+       if (ret)
                goto err;
-       }
 
        data = bch2_dev_has_data(c, ca);
        if (data) {
@@ -1650,10 +1643,9 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
        int ret;
 
        ret = bch2_read_super(path, &opts, &sb);
-       if (ret) {
-               bch_err_msg(c, ret, "reading super");
+       bch_err_msg(c, ret, "reading super");
+       if (ret)
                goto err;
-       }
 
        dev_mi = bch2_sb_member_get(sb.sb, sb.sb->dev_idx);
 
@@ -1666,10 +1658,8 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
        }
 
        ret = bch2_dev_may_add(sb.sb, c);
-       if (ret) {
-               bch_err_fn(c, ret);
+       if (ret)
                goto err;
-       }
 
        ca = __bch2_dev_alloc(c, &dev_mi);
        if (!ca) {
@@ -1684,19 +1674,17 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
                goto err;
 
        ret = bch2_dev_journal_alloc(ca);
-       if (ret) {
-               bch_err_msg(c, ret, "allocating journal");
+       bch_err_msg(c, ret, "allocating journal");
+       if (ret)
                goto err;
-       }
 
        down_write(&c->state_lock);
        mutex_lock(&c->sb_lock);
 
        ret = bch2_sb_from_fs(c, ca);
-       if (ret) {
-               bch_err_msg(c, ret, "setting up new superblock");
+       bch_err_msg(c, ret, "setting up new superblock");
+       if (ret)
                goto err_unlock;
-       }
 
        if (dynamic_fault("bcachefs:add:no_slot"))
                goto no_slot;
@@ -1735,10 +1723,9 @@ have_slot:
 
        if (BCH_MEMBER_GROUP(&dev_mi)) {
                ret = __bch2_dev_group_set(c, ca, label.buf);
-               if (ret) {
-                       bch_err_msg(c, ret, "creating new label");
+               bch_err_msg(c, ret, "creating new label");
+               if (ret)
                        goto err_unlock;
-               }
        }
 
        bch2_write_super(c);
@@ -1747,16 +1734,14 @@ have_slot:
        bch2_dev_usage_journal_reserve(c);
 
        ret = bch2_trans_mark_dev_sb(c, ca);
-       if (ret) {
-               bch_err_msg(ca, ret, "marking new superblock");
+       bch_err_msg(ca, ret, "marking new superblock");
+       if (ret)
                goto err_late;
-       }
 
        ret = bch2_fs_freespace_init(c);
-       if (ret) {
-               bch_err_msg(ca, ret, "initializing free space");
+       bch_err_msg(ca, ret, "initializing free space");
+       if (ret)
                goto err_late;
-       }
 
        ca->new_fs_bucket_idx = 0;
 
@@ -1775,6 +1760,7 @@ err:
        bch2_free_super(&sb);
        printbuf_exit(&label);
        printbuf_exit(&errbuf);
+       bch_err_fn(c, ret);
        return ret;
 err_late:
        up_write(&c->state_lock);
@@ -1802,10 +1788,9 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
        dev_idx = sb.sb->dev_idx;
 
        ret = bch2_dev_in_fs(c->disk_sb.sb, sb.sb);
-       if (ret) {
-               bch_err_msg(c, ret, "bringing %s online", path);
+       bch_err_msg(c, ret, "bringing %s online", path);
+       if (ret)
                goto err;
-       }
 
        ret = bch2_dev_attach_bdev(c, &sb);
        if (ret)
@@ -1814,10 +1799,9 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
        ca = bch_dev_locked(c, dev_idx);
 
        ret = bch2_trans_mark_dev_sb(c, ca);
-       if (ret) {
-               bch_err_msg(c, ret, "bringing %s online: error from bch2_trans_mark_dev_sb", path);
+       bch_err_msg(c, ret, "bringing %s online: error from bch2_trans_mark_dev_sb", path);
+       if (ret)
                goto err;
-       }
 
        if (ca->mi.state == BCH_MEMBER_STATE_rw)
                __bch2_dev_read_write(c, ca);
@@ -1896,10 +1880,9 @@ int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
        }
 
        ret = bch2_dev_buckets_resize(c, ca, nbuckets);
-       if (ret) {
-               bch_err_msg(ca, ret, "resizing buckets");
+       bch_err_msg(ca, ret, "resizing buckets");
+       if (ret)
                goto err;
-       }
 
        ret = bch2_trans_mark_dev_sb(c, ca);
        if (ret)