super.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541
  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.Cox@linux.org>, 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/smp_lock.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/mount.h>
  43. #include <linux/nfs_idmap.h>
  44. #include <linux/vfs.h>
  45. #include <linux/inet.h>
  46. #include <linux/in6.h>
  47. #include <net/ipv6.h>
  48. #include <linux/netdevice.h>
  49. #include <linux/nfs_xdr.h>
  50. #include <linux/magic.h>
  51. #include <linux/parser.h>
  52. #include <asm/system.h>
  53. #include <asm/uaccess.h>
  54. #include "nfs4_fs.h"
  55. #include "callback.h"
  56. #include "delegation.h"
  57. #include "iostat.h"
  58. #include "internal.h"
  59. #define NFSDBG_FACILITY NFSDBG_VFS
  60. enum {
  61. /* Mount options that take no arguments */
  62. Opt_soft, Opt_hard,
  63. Opt_posix, Opt_noposix,
  64. Opt_cto, Opt_nocto,
  65. Opt_ac, Opt_noac,
  66. Opt_lock, Opt_nolock,
  67. Opt_v2, Opt_v3,
  68. Opt_udp, Opt_tcp, Opt_rdma,
  69. Opt_acl, Opt_noacl,
  70. Opt_rdirplus, Opt_nordirplus,
  71. Opt_sharecache, Opt_nosharecache,
  72. /* Mount options that take integer arguments */
  73. Opt_port,
  74. Opt_rsize, Opt_wsize, Opt_bsize,
  75. Opt_timeo, Opt_retrans,
  76. Opt_acregmin, Opt_acregmax,
  77. Opt_acdirmin, Opt_acdirmax,
  78. Opt_actimeo,
  79. Opt_namelen,
  80. Opt_mountport,
  81. Opt_mountvers,
  82. Opt_nfsvers,
  83. /* Mount options that take string arguments */
  84. Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
  85. Opt_addr, Opt_mountaddr, Opt_clientaddr,
  86. /* Mount options that are ignored */
  87. Opt_userspace, Opt_deprecated,
  88. Opt_err
  89. };
  90. static match_table_t nfs_mount_option_tokens = {
  91. { Opt_userspace, "bg" },
  92. { Opt_userspace, "fg" },
  93. { Opt_userspace, "retry=%s" },
  94. { Opt_soft, "soft" },
  95. { Opt_hard, "hard" },
  96. { Opt_deprecated, "intr" },
  97. { Opt_deprecated, "nointr" },
  98. { Opt_posix, "posix" },
  99. { Opt_noposix, "noposix" },
  100. { Opt_cto, "cto" },
  101. { Opt_nocto, "nocto" },
  102. { Opt_ac, "ac" },
  103. { Opt_noac, "noac" },
  104. { Opt_lock, "lock" },
  105. { Opt_nolock, "nolock" },
  106. { Opt_v2, "v2" },
  107. { Opt_v3, "v3" },
  108. { Opt_udp, "udp" },
  109. { Opt_tcp, "tcp" },
  110. { Opt_rdma, "rdma" },
  111. { Opt_acl, "acl" },
  112. { Opt_noacl, "noacl" },
  113. { Opt_rdirplus, "rdirplus" },
  114. { Opt_nordirplus, "nordirplus" },
  115. { Opt_sharecache, "sharecache" },
  116. { Opt_nosharecache, "nosharecache" },
  117. { Opt_port, "port=%u" },
  118. { Opt_rsize, "rsize=%u" },
  119. { Opt_wsize, "wsize=%u" },
  120. { Opt_bsize, "bsize=%u" },
  121. { Opt_timeo, "timeo=%u" },
  122. { Opt_retrans, "retrans=%u" },
  123. { Opt_acregmin, "acregmin=%u" },
  124. { Opt_acregmax, "acregmax=%u" },
  125. { Opt_acdirmin, "acdirmin=%u" },
  126. { Opt_acdirmax, "acdirmax=%u" },
  127. { Opt_actimeo, "actimeo=%u" },
  128. { Opt_namelen, "namlen=%u" },
  129. { Opt_mountport, "mountport=%u" },
  130. { Opt_mountvers, "mountvers=%u" },
  131. { Opt_nfsvers, "nfsvers=%u" },
  132. { Opt_nfsvers, "vers=%u" },
  133. { Opt_sec, "sec=%s" },
  134. { Opt_proto, "proto=%s" },
  135. { Opt_mountproto, "mountproto=%s" },
  136. { Opt_addr, "addr=%s" },
  137. { Opt_clientaddr, "clientaddr=%s" },
  138. { Opt_mounthost, "mounthost=%s" },
  139. { Opt_mountaddr, "mountaddr=%s" },
  140. { Opt_err, NULL }
  141. };
  142. enum {
  143. Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
  144. Opt_xprt_err
  145. };
  146. static match_table_t nfs_xprt_protocol_tokens = {
  147. { Opt_xprt_udp, "udp" },
  148. { Opt_xprt_tcp, "tcp" },
  149. { Opt_xprt_rdma, "rdma" },
  150. { Opt_xprt_err, NULL }
  151. };
  152. enum {
  153. Opt_sec_none, Opt_sec_sys,
  154. Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
  155. Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
  156. Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
  157. Opt_sec_err
  158. };
  159. static match_table_t nfs_secflavor_tokens = {
  160. { Opt_sec_none, "none" },
  161. { Opt_sec_none, "null" },
  162. { Opt_sec_sys, "sys" },
  163. { Opt_sec_krb5, "krb5" },
  164. { Opt_sec_krb5i, "krb5i" },
  165. { Opt_sec_krb5p, "krb5p" },
  166. { Opt_sec_lkey, "lkey" },
  167. { Opt_sec_lkeyi, "lkeyi" },
  168. { Opt_sec_lkeyp, "lkeyp" },
  169. { Opt_sec_spkm, "spkm3" },
  170. { Opt_sec_spkmi, "spkm3i" },
  171. { Opt_sec_spkmp, "spkm3p" },
  172. { Opt_sec_err, NULL }
  173. };
  174. static void nfs_umount_begin(struct super_block *);
  175. static int nfs_statfs(struct dentry *, struct kstatfs *);
  176. static int nfs_show_options(struct seq_file *, struct vfsmount *);
  177. static int nfs_show_stats(struct seq_file *, struct vfsmount *);
  178. static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
  179. static int nfs_xdev_get_sb(struct file_system_type *fs_type,
  180. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  181. static void nfs_kill_super(struct super_block *);
  182. static void nfs_put_super(struct super_block *);
  183. static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
  184. static struct file_system_type nfs_fs_type = {
  185. .owner = THIS_MODULE,
  186. .name = "nfs",
  187. .get_sb = nfs_get_sb,
  188. .kill_sb = nfs_kill_super,
  189. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  190. };
  191. struct file_system_type nfs_xdev_fs_type = {
  192. .owner = THIS_MODULE,
  193. .name = "nfs",
  194. .get_sb = nfs_xdev_get_sb,
  195. .kill_sb = nfs_kill_super,
  196. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  197. };
  198. static const struct super_operations nfs_sops = {
  199. .alloc_inode = nfs_alloc_inode,
  200. .destroy_inode = nfs_destroy_inode,
  201. .write_inode = nfs_write_inode,
  202. .put_super = nfs_put_super,
  203. .statfs = nfs_statfs,
  204. .clear_inode = nfs_clear_inode,
  205. .umount_begin = nfs_umount_begin,
  206. .show_options = nfs_show_options,
  207. .show_stats = nfs_show_stats,
  208. .remount_fs = nfs_remount,
  209. };
  210. #ifdef CONFIG_NFS_V4
  211. static int nfs4_get_sb(struct file_system_type *fs_type,
  212. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  213. static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
  214. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  215. static int nfs4_referral_get_sb(struct file_system_type *fs_type,
  216. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  217. static void nfs4_kill_super(struct super_block *sb);
  218. static struct file_system_type nfs4_fs_type = {
  219. .owner = THIS_MODULE,
  220. .name = "nfs4",
  221. .get_sb = nfs4_get_sb,
  222. .kill_sb = nfs4_kill_super,
  223. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  224. };
  225. struct file_system_type nfs4_xdev_fs_type = {
  226. .owner = THIS_MODULE,
  227. .name = "nfs4",
  228. .get_sb = nfs4_xdev_get_sb,
  229. .kill_sb = nfs4_kill_super,
  230. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  231. };
  232. struct file_system_type nfs4_referral_fs_type = {
  233. .owner = THIS_MODULE,
  234. .name = "nfs4",
  235. .get_sb = nfs4_referral_get_sb,
  236. .kill_sb = nfs4_kill_super,
  237. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  238. };
  239. static const struct super_operations nfs4_sops = {
  240. .alloc_inode = nfs_alloc_inode,
  241. .destroy_inode = nfs_destroy_inode,
  242. .write_inode = nfs_write_inode,
  243. .statfs = nfs_statfs,
  244. .clear_inode = nfs4_clear_inode,
  245. .umount_begin = nfs_umount_begin,
  246. .show_options = nfs_show_options,
  247. .show_stats = nfs_show_stats,
  248. .remount_fs = nfs_remount,
  249. };
  250. #endif
  251. static struct shrinker acl_shrinker = {
  252. .shrink = nfs_access_cache_shrinker,
  253. .seeks = DEFAULT_SEEKS,
  254. };
  255. /*
  256. * Register the NFS filesystems
  257. */
  258. int __init register_nfs_fs(void)
  259. {
  260. int ret;
  261. ret = register_filesystem(&nfs_fs_type);
  262. if (ret < 0)
  263. goto error_0;
  264. ret = nfs_register_sysctl();
  265. if (ret < 0)
  266. goto error_1;
  267. #ifdef CONFIG_NFS_V4
  268. ret = register_filesystem(&nfs4_fs_type);
  269. if (ret < 0)
  270. goto error_2;
  271. #endif
  272. register_shrinker(&acl_shrinker);
  273. return 0;
  274. #ifdef CONFIG_NFS_V4
  275. error_2:
  276. nfs_unregister_sysctl();
  277. #endif
  278. error_1:
  279. unregister_filesystem(&nfs_fs_type);
  280. error_0:
  281. return ret;
  282. }
  283. /*
  284. * Unregister the NFS filesystems
  285. */
  286. void __exit unregister_nfs_fs(void)
  287. {
  288. unregister_shrinker(&acl_shrinker);
  289. #ifdef CONFIG_NFS_V4
  290. unregister_filesystem(&nfs4_fs_type);
  291. #endif
  292. nfs_unregister_sysctl();
  293. unregister_filesystem(&nfs_fs_type);
  294. }
  295. void nfs_sb_active(struct nfs_server *server)
  296. {
  297. atomic_inc(&server->active);
  298. }
  299. void nfs_sb_deactive(struct nfs_server *server)
  300. {
  301. if (atomic_dec_and_test(&server->active))
  302. wake_up(&server->active_wq);
  303. }
  304. static void nfs_put_super(struct super_block *sb)
  305. {
  306. struct nfs_server *server = NFS_SB(sb);
  307. /*
  308. * Make sure there are no outstanding ops to this server.
  309. * If so, wait for them to finish before allowing the
  310. * unmount to continue.
  311. */
  312. wait_event(server->active_wq, atomic_read(&server->active) == 0);
  313. }
  314. /*
  315. * Deliver file system statistics to userspace
  316. */
  317. static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  318. {
  319. struct nfs_server *server = NFS_SB(dentry->d_sb);
  320. unsigned char blockbits;
  321. unsigned long blockres;
  322. struct nfs_fh *fh = NFS_FH(dentry->d_inode);
  323. struct nfs_fattr fattr;
  324. struct nfs_fsstat res = {
  325. .fattr = &fattr,
  326. };
  327. int error;
  328. lock_kernel();
  329. error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
  330. if (error < 0)
  331. goto out_err;
  332. buf->f_type = NFS_SUPER_MAGIC;
  333. /*
  334. * Current versions of glibc do not correctly handle the
  335. * case where f_frsize != f_bsize. Eventually we want to
  336. * report the value of wtmult in this field.
  337. */
  338. buf->f_frsize = dentry->d_sb->s_blocksize;
  339. /*
  340. * On most *nix systems, f_blocks, f_bfree, and f_bavail
  341. * are reported in units of f_frsize. Linux hasn't had
  342. * an f_frsize field in its statfs struct until recently,
  343. * thus historically Linux's sys_statfs reports these
  344. * fields in units of f_bsize.
  345. */
  346. buf->f_bsize = dentry->d_sb->s_blocksize;
  347. blockbits = dentry->d_sb->s_blocksize_bits;
  348. blockres = (1 << blockbits) - 1;
  349. buf->f_blocks = (res.tbytes + blockres) >> blockbits;
  350. buf->f_bfree = (res.fbytes + blockres) >> blockbits;
  351. buf->f_bavail = (res.abytes + blockres) >> blockbits;
  352. buf->f_files = res.tfiles;
  353. buf->f_ffree = res.afiles;
  354. buf->f_namelen = server->namelen;
  355. unlock_kernel();
  356. return 0;
  357. out_err:
  358. dprintk("%s: statfs error = %d\n", __func__, -error);
  359. unlock_kernel();
  360. return error;
  361. }
  362. /*
  363. * Map the security flavour number to a name
  364. */
  365. static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
  366. {
  367. static const struct {
  368. rpc_authflavor_t flavour;
  369. const char *str;
  370. } sec_flavours[] = {
  371. { RPC_AUTH_NULL, "null" },
  372. { RPC_AUTH_UNIX, "sys" },
  373. { RPC_AUTH_GSS_KRB5, "krb5" },
  374. { RPC_AUTH_GSS_KRB5I, "krb5i" },
  375. { RPC_AUTH_GSS_KRB5P, "krb5p" },
  376. { RPC_AUTH_GSS_LKEY, "lkey" },
  377. { RPC_AUTH_GSS_LKEYI, "lkeyi" },
  378. { RPC_AUTH_GSS_LKEYP, "lkeyp" },
  379. { RPC_AUTH_GSS_SPKM, "spkm" },
  380. { RPC_AUTH_GSS_SPKMI, "spkmi" },
  381. { RPC_AUTH_GSS_SPKMP, "spkmp" },
  382. { UINT_MAX, "unknown" }
  383. };
  384. int i;
  385. for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
  386. if (sec_flavours[i].flavour == flavour)
  387. break;
  388. }
  389. return sec_flavours[i].str;
  390. }
  391. static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
  392. int showdefaults)
  393. {
  394. struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
  395. switch (sap->sa_family) {
  396. case AF_INET: {
  397. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  398. seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
  399. NIPQUAD(sin->sin_addr.s_addr));
  400. break;
  401. }
  402. case AF_INET6: {
  403. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  404. seq_printf(m, ",mountaddr=" NIP6_FMT,
  405. NIP6(sin6->sin6_addr));
  406. break;
  407. }
  408. default:
  409. if (showdefaults)
  410. seq_printf(m, ",mountaddr=unspecified");
  411. }
  412. if (nfss->mountd_version || showdefaults)
  413. seq_printf(m, ",mountvers=%u", nfss->mountd_version);
  414. if (nfss->mountd_port || showdefaults)
  415. seq_printf(m, ",mountport=%u", nfss->mountd_port);
  416. switch (nfss->mountd_protocol) {
  417. case IPPROTO_UDP:
  418. seq_printf(m, ",mountproto=udp");
  419. break;
  420. case IPPROTO_TCP:
  421. seq_printf(m, ",mountproto=tcp");
  422. break;
  423. default:
  424. if (showdefaults)
  425. seq_printf(m, ",mountproto=auto");
  426. }
  427. }
  428. /*
  429. * Describe the mount options in force on this server representation
  430. */
  431. static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
  432. int showdefaults)
  433. {
  434. static const struct proc_nfs_info {
  435. int flag;
  436. const char *str;
  437. const char *nostr;
  438. } nfs_info[] = {
  439. { NFS_MOUNT_SOFT, ",soft", ",hard" },
  440. { NFS_MOUNT_INTR, ",intr", ",nointr" },
  441. { NFS_MOUNT_POSIX, ",posix", "" },
  442. { NFS_MOUNT_NOCTO, ",nocto", "" },
  443. { NFS_MOUNT_NOAC, ",noac", "" },
  444. { NFS_MOUNT_NONLM, ",nolock", "" },
  445. { NFS_MOUNT_NOACL, ",noacl", "" },
  446. { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
  447. { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
  448. { 0, NULL, NULL }
  449. };
  450. const struct proc_nfs_info *nfs_infop;
  451. struct nfs_client *clp = nfss->nfs_client;
  452. u32 version = clp->rpc_ops->version;
  453. seq_printf(m, ",vers=%u", version);
  454. seq_printf(m, ",rsize=%u", nfss->rsize);
  455. seq_printf(m, ",wsize=%u", nfss->wsize);
  456. if (nfss->bsize != 0)
  457. seq_printf(m, ",bsize=%u", nfss->bsize);
  458. seq_printf(m, ",namlen=%u", nfss->namelen);
  459. if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
  460. seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
  461. if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
  462. seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
  463. if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
  464. seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
  465. if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
  466. seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
  467. for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
  468. if (nfss->flags & nfs_infop->flag)
  469. seq_puts(m, nfs_infop->str);
  470. else
  471. seq_puts(m, nfs_infop->nostr);
  472. }
  473. seq_printf(m, ",proto=%s",
  474. rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
  475. if (version == 4) {
  476. if (nfss->port != NFS_PORT)
  477. seq_printf(m, ",port=%u", nfss->port);
  478. } else
  479. if (nfss->port)
  480. seq_printf(m, ",port=%u", nfss->port);
  481. seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
  482. seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
  483. seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
  484. if (version != 4)
  485. nfs_show_mountd_options(m, nfss, showdefaults);
  486. #ifdef CONFIG_NFS_V4
  487. if (clp->rpc_ops->version == 4)
  488. seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
  489. #endif
  490. }
  491. /*
  492. * Describe the mount options on this VFS mountpoint
  493. */
  494. static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
  495. {
  496. struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
  497. nfs_show_mount_options(m, nfss, 0);
  498. seq_printf(m, ",addr=%s",
  499. rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
  500. RPC_DISPLAY_ADDR));
  501. return 0;
  502. }
  503. /*
  504. * Present statistical information for this VFS mountpoint
  505. */
  506. static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
  507. {
  508. int i, cpu;
  509. struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
  510. struct rpc_auth *auth = nfss->client->cl_auth;
  511. struct nfs_iostats totals = { };
  512. seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
  513. /*
  514. * Display all mount option settings
  515. */
  516. seq_printf(m, "\n\topts:\t");
  517. seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
  518. seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
  519. seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
  520. seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
  521. nfs_show_mount_options(m, nfss, 1);
  522. seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
  523. seq_printf(m, "\n\tcaps:\t");
  524. seq_printf(m, "caps=0x%x", nfss->caps);
  525. seq_printf(m, ",wtmult=%u", nfss->wtmult);
  526. seq_printf(m, ",dtsize=%u", nfss->dtsize);
  527. seq_printf(m, ",bsize=%u", nfss->bsize);
  528. seq_printf(m, ",namlen=%u", nfss->namelen);
  529. #ifdef CONFIG_NFS_V4
  530. if (nfss->nfs_client->rpc_ops->version == 4) {
  531. seq_printf(m, "\n\tnfsv4:\t");
  532. seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
  533. seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
  534. seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
  535. }
  536. #endif
  537. /*
  538. * Display security flavor in effect for this mount
  539. */
  540. seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
  541. if (auth->au_flavor)
  542. seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
  543. /*
  544. * Display superblock I/O counters
  545. */
  546. for_each_possible_cpu(cpu) {
  547. struct nfs_iostats *stats;
  548. preempt_disable();
  549. stats = per_cpu_ptr(nfss->io_stats, cpu);
  550. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  551. totals.events[i] += stats->events[i];
  552. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  553. totals.bytes[i] += stats->bytes[i];
  554. preempt_enable();
  555. }
  556. seq_printf(m, "\n\tevents:\t");
  557. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  558. seq_printf(m, "%lu ", totals.events[i]);
  559. seq_printf(m, "\n\tbytes:\t");
  560. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  561. seq_printf(m, "%Lu ", totals.bytes[i]);
  562. seq_printf(m, "\n");
  563. rpc_print_iostats(m, nfss->client);
  564. return 0;
  565. }
  566. /*
  567. * Begin unmount by attempting to remove all automounted mountpoints we added
  568. * in response to xdev traversals and referrals
  569. */
  570. static void nfs_umount_begin(struct super_block *sb)
  571. {
  572. struct nfs_server *server = NFS_SB(sb);
  573. struct rpc_clnt *rpc;
  574. /* -EIO all pending I/O */
  575. rpc = server->client_acl;
  576. if (!IS_ERR(rpc))
  577. rpc_killall_tasks(rpc);
  578. rpc = server->client;
  579. if (!IS_ERR(rpc))
  580. rpc_killall_tasks(rpc);
  581. }
  582. /*
  583. * Set the port number in an address. Be agnostic about the address family.
  584. */
  585. static void nfs_set_port(struct sockaddr *sap, unsigned short port)
  586. {
  587. switch (sap->sa_family) {
  588. case AF_INET: {
  589. struct sockaddr_in *ap = (struct sockaddr_in *)sap;
  590. ap->sin_port = htons(port);
  591. break;
  592. }
  593. case AF_INET6: {
  594. struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
  595. ap->sin6_port = htons(port);
  596. break;
  597. }
  598. }
  599. }
  600. /*
  601. * Sanity-check a server address provided by the mount command.
  602. *
  603. * Address family must be initialized, and address must not be
  604. * the ANY address for that family.
  605. */
  606. static int nfs_verify_server_address(struct sockaddr *addr)
  607. {
  608. switch (addr->sa_family) {
  609. case AF_INET: {
  610. struct sockaddr_in *sa = (struct sockaddr_in *)addr;
  611. return sa->sin_addr.s_addr != htonl(INADDR_ANY);
  612. }
  613. case AF_INET6: {
  614. struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
  615. return !ipv6_addr_any(sa);
  616. }
  617. }
  618. return 0;
  619. }
  620. static void nfs_parse_ipv4_address(char *string, size_t str_len,
  621. struct sockaddr *sap, size_t *addr_len)
  622. {
  623. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  624. u8 *addr = (u8 *)&sin->sin_addr.s_addr;
  625. if (str_len <= INET_ADDRSTRLEN) {
  626. dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
  627. (int)str_len, string);
  628. sin->sin_family = AF_INET;
  629. *addr_len = sizeof(*sin);
  630. if (in4_pton(string, str_len, addr, '\0', NULL))
  631. return;
  632. }
  633. sap->sa_family = AF_UNSPEC;
  634. *addr_len = 0;
  635. }
  636. #define IPV6_SCOPE_DELIMITER '%'
  637. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  638. static void nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
  639. const char *delim,
  640. struct sockaddr_in6 *sin6)
  641. {
  642. char *p;
  643. size_t len;
  644. if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
  645. return ;
  646. if (*delim != IPV6_SCOPE_DELIMITER)
  647. return;
  648. len = (string + str_len) - delim - 1;
  649. p = kstrndup(delim + 1, len, GFP_KERNEL);
  650. if (p) {
  651. unsigned long scope_id = 0;
  652. struct net_device *dev;
  653. dev = dev_get_by_name(&init_net, p);
  654. if (dev != NULL) {
  655. scope_id = dev->ifindex;
  656. dev_put(dev);
  657. } else {
  658. /* scope_id is set to zero on error */
  659. strict_strtoul(p, 10, &scope_id);
  660. }
  661. kfree(p);
  662. sin6->sin6_scope_id = scope_id;
  663. dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
  664. }
  665. }
  666. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  667. struct sockaddr *sap, size_t *addr_len)
  668. {
  669. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  670. u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
  671. const char *delim;
  672. if (str_len <= INET6_ADDRSTRLEN) {
  673. dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
  674. (int)str_len, string);
  675. sin6->sin6_family = AF_INET6;
  676. *addr_len = sizeof(*sin6);
  677. if (in6_pton(string, str_len, addr, IPV6_SCOPE_DELIMITER, &delim)) {
  678. nfs_parse_ipv6_scope_id(string, str_len, delim, sin6);
  679. return;
  680. }
  681. }
  682. sap->sa_family = AF_UNSPEC;
  683. *addr_len = 0;
  684. }
  685. #else
  686. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  687. struct sockaddr *sap, size_t *addr_len)
  688. {
  689. sap->sa_family = AF_UNSPEC;
  690. *addr_len = 0;
  691. }
  692. #endif
  693. /*
  694. * Construct a sockaddr based on the contents of a string that contains
  695. * an IP address in presentation format.
  696. *
  697. * If there is a problem constructing the new sockaddr, set the address
  698. * family to AF_UNSPEC.
  699. */
  700. static void nfs_parse_ip_address(char *string, size_t str_len,
  701. struct sockaddr *sap, size_t *addr_len)
  702. {
  703. unsigned int i, colons;
  704. colons = 0;
  705. for (i = 0; i < str_len; i++)
  706. if (string[i] == ':')
  707. colons++;
  708. if (colons >= 2)
  709. nfs_parse_ipv6_address(string, str_len, sap, addr_len);
  710. else
  711. nfs_parse_ipv4_address(string, str_len, sap, addr_len);
  712. }
  713. /*
  714. * Sanity check the NFS transport protocol.
  715. *
  716. */
  717. static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
  718. {
  719. switch (mnt->nfs_server.protocol) {
  720. case XPRT_TRANSPORT_UDP:
  721. case XPRT_TRANSPORT_TCP:
  722. case XPRT_TRANSPORT_RDMA:
  723. break;
  724. default:
  725. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  726. }
  727. }
  728. /*
  729. * For text based NFSv2/v3 mounts, the mount protocol transport default
  730. * settings should depend upon the specified NFS transport.
  731. */
  732. static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
  733. {
  734. nfs_validate_transport_protocol(mnt);
  735. if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
  736. mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
  737. return;
  738. switch (mnt->nfs_server.protocol) {
  739. case XPRT_TRANSPORT_UDP:
  740. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  741. break;
  742. case XPRT_TRANSPORT_TCP:
  743. case XPRT_TRANSPORT_RDMA:
  744. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  745. }
  746. }
  747. /*
  748. * Parse the value of the 'sec=' option.
  749. *
  750. * The flags setting is for v2/v3. The flavor_len setting is for v4.
  751. * v2/v3 also need to know the difference between NULL and UNIX.
  752. */
  753. static int nfs_parse_security_flavors(char *value,
  754. struct nfs_parsed_mount_data *mnt)
  755. {
  756. substring_t args[MAX_OPT_ARGS];
  757. dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
  758. switch (match_token(value, nfs_secflavor_tokens, args)) {
  759. case Opt_sec_none:
  760. mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
  761. mnt->auth_flavor_len = 0;
  762. mnt->auth_flavors[0] = RPC_AUTH_NULL;
  763. break;
  764. case Opt_sec_sys:
  765. mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
  766. mnt->auth_flavor_len = 0;
  767. mnt->auth_flavors[0] = RPC_AUTH_UNIX;
  768. break;
  769. case Opt_sec_krb5:
  770. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  771. mnt->auth_flavor_len = 1;
  772. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
  773. break;
  774. case Opt_sec_krb5i:
  775. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  776. mnt->auth_flavor_len = 1;
  777. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
  778. break;
  779. case Opt_sec_krb5p:
  780. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  781. mnt->auth_flavor_len = 1;
  782. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
  783. break;
  784. case Opt_sec_lkey:
  785. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  786. mnt->auth_flavor_len = 1;
  787. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
  788. break;
  789. case Opt_sec_lkeyi:
  790. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  791. mnt->auth_flavor_len = 1;
  792. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
  793. break;
  794. case Opt_sec_lkeyp:
  795. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  796. mnt->auth_flavor_len = 1;
  797. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
  798. break;
  799. case Opt_sec_spkm:
  800. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  801. mnt->auth_flavor_len = 1;
  802. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
  803. break;
  804. case Opt_sec_spkmi:
  805. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  806. mnt->auth_flavor_len = 1;
  807. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
  808. break;
  809. case Opt_sec_spkmp:
  810. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  811. mnt->auth_flavor_len = 1;
  812. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
  813. break;
  814. default:
  815. return 0;
  816. }
  817. return 1;
  818. }
  819. /*
  820. * Error-check and convert a string of mount options from user space into
  821. * a data structure
  822. */
  823. static int nfs_parse_mount_options(char *raw,
  824. struct nfs_parsed_mount_data *mnt)
  825. {
  826. char *p, *string, *secdata;
  827. int rc;
  828. if (!raw) {
  829. dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
  830. return 1;
  831. }
  832. dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
  833. secdata = alloc_secdata();
  834. if (!secdata)
  835. goto out_nomem;
  836. rc = security_sb_copy_data(raw, secdata);
  837. if (rc)
  838. goto out_security_failure;
  839. rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
  840. if (rc)
  841. goto out_security_failure;
  842. free_secdata(secdata);
  843. while ((p = strsep(&raw, ",")) != NULL) {
  844. substring_t args[MAX_OPT_ARGS];
  845. int option, token;
  846. if (!*p)
  847. continue;
  848. dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
  849. token = match_token(p, nfs_mount_option_tokens, args);
  850. switch (token) {
  851. case Opt_soft:
  852. mnt->flags |= NFS_MOUNT_SOFT;
  853. break;
  854. case Opt_hard:
  855. mnt->flags &= ~NFS_MOUNT_SOFT;
  856. break;
  857. case Opt_posix:
  858. mnt->flags |= NFS_MOUNT_POSIX;
  859. break;
  860. case Opt_noposix:
  861. mnt->flags &= ~NFS_MOUNT_POSIX;
  862. break;
  863. case Opt_cto:
  864. mnt->flags &= ~NFS_MOUNT_NOCTO;
  865. break;
  866. case Opt_nocto:
  867. mnt->flags |= NFS_MOUNT_NOCTO;
  868. break;
  869. case Opt_ac:
  870. mnt->flags &= ~NFS_MOUNT_NOAC;
  871. break;
  872. case Opt_noac:
  873. mnt->flags |= NFS_MOUNT_NOAC;
  874. break;
  875. case Opt_lock:
  876. mnt->flags &= ~NFS_MOUNT_NONLM;
  877. break;
  878. case Opt_nolock:
  879. mnt->flags |= NFS_MOUNT_NONLM;
  880. break;
  881. case Opt_v2:
  882. mnt->flags &= ~NFS_MOUNT_VER3;
  883. break;
  884. case Opt_v3:
  885. mnt->flags |= NFS_MOUNT_VER3;
  886. break;
  887. case Opt_udp:
  888. mnt->flags &= ~NFS_MOUNT_TCP;
  889. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  890. break;
  891. case Opt_tcp:
  892. mnt->flags |= NFS_MOUNT_TCP;
  893. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  894. break;
  895. case Opt_rdma:
  896. mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
  897. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  898. break;
  899. case Opt_acl:
  900. mnt->flags &= ~NFS_MOUNT_NOACL;
  901. break;
  902. case Opt_noacl:
  903. mnt->flags |= NFS_MOUNT_NOACL;
  904. break;
  905. case Opt_rdirplus:
  906. mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
  907. break;
  908. case Opt_nordirplus:
  909. mnt->flags |= NFS_MOUNT_NORDIRPLUS;
  910. break;
  911. case Opt_sharecache:
  912. mnt->flags &= ~NFS_MOUNT_UNSHARED;
  913. break;
  914. case Opt_nosharecache:
  915. mnt->flags |= NFS_MOUNT_UNSHARED;
  916. break;
  917. case Opt_port:
  918. if (match_int(args, &option))
  919. return 0;
  920. if (option < 0 || option > 65535)
  921. return 0;
  922. mnt->nfs_server.port = option;
  923. break;
  924. case Opt_rsize:
  925. if (match_int(args, &mnt->rsize))
  926. return 0;
  927. break;
  928. case Opt_wsize:
  929. if (match_int(args, &mnt->wsize))
  930. return 0;
  931. break;
  932. case Opt_bsize:
  933. if (match_int(args, &option))
  934. return 0;
  935. if (option < 0)
  936. return 0;
  937. mnt->bsize = option;
  938. break;
  939. case Opt_timeo:
  940. if (match_int(args, &mnt->timeo))
  941. return 0;
  942. break;
  943. case Opt_retrans:
  944. if (match_int(args, &mnt->retrans))
  945. return 0;
  946. break;
  947. case Opt_acregmin:
  948. if (match_int(args, &mnt->acregmin))
  949. return 0;
  950. break;
  951. case Opt_acregmax:
  952. if (match_int(args, &mnt->acregmax))
  953. return 0;
  954. break;
  955. case Opt_acdirmin:
  956. if (match_int(args, &mnt->acdirmin))
  957. return 0;
  958. break;
  959. case Opt_acdirmax:
  960. if (match_int(args, &mnt->acdirmax))
  961. return 0;
  962. break;
  963. case Opt_actimeo:
  964. if (match_int(args, &option))
  965. return 0;
  966. if (option < 0)
  967. return 0;
  968. mnt->acregmin =
  969. mnt->acregmax =
  970. mnt->acdirmin =
  971. mnt->acdirmax = option;
  972. break;
  973. case Opt_namelen:
  974. if (match_int(args, &mnt->namlen))
  975. return 0;
  976. break;
  977. case Opt_mountport:
  978. if (match_int(args, &option))
  979. return 0;
  980. if (option < 0 || option > 65535)
  981. return 0;
  982. mnt->mount_server.port = option;
  983. break;
  984. case Opt_mountvers:
  985. if (match_int(args, &option))
  986. return 0;
  987. if (option < 0)
  988. return 0;
  989. mnt->mount_server.version = option;
  990. break;
  991. case Opt_nfsvers:
  992. if (match_int(args, &option))
  993. return 0;
  994. switch (option) {
  995. case 2:
  996. mnt->flags &= ~NFS_MOUNT_VER3;
  997. break;
  998. case 3:
  999. mnt->flags |= NFS_MOUNT_VER3;
  1000. break;
  1001. default:
  1002. goto out_unrec_vers;
  1003. }
  1004. break;
  1005. case Opt_sec:
  1006. string = match_strdup(args);
  1007. if (string == NULL)
  1008. goto out_nomem;
  1009. rc = nfs_parse_security_flavors(string, mnt);
  1010. kfree(string);
  1011. if (!rc)
  1012. goto out_unrec_sec;
  1013. break;
  1014. case Opt_proto:
  1015. string = match_strdup(args);
  1016. if (string == NULL)
  1017. goto out_nomem;
  1018. token = match_token(string,
  1019. nfs_xprt_protocol_tokens, args);
  1020. kfree(string);
  1021. switch (token) {
  1022. case Opt_xprt_udp:
  1023. mnt->flags &= ~NFS_MOUNT_TCP;
  1024. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1025. break;
  1026. case Opt_xprt_tcp:
  1027. mnt->flags |= NFS_MOUNT_TCP;
  1028. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1029. break;
  1030. case Opt_xprt_rdma:
  1031. /* vector side protocols to TCP */
  1032. mnt->flags |= NFS_MOUNT_TCP;
  1033. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1034. break;
  1035. default:
  1036. goto out_unrec_xprt;
  1037. }
  1038. break;
  1039. case Opt_mountproto:
  1040. string = match_strdup(args);
  1041. if (string == NULL)
  1042. goto out_nomem;
  1043. token = match_token(string,
  1044. nfs_xprt_protocol_tokens, args);
  1045. kfree(string);
  1046. switch (token) {
  1047. case Opt_xprt_udp:
  1048. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  1049. break;
  1050. case Opt_xprt_tcp:
  1051. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  1052. break;
  1053. case Opt_xprt_rdma: /* not used for side protocols */
  1054. default:
  1055. goto out_unrec_xprt;
  1056. }
  1057. break;
  1058. case Opt_addr:
  1059. string = match_strdup(args);
  1060. if (string == NULL)
  1061. goto out_nomem;
  1062. nfs_parse_ip_address(string, strlen(string),
  1063. (struct sockaddr *)
  1064. &mnt->nfs_server.address,
  1065. &mnt->nfs_server.addrlen);
  1066. kfree(string);
  1067. break;
  1068. case Opt_clientaddr:
  1069. string = match_strdup(args);
  1070. if (string == NULL)
  1071. goto out_nomem;
  1072. kfree(mnt->client_address);
  1073. mnt->client_address = string;
  1074. break;
  1075. case Opt_mounthost:
  1076. string = match_strdup(args);
  1077. if (string == NULL)
  1078. goto out_nomem;
  1079. kfree(mnt->mount_server.hostname);
  1080. mnt->mount_server.hostname = string;
  1081. break;
  1082. case Opt_mountaddr:
  1083. string = match_strdup(args);
  1084. if (string == NULL)
  1085. goto out_nomem;
  1086. nfs_parse_ip_address(string, strlen(string),
  1087. (struct sockaddr *)
  1088. &mnt->mount_server.address,
  1089. &mnt->mount_server.addrlen);
  1090. kfree(string);
  1091. break;
  1092. case Opt_userspace:
  1093. case Opt_deprecated:
  1094. dfprintk(MOUNT, "NFS: ignoring mount option "
  1095. "'%s'\n", p);
  1096. break;
  1097. default:
  1098. goto out_unknown;
  1099. }
  1100. }
  1101. return 1;
  1102. out_nomem:
  1103. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  1104. return 0;
  1105. out_security_failure:
  1106. free_secdata(secdata);
  1107. printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
  1108. return 0;
  1109. out_unrec_vers:
  1110. printk(KERN_INFO "NFS: unrecognized NFS version number\n");
  1111. return 0;
  1112. out_unrec_xprt:
  1113. printk(KERN_INFO "NFS: unrecognized transport protocol\n");
  1114. return 0;
  1115. out_unrec_sec:
  1116. printk(KERN_INFO "NFS: unrecognized security flavor\n");
  1117. return 0;
  1118. out_unknown:
  1119. printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
  1120. return 0;
  1121. }
  1122. /*
  1123. * Use the remote server's MOUNT service to request the NFS file handle
  1124. * corresponding to the provided path.
  1125. */
  1126. static int nfs_try_mount(struct nfs_parsed_mount_data *args,
  1127. struct nfs_fh *root_fh)
  1128. {
  1129. struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
  1130. char *hostname;
  1131. int status;
  1132. if (args->mount_server.version == 0) {
  1133. if (args->flags & NFS_MOUNT_VER3)
  1134. args->mount_server.version = NFS_MNT3_VERSION;
  1135. else
  1136. args->mount_server.version = NFS_MNT_VERSION;
  1137. }
  1138. if (args->mount_server.hostname)
  1139. hostname = args->mount_server.hostname;
  1140. else
  1141. hostname = args->nfs_server.hostname;
  1142. /*
  1143. * Construct the mount server's address.
  1144. */
  1145. if (args->mount_server.address.ss_family == AF_UNSPEC) {
  1146. memcpy(sap, &args->nfs_server.address,
  1147. args->nfs_server.addrlen);
  1148. args->mount_server.addrlen = args->nfs_server.addrlen;
  1149. }
  1150. /*
  1151. * autobind will be used if mount_server.port == 0
  1152. */
  1153. nfs_set_port(sap, args->mount_server.port);
  1154. /*
  1155. * Now ask the mount server to map our export path
  1156. * to a file handle.
  1157. */
  1158. status = nfs_mount(sap,
  1159. args->mount_server.addrlen,
  1160. hostname,
  1161. args->nfs_server.export_path,
  1162. args->mount_server.version,
  1163. args->mount_server.protocol,
  1164. root_fh);
  1165. if (status == 0)
  1166. return 0;
  1167. dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
  1168. hostname, status);
  1169. return status;
  1170. }
  1171. static int nfs_parse_simple_hostname(const char *dev_name,
  1172. char **hostname, size_t maxnamlen,
  1173. char **export_path, size_t maxpathlen)
  1174. {
  1175. size_t len;
  1176. char *colon, *comma;
  1177. colon = strchr(dev_name, ':');
  1178. if (colon == NULL)
  1179. goto out_bad_devname;
  1180. len = colon - dev_name;
  1181. if (len > maxnamlen)
  1182. goto out_hostname;
  1183. /* N.B. caller will free nfs_server.hostname in all cases */
  1184. *hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1185. if (!*hostname)
  1186. goto out_nomem;
  1187. /* kill possible hostname list: not supported */
  1188. comma = strchr(*hostname, ',');
  1189. if (comma != NULL) {
  1190. if (comma == *hostname)
  1191. goto out_bad_devname;
  1192. *comma = '\0';
  1193. }
  1194. colon++;
  1195. len = strlen(colon);
  1196. if (len > maxpathlen)
  1197. goto out_path;
  1198. *export_path = kstrndup(colon, len, GFP_KERNEL);
  1199. if (!*export_path)
  1200. goto out_nomem;
  1201. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
  1202. return 0;
  1203. out_bad_devname:
  1204. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1205. return -EINVAL;
  1206. out_nomem:
  1207. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1208. return -ENOMEM;
  1209. out_hostname:
  1210. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1211. return -ENAMETOOLONG;
  1212. out_path:
  1213. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1214. return -ENAMETOOLONG;
  1215. }
  1216. /*
  1217. * Hostname has square brackets around it because it contains one or
  1218. * more colons. We look for the first closing square bracket, and a
  1219. * colon must follow it.
  1220. */
  1221. static int nfs_parse_protected_hostname(const char *dev_name,
  1222. char **hostname, size_t maxnamlen,
  1223. char **export_path, size_t maxpathlen)
  1224. {
  1225. size_t len;
  1226. char *start, *end;
  1227. start = (char *)(dev_name + 1);
  1228. end = strchr(start, ']');
  1229. if (end == NULL)
  1230. goto out_bad_devname;
  1231. if (*(end + 1) != ':')
  1232. goto out_bad_devname;
  1233. len = end - start;
  1234. if (len > maxnamlen)
  1235. goto out_hostname;
  1236. /* N.B. caller will free nfs_server.hostname in all cases */
  1237. *hostname = kstrndup(start, len, GFP_KERNEL);
  1238. if (*hostname == NULL)
  1239. goto out_nomem;
  1240. end += 2;
  1241. len = strlen(end);
  1242. if (len > maxpathlen)
  1243. goto out_path;
  1244. *export_path = kstrndup(end, len, GFP_KERNEL);
  1245. if (!*export_path)
  1246. goto out_nomem;
  1247. return 0;
  1248. out_bad_devname:
  1249. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1250. return -EINVAL;
  1251. out_nomem:
  1252. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1253. return -ENOMEM;
  1254. out_hostname:
  1255. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1256. return -ENAMETOOLONG;
  1257. out_path:
  1258. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1259. return -ENAMETOOLONG;
  1260. }
  1261. /*
  1262. * Split "dev_name" into "hostname:export_path".
  1263. *
  1264. * The leftmost colon demarks the split between the server's hostname
  1265. * and the export path. If the hostname starts with a left square
  1266. * bracket, then it may contain colons.
  1267. *
  1268. * Note: caller frees hostname and export path, even on error.
  1269. */
  1270. static int nfs_parse_devname(const char *dev_name,
  1271. char **hostname, size_t maxnamlen,
  1272. char **export_path, size_t maxpathlen)
  1273. {
  1274. if (*dev_name == '[')
  1275. return nfs_parse_protected_hostname(dev_name,
  1276. hostname, maxnamlen,
  1277. export_path, maxpathlen);
  1278. return nfs_parse_simple_hostname(dev_name,
  1279. hostname, maxnamlen,
  1280. export_path, maxpathlen);
  1281. }
  1282. /*
  1283. * Validate the NFS2/NFS3 mount data
  1284. * - fills in the mount root filehandle
  1285. *
  1286. * For option strings, user space handles the following behaviors:
  1287. *
  1288. * + DNS: mapping server host name to IP address ("addr=" option)
  1289. *
  1290. * + failure mode: how to behave if a mount request can't be handled
  1291. * immediately ("fg/bg" option)
  1292. *
  1293. * + retry: how often to retry a mount request ("retry=" option)
  1294. *
  1295. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  1296. * mountproto=tcp after mountproto=udp, and so on
  1297. */
  1298. static int nfs_validate_mount_data(void *options,
  1299. struct nfs_parsed_mount_data *args,
  1300. struct nfs_fh *mntfh,
  1301. const char *dev_name)
  1302. {
  1303. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  1304. if (data == NULL)
  1305. goto out_no_data;
  1306. args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
  1307. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1308. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1309. args->acregmin = NFS_DEF_ACREGMIN;
  1310. args->acregmax = NFS_DEF_ACREGMAX;
  1311. args->acdirmin = NFS_DEF_ACDIRMIN;
  1312. args->acdirmax = NFS_DEF_ACDIRMAX;
  1313. args->mount_server.port = 0; /* autobind unless user sets port */
  1314. args->nfs_server.port = 0; /* autobind unless user sets port */
  1315. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1316. switch (data->version) {
  1317. case 1:
  1318. data->namlen = 0;
  1319. case 2:
  1320. data->bsize = 0;
  1321. case 3:
  1322. if (data->flags & NFS_MOUNT_VER3)
  1323. goto out_no_v3;
  1324. data->root.size = NFS2_FHSIZE;
  1325. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  1326. case 4:
  1327. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1328. goto out_no_sec;
  1329. case 5:
  1330. memset(data->context, 0, sizeof(data->context));
  1331. case 6:
  1332. if (data->flags & NFS_MOUNT_VER3) {
  1333. if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
  1334. goto out_invalid_fh;
  1335. mntfh->size = data->root.size;
  1336. } else
  1337. mntfh->size = NFS2_FHSIZE;
  1338. memcpy(mntfh->data, data->root.data, mntfh->size);
  1339. if (mntfh->size < sizeof(mntfh->data))
  1340. memset(mntfh->data + mntfh->size, 0,
  1341. sizeof(mntfh->data) - mntfh->size);
  1342. /*
  1343. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1344. * can deal with.
  1345. */
  1346. args->flags = data->flags;
  1347. args->rsize = data->rsize;
  1348. args->wsize = data->wsize;
  1349. args->timeo = data->timeo;
  1350. args->retrans = data->retrans;
  1351. args->acregmin = data->acregmin;
  1352. args->acregmax = data->acregmax;
  1353. args->acdirmin = data->acdirmin;
  1354. args->acdirmax = data->acdirmax;
  1355. memcpy(&args->nfs_server.address, &data->addr,
  1356. sizeof(data->addr));
  1357. args->nfs_server.addrlen = sizeof(data->addr);
  1358. if (!nfs_verify_server_address((struct sockaddr *)
  1359. &args->nfs_server.address))
  1360. goto out_no_address;
  1361. if (!(data->flags & NFS_MOUNT_TCP))
  1362. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1363. /* N.B. caller will free nfs_server.hostname in all cases */
  1364. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1365. args->namlen = data->namlen;
  1366. args->bsize = data->bsize;
  1367. args->auth_flavors[0] = data->pseudoflavor;
  1368. if (!args->nfs_server.hostname)
  1369. goto out_nomem;
  1370. /*
  1371. * The legacy version 6 binary mount data from userspace has a
  1372. * field used only to transport selinux information into the
  1373. * the kernel. To continue to support that functionality we
  1374. * have a touch of selinux knowledge here in the NFS code. The
  1375. * userspace code converted context=blah to just blah so we are
  1376. * converting back to the full string selinux understands.
  1377. */
  1378. if (data->context[0]){
  1379. #ifdef CONFIG_SECURITY_SELINUX
  1380. int rc;
  1381. char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
  1382. if (!opts_str)
  1383. return -ENOMEM;
  1384. strcpy(opts_str, "context=");
  1385. data->context[NFS_MAX_CONTEXT_LEN] = '\0';
  1386. strcat(opts_str, &data->context[0]);
  1387. rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
  1388. kfree(opts_str);
  1389. if (rc)
  1390. return rc;
  1391. #else
  1392. return -EINVAL;
  1393. #endif
  1394. }
  1395. break;
  1396. default: {
  1397. int status;
  1398. if (nfs_parse_mount_options((char *)options, args) == 0)
  1399. return -EINVAL;
  1400. if (!nfs_verify_server_address((struct sockaddr *)
  1401. &args->nfs_server.address))
  1402. goto out_no_address;
  1403. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1404. args->nfs_server.port);
  1405. nfs_set_mount_transport_protocol(args);
  1406. status = nfs_parse_devname(dev_name,
  1407. &args->nfs_server.hostname,
  1408. PAGE_SIZE,
  1409. &args->nfs_server.export_path,
  1410. NFS_MAXPATHLEN);
  1411. if (!status)
  1412. status = nfs_try_mount(args, mntfh);
  1413. kfree(args->nfs_server.export_path);
  1414. args->nfs_server.export_path = NULL;
  1415. if (status)
  1416. return status;
  1417. break;
  1418. }
  1419. }
  1420. if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
  1421. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1422. #ifndef CONFIG_NFS_V3
  1423. if (args->flags & NFS_MOUNT_VER3)
  1424. goto out_v3_not_compiled;
  1425. #endif /* !CONFIG_NFS_V3 */
  1426. return 0;
  1427. out_no_data:
  1428. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1429. return -EINVAL;
  1430. out_no_v3:
  1431. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1432. data->version);
  1433. return -EINVAL;
  1434. out_no_sec:
  1435. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1436. return -EINVAL;
  1437. #ifndef CONFIG_NFS_V3
  1438. out_v3_not_compiled:
  1439. dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
  1440. return -EPROTONOSUPPORT;
  1441. #endif /* !CONFIG_NFS_V3 */
  1442. out_nomem:
  1443. dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
  1444. return -ENOMEM;
  1445. out_no_address:
  1446. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1447. return -EINVAL;
  1448. out_invalid_fh:
  1449. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1450. return -EINVAL;
  1451. }
  1452. static int
  1453. nfs_compare_remount_data(struct nfs_server *nfss,
  1454. struct nfs_parsed_mount_data *data)
  1455. {
  1456. if (data->flags != nfss->flags ||
  1457. data->rsize != nfss->rsize ||
  1458. data->wsize != nfss->wsize ||
  1459. data->retrans != nfss->client->cl_timeout->to_retries ||
  1460. data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
  1461. data->acregmin != nfss->acregmin / HZ ||
  1462. data->acregmax != nfss->acregmax / HZ ||
  1463. data->acdirmin != nfss->acdirmin / HZ ||
  1464. data->acdirmax != nfss->acdirmax / HZ ||
  1465. data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
  1466. data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
  1467. memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1468. data->nfs_server.addrlen) != 0)
  1469. return -EINVAL;
  1470. return 0;
  1471. }
  1472. static int
  1473. nfs_remount(struct super_block *sb, int *flags, char *raw_data)
  1474. {
  1475. int error;
  1476. struct nfs_server *nfss = sb->s_fs_info;
  1477. struct nfs_parsed_mount_data *data;
  1478. struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
  1479. struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
  1480. u32 nfsvers = nfss->nfs_client->rpc_ops->version;
  1481. /*
  1482. * Userspace mount programs that send binary options generally send
  1483. * them populated with default values. We have no way to know which
  1484. * ones were explicitly specified. Fall back to legacy behavior and
  1485. * just return success.
  1486. */
  1487. if ((nfsvers == 4 && options4->version == 1) ||
  1488. (nfsvers <= 3 && options->version >= 1 &&
  1489. options->version <= 6))
  1490. return 0;
  1491. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1492. if (data == NULL)
  1493. return -ENOMEM;
  1494. /* fill out struct with values from existing mount */
  1495. data->flags = nfss->flags;
  1496. data->rsize = nfss->rsize;
  1497. data->wsize = nfss->wsize;
  1498. data->retrans = nfss->client->cl_timeout->to_retries;
  1499. data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
  1500. data->acregmin = nfss->acregmin / HZ;
  1501. data->acregmax = nfss->acregmax / HZ;
  1502. data->acdirmin = nfss->acdirmin / HZ;
  1503. data->acdirmax = nfss->acdirmax / HZ;
  1504. data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
  1505. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  1506. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1507. data->nfs_server.addrlen);
  1508. /* overwrite those values with any that were specified */
  1509. error = nfs_parse_mount_options((char *)options, data);
  1510. if (error < 0)
  1511. goto out;
  1512. /* compare new mount options with old ones */
  1513. error = nfs_compare_remount_data(nfss, data);
  1514. out:
  1515. kfree(data);
  1516. return error;
  1517. }
  1518. /*
  1519. * Initialise the common bits of the superblock
  1520. */
  1521. static inline void nfs_initialise_sb(struct super_block *sb)
  1522. {
  1523. struct nfs_server *server = NFS_SB(sb);
  1524. sb->s_magic = NFS_SUPER_MAGIC;
  1525. /* We probably want something more informative here */
  1526. snprintf(sb->s_id, sizeof(sb->s_id),
  1527. "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  1528. if (sb->s_blocksize == 0)
  1529. sb->s_blocksize = nfs_block_bits(server->wsize,
  1530. &sb->s_blocksize_bits);
  1531. if (server->flags & NFS_MOUNT_NOAC)
  1532. sb->s_flags |= MS_SYNCHRONOUS;
  1533. nfs_super_set_maxbytes(sb, server->maxfilesize);
  1534. }
  1535. /*
  1536. * Finish setting up an NFS2/3 superblock
  1537. */
  1538. static void nfs_fill_super(struct super_block *sb,
  1539. struct nfs_parsed_mount_data *data)
  1540. {
  1541. struct nfs_server *server = NFS_SB(sb);
  1542. sb->s_blocksize_bits = 0;
  1543. sb->s_blocksize = 0;
  1544. if (data->bsize)
  1545. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  1546. if (server->flags & NFS_MOUNT_VER3) {
  1547. /* The VFS shouldn't apply the umask to mode bits. We will do
  1548. * so ourselves when necessary.
  1549. */
  1550. sb->s_flags |= MS_POSIXACL;
  1551. sb->s_time_gran = 1;
  1552. }
  1553. sb->s_op = &nfs_sops;
  1554. nfs_initialise_sb(sb);
  1555. }
  1556. /*
  1557. * Finish setting up a cloned NFS2/3 superblock
  1558. */
  1559. static void nfs_clone_super(struct super_block *sb,
  1560. const struct super_block *old_sb)
  1561. {
  1562. struct nfs_server *server = NFS_SB(sb);
  1563. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1564. sb->s_blocksize = old_sb->s_blocksize;
  1565. sb->s_maxbytes = old_sb->s_maxbytes;
  1566. if (server->flags & NFS_MOUNT_VER3) {
  1567. /* The VFS shouldn't apply the umask to mode bits. We will do
  1568. * so ourselves when necessary.
  1569. */
  1570. sb->s_flags |= MS_POSIXACL;
  1571. sb->s_time_gran = 1;
  1572. }
  1573. sb->s_op = old_sb->s_op;
  1574. nfs_initialise_sb(sb);
  1575. }
  1576. #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
  1577. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  1578. {
  1579. const struct nfs_server *a = s->s_fs_info;
  1580. const struct rpc_clnt *clnt_a = a->client;
  1581. const struct rpc_clnt *clnt_b = b->client;
  1582. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  1583. goto Ebusy;
  1584. if (a->nfs_client != b->nfs_client)
  1585. goto Ebusy;
  1586. if (a->flags != b->flags)
  1587. goto Ebusy;
  1588. if (a->wsize != b->wsize)
  1589. goto Ebusy;
  1590. if (a->rsize != b->rsize)
  1591. goto Ebusy;
  1592. if (a->acregmin != b->acregmin)
  1593. goto Ebusy;
  1594. if (a->acregmax != b->acregmax)
  1595. goto Ebusy;
  1596. if (a->acdirmin != b->acdirmin)
  1597. goto Ebusy;
  1598. if (a->acdirmax != b->acdirmax)
  1599. goto Ebusy;
  1600. if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  1601. goto Ebusy;
  1602. return 1;
  1603. Ebusy:
  1604. return 0;
  1605. }
  1606. struct nfs_sb_mountdata {
  1607. struct nfs_server *server;
  1608. int mntflags;
  1609. };
  1610. static int nfs_set_super(struct super_block *s, void *data)
  1611. {
  1612. struct nfs_sb_mountdata *sb_mntdata = data;
  1613. struct nfs_server *server = sb_mntdata->server;
  1614. int ret;
  1615. s->s_flags = sb_mntdata->mntflags;
  1616. s->s_fs_info = server;
  1617. ret = set_anon_super(s, server);
  1618. if (ret == 0)
  1619. server->s_dev = s->s_dev;
  1620. return ret;
  1621. }
  1622. static int nfs_compare_super_address(struct nfs_server *server1,
  1623. struct nfs_server *server2)
  1624. {
  1625. struct sockaddr *sap1, *sap2;
  1626. sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
  1627. sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
  1628. if (sap1->sa_family != sap2->sa_family)
  1629. return 0;
  1630. switch (sap1->sa_family) {
  1631. case AF_INET: {
  1632. struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
  1633. struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
  1634. if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
  1635. return 0;
  1636. if (sin1->sin_port != sin2->sin_port)
  1637. return 0;
  1638. break;
  1639. }
  1640. case AF_INET6: {
  1641. struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
  1642. struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
  1643. if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
  1644. return 0;
  1645. if (sin1->sin6_port != sin2->sin6_port)
  1646. return 0;
  1647. break;
  1648. }
  1649. default:
  1650. return 0;
  1651. }
  1652. return 1;
  1653. }
  1654. static int nfs_compare_super(struct super_block *sb, void *data)
  1655. {
  1656. struct nfs_sb_mountdata *sb_mntdata = data;
  1657. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  1658. int mntflags = sb_mntdata->mntflags;
  1659. if (!nfs_compare_super_address(old, server))
  1660. return 0;
  1661. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  1662. if (old->flags & NFS_MOUNT_UNSHARED)
  1663. return 0;
  1664. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  1665. return 0;
  1666. return nfs_compare_mount_options(sb, server, mntflags);
  1667. }
  1668. static int nfs_bdi_register(struct nfs_server *server)
  1669. {
  1670. return bdi_register_dev(&server->backing_dev_info, server->s_dev);
  1671. }
  1672. static int nfs_get_sb(struct file_system_type *fs_type,
  1673. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1674. {
  1675. struct nfs_server *server = NULL;
  1676. struct super_block *s;
  1677. struct nfs_parsed_mount_data *data;
  1678. struct nfs_fh *mntfh;
  1679. struct dentry *mntroot;
  1680. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1681. struct nfs_sb_mountdata sb_mntdata = {
  1682. .mntflags = flags,
  1683. };
  1684. int error = -ENOMEM;
  1685. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1686. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  1687. if (data == NULL || mntfh == NULL)
  1688. goto out_free_fh;
  1689. security_init_mnt_opts(&data->lsm_opts);
  1690. /* Validate the mount data */
  1691. error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
  1692. if (error < 0)
  1693. goto out;
  1694. /* Get a volume representation */
  1695. server = nfs_create_server(data, mntfh);
  1696. if (IS_ERR(server)) {
  1697. error = PTR_ERR(server);
  1698. goto out;
  1699. }
  1700. sb_mntdata.server = server;
  1701. if (server->flags & NFS_MOUNT_UNSHARED)
  1702. compare_super = NULL;
  1703. /* Get a superblock - note that we may end up sharing one that already exists */
  1704. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1705. if (IS_ERR(s)) {
  1706. error = PTR_ERR(s);
  1707. goto out_err_nosb;
  1708. }
  1709. if (s->s_fs_info != server) {
  1710. nfs_free_server(server);
  1711. server = NULL;
  1712. } else {
  1713. error = nfs_bdi_register(server);
  1714. if (error)
  1715. goto error_splat_super;
  1716. }
  1717. if (!s->s_root) {
  1718. /* initial superblock/root creation */
  1719. nfs_fill_super(s, data);
  1720. }
  1721. mntroot = nfs_get_root(s, mntfh);
  1722. if (IS_ERR(mntroot)) {
  1723. error = PTR_ERR(mntroot);
  1724. goto error_splat_super;
  1725. }
  1726. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  1727. if (error)
  1728. goto error_splat_root;
  1729. s->s_flags |= MS_ACTIVE;
  1730. mnt->mnt_sb = s;
  1731. mnt->mnt_root = mntroot;
  1732. error = 0;
  1733. out:
  1734. kfree(data->nfs_server.hostname);
  1735. kfree(data->mount_server.hostname);
  1736. security_free_mnt_opts(&data->lsm_opts);
  1737. out_free_fh:
  1738. kfree(mntfh);
  1739. kfree(data);
  1740. return error;
  1741. out_err_nosb:
  1742. nfs_free_server(server);
  1743. goto out;
  1744. error_splat_root:
  1745. dput(mntroot);
  1746. error_splat_super:
  1747. up_write(&s->s_umount);
  1748. deactivate_super(s);
  1749. goto out;
  1750. }
  1751. /*
  1752. * Destroy an NFS2/3 superblock
  1753. */
  1754. static void nfs_kill_super(struct super_block *s)
  1755. {
  1756. struct nfs_server *server = NFS_SB(s);
  1757. bdi_unregister(&server->backing_dev_info);
  1758. kill_anon_super(s);
  1759. nfs_free_server(server);
  1760. }
  1761. /*
  1762. * Clone an NFS2/3 server record on xdev traversal (FSID-change)
  1763. */
  1764. static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1765. const char *dev_name, void *raw_data,
  1766. struct vfsmount *mnt)
  1767. {
  1768. struct nfs_clone_mount *data = raw_data;
  1769. struct super_block *s;
  1770. struct nfs_server *server;
  1771. struct dentry *mntroot;
  1772. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1773. struct nfs_sb_mountdata sb_mntdata = {
  1774. .mntflags = flags,
  1775. };
  1776. int error;
  1777. dprintk("--> nfs_xdev_get_sb()\n");
  1778. /* create a new volume representation */
  1779. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1780. if (IS_ERR(server)) {
  1781. error = PTR_ERR(server);
  1782. goto out_err_noserver;
  1783. }
  1784. sb_mntdata.server = server;
  1785. if (server->flags & NFS_MOUNT_UNSHARED)
  1786. compare_super = NULL;
  1787. /* Get a superblock - note that we may end up sharing one that already exists */
  1788. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1789. if (IS_ERR(s)) {
  1790. error = PTR_ERR(s);
  1791. goto out_err_nosb;
  1792. }
  1793. if (s->s_fs_info != server) {
  1794. nfs_free_server(server);
  1795. server = NULL;
  1796. } else {
  1797. error = nfs_bdi_register(server);
  1798. if (error)
  1799. goto error_splat_super;
  1800. }
  1801. if (!s->s_root) {
  1802. /* initial superblock/root creation */
  1803. nfs_clone_super(s, data->sb);
  1804. }
  1805. mntroot = nfs_get_root(s, data->fh);
  1806. if (IS_ERR(mntroot)) {
  1807. error = PTR_ERR(mntroot);
  1808. goto error_splat_super;
  1809. }
  1810. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  1811. dput(mntroot);
  1812. error = -ESTALE;
  1813. goto error_splat_super;
  1814. }
  1815. s->s_flags |= MS_ACTIVE;
  1816. mnt->mnt_sb = s;
  1817. mnt->mnt_root = mntroot;
  1818. /* clone any lsm security options from the parent to the new sb */
  1819. security_sb_clone_mnt_opts(data->sb, s);
  1820. dprintk("<-- nfs_xdev_get_sb() = 0\n");
  1821. return 0;
  1822. out_err_nosb:
  1823. nfs_free_server(server);
  1824. out_err_noserver:
  1825. dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
  1826. return error;
  1827. error_splat_super:
  1828. up_write(&s->s_umount);
  1829. deactivate_super(s);
  1830. dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
  1831. return error;
  1832. }
  1833. #ifdef CONFIG_NFS_V4
  1834. /*
  1835. * Finish setting up a cloned NFS4 superblock
  1836. */
  1837. static void nfs4_clone_super(struct super_block *sb,
  1838. const struct super_block *old_sb)
  1839. {
  1840. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1841. sb->s_blocksize = old_sb->s_blocksize;
  1842. sb->s_maxbytes = old_sb->s_maxbytes;
  1843. sb->s_time_gran = 1;
  1844. sb->s_op = old_sb->s_op;
  1845. nfs_initialise_sb(sb);
  1846. }
  1847. /*
  1848. * Set up an NFS4 superblock
  1849. */
  1850. static void nfs4_fill_super(struct super_block *sb)
  1851. {
  1852. sb->s_time_gran = 1;
  1853. sb->s_op = &nfs4_sops;
  1854. nfs_initialise_sb(sb);
  1855. }
  1856. /*
  1857. * Validate NFSv4 mount options
  1858. */
  1859. static int nfs4_validate_mount_data(void *options,
  1860. struct nfs_parsed_mount_data *args,
  1861. const char *dev_name)
  1862. {
  1863. struct sockaddr_in *ap;
  1864. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  1865. char *c;
  1866. if (data == NULL)
  1867. goto out_no_data;
  1868. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1869. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1870. args->acregmin = NFS_DEF_ACREGMIN;
  1871. args->acregmax = NFS_DEF_ACREGMAX;
  1872. args->acdirmin = NFS_DEF_ACDIRMIN;
  1873. args->acdirmax = NFS_DEF_ACDIRMAX;
  1874. args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
  1875. switch (data->version) {
  1876. case 1:
  1877. ap = (struct sockaddr_in *)&args->nfs_server.address;
  1878. if (data->host_addrlen > sizeof(args->nfs_server.address))
  1879. goto out_no_address;
  1880. if (data->host_addrlen == 0)
  1881. goto out_no_address;
  1882. args->nfs_server.addrlen = data->host_addrlen;
  1883. if (copy_from_user(ap, data->host_addr, data->host_addrlen))
  1884. return -EFAULT;
  1885. if (!nfs_verify_server_address((struct sockaddr *)
  1886. &args->nfs_server.address))
  1887. goto out_no_address;
  1888. switch (data->auth_flavourlen) {
  1889. case 0:
  1890. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1891. break;
  1892. case 1:
  1893. if (copy_from_user(&args->auth_flavors[0],
  1894. data->auth_flavours,
  1895. sizeof(args->auth_flavors[0])))
  1896. return -EFAULT;
  1897. break;
  1898. default:
  1899. goto out_inval_auth;
  1900. }
  1901. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  1902. if (IS_ERR(c))
  1903. return PTR_ERR(c);
  1904. args->nfs_server.hostname = c;
  1905. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  1906. if (IS_ERR(c))
  1907. return PTR_ERR(c);
  1908. args->nfs_server.export_path = c;
  1909. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  1910. c = strndup_user(data->client_addr.data, 16);
  1911. if (IS_ERR(c))
  1912. return PTR_ERR(c);
  1913. args->client_address = c;
  1914. /*
  1915. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  1916. * can deal with.
  1917. */
  1918. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  1919. args->rsize = data->rsize;
  1920. args->wsize = data->wsize;
  1921. args->timeo = data->timeo;
  1922. args->retrans = data->retrans;
  1923. args->acregmin = data->acregmin;
  1924. args->acregmax = data->acregmax;
  1925. args->acdirmin = data->acdirmin;
  1926. args->acdirmax = data->acdirmax;
  1927. args->nfs_server.protocol = data->proto;
  1928. nfs_validate_transport_protocol(args);
  1929. break;
  1930. default: {
  1931. int status;
  1932. if (nfs_parse_mount_options((char *)options, args) == 0)
  1933. return -EINVAL;
  1934. if (!nfs_verify_server_address((struct sockaddr *)
  1935. &args->nfs_server.address))
  1936. return -EINVAL;
  1937. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1938. args->nfs_server.port);
  1939. nfs_validate_transport_protocol(args);
  1940. switch (args->auth_flavor_len) {
  1941. case 0:
  1942. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1943. break;
  1944. case 1:
  1945. break;
  1946. default:
  1947. goto out_inval_auth;
  1948. }
  1949. if (args->client_address == NULL)
  1950. goto out_no_client_address;
  1951. status = nfs_parse_devname(dev_name,
  1952. &args->nfs_server.hostname,
  1953. NFS4_MAXNAMLEN,
  1954. &args->nfs_server.export_path,
  1955. NFS4_MAXPATHLEN);
  1956. if (status < 0)
  1957. return status;
  1958. break;
  1959. }
  1960. }
  1961. return 0;
  1962. out_no_data:
  1963. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  1964. return -EINVAL;
  1965. out_inval_auth:
  1966. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  1967. data->auth_flavourlen);
  1968. return -EINVAL;
  1969. out_no_address:
  1970. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  1971. return -EINVAL;
  1972. out_no_client_address:
  1973. dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
  1974. return -EINVAL;
  1975. }
  1976. /*
  1977. * Get the superblock for an NFS4 mountpoint
  1978. */
  1979. static int nfs4_get_sb(struct file_system_type *fs_type,
  1980. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1981. {
  1982. struct nfs_parsed_mount_data *data;
  1983. struct super_block *s;
  1984. struct nfs_server *server;
  1985. struct nfs_fh *mntfh;
  1986. struct dentry *mntroot;
  1987. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1988. struct nfs_sb_mountdata sb_mntdata = {
  1989. .mntflags = flags,
  1990. };
  1991. int error = -ENOMEM;
  1992. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1993. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  1994. if (data == NULL || mntfh == NULL)
  1995. goto out_free_fh;
  1996. security_init_mnt_opts(&data->lsm_opts);
  1997. /* Validate the mount data */
  1998. error = nfs4_validate_mount_data(raw_data, data, dev_name);
  1999. if (error < 0)
  2000. goto out;
  2001. /* Get a volume representation */
  2002. server = nfs4_create_server(data, mntfh);
  2003. if (IS_ERR(server)) {
  2004. error = PTR_ERR(server);
  2005. goto out;
  2006. }
  2007. sb_mntdata.server = server;
  2008. if (server->flags & NFS4_MOUNT_UNSHARED)
  2009. compare_super = NULL;
  2010. /* Get a superblock - note that we may end up sharing one that already exists */
  2011. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2012. if (IS_ERR(s)) {
  2013. error = PTR_ERR(s);
  2014. goto out_free;
  2015. }
  2016. if (s->s_fs_info != server) {
  2017. nfs_free_server(server);
  2018. server = NULL;
  2019. } else {
  2020. error = nfs_bdi_register(server);
  2021. if (error)
  2022. goto error_splat_super;
  2023. }
  2024. if (!s->s_root) {
  2025. /* initial superblock/root creation */
  2026. nfs4_fill_super(s);
  2027. }
  2028. mntroot = nfs4_get_root(s, mntfh);
  2029. if (IS_ERR(mntroot)) {
  2030. error = PTR_ERR(mntroot);
  2031. goto error_splat_super;
  2032. }
  2033. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  2034. if (error)
  2035. goto error_splat_root;
  2036. s->s_flags |= MS_ACTIVE;
  2037. mnt->mnt_sb = s;
  2038. mnt->mnt_root = mntroot;
  2039. error = 0;
  2040. out:
  2041. kfree(data->client_address);
  2042. kfree(data->nfs_server.export_path);
  2043. kfree(data->nfs_server.hostname);
  2044. security_free_mnt_opts(&data->lsm_opts);
  2045. out_free_fh:
  2046. kfree(mntfh);
  2047. kfree(data);
  2048. return error;
  2049. out_free:
  2050. nfs_free_server(server);
  2051. goto out;
  2052. error_splat_root:
  2053. dput(mntroot);
  2054. error_splat_super:
  2055. up_write(&s->s_umount);
  2056. deactivate_super(s);
  2057. goto out;
  2058. }
  2059. static void nfs4_kill_super(struct super_block *sb)
  2060. {
  2061. struct nfs_server *server = NFS_SB(sb);
  2062. nfs_return_all_delegations(sb);
  2063. kill_anon_super(sb);
  2064. nfs4_renewd_prepare_shutdown(server);
  2065. nfs_free_server(server);
  2066. }
  2067. /*
  2068. * Clone an NFS4 server record on xdev traversal (FSID-change)
  2069. */
  2070. static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
  2071. const char *dev_name, void *raw_data,
  2072. struct vfsmount *mnt)
  2073. {
  2074. struct nfs_clone_mount *data = raw_data;
  2075. struct super_block *s;
  2076. struct nfs_server *server;
  2077. struct dentry *mntroot;
  2078. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2079. struct nfs_sb_mountdata sb_mntdata = {
  2080. .mntflags = flags,
  2081. };
  2082. int error;
  2083. dprintk("--> nfs4_xdev_get_sb()\n");
  2084. /* create a new volume representation */
  2085. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  2086. if (IS_ERR(server)) {
  2087. error = PTR_ERR(server);
  2088. goto out_err_noserver;
  2089. }
  2090. sb_mntdata.server = server;
  2091. if (server->flags & NFS4_MOUNT_UNSHARED)
  2092. compare_super = NULL;
  2093. /* Get a superblock - note that we may end up sharing one that already exists */
  2094. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2095. if (IS_ERR(s)) {
  2096. error = PTR_ERR(s);
  2097. goto out_err_nosb;
  2098. }
  2099. if (s->s_fs_info != server) {
  2100. nfs_free_server(server);
  2101. server = NULL;
  2102. } else {
  2103. error = nfs_bdi_register(server);
  2104. if (error)
  2105. goto error_splat_super;
  2106. }
  2107. if (!s->s_root) {
  2108. /* initial superblock/root creation */
  2109. nfs4_clone_super(s, data->sb);
  2110. }
  2111. mntroot = nfs4_get_root(s, data->fh);
  2112. if (IS_ERR(mntroot)) {
  2113. error = PTR_ERR(mntroot);
  2114. goto error_splat_super;
  2115. }
  2116. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2117. dput(mntroot);
  2118. error = -ESTALE;
  2119. goto error_splat_super;
  2120. }
  2121. s->s_flags |= MS_ACTIVE;
  2122. mnt->mnt_sb = s;
  2123. mnt->mnt_root = mntroot;
  2124. security_sb_clone_mnt_opts(data->sb, s);
  2125. dprintk("<-- nfs4_xdev_get_sb() = 0\n");
  2126. return 0;
  2127. out_err_nosb:
  2128. nfs_free_server(server);
  2129. out_err_noserver:
  2130. dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
  2131. return error;
  2132. error_splat_super:
  2133. up_write(&s->s_umount);
  2134. deactivate_super(s);
  2135. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  2136. return error;
  2137. }
  2138. /*
  2139. * Create an NFS4 server record on referral traversal
  2140. */
  2141. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  2142. const char *dev_name, void *raw_data,
  2143. struct vfsmount *mnt)
  2144. {
  2145. struct nfs_clone_mount *data = raw_data;
  2146. struct super_block *s;
  2147. struct nfs_server *server;
  2148. struct dentry *mntroot;
  2149. struct nfs_fh mntfh;
  2150. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2151. struct nfs_sb_mountdata sb_mntdata = {
  2152. .mntflags = flags,
  2153. };
  2154. int error;
  2155. dprintk("--> nfs4_referral_get_sb()\n");
  2156. /* create a new volume representation */
  2157. server = nfs4_create_referral_server(data, &mntfh);
  2158. if (IS_ERR(server)) {
  2159. error = PTR_ERR(server);
  2160. goto out_err_noserver;
  2161. }
  2162. sb_mntdata.server = server;
  2163. if (server->flags & NFS4_MOUNT_UNSHARED)
  2164. compare_super = NULL;
  2165. /* Get a superblock - note that we may end up sharing one that already exists */
  2166. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2167. if (IS_ERR(s)) {
  2168. error = PTR_ERR(s);
  2169. goto out_err_nosb;
  2170. }
  2171. if (s->s_fs_info != server) {
  2172. nfs_free_server(server);
  2173. server = NULL;
  2174. } else {
  2175. error = nfs_bdi_register(server);
  2176. if (error)
  2177. goto error_splat_super;
  2178. }
  2179. if (!s->s_root) {
  2180. /* initial superblock/root creation */
  2181. nfs4_fill_super(s);
  2182. }
  2183. mntroot = nfs4_get_root(s, &mntfh);
  2184. if (IS_ERR(mntroot)) {
  2185. error = PTR_ERR(mntroot);
  2186. goto error_splat_super;
  2187. }
  2188. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2189. dput(mntroot);
  2190. error = -ESTALE;
  2191. goto error_splat_super;
  2192. }
  2193. s->s_flags |= MS_ACTIVE;
  2194. mnt->mnt_sb = s;
  2195. mnt->mnt_root = mntroot;
  2196. security_sb_clone_mnt_opts(data->sb, s);
  2197. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  2198. return 0;
  2199. out_err_nosb:
  2200. nfs_free_server(server);
  2201. out_err_noserver:
  2202. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  2203. return error;
  2204. error_splat_super:
  2205. up_write(&s->s_umount);
  2206. deactivate_super(s);
  2207. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  2208. return error;
  2209. }
  2210. #endif /* CONFIG_NFS_V4 */