]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/fscache/cookie.c
UBUNTU: [Config] arm64: snapdragon: DRM_MSM=m
[mirror_ubuntu-bionic-kernel.git] / fs / fscache / cookie.c
1 /* netfs cookie management
2 *
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
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.
10 *
11 * See Documentation/filesystems/caching/netfs-api.txt for more information on
12 * the netfs API.
13 */
14
15 #define FSCACHE_DEBUG_LEVEL COOKIE
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include "internal.h"
19
20 struct kmem_cache *fscache_cookie_jar;
21
22 static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
23
24 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
25 static int fscache_alloc_object(struct fscache_cache *cache,
26 struct fscache_cookie *cookie);
27 static int fscache_attach_object(struct fscache_cookie *cookie,
28 struct fscache_object *object);
29
30 /*
31 * initialise an cookie jar slab element prior to any use
32 */
33 void fscache_cookie_init_once(void *_cookie)
34 {
35 struct fscache_cookie *cookie = _cookie;
36
37 memset(cookie, 0, sizeof(*cookie));
38 spin_lock_init(&cookie->lock);
39 spin_lock_init(&cookie->stores_lock);
40 INIT_HLIST_HEAD(&cookie->backing_objects);
41 }
42
43 /*
44 * request a cookie to represent an object (index, datafile, xattr, etc)
45 * - parent specifies the parent object
46 * - the top level index cookie for each netfs is stored in the fscache_netfs
47 * struct upon registration
48 * - def points to the definition
49 * - the netfs_data will be passed to the functions pointed to in *def
50 * - all attached caches will be searched to see if they contain this object
51 * - index objects aren't stored on disk until there's a dependent file that
52 * needs storing
53 * - other objects are stored in a selected cache immediately, and all the
54 * indices forming the path to it are instantiated if necessary
55 * - we never let on to the netfs about errors
56 * - we may set a negative cookie pointer, but that's okay
57 */
58 struct fscache_cookie *__fscache_acquire_cookie(
59 struct fscache_cookie *parent,
60 const struct fscache_cookie_def *def,
61 void *netfs_data,
62 bool enable)
63 {
64 struct fscache_cookie *cookie;
65
66 BUG_ON(!def);
67
68 _enter("{%s},{%s},%p,%u",
69 parent ? (char *) parent->def->name : "<no-parent>",
70 def->name, netfs_data, enable);
71
72 fscache_stat(&fscache_n_acquires);
73
74 /* if there's no parent cookie, then we don't create one here either */
75 if (!parent) {
76 fscache_stat(&fscache_n_acquires_null);
77 _leave(" [no parent]");
78 return NULL;
79 }
80
81 /* validate the definition */
82 BUG_ON(!def->get_key);
83 BUG_ON(!def->name[0]);
84
85 BUG_ON(def->type == FSCACHE_COOKIE_TYPE_INDEX &&
86 parent->def->type != FSCACHE_COOKIE_TYPE_INDEX);
87
88 /* allocate and initialise a cookie */
89 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
90 if (!cookie) {
91 fscache_stat(&fscache_n_acquires_oom);
92 _leave(" [ENOMEM]");
93 return NULL;
94 }
95
96 atomic_set(&cookie->usage, 1);
97 atomic_set(&cookie->n_children, 0);
98
99 /* We keep the active count elevated until relinquishment to prevent an
100 * attempt to wake up every time the object operations queue quiesces.
101 */
102 atomic_set(&cookie->n_active, 1);
103
104 atomic_inc(&parent->usage);
105 atomic_inc(&parent->n_children);
106
107 cookie->def = def;
108 cookie->parent = parent;
109 cookie->netfs_data = netfs_data;
110 cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET);
111
112 /* radix tree insertion won't use the preallocation pool unless it's
113 * told it may not wait */
114 INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
115
116 switch (cookie->def->type) {
117 case FSCACHE_COOKIE_TYPE_INDEX:
118 fscache_stat(&fscache_n_cookie_index);
119 break;
120 case FSCACHE_COOKIE_TYPE_DATAFILE:
121 fscache_stat(&fscache_n_cookie_data);
122 break;
123 default:
124 fscache_stat(&fscache_n_cookie_special);
125 break;
126 }
127
128 if (enable) {
129 /* if the object is an index then we need do nothing more here
130 * - we create indices on disk when we need them as an index
131 * may exist in multiple caches */
132 if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) {
133 if (fscache_acquire_non_index_cookie(cookie) == 0) {
134 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
135 } else {
136 atomic_dec(&parent->n_children);
137 __fscache_cookie_put(cookie);
138 fscache_stat(&fscache_n_acquires_nobufs);
139 _leave(" = NULL");
140 return NULL;
141 }
142 } else {
143 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
144 }
145 }
146
147 fscache_stat(&fscache_n_acquires_ok);
148 _leave(" = %p", cookie);
149 return cookie;
150 }
151 EXPORT_SYMBOL(__fscache_acquire_cookie);
152
153 /*
154 * Enable a cookie to permit it to accept new operations.
155 */
156 void __fscache_enable_cookie(struct fscache_cookie *cookie,
157 bool (*can_enable)(void *data),
158 void *data)
159 {
160 _enter("%p", cookie);
161
162 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
163 TASK_UNINTERRUPTIBLE);
164
165 if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags))
166 goto out_unlock;
167
168 if (can_enable && !can_enable(data)) {
169 /* The netfs decided it didn't want to enable after all */
170 } else if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) {
171 /* Wait for outstanding disablement to complete */
172 __fscache_wait_on_invalidate(cookie);
173
174 if (fscache_acquire_non_index_cookie(cookie) == 0)
175 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
176 } else {
177 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
178 }
179
180 out_unlock:
181 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
182 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
183 }
184 EXPORT_SYMBOL(__fscache_enable_cookie);
185
186 /*
187 * acquire a non-index cookie
188 * - this must make sure the index chain is instantiated and instantiate the
189 * object representation too
190 */
191 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
192 {
193 struct fscache_object *object;
194 struct fscache_cache *cache;
195 uint64_t i_size;
196 int ret;
197
198 _enter("");
199
200 set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags);
201
202 /* now we need to see whether the backing objects for this cookie yet
203 * exist, if not there'll be nothing to search */
204 down_read(&fscache_addremove_sem);
205
206 if (list_empty(&fscache_cache_list)) {
207 up_read(&fscache_addremove_sem);
208 _leave(" = 0 [no caches]");
209 return 0;
210 }
211
212 /* select a cache in which to store the object */
213 cache = fscache_select_cache_for_object(cookie->parent);
214 if (!cache) {
215 up_read(&fscache_addremove_sem);
216 fscache_stat(&fscache_n_acquires_no_cache);
217 _leave(" = -ENOMEDIUM [no cache]");
218 return -ENOMEDIUM;
219 }
220
221 _debug("cache %s", cache->tag->name);
222
223 set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
224
225 /* ask the cache to allocate objects for this cookie and its parent
226 * chain */
227 ret = fscache_alloc_object(cache, cookie);
228 if (ret < 0) {
229 up_read(&fscache_addremove_sem);
230 _leave(" = %d", ret);
231 return ret;
232 }
233
234 /* pass on how big the object we're caching is supposed to be */
235 cookie->def->get_attr(cookie->netfs_data, &i_size);
236
237 spin_lock(&cookie->lock);
238 if (hlist_empty(&cookie->backing_objects)) {
239 spin_unlock(&cookie->lock);
240 goto unavailable;
241 }
242
243 object = hlist_entry(cookie->backing_objects.first,
244 struct fscache_object, cookie_link);
245
246 fscache_set_store_limit(object, i_size);
247
248 /* initiate the process of looking up all the objects in the chain
249 * (done by fscache_initialise_object()) */
250 fscache_raise_event(object, FSCACHE_OBJECT_EV_NEW_CHILD);
251
252 spin_unlock(&cookie->lock);
253
254 /* we may be required to wait for lookup to complete at this point */
255 if (!fscache_defer_lookup) {
256 _debug("non-deferred lookup %p", &cookie->flags);
257 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
258 TASK_UNINTERRUPTIBLE);
259 _debug("complete");
260 if (test_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags))
261 goto unavailable;
262 }
263
264 up_read(&fscache_addremove_sem);
265 _leave(" = 0 [deferred]");
266 return 0;
267
268 unavailable:
269 up_read(&fscache_addremove_sem);
270 _leave(" = -ENOBUFS");
271 return -ENOBUFS;
272 }
273
274 /*
275 * recursively allocate cache object records for a cookie/cache combination
276 * - caller must be holding the addremove sem
277 */
278 static int fscache_alloc_object(struct fscache_cache *cache,
279 struct fscache_cookie *cookie)
280 {
281 struct fscache_object *object;
282 int ret;
283
284 _enter("%p,%p{%s}", cache, cookie, cookie->def->name);
285
286 spin_lock(&cookie->lock);
287 hlist_for_each_entry(object, &cookie->backing_objects,
288 cookie_link) {
289 if (object->cache == cache)
290 goto object_already_extant;
291 }
292 spin_unlock(&cookie->lock);
293
294 /* ask the cache to allocate an object (we may end up with duplicate
295 * objects at this stage, but we sort that out later) */
296 fscache_stat(&fscache_n_cop_alloc_object);
297 object = cache->ops->alloc_object(cache, cookie);
298 fscache_stat_d(&fscache_n_cop_alloc_object);
299 if (IS_ERR(object)) {
300 fscache_stat(&fscache_n_object_no_alloc);
301 ret = PTR_ERR(object);
302 goto error;
303 }
304
305 ASSERTCMP(object->cookie, ==, cookie);
306 fscache_stat(&fscache_n_object_alloc);
307
308 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
309
310 _debug("ALLOC OBJ%x: %s {%lx}",
311 object->debug_id, cookie->def->name, object->events);
312
313 ret = fscache_alloc_object(cache, cookie->parent);
314 if (ret < 0)
315 goto error_put;
316
317 /* only attach if we managed to allocate all we needed, otherwise
318 * discard the object we just allocated and instead use the one
319 * attached to the cookie */
320 if (fscache_attach_object(cookie, object) < 0) {
321 fscache_stat(&fscache_n_cop_put_object);
322 cache->ops->put_object(object);
323 fscache_stat_d(&fscache_n_cop_put_object);
324 }
325
326 _leave(" = 0");
327 return 0;
328
329 object_already_extant:
330 ret = -ENOBUFS;
331 if (fscache_object_is_dying(object) ||
332 fscache_cache_is_broken(object)) {
333 spin_unlock(&cookie->lock);
334 goto error;
335 }
336 spin_unlock(&cookie->lock);
337 _leave(" = 0 [found]");
338 return 0;
339
340 error_put:
341 fscache_stat(&fscache_n_cop_put_object);
342 cache->ops->put_object(object);
343 fscache_stat_d(&fscache_n_cop_put_object);
344 error:
345 _leave(" = %d", ret);
346 return ret;
347 }
348
349 /*
350 * attach a cache object to a cookie
351 */
352 static int fscache_attach_object(struct fscache_cookie *cookie,
353 struct fscache_object *object)
354 {
355 struct fscache_object *p;
356 struct fscache_cache *cache = object->cache;
357 int ret;
358
359 _enter("{%s},{OBJ%x}", cookie->def->name, object->debug_id);
360
361 ASSERTCMP(object->cookie, ==, cookie);
362
363 spin_lock(&cookie->lock);
364
365 /* there may be multiple initial creations of this object, but we only
366 * want one */
367 ret = -EEXIST;
368 hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) {
369 if (p->cache == object->cache) {
370 if (fscache_object_is_dying(p))
371 ret = -ENOBUFS;
372 goto cant_attach_object;
373 }
374 }
375
376 /* pin the parent object */
377 spin_lock_nested(&cookie->parent->lock, 1);
378 hlist_for_each_entry(p, &cookie->parent->backing_objects,
379 cookie_link) {
380 if (p->cache == object->cache) {
381 if (fscache_object_is_dying(p)) {
382 ret = -ENOBUFS;
383 spin_unlock(&cookie->parent->lock);
384 goto cant_attach_object;
385 }
386 object->parent = p;
387 spin_lock(&p->lock);
388 p->n_children++;
389 spin_unlock(&p->lock);
390 break;
391 }
392 }
393 spin_unlock(&cookie->parent->lock);
394
395 /* attach to the cache's object list */
396 if (list_empty(&object->cache_link)) {
397 spin_lock(&cache->object_list_lock);
398 list_add(&object->cache_link, &cache->object_list);
399 spin_unlock(&cache->object_list_lock);
400 }
401
402 /* Attach to the cookie. The object already has a ref on it. */
403 hlist_add_head(&object->cookie_link, &cookie->backing_objects);
404
405 fscache_objlist_add(object);
406 ret = 0;
407
408 cant_attach_object:
409 spin_unlock(&cookie->lock);
410 _leave(" = %d", ret);
411 return ret;
412 }
413
414 /*
415 * Invalidate an object. Callable with spinlocks held.
416 */
417 void __fscache_invalidate(struct fscache_cookie *cookie)
418 {
419 struct fscache_object *object;
420
421 _enter("{%s}", cookie->def->name);
422
423 fscache_stat(&fscache_n_invalidates);
424
425 /* Only permit invalidation of data files. Invalidating an index will
426 * require the caller to release all its attachments to the tree rooted
427 * there, and if it's doing that, it may as well just retire the
428 * cookie.
429 */
430 ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE);
431
432 /* We will be updating the cookie too. */
433 BUG_ON(!cookie->def->get_aux);
434
435 /* If there's an object, we tell the object state machine to handle the
436 * invalidation on our behalf, otherwise there's nothing to do.
437 */
438 if (!hlist_empty(&cookie->backing_objects)) {
439 spin_lock(&cookie->lock);
440
441 if (fscache_cookie_enabled(cookie) &&
442 !hlist_empty(&cookie->backing_objects) &&
443 !test_and_set_bit(FSCACHE_COOKIE_INVALIDATING,
444 &cookie->flags)) {
445 object = hlist_entry(cookie->backing_objects.first,
446 struct fscache_object,
447 cookie_link);
448 if (fscache_object_is_live(object))
449 fscache_raise_event(
450 object, FSCACHE_OBJECT_EV_INVALIDATE);
451 }
452
453 spin_unlock(&cookie->lock);
454 }
455
456 _leave("");
457 }
458 EXPORT_SYMBOL(__fscache_invalidate);
459
460 /*
461 * Wait for object invalidation to complete.
462 */
463 void __fscache_wait_on_invalidate(struct fscache_cookie *cookie)
464 {
465 _enter("%p", cookie);
466
467 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING,
468 TASK_UNINTERRUPTIBLE);
469
470 _leave("");
471 }
472 EXPORT_SYMBOL(__fscache_wait_on_invalidate);
473
474 /*
475 * update the index entries backing a cookie
476 */
477 void __fscache_update_cookie(struct fscache_cookie *cookie)
478 {
479 struct fscache_object *object;
480
481 fscache_stat(&fscache_n_updates);
482
483 if (!cookie) {
484 fscache_stat(&fscache_n_updates_null);
485 _leave(" [no cookie]");
486 return;
487 }
488
489 _enter("{%s}", cookie->def->name);
490
491 BUG_ON(!cookie->def->get_aux);
492
493 spin_lock(&cookie->lock);
494
495 if (fscache_cookie_enabled(cookie)) {
496 /* update the index entry on disk in each cache backing this
497 * cookie.
498 */
499 hlist_for_each_entry(object,
500 &cookie->backing_objects, cookie_link) {
501 fscache_raise_event(object, FSCACHE_OBJECT_EV_UPDATE);
502 }
503 }
504
505 spin_unlock(&cookie->lock);
506 _leave("");
507 }
508 EXPORT_SYMBOL(__fscache_update_cookie);
509
510 /*
511 * Disable a cookie to stop it from accepting new requests from the netfs.
512 */
513 void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate)
514 {
515 struct fscache_object *object;
516 bool awaken = false;
517
518 _enter("%p,%u", cookie, invalidate);
519
520 ASSERTCMP(atomic_read(&cookie->n_active), >, 0);
521
522 if (atomic_read(&cookie->n_children) != 0) {
523 pr_err("Cookie '%s' still has children\n",
524 cookie->def->name);
525 BUG();
526 }
527
528 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
529 TASK_UNINTERRUPTIBLE);
530 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags))
531 goto out_unlock_enable;
532
533 /* If the cookie is being invalidated, wait for that to complete first
534 * so that we can reuse the flag.
535 */
536 __fscache_wait_on_invalidate(cookie);
537
538 /* Dispose of the backing objects */
539 set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags);
540
541 spin_lock(&cookie->lock);
542 if (!hlist_empty(&cookie->backing_objects)) {
543 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) {
544 if (invalidate)
545 set_bit(FSCACHE_OBJECT_RETIRED, &object->flags);
546 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags);
547 fscache_raise_event(object, FSCACHE_OBJECT_EV_KILL);
548 }
549 } else {
550 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags))
551 awaken = true;
552 }
553 spin_unlock(&cookie->lock);
554 if (awaken)
555 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING);
556
557 /* Wait for cessation of activity requiring access to the netfs (when
558 * n_active reaches 0). This makes sure outstanding reads and writes
559 * have completed.
560 */
561 if (!atomic_dec_and_test(&cookie->n_active))
562 wait_on_atomic_t(&cookie->n_active, atomic_t_wait,
563 TASK_UNINTERRUPTIBLE);
564
565 /* Make sure any pending writes are cancelled. */
566 if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX)
567 fscache_invalidate_writes(cookie);
568
569 /* Reset the cookie state if it wasn't relinquished */
570 if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) {
571 atomic_inc(&cookie->n_active);
572 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
573 }
574
575 out_unlock_enable:
576 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
577 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
578 _leave("");
579 }
580 EXPORT_SYMBOL(__fscache_disable_cookie);
581
582 /*
583 * release a cookie back to the cache
584 * - the object will be marked as recyclable on disk if retire is true
585 * - all dependents of this cookie must have already been unregistered
586 * (indices/files/pages)
587 */
588 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
589 {
590 fscache_stat(&fscache_n_relinquishes);
591 if (retire)
592 fscache_stat(&fscache_n_relinquishes_retire);
593
594 if (!cookie) {
595 fscache_stat(&fscache_n_relinquishes_null);
596 _leave(" [no cookie]");
597 return;
598 }
599
600 _enter("%p{%s,%p,%d},%d",
601 cookie, cookie->def->name, cookie->netfs_data,
602 atomic_read(&cookie->n_active), retire);
603
604 /* No further netfs-accessing operations on this cookie permitted */
605 set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags);
606
607 __fscache_disable_cookie(cookie, retire);
608
609 /* Clear pointers back to the netfs */
610 cookie->netfs_data = NULL;
611 cookie->def = NULL;
612 BUG_ON(cookie->stores.rnode);
613
614 if (cookie->parent) {
615 ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0);
616 ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0);
617 atomic_dec(&cookie->parent->n_children);
618 }
619
620 /* Dispose of the netfs's link to the cookie */
621 ASSERTCMP(atomic_read(&cookie->usage), >, 0);
622 fscache_cookie_put(cookie);
623
624 _leave("");
625 }
626 EXPORT_SYMBOL(__fscache_relinquish_cookie);
627
628 /*
629 * destroy a cookie
630 */
631 void __fscache_cookie_put(struct fscache_cookie *cookie)
632 {
633 struct fscache_cookie *parent;
634
635 _enter("%p", cookie);
636
637 for (;;) {
638 _debug("FREE COOKIE %p", cookie);
639 parent = cookie->parent;
640 BUG_ON(!hlist_empty(&cookie->backing_objects));
641 kmem_cache_free(fscache_cookie_jar, cookie);
642
643 if (!parent)
644 break;
645
646 cookie = parent;
647 BUG_ON(atomic_read(&cookie->usage) <= 0);
648 if (!atomic_dec_and_test(&cookie->usage))
649 break;
650 }
651
652 _leave("");
653 }
654
655 /*
656 * check the consistency between the netfs inode and the backing cache
657 *
658 * NOTE: it only serves no-index type
659 */
660 int __fscache_check_consistency(struct fscache_cookie *cookie)
661 {
662 struct fscache_operation *op;
663 struct fscache_object *object;
664 bool wake_cookie = false;
665 int ret;
666
667 _enter("%p,", cookie);
668
669 ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE);
670
671 if (fscache_wait_for_deferred_lookup(cookie) < 0)
672 return -ERESTARTSYS;
673
674 if (hlist_empty(&cookie->backing_objects))
675 return 0;
676
677 op = kzalloc(sizeof(*op), GFP_NOIO | __GFP_NOMEMALLOC | __GFP_NORETRY);
678 if (!op)
679 return -ENOMEM;
680
681 fscache_operation_init(op, NULL, NULL, NULL);
682 op->flags = FSCACHE_OP_MYTHREAD |
683 (1 << FSCACHE_OP_WAITING) |
684 (1 << FSCACHE_OP_UNUSE_COOKIE);
685
686 spin_lock(&cookie->lock);
687
688 if (!fscache_cookie_enabled(cookie) ||
689 hlist_empty(&cookie->backing_objects))
690 goto inconsistent;
691 object = hlist_entry(cookie->backing_objects.first,
692 struct fscache_object, cookie_link);
693 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
694 goto inconsistent;
695
696 op->debug_id = atomic_inc_return(&fscache_op_debug_id);
697
698 __fscache_use_cookie(cookie);
699 if (fscache_submit_op(object, op) < 0)
700 goto submit_failed;
701
702 /* the work queue now carries its own ref on the object */
703 spin_unlock(&cookie->lock);
704
705 ret = fscache_wait_for_operation_activation(object, op, NULL, NULL);
706 if (ret == 0) {
707 /* ask the cache to honour the operation */
708 ret = object->cache->ops->check_consistency(op);
709 fscache_op_complete(op, false);
710 } else if (ret == -ENOBUFS) {
711 ret = 0;
712 }
713
714 fscache_put_operation(op);
715 _leave(" = %d", ret);
716 return ret;
717
718 submit_failed:
719 wake_cookie = __fscache_unuse_cookie(cookie);
720 inconsistent:
721 spin_unlock(&cookie->lock);
722 if (wake_cookie)
723 __fscache_wake_unused_cookie(cookie);
724 kfree(op);
725 _leave(" = -ESTALE");
726 return -ESTALE;
727 }
728 EXPORT_SYMBOL(__fscache_check_consistency);