2020-12-08 13:17:55

by Huang Jianan

[permalink] [raw]
Subject: [PATCH v3] erofs: avoiding using generic_block_bmap

iblock indicates the number of i_blkbits-sized blocks rather than
sectors.

In addition, considering buffer_head limits mapped size to 32-bits,
should avoid using generic_block_bmap.

Fixes: 9da681e017a3 ("staging: erofs: support bmap")
Signed-off-by: Huang Jianan <[email protected]>
Signed-off-by: Guo Weichao <[email protected]>
---
fs/erofs/data.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 347be146884c..399ffd857c50 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -312,36 +312,26 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
submit_bio(bio);
}

-static int erofs_get_block(struct inode *inode, sector_t iblock,
- struct buffer_head *bh, int create)
-{
- struct erofs_map_blocks map = {
- .m_la = iblock << 9,
- };
- int err;
-
- err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
- if (err)
- return err;
-
- if (map.m_flags & EROFS_MAP_MAPPED)
- bh->b_blocknr = erofs_blknr(map.m_pa);
-
- return err;
-}
-
static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
{
struct inode *inode = mapping->host;
+ struct erofs_map_blocks map = {
+ .m_la = blknr_to_addr(iblock),
+ };
+ sector_t blknr = 0;

if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;

if (block >> LOG_SECTORS_PER_BLOCK >= blks)
- return 0;
+ goto out;
}

- return generic_block_bmap(mapping, block, erofs_get_block);
+ if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
+ blknr = erofs_blknr(map.m_pa);
+
+out:
+ return blknr;
}

/* for uncompressed (aligned) files and raw access for other files */
--
2.25.1


2020-12-09 02:38:34

by Huang Jianan

[permalink] [raw]
Subject: Re: [PATCH v3] erofs: avoiding using generic_block_bmap


?? 2020/12/8 21:11, Huang Jianan д??:
> iblock indicates the number of i_blkbits-sized blocks rather than
> sectors.
>
> In addition, considering buffer_head limits mapped size to 32-bits,
> should avoid using generic_block_bmap.
>
> Fixes: 9da681e017a3 ("staging: erofs: support bmap")
> Signed-off-by: Huang Jianan <[email protected]>
> Signed-off-by: Guo Weichao <[email protected]>
> ---
> fs/erofs/data.c | 30 ++++++++++--------------------
> 1 file changed, 10 insertions(+), 20 deletions(-)
>
> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
> index 347be146884c..399ffd857c50 100644
> --- a/fs/erofs/data.c
> +++ b/fs/erofs/data.c
> @@ -312,36 +312,26 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
> submit_bio(bio);
> }
>
> -static int erofs_get_block(struct inode *inode, sector_t iblock,
> - struct buffer_head *bh, int create)
> -{
> - struct erofs_map_blocks map = {
> - .m_la = iblock << 9,
> - };
> - int err;
> -
> - err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
> - if (err)
> - return err;
> -
> - if (map.m_flags & EROFS_MAP_MAPPED)
> - bh->b_blocknr = erofs_blknr(map.m_pa);
> -
> - return err;
> -}
> -
> static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
> {
> struct inode *inode = mapping->host;
> + struct erofs_map_blocks map = {
> + .m_la = blknr_to_addr(iblock),

Sorry for my mistake, it should be:

.m_la = blknr_to_addr(block),

> + };
> + sector_t blknr = 0;
>
> if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
> erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
>
> if (block >> LOG_SECTORS_PER_BLOCK >= blks)
> - return 0;
> + goto out;
> }
>
> - return generic_block_bmap(mapping, block, erofs_get_block);
> + if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
> + blknr = erofs_blknr(map.m_pa);
> +
> +out:
> + return blknr;
> }
>
> /* for uncompressed (aligned) files and raw access for other files */

2020-12-09 03:02:00

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH v3] erofs: avoiding using generic_block_bmap

On 2020/12/9 10:44, Gao Xiang wrote:
> Hi Jianan and Chao,
>
> On Wed, Dec 09, 2020 at 10:34:54AM +0800, Huang Jianan wrote:
>>
>> 在 2020/12/8 21:11, Huang Jianan 写道:
>
> ...
>
>>> -
>>> static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
>>> {
>>> struct inode *inode = mapping->host;
>>> + struct erofs_map_blocks map = {
>>> + .m_la = blknr_to_addr(iblock),
>>
>> Sorry for my mistake, it should be:
>>
>> .m_la = blknr_to_addr(block),
>>
>
> Sigh, since my ro_fsstress doesn't cover bmap interface... I mean do we need
> to add some testcase for this? (But it needs to be fixed anyway, plus this patch
> looks good to me....)
>
> Hi Chao,
> could you kindly leave some free slot for this patch and
>
> erofs: force inplace I/O under low memory scenario
> https://lore.kernel.org/r/[email protected]

Will review soon. :)

Thanks,

>
> Since I'd like to merge these all for 5.11-rc1 (so we could have more time to
> test until the next LTS version), since 5.10 is a LTS version, I tend to not
> introduce any big modification (so in the past months, "erofs: force inplace
> I/O under low memory scenario" never upstreamed at all.)
>
> Thanks,
> Gao Xiang
>
>
> .
>

2020-12-09 03:37:19

by Gao Xiang

[permalink] [raw]
Subject: Re: [PATCH v3] erofs: avoiding using generic_block_bmap

Hi Jianan and Chao,

On Wed, Dec 09, 2020 at 10:34:54AM +0800, Huang Jianan wrote:
>
> 在 2020/12/8 21:11, Huang Jianan 写道:

...

> > -
> > static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
> > {
> > struct inode *inode = mapping->host;
> > + struct erofs_map_blocks map = {
> > + .m_la = blknr_to_addr(iblock),
>
> Sorry for my mistake, it should be:
>
> .m_la = blknr_to_addr(block),
>

Sigh, since my ro_fsstress doesn't cover bmap interface... I mean do we need
to add some testcase for this? (But it needs to be fixed anyway, plus this patch
looks good to me....)

Hi Chao,
could you kindly leave some free slot for this patch and

erofs: force inplace I/O under low memory scenario
https://lore.kernel.org/r/[email protected]

Since I'd like to merge these all for 5.11-rc1 (so we could have more time to
test until the next LTS version), since 5.10 is a LTS version, I tend to not
introduce any big modification (so in the past months, "erofs: force inplace
I/O under low memory scenario" never upstreamed at all.)

Thanks,
Gao Xiang