mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00
cachefiles: extract ondemand info field from cachefiles_object
We'll introduce a @work_struct field for @object in subsequent patches, it will enlarge the size of @object. As the result of that, this commit extracts ondemand info field from @object. Signed-off-by: Jia Zhu <zhujia.zj@bytedance.com> Link: https://lore.kernel.org/r/20231120041422.75170-3-zhujia.zj@bytedance.com Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com> Reviewed-by: David Howells <dhowells@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
357a18d033
commit
3c5ecfe16e
3 changed files with 56 additions and 11 deletions
|
@ -31,6 +31,11 @@ struct cachefiles_object *cachefiles_alloc_object(struct fscache_cookie *cookie)
|
||||||
if (!object)
|
if (!object)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (cachefiles_ondemand_init_obj_info(object, volume)) {
|
||||||
|
kmem_cache_free(cachefiles_object_jar, object);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
refcount_set(&object->ref, 1);
|
refcount_set(&object->ref, 1);
|
||||||
|
|
||||||
spin_lock_init(&object->lock);
|
spin_lock_init(&object->lock);
|
||||||
|
@ -88,7 +93,7 @@ void cachefiles_put_object(struct cachefiles_object *object,
|
||||||
ASSERTCMP(object->file, ==, NULL);
|
ASSERTCMP(object->file, ==, NULL);
|
||||||
|
|
||||||
kfree(object->d_name);
|
kfree(object->d_name);
|
||||||
|
cachefiles_ondemand_deinit_obj_info(object);
|
||||||
cache = object->volume->cache->cache;
|
cache = object->volume->cache->cache;
|
||||||
fscache_put_cookie(object->cookie, fscache_cookie_put_object);
|
fscache_put_cookie(object->cookie, fscache_cookie_put_object);
|
||||||
object->cookie = NULL;
|
object->cookie = NULL;
|
||||||
|
|
|
@ -49,6 +49,12 @@ enum cachefiles_object_state {
|
||||||
CACHEFILES_ONDEMAND_OBJSTATE_OPEN, /* Anonymous fd associated with object is available */
|
CACHEFILES_ONDEMAND_OBJSTATE_OPEN, /* Anonymous fd associated with object is available */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct cachefiles_ondemand_info {
|
||||||
|
int ondemand_id;
|
||||||
|
enum cachefiles_object_state state;
|
||||||
|
struct cachefiles_object *object;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Backing file state.
|
* Backing file state.
|
||||||
*/
|
*/
|
||||||
|
@ -66,8 +72,7 @@ struct cachefiles_object {
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
#define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */
|
#define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */
|
||||||
#ifdef CONFIG_CACHEFILES_ONDEMAND
|
#ifdef CONFIG_CACHEFILES_ONDEMAND
|
||||||
int ondemand_id;
|
struct cachefiles_ondemand_info *ondemand;
|
||||||
enum cachefiles_object_state state;
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -302,17 +307,21 @@ extern void cachefiles_ondemand_clean_object(struct cachefiles_object *object);
|
||||||
extern int cachefiles_ondemand_read(struct cachefiles_object *object,
|
extern int cachefiles_ondemand_read(struct cachefiles_object *object,
|
||||||
loff_t pos, size_t len);
|
loff_t pos, size_t len);
|
||||||
|
|
||||||
|
extern int cachefiles_ondemand_init_obj_info(struct cachefiles_object *obj,
|
||||||
|
struct cachefiles_volume *volume);
|
||||||
|
extern void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj);
|
||||||
|
|
||||||
#define CACHEFILES_OBJECT_STATE_FUNCS(_state, _STATE) \
|
#define CACHEFILES_OBJECT_STATE_FUNCS(_state, _STATE) \
|
||||||
static inline bool \
|
static inline bool \
|
||||||
cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \
|
cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \
|
||||||
{ \
|
{ \
|
||||||
return object->state == CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \
|
return object->ondemand->state == CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \
|
cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \
|
||||||
{ \
|
{ \
|
||||||
object->state = CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \
|
object->ondemand->state = CACHEFILES_ONDEMAND_OBJSTATE_##_STATE; \
|
||||||
}
|
}
|
||||||
|
|
||||||
CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN);
|
CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN);
|
||||||
|
@ -338,6 +347,15 @@ static inline int cachefiles_ondemand_read(struct cachefiles_object *object,
|
||||||
{
|
{
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *obj,
|
||||||
|
struct cachefiles_volume *volume)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj)
|
||||||
|
{
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -9,12 +9,13 @@ static int cachefiles_ondemand_fd_release(struct inode *inode,
|
||||||
{
|
{
|
||||||
struct cachefiles_object *object = file->private_data;
|
struct cachefiles_object *object = file->private_data;
|
||||||
struct cachefiles_cache *cache = object->volume->cache;
|
struct cachefiles_cache *cache = object->volume->cache;
|
||||||
int object_id = object->ondemand_id;
|
struct cachefiles_ondemand_info *info = object->ondemand;
|
||||||
|
int object_id = info->ondemand_id;
|
||||||
struct cachefiles_req *req;
|
struct cachefiles_req *req;
|
||||||
XA_STATE(xas, &cache->reqs, 0);
|
XA_STATE(xas, &cache->reqs, 0);
|
||||||
|
|
||||||
xa_lock(&cache->reqs);
|
xa_lock(&cache->reqs);
|
||||||
object->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED;
|
info->ondemand_id = CACHEFILES_ONDEMAND_ID_CLOSED;
|
||||||
cachefiles_ondemand_set_object_close(object);
|
cachefiles_ondemand_set_object_close(object);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -222,7 +223,7 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req)
|
||||||
load = (void *)req->msg.data;
|
load = (void *)req->msg.data;
|
||||||
load->fd = fd;
|
load->fd = fd;
|
||||||
req->msg.object_id = object_id;
|
req->msg.object_id = object_id;
|
||||||
object->ondemand_id = object_id;
|
object->ondemand->ondemand_id = object_id;
|
||||||
|
|
||||||
cachefiles_get_unbind_pincount(cache);
|
cachefiles_get_unbind_pincount(cache);
|
||||||
trace_cachefiles_ondemand_open(object, &req->msg, load);
|
trace_cachefiles_ondemand_open(object, &req->msg, load);
|
||||||
|
@ -368,7 +369,7 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object,
|
||||||
|
|
||||||
if (opcode != CACHEFILES_OP_OPEN &&
|
if (opcode != CACHEFILES_OP_OPEN &&
|
||||||
!cachefiles_ondemand_object_is_open(object)) {
|
!cachefiles_ondemand_object_is_open(object)) {
|
||||||
WARN_ON_ONCE(object->ondemand_id == 0);
|
WARN_ON_ONCE(object->ondemand->ondemand_id == 0);
|
||||||
xas_unlock(&xas);
|
xas_unlock(&xas);
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -438,7 +439,7 @@ static int cachefiles_ondemand_init_close_req(struct cachefiles_req *req,
|
||||||
if (!cachefiles_ondemand_object_is_open(object))
|
if (!cachefiles_ondemand_object_is_open(object))
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
req->msg.object_id = object->ondemand_id;
|
req->msg.object_id = object->ondemand->ondemand_id;
|
||||||
trace_cachefiles_ondemand_close(object, &req->msg);
|
trace_cachefiles_ondemand_close(object, &req->msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +455,7 @@ static int cachefiles_ondemand_init_read_req(struct cachefiles_req *req,
|
||||||
struct cachefiles_object *object = req->object;
|
struct cachefiles_object *object = req->object;
|
||||||
struct cachefiles_read *load = (void *)req->msg.data;
|
struct cachefiles_read *load = (void *)req->msg.data;
|
||||||
struct cachefiles_read_ctx *read_ctx = private;
|
struct cachefiles_read_ctx *read_ctx = private;
|
||||||
int object_id = object->ondemand_id;
|
int object_id = object->ondemand->ondemand_id;
|
||||||
|
|
||||||
/* Stop enqueuing requests when daemon has closed anon_fd. */
|
/* Stop enqueuing requests when daemon has closed anon_fd. */
|
||||||
if (!cachefiles_ondemand_object_is_open(object)) {
|
if (!cachefiles_ondemand_object_is_open(object)) {
|
||||||
|
@ -500,6 +501,27 @@ void cachefiles_ondemand_clean_object(struct cachefiles_object *object)
|
||||||
cachefiles_ondemand_init_close_req, NULL);
|
cachefiles_ondemand_init_close_req, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cachefiles_ondemand_init_obj_info(struct cachefiles_object *object,
|
||||||
|
struct cachefiles_volume *volume)
|
||||||
|
{
|
||||||
|
if (!cachefiles_in_ondemand_mode(volume->cache))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
object->ondemand = kzalloc(sizeof(struct cachefiles_ondemand_info),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!object->ondemand)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
object->ondemand->object = object;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *object)
|
||||||
|
{
|
||||||
|
kfree(object->ondemand);
|
||||||
|
object->ondemand = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int cachefiles_ondemand_read(struct cachefiles_object *object,
|
int cachefiles_ondemand_read(struct cachefiles_object *object,
|
||||||
loff_t pos, size_t len)
|
loff_t pos, size_t len)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue