mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-09 07:51:16 -04:00
FS-Cache: Add use/unuse/wake cookie wrappers
Add wrapper functions for dealing with cookie->n_active:
(*) __fscache_use_cookie() to increment it.
(*) __fscache_unuse_cookie() to decrement and test against zero.
(*) __fscache_wake_unused_cookie() to wake up anyone waiting for it to reach
zero.
The second and third are split so that the third can be done after cookie->lock
has been released in case the waiter wakes up whilst we're still holding it and
tries to get it.
We will need to wake-on-zero once the cookie disablement patch is applied
because it will then be possible to see n_active become zero without the cookie
being relinquished.
Also move the cookie usement out of fscache_attr_changed_op() and into
fscache_attr_changed() and the operation struct so that cookie disablement
will be able to track it.
Whilst we're at it, only increment n_active if we're about to do
fscache_submit_op() so that we don't have to deal with undoing it if anything
earlier fails. Possibly this should be moved into fscache_submit_op() which
could look at FSCACHE_OP_UNUSE_COOKIE.
Signed-off-by: David Howells <dhowells@redhat.com>
This commit is contained in:
@@ -511,6 +511,11 @@ static inline void fscache_end_io(struct fscache_retrieval *op,
|
||||
op->end_io_func(page, op->context, error);
|
||||
}
|
||||
|
||||
static inline void __fscache_use_cookie(struct fscache_cookie *cookie)
|
||||
{
|
||||
atomic_inc(&cookie->n_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* fscache_use_cookie - Request usage of cookie attached to an object
|
||||
* @object: Object description
|
||||
@@ -524,6 +529,16 @@ static inline bool fscache_use_cookie(struct fscache_object *object)
|
||||
return atomic_inc_not_zero(&cookie->n_active) != 0;
|
||||
}
|
||||
|
||||
static inline bool __fscache_unuse_cookie(struct fscache_cookie *cookie)
|
||||
{
|
||||
return atomic_dec_and_test(&cookie->n_active);
|
||||
}
|
||||
|
||||
static inline void __fscache_wake_unused_cookie(struct fscache_cookie *cookie)
|
||||
{
|
||||
wake_up_atomic_t(&cookie->n_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* fscache_unuse_cookie - Cease usage of cookie attached to an object
|
||||
* @object: Object description
|
||||
@@ -534,8 +549,8 @@ static inline bool fscache_use_cookie(struct fscache_object *object)
|
||||
static inline void fscache_unuse_cookie(struct fscache_object *object)
|
||||
{
|
||||
struct fscache_cookie *cookie = object->cookie;
|
||||
if (atomic_dec_and_test(&cookie->n_active))
|
||||
wake_up_atomic_t(&cookie->n_active);
|
||||
if (__fscache_unuse_cookie(cookie))
|
||||
__fscache_wake_unused_cookie(cookie);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user