diff mbox series

[v3,05/12] ext4: passing block allocation information to ext4_es_insert_extent()

Message ID 20240813123452.2824659-6-yi.zhang@huaweicloud.com (mailing list archive)
State New
Headers show
Series ext4: simplify the counting and management of delalloc reserved blocks | expand

Commit Message

Zhang Yi Aug. 13, 2024, 12:34 p.m. UTC
From: Zhang Yi <yi.zhang@huawei.com>

Just pass the block allocation flag to ext4_es_insert_extent() when we
replacing a current extent after an actually block allocation or extent
status conversion, this flag will be used by later changes.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/extents.c        | 5 +++--
 fs/ext4/extents_status.c | 6 +++---
 fs/ext4/extents_status.h | 2 +-
 fs/ext4/inode.c          | 8 ++++----
 4 files changed, 11 insertions(+), 10 deletions(-)

Comments

Jan Kara Sept. 4, 2024, 10:21 a.m. UTC | #1
On Tue 13-08-24 20:34:45, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> Just pass the block allocation flag to ext4_es_insert_extent() when we
> replacing a current extent after an actually block allocation or extent
> status conversion, this flag will be used by later changes.
> 
> Suggested-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>

Looks good. Just one suggestion below. With that feel free to add:

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

> @@ -848,7 +848,7 @@ static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
>   */
>  void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
>  			   ext4_lblk_t len, ext4_fsblk_t pblk,
> -			   unsigned int status)
> +			   unsigned int status, int flags)

Since you pass flags to ext4_es_insert_extent() only from one place, let's
not pretend these are always full mapping flags and just make this new
argument:

bool delalloc_reserve_used

and from ext4_map_blocks_create() you can pass flags &
EXT4_GET_BLOCKS_DELALLOC_RESERVE.

								Honza
Zhang Yi Sept. 4, 2024, 11:43 a.m. UTC | #2
On 2024/9/4 18:21, Jan Kara wrote:
> On Tue 13-08-24 20:34:45, Zhang Yi wrote:
>> From: Zhang Yi <yi.zhang@huawei.com>
>>
>> Just pass the block allocation flag to ext4_es_insert_extent() when we
>> replacing a current extent after an actually block allocation or extent
>> status conversion, this flag will be used by later changes.
>>
>> Suggested-by: Jan Kara <jack@suse.cz>
>> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> 
> Looks good. Just one suggestion below. With that feel free to add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> 
>> @@ -848,7 +848,7 @@ static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
>>   */
>>  void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
>>  			   ext4_lblk_t len, ext4_fsblk_t pblk,
>> -			   unsigned int status)
>> +			   unsigned int status, int flags)
> 
> Since you pass flags to ext4_es_insert_extent() only from one place, let's
> not pretend these are always full mapping flags and just make this new
> argument:
> 
> bool delalloc_reserve_used
> 
> and from ext4_map_blocks_create() you can pass flags &
> EXT4_GET_BLOCKS_DELALLOC_RESERVE.
> 

Sure, it's a better idea than passing full mapping flags, thanks for your
suggestion, but since I've noticed that Ted had already picked this series
into his dev branch, I can send another patch to do this. Thanks a lot for
reviewing this series again!

Yi.
diff mbox series

Patch

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index e067f2dd0335..671dacd7c873 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3113,7 +3113,7 @@  static void ext4_zeroout_es(struct inode *inode, struct ext4_extent *ex)
 		return;
 
 	ext4_es_insert_extent(inode, ee_block, ee_len, ee_pblock,
-			      EXTENT_STATUS_WRITTEN);
+			      EXTENT_STATUS_WRITTEN, 0);
 }
 
 /* FIXME!! we need to try to merge to left or right after zero-out  */
@@ -4097,7 +4097,8 @@  static ext4_lblk_t ext4_ext_determine_insert_hole(struct inode *inode,
 insert_hole:
 	/* Put just found gap into cache to speed up subsequent requests */
 	ext_debug(inode, " -> %u:%u\n", hole_start, len);
-	ext4_es_insert_extent(inode, hole_start, len, ~0, EXTENT_STATUS_HOLE);
+	ext4_es_insert_extent(inode, hole_start, len, ~0,
+			      EXTENT_STATUS_HOLE, 0);
 
 	/* Update hole_len to reflect hole size after lblk */
 	if (hole_start != lblk)
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 4d24b56cfaf0..0580bc4bc762 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -848,7 +848,7 @@  static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
  */
 void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
 			   ext4_lblk_t len, ext4_fsblk_t pblk,
-			   unsigned int status)
+			   unsigned int status, int flags)
 {
 	struct extent_status newes;
 	ext4_lblk_t end = lblk + len - 1;
@@ -862,8 +862,8 @@  void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
 	if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)
 		return;
 
-	es_debug("add [%u/%u) %llu %x to extent status tree of inode %lu\n",
-		 lblk, len, pblk, status, inode->i_ino);
+	es_debug("add [%u/%u) %llu %x %x to extent status tree of inode %lu\n",
+		 lblk, len, pblk, status, flags, inode->i_ino);
 
 	if (!len)
 		return;
diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
index 3c8e2edee5d5..b74d693c1adb 100644
--- a/fs/ext4/extents_status.h
+++ b/fs/ext4/extents_status.h
@@ -129,7 +129,7 @@  extern void ext4_es_init_tree(struct ext4_es_tree *tree);
 
 extern void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
 				  ext4_lblk_t len, ext4_fsblk_t pblk,
-				  unsigned int status);
+				  unsigned int status, int flags);
 extern void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
 				 ext4_lblk_t len, ext4_fsblk_t pblk,
 				 unsigned int status);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e9ce1e4e6acb..260a38453604 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -478,7 +478,7 @@  static int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
 	status = map->m_flags & EXT4_MAP_UNWRITTEN ?
 			EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
 	ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
-			      map->m_pblk, status);
+			      map->m_pblk, status, 0);
 	return retval;
 }
 
@@ -559,7 +559,7 @@  static int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
 	status = map->m_flags & EXT4_MAP_UNWRITTEN ?
 			EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
 	ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
-			      map->m_pblk, status);
+			      map->m_pblk, status, flags);
 
 	return retval;
 }
@@ -677,7 +677,7 @@  int ext4_map_blocks(handle_t *handle, struct inode *inode,
 		status = map->m_flags & EXT4_MAP_UNWRITTEN ?
 				EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
 		ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
-				      map->m_pblk, status);
+				      map->m_pblk, status, 0);
 	}
 	up_read((&EXT4_I(inode)->i_data_sem));
 
@@ -4065,7 +4065,7 @@  int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
 						    stop_block);
 
 		ext4_es_insert_extent(inode, first_block, hole_len, ~0,
-				      EXTENT_STATUS_HOLE);
+				      EXTENT_STATUS_HOLE, 0);
 		up_write(&EXT4_I(inode)->i_data_sem);
 	}
 	ext4_fc_track_range(handle, inode, first_block, stop_block);