diff options
-rw-r--r-- | fs/bcachefs/alloc_background.c | 33 | ||||
-rw-r--r-- | fs/bcachefs/backpointers.c | 10 | ||||
-rw-r--r-- | fs/bcachefs/bcachefs.h | 5 | ||||
-rw-r--r-- | fs/bcachefs/btree_gc.c | 27 | ||||
-rw-r--r-- | fs/bcachefs/buckets.c | 5 | ||||
-rw-r--r-- | fs/bcachefs/ec.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/fsck.c | 59 | ||||
-rw-r--r-- | fs/bcachefs/journal.c | 15 | ||||
-rw-r--r-- | fs/bcachefs/lru.c | 16 | ||||
-rw-r--r-- | fs/bcachefs/move.c | 8 | ||||
-rw-r--r-- | fs/bcachefs/quota.c | 5 | ||||
-rw-r--r-- | fs/bcachefs/recovery.c | 106 | ||||
-rw-r--r-- | fs/bcachefs/subvolume.c | 9 | ||||
-rw-r--r-- | fs/bcachefs/tests.c | 40 |
14 files changed, 171 insertions, 171 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c index 6c8bcb210ad9..f68330b48847 100644 --- a/fs/bcachefs/alloc_background.c +++ b/fs/bcachefs/alloc_background.c @@ -577,7 +577,7 @@ int bch2_alloc_read(struct bch_fs *c) bch2_trans_exit(&trans); if (ret) - bch_err(c, "error reading alloc info: %s", bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -684,8 +684,7 @@ int bch2_bucket_gens_init(struct bch_fs *c) bch2_trans_exit(&trans); if (ret) - bch_err(c, "%s: error %s", __func__, bch2_err_str(ret)); - + bch_err_fn(c, ret); return ret; } @@ -730,7 +729,7 @@ int bch2_bucket_gens_read(struct bch_fs *c) bch2_trans_exit(&trans); if (ret) - bch_err(c, "error reading alloc info: %s", bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1521,7 +1520,9 @@ bkey_err: bch2_check_bucket_gens_key(&trans, &iter, k)); err: bch2_trans_exit(&trans); - return ret < 0 ? ret : 0; + if (ret) + bch_err_fn(c, ret); + return ret; } static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans, @@ -1599,20 +1600,18 @@ fsck_err: int bch2_check_alloc_to_lru_refs(struct bch_fs *c) { - struct btree_trans trans; struct btree_iter iter; struct bkey_s_c k; int ret = 0; - bch2_trans_init(&trans, c, 0, 0); - - for_each_btree_key_commit(&trans, iter, BTREE_ID_alloc, - POS_MIN, BTREE_ITER_PREFETCH, k, - NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, - bch2_check_alloc_to_lru_ref(&trans, &iter)); - - bch2_trans_exit(&trans); - return ret < 0 ? ret : 0; + ret = bch2_trans_run(c, + for_each_btree_key_commit(&trans, iter, BTREE_ID_alloc, + POS_MIN, BTREE_ITER_PREFETCH, k, + NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, + bch2_check_alloc_to_lru_ref(&trans, &iter))); + if (ret) + bch_err_fn(c, ret); + return ret; } static int bch2_discard_one_bucket(struct btree_trans *trans, @@ -2024,6 +2023,7 @@ int bch2_fs_freespace_init(struct bch_fs *c) ret = bch2_dev_freespace_init(c, ca, &last_updated); if (ret) { percpu_ref_put(&ca->ref); + bch_err_fn(c, ret); return ret; } } @@ -2032,11 +2032,10 @@ int bch2_fs_freespace_init(struct bch_fs *c) mutex_lock(&c->sb_lock); bch2_write_super(c); mutex_unlock(&c->sb_lock); - bch_verbose(c, "done initializing freespace"); } - return ret; + return 0; } /* Bucket IO clocks: */ diff --git a/fs/bcachefs/backpointers.c b/fs/bcachefs/backpointers.c index 11201064d9a4..2641ebef6ae4 100644 --- a/fs/bcachefs/backpointers.c +++ b/fs/bcachefs/backpointers.c @@ -404,12 +404,16 @@ int bch2_check_btree_backpointers(struct bch_fs *c) { struct btree_iter iter; struct bkey_s_c k; + int ret; - return bch2_trans_run(c, + ret = bch2_trans_run(c, for_each_btree_key_commit(&trans, iter, BTREE_ID_backpointers, POS_MIN, 0, k, NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL, bch2_check_btree_backpointer(&trans, &iter, k))); + if (ret) + bch_err_fn(c, ret); + return ret; } struct bpos_level { @@ -769,6 +773,8 @@ int bch2_check_extents_to_backpointers(struct bch_fs *c) } bch2_trans_exit(&trans); + if (ret) + bch_err_fn(c, ret); return ret; } @@ -872,5 +878,7 @@ int bch2_check_backpointers_to_extents(struct bch_fs *c) } bch2_trans_exit(&trans); + if (ret) + bch_err_fn(c, ret); return ret; } diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 4199b42db640..b8d50fe64b3c 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -291,6 +291,11 @@ do { \ #define bch_err_inum_offset_ratelimited(c, _inum, _offset, fmt, ...) \ printk_ratelimited(KERN_ERR bch2_fmt_inum_offset(c, _inum, _offset, fmt), ##__VA_ARGS__) +#define bch_err_fn(_c, _ret) \ + bch_err(_c, "%s(): error %s", __func__, bch2_err_str(_ret)) +#define bch_err_msg(_c, _ret, _msg) \ + bch_err(_c, "%s(): error " _msg " %s", __func__, bch2_err_str(_ret)) + #define bch_verbose(c, fmt, ...) \ do { \ if ((c)->opts.verbose) \ diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index 8477e721b63c..4fbd2e545ac2 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -404,8 +404,7 @@ again: } if (ret) { - bch_err(c, "%s: error getting btree node: %s", - __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "getting btree node"); break; } @@ -473,8 +472,7 @@ again: ret = PTR_ERR_OR_ZERO(cur); if (ret) { - bch_err(c, "%s: error getting btree node: %s", - __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "getting btree node"); goto err; } @@ -687,7 +685,7 @@ 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(c, "%s: error allocating new key", __func__); + bch_err_msg(c, ret, "allocating new key"); ret = -BCH_ERR_ENOMEM_gc_repair_key; goto err; } @@ -814,7 +812,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id, fsck_err: err: if (ret) - bch_err(c, "error from %s(): %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -919,11 +917,8 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b ret = bch2_gc_mark_key(trans, b->c.btree_id, b->c.level, false, &k, true); - if (ret) { - bch_err(c, "%s: error from bch2_gc_mark_key: %s", - __func__, bch2_err_str(ret)); + if (ret) goto fsck_err; - } if (b->c.level) { bch2_bkey_buf_reassemble(&cur, c, k); @@ -981,8 +976,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b continue; } } else if (ret) { - bch_err(c, "%s: error getting btree node: %s", - __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "getting btree node"); break; } @@ -1049,7 +1043,7 @@ fsck_err: six_unlock_read(&b->c.lock); if (ret < 0) - bch_err(c, "error from %s(): %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); printbuf_exit(&buf); return ret; } @@ -1079,7 +1073,7 @@ static int bch2_gc_btrees(struct bch_fs *c, bool initial, bool metadata_only) : bch2_gc_btree(&trans, ids[i], initial, metadata_only); if (ret < 0) - bch_err(c, "error from %s(): %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); bch2_trans_exit(&trans); return ret; @@ -1277,7 +1271,7 @@ fsck_err: if (ca) percpu_ref_put(&ca->ref); if (ret) - bch_err(c, "error from %s(): %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); percpu_up_write(&c->mark_lock); printbuf_exit(&buf); @@ -1883,6 +1877,9 @@ 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); return ret; } diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index fbe0cd0a7de3..d770dc949661 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -1988,7 +1988,10 @@ static int __bch2_trans_mark_dev_sb(struct btree_trans *trans, int bch2_trans_mark_dev_sb(struct bch_fs *c, struct bch_dev *ca) { - return bch2_trans_run(c, __bch2_trans_mark_dev_sb(&trans, ca)); + int ret = bch2_trans_run(c, __bch2_trans_mark_dev_sb(&trans, ca)); + if (ret) + bch_err_fn(c, ret); + return ret; } /* Disk reservations: */ diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index b7e3889b114b..0c5c291e844e 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -798,7 +798,7 @@ static void ec_stripe_delete_work(struct work_struct *work) ret = commit_do(&trans, NULL, NULL, BTREE_INSERT_NOFAIL, ec_stripe_delete(&trans, idx)); if (ret) { - bch_err(c, "%s: err %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); break; } } @@ -1845,7 +1845,7 @@ int bch2_stripes_read(struct bch_fs *c) bch2_trans_exit(&trans); if (ret) - bch_err(c, "error reading stripes: %i", ret); + bch_err_fn(c, ret); return ret; } diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index dcc55cbd3808..194e8d474e86 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -303,7 +303,7 @@ static int __remove_dirent(struct btree_trans *trans, struct bpos pos) bch2_trans_iter_exit(trans, &iter); err: if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -983,7 +983,7 @@ static int check_inode(struct btree_trans *trans, err: fsck_err: if (ret) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1009,7 +1009,7 @@ static int check_inodes(struct bch_fs *c, bool full) bch2_trans_exit(&trans); snapshots_seen_exit(&s); if (ret) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1129,7 +1129,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) } fsck_err: if (ret) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); if (!ret && trans_was_restarted(trans, restart_count)) ret = -BCH_ERR_transaction_restart_nested; return ret; @@ -1353,7 +1353,7 @@ fsck_err: printbuf_exit(&buf); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1395,7 +1395,7 @@ static int check_extents(struct bch_fs *c) snapshots_seen_exit(&s); if (ret) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1434,7 +1434,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w) } fsck_err: if (ret) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); if (!ret && trans_was_restarted(trans, restart_count)) ret = -BCH_ERR_transaction_restart_nested; return ret; @@ -1555,7 +1555,7 @@ fsck_err: printbuf_exit(&buf); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1725,7 +1725,7 @@ fsck_err: printbuf_exit(&buf); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1764,7 +1764,7 @@ static int check_dirents(struct bch_fs *c) inode_walker_exit(&target); if (ret) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1801,7 +1801,7 @@ static int check_xattr(struct btree_trans *trans, struct btree_iter *iter, ret = hash_check_key(trans, bch2_xattr_hash_desc, hash_info, iter, k); fsck_err: if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1833,7 +1833,7 @@ static int check_xattrs(struct bch_fs *c) bch2_trans_exit(&trans); if (ret) - bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1896,12 +1896,18 @@ fsck_err: noinline_for_stack static int check_root(struct bch_fs *c) { + int ret; + bch_verbose(c, "checking root directory"); - return bch2_trans_do(c, NULL, NULL, + ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_NOFAIL| BTREE_INSERT_LAZY_RW, check_root_trans(&trans)); + + if (ret) + bch_err_fn(c, ret); + return ret; } struct pathbuf_entry { @@ -2038,7 +2044,7 @@ static int check_path(struct btree_trans *trans, } fsck_err: if (ret) - bch_err(c, "%s: err %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -2081,10 +2087,11 @@ static int check_directory_structure(struct bch_fs *c) break; } bch2_trans_iter_exit(&trans, &iter); - + bch2_trans_exit(&trans); darray_exit(&path); - bch2_trans_exit(&trans); + if (ret) + bch_err_fn(c, ret); return ret; } @@ -2364,6 +2371,8 @@ static int check_nlinks(struct bch_fs *c) kvfree(links.d); + if (ret) + bch_err_fn(c, ret); return ret; } @@ -2397,7 +2406,6 @@ static int fix_reflink_p_key(struct btree_trans *trans, struct btree_iter *iter, noinline_for_stack static int fix_reflink_p(struct bch_fs *c) { - struct btree_trans trans; struct btree_iter iter; struct bkey_s_c k; int ret; @@ -2407,15 +2415,16 @@ static int fix_reflink_p(struct bch_fs *c) bch_verbose(c, "fixing reflink_p keys"); - bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0); - - ret = for_each_btree_key_commit(&trans, iter, - BTREE_ID_extents, POS_MIN, - BTREE_ITER_INTENT|BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k, - NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, - fix_reflink_p_key(&trans, &iter, k)); + ret = bch2_trans_run(c, + for_each_btree_key_commit(&trans, iter, + BTREE_ID_extents, POS_MIN, + BTREE_ITER_INTENT|BTREE_ITER_PREFETCH| + BTREE_ITER_ALL_SNAPSHOTS, k, + NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, + fix_reflink_p_key(&trans, &iter, k))); - bch2_trans_exit(&trans); + if (ret) + bch_err_fn(c, ret); return ret; } diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index 433c97844f36..64332c78a6bb 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -978,7 +978,7 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca, } if (ret) - bch_err(c, "%s: err %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); unlock: up_write(&c->state_lock); return ret; @@ -987,9 +987,12 @@ unlock: int bch2_dev_journal_alloc(struct bch_dev *ca) { unsigned nr; + int ret; - if (dynamic_fault("bcachefs:add:journal_alloc")) - return -BCH_ERR_ENOMEM_set_nr_journal_buckets; + if (dynamic_fault("bcachefs:add:journal_alloc")) { + ret = -BCH_ERR_ENOMEM_set_nr_journal_buckets; + goto err; + } /* 1/128th of the device by default: */ nr = ca->mi.nbuckets >> 7; @@ -1003,7 +1006,11 @@ int bch2_dev_journal_alloc(struct bch_dev *ca) min(1 << 13, (1 << 24) / ca->mi.bucket_size)); - return __bch2_set_nr_journal_buckets(ca, nr, true, NULL); + ret = __bch2_set_nr_journal_buckets(ca, nr, true, NULL); +err: + if (ret) + bch_err_fn(ca, ret); + return ret; } /* startup/shutdown: */ diff --git a/fs/bcachefs/lru.c b/fs/bcachefs/lru.c index 4f23e88f6ae1..e04c037f0c01 100644 --- a/fs/bcachefs/lru.c +++ b/fs/bcachefs/lru.c @@ -160,20 +160,18 @@ fsck_err: int bch2_check_lrus(struct bch_fs *c) { - struct btree_trans trans; struct btree_iter iter; struct bkey_s_c k; struct bpos last_flushed_pos = POS_MIN; int ret = 0; - bch2_trans_init(&trans, c, 0, 0); - - ret = for_each_btree_key_commit(&trans, iter, - BTREE_ID_lru, POS_MIN, BTREE_ITER_PREFETCH, k, - NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, - bch2_check_lru_key(&trans, &iter, k, &last_flushed_pos)); - - bch2_trans_exit(&trans); + ret = bch2_trans_run(c, + for_each_btree_key_commit(&trans, iter, + BTREE_ID_lru, POS_MIN, BTREE_ITER_PREFETCH, k, + NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, + bch2_check_lru_key(&trans, &iter, k, &last_flushed_pos))); + if (ret) + bch_err_fn(c, ret); return ret; } diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c index fd629136824b..37fb3784a2f9 100644 --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -690,7 +690,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans, bch2_trans_iter_exit(trans, &iter); if (ret) { - bch_err(c, "%s: error looking up alloc key: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "looking up alloc key"); goto err; } @@ -701,7 +701,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans, ret = bch2_btree_write_buffer_flush(trans); if (ret) { - bch_err(c, "%s: error flushing btree write buffer: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "flushing btree write buffer"); goto err; } @@ -904,7 +904,7 @@ next: bch2_trans_exit(&trans); if (ret) - bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); bch2_btree_interior_updates_flush(c); @@ -1029,6 +1029,8 @@ int bch2_scan_old_btree_nodes(struct bch_fs *c, struct bch_move_stats *stats) mutex_unlock(&c->sb_lock); } + if (ret) + bch_err_fn(c, ret); return ret; } diff --git a/fs/bcachefs/quota.c b/fs/bcachefs/quota.c index d20ec9764108..7e1f1828ab20 100644 --- a/fs/bcachefs/quota.c +++ b/fs/bcachefs/quota.c @@ -621,10 +621,11 @@ int bch2_fs_quota_read(struct bch_fs *c) for_each_btree_key2(&trans, iter, BTREE_ID_inodes, POS_MIN, BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k, bch2_fs_quota_read_inode(&trans, &iter, k)); - if (ret) - bch_err(c, "%s: err %s", __func__, bch2_err_str(ret)); bch2_trans_exit(&trans); + + if (ret) + bch_err_fn(c, ret); return ret; } diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index e4983d144483..09c9d4058f82 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -685,6 +685,9 @@ static int bch2_journal_replay(struct bch_fs *c, u64 start_seq, u64 end_seq) bch2_journal_log_msg(c, "journal replay finished"); err: kvfree(keys_sorted); + + if (ret) + bch_err_fn(c, ret); return ret; } @@ -1034,9 +1037,6 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c) root_tree.k.p.offset = 1; root_tree.v.master_subvol = cpu_to_le32(1); root_tree.v.root_snapshot = cpu_to_le32(U32_MAX); - ret = bch2_btree_insert(c, BTREE_ID_snapshot_trees, - &root_tree.k_i, - NULL, NULL, 0); bkey_snapshot_init(&root_snapshot.k_i); root_snapshot.k.p.offset = U32_MAX; @@ -1046,28 +1046,27 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c) root_snapshot.v.tree = cpu_to_le32(1); SET_BCH_SNAPSHOT_SUBVOL(&root_snapshot.v, true); - ret = bch2_btree_insert(c, BTREE_ID_snapshots, - &root_snapshot.k_i, - NULL, NULL, 0); - if (ret) - return ret; - bkey_subvolume_init(&root_volume.k_i); root_volume.k.p.offset = BCACHEFS_ROOT_SUBVOL; root_volume.v.flags = 0; root_volume.v.snapshot = cpu_to_le32(U32_MAX); root_volume.v.inode = cpu_to_le64(BCACHEFS_ROOT_INO); - ret = bch2_btree_insert(c, BTREE_ID_subvolumes, - &root_volume.k_i, - NULL, NULL, 0); + ret = bch2_btree_insert(c, BTREE_ID_snapshot_trees, + &root_tree.k_i, + NULL, NULL, 0) ?: + bch2_btree_insert(c, BTREE_ID_snapshots, + &root_snapshot.k_i, + NULL, NULL, 0) ?: + bch2_btree_insert(c, BTREE_ID_subvolumes, + &root_volume.k_i, + NULL, NULL, 0); if (ret) - return ret; - - return 0; + bch_err_fn(c, ret); + return ret; } -static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans) +static int __bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans) { struct btree_iter iter; struct bkey_s_c k; @@ -1097,9 +1096,19 @@ err: return ret; } +/* set bi_subvol on root inode */ +noinline_for_stack +static int bch2_fs_upgrade_for_subvolumes(struct bch_fs *c) +{ + int ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_LAZY_RW, + __bch2_fs_upgrade_for_subvolumes(&trans)); + if (ret) + bch_err_fn(c, ret); + return ret; +} + int bch2_fs_recovery(struct bch_fs *c) { - const char *err = "cannot allocate memory"; struct bch_sb_field_clean *clean = NULL; struct jset *last_journal_entry = NULL; u64 last_seq, blacklist_seq, journal_seq; @@ -1137,12 +1146,6 @@ int bch2_fs_recovery(struct bch_fs *c) goto err; } - if (!(c->sb.features & (1ULL << BCH_FEATURE_alloc_v2))) { - bch_info(c, "alloc_v2 feature bit not set, fsck required"); - c->opts.fsck = true; - c->opts.fix_errors = FSCK_OPT_YES; - } - if (!c->opts.nochanges) { if (c->sb.version < bcachefs_metadata_required_upgrade_below) { bch_info(c, "version %s (%u) prior to %s (%u), upgrade and fsck required", @@ -1286,34 +1289,28 @@ use_clean: goto err; bch_verbose(c, "starting alloc read"); - err = "error reading allocation information"; - down_read(&c->gc_lock); ret = c->sb.version < bcachefs_metadata_version_bucket_gens ? bch2_alloc_read(c) : bch2_bucket_gens_read(c); up_read(&c->gc_lock); - if (ret) goto err; bch_verbose(c, "alloc read done"); bch_verbose(c, "starting stripes_read"); - err = "error reading stripes"; ret = bch2_stripes_read(c); if (ret) goto err; bch_verbose(c, "stripes_read done"); if (c->sb.version < bcachefs_metadata_version_snapshot_2) { - err = "error creating root snapshot node"; ret = bch2_fs_initialize_subvolumes(c); if (ret) goto err; } bch_verbose(c, "reading snapshots table"); - err = "error reading snapshots table"; ret = bch2_fs_snapshots_start(c); if (ret) goto err; @@ -1323,7 +1320,6 @@ use_clean: bool metadata_only = c->opts.norecovery; bch_info(c, "checking allocations"); - err = "error checking allocations"; ret = bch2_gc(c, true, metadata_only); if (ret) goto err; @@ -1334,7 +1330,6 @@ use_clean: set_bit(BCH_FS_MAY_GO_RW, &c->flags); bch_info(c, "starting journal replay, %zu keys", c->journal_keys.nr); - err = "journal replay failed"; ret = bch2_journal_replay(c, last_seq, blacklist_seq - 1); if (ret) goto err; @@ -1342,7 +1337,6 @@ use_clean: bch_info(c, "journal replay done"); bch_info(c, "checking need_discard and freespace btrees"); - err = "error checking need_discard and freespace btrees"; ret = bch2_check_alloc_info(c); if (ret) goto err; @@ -1351,7 +1345,6 @@ use_clean: set_bit(BCH_FS_CHECK_ALLOC_DONE, &c->flags); bch_info(c, "checking lrus"); - err = "error checking lrus"; ret = bch2_check_lrus(c); if (ret) goto err; @@ -1359,21 +1352,18 @@ use_clean: set_bit(BCH_FS_CHECK_LRUS_DONE, &c->flags); bch_info(c, "checking backpointers to alloc keys"); - err = "error checking backpointers to alloc keys"; ret = bch2_check_btree_backpointers(c); if (ret) goto err; bch_verbose(c, "done checking backpointers to alloc keys"); bch_info(c, "checking backpointers to extents"); - err = "error checking backpointers to extents"; ret = bch2_check_backpointers_to_extents(c); if (ret) goto err; bch_verbose(c, "done checking backpointers to extents"); bch_info(c, "checking extents to backpointers"); - err = "error checking extents to backpointers"; ret = bch2_check_extents_to_backpointers(c); if (ret) goto err; @@ -1381,7 +1371,6 @@ use_clean: set_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags); bch_info(c, "checking alloc to lru refs"); - err = "error checking alloc to lru refs"; ret = bch2_check_alloc_to_lru_refs(c); if (ret) goto err; @@ -1401,7 +1390,6 @@ use_clean: set_bit(BCH_FS_MAY_GO_RW, &c->flags); bch_verbose(c, "starting journal replay, %zu keys", c->journal_keys.nr); - err = "journal replay failed"; ret = bch2_journal_replay(c, last_seq, blacklist_seq - 1); if (ret) goto err; @@ -1409,7 +1397,6 @@ use_clean: bch_info(c, "journal replay done"); } - err = "error initializing freespace"; ret = bch2_fs_freespace_init(c); if (ret) goto err; @@ -1417,7 +1404,6 @@ use_clean: if (c->sb.version < bcachefs_metadata_version_bucket_gens && c->opts.version_upgrade) { bch_info(c, "initializing bucket_gens"); - err = "error initializing bucket gens"; ret = bch2_bucket_gens_init(c); if (ret) goto err; @@ -1425,24 +1411,18 @@ use_clean: } if (c->sb.version < bcachefs_metadata_version_snapshot_2) { - /* set bi_subvol on root inode */ - err = "error upgrade root inode for subvolumes"; - ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_LAZY_RW, - bch2_fs_upgrade_for_subvolumes(&trans)); + ret = bch2_fs_upgrade_for_subvolumes(c); if (ret) goto err; } if (c->opts.fsck) { - bch_info(c, "starting fsck"); - err = "error in fsck"; ret = bch2_fsck_full(c); if (ret) goto err; bch_verbose(c, "fsck done"); } else if (!c->sb.clean) { bch_verbose(c, "checking for deleted inodes"); - err = "error in recovery"; ret = bch2_fsck_walk_inodes_only(c); if (ret) goto err; @@ -1489,11 +1469,8 @@ use_clean: bch2_move_stats_init(&stats, "recovery"); bch_info(c, "scanning for old btree nodes"); - ret = bch2_fs_read_write(c); - if (ret) - goto err; - - ret = bch2_scan_old_btree_nodes(c, &stats); + ret = bch2_fs_read_write(c) ?: + bch2_scan_old_btree_nodes(c, &stats); if (ret) goto err; bch_info(c, "scanning for old btree nodes done"); @@ -1521,7 +1498,7 @@ out: } if (ret) - bch_err(c, "Error in recovery: %s (%s)", err, bch2_err_str(ret)); + bch_err_fn(c, ret); else bch_verbose(c, "ret %s", bch2_err_str(ret)); return ret; @@ -1536,7 +1513,6 @@ int bch2_fs_initialize(struct bch_fs *c) struct bch_inode_unpacked root_inode, lostfound_inode; struct bkey_inode_buf packed_inode; struct qstr lostfound = QSTR("lost+found"); - const char *err = "cannot allocate memory"; struct bch_dev *ca; unsigned i; int ret; @@ -1570,7 +1546,6 @@ int bch2_fs_initialize(struct bch_fs *c) for_each_online_member(ca, c, i) bch2_dev_usage_init(ca); - err = "unable to allocate journal buckets"; for_each_online_member(ca, c, i) { ret = bch2_dev_journal_alloc(ca); if (ret) { @@ -1586,7 +1561,6 @@ int bch2_fs_initialize(struct bch_fs *c) bch2_fs_journal_start(&c->journal, 1); bch2_journal_set_replay_done(&c->journal); - err = "error going read-write"; ret = bch2_fs_read_write_early(c); if (ret) goto err; @@ -1596,7 +1570,6 @@ int bch2_fs_initialize(struct bch_fs *c) * btree updates */ bch_verbose(c, "marking superblocks"); - err = "error marking superblock and journal"; for_each_member_device(ca, c, i) { ret = bch2_trans_mark_dev_sb(c, ca); if (ret) { @@ -1607,19 +1580,15 @@ int bch2_fs_initialize(struct bch_fs *c) ca->new_fs_bucket_idx = 0; } - bch_verbose(c, "initializing freespace"); - err = "error initializing freespace"; ret = bch2_fs_freespace_init(c); if (ret) goto err; - err = "error creating root snapshot node"; ret = bch2_fs_initialize_subvolumes(c); if (ret) goto err; bch_verbose(c, "reading snapshots table"); - err = "error reading snapshots table"; ret = bch2_fs_snapshots_start(c); if (ret) goto err; @@ -1631,16 +1600,16 @@ int bch2_fs_initialize(struct bch_fs *c) bch2_inode_pack(&packed_inode, &root_inode); packed_inode.inode.k.p.snapshot = U32_MAX; - err = "error creating root directory"; ret = bch2_btree_insert(c, BTREE_ID_inodes, &packed_inode.inode.k_i, NULL, NULL, 0); - if (ret) + if (ret) { + bch_err_msg(c, ret, "creating root directory"); goto err; + } bch2_inode_init_early(c, &lostfound_inode); - err = "error creating lost+found"; ret = bch2_trans_do(c, NULL, NULL, 0, bch2_create_trans(&trans, BCACHEFS_ROOT_SUBVOL_INUM, @@ -1649,7 +1618,7 @@ int bch2_fs_initialize(struct bch_fs *c) 0, 0, S_IFDIR|0700, 0, NULL, NULL, (subvol_inum) { 0 }, 0)); if (ret) { - bch_err(c, "error creating lost+found"); + bch_err_msg(c, ret, "creating lost+found"); goto err; } @@ -1659,10 +1628,11 @@ int bch2_fs_initialize(struct bch_fs *c) goto err; } - err = "error writing first journal entry"; ret = bch2_journal_flush(&c->journal); - if (ret) + if (ret) { + bch_err_msg(c, ret, "writing first journal entry"); goto err; + } mutex_lock(&c->sb_lock); SET_BCH_SB_INITIALIZED(c->disk_sb.sb, true); @@ -1673,6 +1643,6 @@ int bch2_fs_initialize(struct bch_fs *c) return 0; err: - pr_err("Error initializing new filesystem: %s (%s)", err, bch2_err_str(ret)); + bch_err_fn(ca, ret); return ret; } diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c index 4b6631c229ee..828644e6c714 100644 --- a/fs/bcachefs/subvolume.c +++ b/fs/bcachefs/subvolume.c @@ -623,7 +623,7 @@ int bch2_fs_check_snapshots(struct bch_fs *c) NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL, check_snapshot(&trans, &iter, k))); if (ret) - bch_err(c, "%s: error %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -702,8 +702,7 @@ int bch2_fs_check_subvols(struct bch_fs *c) NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL, check_subvol(&trans, &iter, k))); if (ret) - bch_err(c, "%s: error %s", __func__, bch2_err_str(ret)); - + bch_err_fn(c, ret); return ret; } @@ -724,7 +723,7 @@ int bch2_fs_snapshots_start(struct bch_fs *c) bch2_mark_snapshot(&trans, BTREE_ID_snapshots, 0, bkey_s_c_null, k, 0) ?: bch2_snapshot_set_equiv(&trans, k))); if (ret) - bch_err(c, "error starting snapshots: %s", bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -1123,6 +1122,8 @@ int bch2_delete_dead_snapshots(struct bch_fs *c) err: darray_exit(&deleted); bch2_trans_exit(&trans); + if (ret) + bch_err_fn(c, ret); return ret; } diff --git a/fs/bcachefs/tests.c b/fs/bcachefs/tests.c index 35df3f940542..50d69a5634bd 100644 --- a/fs/bcachefs/tests.c +++ b/fs/bcachefs/tests.c @@ -47,7 +47,7 @@ static int test_delete(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_trans_update(&trans, &iter, &k.k_i, 0)); if (ret) { - bch_err(c, "%s(): update error in: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "update error"); goto err; } @@ -56,7 +56,7 @@ static int test_delete(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(&trans, &iter, 0)); if (ret) { - bch_err(c, "%s(): delete error (first): %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "delete error (first)"); goto err; } @@ -65,7 +65,7 @@ static int test_delete(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(&trans, &iter, 0)); if (ret) { - bch_err(c, "%s(): delete error (second): %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "delete error (second)"); goto err; } err: @@ -93,7 +93,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_trans_update(&trans, &iter, &k.k_i, 0)); if (ret) { - bch_err(c, "%s(): update error: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "update error"); goto err; } @@ -104,7 +104,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(&trans, &iter, 0)); if (ret) { - bch_err(c, "%s(): delete error: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "delete error"); goto err; } err: @@ -137,7 +137,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "insert error"); goto err; } } @@ -153,7 +153,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) 0; })); if (ret) { - bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating forwards"); goto err; } @@ -168,7 +168,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) 0; })); if (ret) { - bch_err(c, "%s(): error iterating backwards: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating backwards"); goto err; } @@ -204,7 +204,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "insert error"); goto err; } } @@ -221,7 +221,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) 0; })); if (ret) { - bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating forwards"); goto err; } @@ -237,7 +237,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) 0; })); if (ret) { - bch_err(c, "%s(): error iterating backwards: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating backwards"); goto err; } @@ -272,7 +272,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "insert error"); goto err; } } @@ -289,7 +289,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) 0; })); if (ret) { - bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating forwards"); goto err; } @@ -312,7 +312,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) 0; })); if (ret < 0) { - bch_err(c, "%s(): error iterating forwards by slots: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating forwards by slots"); goto err; } ret = 0; @@ -346,7 +346,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "insert error"); goto err; } } @@ -364,7 +364,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) 0; })); if (ret) { - bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating forwards"); goto err; } @@ -387,7 +387,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) 0; })); if (ret) { - bch_err(c, "%s(): error iterating forwards by slots: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "error iterating forwards by slots"); goto err; } ret = 0; @@ -461,7 +461,7 @@ static int insert_test_extent(struct bch_fs *c, ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, NULL, NULL, 0); if (ret) - bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); + bch_err_fn(c, ret); return ret; } @@ -560,7 +560,7 @@ static int test_snapshots(struct bch_fs *c, u64 nr) ret = test_snapshot_filter(c, snapids[0], snapids[1]); if (ret) { - bch_err(c, "%s(): err from test_snapshot_filter: %s", __func__, bch2_err_str(ret)); + bch_err_msg(c, ret, "from test_snapshot_filter"); return ret; } @@ -674,7 +674,7 @@ static int rand_mixed_trans(struct btree_trans *trans, k = bch2_btree_iter_peek(iter); ret = bkey_err(k); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(trans->c, "%s(): lookup error: %s", __func__, bch2_err_str(ret)); + bch_err_msg(trans->c, ret, "lookup error"); if (ret) return ret; |