blob: 510cba15fa560549de1227be97baa0770d783762 [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,
David Howells58fed942017-03-16 16:27:45 +000033 .flush = afs_flush,
David Howells00d3b7a2007-04-26 15:57:07 -070034 .release = afs_release,
35 .llseek = generic_file_llseek,
Al Viroaad4f8b2014-04-02 14:33:16 -040036 .read_iter = generic_file_read_iter,
Al Viro50b55512014-04-03 14:13:46 -040037 .write_iter = afs_file_write,
David Howells00d3b7a2007-04-26 15:57:07 -070038 .mmap = generic_file_readonly_mmap,
Jens Axboe5ffc4ef2007-06-01 11:49:19 +020039 .splice_read = generic_file_splice_read,
David Howells31143d52007-05-09 02:33:46 -070040 .fsync = afs_fsync,
David Howellse8d6c552007-07-15 23:40:12 -070041 .lock = afs_lock,
42 .flock = afs_flock,
David Howells00d3b7a2007-04-26 15:57:07 -070043};
44
Arjan van de Ven754661f2007-02-12 00:55:38 -080045const struct inode_operations afs_file_inode_operations = {
David Howells416351f2007-05-09 02:33:45 -070046 .getattr = afs_getattr,
David Howells31143d52007-05-09 02:33:46 -070047 .setattr = afs_setattr,
David Howells00d3b7a2007-04-26 15:57:07 -070048 .permission = afs_permission,
David Howellsd3e3b7ea2017-07-06 15:50:27 +010049 .listxattr = afs_listxattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
51
Christoph Hellwigf5e54d62006-06-28 04:26:44 -070052const struct address_space_operations afs_fs_aops = {
David Howells416351f2007-05-09 02:33:45 -070053 .readpage = afs_readpage,
David Howells9b3f26c2009-04-03 16:42:41 +010054 .readpages = afs_readpages,
David Howells31143d52007-05-09 02:33:46 -070055 .set_page_dirty = afs_set_page_dirty,
56 .launder_page = afs_launder_page,
David Howells416351f2007-05-09 02:33:45 -070057 .releasepage = afs_releasepage,
58 .invalidatepage = afs_invalidatepage,
Nick Piggin15b46502008-10-15 22:04:32 -070059 .write_begin = afs_write_begin,
60 .write_end = afs_write_end,
David Howells31143d52007-05-09 02:33:46 -070061 .writepage = afs_writepage,
62 .writepages = afs_writepages,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*
David Howells00d3b7a2007-04-26 15:57:07 -070066 * open an AFS file or directory and attach a key to it
67 */
68int afs_open(struct inode *inode, struct file *file)
69{
70 struct afs_vnode *vnode = AFS_FS_I(inode);
71 struct key *key;
David Howells260a9802007-04-26 15:59:35 -070072 int ret;
David Howells00d3b7a2007-04-26 15:57:07 -070073
David Howells416351f2007-05-09 02:33:45 -070074 _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
David Howells00d3b7a2007-04-26 15:57:07 -070075
76 key = afs_request_key(vnode->volume->cell);
77 if (IS_ERR(key)) {
78 _leave(" = %ld [key]", PTR_ERR(key));
79 return PTR_ERR(key);
80 }
81
David Howells260a9802007-04-26 15:59:35 -070082 ret = afs_validate(vnode, key);
83 if (ret < 0) {
84 _leave(" = %d [val]", ret);
85 return ret;
86 }
87
David Howells00d3b7a2007-04-26 15:57:07 -070088 file->private_data = key;
89 _leave(" = 0");
90 return 0;
91}
92
93/*
94 * release an AFS file or directory and discard its key
95 */
96int afs_release(struct inode *inode, struct file *file)
97{
98 struct afs_vnode *vnode = AFS_FS_I(inode);
99
David Howells416351f2007-05-09 02:33:45 -0700100 _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
David Howells00d3b7a2007-04-26 15:57:07 -0700101
102 key_put(file->private_data);
103 _leave(" = 0");
104 return 0;
105}
106
David Howells196ee9c2017-01-05 10:38:34 +0000107/*
108 * Dispose of a ref to a read record.
109 */
110void afs_put_read(struct afs_read *req)
111{
112 int i;
113
114 if (atomic_dec_and_test(&req->usage)) {
115 for (i = 0; i < req->nr_pages; i++)
116 if (req->pages[i])
117 put_page(req->pages[i]);
118 kfree(req);
119 }
120}
121
Matt Kraai6566abd2009-04-17 12:56:38 +0100122#ifdef CONFIG_AFS_FSCACHE
David Howells00d3b7a2007-04-26 15:57:07 -0700123/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 * deal with notification that a page was read from the cache
125 */
David Howells9b3f26c2009-04-03 16:42:41 +0100126static void afs_file_readpage_read_complete(struct page *page,
127 void *data,
128 int error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
David Howells9b3f26c2009-04-03 16:42:41 +0100130 _enter("%p,%p,%d", page, data, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
David Howells9b3f26c2009-04-03 16:42:41 +0100132 /* if the read completes with an error, we just unlock the page and let
133 * the VM reissue the readpage */
134 if (!error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 SetPageUptodate(page);
136 unlock_page(page);
David Howellsec268152007-04-26 15:49:28 -0700137}
Matt Kraai6566abd2009-04-17 12:56:38 +0100138#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/*
Al Virof6d335c2010-05-21 15:27:09 +0100141 * read page from file, directory or symlink, given a key to use
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 */
Al Virof6d335c2010-05-21 15:27:09 +0100143int afs_page_filler(void *data, struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Al Virof6d335c2010-05-21 15:27:09 +0100145 struct inode *inode = page->mapping->host;
146 struct afs_vnode *vnode = AFS_FS_I(inode);
David Howells196ee9c2017-01-05 10:38:34 +0000147 struct afs_read *req;
Al Virof6d335c2010-05-21 15:27:09 +0100148 struct key *key = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 int ret;
150
David Howells00d3b7a2007-04-26 15:57:07 -0700151 _enter("{%x},{%lu},{%lu}", key_serial(key), inode->i_ino, page->index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Matt Mackallcd7619d2005-05-01 08:59:01 -0700153 BUG_ON(!PageLocked(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 ret = -ESTALE;
David Howells08e0e7c2007-04-26 15:55:03 -0700156 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 goto error;
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 /* is it cached? */
David Howells9b3f26c2009-04-03 16:42:41 +0100160#ifdef CONFIG_AFS_FSCACHE
161 ret = fscache_read_or_alloc_page(vnode->cache,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 page,
163 afs_file_readpage_read_complete,
164 NULL,
165 GFP_KERNEL);
166#else
167 ret = -ENOBUFS;
168#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 switch (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 /* read BIO submitted (page in cache) */
171 case 0:
172 break;
173
David Howells9b3f26c2009-04-03 16:42:41 +0100174 /* page not yet cached */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 case -ENODATA:
David Howells9b3f26c2009-04-03 16:42:41 +0100176 _debug("cache said ENODATA");
177 goto go_on;
178
179 /* page will not be cached */
180 case -ENOBUFS:
181 _debug("cache said ENOBUFS");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 default:
David Howells9b3f26c2009-04-03 16:42:41 +0100183 go_on:
David Howells196ee9c2017-01-05 10:38:34 +0000184 req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *),
185 GFP_KERNEL);
186 if (!req)
187 goto enomem;
188
David Howells6db3ac32017-03-16 16:27:44 +0000189 /* We request a full page. If the page is a partial one at the
190 * end of the file, the server will return a short read and the
191 * unmarshalling code will clear the unfilled space.
192 */
David Howells196ee9c2017-01-05 10:38:34 +0000193 atomic_set(&req->usage, 1);
194 req->pos = (loff_t)page->index << PAGE_SHIFT;
David Howells6db3ac32017-03-16 16:27:44 +0000195 req->len = PAGE_SIZE;
David Howells196ee9c2017-01-05 10:38:34 +0000196 req->nr_pages = 1;
197 req->pages[0] = page;
198 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 /* read the contents of the file from the server into the
201 * page */
David Howells196ee9c2017-01-05 10:38:34 +0000202 ret = afs_vnode_fetch_data(vnode, key, req);
203 afs_put_read(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (ret < 0) {
David Howells08e0e7c2007-04-26 15:55:03 -0700205 if (ret == -ENOENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 _debug("got NOENT from server"
207 " - marking file deleted and stale");
David Howells08e0e7c2007-04-26 15:55:03 -0700208 set_bit(AFS_VNODE_DELETED, &vnode->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 ret = -ESTALE;
210 }
David Howells9b3f26c2009-04-03 16:42:41 +0100211
212#ifdef CONFIG_AFS_FSCACHE
213 fscache_uncache_page(vnode->cache, page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#endif
David Howells9b3f26c2009-04-03 16:42:41 +0100215 BUG_ON(PageFsCache(page));
David Howells68ae8492017-03-16 16:27:48 +0000216
217 if (ret == -EINTR ||
218 ret == -ENOMEM ||
219 ret == -ERESTARTSYS ||
220 ret == -EAGAIN)
221 goto error;
222 goto io_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224
225 SetPageUptodate(page);
226
David Howells9b3f26c2009-04-03 16:42:41 +0100227 /* send the page to the cache */
228#ifdef CONFIG_AFS_FSCACHE
229 if (PageFsCache(page) &&
230 fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
231 fscache_uncache_page(vnode->cache, page);
232 BUG_ON(PageFsCache(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#endif
David Howells9b3f26c2009-04-03 16:42:41 +0100235 unlock_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237
238 _leave(" = 0");
239 return 0;
240
David Howells68ae8492017-03-16 16:27:48 +0000241io_error:
242 SetPageError(page);
243 goto error;
David Howells196ee9c2017-01-05 10:38:34 +0000244enomem:
245 ret = -ENOMEM;
David Howells08e0e7c2007-04-26 15:55:03 -0700246error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 unlock_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 _leave(" = %d", ret);
249 return ret;
David Howellsec268152007-04-26 15:49:28 -0700250}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252/*
Al Virof6d335c2010-05-21 15:27:09 +0100253 * read page from file, directory or symlink, given a file to nominate the key
254 * to be used
255 */
256static int afs_readpage(struct file *file, struct page *page)
257{
258 struct key *key;
259 int ret;
260
261 if (file) {
262 key = file->private_data;
263 ASSERT(key != NULL);
264 ret = afs_page_filler(key, page);
265 } else {
266 struct inode *inode = page->mapping->host;
267 key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell);
268 if (IS_ERR(key)) {
269 ret = PTR_ERR(key);
270 } else {
271 ret = afs_page_filler(key, page);
272 key_put(key);
273 }
274 }
275 return ret;
276}
277
278/*
David Howells91b467e2017-01-05 10:38:35 +0000279 * Make pages available as they're filled.
280 */
281static void afs_readpages_page_done(struct afs_call *call, struct afs_read *req)
282{
Arnd Bergmann51c89e62017-01-13 14:46:19 +0000283#ifdef CONFIG_AFS_FSCACHE
David Howells91b467e2017-01-05 10:38:35 +0000284 struct afs_vnode *vnode = call->reply;
Arnd Bergmann51c89e62017-01-13 14:46:19 +0000285#endif
David Howells91b467e2017-01-05 10:38:35 +0000286 struct page *page = req->pages[req->index];
287
288 req->pages[req->index] = NULL;
289 SetPageUptodate(page);
290
291 /* send the page to the cache */
292#ifdef CONFIG_AFS_FSCACHE
293 if (PageFsCache(page) &&
294 fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
295 fscache_uncache_page(vnode->cache, page);
296 BUG_ON(PageFsCache(page));
297 }
298#endif
299 unlock_page(page);
300 put_page(page);
301}
302
303/*
304 * Read a contiguous set of pages.
305 */
306static int afs_readpages_one(struct file *file, struct address_space *mapping,
307 struct list_head *pages)
308{
309 struct afs_vnode *vnode = AFS_FS_I(mapping->host);
310 struct afs_read *req;
311 struct list_head *p;
312 struct page *first, *page;
313 struct key *key = file->private_data;
314 pgoff_t index;
315 int ret, n, i;
316
317 /* Count the number of contiguous pages at the front of the list. Note
318 * that the list goes prev-wards rather than next-wards.
319 */
320 first = list_entry(pages->prev, struct page, lru);
321 index = first->index + 1;
322 n = 1;
323 for (p = first->lru.prev; p != pages; p = p->prev) {
324 page = list_entry(p, struct page, lru);
325 if (page->index != index)
326 break;
327 index++;
328 n++;
329 }
330
331 req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *) * n,
332 GFP_NOFS);
333 if (!req)
334 return -ENOMEM;
335
336 atomic_set(&req->usage, 1);
337 req->page_done = afs_readpages_page_done;
338 req->pos = first->index;
339 req->pos <<= PAGE_SHIFT;
340
341 /* Transfer the pages to the request. We add them in until one fails
342 * to add to the LRU and then we stop (as that'll make a hole in the
343 * contiguous run.
344 *
345 * Note that it's possible for the file size to change whilst we're
346 * doing this, but we rely on the server returning less than we asked
347 * for if the file shrank. We also rely on this to deal with a partial
348 * page at the end of the file.
349 */
350 do {
351 page = list_entry(pages->prev, struct page, lru);
352 list_del(&page->lru);
353 index = page->index;
354 if (add_to_page_cache_lru(page, mapping, index,
355 readahead_gfp_mask(mapping))) {
356#ifdef CONFIG_AFS_FSCACHE
357 fscache_uncache_page(vnode->cache, page);
358#endif
359 put_page(page);
360 break;
361 }
362
363 req->pages[req->nr_pages++] = page;
364 req->len += PAGE_SIZE;
365 } while (req->nr_pages < n);
366
367 if (req->nr_pages == 0) {
368 kfree(req);
369 return 0;
370 }
371
372 ret = afs_vnode_fetch_data(vnode, key, req);
373 if (ret < 0)
374 goto error;
375
376 task_io_account_read(PAGE_SIZE * req->nr_pages);
377 afs_put_read(req);
378 return 0;
379
380error:
381 if (ret == -ENOENT) {
382 _debug("got NOENT from server"
383 " - marking file deleted and stale");
384 set_bit(AFS_VNODE_DELETED, &vnode->flags);
385 ret = -ESTALE;
386 }
387
388 for (i = 0; i < req->nr_pages; i++) {
389 page = req->pages[i];
390 if (page) {
391#ifdef CONFIG_AFS_FSCACHE
392 fscache_uncache_page(vnode->cache, page);
393#endif
394 SetPageError(page);
395 unlock_page(page);
396 }
397 }
398
399 afs_put_read(req);
400 return ret;
401}
402
403/*
David Howells9b3f26c2009-04-03 16:42:41 +0100404 * read a set of pages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 */
David Howells9b3f26c2009-04-03 16:42:41 +0100406static int afs_readpages(struct file *file, struct address_space *mapping,
407 struct list_head *pages, unsigned nr_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Al Virof6d335c2010-05-21 15:27:09 +0100409 struct key *key = file->private_data;
David Howells9b3f26c2009-04-03 16:42:41 +0100410 struct afs_vnode *vnode;
411 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Al Virof6d335c2010-05-21 15:27:09 +0100413 _enter("{%d},{%lu},,%d",
414 key_serial(key), mapping->host->i_ino, nr_pages);
415
416 ASSERT(key != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
David Howells9b3f26c2009-04-03 16:42:41 +0100418 vnode = AFS_FS_I(mapping->host);
Dan Carpenterad2a8e62012-03-20 16:58:06 +0000419 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
David Howells9b3f26c2009-04-03 16:42:41 +0100420 _leave(" = -ESTALE");
421 return -ESTALE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423
David Howells9b3f26c2009-04-03 16:42:41 +0100424 /* attempt to read as many of the pages as possible */
425#ifdef CONFIG_AFS_FSCACHE
426 ret = fscache_read_or_alloc_pages(vnode->cache,
427 mapping,
428 pages,
429 &nr_pages,
430 afs_file_readpage_read_complete,
431 NULL,
432 mapping_gfp_mask(mapping));
433#else
434 ret = -ENOBUFS;
435#endif
436
437 switch (ret) {
438 /* all pages are being read from the cache */
439 case 0:
440 BUG_ON(!list_empty(pages));
441 BUG_ON(nr_pages != 0);
442 _leave(" = 0 [reading all]");
443 return 0;
444
445 /* there were pages that couldn't be read from the cache */
446 case -ENODATA:
447 case -ENOBUFS:
448 break;
449
450 /* other error */
451 default:
452 _leave(" = %d", ret);
453 return ret;
454 }
455
David Howells91b467e2017-01-05 10:38:35 +0000456 while (!list_empty(pages)) {
457 ret = afs_readpages_one(file, mapping, pages);
458 if (ret < 0)
459 break;
460 }
David Howells9b3f26c2009-04-03 16:42:41 +0100461
462 _leave(" = %d [netting]", ret);
463 return ret;
David Howellsec268152007-04-26 15:49:28 -0700464}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/*
David Howells31143d52007-05-09 02:33:46 -0700467 * write back a dirty page
468 */
469static int afs_launder_page(struct page *page)
470{
471 _enter("{%lu}", page->index);
472
473 return 0;
474}
475
476/*
David Howells9b3f26c2009-04-03 16:42:41 +0100477 * invalidate part or all of a page
478 * - release a page and clean up its private data if offset is 0 (indicating
479 * the entire page)
480 */
Lukas Czernerd47992f2013-05-21 23:17:23 -0400481static void afs_invalidatepage(struct page *page, unsigned int offset,
482 unsigned int length)
David Howells9b3f26c2009-04-03 16:42:41 +0100483{
484 struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
485
Lukas Czernerd47992f2013-05-21 23:17:23 -0400486 _enter("{%lu},%u,%u", page->index, offset, length);
David Howells9b3f26c2009-04-03 16:42:41 +0100487
488 BUG_ON(!PageLocked(page));
489
490 /* we clean up only if the entire page is being invalidated */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300491 if (offset == 0 && length == PAGE_SIZE) {
David Howells9b3f26c2009-04-03 16:42:41 +0100492#ifdef CONFIG_AFS_FSCACHE
493 if (PageFsCache(page)) {
494 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
495 fscache_wait_on_page_write(vnode->cache, page);
496 fscache_uncache_page(vnode->cache, page);
David Howells9b3f26c2009-04-03 16:42:41 +0100497 }
498#endif
499
500 if (PagePrivate(page)) {
501 if (wb && !PageWriteback(page)) {
502 set_page_private(page, 0);
503 afs_put_writeback(wb);
504 }
505
506 if (!page_private(page))
507 ClearPagePrivate(page);
508 }
509 }
510
511 _leave("");
512}
513
514/*
515 * release a page and clean up its private state if it's not busy
516 * - return true if the page can now be released, false if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 */
David Howells416351f2007-05-09 02:33:45 -0700518static int afs_releasepage(struct page *page, gfp_t gfp_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
David Howells9b3f26c2009-04-03 16:42:41 +0100520 struct afs_writeback *wb = (struct afs_writeback *) page_private(page);
David Howells416351f2007-05-09 02:33:45 -0700521 struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
David Howells416351f2007-05-09 02:33:45 -0700523 _enter("{{%x:%u}[%lu],%lx},%x",
524 vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
525 gfp_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
David Howells9b3f26c2009-04-03 16:42:41 +0100527 /* deny if page is being written to the cache and the caller hasn't
528 * elected to wait */
529#ifdef CONFIG_AFS_FSCACHE
David Howells201a1542009-11-19 18:11:35 +0000530 if (!fscache_maybe_release_page(vnode->cache, page, gfp_flags)) {
531 _leave(" = F [cache busy]");
532 return 0;
David Howells9b3f26c2009-04-03 16:42:41 +0100533 }
534#endif
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (PagePrivate(page)) {
David Howells9b3f26c2009-04-03 16:42:41 +0100537 if (wb) {
538 set_page_private(page, 0);
539 afs_put_writeback(wb);
540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 ClearPagePrivate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543
David Howells9b3f26c2009-04-03 16:42:41 +0100544 /* indicate that the page can be released */
545 _leave(" = T");
546 return 1;
David Howellsec268152007-04-26 15:49:28 -0700547}