David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 1 | /* AFS filesystem file handling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 3 | * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/fs.h> |
| 16 | #include <linux/pagemap.h> |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 17 | #include <linux/writeback.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/gfp.h> |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 19 | #include <linux/task_io_accounting_ops.h> |
Nikolay Borisov | f86196e | 2019-01-03 15:29:02 -0800 | [diff] [blame] | 20 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include "internal.h" |
| 22 | |
David Howells | 1cf7a15 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 23 | static int afs_file_mmap(struct file *file, struct vm_area_struct *vma); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 24 | static int afs_readpage(struct file *file, struct page *page); |
Lukas Czerner | d47992f | 2013-05-21 23:17:23 -0400 | [diff] [blame] | 25 | static void afs_invalidatepage(struct page *page, unsigned int offset, |
| 26 | unsigned int length); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 27 | static int afs_releasepage(struct page *page, gfp_t gfp_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 29 | static int afs_readpages(struct file *filp, struct address_space *mapping, |
| 30 | struct list_head *pages, unsigned nr_pages); |
| 31 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 32 | const struct file_operations afs_file_operations = { |
| 33 | .open = afs_open, |
| 34 | .release = afs_release, |
| 35 | .llseek = generic_file_llseek, |
Al Viro | aad4f8b | 2014-04-02 14:33:16 -0400 | [diff] [blame] | 36 | .read_iter = generic_file_read_iter, |
Al Viro | 50b5551 | 2014-04-03 14:13:46 -0400 | [diff] [blame] | 37 | .write_iter = afs_file_write, |
David Howells | 1cf7a15 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 38 | .mmap = afs_file_mmap, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 39 | .splice_read = generic_file_splice_read, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 40 | .fsync = afs_fsync, |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 41 | .lock = afs_lock, |
| 42 | .flock = afs_flock, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 45 | const struct inode_operations afs_file_inode_operations = { |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 46 | .getattr = afs_getattr, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 47 | .setattr = afs_setattr, |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 48 | .permission = afs_permission, |
David Howells | d3e3b7ea | 2017-07-06 15:50:27 +0100 | [diff] [blame] | 49 | .listxattr = afs_listxattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 52 | const struct address_space_operations afs_fs_aops = { |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 53 | .readpage = afs_readpage, |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 54 | .readpages = afs_readpages, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 55 | .set_page_dirty = afs_set_page_dirty, |
| 56 | .launder_page = afs_launder_page, |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 57 | .releasepage = afs_releasepage, |
| 58 | .invalidatepage = afs_invalidatepage, |
Nick Piggin | 15b4650 | 2008-10-15 22:04:32 -0700 | [diff] [blame] | 59 | .write_begin = afs_write_begin, |
| 60 | .write_end = afs_write_end, |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 61 | .writepage = afs_writepage, |
| 62 | .writepages = afs_writepages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
David Howells | 1cf7a15 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 65 | static const struct vm_operations_struct afs_vm_ops = { |
| 66 | .fault = filemap_fault, |
| 67 | .map_pages = filemap_map_pages, |
| 68 | .page_mkwrite = afs_page_mkwrite, |
| 69 | }; |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 72 | * Discard a pin on a writeback key. |
| 73 | */ |
| 74 | void afs_put_wb_key(struct afs_wb_key *wbk) |
| 75 | { |
| 76 | if (refcount_dec_and_test(&wbk->usage)) { |
| 77 | key_put(wbk->key); |
| 78 | kfree(wbk); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Cache key for writeback. |
| 84 | */ |
| 85 | int afs_cache_wb_key(struct afs_vnode *vnode, struct afs_file *af) |
| 86 | { |
| 87 | struct afs_wb_key *wbk, *p; |
| 88 | |
| 89 | wbk = kzalloc(sizeof(struct afs_wb_key), GFP_KERNEL); |
| 90 | if (!wbk) |
| 91 | return -ENOMEM; |
| 92 | refcount_set(&wbk->usage, 2); |
| 93 | wbk->key = af->key; |
| 94 | |
| 95 | spin_lock(&vnode->wb_lock); |
| 96 | list_for_each_entry(p, &vnode->wb_keys, vnode_link) { |
| 97 | if (p->key == wbk->key) |
| 98 | goto found; |
| 99 | } |
| 100 | |
| 101 | key_get(wbk->key); |
| 102 | list_add_tail(&wbk->vnode_link, &vnode->wb_keys); |
| 103 | spin_unlock(&vnode->wb_lock); |
| 104 | af->wb = wbk; |
| 105 | return 0; |
| 106 | |
| 107 | found: |
| 108 | refcount_inc(&p->usage); |
| 109 | spin_unlock(&vnode->wb_lock); |
| 110 | af->wb = p; |
| 111 | kfree(wbk); |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /* |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 116 | * open an AFS file or directory and attach a key to it |
| 117 | */ |
| 118 | int afs_open(struct inode *inode, struct file *file) |
| 119 | { |
| 120 | struct afs_vnode *vnode = AFS_FS_I(inode); |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 121 | struct afs_file *af; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 122 | struct key *key; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 123 | int ret; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 124 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 125 | _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 126 | |
| 127 | key = afs_request_key(vnode->volume->cell); |
| 128 | if (IS_ERR(key)) { |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 129 | ret = PTR_ERR(key); |
| 130 | goto error; |
| 131 | } |
| 132 | |
| 133 | af = kzalloc(sizeof(*af), GFP_KERNEL); |
| 134 | if (!af) { |
| 135 | ret = -ENOMEM; |
| 136 | goto error_key; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 137 | } |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 138 | af->key = key; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 139 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 140 | ret = afs_validate(vnode, key); |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 141 | if (ret < 0) |
| 142 | goto error_af; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 143 | |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 144 | if (file->f_mode & FMODE_WRITE) { |
| 145 | ret = afs_cache_wb_key(vnode, af); |
| 146 | if (ret < 0) |
| 147 | goto error_af; |
| 148 | } |
David Howells | 5a81327 | 2018-04-06 14:17:26 +0100 | [diff] [blame] | 149 | |
| 150 | if (file->f_flags & O_TRUNC) |
| 151 | set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags); |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 152 | |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 153 | file->private_data = af; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 154 | _leave(" = 0"); |
| 155 | return 0; |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 156 | |
| 157 | error_af: |
| 158 | kfree(af); |
| 159 | error_key: |
| 160 | key_put(key); |
| 161 | error: |
| 162 | _leave(" = %d", ret); |
| 163 | return ret; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /* |
| 167 | * release an AFS file or directory and discard its key |
| 168 | */ |
| 169 | int afs_release(struct inode *inode, struct file *file) |
| 170 | { |
| 171 | struct afs_vnode *vnode = AFS_FS_I(inode); |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 172 | struct afs_file *af = file->private_data; |
David Howells | a1b879e | 2019-05-15 12:09:17 +0100 | [diff] [blame] | 173 | int ret = 0; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 174 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 175 | _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 176 | |
David Howells | 5a81327 | 2018-04-06 14:17:26 +0100 | [diff] [blame] | 177 | if ((file->f_mode & FMODE_WRITE)) |
David Howells | a1b879e | 2019-05-15 12:09:17 +0100 | [diff] [blame] | 178 | ret = vfs_fsync(file, 0); |
David Howells | 5a81327 | 2018-04-06 14:17:26 +0100 | [diff] [blame] | 179 | |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 180 | file->private_data = NULL; |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 181 | if (af->wb) |
| 182 | afs_put_wb_key(af->wb); |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 183 | key_put(af->key); |
| 184 | kfree(af); |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 185 | afs_prune_wb_keys(vnode); |
David Howells | a1b879e | 2019-05-15 12:09:17 +0100 | [diff] [blame] | 186 | _leave(" = %d", ret); |
| 187 | return ret; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 188 | } |
| 189 | |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 190 | /* |
| 191 | * Dispose of a ref to a read record. |
| 192 | */ |
| 193 | void afs_put_read(struct afs_read *req) |
| 194 | { |
| 195 | int i; |
| 196 | |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 197 | if (refcount_dec_and_test(&req->usage)) { |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 198 | for (i = 0; i < req->nr_pages; i++) |
| 199 | if (req->pages[i]) |
| 200 | put_page(req->pages[i]); |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 201 | if (req->pages != req->array) |
| 202 | kfree(req->pages); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 203 | kfree(req); |
| 204 | } |
| 205 | } |
| 206 | |
Matt Kraai | 6566abd | 2009-04-17 12:56:38 +0100 | [diff] [blame] | 207 | #ifdef CONFIG_AFS_FSCACHE |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 208 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | * deal with notification that a page was read from the cache |
| 210 | */ |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 211 | static void afs_file_readpage_read_complete(struct page *page, |
| 212 | void *data, |
| 213 | int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 215 | _enter("%p,%p,%d", page, data, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 217 | /* if the read completes with an error, we just unlock the page and let |
| 218 | * the VM reissue the readpage */ |
| 219 | if (!error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | SetPageUptodate(page); |
| 221 | unlock_page(page); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 222 | } |
Matt Kraai | 6566abd | 2009-04-17 12:56:38 +0100 | [diff] [blame] | 223 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | /* |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 226 | * Fetch file data from the volume. |
| 227 | */ |
| 228 | int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *desc) |
| 229 | { |
| 230 | struct afs_fs_cursor fc; |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 231 | struct afs_status_cb *scb; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 232 | int ret; |
| 233 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 234 | _enter("%s{%llx:%llu.%u},%x,,,", |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 235 | vnode->volume->name, |
| 236 | vnode->fid.vid, |
| 237 | vnode->fid.vnode, |
| 238 | vnode->fid.unique, |
| 239 | key_serial(key)); |
| 240 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 241 | scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL); |
| 242 | if (!scb) |
| 243 | return -ENOMEM; |
| 244 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 245 | ret = -ERESTARTSYS; |
David Howells | 20b8391 | 2019-05-08 16:16:31 +0100 | [diff] [blame] | 246 | if (afs_begin_vnode_operation(&fc, vnode, key, true)) { |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 247 | afs_dataversion_t data_version = vnode->status.data_version; |
| 248 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 249 | while (afs_select_fileserver(&fc)) { |
David Howells | 68251f0 | 2018-05-12 22:31:33 +0100 | [diff] [blame] | 250 | fc.cb_break = afs_calc_vnode_cb_break(vnode); |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 251 | afs_fs_fetch_data(&fc, scb, desc); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 252 | } |
| 253 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 254 | afs_check_for_remote_deletion(&fc, vnode); |
| 255 | afs_vnode_commit_status(&fc, vnode, fc.cb_break, |
| 256 | &data_version, scb); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 257 | ret = afs_end_vnode_operation(&fc); |
| 258 | } |
| 259 | |
David Howells | 76a5cb6 | 2018-04-06 14:17:26 +0100 | [diff] [blame] | 260 | if (ret == 0) { |
| 261 | afs_stat_v(vnode, n_fetches); |
| 262 | atomic_long_add(desc->actual_len, |
| 263 | &afs_v2net(vnode)->n_fetch_bytes); |
| 264 | } |
| 265 | |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 266 | kfree(scb); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 267 | _leave(" = %d", ret); |
| 268 | return ret; |
| 269 | } |
| 270 | |
| 271 | /* |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 272 | * read page from file, directory or symlink, given a key to use |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | */ |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 274 | int afs_page_filler(void *data, struct page *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 276 | struct inode *inode = page->mapping->host; |
| 277 | struct afs_vnode *vnode = AFS_FS_I(inode); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 278 | struct afs_read *req; |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 279 | struct key *key = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | int ret; |
| 281 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 282 | _enter("{%x},{%lu},{%lu}", key_serial(key), inode->i_ino, page->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Matt Mackall | cd7619d | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 284 | BUG_ON(!PageLocked(page)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | ret = -ESTALE; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 287 | if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | goto error; |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* is it cached? */ |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 291 | #ifdef CONFIG_AFS_FSCACHE |
| 292 | ret = fscache_read_or_alloc_page(vnode->cache, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | page, |
| 294 | afs_file_readpage_read_complete, |
| 295 | NULL, |
| 296 | GFP_KERNEL); |
| 297 | #else |
| 298 | ret = -ENOBUFS; |
| 299 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | switch (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /* read BIO submitted (page in cache) */ |
| 302 | case 0: |
| 303 | break; |
| 304 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 305 | /* page not yet cached */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | case -ENODATA: |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 307 | _debug("cache said ENODATA"); |
| 308 | goto go_on; |
| 309 | |
| 310 | /* page will not be cached */ |
| 311 | case -ENOBUFS: |
| 312 | _debug("cache said ENOBUFS"); |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 313 | |
| 314 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | default: |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 316 | go_on: |
Zhengyuan Liu | ee10258 | 2019-06-20 18:12:17 +0100 | [diff] [blame^] | 317 | req = kzalloc(struct_size(req, array, 1), GFP_KERNEL); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 318 | if (!req) |
| 319 | goto enomem; |
| 320 | |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 321 | /* We request a full page. If the page is a partial one at the |
| 322 | * end of the file, the server will return a short read and the |
| 323 | * unmarshalling code will clear the unfilled space. |
| 324 | */ |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 325 | refcount_set(&req->usage, 1); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 326 | req->pos = (loff_t)page->index << PAGE_SHIFT; |
David Howells | 6db3ac3 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 327 | req->len = PAGE_SIZE; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 328 | req->nr_pages = 1; |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 329 | req->pages = req->array; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 330 | req->pages[0] = page; |
| 331 | get_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | /* read the contents of the file from the server into the |
| 334 | * page */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 335 | ret = afs_fetch_data(vnode, key, req); |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 336 | afs_put_read(req); |
David Howells | dab17c1 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (ret < 0) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 339 | if (ret == -ENOENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | _debug("got NOENT from server" |
| 341 | " - marking file deleted and stale"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 342 | set_bit(AFS_VNODE_DELETED, &vnode->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | ret = -ESTALE; |
| 344 | } |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 345 | |
| 346 | #ifdef CONFIG_AFS_FSCACHE |
| 347 | fscache_uncache_page(vnode->cache, page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | #endif |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 349 | BUG_ON(PageFsCache(page)); |
David Howells | 68ae849 | 2017-03-16 16:27:48 +0000 | [diff] [blame] | 350 | |
| 351 | if (ret == -EINTR || |
| 352 | ret == -ENOMEM || |
| 353 | ret == -ERESTARTSYS || |
| 354 | ret == -EAGAIN) |
| 355 | goto error; |
| 356 | goto io_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | SetPageUptodate(page); |
| 360 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 361 | /* send the page to the cache */ |
| 362 | #ifdef CONFIG_AFS_FSCACHE |
| 363 | if (PageFsCache(page) && |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 364 | fscache_write_page(vnode->cache, page, vnode->status.size, |
| 365 | GFP_KERNEL) != 0) { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 366 | fscache_uncache_page(vnode->cache, page); |
| 367 | BUG_ON(PageFsCache(page)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | #endif |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 370 | unlock_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | _leave(" = 0"); |
| 374 | return 0; |
| 375 | |
David Howells | 68ae849 | 2017-03-16 16:27:48 +0000 | [diff] [blame] | 376 | io_error: |
| 377 | SetPageError(page); |
| 378 | goto error; |
David Howells | 196ee9c | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 379 | enomem: |
| 380 | ret = -ENOMEM; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 381 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | unlock_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | _leave(" = %d", ret); |
| 384 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 388 | * read page from file, directory or symlink, given a file to nominate the key |
| 389 | * to be used |
| 390 | */ |
| 391 | static int afs_readpage(struct file *file, struct page *page) |
| 392 | { |
| 393 | struct key *key; |
| 394 | int ret; |
| 395 | |
| 396 | if (file) { |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 397 | key = afs_file_key(file); |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 398 | ASSERT(key != NULL); |
| 399 | ret = afs_page_filler(key, page); |
| 400 | } else { |
| 401 | struct inode *inode = page->mapping->host; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 402 | key = afs_request_key(AFS_FS_S(inode->i_sb)->cell); |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 403 | if (IS_ERR(key)) { |
| 404 | ret = PTR_ERR(key); |
| 405 | } else { |
| 406 | ret = afs_page_filler(key, page); |
| 407 | key_put(key); |
| 408 | } |
| 409 | } |
| 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | /* |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 414 | * Make pages available as they're filled. |
| 415 | */ |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 416 | static void afs_readpages_page_done(struct afs_read *req) |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 417 | { |
Arnd Bergmann | 51c89e6 | 2017-01-13 14:46:19 +0000 | [diff] [blame] | 418 | #ifdef CONFIG_AFS_FSCACHE |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 419 | struct afs_vnode *vnode = req->vnode; |
Arnd Bergmann | 51c89e6 | 2017-01-13 14:46:19 +0000 | [diff] [blame] | 420 | #endif |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 421 | struct page *page = req->pages[req->index]; |
| 422 | |
| 423 | req->pages[req->index] = NULL; |
| 424 | SetPageUptodate(page); |
| 425 | |
| 426 | /* send the page to the cache */ |
| 427 | #ifdef CONFIG_AFS_FSCACHE |
| 428 | if (PageFsCache(page) && |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 429 | fscache_write_page(vnode->cache, page, vnode->status.size, |
| 430 | GFP_KERNEL) != 0) { |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 431 | fscache_uncache_page(vnode->cache, page); |
| 432 | BUG_ON(PageFsCache(page)); |
| 433 | } |
| 434 | #endif |
| 435 | unlock_page(page); |
| 436 | put_page(page); |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Read a contiguous set of pages. |
| 441 | */ |
| 442 | static int afs_readpages_one(struct file *file, struct address_space *mapping, |
| 443 | struct list_head *pages) |
| 444 | { |
| 445 | struct afs_vnode *vnode = AFS_FS_I(mapping->host); |
| 446 | struct afs_read *req; |
| 447 | struct list_head *p; |
| 448 | struct page *first, *page; |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 449 | struct key *key = afs_file_key(file); |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 450 | pgoff_t index; |
| 451 | int ret, n, i; |
| 452 | |
| 453 | /* Count the number of contiguous pages at the front of the list. Note |
| 454 | * that the list goes prev-wards rather than next-wards. |
| 455 | */ |
Nikolay Borisov | f86196e | 2019-01-03 15:29:02 -0800 | [diff] [blame] | 456 | first = lru_to_page(pages); |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 457 | index = first->index + 1; |
| 458 | n = 1; |
| 459 | for (p = first->lru.prev; p != pages; p = p->prev) { |
| 460 | page = list_entry(p, struct page, lru); |
| 461 | if (page->index != index) |
| 462 | break; |
| 463 | index++; |
| 464 | n++; |
| 465 | } |
| 466 | |
Zhengyuan Liu | ee10258 | 2019-06-20 18:12:17 +0100 | [diff] [blame^] | 467 | req = kzalloc(struct_size(req, array, n), GFP_NOFS); |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 468 | if (!req) |
| 469 | return -ENOMEM; |
| 470 | |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 471 | refcount_set(&req->usage, 1); |
David Howells | a58823a | 2019-05-09 15:16:10 +0100 | [diff] [blame] | 472 | req->vnode = vnode; |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 473 | req->page_done = afs_readpages_page_done; |
| 474 | req->pos = first->index; |
| 475 | req->pos <<= PAGE_SHIFT; |
David Howells | f3ddee8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 476 | req->pages = req->array; |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 477 | |
| 478 | /* Transfer the pages to the request. We add them in until one fails |
| 479 | * to add to the LRU and then we stop (as that'll make a hole in the |
| 480 | * contiguous run. |
| 481 | * |
| 482 | * Note that it's possible for the file size to change whilst we're |
| 483 | * doing this, but we rely on the server returning less than we asked |
| 484 | * for if the file shrank. We also rely on this to deal with a partial |
| 485 | * page at the end of the file. |
| 486 | */ |
| 487 | do { |
Nikolay Borisov | f86196e | 2019-01-03 15:29:02 -0800 | [diff] [blame] | 488 | page = lru_to_page(pages); |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 489 | list_del(&page->lru); |
| 490 | index = page->index; |
| 491 | if (add_to_page_cache_lru(page, mapping, index, |
| 492 | readahead_gfp_mask(mapping))) { |
| 493 | #ifdef CONFIG_AFS_FSCACHE |
| 494 | fscache_uncache_page(vnode->cache, page); |
| 495 | #endif |
| 496 | put_page(page); |
| 497 | break; |
| 498 | } |
| 499 | |
| 500 | req->pages[req->nr_pages++] = page; |
| 501 | req->len += PAGE_SIZE; |
| 502 | } while (req->nr_pages < n); |
| 503 | |
| 504 | if (req->nr_pages == 0) { |
| 505 | kfree(req); |
| 506 | return 0; |
| 507 | } |
| 508 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 509 | ret = afs_fetch_data(vnode, key, req); |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 510 | if (ret < 0) |
| 511 | goto error; |
| 512 | |
| 513 | task_io_account_read(PAGE_SIZE * req->nr_pages); |
| 514 | afs_put_read(req); |
| 515 | return 0; |
| 516 | |
| 517 | error: |
| 518 | if (ret == -ENOENT) { |
| 519 | _debug("got NOENT from server" |
| 520 | " - marking file deleted and stale"); |
| 521 | set_bit(AFS_VNODE_DELETED, &vnode->flags); |
| 522 | ret = -ESTALE; |
| 523 | } |
| 524 | |
| 525 | for (i = 0; i < req->nr_pages; i++) { |
| 526 | page = req->pages[i]; |
| 527 | if (page) { |
| 528 | #ifdef CONFIG_AFS_FSCACHE |
| 529 | fscache_uncache_page(vnode->cache, page); |
| 530 | #endif |
| 531 | SetPageError(page); |
| 532 | unlock_page(page); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | afs_put_read(req); |
| 537 | return ret; |
| 538 | } |
| 539 | |
| 540 | /* |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 541 | * read a set of pages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | */ |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 543 | static int afs_readpages(struct file *file, struct address_space *mapping, |
| 544 | struct list_head *pages, unsigned nr_pages) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
David Howells | 215804a | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 546 | struct key *key = afs_file_key(file); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 547 | struct afs_vnode *vnode; |
| 548 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Al Viro | f6d335c | 2010-05-21 15:27:09 +0100 | [diff] [blame] | 550 | _enter("{%d},{%lu},,%d", |
| 551 | key_serial(key), mapping->host->i_ino, nr_pages); |
| 552 | |
| 553 | ASSERT(key != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 555 | vnode = AFS_FS_I(mapping->host); |
Dan Carpenter | ad2a8e6 | 2012-03-20 16:58:06 +0000 | [diff] [blame] | 556 | if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 557 | _leave(" = -ESTALE"); |
| 558 | return -ESTALE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 561 | /* attempt to read as many of the pages as possible */ |
| 562 | #ifdef CONFIG_AFS_FSCACHE |
| 563 | ret = fscache_read_or_alloc_pages(vnode->cache, |
| 564 | mapping, |
| 565 | pages, |
| 566 | &nr_pages, |
| 567 | afs_file_readpage_read_complete, |
| 568 | NULL, |
| 569 | mapping_gfp_mask(mapping)); |
| 570 | #else |
| 571 | ret = -ENOBUFS; |
| 572 | #endif |
| 573 | |
| 574 | switch (ret) { |
| 575 | /* all pages are being read from the cache */ |
| 576 | case 0: |
| 577 | BUG_ON(!list_empty(pages)); |
| 578 | BUG_ON(nr_pages != 0); |
| 579 | _leave(" = 0 [reading all]"); |
| 580 | return 0; |
| 581 | |
| 582 | /* there were pages that couldn't be read from the cache */ |
| 583 | case -ENODATA: |
| 584 | case -ENOBUFS: |
| 585 | break; |
| 586 | |
| 587 | /* other error */ |
| 588 | default: |
| 589 | _leave(" = %d", ret); |
| 590 | return ret; |
| 591 | } |
| 592 | |
David Howells | 91b467e | 2017-01-05 10:38:35 +0000 | [diff] [blame] | 593 | while (!list_empty(pages)) { |
| 594 | ret = afs_readpages_one(file, mapping, pages); |
| 595 | if (ret < 0) |
| 596 | break; |
| 597 | } |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 598 | |
| 599 | _leave(" = %d [netting]", ret); |
| 600 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | /* |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 604 | * invalidate part or all of a page |
| 605 | * - release a page and clean up its private data if offset is 0 (indicating |
| 606 | * the entire page) |
| 607 | */ |
Lukas Czerner | d47992f | 2013-05-21 23:17:23 -0400 | [diff] [blame] | 608 | static void afs_invalidatepage(struct page *page, unsigned int offset, |
| 609 | unsigned int length) |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 610 | { |
David Howells | 13524ab | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 611 | struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); |
| 612 | unsigned long priv; |
| 613 | |
Lukas Czerner | d47992f | 2013-05-21 23:17:23 -0400 | [diff] [blame] | 614 | _enter("{%lu},%u,%u", page->index, offset, length); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 615 | |
| 616 | BUG_ON(!PageLocked(page)); |
| 617 | |
| 618 | /* we clean up only if the entire page is being invalidated */ |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 619 | if (offset == 0 && length == PAGE_SIZE) { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 620 | #ifdef CONFIG_AFS_FSCACHE |
| 621 | if (PageFsCache(page)) { |
| 622 | struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); |
| 623 | fscache_wait_on_page_write(vnode->cache, page); |
| 624 | fscache_uncache_page(vnode->cache, page); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 625 | } |
| 626 | #endif |
| 627 | |
| 628 | if (PagePrivate(page)) { |
David Howells | 13524ab | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 629 | priv = page_private(page); |
| 630 | trace_afs_page_dirty(vnode, tracepoint_string("inval"), |
| 631 | page->index, priv); |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 632 | set_page_private(page, 0); |
| 633 | ClearPagePrivate(page); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
| 637 | _leave(""); |
| 638 | } |
| 639 | |
| 640 | /* |
| 641 | * release a page and clean up its private state if it's not busy |
| 642 | * - return true if the page can now be released, false if not |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | */ |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 644 | static int afs_releasepage(struct page *page, gfp_t gfp_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 646 | struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); |
David Howells | 13524ab | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 647 | unsigned long priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 649 | _enter("{{%llx:%llu}[%lu],%lx},%x", |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 650 | vnode->fid.vid, vnode->fid.vnode, page->index, page->flags, |
| 651 | gfp_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 653 | /* deny if page is being written to the cache and the caller hasn't |
| 654 | * elected to wait */ |
| 655 | #ifdef CONFIG_AFS_FSCACHE |
David Howells | 201a154 | 2009-11-19 18:11:35 +0000 | [diff] [blame] | 656 | if (!fscache_maybe_release_page(vnode->cache, page, gfp_flags)) { |
| 657 | _leave(" = F [cache busy]"); |
| 658 | return 0; |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 659 | } |
| 660 | #endif |
| 661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | if (PagePrivate(page)) { |
David Howells | 13524ab | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 663 | priv = page_private(page); |
| 664 | trace_afs_page_dirty(vnode, tracepoint_string("rel"), |
| 665 | page->index, priv); |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 666 | set_page_private(page, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | ClearPagePrivate(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 670 | /* indicate that the page can be released */ |
| 671 | _leave(" = T"); |
| 672 | return 1; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 673 | } |
David Howells | 1cf7a15 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * Handle setting up a memory mapping on an AFS file. |
| 677 | */ |
| 678 | static int afs_file_mmap(struct file *file, struct vm_area_struct *vma) |
| 679 | { |
| 680 | int ret; |
| 681 | |
| 682 | ret = generic_file_mmap(file, vma); |
| 683 | if (ret == 0) |
| 684 | vma->vm_ops = &afs_vm_ops; |
| 685 | return ret; |
| 686 | } |