filelayout.c 32 KB

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