super.c 75 KB

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