From 5e215654da7e97a6395de6e7592fbaa426697897 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 26 Sep 2023 17:12:51 -0400 Subject: [PATCH] Update bcachefs sources to a1b6677dca57 bcachefs: Fix looping around bch2_propagate_key_to_snapshot_leaves() --- .bcachefs_revision | 2 +- libbcachefs/bcachefs.h | 12 ++++- libbcachefs/fsck.c | 104 +++++++++++++---------------------------- libbcachefs/inode.c | 4 +- libbcachefs/snapshot.c | 10 +++- libbcachefs/tests.c | 97 +++++++++++++++----------------------- 6 files changed, 89 insertions(+), 140 deletions(-) diff --git a/.bcachefs_revision b/.bcachefs_revision index f8f0e82..a507788 100644 --- a/.bcachefs_revision +++ b/.bcachefs_revision @@ -1 +1 @@ -1336a995cbc3a575002ed517c4d27c847ecb6496 +a1b6677dca574a8bf904d9eea2b108474dc378d1 diff --git a/libbcachefs/bcachefs.h b/libbcachefs/bcachefs.h index 9ae8225..ef5c078 100644 --- a/libbcachefs/bcachefs.h +++ b/libbcachefs/bcachefs.h @@ -293,9 +293,17 @@ do { \ 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)) +do { \ + if (_ret && !bch2_err_matches(_ret, BCH_ERR_transaction_restart))\ + bch_err(_c, "%s(): error %s", __func__, bch2_err_str(_ret));\ +} while (0) + #define bch_err_msg(_c, _ret, _msg, ...) \ - bch_err(_c, "%s(): error " _msg " %s", __func__, ##__VA_ARGS__, bch2_err_str(_ret)) +do { \ + if (_ret && !bch2_err_matches(_ret, BCH_ERR_transaction_restart))\ + bch_err(_c, "%s(): error " _msg " %s", __func__, \ + ##__VA_ARGS__, bch2_err_str(_ret)); \ +} while (0) #define bch_verbose(c, fmt, ...) \ do { \ diff --git a/libbcachefs/fsck.c b/libbcachefs/fsck.c index 2ef14ad..b8f9e74 100644 --- a/libbcachefs/fsck.c +++ b/libbcachefs/fsck.c @@ -126,8 +126,7 @@ static int lookup_first_inode(struct btree_trans *trans, u64 inode_nr, ret = bch2_inode_unpack(k, inode); err: - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(trans->c, ret, "fetching inode %llu", inode_nr); + bch_err_msg(trans->c, ret, "fetching inode %llu", inode_nr); bch2_trans_iter_exit(trans, &iter); return ret; } @@ -152,8 +151,7 @@ static int __lookup_inode(struct btree_trans *trans, u64 inode_nr, if (!ret) *snapshot = iter.pos.snapshot; err: - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(trans->c, ret, "fetching inode %llu:%u", inode_nr, *snapshot); + bch_err_msg(trans->c, ret, "fetching inode %llu:%u", inode_nr, *snapshot); bch2_trans_iter_exit(trans, &iter); return ret; } @@ -238,8 +236,7 @@ static int __remove_dirent(struct btree_trans *trans, struct bpos pos) BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE); bch2_trans_iter_exit(trans, &iter); err: - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -274,8 +271,7 @@ static int lookup_lostfound(struct btree_trans *trans, u32 subvol, goto create_lostfound; } - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_fn(c, ret); + bch_err_fn(c, ret); if (ret) return ret; @@ -297,8 +293,7 @@ create_lostfound: lostfound, &lostfound_str, 0, 0, S_IFDIR|0700, 0, NULL, NULL, (subvol_inum) { }, 0); - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(c, ret, "creating lost+found"); + bch_err_msg(c, ret, "creating lost+found"); return ret; } @@ -361,11 +356,7 @@ static int reattach_inode(struct btree_trans *trans, BTREE_INSERT_LAZY_RW| BTREE_INSERT_NOFAIL, __reattach_inode(trans, inode, inode_snapshot)); - if (ret) { - bch_err_msg(trans->c, ret, "reattaching inode %llu", inode->bi_inum); - return ret; - } - + bch_err_msg(trans->c, ret, "reattaching inode %llu", inode->bi_inum); return ret; } @@ -821,8 +812,7 @@ bad_hash: (printbuf_reset(&buf), bch2_bkey_val_to_text(&buf, c, hash_k), buf.buf))) { ret = hash_redo_key(trans, desc, hash_info, k_iter, hash_k); - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_fn(c, ret); + bch_err_fn(c, ret); if (ret) return ret; ret = -BCH_ERR_transaction_restart_nested; @@ -885,11 +875,9 @@ static int check_inode(struct btree_trans *trans, u.bi_flags &= ~BCH_INODE_I_SIZE_DIRTY|BCH_INODE_UNLINKED; ret = __write_inode(trans, &u, iter->pos.snapshot); - if (ret) { - if (!bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(c, ret, "in fsck updating inode"); + bch_err_msg(c, ret, "in fsck updating inode"); + if (ret) return ret; - } if (!bpos_eq(new_min_pos, POS_MIN)) bch2_btree_iter_set_pos(iter, bpos_predecessor(new_min_pos)); @@ -904,8 +892,7 @@ static int check_inode(struct btree_trans *trans, bch2_fs_lazy_rw(c); ret = bch2_inode_rm_snapshot(trans, u.bi_inum, iter->pos.snapshot); - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(c, ret, "in fsck deleting inode"); + bch_err_msg(c, ret, "in fsck deleting inode"); return ret; } @@ -927,8 +914,7 @@ static int check_inode(struct btree_trans *trans, iter->pos.snapshot), POS(u.bi_inum, U64_MAX), 0, NULL); - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(c, ret, "in fsck truncating inode"); + bch_err_msg(c, ret, "in fsck truncating inode"); if (ret) return ret; @@ -953,7 +939,7 @@ static int check_inode(struct btree_trans *trans, sectors = bch2_count_inode_sectors(trans, u.bi_inum, iter->pos.snapshot); if (sectors < 0) { - bch_err_msg(c, sectors, "fsck recounting inode sectors"); + bch_err_msg(c, sectors, "in fsck recounting inode sectors"); return sectors; } @@ -971,15 +957,13 @@ static int check_inode(struct btree_trans *trans, if (do_update) { ret = __write_inode(trans, &u, iter->pos.snapshot); - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(c, ret, "in fsck updating inode"); + bch_err_msg(c, ret, "in fsck updating inode"); if (ret) return ret; } err: fsck_err: - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1004,8 +988,7 @@ int bch2_check_inodes(struct bch_fs *c) snapshots_seen_exit(&s); bch2_trans_put(trans); - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1084,8 +1067,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) } } fsck_err: - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret ?: trans_was_restarted(trans, restart_count); } @@ -1419,9 +1401,7 @@ out: err: fsck_err: printbuf_exit(&buf); - - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; delete: ret = bch2_btree_delete_at(trans, iter, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE); @@ -1462,8 +1442,7 @@ int bch2_check_extents(struct bch_fs *c) snapshots_seen_exit(&s); bch2_trans_put(trans); - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1501,8 +1480,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w) } } fsck_err: - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret ?: trans_was_restarted(trans, restart_count); } @@ -1619,9 +1597,7 @@ out: err: fsck_err: printbuf_exit(&buf); - - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1785,9 +1761,7 @@ out: err: fsck_err: printbuf_exit(&buf); - - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1820,9 +1794,7 @@ int bch2_check_dirents(struct bch_fs *c) snapshots_seen_exit(&s); inode_walker_exit(&dir); inode_walker_exit(&target); - - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1858,8 +1830,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_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1882,8 +1853,7 @@ int bch2_check_xattrs(struct bch_fs *c) NULL, NULL, BTREE_INSERT_LAZY_RW|BTREE_INSERT_NOFAIL, check_xattr(trans, &iter, k, &hash_info, &inode))); - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -1915,10 +1885,9 @@ static int check_root_trans(struct btree_trans *trans) BTREE_INSERT_LAZY_RW, bch2_btree_insert_trans(trans, BTREE_ID_subvolumes, &root_subvol.k_i, 0)); - if (ret) { - bch_err_msg(c, ret, "writing root subvol"); + bch_err_msg(c, ret, "writing root subvol"); + if (ret) goto err; - } } @@ -1934,8 +1903,7 @@ static int check_root_trans(struct btree_trans *trans) root_inode.bi_inum = inum; ret = __write_inode(trans, &root_inode, snapshot); - if (ret) - bch_err_msg(c, ret, "writing root inode"); + bch_err_msg(c, ret, "writing root inode"); } err: fsck_err: @@ -1951,9 +1919,7 @@ int bch2_check_root(struct bch_fs *c) BTREE_INSERT_NOFAIL| BTREE_INSERT_LAZY_RW, check_root_trans(trans)); - - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -2090,8 +2056,7 @@ static int check_path(struct btree_trans *trans, } } fsck_err: - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -2133,9 +2098,7 @@ int bch2_check_directory_structure(struct bch_fs *c) bch2_trans_iter_exit(trans, &iter); bch2_trans_put(trans); darray_exit(&path); - - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -2402,9 +2365,7 @@ int bch2_check_nlinks(struct bch_fs *c) } while (next_iter_range_start != U64_MAX); kvfree(links.d); - - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -2451,7 +2412,6 @@ int bch2_fix_reflink_p(struct bch_fs *c) BTREE_ITER_ALL_SNAPSHOTS, k, NULL, NULL, BTREE_INSERT_NOFAIL|BTREE_INSERT_LAZY_RW, fix_reflink_p_key(trans, &iter, k))); - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } diff --git a/libbcachefs/inode.c b/libbcachefs/inode.c index 8bfd99c..4a695a8 100644 --- a/libbcachefs/inode.c +++ b/libbcachefs/inode.c @@ -357,9 +357,7 @@ int bch2_inode_peek(struct btree_trans *trans, subvol_inum inum, unsigned flags) { int ret = bch2_inode_peek_nowarn(trans, iter, inode, inum, flags); - - if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err_msg(trans->c, ret, "looking up inum %u:%llu:", inum.subvol, inum.inum); + bch_err_msg(trans->c, ret, "looking up inum %u:%llu:", inum.subvol, inum.inum); return ret; } diff --git a/libbcachefs/snapshot.c b/libbcachefs/snapshot.c index cdf9eda..3ecc17b 100644 --- a/libbcachefs/snapshot.c +++ b/libbcachefs/snapshot.c @@ -1636,9 +1636,15 @@ int bch2_propagate_key_to_snapshot_leaves(struct btree_trans *trans, if (!bch2_snapshot_is_ancestor(c, id, k.k->p.snapshot) || !bch2_snapshot_is_leaf(c, id)) continue; +again: + ret = btree_trans_too_many_iters(trans) ?: + bch2_propagate_key_to_snapshot_leaf(trans, btree, k, id, new_min_pos) ?: + bch2_trans_commit(trans, NULL, NULL, 0); + if (ret && bch2_err_matches(ret, BCH_ERR_transaction_restart)) { + bch2_trans_begin(trans); + goto again; + } - ret = commit_do(trans, NULL, NULL, 0, - bch2_propagate_key_to_snapshot_leaf(trans, btree, k, id, new_min_pos)); if (ret) break; } diff --git a/libbcachefs/tests.c b/libbcachefs/tests.c index c907b3e..2fc9e60 100644 --- a/libbcachefs/tests.c +++ b/libbcachefs/tests.c @@ -45,28 +45,25 @@ static int test_delete(struct bch_fs *c, u64 nr) ret = commit_do(trans, NULL, NULL, 0, bch2_btree_iter_traverse(&iter) ?: bch2_trans_update(trans, &iter, &k.k_i, 0)); - if (ret) { - bch_err_msg(c, ret, "update error"); + bch_err_msg(c, ret, "update error"); + if (ret) goto err; - } pr_info("deleting once"); ret = commit_do(trans, NULL, NULL, 0, bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(trans, &iter, 0)); - if (ret) { - bch_err_msg(c, ret, "delete error (first)"); + bch_err_msg(c, ret, "delete error (first)"); + if (ret) goto err; - } pr_info("deleting twice"); ret = commit_do(trans, NULL, NULL, 0, bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(trans, &iter, 0)); - if (ret) { - bch_err_msg(c, ret, "delete error (second)"); + bch_err_msg(c, ret, "delete error (second)"); + if (ret) goto err; - } err: bch2_trans_iter_exit(trans, &iter); bch2_trans_put(trans); @@ -89,10 +86,9 @@ static int test_delete_written(struct bch_fs *c, u64 nr) ret = commit_do(trans, NULL, NULL, 0, bch2_btree_iter_traverse(&iter) ?: bch2_trans_update(trans, &iter, &k.k_i, 0)); - if (ret) { - bch_err_msg(c, ret, "update error"); + bch_err_msg(c, ret, "update error"); + if (ret) goto err; - } bch2_trans_unlock(trans); bch2_journal_flush_all_pins(&c->journal); @@ -100,10 +96,9 @@ static int test_delete_written(struct bch_fs *c, u64 nr) ret = commit_do(trans, NULL, NULL, 0, bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(trans, &iter, 0)); - if (ret) { - bch_err_msg(c, ret, "delete error"); + bch_err_msg(c, ret, "delete error"); + if (ret) goto err; - } err: bch2_trans_iter_exit(trans, &iter); bch2_trans_put(trans); @@ -130,10 +125,9 @@ static int test_iterate(struct bch_fs *c, u64 nr) ck.k.p.snapshot = U32_MAX; ret = bch2_btree_insert(c, BTREE_ID_xattrs, &ck.k_i, NULL, 0); - if (ret) { - bch_err_msg(c, ret, "insert error"); + bch_err_msg(c, ret, "insert error"); + if (ret) goto err; - } } pr_info("iterating forwards"); @@ -146,10 +140,9 @@ static int test_iterate(struct bch_fs *c, u64 nr) BUG_ON(k.k->p.offset != i++); 0; })); - if (ret) { - bch_err_msg(c, ret, "error iterating forwards"); + bch_err_msg(c, ret, "error iterating forwards"); + if (ret) goto err; - } BUG_ON(i != nr); @@ -161,10 +154,9 @@ static int test_iterate(struct bch_fs *c, u64 nr) BUG_ON(k.k->p.offset != --i); 0; })); - if (ret) { - bch_err_msg(c, ret, "error iterating backwards"); + bch_err_msg(c, ret, "error iterating backwards"); + if (ret) goto err; - } BUG_ON(i); err: @@ -194,10 +186,9 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ck.k.size = 8; ret = bch2_btree_insert(c, BTREE_ID_extents, &ck.k_i, NULL, 0); - if (ret) { - bch_err_msg(c, ret, "insert error"); + bch_err_msg(c, ret, "insert error"); + if (ret) goto err; - } } pr_info("iterating forwards"); @@ -211,10 +202,9 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) i = k.k->p.offset; 0; })); - if (ret) { - bch_err_msg(c, ret, "error iterating forwards"); + bch_err_msg(c, ret, "error iterating forwards"); + if (ret) goto err; - } BUG_ON(i != nr); @@ -227,10 +217,9 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) i = bkey_start_offset(k.k); 0; })); - if (ret) { - bch_err_msg(c, ret, "error iterating backwards"); + bch_err_msg(c, ret, "error iterating backwards"); + if (ret) goto err; - } BUG_ON(i); err: @@ -259,10 +248,9 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ck.k.p.snapshot = U32_MAX; ret = bch2_btree_insert(c, BTREE_ID_xattrs, &ck.k_i, NULL, 0); - if (ret) { - bch_err_msg(c, ret, "insert error"); + bch_err_msg(c, ret, "insert error"); + if (ret) goto err; - } } pr_info("iterating forwards"); @@ -276,10 +264,9 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) i += 2; 0; })); - if (ret) { - bch_err_msg(c, ret, "error iterating forwards"); + bch_err_msg(c, ret, "error iterating forwards"); + if (ret) goto err; - } BUG_ON(i != nr * 2); @@ -330,10 +317,9 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ck.k.size = 8; ret = bch2_btree_insert(c, BTREE_ID_extents, &ck.k_i, NULL, 0); - if (ret) { - bch_err_msg(c, ret, "insert error"); + bch_err_msg(c, ret, "insert error"); + if (ret) goto err; - } } pr_info("iterating forwards"); @@ -348,10 +334,9 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) i += 16; 0; })); - if (ret) { - bch_err_msg(c, ret, "error iterating forwards"); + bch_err_msg(c, ret, "error iterating forwards"); + if (ret) goto err; - } BUG_ON(i != nr); @@ -371,10 +356,9 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) i = k.k->p.offset; 0; })); - if (ret) { - bch_err_msg(c, ret, "error iterating forwards by slots"); + bch_err_msg(c, ret, "error iterating forwards by slots"); + if (ret) goto err; - } ret = 0; err: bch2_trans_put(trans); @@ -442,8 +426,7 @@ static int insert_test_extent(struct bch_fs *c, k.k_i.k.version.lo = test_version++; ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, NULL, 0); - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -499,8 +482,7 @@ static int insert_test_overlapping_extent(struct bch_fs *c, u64 inum, u64 start, ret = bch2_trans_do(c, NULL, NULL, 0, bch2_btree_insert_nonextent(trans, BTREE_ID_extents, &k.k_i, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE)); - if (ret) - bch_err_fn(c, ret); + bch_err_fn(c, ret); return ret; } @@ -569,12 +551,8 @@ static int test_snapshots(struct bch_fs *c, u64 nr) swap(snapids[0], snapids[1]); ret = test_snapshot_filter(c, snapids[0], snapids[1]); - if (ret) { - bch_err_msg(c, ret, "from test_snapshot_filter"); - return ret; - } - - return 0; + bch_err_msg(c, ret, "from test_snapshot_filter"); + return ret; } /* perf tests */ @@ -678,8 +656,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_msg(trans->c, ret, "lookup error"); + bch_err_msg(trans->c, ret, "lookup error"); if (ret) return ret; -- 2.39.2