@@ -41,6 +41,7 @@ static int cachefiles_daemon_dir(struct cachefiles_cache *, char *);
static int cachefiles_daemon_inuse(struct cachefiles_cache *, char *);
static int cachefiles_daemon_secctx(struct cachefiles_cache *, char *);
static int cachefiles_daemon_tag(struct cachefiles_cache *, char *);
+static int cachefiles_daemon_mode(struct cachefiles_cache *, char *);
static int cachefiles_daemon_bind(struct cachefiles_cache *, char *);
static void cachefiles_daemon_unbind(struct cachefiles_cache *);
@@ -83,6 +84,7 @@ static const struct cachefiles_daemon_cmd cachefiles_daemon_cmds[] = {
{ "inuse", cachefiles_daemon_inuse },
{ "secctx", cachefiles_daemon_secctx },
{ "tag", cachefiles_daemon_tag },
+ { "mode", cachefiles_daemon_mode },
{ "", NULL }
};
@@ -671,6 +673,36 @@ static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
return -EINVAL;
}
+/*
+ * Set the cache mode
+ * - command: "mode cache|demand"
+ */
+static int cachefiles_daemon_mode(struct cachefiles_cache *cache, char *args)
+{
+ _enter(",%s", args);
+
+ if (test_bit(CACHEFILES_READY, &cache->flags)) {
+ pr_err("Cache already started\n");
+ return -EINVAL;
+ }
+
+ if (!*args) {
+ pr_err("Empty mode specified\n");
+ return -EINVAL;
+ }
+
+ if (!strncmp(args, "cache", strlen("cache"))) {
+ clear_bit(CACHEFILES_DEMAND_MODE, &cache->flags);
+ } else if (!strncmp(args, "demand", strlen("demand"))) {
+ set_bit(CACHEFILES_DEMAND_MODE, &cache->flags);
+ } else {
+ pr_err("Invalid mode specified\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
/*
* Bind a directory as a cache
*/
@@ -98,6 +98,7 @@ struct cachefiles_cache {
#define CACHEFILES_DEAD 1 /* T if cache dead */
#define CACHEFILES_CULLING 2 /* T if cull engaged */
#define CACHEFILES_STATE_CHANGED 3 /* T if state changed (poll trigger) */
+#define CACHEFILES_DEMAND_MODE 4 /* T if works in demand read mode for read-only fs */
char *rootdirname; /* name of cache root directory */
char *secctx; /* LSM security context */
char *tag; /* cache binding tag */
Add one flag bit to distinguish the new introduced demand-read mode from the original mode. User daemon could set the specified mode with 'mode' command. If user daemon doesn't ever explicitly set the mode, then the behaviour is the same with that prior this patch, i.e. cachefiles serves as the local cache for remote fs by default. Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com> --- fs/cachefiles/daemon.c | 32 ++++++++++++++++++++++++++++++++ fs/cachefiles/internal.h | 1 + 2 files changed, 33 insertions(+)