super.c 76 KB

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