super.c 76 KB

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