public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeffle Xu <jefflexu@linux.alibaba.com>
To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org,
	chao@kernel.org, linux-erofs@lists.ozlabs.org
Cc: linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com,
	bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com,
	gerry@linux.alibaba.com, eguan@linux.alibaba.com,
	linux-kernel@vger.kernel.org
Subject: [RFC 01/19] cachefiles: add mode command
Date: Fri, 10 Dec 2021 15:36:01 +0800	[thread overview]
Message-ID: <20211210073619.21667-2-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20211210073619.21667-1-jefflexu@linux.alibaba.com>

fscache/cachefiles used to serve as a local cache for remote fs.
This patch set introduces a new use case, in which local read-only
fs could implement demand read with fscache.

Thus 'mode' field is used to distinguish which mode cachefiles works in.
User daemon could set the specified mode with 'mode' command. If user
daemon doesn't ever explicitly set the mode, then cachefiles serves as
the local cache for remote fs by default.

Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
 fs/cachefiles/daemon.c   | 35 +++++++++++++++++++++++++++++++++++
 fs/cachefiles/internal.h |  6 ++++++
 2 files changed, 41 insertions(+)

diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index 40a792421fc1..951963e72b44 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -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 *);
 
@@ -75,6 +76,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				}
 };
 
@@ -663,6 +665,39 @@ 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)
+{
+	enum cachefiles_mode mode;
+
+	_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"))) {
+		mode = CACHEFILES_MODE_CACHE;
+	} else if (!strncmp(args, "demand", strlen("demand"))) {
+		mode = CACHEFILES_MODE_DEMAND;
+	} else {
+		pr_err("Invalid mode specified\n");
+		return -EINVAL;
+	}
+
+	cache->mode = mode;
+	return 0;
+}
+
 /*
  * Bind a directory as a cache
  */
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index f42021b3a0be..1366e4319b4e 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -60,6 +60,11 @@ struct cachefiles_object {
 #define CACHEFILES_OBJECT_USING_TMPFILE	0		/* Have an unlinked tmpfile */
 };
 
+enum cachefiles_mode {
+	CACHEFILES_MODE_CACHE,	/* local cache for netfs (Default) */
+	CACHEFILES_MODE_DEMAND,	/* demand read for read-only fs */
+};
+
 /*
  * Cache files cache definition
  */
@@ -93,6 +98,7 @@ struct cachefiles_cache {
 	sector_t			brun;		/* when to stop culling */
 	sector_t			bcull;		/* when to start culling */
 	sector_t			bstop;		/* when to stop allocating */
+	enum cachefiles_mode		mode;
 	unsigned long			flags;
 #define CACHEFILES_READY		0	/* T if cache prepared */
 #define CACHEFILES_DEAD			1	/* T if cache dead */
-- 
2.27.0


  reply	other threads:[~2021-12-10  7:36 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10  7:36 [RFC 00/19] fscache,erofs: fscache-based demand-read semantics Jeffle Xu
2021-12-10  7:36 ` Jeffle Xu [this message]
2021-12-10 11:05   ` [RFC 01/19] cachefiles: add mode command David Howells
2021-12-11  5:23     ` JeffleXu
2021-12-10  7:36 ` [RFC 02/19] cachefiles: implement key scheme for demand-read mode Jeffle Xu
2021-12-10 11:04   ` David Howells
2021-12-11  5:32     ` JeffleXu
2021-12-10  7:36 ` [RFC 03/19] cachefiles: refactor cachefiles_adjust_size() Jeffle Xu
2021-12-10  7:36 ` [RFC 04/19] netfs: make ops->init_rreq() optional Jeffle Xu
2021-12-10  7:36 ` [RFC 05/19] netfs: refactor netfs_alloc_read_request Jeffle Xu
2021-12-10  7:36 ` [RFC 06/19] netfs: add type field to struct netfs_read_request Jeffle Xu
2021-12-10  7:36 ` [RFC 07/19] netfs: add netfs_readpage_demand() Jeffle Xu
2021-12-10  7:36 ` [RFC 08/19] netfs: refactor netfs_clear_unread() Jeffle Xu
2021-12-10  7:36 ` [RFC 09/19] netfs: refactor netfs_rreq_unlock() Jeffle Xu
2021-12-10 15:41   ` David Howells
2021-12-11  5:23     ` JeffleXu
2021-12-11  5:44       ` [Linux-cachefs] " JeffleXu
2021-12-11  6:57         ` Gao Xiang
2021-12-10  7:36 ` [RFC 10/19] netfs: refactor netfs_rreq_prepare_read Jeffle Xu
2021-12-10  7:36 ` [RFC 11/19] cachefiles: refactor cachefiles_prepare_read Jeffle Xu
2021-12-10  7:36 ` [RFC 12/19] erofs: export erofs_map_blocks Jeffle Xu
2021-12-10  7:36 ` [RFC 13/19] erofs: add bootstrap_path mount option Jeffle Xu
2021-12-10  7:36 ` [RFC 14/19] erofs: introduce fscache support Jeffle Xu
2021-12-10  7:36 ` [RFC 15/19] erofs: implement fscache-based metadata read Jeffle Xu
2021-12-10  7:36 ` [RFC 16/19] erofs: implement fscache-based data read Jeffle Xu
2021-12-10  7:36 ` [RFC 17/19] netfs: support on demand read Jeffle Xu
2021-12-10  7:36 ` [RFC 18/19] cachefiles: " Jeffle Xu
2021-12-10  7:36 ` [RFC 19/19] erofs: " Jeffle Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211210073619.21667-2-jefflexu@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=bo.liu@linux.alibaba.com \
    --cc=chao@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=eguan@linux.alibaba.com \
    --cc=gerry@linux.alibaba.com \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tao.peng@linux.alibaba.com \
    --cc=xiang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox