read.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. #include <linux/time.h>
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/fcntl.h>
  13. #include <linux/stat.h>
  14. #include <linux/mm.h>
  15. #include <linux/slab.h>
  16. #include <linux/pagemap.h>
  17. #include <linux/sunrpc/clnt.h>
  18. #include <linux/nfs_fs.h>
  19. #include <linux/nfs_page.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/module.h>
  22. #include <asm/system.h>
  23. #include "pnfs.h"
  24. #include "nfs4_fs.h"
  25. #include "internal.h"
  26. #include "iostat.h"
  27. #include "fscache.h"
  28. #define NFSDBG_FACILITY NFSDBG_PAGECACHE
  29. static int nfs_pagein_multi(struct inode *, struct list_head *, unsigned int, size_t, int, struct pnfs_layout_segment *);
  30. static int nfs_pagein_one(struct inode *, struct list_head *, unsigned int, size_t, int, struct pnfs_layout_segment *);
  31. static const struct rpc_call_ops nfs_read_partial_ops;
  32. static const struct rpc_call_ops nfs_read_full_ops;
  33. static struct kmem_cache *nfs_rdata_cachep;
  34. static mempool_t *nfs_rdata_mempool;
  35. #define MIN_POOL_READ (32)
  36. struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
  37. {
  38. struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, GFP_KERNEL);
  39. if (p) {
  40. memset(p, 0, sizeof(*p));
  41. INIT_LIST_HEAD(&p->pages);
  42. p->npages = pagecount;
  43. if (pagecount <= ARRAY_SIZE(p->page_array))
  44. p->pagevec = p->page_array;
  45. else {
  46. p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL);
  47. if (!p->pagevec) {
  48. mempool_free(p, nfs_rdata_mempool);
  49. p = NULL;
  50. }
  51. }
  52. }
  53. return p;
  54. }
  55. void nfs_readdata_free(struct nfs_read_data *p)
  56. {
  57. if (p && (p->pagevec != &p->page_array[0]))
  58. kfree(p->pagevec);
  59. mempool_free(p, nfs_rdata_mempool);
  60. }
  61. static void nfs_readdata_release(struct nfs_read_data *rdata)
  62. {
  63. put_lseg(rdata->lseg);
  64. put_nfs_open_context(rdata->args.context);
  65. nfs_readdata_free(rdata);
  66. }
  67. static
  68. int nfs_return_empty_page(struct page *page)
  69. {
  70. zero_user(page, 0, PAGE_CACHE_SIZE);
  71. SetPageUptodate(page);
  72. unlock_page(page);
  73. return 0;
  74. }
  75. static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data)
  76. {
  77. unsigned int remainder = data->args.count - data->res.count;
  78. unsigned int base = data->args.pgbase + data->res.count;
  79. unsigned int pglen;
  80. struct page **pages;
  81. if (data->res.eof == 0 || remainder == 0)
  82. return;
  83. /*
  84. * Note: "remainder" can never be negative, since we check for
  85. * this in the XDR code.
  86. */
  87. pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
  88. base &= ~PAGE_CACHE_MASK;
  89. pglen = PAGE_CACHE_SIZE - base;
  90. for (;;) {
  91. if (remainder <= pglen) {
  92. zero_user(*pages, base, remainder);
  93. break;
  94. }
  95. zero_user(*pages, base, pglen);
  96. pages++;
  97. remainder -= pglen;
  98. pglen = PAGE_CACHE_SIZE;
  99. base = 0;
  100. }
  101. }
  102. int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
  103. struct page *page)
  104. {
  105. LIST_HEAD(one_request);
  106. struct nfs_page *new;
  107. unsigned int len;
  108. len = nfs_page_length(page);
  109. if (len == 0)
  110. return nfs_return_empty_page(page);
  111. new = nfs_create_request(ctx, inode, page, 0, len);
  112. if (IS_ERR(new)) {
  113. unlock_page(page);
  114. return PTR_ERR(new);
  115. }
  116. if (len < PAGE_CACHE_SIZE)
  117. zero_user_segment(page, len, PAGE_CACHE_SIZE);
  118. nfs_list_add_request(new, &one_request);
  119. if (NFS_SERVER(inode)->rsize < PAGE_CACHE_SIZE)
  120. nfs_pagein_multi(inode, &one_request, 1, len, 0, NULL);
  121. else
  122. nfs_pagein_one(inode, &one_request, 1, len, 0, NULL);
  123. return 0;
  124. }
  125. static void nfs_readpage_release(struct nfs_page *req)
  126. {
  127. struct inode *d_inode = req->wb_context->path.dentry->d_inode;
  128. if (PageUptodate(req->wb_page))
  129. nfs_readpage_to_fscache(d_inode, req->wb_page, 0);
  130. unlock_page(req->wb_page);
  131. dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",
  132. req->wb_context->path.dentry->d_inode->i_sb->s_id,
  133. (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
  134. req->wb_bytes,
  135. (long long)req_offset(req));
  136. nfs_release_request(req);
  137. }
  138. int nfs_initiate_read(struct nfs_read_data *data, struct rpc_clnt *clnt,
  139. const struct rpc_call_ops *call_ops)
  140. {
  141. struct inode *inode = data->inode;
  142. int swap_flags = IS_SWAPFILE(inode) ? NFS_RPC_SWAPFLAGS : 0;
  143. struct rpc_task *task;
  144. struct rpc_message msg = {
  145. .rpc_argp = &data->args,
  146. .rpc_resp = &data->res,
  147. .rpc_cred = data->cred,
  148. };
  149. struct rpc_task_setup task_setup_data = {
  150. .task = &data->task,
  151. .rpc_client = clnt,
  152. .rpc_message = &msg,
  153. .callback_ops = call_ops,
  154. .callback_data = data,
  155. .workqueue = nfsiod_workqueue,
  156. .flags = RPC_TASK_ASYNC | swap_flags,
  157. };
  158. /* Set up the initial task struct. */
  159. NFS_PROTO(inode)->read_setup(data, &msg);
  160. dprintk("NFS: %5u initiated read call (req %s/%lld, %u bytes @ "
  161. "offset %llu)\n",
  162. data->task.tk_pid,
  163. inode->i_sb->s_id,
  164. (long long)NFS_FILEID(inode),
  165. data->args.count,
  166. (unsigned long long)data->args.offset);
  167. task = rpc_run_task(&task_setup_data);
  168. if (IS_ERR(task))
  169. return PTR_ERR(task);
  170. rpc_put_task(task);
  171. return 0;
  172. }
  173. EXPORT_SYMBOL_GPL(nfs_initiate_read);
  174. /*
  175. * Set up the NFS read request struct
  176. */
  177. static int nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
  178. const struct rpc_call_ops *call_ops,
  179. unsigned int count, unsigned int offset,
  180. struct pnfs_layout_segment *lseg)
  181. {
  182. struct inode *inode = req->wb_context->path.dentry->d_inode;
  183. data->req = req;
  184. data->inode = inode;
  185. data->cred = req->wb_context->cred;
  186. data->lseg = get_lseg(lseg);
  187. data->args.fh = NFS_FH(inode);
  188. data->args.offset = req_offset(req) + offset;
  189. data->args.pgbase = req->wb_pgbase + offset;
  190. data->args.pages = data->pagevec;
  191. data->args.count = count;
  192. data->args.context = get_nfs_open_context(req->wb_context);
  193. data->args.lock_context = req->wb_lock_context;
  194. data->res.fattr = &data->fattr;
  195. data->res.count = count;
  196. data->res.eof = 0;
  197. nfs_fattr_init(&data->fattr);
  198. if (data->lseg &&
  199. (pnfs_try_to_read_data(data, call_ops) == PNFS_ATTEMPTED))
  200. return 0;
  201. return nfs_initiate_read(data, NFS_CLIENT(inode), call_ops);
  202. }
  203. static void
  204. nfs_async_read_error(struct list_head *head)
  205. {
  206. struct nfs_page *req;
  207. while (!list_empty(head)) {
  208. req = nfs_list_entry(head->next);
  209. nfs_list_remove_request(req);
  210. SetPageError(req->wb_page);
  211. nfs_readpage_release(req);
  212. }
  213. }
  214. /*
  215. * Generate multiple requests to fill a single page.
  216. *
  217. * We optimize to reduce the number of read operations on the wire. If we
  218. * detect that we're reading a page, or an area of a page, that is past the
  219. * end of file, we do not generate NFS read operations but just clear the
  220. * parts of the page that would have come back zero from the server anyway.
  221. *
  222. * We rely on the cached value of i_size to make this determination; another
  223. * client can fill pages on the server past our cached end-of-file, but we
  224. * won't see the new data until our attribute cache is updated. This is more
  225. * or less conventional NFS client behavior.
  226. */
  227. static int nfs_pagein_multi(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int flags, struct pnfs_layout_segment *lseg)
  228. {
  229. struct nfs_page *req = nfs_list_entry(head->next);
  230. struct page *page = req->wb_page;
  231. struct nfs_read_data *data;
  232. size_t rsize = NFS_SERVER(inode)->rsize, nbytes;
  233. unsigned int offset;
  234. int requests = 0;
  235. int ret = 0;
  236. LIST_HEAD(list);
  237. nfs_list_remove_request(req);
  238. nbytes = count;
  239. do {
  240. size_t len = min(nbytes,rsize);
  241. data = nfs_readdata_alloc(1);
  242. if (!data)
  243. goto out_bad;
  244. list_add(&data->pages, &list);
  245. requests++;
  246. nbytes -= len;
  247. } while(nbytes != 0);
  248. atomic_set(&req->wb_complete, requests);
  249. /* We know lseg==NULL */
  250. lseg = pnfs_update_layout(inode, req->wb_context, IOMODE_READ);
  251. ClearPageError(page);
  252. offset = 0;
  253. nbytes = count;
  254. do {
  255. int ret2;
  256. data = list_entry(list.next, struct nfs_read_data, pages);
  257. list_del_init(&data->pages);
  258. data->pagevec[0] = page;
  259. if (nbytes < rsize)
  260. rsize = nbytes;
  261. ret2 = nfs_read_rpcsetup(req, data, &nfs_read_partial_ops,
  262. rsize, offset, lseg);
  263. if (ret == 0)
  264. ret = ret2;
  265. offset += rsize;
  266. nbytes -= rsize;
  267. } while (nbytes != 0);
  268. put_lseg(lseg);
  269. return ret;
  270. out_bad:
  271. while (!list_empty(&list)) {
  272. data = list_entry(list.next, struct nfs_read_data, pages);
  273. list_del(&data->pages);
  274. nfs_readdata_free(data);
  275. }
  276. SetPageError(page);
  277. nfs_readpage_release(req);
  278. return -ENOMEM;
  279. }
  280. static int nfs_pagein_one(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int flags, struct pnfs_layout_segment *lseg)
  281. {
  282. struct nfs_page *req;
  283. struct page **pages;
  284. struct nfs_read_data *data;
  285. int ret = -ENOMEM;
  286. data = nfs_readdata_alloc(npages);
  287. if (!data) {
  288. nfs_async_read_error(head);
  289. goto out;
  290. }
  291. pages = data->pagevec;
  292. while (!list_empty(head)) {
  293. req = nfs_list_entry(head->next);
  294. nfs_list_remove_request(req);
  295. nfs_list_add_request(req, &data->pages);
  296. ClearPageError(req->wb_page);
  297. *pages++ = req->wb_page;
  298. }
  299. req = nfs_list_entry(data->pages.next);
  300. if ((!lseg) && list_is_singular(&data->pages))
  301. lseg = pnfs_update_layout(inode, req->wb_context, IOMODE_READ);
  302. ret = nfs_read_rpcsetup(req, data, &nfs_read_full_ops, count, 0, lseg);
  303. out:
  304. put_lseg(lseg);
  305. return ret;
  306. }
  307. /*
  308. * This is the callback from RPC telling us whether a reply was
  309. * received or some error occurred (timeout or socket shutdown).
  310. */
  311. int nfs_readpage_result(struct rpc_task *task, struct nfs_read_data *data)
  312. {
  313. int status;
  314. dprintk("NFS: %s: %5u, (status %d)\n", __func__, task->tk_pid,
  315. task->tk_status);
  316. status = NFS_PROTO(data->inode)->read_done(task, data);
  317. if (status != 0)
  318. return status;
  319. nfs_add_stats(data->inode, NFSIOS_SERVERREADBYTES, data->res.count);
  320. if (task->tk_status == -ESTALE) {
  321. set_bit(NFS_INO_STALE, &NFS_I(data->inode)->flags);
  322. nfs_mark_for_revalidate(data->inode);
  323. }
  324. return 0;
  325. }
  326. static void nfs_readpage_retry(struct rpc_task *task, struct nfs_read_data *data)
  327. {
  328. struct nfs_readargs *argp = &data->args;
  329. struct nfs_readres *resp = &data->res;
  330. if (resp->eof || resp->count == argp->count)
  331. return;
  332. /* This is a short read! */
  333. nfs_inc_stats(data->inode, NFSIOS_SHORTREAD);
  334. /* Has the server at least made some progress? */
  335. if (resp->count == 0)
  336. return;
  337. /* Yes, so retry the read at the end of the data */
  338. argp->offset += resp->count;
  339. argp->pgbase += resp->count;
  340. argp->count -= resp->count;
  341. nfs_restart_rpc(task, NFS_SERVER(data->inode)->nfs_client);
  342. }
  343. /*
  344. * Handle a read reply that fills part of a page.
  345. */
  346. static void nfs_readpage_result_partial(struct rpc_task *task, void *calldata)
  347. {
  348. struct nfs_read_data *data = calldata;
  349. if (nfs_readpage_result(task, data) != 0)
  350. return;
  351. if (task->tk_status < 0)
  352. return;
  353. nfs_readpage_truncate_uninitialised_page(data);
  354. nfs_readpage_retry(task, data);
  355. }
  356. static void nfs_readpage_release_partial(void *calldata)
  357. {
  358. struct nfs_read_data *data = calldata;
  359. struct nfs_page *req = data->req;
  360. struct page *page = req->wb_page;
  361. int status = data->task.tk_status;
  362. if (status < 0)
  363. SetPageError(page);
  364. if (atomic_dec_and_test(&req->wb_complete)) {
  365. if (!PageError(page))
  366. SetPageUptodate(page);
  367. nfs_readpage_release(req);
  368. }
  369. nfs_readdata_release(calldata);
  370. }
  371. #if defined(CONFIG_NFS_V4_1)
  372. void nfs_read_prepare(struct rpc_task *task, void *calldata)
  373. {
  374. struct nfs_read_data *data = calldata;
  375. if (nfs4_setup_sequence(NFS_SERVER(data->inode),
  376. &data->args.seq_args, &data->res.seq_res,
  377. 0, task))
  378. return;
  379. rpc_call_start(task);
  380. }
  381. #endif /* CONFIG_NFS_V4_1 */
  382. static const struct rpc_call_ops nfs_read_partial_ops = {
  383. #if defined(CONFIG_NFS_V4_1)
  384. .rpc_call_prepare = nfs_read_prepare,
  385. #endif /* CONFIG_NFS_V4_1 */
  386. .rpc_call_done = nfs_readpage_result_partial,
  387. .rpc_release = nfs_readpage_release_partial,
  388. };
  389. static void nfs_readpage_set_pages_uptodate(struct nfs_read_data *data)
  390. {
  391. unsigned int count = data->res.count;
  392. unsigned int base = data->args.pgbase;
  393. struct page **pages;
  394. if (data->res.eof)
  395. count = data->args.count;
  396. if (unlikely(count == 0))
  397. return;
  398. pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
  399. base &= ~PAGE_CACHE_MASK;
  400. count += base;
  401. for (;count >= PAGE_CACHE_SIZE; count -= PAGE_CACHE_SIZE, pages++)
  402. SetPageUptodate(*pages);
  403. if (count == 0)
  404. return;
  405. /* Was this a short read? */
  406. if (data->res.eof || data->res.count == data->args.count)
  407. SetPageUptodate(*pages);
  408. }
  409. /*
  410. * This is the callback from RPC telling us whether a reply was
  411. * received or some error occurred (timeout or socket shutdown).
  412. */
  413. static void nfs_readpage_result_full(struct rpc_task *task, void *calldata)
  414. {
  415. struct nfs_read_data *data = calldata;
  416. if (nfs_readpage_result(task, data) != 0)
  417. return;
  418. if (task->tk_status < 0)
  419. return;
  420. /*
  421. * Note: nfs_readpage_retry may change the values of
  422. * data->args. In the multi-page case, we therefore need
  423. * to ensure that we call nfs_readpage_set_pages_uptodate()
  424. * first.
  425. */
  426. nfs_readpage_truncate_uninitialised_page(data);
  427. nfs_readpage_set_pages_uptodate(data);
  428. nfs_readpage_retry(task, data);
  429. }
  430. static void nfs_readpage_release_full(void *calldata)
  431. {
  432. struct nfs_read_data *data = calldata;
  433. while (!list_empty(&data->pages)) {
  434. struct nfs_page *req = nfs_list_entry(data->pages.next);
  435. nfs_list_remove_request(req);
  436. nfs_readpage_release(req);
  437. }
  438. nfs_readdata_release(calldata);
  439. }
  440. static const struct rpc_call_ops nfs_read_full_ops = {
  441. #if defined(CONFIG_NFS_V4_1)
  442. .rpc_call_prepare = nfs_read_prepare,
  443. #endif /* CONFIG_NFS_V4_1 */
  444. .rpc_call_done = nfs_readpage_result_full,
  445. .rpc_release = nfs_readpage_release_full,
  446. };
  447. /*
  448. * Read a page over NFS.
  449. * We read the page synchronously in the following case:
  450. * - The error flag is set for this page. This happens only when a
  451. * previous async read operation failed.
  452. */
  453. int nfs_readpage(struct file *file, struct page *page)
  454. {
  455. struct nfs_open_context *ctx;
  456. struct inode *inode = page->mapping->host;
  457. int error;
  458. dprintk("NFS: nfs_readpage (%p %ld@%lu)\n",
  459. page, PAGE_CACHE_SIZE, page->index);
  460. nfs_inc_stats(inode, NFSIOS_VFSREADPAGE);
  461. nfs_add_stats(inode, NFSIOS_READPAGES, 1);
  462. /*
  463. * Try to flush any pending writes to the file..
  464. *
  465. * NOTE! Because we own the page lock, there cannot
  466. * be any new pending writes generated at this point
  467. * for this page (other pages can be written to).
  468. */
  469. error = nfs_wb_page(inode, page);
  470. if (error)
  471. goto out_unlock;
  472. if (PageUptodate(page))
  473. goto out_unlock;
  474. error = -ESTALE;
  475. if (NFS_STALE(inode))
  476. goto out_unlock;
  477. if (file == NULL) {
  478. error = -EBADF;
  479. ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
  480. if (ctx == NULL)
  481. goto out_unlock;
  482. } else
  483. ctx = get_nfs_open_context(nfs_file_open_context(file));
  484. if (!IS_SYNC(inode)) {
  485. error = nfs_readpage_from_fscache(ctx, inode, page);
  486. if (error == 0)
  487. goto out;
  488. }
  489. error = nfs_readpage_async(ctx, inode, page);
  490. out:
  491. put_nfs_open_context(ctx);
  492. return error;
  493. out_unlock:
  494. unlock_page(page);
  495. return error;
  496. }
  497. struct nfs_readdesc {
  498. struct nfs_pageio_descriptor *pgio;
  499. struct nfs_open_context *ctx;
  500. };
  501. static int
  502. readpage_async_filler(void *data, struct page *page)
  503. {
  504. struct nfs_readdesc *desc = (struct nfs_readdesc *)data;
  505. struct inode *inode = page->mapping->host;
  506. struct nfs_page *new;
  507. unsigned int len;
  508. int error;
  509. len = nfs_page_length(page);
  510. if (len == 0)
  511. return nfs_return_empty_page(page);
  512. new = nfs_create_request(desc->ctx, inode, page, 0, len);
  513. if (IS_ERR(new))
  514. goto out_error;
  515. if (len < PAGE_CACHE_SIZE)
  516. zero_user_segment(page, len, PAGE_CACHE_SIZE);
  517. if (!nfs_pageio_add_request(desc->pgio, new)) {
  518. error = desc->pgio->pg_error;
  519. goto out_unlock;
  520. }
  521. return 0;
  522. out_error:
  523. error = PTR_ERR(new);
  524. SetPageError(page);
  525. out_unlock:
  526. unlock_page(page);
  527. return error;
  528. }
  529. int nfs_readpages(struct file *filp, struct address_space *mapping,
  530. struct list_head *pages, unsigned nr_pages)
  531. {
  532. struct nfs_pageio_descriptor pgio;
  533. struct nfs_readdesc desc = {
  534. .pgio = &pgio,
  535. };
  536. struct inode *inode = mapping->host;
  537. struct nfs_server *server = NFS_SERVER(inode);
  538. size_t rsize = server->rsize;
  539. unsigned long npages;
  540. int ret = -ESTALE;
  541. dprintk("NFS: nfs_readpages (%s/%Ld %d)\n",
  542. inode->i_sb->s_id,
  543. (long long)NFS_FILEID(inode),
  544. nr_pages);
  545. nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
  546. if (NFS_STALE(inode))
  547. goto out;
  548. if (filp == NULL) {
  549. desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
  550. if (desc.ctx == NULL)
  551. return -EBADF;
  552. } else
  553. desc.ctx = get_nfs_open_context(nfs_file_open_context(filp));
  554. /* attempt to read as many of the pages as possible from the cache
  555. * - this returns -ENOBUFS immediately if the cookie is negative
  556. */
  557. ret = nfs_readpages_from_fscache(desc.ctx, inode, mapping,
  558. pages, &nr_pages);
  559. if (ret == 0)
  560. goto read_complete; /* all pages were read */
  561. pnfs_pageio_init_read(&pgio, inode);
  562. if (rsize < PAGE_CACHE_SIZE)
  563. nfs_pageio_init(&pgio, inode, nfs_pagein_multi, rsize, 0);
  564. else
  565. nfs_pageio_init(&pgio, inode, nfs_pagein_one, rsize, 0);
  566. ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc);
  567. nfs_pageio_complete(&pgio);
  568. npages = (pgio.pg_bytes_written + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
  569. nfs_add_stats(inode, NFSIOS_READPAGES, npages);
  570. read_complete:
  571. put_nfs_open_context(desc.ctx);
  572. out:
  573. return ret;
  574. }
  575. int __init nfs_init_readpagecache(void)
  576. {
  577. nfs_rdata_cachep = kmem_cache_create("nfs_read_data",
  578. sizeof(struct nfs_read_data),
  579. 0, SLAB_HWCACHE_ALIGN,
  580. NULL);
  581. if (nfs_rdata_cachep == NULL)
  582. return -ENOMEM;
  583. nfs_rdata_mempool = mempool_create_slab_pool(MIN_POOL_READ,
  584. nfs_rdata_cachep);
  585. if (nfs_rdata_mempool == NULL)
  586. return -ENOMEM;
  587. return 0;
  588. }
  589. void nfs_destroy_readpagecache(void)
  590. {
  591. mempool_destroy(nfs_rdata_mempool);
  592. kmem_cache_destroy(nfs_rdata_cachep);
  593. }