read.c 17 KB

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