summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/subvolume.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-03-13 07:09:33 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:57 -0400
commitae1f56238d55ad6d16564455559d1fa9a8cea2f6 (patch)
tree36690f9c4a6889af17acd3d4fc60bd735ef6402a /fs/bcachefs/subvolume.c
parente6539b0aebd384549aef4dc3b917658f24bb6b83 (diff)
downloadlinux-ae1f56238d55ad6d16564455559d1fa9a8cea2f6.tar.gz
linux-ae1f56238d55ad6d16564455559d1fa9a8cea2f6.tar.bz2
linux-ae1f56238d55ad6d16564455559d1fa9a8cea2f6.zip
bcachefs: Mark new snapshots earlier in create path
This fixes a null ptr deref when creating new snapshots: bch2_create_trans() will lookup the subvolume and find the _new_ snapshot in the BCH_CREATE_SUBVOL path that's being created in that transaction. We have to call bch2_mark_snapshot() earlier so that it's properly initialized, instead of leaving it for transaction commit. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/subvolume.c')
-rw-r--r--fs/bcachefs/subvolume.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c
index d76239654a89..bcc67c0f5dfc 100644
--- a/fs/bcachefs/subvolume.c
+++ b/fs/bcachefs/subvolume.c
@@ -513,7 +513,9 @@ 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);
+ 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);
if (ret)
goto err;
@@ -540,7 +542,7 @@ int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent,
n->v.children[1] = cpu_to_le32(new_snapids[1]);
n->v.subvol = 0;
SET_BCH_SNAPSHOT_SUBVOL(&n->v, false);
- ret = bch2_trans_update(trans, &iter, &n->k_i, 0);
+ ret = bch2_trans_update(trans, &iter, &n->k_i, 0);
if (ret)
goto err;
}