aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fscache
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2013-09-20 19:09:31 -0400
committerDavid Howells <dhowells@redhat.com>2013-09-27 13:40:25 -0400
commit94d30ae90a00cafe686c1057be57f4885f963abf (patch)
tree2a4f927bcaf87e988f4f180d0a011856064186b5 /fs/fscache
parent8fb883f3e30065529e4f35d4b4f355193dcdb7a2 (diff)
FS-Cache: Provide the ability to enable/disable cookies
Provide the ability to enable and disable fscache cookies. A disabled cookie will reject or ignore further requests to: Acquire a child cookie Invalidate and update backing objects Check the consistency of a backing object Allocate storage for backing page Read backing pages Write to backing pages but still allows: Checks/waits on the completion of already in-progress objects Uncaching of pages Relinquishment of cookies Two new operations are provided: (1) Disable a cookie: void fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate); If the cookie is not already disabled, this locks the cookie against other dis/enablement ops, marks the cookie as being disabled, discards or invalidates any backing objects and waits for cessation of activity on any associated object. This is a wrapper around a chunk split out of fscache_relinquish_cookie(), but it reinitialises the cookie such that it can be reenabled. All possible failures are handled internally. The caller should consider calling fscache_uncache_all_inode_pages() afterwards to make sure all page markings are cleared up. (2) Enable a cookie: void fscache_enable_cookie(struct fscache_cookie *cookie, bool (*can_enable)(void *data), void *data) If the cookie is not already enabled, this locks the cookie against other dis/enablement ops, invokes can_enable() and, if the cookie is not an index cookie, will begin the procedure of acquiring backing objects. The optional can_enable() function is passed the data argument and returns a ruling as to whether or not enablement should actually be permitted to begin. All possible failures are handled internally. The cookie will only be marked as enabled if provisional backing objects are allocated. A later patch will introduce these to NFS. Cookie enablement during nfs_open() is then contingent on i_writecount <= 0. can_enable() checks for a race between open(O_RDONLY) and open(O_WRONLY/O_RDWR). This simplifies NFS's cookie handling and allows us to get rid of open(O_RDONLY) accidentally introducing caching to an inode that's open for writing already. One operation has its API modified: (3) Acquire a cookie. struct fscache_cookie *fscache_acquire_cookie( struct fscache_cookie *parent, const struct fscache_cookie_def *def, void *netfs_data, bool enable); This now has an additional argument that indicates whether the requested cookie should be enabled by default. It doesn't need the can_enable() function because the caller must prevent multiple calls for the same netfs object and it doesn't need to take the enablement lock because no one else can get at the cookie before this returns. Signed-off-by: David Howells <dhowells@redhat.com
Diffstat (limited to 'fs/fscache')
-rw-r--r--fs/fscache/cookie.c186
-rw-r--r--fs/fscache/fsdef.c1
-rw-r--r--fs/fscache/netfs.c1
-rw-r--r--fs/fscache/object.c7
-rw-r--r--fs/fscache/page.c17
5 files changed, 155 insertions, 57 deletions
diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
index d851aa555d28..29d7feb62cf7 100644
--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -58,15 +58,16 @@ void fscache_cookie_init_once(void *_cookie)
58struct fscache_cookie *__fscache_acquire_cookie( 58struct fscache_cookie *__fscache_acquire_cookie(
59 struct fscache_cookie *parent, 59 struct fscache_cookie *parent,
60 const struct fscache_cookie_def *def, 60 const struct fscache_cookie_def *def,
61 void *netfs_data) 61 void *netfs_data,
62 bool enable)
62{ 63{
63 struct fscache_cookie *cookie; 64 struct fscache_cookie *cookie;
64 65
65 BUG_ON(!def); 66 BUG_ON(!def);
66 67
67 _enter("{%s},{%s},%p", 68 _enter("{%s},{%s},%p,%u",
68 parent ? (char *) parent->def->name : "<no-parent>", 69 parent ? (char *) parent->def->name : "<no-parent>",
69 def->name, netfs_data); 70 def->name, netfs_data, enable);
70 71
71 fscache_stat(&fscache_n_acquires); 72 fscache_stat(&fscache_n_acquires);
72 73
@@ -106,7 +107,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
106 cookie->def = def; 107 cookie->def = def;
107 cookie->parent = parent; 108 cookie->parent = parent;
108 cookie->netfs_data = netfs_data; 109 cookie->netfs_data = netfs_data;
109 cookie->flags = 0; 110 cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET);
110 111
111 /* radix tree insertion won't use the preallocation pool unless it's 112 /* radix tree insertion won't use the preallocation pool unless it's
112 * told it may not wait */ 113 * told it may not wait */
@@ -124,16 +125,22 @@ struct fscache_cookie *__fscache_acquire_cookie(
124 break; 125 break;
125 } 126 }
126 127
127 /* if the object is an index then we need do nothing more here - we 128 if (enable) {
128 * create indices on disk when we need them as an index may exist in 129 /* if the object is an index then we need do nothing more here
129 * multiple caches */ 130 * - we create indices on disk when we need them as an index
130 if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { 131 * may exist in multiple caches */
131 if (fscache_acquire_non_index_cookie(cookie) < 0) { 132 if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) {
132 atomic_dec(&parent->n_children); 133 if (fscache_acquire_non_index_cookie(cookie) == 0) {
133 __fscache_cookie_put(cookie); 134 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
134 fscache_stat(&fscache_n_acquires_nobufs); 135 } else {
135 _leave(" = NULL"); 136 atomic_dec(&parent->n_children);
136 return NULL; 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);
137 } 144 }
138 } 145 }
139 146
@@ -144,6 +151,39 @@ struct fscache_cookie *__fscache_acquire_cookie(
144EXPORT_SYMBOL(__fscache_acquire_cookie); 151EXPORT_SYMBOL(__fscache_acquire_cookie);
145 152
146/* 153/*
154 * Enable a cookie to permit it to accept new operations.
155 */
156void __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 fscache_wait_bit, 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
180out_unlock:
181 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
182 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
183}
184EXPORT_SYMBOL(__fscache_enable_cookie);
185
186/*
147 * acquire a non-index cookie 187 * acquire a non-index cookie
148 * - this must make sure the index chain is instantiated and instantiate the 188 * - this must make sure the index chain is instantiated and instantiate the
149 * object representation too 189 * object representation too
@@ -157,7 +197,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
157 197
158 _enter(""); 198 _enter("");
159 199
160 cookie->flags = 1 << FSCACHE_COOKIE_UNAVAILABLE; 200 set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags);
161 201
162 /* now we need to see whether the backing objects for this cookie yet 202 /* now we need to see whether the backing objects for this cookie yet
163 * exist, if not there'll be nothing to search */ 203 * exist, if not there'll be nothing to search */
@@ -180,9 +220,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
180 220
181 _debug("cache %s", cache->tag->name); 221 _debug("cache %s", cache->tag->name);
182 222
183 cookie->flags = 223 set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
184 (1 << FSCACHE_COOKIE_LOOKING_UP) |
185 (1 << FSCACHE_COOKIE_NO_DATA_YET);
186 224
187 /* ask the cache to allocate objects for this cookie and its parent 225 /* ask the cache to allocate objects for this cookie and its parent
188 * chain */ 226 * chain */
@@ -398,7 +436,8 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
398 if (!hlist_empty(&cookie->backing_objects)) { 436 if (!hlist_empty(&cookie->backing_objects)) {
399 spin_lock(&cookie->lock); 437 spin_lock(&cookie->lock);
400 438
401 if (!hlist_empty(&cookie->backing_objects) && 439 if (fscache_cookie_enabled(cookie) &&
440 !hlist_empty(&cookie->backing_objects) &&
402 !test_and_set_bit(FSCACHE_COOKIE_INVALIDATING, 441 !test_and_set_bit(FSCACHE_COOKIE_INVALIDATING,
403 &cookie->flags)) { 442 &cookie->flags)) {
404 object = hlist_entry(cookie->backing_objects.first, 443 object = hlist_entry(cookie->backing_objects.first,
@@ -452,10 +491,14 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
452 491
453 spin_lock(&cookie->lock); 492 spin_lock(&cookie->lock);
454 493
455 /* update the index entry on disk in each cache backing this cookie */ 494 if (fscache_cookie_enabled(cookie)) {
456 hlist_for_each_entry(object, 495 /* update the index entry on disk in each cache backing this
457 &cookie->backing_objects, cookie_link) { 496 * cookie.
458 fscache_raise_event(object, FSCACHE_OBJECT_EV_UPDATE); 497 */
498 hlist_for_each_entry(object,
499 &cookie->backing_objects, cookie_link) {
500 fscache_raise_event(object, FSCACHE_OBJECT_EV_UPDATE);
501 }
459 } 502 }
460 503
461 spin_unlock(&cookie->lock); 504 spin_unlock(&cookie->lock);
@@ -464,28 +507,14 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
464EXPORT_SYMBOL(__fscache_update_cookie); 507EXPORT_SYMBOL(__fscache_update_cookie);
465 508
466/* 509/*
467 * release a cookie back to the cache 510 * Disable a cookie to stop it from accepting new requests from the netfs.
468 * - the object will be marked as recyclable on disk if retire is true
469 * - all dependents of this cookie must have already been unregistered
470 * (indices/files/pages)
471 */ 511 */
472void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire) 512void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate)
473{ 513{
474 struct fscache_object *object; 514 struct fscache_object *object;
515 bool awaken = false;
475 516
476 fscache_stat(&fscache_n_relinquishes); 517 _enter("%p,%u", cookie, invalidate);
477 if (retire)
478 fscache_stat(&fscache_n_relinquishes_retire);
479
480 if (!cookie) {
481 fscache_stat(&fscache_n_relinquishes_null);
482 _leave(" [no cookie]");
483 return;
484 }
485
486 _enter("%p{%s,%p,%d},%d",
487 cookie, cookie->def->name, cookie->netfs_data,
488 atomic_read(&cookie->n_active), retire);
489 518
490 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); 519 ASSERTCMP(atomic_read(&cookie->n_active), >, 0);
491 520
@@ -495,24 +524,82 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
495 BUG(); 524 BUG();
496 } 525 }
497 526
498 /* No further netfs-accessing operations on this cookie permitted */ 527 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
499 set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags); 528 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
500 if (retire) 529 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags))
501 set_bit(FSCACHE_COOKIE_RETIRED, &cookie->flags); 530 goto out_unlock_enable;
531
532 /* If the cookie is being invalidated, wait for that to complete first
533 * so that we can reuse the flag.
534 */
535 __fscache_wait_on_invalidate(cookie);
536
537 /* Dispose of the backing objects */
538 set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags);
502 539
503 spin_lock(&cookie->lock); 540 spin_lock(&cookie->lock);
504 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { 541 if (!hlist_empty(&cookie->backing_objects)) {
505 fscache_raise_event(object, FSCACHE_OBJECT_EV_KILL); 542 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) {
543 if (invalidate)
544 set_bit(FSCACHE_OBJECT_RETIRED, &object->flags);
545 fscache_raise_event(object, FSCACHE_OBJECT_EV_KILL);
546 }
547 } else {
548 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags))
549 awaken = true;
506 } 550 }
507 spin_unlock(&cookie->lock); 551 spin_unlock(&cookie->lock);
552 if (awaken)
553 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING);
508 554
509 /* Wait for cessation of activity requiring access to the netfs (when 555 /* Wait for cessation of activity requiring access to the netfs (when
510 * n_active reaches 0). 556 * n_active reaches 0). This makes sure outstanding reads and writes
557 * have completed.
511 */ 558 */
512 if (!atomic_dec_and_test(&cookie->n_active)) 559 if (!atomic_dec_and_test(&cookie->n_active))
513 wait_on_atomic_t(&cookie->n_active, fscache_wait_atomic_t, 560 wait_on_atomic_t(&cookie->n_active, fscache_wait_atomic_t,
514 TASK_UNINTERRUPTIBLE); 561 TASK_UNINTERRUPTIBLE);
515 562
563 /* Reset the cookie state if it wasn't relinquished */
564 if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) {
565 atomic_inc(&cookie->n_active);
566 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
567 }
568
569out_unlock_enable:
570 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
571 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
572 _leave("");
573}
574EXPORT_SYMBOL(__fscache_disable_cookie);
575
576/*
577 * release a cookie back to the cache
578 * - the object will be marked as recyclable on disk if retire is true
579 * - all dependents of this cookie must have already been unregistered
580 * (indices/files/pages)
581 */
582void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
583{
584 fscache_stat(&fscache_n_relinquishes);
585 if (retire)
586 fscache_stat(&fscache_n_relinquishes_retire);
587
588 if (!cookie) {
589 fscache_stat(&fscache_n_relinquishes_null);
590 _leave(" [no cookie]");
591 return;
592 }
593
594 _enter("%p{%s,%p,%d},%d",
595 cookie, cookie->def->name, cookie->netfs_data,
596 atomic_read(&cookie->n_active), retire);
597
598 /* No further netfs-accessing operations on this cookie permitted */
599 set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags);
600
601 __fscache_disable_cookie(cookie, retire);
602
516 /* Clear pointers back to the netfs */ 603 /* Clear pointers back to the netfs */
517 cookie->netfs_data = NULL; 604 cookie->netfs_data = NULL;
518 cookie->def = NULL; 605 cookie->def = NULL;
@@ -592,7 +679,8 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
592 679
593 spin_lock(&cookie->lock); 680 spin_lock(&cookie->lock);
594 681
595 if (hlist_empty(&cookie->backing_objects)) 682 if (!fscache_cookie_enabled(cookie) ||
683 hlist_empty(&cookie->backing_objects))
596 goto inconsistent; 684 goto inconsistent;
597 object = hlist_entry(cookie->backing_objects.first, 685 object = hlist_entry(cookie->backing_objects.first,
598 struct fscache_object, cookie_link); 686 struct fscache_object, cookie_link);
diff --git a/fs/fscache/fsdef.c b/fs/fscache/fsdef.c
index 10a2ade0bdf8..5a117df2a9ef 100644
--- a/fs/fscache/fsdef.c
+++ b/fs/fscache/fsdef.c
@@ -59,6 +59,7 @@ struct fscache_cookie fscache_fsdef_index = {
59 .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock), 59 .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
60 .backing_objects = HLIST_HEAD_INIT, 60 .backing_objects = HLIST_HEAD_INIT,
61 .def = &fscache_fsdef_index_def, 61 .def = &fscache_fsdef_index_def,
62 .flags = 1 << FSCACHE_COOKIE_ENABLED,
62}; 63};
63EXPORT_SYMBOL(fscache_fsdef_index); 64EXPORT_SYMBOL(fscache_fsdef_index);
64 65
diff --git a/fs/fscache/netfs.c b/fs/fscache/netfs.c
index b1bb6117473a..989f39401547 100644
--- a/fs/fscache/netfs.c
+++ b/fs/fscache/netfs.c
@@ -45,6 +45,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
45 netfs->primary_index->def = &fscache_fsdef_netfs_def; 45 netfs->primary_index->def = &fscache_fsdef_netfs_def;
46 netfs->primary_index->parent = &fscache_fsdef_index; 46 netfs->primary_index->parent = &fscache_fsdef_index;
47 netfs->primary_index->netfs_data = netfs; 47 netfs->primary_index->netfs_data = netfs;
48 netfs->primary_index->flags = 1 << FSCACHE_COOKIE_ENABLED;
48 49
49 atomic_inc(&netfs->primary_index->parent->usage); 50 atomic_inc(&netfs->primary_index->parent->usage);
50 atomic_inc(&netfs->primary_index->parent->n_children); 51 atomic_inc(&netfs->primary_index->parent->n_children);
diff --git a/fs/fscache/object.c b/fs/fscache/object.c
index 86d75a60b20c..dcb821617774 100644
--- a/fs/fscache/object.c
+++ b/fs/fscache/object.c
@@ -495,6 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
495 * returning ENODATA. 495 * returning ENODATA.
496 */ 496 */
497 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); 497 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
498 clear_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags);
498 499
499 _debug("wake up lookup %p", &cookie->flags); 500 _debug("wake up lookup %p", &cookie->flags);
500 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); 501 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
@@ -527,6 +528,7 @@ void fscache_obtained_object(struct fscache_object *object)
527 528
528 /* We do (presumably) have data */ 529 /* We do (presumably) have data */
529 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); 530 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
531 clear_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags);
530 532
531 /* Allow write requests to begin stacking up and read requests 533 /* Allow write requests to begin stacking up and read requests
532 * to begin shovelling data. 534 * to begin shovelling data.
@@ -679,7 +681,8 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
679 */ 681 */
680 spin_lock(&cookie->lock); 682 spin_lock(&cookie->lock);
681 hlist_del_init(&object->cookie_link); 683 hlist_del_init(&object->cookie_link);
682 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) 684 if (hlist_empty(&cookie->backing_objects) &&
685 test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags))
683 awaken = true; 686 awaken = true;
684 spin_unlock(&cookie->lock); 687 spin_unlock(&cookie->lock);
685 688
@@ -927,7 +930,7 @@ static const struct fscache_state *_fscache_invalidate_object(struct fscache_obj
927 */ 930 */
928 if (!fscache_use_cookie(object)) { 931 if (!fscache_use_cookie(object)) {
929 ASSERT(object->cookie->stores.rnode == NULL); 932 ASSERT(object->cookie->stores.rnode == NULL);
930 set_bit(FSCACHE_COOKIE_RETIRED, &cookie->flags); 933 set_bit(FSCACHE_OBJECT_RETIRED, &object->flags);
931 _leave(" [no cookie]"); 934 _leave(" [no cookie]");
932 return transit_to(KILL_OBJECT); 935 return transit_to(KILL_OBJECT);
933 } 936 }
diff --git a/fs/fscache/page.c b/fs/fscache/page.c
index 0fe42a6d0e9c..7f5c658af755 100644
--- a/fs/fscache/page.c
+++ b/fs/fscache/page.c
@@ -204,7 +204,8 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
204 204
205 spin_lock(&cookie->lock); 205 spin_lock(&cookie->lock);
206 206
207 if (hlist_empty(&cookie->backing_objects)) 207 if (!fscache_cookie_enabled(cookie) ||
208 hlist_empty(&cookie->backing_objects))
208 goto nobufs; 209 goto nobufs;
209 object = hlist_entry(cookie->backing_objects.first, 210 object = hlist_entry(cookie->backing_objects.first,
210 struct fscache_object, cookie_link); 211 struct fscache_object, cookie_link);
@@ -410,7 +411,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
410 return -ERESTARTSYS; 411 return -ERESTARTSYS;
411 412
412 op = fscache_alloc_retrieval(cookie, page->mapping, 413 op = fscache_alloc_retrieval(cookie, page->mapping,
413 end_io_func,context); 414 end_io_func, context);
414 if (!op) { 415 if (!op) {
415 _leave(" = -ENOMEM"); 416 _leave(" = -ENOMEM");
416 return -ENOMEM; 417 return -ENOMEM;
@@ -419,7 +420,8 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
419 420
420 spin_lock(&cookie->lock); 421 spin_lock(&cookie->lock);
421 422
422 if (hlist_empty(&cookie->backing_objects)) 423 if (!fscache_cookie_enabled(cookie) ||
424 hlist_empty(&cookie->backing_objects))
423 goto nobufs_unlock; 425 goto nobufs_unlock;
424 object = hlist_entry(cookie->backing_objects.first, 426 object = hlist_entry(cookie->backing_objects.first,
425 struct fscache_object, cookie_link); 427 struct fscache_object, cookie_link);
@@ -551,7 +553,8 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
551 553
552 spin_lock(&cookie->lock); 554 spin_lock(&cookie->lock);
553 555
554 if (hlist_empty(&cookie->backing_objects)) 556 if (!fscache_cookie_enabled(cookie) ||
557 hlist_empty(&cookie->backing_objects))
555 goto nobufs_unlock; 558 goto nobufs_unlock;
556 object = hlist_entry(cookie->backing_objects.first, 559 object = hlist_entry(cookie->backing_objects.first,
557 struct fscache_object, cookie_link); 560 struct fscache_object, cookie_link);
@@ -666,7 +669,8 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
666 669
667 spin_lock(&cookie->lock); 670 spin_lock(&cookie->lock);
668 671
669 if (hlist_empty(&cookie->backing_objects)) 672 if (!fscache_cookie_enabled(cookie) ||
673 hlist_empty(&cookie->backing_objects))
670 goto nobufs_unlock; 674 goto nobufs_unlock;
671 object = hlist_entry(cookie->backing_objects.first, 675 object = hlist_entry(cookie->backing_objects.first,
672 struct fscache_object, cookie_link); 676 struct fscache_object, cookie_link);
@@ -938,7 +942,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
938 ret = -ENOBUFS; 942 ret = -ENOBUFS;
939 spin_lock(&cookie->lock); 943 spin_lock(&cookie->lock);
940 944
941 if (hlist_empty(&cookie->backing_objects)) 945 if (!fscache_cookie_enabled(cookie) ||
946 hlist_empty(&cookie->backing_objects))
942 goto nobufs; 947 goto nobufs;
943 object = hlist_entry(cookie->backing_objects.first, 948 object = hlist_entry(cookie->backing_objects.first,
944 struct fscache_object, cookie_link); 949 struct fscache_object, cookie_link);