diff mbox series

btrfs: qgroup: do not check qgroup inherit if qgroup is disabled

Message ID bd677611fcbd89c21d60585e22c8d4aed3b90090.1713599418.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: qgroup: do not check qgroup inherit if qgroup is disabled | expand

Commit Message

Qu Wenruo April 20, 2024, 7:50 a.m. UTC
[BUG]
After kernel commit 86211eea8ae1 ("btrfs: qgroup: validate
btrfs_qgroup_inherit parameter"), user space tool snapper will fail to
create snapshot using its timeline feature.

[CAUSE]
It turns out that, if using timeline snapper would unconditionally pass
btrfs_qgroup_inherit parameter (assigning the new snapshot to qgroup 1/0)
for snapshot creation.

In that case, since qgroup is disabled there would be no qgroup 1/0, and
btrfs_qgroup_check_inherit() would return -ENOENT and fail the whole
snapshot creation.

[FIX]
Just skip the check if qgroup is not enabled.
This is to keep the older behavior for user space tools, as if the
kernel behavior changed for user space, it is a regression of kernel.

Thankfully snapper is also fixing the behavior by detecting if qgroup is
running in the first place, so the effect should not be that huge.

Link: https://github.com/openSUSE/snapper/issues/894
Fixes: 86211eea8ae1 ("btrfs: qgroup: validate btrfs_qgroup_inherit parameter")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/qgroup.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Filipe Manana April 22, 2024, 4:04 p.m. UTC | #1
On Sat, Apr 20, 2024 at 8:52 AM Qu Wenruo <wqu@suse.com> wrote:
>
> [BUG]
> After kernel commit 86211eea8ae1 ("btrfs: qgroup: validate
> btrfs_qgroup_inherit parameter"), user space tool snapper will fail to
> create snapshot using its timeline feature.
>
> [CAUSE]
> It turns out that, if using timeline snapper would unconditionally pass
> btrfs_qgroup_inherit parameter (assigning the new snapshot to qgroup 1/0)
> for snapshot creation.
>
> In that case, since qgroup is disabled there would be no qgroup 1/0, and
> btrfs_qgroup_check_inherit() would return -ENOENT and fail the whole
> snapshot creation.
>
> [FIX]
> Just skip the check if qgroup is not enabled.
> This is to keep the older behavior for user space tools, as if the
> kernel behavior changed for user space, it is a regression of kernel.
>
> Thankfully snapper is also fixing the behavior by detecting if qgroup is
> running in the first place, so the effect should not be that huge.
>
> Link: https://github.com/openSUSE/snapper/issues/894
> Fixes: 86211eea8ae1 ("btrfs: qgroup: validate btrfs_qgroup_inherit parameter")
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/qgroup.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 9aeb740388ab..2f55a89709b3 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -3138,6 +3138,9 @@ int btrfs_qgroup_check_inherit(struct btrfs_fs_info *fs_info,
>                                struct btrfs_qgroup_inherit *inherit,
>                                size_t size)
>  {
> +       /* Qgroup not enabled, ignore the inherit parameter. */
> +       if (!btrfs_qgroup_enabled(fs_info))

Well, the comment is quite redundant as the expression is
self-explaining... I would leave it out.

Anyway, it looks good, thanks.

Reviewed-by: Filipe Manana <fdmanana@suse.com>

> +               return 0;
>         if (inherit->flags & ~BTRFS_QGROUP_INHERIT_FLAGS_SUPP)
>                 return -EOPNOTSUPP;
>         if (size < sizeof(*inherit) || size > PAGE_SIZE)
> --
> 2.44.0
>
>
David Sterba April 23, 2024, 1:46 p.m. UTC | #2
On Sat, Apr 20, 2024 at 05:20:27PM +0930, Qu Wenruo wrote:
> [BUG]
> After kernel commit 86211eea8ae1 ("btrfs: qgroup: validate
> btrfs_qgroup_inherit parameter"), user space tool snapper will fail to
> create snapshot using its timeline feature.
> 
> [CAUSE]
> It turns out that, if using timeline snapper would unconditionally pass
> btrfs_qgroup_inherit parameter (assigning the new snapshot to qgroup 1/0)
> for snapshot creation.
> 
> In that case, since qgroup is disabled there would be no qgroup 1/0, and
> btrfs_qgroup_check_inherit() would return -ENOENT and fail the whole
> snapshot creation.
> 
> [FIX]
> Just skip the check if qgroup is not enabled.
> This is to keep the older behavior for user space tools, as if the
> kernel behavior changed for user space, it is a regression of kernel.
> 
> Thankfully snapper is also fixing the behavior by detecting if qgroup is
> running in the first place, so the effect should not be that huge.
> 
> Link: https://github.com/openSUSE/snapper/issues/894
> Fixes: 86211eea8ae1 ("btrfs: qgroup: validate btrfs_qgroup_inherit parameter")
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: David Sterba <dsterba@suse.com>

> ---
>  fs/btrfs/qgroup.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 9aeb740388ab..2f55a89709b3 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -3138,6 +3138,9 @@ int btrfs_qgroup_check_inherit(struct btrfs_fs_info *fs_info,
>  			       struct btrfs_qgroup_inherit *inherit,
>  			       size_t size)
>  {
> +	/* Qgroup not enabled, ignore the inherit parameter. */

Agreed with Filipe that the comment is not necessary.
diff mbox series

Patch

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 9aeb740388ab..2f55a89709b3 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3138,6 +3138,9 @@  int btrfs_qgroup_check_inherit(struct btrfs_fs_info *fs_info,
 			       struct btrfs_qgroup_inherit *inherit,
 			       size_t size)
 {
+	/* Qgroup not enabled, ignore the inherit parameter. */
+	if (!btrfs_qgroup_enabled(fs_info))
+		return 0;
 	if (inherit->flags & ~BTRFS_QGROUP_INHERIT_FLAGS_SUPP)
 		return -EOPNOTSUPP;
 	if (size < sizeof(*inherit) || size > PAGE_SIZE)