NFS: Fix missing page_unlock() in nfs_readpage
[safe/jmp/linux-2.6] / fs / nfs / read.c
1 /*
2  * linux/fs/nfs/read.c
3  *
4  * Block I/O for NFS
5  *
6  * Partial copy of Linus' read cache modifications to fs/nfs/file.c
7  * modified for async RPC by okir@monad.swb.de
8  *
9  * We do an ugly hack here in order to return proper error codes to the
10  * user program when a read request failed: since generic_file_read
11  * only checks the return value of inode->i_op->readpage() which is always 0
12  * for async RPC, we set the error bit of the page to 1 when an error occurs,
13  * and make nfs_readpage transmit requests synchronously when encountering this.
14  * This is only a small problem, though, since we now retry all operations
15  * within the RPC code when root squashing is suspected.
16  */
17
18 #include <linux/time.h>
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/fcntl.h>
22 #include <linux/stat.h>
23 #include <linux/mm.h>
24 #include <linux/slab.h>
25 #include <linux/pagemap.h>
26 #include <linux/sunrpc/clnt.h>
27 #include <linux/nfs_fs.h>
28 #include <linux/nfs_page.h>
29 #include <linux/smp_lock.h>
30
31 #include <asm/system.h>
32
33 #include "iostat.h"
34
35 #define NFSDBG_FACILITY         NFSDBG_PAGECACHE
36
37 static int nfs_pagein_one(struct list_head *, struct inode *);
38 static const struct rpc_call_ops nfs_read_partial_ops;
39 static const struct rpc_call_ops nfs_read_full_ops;
40
41 static kmem_cache_t *nfs_rdata_cachep;
42 static mempool_t *nfs_rdata_mempool;
43
44 #define MIN_POOL_READ   (32)
45
46 struct nfs_read_data *nfs_readdata_alloc(size_t len)
47 {
48         unsigned int pagecount = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
49         struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, SLAB_NOFS);
50
51         if (p) {
52                 memset(p, 0, sizeof(*p));
53                 INIT_LIST_HEAD(&p->pages);
54                 p->npages = pagecount;
55                 if (pagecount <= ARRAY_SIZE(p->page_array))
56                         p->pagevec = p->page_array;
57                 else {
58                         p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
59                         if (!p->pagevec) {
60                                 mempool_free(p, nfs_rdata_mempool);
61                                 p = NULL;
62                         }
63                 }
64         }
65         return p;
66 }
67
68 static void nfs_readdata_rcu_free(struct rcu_head *head)
69 {
70         struct nfs_read_data *p = container_of(head, struct nfs_read_data, task.u.tk_rcu);
71         if (p && (p->pagevec != &p->page_array[0]))
72                 kfree(p->pagevec);
73         mempool_free(p, nfs_rdata_mempool);
74 }
75
76 static void nfs_readdata_free(struct nfs_read_data *rdata)
77 {
78         call_rcu_bh(&rdata->task.u.tk_rcu, nfs_readdata_rcu_free);
79 }
80
81 void nfs_readdata_release(void *data)
82 {
83         nfs_readdata_free(data);
84 }
85
86 static
87 unsigned int nfs_page_length(struct inode *inode, struct page *page)
88 {
89         loff_t i_size = i_size_read(inode);
90         unsigned long idx;
91
92         if (i_size <= 0)
93                 return 0;
94         idx = (i_size - 1) >> PAGE_CACHE_SHIFT;
95         if (page->index > idx)
96                 return 0;
97         if (page->index != idx)
98                 return PAGE_CACHE_SIZE;
99         return 1 + ((i_size - 1) & (PAGE_CACHE_SIZE - 1));
100 }
101
102 static
103 int nfs_return_empty_page(struct page *page)
104 {
105         memclear_highpage_flush(page, 0, PAGE_CACHE_SIZE);
106         SetPageUptodate(page);
107         unlock_page(page);
108         return 0;
109 }
110
111 static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data)
112 {
113         unsigned int remainder = data->args.count - data->res.count;
114         unsigned int base = data->args.pgbase + data->res.count;
115         unsigned int pglen;
116         struct page **pages;
117
118         if (data->res.eof == 0 || remainder == 0)
119                 return;
120         /*
121          * Note: "remainder" can never be negative, since we check for
122          *      this in the XDR code.
123          */
124         pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
125         base &= ~PAGE_CACHE_MASK;
126         pglen = PAGE_CACHE_SIZE - base;
127         for (;;) {
128                 if (remainder <= pglen) {
129                         memclear_highpage_flush(*pages, base, remainder);
130                         break;
131                 }
132                 memclear_highpage_flush(*pages, base, pglen);
133                 pages++;
134                 remainder -= pglen;
135                 pglen = PAGE_CACHE_SIZE;
136                 base = 0;
137         }
138 }
139
140 /*
141  * Read a page synchronously.
142  */
143 static int nfs_readpage_sync(struct nfs_open_context *ctx, struct inode *inode,
144                 struct page *page)
145 {
146         unsigned int    rsize = NFS_SERVER(inode)->rsize;
147         unsigned int    count = PAGE_CACHE_SIZE;
148         int result = -ENOMEM;
149         struct nfs_read_data *rdata;
150
151         rdata = nfs_readdata_alloc(count);
152         if (!rdata)
153                 goto out_unlock;
154
155         memset(rdata, 0, sizeof(*rdata));
156         rdata->flags = (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
157         rdata->cred = ctx->cred;
158         rdata->inode = inode;
159         INIT_LIST_HEAD(&rdata->pages);
160         rdata->args.fh = NFS_FH(inode);
161         rdata->args.context = ctx;
162         rdata->args.pages = &page;
163         rdata->args.pgbase = 0UL;
164         rdata->args.count = rsize;
165         rdata->res.fattr = &rdata->fattr;
166
167         dprintk("NFS: nfs_readpage_sync(%p)\n", page);
168
169         /*
170          * This works now because the socket layer never tries to DMA
171          * into this buffer directly.
172          */
173         do {
174                 if (count < rsize)
175                         rdata->args.count = count;
176                 rdata->res.count = rdata->args.count;
177                 rdata->args.offset = page_offset(page) + rdata->args.pgbase;
178
179                 dprintk("NFS: nfs_proc_read(%s, (%s/%Ld), %Lu, %u)\n",
180                         NFS_SERVER(inode)->nfs_client->cl_hostname,
181                         inode->i_sb->s_id,
182                         (long long)NFS_FILEID(inode),
183                         (unsigned long long)rdata->args.pgbase,
184                         rdata->args.count);
185
186                 lock_kernel();
187                 result = NFS_PROTO(inode)->read(rdata);
188                 unlock_kernel();
189
190                 /*
191                  * Even if we had a partial success we can't mark the page
192                  * cache valid.
193                  */
194                 if (result < 0) {
195                         if (result == -EISDIR)
196                                 result = -EINVAL;
197                         goto io_error;
198                 }
199                 count -= result;
200                 rdata->args.pgbase += result;
201                 nfs_add_stats(inode, NFSIOS_SERVERREADBYTES, result);
202
203                 /* Note: result == 0 should only happen if we're caching
204                  * a write that extends the file and punches a hole.
205                  */
206                 if (rdata->res.eof != 0 || result == 0)
207                         break;
208         } while (count);
209         spin_lock(&inode->i_lock);
210         NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATIME;
211         spin_unlock(&inode->i_lock);
212
213         if (rdata->res.eof || rdata->res.count == rdata->args.count) {
214                 SetPageUptodate(page);
215                 if (rdata->res.eof && count != 0)
216                         memclear_highpage_flush(page, rdata->args.pgbase, count);
217         }
218         result = 0;
219
220 io_error:
221         nfs_readdata_free(rdata);
222 out_unlock:
223         unlock_page(page);
224         return result;
225 }
226
227 static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
228                 struct page *page)
229 {
230         LIST_HEAD(one_request);
231         struct nfs_page *new;
232         unsigned int len;
233
234         len = nfs_page_length(inode, page);
235         if (len == 0)
236                 return nfs_return_empty_page(page);
237         new = nfs_create_request(ctx, inode, page, 0, len);
238         if (IS_ERR(new)) {
239                 unlock_page(page);
240                 return PTR_ERR(new);
241         }
242         if (len < PAGE_CACHE_SIZE)
243                 memclear_highpage_flush(page, len, PAGE_CACHE_SIZE - len);
244
245         nfs_list_add_request(new, &one_request);
246         nfs_pagein_one(&one_request, inode);
247         return 0;
248 }
249
250 static void nfs_readpage_release(struct nfs_page *req)
251 {
252         unlock_page(req->wb_page);
253
254         dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",
255                         req->wb_context->dentry->d_inode->i_sb->s_id,
256                         (long long)NFS_FILEID(req->wb_context->dentry->d_inode),
257                         req->wb_bytes,
258                         (long long)req_offset(req));
259         nfs_clear_request(req);
260         nfs_release_request(req);
261 }
262
263 /*
264  * Set up the NFS read request struct
265  */
266 static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
267                 const struct rpc_call_ops *call_ops,
268                 unsigned int count, unsigned int offset)
269 {
270         struct inode            *inode;
271         int flags;
272
273         data->req         = req;
274         data->inode       = inode = req->wb_context->dentry->d_inode;
275         data->cred        = req->wb_context->cred;
276
277         data->args.fh     = NFS_FH(inode);
278         data->args.offset = req_offset(req) + offset;
279         data->args.pgbase = req->wb_pgbase + offset;
280         data->args.pages  = data->pagevec;
281         data->args.count  = count;
282         data->args.context = req->wb_context;
283
284         data->res.fattr   = &data->fattr;
285         data->res.count   = count;
286         data->res.eof     = 0;
287         nfs_fattr_init(&data->fattr);
288
289         /* Set up the initial task struct. */
290         flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
291         rpc_init_task(&data->task, NFS_CLIENT(inode), flags, call_ops, data);
292         NFS_PROTO(inode)->read_setup(data);
293
294         data->task.tk_cookie = (unsigned long)inode;
295
296         dprintk("NFS: %4d initiated read call (req %s/%Ld, %u bytes @ offset %Lu)\n",
297                         data->task.tk_pid,
298                         inode->i_sb->s_id,
299                         (long long)NFS_FILEID(inode),
300                         count,
301                         (unsigned long long)data->args.offset);
302 }
303
304 static void
305 nfs_async_read_error(struct list_head *head)
306 {
307         struct nfs_page *req;
308
309         while (!list_empty(head)) {
310                 req = nfs_list_entry(head->next);
311                 nfs_list_remove_request(req);
312                 SetPageError(req->wb_page);
313                 nfs_readpage_release(req);
314         }
315 }
316
317 /*
318  * Start an async read operation
319  */
320 static void nfs_execute_read(struct nfs_read_data *data)
321 {
322         struct rpc_clnt *clnt = NFS_CLIENT(data->inode);
323         sigset_t oldset;
324
325         rpc_clnt_sigmask(clnt, &oldset);
326         lock_kernel();
327         rpc_execute(&data->task);
328         unlock_kernel();
329         rpc_clnt_sigunmask(clnt, &oldset);
330 }
331
332 /*
333  * Generate multiple requests to fill a single page.
334  *
335  * We optimize to reduce the number of read operations on the wire.  If we
336  * detect that we're reading a page, or an area of a page, that is past the
337  * end of file, we do not generate NFS read operations but just clear the
338  * parts of the page that would have come back zero from the server anyway.
339  *
340  * We rely on the cached value of i_size to make this determination; another
341  * client can fill pages on the server past our cached end-of-file, but we
342  * won't see the new data until our attribute cache is updated.  This is more
343  * or less conventional NFS client behavior.
344  */
345 static int nfs_pagein_multi(struct list_head *head, struct inode *inode)
346 {
347         struct nfs_page *req = nfs_list_entry(head->next);
348         struct page *page = req->wb_page;
349         struct nfs_read_data *data;
350         size_t rsize = NFS_SERVER(inode)->rsize, nbytes;
351         unsigned int offset;
352         int requests = 0;
353         LIST_HEAD(list);
354
355         nfs_list_remove_request(req);
356
357         nbytes = req->wb_bytes;
358         do {
359                 size_t len = min(nbytes,rsize);
360
361                 data = nfs_readdata_alloc(len);
362                 if (!data)
363                         goto out_bad;
364                 INIT_LIST_HEAD(&data->pages);
365                 list_add(&data->pages, &list);
366                 requests++;
367                 nbytes -= len;
368         } while(nbytes != 0);
369         atomic_set(&req->wb_complete, requests);
370
371         ClearPageError(page);
372         offset = 0;
373         nbytes = req->wb_bytes;
374         do {
375                 data = list_entry(list.next, struct nfs_read_data, pages);
376                 list_del_init(&data->pages);
377
378                 data->pagevec[0] = page;
379
380                 if (nbytes > rsize) {
381                         nfs_read_rpcsetup(req, data, &nfs_read_partial_ops,
382                                         rsize, offset);
383                         offset += rsize;
384                         nbytes -= rsize;
385                 } else {
386                         nfs_read_rpcsetup(req, data, &nfs_read_partial_ops,
387                                         nbytes, offset);
388                         nbytes = 0;
389                 }
390                 nfs_execute_read(data);
391         } while (nbytes != 0);
392
393         return 0;
394
395 out_bad:
396         while (!list_empty(&list)) {
397                 data = list_entry(list.next, struct nfs_read_data, pages);
398                 list_del(&data->pages);
399                 nfs_readdata_free(data);
400         }
401         SetPageError(page);
402         nfs_readpage_release(req);
403         return -ENOMEM;
404 }
405
406 static int nfs_pagein_one(struct list_head *head, struct inode *inode)
407 {
408         struct nfs_page         *req;
409         struct page             **pages;
410         struct nfs_read_data    *data;
411         unsigned int            count;
412
413         if (NFS_SERVER(inode)->rsize < PAGE_CACHE_SIZE)
414                 return nfs_pagein_multi(head, inode);
415
416         data = nfs_readdata_alloc(NFS_SERVER(inode)->rsize);
417         if (!data)
418                 goto out_bad;
419
420         INIT_LIST_HEAD(&data->pages);
421         pages = data->pagevec;
422         count = 0;
423         while (!list_empty(head)) {
424                 req = nfs_list_entry(head->next);
425                 nfs_list_remove_request(req);
426                 nfs_list_add_request(req, &data->pages);
427                 ClearPageError(req->wb_page);
428                 *pages++ = req->wb_page;
429                 count += req->wb_bytes;
430         }
431         req = nfs_list_entry(data->pages.next);
432
433         nfs_read_rpcsetup(req, data, &nfs_read_full_ops, count, 0);
434
435         nfs_execute_read(data);
436         return 0;
437 out_bad:
438         nfs_async_read_error(head);
439         return -ENOMEM;
440 }
441
442 static int
443 nfs_pagein_list(struct list_head *head, int rpages)
444 {
445         LIST_HEAD(one_request);
446         struct nfs_page         *req;
447         int                     error = 0;
448         unsigned int            pages = 0;
449
450         while (!list_empty(head)) {
451                 pages += nfs_coalesce_requests(head, &one_request, rpages);
452                 req = nfs_list_entry(one_request.next);
453                 error = nfs_pagein_one(&one_request, req->wb_context->dentry->d_inode);
454                 if (error < 0)
455                         break;
456         }
457         if (error >= 0)
458                 return pages;
459
460         nfs_async_read_error(head);
461         return error;
462 }
463
464 /*
465  * This is the callback from RPC telling us whether a reply was
466  * received or some error occurred (timeout or socket shutdown).
467  */
468 int nfs_readpage_result(struct rpc_task *task, struct nfs_read_data *data)
469 {
470         int status;
471
472         dprintk("%s: %4d, (status %d)\n", __FUNCTION__, task->tk_pid,
473                         task->tk_status);
474
475         status = NFS_PROTO(data->inode)->read_done(task, data);
476         if (status != 0)
477                 return status;
478
479         nfs_add_stats(data->inode, NFSIOS_SERVERREADBYTES, data->res.count);
480
481         if (task->tk_status == -ESTALE) {
482                 set_bit(NFS_INO_STALE, &NFS_FLAGS(data->inode));
483                 nfs_mark_for_revalidate(data->inode);
484         }
485         spin_lock(&data->inode->i_lock);
486         NFS_I(data->inode)->cache_validity |= NFS_INO_INVALID_ATIME;
487         spin_unlock(&data->inode->i_lock);
488         return 0;
489 }
490
491 static int nfs_readpage_retry(struct rpc_task *task, struct nfs_read_data *data)
492 {
493         struct nfs_readargs *argp = &data->args;
494         struct nfs_readres *resp = &data->res;
495
496         if (resp->eof || resp->count == argp->count)
497                 return 0;
498
499         /* This is a short read! */
500         nfs_inc_stats(data->inode, NFSIOS_SHORTREAD);
501         /* Has the server at least made some progress? */
502         if (resp->count == 0)
503                 return 0;
504
505         /* Yes, so retry the read at the end of the data */
506         argp->offset += resp->count;
507         argp->pgbase += resp->count;
508         argp->count -= resp->count;
509         rpc_restart_call(task);
510         return -EAGAIN;
511 }
512
513 /*
514  * Handle a read reply that fills part of a page.
515  */
516 static void nfs_readpage_result_partial(struct rpc_task *task, void *calldata)
517 {
518         struct nfs_read_data *data = calldata;
519         struct nfs_page *req = data->req;
520         struct page *page = req->wb_page;
521  
522         if (nfs_readpage_result(task, data) != 0)
523                 return;
524
525         if (likely(task->tk_status >= 0)) {
526                 nfs_readpage_truncate_uninitialised_page(data);
527                 if (nfs_readpage_retry(task, data) != 0)
528                         return;
529         }
530         if (unlikely(task->tk_status < 0))
531                 SetPageError(page);
532         if (atomic_dec_and_test(&req->wb_complete)) {
533                 if (!PageError(page))
534                         SetPageUptodate(page);
535                 nfs_readpage_release(req);
536         }
537 }
538
539 static const struct rpc_call_ops nfs_read_partial_ops = {
540         .rpc_call_done = nfs_readpage_result_partial,
541         .rpc_release = nfs_readdata_release,
542 };
543
544 static void nfs_readpage_set_pages_uptodate(struct nfs_read_data *data)
545 {
546         unsigned int count = data->res.count;
547         unsigned int base = data->args.pgbase;
548         struct page **pages;
549
550         if (data->res.eof)
551                 count = data->args.count;
552         if (unlikely(count == 0))
553                 return;
554         pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
555         base &= ~PAGE_CACHE_MASK;
556         count += base;
557         for (;count >= PAGE_CACHE_SIZE; count -= PAGE_CACHE_SIZE, pages++)
558                 SetPageUptodate(*pages);
559         if (count == 0)
560                 return;
561         /* Was this a short read? */
562         if (data->res.eof || data->res.count == data->args.count)
563                 SetPageUptodate(*pages);
564 }
565
566 /*
567  * This is the callback from RPC telling us whether a reply was
568  * received or some error occurred (timeout or socket shutdown).
569  */
570 static void nfs_readpage_result_full(struct rpc_task *task, void *calldata)
571 {
572         struct nfs_read_data *data = calldata;
573
574         if (nfs_readpage_result(task, data) != 0)
575                 return;
576         /*
577          * Note: nfs_readpage_retry may change the values of
578          * data->args. In the multi-page case, we therefore need
579          * to ensure that we call nfs_readpage_set_pages_uptodate()
580          * first.
581          */
582         if (likely(task->tk_status >= 0)) {
583                 nfs_readpage_truncate_uninitialised_page(data);
584                 nfs_readpage_set_pages_uptodate(data);
585                 if (nfs_readpage_retry(task, data) != 0)
586                         return;
587         }
588         while (!list_empty(&data->pages)) {
589                 struct nfs_page *req = nfs_list_entry(data->pages.next);
590
591                 nfs_list_remove_request(req);
592                 nfs_readpage_release(req);
593         }
594 }
595
596 static const struct rpc_call_ops nfs_read_full_ops = {
597         .rpc_call_done = nfs_readpage_result_full,
598         .rpc_release = nfs_readdata_release,
599 };
600
601 /*
602  * Read a page over NFS.
603  * We read the page synchronously in the following case:
604  *  -   The error flag is set for this page. This happens only when a
605  *      previous async read operation failed.
606  */
607 int nfs_readpage(struct file *file, struct page *page)
608 {
609         struct nfs_open_context *ctx;
610         struct inode *inode = page->mapping->host;
611         int             error;
612
613         dprintk("NFS: nfs_readpage (%p %ld@%lu)\n",
614                 page, PAGE_CACHE_SIZE, page->index);
615         nfs_inc_stats(inode, NFSIOS_VFSREADPAGE);
616         nfs_add_stats(inode, NFSIOS_READPAGES, 1);
617
618         /*
619          * Try to flush any pending writes to the file..
620          *
621          * NOTE! Because we own the page lock, there cannot
622          * be any new pending writes generated at this point
623          * for this page (other pages can be written to).
624          */
625         error = nfs_wb_page(inode, page);
626         if (error)
627                 goto out_error;
628
629         error = -ESTALE;
630         if (NFS_STALE(inode))
631                 goto out_error;
632
633         if (file == NULL) {
634                 error = -EBADF;
635                 ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
636                 if (ctx == NULL)
637                         goto out_error;
638         } else
639                 ctx = get_nfs_open_context((struct nfs_open_context *)
640                                 file->private_data);
641         if (!IS_SYNC(inode)) {
642                 error = nfs_readpage_async(ctx, inode, page);
643                 goto out;
644         }
645
646         error = nfs_readpage_sync(ctx, inode, page);
647         if (error < 0 && IS_SWAPFILE(inode))
648                 printk("Aiee.. nfs swap-in of page failed!\n");
649 out:
650         put_nfs_open_context(ctx);
651         return error;
652
653 out_error:
654         unlock_page(page);
655         return error;
656 }
657
658 struct nfs_readdesc {
659         struct list_head *head;
660         struct nfs_open_context *ctx;
661 };
662
663 static int
664 readpage_async_filler(void *data, struct page *page)
665 {
666         struct nfs_readdesc *desc = (struct nfs_readdesc *)data;
667         struct inode *inode = page->mapping->host;
668         struct nfs_page *new;
669         unsigned int len;
670
671         nfs_wb_page(inode, page);
672         len = nfs_page_length(inode, page);
673         if (len == 0)
674                 return nfs_return_empty_page(page);
675         new = nfs_create_request(desc->ctx, inode, page, 0, len);
676         if (IS_ERR(new)) {
677                         SetPageError(page);
678                         unlock_page(page);
679                         return PTR_ERR(new);
680         }
681         if (len < PAGE_CACHE_SIZE)
682                 memclear_highpage_flush(page, len, PAGE_CACHE_SIZE - len);
683         nfs_list_add_request(new, desc->head);
684         return 0;
685 }
686
687 int nfs_readpages(struct file *filp, struct address_space *mapping,
688                 struct list_head *pages, unsigned nr_pages)
689 {
690         LIST_HEAD(head);
691         struct nfs_readdesc desc = {
692                 .head           = &head,
693         };
694         struct inode *inode = mapping->host;
695         struct nfs_server *server = NFS_SERVER(inode);
696         int ret = -ESTALE;
697
698         dprintk("NFS: nfs_readpages (%s/%Ld %d)\n",
699                         inode->i_sb->s_id,
700                         (long long)NFS_FILEID(inode),
701                         nr_pages);
702         nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
703
704         if (NFS_STALE(inode))
705                 goto out;
706
707         if (filp == NULL) {
708                 desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
709                 if (desc.ctx == NULL)
710                         return -EBADF;
711         } else
712                 desc.ctx = get_nfs_open_context((struct nfs_open_context *)
713                                 filp->private_data);
714         ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc);
715         if (!list_empty(&head)) {
716                 int err = nfs_pagein_list(&head, server->rpages);
717                 if (!ret)
718                         nfs_add_stats(inode, NFSIOS_READPAGES, err);
719                         ret = err;
720         }
721         put_nfs_open_context(desc.ctx);
722 out:
723         return ret;
724 }
725
726 int __init nfs_init_readpagecache(void)
727 {
728         nfs_rdata_cachep = kmem_cache_create("nfs_read_data",
729                                              sizeof(struct nfs_read_data),
730                                              0, SLAB_HWCACHE_ALIGN,
731                                              NULL, NULL);
732         if (nfs_rdata_cachep == NULL)
733                 return -ENOMEM;
734
735         nfs_rdata_mempool = mempool_create_slab_pool(MIN_POOL_READ,
736                                                      nfs_rdata_cachep);
737         if (nfs_rdata_mempool == NULL)
738                 return -ENOMEM;
739
740         return 0;
741 }
742
743 void nfs_destroy_readpagecache(void)
744 {
745         mempool_destroy(nfs_rdata_mempool);
746         kmem_cache_destroy(nfs_rdata_cachep);
747 }