Lines Matching full:object
2 /* FS-Cache object state machine handler
7 * See Documentation/filesystems/caching/object.rst for a description of the
8 * object state machine and the in-kernel representations.
74 * The object state machine.
113 * In such a situation, object->state remembers the state the machine should
149 static inline void fscache_done_parent_op(struct fscache_object *object) in fscache_done_parent_op() argument
151 struct fscache_object *parent = object->parent; in fscache_done_parent_op()
154 object->debug_id, parent->debug_id, parent->n_ops); in fscache_done_parent_op()
165 * Object state machine dispatcher.
167 static void fscache_object_sm_dispatcher(struct fscache_object *object) in fscache_object_sm_dispatcher() argument
175 ASSERT(object != NULL); in fscache_object_sm_dispatcher()
178 object->debug_id, object->state->name, object->events); in fscache_object_sm_dispatcher()
180 event_mask = object->event_mask; in fscache_object_sm_dispatcher()
182 object->event_mask = 0; /* Mask normal event handling */ in fscache_object_sm_dispatcher()
183 state = object->state; in fscache_object_sm_dispatcher()
185 events = object->events; in fscache_object_sm_dispatcher()
188 if (events & object->oob_event_mask) { in fscache_object_sm_dispatcher()
190 object->debug_id, events & object->oob_event_mask); in fscache_object_sm_dispatcher()
192 for (t = object->oob_table; t->events; t++) { in fscache_object_sm_dispatcher()
197 __clear_bit(event, &object->oob_event_mask); in fscache_object_sm_dispatcher()
198 clear_bit(event, &object->events); in fscache_object_sm_dispatcher()
212 trace_fscache_osm(object, state, in fscache_object_sm_dispatcher()
214 clear_bit(event, &object->events); in fscache_object_sm_dispatcher()
216 object->debug_id, event, in fscache_object_sm_dispatcher()
218 object->state = state = new_state; in fscache_object_sm_dispatcher()
231 _debug("{OBJ%x} exec %s", object->debug_id, state->name); in fscache_object_sm_dispatcher()
233 trace_fscache_osm(object, state, false, oob, event); in fscache_object_sm_dispatcher()
234 new_state = state->work(object, event); in fscache_object_sm_dispatcher()
237 _debug("{OBJ%x} %s notrans", object->debug_id, state->name); in fscache_object_sm_dispatcher()
242 fscache_enqueue_object(object); in fscache_object_sm_dispatcher()
243 event_mask = object->oob_event_mask; in fscache_object_sm_dispatcher()
248 object->debug_id, state->name, new_state->name); in fscache_object_sm_dispatcher()
249 object->state = state = new_state; in fscache_object_sm_dispatcher()
260 event_mask = object->oob_event_mask; in fscache_object_sm_dispatcher()
265 object->event_mask = event_mask; in fscache_object_sm_dispatcher()
267 events = object->events; in fscache_object_sm_dispatcher()
274 * execute an object
278 struct fscache_object *object = in fscache_object_work_func() local
282 _enter("{OBJ%x}", object->debug_id); in fscache_object_work_func()
285 fscache_object_sm_dispatcher(object); in fscache_object_work_func()
287 fscache_put_object(object, fscache_obj_put_work); in fscache_object_work_func()
291 * fscache_object_init - Initialise a cache object description
292 * @object: Object description
293 * @cookie: Cookie object will be attached to
294 * @cache: Cache in which backing object will be found
296 * Initialise a cache object description to its basic values.
301 void fscache_object_init(struct fscache_object *object, in fscache_object_init() argument
309 object->state = STATE(WAIT_FOR_INIT); in fscache_object_init()
310 object->oob_table = fscache_osm_init_oob; in fscache_object_init()
311 object->flags = 1 << FSCACHE_OBJECT_IS_LIVE; in fscache_object_init()
312 spin_lock_init(&object->lock); in fscache_object_init()
313 INIT_LIST_HEAD(&object->cache_link); in fscache_object_init()
314 INIT_HLIST_NODE(&object->cookie_link); in fscache_object_init()
315 INIT_WORK(&object->work, fscache_object_work_func); in fscache_object_init()
316 INIT_LIST_HEAD(&object->dependents); in fscache_object_init()
317 INIT_LIST_HEAD(&object->dep_link); in fscache_object_init()
318 INIT_LIST_HEAD(&object->pending_ops); in fscache_object_init()
319 object->n_children = 0; in fscache_object_init()
320 object->n_ops = object->n_in_progress = object->n_exclusive = 0; in fscache_object_init()
321 object->events = 0; in fscache_object_init()
322 object->store_limit = 0; in fscache_object_init()
323 object->store_limit_l = 0; in fscache_object_init()
324 object->cache = cache; in fscache_object_init()
325 object->cookie = cookie; in fscache_object_init()
327 object->parent = NULL; in fscache_object_init()
329 RB_CLEAR_NODE(&object->objlist_link); in fscache_object_init()
332 object->oob_event_mask = 0; in fscache_object_init()
333 for (t = object->oob_table; t->events; t++) in fscache_object_init()
334 object->oob_event_mask |= t->events; in fscache_object_init()
335 object->event_mask = object->oob_event_mask; in fscache_object_init()
336 for (t = object->state->transitions; t->events; t++) in fscache_object_init()
337 object->event_mask |= t->events; in fscache_object_init()
342 * Mark the object as no longer being live, making sure that we synchronise
345 static inline void fscache_mark_object_dead(struct fscache_object *object) in fscache_mark_object_dead() argument
347 spin_lock(&object->lock); in fscache_mark_object_dead()
348 clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); in fscache_mark_object_dead()
349 spin_unlock(&object->lock); in fscache_mark_object_dead()
353 * Abort object initialisation before we start it.
355 static const struct fscache_state *fscache_abort_initialisation(struct fscache_object *object, in fscache_abort_initialisation() argument
358 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_abort_initialisation()
360 object->oob_event_mask = 0; in fscache_abort_initialisation()
361 fscache_dequeue_object(object); in fscache_abort_initialisation()
366 * initialise an object
367 * - check the specified object's parent to see if we can make use of it
372 static const struct fscache_state *fscache_initialise_object(struct fscache_object *object, in fscache_initialise_object() argument
378 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_initialise_object()
380 ASSERT(list_empty(&object->dep_link)); in fscache_initialise_object()
382 parent = object->parent; in fscache_initialise_object()
406 object->cache->ops->grab_object(object, fscache_obj_get_add_to_deps)) { in fscache_initialise_object()
407 list_add(&object->dep_link, &parent->dependents); in fscache_initialise_object()
425 * Once the parent object is ready, we should kick off our lookup op.
427 static const struct fscache_state *fscache_parent_ready(struct fscache_object *object, in fscache_parent_ready() argument
430 struct fscache_object *parent = object->parent; in fscache_parent_ready()
432 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_parent_ready()
439 object->lookup_jif = jiffies; in fscache_parent_ready()
447 * look an object up in the cache from which it was allocated
448 * - we hold an "access lock" on the parent object, so the parent object cannot
451 static const struct fscache_state *fscache_look_up_object(struct fscache_object *object, in fscache_look_up_object() argument
454 struct fscache_cookie *cookie = object->cookie; in fscache_look_up_object()
455 struct fscache_object *parent = object->parent; in fscache_look_up_object()
458 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_look_up_object()
460 object->oob_table = fscache_osm_lookup_oob; in fscache_look_up_object()
470 test_bit(FSCACHE_IOERROR, &object->cache->flags) || in fscache_look_up_object()
471 !fscache_use_cookie(object)) { in fscache_look_up_object()
477 cookie->def->name, object->cache->tag->name); in fscache_look_up_object()
481 ret = object->cache->ops->lookup_object(object); in fscache_look_up_object()
484 fscache_unuse_cookie(object); in fscache_look_up_object()
487 /* probably stuck behind another object, so move this one to in fscache_look_up_object()
505 * @object: Object pointing to cookie to mark
508 * existing backing object to continue as there's no data for them to read.
510 void fscache_object_lookup_negative(struct fscache_object *object) in fscache_object_lookup_negative() argument
512 struct fscache_cookie *cookie = object->cookie; in fscache_object_lookup_negative()
514 _enter("{OBJ%x,%s}", object->debug_id, object->state->name); in fscache_object_lookup_negative()
516 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { in fscache_object_lookup_negative()
534 * fscache_obtained_object - Note successful object lookup or creation
535 * @object: Object pointing to cookie to mark
538 * data to a backing object to continue.
540 * Note that after calling this, an object's cookie may be relinquished by the
541 * netfs, and so must be accessed with object lock held.
543 void fscache_obtained_object(struct fscache_object *object) in fscache_obtained_object() argument
545 struct fscache_cookie *cookie = object->cookie; in fscache_obtained_object()
547 _enter("{OBJ%x,%s}", object->debug_id, object->state->name); in fscache_obtained_object()
551 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { in fscache_obtained_object()
567 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags); in fscache_obtained_object()
573 * handle an object that has just become available
575 static const struct fscache_state *fscache_object_available(struct fscache_object *object, in fscache_object_available() argument
578 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_object_available()
580 object->oob_table = fscache_osm_run_oob; in fscache_object_available()
582 spin_lock(&object->lock); in fscache_object_available()
584 fscache_done_parent_op(object); in fscache_object_available()
585 if (object->n_in_progress == 0) { in fscache_object_available()
586 if (object->n_ops > 0) { in fscache_object_available()
587 ASSERTCMP(object->n_ops, >=, object->n_obj_ops); in fscache_object_available()
588 fscache_start_operations(object); in fscache_object_available()
590 ASSERT(list_empty(&object->pending_ops)); in fscache_object_available()
593 spin_unlock(&object->lock); in fscache_object_available()
596 object->cache->ops->lookup_complete(object); in fscache_object_available()
599 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif); in fscache_object_available()
607 * Wake up this object's dependent objects now that we've become available.
609 static const struct fscache_state *fscache_jumpstart_dependents(struct fscache_object *object, in fscache_jumpstart_dependents() argument
612 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_jumpstart_dependents()
614 if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_PARENT_READY)) in fscache_jumpstart_dependents()
622 static const struct fscache_state *fscache_lookup_failure(struct fscache_object *object, in fscache_lookup_failure() argument
627 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_lookup_failure()
629 object->oob_event_mask = 0; in fscache_lookup_failure()
632 object->cache->ops->lookup_complete(object); in fscache_lookup_failure()
635 set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags); in fscache_lookup_failure()
637 cookie = object->cookie; in fscache_lookup_failure()
642 fscache_done_parent_op(object); in fscache_lookup_failure()
647 * Wait for completion of all active operations on this object and the death of
648 * all child objects of this object.
650 static const struct fscache_state *fscache_kill_object(struct fscache_object *object, in fscache_kill_object() argument
654 object->debug_id, object->n_ops, object->n_children, event); in fscache_kill_object()
656 fscache_mark_object_dead(object); in fscache_kill_object()
657 object->oob_event_mask = 0; in fscache_kill_object()
659 if (test_bit(FSCACHE_OBJECT_RETIRED, &object->flags)) { in fscache_kill_object()
661 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); in fscache_kill_object()
662 fscache_cancel_all_ops(object); in fscache_kill_object()
665 if (list_empty(&object->dependents) && in fscache_kill_object()
666 object->n_ops == 0 && in fscache_kill_object()
667 object->n_children == 0) in fscache_kill_object()
670 if (object->n_in_progress == 0) { in fscache_kill_object()
671 spin_lock(&object->lock); in fscache_kill_object()
672 if (object->n_ops > 0 && object->n_in_progress == 0) in fscache_kill_object()
673 fscache_start_operations(object); in fscache_kill_object()
674 spin_unlock(&object->lock); in fscache_kill_object()
677 if (!list_empty(&object->dependents)) in fscache_kill_object()
686 static const struct fscache_state *fscache_kill_dependents(struct fscache_object *object, in fscache_kill_dependents() argument
689 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_kill_dependents()
691 if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_KILL)) in fscache_kill_dependents()
697 * Drop an object's attachments
699 static const struct fscache_state *fscache_drop_object(struct fscache_object *object, in fscache_drop_object() argument
702 struct fscache_object *parent = object->parent; in fscache_drop_object()
703 struct fscache_cookie *cookie = object->cookie; in fscache_drop_object()
704 struct fscache_cache *cache = object->cache; in fscache_drop_object()
707 _enter("{OBJ%x,%d},%d", object->debug_id, object->n_children, event); in fscache_drop_object()
710 ASSERT(!hlist_unhashed(&object->cookie_link)); in fscache_drop_object()
714 fscache_update_aux_data(object); in fscache_drop_object()
721 hlist_del_init(&object->cookie_link); in fscache_drop_object()
736 spin_lock(&object->lock); in fscache_drop_object()
737 spin_unlock(&object->lock); in fscache_drop_object()
741 list_del_init(&object->cache_link); in fscache_drop_object()
745 cache->ops->drop_object(object); in fscache_drop_object()
748 /* The parent object wants to know when all it dependents have gone */ in fscache_drop_object()
758 object->parent = NULL; in fscache_drop_object()
761 /* this just shifts the object release to the work processor */ in fscache_drop_object()
762 fscache_put_object(object, fscache_obj_put_drop_obj); in fscache_drop_object()
770 * get a ref on an object
772 static int fscache_get_object(struct fscache_object *object, in fscache_get_object() argument
778 ret = object->cache->ops->grab_object(object, why) ? 0 : -EAGAIN; in fscache_get_object()
784 * Discard a ref on an object
786 static void fscache_put_object(struct fscache_object *object, in fscache_put_object() argument
790 object->cache->ops->put_object(object, why); in fscache_put_object()
795 * fscache_object_destroy - Note that a cache object is about to be destroyed
796 * @object: The object to be destroyed
798 * Note the imminent destruction and deallocation of a cache object record.
800 void fscache_object_destroy(struct fscache_object *object) in fscache_object_destroy() argument
802 fscache_objlist_remove(object); in fscache_object_destroy()
805 fscache_cookie_put(object->cookie, fscache_cookie_put_object); in fscache_object_destroy()
806 object->cookie = NULL; in fscache_object_destroy()
811 * enqueue an object for metadata-type processing
813 void fscache_enqueue_object(struct fscache_object *object) in fscache_enqueue_object() argument
815 _enter("{OBJ%x}", object->debug_id); in fscache_enqueue_object()
817 if (fscache_get_object(object, fscache_obj_get_queue) >= 0) { in fscache_enqueue_object()
821 if (queue_work(fscache_object_wq, &object->work)) { in fscache_enqueue_object()
825 fscache_put_object(object, fscache_obj_put_queue); in fscache_enqueue_object()
832 * fscache_object_sleep_till_congested - Sleep until object wq is congested
835 * Allow an object handler to sleep until the object workqueue is congested.
841 * %true is returned if the object wq is congested, %false otherwise.
861 * Enqueue the dependents of an object for metadata-type processing.
867 static bool fscache_enqueue_dependents(struct fscache_object *object, int event) in fscache_enqueue_dependents() argument
872 _enter("{OBJ%x}", object->debug_id); in fscache_enqueue_dependents()
874 if (list_empty(&object->dependents)) in fscache_enqueue_dependents()
877 spin_lock(&object->lock); in fscache_enqueue_dependents()
879 while (!list_empty(&object->dependents)) { in fscache_enqueue_dependents()
880 dep = list_entry(object->dependents.next, in fscache_enqueue_dependents()
887 if (!list_empty(&object->dependents) && need_resched()) { in fscache_enqueue_dependents()
893 spin_unlock(&object->lock); in fscache_enqueue_dependents()
898 * remove an object from whatever queue it's waiting on
900 static void fscache_dequeue_object(struct fscache_object *object) in fscache_dequeue_object() argument
902 _enter("{OBJ%x}", object->debug_id); in fscache_dequeue_object()
904 if (!list_empty(&object->dep_link)) { in fscache_dequeue_object()
905 spin_lock(&object->parent->lock); in fscache_dequeue_object()
906 list_del_init(&object->dep_link); in fscache_dequeue_object()
907 spin_unlock(&object->parent->lock); in fscache_dequeue_object()
914 * fscache_check_aux - Ask the netfs whether an object on disk is still valid
915 * @object: The object to ask about
916 * @data: The auxiliary data for the object
919 * This function consults the netfs about the coherency state of an object.
921 * fscache_look_up_object() on behalf of the cache backend during object lookup
924 enum fscache_checkaux fscache_check_aux(struct fscache_object *object, in fscache_check_aux() argument
930 if (!object->cookie->def->check_aux) { in fscache_check_aux()
935 result = object->cookie->def->check_aux(object->cookie->netfs_data, in fscache_check_aux()
962 * Asynchronously invalidate an object.
964 static const struct fscache_state *_fscache_invalidate_object(struct fscache_object *object, in _fscache_invalidate_object() argument
968 struct fscache_cookie *cookie = object->cookie; in _fscache_invalidate_object()
970 _enter("{OBJ%x},%d", object->debug_id, event); in _fscache_invalidate_object()
973 * retire the object instead. in _fscache_invalidate_object()
975 if (!fscache_use_cookie(object)) { in _fscache_invalidate_object()
976 ASSERT(radix_tree_empty(&object->cookie->stores)); in _fscache_invalidate_object()
977 set_bit(FSCACHE_OBJECT_RETIRED, &object->flags); in _fscache_invalidate_object()
984 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); in _fscache_invalidate_object()
985 fscache_cancel_all_ops(object); in _fscache_invalidate_object()
992 fscache_operation_init(cookie, op, object->cache->ops->invalidate_object, in _fscache_invalidate_object()
1000 if (fscache_submit_exclusive_op(object, op) < 0) in _fscache_invalidate_object()
1020 fscache_mark_object_dead(object); in _fscache_invalidate_object()
1021 fscache_unuse_cookie(object); in _fscache_invalidate_object()
1026 fscache_mark_object_dead(object); in _fscache_invalidate_object()
1028 fscache_unuse_cookie(object); in _fscache_invalidate_object()
1034 static const struct fscache_state *fscache_invalidate_object(struct fscache_object *object, in fscache_invalidate_object() argument
1041 s = _fscache_invalidate_object(object, event); in fscache_invalidate_object()
1049 static void fscache_update_aux_data(struct fscache_object *object) in fscache_update_aux_data() argument
1053 object->cache->ops->update_object(object); in fscache_update_aux_data()
1058 * Asynchronously update an object.
1060 static const struct fscache_state *fscache_update_object(struct fscache_object *object, in fscache_update_object() argument
1063 _enter("{OBJ%x},%d", object->debug_id, event); in fscache_update_object()
1065 fscache_update_aux_data(object); in fscache_update_object()
1072 * fscache_object_retrying_stale - Note retrying stale object
1073 * @object: The object that will be retried
1075 * Note that an object lookup found an on-disk object that was adjudged to be
1078 void fscache_object_retrying_stale(struct fscache_object *object) in fscache_object_retrying_stale() argument
1085 * fscache_object_mark_killed - Note that an object was killed
1086 * @object: The object that was culled
1087 * @why: The reason the object was killed.
1089 * Note that an object was killed. Returns true if the object was
1092 void fscache_object_mark_killed(struct fscache_object *object, in fscache_object_mark_killed() argument
1095 if (test_and_set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags)) { in fscache_object_mark_killed()
1096 pr_err("Error: Object already killed by cache [%s]\n", in fscache_object_mark_killed()
1097 object->cache->identifier); in fscache_object_mark_killed()
1119 * The object is dead. We can get here if an object gets queued by an event
1124 static const struct fscache_state *fscache_object_dead(struct fscache_object *object, in fscache_object_dead() argument
1128 &object->flags)) in fscache_object_dead()
1131 WARN(true, "FS-Cache object redispatched after death"); in fscache_object_dead()