super.c 46 KB

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