linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Zeng Heng <zengheng4@huawei.com>
Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH -next 1/2] xfs: simplify if-else condition in xfs_validate_new_dalign
Date: Tue, 30 Aug 2022 08:19:19 -0700	[thread overview]
Message-ID: <Yw4qd38m++Wg2uXQ@magnolia> (raw)
In-Reply-To: <20220830133939.2726749-2-zengheng4@huawei.com>

On Tue, Aug 30, 2022 at 09:39:38PM +0800, Zeng Heng wrote:
> "else" is not generally useful after a return,
> so remove them which makes if condition a bit
> more clear.
> 
> There is no logical changes.
> 
> Signed-off-by: Zeng Heng <zengheng4@huawei.com>

Yep.
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_mount.c | 38 ++++++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
> index f10c88cee116..e8bb3c2e847e 100644
> --- a/fs/xfs/xfs_mount.c
> +++ b/fs/xfs/xfs_mount.c
> @@ -300,26 +300,28 @@ xfs_validate_new_dalign(
>  	"alignment check failed: sunit/swidth vs. blocksize(%d)",
>  			mp->m_sb.sb_blocksize);
>  		return -EINVAL;
> -	} else {
> -		/*
> -		 * Convert the stripe unit and width to FSBs.
> -		 */
> -		mp->m_dalign = XFS_BB_TO_FSBT(mp, mp->m_dalign);
> -		if (mp->m_dalign && (mp->m_sb.sb_agblocks % mp->m_dalign)) {
> -			xfs_warn(mp,
> -		"alignment check failed: sunit/swidth vs. agsize(%d)",
> -				 mp->m_sb.sb_agblocks);
> -			return -EINVAL;
> -		} else if (mp->m_dalign) {
> -			mp->m_swidth = XFS_BB_TO_FSBT(mp, mp->m_swidth);
> -		} else {
> -			xfs_warn(mp,
> -		"alignment check failed: sunit(%d) less than bsize(%d)",
> -				 mp->m_dalign, mp->m_sb.sb_blocksize);
> -			return -EINVAL;
> -		}
>  	}
>  
> +	/*
> +	 * Convert the stripe unit and width to FSBs.
> +	 */
> +	mp->m_dalign = XFS_BB_TO_FSBT(mp, mp->m_dalign);
> +	if (mp->m_dalign && (mp->m_sb.sb_agblocks % mp->m_dalign)) {
> +		xfs_warn(mp,
> +	"alignment check failed: sunit/swidth vs. agsize(%d)",
> +			mp->m_sb.sb_agblocks);
> +		return -EINVAL;
> +	}
> +
> +	if (!mp->m_dalign) {
> +		xfs_warn(mp,
> +	"alignment check failed: sunit(%d) less than bsize(%d)",
> +			mp->m_dalign, mp->m_sb.sb_blocksize);
> +		return -EINVAL;
> +	}
> +
> +	mp->m_swidth = XFS_BB_TO_FSBT(mp, mp->m_swidth);

I think this reorganization of the if test logic is correct, but I
really wish this unit abuse ("m_swidth is a BB for short periods of time
and fsblock everywhere else") would get fixed to simplify analysis and
prevent us from stumbling over things like that some time later.

So for this change,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

But I would be very happy to see some tripping hazard removal. ;)

--D

> +
>  	if (!xfs_has_dalign(mp)) {
>  		xfs_warn(mp,
>  "cannot change alignment: superblock does not support data alignment");
> -- 
> 2.25.1
> 

  reply	other threads:[~2022-08-30 15:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 13:39 [PATCH -next 0/2] Simplify if-else condition for clean code Zeng Heng
2022-08-30 13:39 ` [PATCH -next 1/2] xfs: simplify if-else condition in xfs_validate_new_dalign Zeng Heng
2022-08-30 15:19   ` Darrick J. Wong [this message]
2022-08-30 13:39 ` [PATCH -next 2/2] xfs: simplify if-else condition in xfs_reflink_trim_around_shared Zeng Heng
2022-08-30 15:12   ` Darrick J. Wong

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=Yw4qd38m++Wg2uXQ@magnolia \
    --to=djwong@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=zengheng4@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).