fscache: Implement simple cookie state machine
Implement a very simple cookie state machine to handle lookup, invalidation, withdrawal, relinquishment and, to be added later, commit on LRU discard. Three cache methods are provided: ->lookup_cookie() to look up and, if necessary, create a data storage object; ->withdraw_cookie() to free the resources associated with that object and potentially delete it; and ->prepare_to_write(), to do prepare for changes to the cached data to be modified locally. Changes ======= ver #3: - Fix a race between LRU discard and relinquishment whereby the former would override the latter and thus the latter would never happen[1]. ver #2: - Don't hold n_accesses elevated whilst cache is bound to a cookie, but rather add a flag that prevents the state machine from being queued when n_accesses reaches 0. 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/599331.1639410068@warthog.procyon.org.uk/ [1] Link: https://lore.kernel.org/r/163819599657.215744.15799615296912341745.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906903925.143852.1805855338154353867.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967105456.1823006.14730395299835841776.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021510706.640689.7961423370243272583.stgit@warthog.procyon.org.uk/ # v4
This commit is contained in:
parent
29f18e79fe
commit
5d00e426f9
3 changed files with 303 additions and 47 deletions
|
|
@ -57,6 +57,15 @@ struct fscache_cache_ops {
|
|||
|
||||
/* 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);
|
||||
|
||||
/* Prepare to write to a live cache object */
|
||||
void (*prepare_to_write)(struct fscache_cookie *cookie);
|
||||
};
|
||||
|
||||
extern struct workqueue_struct *fscache_wq;
|
||||
|
|
@ -72,6 +81,7 @@ extern int fscache_add_cache(struct fscache_cache *cache,
|
|||
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);
|
||||
|
||||
|
|
@ -85,8 +95,21 @@ 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_set_cookie_state(struct fscache_cookie *cookie,
|
||||
enum fscache_cookie_state state);
|
||||
extern void fscache_cookie_lookup_negative(struct fscache_cookie *cookie);
|
||||
extern void fscache_caching_failed(struct fscache_cookie *cookie);
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue