10 #include <linux/time.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/fcntl.h>
14 #include <linux/stat.h>
16 #include <linux/slab.h>
19 #include <linux/nfs_fs.h>
21 #include <linux/module.h>
28 #define NFSDBG_FACILITY NFSDBG_PAGECACHE
40 rhdr = kmem_cache_zalloc(nfs_rdata_cachep,
GFP_KERNEL);
44 INIT_LIST_HEAD(&hdr->
pages);
54 unsigned int pagecount)
92 if (rdata->
pages.pagevec != rdata->
pages.page_array)
104 int nfs_return_empty_page(
struct page *
page)
107 SetPageUptodate(page);
117 NFS_SERVER(inode)->rsize, 0);
123 pgio->
pg_ops = &nfs_pageio_read_ops;
135 len = nfs_page_length(page);
137 return nfs_return_empty_page(page);
146 NFS_PROTO(inode)->read_pageio_init(&pgio, inode, &nfs_async_read_completion_ops);
153 static void nfs_readpage_release(
struct nfs_page *
req)
157 if (PageUptodate(req->
wb_page))
158 nfs_readpage_to_fscache(d_inode, req->
wb_page, 0);
162 dprintk(
"NFS: read done (%s/%Ld %d@%Ld)\n",
164 (
long long)NFS_FILEID(req->
wb_context->dentry->d_inode),
166 (
long long)req_offset(req));
173 unsigned long bytes = 0;
177 while (!list_empty(&hdr->
pages)) {
185 zero_user_segment(page,
191 if (bytes <= hdr->good_bytes)
192 SetPageUptodate(page);
194 SetPageUptodate(page);
195 nfs_list_remove_request(req);
196 nfs_readpage_release(req);
211 .rpc_resp = &data->
res,
212 .rpc_cred = data->
header->cred,
218 .callback_ops = call_ops,
219 .callback_data =
data,
225 NFS_PROTO(inode)->read_setup(data, &msg);
227 dprintk(
"NFS: %5u initiated read call (req %s/%lld, %u bytes @ "
231 (
long long)NFS_FILEID(inode),
233 (
unsigned long long)data->
args.offset);
237 return PTR_ERR(task);
280 while (!list_empty(head)) {
284 list_del_init(&data->
list);
286 ret2 = nfs_do_read(data, call_ops);
294 nfs_async_read_error(
struct list_head *head)
298 while (!list_empty(head)) {
299 req = nfs_list_entry(head->
next);
300 nfs_list_remove_request(req);
301 nfs_readpage_release(req);
306 .error_cleanup = nfs_async_read_error,
307 .completion = nfs_read_completion,
314 while (!list_empty(&hdr->
rpc_list)) {
340 struct page *page = req->
wb_page;
350 data = nfs_readdata_alloc(hdr, 1);
352 nfs_pagein_error(desc, hdr);
356 nfs_read_rpcsetup(data, len, offset);
362 nfs_list_remove_request(req);
363 nfs_list_add_request(req, &hdr->
pages);
376 data = nfs_readdata_alloc(hdr, nfs_page_array_len(desc->
pg_base,
379 nfs_pagein_error(desc, hdr);
383 pages = data->
pages.pagevec;
384 while (!list_empty(head)) {
385 req = nfs_list_entry(head->
next);
386 nfs_list_remove_request(req);
387 nfs_list_add_request(req, &hdr->
pages);
391 nfs_read_rpcsetup(data, desc->
pg_count, 0);
401 return nfs_pagein_multi(desc, hdr);
402 return nfs_pagein_one(desc, hdr);
422 ret = nfs_do_multiple_reads(&hdr->
rpc_list,
431 .pg_doio = nfs_generic_pg_readpages,
440 struct inode *inode = data->
header->inode;
443 dprintk(
"NFS: %s: %5u, (status %d)\n", __func__, task->tk_pid,
446 status = NFS_PROTO(inode)->read_done(task, data);
454 nfs_mark_for_revalidate(inode);
467 if (resp->
count == 0) {
479 static void nfs_readpage_result_common(
struct rpc_task *task,
void *calldata)
489 else if (data->
res.eof) {
492 bound = data->
args.offset + data->
res.count;
493 spin_lock(&hdr->
lock);
499 spin_unlock(&hdr->
lock);
500 }
else if (data->
res.count != data->
args.count)
501 nfs_readpage_retry(task, data);
504 static void nfs_readpage_release_common(
void *calldata)
512 NFS_PROTO(data->
header->inode)->read_rpc_prepare(task, data);
515 static const struct rpc_call_ops nfs_read_common_ops = {
517 .rpc_call_done = nfs_readpage_result_common,
518 .rpc_release = nfs_readpage_release_common,
530 struct inode *inode = page_file_mapping(page)->host;
533 dprintk(
"NFS: nfs_readpage (%p %ld@%lu)\n",
548 if (PageUptodate(page))
552 if (NFS_STALE(inode))
564 error = nfs_readpage_from_fscache(ctx, inode, page);
585 readpage_async_filler(
void *data,
struct page *page)
588 struct inode *inode = page_file_mapping(page)->host;
593 len = nfs_page_length(page);
595 return nfs_return_empty_page(page);
604 error = desc->
pgio->pg_error;
609 error = PTR_ERR(
new);
616 struct list_head *pages,
unsigned nr_pages)
622 struct inode *inode = mapping->
host;
623 unsigned long npages;
626 dprintk(
"NFS: nfs_readpages (%s/%Ld %d)\n",
628 (
long long)NFS_FILEID(inode),
632 if (NFS_STALE(inode))
645 ret = nfs_readpages_from_fscache(desc.
ctx, inode, mapping,
650 NFS_PROTO(inode)->read_pageio_init(&pgio, inode, &nfs_async_read_completion_ops);
670 if (nfs_rdata_cachep ==
NULL)