read.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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. static 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. /*
  174. * Set up the NFS read request struct
  175. */
  176. static int nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
  177. const struct rpc_call_ops *call_ops,
  178. unsigned int count, unsigned int offset,
  179. struct pnfs_layout_segment *lseg)
  180. {
  181. struct inode *inode = req->wb_context->path.dentry->d_inode;
  182. data->req = req;
  183. data->inode = inode;
  184. data->cred = req->wb_context->cred;
  185. data->lseg = get_lseg(lseg);
  186. data->args.fh = NFS_FH(inode);
  187. data->args.offset = req_offset(req) + offset;
  188. data->args.pgbase = req->wb_pgbase + offset;
  189. data->args.pages = data->pagevec;
  190. data->args.count = count;
  191. data->args.context = get_nfs_open_context(req->wb_context);
  192. data->args.lock_context = req->wb_lock_context;
  193. data->res.fattr = &data->fattr;
  194. data->res.count = count;
  195. data->res.eof = 0;
  196. nfs_fattr_init(&data->fattr);
  197. if (data->lseg &&
  198. (pnfs_try_to_read_data(data, call_ops) == PNFS_ATTEMPTED))
  199. return 0;
  200. return nfs_initiate_read(data, NFS_CLIENT(inode), call_ops);
  201. }
  202. static void
  203. nfs_async_read_error(struct list_head *head)
  204. {
  205. struct nfs_page *req;
  206. while (!list_empty(head)) {
  207. req = nfs_list_entry(head->next);
  208. nfs_list_remove_request(req);
  209. SetPageError(req->wb_page);
  210. nfs_readpage_release(req);
  211. }
  212. }
  213. /*
  214. * Generate multiple requests to fill a single page.
  215. *
  216. * We optimize to reduce the number of read operations on the wire. If we
  217. * detect that we're reading a page, or an area of a page, that is past the
  218. * end of file, we do not generate NFS read operations but just clear the
  219. * parts of the page that would have come back zero from the server anyway.
  220. *
  221. * We rely on the cached value of i_size to make this determination; another
  222. * client can fill pages on the server past our cached end-of-file, but we
  223. * won't see the new data until our attribute cache is updated. This is more
  224. * or less conventional NFS client behavior.
  225. */
  226. 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)
  227. {
  228. struct nfs_page *req = nfs_list_entry(head->next);
  229. struct page *page = req->wb_page;
  230. struct nfs_read_data *data;
  231. size_t rsize = NFS_SERVER(inode)->rsize, nbytes;
  232. unsigned int offset;
  233. int requests = 0;
  234. int ret = 0;
  235. LIST_HEAD(list);
  236. nfs_list_remove_request(req);
  237. nbytes = count;
  238. do {
  239. size_t len = min(nbytes,rsize);
  240. data = nfs_readdata_alloc(1);
  241. if (!data)
  242. goto out_bad;
  243. list_add(&data->pages, &list);
  244. requests++;
  245. nbytes -= len;
  246. } while(nbytes != 0);
  247. atomic_set(&req->wb_complete, requests);
  248. /* We know lseg==NULL */
  249. lseg = pnfs_update_layout(inode, req->wb_context, IOMODE_READ);
  250. ClearPageError(page);
  251. offset = 0;
  252. nbytes = count;
  253. do {
  254. int ret2;
  255. data = list_entry(list.next, struct nfs_read_data, pages);
  256. list_del_init(&data->pages);
  257. data->pagevec[0] = page;
  258. if (nbytes < rsize)
  259. rsize = nbytes;
  260. ret2 = nfs_read_rpcsetup(req, data, &nfs_read_partial_ops,
  261. rsize, offset, lseg);
  262. if (ret == 0)
  263. ret = ret2;
  264. offset += rsize;
  265. nbytes -= rsize;
  266. } while (nbytes != 0);
  267. put_lseg(lseg);
  268. return ret;
  269. out_bad:
  270. while (!list_empty(&list)) {
  271. data = list_entry(list.next, struct nfs_read_data, pages);
  272. list_del(&data->pages);
  273. nfs_readdata_free(data);
  274. }
  275. SetPageError(page);
  276. nfs_readpage_release(req);
  277. return -ENOMEM;
  278. }
  279. 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)
  280. {
  281. struct nfs_page *req;
  282. struct page **pages;
  283. struct nfs_read_data *data;
  284. int ret = -ENOMEM;
  285. data = nfs_readdata_alloc(npages);
  286. if (!data) {
  287. nfs_async_read_error(head);
  288. goto out;
  289. }
  290. pages = data->pagevec;
  291. while (!list_empty(head)) {
  292. req = nfs_list_entry(head->next);
  293. nfs_list_remove_request(req);
  294. nfs_list_add_request(req, &data->pages);
  295. ClearPageError(req->wb_page);
  296. *pages++ = req->wb_page;
  297. }
  298. req = nfs_list_entry(data->pages.next);
  299. if ((!lseg) && list_is_singular(&data->pages))
  300. lseg = pnfs_update_layout(inode, req->wb_context, IOMODE_READ);
  301. ret = nfs_read_rpcsetup(req, data, &nfs_read_full_ops, count, 0, lseg);
  302. out:
  303. put_lseg(lseg);
  304. return ret;
  305. }
  306. /*
  307. * This is the callback from RPC telling us whether a reply was
  308. * received or some error occurred (timeout or socket shutdown).
  309. */
  310. int nfs_readpage_result(struct rpc_task *task, struct nfs_read_data *data)
  311. {
  312. int status;
  313. dprintk("NFS: %s: %5u, (status %d)\n", __func__, task->tk_pid,
  314. task->tk_status);
  315. status = NFS_PROTO(data->inode)->read_done(task, data);
  316. if (status != 0)
  317. return status;
  318. nfs_add_stats(data->inode, NFSIOS_SERVERREADBYTES, data->res.count);
  319. if (task->tk_status == -ESTALE) {
  320. set_bit(NFS_INO_STALE, &NFS_I(data->inode)->flags);
  321. nfs_mark_for_revalidate(data->inode);
  322. }
  323. return 0;
  324. }
  325. static void nfs_readpage_retry(struct rpc_task *task, struct nfs_read_data *data)
  326. {
  327. struct nfs_readargs *argp = &data->args;
  328. struct nfs_readres *resp = &data->res;
  329. if (resp->eof || resp->count == argp->count)
  330. return;
  331. /* This is a short read! */
  332. nfs_inc_stats(data->inode, NFSIOS_SHORTREAD);
  333. /* Has the server at least made some progress? */
  334. if (resp->count == 0)
  335. return;
  336. /* Yes, so retry the read at the end of the data */
  337. argp->offset += resp->count;
  338. argp->pgbase += resp->count;
  339. argp->count -= resp->count;
  340. nfs_restart_rpc(task, NFS_SERVER(data->inode)->nfs_client);
  341. }
  342. /*
  343. * Handle a read reply that fills part of a page.
  344. */
  345. static void nfs_readpage_result_partial(struct rpc_task *task, void *calldata)
  346. {
  347. struct nfs_read_data *data = calldata;
  348. if (nfs_readpage_result(task, data) != 0)
  349. return;
  350. if (task->tk_status < 0)
  351. return;
  352. nfs_readpage_truncate_uninitialised_page(data);
  353. nfs_readpage_retry(task, data);
  354. }
  355. static void nfs_readpage_release_partial(void *calldata)
  356. {
  357. struct nfs_read_data *data = calldata;
  358. struct nfs_page *req = data->req;
  359. struct page *page = req->wb_page;
  360. int status = data->task.tk_status;
  361. if (status < 0)
  362. SetPageError(page);
  363. if (atomic_dec_and_test(&req->wb_complete)) {
  364. if (!PageError(page))
  365. SetPageUptodate(page);
  366. nfs_readpage_release(req);
  367. }
  368. nfs_readdata_release(calldata);
  369. }
  370. #if defined(CONFIG_NFS_V4_1)
  371. void nfs_read_prepare(struct rpc_task *task, void *calldata)
  372. {
  373. struct nfs_read_data *data = calldata;
  374. if (nfs4_setup_sequence(NFS_SERVER(data->inode),
  375. &data->args.seq_args, &data->res.seq_res,
  376. 0, task))
  377. return;
  378. rpc_call_start(task);
  379. }
  380. #endif /* CONFIG_NFS_V4_1 */
  381. static const struct rpc_call_ops nfs_read_partial_ops = {
  382. #if defined(CONFIG_NFS_V4_1)
  383. .rpc_call_prepare = nfs_read_prepare,
  384. #endif /* CONFIG_NFS_V4_1 */
  385. .rpc_call_done = nfs_readpage_result_partial,
  386. .rpc_release = nfs_readpage_release_partial,
  387. };
  388. static void nfs_readpage_set_pages_uptodate(struct nfs_read_data *data)
  389. {
  390. unsigned int count = data->res.count;
  391. unsigned int base = data->args.pgbase;
  392. struct page **pages;
  393. if (data->res.eof)
  394. count = data->args.count;
  395. if (unlikely(count == 0))
  396. return;
  397. pages = &data->args.pages[base >> PAGE_CACHE_SHIFT];
  398. base &= ~PAGE_CACHE_MASK;
  399. count += base;
  400. for (;count >= PAGE_CACHE_SIZE; count -= PAGE_CACHE_SIZE, pages++)
  401. SetPageUptodate(*pages);
  402. if (count == 0)
  403. return;
  404. /* Was this a short read? */
  405. if (data->res.eof || data->res.count == data->args.count)
  406. SetPageUptodate(*pages);
  407. }
  408. /*
  409. * This is the callback from RPC telling us whether a reply was
  410. * received or some error occurred (timeout or socket shutdown).
  411. */
  412. static void nfs_readpage_result_full(struct rpc_task *task, void *calldata)
  413. {
  414. struct nfs_read_data *data = calldata;
  415. if (nfs_readpage_result(task, data) != 0)
  416. return;
  417. if (task->tk_status < 0)
  418. return;
  419. /*
  420. * Note: nfs_readpage_retry may change the values of
  421. * data->args. In the multi-page case, we therefore need
  422. * to ensure that we call nfs_readpage_set_pages_uptodate()
  423. * first.
  424. */
  425. nfs_readpage_truncate_uninitialised_page(data);
  426. nfs_readpage_set_pages_uptodate(data);
  427. nfs_readpage_retry(task, data);
  428. }
  429. static void nfs_readpage_release_full(void *calldata)
  430. {
  431. struct nfs_read_data *data = calldata;
  432. while (!list_empty(&data->pages)) {
  433. struct nfs_page *req = nfs_list_entry(data->pages.next);
  434. nfs_list_remove_request(req);
  435. nfs_readpage_release(req);
  436. }
  437. nfs_readdata_release(calldata);
  438. }
  439. static const struct rpc_call_ops nfs_read_full_ops = {
  440. #if defined(CONFIG_NFS_V4_1)
  441. .rpc_call_prepare = nfs_read_prepare,
  442. #endif /* CONFIG_NFS_V4_1 */
  443. .rpc_call_done = nfs_readpage_result_full,
  444. .rpc_release = nfs_readpage_release_full,
  445. };
  446. /*
  447. * Read a page over NFS.
  448. * We read the page synchronously in the following case:
  449. * - The error flag is set for this page. This happens only when a
  450. * previous async read operation failed.
  451. */
  452. int nfs_readpage(struct file *file, struct page *page)
  453. {
  454. struct nfs_open_context *ctx;
  455. struct inode *inode = page->mapping->host;
  456. int error;
  457. dprintk("NFS: nfs_readpage (%p %ld@%lu)\n",
  458. page, PAGE_CACHE_SIZE, page->index);
  459. nfs_inc_stats(inode, NFSIOS_VFSREADPAGE);
  460. nfs_add_stats(inode, NFSIOS_READPAGES, 1);
  461. /*
  462. * Try to flush any pending writes to the file..
  463. *
  464. * NOTE! Because we own the page lock, there cannot
  465. * be any new pending writes generated at this point
  466. * for this page (other pages can be written to).
  467. */
  468. error = nfs_wb_page(inode, page);
  469. if (error)
  470. goto out_unlock;
  471. if (PageUptodate(page))
  472. goto out_unlock;
  473. error = -ESTALE;
  474. if (NFS_STALE(inode))
  475. goto out_unlock;
  476. if (file == NULL) {
  477. error = -EBADF;
  478. ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
  479. if (ctx == NULL)
  480. goto out_unlock;
  481. } else
  482. ctx = get_nfs_open_context(nfs_file_open_context(file));
  483. if (!IS_SYNC(inode)) {
  484. error = nfs_readpage_from_fscache(ctx, inode, page);
  485. if (error == 0)
  486. goto out;
  487. }
  488. error = nfs_readpage_async(ctx, inode, page);
  489. out:
  490. put_nfs_open_context(ctx);
  491. return error;
  492. out_unlock:
  493. unlock_page(page);
  494. return error;
  495. }
  496. struct nfs_readdesc {
  497. struct nfs_pageio_descriptor *pgio;
  498. struct nfs_open_context *ctx;
  499. };
  500. static int
  501. readpage_async_filler(void *data, struct page *page)
  502. {
  503. struct nfs_readdesc *desc = (struct nfs_readdesc *)data;
  504. struct inode *inode = page->mapping->host;
  505. struct nfs_page *new;
  506. unsigned int len;
  507. int error;
  508. len = nfs_page_length(page);
  509. if (len == 0)
  510. return nfs_return_empty_page(page);
  511. new = nfs_create_request(desc->ctx, inode, page, 0, len);
  512. if (IS_ERR(new))
  513. goto out_error;
  514. if (len < PAGE_CACHE_SIZE)
  515. zero_user_segment(page, len, PAGE_CACHE_SIZE);
  516. if (!nfs_pageio_add_request(desc->pgio, new)) {
  517. error = desc->pgio->pg_error;
  518. goto out_unlock;
  519. }
  520. return 0;
  521. out_error:
  522. error = PTR_ERR(new);
  523. SetPageError(page);
  524. out_unlock:
  525. unlock_page(page);
  526. return error;
  527. }
  528. int nfs_readpages(struct file *filp, struct address_space *mapping,
  529. struct list_head *pages, unsigned nr_pages)
  530. {
  531. struct nfs_pageio_descriptor pgio;
  532. struct nfs_readdesc desc = {
  533. .pgio = &pgio,
  534. };
  535. struct inode *inode = mapping->host;
  536. struct nfs_server *server = NFS_SERVER(inode);
  537. size_t rsize = server->rsize;
  538. unsigned long npages;
  539. int ret = -ESTALE;
  540. dprintk("NFS: nfs_readpages (%s/%Ld %d)\n",
  541. inode->i_sb->s_id,
  542. (long long)NFS_FILEID(inode),
  543. nr_pages);
  544. nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
  545. if (NFS_STALE(inode))
  546. goto out;
  547. if (filp == NULL) {
  548. desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
  549. if (desc.ctx == NULL)
  550. return -EBADF;
  551. } else
  552. desc.ctx = get_nfs_open_context(nfs_file_open_context(filp));
  553. /* attempt to read as many of the pages as possible from the cache
  554. * - this returns -ENOBUFS immediately if the cookie is negative
  555. */
  556. ret = nfs_readpages_from_fscache(desc.ctx, inode, mapping,
  557. pages, &nr_pages);
  558. if (ret == 0)
  559. goto read_complete; /* all pages were read */
  560. pnfs_pageio_init_read(&pgio, inode);
  561. if (rsize < PAGE_CACHE_SIZE)
  562. nfs_pageio_init(&pgio, inode, nfs_pagein_multi, rsize, 0);
  563. else
  564. nfs_pageio_init(&pgio, inode, nfs_pagein_one, rsize, 0);
  565. ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc);
  566. nfs_pageio_complete(&pgio);
  567. npages = (pgio.pg_bytes_written + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
  568. nfs_add_stats(inode, NFSIOS_READPAGES, npages);
  569. read_complete:
  570. put_nfs_open_context(desc.ctx);
  571. out:
  572. return ret;
  573. }
  574. int __init nfs_init_readpagecache(void)
  575. {
  576. nfs_rdata_cachep = kmem_cache_create("nfs_read_data",
  577. sizeof(struct nfs_read_data),
  578. 0, SLAB_HWCACHE_ALIGN,
  579. NULL);
  580. if (nfs_rdata_cachep == NULL)
  581. return -ENOMEM;
  582. nfs_rdata_mempool = mempool_create_slab_pool(MIN_POOL_READ,
  583. nfs_rdata_cachep);
  584. if (nfs_rdata_mempool == NULL)
  585. return -ENOMEM;
  586. return 0;
  587. }
  588. void nfs_destroy_readpagecache(void)
  589. {
  590. mempool_destroy(nfs_rdata_mempool);
  591. kmem_cache_destroy(nfs_rdata_cachep);
  592. }