nfs4filelayout.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  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/sunrpc/metrics.h>
  35. #include "internal.h"
  36. #include "delegation.h"
  37. #include "nfs4filelayout.h"
  38. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  39. MODULE_LICENSE("GPL");
  40. MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>");
  41. MODULE_DESCRIPTION("The NFSv4 file layout driver");
  42. #define FILELAYOUT_POLL_RETRY_MAX (15*HZ)
  43. static loff_t
  44. filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg,
  45. loff_t offset)
  46. {
  47. u32 stripe_width = flseg->stripe_unit * flseg->dsaddr->stripe_count;
  48. u64 stripe_no;
  49. u32 rem;
  50. offset -= flseg->pattern_offset;
  51. stripe_no = div_u64(offset, stripe_width);
  52. div_u64_rem(offset, flseg->stripe_unit, &rem);
  53. return stripe_no * flseg->stripe_unit + rem;
  54. }
  55. /* This function is used by the layout driver to calculate the
  56. * offset of the file on the dserver based on whether the
  57. * layout type is STRIPE_DENSE or STRIPE_SPARSE
  58. */
  59. static loff_t
  60. filelayout_get_dserver_offset(struct pnfs_layout_segment *lseg, loff_t offset)
  61. {
  62. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  63. switch (flseg->stripe_type) {
  64. case STRIPE_SPARSE:
  65. return offset;
  66. case STRIPE_DENSE:
  67. return filelayout_get_dense_offset(flseg, offset);
  68. }
  69. BUG();
  70. }
  71. static int filelayout_async_handle_error(struct rpc_task *task,
  72. struct nfs4_state *state,
  73. struct nfs_client *clp,
  74. int *reset)
  75. {
  76. struct nfs_server *mds_server = NFS_SERVER(state->inode);
  77. struct nfs_client *mds_client = mds_server->nfs_client;
  78. if (task->tk_status >= 0)
  79. return 0;
  80. *reset = 0;
  81. switch (task->tk_status) {
  82. /* MDS state errors */
  83. case -NFS4ERR_DELEG_REVOKED:
  84. case -NFS4ERR_ADMIN_REVOKED:
  85. case -NFS4ERR_BAD_STATEID:
  86. nfs_remove_bad_delegation(state->inode);
  87. case -NFS4ERR_OPENMODE:
  88. nfs4_schedule_stateid_recovery(mds_server, state);
  89. goto wait_on_recovery;
  90. case -NFS4ERR_EXPIRED:
  91. nfs4_schedule_stateid_recovery(mds_server, state);
  92. nfs4_schedule_lease_recovery(mds_client);
  93. goto wait_on_recovery;
  94. /* DS session errors */
  95. case -NFS4ERR_BADSESSION:
  96. case -NFS4ERR_BADSLOT:
  97. case -NFS4ERR_BAD_HIGH_SLOT:
  98. case -NFS4ERR_DEADSESSION:
  99. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  100. case -NFS4ERR_SEQ_FALSE_RETRY:
  101. case -NFS4ERR_SEQ_MISORDERED:
  102. dprintk("%s ERROR %d, Reset session. Exchangeid "
  103. "flags 0x%x\n", __func__, task->tk_status,
  104. clp->cl_exchange_flags);
  105. nfs4_schedule_session_recovery(clp->cl_session);
  106. break;
  107. case -NFS4ERR_DELAY:
  108. case -NFS4ERR_GRACE:
  109. case -EKEYEXPIRED:
  110. rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX);
  111. break;
  112. case -NFS4ERR_RETRY_UNCACHED_REP:
  113. break;
  114. default:
  115. dprintk("%s DS error. Retry through MDS %d\n", __func__,
  116. task->tk_status);
  117. *reset = 1;
  118. break;
  119. }
  120. out:
  121. task->tk_status = 0;
  122. return -EAGAIN;
  123. wait_on_recovery:
  124. rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
  125. if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
  126. rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
  127. goto out;
  128. }
  129. /* NFS_PROTO call done callback routines */
  130. static int filelayout_read_done_cb(struct rpc_task *task,
  131. struct nfs_read_data *data)
  132. {
  133. struct nfs_pgio_header *hdr = data->header;
  134. int reset = 0;
  135. dprintk("%s DS read\n", __func__);
  136. if (filelayout_async_handle_error(task, data->args.context->state,
  137. data->ds_clp, &reset) == -EAGAIN) {
  138. dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
  139. __func__, data->ds_clp, data->ds_clp->cl_session);
  140. if (reset) {
  141. pnfs_set_lo_fail(hdr->lseg);
  142. nfs4_reset_read(task, data);
  143. }
  144. rpc_restart_call_prepare(task);
  145. return -EAGAIN;
  146. }
  147. return 0;
  148. }
  149. /*
  150. * We reference the rpc_cred of the first WRITE that triggers the need for
  151. * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
  152. * rfc5661 is not clear about which credential should be used.
  153. */
  154. static void
  155. filelayout_set_layoutcommit(struct nfs_write_data *wdata)
  156. {
  157. struct nfs_pgio_header *hdr = wdata->header;
  158. if (FILELAYOUT_LSEG(hdr->lseg)->commit_through_mds ||
  159. wdata->res.verf->committed == NFS_FILE_SYNC)
  160. return;
  161. pnfs_set_layoutcommit(wdata);
  162. dprintk("%s ionde %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino,
  163. (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb);
  164. }
  165. /*
  166. * Call ops for the async read/write cases
  167. * In the case of dense layouts, the offset needs to be reset to its
  168. * original value.
  169. */
  170. static void filelayout_read_prepare(struct rpc_task *task, void *data)
  171. {
  172. struct nfs_read_data *rdata = data;
  173. rdata->read_done_cb = filelayout_read_done_cb;
  174. if (nfs41_setup_sequence(rdata->ds_clp->cl_session,
  175. &rdata->args.seq_args, &rdata->res.seq_res,
  176. task))
  177. return;
  178. rpc_call_start(task);
  179. }
  180. static void filelayout_read_call_done(struct rpc_task *task, void *data)
  181. {
  182. struct nfs_read_data *rdata = data;
  183. dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
  184. /* Note this may cause RPC to be resent */
  185. rdata->header->mds_ops->rpc_call_done(task, data);
  186. }
  187. static void filelayout_read_count_stats(struct rpc_task *task, void *data)
  188. {
  189. struct nfs_read_data *rdata = data;
  190. rpc_count_iostats(task, NFS_SERVER(rdata->header->inode)->client->cl_metrics);
  191. }
  192. static void filelayout_read_release(void *data)
  193. {
  194. struct nfs_read_data *rdata = data;
  195. rdata->header->mds_ops->rpc_release(data);
  196. }
  197. static int filelayout_write_done_cb(struct rpc_task *task,
  198. struct nfs_write_data *data)
  199. {
  200. struct nfs_pgio_header *hdr = data->header;
  201. int reset = 0;
  202. if (filelayout_async_handle_error(task, data->args.context->state,
  203. data->ds_clp, &reset) == -EAGAIN) {
  204. dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
  205. __func__, data->ds_clp, data->ds_clp->cl_session);
  206. if (reset) {
  207. pnfs_set_lo_fail(hdr->lseg);
  208. nfs4_reset_write(task, data);
  209. }
  210. rpc_restart_call_prepare(task);
  211. return -EAGAIN;
  212. }
  213. filelayout_set_layoutcommit(data);
  214. return 0;
  215. }
  216. /* Fake up some data that will cause nfs_commit_release to retry the writes. */
  217. static void prepare_to_resend_writes(struct nfs_commit_data *data)
  218. {
  219. struct nfs_page *first = nfs_list_entry(data->pages.next);
  220. data->task.tk_status = 0;
  221. memcpy(data->verf.verifier, first->wb_verf.verifier,
  222. sizeof(first->wb_verf.verifier));
  223. data->verf.verifier[0]++; /* ensure verifier mismatch */
  224. }
  225. static int filelayout_commit_done_cb(struct rpc_task *task,
  226. struct nfs_commit_data *data)
  227. {
  228. int reset = 0;
  229. if (filelayout_async_handle_error(task, data->context->state,
  230. data->ds_clp, &reset) == -EAGAIN) {
  231. dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
  232. __func__, data->ds_clp, data->ds_clp->cl_session);
  233. if (reset) {
  234. prepare_to_resend_writes(data);
  235. pnfs_set_lo_fail(data->lseg);
  236. } else
  237. rpc_restart_call_prepare(task);
  238. return -EAGAIN;
  239. }
  240. return 0;
  241. }
  242. static void filelayout_write_prepare(struct rpc_task *task, void *data)
  243. {
  244. struct nfs_write_data *wdata = data;
  245. if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
  246. &wdata->args.seq_args, &wdata->res.seq_res,
  247. task))
  248. return;
  249. rpc_call_start(task);
  250. }
  251. static void filelayout_write_call_done(struct rpc_task *task, void *data)
  252. {
  253. struct nfs_write_data *wdata = data;
  254. /* Note this may cause RPC to be resent */
  255. wdata->header->mds_ops->rpc_call_done(task, data);
  256. }
  257. static void filelayout_write_count_stats(struct rpc_task *task, void *data)
  258. {
  259. struct nfs_write_data *wdata = data;
  260. rpc_count_iostats(task, NFS_SERVER(wdata->header->inode)->client->cl_metrics);
  261. }
  262. static void filelayout_write_release(void *data)
  263. {
  264. struct nfs_write_data *wdata = data;
  265. wdata->header->mds_ops->rpc_release(data);
  266. }
  267. static void filelayout_commit_prepare(struct rpc_task *task, void *data)
  268. {
  269. struct nfs_commit_data *wdata = data;
  270. if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
  271. &wdata->args.seq_args, &wdata->res.seq_res,
  272. task))
  273. return;
  274. rpc_call_start(task);
  275. }
  276. static void filelayout_write_commit_done(struct rpc_task *task, void *data)
  277. {
  278. struct nfs_commit_data *wdata = data;
  279. /* Note this may cause RPC to be resent */
  280. wdata->mds_ops->rpc_call_done(task, data);
  281. }
  282. static void filelayout_commit_count_stats(struct rpc_task *task, void *data)
  283. {
  284. struct nfs_commit_data *cdata = data;
  285. rpc_count_iostats(task, NFS_SERVER(cdata->inode)->client->cl_metrics);
  286. }
  287. static void filelayout_commit_release(void *calldata)
  288. {
  289. struct nfs_commit_data *data = calldata;
  290. data->completion_ops->completion(data);
  291. put_lseg(data->lseg);
  292. nfs_commitdata_release(data);
  293. }
  294. static const struct rpc_call_ops filelayout_read_call_ops = {
  295. .rpc_call_prepare = filelayout_read_prepare,
  296. .rpc_call_done = filelayout_read_call_done,
  297. .rpc_count_stats = filelayout_read_count_stats,
  298. .rpc_release = filelayout_read_release,
  299. };
  300. static const struct rpc_call_ops filelayout_write_call_ops = {
  301. .rpc_call_prepare = filelayout_write_prepare,
  302. .rpc_call_done = filelayout_write_call_done,
  303. .rpc_count_stats = filelayout_write_count_stats,
  304. .rpc_release = filelayout_write_release,
  305. };
  306. static const struct rpc_call_ops filelayout_commit_call_ops = {
  307. .rpc_call_prepare = filelayout_commit_prepare,
  308. .rpc_call_done = filelayout_write_commit_done,
  309. .rpc_count_stats = filelayout_commit_count_stats,
  310. .rpc_release = filelayout_commit_release,
  311. };
  312. static enum pnfs_try_status
  313. filelayout_read_pagelist(struct nfs_read_data *data)
  314. {
  315. struct nfs_pgio_header *hdr = data->header;
  316. struct pnfs_layout_segment *lseg = hdr->lseg;
  317. struct nfs4_pnfs_ds *ds;
  318. loff_t offset = data->args.offset;
  319. u32 j, idx;
  320. struct nfs_fh *fh;
  321. int status;
  322. dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
  323. __func__, hdr->inode->i_ino,
  324. data->args.pgbase, (size_t)data->args.count, offset);
  325. if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags))
  326. return PNFS_NOT_ATTEMPTED;
  327. /* Retrieve the correct rpc_client for the byte range */
  328. j = nfs4_fl_calc_j_index(lseg, offset);
  329. idx = nfs4_fl_calc_ds_index(lseg, j);
  330. ds = nfs4_fl_prepare_ds(lseg, idx);
  331. if (!ds) {
  332. /* Either layout fh index faulty, or ds connect failed */
  333. set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
  334. set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
  335. return PNFS_NOT_ATTEMPTED;
  336. }
  337. dprintk("%s USE DS: %s\n", __func__, ds->ds_remotestr);
  338. /* No multipath support. Use first DS */
  339. data->ds_clp = ds->ds_clp;
  340. fh = nfs4_fl_select_ds_fh(lseg, j);
  341. if (fh)
  342. data->args.fh = fh;
  343. data->args.offset = filelayout_get_dserver_offset(lseg, offset);
  344. data->mds_offset = offset;
  345. /* Perform an asynchronous read to ds */
  346. status = nfs_initiate_read(ds->ds_clp->cl_rpcclient, data,
  347. &filelayout_read_call_ops);
  348. BUG_ON(status != 0);
  349. return PNFS_ATTEMPTED;
  350. }
  351. /* Perform async writes. */
  352. static enum pnfs_try_status
  353. filelayout_write_pagelist(struct nfs_write_data *data, int sync)
  354. {
  355. struct nfs_pgio_header *hdr = data->header;
  356. struct pnfs_layout_segment *lseg = hdr->lseg;
  357. struct nfs4_pnfs_ds *ds;
  358. loff_t offset = data->args.offset;
  359. u32 j, idx;
  360. struct nfs_fh *fh;
  361. int status;
  362. if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags))
  363. return PNFS_NOT_ATTEMPTED;
  364. /* Retrieve the correct rpc_client for the byte range */
  365. j = nfs4_fl_calc_j_index(lseg, offset);
  366. idx = nfs4_fl_calc_ds_index(lseg, j);
  367. ds = nfs4_fl_prepare_ds(lseg, idx);
  368. if (!ds) {
  369. printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
  370. __func__);
  371. set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
  372. set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
  373. return PNFS_NOT_ATTEMPTED;
  374. }
  375. dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s\n", __func__,
  376. hdr->inode->i_ino, sync, (size_t) data->args.count, offset,
  377. ds->ds_remotestr);
  378. data->write_done_cb = filelayout_write_done_cb;
  379. data->ds_clp = ds->ds_clp;
  380. fh = nfs4_fl_select_ds_fh(lseg, j);
  381. if (fh)
  382. data->args.fh = fh;
  383. /*
  384. * Get the file offset on the dserver. Set the write offset to
  385. * this offset and save the original offset.
  386. */
  387. data->args.offset = filelayout_get_dserver_offset(lseg, offset);
  388. /* Perform an asynchronous write */
  389. status = nfs_initiate_write(ds->ds_clp->cl_rpcclient, data,
  390. &filelayout_write_call_ops, sync);
  391. BUG_ON(status != 0);
  392. return PNFS_ATTEMPTED;
  393. }
  394. /*
  395. * filelayout_check_layout()
  396. *
  397. * Make sure layout segment parameters are sane WRT the device.
  398. * At this point no generic layer initialization of the lseg has occurred,
  399. * and nothing has been added to the layout_hdr cache.
  400. *
  401. */
  402. static int
  403. filelayout_check_layout(struct pnfs_layout_hdr *lo,
  404. struct nfs4_filelayout_segment *fl,
  405. struct nfs4_layoutget_res *lgr,
  406. struct nfs4_deviceid *id,
  407. gfp_t gfp_flags)
  408. {
  409. struct nfs4_deviceid_node *d;
  410. struct nfs4_file_layout_dsaddr *dsaddr;
  411. int status = -EINVAL;
  412. struct nfs_server *nfss = NFS_SERVER(lo->plh_inode);
  413. dprintk("--> %s\n", __func__);
  414. /* FIXME: remove this check when layout segment support is added */
  415. if (lgr->range.offset != 0 ||
  416. lgr->range.length != NFS4_MAX_UINT64) {
  417. dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
  418. __func__);
  419. goto out;
  420. }
  421. if (fl->pattern_offset > lgr->range.offset) {
  422. dprintk("%s pattern_offset %lld too large\n",
  423. __func__, fl->pattern_offset);
  424. goto out;
  425. }
  426. if (!fl->stripe_unit || fl->stripe_unit % PAGE_SIZE) {
  427. dprintk("%s Invalid stripe unit (%u)\n",
  428. __func__, fl->stripe_unit);
  429. goto out;
  430. }
  431. /* find and reference the deviceid */
  432. d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode)->pnfs_curr_ld,
  433. NFS_SERVER(lo->plh_inode)->nfs_client, id);
  434. if (d == NULL) {
  435. dsaddr = get_device_info(lo->plh_inode, id, gfp_flags);
  436. if (dsaddr == NULL)
  437. goto out;
  438. } else
  439. dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
  440. /* Found deviceid is being reaped */
  441. if (test_bit(NFS_DEVICEID_INVALID, &dsaddr->id_node.flags))
  442. goto out_put;
  443. fl->dsaddr = dsaddr;
  444. if (fl->first_stripe_index >= dsaddr->stripe_count) {
  445. dprintk("%s Bad first_stripe_index %u\n",
  446. __func__, fl->first_stripe_index);
  447. goto out_put;
  448. }
  449. if ((fl->stripe_type == STRIPE_SPARSE &&
  450. fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
  451. (fl->stripe_type == STRIPE_DENSE &&
  452. fl->num_fh != dsaddr->stripe_count)) {
  453. dprintk("%s num_fh %u not valid for given packing\n",
  454. __func__, fl->num_fh);
  455. goto out_put;
  456. }
  457. if (fl->stripe_unit % nfss->rsize || fl->stripe_unit % nfss->wsize) {
  458. dprintk("%s Stripe unit (%u) not aligned with rsize %u "
  459. "wsize %u\n", __func__, fl->stripe_unit, nfss->rsize,
  460. nfss->wsize);
  461. }
  462. status = 0;
  463. out:
  464. dprintk("--> %s returns %d\n", __func__, status);
  465. return status;
  466. out_put:
  467. nfs4_fl_put_deviceid(dsaddr);
  468. goto out;
  469. }
  470. static void filelayout_free_fh_array(struct nfs4_filelayout_segment *fl)
  471. {
  472. int i;
  473. for (i = 0; i < fl->num_fh; i++) {
  474. if (!fl->fh_array[i])
  475. break;
  476. kfree(fl->fh_array[i]);
  477. }
  478. kfree(fl->fh_array);
  479. fl->fh_array = NULL;
  480. }
  481. static void
  482. _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
  483. {
  484. filelayout_free_fh_array(fl);
  485. kfree(fl);
  486. }
  487. static int
  488. filelayout_decode_layout(struct pnfs_layout_hdr *flo,
  489. struct nfs4_filelayout_segment *fl,
  490. struct nfs4_layoutget_res *lgr,
  491. struct nfs4_deviceid *id,
  492. gfp_t gfp_flags)
  493. {
  494. struct xdr_stream stream;
  495. struct xdr_buf buf;
  496. struct page *scratch;
  497. __be32 *p;
  498. uint32_t nfl_util;
  499. int i;
  500. dprintk("%s: set_layout_map Begin\n", __func__);
  501. scratch = alloc_page(gfp_flags);
  502. if (!scratch)
  503. return -ENOMEM;
  504. xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
  505. xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
  506. /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
  507. * num_fh (4) */
  508. p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20);
  509. if (unlikely(!p))
  510. goto out_err;
  511. memcpy(id, p, sizeof(*id));
  512. p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
  513. nfs4_print_deviceid(id);
  514. nfl_util = be32_to_cpup(p++);
  515. if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
  516. fl->commit_through_mds = 1;
  517. if (nfl_util & NFL4_UFLG_DENSE)
  518. fl->stripe_type = STRIPE_DENSE;
  519. else
  520. fl->stripe_type = STRIPE_SPARSE;
  521. fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
  522. fl->first_stripe_index = be32_to_cpup(p++);
  523. p = xdr_decode_hyper(p, &fl->pattern_offset);
  524. fl->num_fh = be32_to_cpup(p++);
  525. dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
  526. __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
  527. fl->pattern_offset);
  528. /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
  529. * Futher checking is done in filelayout_check_layout */
  530. if (fl->num_fh >
  531. max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
  532. goto out_err;
  533. if (fl->num_fh > 0) {
  534. fl->fh_array = kzalloc(fl->num_fh * sizeof(struct nfs_fh *),
  535. gfp_flags);
  536. if (!fl->fh_array)
  537. goto out_err;
  538. }
  539. for (i = 0; i < fl->num_fh; i++) {
  540. /* Do we want to use a mempool here? */
  541. fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
  542. if (!fl->fh_array[i])
  543. goto out_err_free;
  544. p = xdr_inline_decode(&stream, 4);
  545. if (unlikely(!p))
  546. goto out_err_free;
  547. fl->fh_array[i]->size = be32_to_cpup(p++);
  548. if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
  549. printk(KERN_ERR "NFS: Too big fh %d received %d\n",
  550. i, fl->fh_array[i]->size);
  551. goto out_err_free;
  552. }
  553. p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
  554. if (unlikely(!p))
  555. goto out_err_free;
  556. memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
  557. dprintk("DEBUG: %s: fh len %d\n", __func__,
  558. fl->fh_array[i]->size);
  559. }
  560. __free_page(scratch);
  561. return 0;
  562. out_err_free:
  563. filelayout_free_fh_array(fl);
  564. out_err:
  565. __free_page(scratch);
  566. return -EIO;
  567. }
  568. static void
  569. filelayout_free_lseg(struct pnfs_layout_segment *lseg)
  570. {
  571. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  572. dprintk("--> %s\n", __func__);
  573. nfs4_fl_put_deviceid(fl->dsaddr);
  574. /* This assumes a single RW lseg */
  575. if (lseg->pls_range.iomode == IOMODE_RW) {
  576. struct nfs4_filelayout *flo;
  577. flo = FILELAYOUT_FROM_HDR(lseg->pls_layout);
  578. flo->commit_info.nbuckets = 0;
  579. kfree(flo->commit_info.buckets);
  580. flo->commit_info.buckets = NULL;
  581. }
  582. _filelayout_free_lseg(fl);
  583. }
  584. static int
  585. filelayout_alloc_commit_info(struct pnfs_layout_segment *lseg,
  586. struct nfs_commit_info *cinfo,
  587. gfp_t gfp_flags)
  588. {
  589. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  590. struct pnfs_commit_bucket *buckets;
  591. int size;
  592. if (fl->commit_through_mds)
  593. return 0;
  594. if (cinfo->ds->nbuckets != 0) {
  595. /* This assumes there is only one IOMODE_RW lseg. What
  596. * we really want to do is have a layout_hdr level
  597. * dictionary of <multipath_list4, fh> keys, each
  598. * associated with a struct list_head, populated by calls
  599. * to filelayout_write_pagelist().
  600. * */
  601. return 0;
  602. }
  603. size = (fl->stripe_type == STRIPE_SPARSE) ?
  604. fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
  605. buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
  606. gfp_flags);
  607. if (!buckets)
  608. return -ENOMEM;
  609. else {
  610. int i;
  611. spin_lock(cinfo->lock);
  612. if (cinfo->ds->nbuckets != 0)
  613. kfree(buckets);
  614. else {
  615. cinfo->ds->buckets = buckets;
  616. cinfo->ds->nbuckets = size;
  617. for (i = 0; i < size; i++) {
  618. INIT_LIST_HEAD(&buckets[i].written);
  619. INIT_LIST_HEAD(&buckets[i].committing);
  620. }
  621. }
  622. spin_unlock(cinfo->lock);
  623. return 0;
  624. }
  625. }
  626. static struct pnfs_layout_segment *
  627. filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
  628. struct nfs4_layoutget_res *lgr,
  629. gfp_t gfp_flags)
  630. {
  631. struct nfs4_filelayout_segment *fl;
  632. int rc;
  633. struct nfs4_deviceid id;
  634. dprintk("--> %s\n", __func__);
  635. fl = kzalloc(sizeof(*fl), gfp_flags);
  636. if (!fl)
  637. return NULL;
  638. rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags);
  639. if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) {
  640. _filelayout_free_lseg(fl);
  641. return NULL;
  642. }
  643. return &fl->generic_hdr;
  644. }
  645. /*
  646. * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
  647. *
  648. * return true : coalesce page
  649. * return false : don't coalesce page
  650. */
  651. static bool
  652. filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
  653. struct nfs_page *req)
  654. {
  655. u64 p_stripe, r_stripe;
  656. u32 stripe_unit;
  657. if (!pnfs_generic_pg_test(pgio, prev, req) ||
  658. !nfs_generic_pg_test(pgio, prev, req))
  659. return false;
  660. p_stripe = (u64)req_offset(prev);
  661. r_stripe = (u64)req_offset(req);
  662. stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
  663. do_div(p_stripe, stripe_unit);
  664. do_div(r_stripe, stripe_unit);
  665. return (p_stripe == r_stripe);
  666. }
  667. static void
  668. filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
  669. struct nfs_page *req)
  670. {
  671. BUG_ON(pgio->pg_lseg != NULL);
  672. if (req->wb_offset != req->wb_pgbase) {
  673. /*
  674. * Handling unaligned pages is difficult, because have to
  675. * somehow split a req in two in certain cases in the
  676. * pg.test code. Avoid this by just not using pnfs
  677. * in this case.
  678. */
  679. nfs_pageio_reset_read_mds(pgio);
  680. return;
  681. }
  682. pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
  683. req->wb_context,
  684. 0,
  685. NFS4_MAX_UINT64,
  686. IOMODE_READ,
  687. GFP_KERNEL);
  688. /* If no lseg, fall back to read through mds */
  689. if (pgio->pg_lseg == NULL)
  690. nfs_pageio_reset_read_mds(pgio);
  691. }
  692. static void
  693. filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
  694. struct nfs_page *req)
  695. {
  696. struct nfs_commit_info cinfo;
  697. int status;
  698. BUG_ON(pgio->pg_lseg != NULL);
  699. if (req->wb_offset != req->wb_pgbase)
  700. goto out_mds;
  701. pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
  702. req->wb_context,
  703. 0,
  704. NFS4_MAX_UINT64,
  705. IOMODE_RW,
  706. GFP_NOFS);
  707. /* If no lseg, fall back to write through mds */
  708. if (pgio->pg_lseg == NULL)
  709. goto out_mds;
  710. nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
  711. status = filelayout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
  712. if (status < 0) {
  713. put_lseg(pgio->pg_lseg);
  714. pgio->pg_lseg = NULL;
  715. goto out_mds;
  716. }
  717. return;
  718. out_mds:
  719. nfs_pageio_reset_write_mds(pgio);
  720. }
  721. static const struct nfs_pageio_ops filelayout_pg_read_ops = {
  722. .pg_init = filelayout_pg_init_read,
  723. .pg_test = filelayout_pg_test,
  724. .pg_doio = pnfs_generic_pg_readpages,
  725. };
  726. static const struct nfs_pageio_ops filelayout_pg_write_ops = {
  727. .pg_init = filelayout_pg_init_write,
  728. .pg_test = filelayout_pg_test,
  729. .pg_doio = pnfs_generic_pg_writepages,
  730. };
  731. static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
  732. {
  733. if (fl->stripe_type == STRIPE_SPARSE)
  734. return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
  735. else
  736. return j;
  737. }
  738. /* The generic layer is about to remove the req from the commit list.
  739. * If this will make the bucket empty, it will need to put the lseg reference.
  740. */
  741. static void
  742. filelayout_clear_request_commit(struct nfs_page *req,
  743. struct nfs_commit_info *cinfo)
  744. {
  745. struct pnfs_layout_segment *freeme = NULL;
  746. spin_lock(cinfo->lock);
  747. if (!test_and_clear_bit(PG_COMMIT_TO_DS, &req->wb_flags))
  748. goto out;
  749. cinfo->ds->nwritten--;
  750. if (list_is_singular(&req->wb_list)) {
  751. struct pnfs_commit_bucket *bucket;
  752. bucket = list_first_entry(&req->wb_list,
  753. struct pnfs_commit_bucket,
  754. written);
  755. freeme = bucket->wlseg;
  756. bucket->wlseg = NULL;
  757. }
  758. out:
  759. nfs_request_remove_commit_list(req, cinfo);
  760. spin_unlock(cinfo->lock);
  761. put_lseg(freeme);
  762. }
  763. static struct list_head *
  764. filelayout_choose_commit_list(struct nfs_page *req,
  765. struct pnfs_layout_segment *lseg,
  766. struct nfs_commit_info *cinfo)
  767. {
  768. struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
  769. u32 i, j;
  770. struct list_head *list;
  771. struct pnfs_commit_bucket *buckets;
  772. if (fl->commit_through_mds)
  773. return &cinfo->mds->list;
  774. /* Note that we are calling nfs4_fl_calc_j_index on each page
  775. * that ends up being committed to a data server. An attractive
  776. * alternative is to add a field to nfs_write_data and nfs_page
  777. * to store the value calculated in filelayout_write_pagelist
  778. * and just use that here.
  779. */
  780. j = nfs4_fl_calc_j_index(lseg, req_offset(req));
  781. i = select_bucket_index(fl, j);
  782. buckets = cinfo->ds->buckets;
  783. list = &buckets[i].written;
  784. if (list_empty(list)) {
  785. /* Non-empty buckets hold a reference on the lseg. That ref
  786. * is normally transferred to the COMMIT call and released
  787. * there. It could also be released if the last req is pulled
  788. * off due to a rewrite, in which case it will be done in
  789. * filelayout_clear_request_commit
  790. */
  791. buckets[i].wlseg = get_lseg(lseg);
  792. }
  793. set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
  794. cinfo->ds->nwritten++;
  795. return list;
  796. }
  797. static void
  798. filelayout_mark_request_commit(struct nfs_page *req,
  799. struct pnfs_layout_segment *lseg,
  800. struct nfs_commit_info *cinfo)
  801. {
  802. struct list_head *list;
  803. list = filelayout_choose_commit_list(req, lseg, cinfo);
  804. nfs_request_add_commit_list(req, list, cinfo);
  805. }
  806. static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
  807. {
  808. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  809. if (flseg->stripe_type == STRIPE_SPARSE)
  810. return i;
  811. else
  812. return nfs4_fl_calc_ds_index(lseg, i);
  813. }
  814. static struct nfs_fh *
  815. select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
  816. {
  817. struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
  818. if (flseg->stripe_type == STRIPE_SPARSE) {
  819. if (flseg->num_fh == 1)
  820. i = 0;
  821. else if (flseg->num_fh == 0)
  822. /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
  823. return NULL;
  824. }
  825. return flseg->fh_array[i];
  826. }
  827. static int filelayout_initiate_commit(struct nfs_commit_data *data, int how)
  828. {
  829. struct pnfs_layout_segment *lseg = data->lseg;
  830. struct nfs4_pnfs_ds *ds;
  831. u32 idx;
  832. struct nfs_fh *fh;
  833. idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
  834. ds = nfs4_fl_prepare_ds(lseg, idx);
  835. if (!ds) {
  836. printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
  837. __func__);
  838. set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
  839. set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
  840. prepare_to_resend_writes(data);
  841. filelayout_commit_release(data);
  842. return -EAGAIN;
  843. }
  844. dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how);
  845. data->commit_done_cb = filelayout_commit_done_cb;
  846. data->ds_clp = ds->ds_clp;
  847. fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
  848. if (fh)
  849. data->args.fh = fh;
  850. return nfs_initiate_commit(ds->ds_clp->cl_rpcclient, data,
  851. &filelayout_commit_call_ops, how);
  852. }
  853. static int
  854. transfer_commit_list(struct list_head *src, struct list_head *dst,
  855. struct nfs_commit_info *cinfo, int max)
  856. {
  857. struct nfs_page *req, *tmp;
  858. int ret = 0;
  859. list_for_each_entry_safe(req, tmp, src, wb_list) {
  860. if (!nfs_lock_request(req))
  861. continue;
  862. if (cond_resched_lock(cinfo->lock))
  863. list_safe_reset_next(req, tmp, wb_list);
  864. nfs_request_remove_commit_list(req, cinfo);
  865. clear_bit(PG_COMMIT_TO_DS, &req->wb_flags);
  866. nfs_list_add_request(req, dst);
  867. ret++;
  868. if ((ret == max) && !cinfo->dreq)
  869. break;
  870. }
  871. return ret;
  872. }
  873. static int
  874. filelayout_scan_ds_commit_list(struct pnfs_commit_bucket *bucket,
  875. struct nfs_commit_info *cinfo,
  876. int max)
  877. {
  878. struct list_head *src = &bucket->written;
  879. struct list_head *dst = &bucket->committing;
  880. int ret;
  881. ret = transfer_commit_list(src, dst, cinfo, max);
  882. if (ret) {
  883. cinfo->ds->nwritten -= ret;
  884. cinfo->ds->ncommitting += ret;
  885. bucket->clseg = bucket->wlseg;
  886. if (list_empty(src))
  887. bucket->wlseg = NULL;
  888. else
  889. get_lseg(bucket->clseg);
  890. }
  891. return ret;
  892. }
  893. /* Move reqs from written to committing lists, returning count of number moved.
  894. * Note called with cinfo->lock held.
  895. */
  896. static int filelayout_scan_commit_lists(struct nfs_commit_info *cinfo,
  897. int max)
  898. {
  899. int i, rv = 0, cnt;
  900. for (i = 0; i < cinfo->ds->nbuckets && max != 0; i++) {
  901. cnt = filelayout_scan_ds_commit_list(&cinfo->ds->buckets[i],
  902. cinfo, max);
  903. max -= cnt;
  904. rv += cnt;
  905. }
  906. return rv;
  907. }
  908. /* Pull everything off the committing lists and dump into @dst */
  909. static void filelayout_recover_commit_reqs(struct list_head *dst,
  910. struct nfs_commit_info *cinfo)
  911. {
  912. struct pnfs_commit_bucket *b;
  913. int i;
  914. /* NOTE cinfo->lock is NOT held, relying on fact that this is
  915. * only called on single thread per dreq.
  916. * Can't take the lock because need to do put_lseg
  917. */
  918. for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) {
  919. if (transfer_commit_list(&b->written, dst, cinfo, 0)) {
  920. BUG_ON(!list_empty(&b->written));
  921. put_lseg(b->wlseg);
  922. b->wlseg = NULL;
  923. }
  924. }
  925. cinfo->ds->nwritten = 0;
  926. }
  927. static unsigned int
  928. alloc_ds_commits(struct nfs_commit_info *cinfo, struct list_head *list)
  929. {
  930. struct pnfs_ds_commit_info *fl_cinfo;
  931. struct pnfs_commit_bucket *bucket;
  932. struct nfs_commit_data *data;
  933. int i, j;
  934. unsigned int nreq = 0;
  935. fl_cinfo = cinfo->ds;
  936. bucket = fl_cinfo->buckets;
  937. for (i = 0; i < fl_cinfo->nbuckets; i++, bucket++) {
  938. if (list_empty(&bucket->committing))
  939. continue;
  940. data = nfs_commitdata_alloc();
  941. if (!data)
  942. break;
  943. data->ds_commit_index = i;
  944. data->lseg = bucket->clseg;
  945. bucket->clseg = NULL;
  946. list_add(&data->pages, list);
  947. nreq++;
  948. }
  949. /* Clean up on error */
  950. for (j = i; j < fl_cinfo->nbuckets; j++, bucket++) {
  951. if (list_empty(&bucket->committing))
  952. continue;
  953. nfs_retry_commit(&bucket->committing, bucket->clseg, cinfo);
  954. put_lseg(bucket->clseg);
  955. bucket->clseg = NULL;
  956. }
  957. /* Caller will clean up entries put on list */
  958. return nreq;
  959. }
  960. /* This follows nfs_commit_list pretty closely */
  961. static int
  962. filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
  963. int how, struct nfs_commit_info *cinfo)
  964. {
  965. struct nfs_commit_data *data, *tmp;
  966. LIST_HEAD(list);
  967. unsigned int nreq = 0;
  968. if (!list_empty(mds_pages)) {
  969. data = nfs_commitdata_alloc();
  970. if (data != NULL) {
  971. data->lseg = NULL;
  972. list_add(&data->pages, &list);
  973. nreq++;
  974. } else
  975. nfs_retry_commit(mds_pages, NULL, cinfo);
  976. }
  977. nreq += alloc_ds_commits(cinfo, &list);
  978. if (nreq == 0) {
  979. cinfo->completion_ops->error_cleanup(NFS_I(inode));
  980. goto out;
  981. }
  982. atomic_add(nreq, &cinfo->mds->rpcs_out);
  983. list_for_each_entry_safe(data, tmp, &list, pages) {
  984. list_del_init(&data->pages);
  985. if (!data->lseg) {
  986. nfs_init_commit(data, mds_pages, NULL, cinfo);
  987. nfs_initiate_commit(NFS_CLIENT(inode), data,
  988. data->mds_ops, how);
  989. } else {
  990. struct pnfs_commit_bucket *buckets;
  991. buckets = cinfo->ds->buckets;
  992. nfs_init_commit(data, &buckets[data->ds_commit_index].committing, data->lseg, cinfo);
  993. filelayout_initiate_commit(data, how);
  994. }
  995. }
  996. out:
  997. cinfo->ds->ncommitting = 0;
  998. return PNFS_ATTEMPTED;
  999. }
  1000. static void
  1001. filelayout_free_deveiceid_node(struct nfs4_deviceid_node *d)
  1002. {
  1003. nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
  1004. }
  1005. static struct pnfs_layout_hdr *
  1006. filelayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
  1007. {
  1008. struct nfs4_filelayout *flo;
  1009. flo = kzalloc(sizeof(*flo), gfp_flags);
  1010. return &flo->generic_hdr;
  1011. }
  1012. static void
  1013. filelayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
  1014. {
  1015. kfree(FILELAYOUT_FROM_HDR(lo));
  1016. }
  1017. static struct pnfs_ds_commit_info *
  1018. filelayout_get_ds_info(struct inode *inode)
  1019. {
  1020. struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
  1021. if (layout == NULL)
  1022. return NULL;
  1023. else
  1024. return &FILELAYOUT_FROM_HDR(layout)->commit_info;
  1025. }
  1026. static struct pnfs_layoutdriver_type filelayout_type = {
  1027. .id = LAYOUT_NFSV4_1_FILES,
  1028. .name = "LAYOUT_NFSV4_1_FILES",
  1029. .owner = THIS_MODULE,
  1030. .alloc_layout_hdr = filelayout_alloc_layout_hdr,
  1031. .free_layout_hdr = filelayout_free_layout_hdr,
  1032. .alloc_lseg = filelayout_alloc_lseg,
  1033. .free_lseg = filelayout_free_lseg,
  1034. .pg_read_ops = &filelayout_pg_read_ops,
  1035. .pg_write_ops = &filelayout_pg_write_ops,
  1036. .get_ds_info = &filelayout_get_ds_info,
  1037. .mark_request_commit = filelayout_mark_request_commit,
  1038. .clear_request_commit = filelayout_clear_request_commit,
  1039. .scan_commit_lists = filelayout_scan_commit_lists,
  1040. .recover_commit_reqs = filelayout_recover_commit_reqs,
  1041. .commit_pagelist = filelayout_commit_pagelist,
  1042. .read_pagelist = filelayout_read_pagelist,
  1043. .write_pagelist = filelayout_write_pagelist,
  1044. .free_deviceid_node = filelayout_free_deveiceid_node,
  1045. };
  1046. static int __init nfs4filelayout_init(void)
  1047. {
  1048. printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
  1049. __func__);
  1050. return pnfs_register_layoutdriver(&filelayout_type);
  1051. }
  1052. static void __exit nfs4filelayout_exit(void)
  1053. {
  1054. printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
  1055. __func__);
  1056. pnfs_unregister_layoutdriver(&filelayout_type);
  1057. }
  1058. MODULE_ALIAS("nfs-layouttype4-1");
  1059. module_init(nfs4filelayout_init);
  1060. module_exit(nfs4filelayout_exit);