[PATCH 2/2] erofs-utils: add per-sbi buffer support

Gao Xiang hsiangkao at linux.alibaba.com
Wed Jul 10 17:15:28 AEST 2024



On 2024/7/10 14:59, Hongzhen Luo wrote:
> This updates all relevant function definitions and callers
> to get rid of the global g_sbi, making it suitable for external
> use in liberofs.
> 
> Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
> ---
>   include/erofs/cache.h    |  42 ++++++----
>   include/erofs/internal.h |   5 +-
>   lib/blobchunk.c          |  20 ++---
>   lib/cache.c              | 162 +++++++++++++++++++++------------------
>   lib/compress.c           |  40 +++++-----
>   lib/inode.c              |  43 ++++++-----
>   lib/super.c              |  21 ++---
>   lib/xattr.c              |  10 +--
>   mkfs/main.c              |  15 ++--
>   9 files changed, 198 insertions(+), 160 deletions(-)
> 
> diff --git a/include/erofs/cache.h b/include/erofs/cache.h
> index 288843e..16148ea 100644
> --- a/include/erofs/cache.h
> +++ b/include/erofs/cache.h
> @@ -53,10 +53,20 @@ struct erofs_buffer_block {
>   	struct erofs_buffer_head buffers;
>   };
>   
> -static inline const int get_alignsize(int type, int *type_ret)
> -{
> -	struct erofs_sb_info *sbi = &g_sbi;
> +struct erofs_buffer_manager {
> +	struct erofs_buffer_block blkh;
> +	erofs_blk_t tail_blkaddr, erofs_metablkcnt;
> +
> +	/* buckets for all mapped buffer blocks to boost up allocation */
> +	struct list_head mapped_buckets[META + 1][EROFS_MAX_BLOCK_SIZE];
>   
> +	/* last mapped buffer block to accelerate erofs_mapbh() */
> +	struct erofs_buffer_block *last_mapped_block;
> +};
> +
> +static inline const int get_alignsize(struct erofs_sb_info *sbi, int type,
> +				      int *type_ret)
> +{
>   	if (type == DATA)
>   		return erofs_blksiz(sbi);
>   
> @@ -82,10 +92,10 @@ static inline const int get_alignsize(int type, int *type_ret)
>   extern const struct erofs_bhops erofs_drop_directly_bhops;
>   extern const struct erofs_bhops erofs_skip_write_bhops;
>   
> -static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)
> +static inline erofs_off_t erofs_btell(struct erofs_sb_info *sbi,
> +				      struct erofs_buffer_head *bh, bool end)


Actually I think you could just use bh->block->buffers.fsprivate
to keep sbi, so that interfaces which involve
"struct erofs_buffer_head *" don't need to change.

>   {
>   	const struct erofs_buffer_block *bb = bh->block;
> -	struct erofs_sb_info *sbi = &g_sbi;
>   
>   	if (bb->blkaddr == NULL_ADDR)
>   		return NULL_ADDR_UL;
> @@ -101,20 +111,26 @@ static inline int erofs_bh_flush_generic_end(struct erofs_buffer_head *bh)
>   	return 0;
>   }
>   
> -void erofs_buffer_init(erofs_blk_t startblk);
> -int erofs_bh_balloon(struct erofs_buffer_head *bh, erofs_off_t incr);
> +void erofs_buffer_init(struct erofs_sb_info *sbi, erofs_blk_t startblk);
> +int erofs_bh_balloon(struct erofs_sb_info *sbi, struct erofs_buffer_head *bh,
> +		     erofs_off_t incr);

Same here.

>   
> -struct erofs_buffer_head *erofs_balloc(int type, erofs_off_t size,
> +struct erofs_buffer_head *erofs_balloc(struct erofs_sb_info *sbi,
> +				       int type, erofs_off_t size,
>   				       unsigned int required_ext,
>   				       unsigned int inline_ext);
> -struct erofs_buffer_head *erofs_battach(struct erofs_buffer_head *bh,
> +struct erofs_buffer_head *erofs_battach(struct erofs_sb_info *sbi,
> +					struct erofs_buffer_head *bh,
>   					int type, unsigned int size);

Same here.

>   
> -void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke);
> -erofs_blk_t erofs_total_metablocks(void);
> +void erofs_bdrop(struct erofs_sb_info *sbi, struct erofs_buffer_head *bh,
> +		 bool tryrevoke);

...

Thanks,
Gao Xiang


More information about the Linux-erofs mailing list