flexfilelayout.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329
  1. /*
  2. * Module for pnfs flexfile layout driver.
  3. *
  4. * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
  5. *
  6. * Tao Peng <bergwolf@primarydata.com>
  7. */
  8. #include <linux/nfs_fs.h>
  9. #include <linux/nfs_page.h>
  10. #include <linux/module.h>
  11. #include <linux/sunrpc/metrics.h>
  12. #include "flexfilelayout.h"
  13. #include "../nfs4session.h"
  14. #include "../nfs4idmap.h"
  15. #include "../internal.h"
  16. #include "../delegation.h"
  17. #include "../nfs4trace.h"
  18. #include "../iostat.h"
  19. #include "../nfs.h"
  20. #include "../nfs42.h"
  21. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  22. #define FF_LAYOUT_POLL_RETRY_MAX (15*HZ)
  23. static struct group_info *ff_zero_group;
  24. static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,
  25. struct nfs_pgio_header *hdr);
  26. static struct pnfs_layout_hdr *
  27. ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
  28. {
  29. struct nfs4_flexfile_layout *ffl;
  30. ffl = kzalloc(sizeof(*ffl), gfp_flags);
  31. if (ffl) {
  32. INIT_LIST_HEAD(&ffl->error_list);
  33. INIT_LIST_HEAD(&ffl->mirrors);
  34. ffl->last_report_time = ktime_get();
  35. return &ffl->generic_hdr;
  36. } else
  37. return NULL;
  38. }
  39. static void
  40. ff_layout_free_layout_hdr(struct pnfs_layout_hdr *lo)
  41. {
  42. struct nfs4_ff_layout_ds_err *err, *n;
  43. list_for_each_entry_safe(err, n, &FF_LAYOUT_FROM_HDR(lo)->error_list,
  44. list) {
  45. list_del(&err->list);
  46. kfree(err);
  47. }
  48. kfree(FF_LAYOUT_FROM_HDR(lo));
  49. }
  50. static int decode_pnfs_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  51. {
  52. __be32 *p;
  53. p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE);
  54. if (unlikely(p == NULL))
  55. return -ENOBUFS;
  56. stateid->type = NFS4_PNFS_DS_STATEID_TYPE;
  57. memcpy(stateid->data, p, NFS4_STATEID_SIZE);
  58. dprintk("%s: stateid id= [%x%x%x%x]\n", __func__,
  59. p[0], p[1], p[2], p[3]);
  60. return 0;
  61. }
  62. static int decode_deviceid(struct xdr_stream *xdr, struct nfs4_deviceid *devid)
  63. {
  64. __be32 *p;
  65. p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE);
  66. if (unlikely(!p))
  67. return -ENOBUFS;
  68. memcpy(devid, p, NFS4_DEVICEID4_SIZE);
  69. nfs4_print_deviceid(devid);
  70. return 0;
  71. }
  72. static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
  73. {
  74. __be32 *p;
  75. p = xdr_inline_decode(xdr, 4);
  76. if (unlikely(!p))
  77. return -ENOBUFS;
  78. fh->size = be32_to_cpup(p++);
  79. if (fh->size > sizeof(struct nfs_fh)) {
  80. printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n",
  81. fh->size);
  82. return -EOVERFLOW;
  83. }
  84. /* fh.data */
  85. p = xdr_inline_decode(xdr, fh->size);
  86. if (unlikely(!p))
  87. return -ENOBUFS;
  88. memcpy(&fh->data, p, fh->size);
  89. dprintk("%s: fh len %d\n", __func__, fh->size);
  90. return 0;
  91. }
  92. /*
  93. * Currently only stringified uids and gids are accepted.
  94. * I.e., kerberos is not supported to the DSes, so no pricipals.
  95. *
  96. * That means that one common function will suffice, but when
  97. * principals are added, this should be split to accomodate
  98. * calls to both nfs_map_name_to_uid() and nfs_map_group_to_gid().
  99. */
  100. static int
  101. decode_name(struct xdr_stream *xdr, u32 *id)
  102. {
  103. __be32 *p;
  104. int len;
  105. /* opaque_length(4)*/
  106. p = xdr_inline_decode(xdr, 4);
  107. if (unlikely(!p))
  108. return -ENOBUFS;
  109. len = be32_to_cpup(p++);
  110. if (len < 0)
  111. return -EINVAL;
  112. dprintk("%s: len %u\n", __func__, len);
  113. /* opaque body */
  114. p = xdr_inline_decode(xdr, len);
  115. if (unlikely(!p))
  116. return -ENOBUFS;
  117. if (!nfs_map_string_to_numeric((char *)p, len, id))
  118. return -EINVAL;
  119. return 0;
  120. }
  121. static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror *m1,
  122. const struct nfs4_ff_layout_mirror *m2)
  123. {
  124. int i, j;
  125. if (m1->fh_versions_cnt != m2->fh_versions_cnt)
  126. return false;
  127. for (i = 0; i < m1->fh_versions_cnt; i++) {
  128. bool found_fh = false;
  129. for (j = 0; j < m2->fh_versions_cnt; j++) {
  130. if (nfs_compare_fh(&m1->fh_versions[i],
  131. &m2->fh_versions[j]) == 0) {
  132. found_fh = true;
  133. break;
  134. }
  135. }
  136. if (!found_fh)
  137. return false;
  138. }
  139. return true;
  140. }
  141. static struct nfs4_ff_layout_mirror *
  142. ff_layout_add_mirror(struct pnfs_layout_hdr *lo,
  143. struct nfs4_ff_layout_mirror *mirror)
  144. {
  145. struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
  146. struct nfs4_ff_layout_mirror *pos;
  147. struct inode *inode = lo->plh_inode;
  148. spin_lock(&inode->i_lock);
  149. list_for_each_entry(pos, &ff_layout->mirrors, mirrors) {
  150. if (mirror->mirror_ds != pos->mirror_ds)
  151. continue;
  152. if (!ff_mirror_match_fh(mirror, pos))
  153. continue;
  154. if (atomic_inc_not_zero(&pos->ref)) {
  155. spin_unlock(&inode->i_lock);
  156. return pos;
  157. }
  158. }
  159. list_add(&mirror->mirrors, &ff_layout->mirrors);
  160. mirror->layout = lo;
  161. spin_unlock(&inode->i_lock);
  162. return mirror;
  163. }
  164. static void
  165. ff_layout_remove_mirror(struct nfs4_ff_layout_mirror *mirror)
  166. {
  167. struct inode *inode;
  168. if (mirror->layout == NULL)
  169. return;
  170. inode = mirror->layout->plh_inode;
  171. spin_lock(&inode->i_lock);
  172. list_del(&mirror->mirrors);
  173. spin_unlock(&inode->i_lock);
  174. mirror->layout = NULL;
  175. }
  176. static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
  177. {
  178. struct nfs4_ff_layout_mirror *mirror;
  179. mirror = kzalloc(sizeof(*mirror), gfp_flags);
  180. if (mirror != NULL) {
  181. spin_lock_init(&mirror->lock);
  182. atomic_set(&mirror->ref, 1);
  183. INIT_LIST_HEAD(&mirror->mirrors);
  184. }
  185. return mirror;
  186. }
  187. static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
  188. {
  189. struct rpc_cred *cred;
  190. ff_layout_remove_mirror(mirror);
  191. kfree(mirror->fh_versions);
  192. cred = rcu_access_pointer(mirror->ro_cred);
  193. if (cred)
  194. put_rpccred(cred);
  195. cred = rcu_access_pointer(mirror->rw_cred);
  196. if (cred)
  197. put_rpccred(cred);
  198. nfs4_ff_layout_put_deviceid(mirror->mirror_ds);
  199. kfree(mirror);
  200. }
  201. static void ff_layout_put_mirror(struct nfs4_ff_layout_mirror *mirror)
  202. {
  203. if (mirror != NULL && atomic_dec_and_test(&mirror->ref))
  204. ff_layout_free_mirror(mirror);
  205. }
  206. static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment *fls)
  207. {
  208. int i;
  209. if (fls->mirror_array) {
  210. for (i = 0; i < fls->mirror_array_cnt; i++) {
  211. /* normally mirror_ds is freed in
  212. * .free_deviceid_node but we still do it here
  213. * for .alloc_lseg error path */
  214. ff_layout_put_mirror(fls->mirror_array[i]);
  215. }
  216. kfree(fls->mirror_array);
  217. fls->mirror_array = NULL;
  218. }
  219. }
  220. static int ff_layout_check_layout(struct nfs4_layoutget_res *lgr)
  221. {
  222. int ret = 0;
  223. dprintk("--> %s\n", __func__);
  224. /* FIXME: remove this check when layout segment support is added */
  225. if (lgr->range.offset != 0 ||
  226. lgr->range.length != NFS4_MAX_UINT64) {
  227. dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
  228. __func__);
  229. ret = -EINVAL;
  230. }
  231. dprintk("--> %s returns %d\n", __func__, ret);
  232. return ret;
  233. }
  234. static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls)
  235. {
  236. if (fls) {
  237. ff_layout_free_mirror_array(fls);
  238. kfree(fls);
  239. }
  240. }
  241. static bool
  242. ff_lseg_range_is_after(const struct pnfs_layout_range *l1,
  243. const struct pnfs_layout_range *l2)
  244. {
  245. u64 end1, end2;
  246. if (l1->iomode != l2->iomode)
  247. return l1->iomode != IOMODE_READ;
  248. end1 = pnfs_calc_offset_end(l1->offset, l1->length);
  249. end2 = pnfs_calc_offset_end(l2->offset, l2->length);
  250. if (end1 < l2->offset)
  251. return false;
  252. if (end2 < l1->offset)
  253. return true;
  254. return l2->offset <= l1->offset;
  255. }
  256. static bool
  257. ff_lseg_merge(struct pnfs_layout_segment *new,
  258. struct pnfs_layout_segment *old)
  259. {
  260. u64 new_end, old_end;
  261. if (test_bit(NFS_LSEG_LAYOUTRETURN, &old->pls_flags))
  262. return false;
  263. if (new->pls_range.iomode != old->pls_range.iomode)
  264. return false;
  265. old_end = pnfs_calc_offset_end(old->pls_range.offset,
  266. old->pls_range.length);
  267. if (old_end < new->pls_range.offset)
  268. return false;
  269. new_end = pnfs_calc_offset_end(new->pls_range.offset,
  270. new->pls_range.length);
  271. if (new_end < old->pls_range.offset)
  272. return false;
  273. /* Mergeable: copy info from 'old' to 'new' */
  274. if (new_end < old_end)
  275. new_end = old_end;
  276. if (new->pls_range.offset < old->pls_range.offset)
  277. new->pls_range.offset = old->pls_range.offset;
  278. new->pls_range.length = pnfs_calc_offset_length(new->pls_range.offset,
  279. new_end);
  280. if (test_bit(NFS_LSEG_ROC, &old->pls_flags))
  281. set_bit(NFS_LSEG_ROC, &new->pls_flags);
  282. return true;
  283. }
  284. static void
  285. ff_layout_add_lseg(struct pnfs_layout_hdr *lo,
  286. struct pnfs_layout_segment *lseg,
  287. struct list_head *free_me)
  288. {
  289. pnfs_generic_layout_insert_lseg(lo, lseg,
  290. ff_lseg_range_is_after,
  291. ff_lseg_merge,
  292. free_me);
  293. }
  294. static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment *fls)
  295. {
  296. int i, j;
  297. for (i = 0; i < fls->mirror_array_cnt - 1; i++) {
  298. for (j = i + 1; j < fls->mirror_array_cnt; j++)
  299. if (fls->mirror_array[i]->efficiency <
  300. fls->mirror_array[j]->efficiency)
  301. swap(fls->mirror_array[i],
  302. fls->mirror_array[j]);
  303. }
  304. }
  305. static void ff_layout_mark_devices_valid(struct nfs4_ff_layout_segment *fls)
  306. {
  307. struct nfs4_deviceid_node *node;
  308. int i;
  309. if (!(fls->flags & FF_FLAGS_NO_IO_THRU_MDS))
  310. return;
  311. for (i = 0; i < fls->mirror_array_cnt; i++) {
  312. node = &fls->mirror_array[i]->mirror_ds->id_node;
  313. clear_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
  314. }
  315. }
  316. static struct pnfs_layout_segment *
  317. ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
  318. struct nfs4_layoutget_res *lgr,
  319. gfp_t gfp_flags)
  320. {
  321. struct pnfs_layout_segment *ret;
  322. struct nfs4_ff_layout_segment *fls = NULL;
  323. struct xdr_stream stream;
  324. struct xdr_buf buf;
  325. struct page *scratch;
  326. u64 stripe_unit;
  327. u32 mirror_array_cnt;
  328. __be32 *p;
  329. int i, rc;
  330. dprintk("--> %s\n", __func__);
  331. scratch = alloc_page(gfp_flags);
  332. if (!scratch)
  333. return ERR_PTR(-ENOMEM);
  334. xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages,
  335. lgr->layoutp->len);
  336. xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
  337. /* stripe unit and mirror_array_cnt */
  338. rc = -EIO;
  339. p = xdr_inline_decode(&stream, 8 + 4);
  340. if (!p)
  341. goto out_err_free;
  342. p = xdr_decode_hyper(p, &stripe_unit);
  343. mirror_array_cnt = be32_to_cpup(p++);
  344. dprintk("%s: stripe_unit=%llu mirror_array_cnt=%u\n", __func__,
  345. stripe_unit, mirror_array_cnt);
  346. if (mirror_array_cnt > NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT ||
  347. mirror_array_cnt == 0)
  348. goto out_err_free;
  349. rc = -ENOMEM;
  350. fls = kzalloc(sizeof(*fls), gfp_flags);
  351. if (!fls)
  352. goto out_err_free;
  353. fls->mirror_array_cnt = mirror_array_cnt;
  354. fls->stripe_unit = stripe_unit;
  355. fls->mirror_array = kcalloc(fls->mirror_array_cnt,
  356. sizeof(fls->mirror_array[0]), gfp_flags);
  357. if (fls->mirror_array == NULL)
  358. goto out_err_free;
  359. for (i = 0; i < fls->mirror_array_cnt; i++) {
  360. struct nfs4_ff_layout_mirror *mirror;
  361. struct nfs4_deviceid devid;
  362. struct nfs4_deviceid_node *idnode;
  363. struct auth_cred acred = { .group_info = ff_zero_group };
  364. struct rpc_cred __rcu *cred;
  365. u32 ds_count, fh_count, id;
  366. int j;
  367. rc = -EIO;
  368. p = xdr_inline_decode(&stream, 4);
  369. if (!p)
  370. goto out_err_free;
  371. ds_count = be32_to_cpup(p);
  372. /* FIXME: allow for striping? */
  373. if (ds_count != 1)
  374. goto out_err_free;
  375. fls->mirror_array[i] = ff_layout_alloc_mirror(gfp_flags);
  376. if (fls->mirror_array[i] == NULL) {
  377. rc = -ENOMEM;
  378. goto out_err_free;
  379. }
  380. fls->mirror_array[i]->ds_count = ds_count;
  381. /* deviceid */
  382. rc = decode_deviceid(&stream, &devid);
  383. if (rc)
  384. goto out_err_free;
  385. idnode = nfs4_find_get_deviceid(NFS_SERVER(lh->plh_inode),
  386. &devid, lh->plh_lc_cred,
  387. gfp_flags);
  388. /*
  389. * upon success, mirror_ds is allocated by previous
  390. * getdeviceinfo, or newly by .alloc_deviceid_node
  391. * nfs4_find_get_deviceid failure is indeed getdeviceinfo falure
  392. */
  393. if (idnode)
  394. fls->mirror_array[i]->mirror_ds =
  395. FF_LAYOUT_MIRROR_DS(idnode);
  396. else
  397. goto out_err_free;
  398. /* efficiency */
  399. rc = -EIO;
  400. p = xdr_inline_decode(&stream, 4);
  401. if (!p)
  402. goto out_err_free;
  403. fls->mirror_array[i]->efficiency = be32_to_cpup(p);
  404. /* stateid */
  405. rc = decode_pnfs_stateid(&stream, &fls->mirror_array[i]->stateid);
  406. if (rc)
  407. goto out_err_free;
  408. /* fh */
  409. rc = -EIO;
  410. p = xdr_inline_decode(&stream, 4);
  411. if (!p)
  412. goto out_err_free;
  413. fh_count = be32_to_cpup(p);
  414. fls->mirror_array[i]->fh_versions =
  415. kzalloc(fh_count * sizeof(struct nfs_fh),
  416. gfp_flags);
  417. if (fls->mirror_array[i]->fh_versions == NULL) {
  418. rc = -ENOMEM;
  419. goto out_err_free;
  420. }
  421. for (j = 0; j < fh_count; j++) {
  422. rc = decode_nfs_fh(&stream,
  423. &fls->mirror_array[i]->fh_versions[j]);
  424. if (rc)
  425. goto out_err_free;
  426. }
  427. fls->mirror_array[i]->fh_versions_cnt = fh_count;
  428. /* user */
  429. rc = decode_name(&stream, &id);
  430. if (rc)
  431. goto out_err_free;
  432. acred.uid = make_kuid(&init_user_ns, id);
  433. /* group */
  434. rc = decode_name(&stream, &id);
  435. if (rc)
  436. goto out_err_free;
  437. acred.gid = make_kgid(&init_user_ns, id);
  438. /* find the cred for it */
  439. rcu_assign_pointer(cred, rpc_lookup_generic_cred(&acred, 0, gfp_flags));
  440. if (IS_ERR(cred)) {
  441. rc = PTR_ERR(cred);
  442. goto out_err_free;
  443. }
  444. if (lgr->range.iomode == IOMODE_READ)
  445. rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
  446. else
  447. rcu_assign_pointer(fls->mirror_array[i]->rw_cred, cred);
  448. mirror = ff_layout_add_mirror(lh, fls->mirror_array[i]);
  449. if (mirror != fls->mirror_array[i]) {
  450. /* swap cred ptrs so free_mirror will clean up old */
  451. if (lgr->range.iomode == IOMODE_READ) {
  452. cred = xchg(&mirror->ro_cred, cred);
  453. rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
  454. } else {
  455. cred = xchg(&mirror->rw_cred, cred);
  456. rcu_assign_pointer(fls->mirror_array[i]->rw_cred, cred);
  457. }
  458. ff_layout_free_mirror(fls->mirror_array[i]);
  459. fls->mirror_array[i] = mirror;
  460. }
  461. dprintk("%s: iomode %s uid %u gid %u\n", __func__,
  462. lgr->range.iomode == IOMODE_READ ? "READ" : "RW",
  463. from_kuid(&init_user_ns, acred.uid),
  464. from_kgid(&init_user_ns, acred.gid));
  465. }
  466. p = xdr_inline_decode(&stream, 4);
  467. if (!p)
  468. goto out_sort_mirrors;
  469. fls->flags = be32_to_cpup(p);
  470. p = xdr_inline_decode(&stream, 4);
  471. if (!p)
  472. goto out_sort_mirrors;
  473. for (i=0; i < fls->mirror_array_cnt; i++)
  474. fls->mirror_array[i]->report_interval = be32_to_cpup(p);
  475. out_sort_mirrors:
  476. ff_layout_sort_mirrors(fls);
  477. rc = ff_layout_check_layout(lgr);
  478. if (rc)
  479. goto out_err_free;
  480. ff_layout_mark_devices_valid(fls);
  481. ret = &fls->generic_hdr;
  482. dprintk("<-- %s (success)\n", __func__);
  483. out_free_page:
  484. __free_page(scratch);
  485. return ret;
  486. out_err_free:
  487. _ff_layout_free_lseg(fls);
  488. ret = ERR_PTR(rc);
  489. dprintk("<-- %s (%d)\n", __func__, rc);
  490. goto out_free_page;
  491. }
  492. static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
  493. {
  494. struct pnfs_layout_segment *lseg;
  495. list_for_each_entry(lseg, &layout->plh_segs, pls_list)
  496. if (lseg->pls_range.iomode == IOMODE_RW)
  497. return true;
  498. return false;
  499. }
  500. static void
  501. ff_layout_free_lseg(struct pnfs_layout_segment *lseg)
  502. {
  503. struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
  504. dprintk("--> %s\n", __func__);
  505. if (lseg->pls_range.iomode == IOMODE_RW) {
  506. struct nfs4_flexfile_layout *ffl;
  507. struct inode *inode;
  508. ffl = FF_LAYOUT_FROM_HDR(lseg->pls_layout);
  509. inode = ffl->generic_hdr.plh_inode;
  510. spin_lock(&inode->i_lock);
  511. if (!ff_layout_has_rw_segments(lseg->pls_layout)) {
  512. ffl->commit_info.nbuckets = 0;
  513. kfree(ffl->commit_info.buckets);
  514. ffl->commit_info.buckets = NULL;
  515. }
  516. spin_unlock(&inode->i_lock);
  517. }
  518. _ff_layout_free_lseg(fls);
  519. }
  520. /* Return 1 until we have multiple lsegs support */
  521. static int
  522. ff_layout_get_lseg_count(struct nfs4_ff_layout_segment *fls)
  523. {
  524. return 1;
  525. }
  526. static void
  527. nfs4_ff_start_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
  528. {
  529. /* first IO request? */
  530. if (atomic_inc_return(&timer->n_ops) == 1) {
  531. timer->start_time = now;
  532. }
  533. }
  534. static ktime_t
  535. nfs4_ff_end_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
  536. {
  537. ktime_t start;
  538. if (atomic_dec_return(&timer->n_ops) < 0)
  539. WARN_ON_ONCE(1);
  540. start = timer->start_time;
  541. timer->start_time = now;
  542. return ktime_sub(now, start);
  543. }
  544. static bool
  545. nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror,
  546. struct nfs4_ff_layoutstat *layoutstat,
  547. ktime_t now)
  548. {
  549. static const ktime_t notime = {0};
  550. s64 report_interval = FF_LAYOUTSTATS_REPORT_INTERVAL;
  551. struct nfs4_flexfile_layout *ffl = FF_LAYOUT_FROM_HDR(mirror->layout);
  552. nfs4_ff_start_busy_timer(&layoutstat->busy_timer, now);
  553. if (ktime_equal(mirror->start_time, notime))
  554. mirror->start_time = now;
  555. if (mirror->report_interval != 0)
  556. report_interval = (s64)mirror->report_interval * 1000LL;
  557. else if (layoutstats_timer != 0)
  558. report_interval = (s64)layoutstats_timer * 1000LL;
  559. if (ktime_to_ms(ktime_sub(now, ffl->last_report_time)) >=
  560. report_interval) {
  561. ffl->last_report_time = now;
  562. return true;
  563. }
  564. return false;
  565. }
  566. static void
  567. nfs4_ff_layout_stat_io_update_requested(struct nfs4_ff_layoutstat *layoutstat,
  568. __u64 requested)
  569. {
  570. struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
  571. iostat->ops_requested++;
  572. iostat->bytes_requested += requested;
  573. }
  574. static void
  575. nfs4_ff_layout_stat_io_update_completed(struct nfs4_ff_layoutstat *layoutstat,
  576. __u64 requested,
  577. __u64 completed,
  578. ktime_t time_completed,
  579. ktime_t time_started)
  580. {
  581. struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
  582. ktime_t completion_time = ktime_sub(time_completed, time_started);
  583. ktime_t timer;
  584. iostat->ops_completed++;
  585. iostat->bytes_completed += completed;
  586. iostat->bytes_not_delivered += requested - completed;
  587. timer = nfs4_ff_end_busy_timer(&layoutstat->busy_timer, time_completed);
  588. iostat->total_busy_time =
  589. ktime_add(iostat->total_busy_time, timer);
  590. iostat->aggregate_completion_time =
  591. ktime_add(iostat->aggregate_completion_time,
  592. completion_time);
  593. }
  594. static void
  595. nfs4_ff_layout_stat_io_start_read(struct inode *inode,
  596. struct nfs4_ff_layout_mirror *mirror,
  597. __u64 requested, ktime_t now)
  598. {
  599. bool report;
  600. spin_lock(&mirror->lock);
  601. report = nfs4_ff_layoutstat_start_io(mirror, &mirror->read_stat, now);
  602. nfs4_ff_layout_stat_io_update_requested(&mirror->read_stat, requested);
  603. spin_unlock(&mirror->lock);
  604. if (report)
  605. pnfs_report_layoutstat(inode, GFP_KERNEL);
  606. }
  607. static void
  608. nfs4_ff_layout_stat_io_end_read(struct rpc_task *task,
  609. struct nfs4_ff_layout_mirror *mirror,
  610. __u64 requested,
  611. __u64 completed)
  612. {
  613. spin_lock(&mirror->lock);
  614. nfs4_ff_layout_stat_io_update_completed(&mirror->read_stat,
  615. requested, completed,
  616. ktime_get(), task->tk_start);
  617. spin_unlock(&mirror->lock);
  618. }
  619. static void
  620. nfs4_ff_layout_stat_io_start_write(struct inode *inode,
  621. struct nfs4_ff_layout_mirror *mirror,
  622. __u64 requested, ktime_t now)
  623. {
  624. bool report;
  625. spin_lock(&mirror->lock);
  626. report = nfs4_ff_layoutstat_start_io(mirror , &mirror->write_stat, now);
  627. nfs4_ff_layout_stat_io_update_requested(&mirror->write_stat, requested);
  628. spin_unlock(&mirror->lock);
  629. if (report)
  630. pnfs_report_layoutstat(inode, GFP_NOIO);
  631. }
  632. static void
  633. nfs4_ff_layout_stat_io_end_write(struct rpc_task *task,
  634. struct nfs4_ff_layout_mirror *mirror,
  635. __u64 requested,
  636. __u64 completed,
  637. enum nfs3_stable_how committed)
  638. {
  639. if (committed == NFS_UNSTABLE)
  640. requested = completed = 0;
  641. spin_lock(&mirror->lock);
  642. nfs4_ff_layout_stat_io_update_completed(&mirror->write_stat,
  643. requested, completed, ktime_get(), task->tk_start);
  644. spin_unlock(&mirror->lock);
  645. }
  646. static int
  647. ff_layout_alloc_commit_info(struct pnfs_layout_segment *lseg,
  648. struct nfs_commit_info *cinfo,
  649. gfp_t gfp_flags)
  650. {
  651. struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
  652. struct pnfs_commit_bucket *buckets;
  653. int size;
  654. if (cinfo->ds->nbuckets != 0) {
  655. /* This assumes there is only one RW lseg per file.
  656. * To support multiple lseg per file, we need to
  657. * change struct pnfs_commit_bucket to allow dynamic
  658. * increasing nbuckets.
  659. */
  660. return 0;
  661. }
  662. size = ff_layout_get_lseg_count(fls) * FF_LAYOUT_MIRROR_COUNT(lseg);
  663. buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
  664. gfp_flags);
  665. if (!buckets)
  666. return -ENOMEM;
  667. else {
  668. int i;
  669. spin_lock(&cinfo->inode->i_lock);
  670. if (cinfo->ds->nbuckets != 0)
  671. kfree(buckets);
  672. else {
  673. cinfo->ds->buckets = buckets;
  674. cinfo->ds->nbuckets = size;
  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 =
  680. NFS_INVALID_STABLE_HOW;
  681. }
  682. }
  683. spin_unlock(&cinfo->inode->i_lock);
  684. return 0;
  685. }
  686. }
  687. static struct nfs4_pnfs_ds *
  688. ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
  689. int start_idx,
  690. int *best_idx)
  691. {
  692. struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
  693. struct nfs4_pnfs_ds *ds;
  694. bool fail_return = false;
  695. int idx;
  696. /* mirrors are sorted by efficiency */
  697. for (idx = start_idx; idx < fls->mirror_array_cnt; idx++) {
  698. if (idx+1 == fls->mirror_array_cnt)
  699. fail_return = true;
  700. ds = nfs4_ff_layout_prepare_ds(lseg, idx, fail_return);
  701. if (ds) {
  702. *best_idx = idx;
  703. return ds;
  704. }
  705. }
  706. return NULL;
  707. }
  708. static void
  709. ff_layout_pg_get_read(struct nfs_pageio_descriptor *pgio,
  710. struct nfs_page *req,
  711. bool strict_iomode)
  712. {
  713. retry_strict:
  714. pnfs_put_lseg(pgio->pg_lseg);
  715. pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
  716. req->wb_context,
  717. 0,
  718. NFS4_MAX_UINT64,
  719. IOMODE_READ,
  720. strict_iomode,
  721. GFP_KERNEL);
  722. if (IS_ERR(pgio->pg_lseg)) {
  723. pgio->pg_error = PTR_ERR(pgio->pg_lseg);
  724. pgio->pg_lseg = NULL;
  725. }
  726. /* If we don't have checking, do get a IOMODE_RW
  727. * segment, and the server wants to avoid READs
  728. * there, then retry!
  729. */
  730. if (pgio->pg_lseg && !strict_iomode &&
  731. ff_layout_avoid_read_on_rw(pgio->pg_lseg)) {
  732. strict_iomode = true;
  733. goto retry_strict;
  734. }
  735. }
  736. static void
  737. ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
  738. struct nfs_page *req)
  739. {
  740. struct nfs_pgio_mirror *pgm;
  741. struct nfs4_ff_layout_mirror *mirror;
  742. struct nfs4_pnfs_ds *ds;
  743. int ds_idx;
  744. retry:
  745. /* Use full layout for now */
  746. if (!pgio->pg_lseg)
  747. ff_layout_pg_get_read(pgio, req, false);
  748. else if (ff_layout_avoid_read_on_rw(pgio->pg_lseg))
  749. ff_layout_pg_get_read(pgio, req, true);
  750. /* If no lseg, fall back to read through mds */
  751. if (pgio->pg_lseg == NULL)
  752. goto out_mds;
  753. ds = ff_layout_choose_best_ds_for_read(pgio->pg_lseg, 0, &ds_idx);
  754. if (!ds) {
  755. if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
  756. goto out_mds;
  757. pnfs_put_lseg(pgio->pg_lseg);
  758. pgio->pg_lseg = NULL;
  759. /* Sleep for 1 second before retrying */
  760. ssleep(1);
  761. goto retry;
  762. }
  763. mirror = FF_LAYOUT_COMP(pgio->pg_lseg, ds_idx);
  764. pgio->pg_mirror_idx = ds_idx;
  765. /* read always uses only one mirror - idx 0 for pgio layer */
  766. pgm = &pgio->pg_mirrors[0];
  767. pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].rsize;
  768. return;
  769. out_mds:
  770. pnfs_put_lseg(pgio->pg_lseg);
  771. pgio->pg_lseg = NULL;
  772. nfs_pageio_reset_read_mds(pgio);
  773. }
  774. static void
  775. ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
  776. struct nfs_page *req)
  777. {
  778. struct nfs4_ff_layout_mirror *mirror;
  779. struct nfs_pgio_mirror *pgm;
  780. struct nfs_commit_info cinfo;
  781. struct nfs4_pnfs_ds *ds;
  782. int i;
  783. int status;
  784. retry:
  785. if (!pgio->pg_lseg) {
  786. pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
  787. req->wb_context,
  788. 0,
  789. NFS4_MAX_UINT64,
  790. IOMODE_RW,
  791. false,
  792. GFP_NOFS);
  793. if (IS_ERR(pgio->pg_lseg)) {
  794. pgio->pg_error = PTR_ERR(pgio->pg_lseg);
  795. pgio->pg_lseg = NULL;
  796. return;
  797. }
  798. }
  799. /* If no lseg, fall back to write through mds */
  800. if (pgio->pg_lseg == NULL)
  801. goto out_mds;
  802. nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
  803. status = ff_layout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
  804. if (status < 0)
  805. goto out_mds;
  806. /* Use a direct mapping of ds_idx to pgio mirror_idx */
  807. if (WARN_ON_ONCE(pgio->pg_mirror_count !=
  808. FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg)))
  809. goto out_mds;
  810. for (i = 0; i < pgio->pg_mirror_count; i++) {
  811. ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, i, true);
  812. if (!ds) {
  813. if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
  814. goto out_mds;
  815. pnfs_put_lseg(pgio->pg_lseg);
  816. pgio->pg_lseg = NULL;
  817. /* Sleep for 1 second before retrying */
  818. ssleep(1);
  819. goto retry;
  820. }
  821. pgm = &pgio->pg_mirrors[i];
  822. mirror = FF_LAYOUT_COMP(pgio->pg_lseg, i);
  823. pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].wsize;
  824. }
  825. return;
  826. out_mds:
  827. pnfs_put_lseg(pgio->pg_lseg);
  828. pgio->pg_lseg = NULL;
  829. nfs_pageio_reset_write_mds(pgio);
  830. }
  831. static unsigned int
  832. ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,
  833. struct nfs_page *req)
  834. {
  835. if (!pgio->pg_lseg) {
  836. pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
  837. req->wb_context,
  838. 0,
  839. NFS4_MAX_UINT64,
  840. IOMODE_RW,
  841. false,
  842. GFP_NOFS);
  843. if (IS_ERR(pgio->pg_lseg)) {
  844. pgio->pg_error = PTR_ERR(pgio->pg_lseg);
  845. pgio->pg_lseg = NULL;
  846. goto out;
  847. }
  848. }
  849. if (pgio->pg_lseg)
  850. return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg);
  851. /* no lseg means that pnfs is not in use, so no mirroring here */
  852. nfs_pageio_reset_write_mds(pgio);
  853. out:
  854. return 1;
  855. }
  856. static const struct nfs_pageio_ops ff_layout_pg_read_ops = {
  857. .pg_init = ff_layout_pg_init_read,
  858. .pg_test = pnfs_generic_pg_test,
  859. .pg_doio = pnfs_generic_pg_readpages,
  860. .pg_cleanup = pnfs_generic_pg_cleanup,
  861. };
  862. static const struct nfs_pageio_ops ff_layout_pg_write_ops = {
  863. .pg_init = ff_layout_pg_init_write,
  864. .pg_test = pnfs_generic_pg_test,
  865. .pg_doio = pnfs_generic_pg_writepages,
  866. .pg_get_mirror_count = ff_layout_pg_get_mirror_count_write,
  867. .pg_cleanup = pnfs_generic_pg_cleanup,
  868. };
  869. static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs)
  870. {
  871. struct rpc_task *task = &hdr->task;
  872. pnfs_layoutcommit_inode(hdr->inode, false);
  873. if (retry_pnfs) {
  874. dprintk("%s Reset task %5u for i/o through pNFS "
  875. "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
  876. hdr->task.tk_pid,
  877. hdr->inode->i_sb->s_id,
  878. (unsigned long long)NFS_FILEID(hdr->inode),
  879. hdr->args.count,
  880. (unsigned long long)hdr->args.offset);
  881. hdr->completion_ops->reschedule_io(hdr);
  882. return;
  883. }
  884. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
  885. dprintk("%s Reset task %5u for i/o through MDS "
  886. "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
  887. hdr->task.tk_pid,
  888. hdr->inode->i_sb->s_id,
  889. (unsigned long long)NFS_FILEID(hdr->inode),
  890. hdr->args.count,
  891. (unsigned long long)hdr->args.offset);
  892. task->tk_status = pnfs_write_done_resend_to_mds(hdr);
  893. }
  894. }
  895. static void ff_layout_reset_read(struct nfs_pgio_header *hdr)
  896. {
  897. struct rpc_task *task = &hdr->task;
  898. pnfs_layoutcommit_inode(hdr->inode, false);
  899. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
  900. dprintk("%s Reset task %5u for i/o through MDS "
  901. "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
  902. hdr->task.tk_pid,
  903. hdr->inode->i_sb->s_id,
  904. (unsigned long long)NFS_FILEID(hdr->inode),
  905. hdr->args.count,
  906. (unsigned long long)hdr->args.offset);
  907. task->tk_status = pnfs_read_done_resend_to_mds(hdr);
  908. }
  909. }
  910. static int ff_layout_async_handle_error_v4(struct rpc_task *task,
  911. struct nfs4_state *state,
  912. struct nfs_client *clp,
  913. struct pnfs_layout_segment *lseg,
  914. int idx)
  915. {
  916. struct pnfs_layout_hdr *lo = lseg->pls_layout;
  917. struct inode *inode = lo->plh_inode;
  918. struct nfs_server *mds_server = NFS_SERVER(inode);
  919. struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx);
  920. struct nfs_client *mds_client = mds_server->nfs_client;
  921. struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
  922. switch (task->tk_status) {
  923. /* MDS state errors */
  924. case -NFS4ERR_DELEG_REVOKED:
  925. case -NFS4ERR_ADMIN_REVOKED:
  926. case -NFS4ERR_BAD_STATEID:
  927. if (state == NULL)
  928. break;
  929. nfs_remove_bad_delegation(state->inode, NULL);
  930. case -NFS4ERR_OPENMODE:
  931. if (state == NULL)
  932. break;
  933. if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
  934. goto out_bad_stateid;
  935. goto wait_on_recovery;
  936. case -NFS4ERR_EXPIRED:
  937. if (state != NULL) {
  938. if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
  939. goto out_bad_stateid;
  940. }
  941. nfs4_schedule_lease_recovery(mds_client);
  942. goto wait_on_recovery;
  943. /* DS session errors */
  944. case -NFS4ERR_BADSESSION:
  945. case -NFS4ERR_BADSLOT:
  946. case -NFS4ERR_BAD_HIGH_SLOT:
  947. case -NFS4ERR_DEADSESSION:
  948. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  949. case -NFS4ERR_SEQ_FALSE_RETRY:
  950. case -NFS4ERR_SEQ_MISORDERED:
  951. dprintk("%s ERROR %d, Reset session. Exchangeid "
  952. "flags 0x%x\n", __func__, task->tk_status,
  953. clp->cl_exchange_flags);
  954. nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
  955. break;
  956. case -NFS4ERR_DELAY:
  957. case -NFS4ERR_GRACE:
  958. rpc_delay(task, FF_LAYOUT_POLL_RETRY_MAX);
  959. break;
  960. case -NFS4ERR_RETRY_UNCACHED_REP:
  961. break;
  962. /* Invalidate Layout errors */
  963. case -NFS4ERR_PNFS_NO_LAYOUT:
  964. case -ESTALE: /* mapped NFS4ERR_STALE */
  965. case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */
  966. case -EISDIR: /* mapped NFS4ERR_ISDIR */
  967. case -NFS4ERR_FHEXPIRED:
  968. case -NFS4ERR_WRONG_TYPE:
  969. dprintk("%s Invalid layout error %d\n", __func__,
  970. task->tk_status);
  971. /*
  972. * Destroy layout so new i/o will get a new layout.
  973. * Layout will not be destroyed until all current lseg
  974. * references are put. Mark layout as invalid to resend failed
  975. * i/o and all i/o waiting on the slot table to the MDS until
  976. * layout is destroyed and a new valid layout is obtained.
  977. */
  978. pnfs_destroy_layout(NFS_I(inode));
  979. rpc_wake_up(&tbl->slot_tbl_waitq);
  980. goto reset;
  981. /* RPC connection errors */
  982. case -ECONNREFUSED:
  983. case -EHOSTDOWN:
  984. case -EHOSTUNREACH:
  985. case -ENETUNREACH:
  986. case -EIO:
  987. case -ETIMEDOUT:
  988. case -EPIPE:
  989. dprintk("%s DS connection error %d\n", __func__,
  990. task->tk_status);
  991. nfs4_mark_deviceid_unavailable(devid);
  992. rpc_wake_up(&tbl->slot_tbl_waitq);
  993. /* fall through */
  994. default:
  995. if (ff_layout_avoid_mds_available_ds(lseg))
  996. return -NFS4ERR_RESET_TO_PNFS;
  997. reset:
  998. dprintk("%s Retry through MDS. Error %d\n", __func__,
  999. task->tk_status);
  1000. return -NFS4ERR_RESET_TO_MDS;
  1001. }
  1002. out:
  1003. task->tk_status = 0;
  1004. return -EAGAIN;
  1005. out_bad_stateid:
  1006. task->tk_status = -EIO;
  1007. return 0;
  1008. wait_on_recovery:
  1009. rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
  1010. if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
  1011. rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
  1012. goto out;
  1013. }
  1014. /* Retry all errors through either pNFS or MDS except for -EJUKEBOX */
  1015. static int ff_layout_async_handle_error_v3(struct rpc_task *task,
  1016. struct pnfs_layout_segment *lseg,
  1017. int idx)
  1018. {
  1019. struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx);
  1020. switch (task->tk_status) {
  1021. /* File access problems. Don't mark the device as unavailable */
  1022. case -EACCES:
  1023. case -ESTALE:
  1024. case -EISDIR:
  1025. case -EBADHANDLE:
  1026. case -ELOOP:
  1027. case -ENOSPC:
  1028. break;
  1029. case -EJUKEBOX:
  1030. nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY);
  1031. goto out_retry;
  1032. default:
  1033. dprintk("%s DS connection error %d\n", __func__,
  1034. task->tk_status);
  1035. nfs4_mark_deviceid_unavailable(devid);
  1036. }
  1037. /* FIXME: Need to prevent infinite looping here. */
  1038. return -NFS4ERR_RESET_TO_PNFS;
  1039. out_retry:
  1040. task->tk_status = 0;
  1041. rpc_restart_call_prepare(task);
  1042. rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
  1043. return -EAGAIN;
  1044. }
  1045. static int ff_layout_async_handle_error(struct rpc_task *task,
  1046. struct nfs4_state *state,
  1047. struct nfs_client *clp,
  1048. struct pnfs_layout_segment *lseg,
  1049. int idx)
  1050. {
  1051. int vers = clp->cl_nfs_mod->rpc_vers->number;
  1052. if (task->tk_status >= 0)
  1053. return 0;
  1054. /* Handle the case of an invalid layout segment */
  1055. if (!pnfs_is_valid_lseg(lseg))
  1056. return -NFS4ERR_RESET_TO_PNFS;
  1057. switch (vers) {
  1058. case 3:
  1059. return ff_layout_async_handle_error_v3(task, lseg, idx);
  1060. case 4:
  1061. return ff_layout_async_handle_error_v4(task, state, clp,
  1062. lseg, idx);
  1063. default:
  1064. /* should never happen */
  1065. WARN_ON_ONCE(1);
  1066. return 0;
  1067. }
  1068. }
  1069. static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
  1070. int idx, u64 offset, u64 length,
  1071. u32 status, int opnum, int error)
  1072. {
  1073. struct nfs4_ff_layout_mirror *mirror;
  1074. int err;
  1075. if (status == 0) {
  1076. switch (error) {
  1077. case -ETIMEDOUT:
  1078. case -EPFNOSUPPORT:
  1079. case -EPROTONOSUPPORT:
  1080. case -EOPNOTSUPP:
  1081. case -ECONNREFUSED:
  1082. case -ECONNRESET:
  1083. case -EHOSTDOWN:
  1084. case -EHOSTUNREACH:
  1085. case -ENETUNREACH:
  1086. case -EADDRINUSE:
  1087. case -ENOBUFS:
  1088. case -EPIPE:
  1089. case -EPERM:
  1090. status = NFS4ERR_NXIO;
  1091. break;
  1092. case -EACCES:
  1093. status = NFS4ERR_ACCESS;
  1094. break;
  1095. default:
  1096. return;
  1097. }
  1098. }
  1099. switch (status) {
  1100. case NFS4ERR_DELAY:
  1101. case NFS4ERR_GRACE:
  1102. return;
  1103. default:
  1104. break;
  1105. }
  1106. mirror = FF_LAYOUT_COMP(lseg, idx);
  1107. err = ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout),
  1108. mirror, offset, length, status, opnum,
  1109. GFP_NOIO);
  1110. pnfs_error_mark_layout_for_return(lseg->pls_layout->plh_inode, lseg);
  1111. dprintk("%s: err %d op %d status %u\n", __func__, err, opnum, status);
  1112. }
  1113. /* NFS_PROTO call done callback routines */
  1114. static int ff_layout_read_done_cb(struct rpc_task *task,
  1115. struct nfs_pgio_header *hdr)
  1116. {
  1117. int err;
  1118. trace_nfs4_pnfs_read(hdr, task->tk_status);
  1119. if (task->tk_status < 0)
  1120. ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx,
  1121. hdr->args.offset, hdr->args.count,
  1122. hdr->res.op_status, OP_READ,
  1123. task->tk_status);
  1124. err = ff_layout_async_handle_error(task, hdr->args.context->state,
  1125. hdr->ds_clp, hdr->lseg,
  1126. hdr->pgio_mirror_idx);
  1127. switch (err) {
  1128. case -NFS4ERR_RESET_TO_PNFS:
  1129. if (ff_layout_choose_best_ds_for_read(hdr->lseg,
  1130. hdr->pgio_mirror_idx + 1,
  1131. &hdr->pgio_mirror_idx))
  1132. goto out_eagain;
  1133. ff_layout_read_record_layoutstats_done(task, hdr);
  1134. pnfs_read_resend_pnfs(hdr);
  1135. return task->tk_status;
  1136. case -NFS4ERR_RESET_TO_MDS:
  1137. ff_layout_reset_read(hdr);
  1138. return task->tk_status;
  1139. case -EAGAIN:
  1140. goto out_eagain;
  1141. }
  1142. return 0;
  1143. out_eagain:
  1144. rpc_restart_call_prepare(task);
  1145. return -EAGAIN;
  1146. }
  1147. static bool
  1148. ff_layout_need_layoutcommit(struct pnfs_layout_segment *lseg)
  1149. {
  1150. return !(FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_LAYOUTCOMMIT);
  1151. }
  1152. /*
  1153. * We reference the rpc_cred of the first WRITE that triggers the need for
  1154. * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
  1155. * rfc5661 is not clear about which credential should be used.
  1156. *
  1157. * Flexlayout client should treat DS replied FILE_SYNC as DATA_SYNC, so
  1158. * to follow http://www.rfc-editor.org/errata_search.php?rfc=5661&eid=2751
  1159. * we always send layoutcommit after DS writes.
  1160. */
  1161. static void
  1162. ff_layout_set_layoutcommit(struct inode *inode,
  1163. struct pnfs_layout_segment *lseg,
  1164. loff_t end_offset)
  1165. {
  1166. if (!ff_layout_need_layoutcommit(lseg))
  1167. return;
  1168. pnfs_set_layoutcommit(inode, lseg, end_offset);
  1169. dprintk("%s inode %lu pls_end_pos %llu\n", __func__, inode->i_ino,
  1170. (unsigned long long) NFS_I(inode)->layout->plh_lwb);
  1171. }
  1172. static bool
  1173. ff_layout_device_unavailable(struct pnfs_layout_segment *lseg, int idx)
  1174. {
  1175. /* No mirroring for now */
  1176. struct nfs4_deviceid_node *node = FF_LAYOUT_DEVID_NODE(lseg, idx);
  1177. return ff_layout_test_devid_unavailable(node);
  1178. }
  1179. static void ff_layout_read_record_layoutstats_start(struct rpc_task *task,
  1180. struct nfs_pgio_header *hdr)
  1181. {
  1182. if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
  1183. return;
  1184. nfs4_ff_layout_stat_io_start_read(hdr->inode,
  1185. FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
  1186. hdr->args.count,
  1187. task->tk_start);
  1188. }
  1189. static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,
  1190. struct nfs_pgio_header *hdr)
  1191. {
  1192. if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
  1193. return;
  1194. nfs4_ff_layout_stat_io_end_read(task,
  1195. FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
  1196. hdr->args.count,
  1197. hdr->res.count);
  1198. }
  1199. static int ff_layout_read_prepare_common(struct rpc_task *task,
  1200. struct nfs_pgio_header *hdr)
  1201. {
  1202. if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
  1203. rpc_exit(task, -EIO);
  1204. return -EIO;
  1205. }
  1206. if (ff_layout_device_unavailable(hdr->lseg, hdr->pgio_mirror_idx)) {
  1207. rpc_exit(task, -EHOSTDOWN);
  1208. return -EAGAIN;
  1209. }
  1210. ff_layout_read_record_layoutstats_start(task, hdr);
  1211. return 0;
  1212. }
  1213. /*
  1214. * Call ops for the async read/write cases
  1215. * In the case of dense layouts, the offset needs to be reset to its
  1216. * original value.
  1217. */
  1218. static void ff_layout_read_prepare_v3(struct rpc_task *task, void *data)
  1219. {
  1220. struct nfs_pgio_header *hdr = data;
  1221. if (ff_layout_read_prepare_common(task, hdr))
  1222. return;
  1223. rpc_call_start(task);
  1224. }
  1225. static int ff_layout_setup_sequence(struct nfs_client *ds_clp,
  1226. struct nfs4_sequence_args *args,
  1227. struct nfs4_sequence_res *res,
  1228. struct rpc_task *task)
  1229. {
  1230. if (ds_clp->cl_session)
  1231. return nfs41_setup_sequence(ds_clp->cl_session,
  1232. args,
  1233. res,
  1234. task);
  1235. return nfs40_setup_sequence(ds_clp->cl_slot_tbl,
  1236. args,
  1237. res,
  1238. task);
  1239. }
  1240. static void ff_layout_read_prepare_v4(struct rpc_task *task, void *data)
  1241. {
  1242. struct nfs_pgio_header *hdr = data;
  1243. if (ff_layout_setup_sequence(hdr->ds_clp,
  1244. &hdr->args.seq_args,
  1245. &hdr->res.seq_res,
  1246. task))
  1247. return;
  1248. if (ff_layout_read_prepare_common(task, hdr))
  1249. return;
  1250. if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
  1251. hdr->args.lock_context, FMODE_READ) == -EIO)
  1252. rpc_exit(task, -EIO); /* lost lock, terminate I/O */
  1253. }
  1254. static void ff_layout_read_call_done(struct rpc_task *task, void *data)
  1255. {
  1256. struct nfs_pgio_header *hdr = data;
  1257. dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
  1258. if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
  1259. task->tk_status == 0) {
  1260. nfs4_sequence_done(task, &hdr->res.seq_res);
  1261. return;
  1262. }
  1263. /* Note this may cause RPC to be resent */
  1264. hdr->mds_ops->rpc_call_done(task, hdr);
  1265. }
  1266. static void ff_layout_read_count_stats(struct rpc_task *task, void *data)
  1267. {
  1268. struct nfs_pgio_header *hdr = data;
  1269. ff_layout_read_record_layoutstats_done(task, hdr);
  1270. rpc_count_iostats_metrics(task,
  1271. &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]);
  1272. }
  1273. static void ff_layout_read_release(void *data)
  1274. {
  1275. struct nfs_pgio_header *hdr = data;
  1276. ff_layout_read_record_layoutstats_done(&hdr->task, hdr);
  1277. pnfs_generic_rw_release(data);
  1278. }
  1279. static int ff_layout_write_done_cb(struct rpc_task *task,
  1280. struct nfs_pgio_header *hdr)
  1281. {
  1282. loff_t end_offs = 0;
  1283. int err;
  1284. trace_nfs4_pnfs_write(hdr, task->tk_status);
  1285. if (task->tk_status < 0)
  1286. ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx,
  1287. hdr->args.offset, hdr->args.count,
  1288. hdr->res.op_status, OP_WRITE,
  1289. task->tk_status);
  1290. err = ff_layout_async_handle_error(task, hdr->args.context->state,
  1291. hdr->ds_clp, hdr->lseg,
  1292. hdr->pgio_mirror_idx);
  1293. switch (err) {
  1294. case -NFS4ERR_RESET_TO_PNFS:
  1295. ff_layout_reset_write(hdr, true);
  1296. return task->tk_status;
  1297. case -NFS4ERR_RESET_TO_MDS:
  1298. ff_layout_reset_write(hdr, false);
  1299. return task->tk_status;
  1300. case -EAGAIN:
  1301. return -EAGAIN;
  1302. }
  1303. if (hdr->res.verf->committed == NFS_FILE_SYNC ||
  1304. hdr->res.verf->committed == NFS_DATA_SYNC)
  1305. end_offs = hdr->mds_offset + (loff_t)hdr->res.count;
  1306. /* Note: if the write is unstable, don't set end_offs until commit */
  1307. ff_layout_set_layoutcommit(hdr->inode, hdr->lseg, end_offs);
  1308. /* zero out fattr since we don't care DS attr at all */
  1309. hdr->fattr.valid = 0;
  1310. if (task->tk_status >= 0)
  1311. nfs_writeback_update_inode(hdr);
  1312. return 0;
  1313. }
  1314. static int ff_layout_commit_done_cb(struct rpc_task *task,
  1315. struct nfs_commit_data *data)
  1316. {
  1317. int err;
  1318. trace_nfs4_pnfs_commit_ds(data, task->tk_status);
  1319. if (task->tk_status < 0)
  1320. ff_layout_io_track_ds_error(data->lseg, data->ds_commit_index,
  1321. data->args.offset, data->args.count,
  1322. data->res.op_status, OP_COMMIT,
  1323. task->tk_status);
  1324. err = ff_layout_async_handle_error(task, NULL, data->ds_clp,
  1325. data->lseg, data->ds_commit_index);
  1326. switch (err) {
  1327. case -NFS4ERR_RESET_TO_PNFS:
  1328. pnfs_generic_prepare_to_resend_writes(data);
  1329. return -EAGAIN;
  1330. case -NFS4ERR_RESET_TO_MDS:
  1331. pnfs_generic_prepare_to_resend_writes(data);
  1332. return -EAGAIN;
  1333. case -EAGAIN:
  1334. rpc_restart_call_prepare(task);
  1335. return -EAGAIN;
  1336. }
  1337. ff_layout_set_layoutcommit(data->inode, data->lseg, data->lwb);
  1338. return 0;
  1339. }
  1340. static void ff_layout_write_record_layoutstats_start(struct rpc_task *task,
  1341. struct nfs_pgio_header *hdr)
  1342. {
  1343. if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
  1344. return;
  1345. nfs4_ff_layout_stat_io_start_write(hdr->inode,
  1346. FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
  1347. hdr->args.count,
  1348. task->tk_start);
  1349. }
  1350. static void ff_layout_write_record_layoutstats_done(struct rpc_task *task,
  1351. struct nfs_pgio_header *hdr)
  1352. {
  1353. if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
  1354. return;
  1355. nfs4_ff_layout_stat_io_end_write(task,
  1356. FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
  1357. hdr->args.count, hdr->res.count,
  1358. hdr->res.verf->committed);
  1359. }
  1360. static int ff_layout_write_prepare_common(struct rpc_task *task,
  1361. struct nfs_pgio_header *hdr)
  1362. {
  1363. if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
  1364. rpc_exit(task, -EIO);
  1365. return -EIO;
  1366. }
  1367. if (ff_layout_device_unavailable(hdr->lseg, hdr->pgio_mirror_idx)) {
  1368. rpc_exit(task, -EHOSTDOWN);
  1369. return -EAGAIN;
  1370. }
  1371. ff_layout_write_record_layoutstats_start(task, hdr);
  1372. return 0;
  1373. }
  1374. static void ff_layout_write_prepare_v3(struct rpc_task *task, void *data)
  1375. {
  1376. struct nfs_pgio_header *hdr = data;
  1377. if (ff_layout_write_prepare_common(task, hdr))
  1378. return;
  1379. rpc_call_start(task);
  1380. }
  1381. static void ff_layout_write_prepare_v4(struct rpc_task *task, void *data)
  1382. {
  1383. struct nfs_pgio_header *hdr = data;
  1384. if (ff_layout_setup_sequence(hdr->ds_clp,
  1385. &hdr->args.seq_args,
  1386. &hdr->res.seq_res,
  1387. task))
  1388. return;
  1389. if (ff_layout_write_prepare_common(task, hdr))
  1390. return;
  1391. if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
  1392. hdr->args.lock_context, FMODE_WRITE) == -EIO)
  1393. rpc_exit(task, -EIO); /* lost lock, terminate I/O */
  1394. }
  1395. static void ff_layout_write_call_done(struct rpc_task *task, void *data)
  1396. {
  1397. struct nfs_pgio_header *hdr = data;
  1398. if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
  1399. task->tk_status == 0) {
  1400. nfs4_sequence_done(task, &hdr->res.seq_res);
  1401. return;
  1402. }
  1403. /* Note this may cause RPC to be resent */
  1404. hdr->mds_ops->rpc_call_done(task, hdr);
  1405. }
  1406. static void ff_layout_write_count_stats(struct rpc_task *task, void *data)
  1407. {
  1408. struct nfs_pgio_header *hdr = data;
  1409. ff_layout_write_record_layoutstats_done(task, hdr);
  1410. rpc_count_iostats_metrics(task,
  1411. &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]);
  1412. }
  1413. static void ff_layout_write_release(void *data)
  1414. {
  1415. struct nfs_pgio_header *hdr = data;
  1416. ff_layout_write_record_layoutstats_done(&hdr->task, hdr);
  1417. pnfs_generic_rw_release(data);
  1418. }
  1419. static void ff_layout_commit_record_layoutstats_start(struct rpc_task *task,
  1420. struct nfs_commit_data *cdata)
  1421. {
  1422. if (test_and_set_bit(NFS_IOHDR_STAT, &cdata->flags))
  1423. return;
  1424. nfs4_ff_layout_stat_io_start_write(cdata->inode,
  1425. FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
  1426. 0, task->tk_start);
  1427. }
  1428. static void ff_layout_commit_record_layoutstats_done(struct rpc_task *task,
  1429. struct nfs_commit_data *cdata)
  1430. {
  1431. struct nfs_page *req;
  1432. __u64 count = 0;
  1433. if (!test_and_clear_bit(NFS_IOHDR_STAT, &cdata->flags))
  1434. return;
  1435. if (task->tk_status == 0) {
  1436. list_for_each_entry(req, &cdata->pages, wb_list)
  1437. count += req->wb_bytes;
  1438. }
  1439. nfs4_ff_layout_stat_io_end_write(task,
  1440. FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
  1441. count, count, NFS_FILE_SYNC);
  1442. }
  1443. static void ff_layout_commit_prepare_common(struct rpc_task *task,
  1444. struct nfs_commit_data *cdata)
  1445. {
  1446. ff_layout_commit_record_layoutstats_start(task, cdata);
  1447. }
  1448. static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data)
  1449. {
  1450. ff_layout_commit_prepare_common(task, data);
  1451. rpc_call_start(task);
  1452. }
  1453. static void ff_layout_commit_prepare_v4(struct rpc_task *task, void *data)
  1454. {
  1455. struct nfs_commit_data *wdata = data;
  1456. if (ff_layout_setup_sequence(wdata->ds_clp,
  1457. &wdata->args.seq_args,
  1458. &wdata->res.seq_res,
  1459. task))
  1460. return;
  1461. ff_layout_commit_prepare_common(task, data);
  1462. }
  1463. static void ff_layout_commit_done(struct rpc_task *task, void *data)
  1464. {
  1465. pnfs_generic_write_commit_done(task, data);
  1466. }
  1467. static void ff_layout_commit_count_stats(struct rpc_task *task, void *data)
  1468. {
  1469. struct nfs_commit_data *cdata = data;
  1470. ff_layout_commit_record_layoutstats_done(task, cdata);
  1471. rpc_count_iostats_metrics(task,
  1472. &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]);
  1473. }
  1474. static void ff_layout_commit_release(void *data)
  1475. {
  1476. struct nfs_commit_data *cdata = data;
  1477. ff_layout_commit_record_layoutstats_done(&cdata->task, cdata);
  1478. pnfs_generic_commit_release(data);
  1479. }
  1480. static const struct rpc_call_ops ff_layout_read_call_ops_v3 = {
  1481. .rpc_call_prepare = ff_layout_read_prepare_v3,
  1482. .rpc_call_done = ff_layout_read_call_done,
  1483. .rpc_count_stats = ff_layout_read_count_stats,
  1484. .rpc_release = ff_layout_read_release,
  1485. };
  1486. static const struct rpc_call_ops ff_layout_read_call_ops_v4 = {
  1487. .rpc_call_prepare = ff_layout_read_prepare_v4,
  1488. .rpc_call_done = ff_layout_read_call_done,
  1489. .rpc_count_stats = ff_layout_read_count_stats,
  1490. .rpc_release = ff_layout_read_release,
  1491. };
  1492. static const struct rpc_call_ops ff_layout_write_call_ops_v3 = {
  1493. .rpc_call_prepare = ff_layout_write_prepare_v3,
  1494. .rpc_call_done = ff_layout_write_call_done,
  1495. .rpc_count_stats = ff_layout_write_count_stats,
  1496. .rpc_release = ff_layout_write_release,
  1497. };
  1498. static const struct rpc_call_ops ff_layout_write_call_ops_v4 = {
  1499. .rpc_call_prepare = ff_layout_write_prepare_v4,
  1500. .rpc_call_done = ff_layout_write_call_done,
  1501. .rpc_count_stats = ff_layout_write_count_stats,
  1502. .rpc_release = ff_layout_write_release,
  1503. };
  1504. static const struct rpc_call_ops ff_layout_commit_call_ops_v3 = {
  1505. .rpc_call_prepare = ff_layout_commit_prepare_v3,
  1506. .rpc_call_done = ff_layout_commit_done,
  1507. .rpc_count_stats = ff_layout_commit_count_stats,
  1508. .rpc_release = ff_layout_commit_release,
  1509. };
  1510. static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = {
  1511. .rpc_call_prepare = ff_layout_commit_prepare_v4,
  1512. .rpc_call_done = ff_layout_commit_done,
  1513. .rpc_count_stats = ff_layout_commit_count_stats,
  1514. .rpc_release = ff_layout_commit_release,
  1515. };
  1516. static enum pnfs_try_status
  1517. ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
  1518. {
  1519. struct pnfs_layout_segment *lseg = hdr->lseg;
  1520. struct nfs4_pnfs_ds *ds;
  1521. struct rpc_clnt *ds_clnt;
  1522. struct rpc_cred *ds_cred;
  1523. loff_t offset = hdr->args.offset;
  1524. u32 idx = hdr->pgio_mirror_idx;
  1525. int vers;
  1526. struct nfs_fh *fh;
  1527. dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
  1528. __func__, hdr->inode->i_ino,
  1529. hdr->args.pgbase, (size_t)hdr->args.count, offset);
  1530. ds = nfs4_ff_layout_prepare_ds(lseg, idx, false);
  1531. if (!ds)
  1532. goto out_failed;
  1533. ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
  1534. hdr->inode);
  1535. if (IS_ERR(ds_clnt))
  1536. goto out_failed;
  1537. ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred);
  1538. if (!ds_cred)
  1539. goto out_failed;
  1540. vers = nfs4_ff_layout_ds_version(lseg, idx);
  1541. dprintk("%s USE DS: %s cl_count %d vers %d\n", __func__,
  1542. ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), vers);
  1543. hdr->pgio_done_cb = ff_layout_read_done_cb;
  1544. atomic_inc(&ds->ds_clp->cl_count);
  1545. hdr->ds_clp = ds->ds_clp;
  1546. fh = nfs4_ff_layout_select_ds_fh(lseg, idx);
  1547. if (fh)
  1548. hdr->args.fh = fh;
  1549. /*
  1550. * Note that if we ever decide to split across DSes,
  1551. * then we may need to handle dense-like offsets.
  1552. */
  1553. hdr->args.offset = offset;
  1554. hdr->mds_offset = offset;
  1555. /* Perform an asynchronous read to ds */
  1556. nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
  1557. vers == 3 ? &ff_layout_read_call_ops_v3 :
  1558. &ff_layout_read_call_ops_v4,
  1559. 0, RPC_TASK_SOFTCONN);
  1560. put_rpccred(ds_cred);
  1561. return PNFS_ATTEMPTED;
  1562. out_failed:
  1563. if (ff_layout_avoid_mds_available_ds(lseg))
  1564. return PNFS_TRY_AGAIN;
  1565. return PNFS_NOT_ATTEMPTED;
  1566. }
  1567. /* Perform async writes. */
  1568. static enum pnfs_try_status
  1569. ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
  1570. {
  1571. struct pnfs_layout_segment *lseg = hdr->lseg;
  1572. struct nfs4_pnfs_ds *ds;
  1573. struct rpc_clnt *ds_clnt;
  1574. struct rpc_cred *ds_cred;
  1575. loff_t offset = hdr->args.offset;
  1576. int vers;
  1577. struct nfs_fh *fh;
  1578. int idx = hdr->pgio_mirror_idx;
  1579. ds = nfs4_ff_layout_prepare_ds(lseg, idx, true);
  1580. if (!ds)
  1581. return PNFS_NOT_ATTEMPTED;
  1582. ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
  1583. hdr->inode);
  1584. if (IS_ERR(ds_clnt))
  1585. return PNFS_NOT_ATTEMPTED;
  1586. ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred);
  1587. if (!ds_cred)
  1588. return PNFS_NOT_ATTEMPTED;
  1589. vers = nfs4_ff_layout_ds_version(lseg, idx);
  1590. dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s cl_count %d vers %d\n",
  1591. __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
  1592. offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count),
  1593. vers);
  1594. hdr->pgio_done_cb = ff_layout_write_done_cb;
  1595. atomic_inc(&ds->ds_clp->cl_count);
  1596. hdr->ds_clp = ds->ds_clp;
  1597. hdr->ds_commit_idx = idx;
  1598. fh = nfs4_ff_layout_select_ds_fh(lseg, idx);
  1599. if (fh)
  1600. hdr->args.fh = fh;
  1601. /*
  1602. * Note that if we ever decide to split across DSes,
  1603. * then we may need to handle dense-like offsets.
  1604. */
  1605. hdr->args.offset = offset;
  1606. /* Perform an asynchronous write */
  1607. nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
  1608. vers == 3 ? &ff_layout_write_call_ops_v3 :
  1609. &ff_layout_write_call_ops_v4,
  1610. sync, RPC_TASK_SOFTCONN);
  1611. put_rpccred(ds_cred);
  1612. return PNFS_ATTEMPTED;
  1613. }
  1614. static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
  1615. {
  1616. return i;
  1617. }
  1618. static struct nfs_fh *
  1619. select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
  1620. {
  1621. struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
  1622. /* FIXME: Assume that there is only one NFS version available
  1623. * for the DS.
  1624. */
  1625. return &flseg->mirror_array[i]->fh_versions[0];
  1626. }
  1627. static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
  1628. {
  1629. struct pnfs_layout_segment *lseg = data->lseg;
  1630. struct nfs4_pnfs_ds *ds;
  1631. struct rpc_clnt *ds_clnt;
  1632. struct rpc_cred *ds_cred;
  1633. u32 idx;
  1634. int vers, ret;
  1635. struct nfs_fh *fh;
  1636. idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
  1637. ds = nfs4_ff_layout_prepare_ds(lseg, idx, true);
  1638. if (!ds)
  1639. goto out_err;
  1640. ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
  1641. data->inode);
  1642. if (IS_ERR(ds_clnt))
  1643. goto out_err;
  1644. ds_cred = ff_layout_get_ds_cred(lseg, idx, data->cred);
  1645. if (!ds_cred)
  1646. goto out_err;
  1647. vers = nfs4_ff_layout_ds_version(lseg, idx);
  1648. dprintk("%s ino %lu, how %d cl_count %d vers %d\n", __func__,
  1649. data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count),
  1650. vers);
  1651. data->commit_done_cb = ff_layout_commit_done_cb;
  1652. data->cred = ds_cred;
  1653. atomic_inc(&ds->ds_clp->cl_count);
  1654. data->ds_clp = ds->ds_clp;
  1655. fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
  1656. if (fh)
  1657. data->args.fh = fh;
  1658. ret = nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops,
  1659. vers == 3 ? &ff_layout_commit_call_ops_v3 :
  1660. &ff_layout_commit_call_ops_v4,
  1661. how, RPC_TASK_SOFTCONN);
  1662. put_rpccred(ds_cred);
  1663. return ret;
  1664. out_err:
  1665. pnfs_generic_prepare_to_resend_writes(data);
  1666. pnfs_generic_commit_release(data);
  1667. return -EAGAIN;
  1668. }
  1669. static int
  1670. ff_layout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
  1671. int how, struct nfs_commit_info *cinfo)
  1672. {
  1673. return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
  1674. ff_layout_initiate_commit);
  1675. }
  1676. static struct pnfs_ds_commit_info *
  1677. ff_layout_get_ds_info(struct inode *inode)
  1678. {
  1679. struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
  1680. if (layout == NULL)
  1681. return NULL;
  1682. return &FF_LAYOUT_FROM_HDR(layout)->commit_info;
  1683. }
  1684. static void
  1685. ff_layout_free_deviceid_node(struct nfs4_deviceid_node *d)
  1686. {
  1687. nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds,
  1688. id_node));
  1689. }
  1690. static int ff_layout_encode_ioerr(struct nfs4_flexfile_layout *flo,
  1691. struct xdr_stream *xdr,
  1692. const struct nfs4_layoutreturn_args *args)
  1693. {
  1694. struct pnfs_layout_hdr *hdr = &flo->generic_hdr;
  1695. __be32 *start;
  1696. int count = 0, ret = 0;
  1697. start = xdr_reserve_space(xdr, 4);
  1698. if (unlikely(!start))
  1699. return -E2BIG;
  1700. /* This assume we always return _ALL_ layouts */
  1701. spin_lock(&hdr->plh_inode->i_lock);
  1702. ret = ff_layout_encode_ds_ioerr(flo, xdr, &count, &args->range);
  1703. spin_unlock(&hdr->plh_inode->i_lock);
  1704. *start = cpu_to_be32(count);
  1705. return ret;
  1706. }
  1707. /* report nothing for now */
  1708. static void ff_layout_encode_iostats(struct nfs4_flexfile_layout *flo,
  1709. struct xdr_stream *xdr,
  1710. const struct nfs4_layoutreturn_args *args)
  1711. {
  1712. __be32 *p;
  1713. p = xdr_reserve_space(xdr, 4);
  1714. if (likely(p))
  1715. *p = cpu_to_be32(0);
  1716. }
  1717. static struct nfs4_deviceid_node *
  1718. ff_layout_alloc_deviceid_node(struct nfs_server *server,
  1719. struct pnfs_device *pdev, gfp_t gfp_flags)
  1720. {
  1721. struct nfs4_ff_layout_ds *dsaddr;
  1722. dsaddr = nfs4_ff_alloc_deviceid_node(server, pdev, gfp_flags);
  1723. if (!dsaddr)
  1724. return NULL;
  1725. return &dsaddr->id_node;
  1726. }
  1727. static void
  1728. ff_layout_encode_layoutreturn(struct pnfs_layout_hdr *lo,
  1729. struct xdr_stream *xdr,
  1730. const struct nfs4_layoutreturn_args *args)
  1731. {
  1732. struct nfs4_flexfile_layout *flo = FF_LAYOUT_FROM_HDR(lo);
  1733. __be32 *start;
  1734. dprintk("%s: Begin\n", __func__);
  1735. start = xdr_reserve_space(xdr, 4);
  1736. BUG_ON(!start);
  1737. ff_layout_encode_ioerr(flo, xdr, args);
  1738. ff_layout_encode_iostats(flo, xdr, args);
  1739. *start = cpu_to_be32((xdr->p - start - 1) * 4);
  1740. dprintk("%s: Return\n", __func__);
  1741. }
  1742. static int
  1743. ff_layout_ntop4(const struct sockaddr *sap, char *buf, const size_t buflen)
  1744. {
  1745. const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  1746. return snprintf(buf, buflen, "%pI4", &sin->sin_addr);
  1747. }
  1748. static size_t
  1749. ff_layout_ntop6_noscopeid(const struct sockaddr *sap, char *buf,
  1750. const int buflen)
  1751. {
  1752. const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  1753. const struct in6_addr *addr = &sin6->sin6_addr;
  1754. /*
  1755. * RFC 4291, Section 2.2.2
  1756. *
  1757. * Shorthanded ANY address
  1758. */
  1759. if (ipv6_addr_any(addr))
  1760. return snprintf(buf, buflen, "::");
  1761. /*
  1762. * RFC 4291, Section 2.2.2
  1763. *
  1764. * Shorthanded loopback address
  1765. */
  1766. if (ipv6_addr_loopback(addr))
  1767. return snprintf(buf, buflen, "::1");
  1768. /*
  1769. * RFC 4291, Section 2.2.3
  1770. *
  1771. * Special presentation address format for mapped v4
  1772. * addresses.
  1773. */
  1774. if (ipv6_addr_v4mapped(addr))
  1775. return snprintf(buf, buflen, "::ffff:%pI4",
  1776. &addr->s6_addr32[3]);
  1777. /*
  1778. * RFC 4291, Section 2.2.1
  1779. */
  1780. return snprintf(buf, buflen, "%pI6c", addr);
  1781. }
  1782. /* Derived from rpc_sockaddr2uaddr */
  1783. static void
  1784. ff_layout_encode_netaddr(struct xdr_stream *xdr, struct nfs4_pnfs_ds_addr *da)
  1785. {
  1786. struct sockaddr *sap = (struct sockaddr *)&da->da_addr;
  1787. char portbuf[RPCBIND_MAXUADDRPLEN];
  1788. char addrbuf[RPCBIND_MAXUADDRLEN];
  1789. char *netid;
  1790. unsigned short port;
  1791. int len, netid_len;
  1792. __be32 *p;
  1793. switch (sap->sa_family) {
  1794. case AF_INET:
  1795. if (ff_layout_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0)
  1796. return;
  1797. port = ntohs(((struct sockaddr_in *)sap)->sin_port);
  1798. netid = "tcp";
  1799. netid_len = 3;
  1800. break;
  1801. case AF_INET6:
  1802. if (ff_layout_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0)
  1803. return;
  1804. port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
  1805. netid = "tcp6";
  1806. netid_len = 4;
  1807. break;
  1808. default:
  1809. /* we only support tcp and tcp6 */
  1810. WARN_ON_ONCE(1);
  1811. return;
  1812. }
  1813. snprintf(portbuf, sizeof(portbuf), ".%u.%u", port >> 8, port & 0xff);
  1814. len = strlcat(addrbuf, portbuf, sizeof(addrbuf));
  1815. p = xdr_reserve_space(xdr, 4 + netid_len);
  1816. xdr_encode_opaque(p, netid, netid_len);
  1817. p = xdr_reserve_space(xdr, 4 + len);
  1818. xdr_encode_opaque(p, addrbuf, len);
  1819. }
  1820. static void
  1821. ff_layout_encode_nfstime(struct xdr_stream *xdr,
  1822. ktime_t t)
  1823. {
  1824. struct timespec64 ts;
  1825. __be32 *p;
  1826. p = xdr_reserve_space(xdr, 12);
  1827. ts = ktime_to_timespec64(t);
  1828. p = xdr_encode_hyper(p, ts.tv_sec);
  1829. *p++ = cpu_to_be32(ts.tv_nsec);
  1830. }
  1831. static void
  1832. ff_layout_encode_io_latency(struct xdr_stream *xdr,
  1833. struct nfs4_ff_io_stat *stat)
  1834. {
  1835. __be32 *p;
  1836. p = xdr_reserve_space(xdr, 5 * 8);
  1837. p = xdr_encode_hyper(p, stat->ops_requested);
  1838. p = xdr_encode_hyper(p, stat->bytes_requested);
  1839. p = xdr_encode_hyper(p, stat->ops_completed);
  1840. p = xdr_encode_hyper(p, stat->bytes_completed);
  1841. p = xdr_encode_hyper(p, stat->bytes_not_delivered);
  1842. ff_layout_encode_nfstime(xdr, stat->total_busy_time);
  1843. ff_layout_encode_nfstime(xdr, stat->aggregate_completion_time);
  1844. }
  1845. static void
  1846. ff_layout_encode_layoutstats(struct xdr_stream *xdr,
  1847. struct nfs42_layoutstat_args *args,
  1848. struct nfs42_layoutstat_devinfo *devinfo)
  1849. {
  1850. struct nfs4_ff_layout_mirror *mirror = devinfo->layout_private;
  1851. struct nfs4_pnfs_ds_addr *da;
  1852. struct nfs4_pnfs_ds *ds = mirror->mirror_ds->ds;
  1853. struct nfs_fh *fh = &mirror->fh_versions[0];
  1854. __be32 *p, *start;
  1855. da = list_first_entry(&ds->ds_addrs, struct nfs4_pnfs_ds_addr, da_node);
  1856. dprintk("%s: DS %s: encoding address %s\n",
  1857. __func__, ds->ds_remotestr, da->da_remotestr);
  1858. /* layoutupdate length */
  1859. start = xdr_reserve_space(xdr, 4);
  1860. /* netaddr4 */
  1861. ff_layout_encode_netaddr(xdr, da);
  1862. /* nfs_fh4 */
  1863. p = xdr_reserve_space(xdr, 4 + fh->size);
  1864. xdr_encode_opaque(p, fh->data, fh->size);
  1865. /* ff_io_latency4 read */
  1866. spin_lock(&mirror->lock);
  1867. ff_layout_encode_io_latency(xdr, &mirror->read_stat.io_stat);
  1868. /* ff_io_latency4 write */
  1869. ff_layout_encode_io_latency(xdr, &mirror->write_stat.io_stat);
  1870. spin_unlock(&mirror->lock);
  1871. /* nfstime4 */
  1872. ff_layout_encode_nfstime(xdr, ktime_sub(ktime_get(), mirror->start_time));
  1873. /* bool */
  1874. p = xdr_reserve_space(xdr, 4);
  1875. *p = cpu_to_be32(false);
  1876. *start = cpu_to_be32((xdr->p - start - 1) * 4);
  1877. }
  1878. static int
  1879. ff_layout_mirror_prepare_stats(struct nfs42_layoutstat_args *args,
  1880. struct pnfs_layout_hdr *lo,
  1881. int dev_limit)
  1882. {
  1883. struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
  1884. struct nfs4_ff_layout_mirror *mirror;
  1885. struct nfs4_deviceid_node *dev;
  1886. struct nfs42_layoutstat_devinfo *devinfo;
  1887. int i = 0;
  1888. list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) {
  1889. if (i >= dev_limit)
  1890. break;
  1891. if (!mirror->mirror_ds)
  1892. continue;
  1893. /* mirror refcount put in cleanup_layoutstats */
  1894. if (!atomic_inc_not_zero(&mirror->ref))
  1895. continue;
  1896. dev = &mirror->mirror_ds->id_node;
  1897. devinfo = &args->devinfo[i];
  1898. memcpy(&devinfo->dev_id, &dev->deviceid, NFS4_DEVICEID4_SIZE);
  1899. devinfo->offset = 0;
  1900. devinfo->length = NFS4_MAX_UINT64;
  1901. devinfo->read_count = mirror->read_stat.io_stat.ops_completed;
  1902. devinfo->read_bytes = mirror->read_stat.io_stat.bytes_completed;
  1903. devinfo->write_count = mirror->write_stat.io_stat.ops_completed;
  1904. devinfo->write_bytes = mirror->write_stat.io_stat.bytes_completed;
  1905. devinfo->layout_type = LAYOUT_FLEX_FILES;
  1906. devinfo->layoutstats_encode = ff_layout_encode_layoutstats;
  1907. devinfo->layout_private = mirror;
  1908. i++;
  1909. }
  1910. return i;
  1911. }
  1912. static int
  1913. ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args)
  1914. {
  1915. struct nfs4_flexfile_layout *ff_layout;
  1916. struct nfs4_ff_layout_mirror *mirror;
  1917. int dev_count = 0;
  1918. spin_lock(&args->inode->i_lock);
  1919. ff_layout = FF_LAYOUT_FROM_HDR(NFS_I(args->inode)->layout);
  1920. list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) {
  1921. if (atomic_read(&mirror->ref) != 0)
  1922. dev_count ++;
  1923. }
  1924. spin_unlock(&args->inode->i_lock);
  1925. /* For now, send at most PNFS_LAYOUTSTATS_MAXDEV statistics */
  1926. if (dev_count > PNFS_LAYOUTSTATS_MAXDEV) {
  1927. dprintk("%s: truncating devinfo to limit (%d:%d)\n",
  1928. __func__, dev_count, PNFS_LAYOUTSTATS_MAXDEV);
  1929. dev_count = PNFS_LAYOUTSTATS_MAXDEV;
  1930. }
  1931. args->devinfo = kmalloc_array(dev_count, sizeof(*args->devinfo), GFP_NOIO);
  1932. if (!args->devinfo)
  1933. return -ENOMEM;
  1934. spin_lock(&args->inode->i_lock);
  1935. args->num_dev = ff_layout_mirror_prepare_stats(args,
  1936. &ff_layout->generic_hdr, dev_count);
  1937. spin_unlock(&args->inode->i_lock);
  1938. return 0;
  1939. }
  1940. static void
  1941. ff_layout_cleanup_layoutstats(struct nfs42_layoutstat_data *data)
  1942. {
  1943. struct nfs4_ff_layout_mirror *mirror;
  1944. int i;
  1945. for (i = 0; i < data->args.num_dev; i++) {
  1946. mirror = data->args.devinfo[i].layout_private;
  1947. data->args.devinfo[i].layout_private = NULL;
  1948. ff_layout_put_mirror(mirror);
  1949. }
  1950. }
  1951. static struct pnfs_layoutdriver_type flexfilelayout_type = {
  1952. .id = LAYOUT_FLEX_FILES,
  1953. .name = "LAYOUT_FLEX_FILES",
  1954. .owner = THIS_MODULE,
  1955. .alloc_layout_hdr = ff_layout_alloc_layout_hdr,
  1956. .free_layout_hdr = ff_layout_free_layout_hdr,
  1957. .alloc_lseg = ff_layout_alloc_lseg,
  1958. .free_lseg = ff_layout_free_lseg,
  1959. .add_lseg = ff_layout_add_lseg,
  1960. .pg_read_ops = &ff_layout_pg_read_ops,
  1961. .pg_write_ops = &ff_layout_pg_write_ops,
  1962. .get_ds_info = ff_layout_get_ds_info,
  1963. .free_deviceid_node = ff_layout_free_deviceid_node,
  1964. .mark_request_commit = pnfs_layout_mark_request_commit,
  1965. .clear_request_commit = pnfs_generic_clear_request_commit,
  1966. .scan_commit_lists = pnfs_generic_scan_commit_lists,
  1967. .recover_commit_reqs = pnfs_generic_recover_commit_reqs,
  1968. .commit_pagelist = ff_layout_commit_pagelist,
  1969. .read_pagelist = ff_layout_read_pagelist,
  1970. .write_pagelist = ff_layout_write_pagelist,
  1971. .alloc_deviceid_node = ff_layout_alloc_deviceid_node,
  1972. .encode_layoutreturn = ff_layout_encode_layoutreturn,
  1973. .sync = pnfs_nfs_generic_sync,
  1974. .prepare_layoutstats = ff_layout_prepare_layoutstats,
  1975. .cleanup_layoutstats = ff_layout_cleanup_layoutstats,
  1976. };
  1977. static int __init nfs4flexfilelayout_init(void)
  1978. {
  1979. printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Registering...\n",
  1980. __func__);
  1981. if (!ff_zero_group) {
  1982. ff_zero_group = groups_alloc(0);
  1983. if (!ff_zero_group)
  1984. return -ENOMEM;
  1985. }
  1986. return pnfs_register_layoutdriver(&flexfilelayout_type);
  1987. }
  1988. static void __exit nfs4flexfilelayout_exit(void)
  1989. {
  1990. printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Unregistering...\n",
  1991. __func__);
  1992. pnfs_unregister_layoutdriver(&flexfilelayout_type);
  1993. if (ff_zero_group) {
  1994. put_group_info(ff_zero_group);
  1995. ff_zero_group = NULL;
  1996. }
  1997. }
  1998. MODULE_ALIAS("nfs-layouttype4-4");
  1999. MODULE_LICENSE("GPL");
  2000. MODULE_DESCRIPTION("The NFSv4 flexfile layout driver");
  2001. module_init(nfs4flexfilelayout_init);
  2002. module_exit(nfs4flexfilelayout_exit);