mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-07-19 03:59:45 +02:00

Provide a function to begin a read operation: int fscache_begin_read_operation( struct netfs_cache_resources *cres, struct fscache_cookie *cookie) This is primarily intended to be called by network filesystems on behalf of netfslib, but may also be called to use the I/O access functions directly. It attaches the resources required by the cache to cres struct from the supplied cookie. This holds access to the cache behind the cookie for the duration of the operation and forces cache withdrawal and cookie invalidation to perform synchronisation on the operation. cres->inval_counter is set from the cookie at this point so that it can be compared at the end of the operation. Note that this does not guarantee that the cache state is fully set up and able to perform I/O immediately; looking up and creation may be left in progress in the background. The operations intended to be called by the network filesystem, such as reading and writing, are expected to wait for the cookie to move to the correct state. This will, however, potentially sleep, waiting for a certain minimum state to be set or for operations such as invalidate to advance far enough that I/O can resume. Also provide a function for the cache to call to wait for the cache object to get to a state where it can be used for certain things: bool fscache_wait_for_operation(struct netfs_cache_resources *cres, enum fscache_want_stage stage); This looks at the cache resources provided by the begin function and waits for them to get to an appropriate stage. There's a choice of wanting just some parameters (FSCACHE_WANT_PARAM) or the ability to do I/O (FSCACHE_WANT_READ or FSCACHE_WANT_WRITE). Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> cc: linux-cachefs@redhat.com Link: https://lore.kernel.org/r/163819603692.215744.146724961588817028.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906910672.143852.13856103384424986357.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967110245.1823006.2239170567540431836.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021513617.640689.16627329360866150606.stgit@warthog.procyon.org.uk/ # v4
144 lines
4.6 KiB
C
144 lines
4.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/* General filesystem caching backing cache interface
|
|
*
|
|
* Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*
|
|
* NOTE!!! See:
|
|
*
|
|
* Documentation/filesystems/caching/backend-api.rst
|
|
*
|
|
* for a description of the cache backend interface declared here.
|
|
*/
|
|
|
|
#ifndef _LINUX_FSCACHE_CACHE_H
|
|
#define _LINUX_FSCACHE_CACHE_H
|
|
|
|
#include <linux/fscache.h>
|
|
|
|
enum fscache_cache_trace;
|
|
enum fscache_cookie_trace;
|
|
enum fscache_access_trace;
|
|
|
|
enum fscache_cache_state {
|
|
FSCACHE_CACHE_IS_NOT_PRESENT, /* No cache is present for this name */
|
|
FSCACHE_CACHE_IS_PREPARING, /* A cache is preparing to come live */
|
|
FSCACHE_CACHE_IS_ACTIVE, /* Attached cache is active and can be used */
|
|
FSCACHE_CACHE_GOT_IOERROR, /* Attached cache stopped on I/O error */
|
|
FSCACHE_CACHE_IS_WITHDRAWN, /* Attached cache is being withdrawn */
|
|
#define NR__FSCACHE_CACHE_STATE (FSCACHE_CACHE_IS_WITHDRAWN + 1)
|
|
};
|
|
|
|
/*
|
|
* Cache cookie.
|
|
*/
|
|
struct fscache_cache {
|
|
const struct fscache_cache_ops *ops;
|
|
struct list_head cache_link; /* Link in cache list */
|
|
void *cache_priv; /* Private cache data (or NULL) */
|
|
refcount_t ref;
|
|
atomic_t n_volumes; /* Number of active volumes; */
|
|
atomic_t n_accesses; /* Number of in-progress accesses on the cache */
|
|
atomic_t object_count; /* no. of live objects in this cache */
|
|
unsigned int debug_id;
|
|
enum fscache_cache_state state;
|
|
char *name;
|
|
};
|
|
|
|
/*
|
|
* cache operations
|
|
*/
|
|
struct fscache_cache_ops {
|
|
/* name of cache provider */
|
|
const char *name;
|
|
|
|
/* Acquire a volume */
|
|
void (*acquire_volume)(struct fscache_volume *volume);
|
|
|
|
/* Free the cache's data attached to a volume */
|
|
void (*free_volume)(struct fscache_volume *volume);
|
|
|
|
/* Look up a cookie in the cache */
|
|
bool (*lookup_cookie)(struct fscache_cookie *cookie);
|
|
|
|
/* Withdraw an object without any cookie access counts held */
|
|
void (*withdraw_cookie)(struct fscache_cookie *cookie);
|
|
|
|
/* Invalidate an object */
|
|
bool (*invalidate_cookie)(struct fscache_cookie *cookie);
|
|
|
|
/* Begin an operation for the netfs lib */
|
|
bool (*begin_operation)(struct netfs_cache_resources *cres,
|
|
enum fscache_want_state want_state);
|
|
|
|
/* Prepare to write to a live cache object */
|
|
void (*prepare_to_write)(struct fscache_cookie *cookie);
|
|
};
|
|
|
|
extern struct workqueue_struct *fscache_wq;
|
|
|
|
/*
|
|
* out-of-line cache backend functions
|
|
*/
|
|
extern struct rw_semaphore fscache_addremove_sem;
|
|
extern struct fscache_cache *fscache_acquire_cache(const char *name);
|
|
extern void fscache_relinquish_cache(struct fscache_cache *cache);
|
|
extern int fscache_add_cache(struct fscache_cache *cache,
|
|
const struct fscache_cache_ops *ops,
|
|
void *cache_priv);
|
|
extern void fscache_withdraw_cache(struct fscache_cache *cache);
|
|
extern void fscache_withdraw_volume(struct fscache_volume *volume);
|
|
extern void fscache_withdraw_cookie(struct fscache_cookie *cookie);
|
|
|
|
extern void fscache_io_error(struct fscache_cache *cache);
|
|
|
|
extern void fscache_end_volume_access(struct fscache_volume *volume,
|
|
struct fscache_cookie *cookie,
|
|
enum fscache_access_trace why);
|
|
|
|
extern struct fscache_cookie *fscache_get_cookie(struct fscache_cookie *cookie,
|
|
enum fscache_cookie_trace where);
|
|
extern void fscache_put_cookie(struct fscache_cookie *cookie,
|
|
enum fscache_cookie_trace where);
|
|
extern void fscache_end_cookie_access(struct fscache_cookie *cookie,
|
|
enum fscache_access_trace why);
|
|
extern void fscache_cookie_lookup_negative(struct fscache_cookie *cookie);
|
|
extern void fscache_resume_after_invalidation(struct fscache_cookie *cookie);
|
|
extern void fscache_caching_failed(struct fscache_cookie *cookie);
|
|
extern bool fscache_wait_for_operation(struct netfs_cache_resources *cred,
|
|
enum fscache_want_state state);
|
|
|
|
/**
|
|
* fscache_cookie_state - Read the state of a cookie
|
|
* @cookie: The cookie to query
|
|
*
|
|
* Get the state of a cookie, imposing an ordering between the cookie contents
|
|
* and the state value. Paired with fscache_set_cookie_state().
|
|
*/
|
|
static inline
|
|
enum fscache_cookie_state fscache_cookie_state(struct fscache_cookie *cookie)
|
|
{
|
|
return smp_load_acquire(&cookie->state);
|
|
}
|
|
|
|
/**
|
|
* fscache_get_key - Get a pointer to the cookie key
|
|
* @cookie: The cookie to query
|
|
*
|
|
* Return a pointer to the where a cookie's key is stored.
|
|
*/
|
|
static inline void *fscache_get_key(struct fscache_cookie *cookie)
|
|
{
|
|
if (cookie->key_len <= sizeof(cookie->inline_key))
|
|
return cookie->inline_key;
|
|
else
|
|
return cookie->key;
|
|
}
|
|
|
|
static inline struct fscache_cookie *fscache_cres_cookie(struct netfs_cache_resources *cres)
|
|
{
|
|
return cres->cache_priv;
|
|
}
|
|
|
|
#endif /* _LINUX_FSCACHE_CACHE_H */
|