blob: ba7b71fba34bcc4cd5f8b8a305ace06a388ac607 [file] [log] [blame]
David Howells08e0e7c2007-04-26 15:55:03 -07001/* AFS filesystem file handling
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells08e0e7c2007-04-26 15:55:03 -07003 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/fs.h>
16#include <linux/pagemap.h>
David Howells31143d52007-05-09 02:33:46 -070017#include <linux/writeback.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/gfp.h>
David Howells91b467e2017-01-05 10:38:35 +000019#include <linux/task_io_accounting_ops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "internal.h"
21
David Howells416351f2007-05-09 02:33:45 -070022static int afs_readpage(struct file *file, struct page *page);
Lukas Czernerd47992f2013-05-21 23:17:23 -040023static void afs_invalidatepage(struct page *page, unsigned int offset,
24 unsigned int length);
David Howells416351f2007-05-09 02:33:45 -070025static int afs_releasepage(struct page *page, gfp_t gfp_flags);
David Howells31143d52007-05-09 02:33:46 -070026static int afs_launder_page(struct page *page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
David Howells9b3f26c2009-04-03 16:42:41 +010028static int afs_readpages(struct file *filp, struct address_space *mapping,
29 struct list_head *pages, unsigned nr_pages);
30
David Howells00d3b7a2007-04-26 15:57:07 -070031const struct file_operations afs_file_operations = {
32 .open = afs_open,
33 .release = afs_release,
34 .llseek = generic_file_llseek,
Al Viroaad4f8b2014-04-02 14:33:16 -040035 .read_iter = generic_file_read_iter,
Al Viro50b55512014-04-03 14:13:46 -040036 .write_iter = afs_file_write,
David Howells00d3b7a2007-04-26 15:57:07 -070037 .mmap = generic_file_readonly_mmap,
Jens Axboe5ffc4ef2007-06-01 11:49:19 +020038 .splice_read = generic_file_splice_read,
David Howells31143d52007-05-09 02:33:46 -070039 .fsync = afs_fsync,
David Howellse8d6c552007-07-15 23:40:12 -070040 .lock = afs_lock,
41 .flock = afs_flock,
David Howells00d3b7a2007-04-26 15:57:07 -070042};
43
Arjan van de Ven754661f2007-02-12 00:55:38 -080044const struct inode_operations afs_file_inode_operations = {
David Howells416351f2007-05-09 02:33:45 -070045 .getattr = afs_getattr,
David Howells31143d52007-05-09 02:33:46 -070046 .setattr = afs_setattr,
David Howells00d3b7a2007-04-26 15:57:07 -070047 .permission = afs_permission,
Linus Torvalds1da177e2005-04-16 15:20:36 -070048};
49
Christoph Hellwigf5e54d62006-06-28 04:26:44 -070050const struct address_space_operations afs_fs_aops = {
David Howells416351f2007-05-09 02:33:45 -070051 .readpage = afs_readpage,
David Howells9b3f26c2009-04-03 16:42:41 +010052 .readpages = afs_readpages,
David Howells31143d52007-05-09 02:33:46 -070053 .set_page_dirty = afs_set_page_dirty,
54 .launder_page = afs_launder_page,
David Howells416351f2007-05-09 02:33:45 -070055 .releasepage = afs_releasepage,
56 .invalidatepage = afs_invalidatepage,
Nick Piggin15b46502008-10-15 22:04:32 -070057 .write_begin = afs_write_begin,
58 .write_end = afs_write_end,
David Howells31143d52007-05-09 02:33:46 -070059 .writepage = afs_writepage,
60 .writepages = afs_writepages,
Linus Torvalds1da177e2005-04-16 15:20:36 -070061};
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
David Howells00d3b7a2007-04-26 15:57:07 -070064 * open an AFS file or directory and attach a key to it
65 */
66int afs_open(struct inode *inode, struct file *file)
67{
68 struct afs_vnode *vnode = AFS_FS_I(inode);
69 struct key *key;
David Howells260a9802007-04-26 15:59:35 -070070 int ret;
David Howells00d3b7a2007-04-26 15:57:07 -070071
David Howells416351f2007-05-09 02:33:45 -070072 _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
David Howells00d3b7a2007-04-26 15:57:07 -070073
74 key = afs_request_key(vnode->volume->cell);
75 if (IS_ERR(key)) {
76 _leave(" = %ld [key]", PTR_ERR(key));
77 return PTR_ERR(key);
78 }
79
David Howells260a9802007-04-26 15:59:35 -070080 ret = afs_validate(vnode, key);
81 if (ret < 0) {
82 _leave(" = %d [val]", ret);
83 return ret;
84 }
85
David Howells00d3b7a2007-04-26 15:57:07 -070086 file->private_data = key;
87 _leave(" = 0");
88 return 0;
89}
90
91/*
92 * release an AFS file or directory and discard its key
93 */
94int afs_release(struct inode *inode, struct file *file)
95{
96 struct afs_vnode *vnode = AFS_FS_I(inode);
97
David Howells416351f2007-05-09 02:33:45 -070098 _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
David Howells00d3b7a2007-04-26 15:57:07 -070099
100 key_put(file->private_data);
101 _leave(" = 0");
102 return 0;
103}
104
David Howells196ee9c2017-01-05 10:38:34 +0000105/*
106 * Dispose of a ref to a read record.
107 */
108void afs_put_read(struct afs_read *req)
109{
110 int i;
111
112 if (atomic_dec_and_test(&req->usage)) {
113 for (i = 0; i < req->nr_pages; i++)
114 if (req->pages[i])
115 put_page(req->pages[i]);
116 kfree(req);
117 }
118}
119
Matt Kraai6566abd2009-04-17 12:56:38 +0100120#ifdef CONFIG_AFS_FSCACHE
David Howells00d3b7a2007-04-26 15:57:07 -0700121/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 * deal with notification that a page was read from the cache
123 */
David Howells9b3f26c2009-04-03 16:42:41 +0100124static void afs_file_readpage_read_complete(struct page *page,
125 void *data,
126 int error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
David Howells9b3f26c2009-04-03 16:42:41 +0100128 _enter("%p,%p,%d", page, data, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
David Howells9b3f26c2009-04-03 16:42:41 +0100130 /* if the read completes with an error, we just unlock the page and let
131 * the VM reissue the readpage */
132 if (!error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 SetPageUptodate(page);
134 unlock_page(page);
David Howellsec268152007-04-26 15:49:28 -0700135}
Matt Kraai6566abd2009-04-17 12:56:38 +0100136#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/*
Al Virof6d335c2010-05-21 15:27:09 +0100139 * read page from file, directory or symlink, given a key to use
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 */
Al Virof6d335c2010-05-21 15:27:09 +0100141int afs_page_filler(void *data, struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Al Virof6d335c2010-05-21 15:27:09 +0100143 struct inode *inode = page->mapping->host;
144 struct afs_vnode *vnode = AFS_FS_I(inode);
David Howells196ee9c2017-01-05 10:38:34 +0000145 struct afs_read *req;
Al Virof6d335c2010-05-21 15:27:09 +0100146 struct key *key = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 int ret;
148
David Howells00d3b7a2007-04-26 15:57:07 -0700149 _enter("{%x},{%lu},{%lu}", key_serial(key), inode->i_ino, page->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Matt Mackallcd7619d2005-05-01 08:59:01 -0700151 BUG_ON(!PageLocked(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 ret = -ESTALE;
David Howells08e0e7c2007-04-26 15:55:03 -0700154 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 goto error;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /* is it cached? */
David Howells9b3f26c2009-04-03 16:42:41 +0100158#ifdef CONFIG_AFS_FSCACHE
159 ret = fscache_read_or_alloc_page(vnode->cache,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 page,
161 afs_file_readpage_read_complete,
162 NULL,
163 GFP_KERNEL);
164#else
165 ret = -ENOBUFS;
166#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 switch (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 /* read BIO submitted (page in cache) */
169 case 0:
170 break;
171
David Howells9b3f26c2009-04-03 16:42:41 +0100172 /* page not yet cached */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 case -ENODATA:
David Howells9b3f26c2009-04-03 16:42:41 +0100174 _debug("cache said ENODATA");
175 goto go_on;
176
177 /* page will not be cached */
178 case -ENOBUFS:
179 _debug("cache said ENOBUFS");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 default:
David Howells9b3f26c2009-04-03 16:42:41 +0100181 go_on:
David Howells196ee9c2017-01-05 10:38:34 +0000182 req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *),
183 GFP_KERNEL);
184 if (!req)
185 goto enomem;
186
187 atomic_set(&req->usage, 1);
188 req->pos = (loff_t)page->index << PAGE_SHIFT;
189 req->len = min_t(size_t, i_size_read(inode) - req->pos,
190 PAGE_SIZE);
191 req->nr_pages = 1;
192 req->pages[0] = page;
193 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 /* read the contents of the file from the server into the
196 * page */
David Howells196ee9c2017-01-05 10:38:34 +0000197 ret = afs_vnode_fetch_data(vnode, key, req);
198 afs_put_read(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (ret < 0) {
David Howells08e0e7c2007-04-26 15:55:03 -0700200 if (ret == -ENOENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 _debug("got NOENT from server"
202 " - marking file deleted and stale");
David Howells08e0e7c2007-04-26 15:55:03 -0700203 set_bit(AFS_VNODE_DELETED, &vnode->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 ret = -ESTALE;
205 }
David Howells9b3f26c2009-04-03 16:42:41 +0100206
207#ifdef CONFIG_AFS_FSCACHE
208 fscache_uncache_page(vnode->cache, page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209#endif
David Howells9b3f26c2009-04-03 16:42:41 +0100210 BUG_ON(PageFsCache(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 goto error;
212 }
213
214 SetPageUptodate(page);
215
David Howells9b3f26c2009-04-03 16:42:41 +0100216 /* send the page to the cache */
217#ifdef CONFIG_AFS_FSCACHE
218 if (PageFsCache(page) &&
219 fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
220 fscache_uncache_page(vnode->cache, page);
221 BUG_ON(PageFsCache(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#endif
David Howells9b3f26c2009-04-03 16:42:41 +0100224 unlock_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226
227 _leave(" = 0");
228 return 0;
229
David Howells196ee9c2017-01-05 10:38:34 +0000230enomem:
231 ret = -ENOMEM;
David Howells08e0e7c2007-04-26 15:55:03 -0700232error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 SetPageError(page);
234 unlock_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 _leave(" = %d", ret);
236 return ret;
David Howellsec268152007-04-26 15:49:28 -0700237}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
Al Virof6d335c2010-05-21 15:27:09 +0100240 * read page from file, directory or symlink, given a file to nominate the key
241 * to be used
242 */
243static int afs_readpage(struct file *file, struct page *page)
244{
245 struct key *key;
246 int ret;
247
248 if (file) {
249 key = file->private_data;
250 ASSERT(key != NULL);
251 ret = afs_page_filler(key, page);
252 } else {
253 struct inode *inode = page->mapping->host;
254 key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell);
255 if (IS_ERR(key)) {
256 ret = PTR_ERR(key);
257 } else {
258 ret = afs_page_filler(key, page);
259 key_put(key);
260 }
261 }
262 return ret;
263}
264
265/*
David Howells91b467e2017-01-05 10:38:35 +0000266 * Make pages available as they're filled.
267 */
268static void afs_readpages_page_done(struct afs_call *call, struct afs_read *req)
269{
Arnd Bergmann51c89e62017-01-13 14:46:19 +0000270#ifdef CONFIG_AFS_FSCACHE
David Howells91b467e2017-01-05 10:38:35 +0000271 struct afs_vnode *vnode = call->reply;
Arnd Bergmann51c89e62017-01-13 14:46:19 +0000272#endif
David Howells91b467e2017-01-05 10:38:35 +0000273 struct page *page = req->pages[req->index];
274
275 req->pages[req->index] = NULL;
276 SetPageUptodate(page);
277
278 /* send the page to the cache */
279#ifdef CONFIG_AFS_FSCACHE
280 if (PageFsCache(page) &&
281 fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
282 fscache_uncache_page(vnode->cache, page);
283 BUG_ON(PageFsCache(page));
284 }
285#endif
286 unlock_page(page);
287 put_page(page);
288}
289
290/*
291 * Read a contiguous set of pages.
292 */
293static int afs_readpages_one(struct file *file, struct address_space *mapping,
294 struct list_head *pages)
295{
296 struct afs_vnode *vnode = AFS_FS_I(mapping->host);
297 struct afs_read *req;
298 struct list_head *p;
299 struct page *first, *page;
300 struct key *key = file->private_data;
301 pgoff_t index;
302 int ret, n, i;
303
304 /* Count the number of contiguous pages at the front of the list. Note
305 * that the list goes prev-wards rather than next-wards.
306 */
307 first = list_entry(pages->prev, struct page, lru);
308 index = first->index + 1;
309 n = 1;
310 for (p = first->lru.prev; p != pages; p = p->prev) {
311 page = list_entry(p, struct page, lru);
312 if (page->index != index)
313 break;
314 index++;
315 n++;
316 }
317
318 req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *) * n,
319 GFP_NOFS);
320 if (!req)
321 return -ENOMEM;
322
323 atomic_set(&req->usage, 1);
324 req->page_done = afs_readpages_page_done;
325 req->pos = first->index;
326 req->pos <<= PAGE_SHIFT;
327
328 /* Transfer the pages to the request. We add them in until one fails
329 * to add to the LRU and then we stop (as that'll make a hole in the
330 * contiguous run.
331 *
332 * Note that it's possible for the file size to change whilst we're
333 * doing this, but we rely on the server returning less than we asked
334 * for if the file shrank. We also rely on this to deal with a partial
335 * page at the end of the file.
336 */
337 do {
338 page = list_entry(pages->prev, struct page, lru);
339 list_del(&page->lru);
340 index = page->index;
341 if (add_to_page_cache_lru(page, mapping, index,
342 readahead_gfp_mask(mapping))) {
343#ifdef CONFIG_AFS_FSCACHE
344 fscache_uncache_page(vnode->cache, page);
345#endif
346 put_page(page);
347 break;
348 }
349
350 req->pages[req->nr_pages++] = page;
351 req->len += PAGE_SIZE;
352 } while (req->nr_pages < n);
353
354 if (req->nr_pages == 0) {
355 kfree(req);
356 return 0;
357 }
358
359 ret = afs_vnode_fetch_data(vnode, key, req);
360 if (ret < 0)
361 goto error;
362
363 task_io_account_read(PAGE_SIZE * req->nr_pages);
364 afs_put_read(req);
365 return 0;
366
367error:
368 if (ret == -ENOENT) {
369 _debug("got NOENT from server"
370 " - marking file deleted and stale");
371 set_bit(AFS_VNODE_DELETED, &vnode->flags);
372 ret = -ESTALE;
373 }
374
375 for (i = 0; i < req->nr_pages; i++) {
376 page = req->pages[i];
377 if (page) {
378#ifdef CONFIG_AFS_FSCACHE
379 fscache_uncache_page(vnode->cache, page);
380#endif
381 SetPageError(page);
382 unlock_page(page);
383 }
384 }
385
386 afs_put_read(req);
387 return ret;
388}
389
390/*
David Howells9b3f26c2009-04-03 16:42:41 +0100391 * read a set of pages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 */
David Howells9b3f26c2009-04-03 16:42:41 +0100393static int afs_readpages(struct file *file, struct address_space *mapping,
394 struct list_head *pages, unsigned nr_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Al Virof6d335c2010-05-21 15:27:09 +0100396 struct key *key = file->private_data;
David Howells9b3f26c2009-04-03 16:42:41 +0100397 struct afs_vnode *vnode;
398 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Al Virof6d335c2010-05-21 15:27:09 +0100400 _enter("{%d},{%lu},,%d",
401 key_serial(key), mapping->host->i_ino, nr_pages);
402
403 ASSERT(key != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
David Howells9b3f26c2009-04-03 16:42:41 +0100405 vnode = AFS_FS_I(mapping->host);
Dan Carpenterad2a8e62012-03-20 16:58:06 +0000406 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
David Howells9b3f26c2009-04-03 16:42:41 +0100407 _leave(" = -ESTALE");
408 return -ESTALE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410
David Howells9b3f26c2009-04-03 16:42:41 +0100411 /* attempt to read as many of the pages as possible */
412#ifdef CONFIG_AFS_FSCACHE
413 ret = fscache_read_or_alloc_pages(vnode->cache,
414 mapping,
415 pages,
416 &nr_pages,
417 afs_file_readpage_read_complete,
418 NULL,
419 mapping_gfp_mask(mapping));
420#else
421 ret = -ENOBUFS;
422#endif
423
424 switch (ret) {
425 /* all pages are being read from the cache */
426 case 0:
427 BUG_ON(!list_empty(pages));
428 BUG_ON(nr_pages != 0);
429 _leave(" = 0 [reading all]");
430 return 0;
431
432 /* there were pages that couldn't be read from the cache */
433 case -ENODATA:
434 case -ENOBUFS:
435 break;
436
437 /* other error */
438 default:
439 _leave(" = %d", ret);
440 return ret;
441 }
442
David Howells91b467e2017-01-05 10:38:35 +0000443 while (!list_empty(pages)) {
444 ret = afs_readpages_one(file, mapping, pages);
445 if (ret < 0)
446 break;
447 }
David Howells9b3f26c2009-04-03 16:42:41 +0100448
449 _leave(" = %d [netting]", ret);
450 return ret;
David Howellsec268152007-04-26 15:49:28 -0700451}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/*
David Howells31143d52007-05-09 02:33:46 -0700454 * write back a dirty page
455 */
456static int afs_launder_page(struct page *page)
457{
458 _enter("{%lu}", page->index);
459
460 return 0;
461}
462
463/*
David Howells9b3f26c2009-04-03 16:42:41 +0100464 * invalidate part or all of a page
465 * - release a page and clean up its private data if offset is 0 (indicating
466 * the entire page)
467 */
Lukas Czernerd47992f2013-05-21 23:17:23 -0400468static void afs_invalidatepage(struct page *page, unsigned int offset,
469 unsigned int length)
David Howells9b3f26c2009-04-03 16:42:41 +0100470{
471 struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
472
Lukas Czernerd47992f2013-05-21 23:17:23 -0400473 _enter("{%lu},%u,%u", page->index, offset, length);
David Howells9b3f26c2009-04-03 16:42:41 +0100474
475 BUG_ON(!PageLocked(page));
476
477 /* we clean up only if the entire page is being invalidated */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300478 if (offset == 0 && length == PAGE_SIZE) {
David Howells9b3f26c2009-04-03 16:42:41 +0100479#ifdef CONFIG_AFS_FSCACHE
480 if (PageFsCache(page)) {
481 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
482 fscache_wait_on_page_write(vnode->cache, page);
483 fscache_uncache_page(vnode->cache, page);
David Howells9b3f26c2009-04-03 16:42:41 +0100484 }
485#endif
486
487 if (PagePrivate(page)) {
488 if (wb && !PageWriteback(page)) {
489 set_page_private(page, 0);
490 afs_put_writeback(wb);
491 }
492
493 if (!page_private(page))
494 ClearPagePrivate(page);
495 }
496 }
497
498 _leave("");
499}
500
501/*
502 * release a page and clean up its private state if it's not busy
503 * - return true if the page can now be released, false if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 */
David Howells416351f2007-05-09 02:33:45 -0700505static int afs_releasepage(struct page *page, gfp_t gfp_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
David Howells9b3f26c2009-04-03 16:42:41 +0100507 struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
David Howells416351f2007-05-09 02:33:45 -0700508 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
David Howells416351f2007-05-09 02:33:45 -0700510 _enter("{{%x:%u}[%lu],%lx},%x",
511 vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
512 gfp_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
David Howells9b3f26c2009-04-03 16:42:41 +0100514 /* deny if page is being written to the cache and the caller hasn't
515 * elected to wait */
516#ifdef CONFIG_AFS_FSCACHE
David Howells201a1542009-11-19 18:11:35 +0000517 if (!fscache_maybe_release_page(vnode->cache, page, gfp_flags)) {
518 _leave(" = F [cache busy]");
519 return 0;
David Howells9b3f26c2009-04-03 16:42:41 +0100520 }
521#endif
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (PagePrivate(page)) {
David Howells9b3f26c2009-04-03 16:42:41 +0100524 if (wb) {
525 set_page_private(page, 0);
526 afs_put_writeback(wb);
527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 ClearPagePrivate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
530
David Howells9b3f26c2009-04-03 16:42:41 +0100531 /* indicate that the page can be released */
532 _leave(" = T");
533 return 1;
David Howellsec268152007-04-26 15:49:28 -0700534}