super.c 75 KB

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