summaryrefslogtreecommitdiff
path: root/fs/bcachefs/subvolume.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-04-28 06:20:18 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:10:01 +0300
commit51e84d3bbff55f5ac79fef0d1bbf515d6d397289 (patch)
tree9417ff495c058e6dc7c5883416694d8bb3a2854e /fs/bcachefs/subvolume.c
parentdbda63bbb0dbce070f22132339a07146bf1af850 (diff)
downloadlinux-51e84d3bbff55f5ac79fef0d1bbf515d6d397289.tar.xz
bcachefs: bch2_bkey_get_empty_slot()
Add a new helper for allocating a new slot in a btree. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/subvolume.c')
-rw-r--r--fs/bcachefs/subvolume.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c
index cac295afc75f..8d87f90a0ac6 100644
--- a/fs/bcachefs/subvolume.c
+++ b/fs/bcachefs/subvolume.c
@@ -909,32 +909,19 @@ int bch2_subvolume_create(struct btree_trans *trans, u64 inode,
u32 *new_snapshotid,
bool ro)
{
- struct bch_fs *c = trans->c;
struct btree_iter dst_iter, src_iter = (struct btree_iter) { NULL };
struct bkey_i_subvolume *new_subvol = NULL;
struct bkey_i_subvolume *src_subvol = NULL;
- struct bkey_s_c k;
u32 parent = 0, new_nodes[2], snapshot_subvols[2];
int ret = 0;
- for_each_btree_key(trans, dst_iter, BTREE_ID_subvolumes, SUBVOL_POS_MIN,
- BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k, ret) {
- if (bkey_gt(k.k->p, SUBVOL_POS_MAX))
- break;
-
- /*
- * bch2_subvolume_delete() doesn't flush the btree key cache -
- * ideally it would but that's tricky
- */
- if (bkey_deleted(k.k) &&
- !bch2_btree_key_cache_find(c, BTREE_ID_subvolumes, dst_iter.pos))
- goto found_slot;
- }
-
- if (!ret)
+ ret = bch2_bkey_get_empty_slot(trans, &dst_iter,
+ BTREE_ID_subvolumes, POS(0, U32_MAX));
+ if (ret == -BCH_ERR_ENOSPC_btree_slot)
ret = -BCH_ERR_ENOSPC_subvolume_create;
- goto err;
-found_slot:
+ if (ret)
+ return ret;
+
snapshot_subvols[0] = dst_iter.pos.offset;
snapshot_subvols[1] = src_subvolid;