Commit 94a3e1a6 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 1d81313f
...@@ -73,8 +73,8 @@ int bch2_btree_node_update_key(struct btree_trans *, struct btree_iter *, ...@@ -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 *, int bch2_btree_node_update_key_get_iter(struct btree_trans *,
struct btree *, struct bkey_i *, bool); struct btree *, struct bkey_i *, bool);
int bch2_trans_update(struct btree_trans *, struct btree_iter *, int __must_check bch2_trans_update(struct btree_trans *, struct btree_iter *,
struct bkey_i *, enum btree_update_flags); struct bkey_i *, enum btree_update_flags);
void bch2_trans_commit_hook(struct btree_trans *, void bch2_trans_commit_hook(struct btree_trans *,
struct btree_trans_commit_hook *); struct btree_trans_commit_hook *);
int __bch2_trans_commit(struct btree_trans *); int __bch2_trans_commit(struct btree_trans *);
......
...@@ -1312,8 +1312,8 @@ static int need_whiteout_for_snapshot(struct btree_trans *trans, ...@@ -1312,8 +1312,8 @@ static int need_whiteout_for_snapshot(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, int __must_check bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_i *k, enum btree_update_flags flags) struct bkey_i *k, enum btree_update_flags flags)
{ {
struct btree_insert_entry *i, n; struct btree_insert_entry *i, n;
......
...@@ -1549,7 +1549,9 @@ static int bch2_trans_mark_pointer(struct btree_trans *trans, ...@@ -1549,7 +1549,9 @@ static int bch2_trans_mark_pointer(struct btree_trans *trans,
goto out; goto out;
bch2_alloc_pack(c, a, u); 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: out:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
return ret; return ret;
...@@ -1600,7 +1602,9 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans, ...@@ -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_set(&s->v, p.ec.block,
stripe_blockcount_get(&s->v, p.ec.block) + stripe_blockcount_get(&s->v, p.ec.block) +
sectors); 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)); bch2_bkey_to_replicas(&r.e, bkey_i_to_s_c(&s->k_i));
r.e.data_type = data_type; r.e.data_type = data_type;
...@@ -1738,7 +1742,9 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, ...@@ -1738,7 +1742,9 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
u.data_type = !deleting ? data_type : 0; u.data_type = !deleting ? data_type : 0;
bch2_alloc_pack(c, a, u); 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: err:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
return ret; return ret;
...@@ -2017,7 +2023,9 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans, ...@@ -2017,7 +2023,9 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
u.dirty_sectors = sectors; u.dirty_sectors = sectors;
bch2_alloc_pack(c, a, u); 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: out:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
return ret; return ret;
......
...@@ -367,7 +367,9 @@ int bch2_dirent_rename(struct btree_trans *trans, ...@@ -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: out_set_src:
/* /*
...@@ -384,7 +386,9 @@ int bch2_dirent_rename(struct btree_trans *trans, ...@@ -384,7 +386,9 @@ int bch2_dirent_rename(struct btree_trans *trans,
src_update_flags |= BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE; 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) if (mode == BCH_RENAME_EXCHANGE)
*src_offset = new_src->k.p.offset; *src_offset = new_src->k.p.offset;
......
...@@ -488,7 +488,7 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent, ...@@ -488,7 +488,7 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent,
n = bch2_trans_kmalloc(trans, sizeof(*n)); n = bch2_trans_kmalloc(trans, sizeof(*n));
ret = PTR_ERR_OR_ZERO(n); ret = PTR_ERR_OR_ZERO(n);
if (ret) if (ret)
return ret; goto err;
bkey_snapshot_init(&n->k_i); bkey_snapshot_init(&n->k_i);
n->k.p = iter.pos; n->k.p = iter.pos;
...@@ -498,11 +498,10 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent, ...@@ -498,11 +498,10 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent,
n->v.pad = 0; n->v.pad = 0;
SET_BCH_SNAPSHOT_SUBVOL(&n->v, true); SET_BCH_SNAPSHOT_SUBVOL(&n->v, true);
bch2_trans_update(trans, &iter, &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);
ret = bch2_mark_snapshot(trans, bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0);
if (ret) if (ret)
break; goto err;
new_snapids[i] = iter.pos.offset; new_snapids[i] = iter.pos.offset;
} }
...@@ -536,7 +535,9 @@ static int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent, ...@@ -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[0] = cpu_to_le32(new_snapids[0]);
n->v.children[1] = cpu_to_le32(new_snapids[1]); n->v.children[1] = cpu_to_le32(new_snapids[1]);
SET_BCH_SNAPSHOT_SUBVOL(&n->v, false); 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: err:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
...@@ -1049,7 +1050,9 @@ int bch2_subvolume_create(struct btree_trans *trans, u64 inode, ...@@ -1049,7 +1050,9 @@ int bch2_subvolume_create(struct btree_trans *trans, u64 inode,
if (src_subvolid) { if (src_subvolid) {
src_subvol->v.snapshot = cpu_to_le32(new_nodes[1]); 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)); new_subvol = bch2_trans_kmalloc(trans, sizeof(*new_subvol));
...@@ -1064,7 +1067,9 @@ int bch2_subvolume_create(struct btree_trans *trans, u64 inode, ...@@ -1064,7 +1067,9 @@ int bch2_subvolume_create(struct btree_trans *trans, u64 inode,
SET_BCH_SUBVOLUME_RO(&new_subvol->v, ro); SET_BCH_SUBVOLUME_RO(&new_subvol->v, ro);
SET_BCH_SUBVOLUME_SNAP(&new_subvol->v, src_subvolid != 0); SET_BCH_SUBVOLUME_SNAP(&new_subvol->v, src_subvolid != 0);
new_subvol->k.p = dst_iter.pos; 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_subvolid = new_subvol->k.p.offset;
*new_snapshotid = new_nodes[0]; *new_snapshotid = new_nodes[0];
......
...@@ -584,10 +584,10 @@ static int rand_mixed_trans(struct btree_trans *trans, ...@@ -584,10 +584,10 @@ static int rand_mixed_trans(struct btree_trans *trans,
if (!(i & 3) && k.k) { if (!(i & 3) && k.k) {
bkey_cookie_init(&cookie->k_i); bkey_cookie_init(&cookie->k_i);
cookie->k.p = iter->pos; 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) static int rand_mixed(struct bch_fs *c, u64 nr)
......
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