inode.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216
  1. /*
  2. * linux/fs/nfs/inode.c
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * nfs inode and superblock handling functions
  7. *
  8. * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
  9. * experimental NFS changes. Modularisation taken straight from SYS5 fs.
  10. *
  11. * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
  12. * J.S.Peatfield@damtp.cam.ac.uk
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/sched/signal.h>
  18. #include <linux/time.h>
  19. #include <linux/kernel.h>
  20. #include <linux/mm.h>
  21. #include <linux/string.h>
  22. #include <linux/stat.h>
  23. #include <linux/errno.h>
  24. #include <linux/unistd.h>
  25. #include <linux/sunrpc/clnt.h>
  26. #include <linux/sunrpc/stats.h>
  27. #include <linux/sunrpc/metrics.h>
  28. #include <linux/nfs_fs.h>
  29. #include <linux/nfs_mount.h>
  30. #include <linux/nfs4_mount.h>
  31. #include <linux/lockd/bind.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/mount.h>
  34. #include <linux/vfs.h>
  35. #include <linux/inet.h>
  36. #include <linux/nfs_xdr.h>
  37. #include <linux/slab.h>
  38. #include <linux/compat.h>
  39. #include <linux/freezer.h>
  40. #include <linux/uaccess.h>
  41. #include <linux/iversion.h>
  42. #include "nfs4_fs.h"
  43. #include "callback.h"
  44. #include "delegation.h"
  45. #include "iostat.h"
  46. #include "internal.h"
  47. #include "fscache.h"
  48. #include "pnfs.h"
  49. #include "nfs.h"
  50. #include "netns.h"
  51. #include "nfstrace.h"
  52. #define NFSDBG_FACILITY NFSDBG_VFS
  53. #define NFS_64_BIT_INODE_NUMBERS_ENABLED 1
  54. /* Default is to see 64-bit inode numbers */
  55. static bool enable_ino64 = NFS_64_BIT_INODE_NUMBERS_ENABLED;
  56. static void nfs_invalidate_inode(struct inode *);
  57. static int nfs_update_inode(struct inode *, struct nfs_fattr *);
  58. static struct kmem_cache * nfs_inode_cachep;
  59. static inline unsigned long
  60. nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
  61. {
  62. return nfs_fileid_to_ino_t(fattr->fileid);
  63. }
  64. static int nfs_wait_killable(int mode)
  65. {
  66. freezable_schedule_unsafe();
  67. if (signal_pending_state(mode, current))
  68. return -ERESTARTSYS;
  69. return 0;
  70. }
  71. int nfs_wait_bit_killable(struct wait_bit_key *key, int mode)
  72. {
  73. return nfs_wait_killable(mode);
  74. }
  75. EXPORT_SYMBOL_GPL(nfs_wait_bit_killable);
  76. /**
  77. * nfs_compat_user_ino64 - returns the user-visible inode number
  78. * @fileid: 64-bit fileid
  79. *
  80. * This function returns a 32-bit inode number if the boot parameter
  81. * nfs.enable_ino64 is zero.
  82. */
  83. u64 nfs_compat_user_ino64(u64 fileid)
  84. {
  85. #ifdef CONFIG_COMPAT
  86. compat_ulong_t ino;
  87. #else
  88. unsigned long ino;
  89. #endif
  90. if (enable_ino64)
  91. return fileid;
  92. ino = fileid;
  93. if (sizeof(ino) < sizeof(fileid))
  94. ino ^= fileid >> (sizeof(fileid)-sizeof(ino)) * 8;
  95. return ino;
  96. }
  97. int nfs_drop_inode(struct inode *inode)
  98. {
  99. return NFS_STALE(inode) || generic_drop_inode(inode);
  100. }
  101. EXPORT_SYMBOL_GPL(nfs_drop_inode);
  102. void nfs_clear_inode(struct inode *inode)
  103. {
  104. /*
  105. * The following should never happen...
  106. */
  107. WARN_ON_ONCE(nfs_have_writebacks(inode));
  108. WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files));
  109. nfs_zap_acl_cache(inode);
  110. nfs_access_zap_cache(inode);
  111. nfs_fscache_clear_inode(inode);
  112. }
  113. EXPORT_SYMBOL_GPL(nfs_clear_inode);
  114. void nfs_evict_inode(struct inode *inode)
  115. {
  116. truncate_inode_pages_final(&inode->i_data);
  117. clear_inode(inode);
  118. nfs_clear_inode(inode);
  119. }
  120. int nfs_sync_inode(struct inode *inode)
  121. {
  122. inode_dio_wait(inode);
  123. return nfs_wb_all(inode);
  124. }
  125. EXPORT_SYMBOL_GPL(nfs_sync_inode);
  126. /**
  127. * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
  128. */
  129. int nfs_sync_mapping(struct address_space *mapping)
  130. {
  131. int ret = 0;
  132. if (mapping->nrpages != 0) {
  133. unmap_mapping_range(mapping, 0, 0, 0);
  134. ret = nfs_wb_all(mapping->host);
  135. }
  136. return ret;
  137. }
  138. static int nfs_attribute_timeout(struct inode *inode)
  139. {
  140. struct nfs_inode *nfsi = NFS_I(inode);
  141. return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
  142. }
  143. static bool nfs_check_cache_invalid_delegated(struct inode *inode, unsigned long flags)
  144. {
  145. unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
  146. /* Special case for the pagecache or access cache */
  147. if (flags == NFS_INO_REVAL_PAGECACHE &&
  148. !(cache_validity & NFS_INO_REVAL_FORCED))
  149. return false;
  150. return (cache_validity & flags) != 0;
  151. }
  152. static bool nfs_check_cache_invalid_not_delegated(struct inode *inode, unsigned long flags)
  153. {
  154. unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
  155. if ((cache_validity & flags) != 0)
  156. return true;
  157. if (nfs_attribute_timeout(inode))
  158. return true;
  159. return false;
  160. }
  161. bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags)
  162. {
  163. if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
  164. return nfs_check_cache_invalid_delegated(inode, flags);
  165. return nfs_check_cache_invalid_not_delegated(inode, flags);
  166. }
  167. static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
  168. {
  169. struct nfs_inode *nfsi = NFS_I(inode);
  170. if (inode->i_mapping->nrpages == 0)
  171. flags &= ~NFS_INO_INVALID_DATA;
  172. nfsi->cache_validity |= flags;
  173. if (flags & NFS_INO_INVALID_DATA)
  174. nfs_fscache_invalidate(inode);
  175. }
  176. /*
  177. * Invalidate the local caches
  178. */
  179. static void nfs_zap_caches_locked(struct inode *inode)
  180. {
  181. struct nfs_inode *nfsi = NFS_I(inode);
  182. int mode = inode->i_mode;
  183. nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
  184. nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
  185. nfsi->attrtimeo_timestamp = jiffies;
  186. memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf));
  187. if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
  188. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
  189. | NFS_INO_INVALID_DATA
  190. | NFS_INO_INVALID_ACCESS
  191. | NFS_INO_INVALID_ACL
  192. | NFS_INO_REVAL_PAGECACHE);
  193. } else
  194. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
  195. | NFS_INO_INVALID_ACCESS
  196. | NFS_INO_INVALID_ACL
  197. | NFS_INO_REVAL_PAGECACHE);
  198. nfs_zap_label_cache_locked(nfsi);
  199. }
  200. void nfs_zap_caches(struct inode *inode)
  201. {
  202. spin_lock(&inode->i_lock);
  203. nfs_zap_caches_locked(inode);
  204. spin_unlock(&inode->i_lock);
  205. }
  206. void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
  207. {
  208. if (mapping->nrpages != 0) {
  209. spin_lock(&inode->i_lock);
  210. nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
  211. spin_unlock(&inode->i_lock);
  212. }
  213. }
  214. void nfs_zap_acl_cache(struct inode *inode)
  215. {
  216. void (*clear_acl_cache)(struct inode *);
  217. clear_acl_cache = NFS_PROTO(inode)->clear_acl_cache;
  218. if (clear_acl_cache != NULL)
  219. clear_acl_cache(inode);
  220. spin_lock(&inode->i_lock);
  221. NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_ACL;
  222. spin_unlock(&inode->i_lock);
  223. }
  224. EXPORT_SYMBOL_GPL(nfs_zap_acl_cache);
  225. void nfs_invalidate_atime(struct inode *inode)
  226. {
  227. spin_lock(&inode->i_lock);
  228. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
  229. spin_unlock(&inode->i_lock);
  230. }
  231. EXPORT_SYMBOL_GPL(nfs_invalidate_atime);
  232. /*
  233. * Invalidate, but do not unhash, the inode.
  234. * NB: must be called with inode->i_lock held!
  235. */
  236. static void nfs_invalidate_inode(struct inode *inode)
  237. {
  238. set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
  239. nfs_zap_caches_locked(inode);
  240. }
  241. struct nfs_find_desc {
  242. struct nfs_fh *fh;
  243. struct nfs_fattr *fattr;
  244. };
  245. /*
  246. * In NFSv3 we can have 64bit inode numbers. In order to support
  247. * this, and re-exported directories (also seen in NFSv2)
  248. * we are forced to allow 2 different inodes to have the same
  249. * i_ino.
  250. */
  251. static int
  252. nfs_find_actor(struct inode *inode, void *opaque)
  253. {
  254. struct nfs_find_desc *desc = (struct nfs_find_desc *)opaque;
  255. struct nfs_fh *fh = desc->fh;
  256. struct nfs_fattr *fattr = desc->fattr;
  257. if (NFS_FILEID(inode) != fattr->fileid)
  258. return 0;
  259. if ((S_IFMT & inode->i_mode) != (S_IFMT & fattr->mode))
  260. return 0;
  261. if (nfs_compare_fh(NFS_FH(inode), fh))
  262. return 0;
  263. if (is_bad_inode(inode) || NFS_STALE(inode))
  264. return 0;
  265. return 1;
  266. }
  267. static int
  268. nfs_init_locked(struct inode *inode, void *opaque)
  269. {
  270. struct nfs_find_desc *desc = (struct nfs_find_desc *)opaque;
  271. struct nfs_fattr *fattr = desc->fattr;
  272. set_nfs_fileid(inode, fattr->fileid);
  273. inode->i_mode = fattr->mode;
  274. nfs_copy_fh(NFS_FH(inode), desc->fh);
  275. return 0;
  276. }
  277. #ifdef CONFIG_NFS_V4_SECURITY_LABEL
  278. static void nfs_clear_label_invalid(struct inode *inode)
  279. {
  280. spin_lock(&inode->i_lock);
  281. NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_LABEL;
  282. spin_unlock(&inode->i_lock);
  283. }
  284. void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
  285. struct nfs4_label *label)
  286. {
  287. int error;
  288. if (label == NULL)
  289. return;
  290. if ((fattr->valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL) && inode->i_security) {
  291. error = security_inode_notifysecctx(inode, label->label,
  292. label->len);
  293. if (error)
  294. printk(KERN_ERR "%s() %s %d "
  295. "security_inode_notifysecctx() %d\n",
  296. __func__,
  297. (char *)label->label,
  298. label->len, error);
  299. nfs_clear_label_invalid(inode);
  300. }
  301. }
  302. struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags)
  303. {
  304. struct nfs4_label *label = NULL;
  305. int minor_version = server->nfs_client->cl_minorversion;
  306. if (minor_version < 2)
  307. return label;
  308. if (!(server->caps & NFS_CAP_SECURITY_LABEL))
  309. return label;
  310. label = kzalloc(sizeof(struct nfs4_label), flags);
  311. if (label == NULL)
  312. return ERR_PTR(-ENOMEM);
  313. label->label = kzalloc(NFS4_MAXLABELLEN, flags);
  314. if (label->label == NULL) {
  315. kfree(label);
  316. return ERR_PTR(-ENOMEM);
  317. }
  318. label->len = NFS4_MAXLABELLEN;
  319. return label;
  320. }
  321. EXPORT_SYMBOL_GPL(nfs4_label_alloc);
  322. #else
  323. void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
  324. struct nfs4_label *label)
  325. {
  326. }
  327. #endif
  328. EXPORT_SYMBOL_GPL(nfs_setsecurity);
  329. /* Search for inode identified by fh, fileid and i_mode in inode cache. */
  330. struct inode *
  331. nfs_ilookup(struct super_block *sb, struct nfs_fattr *fattr, struct nfs_fh *fh)
  332. {
  333. struct nfs_find_desc desc = {
  334. .fh = fh,
  335. .fattr = fattr,
  336. };
  337. struct inode *inode;
  338. unsigned long hash;
  339. if (!(fattr->valid & NFS_ATTR_FATTR_FILEID) ||
  340. !(fattr->valid & NFS_ATTR_FATTR_TYPE))
  341. return NULL;
  342. hash = nfs_fattr_to_ino_t(fattr);
  343. inode = ilookup5(sb, hash, nfs_find_actor, &desc);
  344. dprintk("%s: returning %p\n", __func__, inode);
  345. return inode;
  346. }
  347. /*
  348. * This is our front-end to iget that looks up inodes by file handle
  349. * instead of inode number.
  350. */
  351. struct inode *
  352. nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, struct nfs4_label *label)
  353. {
  354. struct nfs_find_desc desc = {
  355. .fh = fh,
  356. .fattr = fattr
  357. };
  358. struct inode *inode = ERR_PTR(-ENOENT);
  359. unsigned long hash;
  360. nfs_attr_check_mountpoint(sb, fattr);
  361. if (nfs_attr_use_mounted_on_fileid(fattr))
  362. fattr->fileid = fattr->mounted_on_fileid;
  363. else if ((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0)
  364. goto out_no_inode;
  365. if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0)
  366. goto out_no_inode;
  367. hash = nfs_fattr_to_ino_t(fattr);
  368. inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc);
  369. if (inode == NULL) {
  370. inode = ERR_PTR(-ENOMEM);
  371. goto out_no_inode;
  372. }
  373. if (inode->i_state & I_NEW) {
  374. struct nfs_inode *nfsi = NFS_I(inode);
  375. unsigned long now = jiffies;
  376. /* We set i_ino for the few things that still rely on it,
  377. * such as stat(2) */
  378. inode->i_ino = hash;
  379. /* We can't support update_atime(), since the server will reset it */
  380. inode->i_flags |= S_NOATIME|S_NOCMTIME;
  381. inode->i_mode = fattr->mode;
  382. if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0
  383. && nfs_server_capable(inode, NFS_CAP_MODE))
  384. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
  385. /* Why so? Because we want revalidate for devices/FIFOs, and
  386. * that's precisely what we have in nfs_file_inode_operations.
  387. */
  388. inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->file_inode_ops;
  389. if (S_ISREG(inode->i_mode)) {
  390. inode->i_fop = NFS_SB(sb)->nfs_client->rpc_ops->file_ops;
  391. inode->i_data.a_ops = &nfs_file_aops;
  392. } else if (S_ISDIR(inode->i_mode)) {
  393. inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
  394. inode->i_fop = &nfs_dir_operations;
  395. inode->i_data.a_ops = &nfs_dir_aops;
  396. /* Deal with crossing mountpoints */
  397. if (fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT ||
  398. fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
  399. if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
  400. inode->i_op = &nfs_referral_inode_operations;
  401. else
  402. inode->i_op = &nfs_mountpoint_inode_operations;
  403. inode->i_fop = NULL;
  404. inode->i_flags |= S_AUTOMOUNT;
  405. }
  406. } else if (S_ISLNK(inode->i_mode)) {
  407. inode->i_op = &nfs_symlink_inode_operations;
  408. inode_nohighmem(inode);
  409. } else
  410. init_special_inode(inode, inode->i_mode, fattr->rdev);
  411. memset(&inode->i_atime, 0, sizeof(inode->i_atime));
  412. memset(&inode->i_mtime, 0, sizeof(inode->i_mtime));
  413. memset(&inode->i_ctime, 0, sizeof(inode->i_ctime));
  414. inode_set_iversion_raw(inode, 0);
  415. inode->i_size = 0;
  416. clear_nlink(inode);
  417. inode->i_uid = make_kuid(&init_user_ns, -2);
  418. inode->i_gid = make_kgid(&init_user_ns, -2);
  419. inode->i_blocks = 0;
  420. memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
  421. nfsi->write_io = 0;
  422. nfsi->read_io = 0;
  423. nfsi->read_cache_jiffies = fattr->time_start;
  424. nfsi->attr_gencount = fattr->gencount;
  425. if (fattr->valid & NFS_ATTR_FATTR_ATIME)
  426. inode->i_atime = fattr->atime;
  427. else if (nfs_server_capable(inode, NFS_CAP_ATIME))
  428. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
  429. if (fattr->valid & NFS_ATTR_FATTR_MTIME)
  430. inode->i_mtime = fattr->mtime;
  431. else if (nfs_server_capable(inode, NFS_CAP_MTIME))
  432. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
  433. if (fattr->valid & NFS_ATTR_FATTR_CTIME)
  434. inode->i_ctime = fattr->ctime;
  435. else if (nfs_server_capable(inode, NFS_CAP_CTIME))
  436. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
  437. if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
  438. inode_set_iversion_raw(inode, fattr->change_attr);
  439. else
  440. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
  441. | NFS_INO_REVAL_PAGECACHE);
  442. if (fattr->valid & NFS_ATTR_FATTR_SIZE)
  443. inode->i_size = nfs_size_to_loff_t(fattr->size);
  444. else
  445. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
  446. | NFS_INO_REVAL_PAGECACHE);
  447. if (fattr->valid & NFS_ATTR_FATTR_NLINK)
  448. set_nlink(inode, fattr->nlink);
  449. else if (nfs_server_capable(inode, NFS_CAP_NLINK))
  450. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
  451. if (fattr->valid & NFS_ATTR_FATTR_OWNER)
  452. inode->i_uid = fattr->uid;
  453. else if (nfs_server_capable(inode, NFS_CAP_OWNER))
  454. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
  455. if (fattr->valid & NFS_ATTR_FATTR_GROUP)
  456. inode->i_gid = fattr->gid;
  457. else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
  458. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
  459. if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
  460. inode->i_blocks = fattr->du.nfs2.blocks;
  461. if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
  462. /*
  463. * report the blocks in 512byte units
  464. */
  465. inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
  466. }
  467. nfs_setsecurity(inode, fattr, label);
  468. nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
  469. nfsi->attrtimeo_timestamp = now;
  470. nfsi->access_cache = RB_ROOT;
  471. nfs_fscache_init_inode(inode);
  472. unlock_new_inode(inode);
  473. } else {
  474. int err = nfs_refresh_inode(inode, fattr);
  475. if (err < 0) {
  476. iput(inode);
  477. inode = ERR_PTR(err);
  478. goto out_no_inode;
  479. }
  480. }
  481. dprintk("NFS: nfs_fhget(%s/%Lu fh_crc=0x%08x ct=%d)\n",
  482. inode->i_sb->s_id,
  483. (unsigned long long)NFS_FILEID(inode),
  484. nfs_display_fhandle_hash(fh),
  485. atomic_read(&inode->i_count));
  486. out:
  487. return inode;
  488. out_no_inode:
  489. dprintk("nfs_fhget: iget failed with error %ld\n", PTR_ERR(inode));
  490. goto out;
  491. }
  492. EXPORT_SYMBOL_GPL(nfs_fhget);
  493. #define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE|ATTR_OPEN)
  494. int
  495. nfs_setattr(struct dentry *dentry, struct iattr *attr)
  496. {
  497. struct inode *inode = d_inode(dentry);
  498. struct nfs_fattr *fattr;
  499. int error = 0;
  500. nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
  501. /* skip mode change if it's just for clearing setuid/setgid */
  502. if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
  503. attr->ia_valid &= ~ATTR_MODE;
  504. if (attr->ia_valid & ATTR_SIZE) {
  505. BUG_ON(!S_ISREG(inode->i_mode));
  506. error = inode_newsize_ok(inode, attr->ia_size);
  507. if (error)
  508. return error;
  509. if (attr->ia_size == i_size_read(inode))
  510. attr->ia_valid &= ~ATTR_SIZE;
  511. }
  512. /* Optimization: if the end result is no change, don't RPC */
  513. attr->ia_valid &= NFS_VALID_ATTRS;
  514. if ((attr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0)
  515. return 0;
  516. trace_nfs_setattr_enter(inode);
  517. /* Write all dirty data */
  518. if (S_ISREG(inode->i_mode))
  519. nfs_sync_inode(inode);
  520. fattr = nfs_alloc_fattr();
  521. if (fattr == NULL) {
  522. error = -ENOMEM;
  523. goto out;
  524. }
  525. /*
  526. * Return any delegations if we're going to change ACLs
  527. */
  528. if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
  529. NFS_PROTO(inode)->return_delegation(inode);
  530. error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
  531. if (error == 0)
  532. error = nfs_refresh_inode(inode, fattr);
  533. nfs_free_fattr(fattr);
  534. out:
  535. trace_nfs_setattr_exit(inode, error);
  536. return error;
  537. }
  538. EXPORT_SYMBOL_GPL(nfs_setattr);
  539. /**
  540. * nfs_vmtruncate - unmap mappings "freed" by truncate() syscall
  541. * @inode: inode of the file used
  542. * @offset: file offset to start truncating
  543. *
  544. * This is a copy of the common vmtruncate, but with the locking
  545. * corrected to take into account the fact that NFS requires
  546. * inode->i_size to be updated under the inode->i_lock.
  547. * Note: must be called with inode->i_lock held!
  548. */
  549. static int nfs_vmtruncate(struct inode * inode, loff_t offset)
  550. {
  551. int err;
  552. err = inode_newsize_ok(inode, offset);
  553. if (err)
  554. goto out;
  555. i_size_write(inode, offset);
  556. /* Optimisation */
  557. if (offset == 0)
  558. NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_DATA;
  559. spin_unlock(&inode->i_lock);
  560. truncate_pagecache(inode, offset);
  561. spin_lock(&inode->i_lock);
  562. out:
  563. return err;
  564. }
  565. /**
  566. * nfs_setattr_update_inode - Update inode metadata after a setattr call.
  567. * @inode: pointer to struct inode
  568. * @attr: pointer to struct iattr
  569. *
  570. * Note: we do this in the *proc.c in order to ensure that
  571. * it works for things like exclusive creates too.
  572. */
  573. void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
  574. struct nfs_fattr *fattr)
  575. {
  576. /* Barrier: bump the attribute generation count. */
  577. nfs_fattr_set_barrier(fattr);
  578. spin_lock(&inode->i_lock);
  579. NFS_I(inode)->attr_gencount = fattr->gencount;
  580. if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) {
  581. if ((attr->ia_valid & ATTR_MODE) != 0) {
  582. int mode = attr->ia_mode & S_IALLUGO;
  583. mode |= inode->i_mode & ~S_IALLUGO;
  584. inode->i_mode = mode;
  585. }
  586. if ((attr->ia_valid & ATTR_UID) != 0)
  587. inode->i_uid = attr->ia_uid;
  588. if ((attr->ia_valid & ATTR_GID) != 0)
  589. inode->i_gid = attr->ia_gid;
  590. nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
  591. | NFS_INO_INVALID_ACL);
  592. }
  593. if ((attr->ia_valid & ATTR_SIZE) != 0) {
  594. nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
  595. nfs_vmtruncate(inode, attr->ia_size);
  596. }
  597. if (fattr->valid)
  598. nfs_update_inode(inode, fattr);
  599. else
  600. NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
  601. spin_unlock(&inode->i_lock);
  602. }
  603. EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
  604. static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry)
  605. {
  606. struct dentry *parent;
  607. if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
  608. return;
  609. parent = dget_parent(dentry);
  610. nfs_force_use_readdirplus(d_inode(parent));
  611. dput(parent);
  612. }
  613. static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)
  614. {
  615. struct dentry *parent;
  616. if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
  617. return;
  618. parent = dget_parent(dentry);
  619. nfs_advise_use_readdirplus(d_inode(parent));
  620. dput(parent);
  621. }
  622. static bool nfs_need_revalidate_inode(struct inode *inode)
  623. {
  624. if (NFS_I(inode)->cache_validity &
  625. (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_LABEL))
  626. return true;
  627. if (nfs_attribute_cache_expired(inode))
  628. return true;
  629. return false;
  630. }
  631. int nfs_getattr(const struct path *path, struct kstat *stat,
  632. u32 request_mask, unsigned int query_flags)
  633. {
  634. struct inode *inode = d_inode(path->dentry);
  635. struct nfs_server *server = NFS_SERVER(inode);
  636. unsigned long cache_validity;
  637. int err = 0;
  638. bool force_sync = query_flags & AT_STATX_FORCE_SYNC;
  639. bool do_update = false;
  640. trace_nfs_getattr_enter(inode);
  641. if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync)
  642. goto out_no_update;
  643. /* Flush out writes to the server in order to update c/mtime. */
  644. if ((request_mask & (STATX_CTIME|STATX_MTIME)) &&
  645. S_ISREG(inode->i_mode)) {
  646. err = filemap_write_and_wait(inode->i_mapping);
  647. if (err)
  648. goto out;
  649. }
  650. /*
  651. * We may force a getattr if the user cares about atime.
  652. *
  653. * Note that we only have to check the vfsmount flags here:
  654. * - NFS always sets S_NOATIME by so checking it would give a
  655. * bogus result
  656. * - NFS never sets SB_NOATIME or SB_NODIRATIME so there is
  657. * no point in checking those.
  658. */
  659. if ((path->mnt->mnt_flags & MNT_NOATIME) ||
  660. ((path->mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
  661. request_mask &= ~STATX_ATIME;
  662. /* Is the user requesting attributes that might need revalidation? */
  663. if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
  664. STATX_MTIME|STATX_UID|STATX_GID|
  665. STATX_SIZE|STATX_BLOCKS)))
  666. goto out_no_revalidate;
  667. /* Check whether the cached attributes are stale */
  668. do_update |= force_sync || nfs_attribute_cache_expired(inode);
  669. cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
  670. do_update |= cache_validity &
  671. (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_LABEL);
  672. if (request_mask & STATX_ATIME)
  673. do_update |= cache_validity & NFS_INO_INVALID_ATIME;
  674. if (request_mask & (STATX_CTIME|STATX_MTIME))
  675. do_update |= cache_validity & NFS_INO_REVAL_PAGECACHE;
  676. if (do_update) {
  677. /* Update the attribute cache */
  678. if (!(server->flags & NFS_MOUNT_NOAC))
  679. nfs_readdirplus_parent_cache_miss(path->dentry);
  680. else
  681. nfs_readdirplus_parent_cache_hit(path->dentry);
  682. err = __nfs_revalidate_inode(server, inode);
  683. if (err)
  684. goto out;
  685. } else
  686. nfs_readdirplus_parent_cache_hit(path->dentry);
  687. out_no_revalidate:
  688. /* Only return attributes that were revalidated. */
  689. stat->result_mask &= request_mask;
  690. out_no_update:
  691. generic_fillattr(inode, stat);
  692. stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
  693. if (S_ISDIR(inode->i_mode))
  694. stat->blksize = NFS_SERVER(inode)->dtsize;
  695. out:
  696. trace_nfs_getattr_exit(inode, err);
  697. return err;
  698. }
  699. EXPORT_SYMBOL_GPL(nfs_getattr);
  700. static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
  701. {
  702. refcount_set(&l_ctx->count, 1);
  703. l_ctx->lockowner = current->files;
  704. INIT_LIST_HEAD(&l_ctx->list);
  705. atomic_set(&l_ctx->io_count, 0);
  706. }
  707. static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
  708. {
  709. struct nfs_lock_context *head = &ctx->lock_context;
  710. struct nfs_lock_context *pos = head;
  711. do {
  712. if (pos->lockowner != current->files)
  713. continue;
  714. refcount_inc(&pos->count);
  715. return pos;
  716. } while ((pos = list_entry(pos->list.next, typeof(*pos), list)) != head);
  717. return NULL;
  718. }
  719. struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
  720. {
  721. struct nfs_lock_context *res, *new = NULL;
  722. struct inode *inode = d_inode(ctx->dentry);
  723. spin_lock(&inode->i_lock);
  724. res = __nfs_find_lock_context(ctx);
  725. if (res == NULL) {
  726. spin_unlock(&inode->i_lock);
  727. new = kmalloc(sizeof(*new), GFP_KERNEL);
  728. if (new == NULL)
  729. return ERR_PTR(-ENOMEM);
  730. nfs_init_lock_context(new);
  731. spin_lock(&inode->i_lock);
  732. res = __nfs_find_lock_context(ctx);
  733. if (res == NULL) {
  734. list_add_tail(&new->list, &ctx->lock_context.list);
  735. new->open_context = ctx;
  736. res = new;
  737. new = NULL;
  738. }
  739. }
  740. spin_unlock(&inode->i_lock);
  741. kfree(new);
  742. return res;
  743. }
  744. EXPORT_SYMBOL_GPL(nfs_get_lock_context);
  745. void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
  746. {
  747. struct nfs_open_context *ctx = l_ctx->open_context;
  748. struct inode *inode = d_inode(ctx->dentry);
  749. if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock))
  750. return;
  751. list_del(&l_ctx->list);
  752. spin_unlock(&inode->i_lock);
  753. kfree(l_ctx);
  754. }
  755. EXPORT_SYMBOL_GPL(nfs_put_lock_context);
  756. /**
  757. * nfs_close_context - Common close_context() routine NFSv2/v3
  758. * @ctx: pointer to context
  759. * @is_sync: is this a synchronous close
  760. *
  761. * Ensure that the attributes are up to date if we're mounted
  762. * with close-to-open semantics and we have cached data that will
  763. * need to be revalidated on open.
  764. */
  765. void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
  766. {
  767. struct nfs_inode *nfsi;
  768. struct inode *inode;
  769. struct nfs_server *server;
  770. if (!(ctx->mode & FMODE_WRITE))
  771. return;
  772. if (!is_sync)
  773. return;
  774. inode = d_inode(ctx->dentry);
  775. if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
  776. return;
  777. nfsi = NFS_I(inode);
  778. if (inode->i_mapping->nrpages == 0)
  779. return;
  780. if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
  781. return;
  782. if (!list_empty(&nfsi->open_files))
  783. return;
  784. server = NFS_SERVER(inode);
  785. if (server->flags & NFS_MOUNT_NOCTO)
  786. return;
  787. nfs_revalidate_inode(server, inode);
  788. }
  789. EXPORT_SYMBOL_GPL(nfs_close_context);
  790. struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry,
  791. fmode_t f_mode,
  792. struct file *filp)
  793. {
  794. struct nfs_open_context *ctx;
  795. struct rpc_cred *cred = rpc_lookup_cred();
  796. if (IS_ERR(cred))
  797. return ERR_CAST(cred);
  798. ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
  799. if (!ctx) {
  800. put_rpccred(cred);
  801. return ERR_PTR(-ENOMEM);
  802. }
  803. nfs_sb_active(dentry->d_sb);
  804. ctx->dentry = dget(dentry);
  805. ctx->cred = cred;
  806. ctx->state = NULL;
  807. ctx->mode = f_mode;
  808. ctx->flags = 0;
  809. ctx->error = 0;
  810. ctx->flock_owner = (fl_owner_t)filp;
  811. nfs_init_lock_context(&ctx->lock_context);
  812. ctx->lock_context.open_context = ctx;
  813. INIT_LIST_HEAD(&ctx->list);
  814. ctx->mdsthreshold = NULL;
  815. return ctx;
  816. }
  817. EXPORT_SYMBOL_GPL(alloc_nfs_open_context);
  818. struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
  819. {
  820. if (ctx != NULL)
  821. refcount_inc(&ctx->lock_context.count);
  822. return ctx;
  823. }
  824. EXPORT_SYMBOL_GPL(get_nfs_open_context);
  825. static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
  826. {
  827. struct inode *inode = d_inode(ctx->dentry);
  828. struct super_block *sb = ctx->dentry->d_sb;
  829. if (!list_empty(&ctx->list)) {
  830. if (!refcount_dec_and_lock(&ctx->lock_context.count, &inode->i_lock))
  831. return;
  832. list_del(&ctx->list);
  833. spin_unlock(&inode->i_lock);
  834. } else if (!refcount_dec_and_test(&ctx->lock_context.count))
  835. return;
  836. if (inode != NULL)
  837. NFS_PROTO(inode)->close_context(ctx, is_sync);
  838. if (ctx->cred != NULL)
  839. put_rpccred(ctx->cred);
  840. dput(ctx->dentry);
  841. nfs_sb_deactive(sb);
  842. kfree(ctx->mdsthreshold);
  843. kfree(ctx);
  844. }
  845. void put_nfs_open_context(struct nfs_open_context *ctx)
  846. {
  847. __put_nfs_open_context(ctx, 0);
  848. }
  849. EXPORT_SYMBOL_GPL(put_nfs_open_context);
  850. static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
  851. {
  852. __put_nfs_open_context(ctx, 1);
  853. }
  854. /*
  855. * Ensure that mmap has a recent RPC credential for use when writing out
  856. * shared pages
  857. */
  858. void nfs_inode_attach_open_context(struct nfs_open_context *ctx)
  859. {
  860. struct inode *inode = d_inode(ctx->dentry);
  861. struct nfs_inode *nfsi = NFS_I(inode);
  862. spin_lock(&inode->i_lock);
  863. if (ctx->mode & FMODE_WRITE)
  864. list_add(&ctx->list, &nfsi->open_files);
  865. else
  866. list_add_tail(&ctx->list, &nfsi->open_files);
  867. spin_unlock(&inode->i_lock);
  868. }
  869. EXPORT_SYMBOL_GPL(nfs_inode_attach_open_context);
  870. void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
  871. {
  872. filp->private_data = get_nfs_open_context(ctx);
  873. if (list_empty(&ctx->list))
  874. nfs_inode_attach_open_context(ctx);
  875. }
  876. EXPORT_SYMBOL_GPL(nfs_file_set_open_context);
  877. /*
  878. * Given an inode, search for an open context with the desired characteristics
  879. */
  880. struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode)
  881. {
  882. struct nfs_inode *nfsi = NFS_I(inode);
  883. struct nfs_open_context *pos, *ctx = NULL;
  884. spin_lock(&inode->i_lock);
  885. list_for_each_entry(pos, &nfsi->open_files, list) {
  886. if (cred != NULL && pos->cred != cred)
  887. continue;
  888. if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode)
  889. continue;
  890. ctx = get_nfs_open_context(pos);
  891. break;
  892. }
  893. spin_unlock(&inode->i_lock);
  894. return ctx;
  895. }
  896. void nfs_file_clear_open_context(struct file *filp)
  897. {
  898. struct nfs_open_context *ctx = nfs_file_open_context(filp);
  899. if (ctx) {
  900. struct inode *inode = d_inode(ctx->dentry);
  901. /*
  902. * We fatal error on write before. Try to writeback
  903. * every page again.
  904. */
  905. if (ctx->error < 0)
  906. invalidate_inode_pages2(inode->i_mapping);
  907. filp->private_data = NULL;
  908. spin_lock(&inode->i_lock);
  909. list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
  910. spin_unlock(&inode->i_lock);
  911. put_nfs_open_context_sync(ctx);
  912. }
  913. }
  914. /*
  915. * These allocate and release file read/write context information.
  916. */
  917. int nfs_open(struct inode *inode, struct file *filp)
  918. {
  919. struct nfs_open_context *ctx;
  920. ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp);
  921. if (IS_ERR(ctx))
  922. return PTR_ERR(ctx);
  923. nfs_file_set_open_context(filp, ctx);
  924. put_nfs_open_context(ctx);
  925. nfs_fscache_open_file(inode, filp);
  926. return 0;
  927. }
  928. /*
  929. * This function is called whenever some part of NFS notices that
  930. * the cached attributes have to be refreshed.
  931. */
  932. int
  933. __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
  934. {
  935. int status = -ESTALE;
  936. struct nfs4_label *label = NULL;
  937. struct nfs_fattr *fattr = NULL;
  938. struct nfs_inode *nfsi = NFS_I(inode);
  939. dfprintk(PAGECACHE, "NFS: revalidating (%s/%Lu)\n",
  940. inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode));
  941. trace_nfs_revalidate_inode_enter(inode);
  942. if (is_bad_inode(inode))
  943. goto out;
  944. if (NFS_STALE(inode))
  945. goto out;
  946. /* pNFS: Attributes aren't updated until we layoutcommit */
  947. if (S_ISREG(inode->i_mode)) {
  948. status = pnfs_sync_inode(inode, false);
  949. if (status)
  950. goto out;
  951. }
  952. status = -ENOMEM;
  953. fattr = nfs_alloc_fattr();
  954. if (fattr == NULL)
  955. goto out;
  956. nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
  957. label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
  958. if (IS_ERR(label)) {
  959. status = PTR_ERR(label);
  960. goto out;
  961. }
  962. status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr, label);
  963. if (status != 0) {
  964. dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) getattr failed, error=%d\n",
  965. inode->i_sb->s_id,
  966. (unsigned long long)NFS_FILEID(inode), status);
  967. if (status == -ESTALE) {
  968. nfs_zap_caches(inode);
  969. if (!S_ISDIR(inode->i_mode))
  970. set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
  971. }
  972. goto err_out;
  973. }
  974. status = nfs_refresh_inode(inode, fattr);
  975. if (status) {
  976. dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) refresh failed, error=%d\n",
  977. inode->i_sb->s_id,
  978. (unsigned long long)NFS_FILEID(inode), status);
  979. goto err_out;
  980. }
  981. if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
  982. nfs_zap_acl_cache(inode);
  983. nfs_setsecurity(inode, fattr, label);
  984. dfprintk(PAGECACHE, "NFS: (%s/%Lu) revalidation complete\n",
  985. inode->i_sb->s_id,
  986. (unsigned long long)NFS_FILEID(inode));
  987. err_out:
  988. nfs4_label_free(label);
  989. out:
  990. nfs_free_fattr(fattr);
  991. trace_nfs_revalidate_inode_exit(inode, status);
  992. return status;
  993. }
  994. int nfs_attribute_cache_expired(struct inode *inode)
  995. {
  996. if (nfs_have_delegated_attributes(inode))
  997. return 0;
  998. return nfs_attribute_timeout(inode);
  999. }
  1000. /**
  1001. * nfs_revalidate_inode - Revalidate the inode attributes
  1002. * @server - pointer to nfs_server struct
  1003. * @inode - pointer to inode struct
  1004. *
  1005. * Updates inode attribute information by retrieving the data from the server.
  1006. */
  1007. int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
  1008. {
  1009. if (!nfs_need_revalidate_inode(inode))
  1010. return NFS_STALE(inode) ? -ESTALE : 0;
  1011. return __nfs_revalidate_inode(server, inode);
  1012. }
  1013. EXPORT_SYMBOL_GPL(nfs_revalidate_inode);
  1014. static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
  1015. {
  1016. struct nfs_inode *nfsi = NFS_I(inode);
  1017. int ret;
  1018. if (mapping->nrpages != 0) {
  1019. if (S_ISREG(inode->i_mode)) {
  1020. ret = nfs_sync_mapping(mapping);
  1021. if (ret < 0)
  1022. return ret;
  1023. }
  1024. ret = invalidate_inode_pages2(mapping);
  1025. if (ret < 0)
  1026. return ret;
  1027. }
  1028. if (S_ISDIR(inode->i_mode)) {
  1029. spin_lock(&inode->i_lock);
  1030. memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
  1031. spin_unlock(&inode->i_lock);
  1032. }
  1033. nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
  1034. nfs_fscache_wait_on_invalidate(inode);
  1035. dfprintk(PAGECACHE, "NFS: (%s/%Lu) data cache invalidated\n",
  1036. inode->i_sb->s_id,
  1037. (unsigned long long)NFS_FILEID(inode));
  1038. return 0;
  1039. }
  1040. bool nfs_mapping_need_revalidate_inode(struct inode *inode)
  1041. {
  1042. return nfs_check_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE) ||
  1043. NFS_STALE(inode);
  1044. }
  1045. int nfs_revalidate_mapping_rcu(struct inode *inode)
  1046. {
  1047. struct nfs_inode *nfsi = NFS_I(inode);
  1048. unsigned long *bitlock = &nfsi->flags;
  1049. int ret = 0;
  1050. if (IS_SWAPFILE(inode))
  1051. goto out;
  1052. if (nfs_mapping_need_revalidate_inode(inode)) {
  1053. ret = -ECHILD;
  1054. goto out;
  1055. }
  1056. spin_lock(&inode->i_lock);
  1057. if (test_bit(NFS_INO_INVALIDATING, bitlock) ||
  1058. (nfsi->cache_validity & NFS_INO_INVALID_DATA))
  1059. ret = -ECHILD;
  1060. spin_unlock(&inode->i_lock);
  1061. out:
  1062. return ret;
  1063. }
  1064. /**
  1065. * nfs_revalidate_mapping - Revalidate the pagecache
  1066. * @inode - pointer to host inode
  1067. * @mapping - pointer to mapping
  1068. */
  1069. int nfs_revalidate_mapping(struct inode *inode,
  1070. struct address_space *mapping)
  1071. {
  1072. struct nfs_inode *nfsi = NFS_I(inode);
  1073. unsigned long *bitlock = &nfsi->flags;
  1074. int ret = 0;
  1075. /* swapfiles are not supposed to be shared. */
  1076. if (IS_SWAPFILE(inode))
  1077. goto out;
  1078. if (nfs_mapping_need_revalidate_inode(inode)) {
  1079. ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
  1080. if (ret < 0)
  1081. goto out;
  1082. }
  1083. /*
  1084. * We must clear NFS_INO_INVALID_DATA first to ensure that
  1085. * invalidations that come in while we're shooting down the mappings
  1086. * are respected. But, that leaves a race window where one revalidator
  1087. * can clear the flag, and then another checks it before the mapping
  1088. * gets invalidated. Fix that by serializing access to this part of
  1089. * the function.
  1090. *
  1091. * At the same time, we need to allow other tasks to see whether we
  1092. * might be in the middle of invalidating the pages, so we only set
  1093. * the bit lock here if it looks like we're going to be doing that.
  1094. */
  1095. for (;;) {
  1096. ret = wait_on_bit_action(bitlock, NFS_INO_INVALIDATING,
  1097. nfs_wait_bit_killable, TASK_KILLABLE);
  1098. if (ret)
  1099. goto out;
  1100. spin_lock(&inode->i_lock);
  1101. if (test_bit(NFS_INO_INVALIDATING, bitlock)) {
  1102. spin_unlock(&inode->i_lock);
  1103. continue;
  1104. }
  1105. if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
  1106. break;
  1107. spin_unlock(&inode->i_lock);
  1108. goto out;
  1109. }
  1110. set_bit(NFS_INO_INVALIDATING, bitlock);
  1111. smp_wmb();
  1112. nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
  1113. spin_unlock(&inode->i_lock);
  1114. trace_nfs_invalidate_mapping_enter(inode);
  1115. ret = nfs_invalidate_mapping(inode, mapping);
  1116. trace_nfs_invalidate_mapping_exit(inode, ret);
  1117. clear_bit_unlock(NFS_INO_INVALIDATING, bitlock);
  1118. smp_mb__after_atomic();
  1119. wake_up_bit(bitlock, NFS_INO_INVALIDATING);
  1120. out:
  1121. return ret;
  1122. }
  1123. static bool nfs_file_has_writers(struct nfs_inode *nfsi)
  1124. {
  1125. struct inode *inode = &nfsi->vfs_inode;
  1126. assert_spin_locked(&inode->i_lock);
  1127. if (!S_ISREG(inode->i_mode))
  1128. return false;
  1129. if (list_empty(&nfsi->open_files))
  1130. return false;
  1131. /* Note: This relies on nfsi->open_files being ordered with writers
  1132. * being placed at the head of the list.
  1133. * See nfs_inode_attach_open_context()
  1134. */
  1135. return (list_first_entry(&nfsi->open_files,
  1136. struct nfs_open_context,
  1137. list)->mode & FMODE_WRITE) == FMODE_WRITE;
  1138. }
  1139. static bool nfs_file_has_buffered_writers(struct nfs_inode *nfsi)
  1140. {
  1141. return nfs_file_has_writers(nfsi) && nfs_file_io_is_buffered(nfsi);
  1142. }
  1143. static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
  1144. {
  1145. unsigned long ret = 0;
  1146. if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE)
  1147. && (fattr->valid & NFS_ATTR_FATTR_CHANGE)
  1148. && inode_eq_iversion_raw(inode, fattr->pre_change_attr)) {
  1149. inode_set_iversion_raw(inode, fattr->change_attr);
  1150. if (S_ISDIR(inode->i_mode))
  1151. nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
  1152. ret |= NFS_INO_INVALID_ATTR;
  1153. }
  1154. /* If we have atomic WCC data, we may update some attributes */
  1155. if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME)
  1156. && (fattr->valid & NFS_ATTR_FATTR_CTIME)
  1157. && timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
  1158. memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
  1159. ret |= NFS_INO_INVALID_ATTR;
  1160. }
  1161. if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME)
  1162. && (fattr->valid & NFS_ATTR_FATTR_MTIME)
  1163. && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
  1164. memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
  1165. if (S_ISDIR(inode->i_mode))
  1166. nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
  1167. ret |= NFS_INO_INVALID_ATTR;
  1168. }
  1169. if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
  1170. && (fattr->valid & NFS_ATTR_FATTR_SIZE)
  1171. && i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
  1172. && !nfs_have_writebacks(inode)) {
  1173. i_size_write(inode, nfs_size_to_loff_t(fattr->size));
  1174. ret |= NFS_INO_INVALID_ATTR;
  1175. }
  1176. return ret;
  1177. }
  1178. /**
  1179. * nfs_check_inode_attributes - verify consistency of the inode attribute cache
  1180. * @inode - pointer to inode
  1181. * @fattr - updated attributes
  1182. *
  1183. * Verifies the attribute cache. If we have just changed the attributes,
  1184. * so that fattr carries weak cache consistency data, then it may
  1185. * also update the ctime/mtime/change_attribute.
  1186. */
  1187. static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fattr)
  1188. {
  1189. struct nfs_inode *nfsi = NFS_I(inode);
  1190. loff_t cur_size, new_isize;
  1191. unsigned long invalid = 0;
  1192. if (nfs_have_delegated_attributes(inode))
  1193. return 0;
  1194. /* Has the inode gone and changed behind our back? */
  1195. if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid)
  1196. return -ESTALE;
  1197. if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
  1198. return -ESTALE;
  1199. if (!nfs_file_has_buffered_writers(nfsi)) {
  1200. /* Verify a few of the more important attributes */
  1201. if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && !inode_eq_iversion_raw(inode, fattr->change_attr))
  1202. invalid |= NFS_INO_INVALID_ATTR | NFS_INO_REVAL_PAGECACHE;
  1203. if ((fattr->valid & NFS_ATTR_FATTR_MTIME) && !timespec_equal(&inode->i_mtime, &fattr->mtime))
  1204. invalid |= NFS_INO_INVALID_ATTR;
  1205. if ((fattr->valid & NFS_ATTR_FATTR_CTIME) && !timespec_equal(&inode->i_ctime, &fattr->ctime))
  1206. invalid |= NFS_INO_INVALID_ATTR;
  1207. if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
  1208. cur_size = i_size_read(inode);
  1209. new_isize = nfs_size_to_loff_t(fattr->size);
  1210. if (cur_size != new_isize)
  1211. invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
  1212. }
  1213. }
  1214. /* Have any file permissions changed? */
  1215. if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
  1216. invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
  1217. if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
  1218. invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
  1219. if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
  1220. invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
  1221. /* Has the link count changed? */
  1222. if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
  1223. invalid |= NFS_INO_INVALID_ATTR;
  1224. if ((fattr->valid & NFS_ATTR_FATTR_ATIME) && !timespec_equal(&inode->i_atime, &fattr->atime))
  1225. invalid |= NFS_INO_INVALID_ATIME;
  1226. if (invalid != 0)
  1227. nfs_set_cache_invalid(inode, invalid | NFS_INO_REVAL_FORCED);
  1228. nfsi->read_cache_jiffies = fattr->time_start;
  1229. return 0;
  1230. }
  1231. static atomic_long_t nfs_attr_generation_counter;
  1232. static unsigned long nfs_read_attr_generation_counter(void)
  1233. {
  1234. return atomic_long_read(&nfs_attr_generation_counter);
  1235. }
  1236. unsigned long nfs_inc_attr_generation_counter(void)
  1237. {
  1238. return atomic_long_inc_return(&nfs_attr_generation_counter);
  1239. }
  1240. EXPORT_SYMBOL_GPL(nfs_inc_attr_generation_counter);
  1241. void nfs_fattr_init(struct nfs_fattr *fattr)
  1242. {
  1243. fattr->valid = 0;
  1244. fattr->time_start = jiffies;
  1245. fattr->gencount = nfs_inc_attr_generation_counter();
  1246. fattr->owner_name = NULL;
  1247. fattr->group_name = NULL;
  1248. }
  1249. EXPORT_SYMBOL_GPL(nfs_fattr_init);
  1250. /**
  1251. * nfs_fattr_set_barrier
  1252. * @fattr: attributes
  1253. *
  1254. * Used to set a barrier after an attribute was updated. This
  1255. * barrier ensures that older attributes from RPC calls that may
  1256. * have raced with our update cannot clobber these new values.
  1257. * Note that you are still responsible for ensuring that other
  1258. * operations which change the attribute on the server do not
  1259. * collide.
  1260. */
  1261. void nfs_fattr_set_barrier(struct nfs_fattr *fattr)
  1262. {
  1263. fattr->gencount = nfs_inc_attr_generation_counter();
  1264. }
  1265. struct nfs_fattr *nfs_alloc_fattr(void)
  1266. {
  1267. struct nfs_fattr *fattr;
  1268. fattr = kmalloc(sizeof(*fattr), GFP_NOFS);
  1269. if (fattr != NULL)
  1270. nfs_fattr_init(fattr);
  1271. return fattr;
  1272. }
  1273. EXPORT_SYMBOL_GPL(nfs_alloc_fattr);
  1274. struct nfs_fh *nfs_alloc_fhandle(void)
  1275. {
  1276. struct nfs_fh *fh;
  1277. fh = kmalloc(sizeof(struct nfs_fh), GFP_NOFS);
  1278. if (fh != NULL)
  1279. fh->size = 0;
  1280. return fh;
  1281. }
  1282. EXPORT_SYMBOL_GPL(nfs_alloc_fhandle);
  1283. #ifdef NFS_DEBUG
  1284. /*
  1285. * _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
  1286. * in the same way that wireshark does
  1287. *
  1288. * @fh: file handle
  1289. *
  1290. * For debugging only.
  1291. */
  1292. u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
  1293. {
  1294. /* wireshark uses 32-bit AUTODIN crc and does a bitwise
  1295. * not on the result */
  1296. return nfs_fhandle_hash(fh);
  1297. }
  1298. EXPORT_SYMBOL_GPL(_nfs_display_fhandle_hash);
  1299. /*
  1300. * _nfs_display_fhandle - display an NFS file handle on the console
  1301. *
  1302. * @fh: file handle to display
  1303. * @caption: display caption
  1304. *
  1305. * For debugging only.
  1306. */
  1307. void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
  1308. {
  1309. unsigned short i;
  1310. if (fh == NULL || fh->size == 0) {
  1311. printk(KERN_DEFAULT "%s at %p is empty\n", caption, fh);
  1312. return;
  1313. }
  1314. printk(KERN_DEFAULT "%s at %p is %u bytes, crc: 0x%08x:\n",
  1315. caption, fh, fh->size, _nfs_display_fhandle_hash(fh));
  1316. for (i = 0; i < fh->size; i += 16) {
  1317. __be32 *pos = (__be32 *)&fh->data[i];
  1318. switch ((fh->size - i - 1) >> 2) {
  1319. case 0:
  1320. printk(KERN_DEFAULT " %08x\n",
  1321. be32_to_cpup(pos));
  1322. break;
  1323. case 1:
  1324. printk(KERN_DEFAULT " %08x %08x\n",
  1325. be32_to_cpup(pos), be32_to_cpup(pos + 1));
  1326. break;
  1327. case 2:
  1328. printk(KERN_DEFAULT " %08x %08x %08x\n",
  1329. be32_to_cpup(pos), be32_to_cpup(pos + 1),
  1330. be32_to_cpup(pos + 2));
  1331. break;
  1332. default:
  1333. printk(KERN_DEFAULT " %08x %08x %08x %08x\n",
  1334. be32_to_cpup(pos), be32_to_cpup(pos + 1),
  1335. be32_to_cpup(pos + 2), be32_to_cpup(pos + 3));
  1336. }
  1337. }
  1338. }
  1339. EXPORT_SYMBOL_GPL(_nfs_display_fhandle);
  1340. #endif
  1341. /**
  1342. * nfs_inode_attrs_need_update - check if the inode attributes need updating
  1343. * @inode - pointer to inode
  1344. * @fattr - attributes
  1345. *
  1346. * Attempt to divine whether or not an RPC call reply carrying stale
  1347. * attributes got scheduled after another call carrying updated ones.
  1348. *
  1349. * To do so, the function first assumes that a more recent ctime means
  1350. * that the attributes in fattr are newer, however it also attempt to
  1351. * catch the case where ctime either didn't change, or went backwards
  1352. * (if someone reset the clock on the server) by looking at whether
  1353. * or not this RPC call was started after the inode was last updated.
  1354. * Note also the check for wraparound of 'attr_gencount'
  1355. *
  1356. * The function returns 'true' if it thinks the attributes in 'fattr' are
  1357. * more recent than the ones cached in the inode.
  1358. *
  1359. */
  1360. static int nfs_inode_attrs_need_update(const struct inode *inode, const struct nfs_fattr *fattr)
  1361. {
  1362. const struct nfs_inode *nfsi = NFS_I(inode);
  1363. return ((long)fattr->gencount - (long)nfsi->attr_gencount) > 0 ||
  1364. ((long)nfsi->attr_gencount - (long)nfs_read_attr_generation_counter() > 0);
  1365. }
  1366. static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
  1367. {
  1368. int ret;
  1369. trace_nfs_refresh_inode_enter(inode);
  1370. if (nfs_inode_attrs_need_update(inode, fattr))
  1371. ret = nfs_update_inode(inode, fattr);
  1372. else
  1373. ret = nfs_check_inode_attributes(inode, fattr);
  1374. trace_nfs_refresh_inode_exit(inode, ret);
  1375. return ret;
  1376. }
  1377. /**
  1378. * nfs_refresh_inode - try to update the inode attribute cache
  1379. * @inode - pointer to inode
  1380. * @fattr - updated attributes
  1381. *
  1382. * Check that an RPC call that returned attributes has not overlapped with
  1383. * other recent updates of the inode metadata, then decide whether it is
  1384. * safe to do a full update of the inode attributes, or whether just to
  1385. * call nfs_check_inode_attributes.
  1386. */
  1387. int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
  1388. {
  1389. int status;
  1390. if ((fattr->valid & NFS_ATTR_FATTR) == 0)
  1391. return 0;
  1392. spin_lock(&inode->i_lock);
  1393. status = nfs_refresh_inode_locked(inode, fattr);
  1394. spin_unlock(&inode->i_lock);
  1395. return status;
  1396. }
  1397. EXPORT_SYMBOL_GPL(nfs_refresh_inode);
  1398. static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
  1399. {
  1400. unsigned long invalid = NFS_INO_INVALID_ATTR;
  1401. if (S_ISDIR(inode->i_mode))
  1402. invalid |= NFS_INO_INVALID_DATA;
  1403. nfs_set_cache_invalid(inode, invalid);
  1404. if ((fattr->valid & NFS_ATTR_FATTR) == 0)
  1405. return 0;
  1406. return nfs_refresh_inode_locked(inode, fattr);
  1407. }
  1408. /**
  1409. * nfs_post_op_update_inode - try to update the inode attribute cache
  1410. * @inode - pointer to inode
  1411. * @fattr - updated attributes
  1412. *
  1413. * After an operation that has changed the inode metadata, mark the
  1414. * attribute cache as being invalid, then try to update it.
  1415. *
  1416. * NB: if the server didn't return any post op attributes, this
  1417. * function will force the retrieval of attributes before the next
  1418. * NFS request. Thus it should be used only for operations that
  1419. * are expected to change one or more attributes, to avoid
  1420. * unnecessary NFS requests and trips through nfs_update_inode().
  1421. */
  1422. int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
  1423. {
  1424. int status;
  1425. spin_lock(&inode->i_lock);
  1426. nfs_fattr_set_barrier(fattr);
  1427. status = nfs_post_op_update_inode_locked(inode, fattr);
  1428. spin_unlock(&inode->i_lock);
  1429. return status;
  1430. }
  1431. EXPORT_SYMBOL_GPL(nfs_post_op_update_inode);
  1432. /**
  1433. * nfs_post_op_update_inode_force_wcc_locked - update the inode attribute cache
  1434. * @inode - pointer to inode
  1435. * @fattr - updated attributes
  1436. *
  1437. * After an operation that has changed the inode metadata, mark the
  1438. * attribute cache as being invalid, then try to update it. Fake up
  1439. * weak cache consistency data, if none exist.
  1440. *
  1441. * This function is mainly designed to be used by the ->write_done() functions.
  1442. */
  1443. int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr)
  1444. {
  1445. int status;
  1446. /* Don't do a WCC update if these attributes are already stale */
  1447. if ((fattr->valid & NFS_ATTR_FATTR) == 0 ||
  1448. !nfs_inode_attrs_need_update(inode, fattr)) {
  1449. fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE
  1450. | NFS_ATTR_FATTR_PRESIZE
  1451. | NFS_ATTR_FATTR_PREMTIME
  1452. | NFS_ATTR_FATTR_PRECTIME);
  1453. goto out_noforce;
  1454. }
  1455. if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 &&
  1456. (fattr->valid & NFS_ATTR_FATTR_PRECHANGE) == 0) {
  1457. fattr->pre_change_attr = inode_peek_iversion_raw(inode);
  1458. fattr->valid |= NFS_ATTR_FATTR_PRECHANGE;
  1459. }
  1460. if ((fattr->valid & NFS_ATTR_FATTR_CTIME) != 0 &&
  1461. (fattr->valid & NFS_ATTR_FATTR_PRECTIME) == 0) {
  1462. memcpy(&fattr->pre_ctime, &inode->i_ctime, sizeof(fattr->pre_ctime));
  1463. fattr->valid |= NFS_ATTR_FATTR_PRECTIME;
  1464. }
  1465. if ((fattr->valid & NFS_ATTR_FATTR_MTIME) != 0 &&
  1466. (fattr->valid & NFS_ATTR_FATTR_PREMTIME) == 0) {
  1467. memcpy(&fattr->pre_mtime, &inode->i_mtime, sizeof(fattr->pre_mtime));
  1468. fattr->valid |= NFS_ATTR_FATTR_PREMTIME;
  1469. }
  1470. if ((fattr->valid & NFS_ATTR_FATTR_SIZE) != 0 &&
  1471. (fattr->valid & NFS_ATTR_FATTR_PRESIZE) == 0) {
  1472. fattr->pre_size = i_size_read(inode);
  1473. fattr->valid |= NFS_ATTR_FATTR_PRESIZE;
  1474. }
  1475. out_noforce:
  1476. status = nfs_post_op_update_inode_locked(inode, fattr);
  1477. return status;
  1478. }
  1479. /**
  1480. * nfs_post_op_update_inode_force_wcc - try to update the inode attribute cache
  1481. * @inode - pointer to inode
  1482. * @fattr - updated attributes
  1483. *
  1484. * After an operation that has changed the inode metadata, mark the
  1485. * attribute cache as being invalid, then try to update it. Fake up
  1486. * weak cache consistency data, if none exist.
  1487. *
  1488. * This function is mainly designed to be used by the ->write_done() functions.
  1489. */
  1490. int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr)
  1491. {
  1492. int status;
  1493. spin_lock(&inode->i_lock);
  1494. nfs_fattr_set_barrier(fattr);
  1495. status = nfs_post_op_update_inode_force_wcc_locked(inode, fattr);
  1496. spin_unlock(&inode->i_lock);
  1497. return status;
  1498. }
  1499. EXPORT_SYMBOL_GPL(nfs_post_op_update_inode_force_wcc);
  1500. static inline bool nfs_fileid_valid(struct nfs_inode *nfsi,
  1501. struct nfs_fattr *fattr)
  1502. {
  1503. bool ret1 = true, ret2 = true;
  1504. if (fattr->valid & NFS_ATTR_FATTR_FILEID)
  1505. ret1 = (nfsi->fileid == fattr->fileid);
  1506. if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
  1507. ret2 = (nfsi->fileid == fattr->mounted_on_fileid);
  1508. return ret1 || ret2;
  1509. }
  1510. /*
  1511. * Many nfs protocol calls return the new file attributes after
  1512. * an operation. Here we update the inode to reflect the state
  1513. * of the server's inode.
  1514. *
  1515. * This is a bit tricky because we have to make sure all dirty pages
  1516. * have been sent off to the server before calling invalidate_inode_pages.
  1517. * To make sure no other process adds more write requests while we try
  1518. * our best to flush them, we make them sleep during the attribute refresh.
  1519. *
  1520. * A very similar scenario holds for the dir cache.
  1521. */
  1522. static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
  1523. {
  1524. struct nfs_server *server;
  1525. struct nfs_inode *nfsi = NFS_I(inode);
  1526. loff_t cur_isize, new_isize;
  1527. unsigned long invalid = 0;
  1528. unsigned long now = jiffies;
  1529. unsigned long save_cache_validity;
  1530. bool have_writers = nfs_file_has_buffered_writers(nfsi);
  1531. bool cache_revalidated = true;
  1532. dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
  1533. __func__, inode->i_sb->s_id, inode->i_ino,
  1534. nfs_display_fhandle_hash(NFS_FH(inode)),
  1535. atomic_read(&inode->i_count), fattr->valid);
  1536. if (!nfs_fileid_valid(nfsi, fattr)) {
  1537. printk(KERN_ERR "NFS: server %s error: fileid changed\n"
  1538. "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
  1539. NFS_SERVER(inode)->nfs_client->cl_hostname,
  1540. inode->i_sb->s_id, (long long)nfsi->fileid,
  1541. (long long)fattr->fileid);
  1542. goto out_err;
  1543. }
  1544. /*
  1545. * Make sure the inode's type hasn't changed.
  1546. */
  1547. if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) {
  1548. /*
  1549. * Big trouble! The inode has become a different object.
  1550. */
  1551. printk(KERN_DEBUG "NFS: %s: inode %lu mode changed, %07o to %07o\n",
  1552. __func__, inode->i_ino, inode->i_mode, fattr->mode);
  1553. goto out_err;
  1554. }
  1555. server = NFS_SERVER(inode);
  1556. /* Update the fsid? */
  1557. if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
  1558. !nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
  1559. !IS_AUTOMOUNT(inode))
  1560. server->fsid = fattr->fsid;
  1561. /*
  1562. * Update the read time so we don't revalidate too often.
  1563. */
  1564. nfsi->read_cache_jiffies = fattr->time_start;
  1565. save_cache_validity = nfsi->cache_validity;
  1566. nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR
  1567. | NFS_INO_INVALID_ATIME
  1568. | NFS_INO_REVAL_FORCED
  1569. | NFS_INO_REVAL_PAGECACHE);
  1570. /* Do atomic weak cache consistency updates */
  1571. invalid |= nfs_wcc_update_inode(inode, fattr);
  1572. if (pnfs_layoutcommit_outstanding(inode)) {
  1573. nfsi->cache_validity |= save_cache_validity & NFS_INO_INVALID_ATTR;
  1574. cache_revalidated = false;
  1575. }
  1576. /* More cache consistency checks */
  1577. if (fattr->valid & NFS_ATTR_FATTR_CHANGE) {
  1578. if (!inode_eq_iversion_raw(inode, fattr->change_attr)) {
  1579. dprintk("NFS: change_attr change on server for file %s/%ld\n",
  1580. inode->i_sb->s_id, inode->i_ino);
  1581. /* Could it be a race with writeback? */
  1582. if (!have_writers) {
  1583. invalid |= NFS_INO_INVALID_ATTR
  1584. | NFS_INO_INVALID_DATA
  1585. | NFS_INO_INVALID_ACCESS
  1586. | NFS_INO_INVALID_ACL;
  1587. if (S_ISDIR(inode->i_mode))
  1588. nfs_force_lookup_revalidate(inode);
  1589. }
  1590. inode_set_iversion_raw(inode, fattr->change_attr);
  1591. }
  1592. } else {
  1593. nfsi->cache_validity |= save_cache_validity;
  1594. cache_revalidated = false;
  1595. }
  1596. if (fattr->valid & NFS_ATTR_FATTR_MTIME) {
  1597. memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
  1598. } else if (server->caps & NFS_CAP_MTIME) {
  1599. nfsi->cache_validity |= save_cache_validity &
  1600. (NFS_INO_INVALID_ATTR
  1601. | NFS_INO_REVAL_FORCED);
  1602. cache_revalidated = false;
  1603. }
  1604. if (fattr->valid & NFS_ATTR_FATTR_CTIME) {
  1605. memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
  1606. } else if (server->caps & NFS_CAP_CTIME) {
  1607. nfsi->cache_validity |= save_cache_validity &
  1608. (NFS_INO_INVALID_ATTR
  1609. | NFS_INO_REVAL_FORCED);
  1610. cache_revalidated = false;
  1611. }
  1612. /* Check if our cached file size is stale */
  1613. if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
  1614. new_isize = nfs_size_to_loff_t(fattr->size);
  1615. cur_isize = i_size_read(inode);
  1616. if (new_isize != cur_isize) {
  1617. /* Do we perhaps have any outstanding writes, or has
  1618. * the file grown beyond our last write? */
  1619. if (!nfs_have_writebacks(inode) || new_isize > cur_isize) {
  1620. i_size_write(inode, new_isize);
  1621. if (!have_writers)
  1622. invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
  1623. }
  1624. dprintk("NFS: isize change on server for file %s/%ld "
  1625. "(%Ld to %Ld)\n",
  1626. inode->i_sb->s_id,
  1627. inode->i_ino,
  1628. (long long)cur_isize,
  1629. (long long)new_isize);
  1630. }
  1631. } else {
  1632. nfsi->cache_validity |= save_cache_validity &
  1633. (NFS_INO_INVALID_ATTR
  1634. | NFS_INO_REVAL_PAGECACHE
  1635. | NFS_INO_REVAL_FORCED);
  1636. cache_revalidated = false;
  1637. }
  1638. if (fattr->valid & NFS_ATTR_FATTR_ATIME)
  1639. memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
  1640. else if (server->caps & NFS_CAP_ATIME) {
  1641. nfsi->cache_validity |= save_cache_validity &
  1642. (NFS_INO_INVALID_ATIME
  1643. | NFS_INO_REVAL_FORCED);
  1644. cache_revalidated = false;
  1645. }
  1646. if (fattr->valid & NFS_ATTR_FATTR_MODE) {
  1647. if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
  1648. umode_t newmode = inode->i_mode & S_IFMT;
  1649. newmode |= fattr->mode & S_IALLUGO;
  1650. inode->i_mode = newmode;
  1651. invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
  1652. }
  1653. } else if (server->caps & NFS_CAP_MODE) {
  1654. nfsi->cache_validity |= save_cache_validity &
  1655. (NFS_INO_INVALID_ATTR
  1656. | NFS_INO_INVALID_ACCESS
  1657. | NFS_INO_INVALID_ACL
  1658. | NFS_INO_REVAL_FORCED);
  1659. cache_revalidated = false;
  1660. }
  1661. if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
  1662. if (!uid_eq(inode->i_uid, fattr->uid)) {
  1663. invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
  1664. inode->i_uid = fattr->uid;
  1665. }
  1666. } else if (server->caps & NFS_CAP_OWNER) {
  1667. nfsi->cache_validity |= save_cache_validity &
  1668. (NFS_INO_INVALID_ATTR
  1669. | NFS_INO_INVALID_ACCESS
  1670. | NFS_INO_INVALID_ACL
  1671. | NFS_INO_REVAL_FORCED);
  1672. cache_revalidated = false;
  1673. }
  1674. if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
  1675. if (!gid_eq(inode->i_gid, fattr->gid)) {
  1676. invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
  1677. inode->i_gid = fattr->gid;
  1678. }
  1679. } else if (server->caps & NFS_CAP_OWNER_GROUP) {
  1680. nfsi->cache_validity |= save_cache_validity &
  1681. (NFS_INO_INVALID_ATTR
  1682. | NFS_INO_INVALID_ACCESS
  1683. | NFS_INO_INVALID_ACL
  1684. | NFS_INO_REVAL_FORCED);
  1685. cache_revalidated = false;
  1686. }
  1687. if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
  1688. if (inode->i_nlink != fattr->nlink) {
  1689. invalid |= NFS_INO_INVALID_ATTR;
  1690. if (S_ISDIR(inode->i_mode))
  1691. invalid |= NFS_INO_INVALID_DATA;
  1692. set_nlink(inode, fattr->nlink);
  1693. }
  1694. } else if (server->caps & NFS_CAP_NLINK) {
  1695. nfsi->cache_validity |= save_cache_validity &
  1696. (NFS_INO_INVALID_ATTR
  1697. | NFS_INO_REVAL_FORCED);
  1698. cache_revalidated = false;
  1699. }
  1700. if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
  1701. /*
  1702. * report the blocks in 512byte units
  1703. */
  1704. inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
  1705. } else if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
  1706. inode->i_blocks = fattr->du.nfs2.blocks;
  1707. else
  1708. cache_revalidated = false;
  1709. /* Update attrtimeo value if we're out of the unstable period */
  1710. if (invalid & NFS_INO_INVALID_ATTR) {
  1711. nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
  1712. nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
  1713. nfsi->attrtimeo_timestamp = now;
  1714. /* Set barrier to be more recent than all outstanding updates */
  1715. nfsi->attr_gencount = nfs_inc_attr_generation_counter();
  1716. } else {
  1717. if (cache_revalidated) {
  1718. if (!time_in_range_open(now, nfsi->attrtimeo_timestamp,
  1719. nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
  1720. nfsi->attrtimeo <<= 1;
  1721. if (nfsi->attrtimeo > NFS_MAXATTRTIMEO(inode))
  1722. nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
  1723. }
  1724. nfsi->attrtimeo_timestamp = now;
  1725. }
  1726. /* Set the barrier to be more recent than this fattr */
  1727. if ((long)fattr->gencount - (long)nfsi->attr_gencount > 0)
  1728. nfsi->attr_gencount = fattr->gencount;
  1729. }
  1730. /* Don't declare attrcache up to date if there were no attrs! */
  1731. if (cache_revalidated)
  1732. invalid &= ~NFS_INO_INVALID_ATTR;
  1733. /* Don't invalidate the data if we were to blame */
  1734. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
  1735. || S_ISLNK(inode->i_mode)))
  1736. invalid &= ~NFS_INO_INVALID_DATA;
  1737. if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) ||
  1738. (save_cache_validity & NFS_INO_REVAL_FORCED))
  1739. nfs_set_cache_invalid(inode, invalid);
  1740. return 0;
  1741. out_err:
  1742. /*
  1743. * No need to worry about unhashing the dentry, as the
  1744. * lookup validation will know that the inode is bad.
  1745. * (But we fall through to invalidate the caches.)
  1746. */
  1747. nfs_invalidate_inode(inode);
  1748. return -ESTALE;
  1749. }
  1750. struct inode *nfs_alloc_inode(struct super_block *sb)
  1751. {
  1752. struct nfs_inode *nfsi;
  1753. nfsi = kmem_cache_alloc(nfs_inode_cachep, GFP_KERNEL);
  1754. if (!nfsi)
  1755. return NULL;
  1756. nfsi->flags = 0UL;
  1757. nfsi->cache_validity = 0UL;
  1758. #if IS_ENABLED(CONFIG_NFS_V4)
  1759. nfsi->nfs4_acl = NULL;
  1760. #endif /* CONFIG_NFS_V4 */
  1761. return &nfsi->vfs_inode;
  1762. }
  1763. EXPORT_SYMBOL_GPL(nfs_alloc_inode);
  1764. static void nfs_i_callback(struct rcu_head *head)
  1765. {
  1766. struct inode *inode = container_of(head, struct inode, i_rcu);
  1767. kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
  1768. }
  1769. void nfs_destroy_inode(struct inode *inode)
  1770. {
  1771. call_rcu(&inode->i_rcu, nfs_i_callback);
  1772. }
  1773. EXPORT_SYMBOL_GPL(nfs_destroy_inode);
  1774. static inline void nfs4_init_once(struct nfs_inode *nfsi)
  1775. {
  1776. #if IS_ENABLED(CONFIG_NFS_V4)
  1777. INIT_LIST_HEAD(&nfsi->open_states);
  1778. nfsi->delegation = NULL;
  1779. init_rwsem(&nfsi->rwsem);
  1780. nfsi->layout = NULL;
  1781. #endif
  1782. }
  1783. static void init_once(void *foo)
  1784. {
  1785. struct nfs_inode *nfsi = (struct nfs_inode *) foo;
  1786. inode_init_once(&nfsi->vfs_inode);
  1787. INIT_LIST_HEAD(&nfsi->open_files);
  1788. INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
  1789. INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
  1790. INIT_LIST_HEAD(&nfsi->commit_info.list);
  1791. atomic_long_set(&nfsi->nrequests, 0);
  1792. atomic_long_set(&nfsi->commit_info.ncommit, 0);
  1793. atomic_set(&nfsi->commit_info.rpcs_out, 0);
  1794. init_rwsem(&nfsi->rmdir_sem);
  1795. mutex_init(&nfsi->commit_mutex);
  1796. nfs4_init_once(nfsi);
  1797. }
  1798. static int __init nfs_init_inodecache(void)
  1799. {
  1800. nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
  1801. sizeof(struct nfs_inode),
  1802. 0, (SLAB_RECLAIM_ACCOUNT|
  1803. SLAB_MEM_SPREAD|SLAB_ACCOUNT),
  1804. init_once);
  1805. if (nfs_inode_cachep == NULL)
  1806. return -ENOMEM;
  1807. return 0;
  1808. }
  1809. static void nfs_destroy_inodecache(void)
  1810. {
  1811. /*
  1812. * Make sure all delayed rcu free inodes are flushed before we
  1813. * destroy cache.
  1814. */
  1815. rcu_barrier();
  1816. kmem_cache_destroy(nfs_inode_cachep);
  1817. }
  1818. struct workqueue_struct *nfsiod_workqueue;
  1819. EXPORT_SYMBOL_GPL(nfsiod_workqueue);
  1820. /*
  1821. * start up the nfsiod workqueue
  1822. */
  1823. static int nfsiod_start(void)
  1824. {
  1825. struct workqueue_struct *wq;
  1826. dprintk("RPC: creating workqueue nfsiod\n");
  1827. wq = alloc_workqueue("nfsiod", WQ_MEM_RECLAIM, 0);
  1828. if (wq == NULL)
  1829. return -ENOMEM;
  1830. nfsiod_workqueue = wq;
  1831. return 0;
  1832. }
  1833. /*
  1834. * Destroy the nfsiod workqueue
  1835. */
  1836. static void nfsiod_stop(void)
  1837. {
  1838. struct workqueue_struct *wq;
  1839. wq = nfsiod_workqueue;
  1840. if (wq == NULL)
  1841. return;
  1842. nfsiod_workqueue = NULL;
  1843. destroy_workqueue(wq);
  1844. }
  1845. unsigned int nfs_net_id;
  1846. EXPORT_SYMBOL_GPL(nfs_net_id);
  1847. static int nfs_net_init(struct net *net)
  1848. {
  1849. nfs_clients_init(net);
  1850. return nfs_fs_proc_net_init(net);
  1851. }
  1852. static void nfs_net_exit(struct net *net)
  1853. {
  1854. struct nfs_net *nn = net_generic(net, nfs_net_id);
  1855. nfs_fs_proc_net_exit(net);
  1856. nfs_cleanup_cb_ident_idr(net);
  1857. WARN_ON_ONCE(!list_empty(&nn->nfs_client_list));
  1858. WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list));
  1859. }
  1860. static struct pernet_operations nfs_net_ops = {
  1861. .init = nfs_net_init,
  1862. .exit = nfs_net_exit,
  1863. .id = &nfs_net_id,
  1864. .size = sizeof(struct nfs_net),
  1865. };
  1866. /*
  1867. * Initialize NFS
  1868. */
  1869. static int __init init_nfs_fs(void)
  1870. {
  1871. int err;
  1872. err = register_pernet_subsys(&nfs_net_ops);
  1873. if (err < 0)
  1874. goto out9;
  1875. err = nfs_fscache_register();
  1876. if (err < 0)
  1877. goto out8;
  1878. err = nfsiod_start();
  1879. if (err)
  1880. goto out7;
  1881. err = nfs_fs_proc_init();
  1882. if (err)
  1883. goto out6;
  1884. err = nfs_init_nfspagecache();
  1885. if (err)
  1886. goto out5;
  1887. err = nfs_init_inodecache();
  1888. if (err)
  1889. goto out4;
  1890. err = nfs_init_readpagecache();
  1891. if (err)
  1892. goto out3;
  1893. err = nfs_init_writepagecache();
  1894. if (err)
  1895. goto out2;
  1896. err = nfs_init_directcache();
  1897. if (err)
  1898. goto out1;
  1899. rpc_proc_register(&init_net, &nfs_rpcstat);
  1900. err = register_nfs_fs();
  1901. if (err)
  1902. goto out0;
  1903. return 0;
  1904. out0:
  1905. rpc_proc_unregister(&init_net, "nfs");
  1906. nfs_destroy_directcache();
  1907. out1:
  1908. nfs_destroy_writepagecache();
  1909. out2:
  1910. nfs_destroy_readpagecache();
  1911. out3:
  1912. nfs_destroy_inodecache();
  1913. out4:
  1914. nfs_destroy_nfspagecache();
  1915. out5:
  1916. nfs_fs_proc_exit();
  1917. out6:
  1918. nfsiod_stop();
  1919. out7:
  1920. nfs_fscache_unregister();
  1921. out8:
  1922. unregister_pernet_subsys(&nfs_net_ops);
  1923. out9:
  1924. return err;
  1925. }
  1926. static void __exit exit_nfs_fs(void)
  1927. {
  1928. nfs_destroy_directcache();
  1929. nfs_destroy_writepagecache();
  1930. nfs_destroy_readpagecache();
  1931. nfs_destroy_inodecache();
  1932. nfs_destroy_nfspagecache();
  1933. nfs_fscache_unregister();
  1934. unregister_pernet_subsys(&nfs_net_ops);
  1935. rpc_proc_unregister(&init_net, "nfs");
  1936. unregister_nfs_fs();
  1937. nfs_fs_proc_exit();
  1938. nfsiod_stop();
  1939. }
  1940. /* Not quite true; I just maintain it */
  1941. MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
  1942. MODULE_LICENSE("GPL");
  1943. module_param(enable_ino64, bool, 0644);
  1944. module_init(init_nfs_fs)
  1945. module_exit(exit_nfs_fs)