fscache: Implement cache-level access helpers
Add a pair of functions to pin/unpin a cache that we're wanting to do a
high-level access to (such as creating or removing a volume):
bool fscache_begin_cache_access(struct fscache_cache *cache,
enum fscache_access_trace why);
void fscache_end_cache_access(struct fscache_cache *cache,
enum fscache_access_trace why);
The way the access gate works/will work is:
(1) If the cache tests as not live (state is not FSCACHE_CACHE_IS_ACTIVE),
then we return false to indicate access was not permitted.
(2) If the cache tests as live, then we increment the n_accesses count and
then recheck the liveness, ending the access if it ceased to be live.
(3) When we end the access, we decrement n_accesses and wake up the any
waiters if it reaches 0.
(4) Whilst the cache is caching, n_accesses is kept artificially
incremented to prevent wakeups from happening.
(5) When the cache is taken offline, the state is changed to prevent new
accesses, n_accesses is decremented and we wait for n_accesses to
become 0.
Note that some of this is implemented in a later patch.
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/163819593239.215744.7537428720603638088.stgit@warthog.procyon.org.uk/ # v1
Link: https://lore.kernel.org/r/163906893368.143852.14164004598465617981.stgit@warthog.procyon.org.uk/ # v2
Link: https://lore.kernel.org/r/163967093977.1823006.6967886507023056409.stgit@warthog.procyon.org.uk/ # v3
Link: https://lore.kernel.org/r/164021499995.640689.18286203753480287850.stgit@warthog.procyon.org.uk/ # v4
This commit is contained in:
@@ -62,6 +62,12 @@ enum fscache_cookie_trace {
|
||||
fscache_cookie_see_work,
|
||||
};
|
||||
|
||||
enum fscache_access_trace {
|
||||
fscache_access_cache_pin,
|
||||
fscache_access_cache_unpin,
|
||||
fscache_access_unlive,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -107,6 +113,11 @@ enum fscache_cookie_trace {
|
||||
EM(fscache_cookie_see_withdraw, "- x-wth") \
|
||||
E_(fscache_cookie_see_work, "- work ")
|
||||
|
||||
#define fscache_access_traces \
|
||||
EM(fscache_access_cache_pin, "PIN cache ") \
|
||||
EM(fscache_access_cache_unpin, "UNPIN cache ") \
|
||||
E_(fscache_access_unlive, "END unlive ")
|
||||
|
||||
/*
|
||||
* Export enum symbols via userspace.
|
||||
*/
|
||||
@@ -118,6 +129,7 @@ enum fscache_cookie_trace {
|
||||
fscache_cache_traces;
|
||||
fscache_volume_traces;
|
||||
fscache_cookie_traces;
|
||||
fscache_access_traces;
|
||||
|
||||
/*
|
||||
* Now redefine the EM() and E_() macros to map the enums to the strings that
|
||||
@@ -204,6 +216,35 @@ TRACE_EVENT(fscache_cookie,
|
||||
__entry->ref)
|
||||
);
|
||||
|
||||
TRACE_EVENT(fscache_access_cache,
|
||||
TP_PROTO(unsigned int cache_debug_id,
|
||||
int ref,
|
||||
int n_accesses,
|
||||
enum fscache_access_trace why),
|
||||
|
||||
TP_ARGS(cache_debug_id, ref, n_accesses, why),
|
||||
|
||||
TP_STRUCT__entry(
|
||||
__field(unsigned int, cache )
|
||||
__field(int, ref )
|
||||
__field(int, n_accesses )
|
||||
__field(enum fscache_access_trace, why )
|
||||
),
|
||||
|
||||
TP_fast_assign(
|
||||
__entry->cache = cache_debug_id;
|
||||
__entry->ref = ref;
|
||||
__entry->n_accesses = n_accesses;
|
||||
__entry->why = why;
|
||||
),
|
||||
|
||||
TP_printk("C=%08x %s r=%d a=%d",
|
||||
__entry->cache,
|
||||
__print_symbolic(__entry->why, fscache_access_traces),
|
||||
__entry->ref,
|
||||
__entry->n_accesses)
|
||||
);
|
||||
|
||||
TRACE_EVENT(fscache_acquire,
|
||||
TP_PROTO(struct fscache_cookie *cookie),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user