Commit f12a798a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_bkey_get_mut() now calls bch2_trans_update()

It's safe to call bch2_trans_update with a k/v pair where the value
hasn't been filled out, as long as the key part has been and the value
is filled out by transaction commit time.

This patch folds the bch2_trans_update() call into bch2_bkey_get_mut(),
eliminating a bit of boilerplate.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f8cb35fd
...@@ -214,7 +214,7 @@ static inline struct bkey_i *bch2_bkey_make_mut(struct btree_trans *trans, struc ...@@ -214,7 +214,7 @@ static inline struct bkey_i *bch2_bkey_make_mut(struct btree_trans *trans, struc
bkey_i_to_##_type(__bch2_bkey_make_mut(_trans, _k, \ bkey_i_to_##_type(__bch2_bkey_make_mut(_trans, _k, \
KEY_TYPE_##_type, sizeof(struct bkey_i_##_type))) KEY_TYPE_##_type, sizeof(struct bkey_i_##_type)))
static inline struct bkey_i *__bch2_bkey_get_mut(struct btree_trans *trans, static inline struct bkey_i *__bch2_bkey_get_mut_noupdate(struct btree_trans *trans,
struct btree_iter *iter, struct btree_iter *iter,
unsigned btree_id, struct bpos pos, unsigned btree_id, struct bpos pos,
unsigned flags, unsigned type, unsigned min_bytes) unsigned flags, unsigned type, unsigned min_bytes)
...@@ -229,6 +229,35 @@ static inline struct bkey_i *__bch2_bkey_get_mut(struct btree_trans *trans, ...@@ -229,6 +229,35 @@ static inline struct bkey_i *__bch2_bkey_get_mut(struct btree_trans *trans,
return ret; return ret;
} }
static inline struct bkey_i *bch2_bkey_get_mut_noupdate(struct btree_trans *trans,
struct btree_iter *iter,
unsigned btree_id, struct bpos pos,
unsigned flags)
{
return __bch2_bkey_get_mut_noupdate(trans, iter, btree_id, pos, flags, 0, 0);
}
static inline struct bkey_i *__bch2_bkey_get_mut(struct btree_trans *trans,
struct btree_iter *iter,
unsigned btree_id, struct bpos pos,
unsigned flags, unsigned type, unsigned min_bytes)
{
struct bkey_i *mut = __bch2_bkey_get_mut_noupdate(trans, iter,
btree_id, pos, flags|BTREE_ITER_INTENT, type, min_bytes);
int ret;
if (IS_ERR(mut))
return mut;
ret = bch2_trans_update(trans, iter, mut, flags);
if (ret) {
bch2_trans_iter_exit(trans, iter);
return ERR_PTR(ret);
}
return mut;
}
static inline struct bkey_i *bch2_bkey_get_mut_minsize(struct btree_trans *trans, static inline struct bkey_i *bch2_bkey_get_mut_minsize(struct btree_trans *trans,
struct btree_iter *iter, struct btree_iter *iter,
unsigned btree_id, struct bpos pos, unsigned btree_id, struct bpos pos,
...@@ -242,7 +271,7 @@ static inline struct bkey_i *bch2_bkey_get_mut(struct btree_trans *trans, ...@@ -242,7 +271,7 @@ static inline struct bkey_i *bch2_bkey_get_mut(struct btree_trans *trans,
unsigned btree_id, struct bpos pos, unsigned btree_id, struct bpos pos,
unsigned flags) unsigned flags)
{ {
return bch2_bkey_get_mut_minsize(trans, iter, btree_id, pos, flags, 0); return __bch2_bkey_get_mut(trans, iter, btree_id, pos, flags, 0, 0);
} }
#define bch2_bkey_get_mut_typed(_trans, _iter, _btree_id, _pos, _flags, _type)\ #define bch2_bkey_get_mut_typed(_trans, _iter, _btree_id, _pos, _flags, _type)\
......
...@@ -1471,10 +1471,6 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans, ...@@ -1471,10 +1471,6 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans,
stripe_blockcount_get(&s->v, p.ec.block) + stripe_blockcount_get(&s->v, p.ec.block) +
sectors); sectors);
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;
update_replicas_list(trans, &r.e, sectors); update_replicas_list(trans, &r.e, sectors);
...@@ -1749,7 +1745,7 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans, ...@@ -1749,7 +1745,7 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans,
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
int ret; int ret;
k = bch2_bkey_get_mut(trans, &iter, k = bch2_bkey_get_mut_noupdate(trans, &iter,
BTREE_ID_reflink, POS(0, *idx), BTREE_ID_reflink, POS(0, *idx),
BTREE_ITER_WITH_UPDATES); BTREE_ITER_WITH_UPDATES);
ret = PTR_ERR_OR_ZERO(k); ret = PTR_ERR_OR_ZERO(k);
......
...@@ -257,7 +257,7 @@ static inline int bch2_extent_update_i_size_sectors(struct btree_trans *trans, ...@@ -257,7 +257,7 @@ static inline int bch2_extent_update_i_size_sectors(struct btree_trans *trans,
unsigned inode_update_flags = BTREE_UPDATE_NOJOURNAL; unsigned inode_update_flags = BTREE_UPDATE_NOJOURNAL;
int ret; int ret;
k = bch2_bkey_get_mut(trans, &iter, BTREE_ID_inodes, k = bch2_bkey_get_mut_noupdate(trans, &iter, BTREE_ID_inodes,
SPOS(0, SPOS(0,
extent_iter->pos.inode, extent_iter->pos.inode,
extent_iter->snapshot), extent_iter->snapshot),
......
...@@ -369,7 +369,7 @@ static int bch2_snapshot_node_set_deleted(struct btree_trans *trans, u32 id) ...@@ -369,7 +369,7 @@ static int bch2_snapshot_node_set_deleted(struct btree_trans *trans, u32 id)
ret = PTR_ERR_OR_ZERO(s); ret = PTR_ERR_OR_ZERO(s);
if (unlikely(ret)) { if (unlikely(ret)) {
bch2_fs_inconsistent_on(ret == -ENOENT, trans->c, "missing snapshot %u", id); bch2_fs_inconsistent_on(ret == -ENOENT, trans->c, "missing snapshot %u", id);
goto err; return ret;
} }
/* already deleted? */ /* already deleted? */
...@@ -379,10 +379,6 @@ static int bch2_snapshot_node_set_deleted(struct btree_trans *trans, u32 id) ...@@ -379,10 +379,6 @@ static int bch2_snapshot_node_set_deleted(struct btree_trans *trans, u32 id)
SET_BCH_SNAPSHOT_DELETED(&s->v, true); SET_BCH_SNAPSHOT_DELETED(&s->v, true);
SET_BCH_SNAPSHOT_SUBVOL(&s->v, false); SET_BCH_SNAPSHOT_SUBVOL(&s->v, false);
s->v.subvol = 0; s->v.subvol = 0;
ret = bch2_trans_update(trans, &iter, &s->k_i, 0);
if (ret)
goto err;
err: err:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
return ret; return ret;
...@@ -434,10 +430,6 @@ static int bch2_snapshot_node_delete(struct btree_trans *trans, u32 id) ...@@ -434,10 +430,6 @@ static int bch2_snapshot_node_delete(struct btree_trans *trans, u32 id)
le32_to_cpu(parent->v.children[1])) le32_to_cpu(parent->v.children[1]))
swap(parent->v.children[0], swap(parent->v.children[0],
parent->v.children[1]); parent->v.children[1]);
ret = bch2_trans_update(trans, &p_iter, &parent->k_i, 0);
if (ret)
goto err;
} }
ret = bch2_btree_delete_at(trans, &iter, 0); ret = bch2_btree_delete_at(trans, &iter, 0);
...@@ -888,30 +880,25 @@ int bch2_subvolume_unlink(struct btree_trans *trans, u32 subvolid) ...@@ -888,30 +880,25 @@ int bch2_subvolume_unlink(struct btree_trans *trans, u32 subvolid)
struct subvolume_unlink_hook *h; struct subvolume_unlink_hook *h;
int ret = 0; int ret = 0;
h = bch2_trans_kmalloc(trans, sizeof(*h));
ret = PTR_ERR_OR_ZERO(h);
if (ret)
return ret;
h->h.fn = bch2_subvolume_wait_for_pagecache_and_delete_hook;
h->subvol = subvolid;
bch2_trans_commit_hook(trans, &h->h);
n = bch2_bkey_get_mut_typed(trans, &iter, n = bch2_bkey_get_mut_typed(trans, &iter,
BTREE_ID_subvolumes, POS(0, subvolid), BTREE_ID_subvolumes, POS(0, subvolid),
BTREE_ITER_CACHED, subvolume); BTREE_ITER_CACHED, subvolume);
ret = PTR_ERR_OR_ZERO(n); ret = PTR_ERR_OR_ZERO(n);
if (unlikely(ret)) { if (unlikely(ret)) {
bch2_fs_inconsistent_on(ret == -ENOENT, trans->c, "missing subvolume %u", subvolid); bch2_fs_inconsistent_on(ret == -ENOENT, trans->c, "missing subvolume %u", subvolid);
goto err; return ret;
} }
SET_BCH_SUBVOLUME_UNLINKED(&n->v, true); SET_BCH_SUBVOLUME_UNLINKED(&n->v, true);
ret = bch2_trans_update(trans, &iter, &n->k_i, 0);
if (ret)
goto err;
h = bch2_trans_kmalloc(trans, sizeof(*h));
ret = PTR_ERR_OR_ZERO(h);
if (ret)
goto err;
h->h.fn = bch2_subvolume_wait_for_pagecache_and_delete_hook;
h->subvol = subvolid;
bch2_trans_commit_hook(trans, &h->h);
err:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
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