diff mbox series

[v11,06/22] cachefiles: enable on-demand read mode

Message ID 20220509074028.74954-7-jefflexu@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series fscache,erofs: fscache-based on-demand read semantics | expand

Commit Message

Jingbo Xu May 9, 2022, 7:40 a.m. UTC
Enable on-demand read mode by adding an optional parameter to the "bind"
command.

On-demand mode will be turned on when this parameter is "ondemand", i.e.
"bind ondemand". Otherwise cachefiles will work in the original mode.

Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
 fs/cachefiles/daemon.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

David Howells May 10, 2022, 12:56 p.m. UTC | #1
Jeffle Xu <jefflexu@linux.alibaba.com> wrote:

> Enable on-demand read mode by adding an optional parameter to the "bind"
> command.
> 
> On-demand mode will be turned on when this parameter is "ondemand", i.e.
> "bind ondemand". Otherwise cachefiles will work in the original mode.
> 
> Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>

Acked-by: David Howells <dhowells@redhat.com>
Gao Xiang May 10, 2022, 1:29 p.m. UTC | #2
On Tue, May 10, 2022 at 01:56:36PM +0100, David Howells wrote:
> Jeffle Xu <jefflexu@linux.alibaba.com> wrote:
> 
> > Enable on-demand read mode by adding an optional parameter to the "bind"
> > command.
> > 
> > On-demand mode will be turned on when this parameter is "ondemand", i.e.
> > "bind ondemand". Otherwise cachefiles will work in the original mode.
> > 
> > Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
> 
> Acked-by: David Howells <dhowells@redhat.com>

Thank you very much, David! Thanks for your so much time and patience!

Many thanks!
Gao Xiang
diff mbox series

Patch

diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index 5b1d0642c749..aa4efcabb5e3 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -755,11 +755,6 @@  static int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
 	    cache->brun_percent  >= 100)
 		return -ERANGE;
 
-	if (*args) {
-		pr_err("'bind' command doesn't take an argument\n");
-		return -EINVAL;
-	}
-
 	if (!cache->rootdirname) {
 		pr_err("No cache directory specified\n");
 		return -EINVAL;
@@ -771,6 +766,18 @@  static int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
 		return -EBUSY;
 	}
 
+	if (IS_ENABLED(CONFIG_CACHEFILES_ONDEMAND)) {
+		if (!strcmp(args, "ondemand")) {
+			set_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags);
+		} else if (*args) {
+			pr_err("Invalid argument to the 'bind' command\n");
+			return -EINVAL;
+		}
+	} else if (*args) {
+		pr_err("'bind' command doesn't take an argument\n");
+		return -EINVAL;
+	}
+
 	/* Make sure we have copies of the tag string */
 	if (!cache->tag) {
 		/*