All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 4/4] btrfs: balance: factor out convert profile validation
Date: Fri, 28 Feb 2020 16:43:17 +0800	[thread overview]
Message-ID: <2a6dc262-d355-b488-d342-6402014e8cf4@gmx.com> (raw)
In-Reply-To: <0432001929a87bd8fc75019ca67257d21d1b1315.1582832619.git.dsterba@suse.com>


[-- Attachment #1.1: Type: text/plain, Size: 3009 bytes --]



On 2020/2/28 上午4:00, David Sterba wrote:
> The validation follows the same steps for all three block group types,
> the existing helper validate_convert_profile can be enhanced and do more
> of the common things.
> 
> Signed-off-by: David Sterba <dsterba@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>  fs/btrfs/volumes.c | 45 +++++++++++++++++++++------------------------
>  1 file changed, 21 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 3d35466f34b0..b5d7dc561b68 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -3762,13 +3762,25 @@ static inline int balance_need_close(struct btrfs_fs_info *fs_info)
>  		 atomic_read(&fs_info->balance_cancel_req) == 0);
>  }
>  
> -/* Non-zero return value signifies invalidity */
> -static inline int validate_convert_profile(struct btrfs_balance_args *bctl_arg,
> -		u64 allowed)
> +/*
> + * Validate target profile against allowed profiles and return true if it's OK.
> + * Otherwise print the error message and return false.
> + */
> +static inline int validate_convert_profile(struct btrfs_fs_info *fs_info,
> +		const struct btrfs_balance_args *bargs,
> +		u64 allowed, const char *type)
>  {
> -	return ((bctl_arg->flags & BTRFS_BALANCE_ARGS_CONVERT) &&
> -		(!alloc_profile_is_valid(bctl_arg->target, 1) ||
> -		 (bctl_arg->target & ~allowed)));
> +	if (!(bargs->flags & BTRFS_BALANCE_ARGS_CONVERT))
> +		return true;
> +
> +	/* Profile is valid and does not have bits outside of the allowed set */
> +	if (alloc_profile_is_valid(bargs->target, 1) &&
> +	    (bargs->target & ~allowed) == 0)
> +		return true;
> +
> +	btrfs_err(fs_info, "balance: invalid convert %s profile %s",
> +			type, btrfs_bg_type_to_raid_name(bargs->target));
> +	return false;
>  }
>  
>  /*
> @@ -3984,24 +3996,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
>  		if (num_devices >= btrfs_raid_array[i].devs_min)
>  			allowed |= btrfs_raid_array[i].bg_flag;
>  
> -	if (validate_convert_profile(&bctl->data, allowed)) {
> -		btrfs_err(fs_info,
> -			  "balance: invalid convert data profile %s",
> -			  btrfs_bg_type_to_raid_name(bctl->data.target));
> -		ret = -EINVAL;
> -		goto out;
> -	}
> -	if (validate_convert_profile(&bctl->meta, allowed)) {
> -		btrfs_err(fs_info,
> -			  "balance: invalid convert metadata profile %s",
> -			  btrfs_bg_type_to_raid_name(bctl->meta.target));
> -		ret = -EINVAL;
> -		goto out;
> -	}
> -	if (validate_convert_profile(&bctl->sys, allowed)) {
> -		btrfs_err(fs_info,
> -			  "balance: invalid convert system profile %s",
> -			  btrfs_bg_type_to_raid_name(bctl->sys.target));
> +	if (!validate_convert_profile(fs_info, &bctl->data, allowed, "data") ||
> +	    !validate_convert_profile(fs_info, &bctl->meta, allowed, "metadata") ||
> +	    !validate_convert_profile(fs_info, &bctl->sys,  allowed, "system")) {
>  		ret = -EINVAL;
>  		goto out;
>  	}
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      parent reply	other threads:[~2020-02-28  8:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27 20:00 [PATCH 0/4] Misc cleanups David Sterba
2020-02-27 20:00 ` [PATCH 1/4] btrfs: inline checksum name and driver definitions David Sterba
2020-02-27 22:31   ` Johannes Thumshirn
2020-02-28  8:38   ` Qu Wenruo
2020-02-27 20:00 ` [PATCH 2/4] btrfs: simplify tree block checksumming loop David Sterba
2020-02-27 22:52   ` Johannes Thumshirn
2020-02-28  8:41   ` Qu Wenruo
2020-02-27 20:00 ` [PATCH 3/4] btrfs: return void from csum_tree_block David Sterba
2020-02-27 22:32   ` Johannes Thumshirn
2020-02-28  8:41   ` Qu Wenruo
2020-02-27 20:00 ` [PATCH 4/4] btrfs: balance: factor out convert profile validation David Sterba
2020-02-27 22:33   ` Johannes Thumshirn
2020-02-28  8:43   ` Qu Wenruo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a6dc262-d355-b488-d342-6402014e8cf4@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.