summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-04-30 18:59:28 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-05-12 19:42:34 -0400
commit8b0a252104ef30404e36b557b0503f9b48803500 (patch)
tree3026f6b8fc8a7e455abd26380d1be739f8183a0c
parent0a72897b89d4002cf2fe5223c0d19c22060ab1af (diff)
bcachefs: bch2_bkey_alloc() 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_alloc(), eliminating a bit of boilerplate. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/btree_update.h23
-rw-r--r--fs/bcachefs/subvolume.c12
2 files changed, 18 insertions, 17 deletions
diff --git a/fs/bcachefs/btree_update.h b/fs/bcachefs/btree_update.h
index 5e2aa21caf55..5743a6e0f474 100644
--- a/fs/bcachefs/btree_update.h
+++ b/fs/bcachefs/btree_update.h
@@ -251,22 +251,27 @@ static inline struct bkey_i *bch2_bkey_get_mut(struct btree_trans *trans,
KEY_TYPE_##_type, sizeof(struct bkey_i_##_type)))
static inline struct bkey_i *__bch2_bkey_alloc(struct btree_trans *trans, struct btree_iter *iter,
- unsigned type, unsigned val_size)
+ unsigned flags, unsigned type, unsigned val_size)
{
struct bkey_i *k = bch2_trans_kmalloc(trans, sizeof(*k) + val_size);
+ int ret;
- if (!IS_ERR(k)) {
- bkey_init(&k->k);
- k->k.p = iter->pos;
- k->k.type = type;
- set_bkey_val_bytes(&k->k, val_size);
- }
+ if (IS_ERR(k))
+ return k;
+
+ bkey_init(&k->k);
+ k->k.p = iter->pos;
+ k->k.type = type;
+ set_bkey_val_bytes(&k->k, val_size);
+ ret = bch2_trans_update(trans, iter, k, flags);
+ if (unlikely(ret))
+ return ERR_PTR(ret);
return k;
}
-#define bch2_bkey_alloc(_trans, _iter, _type) \
- bkey_i_to_##_type(__bch2_bkey_alloc(_trans, _iter, \
+#define bch2_bkey_alloc(_trans, _iter, _flags, _type) \
+ bkey_i_to_##_type(__bch2_bkey_alloc(_trans, _iter, _flags, \
KEY_TYPE_##_type, sizeof(struct bch_##_type)))
#endif /* _BCACHEFS_BTREE_UPDATE_H */
diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c
index eea4c2558998..48956453340d 100644
--- a/fs/bcachefs/subvolume.c
+++ b/fs/bcachefs/subvolume.c
@@ -476,7 +476,7 @@ int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent,
goto err;
}
- n = bch2_bkey_alloc(trans, &iter, snapshot);
+ n = bch2_bkey_alloc(trans, &iter, 0, snapshot);
ret = PTR_ERR_OR_ZERO(n);
if (ret)
goto err;
@@ -487,9 +487,8 @@ int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent,
n->v.pad = 0;
SET_BCH_SNAPSHOT_SUBVOL(&n->v, true);
- ret = bch2_trans_update(trans, &iter, &n->k_i, 0) ?:
- bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0,
- bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0);
+ ret = bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0,
+ bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0);
if (ret)
goto err;
@@ -981,7 +980,7 @@ found_slot:
goto err;
}
- new_subvol = bch2_bkey_alloc(trans, &dst_iter, subvolume);
+ new_subvol = bch2_bkey_alloc(trans, &dst_iter, 0, subvolume);
ret = PTR_ERR_OR_ZERO(new_subvol);
if (ret)
goto err;
@@ -991,9 +990,6 @@ found_slot:
new_subvol->v.inode = cpu_to_le64(inode);
SET_BCH_SUBVOLUME_RO(&new_subvol->v, ro);
SET_BCH_SUBVOLUME_SNAP(&new_subvol->v, src_subvolid != 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];