Commit 1bb3c2a9 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: New error message helpers

Add two new helpers for printing error messages with __func__ and
bch2_err_str():
 - bch_err_fn
 - bch_err_msg

Also kill the old error strings in the recovery path, which were causing
us to incorrectly report memory allocation failures - they're not needed
anymore.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a83e108f
...@@ -577,7 +577,7 @@ int bch2_alloc_read(struct bch_fs *c) ...@@ -577,7 +577,7 @@ int bch2_alloc_read(struct bch_fs *c)
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) if (ret)
bch_err(c, "error reading alloc info: %s", bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -684,8 +684,7 @@ int bch2_bucket_gens_init(struct bch_fs *c) ...@@ -684,8 +684,7 @@ int bch2_bucket_gens_init(struct bch_fs *c)
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) if (ret)
bch_err(c, "%s: error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -730,7 +729,7 @@ int bch2_bucket_gens_read(struct bch_fs *c) ...@@ -730,7 +729,7 @@ int bch2_bucket_gens_read(struct bch_fs *c)
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) if (ret)
bch_err(c, "error reading alloc info: %s", bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1521,7 +1520,9 @@ int bch2_check_alloc_info(struct bch_fs *c) ...@@ -1521,7 +1520,9 @@ int bch2_check_alloc_info(struct bch_fs *c)
bch2_check_bucket_gens_key(&trans, &iter, k)); bch2_check_bucket_gens_key(&trans, &iter, k));
err: err:
bch2_trans_exit(&trans); 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, static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
...@@ -1599,20 +1600,18 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans, ...@@ -1599,20 +1600,18 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
int bch2_check_alloc_to_lru_refs(struct bch_fs *c) int bch2_check_alloc_to_lru_refs(struct bch_fs *c)
{ {
struct btree_trans trans;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
int ret = 0; int ret = 0;
bch2_trans_init(&trans, c, 0, 0); ret = bch2_trans_run(c,
for_each_btree_key_commit(&trans, iter, BTREE_ID_alloc, for_each_btree_key_commit(&trans, iter, BTREE_ID_alloc,
POS_MIN, BTREE_ITER_PREFETCH, k, POS_MIN, BTREE_ITER_PREFETCH, k,
NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW,
bch2_check_alloc_to_lru_ref(&trans, &iter)); bch2_check_alloc_to_lru_ref(&trans, &iter)));
if (ret)
bch2_trans_exit(&trans); bch_err_fn(c, ret);
return ret < 0 ? ret : 0; return ret;
} }
static int bch2_discard_one_bucket(struct btree_trans *trans, static int bch2_discard_one_bucket(struct btree_trans *trans,
...@@ -2024,6 +2023,7 @@ int bch2_fs_freespace_init(struct bch_fs *c) ...@@ -2024,6 +2023,7 @@ int bch2_fs_freespace_init(struct bch_fs *c)
ret = bch2_dev_freespace_init(c, ca, &last_updated); ret = bch2_dev_freespace_init(c, ca, &last_updated);
if (ret) { if (ret) {
percpu_ref_put(&ca->ref); percpu_ref_put(&ca->ref);
bch_err_fn(c, ret);
return ret; return ret;
} }
} }
...@@ -2032,11 +2032,10 @@ int bch2_fs_freespace_init(struct bch_fs *c) ...@@ -2032,11 +2032,10 @@ int bch2_fs_freespace_init(struct bch_fs *c)
mutex_lock(&c->sb_lock); mutex_lock(&c->sb_lock);
bch2_write_super(c); bch2_write_super(c);
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
bch_verbose(c, "done initializing freespace"); bch_verbose(c, "done initializing freespace");
} }
return ret; return 0;
} }
/* Bucket IO clocks: */ /* Bucket IO clocks: */
......
...@@ -404,12 +404,16 @@ int bch2_check_btree_backpointers(struct bch_fs *c) ...@@ -404,12 +404,16 @@ int bch2_check_btree_backpointers(struct bch_fs *c)
{ {
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
int ret;
return bch2_trans_run(c, ret = bch2_trans_run(c,
for_each_btree_key_commit(&trans, iter, for_each_btree_key_commit(&trans, iter,
BTREE_ID_backpointers, POS_MIN, 0, k, BTREE_ID_backpointers, POS_MIN, 0, k,
NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL, NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL,
bch2_check_btree_backpointer(&trans, &iter, k))); bch2_check_btree_backpointer(&trans, &iter, k)));
if (ret)
bch_err_fn(c, ret);
return ret;
} }
struct bpos_level { struct bpos_level {
...@@ -769,6 +773,8 @@ int bch2_check_extents_to_backpointers(struct bch_fs *c) ...@@ -769,6 +773,8 @@ int bch2_check_extents_to_backpointers(struct bch_fs *c)
} }
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -872,5 +878,7 @@ int bch2_check_backpointers_to_extents(struct bch_fs *c) ...@@ -872,5 +878,7 @@ int bch2_check_backpointers_to_extents(struct bch_fs *c)
} }
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -291,6 +291,11 @@ do { \ ...@@ -291,6 +291,11 @@ do { \
#define bch_err_inum_offset_ratelimited(c, _inum, _offset, fmt, ...) \ #define bch_err_inum_offset_ratelimited(c, _inum, _offset, fmt, ...) \
printk_ratelimited(KERN_ERR bch2_fmt_inum_offset(c, _inum, _offset, fmt), ##__VA_ARGS__) 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, ...) \ #define bch_verbose(c, fmt, ...) \
do { \ do { \
if ((c)->opts.verbose) \ if ((c)->opts.verbose) \
......
...@@ -404,8 +404,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct ...@@ -404,8 +404,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
} }
if (ret) { if (ret) {
bch_err(c, "%s: error getting btree node: %s", bch_err_msg(c, ret, "getting btree node");
__func__, bch2_err_str(ret));
break; break;
} }
...@@ -473,8 +472,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct ...@@ -473,8 +472,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
ret = PTR_ERR_OR_ZERO(cur); ret = PTR_ERR_OR_ZERO(cur);
if (ret) { if (ret) {
bch_err(c, "%s: error getting btree node: %s", bch_err_msg(c, ret, "getting btree node");
__func__, bch2_err_str(ret));
goto err; goto err;
} }
...@@ -687,7 +685,7 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id ...@@ -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); new = kmalloc(bkey_bytes(k->k), GFP_KERNEL);
if (!new) { 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; ret = -BCH_ERR_ENOMEM_gc_repair_key;
goto err; goto err;
} }
...@@ -814,7 +812,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id, ...@@ -814,7 +812,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
fsck_err: fsck_err:
err: err:
if (ret) if (ret)
bch_err(c, "error from %s(): %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -919,11 +917,8 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b ...@@ -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, ret = bch2_gc_mark_key(trans, b->c.btree_id, b->c.level,
false, &k, true); false, &k, true);
if (ret) { if (ret)
bch_err(c, "%s: error from bch2_gc_mark_key: %s",
__func__, bch2_err_str(ret));
goto fsck_err; goto fsck_err;
}
if (b->c.level) { if (b->c.level) {
bch2_bkey_buf_reassemble(&cur, c, k); 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 ...@@ -981,8 +976,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b
continue; continue;
} }
} else if (ret) { } else if (ret) {
bch_err(c, "%s: error getting btree node: %s", bch_err_msg(c, ret, "getting btree node");
__func__, bch2_err_str(ret));
break; break;
} }
...@@ -1049,7 +1043,7 @@ static int bch2_gc_btree_init(struct btree_trans *trans, ...@@ -1049,7 +1043,7 @@ static int bch2_gc_btree_init(struct btree_trans *trans,
six_unlock_read(&b->c.lock); six_unlock_read(&b->c.lock);
if (ret < 0) if (ret < 0)
bch_err(c, "error from %s(): %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
printbuf_exit(&buf); printbuf_exit(&buf);
return ret; return ret;
} }
...@@ -1079,7 +1073,7 @@ static int bch2_gc_btrees(struct bch_fs *c, bool initial, bool metadata_only) ...@@ -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); : bch2_gc_btree(&trans, ids[i], initial, metadata_only);
if (ret < 0) if (ret < 0)
bch_err(c, "error from %s(): %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
return ret; return ret;
...@@ -1277,7 +1271,7 @@ static int bch2_gc_done(struct bch_fs *c, ...@@ -1277,7 +1271,7 @@ static int bch2_gc_done(struct bch_fs *c,
if (ca) if (ca)
percpu_ref_put(&ca->ref); percpu_ref_put(&ca->ref);
if (ret) 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); percpu_up_write(&c->mark_lock);
printbuf_exit(&buf); printbuf_exit(&buf);
...@@ -1883,6 +1877,9 @@ int bch2_gc(struct bch_fs *c, bool initial, bool metadata_only) ...@@ -1883,6 +1877,9 @@ int bch2_gc(struct bch_fs *c, bool initial, bool metadata_only)
* allocator thread - issue wakeup in case they blocked on gc_lock: * allocator thread - issue wakeup in case they blocked on gc_lock:
*/ */
closure_wake_up(&c->freelist_wait); closure_wake_up(&c->freelist_wait);
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
......
...@@ -1988,7 +1988,10 @@ static int __bch2_trans_mark_dev_sb(struct btree_trans *trans, ...@@ -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) 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: */ /* Disk reservations: */
......
...@@ -798,7 +798,7 @@ static void ec_stripe_delete_work(struct work_struct *work) ...@@ -798,7 +798,7 @@ static void ec_stripe_delete_work(struct work_struct *work)
ret = commit_do(&trans, NULL, NULL, BTREE_INSERT_NOFAIL, ret = commit_do(&trans, NULL, NULL, BTREE_INSERT_NOFAIL,
ec_stripe_delete(&trans, idx)); ec_stripe_delete(&trans, idx));
if (ret) { if (ret) {
bch_err(c, "%s: err %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
break; break;
} }
} }
...@@ -1845,7 +1845,7 @@ int bch2_stripes_read(struct bch_fs *c) ...@@ -1845,7 +1845,7 @@ int bch2_stripes_read(struct bch_fs *c)
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) if (ret)
bch_err(c, "error reading stripes: %i", ret); bch_err_fn(c, ret);
return ret; return ret;
} }
......
...@@ -303,7 +303,7 @@ static int __remove_dirent(struct btree_trans *trans, struct bpos pos) ...@@ -303,7 +303,7 @@ static int __remove_dirent(struct btree_trans *trans, struct bpos pos)
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
err: err:
if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) 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; return ret;
} }
...@@ -983,7 +983,7 @@ static int check_inode(struct btree_trans *trans, ...@@ -983,7 +983,7 @@ static int check_inode(struct btree_trans *trans,
err: err:
fsck_err: fsck_err:
if (ret) if (ret)
bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1009,7 +1009,7 @@ static int check_inodes(struct bch_fs *c, bool full) ...@@ -1009,7 +1009,7 @@ static int check_inodes(struct bch_fs *c, bool full)
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
snapshots_seen_exit(&s); snapshots_seen_exit(&s);
if (ret) if (ret)
bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1129,7 +1129,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) ...@@ -1129,7 +1129,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w)
} }
fsck_err: fsck_err:
if (ret) 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)) if (!ret && trans_was_restarted(trans, restart_count))
ret = -BCH_ERR_transaction_restart_nested; ret = -BCH_ERR_transaction_restart_nested;
return ret; return ret;
...@@ -1353,7 +1353,7 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter, ...@@ -1353,7 +1353,7 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter,
printbuf_exit(&buf); printbuf_exit(&buf);
if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) 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; return ret;
} }
...@@ -1395,7 +1395,7 @@ static int check_extents(struct bch_fs *c) ...@@ -1395,7 +1395,7 @@ static int check_extents(struct bch_fs *c)
snapshots_seen_exit(&s); snapshots_seen_exit(&s);
if (ret) if (ret)
bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1434,7 +1434,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w) ...@@ -1434,7 +1434,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w)
} }
fsck_err: fsck_err:
if (ret) 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)) if (!ret && trans_was_restarted(trans, restart_count))
ret = -BCH_ERR_transaction_restart_nested; ret = -BCH_ERR_transaction_restart_nested;
return ret; return ret;
...@@ -1555,7 +1555,7 @@ static int check_dirent_target(struct btree_trans *trans, ...@@ -1555,7 +1555,7 @@ static int check_dirent_target(struct btree_trans *trans,
printbuf_exit(&buf); printbuf_exit(&buf);
if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) 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; return ret;
} }
...@@ -1725,7 +1725,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter, ...@@ -1725,7 +1725,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
printbuf_exit(&buf); printbuf_exit(&buf);
if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) 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; return ret;
} }
...@@ -1764,7 +1764,7 @@ static int check_dirents(struct bch_fs *c) ...@@ -1764,7 +1764,7 @@ static int check_dirents(struct bch_fs *c)
inode_walker_exit(&target); inode_walker_exit(&target);
if (ret) if (ret)
bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1801,7 +1801,7 @@ static int check_xattr(struct btree_trans *trans, struct btree_iter *iter, ...@@ -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); ret = hash_check_key(trans, bch2_xattr_hash_desc, hash_info, iter, k);
fsck_err: fsck_err:
if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) 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; return ret;
} }
...@@ -1833,7 +1833,7 @@ static int check_xattrs(struct bch_fs *c) ...@@ -1833,7 +1833,7 @@ static int check_xattrs(struct bch_fs *c)
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) if (ret)
bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1896,12 +1896,18 @@ static int check_root_trans(struct btree_trans *trans) ...@@ -1896,12 +1896,18 @@ static int check_root_trans(struct btree_trans *trans)
noinline_for_stack noinline_for_stack
static int check_root(struct bch_fs *c) static int check_root(struct bch_fs *c)
{ {
int ret;
bch_verbose(c, "checking root directory"); 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_NOFAIL|
BTREE_INSERT_LAZY_RW, BTREE_INSERT_LAZY_RW,
check_root_trans(&trans)); check_root_trans(&trans));
if (ret)
bch_err_fn(c, ret);
return ret;
} }
struct pathbuf_entry { struct pathbuf_entry {
...@@ -2038,7 +2044,7 @@ static int check_path(struct btree_trans *trans, ...@@ -2038,7 +2044,7 @@ static int check_path(struct btree_trans *trans,
} }
fsck_err: fsck_err:
if (ret) if (ret)
bch_err(c, "%s: err %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -2081,10 +2087,11 @@ static int check_directory_structure(struct bch_fs *c) ...@@ -2081,10 +2087,11 @@ static int check_directory_structure(struct bch_fs *c)
break; break;
} }
bch2_trans_iter_exit(&trans, &iter); bch2_trans_iter_exit(&trans, &iter);
bch2_trans_exit(&trans);
darray_exit(&path); darray_exit(&path);
bch2_trans_exit(&trans); if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -2364,6 +2371,8 @@ static int check_nlinks(struct bch_fs *c) ...@@ -2364,6 +2371,8 @@ static int check_nlinks(struct bch_fs *c)
kvfree(links.d); kvfree(links.d);
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -2397,7 +2406,6 @@ static int fix_reflink_p_key(struct btree_trans *trans, struct btree_iter *iter, ...@@ -2397,7 +2406,6 @@ static int fix_reflink_p_key(struct btree_trans *trans, struct btree_iter *iter,
noinline_for_stack noinline_for_stack
static int fix_reflink_p(struct bch_fs *c) static int fix_reflink_p(struct bch_fs *c)
{ {
struct btree_trans trans;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
int ret; int ret;
...@@ -2407,15 +2415,16 @@ static int fix_reflink_p(struct bch_fs *c) ...@@ -2407,15 +2415,16 @@ static int fix_reflink_p(struct bch_fs *c)
bch_verbose(c, "fixing reflink_p keys"); bch_verbose(c, "fixing reflink_p keys");
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0); ret = bch2_trans_run(c,
for_each_btree_key_commit(&trans, iter,
ret = for_each_btree_key_commit(&trans, iter,
BTREE_ID_extents, POS_MIN, BTREE_ID_extents, POS_MIN,
BTREE_ITER_INTENT|BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k, BTREE_ITER_INTENT|BTREE_ITER_PREFETCH|
BTREE_ITER_ALL_SNAPSHOTS, k,
NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW,
fix_reflink_p_key(&trans, &iter, k)); fix_reflink_p_key(&trans, &iter, k)));
bch2_trans_exit(&trans); if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
......
...@@ -978,7 +978,7 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca, ...@@ -978,7 +978,7 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca,
} }
if (ret) if (ret)
bch_err(c, "%s: err %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
unlock: unlock:
up_write(&c->state_lock); up_write(&c->state_lock);
return ret; return ret;
...@@ -987,9 +987,12 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca, ...@@ -987,9 +987,12 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca,
int bch2_dev_journal_alloc(struct bch_dev *ca) int bch2_dev_journal_alloc(struct bch_dev *ca)
{ {
unsigned nr; unsigned nr;
int ret;
if (dynamic_fault("bcachefs:add:journal_alloc")) if (dynamic_fault("bcachefs:add:journal_alloc")) {
return -BCH_ERR_ENOMEM_set_nr_journal_buckets; ret = -BCH_ERR_ENOMEM_set_nr_journal_buckets;
goto err;
}
/* 1/128th of the device by default: */ /* 1/128th of the device by default: */
nr = ca->mi.nbuckets >> 7; nr = ca->mi.nbuckets >> 7;
...@@ -1003,7 +1006,11 @@ int bch2_dev_journal_alloc(struct bch_dev *ca) ...@@ -1003,7 +1006,11 @@ int bch2_dev_journal_alloc(struct bch_dev *ca)
min(1 << 13, min(1 << 13,
(1 << 24) / ca->mi.bucket_size)); (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: */ /* startup/shutdown: */
......
...@@ -160,20 +160,18 @@ static int bch2_check_lru_key(struct btree_trans *trans, ...@@ -160,20 +160,18 @@ static int bch2_check_lru_key(struct btree_trans *trans,
int bch2_check_lrus(struct bch_fs *c) int bch2_check_lrus(struct bch_fs *c)
{ {
struct btree_trans trans;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bpos last_flushed_pos = POS_MIN; struct bpos last_flushed_pos = POS_MIN;
int ret = 0; int ret = 0;
bch2_trans_init(&trans, c, 0, 0); ret = bch2_trans_run(c,
for_each_btree_key_commit(&trans, iter,
ret = for_each_btree_key_commit(&trans, iter,
BTREE_ID_lru, POS_MIN, BTREE_ITER_PREFETCH, k, BTREE_ID_lru, POS_MIN, BTREE_ITER_PREFETCH, k,
NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW,
bch2_check_lru_key(&trans, &iter, k, &last_flushed_pos)); bch2_check_lru_key(&trans, &iter, k, &last_flushed_pos)));
if (ret)
bch2_trans_exit(&trans); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -690,7 +690,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans, ...@@ -690,7 +690,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans,
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
if (ret) { 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; goto err;
} }
...@@ -701,7 +701,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans, ...@@ -701,7 +701,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans,
ret = bch2_btree_write_buffer_flush(trans); ret = bch2_btree_write_buffer_flush(trans);
if (ret) { 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; goto err;
} }
...@@ -904,7 +904,7 @@ static int bch2_move_btree(struct bch_fs *c, ...@@ -904,7 +904,7 @@ static int bch2_move_btree(struct bch_fs *c,
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) 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); 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) ...@@ -1029,6 +1029,8 @@ int bch2_scan_old_btree_nodes(struct bch_fs *c, struct bch_move_stats *stats)
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
} }
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
......
...@@ -621,10 +621,11 @@ int bch2_fs_quota_read(struct bch_fs *c) ...@@ -621,10 +621,11 @@ int bch2_fs_quota_read(struct bch_fs *c)
for_each_btree_key2(&trans, iter, BTREE_ID_inodes, for_each_btree_key2(&trans, iter, BTREE_ID_inodes,
POS_MIN, BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k, POS_MIN, BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k,
bch2_fs_quota_read_inode(&trans, &iter, 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); bch2_trans_exit(&trans);
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
......
...@@ -685,6 +685,9 @@ static int bch2_journal_replay(struct bch_fs *c, u64 start_seq, u64 end_seq) ...@@ -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"); bch2_journal_log_msg(c, "journal replay finished");
err: err:
kvfree(keys_sorted); kvfree(keys_sorted);
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1034,9 +1037,6 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c) ...@@ -1034,9 +1037,6 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c)
root_tree.k.p.offset = 1; root_tree.k.p.offset = 1;
root_tree.v.master_subvol = cpu_to_le32(1); root_tree.v.master_subvol = cpu_to_le32(1);
root_tree.v.root_snapshot = cpu_to_le32(U32_MAX); 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); bkey_snapshot_init(&root_snapshot.k_i);
root_snapshot.k.p.offset = U32_MAX; root_snapshot.k.p.offset = U32_MAX;
...@@ -1046,28 +1046,27 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c) ...@@ -1046,28 +1046,27 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c)
root_snapshot.v.tree = cpu_to_le32(1); root_snapshot.v.tree = cpu_to_le32(1);
SET_BCH_SNAPSHOT_SUBVOL(&root_snapshot.v, true); 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); bkey_subvolume_init(&root_volume.k_i);
root_volume.k.p.offset = BCACHEFS_ROOT_SUBVOL; root_volume.k.p.offset = BCACHEFS_ROOT_SUBVOL;
root_volume.v.flags = 0; root_volume.v.flags = 0;
root_volume.v.snapshot = cpu_to_le32(U32_MAX); root_volume.v.snapshot = cpu_to_le32(U32_MAX);
root_volume.v.inode = cpu_to_le64(BCACHEFS_ROOT_INO); root_volume.v.inode = cpu_to_le64(BCACHEFS_ROOT_INO);
ret = bch2_btree_insert(c, BTREE_ID_subvolumes, 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, &root_volume.k_i,
NULL, NULL, 0); NULL, NULL, 0);
if (ret) if (ret)
bch_err_fn(c, ret);
return ret; return ret;
return 0;
} }
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 btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
...@@ -1097,9 +1096,19 @@ static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans) ...@@ -1097,9 +1096,19 @@ static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans)
return ret; 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) int bch2_fs_recovery(struct bch_fs *c)
{ {
const char *err = "cannot allocate memory";
struct bch_sb_field_clean *clean = NULL; struct bch_sb_field_clean *clean = NULL;
struct jset *last_journal_entry = NULL; struct jset *last_journal_entry = NULL;
u64 last_seq, blacklist_seq, journal_seq; u64 last_seq, blacklist_seq, journal_seq;
...@@ -1137,12 +1146,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1137,12 +1146,6 @@ int bch2_fs_recovery(struct bch_fs *c)
goto err; 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->opts.nochanges) {
if (c->sb.version < bcachefs_metadata_required_upgrade_below) { if (c->sb.version < bcachefs_metadata_required_upgrade_below) {
bch_info(c, "version %s (%u) prior to %s (%u), upgrade and fsck required", bch_info(c, "version %s (%u) prior to %s (%u), upgrade and fsck required",
...@@ -1286,34 +1289,28 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1286,34 +1289,28 @@ int bch2_fs_recovery(struct bch_fs *c)
goto err; goto err;
bch_verbose(c, "starting alloc read"); bch_verbose(c, "starting alloc read");
err = "error reading allocation information";
down_read(&c->gc_lock); down_read(&c->gc_lock);
ret = c->sb.version < bcachefs_metadata_version_bucket_gens ret = c->sb.version < bcachefs_metadata_version_bucket_gens
? bch2_alloc_read(c) ? bch2_alloc_read(c)
: bch2_bucket_gens_read(c); : bch2_bucket_gens_read(c);
up_read(&c->gc_lock); up_read(&c->gc_lock);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "alloc read done"); bch_verbose(c, "alloc read done");
bch_verbose(c, "starting stripes_read"); bch_verbose(c, "starting stripes_read");
err = "error reading stripes";
ret = bch2_stripes_read(c); ret = bch2_stripes_read(c);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "stripes_read done"); bch_verbose(c, "stripes_read done");
if (c->sb.version < bcachefs_metadata_version_snapshot_2) { if (c->sb.version < bcachefs_metadata_version_snapshot_2) {
err = "error creating root snapshot node";
ret = bch2_fs_initialize_subvolumes(c); ret = bch2_fs_initialize_subvolumes(c);
if (ret) if (ret)
goto err; goto err;
} }
bch_verbose(c, "reading snapshots table"); bch_verbose(c, "reading snapshots table");
err = "error reading snapshots table";
ret = bch2_fs_snapshots_start(c); ret = bch2_fs_snapshots_start(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1323,7 +1320,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1323,7 +1320,6 @@ int bch2_fs_recovery(struct bch_fs *c)
bool metadata_only = c->opts.norecovery; bool metadata_only = c->opts.norecovery;
bch_info(c, "checking allocations"); bch_info(c, "checking allocations");
err = "error checking allocations";
ret = bch2_gc(c, true, metadata_only); ret = bch2_gc(c, true, metadata_only);
if (ret) if (ret)
goto err; goto err;
...@@ -1334,7 +1330,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1334,7 +1330,6 @@ int bch2_fs_recovery(struct bch_fs *c)
set_bit(BCH_FS_MAY_GO_RW, &c->flags); set_bit(BCH_FS_MAY_GO_RW, &c->flags);
bch_info(c, "starting journal replay, %zu keys", c->journal_keys.nr); 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); ret = bch2_journal_replay(c, last_seq, blacklist_seq - 1);
if (ret) if (ret)
goto err; goto err;
...@@ -1342,7 +1337,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1342,7 +1337,6 @@ int bch2_fs_recovery(struct bch_fs *c)
bch_info(c, "journal replay done"); bch_info(c, "journal replay done");
bch_info(c, "checking need_discard and freespace btrees"); bch_info(c, "checking need_discard and freespace btrees");
err = "error checking need_discard and freespace btrees";
ret = bch2_check_alloc_info(c); ret = bch2_check_alloc_info(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1351,7 +1345,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1351,7 +1345,6 @@ int bch2_fs_recovery(struct bch_fs *c)
set_bit(BCH_FS_CHECK_ALLOC_DONE, &c->flags); set_bit(BCH_FS_CHECK_ALLOC_DONE, &c->flags);
bch_info(c, "checking lrus"); bch_info(c, "checking lrus");
err = "error checking lrus";
ret = bch2_check_lrus(c); ret = bch2_check_lrus(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1359,21 +1352,18 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1359,21 +1352,18 @@ int bch2_fs_recovery(struct bch_fs *c)
set_bit(BCH_FS_CHECK_LRUS_DONE, &c->flags); set_bit(BCH_FS_CHECK_LRUS_DONE, &c->flags);
bch_info(c, "checking backpointers to alloc keys"); bch_info(c, "checking backpointers to alloc keys");
err = "error checking backpointers to alloc keys";
ret = bch2_check_btree_backpointers(c); ret = bch2_check_btree_backpointers(c);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "done checking backpointers to alloc keys"); bch_verbose(c, "done checking backpointers to alloc keys");
bch_info(c, "checking backpointers to extents"); bch_info(c, "checking backpointers to extents");
err = "error checking backpointers to extents";
ret = bch2_check_backpointers_to_extents(c); ret = bch2_check_backpointers_to_extents(c);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "done checking backpointers to extents"); bch_verbose(c, "done checking backpointers to extents");
bch_info(c, "checking extents to backpointers"); bch_info(c, "checking extents to backpointers");
err = "error checking extents to backpointers";
ret = bch2_check_extents_to_backpointers(c); ret = bch2_check_extents_to_backpointers(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1381,7 +1371,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1381,7 +1371,6 @@ int bch2_fs_recovery(struct bch_fs *c)
set_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags); set_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags);
bch_info(c, "checking alloc to lru refs"); bch_info(c, "checking alloc to lru refs");
err = "error checking alloc to lru refs";
ret = bch2_check_alloc_to_lru_refs(c); ret = bch2_check_alloc_to_lru_refs(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1401,7 +1390,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1401,7 +1390,6 @@ int bch2_fs_recovery(struct bch_fs *c)
set_bit(BCH_FS_MAY_GO_RW, &c->flags); set_bit(BCH_FS_MAY_GO_RW, &c->flags);
bch_verbose(c, "starting journal replay, %zu keys", c->journal_keys.nr); 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); ret = bch2_journal_replay(c, last_seq, blacklist_seq - 1);
if (ret) if (ret)
goto err; goto err;
...@@ -1409,7 +1397,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1409,7 +1397,6 @@ int bch2_fs_recovery(struct bch_fs *c)
bch_info(c, "journal replay done"); bch_info(c, "journal replay done");
} }
err = "error initializing freespace";
ret = bch2_fs_freespace_init(c); ret = bch2_fs_freespace_init(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1417,7 +1404,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1417,7 +1404,6 @@ int bch2_fs_recovery(struct bch_fs *c)
if (c->sb.version < bcachefs_metadata_version_bucket_gens && if (c->sb.version < bcachefs_metadata_version_bucket_gens &&
c->opts.version_upgrade) { c->opts.version_upgrade) {
bch_info(c, "initializing bucket_gens"); bch_info(c, "initializing bucket_gens");
err = "error initializing bucket gens";
ret = bch2_bucket_gens_init(c); ret = bch2_bucket_gens_init(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1425,24 +1411,18 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1425,24 +1411,18 @@ int bch2_fs_recovery(struct bch_fs *c)
} }
if (c->sb.version < bcachefs_metadata_version_snapshot_2) { if (c->sb.version < bcachefs_metadata_version_snapshot_2) {
/* set bi_subvol on root inode */ ret = bch2_fs_upgrade_for_subvolumes(c);
err = "error upgrade root inode for subvolumes";
ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_LAZY_RW,
bch2_fs_upgrade_for_subvolumes(&trans));
if (ret) if (ret)
goto err; goto err;
} }
if (c->opts.fsck) { if (c->opts.fsck) {
bch_info(c, "starting fsck");
err = "error in fsck";
ret = bch2_fsck_full(c); ret = bch2_fsck_full(c);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "fsck done"); bch_verbose(c, "fsck done");
} else if (!c->sb.clean) { } else if (!c->sb.clean) {
bch_verbose(c, "checking for deleted inodes"); bch_verbose(c, "checking for deleted inodes");
err = "error in recovery";
ret = bch2_fsck_walk_inodes_only(c); ret = bch2_fsck_walk_inodes_only(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1489,11 +1469,8 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1489,11 +1469,8 @@ int bch2_fs_recovery(struct bch_fs *c)
bch2_move_stats_init(&stats, "recovery"); bch2_move_stats_init(&stats, "recovery");
bch_info(c, "scanning for old btree nodes"); bch_info(c, "scanning for old btree nodes");
ret = bch2_fs_read_write(c); ret = bch2_fs_read_write(c) ?:
if (ret) bch2_scan_old_btree_nodes(c, &stats);
goto err;
ret = bch2_scan_old_btree_nodes(c, &stats);
if (ret) if (ret)
goto err; goto err;
bch_info(c, "scanning for old btree nodes done"); bch_info(c, "scanning for old btree nodes done");
...@@ -1521,7 +1498,7 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1521,7 +1498,7 @@ int bch2_fs_recovery(struct bch_fs *c)
} }
if (ret) if (ret)
bch_err(c, "Error in recovery: %s (%s)", err, bch2_err_str(ret)); bch_err_fn(c, ret);
else else
bch_verbose(c, "ret %s", bch2_err_str(ret)); bch_verbose(c, "ret %s", bch2_err_str(ret));
return ret; return ret;
...@@ -1536,7 +1513,6 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1536,7 +1513,6 @@ int bch2_fs_initialize(struct bch_fs *c)
struct bch_inode_unpacked root_inode, lostfound_inode; struct bch_inode_unpacked root_inode, lostfound_inode;
struct bkey_inode_buf packed_inode; struct bkey_inode_buf packed_inode;
struct qstr lostfound = QSTR("lost+found"); struct qstr lostfound = QSTR("lost+found");
const char *err = "cannot allocate memory";
struct bch_dev *ca; struct bch_dev *ca;
unsigned i; unsigned i;
int ret; int ret;
...@@ -1570,7 +1546,6 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1570,7 +1546,6 @@ int bch2_fs_initialize(struct bch_fs *c)
for_each_online_member(ca, c, i) for_each_online_member(ca, c, i)
bch2_dev_usage_init(ca); bch2_dev_usage_init(ca);
err = "unable to allocate journal buckets";
for_each_online_member(ca, c, i) { for_each_online_member(ca, c, i) {
ret = bch2_dev_journal_alloc(ca); ret = bch2_dev_journal_alloc(ca);
if (ret) { if (ret) {
...@@ -1586,7 +1561,6 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1586,7 +1561,6 @@ int bch2_fs_initialize(struct bch_fs *c)
bch2_fs_journal_start(&c->journal, 1); bch2_fs_journal_start(&c->journal, 1);
bch2_journal_set_replay_done(&c->journal); bch2_journal_set_replay_done(&c->journal);
err = "error going read-write";
ret = bch2_fs_read_write_early(c); ret = bch2_fs_read_write_early(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1596,7 +1570,6 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1596,7 +1570,6 @@ int bch2_fs_initialize(struct bch_fs *c)
* btree updates * btree updates
*/ */
bch_verbose(c, "marking superblocks"); bch_verbose(c, "marking superblocks");
err = "error marking superblock and journal";
for_each_member_device(ca, c, i) { for_each_member_device(ca, c, i) {
ret = bch2_trans_mark_dev_sb(c, ca); ret = bch2_trans_mark_dev_sb(c, ca);
if (ret) { if (ret) {
...@@ -1607,19 +1580,15 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1607,19 +1580,15 @@ int bch2_fs_initialize(struct bch_fs *c)
ca->new_fs_bucket_idx = 0; ca->new_fs_bucket_idx = 0;
} }
bch_verbose(c, "initializing freespace");
err = "error initializing freespace";
ret = bch2_fs_freespace_init(c); ret = bch2_fs_freespace_init(c);
if (ret) if (ret)
goto err; goto err;
err = "error creating root snapshot node";
ret = bch2_fs_initialize_subvolumes(c); ret = bch2_fs_initialize_subvolumes(c);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "reading snapshots table"); bch_verbose(c, "reading snapshots table");
err = "error reading snapshots table";
ret = bch2_fs_snapshots_start(c); ret = bch2_fs_snapshots_start(c);
if (ret) if (ret)
goto err; goto err;
...@@ -1631,16 +1600,16 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1631,16 +1600,16 @@ int bch2_fs_initialize(struct bch_fs *c)
bch2_inode_pack(&packed_inode, &root_inode); bch2_inode_pack(&packed_inode, &root_inode);
packed_inode.inode.k.p.snapshot = U32_MAX; packed_inode.inode.k.p.snapshot = U32_MAX;
err = "error creating root directory";
ret = bch2_btree_insert(c, BTREE_ID_inodes, ret = bch2_btree_insert(c, BTREE_ID_inodes,
&packed_inode.inode.k_i, &packed_inode.inode.k_i,
NULL, NULL, 0); NULL, NULL, 0);
if (ret) if (ret) {
bch_err_msg(c, ret, "creating root directory");
goto err; goto err;
}
bch2_inode_init_early(c, &lostfound_inode); bch2_inode_init_early(c, &lostfound_inode);
err = "error creating lost+found";
ret = bch2_trans_do(c, NULL, NULL, 0, ret = bch2_trans_do(c, NULL, NULL, 0,
bch2_create_trans(&trans, bch2_create_trans(&trans,
BCACHEFS_ROOT_SUBVOL_INUM, BCACHEFS_ROOT_SUBVOL_INUM,
...@@ -1649,7 +1618,7 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1649,7 +1618,7 @@ int bch2_fs_initialize(struct bch_fs *c)
0, 0, S_IFDIR|0700, 0, 0, 0, S_IFDIR|0700, 0,
NULL, NULL, (subvol_inum) { 0 }, 0)); NULL, NULL, (subvol_inum) { 0 }, 0));
if (ret) { if (ret) {
bch_err(c, "error creating lost+found"); bch_err_msg(c, ret, "creating lost+found");
goto err; goto err;
} }
...@@ -1659,10 +1628,11 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1659,10 +1628,11 @@ int bch2_fs_initialize(struct bch_fs *c)
goto err; goto err;
} }
err = "error writing first journal entry";
ret = bch2_journal_flush(&c->journal); ret = bch2_journal_flush(&c->journal);
if (ret) if (ret) {
bch_err_msg(c, ret, "writing first journal entry");
goto err; goto err;
}
mutex_lock(&c->sb_lock); mutex_lock(&c->sb_lock);
SET_BCH_SB_INITIALIZED(c->disk_sb.sb, true); SET_BCH_SB_INITIALIZED(c->disk_sb.sb, true);
...@@ -1673,6 +1643,6 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1673,6 +1643,6 @@ int bch2_fs_initialize(struct bch_fs *c)
return 0; return 0;
err: err:
pr_err("Error initializing new filesystem: %s (%s)", err, bch2_err_str(ret)); bch_err_fn(ca, ret);
return ret; return ret;
} }
...@@ -623,7 +623,7 @@ int bch2_fs_check_snapshots(struct bch_fs *c) ...@@ -623,7 +623,7 @@ int bch2_fs_check_snapshots(struct bch_fs *c)
NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL, NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL,
check_snapshot(&trans, &iter, k))); check_snapshot(&trans, &iter, k)));
if (ret) if (ret)
bch_err(c, "%s: error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -702,8 +702,7 @@ int bch2_fs_check_subvols(struct bch_fs *c) ...@@ -702,8 +702,7 @@ int bch2_fs_check_subvols(struct bch_fs *c)
NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL, NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL,
check_subvol(&trans, &iter, k))); check_subvol(&trans, &iter, k)));
if (ret) if (ret)
bch_err(c, "%s: error %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -724,7 +723,7 @@ int bch2_fs_snapshots_start(struct bch_fs *c) ...@@ -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_mark_snapshot(&trans, BTREE_ID_snapshots, 0, bkey_s_c_null, k, 0) ?:
bch2_snapshot_set_equiv(&trans, k))); bch2_snapshot_set_equiv(&trans, k)));
if (ret) if (ret)
bch_err(c, "error starting snapshots: %s", bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -1123,6 +1122,8 @@ int bch2_delete_dead_snapshots(struct bch_fs *c) ...@@ -1123,6 +1122,8 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
err: err:
darray_exit(&deleted); darray_exit(&deleted);
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret)
bch_err_fn(c, ret);
return ret; return ret;
} }
......
...@@ -47,7 +47,7 @@ static int test_delete(struct bch_fs *c, u64 nr) ...@@ -47,7 +47,7 @@ static int test_delete(struct bch_fs *c, u64 nr)
bch2_btree_iter_traverse(&iter) ?: bch2_btree_iter_traverse(&iter) ?:
bch2_trans_update(&trans, &iter, &k.k_i, 0)); bch2_trans_update(&trans, &iter, &k.k_i, 0));
if (ret) { if (ret) {
bch_err(c, "%s(): update error in: %s", __func__, bch2_err_str(ret)); bch_err_msg(c, ret, "update error");
goto err; goto err;
} }
...@@ -56,7 +56,7 @@ static int test_delete(struct bch_fs *c, u64 nr) ...@@ -56,7 +56,7 @@ static int test_delete(struct bch_fs *c, u64 nr)
bch2_btree_iter_traverse(&iter) ?: bch2_btree_iter_traverse(&iter) ?:
bch2_btree_delete_at(&trans, &iter, 0)); bch2_btree_delete_at(&trans, &iter, 0));
if (ret) { 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; goto err;
} }
...@@ -65,7 +65,7 @@ static int test_delete(struct bch_fs *c, u64 nr) ...@@ -65,7 +65,7 @@ static int test_delete(struct bch_fs *c, u64 nr)
bch2_btree_iter_traverse(&iter) ?: bch2_btree_iter_traverse(&iter) ?:
bch2_btree_delete_at(&trans, &iter, 0)); bch2_btree_delete_at(&trans, &iter, 0));
if (ret) { 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; goto err;
} }
err: err:
...@@ -93,7 +93,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr) ...@@ -93,7 +93,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr)
bch2_btree_iter_traverse(&iter) ?: bch2_btree_iter_traverse(&iter) ?:
bch2_trans_update(&trans, &iter, &k.k_i, 0)); bch2_trans_update(&trans, &iter, &k.k_i, 0));
if (ret) { if (ret) {
bch_err(c, "%s(): update error: %s", __func__, bch2_err_str(ret)); bch_err_msg(c, ret, "update error");
goto err; goto err;
} }
...@@ -104,7 +104,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr) ...@@ -104,7 +104,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr)
bch2_btree_iter_traverse(&iter) ?: bch2_btree_iter_traverse(&iter) ?:
bch2_btree_delete_at(&trans, &iter, 0)); bch2_btree_delete_at(&trans, &iter, 0));
if (ret) { if (ret) {
bch_err(c, "%s(): delete error: %s", __func__, bch2_err_str(ret)); bch_err_msg(c, ret, "delete error");
goto err; goto err;
} }
err: err:
...@@ -137,7 +137,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) ...@@ -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, ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i,
NULL, NULL, 0); NULL, NULL, 0);
if (ret) { if (ret) {
bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); bch_err_msg(c, ret, "insert error");
goto err; goto err;
} }
} }
...@@ -153,7 +153,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) ...@@ -153,7 +153,7 @@ static int test_iterate(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret) { 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; goto err;
} }
...@@ -168,7 +168,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) ...@@ -168,7 +168,7 @@ static int test_iterate(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret) { 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; goto err;
} }
...@@ -204,7 +204,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ...@@ -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, ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i,
NULL, NULL, 0); NULL, NULL, 0);
if (ret) { if (ret) {
bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); bch_err_msg(c, ret, "insert error");
goto err; goto err;
} }
} }
...@@ -221,7 +221,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ...@@ -221,7 +221,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret) { 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; goto err;
} }
...@@ -237,7 +237,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ...@@ -237,7 +237,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret) { 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; goto err;
} }
...@@ -272,7 +272,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ...@@ -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, ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i,
NULL, NULL, 0); NULL, NULL, 0);
if (ret) { if (ret) {
bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); bch_err_msg(c, ret, "insert error");
goto err; goto err;
} }
} }
...@@ -289,7 +289,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ...@@ -289,7 +289,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret) { 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; goto err;
} }
...@@ -312,7 +312,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ...@@ -312,7 +312,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret < 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; goto err;
} }
ret = 0; ret = 0;
...@@ -346,7 +346,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ...@@ -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, ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i,
NULL, NULL, 0); NULL, NULL, 0);
if (ret) { if (ret) {
bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); bch_err_msg(c, ret, "insert error");
goto err; goto err;
} }
} }
...@@ -364,7 +364,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ...@@ -364,7 +364,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret) { 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; goto err;
} }
...@@ -387,7 +387,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ...@@ -387,7 +387,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr)
0; 0;
})); }));
if (ret) { 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; goto err;
} }
ret = 0; ret = 0;
...@@ -461,7 +461,7 @@ static int insert_test_extent(struct bch_fs *c, ...@@ -461,7 +461,7 @@ static int insert_test_extent(struct bch_fs *c,
ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i,
NULL, NULL, 0); NULL, NULL, 0);
if (ret) if (ret)
bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); bch_err_fn(c, ret);
return ret; return ret;
} }
...@@ -560,7 +560,7 @@ static int test_snapshots(struct bch_fs *c, u64 nr) ...@@ -560,7 +560,7 @@ static int test_snapshots(struct bch_fs *c, u64 nr)
ret = test_snapshot_filter(c, snapids[0], snapids[1]); ret = test_snapshot_filter(c, snapids[0], snapids[1]);
if (ret) { 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; return ret;
} }
...@@ -674,7 +674,7 @@ static int rand_mixed_trans(struct btree_trans *trans, ...@@ -674,7 +674,7 @@ static int rand_mixed_trans(struct btree_trans *trans,
k = bch2_btree_iter_peek(iter); k = bch2_btree_iter_peek(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) 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) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment