1 /* FS-Cache object state machine handler
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * See Documentation/filesystems/caching/object.txt for a description of the
12 * object state machine and the in-kernel representations.
15 #define FSCACHE_DEBUG_LEVEL COOKIE
16 #include <linux/module.h>
19 const char *fscache_object_states
[] = {
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",
34 EXPORT_SYMBOL(fscache_object_states
);
36 static void fscache_object_slow_work_put_ref(struct slow_work
*);
37 static int fscache_object_slow_work_get_ref(struct slow_work
*);
38 static void fscache_object_slow_work_execute(struct slow_work
*);
39 static void fscache_initialise_object(struct fscache_object
*);
40 static void fscache_lookup_object(struct fscache_object
*);
41 static void fscache_object_available(struct fscache_object
*);
42 static void fscache_release_object(struct fscache_object
*);
43 static void fscache_withdraw_object(struct fscache_object
*);
44 static void fscache_enqueue_dependents(struct fscache_object
*);
45 static void fscache_dequeue_object(struct fscache_object
*);
47 const struct slow_work_ops fscache_object_slow_work_ops
= {
49 .get_ref
= fscache_object_slow_work_get_ref
,
50 .put_ref
= fscache_object_slow_work_put_ref
,
51 .execute
= fscache_object_slow_work_execute
,
53 EXPORT_SYMBOL(fscache_object_slow_work_ops
);
56 * we need to notify the parent when an op completes that we had outstanding
59 static inline void fscache_done_parent_op(struct fscache_object
*object
)
61 struct fscache_object
*parent
= object
->parent
;
63 _enter("OBJ%x {OBJ%x,%x}",
64 object
->debug_id
, parent
->debug_id
, parent
->n_ops
);
66 spin_lock_nested(&parent
->lock
, 1);
69 if (parent
->n_ops
== 0)
70 fscache_raise_event(parent
, FSCACHE_OBJECT_EV_CLEARED
);
71 spin_unlock(&parent
->lock
);
75 * process events that have been sent to an object's state machine
76 * - initiates parent lookup
77 * - does object lookup
78 * - does object creation
79 * - does object recycling and retirement
80 * - does object withdrawal
82 static void fscache_object_state_machine(struct fscache_object
*object
)
84 enum fscache_object_state new_state
;
86 ASSERT(object
!= NULL
);
88 _enter("{OBJ%x,%s,%lx}",
89 object
->debug_id
, fscache_object_states
[object
->state
],
92 switch (object
->state
) {
93 /* wait for the parent object to become ready */
94 case FSCACHE_OBJECT_INIT
:
96 ULONG_MAX
& ~(1 << FSCACHE_OBJECT_EV_CLEARED
);
97 fscache_initialise_object(object
);
100 /* look up the object metadata on disk */
101 case FSCACHE_OBJECT_LOOKING_UP
:
102 fscache_lookup_object(object
);
105 /* create the object metadata on disk */
106 case FSCACHE_OBJECT_CREATING
:
107 fscache_lookup_object(object
);
110 /* handle an object becoming available; start pending
111 * operations and queue dependent operations for processing */
112 case FSCACHE_OBJECT_AVAILABLE
:
113 fscache_object_available(object
);
116 /* normal running state */
117 case FSCACHE_OBJECT_ACTIVE
:
120 /* update the object metadata on disk */
121 case FSCACHE_OBJECT_UPDATING
:
122 clear_bit(FSCACHE_OBJECT_EV_UPDATE
, &object
->events
);
123 fscache_stat(&fscache_n_updates_run
);
124 object
->cache
->ops
->update_object(object
);
127 /* handle an object dying during lookup or creation */
128 case FSCACHE_OBJECT_LC_DYING
:
129 object
->event_mask
&= ~(1 << FSCACHE_OBJECT_EV_UPDATE
);
130 object
->cache
->ops
->lookup_complete(object
);
132 spin_lock(&object
->lock
);
133 object
->state
= FSCACHE_OBJECT_DYING
;
134 if (test_and_clear_bit(FSCACHE_COOKIE_CREATING
,
135 &object
->cookie
->flags
))
136 wake_up_bit(&object
->cookie
->flags
,
137 FSCACHE_COOKIE_CREATING
);
138 spin_unlock(&object
->lock
);
140 fscache_done_parent_op(object
);
142 /* wait for completion of all active operations on this object
143 * and the death of all child objects of this object */
144 case FSCACHE_OBJECT_DYING
:
146 clear_bit(FSCACHE_OBJECT_EV_CLEARED
, &object
->events
);
147 spin_lock(&object
->lock
);
148 _debug("dying OBJ%x {%d,%d}",
149 object
->debug_id
, object
->n_ops
, object
->n_children
);
150 if (object
->n_ops
== 0 && object
->n_children
== 0) {
151 object
->event_mask
&=
152 ~(1 << FSCACHE_OBJECT_EV_CLEARED
);
153 object
->event_mask
|=
154 (1 << FSCACHE_OBJECT_EV_WITHDRAW
) |
155 (1 << FSCACHE_OBJECT_EV_RETIRE
) |
156 (1 << FSCACHE_OBJECT_EV_RELEASE
) |
157 (1 << FSCACHE_OBJECT_EV_ERROR
);
159 object
->event_mask
&=
160 ~((1 << FSCACHE_OBJECT_EV_WITHDRAW
) |
161 (1 << FSCACHE_OBJECT_EV_RETIRE
) |
162 (1 << FSCACHE_OBJECT_EV_RELEASE
) |
163 (1 << FSCACHE_OBJECT_EV_ERROR
));
164 object
->event_mask
|=
165 1 << FSCACHE_OBJECT_EV_CLEARED
;
167 spin_unlock(&object
->lock
);
168 fscache_enqueue_dependents(object
);
169 goto terminal_transit
;
171 /* handle an abort during initialisation */
172 case FSCACHE_OBJECT_ABORT_INIT
:
173 _debug("handle abort init %lx", object
->events
);
174 object
->event_mask
&= ~(1 << FSCACHE_OBJECT_EV_UPDATE
);
176 spin_lock(&object
->lock
);
177 fscache_dequeue_object(object
);
179 object
->state
= FSCACHE_OBJECT_DYING
;
180 if (test_and_clear_bit(FSCACHE_COOKIE_CREATING
,
181 &object
->cookie
->flags
))
182 wake_up_bit(&object
->cookie
->flags
,
183 FSCACHE_COOKIE_CREATING
);
184 spin_unlock(&object
->lock
);
187 /* handle the netfs releasing an object and possibly marking it
189 case FSCACHE_OBJECT_RELEASING
:
190 case FSCACHE_OBJECT_RECYCLING
:
191 object
->event_mask
&=
192 ~((1 << FSCACHE_OBJECT_EV_WITHDRAW
) |
193 (1 << FSCACHE_OBJECT_EV_RETIRE
) |
194 (1 << FSCACHE_OBJECT_EV_RELEASE
) |
195 (1 << FSCACHE_OBJECT_EV_ERROR
));
196 fscache_release_object(object
);
197 spin_lock(&object
->lock
);
198 object
->state
= FSCACHE_OBJECT_DEAD
;
199 spin_unlock(&object
->lock
);
200 fscache_stat(&fscache_n_object_dead
);
201 goto terminal_transit
;
203 /* handle the parent cache of this object being withdrawn from
205 case FSCACHE_OBJECT_WITHDRAWING
:
206 object
->event_mask
&=
207 ~((1 << FSCACHE_OBJECT_EV_WITHDRAW
) |
208 (1 << FSCACHE_OBJECT_EV_RETIRE
) |
209 (1 << FSCACHE_OBJECT_EV_RELEASE
) |
210 (1 << FSCACHE_OBJECT_EV_ERROR
));
211 fscache_withdraw_object(object
);
212 spin_lock(&object
->lock
);
213 object
->state
= FSCACHE_OBJECT_DEAD
;
214 spin_unlock(&object
->lock
);
215 fscache_stat(&fscache_n_object_dead
);
216 goto terminal_transit
;
218 /* complain about the object being woken up once it is
220 case FSCACHE_OBJECT_DEAD
:
221 printk(KERN_ERR
"FS-Cache:"
222 " Unexpected event in dead state %lx\n",
223 object
->events
& object
->event_mask
);
227 printk(KERN_ERR
"FS-Cache: Unknown object state %u\n",
232 /* determine the transition from a lookup state */
234 switch (fls(object
->events
& object
->event_mask
) - 1) {
235 case FSCACHE_OBJECT_EV_WITHDRAW
:
236 case FSCACHE_OBJECT_EV_RETIRE
:
237 case FSCACHE_OBJECT_EV_RELEASE
:
238 case FSCACHE_OBJECT_EV_ERROR
:
239 new_state
= FSCACHE_OBJECT_LC_DYING
;
241 case FSCACHE_OBJECT_EV_REQUEUE
:
244 goto done
; /* sleep until event */
246 goto unsupported_event
;
249 /* determine the transition from an active state */
251 switch (fls(object
->events
& object
->event_mask
) - 1) {
252 case FSCACHE_OBJECT_EV_WITHDRAW
:
253 case FSCACHE_OBJECT_EV_RETIRE
:
254 case FSCACHE_OBJECT_EV_RELEASE
:
255 case FSCACHE_OBJECT_EV_ERROR
:
256 new_state
= FSCACHE_OBJECT_DYING
;
258 case FSCACHE_OBJECT_EV_UPDATE
:
259 new_state
= FSCACHE_OBJECT_UPDATING
;
262 new_state
= FSCACHE_OBJECT_ACTIVE
;
263 goto change_state
; /* sleep until event */
265 goto unsupported_event
;
268 /* determine the transition from a terminal state */
270 switch (fls(object
->events
& object
->event_mask
) - 1) {
271 case FSCACHE_OBJECT_EV_WITHDRAW
:
272 new_state
= FSCACHE_OBJECT_WITHDRAWING
;
274 case FSCACHE_OBJECT_EV_RETIRE
:
275 new_state
= FSCACHE_OBJECT_RECYCLING
;
277 case FSCACHE_OBJECT_EV_RELEASE
:
278 new_state
= FSCACHE_OBJECT_RELEASING
;
280 case FSCACHE_OBJECT_EV_ERROR
:
281 new_state
= FSCACHE_OBJECT_WITHDRAWING
;
283 case FSCACHE_OBJECT_EV_CLEARED
:
284 new_state
= FSCACHE_OBJECT_DYING
;
287 goto done
; /* sleep until event */
289 goto unsupported_event
;
293 spin_lock(&object
->lock
);
294 object
->state
= new_state
;
295 spin_unlock(&object
->lock
);
298 _leave(" [->%s]", fscache_object_states
[object
->state
]);
302 printk(KERN_ERR
"FS-Cache:"
303 " Unsupported event %lx [mask %lx] in state %s\n",
304 object
->events
, object
->event_mask
,
305 fscache_object_states
[object
->state
]);
312 static void fscache_object_slow_work_execute(struct slow_work
*work
)
314 struct fscache_object
*object
=
315 container_of(work
, struct fscache_object
, work
);
318 _enter("{OBJ%x}", object
->debug_id
);
320 clear_bit(FSCACHE_OBJECT_EV_REQUEUE
, &object
->events
);
323 fscache_object_state_machine(object
);
324 fscache_hist(fscache_objs_histogram
, start
);
325 if (object
->events
& object
->event_mask
)
326 fscache_enqueue_object(object
);
330 * initialise an object
331 * - check the specified object's parent to see if we can make use of it
332 * immediately to do a creation
333 * - we may need to start the process of creating a parent and we need to wait
334 * for the parent's lookup and creation to complete if it's not there yet
335 * - an object's cookie is pinned until we clear FSCACHE_COOKIE_CREATING on the
336 * leaf-most cookies of the object and all its children
338 static void fscache_initialise_object(struct fscache_object
*object
)
340 struct fscache_object
*parent
;
343 ASSERT(object
->cookie
!= NULL
);
344 ASSERT(object
->cookie
->parent
!= NULL
);
345 ASSERT(list_empty(&object
->work
.link
));
347 if (object
->events
& ((1 << FSCACHE_OBJECT_EV_ERROR
) |
348 (1 << FSCACHE_OBJECT_EV_RELEASE
) |
349 (1 << FSCACHE_OBJECT_EV_RETIRE
) |
350 (1 << FSCACHE_OBJECT_EV_WITHDRAW
))) {
351 _debug("abort init %lx", object
->events
);
352 spin_lock(&object
->lock
);
353 object
->state
= FSCACHE_OBJECT_ABORT_INIT
;
354 spin_unlock(&object
->lock
);
358 spin_lock(&object
->cookie
->lock
);
359 spin_lock_nested(&object
->cookie
->parent
->lock
, 1);
361 parent
= object
->parent
;
364 set_bit(FSCACHE_OBJECT_EV_WITHDRAW
, &object
->events
);
366 spin_lock(&object
->lock
);
367 spin_lock_nested(&parent
->lock
, 1);
368 _debug("parent %s", fscache_object_states
[parent
->state
]);
370 if (parent
->state
>= FSCACHE_OBJECT_DYING
) {
371 _debug("bad parent");
372 set_bit(FSCACHE_OBJECT_EV_WITHDRAW
, &object
->events
);
373 } else if (parent
->state
< FSCACHE_OBJECT_AVAILABLE
) {
376 /* we may get woken up in this state by child objects
377 * binding on to us, so we need to make sure we don't
378 * add ourself to the list multiple times */
379 if (list_empty(&object
->dep_link
)) {
380 object
->cache
->ops
->grab_object(object
);
381 list_add(&object
->dep_link
,
382 &parent
->dependents
);
384 /* fscache_acquire_non_index_cookie() uses this
385 * to wake the chain up */
386 if (parent
->state
== FSCACHE_OBJECT_INIT
)
387 fscache_enqueue_object(parent
);
393 object
->lookup_jif
= jiffies
;
394 object
->state
= FSCACHE_OBJECT_LOOKING_UP
;
395 set_bit(FSCACHE_OBJECT_EV_REQUEUE
, &object
->events
);
398 spin_unlock(&parent
->lock
);
399 spin_unlock(&object
->lock
);
402 spin_unlock(&object
->cookie
->parent
->lock
);
403 spin_unlock(&object
->cookie
->lock
);
408 * look an object up in the cache from which it was allocated
409 * - we hold an "access lock" on the parent object, so the parent object cannot
410 * be withdrawn by either party till we've finished
411 * - an object's cookie is pinned until we clear FSCACHE_COOKIE_CREATING on the
412 * leaf-most cookies of the object and all its children
414 static void fscache_lookup_object(struct fscache_object
*object
)
416 struct fscache_cookie
*cookie
= object
->cookie
;
417 struct fscache_object
*parent
;
421 parent
= object
->parent
;
422 ASSERT(parent
!= NULL
);
423 ASSERTCMP(parent
->n_ops
, >, 0);
424 ASSERTCMP(parent
->n_obj_ops
, >, 0);
426 /* make sure the parent is still available */
427 ASSERTCMP(parent
->state
, >=, FSCACHE_OBJECT_AVAILABLE
);
429 if (parent
->state
>= FSCACHE_OBJECT_DYING
||
430 test_bit(FSCACHE_IOERROR
, &object
->cache
->flags
)) {
431 _debug("unavailable");
432 set_bit(FSCACHE_OBJECT_EV_WITHDRAW
, &object
->events
);
437 _debug("LOOKUP \"%s/%s\" in \"%s\"",
438 parent
->cookie
->def
->name
, cookie
->def
->name
,
439 object
->cache
->tag
->name
);
441 fscache_stat(&fscache_n_object_lookups
);
442 object
->cache
->ops
->lookup_object(object
);
444 if (test_bit(FSCACHE_OBJECT_EV_ERROR
, &object
->events
))
445 set_bit(FSCACHE_COOKIE_UNAVAILABLE
, &cookie
->flags
);
451 * fscache_object_lookup_negative - Note negative cookie lookup
452 * @object: Object pointing to cookie to mark
454 * Note negative lookup, permitting those waiting to read data from an already
455 * existing backing object to continue as there's no data for them to read.
457 void fscache_object_lookup_negative(struct fscache_object
*object
)
459 struct fscache_cookie
*cookie
= object
->cookie
;
462 object
->debug_id
, fscache_object_states
[object
->state
]);
464 spin_lock(&object
->lock
);
465 if (object
->state
== FSCACHE_OBJECT_LOOKING_UP
) {
466 fscache_stat(&fscache_n_object_lookups_negative
);
468 /* transit here to allow write requests to begin stacking up
469 * and read requests to begin returning ENODATA */
470 object
->state
= FSCACHE_OBJECT_CREATING
;
471 spin_unlock(&object
->lock
);
473 set_bit(FSCACHE_COOKIE_PENDING_FILL
, &cookie
->flags
);
474 set_bit(FSCACHE_COOKIE_NO_DATA_YET
, &cookie
->flags
);
476 _debug("wake up lookup %p", &cookie
->flags
);
477 smp_mb__before_clear_bit();
478 clear_bit(FSCACHE_COOKIE_LOOKING_UP
, &cookie
->flags
);
479 smp_mb__after_clear_bit();
480 wake_up_bit(&cookie
->flags
, FSCACHE_COOKIE_LOOKING_UP
);
481 set_bit(FSCACHE_OBJECT_EV_REQUEUE
, &object
->events
);
483 ASSERTCMP(object
->state
, ==, FSCACHE_OBJECT_CREATING
);
484 spin_unlock(&object
->lock
);
489 EXPORT_SYMBOL(fscache_object_lookup_negative
);
492 * fscache_obtained_object - Note successful object lookup or creation
493 * @object: Object pointing to cookie to mark
495 * Note successful lookup and/or creation, permitting those waiting to write
496 * data to a backing object to continue.
498 * Note that after calling this, an object's cookie may be relinquished by the
499 * netfs, and so must be accessed with object lock held.
501 void fscache_obtained_object(struct fscache_object
*object
)
503 struct fscache_cookie
*cookie
= object
->cookie
;
506 object
->debug_id
, fscache_object_states
[object
->state
]);
508 /* if we were still looking up, then we must have a positive lookup
509 * result, in which case there may be data available */
510 spin_lock(&object
->lock
);
511 if (object
->state
== FSCACHE_OBJECT_LOOKING_UP
) {
512 fscache_stat(&fscache_n_object_lookups_positive
);
514 clear_bit(FSCACHE_COOKIE_NO_DATA_YET
, &cookie
->flags
);
516 object
->state
= FSCACHE_OBJECT_AVAILABLE
;
517 spin_unlock(&object
->lock
);
519 smp_mb__before_clear_bit();
520 clear_bit(FSCACHE_COOKIE_LOOKING_UP
, &cookie
->flags
);
521 smp_mb__after_clear_bit();
522 wake_up_bit(&cookie
->flags
, FSCACHE_COOKIE_LOOKING_UP
);
523 set_bit(FSCACHE_OBJECT_EV_REQUEUE
, &object
->events
);
525 ASSERTCMP(object
->state
, ==, FSCACHE_OBJECT_CREATING
);
526 fscache_stat(&fscache_n_object_created
);
528 object
->state
= FSCACHE_OBJECT_AVAILABLE
;
529 spin_unlock(&object
->lock
);
530 set_bit(FSCACHE_OBJECT_EV_REQUEUE
, &object
->events
);
534 if (test_and_clear_bit(FSCACHE_COOKIE_CREATING
, &cookie
->flags
))
535 wake_up_bit(&cookie
->flags
, FSCACHE_COOKIE_CREATING
);
539 EXPORT_SYMBOL(fscache_obtained_object
);
542 * handle an object that has just become available
544 static void fscache_object_available(struct fscache_object
*object
)
546 _enter("{OBJ%x}", object
->debug_id
);
548 spin_lock(&object
->lock
);
550 if (test_and_clear_bit(FSCACHE_COOKIE_CREATING
, &object
->cookie
->flags
))
551 wake_up_bit(&object
->cookie
->flags
, FSCACHE_COOKIE_CREATING
);
553 fscache_done_parent_op(object
);
554 if (object
->n_in_progress
== 0) {
555 if (object
->n_ops
> 0) {
556 ASSERTCMP(object
->n_ops
, >=, object
->n_obj_ops
);
557 ASSERTIF(object
->n_ops
> object
->n_obj_ops
,
558 !list_empty(&object
->pending_ops
));
559 fscache_start_operations(object
);
561 ASSERT(list_empty(&object
->pending_ops
));
564 spin_unlock(&object
->lock
);
566 object
->cache
->ops
->lookup_complete(object
);
567 fscache_enqueue_dependents(object
);
569 fscache_hist(fscache_obj_instantiate_histogram
, object
->lookup_jif
);
570 fscache_stat(&fscache_n_object_avail
);
576 * drop an object's attachments
578 static void fscache_drop_object(struct fscache_object
*object
)
580 struct fscache_object
*parent
= object
->parent
;
581 struct fscache_cache
*cache
= object
->cache
;
583 _enter("{OBJ%x,%d}", object
->debug_id
, object
->n_children
);
585 spin_lock(&cache
->object_list_lock
);
586 list_del_init(&object
->cache_link
);
587 spin_unlock(&cache
->object_list_lock
);
589 cache
->ops
->drop_object(object
);
592 _debug("release parent OBJ%x {%d}",
593 parent
->debug_id
, parent
->n_children
);
595 spin_lock(&parent
->lock
);
596 parent
->n_children
--;
597 if (parent
->n_children
== 0)
598 fscache_raise_event(parent
, FSCACHE_OBJECT_EV_CLEARED
);
599 spin_unlock(&parent
->lock
);
600 object
->parent
= NULL
;
603 /* this just shifts the object release to the slow work processor */
604 object
->cache
->ops
->put_object(object
);
610 * release or recycle an object that the netfs has discarded
612 static void fscache_release_object(struct fscache_object
*object
)
616 fscache_drop_object(object
);
620 * withdraw an object from active service
622 static void fscache_withdraw_object(struct fscache_object
*object
)
624 struct fscache_cookie
*cookie
;
629 spin_lock(&object
->lock
);
630 cookie
= object
->cookie
;
632 /* need to get the cookie lock before the object lock, starting
633 * from the object pointer */
634 atomic_inc(&cookie
->usage
);
635 spin_unlock(&object
->lock
);
638 spin_lock(&cookie
->lock
);
639 spin_lock(&object
->lock
);
641 if (object
->cookie
== cookie
) {
642 hlist_del_init(&object
->cookie_link
);
643 object
->cookie
= NULL
;
646 spin_unlock(&cookie
->lock
);
647 fscache_cookie_put(cookie
);
649 fscache_cookie_put(cookie
);
652 spin_unlock(&object
->lock
);
654 fscache_drop_object(object
);
658 * withdraw an object from active service at the behest of the cache
659 * - need break the links to a cached object cookie
660 * - called under two situations:
661 * (1) recycler decides to reclaim an in-use object
662 * (2) a cache is unmounted
663 * - have to take care as the cookie can be being relinquished by the netfs
665 * - the object is pinned by the caller holding a refcount on it
667 void fscache_withdrawing_object(struct fscache_cache
*cache
,
668 struct fscache_object
*object
)
670 bool enqueue
= false;
672 _enter(",OBJ%x", object
->debug_id
);
674 spin_lock(&object
->lock
);
675 if (object
->state
< FSCACHE_OBJECT_WITHDRAWING
) {
676 object
->state
= FSCACHE_OBJECT_WITHDRAWING
;
679 spin_unlock(&object
->lock
);
682 fscache_enqueue_object(object
);
688 * allow the slow work item processor to get a ref on an object
690 static int fscache_object_slow_work_get_ref(struct slow_work
*work
)
692 struct fscache_object
*object
=
693 container_of(work
, struct fscache_object
, work
);
695 return object
->cache
->ops
->grab_object(object
) ? 0 : -EAGAIN
;
699 * allow the slow work item processor to discard a ref on a work item
701 static void fscache_object_slow_work_put_ref(struct slow_work
*work
)
703 struct fscache_object
*object
=
704 container_of(work
, struct fscache_object
, work
);
706 return object
->cache
->ops
->put_object(object
);
710 * enqueue an object for metadata-type processing
712 void fscache_enqueue_object(struct fscache_object
*object
)
714 _enter("{OBJ%x}", object
->debug_id
);
716 slow_work_enqueue(&object
->work
);
720 * enqueue the dependents of an object for metadata-type processing
721 * - the caller must hold the object's lock
722 * - this may cause an already locked object to wind up being processed again
724 static void fscache_enqueue_dependents(struct fscache_object
*object
)
726 struct fscache_object
*dep
;
728 _enter("{OBJ%x}", object
->debug_id
);
730 if (list_empty(&object
->dependents
))
733 spin_lock(&object
->lock
);
735 while (!list_empty(&object
->dependents
)) {
736 dep
= list_entry(object
->dependents
.next
,
737 struct fscache_object
, dep_link
);
738 list_del_init(&dep
->dep_link
);
741 /* sort onto appropriate lists */
742 fscache_enqueue_object(dep
);
743 dep
->cache
->ops
->put_object(dep
);
745 if (!list_empty(&object
->dependents
))
746 cond_resched_lock(&object
->lock
);
749 spin_unlock(&object
->lock
);
753 * remove an object from whatever queue it's waiting on
754 * - the caller must hold object->lock
756 void fscache_dequeue_object(struct fscache_object
*object
)
758 _enter("{OBJ%x}", object
->debug_id
);
760 if (!list_empty(&object
->dep_link
)) {
761 spin_lock(&object
->parent
->lock
);
762 list_del_init(&object
->dep_link
);
763 spin_unlock(&object
->parent
->lock
);
770 * fscache_check_aux - Ask the netfs whether an object on disk is still valid
771 * @object: The object to ask about
772 * @data: The auxiliary data for the object
773 * @datalen: The size of the auxiliary data
775 * This function consults the netfs about the coherency state of an object
777 enum fscache_checkaux
fscache_check_aux(struct fscache_object
*object
,
778 const void *data
, uint16_t datalen
)
780 enum fscache_checkaux result
;
782 if (!object
->cookie
->def
->check_aux
) {
783 fscache_stat(&fscache_n_checkaux_none
);
784 return FSCACHE_CHECKAUX_OKAY
;
787 result
= object
->cookie
->def
->check_aux(object
->cookie
->netfs_data
,
790 /* entry okay as is */
791 case FSCACHE_CHECKAUX_OKAY
:
792 fscache_stat(&fscache_n_checkaux_okay
);
795 /* entry requires update */
796 case FSCACHE_CHECKAUX_NEEDS_UPDATE
:
797 fscache_stat(&fscache_n_checkaux_update
);
800 /* entry requires deletion */
801 case FSCACHE_CHECKAUX_OBSOLETE
:
802 fscache_stat(&fscache_n_checkaux_obsolete
);
811 EXPORT_SYMBOL(fscache_check_aux
);