super.c 77 KB

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