super.c 77 KB

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