[PATCH 19/25] ext4: support large block size in mpage_prepare_extent_to_map()

libaokun@huaweicloud.com posted 25 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH 19/25] ext4: support large block size in mpage_prepare_extent_to_map()
Posted by libaokun@huaweicloud.com 3 months, 2 weeks ago
From: Baokun Li <libaokun1@huawei.com>

Use the EXT4_P_TO_LBLK/EXT4_LBLK_TO_P macros to complete the conversion
between folio indexes and blocks to avoid negative left/right shifts after
supporting blocksize greater than PAGE_SIZE.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/inode.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index cbf04b473ae7..ce48cc6780a3 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2610,7 +2610,6 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 	pgoff_t end = mpd->end_pos >> PAGE_SHIFT;
 	xa_mark_t tag;
 	int i, err = 0;
-	int blkbits = mpd->inode->i_blkbits;
 	ext4_lblk_t lblk;
 	struct buffer_head *head;
 	handle_t *handle = NULL;
@@ -2649,7 +2648,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 			 */
 			if (mpd->wbc->sync_mode == WB_SYNC_NONE &&
 			    mpd->wbc->nr_to_write <=
-			    mpd->map.m_len >> (PAGE_SHIFT - blkbits))
+			    EXT4_LBLK_TO_P(mpd->inode, mpd->map.m_len))
 				goto out;
 
 			/* If we can't merge this page, we are done. */
@@ -2727,8 +2726,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 				mpage_folio_done(mpd, folio);
 			} else {
 				/* Add all dirty buffers to mpd */
-				lblk = ((ext4_lblk_t)folio->index) <<
-					(PAGE_SHIFT - blkbits);
+				lblk = EXT4_P_TO_LBLK(mpd->inode, folio->index);
 				head = folio_buffers(folio);
 				err = mpage_process_page_bufs(mpd, head, head,
 						lblk);
-- 
2.46.1
Re: [PATCH 19/25] ext4: support large block size in mpage_prepare_extent_to_map()
Posted by Jan Kara 3 months ago
On Sat 25-10-25 11:22:15, libaokun@huaweicloud.com wrote:
> From: Baokun Li <libaokun1@huawei.com>
> 
> Use the EXT4_P_TO_LBLK/EXT4_LBLK_TO_P macros to complete the conversion
> between folio indexes and blocks to avoid negative left/right shifts after
> supporting blocksize greater than PAGE_SIZE.
> 
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
> Reviewed-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 | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index cbf04b473ae7..ce48cc6780a3 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -2610,7 +2610,6 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
>  	pgoff_t end = mpd->end_pos >> PAGE_SHIFT;
>  	xa_mark_t tag;
>  	int i, err = 0;
> -	int blkbits = mpd->inode->i_blkbits;
>  	ext4_lblk_t lblk;
>  	struct buffer_head *head;
>  	handle_t *handle = NULL;
> @@ -2649,7 +2648,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
>  			 */
>  			if (mpd->wbc->sync_mode == WB_SYNC_NONE &&
>  			    mpd->wbc->nr_to_write <=
> -			    mpd->map.m_len >> (PAGE_SHIFT - blkbits))
> +			    EXT4_LBLK_TO_P(mpd->inode, mpd->map.m_len))
>  				goto out;
>  
>  			/* If we can't merge this page, we are done. */
> @@ -2727,8 +2726,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
>  				mpage_folio_done(mpd, folio);
>  			} else {
>  				/* Add all dirty buffers to mpd */
> -				lblk = ((ext4_lblk_t)folio->index) <<
> -					(PAGE_SHIFT - blkbits);
> +				lblk = EXT4_P_TO_LBLK(mpd->inode, folio->index);
>  				head = folio_buffers(folio);
>  				err = mpage_process_page_bufs(mpd, head, head,
>  						lblk);
> -- 
> 2.46.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR