pnfs.c 45 KB

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