From 94a3e1a6c1bd441b58972ee0216593fc0b09ee75 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 5 Dec 2021 00:30:49 -0500 Subject: [PATCH] bcachefs: bch2_trans_update() is now __must_check With snapshots, bch2_trans_update() has to check if we need a whitout, which can cause a transaction restart, so this is important now. Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_update.h | 4 ++-- fs/bcachefs/btree_update_leaf.c | 4 ++-- fs/bcachefs/buckets.c | 16 ++++++++++++---- fs/bcachefs/dirent.c | 8 ++++++-- fs/bcachefs/subvolume.c | 21 +++++++++++++-------- fs/bcachefs/tests.c | 4 ++-- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/fs/bcachefs/btree_update.h b/fs/bcachefs/btree_update.h index 4c1a1b617bf1..a61b64fc0859 100644 --- a/fs/bcachefs/btree_update.h +++ b/fs/bcachefs/btree_update.h @@ -73,8 +73,8 @@ int bch2_btree_node_update_key(struct btree_trans *, struct btree_iter *, int bch2_btree_node_update_key_get_iter(struct btree_trans *, struct btree *, struct bkey_i *, bool); -int bch2_trans_update(struct btree_trans *, struct btree_iter *, - struct bkey_i *, enum btree_update_flags); +int __must_check bch2_trans_update(struct btree_trans *, struct btree_iter *, + struct bkey_i *, enum btree_update_flags); void bch2_trans_commit_hook(struct btree_trans *, struct btree_trans_commit_hook *); int __bch2_trans_commit(struct btree_trans *); diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c index 65facdd1536f..1079daef4e86 100644 --- a/fs/bcachefs/btree_update_leaf.c +++ b/fs/bcachefs/btree_update_leaf.c @@ -1312,8 +1312,8 @@ static int need_whiteout_for_snapshot(struct btree_trans *trans, return ret; } -int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, - struct bkey_i *k, enum btree_update_flags flags) +int __must_check bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, + struct bkey_i *k, enum btree_update_flags flags) { struct btree_insert_entry *i, n; diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 66f072905173..ef018c27d276 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -1549,7 +1549,9 @@ static int bch2_trans_mark_pointer(struct btree_trans *trans, goto out; bch2_alloc_pack(c, a, u); - bch2_trans_update(trans, &iter, &a->k, 0); + ret = bch2_trans_update(trans, &iter, &a->k, 0); + if (ret) + goto out; out: bch2_trans_iter_exit(trans, &iter); return ret; @@ -1600,7 +1602,9 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans, stripe_blockcount_set(&s->v, p.ec.block, stripe_blockcount_get(&s->v, p.ec.block) + sectors); - bch2_trans_update(trans, &iter, &s->k_i, 0); + ret = bch2_trans_update(trans, &iter, &s->k_i, 0); + if (ret) + goto err; bch2_bkey_to_replicas(&r.e, bkey_i_to_s_c(&s->k_i)); r.e.data_type = data_type; @@ -1738,7 +1742,9 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, u.data_type = !deleting ? data_type : 0; bch2_alloc_pack(c, a, u); - bch2_trans_update(trans, &iter, &a->k, 0); + ret = bch2_trans_update(trans, &iter, &a->k, 0); + if (ret) + goto err; err: bch2_trans_iter_exit(trans, &iter); return ret; @@ -2017,7 +2023,9 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans, u.dirty_sectors = sectors; bch2_alloc_pack(c, a, u); - bch2_trans_update(trans, &iter, &a->k, 0); + ret = bch2_trans_update(trans, &iter, &a->k, 0); + if (ret) + goto out; out: bch2_trans_iter_exit(trans, &iter); return ret; diff --git a/fs/bcachefs/dirent.c b/fs/bcachefs/dirent.c index fe4a85a6a8cb..a165d08c3668 100644 --- a/fs/bcachefs/dirent.c +++ b/fs/bcachefs/dirent.c @@ -367,7 +367,9 @@ int bch2_dirent_rename(struct btree_trans *trans, } } - bch2_trans_update(trans, &dst_iter, &new_dst->k_i, 0); + ret = bch2_trans_update(trans, &dst_iter, &new_dst->k_i, 0); + if (ret) + goto out; out_set_src: /* @@ -384,7 +386,9 @@ out_set_src: src_update_flags |= BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE; } - bch2_trans_update(trans, &src_iter, &new_src->k_i, src_update_flags); + ret = bch2_trans_update(trans, &src_iter, &new_src->k_i, src_update_flags); + if (ret) + goto out; if (mode == BCH_RENAME_EXCHANGE) *src_offset = new_src->k.p.offset; diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c index 7e909a118189..8aeb2e417a15 100644 --- a/fs/bcachefs/subvolume.c +++ b/fs/bcachefs/subvolume.c @@ -488,7 +488,7 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent, n = bch2_trans_kmalloc(trans, sizeof(*n)); ret = PTR_ERR_OR_ZERO(n); if (ret) - return ret; + goto err; bkey_snapshot_init(&n->k_i); n->k.p = iter.pos; @@ -498,11 +498,10 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent, n->v.pad = 0; SET_BCH_SNAPSHOT_SUBVOL(&n->v, true); - bch2_trans_update(trans, &iter, &n->k_i, 0); - - ret = bch2_mark_snapshot(trans, bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0); + ret = bch2_trans_update(trans, &iter, &n->k_i, 0) ?: + bch2_mark_snapshot(trans, bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0); if (ret) - break; + goto err; new_snapids[i] = iter.pos.offset; } @@ -536,7 +535,9 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent, n->v.children[0] = cpu_to_le32(new_snapids[0]); n->v.children[1] = cpu_to_le32(new_snapids[1]); SET_BCH_SNAPSHOT_SUBVOL(&n->v, false); - bch2_trans_update(trans, &iter, &n->k_i, 0); + ret = bch2_trans_update(trans, &iter, &n->k_i, 0); + if (ret) + goto err; } err: bch2_trans_iter_exit(trans, &iter); @@ -1049,7 +1050,9 @@ found_slot: if (src_subvolid) { src_subvol->v.snapshot = cpu_to_le32(new_nodes[1]); - bch2_trans_update(trans, &src_iter, &src_subvol->k_i, 0); + ret = bch2_trans_update(trans, &src_iter, &src_subvol->k_i, 0); + if (ret) + goto err; } new_subvol = bch2_trans_kmalloc(trans, sizeof(*new_subvol)); @@ -1064,7 +1067,9 @@ found_slot: SET_BCH_SUBVOLUME_RO(&new_subvol->v, ro); SET_BCH_SUBVOLUME_SNAP(&new_subvol->v, src_subvolid != 0); new_subvol->k.p = dst_iter.pos; - bch2_trans_update(trans, &dst_iter, &new_subvol->k_i, 0); + ret = bch2_trans_update(trans, &dst_iter, &new_subvol->k_i, 0); + if (ret) + goto err; *new_subvolid = new_subvol->k.p.offset; *new_snapshotid = new_nodes[0]; diff --git a/fs/bcachefs/tests.c b/fs/bcachefs/tests.c index 6023661ece16..145b85320d22 100644 --- a/fs/bcachefs/tests.c +++ b/fs/bcachefs/tests.c @@ -584,10 +584,10 @@ static int rand_mixed_trans(struct btree_trans *trans, if (!(i & 3) && k.k) { bkey_cookie_init(&cookie->k_i); cookie->k.p = iter->pos; - bch2_trans_update(trans, iter, &cookie->k_i, 0); + ret = bch2_trans_update(trans, iter, &cookie->k_i, 0); } - return 0; + return ret; } static int rand_mixed(struct bch_fs *c, u64 nr)