filelayout.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. /*
  2. * Module for the pnfs nfs4 file layout driver.
  3. * Defines all I/O and Policy interface operations, plus code
  4. * to register itself with the pNFS client.
  5. *
  6. * Copyright (c) 2002
  7. * The Regents of the University of Michigan
  8. * All Rights Reserved
  9. *
  10. * Dean Hildebrand <dhildebz@umich.edu>
  11. *
  12. * Permission is granted to use, copy, create derivative works, and
  13. * redistribute this software and such derivative works for any purpose,
  14. * so long as the name of the University of Michigan is not used in
  15. * any advertising or publicity pertaining to the use or distribution
  16. * of this software without specific, written prior authorization. If
  17. * the above copyright notice or any other identification of the
  18. * University of Michigan is included in any copy of any portion of
  19. * this software, then the disclaimer below must also be included.
  20. *
  21. * This software is provided as is, without representation or warranty
  22. * of any kind either express or implied, including without limitation
  23. * the implied warranties of merchantability, fitness for a particular
  24. * purpose, or noninfringement. The Regents of the University of
  25. * Michigan shall not be liable for any damages, including special,
  26. * indirect, incidental, or consequential damages, with respect to any
  27. * claim arising out of or in connection with the use of the software,
  28. * even if it has been or is hereafter advised of the possibility of
  29. * such damages.
  30. */
  31. #include <linux/nfs_fs.h>
  32. #include <linux/nfs_page.h>
  33. #include <linux/module.h>
  34. #include <linux/backing-dev.h>
  35. #include <linux/sunrpc/metrics.h>
  36. #include "../nfs4session.h"
  37. #include "../internal.h"
  38. #include "../delegation.h"
  39. #include "filelayout.h"
  40. #include "../nfs4trace.h"
  41. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  42. MODULE_LICENSE("GPL");
  43. MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>");
  44. MODULE_DESCRIPTION("The NFSv4 file layout driver");
  45. #define FILELAYOUT_POLL_RETRY_MAX (15*HZ)
  46. static loff_t
  47. filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg,
  48. loff_t offset)
  49. {
  50. u32 stripe_width = flseg->stripe_unit * flseg->dsaddr->stripe_count;
  51. u64 stripe_no;
  52. u32 rem;
  53. offset -= flseg->pattern_offset;
  54. stripe_no = div_u64(offset, stripe_width);
  55. div_u64_rem(offset, flseg->stripe_unit, &rem);
  56. return stripe_no * flseg->stripe_unit + rem;
  57. }
  58. /* This function is used by the layout driver to calculate the
  59. * offset of the file on the dserver based on whether the
  60. * layout type is STRIPE_DENSE or STRIPE_SPARSE
  61. */
  62. static loff_t
  63. filelayout_get_dserver_offset(struct pnfs_layout_segment *lseg, loff_t offset)
  64. {
  65. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  66. switch (flseg->stripe_type) {
  67. case STRIPE_SPARSE:
  68. return offset;
  69. case STRIPE_DENSE:
  70. return filelayout_get_dense_offset(flseg, offset);
  71. }
  72. BUG();
  73. }
  74. static void filelayout_reset_write(struct nfs_pgio_header *hdr)
  75. {
  76. struct rpc_task *task = &hdr->task;
  77. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
  78. dprintk("%s Reset task %5u for i/o through MDS "
  79. "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
  80. hdr->task.tk_pid,
  81. hdr->inode->i_sb->s_id,
  82. (unsigned long long)NFS_FILEID(hdr->inode),
  83. hdr->args.count,
  84. (unsigned long long)hdr->args.offset);
  85. task->tk_status = pnfs_write_done_resend_to_mds(hdr);
  86. }
  87. }
  88. static void filelayout_reset_read(struct nfs_pgio_header *hdr)
  89. {
  90. struct rpc_task *task = &hdr->task;
  91. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
  92. dprintk("%s Reset task %5u for i/o through MDS "
  93. "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
  94. hdr->task.tk_pid,
  95. hdr->inode->i_sb->s_id,
  96. (unsigned long long)NFS_FILEID(hdr->inode),
  97. hdr->args.count,
  98. (unsigned long long)hdr->args.offset);
  99. task->tk_status = pnfs_read_done_resend_to_mds(hdr);
  100. }
  101. }
  102. static int filelayout_async_handle_error(struct rpc_task *task,
  103. struct nfs4_state *state,
  104. struct nfs_client *clp,
  105. struct pnfs_layout_segment *lseg)
  106. {
  107. struct pnfs_layout_hdr *lo = lseg->pls_layout;
  108. struct inode *inode = lo->plh_inode;
  109. struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg);
  110. struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
  111. if (task->tk_status >= 0)
  112. return 0;
  113. switch (task->tk_status) {
  114. /* DS session errors */
  115. case -NFS4ERR_BADSESSION:
  116. case -NFS4ERR_BADSLOT:
  117. case -NFS4ERR_BAD_HIGH_SLOT:
  118. case -NFS4ERR_DEADSESSION:
  119. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  120. case -NFS4ERR_SEQ_FALSE_RETRY:
  121. case -NFS4ERR_SEQ_MISORDERED:
  122. dprintk("%s ERROR %d, Reset session. Exchangeid "
  123. "flags 0x%x\n", __func__, task->tk_status,
  124. clp->cl_exchange_flags);
  125. nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
  126. break;
  127. case -NFS4ERR_DELAY:
  128. case -NFS4ERR_GRACE:
  129. rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX);
  130. break;
  131. case -NFS4ERR_RETRY_UNCACHED_REP:
  132. break;
  133. /* Invalidate Layout errors */
  134. case -NFS4ERR_ACCESS:
  135. case -NFS4ERR_PNFS_NO_LAYOUT:
  136. case -ESTALE: /* mapped NFS4ERR_STALE */
  137. case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */
  138. case -EISDIR: /* mapped NFS4ERR_ISDIR */
  139. case -NFS4ERR_FHEXPIRED:
  140. case -NFS4ERR_WRONG_TYPE:
  141. dprintk("%s Invalid layout error %d\n", __func__,
  142. task->tk_status);
  143. /*
  144. * Destroy layout so new i/o will get a new layout.
  145. * Layout will not be destroyed until all current lseg
  146. * references are put. Mark layout as invalid to resend failed
  147. * i/o and all i/o waiting on the slot table to the MDS until
  148. * layout is destroyed and a new valid layout is obtained.
  149. */
  150. pnfs_destroy_layout(NFS_I(inode));
  151. rpc_wake_up(&tbl->slot_tbl_waitq);
  152. goto reset;
  153. /* RPC connection errors */
  154. case -ECONNREFUSED:
  155. case -EHOSTDOWN:
  156. case -EHOSTUNREACH:
  157. case -ENETUNREACH:
  158. case -EIO:
  159. case -ETIMEDOUT:
  160. case -EPIPE:
  161. dprintk("%s DS connection error %d\n", __func__,
  162. task->tk_status);
  163. nfs4_mark_deviceid_unavailable(devid);
  164. pnfs_error_mark_layout_for_return(inode, lseg);
  165. pnfs_set_lo_fail(lseg);
  166. rpc_wake_up(&tbl->slot_tbl_waitq);
  167. /* fall through */
  168. default:
  169. reset:
  170. dprintk("%s Retry through MDS. Error %d\n", __func__,
  171. task->tk_status);
  172. return -NFS4ERR_RESET_TO_MDS;
  173. }
  174. task->tk_status = 0;
  175. return -EAGAIN;
  176. }
  177. /* NFS_PROTO call done callback routines */
  178. static int filelayout_read_done_cb(struct rpc_task *task,
  179. struct nfs_pgio_header *hdr)
  180. {
  181. int err;
  182. trace_nfs4_pnfs_read(hdr, task->tk_status);
  183. err = filelayout_async_handle_error(task, hdr->args.context->state,
  184. hdr->ds_clp, hdr->lseg);
  185. switch (err) {
  186. case -NFS4ERR_RESET_TO_MDS:
  187. filelayout_reset_read(hdr);
  188. return task->tk_status;
  189. case -EAGAIN:
  190. rpc_restart_call_prepare(task);
  191. return -EAGAIN;
  192. }
  193. return 0;
  194. }
  195. /*
  196. * We reference the rpc_cred of the first WRITE that triggers the need for
  197. * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
  198. * rfc5661 is not clear about which credential should be used.
  199. */
  200. static void
  201. filelayout_set_layoutcommit(struct nfs_pgio_header *hdr)
  202. {
  203. loff_t end_offs = 0;
  204. if (FILELAYOUT_LSEG(hdr->lseg)->commit_through_mds ||
  205. hdr->res.verf->committed == NFS_FILE_SYNC)
  206. return;
  207. if (hdr->res.verf->committed == NFS_DATA_SYNC)
  208. end_offs = hdr->mds_offset + (loff_t)hdr->res.count;
  209. /* Note: if the write is unstable, don't set end_offs until commit */
  210. pnfs_set_layoutcommit(hdr->inode, hdr->lseg, end_offs);
  211. dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino,
  212. (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb);
  213. }
  214. bool
  215. filelayout_test_devid_unavailable(struct nfs4_deviceid_node *node)
  216. {
  217. return filelayout_test_devid_invalid(node) ||
  218. nfs4_test_deviceid_unavailable(node);
  219. }
  220. static bool
  221. filelayout_reset_to_mds(struct pnfs_layout_segment *lseg)
  222. {
  223. struct nfs4_deviceid_node *node = FILELAYOUT_DEVID_NODE(lseg);
  224. return filelayout_test_devid_unavailable(node);
  225. }
  226. /*
  227. * Call ops for the async read/write cases
  228. * In the case of dense layouts, the offset needs to be reset to its
  229. * original value.
  230. */
  231. static void filelayout_read_prepare(struct rpc_task *task, void *data)
  232. {
  233. struct nfs_pgio_header *hdr = data;
  234. if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
  235. rpc_exit(task, -EIO);
  236. return;
  237. }
  238. if (filelayout_reset_to_mds(hdr->lseg)) {
  239. dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid);
  240. filelayout_reset_read(hdr);
  241. rpc_exit(task, 0);
  242. return;
  243. }
  244. hdr->pgio_done_cb = filelayout_read_done_cb;
  245. if (nfs4_setup_sequence(hdr->ds_clp,
  246. &hdr->args.seq_args,
  247. &hdr->res.seq_res,
  248. task))
  249. return;
  250. if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
  251. hdr->args.lock_context, FMODE_READ) == -EIO)
  252. rpc_exit(task, -EIO); /* lost lock, terminate I/O */
  253. }
  254. static void filelayout_read_call_done(struct rpc_task *task, void *data)
  255. {
  256. struct nfs_pgio_header *hdr = data;
  257. dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
  258. if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
  259. task->tk_status == 0) {
  260. nfs41_sequence_done(task, &hdr->res.seq_res);
  261. return;
  262. }
  263. /* Note this may cause RPC to be resent */
  264. hdr->mds_ops->rpc_call_done(task, data);
  265. }
  266. static void filelayout_read_count_stats(struct rpc_task *task, void *data)
  267. {
  268. struct nfs_pgio_header *hdr = data;
  269. rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics);
  270. }
  271. static int filelayout_write_done_cb(struct rpc_task *task,
  272. struct nfs_pgio_header *hdr)
  273. {
  274. int err;
  275. trace_nfs4_pnfs_write(hdr, task->tk_status);
  276. err = filelayout_async_handle_error(task, hdr->args.context->state,
  277. hdr->ds_clp, hdr->lseg);
  278. switch (err) {
  279. case -NFS4ERR_RESET_TO_MDS:
  280. filelayout_reset_write(hdr);
  281. return task->tk_status;
  282. case -EAGAIN:
  283. rpc_restart_call_prepare(task);
  284. return -EAGAIN;
  285. }
  286. filelayout_set_layoutcommit(hdr);
  287. /* zero out the fattr */
  288. hdr->fattr.valid = 0;
  289. if (task->tk_status >= 0)
  290. nfs_writeback_update_inode(hdr);
  291. return 0;
  292. }
  293. static int filelayout_commit_done_cb(struct rpc_task *task,
  294. struct nfs_commit_data *data)
  295. {
  296. int err;
  297. trace_nfs4_pnfs_commit_ds(data, task->tk_status);
  298. err = filelayout_async_handle_error(task, NULL, data->ds_clp,
  299. data->lseg);
  300. switch (err) {
  301. case -NFS4ERR_RESET_TO_MDS:
  302. pnfs_generic_prepare_to_resend_writes(data);
  303. return -EAGAIN;
  304. case -EAGAIN:
  305. rpc_restart_call_prepare(task);
  306. return -EAGAIN;
  307. }
  308. pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb);
  309. return 0;
  310. }
  311. static void filelayout_write_prepare(struct rpc_task *task, void *data)
  312. {
  313. struct nfs_pgio_header *hdr = data;
  314. if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
  315. rpc_exit(task, -EIO);
  316. return;
  317. }
  318. if (filelayout_reset_to_mds(hdr->lseg)) {
  319. dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid);
  320. filelayout_reset_write(hdr);
  321. rpc_exit(task, 0);
  322. return;
  323. }
  324. if (nfs4_setup_sequence(hdr->ds_clp,
  325. &hdr->args.seq_args,
  326. &hdr->res.seq_res,
  327. task))
  328. return;
  329. if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
  330. hdr->args.lock_context, FMODE_WRITE) == -EIO)
  331. rpc_exit(task, -EIO); /* lost lock, terminate I/O */
  332. }
  333. static void filelayout_write_call_done(struct rpc_task *task, void *data)
  334. {
  335. struct nfs_pgio_header *hdr = data;
  336. if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
  337. task->tk_status == 0) {
  338. nfs41_sequence_done(task, &hdr->res.seq_res);
  339. return;
  340. }
  341. /* Note this may cause RPC to be resent */
  342. hdr->mds_ops->rpc_call_done(task, data);
  343. }
  344. static void filelayout_write_count_stats(struct rpc_task *task, void *data)
  345. {
  346. struct nfs_pgio_header *hdr = data;
  347. rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics);
  348. }
  349. static void filelayout_commit_prepare(struct rpc_task *task, void *data)
  350. {
  351. struct nfs_commit_data *wdata = data;
  352. nfs4_setup_sequence(wdata->ds_clp,
  353. &wdata->args.seq_args,
  354. &wdata->res.seq_res,
  355. task);
  356. }
  357. static void filelayout_commit_count_stats(struct rpc_task *task, void *data)
  358. {
  359. struct nfs_commit_data *cdata = data;
  360. rpc_count_iostats(task, NFS_SERVER(cdata->inode)->client->cl_metrics);
  361. }
  362. static const struct rpc_call_ops filelayout_read_call_ops = {
  363. .rpc_call_prepare = filelayout_read_prepare,
  364. .rpc_call_done = filelayout_read_call_done,
  365. .rpc_count_stats = filelayout_read_count_stats,
  366. .rpc_release = pnfs_generic_rw_release,
  367. };
  368. static const struct rpc_call_ops filelayout_write_call_ops = {
  369. .rpc_call_prepare = filelayout_write_prepare,
  370. .rpc_call_done = filelayout_write_call_done,
  371. .rpc_count_stats = filelayout_write_count_stats,
  372. .rpc_release = pnfs_generic_rw_release,
  373. };
  374. static const struct rpc_call_ops filelayout_commit_call_ops = {
  375. .rpc_call_prepare = filelayout_commit_prepare,
  376. .rpc_call_done = pnfs_generic_write_commit_done,
  377. .rpc_count_stats = filelayout_commit_count_stats,
  378. .rpc_release = pnfs_generic_commit_release,
  379. };
  380. static enum pnfs_try_status
  381. filelayout_read_pagelist(struct nfs_pgio_header *hdr)
  382. {
  383. struct pnfs_layout_segment *lseg = hdr->lseg;
  384. struct nfs4_pnfs_ds *ds;
  385. struct rpc_clnt *ds_clnt;
  386. loff_t offset = hdr->args.offset;
  387. u32 j, idx;
  388. struct nfs_fh *fh;
  389. dprintk("--> %s ino %lu pgbase %u req %zu@%llu\n",
  390. __func__, hdr->inode->i_ino,
  391. hdr->args.pgbase, (size_t)hdr->args.count, offset);
  392. /* Retrieve the correct rpc_client for the byte range */
  393. j = nfs4_fl_calc_j_index(lseg, offset);
  394. idx = nfs4_fl_calc_ds_index(lseg, j);
  395. ds = nfs4_fl_prepare_ds(lseg, idx);
  396. if (!ds)
  397. return PNFS_NOT_ATTEMPTED;
  398. ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, hdr->inode);
  399. if (IS_ERR(ds_clnt))
  400. return PNFS_NOT_ATTEMPTED;
  401. dprintk("%s USE DS: %s cl_count %d\n", __func__,
  402. ds->ds_remotestr, refcount_read(&ds->ds_clp->cl_count));
  403. /* No multipath support. Use first DS */
  404. refcount_inc(&ds->ds_clp->cl_count);
  405. hdr->ds_clp = ds->ds_clp;
  406. hdr->ds_commit_idx = idx;
  407. fh = nfs4_fl_select_ds_fh(lseg, j);
  408. if (fh)
  409. hdr->args.fh = fh;
  410. hdr->args.offset = filelayout_get_dserver_offset(lseg, offset);
  411. hdr->mds_offset = offset;
  412. /* Perform an asynchronous read to ds */
  413. nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
  414. NFS_PROTO(hdr->inode), &filelayout_read_call_ops,
  415. 0, RPC_TASK_SOFTCONN);
  416. return PNFS_ATTEMPTED;
  417. }
  418. /* Perform async writes. */
  419. static enum pnfs_try_status
  420. filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
  421. {
  422. struct pnfs_layout_segment *lseg = hdr->lseg;
  423. struct nfs4_pnfs_ds *ds;
  424. struct rpc_clnt *ds_clnt;
  425. loff_t offset = hdr->args.offset;
  426. u32 j, idx;
  427. struct nfs_fh *fh;
  428. /* Retrieve the correct rpc_client for the byte range */
  429. j = nfs4_fl_calc_j_index(lseg, offset);
  430. idx = nfs4_fl_calc_ds_index(lseg, j);
  431. ds = nfs4_fl_prepare_ds(lseg, idx);
  432. if (!ds)
  433. return PNFS_NOT_ATTEMPTED;
  434. ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, hdr->inode);
  435. if (IS_ERR(ds_clnt))
  436. return PNFS_NOT_ATTEMPTED;
  437. dprintk("%s ino %lu sync %d req %zu@%llu DS: %s cl_count %d\n",
  438. __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
  439. offset, ds->ds_remotestr, refcount_read(&ds->ds_clp->cl_count));
  440. hdr->pgio_done_cb = filelayout_write_done_cb;
  441. refcount_inc(&ds->ds_clp->cl_count);
  442. hdr->ds_clp = ds->ds_clp;
  443. hdr->ds_commit_idx = idx;
  444. fh = nfs4_fl_select_ds_fh(lseg, j);
  445. if (fh)
  446. hdr->args.fh = fh;
  447. hdr->args.offset = filelayout_get_dserver_offset(lseg, offset);
  448. /* Perform an asynchronous write */
  449. nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
  450. NFS_PROTO(hdr->inode), &filelayout_write_call_ops,
  451. sync, RPC_TASK_SOFTCONN);
  452. return PNFS_ATTEMPTED;
  453. }
  454. static int
  455. filelayout_check_deviceid(struct pnfs_layout_hdr *lo,
  456. struct nfs4_filelayout_segment *fl,
  457. gfp_t gfp_flags)
  458. {
  459. struct nfs4_deviceid_node *d;
  460. struct nfs4_file_layout_dsaddr *dsaddr;
  461. int status = -EINVAL;
  462. /* Is the deviceid already set? If so, we're good. */
  463. if (fl->dsaddr != NULL)
  464. return 0;
  465. /* find and reference the deviceid */
  466. d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), &fl->deviceid,
  467. lo->plh_lc_cred, gfp_flags);
  468. if (d == NULL)
  469. goto out;
  470. dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
  471. /* Found deviceid is unavailable */
  472. if (filelayout_test_devid_unavailable(&dsaddr->id_node))
  473. goto out_put;
  474. if (fl->first_stripe_index >= dsaddr->stripe_count) {
  475. dprintk("%s Bad first_stripe_index %u\n",
  476. __func__, fl->first_stripe_index);
  477. goto out_put;
  478. }
  479. if ((fl->stripe_type == STRIPE_SPARSE &&
  480. fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
  481. (fl->stripe_type == STRIPE_DENSE &&
  482. fl->num_fh != dsaddr->stripe_count)) {
  483. dprintk("%s num_fh %u not valid for given packing\n",
  484. __func__, fl->num_fh);
  485. goto out_put;
  486. }
  487. status = 0;
  488. /*
  489. * Atomic compare and xchange to ensure we don't scribble
  490. * over a non-NULL pointer.
  491. */
  492. if (cmpxchg(&fl->dsaddr, NULL, dsaddr) != NULL)
  493. goto out_put;
  494. out:
  495. return status;
  496. out_put:
  497. nfs4_fl_put_deviceid(dsaddr);
  498. goto out;
  499. }
  500. /*
  501. * filelayout_check_layout()
  502. *
  503. * Make sure layout segment parameters are sane WRT the device.
  504. * At this point no generic layer initialization of the lseg has occurred,
  505. * and nothing has been added to the layout_hdr cache.
  506. *
  507. */
  508. static int
  509. filelayout_check_layout(struct pnfs_layout_hdr *lo,
  510. struct nfs4_filelayout_segment *fl,
  511. struct nfs4_layoutget_res *lgr,
  512. gfp_t gfp_flags)
  513. {
  514. int status = -EINVAL;
  515. dprintk("--> %s\n", __func__);
  516. /* FIXME: remove this check when layout segment support is added */
  517. if (lgr->range.offset != 0 ||
  518. lgr->range.length != NFS4_MAX_UINT64) {
  519. dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
  520. __func__);
  521. goto out;
  522. }
  523. if (fl->pattern_offset > lgr->range.offset) {
  524. dprintk("%s pattern_offset %lld too large\n",
  525. __func__, fl->pattern_offset);
  526. goto out;
  527. }
  528. if (!fl->stripe_unit) {
  529. dprintk("%s Invalid stripe unit (%u)\n",
  530. __func__, fl->stripe_unit);
  531. goto out;
  532. }
  533. status = 0;
  534. out:
  535. dprintk("--> %s returns %d\n", __func__, status);
  536. return status;
  537. }
  538. static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
  539. {
  540. int i;
  541. if (fl->fh_array) {
  542. for (i = 0; i < fl->num_fh; i++) {
  543. if (!fl->fh_array[i])
  544. break;
  545. kfree(fl->fh_array[i]);
  546. }
  547. kfree(fl->fh_array);
  548. }
  549. kfree(fl);
  550. }
  551. static int
  552. filelayout_decode_layout(struct pnfs_layout_hdr *flo,
  553. struct nfs4_filelayout_segment *fl,
  554. struct nfs4_layoutget_res *lgr,
  555. gfp_t gfp_flags)
  556. {
  557. struct xdr_stream stream;
  558. struct xdr_buf buf;
  559. struct page *scratch;
  560. __be32 *p;
  561. uint32_t nfl_util;
  562. int i;
  563. dprintk("%s: set_layout_map Begin\n", __func__);
  564. scratch = alloc_page(gfp_flags);
  565. if (!scratch)
  566. return -ENOMEM;
  567. xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
  568. xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
  569. /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
  570. * num_fh (4) */
  571. p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20);
  572. if (unlikely(!p))
  573. goto out_err;
  574. memcpy(&fl->deviceid, p, sizeof(fl->deviceid));
  575. p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
  576. nfs4_print_deviceid(&fl->deviceid);
  577. nfl_util = be32_to_cpup(p++);
  578. if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
  579. fl->commit_through_mds = 1;
  580. if (nfl_util & NFL4_UFLG_DENSE)
  581. fl->stripe_type = STRIPE_DENSE;
  582. else
  583. fl->stripe_type = STRIPE_SPARSE;
  584. fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
  585. fl->first_stripe_index = be32_to_cpup(p++);
  586. p = xdr_decode_hyper(p, &fl->pattern_offset);
  587. fl->num_fh = be32_to_cpup(p++);
  588. dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
  589. __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
  590. fl->pattern_offset);
  591. /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
  592. * Futher checking is done in filelayout_check_layout */
  593. if (fl->num_fh >
  594. max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
  595. goto out_err;
  596. if (fl->num_fh > 0) {
  597. fl->fh_array = kcalloc(fl->num_fh, sizeof(fl->fh_array[0]),
  598. gfp_flags);
  599. if (!fl->fh_array)
  600. goto out_err;
  601. }
  602. for (i = 0; i < fl->num_fh; i++) {
  603. /* Do we want to use a mempool here? */
  604. fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
  605. if (!fl->fh_array[i])
  606. goto out_err;
  607. p = xdr_inline_decode(&stream, 4);
  608. if (unlikely(!p))
  609. goto out_err;
  610. fl->fh_array[i]->size = be32_to_cpup(p++);
  611. if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
  612. printk(KERN_ERR "NFS: Too big fh %d received %d\n",
  613. i, fl->fh_array[i]->size);
  614. goto out_err;
  615. }
  616. p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
  617. if (unlikely(!p))
  618. goto out_err;
  619. memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
  620. dprintk("DEBUG: %s: fh len %d\n", __func__,
  621. fl->fh_array[i]->size);
  622. }
  623. __free_page(scratch);
  624. return 0;
  625. out_err:
  626. __free_page(scratch);
  627. return -EIO;
  628. }
  629. static void
  630. filelayout_free_lseg(struct pnfs_layout_segment *lseg)
  631. {
  632. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  633. dprintk("--> %s\n", __func__);
  634. if (fl->dsaddr != NULL)
  635. nfs4_fl_put_deviceid(fl->dsaddr);
  636. /* This assumes a single RW lseg */
  637. if (lseg->pls_range.iomode == IOMODE_RW) {
  638. struct nfs4_filelayout *flo;
  639. flo = FILELAYOUT_FROM_HDR(lseg->pls_layout);
  640. flo->commit_info.nbuckets = 0;
  641. kfree(flo->commit_info.buckets);
  642. flo->commit_info.buckets = NULL;
  643. }
  644. _filelayout_free_lseg(fl);
  645. }
  646. static int
  647. filelayout_alloc_commit_info(struct pnfs_layout_segment *lseg,
  648. struct nfs_commit_info *cinfo,
  649. gfp_t gfp_flags)
  650. {
  651. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  652. struct pnfs_commit_bucket *buckets;
  653. int size, i;
  654. if (fl->commit_through_mds)
  655. return 0;
  656. size = (fl->stripe_type == STRIPE_SPARSE) ?
  657. fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
  658. if (cinfo->ds->nbuckets >= size) {
  659. /* This assumes there is only one IOMODE_RW lseg. What
  660. * we really want to do is have a layout_hdr level
  661. * dictionary of <multipath_list4, fh> keys, each
  662. * associated with a struct list_head, populated by calls
  663. * to filelayout_write_pagelist().
  664. * */
  665. return 0;
  666. }
  667. buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
  668. gfp_flags);
  669. if (!buckets)
  670. return -ENOMEM;
  671. for (i = 0; i < size; i++) {
  672. INIT_LIST_HEAD(&buckets[i].written);
  673. INIT_LIST_HEAD(&buckets[i].committing);
  674. /* mark direct verifier as unset */
  675. buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
  676. }
  677. spin_lock(&cinfo->inode->i_lock);
  678. if (cinfo->ds->nbuckets >= size)
  679. goto out;
  680. for (i = 0; i < cinfo->ds->nbuckets; i++) {
  681. list_splice(&cinfo->ds->buckets[i].written,
  682. &buckets[i].written);
  683. list_splice(&cinfo->ds->buckets[i].committing,
  684. &buckets[i].committing);
  685. buckets[i].direct_verf.committed =
  686. cinfo->ds->buckets[i].direct_verf.committed;
  687. buckets[i].wlseg = cinfo->ds->buckets[i].wlseg;
  688. buckets[i].clseg = cinfo->ds->buckets[i].clseg;
  689. }
  690. swap(cinfo->ds->buckets, buckets);
  691. cinfo->ds->nbuckets = size;
  692. out:
  693. spin_unlock(&cinfo->inode->i_lock);
  694. kfree(buckets);
  695. return 0;
  696. }
  697. static struct pnfs_layout_segment *
  698. filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
  699. struct nfs4_layoutget_res *lgr,
  700. gfp_t gfp_flags)
  701. {
  702. struct nfs4_filelayout_segment *fl;
  703. int rc;
  704. dprintk("--> %s\n", __func__);
  705. fl = kzalloc(sizeof(*fl), gfp_flags);
  706. if (!fl)
  707. return NULL;
  708. rc = filelayout_decode_layout(layoutid, fl, lgr, gfp_flags);
  709. if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, gfp_flags)) {
  710. _filelayout_free_lseg(fl);
  711. return NULL;
  712. }
  713. return &fl->generic_hdr;
  714. }
  715. /*
  716. * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
  717. *
  718. * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
  719. * of bytes (maximum @req->wb_bytes) that can be coalesced.
  720. */
  721. static size_t
  722. filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
  723. struct nfs_page *req)
  724. {
  725. unsigned int size;
  726. u64 p_stripe, r_stripe;
  727. u32 stripe_offset;
  728. u64 segment_offset = pgio->pg_lseg->pls_range.offset;
  729. u32 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
  730. /* calls nfs_generic_pg_test */
  731. size = pnfs_generic_pg_test(pgio, prev, req);
  732. if (!size)
  733. return 0;
  734. /* see if req and prev are in the same stripe */
  735. if (prev) {
  736. p_stripe = (u64)req_offset(prev) - segment_offset;
  737. r_stripe = (u64)req_offset(req) - segment_offset;
  738. do_div(p_stripe, stripe_unit);
  739. do_div(r_stripe, stripe_unit);
  740. if (p_stripe != r_stripe)
  741. return 0;
  742. }
  743. /* calculate remaining bytes in the current stripe */
  744. div_u64_rem((u64)req_offset(req) - segment_offset,
  745. stripe_unit,
  746. &stripe_offset);
  747. WARN_ON_ONCE(stripe_offset > stripe_unit);
  748. if (stripe_offset >= stripe_unit)
  749. return 0;
  750. return min(stripe_unit - (unsigned int)stripe_offset, size);
  751. }
  752. static struct pnfs_layout_segment *
  753. fl_pnfs_update_layout(struct inode *ino,
  754. struct nfs_open_context *ctx,
  755. loff_t pos,
  756. u64 count,
  757. enum pnfs_iomode iomode,
  758. bool strict_iomode,
  759. gfp_t gfp_flags)
  760. {
  761. struct pnfs_layout_segment *lseg = NULL;
  762. struct pnfs_layout_hdr *lo;
  763. struct nfs4_filelayout_segment *fl;
  764. int status;
  765. lseg = pnfs_update_layout(ino, ctx, pos, count, iomode, strict_iomode,
  766. gfp_flags);
  767. if (!lseg)
  768. lseg = ERR_PTR(-ENOMEM);
  769. if (IS_ERR(lseg))
  770. goto out;
  771. lo = NFS_I(ino)->layout;
  772. fl = FILELAYOUT_LSEG(lseg);
  773. status = filelayout_check_deviceid(lo, fl, gfp_flags);
  774. if (status) {
  775. pnfs_put_lseg(lseg);
  776. lseg = ERR_PTR(status);
  777. }
  778. out:
  779. return lseg;
  780. }
  781. static void
  782. filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
  783. struct nfs_page *req)
  784. {
  785. pnfs_generic_pg_check_layout(pgio);
  786. if (!pgio->pg_lseg) {
  787. pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode,
  788. req->wb_context,
  789. 0,
  790. NFS4_MAX_UINT64,
  791. IOMODE_READ,
  792. false,
  793. GFP_KERNEL);
  794. if (IS_ERR(pgio->pg_lseg)) {
  795. pgio->pg_error = PTR_ERR(pgio->pg_lseg);
  796. pgio->pg_lseg = NULL;
  797. return;
  798. }
  799. }
  800. /* If no lseg, fall back to read through mds */
  801. if (pgio->pg_lseg == NULL)
  802. nfs_pageio_reset_read_mds(pgio);
  803. }
  804. static void
  805. filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
  806. struct nfs_page *req)
  807. {
  808. struct nfs_commit_info cinfo;
  809. int status;
  810. pnfs_generic_pg_check_layout(pgio);
  811. if (!pgio->pg_lseg) {
  812. pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode,
  813. req->wb_context,
  814. 0,
  815. NFS4_MAX_UINT64,
  816. IOMODE_RW,
  817. false,
  818. GFP_NOFS);
  819. if (IS_ERR(pgio->pg_lseg)) {
  820. pgio->pg_error = PTR_ERR(pgio->pg_lseg);
  821. pgio->pg_lseg = NULL;
  822. return;
  823. }
  824. }
  825. /* If no lseg, fall back to write through mds */
  826. if (pgio->pg_lseg == NULL)
  827. goto out_mds;
  828. nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
  829. status = filelayout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
  830. if (status < 0) {
  831. pnfs_put_lseg(pgio->pg_lseg);
  832. pgio->pg_lseg = NULL;
  833. goto out_mds;
  834. }
  835. return;
  836. out_mds:
  837. nfs_pageio_reset_write_mds(pgio);
  838. }
  839. static const struct nfs_pageio_ops filelayout_pg_read_ops = {
  840. .pg_init = filelayout_pg_init_read,
  841. .pg_test = filelayout_pg_test,
  842. .pg_doio = pnfs_generic_pg_readpages,
  843. .pg_cleanup = pnfs_generic_pg_cleanup,
  844. };
  845. static const struct nfs_pageio_ops filelayout_pg_write_ops = {
  846. .pg_init = filelayout_pg_init_write,
  847. .pg_test = filelayout_pg_test,
  848. .pg_doio = pnfs_generic_pg_writepages,
  849. .pg_cleanup = pnfs_generic_pg_cleanup,
  850. };
  851. static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
  852. {
  853. if (fl->stripe_type == STRIPE_SPARSE)
  854. return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
  855. else
  856. return j;
  857. }
  858. static void
  859. filelayout_mark_request_commit(struct nfs_page *req,
  860. struct pnfs_layout_segment *lseg,
  861. struct nfs_commit_info *cinfo,
  862. u32 ds_commit_idx)
  863. {
  864. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  865. u32 i, j;
  866. if (fl->commit_through_mds) {
  867. nfs_request_add_commit_list(req, cinfo);
  868. } else {
  869. /* Note that we are calling nfs4_fl_calc_j_index on each page
  870. * that ends up being committed to a data server. An attractive
  871. * alternative is to add a field to nfs_write_data and nfs_page
  872. * to store the value calculated in filelayout_write_pagelist
  873. * and just use that here.
  874. */
  875. j = nfs4_fl_calc_j_index(lseg, req_offset(req));
  876. i = select_bucket_index(fl, j);
  877. pnfs_layout_mark_request_commit(req, lseg, cinfo, i);
  878. }
  879. }
  880. static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
  881. {
  882. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  883. if (flseg->stripe_type == STRIPE_SPARSE)
  884. return i;
  885. else
  886. return nfs4_fl_calc_ds_index(lseg, i);
  887. }
  888. static struct nfs_fh *
  889. select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
  890. {
  891. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  892. if (flseg->stripe_type == STRIPE_SPARSE) {
  893. if (flseg->num_fh == 1)
  894. i = 0;
  895. else if (flseg->num_fh == 0)
  896. /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
  897. return NULL;
  898. }
  899. return flseg->fh_array[i];
  900. }
  901. static int filelayout_initiate_commit(struct nfs_commit_data *data, int how)
  902. {
  903. struct pnfs_layout_segment *lseg = data->lseg;
  904. struct nfs4_pnfs_ds *ds;
  905. struct rpc_clnt *ds_clnt;
  906. u32 idx;
  907. struct nfs_fh *fh;
  908. idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
  909. ds = nfs4_fl_prepare_ds(lseg, idx);
  910. if (!ds)
  911. goto out_err;
  912. ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, data->inode);
  913. if (IS_ERR(ds_clnt))
  914. goto out_err;
  915. dprintk("%s ino %lu, how %d cl_count %d\n", __func__,
  916. data->inode->i_ino, how, refcount_read(&ds->ds_clp->cl_count));
  917. data->commit_done_cb = filelayout_commit_done_cb;
  918. refcount_inc(&ds->ds_clp->cl_count);
  919. data->ds_clp = ds->ds_clp;
  920. fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
  921. if (fh)
  922. data->args.fh = fh;
  923. return nfs_initiate_commit(ds_clnt, data, NFS_PROTO(data->inode),
  924. &filelayout_commit_call_ops, how,
  925. RPC_TASK_SOFTCONN);
  926. out_err:
  927. pnfs_generic_prepare_to_resend_writes(data);
  928. pnfs_generic_commit_release(data);
  929. return -EAGAIN;
  930. }
  931. /* filelayout_search_commit_reqs - Search lists in @cinfo for the head reqest
  932. * for @page
  933. * @cinfo - commit info for current inode
  934. * @page - page to search for matching head request
  935. *
  936. * Returns a the head request if one is found, otherwise returns NULL.
  937. */
  938. static struct nfs_page *
  939. filelayout_search_commit_reqs(struct nfs_commit_info *cinfo, struct page *page)
  940. {
  941. struct nfs_page *freq, *t;
  942. struct pnfs_commit_bucket *b;
  943. int i;
  944. /* Linearly search the commit lists for each bucket until a matching
  945. * request is found */
  946. for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) {
  947. list_for_each_entry_safe(freq, t, &b->written, wb_list) {
  948. if (freq->wb_page == page)
  949. return freq->wb_head;
  950. }
  951. list_for_each_entry_safe(freq, t, &b->committing, wb_list) {
  952. if (freq->wb_page == page)
  953. return freq->wb_head;
  954. }
  955. }
  956. return NULL;
  957. }
  958. static int
  959. filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
  960. int how, struct nfs_commit_info *cinfo)
  961. {
  962. return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
  963. filelayout_initiate_commit);
  964. }
  965. static struct nfs4_deviceid_node *
  966. filelayout_alloc_deviceid_node(struct nfs_server *server,
  967. struct pnfs_device *pdev, gfp_t gfp_flags)
  968. {
  969. struct nfs4_file_layout_dsaddr *dsaddr;
  970. dsaddr = nfs4_fl_alloc_deviceid_node(server, pdev, gfp_flags);
  971. if (!dsaddr)
  972. return NULL;
  973. return &dsaddr->id_node;
  974. }
  975. static void
  976. filelayout_free_deviceid_node(struct nfs4_deviceid_node *d)
  977. {
  978. nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
  979. }
  980. static struct pnfs_layout_hdr *
  981. filelayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
  982. {
  983. struct nfs4_filelayout *flo;
  984. flo = kzalloc(sizeof(*flo), gfp_flags);
  985. return flo != NULL ? &flo->generic_hdr : NULL;
  986. }
  987. static void
  988. filelayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
  989. {
  990. kfree(FILELAYOUT_FROM_HDR(lo));
  991. }
  992. static struct pnfs_ds_commit_info *
  993. filelayout_get_ds_info(struct inode *inode)
  994. {
  995. struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
  996. if (layout == NULL)
  997. return NULL;
  998. else
  999. return &FILELAYOUT_FROM_HDR(layout)->commit_info;
  1000. }
  1001. static struct pnfs_layoutdriver_type filelayout_type = {
  1002. .id = LAYOUT_NFSV4_1_FILES,
  1003. .name = "LAYOUT_NFSV4_1_FILES",
  1004. .owner = THIS_MODULE,
  1005. .alloc_layout_hdr = filelayout_alloc_layout_hdr,
  1006. .free_layout_hdr = filelayout_free_layout_hdr,
  1007. .alloc_lseg = filelayout_alloc_lseg,
  1008. .free_lseg = filelayout_free_lseg,
  1009. .pg_read_ops = &filelayout_pg_read_ops,
  1010. .pg_write_ops = &filelayout_pg_write_ops,
  1011. .get_ds_info = &filelayout_get_ds_info,
  1012. .mark_request_commit = filelayout_mark_request_commit,
  1013. .clear_request_commit = pnfs_generic_clear_request_commit,
  1014. .scan_commit_lists = pnfs_generic_scan_commit_lists,
  1015. .recover_commit_reqs = pnfs_generic_recover_commit_reqs,
  1016. .search_commit_reqs = filelayout_search_commit_reqs,
  1017. .commit_pagelist = filelayout_commit_pagelist,
  1018. .read_pagelist = filelayout_read_pagelist,
  1019. .write_pagelist = filelayout_write_pagelist,
  1020. .alloc_deviceid_node = filelayout_alloc_deviceid_node,
  1021. .free_deviceid_node = filelayout_free_deviceid_node,
  1022. .sync = pnfs_nfs_generic_sync,
  1023. };
  1024. static int __init nfs4filelayout_init(void)
  1025. {
  1026. printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
  1027. __func__);
  1028. return pnfs_register_layoutdriver(&filelayout_type);
  1029. }
  1030. static void __exit nfs4filelayout_exit(void)
  1031. {
  1032. printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
  1033. __func__);
  1034. pnfs_unregister_layoutdriver(&filelayout_type);
  1035. }
  1036. MODULE_ALIAS("nfs-layouttype4-1");
  1037. module_init(nfs4filelayout_init);
  1038. module_exit(nfs4filelayout_exit);