Skip to content

Commit b2e2bed

Browse files
author
Kent Overstreet
committed
bcachefs: Add missing key type checks to check_snapshot_exists()
For now we only have one key type in these btrees, but forward compatibility means we do have to check. Reported-by: [email protected] Signed-off-by: Kent Overstreet <[email protected]>
1 parent 32a01cd commit b2e2bed

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/bcachefs/snapshot.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ static int check_snapshot_exists(struct btree_trans *trans, u32 id)
871871

872872
for_each_btree_key_norestart(trans, iter, BTREE_ID_snapshot_trees, POS_MIN,
873873
0, k, ret) {
874-
if (le32_to_cpu(bkey_s_c_to_snapshot_tree(k).v->root_snapshot) == id) {
874+
if (k.k->type == KEY_TYPE_snapshot_tree &&
875+
le32_to_cpu(bkey_s_c_to_snapshot_tree(k).v->root_snapshot) == id) {
875876
tree_id = k.k->p.offset;
876877
break;
877878
}
@@ -899,7 +900,8 @@ static int check_snapshot_exists(struct btree_trans *trans, u32 id)
899900

900901
for_each_btree_key_norestart(trans, iter, BTREE_ID_subvolumes, POS_MIN,
901902
0, k, ret) {
902-
if (le32_to_cpu(bkey_s_c_to_subvolume(k).v->snapshot) == id) {
903+
if (k.k->type == KEY_TYPE_subvolume &&
904+
le32_to_cpu(bkey_s_c_to_subvolume(k).v->snapshot) == id) {
903905
snapshot->v.subvol = cpu_to_le32(k.k->p.offset);
904906
SET_BCH_SNAPSHOT_SUBVOL(&snapshot->v, true);
905907
break;

0 commit comments

Comments
 (0)