pnfs.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  1. /*
  2. * pNFS functions to call and manage layout drivers.
  3. *
  4. * Copyright (c) 2002 [year of first publication]
  5. * The Regents of the University of Michigan
  6. * All Rights Reserved
  7. *
  8. * Dean Hildebrand <dhildebz@umich.edu>
  9. *
  10. * Permission is granted to use, copy, create derivative works, and
  11. * redistribute this software and such derivative works for any purpose,
  12. * so long as the name of the University of Michigan is not used in
  13. * any advertising or publicity pertaining to the use or distribution
  14. * of this software without specific, written prior authorization. If
  15. * the above copyright notice or any other identification of the
  16. * University of Michigan is included in any copy of any portion of
  17. * this software, then the disclaimer below must also be included.
  18. *
  19. * This software is provided as is, without representation or warranty
  20. * of any kind either express or implied, including without limitation
  21. * the implied warranties of merchantability, fitness for a particular
  22. * purpose, or noninfringement. The Regents of the University of
  23. * Michigan shall not be liable for any damages, including special,
  24. * indirect, incidental, or consequential damages, with respect to any
  25. * claim arising out of or in connection with the use of the software,
  26. * even if it has been or is hereafter advised of the possibility of
  27. * such damages.
  28. */
  29. #include <linux/nfs_fs.h>
  30. #include <linux/nfs_page.h>
  31. #include <linux/module.h>
  32. #include "internal.h"
  33. #include "pnfs.h"
  34. #include "iostat.h"
  35. #define NFSDBG_FACILITY NFSDBG_PNFS
  36. /* Locking:
  37. *
  38. * pnfs_spinlock:
  39. * protects pnfs_modules_tbl.
  40. */
  41. static DEFINE_SPINLOCK(pnfs_spinlock);
  42. /*
  43. * pnfs_modules_tbl holds all pnfs modules
  44. */
  45. static LIST_HEAD(pnfs_modules_tbl);
  46. /* Return the registered pnfs layout driver module matching given id */
  47. static struct pnfs_layoutdriver_type *
  48. find_pnfs_driver_locked(u32 id)
  49. {
  50. struct pnfs_layoutdriver_type *local;
  51. list_for_each_entry(local, &pnfs_modules_tbl, pnfs_tblid)
  52. if (local->id == id)
  53. goto out;
  54. local = NULL;
  55. out:
  56. dprintk("%s: Searching for id %u, found %p\n", __func__, id, local);
  57. return local;
  58. }
  59. static struct pnfs_layoutdriver_type *
  60. find_pnfs_driver(u32 id)
  61. {
  62. struct pnfs_layoutdriver_type *local;
  63. spin_lock(&pnfs_spinlock);
  64. local = find_pnfs_driver_locked(id);
  65. spin_unlock(&pnfs_spinlock);
  66. return local;
  67. }
  68. void
  69. unset_pnfs_layoutdriver(struct nfs_server *nfss)
  70. {
  71. if (nfss->pnfs_curr_ld) {
  72. if (nfss->pnfs_curr_ld->clear_layoutdriver)
  73. nfss->pnfs_curr_ld->clear_layoutdriver(nfss);
  74. module_put(nfss->pnfs_curr_ld->owner);
  75. }
  76. nfss->pnfs_curr_ld = NULL;
  77. }
  78. /*
  79. * Try to set the server's pnfs module to the pnfs layout type specified by id.
  80. * Currently only one pNFS layout driver per filesystem is supported.
  81. *
  82. * @id layout type. Zero (illegal layout type) indicates pNFS not in use.
  83. */
  84. void
  85. set_pnfs_layoutdriver(struct nfs_server *server, const struct nfs_fh *mntfh,
  86. u32 id)
  87. {
  88. struct pnfs_layoutdriver_type *ld_type = NULL;
  89. if (id == 0)
  90. goto out_no_driver;
  91. if (!(server->nfs_client->cl_exchange_flags &
  92. (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) {
  93. printk(KERN_ERR "NFS: %s: id %u cl_exchange_flags 0x%x\n",
  94. __func__, id, server->nfs_client->cl_exchange_flags);
  95. goto out_no_driver;
  96. }
  97. ld_type = find_pnfs_driver(id);
  98. if (!ld_type) {
  99. request_module("%s-%u", LAYOUT_NFSV4_1_MODULE_PREFIX, id);
  100. ld_type = find_pnfs_driver(id);
  101. if (!ld_type) {
  102. dprintk("%s: No pNFS module found for %u.\n",
  103. __func__, id);
  104. goto out_no_driver;
  105. }
  106. }
  107. if (!try_module_get(ld_type->owner)) {
  108. dprintk("%s: Could not grab reference on module\n", __func__);
  109. goto out_no_driver;
  110. }
  111. server->pnfs_curr_ld = ld_type;
  112. if (ld_type->set_layoutdriver
  113. && ld_type->set_layoutdriver(server, mntfh)) {
  114. printk(KERN_ERR "NFS: %s: Error initializing pNFS layout "
  115. "driver %u.\n", __func__, id);
  116. module_put(ld_type->owner);
  117. goto out_no_driver;
  118. }
  119. dprintk("%s: pNFS module for %u set\n", __func__, id);
  120. return;
  121. out_no_driver:
  122. dprintk("%s: Using NFSv4 I/O\n", __func__);
  123. server->pnfs_curr_ld = NULL;
  124. }
  125. int
  126. pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
  127. {
  128. int status = -EINVAL;
  129. struct pnfs_layoutdriver_type *tmp;
  130. if (ld_type->id == 0) {
  131. printk(KERN_ERR "NFS: %s id 0 is reserved\n", __func__);
  132. return status;
  133. }
  134. if (!ld_type->alloc_lseg || !ld_type->free_lseg) {
  135. printk(KERN_ERR "NFS: %s Layout driver must provide "
  136. "alloc_lseg and free_lseg.\n", __func__);
  137. return status;
  138. }
  139. spin_lock(&pnfs_spinlock);
  140. tmp = find_pnfs_driver_locked(ld_type->id);
  141. if (!tmp) {
  142. list_add(&ld_type->pnfs_tblid, &pnfs_modules_tbl);
  143. status = 0;
  144. dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id,
  145. ld_type->name);
  146. } else {
  147. printk(KERN_ERR "NFS: %s Module with id %d already loaded!\n",
  148. __func__, ld_type->id);
  149. }
  150. spin_unlock(&pnfs_spinlock);
  151. return status;
  152. }
  153. EXPORT_SYMBOL_GPL(pnfs_register_layoutdriver);
  154. void
  155. pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
  156. {
  157. dprintk("%s Deregistering id:%u\n", __func__, ld_type->id);
  158. spin_lock(&pnfs_spinlock);
  159. list_del(&ld_type->pnfs_tblid);
  160. spin_unlock(&pnfs_spinlock);
  161. }
  162. EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver);
  163. /*
  164. * pNFS client layout cache
  165. */
  166. /* Need to hold i_lock if caller does not already hold reference */
  167. void
  168. get_layout_hdr(struct pnfs_layout_hdr *lo)
  169. {
  170. atomic_inc(&lo->plh_refcount);
  171. }
  172. static struct pnfs_layout_hdr *
  173. pnfs_alloc_layout_hdr(struct inode *ino, gfp_t gfp_flags)
  174. {
  175. struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld;
  176. return ld->alloc_layout_hdr ? ld->alloc_layout_hdr(ino, gfp_flags) :
  177. kzalloc(sizeof(struct pnfs_layout_hdr), gfp_flags);
  178. }
  179. static void
  180. pnfs_free_layout_hdr(struct pnfs_layout_hdr *lo)
  181. {
  182. struct pnfs_layoutdriver_type *ld = NFS_SERVER(lo->plh_inode)->pnfs_curr_ld;
  183. put_rpccred(lo->plh_lc_cred);
  184. return ld->alloc_layout_hdr ? ld->free_layout_hdr(lo) : kfree(lo);
  185. }
  186. static void
  187. destroy_layout_hdr(struct pnfs_layout_hdr *lo)
  188. {
  189. dprintk("%s: freeing layout cache %p\n", __func__, lo);
  190. BUG_ON(!list_empty(&lo->plh_layouts));
  191. NFS_I(lo->plh_inode)->layout = NULL;
  192. pnfs_free_layout_hdr(lo);
  193. }
  194. static void
  195. put_layout_hdr_locked(struct pnfs_layout_hdr *lo)
  196. {
  197. if (atomic_dec_and_test(&lo->plh_refcount))
  198. destroy_layout_hdr(lo);
  199. }
  200. void
  201. put_layout_hdr(struct pnfs_layout_hdr *lo)
  202. {
  203. struct inode *inode = lo->plh_inode;
  204. if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
  205. destroy_layout_hdr(lo);
  206. spin_unlock(&inode->i_lock);
  207. }
  208. }
  209. static void
  210. init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg)
  211. {
  212. INIT_LIST_HEAD(&lseg->pls_list);
  213. INIT_LIST_HEAD(&lseg->pls_lc_list);
  214. atomic_set(&lseg->pls_refcount, 1);
  215. smp_mb();
  216. set_bit(NFS_LSEG_VALID, &lseg->pls_flags);
  217. lseg->pls_layout = lo;
  218. }
  219. static void free_lseg(struct pnfs_layout_segment *lseg)
  220. {
  221. struct inode *ino = lseg->pls_layout->plh_inode;
  222. NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
  223. /* Matched by get_layout_hdr in pnfs_insert_layout */
  224. put_layout_hdr(NFS_I(ino)->layout);
  225. }
  226. static void
  227. put_lseg_common(struct pnfs_layout_segment *lseg)
  228. {
  229. struct inode *inode = lseg->pls_layout->plh_inode;
  230. WARN_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
  231. list_del_init(&lseg->pls_list);
  232. if (list_empty(&lseg->pls_layout->plh_segs)) {
  233. set_bit(NFS_LAYOUT_DESTROYED, &lseg->pls_layout->plh_flags);
  234. /* Matched by initial refcount set in alloc_init_layout_hdr */
  235. put_layout_hdr_locked(lseg->pls_layout);
  236. }
  237. rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq);
  238. }
  239. void
  240. put_lseg(struct pnfs_layout_segment *lseg)
  241. {
  242. struct inode *inode;
  243. if (!lseg)
  244. return;
  245. dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg,
  246. atomic_read(&lseg->pls_refcount),
  247. test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
  248. inode = lseg->pls_layout->plh_inode;
  249. if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) {
  250. LIST_HEAD(free_me);
  251. put_lseg_common(lseg);
  252. list_add(&lseg->pls_list, &free_me);
  253. spin_unlock(&inode->i_lock);
  254. pnfs_free_lseg_list(&free_me);
  255. }
  256. }
  257. EXPORT_SYMBOL_GPL(put_lseg);
  258. static inline u64
  259. end_offset(u64 start, u64 len)
  260. {
  261. u64 end;
  262. end = start + len;
  263. return end >= start ? end : NFS4_MAX_UINT64;
  264. }
  265. /* last octet in a range */
  266. static inline u64
  267. last_byte_offset(u64 start, u64 len)
  268. {
  269. u64 end;
  270. BUG_ON(!len);
  271. end = start + len;
  272. return end > start ? end - 1 : NFS4_MAX_UINT64;
  273. }
  274. /*
  275. * is l2 fully contained in l1?
  276. * start1 end1
  277. * [----------------------------------)
  278. * start2 end2
  279. * [----------------)
  280. */
  281. static inline int
  282. lo_seg_contained(struct pnfs_layout_range *l1,
  283. struct pnfs_layout_range *l2)
  284. {
  285. u64 start1 = l1->offset;
  286. u64 end1 = end_offset(start1, l1->length);
  287. u64 start2 = l2->offset;
  288. u64 end2 = end_offset(start2, l2->length);
  289. return (start1 <= start2) && (end1 >= end2);
  290. }
  291. /*
  292. * is l1 and l2 intersecting?
  293. * start1 end1
  294. * [----------------------------------)
  295. * start2 end2
  296. * [----------------)
  297. */
  298. static inline int
  299. lo_seg_intersecting(struct pnfs_layout_range *l1,
  300. struct pnfs_layout_range *l2)
  301. {
  302. u64 start1 = l1->offset;
  303. u64 end1 = end_offset(start1, l1->length);
  304. u64 start2 = l2->offset;
  305. u64 end2 = end_offset(start2, l2->length);
  306. return (end1 == NFS4_MAX_UINT64 || end1 > start2) &&
  307. (end2 == NFS4_MAX_UINT64 || end2 > start1);
  308. }
  309. static bool
  310. should_free_lseg(struct pnfs_layout_range *lseg_range,
  311. struct pnfs_layout_range *recall_range)
  312. {
  313. return (recall_range->iomode == IOMODE_ANY ||
  314. lseg_range->iomode == recall_range->iomode) &&
  315. lo_seg_intersecting(lseg_range, recall_range);
  316. }
  317. /* Returns 1 if lseg is removed from list, 0 otherwise */
  318. static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
  319. struct list_head *tmp_list)
  320. {
  321. int rv = 0;
  322. if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) {
  323. /* Remove the reference keeping the lseg in the
  324. * list. It will now be removed when all
  325. * outstanding io is finished.
  326. */
  327. dprintk("%s: lseg %p ref %d\n", __func__, lseg,
  328. atomic_read(&lseg->pls_refcount));
  329. if (atomic_dec_and_test(&lseg->pls_refcount)) {
  330. put_lseg_common(lseg);
  331. list_add(&lseg->pls_list, tmp_list);
  332. rv = 1;
  333. }
  334. }
  335. return rv;
  336. }
  337. /* Returns count of number of matching invalid lsegs remaining in list
  338. * after call.
  339. */
  340. int
  341. mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
  342. struct list_head *tmp_list,
  343. struct pnfs_layout_range *recall_range)
  344. {
  345. struct pnfs_layout_segment *lseg, *next;
  346. int invalid = 0, removed = 0;
  347. dprintk("%s:Begin lo %p\n", __func__, lo);
  348. if (list_empty(&lo->plh_segs)) {
  349. /* Reset MDS Threshold I/O counters */
  350. NFS_I(lo->plh_inode)->write_io = 0;
  351. NFS_I(lo->plh_inode)->read_io = 0;
  352. if (!test_and_set_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags))
  353. put_layout_hdr_locked(lo);
  354. return 0;
  355. }
  356. list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
  357. if (!recall_range ||
  358. should_free_lseg(&lseg->pls_range, recall_range)) {
  359. dprintk("%s: freeing lseg %p iomode %d "
  360. "offset %llu length %llu\n", __func__,
  361. lseg, lseg->pls_range.iomode, lseg->pls_range.offset,
  362. lseg->pls_range.length);
  363. invalid++;
  364. removed += mark_lseg_invalid(lseg, tmp_list);
  365. }
  366. dprintk("%s:Return %i\n", __func__, invalid - removed);
  367. return invalid - removed;
  368. }
  369. /* note free_me must contain lsegs from a single layout_hdr */
  370. void
  371. pnfs_free_lseg_list(struct list_head *free_me)
  372. {
  373. struct pnfs_layout_segment *lseg, *tmp;
  374. struct pnfs_layout_hdr *lo;
  375. if (list_empty(free_me))
  376. return;
  377. lo = list_first_entry(free_me, struct pnfs_layout_segment,
  378. pls_list)->pls_layout;
  379. if (test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags)) {
  380. struct nfs_client *clp;
  381. clp = NFS_SERVER(lo->plh_inode)->nfs_client;
  382. spin_lock(&clp->cl_lock);
  383. list_del_init(&lo->plh_layouts);
  384. spin_unlock(&clp->cl_lock);
  385. }
  386. list_for_each_entry_safe(lseg, tmp, free_me, pls_list) {
  387. list_del(&lseg->pls_list);
  388. free_lseg(lseg);
  389. }
  390. }
  391. void
  392. pnfs_destroy_layout(struct nfs_inode *nfsi)
  393. {
  394. struct pnfs_layout_hdr *lo;
  395. LIST_HEAD(tmp_list);
  396. spin_lock(&nfsi->vfs_inode.i_lock);
  397. lo = nfsi->layout;
  398. if (lo) {
  399. lo->plh_block_lgets++; /* permanently block new LAYOUTGETs */
  400. mark_matching_lsegs_invalid(lo, &tmp_list, NULL);
  401. }
  402. spin_unlock(&nfsi->vfs_inode.i_lock);
  403. pnfs_free_lseg_list(&tmp_list);
  404. }
  405. EXPORT_SYMBOL_GPL(pnfs_destroy_layout);
  406. /*
  407. * Called by the state manger to remove all layouts established under an
  408. * expired lease.
  409. */
  410. void
  411. pnfs_destroy_all_layouts(struct nfs_client *clp)
  412. {
  413. struct nfs_server *server;
  414. struct pnfs_layout_hdr *lo;
  415. LIST_HEAD(tmp_list);
  416. nfs4_deviceid_mark_client_invalid(clp);
  417. nfs4_deviceid_purge_client(clp);
  418. spin_lock(&clp->cl_lock);
  419. rcu_read_lock();
  420. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  421. if (!list_empty(&server->layouts))
  422. list_splice_init(&server->layouts, &tmp_list);
  423. }
  424. rcu_read_unlock();
  425. spin_unlock(&clp->cl_lock);
  426. while (!list_empty(&tmp_list)) {
  427. lo = list_entry(tmp_list.next, struct pnfs_layout_hdr,
  428. plh_layouts);
  429. dprintk("%s freeing layout for inode %lu\n", __func__,
  430. lo->plh_inode->i_ino);
  431. list_del_init(&lo->plh_layouts);
  432. pnfs_destroy_layout(NFS_I(lo->plh_inode));
  433. }
  434. }
  435. /* update lo->plh_stateid with new if is more recent */
  436. void
  437. pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
  438. bool update_barrier)
  439. {
  440. u32 oldseq, newseq;
  441. oldseq = be32_to_cpu(lo->plh_stateid.seqid);
  442. newseq = be32_to_cpu(new->seqid);
  443. if ((int)(newseq - oldseq) > 0) {
  444. nfs4_stateid_copy(&lo->plh_stateid, new);
  445. if (update_barrier) {
  446. u32 new_barrier = be32_to_cpu(new->seqid);
  447. if ((int)(new_barrier - lo->plh_barrier))
  448. lo->plh_barrier = new_barrier;
  449. } else {
  450. /* Because of wraparound, we want to keep the barrier
  451. * "close" to the current seqids. It needs to be
  452. * within 2**31 to count as "behind", so if it
  453. * gets too near that limit, give us a litle leeway
  454. * and bring it to within 2**30.
  455. * NOTE - and yes, this is all unsigned arithmetic.
  456. */
  457. if (unlikely((newseq - lo->plh_barrier) > (3 << 29)))
  458. lo->plh_barrier = newseq - (1 << 30);
  459. }
  460. }
  461. }
  462. /* lget is set to 1 if called from inside send_layoutget call chain */
  463. static bool
  464. pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
  465. int lget)
  466. {
  467. if ((stateid) &&
  468. (int)(lo->plh_barrier - be32_to_cpu(stateid->seqid)) >= 0)
  469. return true;
  470. return lo->plh_block_lgets ||
  471. test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) ||
  472. test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
  473. (list_empty(&lo->plh_segs) &&
  474. (atomic_read(&lo->plh_outstanding) > lget));
  475. }
  476. int
  477. pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
  478. struct nfs4_state *open_state)
  479. {
  480. int status = 0;
  481. dprintk("--> %s\n", __func__);
  482. spin_lock(&lo->plh_inode->i_lock);
  483. if (pnfs_layoutgets_blocked(lo, NULL, 1)) {
  484. status = -EAGAIN;
  485. } else if (list_empty(&lo->plh_segs)) {
  486. int seq;
  487. do {
  488. seq = read_seqbegin(&open_state->seqlock);
  489. nfs4_stateid_copy(dst, &open_state->stateid);
  490. } while (read_seqretry(&open_state->seqlock, seq));
  491. } else
  492. nfs4_stateid_copy(dst, &lo->plh_stateid);
  493. spin_unlock(&lo->plh_inode->i_lock);
  494. dprintk("<-- %s\n", __func__);
  495. return status;
  496. }
  497. /*
  498. * Get layout from server.
  499. * for now, assume that whole file layouts are requested.
  500. * arg->offset: 0
  501. * arg->length: all ones
  502. */
  503. static struct pnfs_layout_segment *
  504. send_layoutget(struct pnfs_layout_hdr *lo,
  505. struct nfs_open_context *ctx,
  506. struct pnfs_layout_range *range,
  507. gfp_t gfp_flags)
  508. {
  509. struct inode *ino = lo->plh_inode;
  510. struct nfs_server *server = NFS_SERVER(ino);
  511. struct nfs4_layoutget *lgp;
  512. struct pnfs_layout_segment *lseg = NULL;
  513. struct page **pages = NULL;
  514. int i;
  515. u32 max_resp_sz, max_pages;
  516. dprintk("--> %s\n", __func__);
  517. BUG_ON(ctx == NULL);
  518. lgp = kzalloc(sizeof(*lgp), gfp_flags);
  519. if (lgp == NULL)
  520. return NULL;
  521. /* allocate pages for xdr post processing */
  522. max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
  523. max_pages = nfs_page_array_len(0, max_resp_sz);
  524. pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags);
  525. if (!pages)
  526. goto out_err_free;
  527. for (i = 0; i < max_pages; i++) {
  528. pages[i] = alloc_page(gfp_flags);
  529. if (!pages[i])
  530. goto out_err_free;
  531. }
  532. lgp->args.minlength = PAGE_CACHE_SIZE;
  533. if (lgp->args.minlength > range->length)
  534. lgp->args.minlength = range->length;
  535. lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE;
  536. lgp->args.range = *range;
  537. lgp->args.type = server->pnfs_curr_ld->id;
  538. lgp->args.inode = ino;
  539. lgp->args.ctx = get_nfs_open_context(ctx);
  540. lgp->args.layout.pages = pages;
  541. lgp->args.layout.pglen = max_pages * PAGE_SIZE;
  542. lgp->lsegpp = &lseg;
  543. lgp->gfp_flags = gfp_flags;
  544. /* Synchronously retrieve layout information from server and
  545. * store in lseg.
  546. */
  547. nfs4_proc_layoutget(lgp);
  548. if (!lseg) {
  549. /* remember that LAYOUTGET failed and suspend trying */
  550. set_bit(lo_fail_bit(range->iomode), &lo->plh_flags);
  551. }
  552. /* free xdr pages */
  553. for (i = 0; i < max_pages; i++)
  554. __free_page(pages[i]);
  555. kfree(pages);
  556. return lseg;
  557. out_err_free:
  558. /* free any allocated xdr pages, lgp as it's not used */
  559. if (pages) {
  560. for (i = 0; i < max_pages; i++) {
  561. if (!pages[i])
  562. break;
  563. __free_page(pages[i]);
  564. }
  565. kfree(pages);
  566. }
  567. kfree(lgp);
  568. return NULL;
  569. }
  570. /* Initiates a LAYOUTRETURN(FILE) */
  571. int
  572. _pnfs_return_layout(struct inode *ino)
  573. {
  574. struct pnfs_layout_hdr *lo = NULL;
  575. struct nfs_inode *nfsi = NFS_I(ino);
  576. LIST_HEAD(tmp_list);
  577. struct nfs4_layoutreturn *lrp;
  578. nfs4_stateid stateid;
  579. int status = 0;
  580. dprintk("--> %s\n", __func__);
  581. spin_lock(&ino->i_lock);
  582. lo = nfsi->layout;
  583. if (!lo) {
  584. spin_unlock(&ino->i_lock);
  585. dprintk("%s: no layout to return\n", __func__);
  586. return status;
  587. }
  588. stateid = nfsi->layout->plh_stateid;
  589. /* Reference matched in nfs4_layoutreturn_release */
  590. get_layout_hdr(lo);
  591. mark_matching_lsegs_invalid(lo, &tmp_list, NULL);
  592. lo->plh_block_lgets++;
  593. spin_unlock(&ino->i_lock);
  594. pnfs_free_lseg_list(&tmp_list);
  595. WARN_ON(test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags));
  596. lrp = kzalloc(sizeof(*lrp), GFP_KERNEL);
  597. if (unlikely(lrp == NULL)) {
  598. status = -ENOMEM;
  599. set_bit(NFS_LAYOUT_RW_FAILED, &lo->plh_flags);
  600. set_bit(NFS_LAYOUT_RO_FAILED, &lo->plh_flags);
  601. put_layout_hdr(lo);
  602. goto out;
  603. }
  604. lrp->args.stateid = stateid;
  605. lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id;
  606. lrp->args.inode = ino;
  607. lrp->args.layout = lo;
  608. lrp->clp = NFS_SERVER(ino)->nfs_client;
  609. status = nfs4_proc_layoutreturn(lrp);
  610. out:
  611. dprintk("<-- %s status: %d\n", __func__, status);
  612. return status;
  613. }
  614. EXPORT_SYMBOL_GPL(_pnfs_return_layout);
  615. bool pnfs_roc(struct inode *ino)
  616. {
  617. struct pnfs_layout_hdr *lo;
  618. struct pnfs_layout_segment *lseg, *tmp;
  619. LIST_HEAD(tmp_list);
  620. bool found = false;
  621. spin_lock(&ino->i_lock);
  622. lo = NFS_I(ino)->layout;
  623. if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) ||
  624. test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags))
  625. goto out_nolayout;
  626. list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list)
  627. if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
  628. mark_lseg_invalid(lseg, &tmp_list);
  629. found = true;
  630. }
  631. if (!found)
  632. goto out_nolayout;
  633. lo->plh_block_lgets++;
  634. get_layout_hdr(lo); /* matched in pnfs_roc_release */
  635. spin_unlock(&ino->i_lock);
  636. pnfs_free_lseg_list(&tmp_list);
  637. return true;
  638. out_nolayout:
  639. spin_unlock(&ino->i_lock);
  640. return false;
  641. }
  642. void pnfs_roc_release(struct inode *ino)
  643. {
  644. struct pnfs_layout_hdr *lo;
  645. spin_lock(&ino->i_lock);
  646. lo = NFS_I(ino)->layout;
  647. lo->plh_block_lgets--;
  648. put_layout_hdr_locked(lo);
  649. spin_unlock(&ino->i_lock);
  650. }
  651. void pnfs_roc_set_barrier(struct inode *ino, u32 barrier)
  652. {
  653. struct pnfs_layout_hdr *lo;
  654. spin_lock(&ino->i_lock);
  655. lo = NFS_I(ino)->layout;
  656. if ((int)(barrier - lo->plh_barrier) > 0)
  657. lo->plh_barrier = barrier;
  658. spin_unlock(&ino->i_lock);
  659. }
  660. bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
  661. {
  662. struct nfs_inode *nfsi = NFS_I(ino);
  663. struct pnfs_layout_segment *lseg;
  664. bool found = false;
  665. spin_lock(&ino->i_lock);
  666. list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list)
  667. if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
  668. found = true;
  669. break;
  670. }
  671. if (!found) {
  672. struct pnfs_layout_hdr *lo = nfsi->layout;
  673. u32 current_seqid = be32_to_cpu(lo->plh_stateid.seqid);
  674. /* Since close does not return a layout stateid for use as
  675. * a barrier, we choose the worst-case barrier.
  676. */
  677. *barrier = current_seqid + atomic_read(&lo->plh_outstanding);
  678. }
  679. spin_unlock(&ino->i_lock);
  680. return found;
  681. }
  682. /*
  683. * Compare two layout segments for sorting into layout cache.
  684. * We want to preferentially return RW over RO layouts, so ensure those
  685. * are seen first.
  686. */
  687. static s64
  688. cmp_layout(struct pnfs_layout_range *l1,
  689. struct pnfs_layout_range *l2)
  690. {
  691. s64 d;
  692. /* high offset > low offset */
  693. d = l1->offset - l2->offset;
  694. if (d)
  695. return d;
  696. /* short length > long length */
  697. d = l2->length - l1->length;
  698. if (d)
  699. return d;
  700. /* read > read/write */
  701. return (int)(l1->iomode == IOMODE_READ) - (int)(l2->iomode == IOMODE_READ);
  702. }
  703. static void
  704. pnfs_insert_layout(struct pnfs_layout_hdr *lo,
  705. struct pnfs_layout_segment *lseg)
  706. {
  707. struct pnfs_layout_segment *lp;
  708. dprintk("%s:Begin\n", __func__);
  709. assert_spin_locked(&lo->plh_inode->i_lock);
  710. list_for_each_entry(lp, &lo->plh_segs, pls_list) {
  711. if (cmp_layout(&lseg->pls_range, &lp->pls_range) > 0)
  712. continue;
  713. list_add_tail(&lseg->pls_list, &lp->pls_list);
  714. dprintk("%s: inserted lseg %p "
  715. "iomode %d offset %llu length %llu before "
  716. "lp %p iomode %d offset %llu length %llu\n",
  717. __func__, lseg, lseg->pls_range.iomode,
  718. lseg->pls_range.offset, lseg->pls_range.length,
  719. lp, lp->pls_range.iomode, lp->pls_range.offset,
  720. lp->pls_range.length);
  721. goto out;
  722. }
  723. list_add_tail(&lseg->pls_list, &lo->plh_segs);
  724. dprintk("%s: inserted lseg %p "
  725. "iomode %d offset %llu length %llu at tail\n",
  726. __func__, lseg, lseg->pls_range.iomode,
  727. lseg->pls_range.offset, lseg->pls_range.length);
  728. out:
  729. get_layout_hdr(lo);
  730. dprintk("%s:Return\n", __func__);
  731. }
  732. static struct pnfs_layout_hdr *
  733. alloc_init_layout_hdr(struct inode *ino,
  734. struct nfs_open_context *ctx,
  735. gfp_t gfp_flags)
  736. {
  737. struct pnfs_layout_hdr *lo;
  738. lo = pnfs_alloc_layout_hdr(ino, gfp_flags);
  739. if (!lo)
  740. return NULL;
  741. atomic_set(&lo->plh_refcount, 1);
  742. INIT_LIST_HEAD(&lo->plh_layouts);
  743. INIT_LIST_HEAD(&lo->plh_segs);
  744. INIT_LIST_HEAD(&lo->plh_bulk_recall);
  745. lo->plh_inode = ino;
  746. lo->plh_lc_cred = get_rpccred(ctx->state->owner->so_cred);
  747. return lo;
  748. }
  749. static struct pnfs_layout_hdr *
  750. pnfs_find_alloc_layout(struct inode *ino,
  751. struct nfs_open_context *ctx,
  752. gfp_t gfp_flags)
  753. {
  754. struct nfs_inode *nfsi = NFS_I(ino);
  755. struct pnfs_layout_hdr *new = NULL;
  756. dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout);
  757. assert_spin_locked(&ino->i_lock);
  758. if (nfsi->layout) {
  759. if (test_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags))
  760. return NULL;
  761. else
  762. return nfsi->layout;
  763. }
  764. spin_unlock(&ino->i_lock);
  765. new = alloc_init_layout_hdr(ino, ctx, gfp_flags);
  766. spin_lock(&ino->i_lock);
  767. if (likely(nfsi->layout == NULL)) /* Won the race? */
  768. nfsi->layout = new;
  769. else
  770. pnfs_free_layout_hdr(new);
  771. return nfsi->layout;
  772. }
  773. /*
  774. * iomode matching rules:
  775. * iomode lseg match
  776. * ----- ----- -----
  777. * ANY READ true
  778. * ANY RW true
  779. * RW READ false
  780. * RW RW true
  781. * READ READ true
  782. * READ RW true
  783. */
  784. static int
  785. is_matching_lseg(struct pnfs_layout_range *ls_range,
  786. struct pnfs_layout_range *range)
  787. {
  788. struct pnfs_layout_range range1;
  789. if ((range->iomode == IOMODE_RW &&
  790. ls_range->iomode != IOMODE_RW) ||
  791. !lo_seg_intersecting(ls_range, range))
  792. return 0;
  793. /* range1 covers only the first byte in the range */
  794. range1 = *range;
  795. range1.length = 1;
  796. return lo_seg_contained(ls_range, &range1);
  797. }
  798. /*
  799. * lookup range in layout
  800. */
  801. static struct pnfs_layout_segment *
  802. pnfs_find_lseg(struct pnfs_layout_hdr *lo,
  803. struct pnfs_layout_range *range)
  804. {
  805. struct pnfs_layout_segment *lseg, *ret = NULL;
  806. dprintk("%s:Begin\n", __func__);
  807. assert_spin_locked(&lo->plh_inode->i_lock);
  808. list_for_each_entry(lseg, &lo->plh_segs, pls_list) {
  809. if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) &&
  810. is_matching_lseg(&lseg->pls_range, range)) {
  811. ret = get_lseg(lseg);
  812. break;
  813. }
  814. if (lseg->pls_range.offset > range->offset)
  815. break;
  816. }
  817. dprintk("%s:Return lseg %p ref %d\n",
  818. __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0);
  819. return ret;
  820. }
  821. /*
  822. * Use mdsthreshold hints set at each OPEN to determine if I/O should go
  823. * to the MDS or over pNFS
  824. *
  825. * The nfs_inode read_io and write_io fields are cumulative counters reset
  826. * when there are no layout segments. Note that in pnfs_update_layout iomode
  827. * is set to IOMODE_READ for a READ request, and set to IOMODE_RW for a
  828. * WRITE request.
  829. *
  830. * A return of true means use MDS I/O.
  831. *
  832. * From rfc 5661:
  833. * If a file's size is smaller than the file size threshold, data accesses
  834. * SHOULD be sent to the metadata server. If an I/O request has a length that
  835. * is below the I/O size threshold, the I/O SHOULD be sent to the metadata
  836. * server. If both file size and I/O size are provided, the client SHOULD
  837. * reach or exceed both thresholds before sending its read or write
  838. * requests to the data server.
  839. */
  840. static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx,
  841. struct inode *ino, int iomode)
  842. {
  843. struct nfs4_threshold *t = ctx->mdsthreshold;
  844. struct nfs_inode *nfsi = NFS_I(ino);
  845. loff_t fsize = i_size_read(ino);
  846. bool size = false, size_set = false, io = false, io_set = false, ret = false;
  847. if (t == NULL)
  848. return ret;
  849. dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
  850. __func__, t->bm, t->rd_sz, t->wr_sz, t->rd_io_sz, t->wr_io_sz);
  851. switch (iomode) {
  852. case IOMODE_READ:
  853. if (t->bm & THRESHOLD_RD) {
  854. dprintk("%s fsize %llu\n", __func__, fsize);
  855. size_set = true;
  856. if (fsize < t->rd_sz)
  857. size = true;
  858. }
  859. if (t->bm & THRESHOLD_RD_IO) {
  860. dprintk("%s nfsi->read_io %llu\n", __func__,
  861. nfsi->read_io);
  862. io_set = true;
  863. if (nfsi->read_io < t->rd_io_sz)
  864. io = true;
  865. }
  866. break;
  867. case IOMODE_RW:
  868. if (t->bm & THRESHOLD_WR) {
  869. dprintk("%s fsize %llu\n", __func__, fsize);
  870. size_set = true;
  871. if (fsize < t->wr_sz)
  872. size = true;
  873. }
  874. if (t->bm & THRESHOLD_WR_IO) {
  875. dprintk("%s nfsi->write_io %llu\n", __func__,
  876. nfsi->write_io);
  877. io_set = true;
  878. if (nfsi->write_io < t->wr_io_sz)
  879. io = true;
  880. }
  881. break;
  882. }
  883. if (size_set && io_set) {
  884. if (size && io)
  885. ret = true;
  886. } else if (size || io)
  887. ret = true;
  888. dprintk("<-- %s size %d io %d ret %d\n", __func__, size, io, ret);
  889. return ret;
  890. }
  891. /*
  892. * Layout segment is retreived from the server if not cached.
  893. * The appropriate layout segment is referenced and returned to the caller.
  894. */
  895. struct pnfs_layout_segment *
  896. pnfs_update_layout(struct inode *ino,
  897. struct nfs_open_context *ctx,
  898. loff_t pos,
  899. u64 count,
  900. enum pnfs_iomode iomode,
  901. gfp_t gfp_flags)
  902. {
  903. struct pnfs_layout_range arg = {
  904. .iomode = iomode,
  905. .offset = pos,
  906. .length = count,
  907. };
  908. unsigned pg_offset;
  909. struct nfs_inode *nfsi = NFS_I(ino);
  910. struct nfs_server *server = NFS_SERVER(ino);
  911. struct nfs_client *clp = server->nfs_client;
  912. struct pnfs_layout_hdr *lo;
  913. struct pnfs_layout_segment *lseg = NULL;
  914. bool first = false;
  915. if (!pnfs_enabled_sb(NFS_SERVER(ino)))
  916. return NULL;
  917. if (pnfs_within_mdsthreshold(ctx, ino, iomode))
  918. return NULL;
  919. spin_lock(&ino->i_lock);
  920. lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags);
  921. if (lo == NULL) {
  922. dprintk("%s ERROR: can't get pnfs_layout_hdr\n", __func__);
  923. goto out_unlock;
  924. }
  925. /* Do we even need to bother with this? */
  926. if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
  927. dprintk("%s matches recall, use MDS\n", __func__);
  928. goto out_unlock;
  929. }
  930. /* if LAYOUTGET already failed once we don't try again */
  931. if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags))
  932. goto out_unlock;
  933. /* Check to see if the layout for the given range already exists */
  934. lseg = pnfs_find_lseg(lo, &arg);
  935. if (lseg)
  936. goto out_unlock;
  937. if (pnfs_layoutgets_blocked(lo, NULL, 0))
  938. goto out_unlock;
  939. atomic_inc(&lo->plh_outstanding);
  940. get_layout_hdr(lo);
  941. if (list_empty(&lo->plh_segs))
  942. first = true;
  943. spin_unlock(&ino->i_lock);
  944. if (first) {
  945. /* The lo must be on the clp list if there is any
  946. * chance of a CB_LAYOUTRECALL(FILE) coming in.
  947. */
  948. spin_lock(&clp->cl_lock);
  949. BUG_ON(!list_empty(&lo->plh_layouts));
  950. list_add_tail(&lo->plh_layouts, &server->layouts);
  951. spin_unlock(&clp->cl_lock);
  952. }
  953. pg_offset = arg.offset & ~PAGE_CACHE_MASK;
  954. if (pg_offset) {
  955. arg.offset -= pg_offset;
  956. arg.length += pg_offset;
  957. }
  958. if (arg.length != NFS4_MAX_UINT64)
  959. arg.length = PAGE_CACHE_ALIGN(arg.length);
  960. lseg = send_layoutget(lo, ctx, &arg, gfp_flags);
  961. if (!lseg && first) {
  962. spin_lock(&clp->cl_lock);
  963. list_del_init(&lo->plh_layouts);
  964. spin_unlock(&clp->cl_lock);
  965. }
  966. atomic_dec(&lo->plh_outstanding);
  967. put_layout_hdr(lo);
  968. out:
  969. dprintk("%s end, state 0x%lx lseg %p\n", __func__,
  970. nfsi->layout ? nfsi->layout->plh_flags : -1, lseg);
  971. return lseg;
  972. out_unlock:
  973. spin_unlock(&ino->i_lock);
  974. goto out;
  975. }
  976. EXPORT_SYMBOL_GPL(pnfs_update_layout);
  977. int
  978. pnfs_layout_process(struct nfs4_layoutget *lgp)
  979. {
  980. struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout;
  981. struct nfs4_layoutget_res *res = &lgp->res;
  982. struct pnfs_layout_segment *lseg;
  983. struct inode *ino = lo->plh_inode;
  984. int status = 0;
  985. /* Inject layout blob into I/O device driver */
  986. lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res, lgp->gfp_flags);
  987. if (!lseg || IS_ERR(lseg)) {
  988. if (!lseg)
  989. status = -ENOMEM;
  990. else
  991. status = PTR_ERR(lseg);
  992. dprintk("%s: Could not allocate layout: error %d\n",
  993. __func__, status);
  994. goto out;
  995. }
  996. spin_lock(&ino->i_lock);
  997. if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
  998. dprintk("%s forget reply due to recall\n", __func__);
  999. goto out_forget_reply;
  1000. }
  1001. if (pnfs_layoutgets_blocked(lo, &res->stateid, 1)) {
  1002. dprintk("%s forget reply due to state\n", __func__);
  1003. goto out_forget_reply;
  1004. }
  1005. init_lseg(lo, lseg);
  1006. lseg->pls_range = res->range;
  1007. *lgp->lsegpp = get_lseg(lseg);
  1008. pnfs_insert_layout(lo, lseg);
  1009. if (res->return_on_close) {
  1010. set_bit(NFS_LSEG_ROC, &lseg->pls_flags);
  1011. set_bit(NFS_LAYOUT_ROC, &lo->plh_flags);
  1012. }
  1013. /* Done processing layoutget. Set the layout stateid */
  1014. pnfs_set_layout_stateid(lo, &res->stateid, false);
  1015. spin_unlock(&ino->i_lock);
  1016. out:
  1017. return status;
  1018. out_forget_reply:
  1019. spin_unlock(&ino->i_lock);
  1020. lseg->pls_layout = lo;
  1021. NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
  1022. goto out;
  1023. }
  1024. void
  1025. pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
  1026. {
  1027. BUG_ON(pgio->pg_lseg != NULL);
  1028. if (req->wb_offset != req->wb_pgbase) {
  1029. nfs_pageio_reset_read_mds(pgio);
  1030. return;
  1031. }
  1032. pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
  1033. req->wb_context,
  1034. req_offset(req),
  1035. req->wb_bytes,
  1036. IOMODE_READ,
  1037. GFP_KERNEL);
  1038. /* If no lseg, fall back to read through mds */
  1039. if (pgio->pg_lseg == NULL)
  1040. nfs_pageio_reset_read_mds(pgio);
  1041. }
  1042. EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_read);
  1043. void
  1044. pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
  1045. {
  1046. BUG_ON(pgio->pg_lseg != NULL);
  1047. if (req->wb_offset != req->wb_pgbase) {
  1048. nfs_pageio_reset_write_mds(pgio);
  1049. return;
  1050. }
  1051. pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
  1052. req->wb_context,
  1053. req_offset(req),
  1054. req->wb_bytes,
  1055. IOMODE_RW,
  1056. GFP_NOFS);
  1057. /* If no lseg, fall back to write through mds */
  1058. if (pgio->pg_lseg == NULL)
  1059. nfs_pageio_reset_write_mds(pgio);
  1060. }
  1061. EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write);
  1062. bool
  1063. pnfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, struct inode *inode,
  1064. const struct nfs_pgio_completion_ops *compl_ops)
  1065. {
  1066. struct nfs_server *server = NFS_SERVER(inode);
  1067. struct pnfs_layoutdriver_type *ld = server->pnfs_curr_ld;
  1068. if (ld == NULL)
  1069. return false;
  1070. nfs_pageio_init(pgio, inode, ld->pg_read_ops, compl_ops,
  1071. server->rsize, 0);
  1072. return true;
  1073. }
  1074. bool
  1075. pnfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, struct inode *inode,
  1076. int ioflags,
  1077. const struct nfs_pgio_completion_ops *compl_ops)
  1078. {
  1079. struct nfs_server *server = NFS_SERVER(inode);
  1080. struct pnfs_layoutdriver_type *ld = server->pnfs_curr_ld;
  1081. if (ld == NULL)
  1082. return false;
  1083. nfs_pageio_init(pgio, inode, ld->pg_write_ops, compl_ops,
  1084. server->wsize, ioflags);
  1085. return true;
  1086. }
  1087. bool
  1088. pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
  1089. struct nfs_page *req)
  1090. {
  1091. if (pgio->pg_lseg == NULL)
  1092. return nfs_generic_pg_test(pgio, prev, req);
  1093. /*
  1094. * Test if a nfs_page is fully contained in the pnfs_layout_range.
  1095. * Note that this test makes several assumptions:
  1096. * - that the previous nfs_page in the struct nfs_pageio_descriptor
  1097. * is known to lie within the range.
  1098. * - that the nfs_page being tested is known to be contiguous with the
  1099. * previous nfs_page.
  1100. * - Layout ranges are page aligned, so we only have to test the
  1101. * start offset of the request.
  1102. *
  1103. * Please also note that 'end_offset' is actually the offset of the
  1104. * first byte that lies outside the pnfs_layout_range. FIXME?
  1105. *
  1106. */
  1107. return req_offset(req) < end_offset(pgio->pg_lseg->pls_range.offset,
  1108. pgio->pg_lseg->pls_range.length);
  1109. }
  1110. EXPORT_SYMBOL_GPL(pnfs_generic_pg_test);
  1111. int pnfs_write_done_resend_to_mds(struct inode *inode,
  1112. struct list_head *head,
  1113. const struct nfs_pgio_completion_ops *compl_ops)
  1114. {
  1115. struct nfs_pageio_descriptor pgio;
  1116. LIST_HEAD(failed);
  1117. /* Resend all requests through the MDS */
  1118. nfs_pageio_init_write_mds(&pgio, inode, FLUSH_STABLE, compl_ops);
  1119. while (!list_empty(head)) {
  1120. struct nfs_page *req = nfs_list_entry(head->next);
  1121. nfs_list_remove_request(req);
  1122. if (!nfs_pageio_add_request(&pgio, req))
  1123. nfs_list_add_request(req, &failed);
  1124. }
  1125. nfs_pageio_complete(&pgio);
  1126. if (!list_empty(&failed)) {
  1127. /* For some reason our attempt to resend pages. Mark the
  1128. * overall send request as having failed, and let
  1129. * nfs_writeback_release_full deal with the error.
  1130. */
  1131. list_move(&failed, head);
  1132. return -EIO;
  1133. }
  1134. return 0;
  1135. }
  1136. EXPORT_SYMBOL_GPL(pnfs_write_done_resend_to_mds);
  1137. static void pnfs_ld_handle_write_error(struct nfs_write_data *data)
  1138. {
  1139. struct nfs_pgio_header *hdr = data->header;
  1140. dprintk("pnfs write error = %d\n", hdr->pnfs_error);
  1141. if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags &
  1142. PNFS_LAYOUTRET_ON_ERROR) {
  1143. clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags);
  1144. pnfs_return_layout(hdr->inode);
  1145. }
  1146. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags))
  1147. data->task.tk_status = pnfs_write_done_resend_to_mds(hdr->inode,
  1148. &hdr->pages,
  1149. hdr->completion_ops);
  1150. }
  1151. /*
  1152. * Called by non rpc-based layout drivers
  1153. */
  1154. void pnfs_ld_write_done(struct nfs_write_data *data)
  1155. {
  1156. struct nfs_pgio_header *hdr = data->header;
  1157. if (!hdr->pnfs_error) {
  1158. pnfs_set_layoutcommit(data);
  1159. hdr->mds_ops->rpc_call_done(&data->task, data);
  1160. } else
  1161. pnfs_ld_handle_write_error(data);
  1162. hdr->mds_ops->rpc_release(data);
  1163. }
  1164. EXPORT_SYMBOL_GPL(pnfs_ld_write_done);
  1165. static void
  1166. pnfs_write_through_mds(struct nfs_pageio_descriptor *desc,
  1167. struct nfs_write_data *data)
  1168. {
  1169. struct nfs_pgio_header *hdr = data->header;
  1170. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
  1171. list_splice_tail_init(&hdr->pages, &desc->pg_list);
  1172. nfs_pageio_reset_write_mds(desc);
  1173. desc->pg_recoalesce = 1;
  1174. }
  1175. nfs_writedata_release(data);
  1176. }
  1177. static enum pnfs_try_status
  1178. pnfs_try_to_write_data(struct nfs_write_data *wdata,
  1179. const struct rpc_call_ops *call_ops,
  1180. struct pnfs_layout_segment *lseg,
  1181. int how)
  1182. {
  1183. struct nfs_pgio_header *hdr = wdata->header;
  1184. struct inode *inode = hdr->inode;
  1185. enum pnfs_try_status trypnfs;
  1186. struct nfs_server *nfss = NFS_SERVER(inode);
  1187. hdr->mds_ops = call_ops;
  1188. dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__,
  1189. inode->i_ino, wdata->args.count, wdata->args.offset, how);
  1190. trypnfs = nfss->pnfs_curr_ld->write_pagelist(wdata, how);
  1191. if (trypnfs != PNFS_NOT_ATTEMPTED)
  1192. nfs_inc_stats(inode, NFSIOS_PNFS_WRITE);
  1193. dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
  1194. return trypnfs;
  1195. }
  1196. static void
  1197. pnfs_do_multiple_writes(struct nfs_pageio_descriptor *desc, struct list_head *head, int how)
  1198. {
  1199. struct nfs_write_data *data;
  1200. const struct rpc_call_ops *call_ops = desc->pg_rpc_callops;
  1201. struct pnfs_layout_segment *lseg = desc->pg_lseg;
  1202. desc->pg_lseg = NULL;
  1203. while (!list_empty(head)) {
  1204. enum pnfs_try_status trypnfs;
  1205. data = list_first_entry(head, struct nfs_write_data, list);
  1206. list_del_init(&data->list);
  1207. trypnfs = pnfs_try_to_write_data(data, call_ops, lseg, how);
  1208. if (trypnfs == PNFS_NOT_ATTEMPTED)
  1209. pnfs_write_through_mds(desc, data);
  1210. }
  1211. put_lseg(lseg);
  1212. }
  1213. static void pnfs_writehdr_free(struct nfs_pgio_header *hdr)
  1214. {
  1215. put_lseg(hdr->lseg);
  1216. nfs_writehdr_free(hdr);
  1217. }
  1218. int
  1219. pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc)
  1220. {
  1221. struct nfs_write_header *whdr;
  1222. struct nfs_pgio_header *hdr;
  1223. int ret;
  1224. whdr = nfs_writehdr_alloc();
  1225. if (!whdr) {
  1226. desc->pg_completion_ops->error_cleanup(&desc->pg_list);
  1227. put_lseg(desc->pg_lseg);
  1228. desc->pg_lseg = NULL;
  1229. return -ENOMEM;
  1230. }
  1231. hdr = &whdr->header;
  1232. nfs_pgheader_init(desc, hdr, pnfs_writehdr_free);
  1233. hdr->lseg = get_lseg(desc->pg_lseg);
  1234. atomic_inc(&hdr->refcnt);
  1235. ret = nfs_generic_flush(desc, hdr);
  1236. if (ret != 0) {
  1237. put_lseg(desc->pg_lseg);
  1238. desc->pg_lseg = NULL;
  1239. } else
  1240. pnfs_do_multiple_writes(desc, &hdr->rpc_list, desc->pg_ioflags);
  1241. if (atomic_dec_and_test(&hdr->refcnt))
  1242. hdr->completion_ops->completion(hdr);
  1243. return ret;
  1244. }
  1245. EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages);
  1246. int pnfs_read_done_resend_to_mds(struct inode *inode,
  1247. struct list_head *head,
  1248. const struct nfs_pgio_completion_ops *compl_ops)
  1249. {
  1250. struct nfs_pageio_descriptor pgio;
  1251. LIST_HEAD(failed);
  1252. /* Resend all requests through the MDS */
  1253. nfs_pageio_init_read_mds(&pgio, inode, compl_ops);
  1254. while (!list_empty(head)) {
  1255. struct nfs_page *req = nfs_list_entry(head->next);
  1256. nfs_list_remove_request(req);
  1257. if (!nfs_pageio_add_request(&pgio, req))
  1258. nfs_list_add_request(req, &failed);
  1259. }
  1260. nfs_pageio_complete(&pgio);
  1261. if (!list_empty(&failed)) {
  1262. list_move(&failed, head);
  1263. return -EIO;
  1264. }
  1265. return 0;
  1266. }
  1267. EXPORT_SYMBOL_GPL(pnfs_read_done_resend_to_mds);
  1268. static void pnfs_ld_handle_read_error(struct nfs_read_data *data)
  1269. {
  1270. struct nfs_pgio_header *hdr = data->header;
  1271. dprintk("pnfs read error = %d\n", hdr->pnfs_error);
  1272. if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags &
  1273. PNFS_LAYOUTRET_ON_ERROR) {
  1274. clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags);
  1275. pnfs_return_layout(hdr->inode);
  1276. }
  1277. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags))
  1278. data->task.tk_status = pnfs_read_done_resend_to_mds(hdr->inode,
  1279. &hdr->pages,
  1280. hdr->completion_ops);
  1281. }
  1282. /*
  1283. * Called by non rpc-based layout drivers
  1284. */
  1285. void pnfs_ld_read_done(struct nfs_read_data *data)
  1286. {
  1287. struct nfs_pgio_header *hdr = data->header;
  1288. if (likely(!hdr->pnfs_error)) {
  1289. __nfs4_read_done_cb(data);
  1290. hdr->mds_ops->rpc_call_done(&data->task, data);
  1291. } else
  1292. pnfs_ld_handle_read_error(data);
  1293. hdr->mds_ops->rpc_release(data);
  1294. }
  1295. EXPORT_SYMBOL_GPL(pnfs_ld_read_done);
  1296. static void
  1297. pnfs_read_through_mds(struct nfs_pageio_descriptor *desc,
  1298. struct nfs_read_data *data)
  1299. {
  1300. struct nfs_pgio_header *hdr = data->header;
  1301. if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
  1302. list_splice_tail_init(&hdr->pages, &desc->pg_list);
  1303. nfs_pageio_reset_read_mds(desc);
  1304. desc->pg_recoalesce = 1;
  1305. }
  1306. nfs_readdata_release(data);
  1307. }
  1308. /*
  1309. * Call the appropriate parallel I/O subsystem read function.
  1310. */
  1311. static enum pnfs_try_status
  1312. pnfs_try_to_read_data(struct nfs_read_data *rdata,
  1313. const struct rpc_call_ops *call_ops,
  1314. struct pnfs_layout_segment *lseg)
  1315. {
  1316. struct nfs_pgio_header *hdr = rdata->header;
  1317. struct inode *inode = hdr->inode;
  1318. struct nfs_server *nfss = NFS_SERVER(inode);
  1319. enum pnfs_try_status trypnfs;
  1320. hdr->mds_ops = call_ops;
  1321. dprintk("%s: Reading ino:%lu %u@%llu\n",
  1322. __func__, inode->i_ino, rdata->args.count, rdata->args.offset);
  1323. trypnfs = nfss->pnfs_curr_ld->read_pagelist(rdata);
  1324. if (trypnfs != PNFS_NOT_ATTEMPTED)
  1325. nfs_inc_stats(inode, NFSIOS_PNFS_READ);
  1326. dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
  1327. return trypnfs;
  1328. }
  1329. static void
  1330. pnfs_do_multiple_reads(struct nfs_pageio_descriptor *desc, struct list_head *head)
  1331. {
  1332. struct nfs_read_data *data;
  1333. const struct rpc_call_ops *call_ops = desc->pg_rpc_callops;
  1334. struct pnfs_layout_segment *lseg = desc->pg_lseg;
  1335. desc->pg_lseg = NULL;
  1336. while (!list_empty(head)) {
  1337. enum pnfs_try_status trypnfs;
  1338. data = list_first_entry(head, struct nfs_read_data, list);
  1339. list_del_init(&data->list);
  1340. trypnfs = pnfs_try_to_read_data(data, call_ops, lseg);
  1341. if (trypnfs == PNFS_NOT_ATTEMPTED)
  1342. pnfs_read_through_mds(desc, data);
  1343. }
  1344. put_lseg(lseg);
  1345. }
  1346. static void pnfs_readhdr_free(struct nfs_pgio_header *hdr)
  1347. {
  1348. put_lseg(hdr->lseg);
  1349. nfs_readhdr_free(hdr);
  1350. }
  1351. int
  1352. pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc)
  1353. {
  1354. struct nfs_read_header *rhdr;
  1355. struct nfs_pgio_header *hdr;
  1356. int ret;
  1357. rhdr = nfs_readhdr_alloc();
  1358. if (!rhdr) {
  1359. desc->pg_completion_ops->error_cleanup(&desc->pg_list);
  1360. ret = -ENOMEM;
  1361. put_lseg(desc->pg_lseg);
  1362. desc->pg_lseg = NULL;
  1363. return ret;
  1364. }
  1365. hdr = &rhdr->header;
  1366. nfs_pgheader_init(desc, hdr, pnfs_readhdr_free);
  1367. hdr->lseg = get_lseg(desc->pg_lseg);
  1368. atomic_inc(&hdr->refcnt);
  1369. ret = nfs_generic_pagein(desc, hdr);
  1370. if (ret != 0) {
  1371. put_lseg(desc->pg_lseg);
  1372. desc->pg_lseg = NULL;
  1373. } else
  1374. pnfs_do_multiple_reads(desc, &hdr->rpc_list);
  1375. if (atomic_dec_and_test(&hdr->refcnt))
  1376. hdr->completion_ops->completion(hdr);
  1377. return ret;
  1378. }
  1379. EXPORT_SYMBOL_GPL(pnfs_generic_pg_readpages);
  1380. /*
  1381. * There can be multiple RW segments.
  1382. */
  1383. static void pnfs_list_write_lseg(struct inode *inode, struct list_head *listp)
  1384. {
  1385. struct pnfs_layout_segment *lseg;
  1386. list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) {
  1387. if (lseg->pls_range.iomode == IOMODE_RW &&
  1388. test_bit(NFS_LSEG_LAYOUTCOMMIT, &lseg->pls_flags))
  1389. list_add(&lseg->pls_lc_list, listp);
  1390. }
  1391. }
  1392. void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg)
  1393. {
  1394. if (lseg->pls_range.iomode == IOMODE_RW) {
  1395. dprintk("%s Setting layout IOMODE_RW fail bit\n", __func__);
  1396. set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
  1397. } else {
  1398. dprintk("%s Setting layout IOMODE_READ fail bit\n", __func__);
  1399. set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
  1400. }
  1401. }
  1402. EXPORT_SYMBOL_GPL(pnfs_set_lo_fail);
  1403. void
  1404. pnfs_set_layoutcommit(struct nfs_write_data *wdata)
  1405. {
  1406. struct nfs_pgio_header *hdr = wdata->header;
  1407. struct inode *inode = hdr->inode;
  1408. struct nfs_inode *nfsi = NFS_I(inode);
  1409. loff_t end_pos = wdata->mds_offset + wdata->res.count;
  1410. bool mark_as_dirty = false;
  1411. spin_lock(&inode->i_lock);
  1412. if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
  1413. mark_as_dirty = true;
  1414. dprintk("%s: Set layoutcommit for inode %lu ",
  1415. __func__, inode->i_ino);
  1416. }
  1417. if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &hdr->lseg->pls_flags)) {
  1418. /* references matched in nfs4_layoutcommit_release */
  1419. get_lseg(hdr->lseg);
  1420. }
  1421. if (end_pos > nfsi->layout->plh_lwb)
  1422. nfsi->layout->plh_lwb = end_pos;
  1423. spin_unlock(&inode->i_lock);
  1424. dprintk("%s: lseg %p end_pos %llu\n",
  1425. __func__, hdr->lseg, nfsi->layout->plh_lwb);
  1426. /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
  1427. * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
  1428. if (mark_as_dirty)
  1429. mark_inode_dirty_sync(inode);
  1430. }
  1431. EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
  1432. void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data)
  1433. {
  1434. struct nfs_server *nfss = NFS_SERVER(data->args.inode);
  1435. if (nfss->pnfs_curr_ld->cleanup_layoutcommit)
  1436. nfss->pnfs_curr_ld->cleanup_layoutcommit(data);
  1437. }
  1438. /*
  1439. * For the LAYOUT4_NFSV4_1_FILES layout type, NFS_DATA_SYNC WRITEs and
  1440. * NFS_UNSTABLE WRITEs with a COMMIT to data servers must store enough
  1441. * data to disk to allow the server to recover the data if it crashes.
  1442. * LAYOUTCOMMIT is only needed when the NFL4_UFLG_COMMIT_THRU_MDS flag
  1443. * is off, and a COMMIT is sent to a data server, or
  1444. * if WRITEs to a data server return NFS_DATA_SYNC.
  1445. */
  1446. int
  1447. pnfs_layoutcommit_inode(struct inode *inode, bool sync)
  1448. {
  1449. struct nfs4_layoutcommit_data *data;
  1450. struct nfs_inode *nfsi = NFS_I(inode);
  1451. loff_t end_pos;
  1452. int status = 0;
  1453. dprintk("--> %s inode %lu\n", __func__, inode->i_ino);
  1454. if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
  1455. return 0;
  1456. /* Note kzalloc ensures data->res.seq_res.sr_slot == NULL */
  1457. data = kzalloc(sizeof(*data), GFP_NOFS);
  1458. if (!data) {
  1459. status = -ENOMEM;
  1460. goto out;
  1461. }
  1462. if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
  1463. goto out_free;
  1464. if (test_and_set_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags)) {
  1465. if (!sync) {
  1466. status = -EAGAIN;
  1467. goto out_free;
  1468. }
  1469. status = wait_on_bit_lock(&nfsi->flags, NFS_INO_LAYOUTCOMMITTING,
  1470. nfs_wait_bit_killable, TASK_KILLABLE);
  1471. if (status)
  1472. goto out_free;
  1473. }
  1474. INIT_LIST_HEAD(&data->lseg_list);
  1475. spin_lock(&inode->i_lock);
  1476. if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
  1477. clear_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags);
  1478. spin_unlock(&inode->i_lock);
  1479. wake_up_bit(&nfsi->flags, NFS_INO_LAYOUTCOMMITTING);
  1480. goto out_free;
  1481. }
  1482. pnfs_list_write_lseg(inode, &data->lseg_list);
  1483. end_pos = nfsi->layout->plh_lwb;
  1484. nfsi->layout->plh_lwb = 0;
  1485. nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
  1486. spin_unlock(&inode->i_lock);
  1487. data->args.inode = inode;
  1488. data->cred = get_rpccred(nfsi->layout->plh_lc_cred);
  1489. nfs_fattr_init(&data->fattr);
  1490. data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask;
  1491. data->res.fattr = &data->fattr;
  1492. data->args.lastbytewritten = end_pos - 1;
  1493. data->res.server = NFS_SERVER(inode);
  1494. status = nfs4_proc_layoutcommit(data, sync);
  1495. out:
  1496. if (status)
  1497. mark_inode_dirty_sync(inode);
  1498. dprintk("<-- %s status %d\n", __func__, status);
  1499. return status;
  1500. out_free:
  1501. kfree(data);
  1502. goto out;
  1503. }
  1504. struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
  1505. {
  1506. struct nfs4_threshold *thp;
  1507. thp = kzalloc(sizeof(*thp), GFP_NOFS);
  1508. if (!thp) {
  1509. dprintk("%s mdsthreshold allocation failed\n", __func__);
  1510. return NULL;
  1511. }
  1512. return thp;
  1513. }