super.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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/nfs_xdr.h>
  47. #include <linux/magic.h>
  48. #include <linux/parser.h>
  49. #include <asm/system.h>
  50. #include <asm/uaccess.h>
  51. #include "nfs4_fs.h"
  52. #include "callback.h"
  53. #include "delegation.h"
  54. #include "iostat.h"
  55. #include "internal.h"
  56. #define NFSDBG_FACILITY NFSDBG_VFS
  57. enum {
  58. /* Mount options that take no arguments */
  59. Opt_soft, Opt_hard,
  60. Opt_intr, Opt_nointr,
  61. Opt_posix, Opt_noposix,
  62. Opt_cto, Opt_nocto,
  63. Opt_ac, Opt_noac,
  64. Opt_lock, Opt_nolock,
  65. Opt_v2, Opt_v3,
  66. Opt_udp, Opt_tcp, Opt_rdma,
  67. Opt_acl, Opt_noacl,
  68. Opt_rdirplus, Opt_nordirplus,
  69. Opt_sharecache, Opt_nosharecache,
  70. /* Mount options that take integer arguments */
  71. Opt_port,
  72. Opt_rsize, Opt_wsize, Opt_bsize,
  73. Opt_timeo, Opt_retrans,
  74. Opt_acregmin, Opt_acregmax,
  75. Opt_acdirmin, Opt_acdirmax,
  76. Opt_actimeo,
  77. Opt_namelen,
  78. Opt_mountport,
  79. Opt_mountprog, Opt_mountvers,
  80. Opt_nfsprog, Opt_nfsvers,
  81. /* Mount options that take string arguments */
  82. Opt_sec, Opt_proto, Opt_mountproto,
  83. Opt_addr, Opt_mountaddr, Opt_clientaddr,
  84. /* Mount options that are ignored */
  85. Opt_userspace, Opt_deprecated,
  86. Opt_err
  87. };
  88. static match_table_t nfs_mount_option_tokens = {
  89. { Opt_userspace, "bg" },
  90. { Opt_userspace, "fg" },
  91. { Opt_soft, "soft" },
  92. { Opt_hard, "hard" },
  93. { Opt_intr, "intr" },
  94. { Opt_nointr, "nointr" },
  95. { Opt_posix, "posix" },
  96. { Opt_noposix, "noposix" },
  97. { Opt_cto, "cto" },
  98. { Opt_nocto, "nocto" },
  99. { Opt_ac, "ac" },
  100. { Opt_noac, "noac" },
  101. { Opt_lock, "lock" },
  102. { Opt_nolock, "nolock" },
  103. { Opt_v2, "v2" },
  104. { Opt_v3, "v3" },
  105. { Opt_udp, "udp" },
  106. { Opt_tcp, "tcp" },
  107. { Opt_rdma, "rdma" },
  108. { Opt_acl, "acl" },
  109. { Opt_noacl, "noacl" },
  110. { Opt_rdirplus, "rdirplus" },
  111. { Opt_nordirplus, "nordirplus" },
  112. { Opt_sharecache, "sharecache" },
  113. { Opt_nosharecache, "nosharecache" },
  114. { Opt_port, "port=%u" },
  115. { Opt_rsize, "rsize=%u" },
  116. { Opt_wsize, "wsize=%u" },
  117. { Opt_bsize, "bsize=%u" },
  118. { Opt_timeo, "timeo=%u" },
  119. { Opt_retrans, "retrans=%u" },
  120. { Opt_acregmin, "acregmin=%u" },
  121. { Opt_acregmax, "acregmax=%u" },
  122. { Opt_acdirmin, "acdirmin=%u" },
  123. { Opt_acdirmax, "acdirmax=%u" },
  124. { Opt_actimeo, "actimeo=%u" },
  125. { Opt_userspace, "retry=%u" },
  126. { Opt_namelen, "namlen=%u" },
  127. { Opt_mountport, "mountport=%u" },
  128. { Opt_mountprog, "mountprog=%u" },
  129. { Opt_mountvers, "mountvers=%u" },
  130. { Opt_nfsprog, "nfsprog=%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_userspace, "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_err, NULL }
  170. };
  171. static void nfs_umount_begin(struct vfsmount *, int);
  172. static int nfs_statfs(struct dentry *, struct kstatfs *);
  173. static int nfs_show_options(struct seq_file *, struct vfsmount *);
  174. static int nfs_show_stats(struct seq_file *, struct vfsmount *);
  175. static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
  176. static int nfs_xdev_get_sb(struct file_system_type *fs_type,
  177. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  178. static void nfs_kill_super(struct super_block *);
  179. static struct file_system_type nfs_fs_type = {
  180. .owner = THIS_MODULE,
  181. .name = "nfs",
  182. .get_sb = nfs_get_sb,
  183. .kill_sb = nfs_kill_super,
  184. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  185. };
  186. struct file_system_type nfs_xdev_fs_type = {
  187. .owner = THIS_MODULE,
  188. .name = "nfs",
  189. .get_sb = nfs_xdev_get_sb,
  190. .kill_sb = nfs_kill_super,
  191. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  192. };
  193. static const struct super_operations nfs_sops = {
  194. .alloc_inode = nfs_alloc_inode,
  195. .destroy_inode = nfs_destroy_inode,
  196. .write_inode = nfs_write_inode,
  197. .statfs = nfs_statfs,
  198. .clear_inode = nfs_clear_inode,
  199. .umount_begin = nfs_umount_begin,
  200. .show_options = nfs_show_options,
  201. .show_stats = nfs_show_stats,
  202. };
  203. #ifdef CONFIG_NFS_V4
  204. static int nfs4_get_sb(struct file_system_type *fs_type,
  205. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  206. static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
  207. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  208. static int nfs4_referral_get_sb(struct file_system_type *fs_type,
  209. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  210. static void nfs4_kill_super(struct super_block *sb);
  211. static struct file_system_type nfs4_fs_type = {
  212. .owner = THIS_MODULE,
  213. .name = "nfs4",
  214. .get_sb = nfs4_get_sb,
  215. .kill_sb = nfs4_kill_super,
  216. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  217. };
  218. struct file_system_type nfs4_xdev_fs_type = {
  219. .owner = THIS_MODULE,
  220. .name = "nfs4",
  221. .get_sb = nfs4_xdev_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_referral_fs_type = {
  226. .owner = THIS_MODULE,
  227. .name = "nfs4",
  228. .get_sb = nfs4_referral_get_sb,
  229. .kill_sb = nfs4_kill_super,
  230. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  231. };
  232. static const struct super_operations nfs4_sops = {
  233. .alloc_inode = nfs_alloc_inode,
  234. .destroy_inode = nfs_destroy_inode,
  235. .write_inode = nfs_write_inode,
  236. .statfs = nfs_statfs,
  237. .clear_inode = nfs4_clear_inode,
  238. .umount_begin = nfs_umount_begin,
  239. .show_options = nfs_show_options,
  240. .show_stats = nfs_show_stats,
  241. };
  242. #endif
  243. static struct shrinker acl_shrinker = {
  244. .shrink = nfs_access_cache_shrinker,
  245. .seeks = DEFAULT_SEEKS,
  246. };
  247. /*
  248. * Register the NFS filesystems
  249. */
  250. int __init register_nfs_fs(void)
  251. {
  252. int ret;
  253. ret = register_filesystem(&nfs_fs_type);
  254. if (ret < 0)
  255. goto error_0;
  256. ret = nfs_register_sysctl();
  257. if (ret < 0)
  258. goto error_1;
  259. #ifdef CONFIG_NFS_V4
  260. ret = register_filesystem(&nfs4_fs_type);
  261. if (ret < 0)
  262. goto error_2;
  263. #endif
  264. register_shrinker(&acl_shrinker);
  265. return 0;
  266. #ifdef CONFIG_NFS_V4
  267. error_2:
  268. nfs_unregister_sysctl();
  269. #endif
  270. error_1:
  271. unregister_filesystem(&nfs_fs_type);
  272. error_0:
  273. return ret;
  274. }
  275. /*
  276. * Unregister the NFS filesystems
  277. */
  278. void __exit unregister_nfs_fs(void)
  279. {
  280. unregister_shrinker(&acl_shrinker);
  281. #ifdef CONFIG_NFS_V4
  282. unregister_filesystem(&nfs4_fs_type);
  283. #endif
  284. nfs_unregister_sysctl();
  285. unregister_filesystem(&nfs_fs_type);
  286. }
  287. /*
  288. * Deliver file system statistics to userspace
  289. */
  290. static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  291. {
  292. struct nfs_server *server = NFS_SB(dentry->d_sb);
  293. unsigned char blockbits;
  294. unsigned long blockres;
  295. struct nfs_fh *fh = NFS_FH(dentry->d_inode);
  296. struct nfs_fattr fattr;
  297. struct nfs_fsstat res = {
  298. .fattr = &fattr,
  299. };
  300. int error;
  301. lock_kernel();
  302. error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
  303. if (error < 0)
  304. goto out_err;
  305. buf->f_type = NFS_SUPER_MAGIC;
  306. /*
  307. * Current versions of glibc do not correctly handle the
  308. * case where f_frsize != f_bsize. Eventually we want to
  309. * report the value of wtmult in this field.
  310. */
  311. buf->f_frsize = dentry->d_sb->s_blocksize;
  312. /*
  313. * On most *nix systems, f_blocks, f_bfree, and f_bavail
  314. * are reported in units of f_frsize. Linux hasn't had
  315. * an f_frsize field in its statfs struct until recently,
  316. * thus historically Linux's sys_statfs reports these
  317. * fields in units of f_bsize.
  318. */
  319. buf->f_bsize = dentry->d_sb->s_blocksize;
  320. blockbits = dentry->d_sb->s_blocksize_bits;
  321. blockres = (1 << blockbits) - 1;
  322. buf->f_blocks = (res.tbytes + blockres) >> blockbits;
  323. buf->f_bfree = (res.fbytes + blockres) >> blockbits;
  324. buf->f_bavail = (res.abytes + blockres) >> blockbits;
  325. buf->f_files = res.tfiles;
  326. buf->f_ffree = res.afiles;
  327. buf->f_namelen = server->namelen;
  328. unlock_kernel();
  329. return 0;
  330. out_err:
  331. dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
  332. unlock_kernel();
  333. return error;
  334. }
  335. /*
  336. * Map the security flavour number to a name
  337. */
  338. static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
  339. {
  340. static const struct {
  341. rpc_authflavor_t flavour;
  342. const char *str;
  343. } sec_flavours[] = {
  344. { RPC_AUTH_NULL, "null" },
  345. { RPC_AUTH_UNIX, "sys" },
  346. { RPC_AUTH_GSS_KRB5, "krb5" },
  347. { RPC_AUTH_GSS_KRB5I, "krb5i" },
  348. { RPC_AUTH_GSS_KRB5P, "krb5p" },
  349. { RPC_AUTH_GSS_LKEY, "lkey" },
  350. { RPC_AUTH_GSS_LKEYI, "lkeyi" },
  351. { RPC_AUTH_GSS_LKEYP, "lkeyp" },
  352. { RPC_AUTH_GSS_SPKM, "spkm" },
  353. { RPC_AUTH_GSS_SPKMI, "spkmi" },
  354. { RPC_AUTH_GSS_SPKMP, "spkmp" },
  355. { UINT_MAX, "unknown" }
  356. };
  357. int i;
  358. for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
  359. if (sec_flavours[i].flavour == flavour)
  360. break;
  361. }
  362. return sec_flavours[i].str;
  363. }
  364. /*
  365. * Describe the mount options in force on this server representation
  366. */
  367. static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
  368. {
  369. static const struct proc_nfs_info {
  370. int flag;
  371. const char *str;
  372. const char *nostr;
  373. } nfs_info[] = {
  374. { NFS_MOUNT_SOFT, ",soft", ",hard" },
  375. { NFS_MOUNT_INTR, ",intr", ",nointr" },
  376. { NFS_MOUNT_NOCTO, ",nocto", "" },
  377. { NFS_MOUNT_NOAC, ",noac", "" },
  378. { NFS_MOUNT_NONLM, ",nolock", "" },
  379. { NFS_MOUNT_NOACL, ",noacl", "" },
  380. { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
  381. { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
  382. { 0, NULL, NULL }
  383. };
  384. const struct proc_nfs_info *nfs_infop;
  385. struct nfs_client *clp = nfss->nfs_client;
  386. seq_printf(m, ",vers=%d", clp->rpc_ops->version);
  387. seq_printf(m, ",rsize=%d", nfss->rsize);
  388. seq_printf(m, ",wsize=%d", nfss->wsize);
  389. if (nfss->acregmin != 3*HZ || showdefaults)
  390. seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
  391. if (nfss->acregmax != 60*HZ || showdefaults)
  392. seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
  393. if (nfss->acdirmin != 30*HZ || showdefaults)
  394. seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
  395. if (nfss->acdirmax != 60*HZ || showdefaults)
  396. seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
  397. for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
  398. if (nfss->flags & nfs_infop->flag)
  399. seq_puts(m, nfs_infop->str);
  400. else
  401. seq_puts(m, nfs_infop->nostr);
  402. }
  403. seq_printf(m, ",proto=%s",
  404. rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
  405. seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
  406. seq_printf(m, ",retrans=%u", clp->retrans_count);
  407. seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
  408. }
  409. /*
  410. * Describe the mount options on this VFS mountpoint
  411. */
  412. static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
  413. {
  414. struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
  415. nfs_show_mount_options(m, nfss, 0);
  416. seq_printf(m, ",addr="NIPQUAD_FMT,
  417. NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
  418. return 0;
  419. }
  420. /*
  421. * Present statistical information for this VFS mountpoint
  422. */
  423. static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
  424. {
  425. int i, cpu;
  426. struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
  427. struct rpc_auth *auth = nfss->client->cl_auth;
  428. struct nfs_iostats totals = { };
  429. seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
  430. /*
  431. * Display all mount option settings
  432. */
  433. seq_printf(m, "\n\topts:\t");
  434. seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
  435. seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
  436. seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
  437. seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
  438. nfs_show_mount_options(m, nfss, 1);
  439. seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
  440. seq_printf(m, "\n\tcaps:\t");
  441. seq_printf(m, "caps=0x%x", nfss->caps);
  442. seq_printf(m, ",wtmult=%d", nfss->wtmult);
  443. seq_printf(m, ",dtsize=%d", nfss->dtsize);
  444. seq_printf(m, ",bsize=%d", nfss->bsize);
  445. seq_printf(m, ",namelen=%d", nfss->namelen);
  446. #ifdef CONFIG_NFS_V4
  447. if (nfss->nfs_client->cl_nfsversion == 4) {
  448. seq_printf(m, "\n\tnfsv4:\t");
  449. seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
  450. seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
  451. seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
  452. }
  453. #endif
  454. /*
  455. * Display security flavor in effect for this mount
  456. */
  457. seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
  458. if (auth->au_flavor)
  459. seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
  460. /*
  461. * Display superblock I/O counters
  462. */
  463. for_each_possible_cpu(cpu) {
  464. struct nfs_iostats *stats;
  465. preempt_disable();
  466. stats = per_cpu_ptr(nfss->io_stats, cpu);
  467. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  468. totals.events[i] += stats->events[i];
  469. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  470. totals.bytes[i] += stats->bytes[i];
  471. preempt_enable();
  472. }
  473. seq_printf(m, "\n\tevents:\t");
  474. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  475. seq_printf(m, "%lu ", totals.events[i]);
  476. seq_printf(m, "\n\tbytes:\t");
  477. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  478. seq_printf(m, "%Lu ", totals.bytes[i]);
  479. seq_printf(m, "\n");
  480. rpc_print_iostats(m, nfss->client);
  481. return 0;
  482. }
  483. /*
  484. * Begin unmount by attempting to remove all automounted mountpoints we added
  485. * in response to xdev traversals and referrals
  486. */
  487. static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
  488. {
  489. struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
  490. struct rpc_clnt *rpc;
  491. shrink_submounts(vfsmnt, &nfs_automount_list);
  492. if (!(flags & MNT_FORCE))
  493. return;
  494. /* -EIO all pending I/O */
  495. rpc = server->client_acl;
  496. if (!IS_ERR(rpc))
  497. rpc_killall_tasks(rpc);
  498. rpc = server->client;
  499. if (!IS_ERR(rpc))
  500. rpc_killall_tasks(rpc);
  501. }
  502. /*
  503. * Sanity-check a server address provided by the mount command
  504. */
  505. static int nfs_verify_server_address(struct sockaddr *addr)
  506. {
  507. switch (addr->sa_family) {
  508. case AF_INET: {
  509. struct sockaddr_in *sa = (struct sockaddr_in *) addr;
  510. if (sa->sin_addr.s_addr != INADDR_ANY)
  511. return 1;
  512. break;
  513. }
  514. }
  515. return 0;
  516. }
  517. /*
  518. * Error-check and convert a string of mount options from user space into
  519. * a data structure
  520. */
  521. static int nfs_parse_mount_options(char *raw,
  522. struct nfs_parsed_mount_data *mnt)
  523. {
  524. char *p, *string;
  525. if (!raw) {
  526. dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
  527. return 1;
  528. }
  529. dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
  530. while ((p = strsep(&raw, ",")) != NULL) {
  531. substring_t args[MAX_OPT_ARGS];
  532. int option, token;
  533. if (!*p)
  534. continue;
  535. dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
  536. token = match_token(p, nfs_mount_option_tokens, args);
  537. switch (token) {
  538. case Opt_soft:
  539. mnt->flags |= NFS_MOUNT_SOFT;
  540. break;
  541. case Opt_hard:
  542. mnt->flags &= ~NFS_MOUNT_SOFT;
  543. break;
  544. case Opt_intr:
  545. mnt->flags |= NFS_MOUNT_INTR;
  546. break;
  547. case Opt_nointr:
  548. mnt->flags &= ~NFS_MOUNT_INTR;
  549. break;
  550. case Opt_posix:
  551. mnt->flags |= NFS_MOUNT_POSIX;
  552. break;
  553. case Opt_noposix:
  554. mnt->flags &= ~NFS_MOUNT_POSIX;
  555. break;
  556. case Opt_cto:
  557. mnt->flags &= ~NFS_MOUNT_NOCTO;
  558. break;
  559. case Opt_nocto:
  560. mnt->flags |= NFS_MOUNT_NOCTO;
  561. break;
  562. case Opt_ac:
  563. mnt->flags &= ~NFS_MOUNT_NOAC;
  564. break;
  565. case Opt_noac:
  566. mnt->flags |= NFS_MOUNT_NOAC;
  567. break;
  568. case Opt_lock:
  569. mnt->flags &= ~NFS_MOUNT_NONLM;
  570. break;
  571. case Opt_nolock:
  572. mnt->flags |= NFS_MOUNT_NONLM;
  573. break;
  574. case Opt_v2:
  575. mnt->flags &= ~NFS_MOUNT_VER3;
  576. break;
  577. case Opt_v3:
  578. mnt->flags |= NFS_MOUNT_VER3;
  579. break;
  580. case Opt_udp:
  581. mnt->flags &= ~NFS_MOUNT_TCP;
  582. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  583. mnt->timeo = 7;
  584. mnt->retrans = 5;
  585. break;
  586. case Opt_tcp:
  587. mnt->flags |= NFS_MOUNT_TCP;
  588. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  589. mnt->timeo = 600;
  590. mnt->retrans = 2;
  591. break;
  592. case Opt_rdma:
  593. mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
  594. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  595. mnt->timeo = 600;
  596. mnt->retrans = 2;
  597. break;
  598. case Opt_acl:
  599. mnt->flags &= ~NFS_MOUNT_NOACL;
  600. break;
  601. case Opt_noacl:
  602. mnt->flags |= NFS_MOUNT_NOACL;
  603. break;
  604. case Opt_rdirplus:
  605. mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
  606. break;
  607. case Opt_nordirplus:
  608. mnt->flags |= NFS_MOUNT_NORDIRPLUS;
  609. break;
  610. case Opt_sharecache:
  611. mnt->flags &= ~NFS_MOUNT_UNSHARED;
  612. break;
  613. case Opt_nosharecache:
  614. mnt->flags |= NFS_MOUNT_UNSHARED;
  615. break;
  616. case Opt_port:
  617. if (match_int(args, &option))
  618. return 0;
  619. if (option < 0 || option > 65535)
  620. return 0;
  621. mnt->nfs_server.address.sin_port = htons(option);
  622. break;
  623. case Opt_rsize:
  624. if (match_int(args, &mnt->rsize))
  625. return 0;
  626. break;
  627. case Opt_wsize:
  628. if (match_int(args, &mnt->wsize))
  629. return 0;
  630. break;
  631. case Opt_bsize:
  632. if (match_int(args, &option))
  633. return 0;
  634. if (option < 0)
  635. return 0;
  636. mnt->bsize = option;
  637. break;
  638. case Opt_timeo:
  639. if (match_int(args, &mnt->timeo))
  640. return 0;
  641. break;
  642. case Opt_retrans:
  643. if (match_int(args, &mnt->retrans))
  644. return 0;
  645. break;
  646. case Opt_acregmin:
  647. if (match_int(args, &mnt->acregmin))
  648. return 0;
  649. break;
  650. case Opt_acregmax:
  651. if (match_int(args, &mnt->acregmax))
  652. return 0;
  653. break;
  654. case Opt_acdirmin:
  655. if (match_int(args, &mnt->acdirmin))
  656. return 0;
  657. break;
  658. case Opt_acdirmax:
  659. if (match_int(args, &mnt->acdirmax))
  660. return 0;
  661. break;
  662. case Opt_actimeo:
  663. if (match_int(args, &option))
  664. return 0;
  665. if (option < 0)
  666. return 0;
  667. mnt->acregmin =
  668. mnt->acregmax =
  669. mnt->acdirmin =
  670. mnt->acdirmax = option;
  671. break;
  672. case Opt_namelen:
  673. if (match_int(args, &mnt->namlen))
  674. return 0;
  675. break;
  676. case Opt_mountport:
  677. if (match_int(args, &option))
  678. return 0;
  679. if (option < 0 || option > 65535)
  680. return 0;
  681. mnt->mount_server.port = option;
  682. break;
  683. case Opt_mountprog:
  684. if (match_int(args, &option))
  685. return 0;
  686. if (option < 0)
  687. return 0;
  688. mnt->mount_server.program = option;
  689. break;
  690. case Opt_mountvers:
  691. if (match_int(args, &option))
  692. return 0;
  693. if (option < 0)
  694. return 0;
  695. mnt->mount_server.version = option;
  696. break;
  697. case Opt_nfsprog:
  698. if (match_int(args, &option))
  699. return 0;
  700. if (option < 0)
  701. return 0;
  702. mnt->nfs_server.program = option;
  703. break;
  704. case Opt_nfsvers:
  705. if (match_int(args, &option))
  706. return 0;
  707. switch (option) {
  708. case 2:
  709. mnt->flags &= ~NFS_MOUNT_VER3;
  710. break;
  711. case 3:
  712. mnt->flags |= NFS_MOUNT_VER3;
  713. break;
  714. default:
  715. goto out_unrec_vers;
  716. }
  717. break;
  718. case Opt_sec:
  719. string = match_strdup(args);
  720. if (string == NULL)
  721. goto out_nomem;
  722. token = match_token(string, nfs_secflavor_tokens, args);
  723. kfree(string);
  724. /*
  725. * The flags setting is for v2/v3. The flavor_len
  726. * setting is for v4. v2/v3 also need to know the
  727. * difference between NULL and UNIX.
  728. */
  729. switch (token) {
  730. case Opt_sec_none:
  731. mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
  732. mnt->auth_flavor_len = 0;
  733. mnt->auth_flavors[0] = RPC_AUTH_NULL;
  734. break;
  735. case Opt_sec_sys:
  736. mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
  737. mnt->auth_flavor_len = 0;
  738. mnt->auth_flavors[0] = RPC_AUTH_UNIX;
  739. break;
  740. case Opt_sec_krb5:
  741. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  742. mnt->auth_flavor_len = 1;
  743. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
  744. break;
  745. case Opt_sec_krb5i:
  746. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  747. mnt->auth_flavor_len = 1;
  748. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
  749. break;
  750. case Opt_sec_krb5p:
  751. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  752. mnt->auth_flavor_len = 1;
  753. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
  754. break;
  755. case Opt_sec_lkey:
  756. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  757. mnt->auth_flavor_len = 1;
  758. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
  759. break;
  760. case Opt_sec_lkeyi:
  761. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  762. mnt->auth_flavor_len = 1;
  763. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
  764. break;
  765. case Opt_sec_lkeyp:
  766. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  767. mnt->auth_flavor_len = 1;
  768. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
  769. break;
  770. case Opt_sec_spkm:
  771. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  772. mnt->auth_flavor_len = 1;
  773. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
  774. break;
  775. case Opt_sec_spkmi:
  776. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  777. mnt->auth_flavor_len = 1;
  778. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
  779. break;
  780. case Opt_sec_spkmp:
  781. mnt->flags |= NFS_MOUNT_SECFLAVOUR;
  782. mnt->auth_flavor_len = 1;
  783. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
  784. break;
  785. default:
  786. goto out_unrec_sec;
  787. }
  788. break;
  789. case Opt_proto:
  790. string = match_strdup(args);
  791. if (string == NULL)
  792. goto out_nomem;
  793. token = match_token(string,
  794. nfs_xprt_protocol_tokens, args);
  795. kfree(string);
  796. switch (token) {
  797. case Opt_xprt_udp:
  798. mnt->flags &= ~NFS_MOUNT_TCP;
  799. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  800. mnt->timeo = 7;
  801. mnt->retrans = 5;
  802. break;
  803. case Opt_xprt_tcp:
  804. mnt->flags |= NFS_MOUNT_TCP;
  805. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  806. mnt->timeo = 600;
  807. mnt->retrans = 2;
  808. break;
  809. case Opt_xprt_rdma:
  810. /* vector side protocols to TCP */
  811. mnt->flags |= NFS_MOUNT_TCP;
  812. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  813. mnt->timeo = 600;
  814. mnt->retrans = 2;
  815. break;
  816. default:
  817. goto out_unrec_xprt;
  818. }
  819. break;
  820. case Opt_mountproto:
  821. string = match_strdup(args);
  822. if (string == NULL)
  823. goto out_nomem;
  824. token = match_token(string,
  825. nfs_xprt_protocol_tokens, args);
  826. kfree(string);
  827. switch (token) {
  828. case Opt_xprt_udp:
  829. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  830. break;
  831. case Opt_xprt_tcp:
  832. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  833. break;
  834. case Opt_xprt_rdma: /* not used for side protocols */
  835. default:
  836. goto out_unrec_xprt;
  837. }
  838. break;
  839. case Opt_addr:
  840. string = match_strdup(args);
  841. if (string == NULL)
  842. goto out_nomem;
  843. mnt->nfs_server.address.sin_family = AF_INET;
  844. mnt->nfs_server.address.sin_addr.s_addr =
  845. in_aton(string);
  846. kfree(string);
  847. break;
  848. case Opt_clientaddr:
  849. string = match_strdup(args);
  850. if (string == NULL)
  851. goto out_nomem;
  852. mnt->client_address = string;
  853. break;
  854. case Opt_mountaddr:
  855. string = match_strdup(args);
  856. if (string == NULL)
  857. goto out_nomem;
  858. mnt->mount_server.address.sin_family = AF_INET;
  859. mnt->mount_server.address.sin_addr.s_addr =
  860. in_aton(string);
  861. kfree(string);
  862. break;
  863. case Opt_userspace:
  864. case Opt_deprecated:
  865. break;
  866. default:
  867. goto out_unknown;
  868. }
  869. }
  870. return 1;
  871. out_nomem:
  872. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  873. return 0;
  874. out_unrec_vers:
  875. printk(KERN_INFO "NFS: unrecognized NFS version number\n");
  876. return 0;
  877. out_unrec_xprt:
  878. printk(KERN_INFO "NFS: unrecognized transport protocol\n");
  879. return 0;
  880. out_unrec_sec:
  881. printk(KERN_INFO "NFS: unrecognized security flavor\n");
  882. return 0;
  883. out_unknown:
  884. printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
  885. return 0;
  886. }
  887. /*
  888. * Use the remote server's MOUNT service to request the NFS file handle
  889. * corresponding to the provided path.
  890. */
  891. static int nfs_try_mount(struct nfs_parsed_mount_data *args,
  892. struct nfs_fh *root_fh)
  893. {
  894. struct sockaddr_in sin;
  895. int status;
  896. if (args->mount_server.version == 0) {
  897. if (args->flags & NFS_MOUNT_VER3)
  898. args->mount_server.version = NFS_MNT3_VERSION;
  899. else
  900. args->mount_server.version = NFS_MNT_VERSION;
  901. }
  902. /*
  903. * Construct the mount server's address.
  904. */
  905. if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
  906. sin = args->mount_server.address;
  907. else
  908. sin = args->nfs_server.address;
  909. /*
  910. * autobind will be used if mount_server.port == 0
  911. */
  912. sin.sin_port = htons(args->mount_server.port);
  913. /*
  914. * Now ask the mount server to map our export path
  915. * to a file handle.
  916. */
  917. status = nfs_mount((struct sockaddr *) &sin,
  918. sizeof(sin),
  919. args->nfs_server.hostname,
  920. args->nfs_server.export_path,
  921. args->mount_server.version,
  922. args->mount_server.protocol,
  923. root_fh);
  924. if (status == 0)
  925. return 0;
  926. dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
  927. ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
  928. return status;
  929. }
  930. /*
  931. * Validate the NFS2/NFS3 mount data
  932. * - fills in the mount root filehandle
  933. *
  934. * For option strings, user space handles the following behaviors:
  935. *
  936. * + DNS: mapping server host name to IP address ("addr=" option)
  937. *
  938. * + failure mode: how to behave if a mount request can't be handled
  939. * immediately ("fg/bg" option)
  940. *
  941. * + retry: how often to retry a mount request ("retry=" option)
  942. *
  943. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  944. * mountproto=tcp after mountproto=udp, and so on
  945. *
  946. * XXX: as far as I can tell, changing the NFS program number is not
  947. * supported in the NFS client.
  948. */
  949. static int nfs_validate_mount_data(void *options,
  950. struct nfs_parsed_mount_data *args,
  951. struct nfs_fh *mntfh,
  952. const char *dev_name)
  953. {
  954. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  955. if (data == NULL)
  956. goto out_no_data;
  957. memset(args, 0, sizeof(*args));
  958. args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
  959. args->rsize = NFS_MAX_FILE_IO_SIZE;
  960. args->wsize = NFS_MAX_FILE_IO_SIZE;
  961. args->timeo = 600;
  962. args->retrans = 2;
  963. args->acregmin = 3;
  964. args->acregmax = 60;
  965. args->acdirmin = 30;
  966. args->acdirmax = 60;
  967. args->mount_server.protocol = XPRT_TRANSPORT_UDP;
  968. args->mount_server.program = NFS_MNT_PROGRAM;
  969. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  970. args->nfs_server.program = NFS_PROGRAM;
  971. switch (data->version) {
  972. case 1:
  973. data->namlen = 0;
  974. case 2:
  975. data->bsize = 0;
  976. case 3:
  977. if (data->flags & NFS_MOUNT_VER3)
  978. goto out_no_v3;
  979. data->root.size = NFS2_FHSIZE;
  980. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  981. case 4:
  982. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  983. goto out_no_sec;
  984. case 5:
  985. memset(data->context, 0, sizeof(data->context));
  986. case 6:
  987. if (data->flags & NFS_MOUNT_VER3)
  988. mntfh->size = data->root.size;
  989. else
  990. mntfh->size = NFS2_FHSIZE;
  991. if (mntfh->size > sizeof(mntfh->data))
  992. goto out_invalid_fh;
  993. memcpy(mntfh->data, data->root.data, mntfh->size);
  994. if (mntfh->size < sizeof(mntfh->data))
  995. memset(mntfh->data + mntfh->size, 0,
  996. sizeof(mntfh->data) - mntfh->size);
  997. if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
  998. goto out_no_address;
  999. /*
  1000. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1001. * can deal with.
  1002. */
  1003. args->flags = data->flags;
  1004. args->rsize = data->rsize;
  1005. args->wsize = data->wsize;
  1006. args->flags = data->flags;
  1007. args->timeo = data->timeo;
  1008. args->retrans = data->retrans;
  1009. args->acregmin = data->acregmin;
  1010. args->acregmax = data->acregmax;
  1011. args->acdirmin = data->acdirmin;
  1012. args->acdirmax = data->acdirmax;
  1013. args->nfs_server.address = data->addr;
  1014. if (!(data->flags & NFS_MOUNT_TCP))
  1015. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1016. /* N.B. caller will free nfs_server.hostname in all cases */
  1017. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1018. args->namlen = data->namlen;
  1019. args->bsize = data->bsize;
  1020. args->auth_flavors[0] = data->pseudoflavor;
  1021. break;
  1022. default: {
  1023. unsigned int len;
  1024. char *c;
  1025. int status;
  1026. if (nfs_parse_mount_options((char *)options, args) == 0)
  1027. return -EINVAL;
  1028. if (!nfs_verify_server_address((struct sockaddr *)
  1029. &args->nfs_server.address))
  1030. goto out_no_address;
  1031. c = strchr(dev_name, ':');
  1032. if (c == NULL)
  1033. return -EINVAL;
  1034. len = c - dev_name;
  1035. /* N.B. caller will free nfs_server.hostname in all cases */
  1036. args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1037. c++;
  1038. if (strlen(c) > NFS_MAXPATHLEN)
  1039. return -ENAMETOOLONG;
  1040. args->nfs_server.export_path = c;
  1041. status = nfs_try_mount(args, mntfh);
  1042. if (status)
  1043. return status;
  1044. break;
  1045. }
  1046. }
  1047. if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
  1048. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1049. #ifndef CONFIG_NFS_V3
  1050. if (args->flags & NFS_MOUNT_VER3)
  1051. goto out_v3_not_compiled;
  1052. #endif /* !CONFIG_NFS_V3 */
  1053. return 0;
  1054. out_no_data:
  1055. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1056. return -EINVAL;
  1057. out_no_v3:
  1058. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1059. data->version);
  1060. return -EINVAL;
  1061. out_no_sec:
  1062. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1063. return -EINVAL;
  1064. #ifndef CONFIG_NFS_V3
  1065. out_v3_not_compiled:
  1066. dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
  1067. return -EPROTONOSUPPORT;
  1068. #endif /* !CONFIG_NFS_V3 */
  1069. out_no_address:
  1070. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1071. return -EINVAL;
  1072. out_invalid_fh:
  1073. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1074. return -EINVAL;
  1075. }
  1076. /*
  1077. * Initialise the common bits of the superblock
  1078. */
  1079. static inline void nfs_initialise_sb(struct super_block *sb)
  1080. {
  1081. struct nfs_server *server = NFS_SB(sb);
  1082. sb->s_magic = NFS_SUPER_MAGIC;
  1083. /* We probably want something more informative here */
  1084. snprintf(sb->s_id, sizeof(sb->s_id),
  1085. "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  1086. if (sb->s_blocksize == 0)
  1087. sb->s_blocksize = nfs_block_bits(server->wsize,
  1088. &sb->s_blocksize_bits);
  1089. if (server->flags & NFS_MOUNT_NOAC)
  1090. sb->s_flags |= MS_SYNCHRONOUS;
  1091. nfs_super_set_maxbytes(sb, server->maxfilesize);
  1092. }
  1093. /*
  1094. * Finish setting up an NFS2/3 superblock
  1095. */
  1096. static void nfs_fill_super(struct super_block *sb,
  1097. struct nfs_parsed_mount_data *data)
  1098. {
  1099. struct nfs_server *server = NFS_SB(sb);
  1100. sb->s_blocksize_bits = 0;
  1101. sb->s_blocksize = 0;
  1102. if (data->bsize)
  1103. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  1104. if (server->flags & NFS_MOUNT_VER3) {
  1105. /* The VFS shouldn't apply the umask to mode bits. We will do
  1106. * so ourselves when necessary.
  1107. */
  1108. sb->s_flags |= MS_POSIXACL;
  1109. sb->s_time_gran = 1;
  1110. }
  1111. sb->s_op = &nfs_sops;
  1112. nfs_initialise_sb(sb);
  1113. }
  1114. /*
  1115. * Finish setting up a cloned NFS2/3 superblock
  1116. */
  1117. static void nfs_clone_super(struct super_block *sb,
  1118. const struct super_block *old_sb)
  1119. {
  1120. struct nfs_server *server = NFS_SB(sb);
  1121. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1122. sb->s_blocksize = old_sb->s_blocksize;
  1123. sb->s_maxbytes = old_sb->s_maxbytes;
  1124. if (server->flags & NFS_MOUNT_VER3) {
  1125. /* The VFS shouldn't apply the umask to mode bits. We will do
  1126. * so ourselves when necessary.
  1127. */
  1128. sb->s_flags |= MS_POSIXACL;
  1129. sb->s_time_gran = 1;
  1130. }
  1131. sb->s_op = old_sb->s_op;
  1132. nfs_initialise_sb(sb);
  1133. }
  1134. #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
  1135. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  1136. {
  1137. const struct nfs_server *a = s->s_fs_info;
  1138. const struct rpc_clnt *clnt_a = a->client;
  1139. const struct rpc_clnt *clnt_b = b->client;
  1140. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  1141. goto Ebusy;
  1142. if (a->nfs_client != b->nfs_client)
  1143. goto Ebusy;
  1144. if (a->flags != b->flags)
  1145. goto Ebusy;
  1146. if (a->wsize != b->wsize)
  1147. goto Ebusy;
  1148. if (a->rsize != b->rsize)
  1149. goto Ebusy;
  1150. if (a->acregmin != b->acregmin)
  1151. goto Ebusy;
  1152. if (a->acregmax != b->acregmax)
  1153. goto Ebusy;
  1154. if (a->acdirmin != b->acdirmin)
  1155. goto Ebusy;
  1156. if (a->acdirmax != b->acdirmax)
  1157. goto Ebusy;
  1158. if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  1159. goto Ebusy;
  1160. return 1;
  1161. Ebusy:
  1162. return 0;
  1163. }
  1164. struct nfs_sb_mountdata {
  1165. struct nfs_server *server;
  1166. int mntflags;
  1167. };
  1168. static int nfs_set_super(struct super_block *s, void *data)
  1169. {
  1170. struct nfs_sb_mountdata *sb_mntdata = data;
  1171. struct nfs_server *server = sb_mntdata->server;
  1172. int ret;
  1173. s->s_flags = sb_mntdata->mntflags;
  1174. s->s_fs_info = server;
  1175. ret = set_anon_super(s, server);
  1176. if (ret == 0)
  1177. server->s_dev = s->s_dev;
  1178. return ret;
  1179. }
  1180. static int nfs_compare_super(struct super_block *sb, void *data)
  1181. {
  1182. struct nfs_sb_mountdata *sb_mntdata = data;
  1183. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  1184. int mntflags = sb_mntdata->mntflags;
  1185. if (memcmp(&old->nfs_client->cl_addr,
  1186. &server->nfs_client->cl_addr,
  1187. sizeof(old->nfs_client->cl_addr)) != 0)
  1188. return 0;
  1189. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  1190. if (old->flags & NFS_MOUNT_UNSHARED)
  1191. return 0;
  1192. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  1193. return 0;
  1194. return nfs_compare_mount_options(sb, server, mntflags);
  1195. }
  1196. static int nfs_get_sb(struct file_system_type *fs_type,
  1197. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1198. {
  1199. struct nfs_server *server = NULL;
  1200. struct super_block *s;
  1201. struct nfs_fh mntfh;
  1202. struct nfs_parsed_mount_data data;
  1203. struct dentry *mntroot;
  1204. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1205. struct nfs_sb_mountdata sb_mntdata = {
  1206. .mntflags = flags,
  1207. };
  1208. int error;
  1209. /* Validate the mount data */
  1210. error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
  1211. if (error < 0)
  1212. goto out;
  1213. /* Get a volume representation */
  1214. server = nfs_create_server(&data, &mntfh);
  1215. if (IS_ERR(server)) {
  1216. error = PTR_ERR(server);
  1217. goto out;
  1218. }
  1219. sb_mntdata.server = server;
  1220. if (server->flags & NFS_MOUNT_UNSHARED)
  1221. compare_super = NULL;
  1222. /* Get a superblock - note that we may end up sharing one that already exists */
  1223. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1224. if (IS_ERR(s)) {
  1225. error = PTR_ERR(s);
  1226. goto out_err_nosb;
  1227. }
  1228. if (s->s_fs_info != server) {
  1229. nfs_free_server(server);
  1230. server = NULL;
  1231. }
  1232. if (!s->s_root) {
  1233. /* initial superblock/root creation */
  1234. nfs_fill_super(s, &data);
  1235. }
  1236. mntroot = nfs_get_root(s, &mntfh);
  1237. if (IS_ERR(mntroot)) {
  1238. error = PTR_ERR(mntroot);
  1239. goto error_splat_super;
  1240. }
  1241. s->s_flags |= MS_ACTIVE;
  1242. mnt->mnt_sb = s;
  1243. mnt->mnt_root = mntroot;
  1244. error = 0;
  1245. out:
  1246. kfree(data.nfs_server.hostname);
  1247. return error;
  1248. out_err_nosb:
  1249. nfs_free_server(server);
  1250. goto out;
  1251. error_splat_super:
  1252. up_write(&s->s_umount);
  1253. deactivate_super(s);
  1254. goto out;
  1255. }
  1256. /*
  1257. * Destroy an NFS2/3 superblock
  1258. */
  1259. static void nfs_kill_super(struct super_block *s)
  1260. {
  1261. struct nfs_server *server = NFS_SB(s);
  1262. kill_anon_super(s);
  1263. nfs_free_server(server);
  1264. }
  1265. /*
  1266. * Clone an NFS2/3 server record on xdev traversal (FSID-change)
  1267. */
  1268. static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1269. const char *dev_name, void *raw_data,
  1270. struct vfsmount *mnt)
  1271. {
  1272. struct nfs_clone_mount *data = raw_data;
  1273. struct super_block *s;
  1274. struct nfs_server *server;
  1275. struct dentry *mntroot;
  1276. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1277. struct nfs_sb_mountdata sb_mntdata = {
  1278. .mntflags = flags,
  1279. };
  1280. int error;
  1281. dprintk("--> nfs_xdev_get_sb()\n");
  1282. /* create a new volume representation */
  1283. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1284. if (IS_ERR(server)) {
  1285. error = PTR_ERR(server);
  1286. goto out_err_noserver;
  1287. }
  1288. sb_mntdata.server = server;
  1289. if (server->flags & NFS_MOUNT_UNSHARED)
  1290. compare_super = NULL;
  1291. /* Get a superblock - note that we may end up sharing one that already exists */
  1292. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1293. if (IS_ERR(s)) {
  1294. error = PTR_ERR(s);
  1295. goto out_err_nosb;
  1296. }
  1297. if (s->s_fs_info != server) {
  1298. nfs_free_server(server);
  1299. server = NULL;
  1300. }
  1301. if (!s->s_root) {
  1302. /* initial superblock/root creation */
  1303. nfs_clone_super(s, data->sb);
  1304. }
  1305. mntroot = nfs_get_root(s, data->fh);
  1306. if (IS_ERR(mntroot)) {
  1307. error = PTR_ERR(mntroot);
  1308. goto error_splat_super;
  1309. }
  1310. s->s_flags |= MS_ACTIVE;
  1311. mnt->mnt_sb = s;
  1312. mnt->mnt_root = mntroot;
  1313. dprintk("<-- nfs_xdev_get_sb() = 0\n");
  1314. return 0;
  1315. out_err_nosb:
  1316. nfs_free_server(server);
  1317. out_err_noserver:
  1318. dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
  1319. return error;
  1320. error_splat_super:
  1321. up_write(&s->s_umount);
  1322. deactivate_super(s);
  1323. dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
  1324. return error;
  1325. }
  1326. #ifdef CONFIG_NFS_V4
  1327. /*
  1328. * Finish setting up a cloned NFS4 superblock
  1329. */
  1330. static void nfs4_clone_super(struct super_block *sb,
  1331. const struct super_block *old_sb)
  1332. {
  1333. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1334. sb->s_blocksize = old_sb->s_blocksize;
  1335. sb->s_maxbytes = old_sb->s_maxbytes;
  1336. sb->s_time_gran = 1;
  1337. sb->s_op = old_sb->s_op;
  1338. nfs_initialise_sb(sb);
  1339. }
  1340. /*
  1341. * Set up an NFS4 superblock
  1342. */
  1343. static void nfs4_fill_super(struct super_block *sb)
  1344. {
  1345. sb->s_time_gran = 1;
  1346. sb->s_op = &nfs4_sops;
  1347. nfs_initialise_sb(sb);
  1348. }
  1349. /*
  1350. * Validate NFSv4 mount options
  1351. */
  1352. static int nfs4_validate_mount_data(void *options,
  1353. struct nfs_parsed_mount_data *args,
  1354. const char *dev_name)
  1355. {
  1356. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  1357. char *c;
  1358. if (data == NULL)
  1359. goto out_no_data;
  1360. memset(args, 0, sizeof(*args));
  1361. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1362. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1363. args->timeo = 600;
  1364. args->retrans = 2;
  1365. args->acregmin = 3;
  1366. args->acregmax = 60;
  1367. args->acdirmin = 30;
  1368. args->acdirmax = 60;
  1369. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1370. switch (data->version) {
  1371. case 1:
  1372. if (data->host_addrlen != sizeof(args->nfs_server.address))
  1373. goto out_no_address;
  1374. if (copy_from_user(&args->nfs_server.address,
  1375. data->host_addr,
  1376. sizeof(args->nfs_server.address)))
  1377. return -EFAULT;
  1378. if (args->nfs_server.address.sin_port == 0)
  1379. args->nfs_server.address.sin_port = htons(NFS_PORT);
  1380. if (!nfs_verify_server_address((struct sockaddr *)
  1381. &args->nfs_server.address))
  1382. goto out_no_address;
  1383. switch (data->auth_flavourlen) {
  1384. case 0:
  1385. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1386. break;
  1387. case 1:
  1388. if (copy_from_user(&args->auth_flavors[0],
  1389. data->auth_flavours,
  1390. sizeof(args->auth_flavors[0])))
  1391. return -EFAULT;
  1392. break;
  1393. default:
  1394. goto out_inval_auth;
  1395. }
  1396. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  1397. if (IS_ERR(c))
  1398. return PTR_ERR(c);
  1399. args->nfs_server.hostname = c;
  1400. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  1401. if (IS_ERR(c))
  1402. return PTR_ERR(c);
  1403. args->nfs_server.export_path = c;
  1404. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  1405. c = strndup_user(data->client_addr.data, 16);
  1406. if (IS_ERR(c))
  1407. return PTR_ERR(c);
  1408. args->client_address = c;
  1409. /*
  1410. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  1411. * can deal with.
  1412. */
  1413. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  1414. args->rsize = data->rsize;
  1415. args->wsize = data->wsize;
  1416. args->timeo = data->timeo;
  1417. args->retrans = data->retrans;
  1418. args->acregmin = data->acregmin;
  1419. args->acregmax = data->acregmax;
  1420. args->acdirmin = data->acdirmin;
  1421. args->acdirmax = data->acdirmax;
  1422. args->nfs_server.protocol = data->proto;
  1423. break;
  1424. default: {
  1425. unsigned int len;
  1426. if (nfs_parse_mount_options((char *)options, args) == 0)
  1427. return -EINVAL;
  1428. if (!nfs_verify_server_address((struct sockaddr *)
  1429. &args->nfs_server.address))
  1430. return -EINVAL;
  1431. switch (args->auth_flavor_len) {
  1432. case 0:
  1433. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1434. break;
  1435. case 1:
  1436. break;
  1437. default:
  1438. goto out_inval_auth;
  1439. }
  1440. /*
  1441. * Split "dev_name" into "hostname:mntpath".
  1442. */
  1443. c = strchr(dev_name, ':');
  1444. if (c == NULL)
  1445. return -EINVAL;
  1446. /* while calculating len, pretend ':' is '\0' */
  1447. len = c - dev_name;
  1448. if (len > NFS4_MAXNAMLEN)
  1449. return -ENAMETOOLONG;
  1450. args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
  1451. if (args->nfs_server.hostname == NULL)
  1452. return -ENOMEM;
  1453. strncpy(args->nfs_server.hostname, dev_name, len - 1);
  1454. c++; /* step over the ':' */
  1455. len = strlen(c);
  1456. if (len > NFS4_MAXPATHLEN)
  1457. return -ENAMETOOLONG;
  1458. args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
  1459. if (args->nfs_server.export_path == NULL)
  1460. return -ENOMEM;
  1461. strncpy(args->nfs_server.export_path, c, len);
  1462. dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
  1463. if (args->client_address == NULL)
  1464. goto out_no_client_address;
  1465. break;
  1466. }
  1467. }
  1468. return 0;
  1469. out_no_data:
  1470. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  1471. return -EINVAL;
  1472. out_inval_auth:
  1473. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  1474. data->auth_flavourlen);
  1475. return -EINVAL;
  1476. out_no_address:
  1477. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  1478. return -EINVAL;
  1479. out_no_client_address:
  1480. dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
  1481. return -EINVAL;
  1482. }
  1483. /*
  1484. * Get the superblock for an NFS4 mountpoint
  1485. */
  1486. static int nfs4_get_sb(struct file_system_type *fs_type,
  1487. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1488. {
  1489. struct nfs_parsed_mount_data data;
  1490. struct super_block *s;
  1491. struct nfs_server *server;
  1492. struct nfs_fh mntfh;
  1493. struct dentry *mntroot;
  1494. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1495. struct nfs_sb_mountdata sb_mntdata = {
  1496. .mntflags = flags,
  1497. };
  1498. int error;
  1499. /* Validate the mount data */
  1500. error = nfs4_validate_mount_data(raw_data, &data, dev_name);
  1501. if (error < 0)
  1502. goto out;
  1503. /* Get a volume representation */
  1504. server = nfs4_create_server(&data, &mntfh);
  1505. if (IS_ERR(server)) {
  1506. error = PTR_ERR(server);
  1507. goto out;
  1508. }
  1509. sb_mntdata.server = server;
  1510. if (server->flags & NFS4_MOUNT_UNSHARED)
  1511. compare_super = NULL;
  1512. /* Get a superblock - note that we may end up sharing one that already exists */
  1513. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1514. if (IS_ERR(s)) {
  1515. error = PTR_ERR(s);
  1516. goto out_free;
  1517. }
  1518. if (s->s_fs_info != server) {
  1519. nfs_free_server(server);
  1520. server = NULL;
  1521. }
  1522. if (!s->s_root) {
  1523. /* initial superblock/root creation */
  1524. nfs4_fill_super(s);
  1525. }
  1526. mntroot = nfs4_get_root(s, &mntfh);
  1527. if (IS_ERR(mntroot)) {
  1528. error = PTR_ERR(mntroot);
  1529. goto error_splat_super;
  1530. }
  1531. s->s_flags |= MS_ACTIVE;
  1532. mnt->mnt_sb = s;
  1533. mnt->mnt_root = mntroot;
  1534. error = 0;
  1535. out:
  1536. kfree(data.client_address);
  1537. kfree(data.nfs_server.export_path);
  1538. kfree(data.nfs_server.hostname);
  1539. return error;
  1540. out_free:
  1541. nfs_free_server(server);
  1542. goto out;
  1543. error_splat_super:
  1544. up_write(&s->s_umount);
  1545. deactivate_super(s);
  1546. goto out;
  1547. }
  1548. static void nfs4_kill_super(struct super_block *sb)
  1549. {
  1550. struct nfs_server *server = NFS_SB(sb);
  1551. nfs_return_all_delegations(sb);
  1552. kill_anon_super(sb);
  1553. nfs4_renewd_prepare_shutdown(server);
  1554. nfs_free_server(server);
  1555. }
  1556. /*
  1557. * Clone an NFS4 server record on xdev traversal (FSID-change)
  1558. */
  1559. static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1560. const char *dev_name, void *raw_data,
  1561. struct vfsmount *mnt)
  1562. {
  1563. struct nfs_clone_mount *data = raw_data;
  1564. struct super_block *s;
  1565. struct nfs_server *server;
  1566. struct dentry *mntroot;
  1567. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1568. struct nfs_sb_mountdata sb_mntdata = {
  1569. .mntflags = flags,
  1570. };
  1571. int error;
  1572. dprintk("--> nfs4_xdev_get_sb()\n");
  1573. /* create a new volume representation */
  1574. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1575. if (IS_ERR(server)) {
  1576. error = PTR_ERR(server);
  1577. goto out_err_noserver;
  1578. }
  1579. sb_mntdata.server = server;
  1580. if (server->flags & NFS4_MOUNT_UNSHARED)
  1581. compare_super = NULL;
  1582. /* Get a superblock - note that we may end up sharing one that already exists */
  1583. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1584. if (IS_ERR(s)) {
  1585. error = PTR_ERR(s);
  1586. goto out_err_nosb;
  1587. }
  1588. if (s->s_fs_info != server) {
  1589. nfs_free_server(server);
  1590. server = NULL;
  1591. }
  1592. if (!s->s_root) {
  1593. /* initial superblock/root creation */
  1594. nfs4_clone_super(s, data->sb);
  1595. }
  1596. mntroot = nfs4_get_root(s, data->fh);
  1597. if (IS_ERR(mntroot)) {
  1598. error = PTR_ERR(mntroot);
  1599. goto error_splat_super;
  1600. }
  1601. s->s_flags |= MS_ACTIVE;
  1602. mnt->mnt_sb = s;
  1603. mnt->mnt_root = mntroot;
  1604. dprintk("<-- nfs4_xdev_get_sb() = 0\n");
  1605. return 0;
  1606. out_err_nosb:
  1607. nfs_free_server(server);
  1608. out_err_noserver:
  1609. dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
  1610. return error;
  1611. error_splat_super:
  1612. up_write(&s->s_umount);
  1613. deactivate_super(s);
  1614. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  1615. return error;
  1616. }
  1617. /*
  1618. * Create an NFS4 server record on referral traversal
  1619. */
  1620. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  1621. const char *dev_name, void *raw_data,
  1622. struct vfsmount *mnt)
  1623. {
  1624. struct nfs_clone_mount *data = raw_data;
  1625. struct super_block *s;
  1626. struct nfs_server *server;
  1627. struct dentry *mntroot;
  1628. struct nfs_fh mntfh;
  1629. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1630. struct nfs_sb_mountdata sb_mntdata = {
  1631. .mntflags = flags,
  1632. };
  1633. int error;
  1634. dprintk("--> nfs4_referral_get_sb()\n");
  1635. /* create a new volume representation */
  1636. server = nfs4_create_referral_server(data, &mntfh);
  1637. if (IS_ERR(server)) {
  1638. error = PTR_ERR(server);
  1639. goto out_err_noserver;
  1640. }
  1641. sb_mntdata.server = server;
  1642. if (server->flags & NFS4_MOUNT_UNSHARED)
  1643. compare_super = NULL;
  1644. /* Get a superblock - note that we may end up sharing one that already exists */
  1645. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1646. if (IS_ERR(s)) {
  1647. error = PTR_ERR(s);
  1648. goto out_err_nosb;
  1649. }
  1650. if (s->s_fs_info != server) {
  1651. nfs_free_server(server);
  1652. server = NULL;
  1653. }
  1654. if (!s->s_root) {
  1655. /* initial superblock/root creation */
  1656. nfs4_fill_super(s);
  1657. }
  1658. mntroot = nfs4_get_root(s, &mntfh);
  1659. if (IS_ERR(mntroot)) {
  1660. error = PTR_ERR(mntroot);
  1661. goto error_splat_super;
  1662. }
  1663. s->s_flags |= MS_ACTIVE;
  1664. mnt->mnt_sb = s;
  1665. mnt->mnt_root = mntroot;
  1666. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  1667. return 0;
  1668. out_err_nosb:
  1669. nfs_free_server(server);
  1670. out_err_noserver:
  1671. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  1672. return error;
  1673. error_splat_super:
  1674. up_write(&s->s_umount);
  1675. deactivate_super(s);
  1676. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  1677. return error;
  1678. }
  1679. #endif /* CONFIG_NFS_V4 */