Lines Matching full:object
1 /* FS-Cache object state machine handler
11 * See Documentation/filesystems/caching/object.txt for a description of the
12 * object state machine and the in-kernel representations.
78 * The object state machine.
117 * In such a situation, object->state remembers the state the machine should
153 static inline void fscache_done_parent_op(struct fscache_object *object) in fscache_done_parent_op() argument
155 struct fscache_object *parent = object->parent; in fscache_done_parent_op()
158 object->debug_id, parent->debug_id, parent->n_ops); in fscache_done_parent_op()
169 * Object state machine dispatcher.
171 static void fscache_object_sm_dispatcher(struct fscache_object *object) in fscache_object_sm_dispatcher() argument
179 ASSERT(object != NULL); in fscache_object_sm_dispatcher()
182 object->debug_id, object->state->name, object->events); in fscache_object_sm_dispatcher()
184 event_mask = object->event_mask; in fscache_object_sm_dispatcher()
186 object->event_mask = 0; /* Mask normal event handling */ in fscache_object_sm_dispatcher()
187 state = object->state; in fscache_object_sm_dispatcher()
189 events = object->events; in fscache_object_sm_dispatcher()
192 if (events & object->oob_event_mask) { in fscache_object_sm_dispatcher()
194 object->debug_id, events & object->oob_event_mask); in fscache_object_sm_dispatcher()
196 for (t = object->oob_table; t->events; t++) { in fscache_object_sm_dispatcher()
201 __clear_bit(event, &object->oob_event_mask); in fscache_object_sm_dispatcher()
202 clear_bit(event, &object->events); in fscache_object_sm_dispatcher()
216 trace_fscache_osm(object, state, in fscache_object_sm_dispatcher()
218 clear_bit(event, &object->events); in fscache_object_sm_dispatcher()
220 object->debug_id, event, in fscache_object_sm_dispatcher()
222 object->state = state = new_state; in fscache_object_sm_dispatcher()
235 _debug("{OBJ%x} exec %s", object->debug_id, state->name); in fscache_object_sm_dispatcher()
237 trace_fscache_osm(object, state, false, oob, event); in fscache_object_sm_dispatcher()
238 new_state = state->work(object, event); in fscache_object_sm_dispatcher()
241 _debug("{OBJ%x} %s notrans", object->debug_id, state->name); in fscache_object_sm_dispatcher()
246 fscache_enqueue_object(object); in fscache_object_sm_dispatcher()
247 event_mask = object->oob_event_mask; in fscache_object_sm_dispatcher()
252 object->debug_id, state->name, new_state->name); in fscache_object_sm_dispatcher()
253 object->state = state = new_state; in fscache_object_sm_dispatcher()
264 event_mask = object->oob_event_mask; in fscache_object_sm_dispatcher()
269 object->event_mask = event_mask; in fscache_object_sm_dispatcher()
271 events = object->events; in fscache_object_sm_dispatcher()
278 * execute an object
282 struct fscache_object *object = in fscache_object_work_func() local
286 _enter("{OBJ%x}", object->debug_id); in fscache_object_work_func()
289 fscache_object_sm_dispatcher(object); in fscache_object_work_func()
291 fscache_put_object(object, fscache_obj_put_work); in fscache_object_work_func()
295 * fscache_object_init - Initialise a cache object description
296 * @object: Object description
297 * @cookie: Cookie object will be attached to
298 * @cache: Cache in which backing object will be found
300 * Initialise a cache object description to its basic values.
305 void fscache_object_init(struct fscache_object *object, in fscache_object_init() argument
313 object->state = STATE(WAIT_FOR_INIT); in fscache_object_init()
314 object->oob_table = fscache_osm_init_oob; in fscache_object_init()
315 object->flags = 1 << FSCACHE_OBJECT_IS_LIVE; in fscache_object_init()
316 spin_lock_init(&object->lock); in fscache_object_init()
317 INIT_LIST_HEAD(&object->cache_link); in fscache_object_init()
318 INIT_HLIST_NODE(&object->cookie_link); in fscache_object_init()
319 INIT_WORK(&object->work, fscache_object_work_func); in fscache_object_init()
320 INIT_LIST_HEAD(&object->dependents); in fscache_object_init()
321 INIT_LIST_HEAD(&object->dep_link); in fscache_object_init()
322 INIT_LIST_HEAD(&object->pending_ops); in fscache_object_init()
323 object->n_children = 0; in fscache_object_init()
324 object->n_ops = object->n_in_progress = object->n_exclusive = 0; in fscache_object_init()
325 object->events = 0; in fscache_object_init()
326 object->store_limit = 0; in fscache_object_init()
327 object->store_limit_l = 0; in fscache_object_init()
328 object->cache = cache; in fscache_object_init()
329 object->cookie = cookie; in fscache_object_init()
331 object->parent = NULL; in fscache_object_init()
333 RB_CLEAR_NODE(&object->objlist_link); in fscache_object_init()
336 object->oob_event_mask = 0; in fscache_object_init()
337 for (t = object->oob_table; t->events; t++) in fscache_object_init()
338 object->oob_event_mask |= t->events; in fscache_object_init()
339 object->event_mask = object->oob_event_mask; in fscache_object_init()
340 for (t = object->state->transitions; t->events; t++) in fscache_object_init()
341 object->event_mask |= t->events; in fscache_object_init()
346 * Mark the object as no longer being live, making sure that we synchronise
349 static inline void fscache_mark_object_dead(struct fscache_object *object) in fscache_mark_object_dead() argument
351 spin_lock(&object->lock); in fscache_mark_object_dead()
352 clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); in fscache_mark_object_dead()
353 spin_unlock(&object->lock); in fscache_mark_object_dead()
357 * Abort object initialisation before we start it.
359 static const struct fscache_state *fscache_abort_initialisation(struct fscache_object *object, in fscache_abort_initialisation() argument
362 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_abort_initialisation()
364 object->oob_event_mask = 0; in fscache_abort_initialisation()
365 fscache_dequeue_object(object); in fscache_abort_initialisation()
370 * initialise an object
371 * - check the specified object's parent to see if we can make use of it
376 static const struct fscache_state *fscache_initialise_object(struct fscache_object *object, in fscache_initialise_object() argument
382 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_initialise_object()
384 ASSERT(list_empty(&object->dep_link)); in fscache_initialise_object()
386 parent = object->parent; in fscache_initialise_object()
410 object->cache->ops->grab_object(object, fscache_obj_get_add_to_deps)) { in fscache_initialise_object()
411 list_add(&object->dep_link, &parent->dependents); in fscache_initialise_object()
429 * Once the parent object is ready, we should kick off our lookup op.
431 static const struct fscache_state *fscache_parent_ready(struct fscache_object *object, in fscache_parent_ready() argument
434 struct fscache_object *parent = object->parent; in fscache_parent_ready()
436 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_parent_ready()
443 object->lookup_jif = jiffies; in fscache_parent_ready()
451 * look an object up in the cache from which it was allocated
452 * - we hold an "access lock" on the parent object, so the parent object cannot
455 static const struct fscache_state *fscache_look_up_object(struct fscache_object *object, in fscache_look_up_object() argument
458 struct fscache_cookie *cookie = object->cookie; in fscache_look_up_object()
459 struct fscache_object *parent = object->parent; in fscache_look_up_object()
462 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_look_up_object()
464 object->oob_table = fscache_osm_lookup_oob; in fscache_look_up_object()
474 test_bit(FSCACHE_IOERROR, &object->cache->flags) || in fscache_look_up_object()
475 !fscache_use_cookie(object)) { in fscache_look_up_object()
481 cookie->def->name, object->cache->tag->name); in fscache_look_up_object()
485 ret = object->cache->ops->lookup_object(object); in fscache_look_up_object()
488 fscache_unuse_cookie(object); in fscache_look_up_object()
491 /* probably stuck behind another object, so move this one to in fscache_look_up_object()
509 * @object: Object pointing to cookie to mark
512 * existing backing object to continue as there's no data for them to read.
514 void fscache_object_lookup_negative(struct fscache_object *object) in fscache_object_lookup_negative() argument
516 struct fscache_cookie *cookie = object->cookie; in fscache_object_lookup_negative()
518 _enter("{OBJ%x,%s}", object->debug_id, object->state->name); in fscache_object_lookup_negative()
520 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { in fscache_object_lookup_negative()
538 * fscache_obtained_object - Note successful object lookup or creation
539 * @object: Object pointing to cookie to mark
542 * data to a backing object to continue.
544 * Note that after calling this, an object's cookie may be relinquished by the
545 * netfs, and so must be accessed with object lock held.
547 void fscache_obtained_object(struct fscache_object *object) in fscache_obtained_object() argument
549 struct fscache_cookie *cookie = object->cookie; in fscache_obtained_object()
551 _enter("{OBJ%x,%s}", object->debug_id, object->state->name); in fscache_obtained_object()
555 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { in fscache_obtained_object()
571 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags); in fscache_obtained_object()
577 * handle an object that has just become available
579 static const struct fscache_state *fscache_object_available(struct fscache_object *object, in fscache_object_available() argument
582 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_object_available()
584 object->oob_table = fscache_osm_run_oob; in fscache_object_available()
586 spin_lock(&object->lock); in fscache_object_available()
588 fscache_done_parent_op(object); in fscache_object_available()
589 if (object->n_in_progress == 0) { in fscache_object_available()
590 if (object->n_ops > 0) { in fscache_object_available()
591 ASSERTCMP(object->n_ops, >=, object->n_obj_ops); in fscache_object_available()
592 fscache_start_operations(object); in fscache_object_available()
594 ASSERT(list_empty(&object->pending_ops)); in fscache_object_available()
597 spin_unlock(&object->lock); in fscache_object_available()
600 object->cache->ops->lookup_complete(object); in fscache_object_available()
603 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif); in fscache_object_available()
611 * Wake up this object's dependent objects now that we've become available.
613 static const struct fscache_state *fscache_jumpstart_dependents(struct fscache_object *object, in fscache_jumpstart_dependents() argument
616 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_jumpstart_dependents()
618 if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_PARENT_READY)) in fscache_jumpstart_dependents()
626 static const struct fscache_state *fscache_lookup_failure(struct fscache_object *object, in fscache_lookup_failure() argument
631 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_lookup_failure()
633 object->oob_event_mask = 0; in fscache_lookup_failure()
636 object->cache->ops->lookup_complete(object); in fscache_lookup_failure()
639 set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags); in fscache_lookup_failure()
641 cookie = object->cookie; in fscache_lookup_failure()
646 fscache_done_parent_op(object); in fscache_lookup_failure()
651 * Wait for completion of all active operations on this object and the death of
652 * all child objects of this object.
654 static const struct fscache_state *fscache_kill_object(struct fscache_object *object, in fscache_kill_object() argument
658 object->debug_id, object->n_ops, object->n_children, event); in fscache_kill_object()
660 fscache_mark_object_dead(object); in fscache_kill_object()
661 object->oob_event_mask = 0; in fscache_kill_object()
663 if (test_bit(FSCACHE_OBJECT_RETIRED, &object->flags)) { in fscache_kill_object()
665 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); in fscache_kill_object()
666 fscache_cancel_all_ops(object); in fscache_kill_object()
669 if (list_empty(&object->dependents) && in fscache_kill_object()
670 object->n_ops == 0 && in fscache_kill_object()
671 object->n_children == 0) in fscache_kill_object()
674 if (object->n_in_progress == 0) { in fscache_kill_object()
675 spin_lock(&object->lock); in fscache_kill_object()
676 if (object->n_ops > 0 && object->n_in_progress == 0) in fscache_kill_object()
677 fscache_start_operations(object); in fscache_kill_object()
678 spin_unlock(&object->lock); in fscache_kill_object()
681 if (!list_empty(&object->dependents)) in fscache_kill_object()
690 static const struct fscache_state *fscache_kill_dependents(struct fscache_object *object, in fscache_kill_dependents() argument
693 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_kill_dependents()
695 if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_KILL)) in fscache_kill_dependents()
701 * Drop an object's attachments
703 static const struct fscache_state *fscache_drop_object(struct fscache_object *object, in fscache_drop_object() argument
706 struct fscache_object *parent = object->parent; in fscache_drop_object()
707 struct fscache_cookie *cookie = object->cookie; in fscache_drop_object()
708 struct fscache_cache *cache = object->cache; in fscache_drop_object()
711 _enter("{OBJ%x,%d},%d", object->debug_id, object->n_children, event); in fscache_drop_object()
714 ASSERT(!hlist_unhashed(&object->cookie_link)); in fscache_drop_object()
718 fscache_update_aux_data(object); in fscache_drop_object()
725 hlist_del_init(&object->cookie_link); in fscache_drop_object()
740 spin_lock(&object->lock); in fscache_drop_object()
741 spin_unlock(&object->lock); in fscache_drop_object()
745 list_del_init(&object->cache_link); in fscache_drop_object()
749 cache->ops->drop_object(object); in fscache_drop_object()
752 /* The parent object wants to know when all it dependents have gone */ in fscache_drop_object()
762 object->parent = NULL; in fscache_drop_object()
765 /* this just shifts the object release to the work processor */ in fscache_drop_object()
766 fscache_put_object(object, fscache_obj_put_drop_obj); in fscache_drop_object()
774 * get a ref on an object
776 static int fscache_get_object(struct fscache_object *object, in fscache_get_object() argument
782 ret = object->cache->ops->grab_object(object, why) ? 0 : -EAGAIN; in fscache_get_object()
788 * Discard a ref on an object
790 static void fscache_put_object(struct fscache_object *object, in fscache_put_object() argument
794 object->cache->ops->put_object(object, why); in fscache_put_object()
799 * fscache_object_destroy - Note that a cache object is about to be destroyed
800 * @object: The object to be destroyed
802 * Note the imminent destruction and deallocation of a cache object record.
804 void fscache_object_destroy(struct fscache_object *object) in fscache_object_destroy() argument
806 fscache_objlist_remove(object); in fscache_object_destroy()
809 fscache_cookie_put(object->cookie, fscache_cookie_put_object); in fscache_object_destroy()
810 object->cookie = NULL; in fscache_object_destroy()
815 * enqueue an object for metadata-type processing
817 void fscache_enqueue_object(struct fscache_object *object) in fscache_enqueue_object() argument
819 _enter("{OBJ%x}", object->debug_id); in fscache_enqueue_object()
821 if (fscache_get_object(object, fscache_obj_get_queue) >= 0) { in fscache_enqueue_object()
825 if (queue_work(fscache_object_wq, &object->work)) { in fscache_enqueue_object()
829 fscache_put_object(object, fscache_obj_put_queue); in fscache_enqueue_object()
836 * fscache_object_sleep_till_congested - Sleep until object wq is congested
839 * Allow an object handler to sleep until the object workqueue is congested.
845 * %true is returned if the object wq is congested, %false otherwise.
865 * Enqueue the dependents of an object for metadata-type processing.
871 static bool fscache_enqueue_dependents(struct fscache_object *object, int event) in fscache_enqueue_dependents() argument
876 _enter("{OBJ%x}", object->debug_id); in fscache_enqueue_dependents()
878 if (list_empty(&object->dependents)) in fscache_enqueue_dependents()
881 spin_lock(&object->lock); in fscache_enqueue_dependents()
883 while (!list_empty(&object->dependents)) { in fscache_enqueue_dependents()
884 dep = list_entry(object->dependents.next, in fscache_enqueue_dependents()
891 if (!list_empty(&object->dependents) && need_resched()) { in fscache_enqueue_dependents()
897 spin_unlock(&object->lock); in fscache_enqueue_dependents()
902 * remove an object from whatever queue it's waiting on
904 static void fscache_dequeue_object(struct fscache_object *object) in fscache_dequeue_object() argument
906 _enter("{OBJ%x}", object->debug_id); in fscache_dequeue_object()
908 if (!list_empty(&object->dep_link)) { in fscache_dequeue_object()
909 spin_lock(&object->parent->lock); in fscache_dequeue_object()
910 list_del_init(&object->dep_link); in fscache_dequeue_object()
911 spin_unlock(&object->parent->lock); in fscache_dequeue_object()
918 * fscache_check_aux - Ask the netfs whether an object on disk is still valid
919 * @object: The object to ask about
920 * @data: The auxiliary data for the object
923 * This function consults the netfs about the coherency state of an object.
925 * fscache_look_up_object() on behalf of the cache backend during object lookup
928 enum fscache_checkaux fscache_check_aux(struct fscache_object *object, in fscache_check_aux() argument
934 if (!object->cookie->def->check_aux) { in fscache_check_aux()
939 result = object->cookie->def->check_aux(object->cookie->netfs_data, in fscache_check_aux()
966 * Asynchronously invalidate an object.
968 static const struct fscache_state *_fscache_invalidate_object(struct fscache_object *object, in _fscache_invalidate_object() argument
972 struct fscache_cookie *cookie = object->cookie; in _fscache_invalidate_object()
974 _enter("{OBJ%x},%d", object->debug_id, event); in _fscache_invalidate_object()
977 * retire the object instead. in _fscache_invalidate_object()
979 if (!fscache_use_cookie(object)) { in _fscache_invalidate_object()
980 ASSERT(radix_tree_empty(&object->cookie->stores)); in _fscache_invalidate_object()
981 set_bit(FSCACHE_OBJECT_RETIRED, &object->flags); in _fscache_invalidate_object()
988 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); in _fscache_invalidate_object()
989 fscache_cancel_all_ops(object); in _fscache_invalidate_object()
996 fscache_operation_init(cookie, op, object->cache->ops->invalidate_object, in _fscache_invalidate_object()
1004 if (fscache_submit_exclusive_op(object, op) < 0) in _fscache_invalidate_object()
1024 fscache_mark_object_dead(object); in _fscache_invalidate_object()
1025 fscache_unuse_cookie(object); in _fscache_invalidate_object()
1030 fscache_mark_object_dead(object); in _fscache_invalidate_object()
1032 fscache_unuse_cookie(object); in _fscache_invalidate_object()
1038 static const struct fscache_state *fscache_invalidate_object(struct fscache_object *object, in fscache_invalidate_object() argument
1045 s = _fscache_invalidate_object(object, event); in fscache_invalidate_object()
1053 static void fscache_update_aux_data(struct fscache_object *object) in fscache_update_aux_data() argument
1057 object->cache->ops->update_object(object); in fscache_update_aux_data()
1062 * Asynchronously update an object.
1064 static const struct fscache_state *fscache_update_object(struct fscache_object *object, in fscache_update_object() argument
1067 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_update_object()
1069 fscache_update_aux_data(object); in fscache_update_object()
1076 * fscache_object_retrying_stale - Note retrying stale object
1077 * @object: The object that will be retried
1079 * Note that an object lookup found an on-disk object that was adjudged to be
1082 void fscache_object_retrying_stale(struct fscache_object *object) in fscache_object_retrying_stale() argument
1089 * fscache_object_mark_killed - Note that an object was killed
1090 * @object: The object that was culled
1091 * @why: The reason the object was killed.
1093 * Note that an object was killed. Returns true if the object was
1096 void fscache_object_mark_killed(struct fscache_object *object, in fscache_object_mark_killed() argument
1099 if (test_and_set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags)) { in fscache_object_mark_killed()
1100 pr_err("Error: Object already killed by cache [%s]\n", in fscache_object_mark_killed()
1101 object->cache->identifier); in fscache_object_mark_killed()
1123 * The object is dead. We can get here if an object gets queued by an event
1128 static const struct fscache_state *fscache_object_dead(struct fscache_object *object, in fscache_object_dead() argument
1132 &object->flags)) in fscache_object_dead()
1135 WARN(true, "FS-Cache object redispatched after death"); in fscache_object_dead()