Commit 493f7bc1 authored by David Howells's avatar David Howells

FS-Cache: Wrap checks on object state

Wrap checks on object state (mostly outside of fs/fscache/object.c) with
inline functions so that the mechanism can be replaced.

Some of the state checks within object.c are left as-is as they will be
replaced.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Tested-By: default avatarMilosz Tanski <milosz@adfin.com>
Acked-by: default avatarJeff Layton <jlayton@redhat.com>
parent 610be24e
...@@ -130,7 +130,7 @@ static void cachefiles_mark_object_buried(struct cachefiles_cache *cache, ...@@ -130,7 +130,7 @@ static void cachefiles_mark_object_buried(struct cachefiles_cache *cache,
fscache_object_states[object->fscache.state], fscache_object_states[object->fscache.state],
dentry); dentry);
if (object->fscache.state < FSCACHE_OBJECT_DYING) { if (fscache_object_is_live(&object->fscache)) {
printk(KERN_ERR "\n"); printk(KERN_ERR "\n");
printk(KERN_ERR "CacheFiles: Error:" printk(KERN_ERR "CacheFiles: Error:"
" Can't preemptively bury live object\n"); " Can't preemptively bury live object\n");
...@@ -192,7 +192,7 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache, ...@@ -192,7 +192,7 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache,
/* an old object from a previous incarnation is hogging the slot - we /* an old object from a previous incarnation is hogging the slot - we
* need to wait for it to be destroyed */ * need to wait for it to be destroyed */
wait_for_old_object: wait_for_old_object:
if (xobject->fscache.state < FSCACHE_OBJECT_DYING) { if (fscache_object_is_live(&object->fscache)) {
printk(KERN_ERR "\n"); printk(KERN_ERR "\n");
printk(KERN_ERR "CacheFiles: Error:" printk(KERN_ERR "CacheFiles: Error:"
" Unexpected object collision\n"); " Unexpected object collision\n");
......
...@@ -115,7 +115,7 @@ struct fscache_cache *fscache_select_cache_for_object( ...@@ -115,7 +115,7 @@ struct fscache_cache *fscache_select_cache_for_object(
struct fscache_object, cookie_link); struct fscache_object, cookie_link);
cache = object->cache; cache = object->cache;
if (object->state >= FSCACHE_OBJECT_DYING || if (fscache_object_is_dying(object) ||
test_bit(FSCACHE_IOERROR, &cache->flags)) test_bit(FSCACHE_IOERROR, &cache->flags))
cache = NULL; cache = NULL;
......
...@@ -285,7 +285,7 @@ static int fscache_alloc_object(struct fscache_cache *cache, ...@@ -285,7 +285,7 @@ static int fscache_alloc_object(struct fscache_cache *cache,
object_already_extant: object_already_extant:
ret = -ENOBUFS; ret = -ENOBUFS;
if (object->state >= FSCACHE_OBJECT_DYING) { if (fscache_object_is_dead(object)) {
spin_unlock(&cookie->lock); spin_unlock(&cookie->lock);
goto error; goto error;
} }
...@@ -321,7 +321,7 @@ static int fscache_attach_object(struct fscache_cookie *cookie, ...@@ -321,7 +321,7 @@ static int fscache_attach_object(struct fscache_cookie *cookie,
ret = -EEXIST; ret = -EEXIST;
hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) {
if (p->cache == object->cache) { if (p->cache == object->cache) {
if (p->state >= FSCACHE_OBJECT_DYING) if (fscache_object_is_dying(p))
ret = -ENOBUFS; ret = -ENOBUFS;
goto cant_attach_object; goto cant_attach_object;
} }
...@@ -332,7 +332,7 @@ static int fscache_attach_object(struct fscache_cookie *cookie, ...@@ -332,7 +332,7 @@ static int fscache_attach_object(struct fscache_cookie *cookie,
hlist_for_each_entry(p, &cookie->parent->backing_objects, hlist_for_each_entry(p, &cookie->parent->backing_objects,
cookie_link) { cookie_link) {
if (p->cache == object->cache) { if (p->cache == object->cache) {
if (p->state >= FSCACHE_OBJECT_DYING) { if (fscache_object_is_dying(p)) {
ret = -ENOBUFS; ret = -ENOBUFS;
spin_unlock(&cookie->parent->lock); spin_unlock(&cookie->parent->lock);
goto cant_attach_object; goto cant_attach_object;
...@@ -400,7 +400,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie) ...@@ -400,7 +400,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
object = hlist_entry(cookie->backing_objects.first, object = hlist_entry(cookie->backing_objects.first,
struct fscache_object, struct fscache_object,
cookie_link); cookie_link);
if (object->state < FSCACHE_OBJECT_DYING) if (fscache_object_is_live(object))
fscache_raise_event( fscache_raise_event(
object, FSCACHE_OBJECT_EV_INVALIDATE); object, FSCACHE_OBJECT_EV_INVALIDATE);
} }
......
...@@ -457,10 +457,10 @@ static void fscache_initialise_object(struct fscache_object *object) ...@@ -457,10 +457,10 @@ static void fscache_initialise_object(struct fscache_object *object)
spin_lock_nested(&parent->lock, 1); spin_lock_nested(&parent->lock, 1);
_debug("parent %s", fscache_object_states[parent->state]); _debug("parent %s", fscache_object_states[parent->state]);
if (parent->state >= FSCACHE_OBJECT_DYING) { if (fscache_object_is_dying(parent)) {
_debug("bad parent"); _debug("bad parent");
set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events); set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events);
} else if (parent->state < FSCACHE_OBJECT_AVAILABLE) { } else if (!fscache_object_is_available(parent)) {
_debug("wait"); _debug("wait");
/* we may get woken up in this state by child objects /* we may get woken up in this state by child objects
...@@ -517,9 +517,9 @@ static void fscache_lookup_object(struct fscache_object *object) ...@@ -517,9 +517,9 @@ static void fscache_lookup_object(struct fscache_object *object)
ASSERTCMP(parent->n_obj_ops, >, 0); ASSERTCMP(parent->n_obj_ops, >, 0);
/* make sure the parent is still available */ /* make sure the parent is still available */
ASSERTCMP(parent->state, >=, FSCACHE_OBJECT_AVAILABLE); ASSERT(fscache_object_is_available(parent));
if (parent->state >= FSCACHE_OBJECT_DYING || if (fscache_object_is_dying(parent) ||
test_bit(FSCACHE_IOERROR, &object->cache->flags)) { test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
_debug("unavailable"); _debug("unavailable");
set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events); set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events);
......
...@@ -35,7 +35,7 @@ void fscache_enqueue_operation(struct fscache_operation *op) ...@@ -35,7 +35,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
ASSERT(list_empty(&op->pend_link)); ASSERT(list_empty(&op->pend_link));
ASSERT(op->processor != NULL); ASSERT(op->processor != NULL);
ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE); ASSERT(fscache_object_is_available(op->object));
ASSERTCMP(atomic_read(&op->usage), >, 0); ASSERTCMP(atomic_read(&op->usage), >, 0);
ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS); ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
......
...@@ -417,15 +417,6 @@ struct fscache_object { ...@@ -417,15 +417,6 @@ struct fscache_object {
extern const char *fscache_object_states[]; extern const char *fscache_object_states[];
#define fscache_object_is_active(obj) \
(!test_bit(FSCACHE_IOERROR, &(obj)->cache->flags) && \
(obj)->state >= FSCACHE_OBJECT_AVAILABLE && \
(obj)->state < FSCACHE_OBJECT_DYING)
#define fscache_object_is_dead(obj) \
(test_bit(FSCACHE_IOERROR, &(obj)->cache->flags) && \
(obj)->state >= FSCACHE_OBJECT_DYING)
extern void fscache_object_init(struct fscache_object *, struct fscache_cookie *, extern void fscache_object_init(struct fscache_object *, struct fscache_cookie *,
struct fscache_cache *); struct fscache_cache *);
...@@ -438,6 +429,34 @@ extern void fscache_object_destroy(struct fscache_object *object); ...@@ -438,6 +429,34 @@ extern void fscache_object_destroy(struct fscache_object *object);
#define fscache_object_destroy(object) do {} while(0) #define fscache_object_destroy(object) do {} while(0)
#endif #endif
static inline bool fscache_object_is_live(struct fscache_object *object)
{
return object->state < FSCACHE_OBJECT_DYING;
}
static inline bool fscache_object_is_dying(struct fscache_object *object)
{
return !fscache_object_is_live(object);
}
static inline bool fscache_object_is_available(struct fscache_object *object)
{
return object->state >= FSCACHE_OBJECT_AVAILABLE;
}
static inline bool fscache_object_is_active(struct fscache_object *object)
{
return fscache_object_is_available(object) &&
fscache_object_is_live(object) &&
!test_bit(FSCACHE_IOERROR, &object->cache->flags);
}
static inline bool fscache_object_is_dead(struct fscache_object *object)
{
return fscache_object_is_dying(object) &&
test_bit(FSCACHE_IOERROR, &object->cache->flags);
}
/** /**
* fscache_object_destroyed - Note destruction of an object in a cache * fscache_object_destroyed - Note destruction of an object in a cache
* @cache: The cache from which the object came * @cache: The cache from which the object came
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment