15 #define FSCACHE_DEBUG_LEVEL COOKIE
16 #include <linux/module.h>
20 [FSCACHE_OBJECT_INIT] =
"OBJECT_INIT",
21 [FSCACHE_OBJECT_LOOKING_UP] =
"OBJECT_LOOKING_UP",
22 [FSCACHE_OBJECT_CREATING] =
"OBJECT_CREATING",
23 [FSCACHE_OBJECT_AVAILABLE] =
"OBJECT_AVAILABLE",
24 [FSCACHE_OBJECT_ACTIVE] =
"OBJECT_ACTIVE",
25 [FSCACHE_OBJECT_UPDATING] =
"OBJECT_UPDATING",
26 [FSCACHE_OBJECT_DYING] =
"OBJECT_DYING",
27 [FSCACHE_OBJECT_LC_DYING] =
"OBJECT_LC_DYING",
28 [FSCACHE_OBJECT_ABORT_INIT] =
"OBJECT_ABORT_INIT",
29 [FSCACHE_OBJECT_RELEASING] =
"OBJECT_RELEASING",
30 [FSCACHE_OBJECT_RECYCLING] =
"OBJECT_RECYCLING",
31 [FSCACHE_OBJECT_WITHDRAWING] =
"OBJECT_WITHDRAWING",
32 [FSCACHE_OBJECT_DEAD] =
"OBJECT_DEAD",
37 [FSCACHE_OBJECT_INIT] =
"INIT",
38 [FSCACHE_OBJECT_LOOKING_UP] =
"LOOK",
39 [FSCACHE_OBJECT_CREATING] =
"CRTN",
40 [FSCACHE_OBJECT_AVAILABLE] =
"AVBL",
41 [FSCACHE_OBJECT_ACTIVE] =
"ACTV",
42 [FSCACHE_OBJECT_UPDATING] =
"UPDT",
43 [FSCACHE_OBJECT_DYING] =
"DYNG",
44 [FSCACHE_OBJECT_LC_DYING] =
"LCDY",
45 [FSCACHE_OBJECT_ABORT_INIT] =
"ABTI",
46 [FSCACHE_OBJECT_RELEASING] =
"RELS",
47 [FSCACHE_OBJECT_RECYCLING] =
"RCYC",
48 [FSCACHE_OBJECT_WITHDRAWING] =
"WTHD",
49 [FSCACHE_OBJECT_DEAD] =
"DEAD",
66 static inline void fscache_done_parent_op(
struct fscache_object *
object)
76 if (parent->
n_ops == 0)
78 spin_unlock(&parent->
lock);
89 static void fscache_object_state_machine(
struct fscache_object *
object)
100 switch (object->
state) {
102 case FSCACHE_OBJECT_INIT:
105 fscache_initialise_object(
object);
109 case FSCACHE_OBJECT_LOOKING_UP:
110 fscache_lookup_object(
object);
114 case FSCACHE_OBJECT_CREATING:
115 fscache_lookup_object(
object);
120 case FSCACHE_OBJECT_AVAILABLE:
121 fscache_object_available(
object);
125 case FSCACHE_OBJECT_ACTIVE:
129 case FSCACHE_OBJECT_UPDATING:
133 object->cache->ops->update_object(
object);
138 case FSCACHE_OBJECT_LC_DYING:
141 object->cache->ops->lookup_complete(
object);
144 spin_lock(&object->
lock);
145 object->state = FSCACHE_OBJECT_DYING;
146 cookie =
object->cookie;
157 spin_unlock(&object->
lock);
159 fscache_done_parent_op(
object);
163 case FSCACHE_OBJECT_DYING:
166 spin_lock(&object->
lock);
167 _debug(
"dying OBJ%x {%d,%d}",
170 object->event_mask &=
172 object->event_mask |=
178 object->event_mask &=
183 object->event_mask |=
186 spin_unlock(&object->
lock);
187 fscache_enqueue_dependents(
object);
189 goto terminal_transit;
192 case FSCACHE_OBJECT_ABORT_INIT:
196 spin_lock(&object->
lock);
197 fscache_dequeue_object(
object);
199 object->state = FSCACHE_OBJECT_DYING;
204 spin_unlock(&object->
lock);
209 case FSCACHE_OBJECT_RELEASING:
210 case FSCACHE_OBJECT_RECYCLING:
211 object->event_mask &=
216 fscache_release_object(
object);
217 spin_lock(&object->
lock);
218 object->state = FSCACHE_OBJECT_DEAD;
219 spin_unlock(&object->
lock);
221 goto terminal_transit;
225 case FSCACHE_OBJECT_WITHDRAWING:
226 object->event_mask &=
231 fscache_withdraw_object(
object);
232 spin_lock(&object->
lock);
233 object->state = FSCACHE_OBJECT_DEAD;
234 spin_unlock(&object->
lock);
236 goto terminal_transit;
240 case FSCACHE_OBJECT_DEAD:
242 " Unexpected event in dead state %lx\n",
259 new_state = FSCACHE_OBJECT_LC_DYING;
266 goto unsupported_event;
276 new_state = FSCACHE_OBJECT_DYING;
279 new_state = FSCACHE_OBJECT_UPDATING;
282 new_state = FSCACHE_OBJECT_ACTIVE;
285 goto unsupported_event;
292 new_state = FSCACHE_OBJECT_WITHDRAWING;
295 new_state = FSCACHE_OBJECT_RECYCLING;
298 new_state = FSCACHE_OBJECT_RELEASING;
301 new_state = FSCACHE_OBJECT_WITHDRAWING;
304 new_state = FSCACHE_OBJECT_DYING;
309 goto unsupported_event;
313 spin_lock(&object->
lock);
315 spin_unlock(&object->
lock);
323 " Unsupported event %lx [mask %lx] in state %s\n",
341 fscache_object_state_machine(
object);
346 fscache_put_object(
object);
359 static void fscache_initialise_object(
struct fscache_object *
object)
372 spin_lock(&object->
lock);
374 spin_unlock(&object->
lock);
378 spin_lock(&object->
cookie->lock);
386 spin_lock(&object->
lock);
399 if (list_empty(&object->
dep_link)) {
401 object->cache->ops->grab_object(
object);
420 spin_unlock(&parent->
lock);
421 spin_unlock(&object->
lock);
424 spin_unlock(&object->
cookie->parent->lock);
425 spin_unlock(&object->
cookie->lock);
460 _debug(
"LOOKUP \"%s/%s\" in \"%s\"",
461 parent->
cookie->def->name, cookie->
def->name,
462 object->
cache->tag->name);
466 ret =
object->cache->ops->lookup_object(
object);
496 spin_lock(&object->
lock);
497 if (object->
state == FSCACHE_OBJECT_LOOKING_UP) {
502 object->state = FSCACHE_OBJECT_CREATING;
503 spin_unlock(&object->
lock);
516 spin_unlock(&object->
lock);
542 spin_lock(&object->
lock);
543 if (object->
state == FSCACHE_OBJECT_LOOKING_UP) {
548 object->state = FSCACHE_OBJECT_AVAILABLE;
549 spin_unlock(&object->
lock);
560 object->state = FSCACHE_OBJECT_AVAILABLE;
561 spin_unlock(&object->
lock);
576 static void fscache_object_available(
struct fscache_object *
object)
580 spin_lock(&object->
lock);
586 fscache_done_parent_op(
object);
588 if (object->
n_ops > 0) {
597 spin_unlock(&object->
lock);
600 object->cache->ops->lookup_complete(
object);
602 fscache_enqueue_dependents(
object);
628 cache->
ops->drop_object(
object);
632 _debug(
"release parent OBJ%x {%d}",
635 spin_lock(&parent->
lock);
639 spin_unlock(&parent->
lock);
640 object->parent =
NULL;
644 fscache_put_object(
object);
656 fscache_drop_object(
object);
662 static void fscache_withdraw_object(
struct fscache_object *
object)
669 spin_lock(&object->
lock);
670 cookie =
object->cookie;
675 spin_unlock(&object->
lock);
678 spin_lock(&cookie->
lock);
679 spin_lock(&object->
lock);
681 if (object->
cookie == cookie) {
683 object->cookie =
NULL;
686 spin_unlock(&cookie->
lock);
687 fscache_cookie_put(cookie);
689 fscache_cookie_put(cookie);
692 spin_unlock(&object->
lock);
694 fscache_drop_object(
object);
710 bool enqueue =
false;
714 spin_lock(&object->
lock);
715 if (object->
state < FSCACHE_OBJECT_WITHDRAWING) {
716 object->state = FSCACHE_OBJECT_WITHDRAWING;
719 spin_unlock(&object->
lock);
735 ret =
object->cache->ops->grab_object(
object) ? 0 : -
EAGAIN;
746 object->cache->ops->put_object(
object);
757 if (fscache_get_object(
object) >= 0) {
762 if (fscache_object_congested())
765 fscache_put_object(
object);
788 if (fscache_object_congested())
792 if (!fscache_object_congested())
796 return fscache_object_congested();
805 static void fscache_enqueue_dependents(
struct fscache_object *
object)
814 spin_lock(&object->
lock);
824 fscache_put_object(dep);
830 spin_unlock(&object->
lock);
841 if (!list_empty(&object->
dep_link)) {
842 spin_lock(&object->
parent->lock);
844 spin_unlock(&object->
parent->lock);
863 if (!object->
cookie->def->check_aux) {
868 result =
object->cookie->def->check_aux(object->
cookie->netfs_data,