Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+40 -21
+2 -2
fs/cachefiles/namei.c
··· 130 130 fscache_object_states[object->fscache.state], 131 131 dentry); 132 132 133 - if (object->fscache.state < FSCACHE_OBJECT_DYING) { 133 + if (fscache_object_is_live(&object->fscache)) { 134 134 printk(KERN_ERR "\n"); 135 135 printk(KERN_ERR "CacheFiles: Error:" 136 136 " Can't preemptively bury live object\n"); ··· 192 192 /* an old object from a previous incarnation is hogging the slot - we 193 193 * need to wait for it to be destroyed */ 194 194 wait_for_old_object: 195 - if (xobject->fscache.state < FSCACHE_OBJECT_DYING) { 195 + if (fscache_object_is_live(&object->fscache)) { 196 196 printk(KERN_ERR "\n"); 197 197 printk(KERN_ERR "CacheFiles: Error:" 198 198 " Unexpected object collision\n");
+1 -1
fs/fscache/cache.c
··· 115 115 struct fscache_object, cookie_link); 116 116 117 117 cache = object->cache; 118 - if (object->state >= FSCACHE_OBJECT_DYING || 118 + if (fscache_object_is_dying(object) || 119 119 test_bit(FSCACHE_IOERROR, &cache->flags)) 120 120 cache = NULL; 121 121
+4 -4
fs/fscache/cookie.c
··· 285 285 286 286 object_already_extant: 287 287 ret = -ENOBUFS; 288 - if (object->state >= FSCACHE_OBJECT_DYING) { 288 + if (fscache_object_is_dead(object)) { 289 289 spin_unlock(&cookie->lock); 290 290 goto error; 291 291 } ··· 321 321 ret = -EEXIST; 322 322 hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { 323 323 if (p->cache == object->cache) { 324 - if (p->state >= FSCACHE_OBJECT_DYING) 324 + if (fscache_object_is_dying(p)) 325 325 ret = -ENOBUFS; 326 326 goto cant_attach_object; 327 327 } ··· 332 332 hlist_for_each_entry(p, &cookie->parent->backing_objects, 333 333 cookie_link) { 334 334 if (p->cache == object->cache) { 335 - if (p->state >= FSCACHE_OBJECT_DYING) { 335 + if (fscache_object_is_dying(p)) { 336 336 ret = -ENOBUFS; 337 337 spin_unlock(&cookie->parent->lock); 338 338 goto cant_attach_object; ··· 400 400 object = hlist_entry(cookie->backing_objects.first, 401 401 struct fscache_object, 402 402 cookie_link); 403 - if (object->state < FSCACHE_OBJECT_DYING) 403 + if (fscache_object_is_live(object)) 404 404 fscache_raise_event( 405 405 object, FSCACHE_OBJECT_EV_INVALIDATE); 406 406 }
+4 -4
fs/fscache/object.c
··· 457 457 spin_lock_nested(&parent->lock, 1); 458 458 _debug("parent %s", fscache_object_states[parent->state]); 459 459 460 - if (parent->state >= FSCACHE_OBJECT_DYING) { 460 + if (fscache_object_is_dying(parent)) { 461 461 _debug("bad parent"); 462 462 set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events); 463 - } else if (parent->state < FSCACHE_OBJECT_AVAILABLE) { 463 + } else if (!fscache_object_is_available(parent)) { 464 464 _debug("wait"); 465 465 466 466 /* we may get woken up in this state by child objects ··· 517 517 ASSERTCMP(parent->n_obj_ops, >, 0); 518 518 519 519 /* make sure the parent is still available */ 520 - ASSERTCMP(parent->state, >=, FSCACHE_OBJECT_AVAILABLE); 520 + ASSERT(fscache_object_is_available(parent)); 521 521 522 - if (parent->state >= FSCACHE_OBJECT_DYING || 522 + if (fscache_object_is_dying(parent) || 523 523 test_bit(FSCACHE_IOERROR, &object->cache->flags)) { 524 524 _debug("unavailable"); 525 525 set_bit(FSCACHE_OBJECT_EV_WITHDRAW, &object->events);
+1 -1
fs/fscache/operation.c
··· 35 35 36 36 ASSERT(list_empty(&op->pend_link)); 37 37 ASSERT(op->processor != NULL); 38 - ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE); 38 + ASSERT(fscache_object_is_available(op->object)); 39 39 ASSERTCMP(atomic_read(&op->usage), >, 0); 40 40 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS); 41 41
+28 -9
include/linux/fscache-cache.h
··· 417 417 418 418 extern const char *fscache_object_states[]; 419 419 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 - 429 420 extern void fscache_object_init(struct fscache_object *, struct fscache_cookie *, 430 421 struct fscache_cache *); 431 422 ··· 428 437 #else 429 438 #define fscache_object_destroy(object) do {} while(0) 430 439 #endif 440 + 441 + static inline bool fscache_object_is_live(struct fscache_object *object) 442 + { 443 + return object->state < FSCACHE_OBJECT_DYING; 444 + } 445 + 446 + static inline bool fscache_object_is_dying(struct fscache_object *object) 447 + { 448 + return !fscache_object_is_live(object); 449 + } 450 + 451 + static inline bool fscache_object_is_available(struct fscache_object *object) 452 + { 453 + return object->state >= FSCACHE_OBJECT_AVAILABLE; 454 + } 455 + 456 + static inline bool fscache_object_is_active(struct fscache_object *object) 457 + { 458 + return fscache_object_is_available(object) && 459 + fscache_object_is_live(object) && 460 + !test_bit(FSCACHE_IOERROR, &object->cache->flags); 461 + } 462 + 463 + static inline bool fscache_object_is_dead(struct fscache_object *object) 464 + { 465 + return fscache_object_is_dying(object) && 466 + test_bit(FSCACHE_IOERROR, &object->cache->flags); 467 + } 431 468 432 469 /** 433 470 * fscache_object_destroyed - Note destruction of an object in a cache