super.c 78 KB

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