| Message ID | 20251107144249.435029-11-libaokun@huaweicloud.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series | ext4: enable block size larger than page size | expand |
On Fri 07-11-25 22:42:35, libaokun@huaweicloud.com wrote: > From: Baokun Li <libaokun1@huawei.com> > > As BS > PS support is coming, all block number to page index (and > vice-versa) conversions must now go via bytes. Added EXT4_LBLK_TO_PG() > and EXT4_PG_TO_LBLK() macros to simplify these conversions and handle > both BS <= PS and BS > PS scenarios cleanly. > > Suggested-by: Jan Kara <jack@suse.cz> > 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/ext4.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h > index c00ce6db69f0..4bc0b2b7288a 100644 > --- a/fs/ext4/ext4.h > +++ b/fs/ext4/ext4.h > @@ -370,6 +370,12 @@ struct ext4_io_submit { > (round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits) > #define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits) > > +/* Translate a block number to a page index */ > +#define EXT4_LBLK_TO_PG(inode, lblk) (EXT4_LBLK_TO_B((inode), (lblk)) >> \ > + PAGE_SHIFT) > +/* Translate a page index to a block number */ > +#define EXT4_PG_TO_LBLK(inode, pnum) (((loff_t)(pnum) << PAGE_SHIFT) >> \ > + (inode)->i_blkbits) > /* Translate a block number to a cluster number */ > #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) > /* Translate a cluster number to a block number */ > -- > 2.46.1 >
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index c00ce6db69f0..4bc0b2b7288a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -370,6 +370,12 @@ struct ext4_io_submit { (round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits) #define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits) +/* Translate a block number to a page index */ +#define EXT4_LBLK_TO_PG(inode, lblk) (EXT4_LBLK_TO_B((inode), (lblk)) >> \ + PAGE_SHIFT) +/* Translate a page index to a block number */ +#define EXT4_PG_TO_LBLK(inode, pnum) (((loff_t)(pnum) << PAGE_SHIFT) >> \ + (inode)->i_blkbits) /* Translate a block number to a cluster number */ #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) /* Translate a cluster number to a block number */