Re: [PATCH v6 17/22] erofs: implement fscache-based data read for non-inline layout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 25, 2022 at 08:22:18PM +0800, Jeffle Xu wrote:
> Implements the data plane of reading data from bootstrap blob file over
> fscache for non-inline layout.
> 
> Be noted that compressed layout is not supported yet.
> 
> Signed-off-by: Jeffle Xu <jefflexu@xxxxxxxxxxxxxxxxx>
> ---
>  fs/erofs/fscache.c  | 83 +++++++++++++++++++++++++++++++++++++++++++++
>  fs/erofs/inode.c    |  8 ++++-
>  fs/erofs/internal.h |  5 +++
>  3 files changed, 95 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
> index 91377939b4f7..4a9a4e60c15d 100644
> --- a/fs/erofs/fscache.c
> +++ b/fs/erofs/fscache.c
> @@ -60,10 +60,93 @@ static int erofs_fscache_readpage_blob(struct file *data, struct page *page)
>  	return ret;
>  }
>  
> +static inline int erofs_fscache_get_map(struct erofs_map_blocks *map,
> +					struct super_block *sb)

I wonder if m_fscache should be settled in struct erofs_map_dev

And such helper can be merged into erofs_map_dev() as well.

> +{
> +	struct erofs_sb_info *sbi = EROFS_SB(sb);
> +
> +	map->m_fscache	= sbi->bootstrap;
> +	return 0;
> +}
> +
> +static int erofs_fscache_readpage_noinline(struct folio *folio,
> +					   struct erofs_map_blocks *map)
> +{
> +	struct fscache_cookie *cookie = map->m_fscache->cookie;
> +	/*
> +	 * 1) For FLAT_PLAIN layout, the output map.m_la shall be equal to o_la,
> +	 * and the output map.m_pa is exactly the physical address of o_la.
> +	 * 2) For CHUNK_BASED layout, the output map.m_la is rounded down to the
> +	 * nearest chunk boundary, and the output map.m_pa is actually the
> +	 * physical address of this chunk boundary. So we need to recalculate
> +	 * the actual physical address of o_la.
> +	 */
> +	loff_t start = map->m_pa + (map->o_la - map->m_la);

I think o_la can be directly replaced with "folio_pos(folio)".

Also such helper might be unneeded...

> +
> +	return erofs_fscache_read_folio(cookie, folio, start);
> +}
> +
> +static int erofs_fscache_do_readpage(struct folio *folio)

Can it fold into erofs_fscache_readpage?
Another unneeded helper...

> +{
> +	struct inode *inode = folio_file_mapping(folio)->host;
> +	struct erofs_inode *vi = EROFS_I(inode);
> +	struct super_block *sb = inode->i_sb;
> +	struct erofs_map_blocks map;
> +	int ret;
> +
> +	if (erofs_inode_is_data_compressed(vi->datalayout)) {

It's impossible for now. So the check above is redundant.

Thanks,
Gao Xiang

> +		erofs_info(sb, "compressed layout not supported yet");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	DBG_BUGON(folio_size(folio) != EROFS_BLKSIZ);
> +
> +	map.m_la = map.o_la = folio_pos(folio);
> +
> +	ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
> +	if (ret)
> +		return ret;
> +
> +	if (!(map.m_flags & EROFS_MAP_MAPPED)) {
> +		folio_zero_range(folio, 0, folio_size(folio));
> +		return 0;
> +	}
> +
> +	ret = erofs_fscache_get_map(&map, sb);
> +	if (ret)
> +		return ret;
> +
> +	switch (vi->datalayout) {
> +	case EROFS_INODE_FLAT_PLAIN:
> +	case EROFS_INODE_CHUNK_BASED:
> +		return erofs_fscache_readpage_noinline(folio, &map);
> +	default:
> +		DBG_BUGON(1);
> +		return -EOPNOTSUPP;
> +	}
> +}
> +
> +static int erofs_fscache_readpage(struct file *file, struct page *page)
> +{
> +	struct folio *folio = page_folio(page);
> +	int ret;
> +
> +	ret = erofs_fscache_do_readpage(folio);
> +	if (!ret)
> +		folio_mark_uptodate(folio);
> +
> +	folio_unlock(folio);
> +	return ret;
> +}
> +
>  static const struct address_space_operations erofs_fscache_blob_aops = {
>  	.readpage = erofs_fscache_readpage_blob,
>  };
>  
> +const struct address_space_operations erofs_fscache_access_aops = {
> +	.readpage = erofs_fscache_readpage,
> +};
> +
>  /*
>   * erofs_fscache_get_folio - find and read page cache of blob file
>   * @ctx:	the context of the blob file
> diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
> index ff62f84f47d3..744faf3ef9f4 100644
> --- a/fs/erofs/inode.c
> +++ b/fs/erofs/inode.c
> @@ -296,7 +296,13 @@ static int erofs_fill_inode(struct inode *inode, int isdir)
>  		err = z_erofs_fill_inode(inode);
>  		goto out_unlock;
>  	}
> -	inode->i_mapping->a_ops = &erofs_raw_access_aops;
> +
> +#ifdef CONFIG_EROFS_FS_ONDEMAND
> +	if (erofs_is_nodev_mode(inode->i_sb))
> +		inode->i_mapping->a_ops = &erofs_fscache_access_aops;
> +#endif
> +	if (!erofs_is_nodev_mode(inode->i_sb))
> +		inode->i_mapping->a_ops = &erofs_raw_access_aops;
>  
>  out_unlock:
>  	erofs_put_metabuf(&buf);
> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
> index fa89a1e3012f..6537ededed51 100644
> --- a/fs/erofs/internal.h
> +++ b/fs/erofs/internal.h
> @@ -442,6 +442,9 @@ struct erofs_map_blocks {
>  	unsigned short m_deviceid;
>  	char m_algorithmformat;
>  	unsigned int m_flags;
> +
> +	struct erofs_fscache *m_fscache;
> +	erofs_off_t o_la;
>  };
>  
>  /* Flags used by erofs_map_blocks_flatmode() */
> @@ -634,6 +637,8 @@ struct erofs_fscache *erofs_fscache_get(struct super_block *sb, char *path,
>  void erofs_fscache_put(struct erofs_fscache *ctx);
>  
>  struct folio *erofs_fscache_get_folio(struct erofs_fscache *ctx, pgoff_t index);
> +
> +extern const struct address_space_operations erofs_fscache_access_aops;
>  #else
>  static inline int erofs_init_fscache(void) { return 0; }
>  static inline void erofs_exit_fscache(void) {}
> -- 
> 2.27.0

--
Linux-cachefs mailing list
Linux-cachefs@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/linux-cachefs




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]
  Powered by Linux