~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/afs/file.c

Version: ~ [ linux-5.15-rc1 ] ~ [ linux-5.14.5 ] ~ [ linux-5.13.18 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.66 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.147 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.206 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.246 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.282 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.283 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/afs/file.c (Version linux-4.18.20) and /fs/afs/file.c (Version linux-5.6.19)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp