[PATCH v1 01/23] cachefiles: add cachefiles_demand devnode

Joseph Qi joseph.qi at linux.alibaba.com
Tue Dec 28 13:47:49 AEDT 2021



On 12/27/21 8:54 PM, Jeffle Xu wrote:
> fscache/cachefiles used to serve as a local cache for remote fs. The
> following patches will introduce a new use case, in which local
> read-only fs could implement demand reading with fscache. By then the
> user daemon needs to read and poll on the devnode, and thus the original
> cachefiles devnode can't be reused in this case.
> 
> Thus create a new devnode specifically for the new mode. The following
> patches will add more file_operations.
> 
> Signed-off-by: Jeffle Xu <jefflexu at linux.alibaba.com>
> ---
>  fs/cachefiles/daemon.c   |  8 ++++++++
>  fs/cachefiles/internal.h |  1 +
>  fs/cachefiles/main.c     | 12 ++++++++++++
>  3 files changed, 21 insertions(+)
> 
> diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
> index 40a792421fc1..871f1e0f423d 100644
> --- a/fs/cachefiles/daemon.c
> +++ b/fs/cachefiles/daemon.c
> @@ -56,6 +56,14 @@ const struct file_operations cachefiles_daemon_fops = {
>  	.llseek		= noop_llseek,
>  };
>  
> +const struct file_operations cachefiles_demand_fops = {
> +	.owner		= THIS_MODULE,
> +	.open		= cachefiles_daemon_open,
> +	.release	= cachefiles_daemon_release,
> +	.write		= cachefiles_daemon_write,
> +	.llseek		= noop_llseek,
> +};
> +

Better to prepare the on-demand read() and poll() first, and then add
the on-demand cachefiles dev.

Thanks,
Joseph

>  struct cachefiles_daemon_cmd {
>  	char name[8];
>  	int (*handler)(struct cachefiles_cache *cache, char *args);
> diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
> index 421423819d63..e0ed811d628d 100644
> --- a/fs/cachefiles/internal.h
> +++ b/fs/cachefiles/internal.h
> @@ -145,6 +145,7 @@ extern int cachefiles_has_space(struct cachefiles_cache *cache,
>   * daemon.c
>   */
>  extern const struct file_operations cachefiles_daemon_fops;
> +extern const struct file_operations cachefiles_demand_fops;
>  
>  /*
>   * error_inject.c
> diff --git a/fs/cachefiles/main.c b/fs/cachefiles/main.c
> index 3f369c6f816d..0a423274d283 100644
> --- a/fs/cachefiles/main.c
> +++ b/fs/cachefiles/main.c
> @@ -39,6 +39,12 @@ static struct miscdevice cachefiles_dev = {
>  	.fops	= &cachefiles_daemon_fops,
>  };
>  
> +static struct miscdevice cachefiles_demand_dev = {
> +	.minor	= MISC_DYNAMIC_MINOR,
> +	.name	= "cachefiles_demand",
> +	.fops	= &cachefiles_demand_fops,
> +};
> +
>  /*
>   * initialise the fs caching module
>   */
> @@ -52,6 +58,9 @@ static int __init cachefiles_init(void)
>  	ret = misc_register(&cachefiles_dev);
>  	if (ret < 0)
>  		goto error_dev;
> +	ret = misc_register(&cachefiles_demand_dev);
> +	if (ret < 0)
> +		goto error_demand_dev;
>  
>  	/* create an object jar */
>  	ret = -ENOMEM;
> @@ -68,6 +77,8 @@ static int __init cachefiles_init(void)
>  	return 0;
>  
>  error_object_jar:
> +	misc_deregister(&cachefiles_demand_dev);
> +error_demand_dev:
>  	misc_deregister(&cachefiles_dev);
>  error_dev:
>  	cachefiles_unregister_error_injection();
> @@ -86,6 +97,7 @@ static void __exit cachefiles_exit(void)
>  	pr_info("Unloading\n");
>  
>  	kmem_cache_destroy(cachefiles_object_jar);
> +	misc_deregister(&cachefiles_demand_dev);
>  	misc_deregister(&cachefiles_dev);
>  	cachefiles_unregister_error_injection();
>  }


More information about the Linux-erofs mailing list