super.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  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. memset(args, 0, sizeof(*args));
  956. if (data == NULL)
  957. goto out_no_data;
  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. if (mntroot->d_inode->i_op != &nfs_dir_inode_operations) {
  1311. dput(mntroot);
  1312. error = -ESTALE;
  1313. goto error_splat_super;
  1314. }
  1315. s->s_flags |= MS_ACTIVE;
  1316. mnt->mnt_sb = s;
  1317. mnt->mnt_root = mntroot;
  1318. dprintk("<-- nfs_xdev_get_sb() = 0\n");
  1319. return 0;
  1320. out_err_nosb:
  1321. nfs_free_server(server);
  1322. out_err_noserver:
  1323. dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
  1324. return error;
  1325. error_splat_super:
  1326. up_write(&s->s_umount);
  1327. deactivate_super(s);
  1328. dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
  1329. return error;
  1330. }
  1331. #ifdef CONFIG_NFS_V4
  1332. /*
  1333. * Finish setting up a cloned NFS4 superblock
  1334. */
  1335. static void nfs4_clone_super(struct super_block *sb,
  1336. const struct super_block *old_sb)
  1337. {
  1338. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1339. sb->s_blocksize = old_sb->s_blocksize;
  1340. sb->s_maxbytes = old_sb->s_maxbytes;
  1341. sb->s_time_gran = 1;
  1342. sb->s_op = old_sb->s_op;
  1343. nfs_initialise_sb(sb);
  1344. }
  1345. /*
  1346. * Set up an NFS4 superblock
  1347. */
  1348. static void nfs4_fill_super(struct super_block *sb)
  1349. {
  1350. sb->s_time_gran = 1;
  1351. sb->s_op = &nfs4_sops;
  1352. nfs_initialise_sb(sb);
  1353. }
  1354. /*
  1355. * Validate NFSv4 mount options
  1356. */
  1357. static int nfs4_validate_mount_data(void *options,
  1358. struct nfs_parsed_mount_data *args,
  1359. const char *dev_name)
  1360. {
  1361. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  1362. char *c;
  1363. memset(args, 0, sizeof(*args));
  1364. if (data == NULL)
  1365. goto out_no_data;
  1366. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1367. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1368. args->timeo = 600;
  1369. args->retrans = 2;
  1370. args->acregmin = 3;
  1371. args->acregmax = 60;
  1372. args->acdirmin = 30;
  1373. args->acdirmax = 60;
  1374. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1375. switch (data->version) {
  1376. case 1:
  1377. if (data->host_addrlen != sizeof(args->nfs_server.address))
  1378. goto out_no_address;
  1379. if (copy_from_user(&args->nfs_server.address,
  1380. data->host_addr,
  1381. sizeof(args->nfs_server.address)))
  1382. return -EFAULT;
  1383. if (args->nfs_server.address.sin_port == 0)
  1384. args->nfs_server.address.sin_port = htons(NFS_PORT);
  1385. if (!nfs_verify_server_address((struct sockaddr *)
  1386. &args->nfs_server.address))
  1387. goto out_no_address;
  1388. switch (data->auth_flavourlen) {
  1389. case 0:
  1390. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1391. break;
  1392. case 1:
  1393. if (copy_from_user(&args->auth_flavors[0],
  1394. data->auth_flavours,
  1395. sizeof(args->auth_flavors[0])))
  1396. return -EFAULT;
  1397. break;
  1398. default:
  1399. goto out_inval_auth;
  1400. }
  1401. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  1402. if (IS_ERR(c))
  1403. return PTR_ERR(c);
  1404. args->nfs_server.hostname = c;
  1405. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  1406. if (IS_ERR(c))
  1407. return PTR_ERR(c);
  1408. args->nfs_server.export_path = c;
  1409. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  1410. c = strndup_user(data->client_addr.data, 16);
  1411. if (IS_ERR(c))
  1412. return PTR_ERR(c);
  1413. args->client_address = c;
  1414. /*
  1415. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  1416. * can deal with.
  1417. */
  1418. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  1419. args->rsize = data->rsize;
  1420. args->wsize = data->wsize;
  1421. args->timeo = data->timeo;
  1422. args->retrans = data->retrans;
  1423. args->acregmin = data->acregmin;
  1424. args->acregmax = data->acregmax;
  1425. args->acdirmin = data->acdirmin;
  1426. args->acdirmax = data->acdirmax;
  1427. args->nfs_server.protocol = data->proto;
  1428. break;
  1429. default: {
  1430. unsigned int len;
  1431. if (nfs_parse_mount_options((char *)options, args) == 0)
  1432. return -EINVAL;
  1433. if (!nfs_verify_server_address((struct sockaddr *)
  1434. &args->nfs_server.address))
  1435. return -EINVAL;
  1436. switch (args->auth_flavor_len) {
  1437. case 0:
  1438. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1439. break;
  1440. case 1:
  1441. break;
  1442. default:
  1443. goto out_inval_auth;
  1444. }
  1445. /*
  1446. * Split "dev_name" into "hostname:mntpath".
  1447. */
  1448. c = strchr(dev_name, ':');
  1449. if (c == NULL)
  1450. return -EINVAL;
  1451. /* while calculating len, pretend ':' is '\0' */
  1452. len = c - dev_name;
  1453. if (len > NFS4_MAXNAMLEN)
  1454. return -ENAMETOOLONG;
  1455. args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
  1456. if (args->nfs_server.hostname == NULL)
  1457. return -ENOMEM;
  1458. strncpy(args->nfs_server.hostname, dev_name, len - 1);
  1459. c++; /* step over the ':' */
  1460. len = strlen(c);
  1461. if (len > NFS4_MAXPATHLEN)
  1462. return -ENAMETOOLONG;
  1463. args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
  1464. if (args->nfs_server.export_path == NULL)
  1465. return -ENOMEM;
  1466. strncpy(args->nfs_server.export_path, c, len);
  1467. dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
  1468. if (args->client_address == NULL)
  1469. goto out_no_client_address;
  1470. break;
  1471. }
  1472. }
  1473. return 0;
  1474. out_no_data:
  1475. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  1476. return -EINVAL;
  1477. out_inval_auth:
  1478. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  1479. data->auth_flavourlen);
  1480. return -EINVAL;
  1481. out_no_address:
  1482. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  1483. return -EINVAL;
  1484. out_no_client_address:
  1485. dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
  1486. return -EINVAL;
  1487. }
  1488. /*
  1489. * Get the superblock for an NFS4 mountpoint
  1490. */
  1491. static int nfs4_get_sb(struct file_system_type *fs_type,
  1492. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1493. {
  1494. struct nfs_parsed_mount_data data;
  1495. struct super_block *s;
  1496. struct nfs_server *server;
  1497. struct nfs_fh mntfh;
  1498. struct dentry *mntroot;
  1499. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1500. struct nfs_sb_mountdata sb_mntdata = {
  1501. .mntflags = flags,
  1502. };
  1503. int error;
  1504. /* Validate the mount data */
  1505. error = nfs4_validate_mount_data(raw_data, &data, dev_name);
  1506. if (error < 0)
  1507. goto out;
  1508. /* Get a volume representation */
  1509. server = nfs4_create_server(&data, &mntfh);
  1510. if (IS_ERR(server)) {
  1511. error = PTR_ERR(server);
  1512. goto out;
  1513. }
  1514. sb_mntdata.server = server;
  1515. if (server->flags & NFS4_MOUNT_UNSHARED)
  1516. compare_super = NULL;
  1517. /* Get a superblock - note that we may end up sharing one that already exists */
  1518. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1519. if (IS_ERR(s)) {
  1520. error = PTR_ERR(s);
  1521. goto out_free;
  1522. }
  1523. if (s->s_fs_info != server) {
  1524. nfs_free_server(server);
  1525. server = NULL;
  1526. }
  1527. if (!s->s_root) {
  1528. /* initial superblock/root creation */
  1529. nfs4_fill_super(s);
  1530. }
  1531. mntroot = nfs4_get_root(s, &mntfh);
  1532. if (IS_ERR(mntroot)) {
  1533. error = PTR_ERR(mntroot);
  1534. goto error_splat_super;
  1535. }
  1536. s->s_flags |= MS_ACTIVE;
  1537. mnt->mnt_sb = s;
  1538. mnt->mnt_root = mntroot;
  1539. error = 0;
  1540. out:
  1541. kfree(data.client_address);
  1542. kfree(data.nfs_server.export_path);
  1543. kfree(data.nfs_server.hostname);
  1544. return error;
  1545. out_free:
  1546. nfs_free_server(server);
  1547. goto out;
  1548. error_splat_super:
  1549. up_write(&s->s_umount);
  1550. deactivate_super(s);
  1551. goto out;
  1552. }
  1553. static void nfs4_kill_super(struct super_block *sb)
  1554. {
  1555. struct nfs_server *server = NFS_SB(sb);
  1556. nfs_return_all_delegations(sb);
  1557. kill_anon_super(sb);
  1558. nfs4_renewd_prepare_shutdown(server);
  1559. nfs_free_server(server);
  1560. }
  1561. /*
  1562. * Clone an NFS4 server record on xdev traversal (FSID-change)
  1563. */
  1564. static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1565. const char *dev_name, void *raw_data,
  1566. struct vfsmount *mnt)
  1567. {
  1568. struct nfs_clone_mount *data = raw_data;
  1569. struct super_block *s;
  1570. struct nfs_server *server;
  1571. struct dentry *mntroot;
  1572. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1573. struct nfs_sb_mountdata sb_mntdata = {
  1574. .mntflags = flags,
  1575. };
  1576. int error;
  1577. dprintk("--> nfs4_xdev_get_sb()\n");
  1578. /* create a new volume representation */
  1579. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1580. if (IS_ERR(server)) {
  1581. error = PTR_ERR(server);
  1582. goto out_err_noserver;
  1583. }
  1584. sb_mntdata.server = server;
  1585. if (server->flags & NFS4_MOUNT_UNSHARED)
  1586. compare_super = NULL;
  1587. /* Get a superblock - note that we may end up sharing one that already exists */
  1588. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1589. if (IS_ERR(s)) {
  1590. error = PTR_ERR(s);
  1591. goto out_err_nosb;
  1592. }
  1593. if (s->s_fs_info != server) {
  1594. nfs_free_server(server);
  1595. server = NULL;
  1596. }
  1597. if (!s->s_root) {
  1598. /* initial superblock/root creation */
  1599. nfs4_clone_super(s, data->sb);
  1600. }
  1601. mntroot = nfs4_get_root(s, data->fh);
  1602. if (IS_ERR(mntroot)) {
  1603. error = PTR_ERR(mntroot);
  1604. goto error_splat_super;
  1605. }
  1606. s->s_flags |= MS_ACTIVE;
  1607. mnt->mnt_sb = s;
  1608. mnt->mnt_root = mntroot;
  1609. dprintk("<-- nfs4_xdev_get_sb() = 0\n");
  1610. return 0;
  1611. out_err_nosb:
  1612. nfs_free_server(server);
  1613. out_err_noserver:
  1614. dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
  1615. return error;
  1616. error_splat_super:
  1617. up_write(&s->s_umount);
  1618. deactivate_super(s);
  1619. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  1620. return error;
  1621. }
  1622. /*
  1623. * Create an NFS4 server record on referral traversal
  1624. */
  1625. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  1626. const char *dev_name, void *raw_data,
  1627. struct vfsmount *mnt)
  1628. {
  1629. struct nfs_clone_mount *data = raw_data;
  1630. struct super_block *s;
  1631. struct nfs_server *server;
  1632. struct dentry *mntroot;
  1633. struct nfs_fh mntfh;
  1634. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1635. struct nfs_sb_mountdata sb_mntdata = {
  1636. .mntflags = flags,
  1637. };
  1638. int error;
  1639. dprintk("--> nfs4_referral_get_sb()\n");
  1640. /* create a new volume representation */
  1641. server = nfs4_create_referral_server(data, &mntfh);
  1642. if (IS_ERR(server)) {
  1643. error = PTR_ERR(server);
  1644. goto out_err_noserver;
  1645. }
  1646. sb_mntdata.server = server;
  1647. if (server->flags & NFS4_MOUNT_UNSHARED)
  1648. compare_super = NULL;
  1649. /* Get a superblock - note that we may end up sharing one that already exists */
  1650. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1651. if (IS_ERR(s)) {
  1652. error = PTR_ERR(s);
  1653. goto out_err_nosb;
  1654. }
  1655. if (s->s_fs_info != server) {
  1656. nfs_free_server(server);
  1657. server = NULL;
  1658. }
  1659. if (!s->s_root) {
  1660. /* initial superblock/root creation */
  1661. nfs4_fill_super(s);
  1662. }
  1663. mntroot = nfs4_get_root(s, &mntfh);
  1664. if (IS_ERR(mntroot)) {
  1665. error = PTR_ERR(mntroot);
  1666. goto error_splat_super;
  1667. }
  1668. s->s_flags |= MS_ACTIVE;
  1669. mnt->mnt_sb = s;
  1670. mnt->mnt_root = mntroot;
  1671. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  1672. return 0;
  1673. out_err_nosb:
  1674. nfs_free_server(server);
  1675. out_err_noserver:
  1676. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  1677. return error;
  1678. error_splat_super:
  1679. up_write(&s->s_umount);
  1680. deactivate_super(s);
  1681. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  1682. return error;
  1683. }
  1684. #endif /* CONFIG_NFS_V4 */