Linux-ext4 Archive mirror
 help / color / mirror / Atom feed
From: Zhang Yi <yi.zhang@huaweicloud.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, ritesh.list@gmail.com,
	yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH v3 08/10] ext4: factor out check for whether a cluster is allocated
Date: Tue, 14 May 2024 10:37:51 +0800	[thread overview]
Message-ID: <0d2c6419-0dad-1bd5-92fe-2239ef6809e0@huaweicloud.com> (raw)
In-Reply-To: <20240512154037.x6icodkj2zmzeqtg@quack3>

On 2024/5/12 23:40, Jan Kara wrote:
> On Wed 08-05-24 14:12:18, Zhang Yi wrote:
>> From: Zhang Yi <yi.zhang@huawei.com>
>>
>> Factor out a common helper ext4_da_check_clu_allocated(), check whether
>> the cluster containing a delalloc block to be added has been delayed or
>> allocated, no logic changes.
>>
>> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> 
> I have one suggestion for improvement here.
> 
>> +/*
>> + * Check whether the cluster containing lblk has been delayed or allocated,
>> + * if not, it means we should reserve a cluster when add delalloc, return 1,
>> + * otherwise return 0 or error code.
>> + */
>> +static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk,
>> +				       bool *allocated)
> 
> The name of the function does not quite match what it is returning and that
> is confusing. Essentially we have three states here:
> 
> a) cluster allocated
> b) cluster has delalloc reservation
> c) cluster doesn't have either
> 
> So maybe we could call the function ext4_clu_alloc_state() and return 0 /
> 1 / 2 based on the state?
> 
> 								Honza

Sure, thanks for the suggestion, it looks better.

Thanks,
Yi.

> 
>> +{
>> +	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
>> +	int ret;
>> +
>> +	*allocated = false;
>> +	if (ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk))
>> +		return 0;
>> +
>> +	if (ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk))
>> +		goto allocated;
>> +
>> +	ret = ext4_clu_mapped(inode, EXT4_B2C(sbi, lblk));
>> +	if (ret < 0)
>> +		return ret;
>> +	if (ret == 0)
>> +		return 1;
>> +allocated:
>> +	*allocated = true;
>> +	return 0;
>> +}
>> +
>>  /*
>>   * ext4_insert_delayed_block - adds a delayed block to the extents status
>>   *                             tree, incrementing the reserved cluster/block
>> @@ -1682,23 +1710,13 @@ 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_da_check_clu_allocated(inode, lblk, &allocated);
>> +		if (ret < 0)
>> +			return ret;
>> +		if (ret > 0) {
>> +			ret = ext4_da_reserve_space(inode, 1);
>> +			if (ret != 0)   /* ENOSPC */
>> +				return ret;
>>  		}
>>  	}
>>  
>> -- 
>> 2.39.2
>>


  reply	other threads:[~2024-05-14  2:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08  6:12 [PATCH v3 00/10] ext4: support adding multi-delalloc blocks Zhang Yi
2024-05-08  6:12 ` [PATCH v3 01/10] ext4: factor out a common helper to query extent map Zhang Yi
2024-05-08  6:12 ` [PATCH v3 02/10] ext4: check the extent status again before inserting delalloc block Zhang Yi
2024-05-08 15:02   ` Markus Elfring
2024-05-09  8:26     ` Zhang Yi
2024-05-08  6:12 ` [PATCH v3 03/10] ext4: warn if delalloc counters are not zero on inactive Zhang Yi
2024-05-12 15:10   ` Jan Kara
2024-05-13 14:17     ` Zhang Yi
2024-05-08  6:12 ` [PATCH v3 04/10] ext4: trim delalloc extent Zhang Yi
2024-05-08 15:21   ` Markus Elfring
2024-05-09  8:27     ` Zhang Yi
2024-05-08  6:12 ` [PATCH v3 05/10] ext4: drop iblock parameter Zhang Yi
2024-05-08  6:12 ` [PATCH v3 06/10] ext4: make ext4_es_insert_delayed_block() insert multi-blocks Zhang Yi
2024-05-12 15:19   ` Jan Kara
2024-05-08  6:12 ` [PATCH v3 07/10] ext4: make ext4_da_reserve_space() reserve multi-clusters Zhang Yi
2024-05-08  6:12 ` [PATCH v3 08/10] ext4: factor out check for whether a cluster is allocated Zhang Yi
2024-05-12 15:40   ` Jan Kara
2024-05-14  2:37     ` Zhang Yi [this message]
2024-05-08  6:12 ` [PATCH v3 09/10] ext4: make ext4_insert_delayed_block() insert multi-blocks Zhang Yi
2024-05-12 21:47   ` Jan Kara
2024-05-08  6:12 ` [PATCH v3 10/10] ext4: make ext4_da_map_blocks() buffer_head unaware Zhang Yi
2024-05-12 21:51   ` Jan Kara

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=0d2c6419-0dad-1bd5-92fe-2239ef6809e0@huaweicloud.com \
    --to=yi.zhang@huaweicloud.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=chengzhihao1@huawei.com \
    --cc=jack@suse.cz \
    --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=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).