super.c 79 KB

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