1 /* Cache page management and data I/O routines
3 * Copyright (C) 2004-2008 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.
12 #define FSCACHE_DEBUG_LEVEL PAGE
13 #include <linux/module.h>
14 #include <linux/fscache-cache.h>
15 #include <linux/buffer_head.h>
16 #include <linux/pagevec.h>
17 #include <linux/slab.h>
21 * check to see if a page is being written to the cache
23 bool __fscache_check_page_write(struct fscache_cookie *cookie, struct page *page)
28 val = radix_tree_lookup(&cookie->stores, page->index);
33 EXPORT_SYMBOL(__fscache_check_page_write);
36 * wait for a page to finish being written to the cache
38 void __fscache_wait_on_page_write(struct fscache_cookie *cookie, struct page *page)
40 wait_queue_head_t *wq = bit_waitqueue(&cookie->flags, 0);
42 wait_event(*wq, !__fscache_check_page_write(cookie, page));
44 EXPORT_SYMBOL(__fscache_wait_on_page_write);
47 * decide whether a page can be released, possibly by cancelling a store to it
48 * - we're allowed to sleep if __GFP_WAIT is flagged
50 bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
57 _enter("%p,%p,%x", cookie, page, gfp);
60 val = radix_tree_lookup(&cookie->stores, page->index);
63 fscache_stat(&fscache_n_store_vmscan_not_storing);
64 __fscache_uncache_page(cookie, page);
68 /* see if the page is actually undergoing storage - if so we can't get
69 * rid of it till the cache has finished with it */
70 if (radix_tree_tag_get(&cookie->stores, page->index,
71 FSCACHE_COOKIE_STORING_TAG)) {
76 /* the page is pending storage, so we attempt to cancel the store and
77 * discard the store request so that the page can be reclaimed */
78 spin_lock(&cookie->stores_lock);
81 if (radix_tree_tag_get(&cookie->stores, page->index,
82 FSCACHE_COOKIE_STORING_TAG)) {
83 /* the page started to undergo storage whilst we were looking,
84 * so now we can only wait or return */
85 spin_unlock(&cookie->stores_lock);
89 xpage = radix_tree_delete(&cookie->stores, page->index);
90 spin_unlock(&cookie->stores_lock);
93 fscache_stat(&fscache_n_store_vmscan_cancelled);
94 fscache_stat(&fscache_n_store_radix_deletes);
95 ASSERTCMP(xpage, ==, page);
97 fscache_stat(&fscache_n_store_vmscan_gone);
100 wake_up_bit(&cookie->flags, 0);
102 page_cache_release(xpage);
103 __fscache_uncache_page(cookie, page);
107 /* we might want to wait here, but that could deadlock the allocator as
108 * the work threads writing to the cache may all end up sleeping
109 * on memory allocation */
110 fscache_stat(&fscache_n_store_vmscan_busy);
113 EXPORT_SYMBOL(__fscache_maybe_release_page);
116 * note that a page has finished being written to the cache
118 static void fscache_end_page_write(struct fscache_object *object,
121 struct fscache_cookie *cookie;
122 struct page *xpage = NULL;
124 spin_lock(&object->lock);
125 cookie = object->cookie;
127 /* delete the page from the tree if it is now no longer
129 spin_lock(&cookie->stores_lock);
130 radix_tree_tag_clear(&cookie->stores, page->index,
131 FSCACHE_COOKIE_STORING_TAG);
132 if (!radix_tree_tag_get(&cookie->stores, page->index,
133 FSCACHE_COOKIE_PENDING_TAG)) {
134 fscache_stat(&fscache_n_store_radix_deletes);
135 xpage = radix_tree_delete(&cookie->stores, page->index);
137 spin_unlock(&cookie->stores_lock);
138 wake_up_bit(&cookie->flags, 0);
140 spin_unlock(&object->lock);
142 page_cache_release(xpage);
146 * actually apply the changed attributes to a cache object
148 static void fscache_attr_changed_op(struct fscache_operation *op)
150 struct fscache_object *object = op->object;
153 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
155 fscache_stat(&fscache_n_attr_changed_calls);
157 if (fscache_object_is_active(object)) {
158 fscache_set_op_state(op, "CallFS");
159 fscache_stat(&fscache_n_cop_attr_changed);
160 ret = object->cache->ops->attr_changed(object);
161 fscache_stat_d(&fscache_n_cop_attr_changed);
162 fscache_set_op_state(op, "Done");
164 fscache_abort_object(object);
171 * notification that the attributes on an object have changed
173 int __fscache_attr_changed(struct fscache_cookie *cookie)
175 struct fscache_operation *op;
176 struct fscache_object *object;
178 _enter("%p", cookie);
180 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
182 fscache_stat(&fscache_n_attr_changed);
184 op = kzalloc(sizeof(*op), GFP_KERNEL);
186 fscache_stat(&fscache_n_attr_changed_nomem);
187 _leave(" = -ENOMEM");
191 fscache_operation_init(op, fscache_attr_changed_op, NULL);
192 op->flags = FSCACHE_OP_ASYNC | (1 << FSCACHE_OP_EXCLUSIVE);
193 fscache_set_op_name(op, "Attr");
195 spin_lock(&cookie->lock);
197 if (hlist_empty(&cookie->backing_objects))
199 object = hlist_entry(cookie->backing_objects.first,
200 struct fscache_object, cookie_link);
202 if (fscache_submit_exclusive_op(object, op) < 0)
204 spin_unlock(&cookie->lock);
205 fscache_stat(&fscache_n_attr_changed_ok);
206 fscache_put_operation(op);
211 spin_unlock(&cookie->lock);
213 fscache_stat(&fscache_n_attr_changed_nobufs);
214 _leave(" = %d", -ENOBUFS);
217 EXPORT_SYMBOL(__fscache_attr_changed);
220 * release a retrieval op reference
222 static void fscache_release_retrieval_op(struct fscache_operation *_op)
224 struct fscache_retrieval *op =
225 container_of(_op, struct fscache_retrieval, op);
227 _enter("{OP%x}", op->op.debug_id);
229 fscache_hist(fscache_retrieval_histogram, op->start_time);
231 fscache_put_context(op->op.object->cookie, op->context);
237 * allocate a retrieval op
239 static struct fscache_retrieval *fscache_alloc_retrieval(
240 struct address_space *mapping,
241 fscache_rw_complete_t end_io_func,
244 struct fscache_retrieval *op;
246 /* allocate a retrieval operation and attempt to submit it */
247 op = kzalloc(sizeof(*op), GFP_NOIO);
249 fscache_stat(&fscache_n_retrievals_nomem);
253 fscache_operation_init(&op->op, NULL, fscache_release_retrieval_op);
254 op->op.flags = FSCACHE_OP_MYTHREAD | (1 << FSCACHE_OP_WAITING);
255 op->mapping = mapping;
256 op->end_io_func = end_io_func;
257 op->context = context;
258 op->start_time = jiffies;
259 INIT_LIST_HEAD(&op->to_do);
260 fscache_set_op_name(&op->op, "Retr");
265 * wait for a deferred lookup to complete
267 static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
273 if (!test_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags)) {
274 _leave(" = 0 [imm]");
278 fscache_stat(&fscache_n_retrievals_wait);
281 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
282 fscache_wait_bit_interruptible,
283 TASK_INTERRUPTIBLE) != 0) {
284 fscache_stat(&fscache_n_retrievals_intr);
285 _leave(" = -ERESTARTSYS");
289 ASSERT(!test_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags));
292 fscache_hist(fscache_retrieval_delay_histogram, jif);
293 _leave(" = 0 [dly]");
298 * wait for an object to become active (or dead)
300 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
301 struct fscache_retrieval *op,
302 atomic_t *stat_op_waits,
303 atomic_t *stat_object_dead)
307 if (!test_bit(FSCACHE_OP_WAITING, &op->op.flags))
311 fscache_stat(stat_op_waits);
312 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
313 fscache_wait_bit_interruptible,
314 TASK_INTERRUPTIBLE) < 0) {
315 ret = fscache_cancel_op(&op->op);
319 /* it's been removed from the pending queue by another party,
320 * so we should get to run shortly */
321 wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
322 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
327 if (unlikely(fscache_object_is_dead(object))) {
328 fscache_stat(stat_object_dead);
335 * read a page from the cache or allocate a block in which to store it
337 * -ENOMEM - out of memory, nothing done
338 * -ERESTARTSYS - interrupted
339 * -ENOBUFS - no backing object available in which to cache the block
340 * -ENODATA - no data available in the backing object for this block
341 * 0 - dispatched a read - it'll call end_io_func() when finished
343 int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
345 fscache_rw_complete_t end_io_func,
349 struct fscache_retrieval *op;
350 struct fscache_object *object;
353 _enter("%p,%p,,,", cookie, page);
355 fscache_stat(&fscache_n_retrievals);
357 if (hlist_empty(&cookie->backing_objects))
360 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
361 ASSERTCMP(page, !=, NULL);
363 if (fscache_wait_for_deferred_lookup(cookie) < 0)
366 op = fscache_alloc_retrieval(page->mapping, end_io_func, context);
368 _leave(" = -ENOMEM");
371 fscache_set_op_name(&op->op, "RetrRA1");
373 spin_lock(&cookie->lock);
375 if (hlist_empty(&cookie->backing_objects))
377 object = hlist_entry(cookie->backing_objects.first,
378 struct fscache_object, cookie_link);
380 ASSERTCMP(object->state, >, FSCACHE_OBJECT_LOOKING_UP);
382 atomic_inc(&object->n_reads);
383 set_bit(FSCACHE_OP_DEC_READ_CNT, &op->op.flags);
385 if (fscache_submit_op(object, &op->op) < 0)
387 spin_unlock(&cookie->lock);
389 fscache_stat(&fscache_n_retrieval_ops);
391 /* pin the netfs read context in case we need to do the actual netfs
392 * read because we've encountered a cache read failure */
393 fscache_get_context(object->cookie, op->context);
395 /* we wait for the operation to become active, and then process it
396 * *here*, in this thread, and not in the thread pool */
397 ret = fscache_wait_for_retrieval_activation(
399 __fscache_stat(&fscache_n_retrieval_op_waits),
400 __fscache_stat(&fscache_n_retrievals_object_dead));
404 /* ask the cache to honour the operation */
405 if (test_bit(FSCACHE_COOKIE_NO_DATA_YET, &object->cookie->flags)) {
406 fscache_stat(&fscache_n_cop_allocate_page);
407 ret = object->cache->ops->allocate_page(op, page, gfp);
408 fscache_stat_d(&fscache_n_cop_allocate_page);
412 fscache_stat(&fscache_n_cop_read_or_alloc_page);
413 ret = object->cache->ops->read_or_alloc_page(op, page, gfp);
414 fscache_stat_d(&fscache_n_cop_read_or_alloc_page);
419 fscache_stat(&fscache_n_retrievals_nomem);
420 else if (ret == -ERESTARTSYS)
421 fscache_stat(&fscache_n_retrievals_intr);
422 else if (ret == -ENODATA)
423 fscache_stat(&fscache_n_retrievals_nodata);
425 fscache_stat(&fscache_n_retrievals_nobufs);
427 fscache_stat(&fscache_n_retrievals_ok);
429 fscache_put_retrieval(op);
430 _leave(" = %d", ret);
434 spin_unlock(&cookie->lock);
437 fscache_stat(&fscache_n_retrievals_nobufs);
438 _leave(" = -ENOBUFS");
441 EXPORT_SYMBOL(__fscache_read_or_alloc_page);
444 * read a list of page from the cache or allocate a block in which to store
447 * -ENOMEM - out of memory, some pages may be being read
448 * -ERESTARTSYS - interrupted, some pages may be being read
449 * -ENOBUFS - no backing object or space available in which to cache any
450 * pages not being read
451 * -ENODATA - no data available in the backing object for some or all of
453 * 0 - dispatched a read on all pages
455 * end_io_func() will be called for each page read from the cache as it is
456 * finishes being read
458 * any pages for which a read is dispatched will be removed from pages and
461 int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
462 struct address_space *mapping,
463 struct list_head *pages,
465 fscache_rw_complete_t end_io_func,
469 struct fscache_retrieval *op;
470 struct fscache_object *object;
473 _enter("%p,,%d,,,", cookie, *nr_pages);
475 fscache_stat(&fscache_n_retrievals);
477 if (hlist_empty(&cookie->backing_objects))
480 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
481 ASSERTCMP(*nr_pages, >, 0);
482 ASSERT(!list_empty(pages));
484 if (fscache_wait_for_deferred_lookup(cookie) < 0)
487 op = fscache_alloc_retrieval(mapping, end_io_func, context);
490 fscache_set_op_name(&op->op, "RetrRAN");
492 spin_lock(&cookie->lock);
494 if (hlist_empty(&cookie->backing_objects))
496 object = hlist_entry(cookie->backing_objects.first,
497 struct fscache_object, cookie_link);
499 atomic_inc(&object->n_reads);
500 set_bit(FSCACHE_OP_DEC_READ_CNT, &op->op.flags);
502 if (fscache_submit_op(object, &op->op) < 0)
504 spin_unlock(&cookie->lock);
506 fscache_stat(&fscache_n_retrieval_ops);
508 /* pin the netfs read context in case we need to do the actual netfs
509 * read because we've encountered a cache read failure */
510 fscache_get_context(object->cookie, op->context);
512 /* we wait for the operation to become active, and then process it
513 * *here*, in this thread, and not in the thread pool */
514 ret = fscache_wait_for_retrieval_activation(
516 __fscache_stat(&fscache_n_retrieval_op_waits),
517 __fscache_stat(&fscache_n_retrievals_object_dead));
521 /* ask the cache to honour the operation */
522 if (test_bit(FSCACHE_COOKIE_NO_DATA_YET, &object->cookie->flags)) {
523 fscache_stat(&fscache_n_cop_allocate_pages);
524 ret = object->cache->ops->allocate_pages(
525 op, pages, nr_pages, gfp);
526 fscache_stat_d(&fscache_n_cop_allocate_pages);
528 fscache_stat(&fscache_n_cop_read_or_alloc_pages);
529 ret = object->cache->ops->read_or_alloc_pages(
530 op, pages, nr_pages, gfp);
531 fscache_stat_d(&fscache_n_cop_read_or_alloc_pages);
536 fscache_stat(&fscache_n_retrievals_nomem);
537 else if (ret == -ERESTARTSYS)
538 fscache_stat(&fscache_n_retrievals_intr);
539 else if (ret == -ENODATA)
540 fscache_stat(&fscache_n_retrievals_nodata);
542 fscache_stat(&fscache_n_retrievals_nobufs);
544 fscache_stat(&fscache_n_retrievals_ok);
546 fscache_put_retrieval(op);
547 _leave(" = %d", ret);
551 spin_unlock(&cookie->lock);
554 fscache_stat(&fscache_n_retrievals_nobufs);
555 _leave(" = -ENOBUFS");
558 EXPORT_SYMBOL(__fscache_read_or_alloc_pages);
561 * allocate a block in the cache on which to store a page
563 * -ENOMEM - out of memory, nothing done
564 * -ERESTARTSYS - interrupted
565 * -ENOBUFS - no backing object available in which to cache the block
566 * 0 - block allocated
568 int __fscache_alloc_page(struct fscache_cookie *cookie,
572 struct fscache_retrieval *op;
573 struct fscache_object *object;
576 _enter("%p,%p,,,", cookie, page);
578 fscache_stat(&fscache_n_allocs);
580 if (hlist_empty(&cookie->backing_objects))
583 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
584 ASSERTCMP(page, !=, NULL);
586 if (fscache_wait_for_deferred_lookup(cookie) < 0)
589 op = fscache_alloc_retrieval(page->mapping, NULL, NULL);
592 fscache_set_op_name(&op->op, "RetrAL1");
594 spin_lock(&cookie->lock);
596 if (hlist_empty(&cookie->backing_objects))
598 object = hlist_entry(cookie->backing_objects.first,
599 struct fscache_object, cookie_link);
601 if (fscache_submit_op(object, &op->op) < 0)
603 spin_unlock(&cookie->lock);
605 fscache_stat(&fscache_n_alloc_ops);
607 ret = fscache_wait_for_retrieval_activation(
609 __fscache_stat(&fscache_n_alloc_op_waits),
610 __fscache_stat(&fscache_n_allocs_object_dead));
614 /* ask the cache to honour the operation */
615 fscache_stat(&fscache_n_cop_allocate_page);
616 ret = object->cache->ops->allocate_page(op, page, gfp);
617 fscache_stat_d(&fscache_n_cop_allocate_page);
620 if (ret == -ERESTARTSYS)
621 fscache_stat(&fscache_n_allocs_intr);
623 fscache_stat(&fscache_n_allocs_nobufs);
625 fscache_stat(&fscache_n_allocs_ok);
627 fscache_put_retrieval(op);
628 _leave(" = %d", ret);
632 spin_unlock(&cookie->lock);
635 fscache_stat(&fscache_n_allocs_nobufs);
636 _leave(" = -ENOBUFS");
639 EXPORT_SYMBOL(__fscache_alloc_page);
642 * release a write op reference
644 static void fscache_release_write_op(struct fscache_operation *_op)
646 _enter("{OP%x}", _op->debug_id);
650 * perform the background storage of a page into the cache
652 static void fscache_write_op(struct fscache_operation *_op)
654 struct fscache_storage *op =
655 container_of(_op, struct fscache_storage, op);
656 struct fscache_object *object = op->op.object;
657 struct fscache_cookie *cookie;
663 _enter("{OP%x,%d}", op->op.debug_id, atomic_read(&op->op.usage));
665 fscache_set_op_state(&op->op, "GetPage");
667 spin_lock(&object->lock);
668 cookie = object->cookie;
670 if (!fscache_object_is_active(object) || !cookie) {
671 spin_unlock(&object->lock);
676 spin_lock(&cookie->stores_lock);
678 fscache_stat(&fscache_n_store_calls);
680 /* find a page to store */
682 n = radix_tree_gang_lookup_tag(&cookie->stores, results, 0, 1,
683 FSCACHE_COOKIE_PENDING_TAG);
687 _debug("gang %d [%lx]", n, page->index);
688 if (page->index > op->store_limit) {
689 fscache_stat(&fscache_n_store_pages_over_limit);
693 radix_tree_tag_set(&cookie->stores, page->index,
694 FSCACHE_COOKIE_STORING_TAG);
695 radix_tree_tag_clear(&cookie->stores, page->index,
696 FSCACHE_COOKIE_PENDING_TAG);
698 spin_unlock(&cookie->stores_lock);
699 spin_unlock(&object->lock);
701 fscache_set_op_state(&op->op, "Store");
702 fscache_stat(&fscache_n_store_pages);
703 fscache_stat(&fscache_n_cop_write_page);
704 ret = object->cache->ops->write_page(op, page);
705 fscache_stat_d(&fscache_n_cop_write_page);
706 fscache_set_op_state(&op->op, "EndWrite");
707 fscache_end_page_write(object, page);
709 fscache_set_op_state(&op->op, "Abort");
710 fscache_abort_object(object);
712 fscache_enqueue_operation(&op->op);
719 /* this writer is going away and there aren't any more things to
722 spin_unlock(&cookie->stores_lock);
723 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags);
724 spin_unlock(&object->lock);
729 * request a page be stored in the cache
731 * -ENOMEM - out of memory, nothing done
732 * -ENOBUFS - no backing object available in which to cache the page
733 * 0 - dispatched a write - it'll call end_io_func() when finished
735 * if the cookie still has a backing object at this point, that object can be
736 * in one of a few states with respect to storage processing:
738 * (1) negative lookup, object not yet created (FSCACHE_COOKIE_CREATING is
741 * (a) no writes yet (set FSCACHE_COOKIE_PENDING_FILL and queue deferred
744 * (b) writes deferred till post-creation (mark page for writing and
745 * return immediately)
747 * (2) negative lookup, object created, initial fill being made from netfs
748 * (FSCACHE_COOKIE_INITIAL_FILL is set)
750 * (a) fill point not yet reached this page (mark page for writing and
753 * (b) fill point passed this page (queue op to store this page)
755 * (3) object extant (queue op to store this page)
757 * any other state is invalid
759 int __fscache_write_page(struct fscache_cookie *cookie,
763 struct fscache_storage *op;
764 struct fscache_object *object;
767 _enter("%p,%x,", cookie, (u32) page->flags);
769 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
770 ASSERT(PageFsCache(page));
772 fscache_stat(&fscache_n_stores);
774 op = kzalloc(sizeof(*op), GFP_NOIO);
778 fscache_operation_init(&op->op, fscache_write_op,
779 fscache_release_write_op);
780 op->op.flags = FSCACHE_OP_ASYNC | (1 << FSCACHE_OP_WAITING);
781 fscache_set_op_name(&op->op, "Write1");
783 ret = radix_tree_preload(gfp & ~__GFP_HIGHMEM);
788 spin_lock(&cookie->lock);
790 if (hlist_empty(&cookie->backing_objects))
792 object = hlist_entry(cookie->backing_objects.first,
793 struct fscache_object, cookie_link);
794 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
797 /* add the page to the pending-storage radix tree on the backing
799 spin_lock(&object->lock);
800 spin_lock(&cookie->stores_lock);
802 _debug("store limit %llx", (unsigned long long) object->store_limit);
804 ret = radix_tree_insert(&cookie->stores, page->index, page);
808 _debug("insert failed %d", ret);
809 goto nobufs_unlock_obj;
812 radix_tree_tag_set(&cookie->stores, page->index,
813 FSCACHE_COOKIE_PENDING_TAG);
814 page_cache_get(page);
816 /* we only want one writer at a time, but we do need to queue new
817 * writers after exclusive ops */
818 if (test_and_set_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags))
819 goto already_pending;
821 spin_unlock(&cookie->stores_lock);
822 spin_unlock(&object->lock);
824 op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
825 op->store_limit = object->store_limit;
827 if (fscache_submit_op(object, &op->op) < 0)
830 spin_unlock(&cookie->lock);
831 radix_tree_preload_end();
832 fscache_stat(&fscache_n_store_ops);
833 fscache_stat(&fscache_n_stores_ok);
835 /* the work queue now carries its own ref on the object */
836 fscache_put_operation(&op->op);
841 fscache_stat(&fscache_n_stores_again);
843 spin_unlock(&cookie->stores_lock);
844 spin_unlock(&object->lock);
845 spin_unlock(&cookie->lock);
846 radix_tree_preload_end();
848 fscache_stat(&fscache_n_stores_ok);
853 spin_lock(&cookie->stores_lock);
854 radix_tree_delete(&cookie->stores, page->index);
855 spin_unlock(&cookie->stores_lock);
856 page_cache_release(page);
861 spin_unlock(&cookie->stores_lock);
862 spin_unlock(&object->lock);
864 spin_unlock(&cookie->lock);
865 radix_tree_preload_end();
867 fscache_stat(&fscache_n_stores_nobufs);
868 _leave(" = -ENOBUFS");
874 fscache_stat(&fscache_n_stores_oom);
875 _leave(" = -ENOMEM");
878 EXPORT_SYMBOL(__fscache_write_page);
881 * remove a page from the cache
883 void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
885 struct fscache_object *object;
889 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
890 ASSERTCMP(page, !=, NULL);
892 fscache_stat(&fscache_n_uncaches);
894 /* cache withdrawal may beat us to it */
895 if (!PageFsCache(page))
899 spin_lock(&cookie->lock);
901 if (hlist_empty(&cookie->backing_objects)) {
902 ClearPageFsCache(page);
906 object = hlist_entry(cookie->backing_objects.first,
907 struct fscache_object, cookie_link);
909 /* there might now be stuff on disk we could read */
910 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
912 /* only invoke the cache backend if we managed to mark the page
913 * uncached here; this deals with synchronisation vs withdrawal */
914 if (TestClearPageFsCache(page) &&
915 object->cache->ops->uncache_page) {
916 /* the cache backend releases the cookie lock */
917 fscache_stat(&fscache_n_cop_uncache_page);
918 object->cache->ops->uncache_page(object, page);
919 fscache_stat_d(&fscache_n_cop_uncache_page);
924 spin_unlock(&cookie->lock);
928 EXPORT_SYMBOL(__fscache_uncache_page);
931 * fscache_mark_pages_cached - Mark pages as being cached
932 * @op: The retrieval op pages are being marked for
933 * @pagevec: The pages to be marked
935 * Mark a bunch of netfs pages as being cached. After this is called,
936 * the netfs must call fscache_uncache_page() to remove the mark.
938 void fscache_mark_pages_cached(struct fscache_retrieval *op,
939 struct pagevec *pagevec)
941 struct fscache_cookie *cookie = op->op.object->cookie;
944 #ifdef CONFIG_FSCACHE_STATS
945 atomic_add(pagevec->nr, &fscache_n_marks);
948 for (loop = 0; loop < pagevec->nr; loop++) {
949 struct page *page = pagevec->pages[loop];
951 _debug("- mark %p{%lx}", page, page->index);
952 if (TestSetPageFsCache(page)) {
953 static bool once_only;
956 printk(KERN_WARNING "FS-Cache:"
957 " Cookie type %s marked page %lx"
959 cookie->def->name, page->index);
964 if (cookie->def->mark_pages_cached)
965 cookie->def->mark_pages_cached(cookie->netfs_data,
966 op->mapping, pagevec);
967 pagevec_reinit(pagevec);
969 EXPORT_SYMBOL(fscache_mark_pages_cached);