filelayout.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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, atomic_read(&ds->ds_clp->cl_count));
  403. /* No multipath support. Use first DS */
  404. atomic_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, atomic_read(&ds->ds_clp->cl_count));
  440. hdr->pgio_done_cb = filelayout_write_done_cb;
  441. atomic_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. /* find and reference the deviceid */
  463. d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), &fl->deviceid,
  464. lo->plh_lc_cred, gfp_flags);
  465. if (d == NULL)
  466. goto out;
  467. dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
  468. /* Found deviceid is unavailable */
  469. if (filelayout_test_devid_unavailable(&dsaddr->id_node))
  470. goto out_put;
  471. fl->dsaddr = dsaddr;
  472. if (fl->first_stripe_index >= dsaddr->stripe_count) {
  473. dprintk("%s Bad first_stripe_index %u\n",
  474. __func__, fl->first_stripe_index);
  475. goto out_put;
  476. }
  477. if ((fl->stripe_type == STRIPE_SPARSE &&
  478. fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
  479. (fl->stripe_type == STRIPE_DENSE &&
  480. fl->num_fh != dsaddr->stripe_count)) {
  481. dprintk("%s num_fh %u not valid for given packing\n",
  482. __func__, fl->num_fh);
  483. goto out_put;
  484. }
  485. status = 0;
  486. out:
  487. return status;
  488. out_put:
  489. nfs4_fl_put_deviceid(dsaddr);
  490. goto out;
  491. }
  492. /*
  493. * filelayout_check_layout()
  494. *
  495. * Make sure layout segment parameters are sane WRT the device.
  496. * At this point no generic layer initialization of the lseg has occurred,
  497. * and nothing has been added to the layout_hdr cache.
  498. *
  499. */
  500. static int
  501. filelayout_check_layout(struct pnfs_layout_hdr *lo,
  502. struct nfs4_filelayout_segment *fl,
  503. struct nfs4_layoutget_res *lgr,
  504. gfp_t gfp_flags)
  505. {
  506. int status = -EINVAL;
  507. dprintk("--> %s\n", __func__);
  508. /* FIXME: remove this check when layout segment support is added */
  509. if (lgr->range.offset != 0 ||
  510. lgr->range.length != NFS4_MAX_UINT64) {
  511. dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
  512. __func__);
  513. goto out;
  514. }
  515. if (fl->pattern_offset > lgr->range.offset) {
  516. dprintk("%s pattern_offset %lld too large\n",
  517. __func__, fl->pattern_offset);
  518. goto out;
  519. }
  520. if (!fl->stripe_unit) {
  521. dprintk("%s Invalid stripe unit (%u)\n",
  522. __func__, fl->stripe_unit);
  523. goto out;
  524. }
  525. status = 0;
  526. out:
  527. dprintk("--> %s returns %d\n", __func__, status);
  528. return status;
  529. }
  530. static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
  531. {
  532. int i;
  533. if (fl->fh_array) {
  534. for (i = 0; i < fl->num_fh; i++) {
  535. if (!fl->fh_array[i])
  536. break;
  537. kfree(fl->fh_array[i]);
  538. }
  539. kfree(fl->fh_array);
  540. }
  541. kfree(fl);
  542. }
  543. static int
  544. filelayout_decode_layout(struct pnfs_layout_hdr *flo,
  545. struct nfs4_filelayout_segment *fl,
  546. struct nfs4_layoutget_res *lgr,
  547. gfp_t gfp_flags)
  548. {
  549. struct xdr_stream stream;
  550. struct xdr_buf buf;
  551. struct page *scratch;
  552. __be32 *p;
  553. uint32_t nfl_util;
  554. int i;
  555. dprintk("%s: set_layout_map Begin\n", __func__);
  556. scratch = alloc_page(gfp_flags);
  557. if (!scratch)
  558. return -ENOMEM;
  559. xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
  560. xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
  561. /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
  562. * num_fh (4) */
  563. p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20);
  564. if (unlikely(!p))
  565. goto out_err;
  566. memcpy(&fl->deviceid, p, sizeof(fl->deviceid));
  567. p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
  568. nfs4_print_deviceid(&fl->deviceid);
  569. nfl_util = be32_to_cpup(p++);
  570. if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
  571. fl->commit_through_mds = 1;
  572. if (nfl_util & NFL4_UFLG_DENSE)
  573. fl->stripe_type = STRIPE_DENSE;
  574. else
  575. fl->stripe_type = STRIPE_SPARSE;
  576. fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
  577. fl->first_stripe_index = be32_to_cpup(p++);
  578. p = xdr_decode_hyper(p, &fl->pattern_offset);
  579. fl->num_fh = be32_to_cpup(p++);
  580. dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
  581. __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
  582. fl->pattern_offset);
  583. /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
  584. * Futher checking is done in filelayout_check_layout */
  585. if (fl->num_fh >
  586. max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
  587. goto out_err;
  588. if (fl->num_fh > 0) {
  589. fl->fh_array = kcalloc(fl->num_fh, sizeof(fl->fh_array[0]),
  590. gfp_flags);
  591. if (!fl->fh_array)
  592. goto out_err;
  593. }
  594. for (i = 0; i < fl->num_fh; i++) {
  595. /* Do we want to use a mempool here? */
  596. fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
  597. if (!fl->fh_array[i])
  598. goto out_err;
  599. p = xdr_inline_decode(&stream, 4);
  600. if (unlikely(!p))
  601. goto out_err;
  602. fl->fh_array[i]->size = be32_to_cpup(p++);
  603. if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
  604. printk(KERN_ERR "NFS: Too big fh %d received %d\n",
  605. i, fl->fh_array[i]->size);
  606. goto out_err;
  607. }
  608. p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
  609. if (unlikely(!p))
  610. goto out_err;
  611. memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
  612. dprintk("DEBUG: %s: fh len %d\n", __func__,
  613. fl->fh_array[i]->size);
  614. }
  615. __free_page(scratch);
  616. return 0;
  617. out_err:
  618. __free_page(scratch);
  619. return -EIO;
  620. }
  621. static void
  622. filelayout_free_lseg(struct pnfs_layout_segment *lseg)
  623. {
  624. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  625. dprintk("--> %s\n", __func__);
  626. nfs4_fl_put_deviceid(fl->dsaddr);
  627. /* This assumes a single RW lseg */
  628. if (lseg->pls_range.iomode == IOMODE_RW) {
  629. struct nfs4_filelayout *flo;
  630. flo = FILELAYOUT_FROM_HDR(lseg->pls_layout);
  631. flo->commit_info.nbuckets = 0;
  632. kfree(flo->commit_info.buckets);
  633. flo->commit_info.buckets = NULL;
  634. }
  635. _filelayout_free_lseg(fl);
  636. }
  637. static int
  638. filelayout_alloc_commit_info(struct pnfs_layout_segment *lseg,
  639. struct nfs_commit_info *cinfo,
  640. gfp_t gfp_flags)
  641. {
  642. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  643. struct pnfs_commit_bucket *buckets;
  644. int size, i;
  645. if (fl->commit_through_mds)
  646. return 0;
  647. size = (fl->stripe_type == STRIPE_SPARSE) ?
  648. fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
  649. if (cinfo->ds->nbuckets >= size) {
  650. /* This assumes there is only one IOMODE_RW lseg. What
  651. * we really want to do is have a layout_hdr level
  652. * dictionary of <multipath_list4, fh> keys, each
  653. * associated with a struct list_head, populated by calls
  654. * to filelayout_write_pagelist().
  655. * */
  656. return 0;
  657. }
  658. buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
  659. gfp_flags);
  660. if (!buckets)
  661. return -ENOMEM;
  662. for (i = 0; i < size; i++) {
  663. INIT_LIST_HEAD(&buckets[i].written);
  664. INIT_LIST_HEAD(&buckets[i].committing);
  665. /* mark direct verifier as unset */
  666. buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
  667. }
  668. spin_lock(&cinfo->inode->i_lock);
  669. if (cinfo->ds->nbuckets >= size)
  670. goto out;
  671. for (i = 0; i < cinfo->ds->nbuckets; i++) {
  672. list_splice(&cinfo->ds->buckets[i].written,
  673. &buckets[i].written);
  674. list_splice(&cinfo->ds->buckets[i].committing,
  675. &buckets[i].committing);
  676. buckets[i].direct_verf.committed =
  677. cinfo->ds->buckets[i].direct_verf.committed;
  678. buckets[i].wlseg = cinfo->ds->buckets[i].wlseg;
  679. buckets[i].clseg = cinfo->ds->buckets[i].clseg;
  680. }
  681. swap(cinfo->ds->buckets, buckets);
  682. cinfo->ds->nbuckets = size;
  683. out:
  684. spin_unlock(&cinfo->inode->i_lock);
  685. kfree(buckets);
  686. return 0;
  687. }
  688. static struct pnfs_layout_segment *
  689. filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
  690. struct nfs4_layoutget_res *lgr,
  691. gfp_t gfp_flags)
  692. {
  693. struct nfs4_filelayout_segment *fl;
  694. int rc;
  695. dprintk("--> %s\n", __func__);
  696. fl = kzalloc(sizeof(*fl), gfp_flags);
  697. if (!fl)
  698. return NULL;
  699. rc = filelayout_decode_layout(layoutid, fl, lgr, gfp_flags);
  700. if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, gfp_flags)) {
  701. _filelayout_free_lseg(fl);
  702. return NULL;
  703. }
  704. return &fl->generic_hdr;
  705. }
  706. /*
  707. * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
  708. *
  709. * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
  710. * of bytes (maximum @req->wb_bytes) that can be coalesced.
  711. */
  712. static size_t
  713. filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
  714. struct nfs_page *req)
  715. {
  716. unsigned int size;
  717. u64 p_stripe, r_stripe;
  718. u32 stripe_offset;
  719. u64 segment_offset = pgio->pg_lseg->pls_range.offset;
  720. u32 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
  721. /* calls nfs_generic_pg_test */
  722. size = pnfs_generic_pg_test(pgio, prev, req);
  723. if (!size)
  724. return 0;
  725. /* see if req and prev are in the same stripe */
  726. if (prev) {
  727. p_stripe = (u64)req_offset(prev) - segment_offset;
  728. r_stripe = (u64)req_offset(req) - segment_offset;
  729. do_div(p_stripe, stripe_unit);
  730. do_div(r_stripe, stripe_unit);
  731. if (p_stripe != r_stripe)
  732. return 0;
  733. }
  734. /* calculate remaining bytes in the current stripe */
  735. div_u64_rem((u64)req_offset(req) - segment_offset,
  736. stripe_unit,
  737. &stripe_offset);
  738. WARN_ON_ONCE(stripe_offset > stripe_unit);
  739. if (stripe_offset >= stripe_unit)
  740. return 0;
  741. return min(stripe_unit - (unsigned int)stripe_offset, size);
  742. }
  743. static struct pnfs_layout_segment *
  744. fl_pnfs_update_layout(struct inode *ino,
  745. struct nfs_open_context *ctx,
  746. loff_t pos,
  747. u64 count,
  748. enum pnfs_iomode iomode,
  749. bool strict_iomode,
  750. gfp_t gfp_flags)
  751. {
  752. struct pnfs_layout_segment *lseg = NULL;
  753. struct pnfs_layout_hdr *lo;
  754. struct nfs4_filelayout_segment *fl;
  755. int status;
  756. lseg = pnfs_update_layout(ino, ctx, pos, count, iomode, strict_iomode,
  757. gfp_flags);
  758. if (!lseg)
  759. lseg = ERR_PTR(-ENOMEM);
  760. if (IS_ERR(lseg))
  761. goto out;
  762. lo = NFS_I(ino)->layout;
  763. fl = FILELAYOUT_LSEG(lseg);
  764. status = filelayout_check_deviceid(lo, fl, gfp_flags);
  765. if (status) {
  766. pnfs_put_lseg(lseg);
  767. lseg = ERR_PTR(status);
  768. }
  769. out:
  770. return lseg;
  771. }
  772. static void
  773. filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
  774. struct nfs_page *req)
  775. {
  776. pnfs_generic_pg_check_layout(pgio);
  777. if (!pgio->pg_lseg) {
  778. pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode,
  779. req->wb_context,
  780. 0,
  781. NFS4_MAX_UINT64,
  782. IOMODE_READ,
  783. false,
  784. GFP_KERNEL);
  785. if (IS_ERR(pgio->pg_lseg)) {
  786. pgio->pg_error = PTR_ERR(pgio->pg_lseg);
  787. pgio->pg_lseg = NULL;
  788. return;
  789. }
  790. }
  791. /* If no lseg, fall back to read through mds */
  792. if (pgio->pg_lseg == NULL)
  793. nfs_pageio_reset_read_mds(pgio);
  794. }
  795. static void
  796. filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
  797. struct nfs_page *req)
  798. {
  799. struct nfs_commit_info cinfo;
  800. int status;
  801. pnfs_generic_pg_check_layout(pgio);
  802. if (!pgio->pg_lseg) {
  803. pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode,
  804. req->wb_context,
  805. 0,
  806. NFS4_MAX_UINT64,
  807. IOMODE_RW,
  808. false,
  809. GFP_NOFS);
  810. if (IS_ERR(pgio->pg_lseg)) {
  811. pgio->pg_error = PTR_ERR(pgio->pg_lseg);
  812. pgio->pg_lseg = NULL;
  813. return;
  814. }
  815. }
  816. /* If no lseg, fall back to write through mds */
  817. if (pgio->pg_lseg == NULL)
  818. goto out_mds;
  819. nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
  820. status = filelayout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
  821. if (status < 0) {
  822. pnfs_put_lseg(pgio->pg_lseg);
  823. pgio->pg_lseg = NULL;
  824. goto out_mds;
  825. }
  826. return;
  827. out_mds:
  828. nfs_pageio_reset_write_mds(pgio);
  829. }
  830. static const struct nfs_pageio_ops filelayout_pg_read_ops = {
  831. .pg_init = filelayout_pg_init_read,
  832. .pg_test = filelayout_pg_test,
  833. .pg_doio = pnfs_generic_pg_readpages,
  834. .pg_cleanup = pnfs_generic_pg_cleanup,
  835. };
  836. static const struct nfs_pageio_ops filelayout_pg_write_ops = {
  837. .pg_init = filelayout_pg_init_write,
  838. .pg_test = filelayout_pg_test,
  839. .pg_doio = pnfs_generic_pg_writepages,
  840. .pg_cleanup = pnfs_generic_pg_cleanup,
  841. };
  842. static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
  843. {
  844. if (fl->stripe_type == STRIPE_SPARSE)
  845. return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
  846. else
  847. return j;
  848. }
  849. static void
  850. filelayout_mark_request_commit(struct nfs_page *req,
  851. struct pnfs_layout_segment *lseg,
  852. struct nfs_commit_info *cinfo,
  853. u32 ds_commit_idx)
  854. {
  855. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  856. u32 i, j;
  857. if (fl->commit_through_mds) {
  858. nfs_request_add_commit_list(req, cinfo);
  859. } else {
  860. /* Note that we are calling nfs4_fl_calc_j_index on each page
  861. * that ends up being committed to a data server. An attractive
  862. * alternative is to add a field to nfs_write_data and nfs_page
  863. * to store the value calculated in filelayout_write_pagelist
  864. * and just use that here.
  865. */
  866. j = nfs4_fl_calc_j_index(lseg, req_offset(req));
  867. i = select_bucket_index(fl, j);
  868. pnfs_layout_mark_request_commit(req, lseg, cinfo, i);
  869. }
  870. }
  871. static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
  872. {
  873. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  874. if (flseg->stripe_type == STRIPE_SPARSE)
  875. return i;
  876. else
  877. return nfs4_fl_calc_ds_index(lseg, i);
  878. }
  879. static struct nfs_fh *
  880. select_ds_fh_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. if (flseg->num_fh == 1)
  885. i = 0;
  886. else if (flseg->num_fh == 0)
  887. /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
  888. return NULL;
  889. }
  890. return flseg->fh_array[i];
  891. }
  892. static int filelayout_initiate_commit(struct nfs_commit_data *data, int how)
  893. {
  894. struct pnfs_layout_segment *lseg = data->lseg;
  895. struct nfs4_pnfs_ds *ds;
  896. struct rpc_clnt *ds_clnt;
  897. u32 idx;
  898. struct nfs_fh *fh;
  899. idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
  900. ds = nfs4_fl_prepare_ds(lseg, idx);
  901. if (!ds)
  902. goto out_err;
  903. ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, data->inode);
  904. if (IS_ERR(ds_clnt))
  905. goto out_err;
  906. dprintk("%s ino %lu, how %d cl_count %d\n", __func__,
  907. data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count));
  908. data->commit_done_cb = filelayout_commit_done_cb;
  909. atomic_inc(&ds->ds_clp->cl_count);
  910. data->ds_clp = ds->ds_clp;
  911. fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
  912. if (fh)
  913. data->args.fh = fh;
  914. return nfs_initiate_commit(ds_clnt, data, NFS_PROTO(data->inode),
  915. &filelayout_commit_call_ops, how,
  916. RPC_TASK_SOFTCONN);
  917. out_err:
  918. pnfs_generic_prepare_to_resend_writes(data);
  919. pnfs_generic_commit_release(data);
  920. return -EAGAIN;
  921. }
  922. /* filelayout_search_commit_reqs - Search lists in @cinfo for the head reqest
  923. * for @page
  924. * @cinfo - commit info for current inode
  925. * @page - page to search for matching head request
  926. *
  927. * Returns a the head request if one is found, otherwise returns NULL.
  928. */
  929. static struct nfs_page *
  930. filelayout_search_commit_reqs(struct nfs_commit_info *cinfo, struct page *page)
  931. {
  932. struct nfs_page *freq, *t;
  933. struct pnfs_commit_bucket *b;
  934. int i;
  935. /* Linearly search the commit lists for each bucket until a matching
  936. * request is found */
  937. for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) {
  938. list_for_each_entry_safe(freq, t, &b->written, wb_list) {
  939. if (freq->wb_page == page)
  940. return freq->wb_head;
  941. }
  942. list_for_each_entry_safe(freq, t, &b->committing, wb_list) {
  943. if (freq->wb_page == page)
  944. return freq->wb_head;
  945. }
  946. }
  947. return NULL;
  948. }
  949. static int
  950. filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
  951. int how, struct nfs_commit_info *cinfo)
  952. {
  953. return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
  954. filelayout_initiate_commit);
  955. }
  956. static struct nfs4_deviceid_node *
  957. filelayout_alloc_deviceid_node(struct nfs_server *server,
  958. struct pnfs_device *pdev, gfp_t gfp_flags)
  959. {
  960. struct nfs4_file_layout_dsaddr *dsaddr;
  961. dsaddr = nfs4_fl_alloc_deviceid_node(server, pdev, gfp_flags);
  962. if (!dsaddr)
  963. return NULL;
  964. return &dsaddr->id_node;
  965. }
  966. static void
  967. filelayout_free_deviceid_node(struct nfs4_deviceid_node *d)
  968. {
  969. nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
  970. }
  971. static struct pnfs_layout_hdr *
  972. filelayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
  973. {
  974. struct nfs4_filelayout *flo;
  975. flo = kzalloc(sizeof(*flo), gfp_flags);
  976. return flo != NULL ? &flo->generic_hdr : NULL;
  977. }
  978. static void
  979. filelayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
  980. {
  981. kfree(FILELAYOUT_FROM_HDR(lo));
  982. }
  983. static struct pnfs_ds_commit_info *
  984. filelayout_get_ds_info(struct inode *inode)
  985. {
  986. struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
  987. if (layout == NULL)
  988. return NULL;
  989. else
  990. return &FILELAYOUT_FROM_HDR(layout)->commit_info;
  991. }
  992. static struct pnfs_layoutdriver_type filelayout_type = {
  993. .id = LAYOUT_NFSV4_1_FILES,
  994. .name = "LAYOUT_NFSV4_1_FILES",
  995. .owner = THIS_MODULE,
  996. .alloc_layout_hdr = filelayout_alloc_layout_hdr,
  997. .free_layout_hdr = filelayout_free_layout_hdr,
  998. .alloc_lseg = filelayout_alloc_lseg,
  999. .free_lseg = filelayout_free_lseg,
  1000. .pg_read_ops = &filelayout_pg_read_ops,
  1001. .pg_write_ops = &filelayout_pg_write_ops,
  1002. .get_ds_info = &filelayout_get_ds_info,
  1003. .mark_request_commit = filelayout_mark_request_commit,
  1004. .clear_request_commit = pnfs_generic_clear_request_commit,
  1005. .scan_commit_lists = pnfs_generic_scan_commit_lists,
  1006. .recover_commit_reqs = pnfs_generic_recover_commit_reqs,
  1007. .search_commit_reqs = filelayout_search_commit_reqs,
  1008. .commit_pagelist = filelayout_commit_pagelist,
  1009. .read_pagelist = filelayout_read_pagelist,
  1010. .write_pagelist = filelayout_write_pagelist,
  1011. .alloc_deviceid_node = filelayout_alloc_deviceid_node,
  1012. .free_deviceid_node = filelayout_free_deviceid_node,
  1013. .sync = pnfs_nfs_generic_sync,
  1014. };
  1015. static int __init nfs4filelayout_init(void)
  1016. {
  1017. printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
  1018. __func__);
  1019. return pnfs_register_layoutdriver(&filelayout_type);
  1020. }
  1021. static void __exit nfs4filelayout_exit(void)
  1022. {
  1023. printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
  1024. __func__);
  1025. pnfs_unregister_layoutdriver(&filelayout_type);
  1026. }
  1027. MODULE_ALIAS("nfs-layouttype4-1");
  1028. module_init(nfs4filelayout_init);
  1029. module_exit(nfs4filelayout_exit);