[PATCH] bcachefs: fix incorrect pointer check in __bch2_subvolume_delete()

Jeongjun Park posted 1 patch 1 year ago
fs/bcachefs/subvolume.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] bcachefs: fix incorrect pointer check in __bch2_subvolume_delete()
Posted by Jeongjun Park 1 year ago
For some unknown reason, checks on struct bkey_s_c_snapshot and struct
bkey_s_c_snapshot_tree pointers are missing.

Therefore, I think it would be appropriate to fix the incorrect pointer checking
through this patch.

Fixes: 4bd06f07bcb5 ("bcachefs: Fixes for snapshot_tree.master_subvol")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 fs/bcachefs/subvolume.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c
index e3d0475232e5..b7b96283c316 100644
--- a/fs/bcachefs/subvolume.c
+++ b/fs/bcachefs/subvolume.c
@@ -428,7 +428,7 @@ static int __bch2_subvolume_delete(struct btree_trans *trans, u32 subvolid)
 		bch2_bkey_get_iter_typed(trans, &snapshot_iter,
 				BTREE_ID_snapshots, POS(0, snapid),
 				0, snapshot);
-	ret = bkey_err(subvol);
+	ret = bkey_err(snapshot);
 	bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), trans->c,
 				"missing snapshot %u", snapid);
 	if (ret)
@@ -440,6 +440,11 @@ static int __bch2_subvolume_delete(struct btree_trans *trans, u32 subvolid)
 		bch2_bkey_get_iter_typed(trans, &snapshot_tree_iter,
 				BTREE_ID_snapshot_trees, POS(0, treeid),
 				0, snapshot_tree);
+	ret = bkey_err(snapshot_tree);
+	bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), trans->c,
+				"missing snapshot tree %u", treeid);
+	if (ret)
+		goto err;
 
 	if (le32_to_cpu(snapshot_tree.v->master_subvol) == subvolid) {
 		struct bkey_i_snapshot_tree *snapshot_tree_mut =
--
Re: [PATCH] bcachefs: fix incorrect pointer check in __bch2_subvolume_delete()
Posted by Kent Overstreet 1 year ago
On Sat, Feb 01, 2025 at 01:20:31AM +0900, Jeongjun Park wrote:
> For some unknown reason, checks on struct bkey_s_c_snapshot and struct
> bkey_s_c_snapshot_tree pointers are missing.
> 
> Therefore, I think it would be appropriate to fix the incorrect pointer checking
> through this patch.
> 
> Fixes: 4bd06f07bcb5 ("bcachefs: Fixes for snapshot_tree.master_subvol")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>

Thanks! Applied
> ---
>  fs/bcachefs/subvolume.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c
> index e3d0475232e5..b7b96283c316 100644
> --- a/fs/bcachefs/subvolume.c
> +++ b/fs/bcachefs/subvolume.c
> @@ -428,7 +428,7 @@ static int __bch2_subvolume_delete(struct btree_trans *trans, u32 subvolid)
>  		bch2_bkey_get_iter_typed(trans, &snapshot_iter,
>  				BTREE_ID_snapshots, POS(0, snapid),
>  				0, snapshot);
> -	ret = bkey_err(subvol);
> +	ret = bkey_err(snapshot);
>  	bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), trans->c,
>  				"missing snapshot %u", snapid);
>  	if (ret)
> @@ -440,6 +440,11 @@ static int __bch2_subvolume_delete(struct btree_trans *trans, u32 subvolid)
>  		bch2_bkey_get_iter_typed(trans, &snapshot_tree_iter,
>  				BTREE_ID_snapshot_trees, POS(0, treeid),
>  				0, snapshot_tree);
> +	ret = bkey_err(snapshot_tree);
> +	bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), trans->c,
> +				"missing snapshot tree %u", treeid);
> +	if (ret)
> +		goto err;
>  
>  	if (le32_to_cpu(snapshot_tree.v->master_subvol) == subvolid) {
>  		struct bkey_i_snapshot_tree *snapshot_tree_mut =
> --