blob: a38e1c30d1106a6c593ca61b3663cddc160b1334 [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
David Howells6db3ac32017-03-16 16:27:44 +0000187 /* We request a full page. If the page is a partial one at the
188 * end of the file, the server will return a short read and the
189 * unmarshalling code will clear the unfilled space.
190 */
David Howells196ee9c2017-01-05 10:38:34 +0000191 atomic_set(&req->usage, 1);
192 req->pos = (loff_t)page->index << PAGE_SHIFT;
David Howells6db3ac32017-03-16 16:27:44 +0000193 req->len = PAGE_SIZE;
David Howells196ee9c2017-01-05 10:38:34 +0000194 req->nr_pages = 1;
195 req->pages[0] = page;
196 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 /* read the contents of the file from the server into the
199 * page */
David Howells196ee9c2017-01-05 10:38:34 +0000200 ret = afs_vnode_fetch_data(vnode, key, req);
201 afs_put_read(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (ret < 0) {
David Howells08e0e7c2007-04-26 15:55:03 -0700203 if (ret == -ENOENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 _debug("got NOENT from server"
205 " - marking file deleted and stale");
David Howells08e0e7c2007-04-26 15:55:03 -0700206 set_bit(AFS_VNODE_DELETED, &vnode->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 ret = -ESTALE;
208 }
David Howells9b3f26c2009-04-03 16:42:41 +0100209
210#ifdef CONFIG_AFS_FSCACHE
211 fscache_uncache_page(vnode->cache, page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#endif
David Howells9b3f26c2009-04-03 16:42:41 +0100213 BUG_ON(PageFsCache(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 goto error;
215 }
216
217 SetPageUptodate(page);
218
David Howells9b3f26c2009-04-03 16:42:41 +0100219 /* send the page to the cache */
220#ifdef CONFIG_AFS_FSCACHE
221 if (PageFsCache(page) &&
222 fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
223 fscache_uncache_page(vnode->cache, page);
224 BUG_ON(PageFsCache(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#endif
David Howells9b3f26c2009-04-03 16:42:41 +0100227 unlock_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
230 _leave(" = 0");
231 return 0;
232
David Howells196ee9c2017-01-05 10:38:34 +0000233enomem:
234 ret = -ENOMEM;
David Howells08e0e7c2007-04-26 15:55:03 -0700235error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 SetPageError(page);
237 unlock_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 _leave(" = %d", ret);
239 return ret;
David Howellsec268152007-04-26 15:49:28 -0700240}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242/*
Al Virof6d335c2010-05-21 15:27:09 +0100243 * read page from file, directory or symlink, given a file to nominate the key
244 * to be used
245 */
246static int afs_readpage(struct file *file, struct page *page)
247{
248 struct key *key;
249 int ret;
250
251 if (file) {
252 key = file->private_data;
253 ASSERT(key != NULL);
254 ret = afs_page_filler(key, page);
255 } else {
256 struct inode *inode = page->mapping->host;
257 key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell);
258 if (IS_ERR(key)) {
259 ret = PTR_ERR(key);
260 } else {
261 ret = afs_page_filler(key, page);
262 key_put(key);
263 }
264 }
265 return ret;
266}
267
268/*
David Howells91b467e2017-01-05 10:38:35 +0000269 * Make pages available as they're filled.
270 */
271static void afs_readpages_page_done(struct afs_call *call, struct afs_read *req)
272{
Arnd Bergmann51c89e62017-01-13 14:46:19 +0000273#ifdef CONFIG_AFS_FSCACHE
David Howells91b467e2017-01-05 10:38:35 +0000274 struct afs_vnode *vnode = call->reply;
Arnd Bergmann51c89e62017-01-13 14:46:19 +0000275#endif
David Howells91b467e2017-01-05 10:38:35 +0000276 struct page *page = req->pages[req->index];
277
278 req->pages[req->index] = NULL;
279 SetPageUptodate(page);
280
281 /* send the page to the cache */
282#ifdef CONFIG_AFS_FSCACHE
283 if (PageFsCache(page) &&
284 fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
285 fscache_uncache_page(vnode->cache, page);
286 BUG_ON(PageFsCache(page));
287 }
288#endif
289 unlock_page(page);
290 put_page(page);
291}
292
293/*
294 * Read a contiguous set of pages.
295 */
296static int afs_readpages_one(struct file *file, struct address_space *mapping,
297 struct list_head *pages)
298{
299 struct afs_vnode *vnode = AFS_FS_I(mapping->host);
300 struct afs_read *req;
301 struct list_head *p;
302 struct page *first, *page;
303 struct key *key = file->private_data;
304 pgoff_t index;
305 int ret, n, i;
306
307 /* Count the number of contiguous pages at the front of the list. Note
308 * that the list goes prev-wards rather than next-wards.
309 */
310 first = list_entry(pages->prev, struct page, lru);
311 index = first->index + 1;
312 n = 1;
313 for (p = first->lru.prev; p != pages; p = p->prev) {
314 page = list_entry(p, struct page, lru);
315 if (page->index != index)
316 break;
317 index++;
318 n++;
319 }
320
321 req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *) * n,
322 GFP_NOFS);
323 if (!req)
324 return -ENOMEM;
325
326 atomic_set(&req->usage, 1);
327 req->page_done = afs_readpages_page_done;
328 req->pos = first->index;
329 req->pos <<= PAGE_SHIFT;
330
331 /* Transfer the pages to the request. We add them in until one fails
332 * to add to the LRU and then we stop (as that'll make a hole in the
333 * contiguous run.
334 *
335 * Note that it's possible for the file size to change whilst we're
336 * doing this, but we rely on the server returning less than we asked
337 * for if the file shrank. We also rely on this to deal with a partial
338 * page at the end of the file.
339 */
340 do {
341 page = list_entry(pages->prev, struct page, lru);
342 list_del(&page->lru);
343 index = page->index;
344 if (add_to_page_cache_lru(page, mapping, index,
345 readahead_gfp_mask(mapping))) {
346#ifdef CONFIG_AFS_FSCACHE
347 fscache_uncache_page(vnode->cache, page);
348#endif
349 put_page(page);
350 break;
351 }
352
353 req->pages[req->nr_pages++] = page;
354 req->len += PAGE_SIZE;
355 } while (req->nr_pages < n);
356
357 if (req->nr_pages == 0) {
358 kfree(req);
359 return 0;
360 }
361
362 ret = afs_vnode_fetch_data(vnode, key, req);
363 if (ret < 0)
364 goto error;
365
366 task_io_account_read(PAGE_SIZE * req->nr_pages);
367 afs_put_read(req);
368 return 0;
369
370error:
371 if (ret == -ENOENT) {
372 _debug("got NOENT from server"
373 " - marking file deleted and stale");
374 set_bit(AFS_VNODE_DELETED, &vnode->flags);
375 ret = -ESTALE;
376 }
377
378 for (i = 0; i < req->nr_pages; i++) {
379 page = req->pages[i];
380 if (page) {
381#ifdef CONFIG_AFS_FSCACHE
382 fscache_uncache_page(vnode->cache, page);
383#endif
384 SetPageError(page);
385 unlock_page(page);
386 }
387 }
388
389 afs_put_read(req);
390 return ret;
391}
392
393/*
David Howells9b3f26c2009-04-03 16:42:41 +0100394 * read a set of pages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 */
David Howells9b3f26c2009-04-03 16:42:41 +0100396static int afs_readpages(struct file *file, struct address_space *mapping,
397 struct list_head *pages, unsigned nr_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Al Virof6d335c2010-05-21 15:27:09 +0100399 struct key *key = file->private_data;
David Howells9b3f26c2009-04-03 16:42:41 +0100400 struct afs_vnode *vnode;
401 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Al Virof6d335c2010-05-21 15:27:09 +0100403 _enter("{%d},{%lu},,%d",
404 key_serial(key), mapping->host->i_ino, nr_pages);
405
406 ASSERT(key != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
David Howells9b3f26c2009-04-03 16:42:41 +0100408 vnode = AFS_FS_I(mapping->host);
Dan Carpenterad2a8e62012-03-20 16:58:06 +0000409 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
David Howells9b3f26c2009-04-03 16:42:41 +0100410 _leave(" = -ESTALE");
411 return -ESTALE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
413
David Howells9b3f26c2009-04-03 16:42:41 +0100414 /* attempt to read as many of the pages as possible */
415#ifdef CONFIG_AFS_FSCACHE
416 ret = fscache_read_or_alloc_pages(vnode->cache,
417 mapping,
418 pages,
419 &nr_pages,
420 afs_file_readpage_read_complete,
421 NULL,
422 mapping_gfp_mask(mapping));
423#else
424 ret = -ENOBUFS;
425#endif
426
427 switch (ret) {
428 /* all pages are being read from the cache */
429 case 0:
430 BUG_ON(!list_empty(pages));
431 BUG_ON(nr_pages != 0);
432 _leave(" = 0 [reading all]");
433 return 0;
434
435 /* there were pages that couldn't be read from the cache */
436 case -ENODATA:
437 case -ENOBUFS:
438 break;
439
440 /* other error */
441 default:
442 _leave(" = %d", ret);
443 return ret;
444 }
445
David Howells91b467e2017-01-05 10:38:35 +0000446 while (!list_empty(pages)) {
447 ret = afs_readpages_one(file, mapping, pages);
448 if (ret < 0)
449 break;
450 }
David Howells9b3f26c2009-04-03 16:42:41 +0100451
452 _leave(" = %d [netting]", ret);
453 return ret;
David Howellsec268152007-04-26 15:49:28 -0700454}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456/*
David Howells31143d52007-05-09 02:33:46 -0700457 * write back a dirty page
458 */
459static int afs_launder_page(struct page *page)
460{
461 _enter("{%lu}", page->index);
462
463 return 0;
464}
465
466/*
David Howells9b3f26c2009-04-03 16:42:41 +0100467 * invalidate part or all of a page
468 * - release a page and clean up its private data if offset is 0 (indicating
469 * the entire page)
470 */
Lukas Czernerd47992f2013-05-21 23:17:23 -0400471static void afs_invalidatepage(struct page *page, unsigned int offset,
472 unsigned int length)
David Howells9b3f26c2009-04-03 16:42:41 +0100473{
474 struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
475
Lukas Czernerd47992f2013-05-21 23:17:23 -0400476 _enter("{%lu},%u,%u", page->index, offset, length);
David Howells9b3f26c2009-04-03 16:42:41 +0100477
478 BUG_ON(!PageLocked(page));
479
480 /* we clean up only if the entire page is being invalidated */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300481 if (offset == 0 && length == PAGE_SIZE) {
David Howells9b3f26c2009-04-03 16:42:41 +0100482#ifdef CONFIG_AFS_FSCACHE
483 if (PageFsCache(page)) {
484 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
485 fscache_wait_on_page_write(vnode->cache, page);
486 fscache_uncache_page(vnode->cache, page);
David Howells9b3f26c2009-04-03 16:42:41 +0100487 }
488#endif
489
490 if (PagePrivate(page)) {
491 if (wb && !PageWriteback(page)) {
492 set_page_private(page, 0);
493 afs_put_writeback(wb);
494 }
495
496 if (!page_private(page))
497 ClearPagePrivate(page);
498 }
499 }
500
501 _leave("");
502}
503
504/*
505 * release a page and clean up its private state if it's not busy
506 * - return true if the page can now be released, false if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 */
David Howells416351f2007-05-09 02:33:45 -0700508static int afs_releasepage(struct page *page, gfp_t gfp_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
David Howells9b3f26c2009-04-03 16:42:41 +0100510 struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
David Howells416351f2007-05-09 02:33:45 -0700511 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
David Howells416351f2007-05-09 02:33:45 -0700513 _enter("{{%x:%u}[%lu],%lx},%x",
514 vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
515 gfp_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
David Howells9b3f26c2009-04-03 16:42:41 +0100517 /* deny if page is being written to the cache and the caller hasn't
518 * elected to wait */
519#ifdef CONFIG_AFS_FSCACHE
David Howells201a1542009-11-19 18:11:35 +0000520 if (!fscache_maybe_release_page(vnode->cache, page, gfp_flags)) {
521 _leave(" = F [cache busy]");
522 return 0;
David Howells9b3f26c2009-04-03 16:42:41 +0100523 }
524#endif
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (PagePrivate(page)) {
David Howells9b3f26c2009-04-03 16:42:41 +0100527 if (wb) {
528 set_page_private(page, 0);
529 afs_put_writeback(wb);
530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 ClearPagePrivate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 }
533
David Howells9b3f26c2009-04-03 16:42:41 +0100534 /* indicate that the page can be released */
535 _leave(" = T");
536 return 1;
David Howellsec268152007-04-26 15:49:28 -0700537}