super.c 47 KB

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