super.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  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_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  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. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  1607. dput(mntroot);
  1608. error = -ESTALE;
  1609. goto error_splat_super;
  1610. }
  1611. s->s_flags |= MS_ACTIVE;
  1612. mnt->mnt_sb = s;
  1613. mnt->mnt_root = mntroot;
  1614. dprintk("<-- nfs4_xdev_get_sb() = 0\n");
  1615. return 0;
  1616. out_err_nosb:
  1617. nfs_free_server(server);
  1618. out_err_noserver:
  1619. dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
  1620. return error;
  1621. error_splat_super:
  1622. up_write(&s->s_umount);
  1623. deactivate_super(s);
  1624. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  1625. return error;
  1626. }
  1627. /*
  1628. * Create an NFS4 server record on referral traversal
  1629. */
  1630. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  1631. const char *dev_name, void *raw_data,
  1632. struct vfsmount *mnt)
  1633. {
  1634. struct nfs_clone_mount *data = raw_data;
  1635. struct super_block *s;
  1636. struct nfs_server *server;
  1637. struct dentry *mntroot;
  1638. struct nfs_fh mntfh;
  1639. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1640. struct nfs_sb_mountdata sb_mntdata = {
  1641. .mntflags = flags,
  1642. };
  1643. int error;
  1644. dprintk("--> nfs4_referral_get_sb()\n");
  1645. /* create a new volume representation */
  1646. server = nfs4_create_referral_server(data, &mntfh);
  1647. if (IS_ERR(server)) {
  1648. error = PTR_ERR(server);
  1649. goto out_err_noserver;
  1650. }
  1651. sb_mntdata.server = server;
  1652. if (server->flags & NFS4_MOUNT_UNSHARED)
  1653. compare_super = NULL;
  1654. /* Get a superblock - note that we may end up sharing one that already exists */
  1655. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1656. if (IS_ERR(s)) {
  1657. error = PTR_ERR(s);
  1658. goto out_err_nosb;
  1659. }
  1660. if (s->s_fs_info != server) {
  1661. nfs_free_server(server);
  1662. server = NULL;
  1663. }
  1664. if (!s->s_root) {
  1665. /* initial superblock/root creation */
  1666. nfs4_fill_super(s);
  1667. }
  1668. mntroot = nfs4_get_root(s, &mntfh);
  1669. if (IS_ERR(mntroot)) {
  1670. error = PTR_ERR(mntroot);
  1671. goto error_splat_super;
  1672. }
  1673. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  1674. dput(mntroot);
  1675. error = -ESTALE;
  1676. goto error_splat_super;
  1677. }
  1678. s->s_flags |= MS_ACTIVE;
  1679. mnt->mnt_sb = s;
  1680. mnt->mnt_root = mntroot;
  1681. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  1682. return 0;
  1683. out_err_nosb:
  1684. nfs_free_server(server);
  1685. out_err_noserver:
  1686. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  1687. return error;
  1688. error_splat_super:
  1689. up_write(&s->s_umount);
  1690. deactivate_super(s);
  1691. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  1692. return error;
  1693. }
  1694. #endif /* CONFIG_NFS_V4 */