inode.c 60 KB

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