Linux-Fsdevel Archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com,
	yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH v5 08/10] ext4: factor out a helper to check the cluster allocation state
Date: Mon, 20 May 2024 11:37:21 +0200	[thread overview]
Message-ID: <20240520093721.xqrhhn43ldvhoh5y@quack3> (raw)
In-Reply-To: <20240517124005.347221-9-yi.zhang@huaweicloud.com>

On Fri 17-05-24 20:40:03, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> Factor out a common helper ext4_clu_alloc_state(), check whether the
> cluster containing a delalloc block to be added has been allocated or
> has delalloc reservation, no logic changes.
> 
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/inode.c | 55 ++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 38 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 0c52969654ac..eefedb7264c7 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -1649,6 +1649,35 @@ static void ext4_print_free_blocks(struct inode *inode)
>  	return;
>  }
>  
> +/*
> + * Check whether the cluster containing lblk has been allocated or has
> + * delalloc reservation.
> + *
> + * Returns 0 if the cluster doesn't have either, 1 if it has delalloc
> + * reservation, 2 if it's already been allocated, negative error code on
> + * failure.
> + */
> +static int ext4_clu_alloc_state(struct inode *inode, ext4_lblk_t lblk)
> +{
> +	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
> +	int ret;
> +
> +	/* Has delalloc reservation? */
> +	if (ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk))
> +		return 1;
> +
> +	/* Already been allocated? */
> +	if (ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk))
> +		return 2;
> +	ret = ext4_clu_mapped(inode, EXT4_B2C(sbi, lblk));
> +	if (ret < 0)
> +		return ret;
> +	if (ret > 0)
> +		return 2;
> +
> +	return 0;
> +}
> +
>  /*
>   * ext4_insert_delayed_block - adds a delayed block to the extents status
>   *                             tree, incrementing the reserved cluster/block
> @@ -1682,23 +1711,15 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk)
>  		if (ret != 0)   /* ENOSPC */
>  			return ret;
>  	} else {   /* bigalloc */
> -		if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) {
> -			if (!ext4_es_scan_clu(inode,
> -					      &ext4_es_is_mapped, lblk)) {
> -				ret = ext4_clu_mapped(inode,
> -						      EXT4_B2C(sbi, lblk));
> -				if (ret < 0)
> -					return ret;
> -				if (ret == 0) {
> -					ret = ext4_da_reserve_space(inode, 1);
> -					if (ret != 0)   /* ENOSPC */
> -						return ret;
> -				} else {
> -					allocated = true;
> -				}
> -			} else {
> -				allocated = true;
> -			}
> +		ret = ext4_clu_alloc_state(inode, lblk);
> +		if (ret < 0)
> +			return ret;
> +		if (ret == 2)
> +			allocated = true;
> +		if (ret == 0) {
> +			ret = ext4_da_reserve_space(inode, 1);
> +			if (ret != 0)   /* ENOSPC */
> +				return ret;
>  		}
>  	}
>  
> -- 
> 2.39.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2024-05-20  9:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17 12:39 [PATCH v5 00/10] ext4: support adding multi-delalloc blocks Zhang Yi
2024-05-17 12:39 ` [PATCH v5 01/10] ext4: factor out a common helper to query extent map Zhang Yi
2024-05-17 16:19   ` Markus Elfring
2024-05-17 12:39 ` [PATCH v5 02/10] ext4: check the extent status again before inserting delalloc block Zhang Yi
2024-05-17 12:39 ` [PATCH v5 03/10] ext4: warn if delalloc counters are not zero on inactive Zhang Yi
2024-05-20  9:35   ` Jan Kara
2024-05-17 12:39 ` [PATCH v5 04/10] ext4: trim delalloc extent Zhang Yi
2024-05-17 12:40 ` [PATCH v5 05/10] ext4: drop iblock parameter Zhang Yi
2024-05-17 12:40 ` [PATCH v5 06/10] ext4: make ext4_es_insert_delayed_block() insert multi-blocks Zhang Yi
2024-05-17 12:40 ` [PATCH v5 07/10] ext4: make ext4_da_reserve_space() reserve multi-clusters Zhang Yi
2024-05-17 12:40 ` [PATCH v5 08/10] ext4: factor out a helper to check the cluster allocation state Zhang Yi
2024-05-20  9:37   ` Jan Kara [this message]
2024-05-17 12:40 ` [PATCH v5 09/10] ext4: make ext4_insert_delayed_block() insert multi-blocks Zhang Yi
2024-05-20  9:39   ` Jan Kara
2024-05-17 12:40 ` [PATCH v5 10/10] ext4: make ext4_da_map_blocks() buffer_head unaware Zhang Yi

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=20240520093721.xqrhhn43ldvhoh5y@quack3 \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=chengzhihao1@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    --cc=yi.zhang@huaweicloud.com \
    --cc=yukuai3@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 read-only IMAP folder(s) and NNTP newsgroup(s).