[RFC 02/19] cachefiles: implement key scheme for demand-read mode

From: Jeffle Xu
Date: Fri Dec 10 2021 - 02:36:48 EST


In demand-read mode, user daemon may prepare data blob files in advance
before they are lookud up.

Thus simplify the logic of placing backing files, in which backing files
are under "cache/<volume>/" directory directly.

Also skip coherency checking currently to ease the development and debug.

Signed-off-by: Jeffle Xu <jefflexu@xxxxxxxxxxxxxxxxx>
---
fs/cachefiles/namei.c | 8 +++++++-
fs/cachefiles/xattr.c | 5 +++++
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 61d412580353..981e6e80690b 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -603,11 +603,17 @@ static bool cachefiles_open_file(struct cachefiles_object *object,
bool cachefiles_look_up_object(struct cachefiles_object *object)
{
struct cachefiles_volume *volume = object->volume;
- struct dentry *dentry, *fan = volume->fanout[(u8)object->cookie->key_hash];
+ struct cachefiles_cache *cache = volume->cache;
+ struct dentry *dentry, *fan;
int ret;

_enter("OBJ%x,%s,", object->debug_id, object->d_name);

+ if (cache->mode == CACHEFILES_MODE_CACHE)
+ fan = volume->fanout[(u8)object->cookie->key_hash];
+ else
+ fan = volume->dentry;
+
/* Look up path "cache/vol/fanout/file". */
ret = cachefiles_inject_read_error();
if (ret == 0)
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index 0601c46a22ef..f562dd0d4bdd 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -88,6 +88,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
*/
int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file)
{
+ struct cachefiles_cache *cache = object->volume->cache;
struct cachefiles_xattr *buf;
struct dentry *dentry = file->f_path.dentry;
unsigned int len = object->cookie->aux_len, tlen;
@@ -96,6 +97,10 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file
ssize_t xlen;
int ret = -ESTALE;

+ /* TODO: coherency check */
+ if (cache->mode == CACHEFILES_MODE_DEMAND)
+ return 0;
+
tlen = sizeof(struct cachefiles_xattr) + len;
buf = kmalloc(tlen, GFP_KERNEL);
if (!buf)
--
2.27.0