super.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888
  1. /*
  2. * linux/fs/nfs/super.c
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * nfs 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. * Split from inode.c by David Howells <dhowells@redhat.com>
  15. *
  16. * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
  17. * particular server are held in the same superblock
  18. * - NFS superblocks can have several effective roots to the dentry tree
  19. * - directory type roots are spliced into the tree when a path from one root reaches the root
  20. * of another (see nfs_lookup())
  21. */
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/time.h>
  25. #include <linux/kernel.h>
  26. #include <linux/mm.h>
  27. #include <linux/string.h>
  28. #include <linux/stat.h>
  29. #include <linux/errno.h>
  30. #include <linux/unistd.h>
  31. #include <linux/sunrpc/clnt.h>
  32. #include <linux/sunrpc/addr.h>
  33. #include <linux/sunrpc/stats.h>
  34. #include <linux/sunrpc/metrics.h>
  35. #include <linux/sunrpc/xprtsock.h>
  36. #include <linux/sunrpc/xprtrdma.h>
  37. #include <linux/nfs_fs.h>
  38. #include <linux/nfs_mount.h>
  39. #include <linux/nfs4_mount.h>
  40. #include <linux/lockd/bind.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/mount.h>
  43. #include <linux/namei.h>
  44. #include <linux/nfs_idmap.h>
  45. #include <linux/vfs.h>
  46. #include <linux/inet.h>
  47. #include <linux/in6.h>
  48. #include <linux/slab.h>
  49. #include <net/ipv6.h>
  50. #include <linux/netdevice.h>
  51. #include <linux/nfs_xdr.h>
  52. #include <linux/magic.h>
  53. #include <linux/parser.h>
  54. #include <linux/nsproxy.h>
  55. #include <linux/rcupdate.h>
  56. #include <asm/uaccess.h>
  57. #include "nfs4_fs.h"
  58. #include "callback.h"
  59. #include "delegation.h"
  60. #include "iostat.h"
  61. #include "internal.h"
  62. #include "fscache.h"
  63. #include "nfs4session.h"
  64. #include "pnfs.h"
  65. #include "nfs.h"
  66. #define NFSDBG_FACILITY NFSDBG_VFS
  67. #define NFS_TEXT_DATA 1
  68. #if IS_ENABLED(CONFIG_NFS_V3)
  69. #define NFS_DEFAULT_VERSION 3
  70. #else
  71. #define NFS_DEFAULT_VERSION 2
  72. #endif
  73. enum {
  74. /* Mount options that take no arguments */
  75. Opt_soft, Opt_hard,
  76. Opt_posix, Opt_noposix,
  77. Opt_cto, Opt_nocto,
  78. Opt_ac, Opt_noac,
  79. Opt_lock, Opt_nolock,
  80. Opt_udp, Opt_tcp, Opt_rdma,
  81. Opt_acl, Opt_noacl,
  82. Opt_rdirplus, Opt_nordirplus,
  83. Opt_sharecache, Opt_nosharecache,
  84. Opt_resvport, Opt_noresvport,
  85. Opt_fscache, Opt_nofscache,
  86. Opt_migration, Opt_nomigration,
  87. /* Mount options that take integer arguments */
  88. Opt_port,
  89. Opt_rsize, Opt_wsize, Opt_bsize,
  90. Opt_timeo, Opt_retrans,
  91. Opt_acregmin, Opt_acregmax,
  92. Opt_acdirmin, Opt_acdirmax,
  93. Opt_actimeo,
  94. Opt_namelen,
  95. Opt_mountport,
  96. Opt_mountvers,
  97. Opt_minorversion,
  98. /* Mount options that take string arguments */
  99. Opt_nfsvers,
  100. Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
  101. Opt_addr, Opt_mountaddr, Opt_clientaddr,
  102. Opt_lookupcache,
  103. Opt_fscache_uniq,
  104. Opt_local_lock,
  105. /* Special mount options */
  106. Opt_userspace, Opt_deprecated, Opt_sloppy,
  107. Opt_err
  108. };
  109. static const match_table_t nfs_mount_option_tokens = {
  110. { Opt_userspace, "bg" },
  111. { Opt_userspace, "fg" },
  112. { Opt_userspace, "retry=%s" },
  113. { Opt_sloppy, "sloppy" },
  114. { Opt_soft, "soft" },
  115. { Opt_hard, "hard" },
  116. { Opt_deprecated, "intr" },
  117. { Opt_deprecated, "nointr" },
  118. { Opt_posix, "posix" },
  119. { Opt_noposix, "noposix" },
  120. { Opt_cto, "cto" },
  121. { Opt_nocto, "nocto" },
  122. { Opt_ac, "ac" },
  123. { Opt_noac, "noac" },
  124. { Opt_lock, "lock" },
  125. { Opt_nolock, "nolock" },
  126. { Opt_udp, "udp" },
  127. { Opt_tcp, "tcp" },
  128. { Opt_rdma, "rdma" },
  129. { Opt_acl, "acl" },
  130. { Opt_noacl, "noacl" },
  131. { Opt_rdirplus, "rdirplus" },
  132. { Opt_nordirplus, "nordirplus" },
  133. { Opt_sharecache, "sharecache" },
  134. { Opt_nosharecache, "nosharecache" },
  135. { Opt_resvport, "resvport" },
  136. { Opt_noresvport, "noresvport" },
  137. { Opt_fscache, "fsc" },
  138. { Opt_nofscache, "nofsc" },
  139. { Opt_migration, "migration" },
  140. { Opt_nomigration, "nomigration" },
  141. { Opt_port, "port=%s" },
  142. { Opt_rsize, "rsize=%s" },
  143. { Opt_wsize, "wsize=%s" },
  144. { Opt_bsize, "bsize=%s" },
  145. { Opt_timeo, "timeo=%s" },
  146. { Opt_retrans, "retrans=%s" },
  147. { Opt_acregmin, "acregmin=%s" },
  148. { Opt_acregmax, "acregmax=%s" },
  149. { Opt_acdirmin, "acdirmin=%s" },
  150. { Opt_acdirmax, "acdirmax=%s" },
  151. { Opt_actimeo, "actimeo=%s" },
  152. { Opt_namelen, "namlen=%s" },
  153. { Opt_mountport, "mountport=%s" },
  154. { Opt_mountvers, "mountvers=%s" },
  155. { Opt_minorversion, "minorversion=%s" },
  156. { Opt_nfsvers, "nfsvers=%s" },
  157. { Opt_nfsvers, "vers=%s" },
  158. { Opt_sec, "sec=%s" },
  159. { Opt_proto, "proto=%s" },
  160. { Opt_mountproto, "mountproto=%s" },
  161. { Opt_addr, "addr=%s" },
  162. { Opt_clientaddr, "clientaddr=%s" },
  163. { Opt_mounthost, "mounthost=%s" },
  164. { Opt_mountaddr, "mountaddr=%s" },
  165. { Opt_lookupcache, "lookupcache=%s" },
  166. { Opt_fscache_uniq, "fsc=%s" },
  167. { Opt_local_lock, "local_lock=%s" },
  168. /* The following needs to be listed after all other options */
  169. { Opt_nfsvers, "v%s" },
  170. { Opt_err, NULL }
  171. };
  172. enum {
  173. Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
  174. Opt_xprt_err
  175. };
  176. static const match_table_t nfs_xprt_protocol_tokens = {
  177. { Opt_xprt_udp, "udp" },
  178. { Opt_xprt_udp6, "udp6" },
  179. { Opt_xprt_tcp, "tcp" },
  180. { Opt_xprt_tcp6, "tcp6" },
  181. { Opt_xprt_rdma, "rdma" },
  182. { Opt_xprt_err, NULL }
  183. };
  184. enum {
  185. Opt_sec_none, Opt_sec_sys,
  186. Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
  187. Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
  188. Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
  189. Opt_sec_err
  190. };
  191. static const match_table_t nfs_secflavor_tokens = {
  192. { Opt_sec_none, "none" },
  193. { Opt_sec_none, "null" },
  194. { Opt_sec_sys, "sys" },
  195. { Opt_sec_krb5, "krb5" },
  196. { Opt_sec_krb5i, "krb5i" },
  197. { Opt_sec_krb5p, "krb5p" },
  198. { Opt_sec_lkey, "lkey" },
  199. { Opt_sec_lkeyi, "lkeyi" },
  200. { Opt_sec_lkeyp, "lkeyp" },
  201. { Opt_sec_spkm, "spkm3" },
  202. { Opt_sec_spkmi, "spkm3i" },
  203. { Opt_sec_spkmp, "spkm3p" },
  204. { Opt_sec_err, NULL }
  205. };
  206. enum {
  207. Opt_lookupcache_all, Opt_lookupcache_positive,
  208. Opt_lookupcache_none,
  209. Opt_lookupcache_err
  210. };
  211. static match_table_t nfs_lookupcache_tokens = {
  212. { Opt_lookupcache_all, "all" },
  213. { Opt_lookupcache_positive, "pos" },
  214. { Opt_lookupcache_positive, "positive" },
  215. { Opt_lookupcache_none, "none" },
  216. { Opt_lookupcache_err, NULL }
  217. };
  218. enum {
  219. Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
  220. Opt_local_lock_none,
  221. Opt_local_lock_err
  222. };
  223. static match_table_t nfs_local_lock_tokens = {
  224. { Opt_local_lock_all, "all" },
  225. { Opt_local_lock_flock, "flock" },
  226. { Opt_local_lock_posix, "posix" },
  227. { Opt_local_lock_none, "none" },
  228. { Opt_local_lock_err, NULL }
  229. };
  230. enum {
  231. Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
  232. Opt_vers_4_1, Opt_vers_4_2,
  233. Opt_vers_err
  234. };
  235. static match_table_t nfs_vers_tokens = {
  236. { Opt_vers_2, "2" },
  237. { Opt_vers_3, "3" },
  238. { Opt_vers_4, "4" },
  239. { Opt_vers_4_0, "4.0" },
  240. { Opt_vers_4_1, "4.1" },
  241. { Opt_vers_4_2, "4.2" },
  242. { Opt_vers_err, NULL }
  243. };
  244. static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
  245. int flags, const char *dev_name, void *raw_data);
  246. struct file_system_type nfs_fs_type = {
  247. .owner = THIS_MODULE,
  248. .name = "nfs",
  249. .mount = nfs_fs_mount,
  250. .kill_sb = nfs_kill_super,
  251. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
  252. };
  253. MODULE_ALIAS_FS("nfs");
  254. EXPORT_SYMBOL_GPL(nfs_fs_type);
  255. struct file_system_type nfs_xdev_fs_type = {
  256. .owner = THIS_MODULE,
  257. .name = "nfs",
  258. .mount = nfs_xdev_mount,
  259. .kill_sb = nfs_kill_super,
  260. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
  261. };
  262. const struct super_operations nfs_sops = {
  263. .alloc_inode = nfs_alloc_inode,
  264. .destroy_inode = nfs_destroy_inode,
  265. .write_inode = nfs_write_inode,
  266. .drop_inode = nfs_drop_inode,
  267. .put_super = nfs_put_super,
  268. .statfs = nfs_statfs,
  269. .evict_inode = nfs_evict_inode,
  270. .umount_begin = nfs_umount_begin,
  271. .show_options = nfs_show_options,
  272. .show_devname = nfs_show_devname,
  273. .show_path = nfs_show_path,
  274. .show_stats = nfs_show_stats,
  275. .remount_fs = nfs_remount,
  276. };
  277. EXPORT_SYMBOL_GPL(nfs_sops);
  278. #if IS_ENABLED(CONFIG_NFS_V4)
  279. static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
  280. static int nfs4_validate_mount_data(void *options,
  281. struct nfs_parsed_mount_data *args, const char *dev_name);
  282. struct file_system_type nfs4_fs_type = {
  283. .owner = THIS_MODULE,
  284. .name = "nfs4",
  285. .mount = nfs_fs_mount,
  286. .kill_sb = nfs_kill_super,
  287. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
  288. };
  289. MODULE_ALIAS_FS("nfs4");
  290. MODULE_ALIAS("nfs4");
  291. EXPORT_SYMBOL_GPL(nfs4_fs_type);
  292. static int __init register_nfs4_fs(void)
  293. {
  294. return register_filesystem(&nfs4_fs_type);
  295. }
  296. static void unregister_nfs4_fs(void)
  297. {
  298. unregister_filesystem(&nfs4_fs_type);
  299. }
  300. #else
  301. static int __init register_nfs4_fs(void)
  302. {
  303. return 0;
  304. }
  305. static void unregister_nfs4_fs(void)
  306. {
  307. }
  308. #endif
  309. static struct shrinker acl_shrinker = {
  310. .count_objects = nfs_access_cache_count,
  311. .scan_objects = nfs_access_cache_scan,
  312. .seeks = DEFAULT_SEEKS,
  313. };
  314. /*
  315. * Register the NFS filesystems
  316. */
  317. int __init register_nfs_fs(void)
  318. {
  319. int ret;
  320. ret = register_filesystem(&nfs_fs_type);
  321. if (ret < 0)
  322. goto error_0;
  323. ret = register_nfs4_fs();
  324. if (ret < 0)
  325. goto error_1;
  326. ret = nfs_register_sysctl();
  327. if (ret < 0)
  328. goto error_2;
  329. register_shrinker(&acl_shrinker);
  330. return 0;
  331. error_2:
  332. unregister_nfs4_fs();
  333. error_1:
  334. unregister_filesystem(&nfs_fs_type);
  335. error_0:
  336. return ret;
  337. }
  338. /*
  339. * Unregister the NFS filesystems
  340. */
  341. void __exit unregister_nfs_fs(void)
  342. {
  343. unregister_shrinker(&acl_shrinker);
  344. nfs_unregister_sysctl();
  345. unregister_nfs4_fs();
  346. unregister_filesystem(&nfs_fs_type);
  347. }
  348. void nfs_sb_active(struct super_block *sb)
  349. {
  350. struct nfs_server *server = NFS_SB(sb);
  351. if (atomic_inc_return(&server->active) == 1)
  352. atomic_inc(&sb->s_active);
  353. }
  354. EXPORT_SYMBOL_GPL(nfs_sb_active);
  355. void nfs_sb_deactive(struct super_block *sb)
  356. {
  357. struct nfs_server *server = NFS_SB(sb);
  358. if (atomic_dec_and_test(&server->active))
  359. deactivate_super(sb);
  360. }
  361. EXPORT_SYMBOL_GPL(nfs_sb_deactive);
  362. /*
  363. * Deliver file system statistics to userspace
  364. */
  365. int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  366. {
  367. struct nfs_server *server = NFS_SB(dentry->d_sb);
  368. unsigned char blockbits;
  369. unsigned long blockres;
  370. struct nfs_fh *fh = NFS_FH(dentry->d_inode);
  371. struct nfs_fsstat res;
  372. int error = -ENOMEM;
  373. res.fattr = nfs_alloc_fattr();
  374. if (res.fattr == NULL)
  375. goto out_err;
  376. error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
  377. if (unlikely(error == -ESTALE)) {
  378. struct dentry *pd_dentry;
  379. pd_dentry = dget_parent(dentry);
  380. if (pd_dentry != NULL) {
  381. nfs_zap_caches(pd_dentry->d_inode);
  382. dput(pd_dentry);
  383. }
  384. }
  385. nfs_free_fattr(res.fattr);
  386. if (error < 0)
  387. goto out_err;
  388. buf->f_type = NFS_SUPER_MAGIC;
  389. /*
  390. * Current versions of glibc do not correctly handle the
  391. * case where f_frsize != f_bsize. Eventually we want to
  392. * report the value of wtmult in this field.
  393. */
  394. buf->f_frsize = dentry->d_sb->s_blocksize;
  395. /*
  396. * On most *nix systems, f_blocks, f_bfree, and f_bavail
  397. * are reported in units of f_frsize. Linux hasn't had
  398. * an f_frsize field in its statfs struct until recently,
  399. * thus historically Linux's sys_statfs reports these
  400. * fields in units of f_bsize.
  401. */
  402. buf->f_bsize = dentry->d_sb->s_blocksize;
  403. blockbits = dentry->d_sb->s_blocksize_bits;
  404. blockres = (1 << blockbits) - 1;
  405. buf->f_blocks = (res.tbytes + blockres) >> blockbits;
  406. buf->f_bfree = (res.fbytes + blockres) >> blockbits;
  407. buf->f_bavail = (res.abytes + blockres) >> blockbits;
  408. buf->f_files = res.tfiles;
  409. buf->f_ffree = res.afiles;
  410. buf->f_namelen = server->namelen;
  411. return 0;
  412. out_err:
  413. dprintk("%s: statfs error = %d\n", __func__, -error);
  414. return error;
  415. }
  416. EXPORT_SYMBOL_GPL(nfs_statfs);
  417. /*
  418. * Map the security flavour number to a name
  419. */
  420. static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
  421. {
  422. static const struct {
  423. rpc_authflavor_t flavour;
  424. const char *str;
  425. } sec_flavours[NFS_AUTH_INFO_MAX_FLAVORS] = {
  426. /* update NFS_AUTH_INFO_MAX_FLAVORS when this list changes! */
  427. { RPC_AUTH_NULL, "null" },
  428. { RPC_AUTH_UNIX, "sys" },
  429. { RPC_AUTH_GSS_KRB5, "krb5" },
  430. { RPC_AUTH_GSS_KRB5I, "krb5i" },
  431. { RPC_AUTH_GSS_KRB5P, "krb5p" },
  432. { RPC_AUTH_GSS_LKEY, "lkey" },
  433. { RPC_AUTH_GSS_LKEYI, "lkeyi" },
  434. { RPC_AUTH_GSS_LKEYP, "lkeyp" },
  435. { RPC_AUTH_GSS_SPKM, "spkm" },
  436. { RPC_AUTH_GSS_SPKMI, "spkmi" },
  437. { RPC_AUTH_GSS_SPKMP, "spkmp" },
  438. { UINT_MAX, "unknown" }
  439. };
  440. int i;
  441. for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
  442. if (sec_flavours[i].flavour == flavour)
  443. break;
  444. }
  445. return sec_flavours[i].str;
  446. }
  447. static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
  448. int showdefaults)
  449. {
  450. struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
  451. seq_printf(m, ",mountproto=");
  452. switch (sap->sa_family) {
  453. case AF_INET:
  454. switch (nfss->mountd_protocol) {
  455. case IPPROTO_UDP:
  456. seq_printf(m, RPCBIND_NETID_UDP);
  457. break;
  458. case IPPROTO_TCP:
  459. seq_printf(m, RPCBIND_NETID_TCP);
  460. break;
  461. default:
  462. if (showdefaults)
  463. seq_printf(m, "auto");
  464. }
  465. break;
  466. case AF_INET6:
  467. switch (nfss->mountd_protocol) {
  468. case IPPROTO_UDP:
  469. seq_printf(m, RPCBIND_NETID_UDP6);
  470. break;
  471. case IPPROTO_TCP:
  472. seq_printf(m, RPCBIND_NETID_TCP6);
  473. break;
  474. default:
  475. if (showdefaults)
  476. seq_printf(m, "auto");
  477. }
  478. break;
  479. default:
  480. if (showdefaults)
  481. seq_printf(m, "auto");
  482. }
  483. }
  484. static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
  485. int showdefaults)
  486. {
  487. struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
  488. if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
  489. return;
  490. switch (sap->sa_family) {
  491. case AF_INET: {
  492. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  493. seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
  494. break;
  495. }
  496. case AF_INET6: {
  497. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  498. seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
  499. break;
  500. }
  501. default:
  502. if (showdefaults)
  503. seq_printf(m, ",mountaddr=unspecified");
  504. }
  505. if (nfss->mountd_version || showdefaults)
  506. seq_printf(m, ",mountvers=%u", nfss->mountd_version);
  507. if ((nfss->mountd_port &&
  508. nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
  509. showdefaults)
  510. seq_printf(m, ",mountport=%u", nfss->mountd_port);
  511. nfs_show_mountd_netid(m, nfss, showdefaults);
  512. }
  513. #if IS_ENABLED(CONFIG_NFS_V4)
  514. static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
  515. int showdefaults)
  516. {
  517. struct nfs_client *clp = nfss->nfs_client;
  518. seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
  519. }
  520. #else
  521. static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
  522. int showdefaults)
  523. {
  524. }
  525. #endif
  526. static void nfs_show_nfs_version(struct seq_file *m,
  527. unsigned int version,
  528. unsigned int minorversion)
  529. {
  530. seq_printf(m, ",vers=%u", version);
  531. if (version == 4)
  532. seq_printf(m, ".%u", minorversion);
  533. }
  534. /*
  535. * Describe the mount options in force on this server representation
  536. */
  537. static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
  538. int showdefaults)
  539. {
  540. static const struct proc_nfs_info {
  541. int flag;
  542. const char *str;
  543. const char *nostr;
  544. } nfs_info[] = {
  545. { NFS_MOUNT_SOFT, ",soft", ",hard" },
  546. { NFS_MOUNT_POSIX, ",posix", "" },
  547. { NFS_MOUNT_NOCTO, ",nocto", "" },
  548. { NFS_MOUNT_NOAC, ",noac", "" },
  549. { NFS_MOUNT_NONLM, ",nolock", "" },
  550. { NFS_MOUNT_NOACL, ",noacl", "" },
  551. { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
  552. { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
  553. { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
  554. { 0, NULL, NULL }
  555. };
  556. const struct proc_nfs_info *nfs_infop;
  557. struct nfs_client *clp = nfss->nfs_client;
  558. u32 version = clp->rpc_ops->version;
  559. int local_flock, local_fcntl;
  560. nfs_show_nfs_version(m, version, clp->cl_minorversion);
  561. seq_printf(m, ",rsize=%u", nfss->rsize);
  562. seq_printf(m, ",wsize=%u", nfss->wsize);
  563. if (nfss->bsize != 0)
  564. seq_printf(m, ",bsize=%u", nfss->bsize);
  565. seq_printf(m, ",namlen=%u", nfss->namelen);
  566. if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
  567. seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
  568. if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
  569. seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
  570. if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
  571. seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
  572. if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
  573. seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
  574. for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
  575. if (nfss->flags & nfs_infop->flag)
  576. seq_puts(m, nfs_infop->str);
  577. else
  578. seq_puts(m, nfs_infop->nostr);
  579. }
  580. rcu_read_lock();
  581. seq_printf(m, ",proto=%s",
  582. rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
  583. rcu_read_unlock();
  584. if (version == 4) {
  585. if (nfss->port != NFS_PORT)
  586. seq_printf(m, ",port=%u", nfss->port);
  587. } else
  588. if (nfss->port)
  589. seq_printf(m, ",port=%u", nfss->port);
  590. seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
  591. seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
  592. seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
  593. if (version != 4)
  594. nfs_show_mountd_options(m, nfss, showdefaults);
  595. else
  596. nfs_show_nfsv4_options(m, nfss, showdefaults);
  597. if (nfss->options & NFS_OPTION_FSCACHE)
  598. seq_printf(m, ",fsc");
  599. if (nfss->options & NFS_OPTION_MIGRATION)
  600. seq_printf(m, ",migration");
  601. if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
  602. if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
  603. seq_printf(m, ",lookupcache=none");
  604. else
  605. seq_printf(m, ",lookupcache=pos");
  606. }
  607. local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
  608. local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
  609. if (!local_flock && !local_fcntl)
  610. seq_printf(m, ",local_lock=none");
  611. else if (local_flock && local_fcntl)
  612. seq_printf(m, ",local_lock=all");
  613. else if (local_flock)
  614. seq_printf(m, ",local_lock=flock");
  615. else
  616. seq_printf(m, ",local_lock=posix");
  617. }
  618. /*
  619. * Describe the mount options on this VFS mountpoint
  620. */
  621. int nfs_show_options(struct seq_file *m, struct dentry *root)
  622. {
  623. struct nfs_server *nfss = NFS_SB(root->d_sb);
  624. nfs_show_mount_options(m, nfss, 0);
  625. rcu_read_lock();
  626. seq_printf(m, ",addr=%s",
  627. rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
  628. RPC_DISPLAY_ADDR));
  629. rcu_read_unlock();
  630. return 0;
  631. }
  632. EXPORT_SYMBOL_GPL(nfs_show_options);
  633. #if IS_ENABLED(CONFIG_NFS_V4)
  634. #ifdef CONFIG_NFS_V4_1
  635. static void show_sessions(struct seq_file *m, struct nfs_server *server)
  636. {
  637. if (nfs4_has_session(server->nfs_client))
  638. seq_printf(m, ",sessions");
  639. }
  640. #else
  641. static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
  642. #endif
  643. #endif
  644. #ifdef CONFIG_NFS_V4_1
  645. static void show_pnfs(struct seq_file *m, struct nfs_server *server)
  646. {
  647. seq_printf(m, ",pnfs=");
  648. if (server->pnfs_curr_ld)
  649. seq_printf(m, "%s", server->pnfs_curr_ld->name);
  650. else
  651. seq_printf(m, "not configured");
  652. }
  653. static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
  654. {
  655. if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
  656. struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
  657. seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
  658. "date='%llu,%u'",
  659. impl_id->name, impl_id->domain,
  660. impl_id->date.seconds, impl_id->date.nseconds);
  661. }
  662. }
  663. #else
  664. #if IS_ENABLED(CONFIG_NFS_V4)
  665. static void show_pnfs(struct seq_file *m, struct nfs_server *server)
  666. {
  667. }
  668. #endif
  669. static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
  670. {
  671. }
  672. #endif
  673. int nfs_show_devname(struct seq_file *m, struct dentry *root)
  674. {
  675. char *page = (char *) __get_free_page(GFP_KERNEL);
  676. char *devname, *dummy;
  677. int err = 0;
  678. if (!page)
  679. return -ENOMEM;
  680. devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
  681. if (IS_ERR(devname))
  682. err = PTR_ERR(devname);
  683. else
  684. seq_escape(m, devname, " \t\n\\");
  685. free_page((unsigned long)page);
  686. return err;
  687. }
  688. EXPORT_SYMBOL_GPL(nfs_show_devname);
  689. int nfs_show_path(struct seq_file *m, struct dentry *dentry)
  690. {
  691. seq_puts(m, "/");
  692. return 0;
  693. }
  694. EXPORT_SYMBOL_GPL(nfs_show_path);
  695. /*
  696. * Present statistical information for this VFS mountpoint
  697. */
  698. int nfs_show_stats(struct seq_file *m, struct dentry *root)
  699. {
  700. int i, cpu;
  701. struct nfs_server *nfss = NFS_SB(root->d_sb);
  702. struct rpc_auth *auth = nfss->client->cl_auth;
  703. struct nfs_iostats totals = { };
  704. seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
  705. /*
  706. * Display all mount option settings
  707. */
  708. seq_printf(m, "\n\topts:\t");
  709. seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
  710. seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
  711. seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
  712. seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
  713. nfs_show_mount_options(m, nfss, 1);
  714. seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
  715. show_implementation_id(m, nfss);
  716. seq_printf(m, "\n\tcaps:\t");
  717. seq_printf(m, "caps=0x%x", nfss->caps);
  718. seq_printf(m, ",wtmult=%u", nfss->wtmult);
  719. seq_printf(m, ",dtsize=%u", nfss->dtsize);
  720. seq_printf(m, ",bsize=%u", nfss->bsize);
  721. seq_printf(m, ",namlen=%u", nfss->namelen);
  722. #if IS_ENABLED(CONFIG_NFS_V4)
  723. if (nfss->nfs_client->rpc_ops->version == 4) {
  724. seq_printf(m, "\n\tnfsv4:\t");
  725. seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
  726. seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
  727. seq_printf(m, ",bm2=0x%x", nfss->attr_bitmask[2]);
  728. seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
  729. show_sessions(m, nfss);
  730. show_pnfs(m, nfss);
  731. }
  732. #endif
  733. /*
  734. * Display security flavor in effect for this mount
  735. */
  736. seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
  737. if (auth->au_flavor)
  738. seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
  739. /*
  740. * Display superblock I/O counters
  741. */
  742. for_each_possible_cpu(cpu) {
  743. struct nfs_iostats *stats;
  744. preempt_disable();
  745. stats = per_cpu_ptr(nfss->io_stats, cpu);
  746. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  747. totals.events[i] += stats->events[i];
  748. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  749. totals.bytes[i] += stats->bytes[i];
  750. #ifdef CONFIG_NFS_FSCACHE
  751. for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
  752. totals.fscache[i] += stats->fscache[i];
  753. #endif
  754. preempt_enable();
  755. }
  756. seq_printf(m, "\n\tevents:\t");
  757. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  758. seq_printf(m, "%lu ", totals.events[i]);
  759. seq_printf(m, "\n\tbytes:\t");
  760. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  761. seq_printf(m, "%Lu ", totals.bytes[i]);
  762. #ifdef CONFIG_NFS_FSCACHE
  763. if (nfss->options & NFS_OPTION_FSCACHE) {
  764. seq_printf(m, "\n\tfsc:\t");
  765. for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
  766. seq_printf(m, "%Lu ", totals.bytes[i]);
  767. }
  768. #endif
  769. seq_printf(m, "\n");
  770. rpc_print_iostats(m, nfss->client);
  771. return 0;
  772. }
  773. EXPORT_SYMBOL_GPL(nfs_show_stats);
  774. /*
  775. * Begin unmount by attempting to remove all automounted mountpoints we added
  776. * in response to xdev traversals and referrals
  777. */
  778. void nfs_umount_begin(struct super_block *sb)
  779. {
  780. struct nfs_server *server;
  781. struct rpc_clnt *rpc;
  782. server = NFS_SB(sb);
  783. /* -EIO all pending I/O */
  784. rpc = server->client_acl;
  785. if (!IS_ERR(rpc))
  786. rpc_killall_tasks(rpc);
  787. rpc = server->client;
  788. if (!IS_ERR(rpc))
  789. rpc_killall_tasks(rpc);
  790. }
  791. EXPORT_SYMBOL_GPL(nfs_umount_begin);
  792. static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
  793. {
  794. struct nfs_parsed_mount_data *data;
  795. data = kzalloc(sizeof(*data), GFP_KERNEL);
  796. if (data) {
  797. data->acregmin = NFS_DEF_ACREGMIN;
  798. data->acregmax = NFS_DEF_ACREGMAX;
  799. data->acdirmin = NFS_DEF_ACDIRMIN;
  800. data->acdirmax = NFS_DEF_ACDIRMAX;
  801. data->mount_server.port = NFS_UNSPEC_PORT;
  802. data->nfs_server.port = NFS_UNSPEC_PORT;
  803. data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  804. data->selected_flavor = RPC_AUTH_MAXFLAVOR;
  805. data->minorversion = 0;
  806. data->need_mount = true;
  807. data->net = current->nsproxy->net_ns;
  808. security_init_mnt_opts(&data->lsm_opts);
  809. }
  810. return data;
  811. }
  812. static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
  813. {
  814. if (data) {
  815. kfree(data->client_address);
  816. kfree(data->mount_server.hostname);
  817. kfree(data->nfs_server.export_path);
  818. kfree(data->nfs_server.hostname);
  819. kfree(data->fscache_uniq);
  820. security_free_mnt_opts(&data->lsm_opts);
  821. kfree(data);
  822. }
  823. }
  824. /*
  825. * Sanity-check a server address provided by the mount command.
  826. *
  827. * Address family must be initialized, and address must not be
  828. * the ANY address for that family.
  829. */
  830. static int nfs_verify_server_address(struct sockaddr *addr)
  831. {
  832. switch (addr->sa_family) {
  833. case AF_INET: {
  834. struct sockaddr_in *sa = (struct sockaddr_in *)addr;
  835. return sa->sin_addr.s_addr != htonl(INADDR_ANY);
  836. }
  837. case AF_INET6: {
  838. struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
  839. return !ipv6_addr_any(sa);
  840. }
  841. }
  842. dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
  843. return 0;
  844. }
  845. /*
  846. * Select between a default port value and a user-specified port value.
  847. * If a zero value is set, then autobind will be used.
  848. */
  849. static void nfs_set_port(struct sockaddr *sap, int *port,
  850. const unsigned short default_port)
  851. {
  852. if (*port == NFS_UNSPEC_PORT)
  853. *port = default_port;
  854. rpc_set_port(sap, *port);
  855. }
  856. /*
  857. * Sanity check the NFS transport protocol.
  858. *
  859. */
  860. static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
  861. {
  862. switch (mnt->nfs_server.protocol) {
  863. case XPRT_TRANSPORT_UDP:
  864. case XPRT_TRANSPORT_TCP:
  865. case XPRT_TRANSPORT_RDMA:
  866. break;
  867. default:
  868. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  869. }
  870. }
  871. /*
  872. * For text based NFSv2/v3 mounts, the mount protocol transport default
  873. * settings should depend upon the specified NFS transport.
  874. */
  875. static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
  876. {
  877. nfs_validate_transport_protocol(mnt);
  878. if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
  879. mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
  880. return;
  881. switch (mnt->nfs_server.protocol) {
  882. case XPRT_TRANSPORT_UDP:
  883. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  884. break;
  885. case XPRT_TRANSPORT_TCP:
  886. case XPRT_TRANSPORT_RDMA:
  887. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  888. }
  889. }
  890. /*
  891. * Add 'flavor' to 'auth_info' if not already present.
  892. * Returns true if 'flavor' ends up in the list, false otherwise
  893. */
  894. static bool nfs_auth_info_add(struct nfs_auth_info *auth_info,
  895. rpc_authflavor_t flavor)
  896. {
  897. unsigned int i;
  898. unsigned int max_flavor_len = ARRAY_SIZE(auth_info->flavors);
  899. /* make sure this flavor isn't already in the list */
  900. for (i = 0; i < auth_info->flavor_len; i++) {
  901. if (flavor == auth_info->flavors[i])
  902. return true;
  903. }
  904. if (auth_info->flavor_len + 1 >= max_flavor_len) {
  905. dfprintk(MOUNT, "NFS: too many sec= flavors\n");
  906. return false;
  907. }
  908. auth_info->flavors[auth_info->flavor_len++] = flavor;
  909. return true;
  910. }
  911. /*
  912. * Return true if 'match' is in auth_info or auth_info is empty.
  913. * Return false otherwise.
  914. */
  915. bool nfs_auth_info_match(const struct nfs_auth_info *auth_info,
  916. rpc_authflavor_t match)
  917. {
  918. int i;
  919. if (!auth_info->flavor_len)
  920. return true;
  921. for (i = 0; i < auth_info->flavor_len; i++) {
  922. if (auth_info->flavors[i] == match)
  923. return true;
  924. }
  925. return false;
  926. }
  927. EXPORT_SYMBOL_GPL(nfs_auth_info_match);
  928. /*
  929. * Parse the value of the 'sec=' option.
  930. */
  931. static int nfs_parse_security_flavors(char *value,
  932. struct nfs_parsed_mount_data *mnt)
  933. {
  934. substring_t args[MAX_OPT_ARGS];
  935. rpc_authflavor_t pseudoflavor;
  936. char *p;
  937. dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
  938. while ((p = strsep(&value, ":")) != NULL) {
  939. switch (match_token(p, nfs_secflavor_tokens, args)) {
  940. case Opt_sec_none:
  941. pseudoflavor = RPC_AUTH_NULL;
  942. break;
  943. case Opt_sec_sys:
  944. pseudoflavor = RPC_AUTH_UNIX;
  945. break;
  946. case Opt_sec_krb5:
  947. pseudoflavor = RPC_AUTH_GSS_KRB5;
  948. break;
  949. case Opt_sec_krb5i:
  950. pseudoflavor = RPC_AUTH_GSS_KRB5I;
  951. break;
  952. case Opt_sec_krb5p:
  953. pseudoflavor = RPC_AUTH_GSS_KRB5P;
  954. break;
  955. case Opt_sec_lkey:
  956. pseudoflavor = RPC_AUTH_GSS_LKEY;
  957. break;
  958. case Opt_sec_lkeyi:
  959. pseudoflavor = RPC_AUTH_GSS_LKEYI;
  960. break;
  961. case Opt_sec_lkeyp:
  962. pseudoflavor = RPC_AUTH_GSS_LKEYP;
  963. break;
  964. case Opt_sec_spkm:
  965. pseudoflavor = RPC_AUTH_GSS_SPKM;
  966. break;
  967. case Opt_sec_spkmi:
  968. pseudoflavor = RPC_AUTH_GSS_SPKMI;
  969. break;
  970. case Opt_sec_spkmp:
  971. pseudoflavor = RPC_AUTH_GSS_SPKMP;
  972. break;
  973. default:
  974. dfprintk(MOUNT,
  975. "NFS: sec= option '%s' not recognized\n", p);
  976. return 0;
  977. }
  978. if (!nfs_auth_info_add(&mnt->auth_info, pseudoflavor))
  979. return 0;
  980. }
  981. return 1;
  982. }
  983. static int nfs_parse_version_string(char *string,
  984. struct nfs_parsed_mount_data *mnt,
  985. substring_t *args)
  986. {
  987. mnt->flags &= ~NFS_MOUNT_VER3;
  988. switch (match_token(string, nfs_vers_tokens, args)) {
  989. case Opt_vers_2:
  990. mnt->version = 2;
  991. break;
  992. case Opt_vers_3:
  993. mnt->flags |= NFS_MOUNT_VER3;
  994. mnt->version = 3;
  995. break;
  996. case Opt_vers_4:
  997. /* Backward compatibility option. In future,
  998. * the mount program should always supply
  999. * a NFSv4 minor version number.
  1000. */
  1001. mnt->version = 4;
  1002. break;
  1003. case Opt_vers_4_0:
  1004. mnt->version = 4;
  1005. mnt->minorversion = 0;
  1006. break;
  1007. case Opt_vers_4_1:
  1008. mnt->version = 4;
  1009. mnt->minorversion = 1;
  1010. break;
  1011. case Opt_vers_4_2:
  1012. mnt->version = 4;
  1013. mnt->minorversion = 2;
  1014. break;
  1015. default:
  1016. return 0;
  1017. }
  1018. return 1;
  1019. }
  1020. static int nfs_get_option_str(substring_t args[], char **option)
  1021. {
  1022. kfree(*option);
  1023. *option = match_strdup(args);
  1024. return !*option;
  1025. }
  1026. static int nfs_get_option_ul(substring_t args[], unsigned long *option)
  1027. {
  1028. int rc;
  1029. char *string;
  1030. string = match_strdup(args);
  1031. if (string == NULL)
  1032. return -ENOMEM;
  1033. rc = kstrtoul(string, 10, option);
  1034. kfree(string);
  1035. return rc;
  1036. }
  1037. /*
  1038. * Error-check and convert a string of mount options from user space into
  1039. * a data structure. The whole mount string is processed; bad options are
  1040. * skipped as they are encountered. If there were no errors, return 1;
  1041. * otherwise return 0 (zero).
  1042. */
  1043. static int nfs_parse_mount_options(char *raw,
  1044. struct nfs_parsed_mount_data *mnt)
  1045. {
  1046. char *p, *string, *secdata;
  1047. int rc, sloppy = 0, invalid_option = 0;
  1048. unsigned short protofamily = AF_UNSPEC;
  1049. unsigned short mountfamily = AF_UNSPEC;
  1050. if (!raw) {
  1051. dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
  1052. return 1;
  1053. }
  1054. dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
  1055. secdata = alloc_secdata();
  1056. if (!secdata)
  1057. goto out_nomem;
  1058. rc = security_sb_copy_data(raw, secdata);
  1059. if (rc)
  1060. goto out_security_failure;
  1061. rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
  1062. if (rc)
  1063. goto out_security_failure;
  1064. free_secdata(secdata);
  1065. while ((p = strsep(&raw, ",")) != NULL) {
  1066. substring_t args[MAX_OPT_ARGS];
  1067. unsigned long option;
  1068. int token;
  1069. if (!*p)
  1070. continue;
  1071. dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
  1072. token = match_token(p, nfs_mount_option_tokens, args);
  1073. switch (token) {
  1074. /*
  1075. * boolean options: foo/nofoo
  1076. */
  1077. case Opt_soft:
  1078. mnt->flags |= NFS_MOUNT_SOFT;
  1079. break;
  1080. case Opt_hard:
  1081. mnt->flags &= ~NFS_MOUNT_SOFT;
  1082. break;
  1083. case Opt_posix:
  1084. mnt->flags |= NFS_MOUNT_POSIX;
  1085. break;
  1086. case Opt_noposix:
  1087. mnt->flags &= ~NFS_MOUNT_POSIX;
  1088. break;
  1089. case Opt_cto:
  1090. mnt->flags &= ~NFS_MOUNT_NOCTO;
  1091. break;
  1092. case Opt_nocto:
  1093. mnt->flags |= NFS_MOUNT_NOCTO;
  1094. break;
  1095. case Opt_ac:
  1096. mnt->flags &= ~NFS_MOUNT_NOAC;
  1097. break;
  1098. case Opt_noac:
  1099. mnt->flags |= NFS_MOUNT_NOAC;
  1100. break;
  1101. case Opt_lock:
  1102. mnt->flags &= ~NFS_MOUNT_NONLM;
  1103. mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
  1104. NFS_MOUNT_LOCAL_FCNTL);
  1105. break;
  1106. case Opt_nolock:
  1107. mnt->flags |= NFS_MOUNT_NONLM;
  1108. mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
  1109. NFS_MOUNT_LOCAL_FCNTL);
  1110. break;
  1111. case Opt_udp:
  1112. mnt->flags &= ~NFS_MOUNT_TCP;
  1113. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1114. break;
  1115. case Opt_tcp:
  1116. mnt->flags |= NFS_MOUNT_TCP;
  1117. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1118. break;
  1119. case Opt_rdma:
  1120. mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
  1121. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1122. xprt_load_transport(p);
  1123. break;
  1124. case Opt_acl:
  1125. mnt->flags &= ~NFS_MOUNT_NOACL;
  1126. break;
  1127. case Opt_noacl:
  1128. mnt->flags |= NFS_MOUNT_NOACL;
  1129. break;
  1130. case Opt_rdirplus:
  1131. mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
  1132. break;
  1133. case Opt_nordirplus:
  1134. mnt->flags |= NFS_MOUNT_NORDIRPLUS;
  1135. break;
  1136. case Opt_sharecache:
  1137. mnt->flags &= ~NFS_MOUNT_UNSHARED;
  1138. break;
  1139. case Opt_nosharecache:
  1140. mnt->flags |= NFS_MOUNT_UNSHARED;
  1141. break;
  1142. case Opt_resvport:
  1143. mnt->flags &= ~NFS_MOUNT_NORESVPORT;
  1144. break;
  1145. case Opt_noresvport:
  1146. mnt->flags |= NFS_MOUNT_NORESVPORT;
  1147. break;
  1148. case Opt_fscache:
  1149. mnt->options |= NFS_OPTION_FSCACHE;
  1150. kfree(mnt->fscache_uniq);
  1151. mnt->fscache_uniq = NULL;
  1152. break;
  1153. case Opt_nofscache:
  1154. mnt->options &= ~NFS_OPTION_FSCACHE;
  1155. kfree(mnt->fscache_uniq);
  1156. mnt->fscache_uniq = NULL;
  1157. break;
  1158. case Opt_migration:
  1159. mnt->options |= NFS_OPTION_MIGRATION;
  1160. break;
  1161. case Opt_nomigration:
  1162. mnt->options &= NFS_OPTION_MIGRATION;
  1163. break;
  1164. /*
  1165. * options that take numeric values
  1166. */
  1167. case Opt_port:
  1168. if (nfs_get_option_ul(args, &option) ||
  1169. option > USHRT_MAX)
  1170. goto out_invalid_value;
  1171. mnt->nfs_server.port = option;
  1172. break;
  1173. case Opt_rsize:
  1174. if (nfs_get_option_ul(args, &option))
  1175. goto out_invalid_value;
  1176. mnt->rsize = option;
  1177. break;
  1178. case Opt_wsize:
  1179. if (nfs_get_option_ul(args, &option))
  1180. goto out_invalid_value;
  1181. mnt->wsize = option;
  1182. break;
  1183. case Opt_bsize:
  1184. if (nfs_get_option_ul(args, &option))
  1185. goto out_invalid_value;
  1186. mnt->bsize = option;
  1187. break;
  1188. case Opt_timeo:
  1189. if (nfs_get_option_ul(args, &option) || option == 0)
  1190. goto out_invalid_value;
  1191. mnt->timeo = option;
  1192. break;
  1193. case Opt_retrans:
  1194. if (nfs_get_option_ul(args, &option) || option == 0)
  1195. goto out_invalid_value;
  1196. mnt->retrans = option;
  1197. break;
  1198. case Opt_acregmin:
  1199. if (nfs_get_option_ul(args, &option))
  1200. goto out_invalid_value;
  1201. mnt->acregmin = option;
  1202. break;
  1203. case Opt_acregmax:
  1204. if (nfs_get_option_ul(args, &option))
  1205. goto out_invalid_value;
  1206. mnt->acregmax = option;
  1207. break;
  1208. case Opt_acdirmin:
  1209. if (nfs_get_option_ul(args, &option))
  1210. goto out_invalid_value;
  1211. mnt->acdirmin = option;
  1212. break;
  1213. case Opt_acdirmax:
  1214. if (nfs_get_option_ul(args, &option))
  1215. goto out_invalid_value;
  1216. mnt->acdirmax = option;
  1217. break;
  1218. case Opt_actimeo:
  1219. if (nfs_get_option_ul(args, &option))
  1220. goto out_invalid_value;
  1221. mnt->acregmin = mnt->acregmax =
  1222. mnt->acdirmin = mnt->acdirmax = option;
  1223. break;
  1224. case Opt_namelen:
  1225. if (nfs_get_option_ul(args, &option))
  1226. goto out_invalid_value;
  1227. mnt->namlen = option;
  1228. break;
  1229. case Opt_mountport:
  1230. if (nfs_get_option_ul(args, &option) ||
  1231. option > USHRT_MAX)
  1232. goto out_invalid_value;
  1233. mnt->mount_server.port = option;
  1234. break;
  1235. case Opt_mountvers:
  1236. if (nfs_get_option_ul(args, &option) ||
  1237. option < NFS_MNT_VERSION ||
  1238. option > NFS_MNT3_VERSION)
  1239. goto out_invalid_value;
  1240. mnt->mount_server.version = option;
  1241. break;
  1242. case Opt_minorversion:
  1243. if (nfs_get_option_ul(args, &option))
  1244. goto out_invalid_value;
  1245. if (option > NFS4_MAX_MINOR_VERSION)
  1246. goto out_invalid_value;
  1247. mnt->minorversion = option;
  1248. break;
  1249. /*
  1250. * options that take text values
  1251. */
  1252. case Opt_nfsvers:
  1253. string = match_strdup(args);
  1254. if (string == NULL)
  1255. goto out_nomem;
  1256. rc = nfs_parse_version_string(string, mnt, args);
  1257. kfree(string);
  1258. if (!rc)
  1259. goto out_invalid_value;
  1260. break;
  1261. case Opt_sec:
  1262. string = match_strdup(args);
  1263. if (string == NULL)
  1264. goto out_nomem;
  1265. rc = nfs_parse_security_flavors(string, mnt);
  1266. kfree(string);
  1267. if (!rc) {
  1268. dfprintk(MOUNT, "NFS: unrecognized "
  1269. "security flavor\n");
  1270. return 0;
  1271. }
  1272. break;
  1273. case Opt_proto:
  1274. string = match_strdup(args);
  1275. if (string == NULL)
  1276. goto out_nomem;
  1277. token = match_token(string,
  1278. nfs_xprt_protocol_tokens, args);
  1279. protofamily = AF_INET;
  1280. switch (token) {
  1281. case Opt_xprt_udp6:
  1282. protofamily = AF_INET6;
  1283. case Opt_xprt_udp:
  1284. mnt->flags &= ~NFS_MOUNT_TCP;
  1285. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1286. break;
  1287. case Opt_xprt_tcp6:
  1288. protofamily = AF_INET6;
  1289. case Opt_xprt_tcp:
  1290. mnt->flags |= NFS_MOUNT_TCP;
  1291. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1292. break;
  1293. case Opt_xprt_rdma:
  1294. /* vector side protocols to TCP */
  1295. mnt->flags |= NFS_MOUNT_TCP;
  1296. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1297. xprt_load_transport(string);
  1298. break;
  1299. default:
  1300. dfprintk(MOUNT, "NFS: unrecognized "
  1301. "transport protocol\n");
  1302. kfree(string);
  1303. return 0;
  1304. }
  1305. kfree(string);
  1306. break;
  1307. case Opt_mountproto:
  1308. string = match_strdup(args);
  1309. if (string == NULL)
  1310. goto out_nomem;
  1311. token = match_token(string,
  1312. nfs_xprt_protocol_tokens, args);
  1313. kfree(string);
  1314. mountfamily = AF_INET;
  1315. switch (token) {
  1316. case Opt_xprt_udp6:
  1317. mountfamily = AF_INET6;
  1318. case Opt_xprt_udp:
  1319. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  1320. break;
  1321. case Opt_xprt_tcp6:
  1322. mountfamily = AF_INET6;
  1323. case Opt_xprt_tcp:
  1324. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  1325. break;
  1326. case Opt_xprt_rdma: /* not used for side protocols */
  1327. default:
  1328. dfprintk(MOUNT, "NFS: unrecognized "
  1329. "transport protocol\n");
  1330. return 0;
  1331. }
  1332. break;
  1333. case Opt_addr:
  1334. string = match_strdup(args);
  1335. if (string == NULL)
  1336. goto out_nomem;
  1337. mnt->nfs_server.addrlen =
  1338. rpc_pton(mnt->net, string, strlen(string),
  1339. (struct sockaddr *)
  1340. &mnt->nfs_server.address,
  1341. sizeof(mnt->nfs_server.address));
  1342. kfree(string);
  1343. if (mnt->nfs_server.addrlen == 0)
  1344. goto out_invalid_address;
  1345. break;
  1346. case Opt_clientaddr:
  1347. if (nfs_get_option_str(args, &mnt->client_address))
  1348. goto out_nomem;
  1349. break;
  1350. case Opt_mounthost:
  1351. if (nfs_get_option_str(args,
  1352. &mnt->mount_server.hostname))
  1353. goto out_nomem;
  1354. break;
  1355. case Opt_mountaddr:
  1356. string = match_strdup(args);
  1357. if (string == NULL)
  1358. goto out_nomem;
  1359. mnt->mount_server.addrlen =
  1360. rpc_pton(mnt->net, string, strlen(string),
  1361. (struct sockaddr *)
  1362. &mnt->mount_server.address,
  1363. sizeof(mnt->mount_server.address));
  1364. kfree(string);
  1365. if (mnt->mount_server.addrlen == 0)
  1366. goto out_invalid_address;
  1367. break;
  1368. case Opt_lookupcache:
  1369. string = match_strdup(args);
  1370. if (string == NULL)
  1371. goto out_nomem;
  1372. token = match_token(string,
  1373. nfs_lookupcache_tokens, args);
  1374. kfree(string);
  1375. switch (token) {
  1376. case Opt_lookupcache_all:
  1377. mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
  1378. break;
  1379. case Opt_lookupcache_positive:
  1380. mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
  1381. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
  1382. break;
  1383. case Opt_lookupcache_none:
  1384. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
  1385. break;
  1386. default:
  1387. dfprintk(MOUNT, "NFS: invalid "
  1388. "lookupcache argument\n");
  1389. return 0;
  1390. };
  1391. break;
  1392. case Opt_fscache_uniq:
  1393. if (nfs_get_option_str(args, &mnt->fscache_uniq))
  1394. goto out_nomem;
  1395. mnt->options |= NFS_OPTION_FSCACHE;
  1396. break;
  1397. case Opt_local_lock:
  1398. string = match_strdup(args);
  1399. if (string == NULL)
  1400. goto out_nomem;
  1401. token = match_token(string, nfs_local_lock_tokens,
  1402. args);
  1403. kfree(string);
  1404. switch (token) {
  1405. case Opt_local_lock_all:
  1406. mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
  1407. NFS_MOUNT_LOCAL_FCNTL);
  1408. break;
  1409. case Opt_local_lock_flock:
  1410. mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
  1411. break;
  1412. case Opt_local_lock_posix:
  1413. mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
  1414. break;
  1415. case Opt_local_lock_none:
  1416. mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
  1417. NFS_MOUNT_LOCAL_FCNTL);
  1418. break;
  1419. default:
  1420. dfprintk(MOUNT, "NFS: invalid "
  1421. "local_lock argument\n");
  1422. return 0;
  1423. };
  1424. break;
  1425. /*
  1426. * Special options
  1427. */
  1428. case Opt_sloppy:
  1429. sloppy = 1;
  1430. dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
  1431. break;
  1432. case Opt_userspace:
  1433. case Opt_deprecated:
  1434. dfprintk(MOUNT, "NFS: ignoring mount option "
  1435. "'%s'\n", p);
  1436. break;
  1437. default:
  1438. invalid_option = 1;
  1439. dfprintk(MOUNT, "NFS: unrecognized mount option "
  1440. "'%s'\n", p);
  1441. }
  1442. }
  1443. if (!sloppy && invalid_option)
  1444. return 0;
  1445. if (mnt->minorversion && mnt->version != 4)
  1446. goto out_minorversion_mismatch;
  1447. if (mnt->options & NFS_OPTION_MIGRATION &&
  1448. (mnt->version != 4 || mnt->minorversion != 0))
  1449. goto out_migration_misuse;
  1450. /*
  1451. * verify that any proto=/mountproto= options match the address
  1452. * families in the addr=/mountaddr= options.
  1453. */
  1454. if (protofamily != AF_UNSPEC &&
  1455. protofamily != mnt->nfs_server.address.ss_family)
  1456. goto out_proto_mismatch;
  1457. if (mountfamily != AF_UNSPEC) {
  1458. if (mnt->mount_server.addrlen) {
  1459. if (mountfamily != mnt->mount_server.address.ss_family)
  1460. goto out_mountproto_mismatch;
  1461. } else {
  1462. if (mountfamily != mnt->nfs_server.address.ss_family)
  1463. goto out_mountproto_mismatch;
  1464. }
  1465. }
  1466. return 1;
  1467. out_mountproto_mismatch:
  1468. printk(KERN_INFO "NFS: mount server address does not match mountproto= "
  1469. "option\n");
  1470. return 0;
  1471. out_proto_mismatch:
  1472. printk(KERN_INFO "NFS: server address does not match proto= option\n");
  1473. return 0;
  1474. out_invalid_address:
  1475. printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
  1476. return 0;
  1477. out_invalid_value:
  1478. printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
  1479. return 0;
  1480. out_minorversion_mismatch:
  1481. printk(KERN_INFO "NFS: mount option vers=%u does not support "
  1482. "minorversion=%u\n", mnt->version, mnt->minorversion);
  1483. return 0;
  1484. out_migration_misuse:
  1485. printk(KERN_INFO
  1486. "NFS: 'migration' not supported for this NFS version\n");
  1487. return 0;
  1488. out_nomem:
  1489. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  1490. return 0;
  1491. out_security_failure:
  1492. free_secdata(secdata);
  1493. printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
  1494. return 0;
  1495. }
  1496. /*
  1497. * Ensure that a specified authtype in args->auth_info is supported by
  1498. * the server. Returns 0 and sets args->selected_flavor if it's ok, and
  1499. * -EACCES if not.
  1500. */
  1501. static int nfs_verify_authflavors(struct nfs_parsed_mount_data *args,
  1502. rpc_authflavor_t *server_authlist, unsigned int count)
  1503. {
  1504. rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR;
  1505. unsigned int i;
  1506. /*
  1507. * If the sec= mount option is used, the specified flavor or AUTH_NULL
  1508. * must be in the list returned by the server.
  1509. *
  1510. * AUTH_NULL has a special meaning when it's in the server list - it
  1511. * means that the server will ignore the rpc creds, so any flavor
  1512. * can be used.
  1513. */
  1514. for (i = 0; i < count; i++) {
  1515. flavor = server_authlist[i];
  1516. if (nfs_auth_info_match(&args->auth_info, flavor) ||
  1517. flavor == RPC_AUTH_NULL)
  1518. goto out;
  1519. }
  1520. dfprintk(MOUNT,
  1521. "NFS: specified auth flavors not supported by server\n");
  1522. return -EACCES;
  1523. out:
  1524. args->selected_flavor = flavor;
  1525. dfprintk(MOUNT, "NFS: using auth flavor %u\n", args->selected_flavor);
  1526. return 0;
  1527. }
  1528. /*
  1529. * Use the remote server's MOUNT service to request the NFS file handle
  1530. * corresponding to the provided path.
  1531. */
  1532. static int nfs_request_mount(struct nfs_parsed_mount_data *args,
  1533. struct nfs_fh *root_fh,
  1534. rpc_authflavor_t *server_authlist,
  1535. unsigned int *server_authlist_len)
  1536. {
  1537. struct nfs_mount_request request = {
  1538. .sap = (struct sockaddr *)
  1539. &args->mount_server.address,
  1540. .dirpath = args->nfs_server.export_path,
  1541. .protocol = args->mount_server.protocol,
  1542. .fh = root_fh,
  1543. .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
  1544. .auth_flav_len = server_authlist_len,
  1545. .auth_flavs = server_authlist,
  1546. .net = args->net,
  1547. };
  1548. int status;
  1549. if (args->mount_server.version == 0) {
  1550. switch (args->version) {
  1551. default:
  1552. args->mount_server.version = NFS_MNT3_VERSION;
  1553. break;
  1554. case 2:
  1555. args->mount_server.version = NFS_MNT_VERSION;
  1556. }
  1557. }
  1558. request.version = args->mount_server.version;
  1559. if (args->mount_server.hostname)
  1560. request.hostname = args->mount_server.hostname;
  1561. else
  1562. request.hostname = args->nfs_server.hostname;
  1563. /*
  1564. * Construct the mount server's address.
  1565. */
  1566. if (args->mount_server.address.ss_family == AF_UNSPEC) {
  1567. memcpy(request.sap, &args->nfs_server.address,
  1568. args->nfs_server.addrlen);
  1569. args->mount_server.addrlen = args->nfs_server.addrlen;
  1570. }
  1571. request.salen = args->mount_server.addrlen;
  1572. nfs_set_port(request.sap, &args->mount_server.port, 0);
  1573. /*
  1574. * Now ask the mount server to map our export path
  1575. * to a file handle.
  1576. */
  1577. status = nfs_mount(&request);
  1578. if (status != 0) {
  1579. dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
  1580. request.hostname, status);
  1581. return status;
  1582. }
  1583. return 0;
  1584. }
  1585. static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_info,
  1586. struct nfs_subversion *nfs_mod)
  1587. {
  1588. int status;
  1589. unsigned int i;
  1590. bool tried_auth_unix = false;
  1591. bool auth_null_in_list = false;
  1592. struct nfs_server *server = ERR_PTR(-EACCES);
  1593. struct nfs_parsed_mount_data *args = mount_info->parsed;
  1594. rpc_authflavor_t authlist[NFS_MAX_SECFLAVORS];
  1595. unsigned int authlist_len = ARRAY_SIZE(authlist);
  1596. status = nfs_request_mount(args, mount_info->mntfh, authlist,
  1597. &authlist_len);
  1598. if (status)
  1599. return ERR_PTR(status);
  1600. /*
  1601. * Was a sec= authflavor specified in the options? First, verify
  1602. * whether the server supports it, and then just try to use it if so.
  1603. */
  1604. if (args->auth_info.flavor_len > 0) {
  1605. status = nfs_verify_authflavors(args, authlist, authlist_len);
  1606. dfprintk(MOUNT, "NFS: using auth flavor %u\n",
  1607. args->selected_flavor);
  1608. if (status)
  1609. return ERR_PTR(status);
  1610. return nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1611. }
  1612. /*
  1613. * No sec= option was provided. RFC 2623, section 2.7 suggests we
  1614. * SHOULD prefer the flavor listed first. However, some servers list
  1615. * AUTH_NULL first. Avoid ever choosing AUTH_NULL.
  1616. */
  1617. for (i = 0; i < authlist_len; ++i) {
  1618. rpc_authflavor_t flavor;
  1619. struct rpcsec_gss_info info;
  1620. flavor = authlist[i];
  1621. switch (flavor) {
  1622. case RPC_AUTH_UNIX:
  1623. tried_auth_unix = true;
  1624. break;
  1625. case RPC_AUTH_NULL:
  1626. auth_null_in_list = true;
  1627. continue;
  1628. default:
  1629. if (rpcauth_get_gssinfo(flavor, &info) != 0)
  1630. continue;
  1631. /* Fallthrough */
  1632. }
  1633. dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
  1634. args->selected_flavor = flavor;
  1635. server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1636. if (!IS_ERR(server))
  1637. return server;
  1638. }
  1639. /*
  1640. * Nothing we tried so far worked. At this point, give up if we've
  1641. * already tried AUTH_UNIX or if the server's list doesn't contain
  1642. * AUTH_NULL
  1643. */
  1644. if (tried_auth_unix || !auth_null_in_list)
  1645. return server;
  1646. /* Last chance! Try AUTH_UNIX */
  1647. dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", RPC_AUTH_UNIX);
  1648. args->selected_flavor = RPC_AUTH_UNIX;
  1649. return nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1650. }
  1651. struct dentry *nfs_try_mount(int flags, const char *dev_name,
  1652. struct nfs_mount_info *mount_info,
  1653. struct nfs_subversion *nfs_mod)
  1654. {
  1655. struct nfs_server *server;
  1656. if (mount_info->parsed->need_mount)
  1657. server = nfs_try_mount_request(mount_info, nfs_mod);
  1658. else
  1659. server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1660. if (IS_ERR(server))
  1661. return ERR_CAST(server);
  1662. return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
  1663. }
  1664. EXPORT_SYMBOL_GPL(nfs_try_mount);
  1665. /*
  1666. * Split "dev_name" into "hostname:export_path".
  1667. *
  1668. * The leftmost colon demarks the split between the server's hostname
  1669. * and the export path. If the hostname starts with a left square
  1670. * bracket, then it may contain colons.
  1671. *
  1672. * Note: caller frees hostname and export path, even on error.
  1673. */
  1674. static int nfs_parse_devname(const char *dev_name,
  1675. char **hostname, size_t maxnamlen,
  1676. char **export_path, size_t maxpathlen)
  1677. {
  1678. size_t len;
  1679. char *end;
  1680. /* Is the host name protected with square brakcets? */
  1681. if (*dev_name == '[') {
  1682. end = strchr(++dev_name, ']');
  1683. if (end == NULL || end[1] != ':')
  1684. goto out_bad_devname;
  1685. len = end - dev_name;
  1686. end++;
  1687. } else {
  1688. char *comma;
  1689. end = strchr(dev_name, ':');
  1690. if (end == NULL)
  1691. goto out_bad_devname;
  1692. len = end - dev_name;
  1693. /* kill possible hostname list: not supported */
  1694. comma = strchr(dev_name, ',');
  1695. if (comma != NULL && comma < end)
  1696. *comma = 0;
  1697. }
  1698. if (len > maxnamlen)
  1699. goto out_hostname;
  1700. /* N.B. caller will free nfs_server.hostname in all cases */
  1701. *hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1702. if (*hostname == NULL)
  1703. goto out_nomem;
  1704. len = strlen(++end);
  1705. if (len > maxpathlen)
  1706. goto out_path;
  1707. *export_path = kstrndup(end, len, GFP_KERNEL);
  1708. if (!*export_path)
  1709. goto out_nomem;
  1710. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
  1711. return 0;
  1712. out_bad_devname:
  1713. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1714. return -EINVAL;
  1715. out_nomem:
  1716. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1717. return -ENOMEM;
  1718. out_hostname:
  1719. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1720. return -ENAMETOOLONG;
  1721. out_path:
  1722. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1723. return -ENAMETOOLONG;
  1724. }
  1725. /*
  1726. * Validate the NFS2/NFS3 mount data
  1727. * - fills in the mount root filehandle
  1728. *
  1729. * For option strings, user space handles the following behaviors:
  1730. *
  1731. * + DNS: mapping server host name to IP address ("addr=" option)
  1732. *
  1733. * + failure mode: how to behave if a mount request can't be handled
  1734. * immediately ("fg/bg" option)
  1735. *
  1736. * + retry: how often to retry a mount request ("retry=" option)
  1737. *
  1738. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  1739. * mountproto=tcp after mountproto=udp, and so on
  1740. */
  1741. static int nfs23_validate_mount_data(void *options,
  1742. struct nfs_parsed_mount_data *args,
  1743. struct nfs_fh *mntfh,
  1744. const char *dev_name)
  1745. {
  1746. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  1747. struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
  1748. int extra_flags = NFS_MOUNT_LEGACY_INTERFACE;
  1749. if (data == NULL)
  1750. goto out_no_data;
  1751. args->version = NFS_DEFAULT_VERSION;
  1752. switch (data->version) {
  1753. case 1:
  1754. data->namlen = 0;
  1755. case 2:
  1756. data->bsize = 0;
  1757. case 3:
  1758. if (data->flags & NFS_MOUNT_VER3)
  1759. goto out_no_v3;
  1760. data->root.size = NFS2_FHSIZE;
  1761. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  1762. /* Turn off security negotiation */
  1763. extra_flags |= NFS_MOUNT_SECFLAVOUR;
  1764. case 4:
  1765. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1766. goto out_no_sec;
  1767. case 5:
  1768. memset(data->context, 0, sizeof(data->context));
  1769. case 6:
  1770. if (data->flags & NFS_MOUNT_VER3) {
  1771. if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
  1772. goto out_invalid_fh;
  1773. mntfh->size = data->root.size;
  1774. args->version = 3;
  1775. } else {
  1776. mntfh->size = NFS2_FHSIZE;
  1777. args->version = 2;
  1778. }
  1779. memcpy(mntfh->data, data->root.data, mntfh->size);
  1780. if (mntfh->size < sizeof(mntfh->data))
  1781. memset(mntfh->data + mntfh->size, 0,
  1782. sizeof(mntfh->data) - mntfh->size);
  1783. /*
  1784. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1785. * can deal with.
  1786. */
  1787. args->flags = data->flags & NFS_MOUNT_FLAGMASK;
  1788. args->flags |= extra_flags;
  1789. args->rsize = data->rsize;
  1790. args->wsize = data->wsize;
  1791. args->timeo = data->timeo;
  1792. args->retrans = data->retrans;
  1793. args->acregmin = data->acregmin;
  1794. args->acregmax = data->acregmax;
  1795. args->acdirmin = data->acdirmin;
  1796. args->acdirmax = data->acdirmax;
  1797. args->need_mount = false;
  1798. memcpy(sap, &data->addr, sizeof(data->addr));
  1799. args->nfs_server.addrlen = sizeof(data->addr);
  1800. args->nfs_server.port = ntohs(data->addr.sin_port);
  1801. if (!nfs_verify_server_address(sap))
  1802. goto out_no_address;
  1803. if (!(data->flags & NFS_MOUNT_TCP))
  1804. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1805. /* N.B. caller will free nfs_server.hostname in all cases */
  1806. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1807. args->namlen = data->namlen;
  1808. args->bsize = data->bsize;
  1809. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1810. args->selected_flavor = data->pseudoflavor;
  1811. else
  1812. args->selected_flavor = RPC_AUTH_UNIX;
  1813. if (!args->nfs_server.hostname)
  1814. goto out_nomem;
  1815. if (!(data->flags & NFS_MOUNT_NONLM))
  1816. args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
  1817. NFS_MOUNT_LOCAL_FCNTL);
  1818. else
  1819. args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
  1820. NFS_MOUNT_LOCAL_FCNTL);
  1821. /*
  1822. * The legacy version 6 binary mount data from userspace has a
  1823. * field used only to transport selinux information into the
  1824. * the kernel. To continue to support that functionality we
  1825. * have a touch of selinux knowledge here in the NFS code. The
  1826. * userspace code converted context=blah to just blah so we are
  1827. * converting back to the full string selinux understands.
  1828. */
  1829. if (data->context[0]){
  1830. #ifdef CONFIG_SECURITY_SELINUX
  1831. int rc;
  1832. char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
  1833. if (!opts_str)
  1834. return -ENOMEM;
  1835. strcpy(opts_str, "context=");
  1836. data->context[NFS_MAX_CONTEXT_LEN] = '\0';
  1837. strcat(opts_str, &data->context[0]);
  1838. rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
  1839. kfree(opts_str);
  1840. if (rc)
  1841. return rc;
  1842. #else
  1843. return -EINVAL;
  1844. #endif
  1845. }
  1846. break;
  1847. default:
  1848. return NFS_TEXT_DATA;
  1849. }
  1850. return 0;
  1851. out_no_data:
  1852. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1853. return -EINVAL;
  1854. out_no_v3:
  1855. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1856. data->version);
  1857. return -EINVAL;
  1858. out_no_sec:
  1859. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1860. return -EINVAL;
  1861. out_nomem:
  1862. dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
  1863. return -ENOMEM;
  1864. out_no_address:
  1865. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1866. return -EINVAL;
  1867. out_invalid_fh:
  1868. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1869. return -EINVAL;
  1870. }
  1871. #if IS_ENABLED(CONFIG_NFS_V4)
  1872. static int nfs_validate_mount_data(struct file_system_type *fs_type,
  1873. void *options,
  1874. struct nfs_parsed_mount_data *args,
  1875. struct nfs_fh *mntfh,
  1876. const char *dev_name)
  1877. {
  1878. if (fs_type == &nfs_fs_type)
  1879. return nfs23_validate_mount_data(options, args, mntfh, dev_name);
  1880. return nfs4_validate_mount_data(options, args, dev_name);
  1881. }
  1882. #else
  1883. static int nfs_validate_mount_data(struct file_system_type *fs_type,
  1884. void *options,
  1885. struct nfs_parsed_mount_data *args,
  1886. struct nfs_fh *mntfh,
  1887. const char *dev_name)
  1888. {
  1889. return nfs23_validate_mount_data(options, args, mntfh, dev_name);
  1890. }
  1891. #endif
  1892. static int nfs_validate_text_mount_data(void *options,
  1893. struct nfs_parsed_mount_data *args,
  1894. const char *dev_name)
  1895. {
  1896. int port = 0;
  1897. int max_namelen = PAGE_SIZE;
  1898. int max_pathlen = NFS_MAXPATHLEN;
  1899. struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
  1900. if (nfs_parse_mount_options((char *)options, args) == 0)
  1901. return -EINVAL;
  1902. if (!nfs_verify_server_address(sap))
  1903. goto out_no_address;
  1904. if (args->version == 4) {
  1905. #if IS_ENABLED(CONFIG_NFS_V4)
  1906. port = NFS_PORT;
  1907. max_namelen = NFS4_MAXNAMLEN;
  1908. max_pathlen = NFS4_MAXPATHLEN;
  1909. nfs_validate_transport_protocol(args);
  1910. if (args->nfs_server.protocol == XPRT_TRANSPORT_UDP)
  1911. goto out_invalid_transport_udp;
  1912. nfs4_validate_mount_flags(args);
  1913. #else
  1914. goto out_v4_not_compiled;
  1915. #endif /* CONFIG_NFS_V4 */
  1916. } else
  1917. nfs_set_mount_transport_protocol(args);
  1918. nfs_set_port(sap, &args->nfs_server.port, port);
  1919. return nfs_parse_devname(dev_name,
  1920. &args->nfs_server.hostname,
  1921. max_namelen,
  1922. &args->nfs_server.export_path,
  1923. max_pathlen);
  1924. #if !IS_ENABLED(CONFIG_NFS_V4)
  1925. out_v4_not_compiled:
  1926. dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
  1927. return -EPROTONOSUPPORT;
  1928. #else
  1929. out_invalid_transport_udp:
  1930. dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
  1931. return -EINVAL;
  1932. #endif /* !CONFIG_NFS_V4 */
  1933. out_no_address:
  1934. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1935. return -EINVAL;
  1936. }
  1937. #define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \
  1938. | NFS_MOUNT_SECURE \
  1939. | NFS_MOUNT_TCP \
  1940. | NFS_MOUNT_VER3 \
  1941. | NFS_MOUNT_KERBEROS \
  1942. | NFS_MOUNT_NONLM \
  1943. | NFS_MOUNT_BROKEN_SUID \
  1944. | NFS_MOUNT_STRICTLOCK \
  1945. | NFS_MOUNT_LEGACY_INTERFACE)
  1946. #define NFS_MOUNT_CMP_FLAGMASK (NFS_REMOUNT_CMP_FLAGMASK & \
  1947. ~(NFS_MOUNT_UNSHARED | NFS_MOUNT_NORESVPORT))
  1948. static int
  1949. nfs_compare_remount_data(struct nfs_server *nfss,
  1950. struct nfs_parsed_mount_data *data)
  1951. {
  1952. if ((data->flags ^ nfss->flags) & NFS_REMOUNT_CMP_FLAGMASK ||
  1953. data->rsize != nfss->rsize ||
  1954. data->wsize != nfss->wsize ||
  1955. data->version != nfss->nfs_client->rpc_ops->version ||
  1956. data->minorversion != nfss->nfs_client->cl_minorversion ||
  1957. data->retrans != nfss->client->cl_timeout->to_retries ||
  1958. data->selected_flavor != nfss->client->cl_auth->au_flavor ||
  1959. data->acregmin != nfss->acregmin / HZ ||
  1960. data->acregmax != nfss->acregmax / HZ ||
  1961. data->acdirmin != nfss->acdirmin / HZ ||
  1962. data->acdirmax != nfss->acdirmax / HZ ||
  1963. data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
  1964. data->nfs_server.port != nfss->port ||
  1965. data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
  1966. !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
  1967. (struct sockaddr *)&nfss->nfs_client->cl_addr))
  1968. return -EINVAL;
  1969. return 0;
  1970. }
  1971. int
  1972. nfs_remount(struct super_block *sb, int *flags, char *raw_data)
  1973. {
  1974. int error;
  1975. struct nfs_server *nfss = sb->s_fs_info;
  1976. struct nfs_parsed_mount_data *data;
  1977. struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
  1978. struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
  1979. u32 nfsvers = nfss->nfs_client->rpc_ops->version;
  1980. sync_filesystem(sb);
  1981. /*
  1982. * Userspace mount programs that send binary options generally send
  1983. * them populated with default values. We have no way to know which
  1984. * ones were explicitly specified. Fall back to legacy behavior and
  1985. * just return success.
  1986. */
  1987. if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
  1988. (nfsvers <= 3 && (!options || (options->version >= 1 &&
  1989. options->version <= 6))))
  1990. return 0;
  1991. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1992. if (data == NULL)
  1993. return -ENOMEM;
  1994. /* fill out struct with values from existing mount */
  1995. data->flags = nfss->flags;
  1996. data->rsize = nfss->rsize;
  1997. data->wsize = nfss->wsize;
  1998. data->retrans = nfss->client->cl_timeout->to_retries;
  1999. data->selected_flavor = nfss->client->cl_auth->au_flavor;
  2000. data->auth_info = nfss->auth_info;
  2001. data->acregmin = nfss->acregmin / HZ;
  2002. data->acregmax = nfss->acregmax / HZ;
  2003. data->acdirmin = nfss->acdirmin / HZ;
  2004. data->acdirmax = nfss->acdirmax / HZ;
  2005. data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
  2006. data->nfs_server.port = nfss->port;
  2007. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  2008. data->version = nfsvers;
  2009. data->minorversion = nfss->nfs_client->cl_minorversion;
  2010. data->net = current->nsproxy->net_ns;
  2011. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  2012. data->nfs_server.addrlen);
  2013. /* overwrite those values with any that were specified */
  2014. error = -EINVAL;
  2015. if (!nfs_parse_mount_options((char *)options, data))
  2016. goto out;
  2017. /*
  2018. * noac is a special case. It implies -o sync, but that's not
  2019. * necessarily reflected in the mtab options. do_remount_sb
  2020. * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
  2021. * remount options, so we have to explicitly reset it.
  2022. */
  2023. if (data->flags & NFS_MOUNT_NOAC)
  2024. *flags |= MS_SYNCHRONOUS;
  2025. /* compare new mount options with old ones */
  2026. error = nfs_compare_remount_data(nfss, data);
  2027. out:
  2028. kfree(data);
  2029. return error;
  2030. }
  2031. EXPORT_SYMBOL_GPL(nfs_remount);
  2032. /*
  2033. * Initialise the common bits of the superblock
  2034. */
  2035. inline void nfs_initialise_sb(struct super_block *sb)
  2036. {
  2037. struct nfs_server *server = NFS_SB(sb);
  2038. sb->s_magic = NFS_SUPER_MAGIC;
  2039. /* We probably want something more informative here */
  2040. snprintf(sb->s_id, sizeof(sb->s_id),
  2041. "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  2042. if (sb->s_blocksize == 0)
  2043. sb->s_blocksize = nfs_block_bits(server->wsize,
  2044. &sb->s_blocksize_bits);
  2045. sb->s_bdi = &server->backing_dev_info;
  2046. nfs_super_set_maxbytes(sb, server->maxfilesize);
  2047. }
  2048. /*
  2049. * Finish setting up an NFS2/3 superblock
  2050. */
  2051. void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
  2052. {
  2053. struct nfs_parsed_mount_data *data = mount_info->parsed;
  2054. struct nfs_server *server = NFS_SB(sb);
  2055. sb->s_blocksize_bits = 0;
  2056. sb->s_blocksize = 0;
  2057. sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
  2058. sb->s_op = server->nfs_client->cl_nfs_mod->sops;
  2059. if (data && data->bsize)
  2060. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  2061. if (server->nfs_client->rpc_ops->version != 2) {
  2062. /* The VFS shouldn't apply the umask to mode bits. We will do
  2063. * so ourselves when necessary.
  2064. */
  2065. sb->s_flags |= MS_POSIXACL;
  2066. sb->s_time_gran = 1;
  2067. }
  2068. nfs_initialise_sb(sb);
  2069. }
  2070. EXPORT_SYMBOL_GPL(nfs_fill_super);
  2071. /*
  2072. * Finish setting up a cloned NFS2/3/4 superblock
  2073. */
  2074. void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
  2075. {
  2076. const struct super_block *old_sb = mount_info->cloned->sb;
  2077. struct nfs_server *server = NFS_SB(sb);
  2078. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  2079. sb->s_blocksize = old_sb->s_blocksize;
  2080. sb->s_maxbytes = old_sb->s_maxbytes;
  2081. sb->s_xattr = old_sb->s_xattr;
  2082. sb->s_op = old_sb->s_op;
  2083. sb->s_time_gran = 1;
  2084. if (server->nfs_client->rpc_ops->version != 2) {
  2085. /* The VFS shouldn't apply the umask to mode bits. We will do
  2086. * so ourselves when necessary.
  2087. */
  2088. sb->s_flags |= MS_POSIXACL;
  2089. }
  2090. nfs_initialise_sb(sb);
  2091. }
  2092. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  2093. {
  2094. const struct nfs_server *a = s->s_fs_info;
  2095. const struct rpc_clnt *clnt_a = a->client;
  2096. const struct rpc_clnt *clnt_b = b->client;
  2097. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  2098. goto Ebusy;
  2099. if (a->nfs_client != b->nfs_client)
  2100. goto Ebusy;
  2101. if ((a->flags ^ b->flags) & NFS_MOUNT_CMP_FLAGMASK)
  2102. goto Ebusy;
  2103. if (a->wsize != b->wsize)
  2104. goto Ebusy;
  2105. if (a->rsize != b->rsize)
  2106. goto Ebusy;
  2107. if (a->acregmin != b->acregmin)
  2108. goto Ebusy;
  2109. if (a->acregmax != b->acregmax)
  2110. goto Ebusy;
  2111. if (a->acdirmin != b->acdirmin)
  2112. goto Ebusy;
  2113. if (a->acdirmax != b->acdirmax)
  2114. goto Ebusy;
  2115. if (b->auth_info.flavor_len > 0 &&
  2116. clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  2117. goto Ebusy;
  2118. return 1;
  2119. Ebusy:
  2120. return 0;
  2121. }
  2122. struct nfs_sb_mountdata {
  2123. struct nfs_server *server;
  2124. int mntflags;
  2125. };
  2126. static int nfs_set_super(struct super_block *s, void *data)
  2127. {
  2128. struct nfs_sb_mountdata *sb_mntdata = data;
  2129. struct nfs_server *server = sb_mntdata->server;
  2130. int ret;
  2131. s->s_flags = sb_mntdata->mntflags;
  2132. s->s_fs_info = server;
  2133. s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
  2134. ret = set_anon_super(s, server);
  2135. if (ret == 0)
  2136. server->s_dev = s->s_dev;
  2137. return ret;
  2138. }
  2139. static int nfs_compare_super_address(struct nfs_server *server1,
  2140. struct nfs_server *server2)
  2141. {
  2142. struct sockaddr *sap1, *sap2;
  2143. sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
  2144. sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
  2145. if (sap1->sa_family != sap2->sa_family)
  2146. return 0;
  2147. switch (sap1->sa_family) {
  2148. case AF_INET: {
  2149. struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
  2150. struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
  2151. if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
  2152. return 0;
  2153. if (sin1->sin_port != sin2->sin_port)
  2154. return 0;
  2155. break;
  2156. }
  2157. case AF_INET6: {
  2158. struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
  2159. struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
  2160. if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
  2161. return 0;
  2162. if (sin1->sin6_port != sin2->sin6_port)
  2163. return 0;
  2164. break;
  2165. }
  2166. default:
  2167. return 0;
  2168. }
  2169. return 1;
  2170. }
  2171. static int nfs_compare_super(struct super_block *sb, void *data)
  2172. {
  2173. struct nfs_sb_mountdata *sb_mntdata = data;
  2174. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  2175. int mntflags = sb_mntdata->mntflags;
  2176. if (!nfs_compare_super_address(old, server))
  2177. return 0;
  2178. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  2179. if (old->flags & NFS_MOUNT_UNSHARED)
  2180. return 0;
  2181. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  2182. return 0;
  2183. return nfs_compare_mount_options(sb, server, mntflags);
  2184. }
  2185. #ifdef CONFIG_NFS_FSCACHE
  2186. static void nfs_get_cache_cookie(struct super_block *sb,
  2187. struct nfs_parsed_mount_data *parsed,
  2188. struct nfs_clone_mount *cloned)
  2189. {
  2190. struct nfs_server *nfss = NFS_SB(sb);
  2191. char *uniq = NULL;
  2192. int ulen = 0;
  2193. nfss->fscache_key = NULL;
  2194. nfss->fscache = NULL;
  2195. if (parsed) {
  2196. if (!(parsed->options & NFS_OPTION_FSCACHE))
  2197. return;
  2198. if (parsed->fscache_uniq) {
  2199. uniq = parsed->fscache_uniq;
  2200. ulen = strlen(parsed->fscache_uniq);
  2201. }
  2202. } else if (cloned) {
  2203. struct nfs_server *mnt_s = NFS_SB(cloned->sb);
  2204. if (!(mnt_s->options & NFS_OPTION_FSCACHE))
  2205. return;
  2206. if (mnt_s->fscache_key) {
  2207. uniq = mnt_s->fscache_key->key.uniquifier;
  2208. ulen = mnt_s->fscache_key->key.uniq_len;
  2209. };
  2210. } else
  2211. return;
  2212. nfs_fscache_get_super_cookie(sb, uniq, ulen);
  2213. }
  2214. #else
  2215. static void nfs_get_cache_cookie(struct super_block *sb,
  2216. struct nfs_parsed_mount_data *parsed,
  2217. struct nfs_clone_mount *cloned)
  2218. {
  2219. }
  2220. #endif
  2221. static int nfs_bdi_register(struct nfs_server *server)
  2222. {
  2223. return bdi_register_dev(&server->backing_dev_info, server->s_dev);
  2224. }
  2225. int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
  2226. struct nfs_mount_info *mount_info)
  2227. {
  2228. int error;
  2229. unsigned long kflags = 0, kflags_out = 0;
  2230. if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL)
  2231. kflags |= SECURITY_LSM_NATIVE_LABELS;
  2232. error = security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts,
  2233. kflags, &kflags_out);
  2234. if (error)
  2235. goto err;
  2236. if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL &&
  2237. !(kflags_out & SECURITY_LSM_NATIVE_LABELS))
  2238. NFS_SB(s)->caps &= ~NFS_CAP_SECURITY_LABEL;
  2239. err:
  2240. return error;
  2241. }
  2242. EXPORT_SYMBOL_GPL(nfs_set_sb_security);
  2243. int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
  2244. struct nfs_mount_info *mount_info)
  2245. {
  2246. /* clone any lsm security options from the parent to the new sb */
  2247. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
  2248. return -ESTALE;
  2249. return security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
  2250. }
  2251. EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
  2252. struct dentry *nfs_fs_mount_common(struct nfs_server *server,
  2253. int flags, const char *dev_name,
  2254. struct nfs_mount_info *mount_info,
  2255. struct nfs_subversion *nfs_mod)
  2256. {
  2257. struct super_block *s;
  2258. struct dentry *mntroot = ERR_PTR(-ENOMEM);
  2259. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2260. struct nfs_sb_mountdata sb_mntdata = {
  2261. .mntflags = flags,
  2262. .server = server,
  2263. };
  2264. int error;
  2265. if (server->flags & NFS_MOUNT_UNSHARED)
  2266. compare_super = NULL;
  2267. /* -o noac implies -o sync */
  2268. if (server->flags & NFS_MOUNT_NOAC)
  2269. sb_mntdata.mntflags |= MS_SYNCHRONOUS;
  2270. if (mount_info->cloned != NULL && mount_info->cloned->sb != NULL)
  2271. if (mount_info->cloned->sb->s_flags & MS_SYNCHRONOUS)
  2272. sb_mntdata.mntflags |= MS_SYNCHRONOUS;
  2273. /* Get a superblock - note that we may end up sharing one that already exists */
  2274. s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
  2275. if (IS_ERR(s)) {
  2276. mntroot = ERR_CAST(s);
  2277. goto out_err_nosb;
  2278. }
  2279. if (s->s_fs_info != server) {
  2280. nfs_free_server(server);
  2281. server = NULL;
  2282. } else {
  2283. error = nfs_bdi_register(server);
  2284. if (error) {
  2285. mntroot = ERR_PTR(error);
  2286. goto error_splat_bdi;
  2287. }
  2288. server->super = s;
  2289. }
  2290. if (!s->s_root) {
  2291. /* initial superblock/root creation */
  2292. mount_info->fill_super(s, mount_info);
  2293. nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
  2294. }
  2295. mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
  2296. if (IS_ERR(mntroot))
  2297. goto error_splat_super;
  2298. error = mount_info->set_security(s, mntroot, mount_info);
  2299. if (error)
  2300. goto error_splat_root;
  2301. s->s_flags |= MS_ACTIVE;
  2302. out:
  2303. return mntroot;
  2304. out_err_nosb:
  2305. nfs_free_server(server);
  2306. goto out;
  2307. error_splat_root:
  2308. dput(mntroot);
  2309. mntroot = ERR_PTR(error);
  2310. error_splat_super:
  2311. if (server && !s->s_root)
  2312. bdi_unregister(&server->backing_dev_info);
  2313. error_splat_bdi:
  2314. deactivate_locked_super(s);
  2315. goto out;
  2316. }
  2317. EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
  2318. struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
  2319. int flags, const char *dev_name, void *raw_data)
  2320. {
  2321. struct nfs_mount_info mount_info = {
  2322. .fill_super = nfs_fill_super,
  2323. .set_security = nfs_set_sb_security,
  2324. };
  2325. struct dentry *mntroot = ERR_PTR(-ENOMEM);
  2326. struct nfs_subversion *nfs_mod;
  2327. int error;
  2328. mount_info.parsed = nfs_alloc_parsed_mount_data();
  2329. mount_info.mntfh = nfs_alloc_fhandle();
  2330. if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
  2331. goto out;
  2332. /* Validate the mount data */
  2333. error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
  2334. if (error == NFS_TEXT_DATA)
  2335. error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
  2336. if (error < 0) {
  2337. mntroot = ERR_PTR(error);
  2338. goto out;
  2339. }
  2340. nfs_mod = get_nfs_version(mount_info.parsed->version);
  2341. if (IS_ERR(nfs_mod)) {
  2342. mntroot = ERR_CAST(nfs_mod);
  2343. goto out;
  2344. }
  2345. mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
  2346. put_nfs_version(nfs_mod);
  2347. out:
  2348. nfs_free_parsed_mount_data(mount_info.parsed);
  2349. nfs_free_fhandle(mount_info.mntfh);
  2350. return mntroot;
  2351. }
  2352. EXPORT_SYMBOL_GPL(nfs_fs_mount);
  2353. /*
  2354. * Ensure that we unregister the bdi before kill_anon_super
  2355. * releases the device name
  2356. */
  2357. void nfs_put_super(struct super_block *s)
  2358. {
  2359. struct nfs_server *server = NFS_SB(s);
  2360. bdi_unregister(&server->backing_dev_info);
  2361. }
  2362. EXPORT_SYMBOL_GPL(nfs_put_super);
  2363. /*
  2364. * Destroy an NFS2/3 superblock
  2365. */
  2366. void nfs_kill_super(struct super_block *s)
  2367. {
  2368. struct nfs_server *server = NFS_SB(s);
  2369. kill_anon_super(s);
  2370. nfs_fscache_release_super_cookie(s);
  2371. nfs_free_server(server);
  2372. }
  2373. EXPORT_SYMBOL_GPL(nfs_kill_super);
  2374. /*
  2375. * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
  2376. */
  2377. static struct dentry *
  2378. nfs_xdev_mount(struct file_system_type *fs_type, int flags,
  2379. const char *dev_name, void *raw_data)
  2380. {
  2381. struct nfs_clone_mount *data = raw_data;
  2382. struct nfs_mount_info mount_info = {
  2383. .fill_super = nfs_clone_super,
  2384. .set_security = nfs_clone_sb_security,
  2385. .cloned = data,
  2386. };
  2387. struct nfs_server *server;
  2388. struct dentry *mntroot = ERR_PTR(-ENOMEM);
  2389. struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
  2390. dprintk("--> nfs_xdev_mount()\n");
  2391. mount_info.mntfh = mount_info.cloned->fh;
  2392. /* create a new volume representation */
  2393. server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
  2394. if (IS_ERR(server))
  2395. mntroot = ERR_CAST(server);
  2396. else
  2397. mntroot = nfs_fs_mount_common(server, flags,
  2398. dev_name, &mount_info, nfs_mod);
  2399. dprintk("<-- nfs_xdev_mount() = %ld\n",
  2400. IS_ERR(mntroot) ? PTR_ERR(mntroot) : 0L);
  2401. return mntroot;
  2402. }
  2403. #if IS_ENABLED(CONFIG_NFS_V4)
  2404. static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
  2405. {
  2406. args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
  2407. NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
  2408. }
  2409. /*
  2410. * Validate NFSv4 mount options
  2411. */
  2412. static int nfs4_validate_mount_data(void *options,
  2413. struct nfs_parsed_mount_data *args,
  2414. const char *dev_name)
  2415. {
  2416. struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
  2417. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  2418. char *c;
  2419. if (data == NULL)
  2420. goto out_no_data;
  2421. args->version = 4;
  2422. switch (data->version) {
  2423. case 1:
  2424. if (data->host_addrlen > sizeof(args->nfs_server.address))
  2425. goto out_no_address;
  2426. if (data->host_addrlen == 0)
  2427. goto out_no_address;
  2428. args->nfs_server.addrlen = data->host_addrlen;
  2429. if (copy_from_user(sap, data->host_addr, data->host_addrlen))
  2430. return -EFAULT;
  2431. if (!nfs_verify_server_address(sap))
  2432. goto out_no_address;
  2433. args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
  2434. if (data->auth_flavourlen) {
  2435. rpc_authflavor_t pseudoflavor;
  2436. if (data->auth_flavourlen > 1)
  2437. goto out_inval_auth;
  2438. if (copy_from_user(&pseudoflavor,
  2439. data->auth_flavours,
  2440. sizeof(pseudoflavor)))
  2441. return -EFAULT;
  2442. args->selected_flavor = pseudoflavor;
  2443. } else
  2444. args->selected_flavor = RPC_AUTH_UNIX;
  2445. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  2446. if (IS_ERR(c))
  2447. return PTR_ERR(c);
  2448. args->nfs_server.hostname = c;
  2449. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  2450. if (IS_ERR(c))
  2451. return PTR_ERR(c);
  2452. args->nfs_server.export_path = c;
  2453. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  2454. c = strndup_user(data->client_addr.data, 16);
  2455. if (IS_ERR(c))
  2456. return PTR_ERR(c);
  2457. args->client_address = c;
  2458. /*
  2459. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  2460. * can deal with.
  2461. */
  2462. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  2463. args->rsize = data->rsize;
  2464. args->wsize = data->wsize;
  2465. args->timeo = data->timeo;
  2466. args->retrans = data->retrans;
  2467. args->acregmin = data->acregmin;
  2468. args->acregmax = data->acregmax;
  2469. args->acdirmin = data->acdirmin;
  2470. args->acdirmax = data->acdirmax;
  2471. args->nfs_server.protocol = data->proto;
  2472. nfs_validate_transport_protocol(args);
  2473. if (args->nfs_server.protocol == XPRT_TRANSPORT_UDP)
  2474. goto out_invalid_transport_udp;
  2475. break;
  2476. default:
  2477. return NFS_TEXT_DATA;
  2478. }
  2479. return 0;
  2480. out_no_data:
  2481. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  2482. return -EINVAL;
  2483. out_inval_auth:
  2484. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  2485. data->auth_flavourlen);
  2486. return -EINVAL;
  2487. out_no_address:
  2488. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  2489. return -EINVAL;
  2490. out_invalid_transport_udp:
  2491. dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
  2492. return -EINVAL;
  2493. }
  2494. /*
  2495. * NFS v4 module parameters need to stay in the
  2496. * NFS client for backwards compatibility
  2497. */
  2498. unsigned int nfs_callback_set_tcpport;
  2499. unsigned short nfs_callback_tcpport;
  2500. /* Default cache timeout is 10 minutes */
  2501. unsigned int nfs_idmap_cache_timeout = 600;
  2502. /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
  2503. bool nfs4_disable_idmapping = true;
  2504. unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
  2505. unsigned short send_implementation_id = 1;
  2506. char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
  2507. bool recover_lost_locks = false;
  2508. EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
  2509. EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
  2510. EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
  2511. EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
  2512. EXPORT_SYMBOL_GPL(max_session_slots);
  2513. EXPORT_SYMBOL_GPL(send_implementation_id);
  2514. EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
  2515. EXPORT_SYMBOL_GPL(recover_lost_locks);
  2516. #define NFS_CALLBACK_MAXPORTNR (65535U)
  2517. static int param_set_portnr(const char *val, const struct kernel_param *kp)
  2518. {
  2519. unsigned long num;
  2520. int ret;
  2521. if (!val)
  2522. return -EINVAL;
  2523. ret = kstrtoul(val, 0, &num);
  2524. if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
  2525. return -EINVAL;
  2526. *((unsigned int *)kp->arg) = num;
  2527. return 0;
  2528. }
  2529. static struct kernel_param_ops param_ops_portnr = {
  2530. .set = param_set_portnr,
  2531. .get = param_get_uint,
  2532. };
  2533. #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
  2534. module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
  2535. module_param(nfs_idmap_cache_timeout, int, 0644);
  2536. module_param(nfs4_disable_idmapping, bool, 0644);
  2537. module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
  2538. NFS4_CLIENT_ID_UNIQ_LEN, 0600);
  2539. MODULE_PARM_DESC(nfs4_disable_idmapping,
  2540. "Turn off NFSv4 idmapping when using 'sec=sys'");
  2541. module_param(max_session_slots, ushort, 0644);
  2542. MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
  2543. "requests the client will negotiate");
  2544. module_param(send_implementation_id, ushort, 0644);
  2545. MODULE_PARM_DESC(send_implementation_id,
  2546. "Send implementation ID with NFSv4.1 exchange_id");
  2547. MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
  2548. module_param(recover_lost_locks, bool, 0644);
  2549. MODULE_PARM_DESC(recover_lost_locks,
  2550. "If the server reports that a lock might be lost, "
  2551. "try to recover it risking data corruption.");
  2552. #endif /* CONFIG_NFS_V4 */