Lines Matching refs: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)
151 struct fscache_object *parent = object->parent;
154 object->debug_id, parent->debug_id, parent->n_ops);
167 static void fscache_object_sm_dispatcher(struct fscache_object *object)
175 ASSERT(object != NULL);
178 object->debug_id, object->state->name, object->events);
180 event_mask = object->event_mask;
182 object->event_mask = 0; /* Mask normal event handling */
183 state = object->state;
185 events = object->events;
188 if (events & object->oob_event_mask) {
190 object->debug_id, events & object->oob_event_mask);
192 for (t = object->oob_table; t->events; t++) {
197 __clear_bit(event, &object->oob_event_mask);
198 clear_bit(event, &object->events);
212 trace_fscache_osm(object, state,
214 clear_bit(event, &object->events);
216 object->debug_id, event,
218 object->state = state = new_state;
231 _debug("{OBJ%x} exec %s", object->debug_id, state->name);
233 trace_fscache_osm(object, state, false, oob, event);
234 new_state = state->work(object, event);
237 _debug("{OBJ%x} %s notrans", object->debug_id, state->name);
242 fscache_enqueue_object(object);
243 event_mask = object->oob_event_mask;
248 object->debug_id, state->name, new_state->name);
249 object->state = state = new_state;
260 event_mask = object->oob_event_mask;
265 object->event_mask = event_mask;
267 events = object->events;
274 * execute an object
278 struct fscache_object *object =
282 _enter("{OBJ%x}", object->debug_id);
285 fscache_object_sm_dispatcher(object);
287 fscache_put_object(object, fscache_obj_put_work);
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,
309 object->state = STATE(WAIT_FOR_INIT);
310 object->oob_table = fscache_osm_init_oob;
311 object->flags = 1 << FSCACHE_OBJECT_IS_LIVE;
312 spin_lock_init(&object->lock);
313 INIT_LIST_HEAD(&object->cache_link);
314 INIT_HLIST_NODE(&object->cookie_link);
315 INIT_WORK(&object->work, fscache_object_work_func);
316 INIT_LIST_HEAD(&object->dependents);
317 INIT_LIST_HEAD(&object->dep_link);
318 INIT_LIST_HEAD(&object->pending_ops);
319 object->n_children = 0;
320 object->n_ops = object->n_in_progress = object->n_exclusive = 0;
321 object->events = 0;
322 object->store_limit = 0;
323 object->store_limit_l = 0;
324 object->cache = cache;
325 object->cookie = cookie;
327 object->parent = NULL;
329 RB_CLEAR_NODE(&object->objlist_link);
332 object->oob_event_mask = 0;
333 for (t = object->oob_table; t->events; t++)
334 object->oob_event_mask |= t->events;
335 object->event_mask = object->oob_event_mask;
336 for (t = object->state->transitions; t->events; t++)
337 object->event_mask |= t->events;
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)
347 spin_lock(&object->lock);
348 clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags);
349 spin_unlock(&object->lock);
353 * Abort object initialisation before we start it.
355 static const struct fscache_state *fscache_abort_initialisation(struct fscache_object *object,
358 _enter("{OBJ%x},%d", object->debug_id, event);
360 object->oob_event_mask = 0;
361 fscache_dequeue_object(object);
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,
378 _enter("{OBJ%x},%d", object->debug_id, event);
380 ASSERT(list_empty(&object->dep_link));
382 parent = object->parent;
406 object->cache->ops->grab_object(object, fscache_obj_get_add_to_deps)) {
407 list_add(&object->dep_link, &parent->dependents);
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,
430 struct fscache_object *parent = object->parent;
432 _enter("{OBJ%x},%d", object->debug_id, event);
439 object->lookup_jif = jiffies;
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,
454 struct fscache_cookie *cookie = object->cookie;
455 struct fscache_object *parent = object->parent;
458 _enter("{OBJ%x},%d", object->debug_id, event);
460 object->oob_table = fscache_osm_lookup_oob;
470 test_bit(FSCACHE_IOERROR, &object->cache->flags) ||
471 !fscache_use_cookie(object)) {
477 cookie->def->name, object->cache->tag->name);
481 ret = object->cache->ops->lookup_object(object);
484 fscache_unuse_cookie(object);
487 /* probably stuck behind another object, so move this one to
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)
512 struct fscache_cookie *cookie = object->cookie;
514 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
516 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
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)
545 struct fscache_cookie *cookie = object->cookie;
547 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
551 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
567 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
573 * handle an object that has just become available
575 static const struct fscache_state *fscache_object_available(struct fscache_object *object,
578 _enter("{OBJ%x},%d", object->debug_id, event);
580 object->oob_table = fscache_osm_run_oob;
582 spin_lock(&object->lock);
584 fscache_done_parent_op(object);
585 if (object->n_in_progress == 0) {
586 if (object->n_ops > 0) {
587 ASSERTCMP(object->n_ops, >=, object->n_obj_ops);
588 fscache_start_operations(object);
590 ASSERT(list_empty(&object->pending_ops));
593 spin_unlock(&object->lock);
596 object->cache->ops->lookup_complete(object);
599 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
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,
612 _enter("{OBJ%x},%d", object->debug_id, event);
614 if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_PARENT_READY))
622 static const struct fscache_state *fscache_lookup_failure(struct fscache_object *object,
627 _enter("{OBJ%x},%d", object->debug_id, event);
629 object->oob_event_mask = 0;
632 object->cache->ops->lookup_complete(object);
635 set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags);
637 cookie = object->cookie;
642 fscache_done_parent_op(object);
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,
654 object->debug_id, object->n_ops, object->n_children, event);
656 fscache_mark_object_dead(object);
657 object->oob_event_mask = 0;
659 if (test_bit(FSCACHE_OBJECT_RETIRED, &object->flags)) {
661 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags);
662 fscache_cancel_all_ops(object);
665 if (list_empty(&object->dependents) &&
666 object->n_ops == 0 &&
667 object->n_children == 0)
670 if (object->n_in_progress == 0) {
671 spin_lock(&object->lock);
672 if (object->n_ops > 0 && object->n_in_progress == 0)
673 fscache_start_operations(object);
674 spin_unlock(&object->lock);
677 if (!list_empty(&object->dependents))
686 static const struct fscache_state *fscache_kill_dependents(struct fscache_object *object,
689 _enter("{OBJ%x},%d", object->debug_id, event);
691 if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_KILL))
697 * Drop an object's attachments
699 static const struct fscache_state *fscache_drop_object(struct fscache_object *object,
702 struct fscache_object *parent = object->parent;
703 struct fscache_cookie *cookie = object->cookie;
704 struct fscache_cache *cache = object->cache;
707 _enter("{OBJ%x,%d},%d", object->debug_id, object->n_children, event);
710 ASSERT(!hlist_unhashed(&object->cookie_link));
714 fscache_update_aux_data(object);
721 hlist_del_init(&object->cookie_link);
736 spin_lock(&object->lock);
737 spin_unlock(&object->lock);
741 list_del_init(&object->cache_link);
745 cache->ops->drop_object(object);
748 /* The parent object wants to know when all it dependents have gone */
758 object->parent = NULL;
761 /* this just shifts the object release to the work processor */
762 fscache_put_object(object, fscache_obj_put_drop_obj);
770 * get a ref on an object
772 static int fscache_get_object(struct fscache_object *object,
778 ret = object->cache->ops->grab_object(object, why) ? 0 : -EAGAIN;
784 * Discard a ref on an object
786 static void fscache_put_object(struct fscache_object *object,
790 object->cache->ops->put_object(object, why);
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)
802 fscache_objlist_remove(object);
805 fscache_cookie_put(object->cookie, fscache_cookie_put_object);
806 object->cookie = NULL;
811 * enqueue an object for metadata-type processing
813 void fscache_enqueue_object(struct fscache_object *object)
815 _enter("{OBJ%x}", object->debug_id);
817 if (fscache_get_object(object, fscache_obj_get_queue) >= 0) {
821 if (queue_work(fscache_object_wq, &object->work)) {
825 fscache_put_object(object, fscache_obj_put_queue);
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)
872 _enter("{OBJ%x}", object->debug_id);
874 if (list_empty(&object->dependents))
877 spin_lock(&object->lock);
879 while (!list_empty(&object->dependents)) {
880 dep = list_entry(object->dependents.next,
887 if (!list_empty(&object->dependents) && need_resched()) {
893 spin_unlock(&object->lock);
898 * remove an object from whatever queue it's waiting on
900 static void fscache_dequeue_object(struct fscache_object *object)
902 _enter("{OBJ%x}", object->debug_id);
904 if (!list_empty(&object->dep_link)) {
905 spin_lock(&object->parent->lock);
906 list_del_init(&object->dep_link);
907 spin_unlock(&object->parent->lock);
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,
930 if (!object->cookie->def->check_aux) {
935 result = object->cookie->def->check_aux(object->cookie->netfs_data,
962 * Asynchronously invalidate an object.
964 static const struct fscache_state *_fscache_invalidate_object(struct fscache_object *object,
968 struct fscache_cookie *cookie = object->cookie;
970 _enter("{OBJ%x},%d", object->debug_id, event);
973 * retire the object instead.
975 if (!fscache_use_cookie(object)) {
976 ASSERT(radix_tree_empty(&object->cookie->stores));
977 set_bit(FSCACHE_OBJECT_RETIRED, &object->flags);
984 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags);
985 fscache_cancel_all_ops(object);
992 fscache_operation_init(cookie, op, object->cache->ops->invalidate_object,
1000 if (fscache_submit_exclusive_op(object, op) < 0)
1020 fscache_mark_object_dead(object);
1021 fscache_unuse_cookie(object);
1026 fscache_mark_object_dead(object);
1028 fscache_unuse_cookie(object);
1034 static const struct fscache_state *fscache_invalidate_object(struct fscache_object *object,
1041 s = _fscache_invalidate_object(object, event);
1049 static void fscache_update_aux_data(struct fscache_object *object)
1053 object->cache->ops->update_object(object);
1058 * Asynchronously update an object.
1060 static const struct fscache_state *fscache_update_object(struct fscache_object *object,
1063 _enter("{OBJ%x},%d", object->debug_id, event);
1065 fscache_update_aux_data(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)
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,
1095 if (test_and_set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags)) {
1097 object->cache->identifier);
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,
1128 &object->flags))
1131 WARN(true, "FS-Cache object redispatched after death");