Skip to content

Commit 493f7bc

Browse files
committed
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: David Howells <dhowells@redhat.com> Tested-By: Milosz Tanski <milosz@adfin.com> Acked-by: Jeff Layton <jlayton@redhat.com>
1 parent 610be24 commit 493f7bc

6 files changed

Lines changed: 40 additions & 21 deletions

File tree

‎fs/cachefiles/namei.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static void cachefiles_mark_object_buried(struct cachefiles_cache *cache,
130130
fscache_object_states[object->fscache.state],
131131
dentry);
132132

133-
if (object->fscache.state < FSCACHE_OBJECT_DYING) {
133+
if (fscache_object_is_live(&object->fscache)) {
134134
printk(KERN_ERR "\n");
135135
printk(KERN_ERR "CacheFiles: Error:"
136136
" Can't preemptively bury live object\n");
@@ -192,7 +192,7 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache,
192192
/* an old object from a previous incarnation is hogging the slot - we
193193
* need to wait for it to be destroyed */
194194
wait_for_old_object:
195-
if (xobject->fscache.state < FSCACHE_OBJECT_DYING) {
195+
if (fscache_object_is_live(&object->fscache)) {
196196
printk(KERN_ERR "\n");
197197
printk(KERN_ERR "CacheFiles: Error:"
198198
" Unexpected object collision\n");

‎fs/fscache/cache.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct fscache_cache *fscache_select_cache_for_object(
115115
struct fscache_object, cookie_link);
116116

117117
cache = object->cache;
118-
if (object->state >= FSCACHE_OBJECT_DYING ||
118+
if (fscache_object_is_dying(object) ||
119119
test_bit(FSCACHE_IOERROR, &cache->flags))
120120
cache = NULL;
121121

‎fs/fscache/cookie.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int fscache_alloc_object(struct fscache_cache *cache,
285285

286286
object_already_extant:
287287
ret = -ENOBUFS;
288-
if (object->state >= FSCACHE_OBJECT_DYING) {
288+
if (fscache_object_is_dead(object)) {
289289
spin_unlock(&cookie->lock);
290290
goto error;
291291
}
@@ -321,7 +321,7 @@ static int fscache_attach_object(struct fscache_cookie *cookie,
321321
ret = -EEXIST;
322322
hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) {
323323
if (p->cache == object->cache) {
324-
if (p->state >= FSCACHE_OBJECT_DYING)
324+
if (fscache_object_is_dying(p))
325325
ret = -ENOBUFS;
326326
goto cant_attach_object;
327327
}
@@ -332,7 +332,7 @@ static int fscache_attach_object(struct fscache_cookie *cookie,
332332
hlist_for_each_entry(p, &cookie->parent->backing_objects,
333333
cookie_link) {
334334
if (p->cache == object->cache) {
335-
if (p->state >= FSCACHE_OBJECT_DYING) {
335+
if (fscache_object_is_dying(p)) {
336336
ret = -ENOBUFS;
337337
spin_unlock(&cookie->parent->lock);
338338
goto cant_attach_object;
@@ -400,7 +400,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
400400
object = hlist_entry(cookie->backing_objects.first,
401401
struct fscache_object,
402402
cookie_link);
403-
if (object->state < FSCACHE_OBJECT_DYING)
403+
if (fscache_object_is_live(object))
404404
fscache_raise_event(
405405
object, FSCACHE_OBJECT_EV_INVALIDATE);
406406
}

‎fs/fscache/object.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ static void fscache_initialise_object(struct fscache_object *object)
457457
spin_lock_nested(&parent->lock, 1);
458458
_debug("parent %s", fscache_object_states[parent->state]);
459459

460-
if (parent->state >= FSCACHE_OBJECT_DYING) {
460+
if (fscache_object_is_dying(parent)) {
461461
_debug("bad parent");
462462
set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events);
463-
} else if (parent->state < FSCACHE_OBJECT_AVAILABLE) {
463+
} else if (!fscache_object_is_available(parent)) {
464464
_debug("wait");
465465

466466
/* we may get woken up in this state by child objects
@@ -517,9 +517,9 @@ static void fscache_lookup_object(struct fscache_object *object)
517517
ASSERTCMP(parent->n_obj_ops, >, 0);
518518

519519
/* make sure the parent is still available */
520-
ASSERTCMP(parent->state, >=, FSCACHE_OBJECT_AVAILABLE);
520+
ASSERT(fscache_object_is_available(parent));
521521

522-
if (parent->state >= FSCACHE_OBJECT_DYING ||
522+
if (fscache_object_is_dying(parent) ||
523523
test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
524524
_debug("unavailable");
525525
set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events);

‎fs/fscache/operation.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
3535

3636
ASSERT(list_empty(&op->pend_link));
3737
ASSERT(op->processor != NULL);
38-
ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
38+
ASSERT(fscache_object_is_available(op->object));
3939
ASSERTCMP(atomic_read(&op->usage), >, 0);
4040
ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
4141

‎include/linux/fscache-cache.h‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,6 @@ struct fscache_object {
417417

418418
extern const char *fscache_object_states[];
419419

420-
#define fscache_object_is_active(obj) \
421-
(!test_bit(FSCACHE_IOERROR, &(obj)->cache->flags) && \
422-
(obj)->state >= FSCACHE_OBJECT_AVAILABLE && \
423-
(obj)->state < FSCACHE_OBJECT_DYING)
424-
425-
#define fscache_object_is_dead(obj) \
426-
(test_bit(FSCACHE_IOERROR, &(obj)->cache->flags) && \
427-
(obj)->state >= FSCACHE_OBJECT_DYING)
428-
429420
extern void fscache_object_init(struct fscache_object *, struct fscache_cookie *,
430421
struct fscache_cache *);
431422

@@ -438,6 +429,34 @@ extern void fscache_object_destroy(struct fscache_object *object);
438429
#define fscache_object_destroy(object) do {} while(0)
439430
#endif
440431

432+
static inline bool fscache_object_is_live(struct fscache_object *object)
433+
{
434+
return object->state < FSCACHE_OBJECT_DYING;
435+
}
436+
437+
static inline bool fscache_object_is_dying(struct fscache_object *object)
438+
{
439+
return !fscache_object_is_live(object);
440+
}
441+
442+
static inline bool fscache_object_is_available(struct fscache_object *object)
443+
{
444+
return object->state >= FSCACHE_OBJECT_AVAILABLE;
445+
}
446+
447+
static inline bool fscache_object_is_active(struct fscache_object *object)
448+
{
449+
return fscache_object_is_available(object) &&
450+
fscache_object_is_live(object) &&
451+
!test_bit(FSCACHE_IOERROR, &object->cache->flags);
452+
}
453+
454+
static inline bool fscache_object_is_dead(struct fscache_object *object)
455+
{
456+
return fscache_object_is_dying(object) &&
457+
test_bit(FSCACHE_IOERROR, &object->cache->flags);
458+
}
459+
441460
/**
442461
* fscache_object_destroyed - Note destruction of an object in a cache
443462
* @cache: The cache from which the object came

0 commit comments

Comments
 (0)