~ [ 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-3.16.85)


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

~ [ 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