super.c 77 KB

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