super.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566
  1. /*
  2. * linux/fs/nfs/super.c
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * nfs superblock handling functions
  7. *
  8. * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
  9. * experimental NFS changes. Modularisation taken straight from SYS5 fs.
  10. *
  11. * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
  12. * J.S.Peatfield@damtp.cam.ac.uk
  13. *
  14. * Split from inode.c by David Howells <dhowells@redhat.com>
  15. *
  16. * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
  17. * particular server are held in the same superblock
  18. * - NFS superblocks can have several effective roots to the dentry tree
  19. * - directory type roots are spliced into the tree when a path from one root reaches the root
  20. * of another (see nfs_lookup())
  21. */
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/time.h>
  25. #include <linux/kernel.h>
  26. #include <linux/mm.h>
  27. #include <linux/string.h>
  28. #include <linux/stat.h>
  29. #include <linux/errno.h>
  30. #include <linux/unistd.h>
  31. #include <linux/sunrpc/clnt.h>
  32. #include <linux/sunrpc/stats.h>
  33. #include <linux/sunrpc/metrics.h>
  34. #include <linux/sunrpc/xprtsock.h>
  35. #include <linux/sunrpc/xprtrdma.h>
  36. #include <linux/nfs_fs.h>
  37. #include <linux/nfs_mount.h>
  38. #include <linux/nfs4_mount.h>
  39. #include <linux/lockd/bind.h>
  40. #include <linux/smp_lock.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/mount.h>
  43. #include <linux/nfs_idmap.h>
  44. #include <linux/vfs.h>
  45. #include <linux/inet.h>
  46. #include <linux/in6.h>
  47. #include <net/ipv6.h>
  48. #include <linux/netdevice.h>
  49. #include <linux/nfs_xdr.h>
  50. #include <linux/magic.h>
  51. #include <linux/parser.h>
  52. #include <asm/system.h>
  53. #include <asm/uaccess.h>
  54. #include "nfs4_fs.h"
  55. #include "callback.h"
  56. #include "delegation.h"
  57. #include "iostat.h"
  58. #include "internal.h"
  59. #define NFSDBG_FACILITY NFSDBG_VFS
  60. enum {
  61. /* Mount options that take no arguments */
  62. Opt_soft, Opt_hard,
  63. Opt_posix, Opt_noposix,
  64. Opt_cto, Opt_nocto,
  65. Opt_ac, Opt_noac,
  66. Opt_lock, Opt_nolock,
  67. Opt_v2, Opt_v3,
  68. Opt_udp, Opt_tcp, Opt_rdma,
  69. Opt_acl, Opt_noacl,
  70. Opt_rdirplus, Opt_nordirplus,
  71. Opt_sharecache, Opt_nosharecache,
  72. /* Mount options that take integer arguments */
  73. Opt_port,
  74. Opt_rsize, Opt_wsize, Opt_bsize,
  75. Opt_timeo, Opt_retrans,
  76. Opt_acregmin, Opt_acregmax,
  77. Opt_acdirmin, Opt_acdirmax,
  78. Opt_actimeo,
  79. Opt_namelen,
  80. Opt_mountport,
  81. Opt_mountvers,
  82. Opt_nfsvers,
  83. /* Mount options that take string arguments */
  84. Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
  85. Opt_addr, Opt_mountaddr, Opt_clientaddr,
  86. /* Special mount options */
  87. Opt_userspace, Opt_deprecated, Opt_sloppy,
  88. Opt_err
  89. };
  90. static match_table_t nfs_mount_option_tokens = {
  91. { Opt_userspace, "bg" },
  92. { Opt_userspace, "fg" },
  93. { Opt_userspace, "retry=%s" },
  94. { Opt_sloppy, "sloppy" },
  95. { Opt_soft, "soft" },
  96. { Opt_hard, "hard" },
  97. { Opt_deprecated, "intr" },
  98. { Opt_deprecated, "nointr" },
  99. { Opt_posix, "posix" },
  100. { Opt_noposix, "noposix" },
  101. { Opt_cto, "cto" },
  102. { Opt_nocto, "nocto" },
  103. { Opt_ac, "ac" },
  104. { Opt_noac, "noac" },
  105. { Opt_lock, "lock" },
  106. { Opt_nolock, "nolock" },
  107. { Opt_v2, "v2" },
  108. { Opt_v3, "v3" },
  109. { Opt_udp, "udp" },
  110. { Opt_tcp, "tcp" },
  111. { Opt_rdma, "rdma" },
  112. { Opt_acl, "acl" },
  113. { Opt_noacl, "noacl" },
  114. { Opt_rdirplus, "rdirplus" },
  115. { Opt_nordirplus, "nordirplus" },
  116. { Opt_sharecache, "sharecache" },
  117. { Opt_nosharecache, "nosharecache" },
  118. { Opt_port, "port=%u" },
  119. { Opt_rsize, "rsize=%u" },
  120. { Opt_wsize, "wsize=%u" },
  121. { Opt_bsize, "bsize=%u" },
  122. { Opt_timeo, "timeo=%u" },
  123. { Opt_retrans, "retrans=%u" },
  124. { Opt_acregmin, "acregmin=%u" },
  125. { Opt_acregmax, "acregmax=%u" },
  126. { Opt_acdirmin, "acdirmin=%u" },
  127. { Opt_acdirmax, "acdirmax=%u" },
  128. { Opt_actimeo, "actimeo=%u" },
  129. { Opt_namelen, "namlen=%u" },
  130. { Opt_mountport, "mountport=%u" },
  131. { Opt_mountvers, "mountvers=%u" },
  132. { Opt_nfsvers, "nfsvers=%u" },
  133. { Opt_nfsvers, "vers=%u" },
  134. { Opt_sec, "sec=%s" },
  135. { Opt_proto, "proto=%s" },
  136. { Opt_mountproto, "mountproto=%s" },
  137. { Opt_addr, "addr=%s" },
  138. { Opt_clientaddr, "clientaddr=%s" },
  139. { Opt_mounthost, "mounthost=%s" },
  140. { Opt_mountaddr, "mountaddr=%s" },
  141. { Opt_err, NULL }
  142. };
  143. enum {
  144. Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
  145. Opt_xprt_err
  146. };
  147. static match_table_t nfs_xprt_protocol_tokens = {
  148. { Opt_xprt_udp, "udp" },
  149. { Opt_xprt_tcp, "tcp" },
  150. { Opt_xprt_rdma, "rdma" },
  151. { Opt_xprt_err, NULL }
  152. };
  153. enum {
  154. Opt_sec_none, Opt_sec_sys,
  155. Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
  156. Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
  157. Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
  158. Opt_sec_err
  159. };
  160. static match_table_t nfs_secflavor_tokens = {
  161. { Opt_sec_none, "none" },
  162. { Opt_sec_none, "null" },
  163. { Opt_sec_sys, "sys" },
  164. { Opt_sec_krb5, "krb5" },
  165. { Opt_sec_krb5i, "krb5i" },
  166. { Opt_sec_krb5p, "krb5p" },
  167. { Opt_sec_lkey, "lkey" },
  168. { Opt_sec_lkeyi, "lkeyi" },
  169. { Opt_sec_lkeyp, "lkeyp" },
  170. { Opt_sec_spkm, "spkm3" },
  171. { Opt_sec_spkmi, "spkm3i" },
  172. { Opt_sec_spkmp, "spkm3p" },
  173. { Opt_sec_err, NULL }
  174. };
  175. static void nfs_umount_begin(struct super_block *);
  176. static int nfs_statfs(struct dentry *, struct kstatfs *);
  177. static int nfs_show_options(struct seq_file *, struct vfsmount *);
  178. static int nfs_show_stats(struct seq_file *, struct vfsmount *);
  179. static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
  180. static int nfs_xdev_get_sb(struct file_system_type *fs_type,
  181. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  182. static void nfs_kill_super(struct super_block *);
  183. static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
  184. static struct file_system_type nfs_fs_type = {
  185. .owner = THIS_MODULE,
  186. .name = "nfs",
  187. .get_sb = nfs_get_sb,
  188. .kill_sb = nfs_kill_super,
  189. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  190. };
  191. struct file_system_type nfs_xdev_fs_type = {
  192. .owner = THIS_MODULE,
  193. .name = "nfs",
  194. .get_sb = nfs_xdev_get_sb,
  195. .kill_sb = nfs_kill_super,
  196. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  197. };
  198. static const struct super_operations nfs_sops = {
  199. .alloc_inode = nfs_alloc_inode,
  200. .destroy_inode = nfs_destroy_inode,
  201. .write_inode = nfs_write_inode,
  202. .statfs = nfs_statfs,
  203. .clear_inode = nfs_clear_inode,
  204. .umount_begin = nfs_umount_begin,
  205. .show_options = nfs_show_options,
  206. .show_stats = nfs_show_stats,
  207. .remount_fs = nfs_remount,
  208. };
  209. #ifdef CONFIG_NFS_V4
  210. static int nfs4_get_sb(struct file_system_type *fs_type,
  211. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  212. static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
  213. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  214. static int nfs4_referral_get_sb(struct file_system_type *fs_type,
  215. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
  216. static void nfs4_kill_super(struct super_block *sb);
  217. static struct file_system_type nfs4_fs_type = {
  218. .owner = THIS_MODULE,
  219. .name = "nfs4",
  220. .get_sb = nfs4_get_sb,
  221. .kill_sb = nfs4_kill_super,
  222. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  223. };
  224. struct file_system_type nfs4_xdev_fs_type = {
  225. .owner = THIS_MODULE,
  226. .name = "nfs4",
  227. .get_sb = nfs4_xdev_get_sb,
  228. .kill_sb = nfs4_kill_super,
  229. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  230. };
  231. struct file_system_type nfs4_referral_fs_type = {
  232. .owner = THIS_MODULE,
  233. .name = "nfs4",
  234. .get_sb = nfs4_referral_get_sb,
  235. .kill_sb = nfs4_kill_super,
  236. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
  237. };
  238. static const struct super_operations nfs4_sops = {
  239. .alloc_inode = nfs_alloc_inode,
  240. .destroy_inode = nfs_destroy_inode,
  241. .write_inode = nfs_write_inode,
  242. .statfs = nfs_statfs,
  243. .clear_inode = nfs4_clear_inode,
  244. .umount_begin = nfs_umount_begin,
  245. .show_options = nfs_show_options,
  246. .show_stats = nfs_show_stats,
  247. .remount_fs = nfs_remount,
  248. };
  249. #endif
  250. static struct shrinker acl_shrinker = {
  251. .shrink = nfs_access_cache_shrinker,
  252. .seeks = DEFAULT_SEEKS,
  253. };
  254. /*
  255. * Register the NFS filesystems
  256. */
  257. int __init register_nfs_fs(void)
  258. {
  259. int ret;
  260. ret = register_filesystem(&nfs_fs_type);
  261. if (ret < 0)
  262. goto error_0;
  263. ret = nfs_register_sysctl();
  264. if (ret < 0)
  265. goto error_1;
  266. #ifdef CONFIG_NFS_V4
  267. ret = register_filesystem(&nfs4_fs_type);
  268. if (ret < 0)
  269. goto error_2;
  270. #endif
  271. register_shrinker(&acl_shrinker);
  272. return 0;
  273. #ifdef CONFIG_NFS_V4
  274. error_2:
  275. nfs_unregister_sysctl();
  276. #endif
  277. error_1:
  278. unregister_filesystem(&nfs_fs_type);
  279. error_0:
  280. return ret;
  281. }
  282. /*
  283. * Unregister the NFS filesystems
  284. */
  285. void __exit unregister_nfs_fs(void)
  286. {
  287. unregister_shrinker(&acl_shrinker);
  288. #ifdef CONFIG_NFS_V4
  289. unregister_filesystem(&nfs4_fs_type);
  290. #endif
  291. nfs_unregister_sysctl();
  292. unregister_filesystem(&nfs_fs_type);
  293. }
  294. void nfs_sb_active(struct super_block *sb)
  295. {
  296. struct nfs_server *server = NFS_SB(sb);
  297. if (atomic_inc_return(&server->active) == 1)
  298. atomic_inc(&sb->s_active);
  299. }
  300. void nfs_sb_deactive(struct super_block *sb)
  301. {
  302. struct nfs_server *server = NFS_SB(sb);
  303. if (atomic_dec_and_test(&server->active))
  304. deactivate_super(sb);
  305. }
  306. /*
  307. * Deliver file system statistics to userspace
  308. */
  309. static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  310. {
  311. struct nfs_server *server = NFS_SB(dentry->d_sb);
  312. unsigned char blockbits;
  313. unsigned long blockres;
  314. struct nfs_fh *fh = NFS_FH(dentry->d_inode);
  315. struct nfs_fattr fattr;
  316. struct nfs_fsstat res = {
  317. .fattr = &fattr,
  318. };
  319. int error;
  320. error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
  321. if (error < 0)
  322. goto out_err;
  323. buf->f_type = NFS_SUPER_MAGIC;
  324. /*
  325. * Current versions of glibc do not correctly handle the
  326. * case where f_frsize != f_bsize. Eventually we want to
  327. * report the value of wtmult in this field.
  328. */
  329. buf->f_frsize = dentry->d_sb->s_blocksize;
  330. /*
  331. * On most *nix systems, f_blocks, f_bfree, and f_bavail
  332. * are reported in units of f_frsize. Linux hasn't had
  333. * an f_frsize field in its statfs struct until recently,
  334. * thus historically Linux's sys_statfs reports these
  335. * fields in units of f_bsize.
  336. */
  337. buf->f_bsize = dentry->d_sb->s_blocksize;
  338. blockbits = dentry->d_sb->s_blocksize_bits;
  339. blockres = (1 << blockbits) - 1;
  340. buf->f_blocks = (res.tbytes + blockres) >> blockbits;
  341. buf->f_bfree = (res.fbytes + blockres) >> blockbits;
  342. buf->f_bavail = (res.abytes + blockres) >> blockbits;
  343. buf->f_files = res.tfiles;
  344. buf->f_ffree = res.afiles;
  345. buf->f_namelen = server->namelen;
  346. return 0;
  347. out_err:
  348. dprintk("%s: statfs error = %d\n", __func__, -error);
  349. return error;
  350. }
  351. /*
  352. * Map the security flavour number to a name
  353. */
  354. static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
  355. {
  356. static const struct {
  357. rpc_authflavor_t flavour;
  358. const char *str;
  359. } sec_flavours[] = {
  360. { RPC_AUTH_NULL, "null" },
  361. { RPC_AUTH_UNIX, "sys" },
  362. { RPC_AUTH_GSS_KRB5, "krb5" },
  363. { RPC_AUTH_GSS_KRB5I, "krb5i" },
  364. { RPC_AUTH_GSS_KRB5P, "krb5p" },
  365. { RPC_AUTH_GSS_LKEY, "lkey" },
  366. { RPC_AUTH_GSS_LKEYI, "lkeyi" },
  367. { RPC_AUTH_GSS_LKEYP, "lkeyp" },
  368. { RPC_AUTH_GSS_SPKM, "spkm" },
  369. { RPC_AUTH_GSS_SPKMI, "spkmi" },
  370. { RPC_AUTH_GSS_SPKMP, "spkmp" },
  371. { UINT_MAX, "unknown" }
  372. };
  373. int i;
  374. for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
  375. if (sec_flavours[i].flavour == flavour)
  376. break;
  377. }
  378. return sec_flavours[i].str;
  379. }
  380. static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
  381. int showdefaults)
  382. {
  383. struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
  384. switch (sap->sa_family) {
  385. case AF_INET: {
  386. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  387. seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
  388. NIPQUAD(sin->sin_addr.s_addr));
  389. break;
  390. }
  391. case AF_INET6: {
  392. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  393. seq_printf(m, ",mountaddr=" NIP6_FMT,
  394. NIP6(sin6->sin6_addr));
  395. break;
  396. }
  397. default:
  398. if (showdefaults)
  399. seq_printf(m, ",mountaddr=unspecified");
  400. }
  401. if (nfss->mountd_version || showdefaults)
  402. seq_printf(m, ",mountvers=%u", nfss->mountd_version);
  403. if (nfss->mountd_port || showdefaults)
  404. seq_printf(m, ",mountport=%u", nfss->mountd_port);
  405. switch (nfss->mountd_protocol) {
  406. case IPPROTO_UDP:
  407. seq_printf(m, ",mountproto=udp");
  408. break;
  409. case IPPROTO_TCP:
  410. seq_printf(m, ",mountproto=tcp");
  411. break;
  412. default:
  413. if (showdefaults)
  414. seq_printf(m, ",mountproto=auto");
  415. }
  416. }
  417. /*
  418. * Describe the mount options in force on this server representation
  419. */
  420. static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
  421. int showdefaults)
  422. {
  423. static const struct proc_nfs_info {
  424. int flag;
  425. const char *str;
  426. const char *nostr;
  427. } nfs_info[] = {
  428. { NFS_MOUNT_SOFT, ",soft", ",hard" },
  429. { NFS_MOUNT_INTR, ",intr", ",nointr" },
  430. { NFS_MOUNT_POSIX, ",posix", "" },
  431. { NFS_MOUNT_NOCTO, ",nocto", "" },
  432. { NFS_MOUNT_NOAC, ",noac", "" },
  433. { NFS_MOUNT_NONLM, ",nolock", "" },
  434. { NFS_MOUNT_NOACL, ",noacl", "" },
  435. { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
  436. { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
  437. { 0, NULL, NULL }
  438. };
  439. const struct proc_nfs_info *nfs_infop;
  440. struct nfs_client *clp = nfss->nfs_client;
  441. u32 version = clp->rpc_ops->version;
  442. seq_printf(m, ",vers=%u", version);
  443. seq_printf(m, ",rsize=%u", nfss->rsize);
  444. seq_printf(m, ",wsize=%u", nfss->wsize);
  445. if (nfss->bsize != 0)
  446. seq_printf(m, ",bsize=%u", nfss->bsize);
  447. seq_printf(m, ",namlen=%u", nfss->namelen);
  448. if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
  449. seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
  450. if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
  451. seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
  452. if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
  453. seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
  454. if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
  455. seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
  456. for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
  457. if (nfss->flags & nfs_infop->flag)
  458. seq_puts(m, nfs_infop->str);
  459. else
  460. seq_puts(m, nfs_infop->nostr);
  461. }
  462. seq_printf(m, ",proto=%s",
  463. rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
  464. if (version == 4) {
  465. if (nfss->port != NFS_PORT)
  466. seq_printf(m, ",port=%u", nfss->port);
  467. } else
  468. if (nfss->port)
  469. seq_printf(m, ",port=%u", nfss->port);
  470. seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
  471. seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
  472. seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
  473. if (version != 4)
  474. nfs_show_mountd_options(m, nfss, showdefaults);
  475. #ifdef CONFIG_NFS_V4
  476. if (clp->rpc_ops->version == 4)
  477. seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
  478. #endif
  479. }
  480. /*
  481. * Describe the mount options on this VFS mountpoint
  482. */
  483. static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
  484. {
  485. struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
  486. nfs_show_mount_options(m, nfss, 0);
  487. seq_printf(m, ",addr=%s",
  488. rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
  489. RPC_DISPLAY_ADDR));
  490. return 0;
  491. }
  492. /*
  493. * Present statistical information for this VFS mountpoint
  494. */
  495. static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
  496. {
  497. int i, cpu;
  498. struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
  499. struct rpc_auth *auth = nfss->client->cl_auth;
  500. struct nfs_iostats totals = { };
  501. seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
  502. /*
  503. * Display all mount option settings
  504. */
  505. seq_printf(m, "\n\topts:\t");
  506. seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
  507. seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
  508. seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
  509. seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
  510. nfs_show_mount_options(m, nfss, 1);
  511. seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
  512. seq_printf(m, "\n\tcaps:\t");
  513. seq_printf(m, "caps=0x%x", nfss->caps);
  514. seq_printf(m, ",wtmult=%u", nfss->wtmult);
  515. seq_printf(m, ",dtsize=%u", nfss->dtsize);
  516. seq_printf(m, ",bsize=%u", nfss->bsize);
  517. seq_printf(m, ",namlen=%u", nfss->namelen);
  518. #ifdef CONFIG_NFS_V4
  519. if (nfss->nfs_client->rpc_ops->version == 4) {
  520. seq_printf(m, "\n\tnfsv4:\t");
  521. seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
  522. seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
  523. seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
  524. }
  525. #endif
  526. /*
  527. * Display security flavor in effect for this mount
  528. */
  529. seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
  530. if (auth->au_flavor)
  531. seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
  532. /*
  533. * Display superblock I/O counters
  534. */
  535. for_each_possible_cpu(cpu) {
  536. struct nfs_iostats *stats;
  537. preempt_disable();
  538. stats = per_cpu_ptr(nfss->io_stats, cpu);
  539. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  540. totals.events[i] += stats->events[i];
  541. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  542. totals.bytes[i] += stats->bytes[i];
  543. preempt_enable();
  544. }
  545. seq_printf(m, "\n\tevents:\t");
  546. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  547. seq_printf(m, "%lu ", totals.events[i]);
  548. seq_printf(m, "\n\tbytes:\t");
  549. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  550. seq_printf(m, "%Lu ", totals.bytes[i]);
  551. seq_printf(m, "\n");
  552. rpc_print_iostats(m, nfss->client);
  553. return 0;
  554. }
  555. /*
  556. * Begin unmount by attempting to remove all automounted mountpoints we added
  557. * in response to xdev traversals and referrals
  558. */
  559. static void nfs_umount_begin(struct super_block *sb)
  560. {
  561. struct nfs_server *server = NFS_SB(sb);
  562. struct rpc_clnt *rpc;
  563. /* -EIO all pending I/O */
  564. rpc = server->client_acl;
  565. if (!IS_ERR(rpc))
  566. rpc_killall_tasks(rpc);
  567. rpc = server->client;
  568. if (!IS_ERR(rpc))
  569. rpc_killall_tasks(rpc);
  570. }
  571. /*
  572. * Set the port number in an address. Be agnostic about the address family.
  573. */
  574. static void nfs_set_port(struct sockaddr *sap, unsigned short port)
  575. {
  576. switch (sap->sa_family) {
  577. case AF_INET: {
  578. struct sockaddr_in *ap = (struct sockaddr_in *)sap;
  579. ap->sin_port = htons(port);
  580. break;
  581. }
  582. case AF_INET6: {
  583. struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
  584. ap->sin6_port = htons(port);
  585. break;
  586. }
  587. }
  588. }
  589. /*
  590. * Sanity-check a server address provided by the mount command.
  591. *
  592. * Address family must be initialized, and address must not be
  593. * the ANY address for that family.
  594. */
  595. static int nfs_verify_server_address(struct sockaddr *addr)
  596. {
  597. switch (addr->sa_family) {
  598. case AF_INET: {
  599. struct sockaddr_in *sa = (struct sockaddr_in *)addr;
  600. return sa->sin_addr.s_addr != htonl(INADDR_ANY);
  601. }
  602. case AF_INET6: {
  603. struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
  604. return !ipv6_addr_any(sa);
  605. }
  606. }
  607. return 0;
  608. }
  609. static void nfs_parse_ipv4_address(char *string, size_t str_len,
  610. struct sockaddr *sap, size_t *addr_len)
  611. {
  612. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  613. u8 *addr = (u8 *)&sin->sin_addr.s_addr;
  614. if (str_len <= INET_ADDRSTRLEN) {
  615. dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
  616. (int)str_len, string);
  617. sin->sin_family = AF_INET;
  618. *addr_len = sizeof(*sin);
  619. if (in4_pton(string, str_len, addr, '\0', NULL))
  620. return;
  621. }
  622. sap->sa_family = AF_UNSPEC;
  623. *addr_len = 0;
  624. }
  625. #define IPV6_SCOPE_DELIMITER '%'
  626. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  627. static void nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
  628. const char *delim,
  629. struct sockaddr_in6 *sin6)
  630. {
  631. char *p;
  632. size_t len;
  633. if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
  634. return ;
  635. if (*delim != IPV6_SCOPE_DELIMITER)
  636. return;
  637. len = (string + str_len) - delim - 1;
  638. p = kstrndup(delim + 1, len, GFP_KERNEL);
  639. if (p) {
  640. unsigned long scope_id = 0;
  641. struct net_device *dev;
  642. dev = dev_get_by_name(&init_net, p);
  643. if (dev != NULL) {
  644. scope_id = dev->ifindex;
  645. dev_put(dev);
  646. } else {
  647. /* scope_id is set to zero on error */
  648. strict_strtoul(p, 10, &scope_id);
  649. }
  650. kfree(p);
  651. sin6->sin6_scope_id = scope_id;
  652. dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
  653. }
  654. }
  655. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  656. struct sockaddr *sap, size_t *addr_len)
  657. {
  658. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  659. u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
  660. const char *delim;
  661. if (str_len <= INET6_ADDRSTRLEN) {
  662. dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
  663. (int)str_len, string);
  664. sin6->sin6_family = AF_INET6;
  665. *addr_len = sizeof(*sin6);
  666. if (in6_pton(string, str_len, addr, IPV6_SCOPE_DELIMITER, &delim)) {
  667. nfs_parse_ipv6_scope_id(string, str_len, delim, sin6);
  668. return;
  669. }
  670. }
  671. sap->sa_family = AF_UNSPEC;
  672. *addr_len = 0;
  673. }
  674. #else
  675. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  676. struct sockaddr *sap, size_t *addr_len)
  677. {
  678. sap->sa_family = AF_UNSPEC;
  679. *addr_len = 0;
  680. }
  681. #endif
  682. /*
  683. * Construct a sockaddr based on the contents of a string that contains
  684. * an IP address in presentation format.
  685. *
  686. * If there is a problem constructing the new sockaddr, set the address
  687. * family to AF_UNSPEC.
  688. */
  689. static void nfs_parse_ip_address(char *string, size_t str_len,
  690. struct sockaddr *sap, size_t *addr_len)
  691. {
  692. unsigned int i, colons;
  693. colons = 0;
  694. for (i = 0; i < str_len; i++)
  695. if (string[i] == ':')
  696. colons++;
  697. if (colons >= 2)
  698. nfs_parse_ipv6_address(string, str_len, sap, addr_len);
  699. else
  700. nfs_parse_ipv4_address(string, str_len, sap, addr_len);
  701. }
  702. /*
  703. * Sanity check the NFS transport protocol.
  704. *
  705. */
  706. static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
  707. {
  708. switch (mnt->nfs_server.protocol) {
  709. case XPRT_TRANSPORT_UDP:
  710. case XPRT_TRANSPORT_TCP:
  711. case XPRT_TRANSPORT_RDMA:
  712. break;
  713. default:
  714. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  715. }
  716. }
  717. /*
  718. * For text based NFSv2/v3 mounts, the mount protocol transport default
  719. * settings should depend upon the specified NFS transport.
  720. */
  721. static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
  722. {
  723. nfs_validate_transport_protocol(mnt);
  724. if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
  725. mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
  726. return;
  727. switch (mnt->nfs_server.protocol) {
  728. case XPRT_TRANSPORT_UDP:
  729. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  730. break;
  731. case XPRT_TRANSPORT_TCP:
  732. case XPRT_TRANSPORT_RDMA:
  733. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  734. }
  735. }
  736. /*
  737. * Parse the value of the 'sec=' option.
  738. *
  739. * The flavor_len setting is for v4 mounts.
  740. */
  741. static int nfs_parse_security_flavors(char *value,
  742. struct nfs_parsed_mount_data *mnt)
  743. {
  744. substring_t args[MAX_OPT_ARGS];
  745. dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
  746. switch (match_token(value, nfs_secflavor_tokens, args)) {
  747. case Opt_sec_none:
  748. mnt->auth_flavor_len = 0;
  749. mnt->auth_flavors[0] = RPC_AUTH_NULL;
  750. break;
  751. case Opt_sec_sys:
  752. mnt->auth_flavor_len = 0;
  753. mnt->auth_flavors[0] = RPC_AUTH_UNIX;
  754. break;
  755. case Opt_sec_krb5:
  756. mnt->auth_flavor_len = 1;
  757. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
  758. break;
  759. case Opt_sec_krb5i:
  760. mnt->auth_flavor_len = 1;
  761. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
  762. break;
  763. case Opt_sec_krb5p:
  764. mnt->auth_flavor_len = 1;
  765. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
  766. break;
  767. case Opt_sec_lkey:
  768. mnt->auth_flavor_len = 1;
  769. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
  770. break;
  771. case Opt_sec_lkeyi:
  772. mnt->auth_flavor_len = 1;
  773. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
  774. break;
  775. case Opt_sec_lkeyp:
  776. mnt->auth_flavor_len = 1;
  777. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
  778. break;
  779. case Opt_sec_spkm:
  780. mnt->auth_flavor_len = 1;
  781. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
  782. break;
  783. case Opt_sec_spkmi:
  784. mnt->auth_flavor_len = 1;
  785. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
  786. break;
  787. case Opt_sec_spkmp:
  788. mnt->auth_flavor_len = 1;
  789. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
  790. break;
  791. default:
  792. return 0;
  793. }
  794. return 1;
  795. }
  796. static void nfs_parse_invalid_value(const char *option)
  797. {
  798. dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
  799. }
  800. /*
  801. * Error-check and convert a string of mount options from user space into
  802. * a data structure. The whole mount string is processed; bad options are
  803. * skipped as they are encountered. If there were no errors, return 1;
  804. * otherwise return 0 (zero).
  805. */
  806. static int nfs_parse_mount_options(char *raw,
  807. struct nfs_parsed_mount_data *mnt)
  808. {
  809. char *p, *string, *secdata;
  810. int rc, sloppy = 0, errors = 0;
  811. if (!raw) {
  812. dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
  813. return 1;
  814. }
  815. dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
  816. secdata = alloc_secdata();
  817. if (!secdata)
  818. goto out_nomem;
  819. rc = security_sb_copy_data(raw, secdata);
  820. if (rc)
  821. goto out_security_failure;
  822. rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
  823. if (rc)
  824. goto out_security_failure;
  825. free_secdata(secdata);
  826. while ((p = strsep(&raw, ",")) != NULL) {
  827. substring_t args[MAX_OPT_ARGS];
  828. int option, token;
  829. if (!*p)
  830. continue;
  831. dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
  832. token = match_token(p, nfs_mount_option_tokens, args);
  833. switch (token) {
  834. /*
  835. * boolean options: foo/nofoo
  836. */
  837. case Opt_soft:
  838. mnt->flags |= NFS_MOUNT_SOFT;
  839. break;
  840. case Opt_hard:
  841. mnt->flags &= ~NFS_MOUNT_SOFT;
  842. break;
  843. case Opt_posix:
  844. mnt->flags |= NFS_MOUNT_POSIX;
  845. break;
  846. case Opt_noposix:
  847. mnt->flags &= ~NFS_MOUNT_POSIX;
  848. break;
  849. case Opt_cto:
  850. mnt->flags &= ~NFS_MOUNT_NOCTO;
  851. break;
  852. case Opt_nocto:
  853. mnt->flags |= NFS_MOUNT_NOCTO;
  854. break;
  855. case Opt_ac:
  856. mnt->flags &= ~NFS_MOUNT_NOAC;
  857. break;
  858. case Opt_noac:
  859. mnt->flags |= NFS_MOUNT_NOAC;
  860. break;
  861. case Opt_lock:
  862. mnt->flags &= ~NFS_MOUNT_NONLM;
  863. break;
  864. case Opt_nolock:
  865. mnt->flags |= NFS_MOUNT_NONLM;
  866. break;
  867. case Opt_v2:
  868. mnt->flags &= ~NFS_MOUNT_VER3;
  869. break;
  870. case Opt_v3:
  871. mnt->flags |= NFS_MOUNT_VER3;
  872. break;
  873. case Opt_udp:
  874. mnt->flags &= ~NFS_MOUNT_TCP;
  875. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  876. break;
  877. case Opt_tcp:
  878. mnt->flags |= NFS_MOUNT_TCP;
  879. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  880. break;
  881. case Opt_rdma:
  882. mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
  883. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  884. break;
  885. case Opt_acl:
  886. mnt->flags &= ~NFS_MOUNT_NOACL;
  887. break;
  888. case Opt_noacl:
  889. mnt->flags |= NFS_MOUNT_NOACL;
  890. break;
  891. case Opt_rdirplus:
  892. mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
  893. break;
  894. case Opt_nordirplus:
  895. mnt->flags |= NFS_MOUNT_NORDIRPLUS;
  896. break;
  897. case Opt_sharecache:
  898. mnt->flags &= ~NFS_MOUNT_UNSHARED;
  899. break;
  900. case Opt_nosharecache:
  901. mnt->flags |= NFS_MOUNT_UNSHARED;
  902. break;
  903. /*
  904. * options that take numeric values
  905. */
  906. case Opt_port:
  907. if (match_int(args, &option) ||
  908. option < 0 || option > USHORT_MAX) {
  909. errors++;
  910. nfs_parse_invalid_value("port");
  911. } else
  912. mnt->nfs_server.port = option;
  913. break;
  914. case Opt_rsize:
  915. if (match_int(args, &option) || option < 0) {
  916. errors++;
  917. nfs_parse_invalid_value("rsize");
  918. } else
  919. mnt->rsize = option;
  920. break;
  921. case Opt_wsize:
  922. if (match_int(args, &option) || option < 0) {
  923. errors++;
  924. nfs_parse_invalid_value("wsize");
  925. } else
  926. mnt->wsize = option;
  927. break;
  928. case Opt_bsize:
  929. if (match_int(args, &option) || option < 0) {
  930. errors++;
  931. nfs_parse_invalid_value("bsize");
  932. } else
  933. mnt->bsize = option;
  934. break;
  935. case Opt_timeo:
  936. if (match_int(args, &option) || option <= 0) {
  937. errors++;
  938. nfs_parse_invalid_value("timeo");
  939. } else
  940. mnt->timeo = option;
  941. break;
  942. case Opt_retrans:
  943. if (match_int(args, &option) || option <= 0) {
  944. errors++;
  945. nfs_parse_invalid_value("retrans");
  946. } else
  947. mnt->retrans = option;
  948. break;
  949. case Opt_acregmin:
  950. if (match_int(args, &option) || option < 0) {
  951. errors++;
  952. nfs_parse_invalid_value("acregmin");
  953. } else
  954. mnt->acregmin = option;
  955. break;
  956. case Opt_acregmax:
  957. if (match_int(args, &option) || option < 0) {
  958. errors++;
  959. nfs_parse_invalid_value("acregmax");
  960. } else
  961. mnt->acregmax = option;
  962. break;
  963. case Opt_acdirmin:
  964. if (match_int(args, &option) || option < 0) {
  965. errors++;
  966. nfs_parse_invalid_value("acdirmin");
  967. } else
  968. mnt->acdirmin = option;
  969. break;
  970. case Opt_acdirmax:
  971. if (match_int(args, &option) || option < 0) {
  972. errors++;
  973. nfs_parse_invalid_value("acdirmax");
  974. } else
  975. mnt->acdirmax = option;
  976. break;
  977. case Opt_actimeo:
  978. if (match_int(args, &option) || option < 0) {
  979. errors++;
  980. nfs_parse_invalid_value("actimeo");
  981. } else
  982. mnt->acregmin = mnt->acregmax =
  983. mnt->acdirmin = mnt->acdirmax = option;
  984. break;
  985. case Opt_namelen:
  986. if (match_int(args, &option) || option < 0) {
  987. errors++;
  988. nfs_parse_invalid_value("namlen");
  989. } else
  990. mnt->namlen = option;
  991. break;
  992. case Opt_mountport:
  993. if (match_int(args, &option) ||
  994. option < 0 || option > USHORT_MAX) {
  995. errors++;
  996. nfs_parse_invalid_value("mountport");
  997. } else
  998. mnt->mount_server.port = option;
  999. break;
  1000. case Opt_mountvers:
  1001. if (match_int(args, &option) ||
  1002. option < NFS_MNT_VERSION ||
  1003. option > NFS_MNT3_VERSION) {
  1004. errors++;
  1005. nfs_parse_invalid_value("mountvers");
  1006. } else
  1007. mnt->mount_server.version = option;
  1008. break;
  1009. case Opt_nfsvers:
  1010. if (match_int(args, &option)) {
  1011. errors++;
  1012. nfs_parse_invalid_value("nfsvers");
  1013. break;
  1014. }
  1015. switch (option) {
  1016. case NFS2_VERSION:
  1017. mnt->flags &= ~NFS_MOUNT_VER3;
  1018. break;
  1019. case NFS3_VERSION:
  1020. mnt->flags |= NFS_MOUNT_VER3;
  1021. break;
  1022. default:
  1023. errors++;
  1024. nfs_parse_invalid_value("nfsvers");
  1025. }
  1026. break;
  1027. /*
  1028. * options that take text values
  1029. */
  1030. case Opt_sec:
  1031. string = match_strdup(args);
  1032. if (string == NULL)
  1033. goto out_nomem;
  1034. rc = nfs_parse_security_flavors(string, mnt);
  1035. kfree(string);
  1036. if (!rc) {
  1037. errors++;
  1038. dfprintk(MOUNT, "NFS: unrecognized "
  1039. "security flavor\n");
  1040. }
  1041. break;
  1042. case Opt_proto:
  1043. string = match_strdup(args);
  1044. if (string == NULL)
  1045. goto out_nomem;
  1046. token = match_token(string,
  1047. nfs_xprt_protocol_tokens, args);
  1048. kfree(string);
  1049. switch (token) {
  1050. case Opt_xprt_udp:
  1051. mnt->flags &= ~NFS_MOUNT_TCP;
  1052. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1053. break;
  1054. case Opt_xprt_tcp:
  1055. mnt->flags |= NFS_MOUNT_TCP;
  1056. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1057. break;
  1058. case Opt_xprt_rdma:
  1059. /* vector side protocols to TCP */
  1060. mnt->flags |= NFS_MOUNT_TCP;
  1061. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1062. break;
  1063. default:
  1064. errors++;
  1065. dfprintk(MOUNT, "NFS: unrecognized "
  1066. "transport protocol\n");
  1067. }
  1068. break;
  1069. case Opt_mountproto:
  1070. string = match_strdup(args);
  1071. if (string == NULL)
  1072. goto out_nomem;
  1073. token = match_token(string,
  1074. nfs_xprt_protocol_tokens, args);
  1075. kfree(string);
  1076. switch (token) {
  1077. case Opt_xprt_udp:
  1078. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  1079. break;
  1080. case Opt_xprt_tcp:
  1081. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  1082. break;
  1083. case Opt_xprt_rdma: /* not used for side protocols */
  1084. default:
  1085. errors++;
  1086. dfprintk(MOUNT, "NFS: unrecognized "
  1087. "transport protocol\n");
  1088. }
  1089. break;
  1090. case Opt_addr:
  1091. string = match_strdup(args);
  1092. if (string == NULL)
  1093. goto out_nomem;
  1094. nfs_parse_ip_address(string, strlen(string),
  1095. (struct sockaddr *)
  1096. &mnt->nfs_server.address,
  1097. &mnt->nfs_server.addrlen);
  1098. kfree(string);
  1099. break;
  1100. case Opt_clientaddr:
  1101. string = match_strdup(args);
  1102. if (string == NULL)
  1103. goto out_nomem;
  1104. kfree(mnt->client_address);
  1105. mnt->client_address = string;
  1106. break;
  1107. case Opt_mounthost:
  1108. string = match_strdup(args);
  1109. if (string == NULL)
  1110. goto out_nomem;
  1111. kfree(mnt->mount_server.hostname);
  1112. mnt->mount_server.hostname = string;
  1113. break;
  1114. case Opt_mountaddr:
  1115. string = match_strdup(args);
  1116. if (string == NULL)
  1117. goto out_nomem;
  1118. nfs_parse_ip_address(string, strlen(string),
  1119. (struct sockaddr *)
  1120. &mnt->mount_server.address,
  1121. &mnt->mount_server.addrlen);
  1122. kfree(string);
  1123. break;
  1124. /*
  1125. * Special options
  1126. */
  1127. case Opt_sloppy:
  1128. sloppy = 1;
  1129. dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
  1130. break;
  1131. case Opt_userspace:
  1132. case Opt_deprecated:
  1133. dfprintk(MOUNT, "NFS: ignoring mount option "
  1134. "'%s'\n", p);
  1135. break;
  1136. default:
  1137. errors++;
  1138. dfprintk(MOUNT, "NFS: unrecognized mount option "
  1139. "'%s'\n", p);
  1140. }
  1141. }
  1142. if (errors > 0) {
  1143. dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
  1144. errors, (errors == 1 ? "" : "s"));
  1145. if (!sloppy)
  1146. return 0;
  1147. }
  1148. return 1;
  1149. out_nomem:
  1150. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  1151. return 0;
  1152. out_security_failure:
  1153. free_secdata(secdata);
  1154. printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
  1155. return 0;
  1156. }
  1157. /*
  1158. * Use the remote server's MOUNT service to request the NFS file handle
  1159. * corresponding to the provided path.
  1160. */
  1161. static int nfs_try_mount(struct nfs_parsed_mount_data *args,
  1162. struct nfs_fh *root_fh)
  1163. {
  1164. struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
  1165. char *hostname;
  1166. int status;
  1167. if (args->mount_server.version == 0) {
  1168. if (args->flags & NFS_MOUNT_VER3)
  1169. args->mount_server.version = NFS_MNT3_VERSION;
  1170. else
  1171. args->mount_server.version = NFS_MNT_VERSION;
  1172. }
  1173. if (args->mount_server.hostname)
  1174. hostname = args->mount_server.hostname;
  1175. else
  1176. hostname = args->nfs_server.hostname;
  1177. /*
  1178. * Construct the mount server's address.
  1179. */
  1180. if (args->mount_server.address.ss_family == AF_UNSPEC) {
  1181. memcpy(sap, &args->nfs_server.address,
  1182. args->nfs_server.addrlen);
  1183. args->mount_server.addrlen = args->nfs_server.addrlen;
  1184. }
  1185. /*
  1186. * autobind will be used if mount_server.port == 0
  1187. */
  1188. nfs_set_port(sap, args->mount_server.port);
  1189. /*
  1190. * Now ask the mount server to map our export path
  1191. * to a file handle.
  1192. */
  1193. status = nfs_mount(sap,
  1194. args->mount_server.addrlen,
  1195. hostname,
  1196. args->nfs_server.export_path,
  1197. args->mount_server.version,
  1198. args->mount_server.protocol,
  1199. root_fh);
  1200. if (status == 0)
  1201. return 0;
  1202. dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
  1203. hostname, status);
  1204. return status;
  1205. }
  1206. static int nfs_parse_simple_hostname(const char *dev_name,
  1207. char **hostname, size_t maxnamlen,
  1208. char **export_path, size_t maxpathlen)
  1209. {
  1210. size_t len;
  1211. char *colon, *comma;
  1212. colon = strchr(dev_name, ':');
  1213. if (colon == NULL)
  1214. goto out_bad_devname;
  1215. len = colon - dev_name;
  1216. if (len > maxnamlen)
  1217. goto out_hostname;
  1218. /* N.B. caller will free nfs_server.hostname in all cases */
  1219. *hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1220. if (!*hostname)
  1221. goto out_nomem;
  1222. /* kill possible hostname list: not supported */
  1223. comma = strchr(*hostname, ',');
  1224. if (comma != NULL) {
  1225. if (comma == *hostname)
  1226. goto out_bad_devname;
  1227. *comma = '\0';
  1228. }
  1229. colon++;
  1230. len = strlen(colon);
  1231. if (len > maxpathlen)
  1232. goto out_path;
  1233. *export_path = kstrndup(colon, len, GFP_KERNEL);
  1234. if (!*export_path)
  1235. goto out_nomem;
  1236. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
  1237. return 0;
  1238. out_bad_devname:
  1239. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1240. return -EINVAL;
  1241. out_nomem:
  1242. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1243. return -ENOMEM;
  1244. out_hostname:
  1245. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1246. return -ENAMETOOLONG;
  1247. out_path:
  1248. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1249. return -ENAMETOOLONG;
  1250. }
  1251. /*
  1252. * Hostname has square brackets around it because it contains one or
  1253. * more colons. We look for the first closing square bracket, and a
  1254. * colon must follow it.
  1255. */
  1256. static int nfs_parse_protected_hostname(const char *dev_name,
  1257. char **hostname, size_t maxnamlen,
  1258. char **export_path, size_t maxpathlen)
  1259. {
  1260. size_t len;
  1261. char *start, *end;
  1262. start = (char *)(dev_name + 1);
  1263. end = strchr(start, ']');
  1264. if (end == NULL)
  1265. goto out_bad_devname;
  1266. if (*(end + 1) != ':')
  1267. goto out_bad_devname;
  1268. len = end - start;
  1269. if (len > maxnamlen)
  1270. goto out_hostname;
  1271. /* N.B. caller will free nfs_server.hostname in all cases */
  1272. *hostname = kstrndup(start, len, GFP_KERNEL);
  1273. if (*hostname == NULL)
  1274. goto out_nomem;
  1275. end += 2;
  1276. len = strlen(end);
  1277. if (len > maxpathlen)
  1278. goto out_path;
  1279. *export_path = kstrndup(end, len, GFP_KERNEL);
  1280. if (!*export_path)
  1281. goto out_nomem;
  1282. return 0;
  1283. out_bad_devname:
  1284. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1285. return -EINVAL;
  1286. out_nomem:
  1287. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1288. return -ENOMEM;
  1289. out_hostname:
  1290. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1291. return -ENAMETOOLONG;
  1292. out_path:
  1293. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1294. return -ENAMETOOLONG;
  1295. }
  1296. /*
  1297. * Split "dev_name" into "hostname:export_path".
  1298. *
  1299. * The leftmost colon demarks the split between the server's hostname
  1300. * and the export path. If the hostname starts with a left square
  1301. * bracket, then it may contain colons.
  1302. *
  1303. * Note: caller frees hostname and export path, even on error.
  1304. */
  1305. static int nfs_parse_devname(const char *dev_name,
  1306. char **hostname, size_t maxnamlen,
  1307. char **export_path, size_t maxpathlen)
  1308. {
  1309. if (*dev_name == '[')
  1310. return nfs_parse_protected_hostname(dev_name,
  1311. hostname, maxnamlen,
  1312. export_path, maxpathlen);
  1313. return nfs_parse_simple_hostname(dev_name,
  1314. hostname, maxnamlen,
  1315. export_path, maxpathlen);
  1316. }
  1317. /*
  1318. * Validate the NFS2/NFS3 mount data
  1319. * - fills in the mount root filehandle
  1320. *
  1321. * For option strings, user space handles the following behaviors:
  1322. *
  1323. * + DNS: mapping server host name to IP address ("addr=" option)
  1324. *
  1325. * + failure mode: how to behave if a mount request can't be handled
  1326. * immediately ("fg/bg" option)
  1327. *
  1328. * + retry: how often to retry a mount request ("retry=" option)
  1329. *
  1330. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  1331. * mountproto=tcp after mountproto=udp, and so on
  1332. */
  1333. static int nfs_validate_mount_data(void *options,
  1334. struct nfs_parsed_mount_data *args,
  1335. struct nfs_fh *mntfh,
  1336. const char *dev_name)
  1337. {
  1338. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  1339. if (data == NULL)
  1340. goto out_no_data;
  1341. args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
  1342. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1343. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1344. args->acregmin = NFS_DEF_ACREGMIN;
  1345. args->acregmax = NFS_DEF_ACREGMAX;
  1346. args->acdirmin = NFS_DEF_ACDIRMIN;
  1347. args->acdirmax = NFS_DEF_ACDIRMAX;
  1348. args->mount_server.port = 0; /* autobind unless user sets port */
  1349. args->nfs_server.port = 0; /* autobind unless user sets port */
  1350. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1351. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1352. switch (data->version) {
  1353. case 1:
  1354. data->namlen = 0;
  1355. case 2:
  1356. data->bsize = 0;
  1357. case 3:
  1358. if (data->flags & NFS_MOUNT_VER3)
  1359. goto out_no_v3;
  1360. data->root.size = NFS2_FHSIZE;
  1361. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  1362. case 4:
  1363. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1364. goto out_no_sec;
  1365. case 5:
  1366. memset(data->context, 0, sizeof(data->context));
  1367. case 6:
  1368. if (data->flags & NFS_MOUNT_VER3) {
  1369. if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
  1370. goto out_invalid_fh;
  1371. mntfh->size = data->root.size;
  1372. } else
  1373. mntfh->size = NFS2_FHSIZE;
  1374. memcpy(mntfh->data, data->root.data, mntfh->size);
  1375. if (mntfh->size < sizeof(mntfh->data))
  1376. memset(mntfh->data + mntfh->size, 0,
  1377. sizeof(mntfh->data) - mntfh->size);
  1378. /*
  1379. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1380. * can deal with.
  1381. */
  1382. args->flags = data->flags & NFS_MOUNT_FLAGMASK;
  1383. args->rsize = data->rsize;
  1384. args->wsize = data->wsize;
  1385. args->timeo = data->timeo;
  1386. args->retrans = data->retrans;
  1387. args->acregmin = data->acregmin;
  1388. args->acregmax = data->acregmax;
  1389. args->acdirmin = data->acdirmin;
  1390. args->acdirmax = data->acdirmax;
  1391. memcpy(&args->nfs_server.address, &data->addr,
  1392. sizeof(data->addr));
  1393. args->nfs_server.addrlen = sizeof(data->addr);
  1394. if (!nfs_verify_server_address((struct sockaddr *)
  1395. &args->nfs_server.address))
  1396. goto out_no_address;
  1397. if (!(data->flags & NFS_MOUNT_TCP))
  1398. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1399. /* N.B. caller will free nfs_server.hostname in all cases */
  1400. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1401. args->namlen = data->namlen;
  1402. args->bsize = data->bsize;
  1403. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1404. args->auth_flavors[0] = data->pseudoflavor;
  1405. if (!args->nfs_server.hostname)
  1406. goto out_nomem;
  1407. /*
  1408. * The legacy version 6 binary mount data from userspace has a
  1409. * field used only to transport selinux information into the
  1410. * the kernel. To continue to support that functionality we
  1411. * have a touch of selinux knowledge here in the NFS code. The
  1412. * userspace code converted context=blah to just blah so we are
  1413. * converting back to the full string selinux understands.
  1414. */
  1415. if (data->context[0]){
  1416. #ifdef CONFIG_SECURITY_SELINUX
  1417. int rc;
  1418. char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
  1419. if (!opts_str)
  1420. return -ENOMEM;
  1421. strcpy(opts_str, "context=");
  1422. data->context[NFS_MAX_CONTEXT_LEN] = '\0';
  1423. strcat(opts_str, &data->context[0]);
  1424. rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
  1425. kfree(opts_str);
  1426. if (rc)
  1427. return rc;
  1428. #else
  1429. return -EINVAL;
  1430. #endif
  1431. }
  1432. break;
  1433. default: {
  1434. int status;
  1435. if (nfs_parse_mount_options((char *)options, args) == 0)
  1436. return -EINVAL;
  1437. if (!nfs_verify_server_address((struct sockaddr *)
  1438. &args->nfs_server.address))
  1439. goto out_no_address;
  1440. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1441. args->nfs_server.port);
  1442. nfs_set_mount_transport_protocol(args);
  1443. status = nfs_parse_devname(dev_name,
  1444. &args->nfs_server.hostname,
  1445. PAGE_SIZE,
  1446. &args->nfs_server.export_path,
  1447. NFS_MAXPATHLEN);
  1448. if (!status)
  1449. status = nfs_try_mount(args, mntfh);
  1450. kfree(args->nfs_server.export_path);
  1451. args->nfs_server.export_path = NULL;
  1452. if (status)
  1453. return status;
  1454. break;
  1455. }
  1456. }
  1457. #ifndef CONFIG_NFS_V3
  1458. if (args->flags & NFS_MOUNT_VER3)
  1459. goto out_v3_not_compiled;
  1460. #endif /* !CONFIG_NFS_V3 */
  1461. return 0;
  1462. out_no_data:
  1463. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1464. return -EINVAL;
  1465. out_no_v3:
  1466. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1467. data->version);
  1468. return -EINVAL;
  1469. out_no_sec:
  1470. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1471. return -EINVAL;
  1472. #ifndef CONFIG_NFS_V3
  1473. out_v3_not_compiled:
  1474. dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
  1475. return -EPROTONOSUPPORT;
  1476. #endif /* !CONFIG_NFS_V3 */
  1477. out_nomem:
  1478. dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
  1479. return -ENOMEM;
  1480. out_no_address:
  1481. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1482. return -EINVAL;
  1483. out_invalid_fh:
  1484. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1485. return -EINVAL;
  1486. }
  1487. static int
  1488. nfs_compare_remount_data(struct nfs_server *nfss,
  1489. struct nfs_parsed_mount_data *data)
  1490. {
  1491. if (data->flags != nfss->flags ||
  1492. data->rsize != nfss->rsize ||
  1493. data->wsize != nfss->wsize ||
  1494. data->retrans != nfss->client->cl_timeout->to_retries ||
  1495. data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
  1496. data->acregmin != nfss->acregmin / HZ ||
  1497. data->acregmax != nfss->acregmax / HZ ||
  1498. data->acdirmin != nfss->acdirmin / HZ ||
  1499. data->acdirmax != nfss->acdirmax / HZ ||
  1500. data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
  1501. data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
  1502. memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1503. data->nfs_server.addrlen) != 0)
  1504. return -EINVAL;
  1505. return 0;
  1506. }
  1507. static int
  1508. nfs_remount(struct super_block *sb, int *flags, char *raw_data)
  1509. {
  1510. int error;
  1511. struct nfs_server *nfss = sb->s_fs_info;
  1512. struct nfs_parsed_mount_data *data;
  1513. struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
  1514. struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
  1515. u32 nfsvers = nfss->nfs_client->rpc_ops->version;
  1516. /*
  1517. * Userspace mount programs that send binary options generally send
  1518. * them populated with default values. We have no way to know which
  1519. * ones were explicitly specified. Fall back to legacy behavior and
  1520. * just return success.
  1521. */
  1522. if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
  1523. (nfsvers <= 3 && (!options || (options->version >= 1 &&
  1524. options->version <= 6))))
  1525. return 0;
  1526. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1527. if (data == NULL)
  1528. return -ENOMEM;
  1529. /* fill out struct with values from existing mount */
  1530. data->flags = nfss->flags;
  1531. data->rsize = nfss->rsize;
  1532. data->wsize = nfss->wsize;
  1533. data->retrans = nfss->client->cl_timeout->to_retries;
  1534. data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
  1535. data->acregmin = nfss->acregmin / HZ;
  1536. data->acregmax = nfss->acregmax / HZ;
  1537. data->acdirmin = nfss->acdirmin / HZ;
  1538. data->acdirmax = nfss->acdirmax / HZ;
  1539. data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
  1540. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  1541. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1542. data->nfs_server.addrlen);
  1543. /* overwrite those values with any that were specified */
  1544. error = nfs_parse_mount_options((char *)options, data);
  1545. if (error < 0)
  1546. goto out;
  1547. /* compare new mount options with old ones */
  1548. error = nfs_compare_remount_data(nfss, data);
  1549. out:
  1550. kfree(data);
  1551. return error;
  1552. }
  1553. /*
  1554. * Initialise the common bits of the superblock
  1555. */
  1556. static inline void nfs_initialise_sb(struct super_block *sb)
  1557. {
  1558. struct nfs_server *server = NFS_SB(sb);
  1559. sb->s_magic = NFS_SUPER_MAGIC;
  1560. /* We probably want something more informative here */
  1561. snprintf(sb->s_id, sizeof(sb->s_id),
  1562. "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  1563. if (sb->s_blocksize == 0)
  1564. sb->s_blocksize = nfs_block_bits(server->wsize,
  1565. &sb->s_blocksize_bits);
  1566. if (server->flags & NFS_MOUNT_NOAC)
  1567. sb->s_flags |= MS_SYNCHRONOUS;
  1568. nfs_super_set_maxbytes(sb, server->maxfilesize);
  1569. }
  1570. /*
  1571. * Finish setting up an NFS2/3 superblock
  1572. */
  1573. static void nfs_fill_super(struct super_block *sb,
  1574. struct nfs_parsed_mount_data *data)
  1575. {
  1576. struct nfs_server *server = NFS_SB(sb);
  1577. sb->s_blocksize_bits = 0;
  1578. sb->s_blocksize = 0;
  1579. if (data->bsize)
  1580. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  1581. if (server->flags & NFS_MOUNT_VER3) {
  1582. /* The VFS shouldn't apply the umask to mode bits. We will do
  1583. * so ourselves when necessary.
  1584. */
  1585. sb->s_flags |= MS_POSIXACL;
  1586. sb->s_time_gran = 1;
  1587. }
  1588. sb->s_op = &nfs_sops;
  1589. nfs_initialise_sb(sb);
  1590. }
  1591. /*
  1592. * Finish setting up a cloned NFS2/3 superblock
  1593. */
  1594. static void nfs_clone_super(struct super_block *sb,
  1595. const struct super_block *old_sb)
  1596. {
  1597. struct nfs_server *server = NFS_SB(sb);
  1598. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1599. sb->s_blocksize = old_sb->s_blocksize;
  1600. sb->s_maxbytes = old_sb->s_maxbytes;
  1601. if (server->flags & NFS_MOUNT_VER3) {
  1602. /* The VFS shouldn't apply the umask to mode bits. We will do
  1603. * so ourselves when necessary.
  1604. */
  1605. sb->s_flags |= MS_POSIXACL;
  1606. sb->s_time_gran = 1;
  1607. }
  1608. sb->s_op = old_sb->s_op;
  1609. nfs_initialise_sb(sb);
  1610. }
  1611. #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
  1612. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  1613. {
  1614. const struct nfs_server *a = s->s_fs_info;
  1615. const struct rpc_clnt *clnt_a = a->client;
  1616. const struct rpc_clnt *clnt_b = b->client;
  1617. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  1618. goto Ebusy;
  1619. if (a->nfs_client != b->nfs_client)
  1620. goto Ebusy;
  1621. if (a->flags != b->flags)
  1622. goto Ebusy;
  1623. if (a->wsize != b->wsize)
  1624. goto Ebusy;
  1625. if (a->rsize != b->rsize)
  1626. goto Ebusy;
  1627. if (a->acregmin != b->acregmin)
  1628. goto Ebusy;
  1629. if (a->acregmax != b->acregmax)
  1630. goto Ebusy;
  1631. if (a->acdirmin != b->acdirmin)
  1632. goto Ebusy;
  1633. if (a->acdirmax != b->acdirmax)
  1634. goto Ebusy;
  1635. if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  1636. goto Ebusy;
  1637. return 1;
  1638. Ebusy:
  1639. return 0;
  1640. }
  1641. struct nfs_sb_mountdata {
  1642. struct nfs_server *server;
  1643. int mntflags;
  1644. };
  1645. static int nfs_set_super(struct super_block *s, void *data)
  1646. {
  1647. struct nfs_sb_mountdata *sb_mntdata = data;
  1648. struct nfs_server *server = sb_mntdata->server;
  1649. int ret;
  1650. s->s_flags = sb_mntdata->mntflags;
  1651. s->s_fs_info = server;
  1652. ret = set_anon_super(s, server);
  1653. if (ret == 0)
  1654. server->s_dev = s->s_dev;
  1655. return ret;
  1656. }
  1657. static int nfs_compare_super_address(struct nfs_server *server1,
  1658. struct nfs_server *server2)
  1659. {
  1660. struct sockaddr *sap1, *sap2;
  1661. sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
  1662. sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
  1663. if (sap1->sa_family != sap2->sa_family)
  1664. return 0;
  1665. switch (sap1->sa_family) {
  1666. case AF_INET: {
  1667. struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
  1668. struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
  1669. if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
  1670. return 0;
  1671. if (sin1->sin_port != sin2->sin_port)
  1672. return 0;
  1673. break;
  1674. }
  1675. case AF_INET6: {
  1676. struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
  1677. struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
  1678. if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
  1679. return 0;
  1680. if (sin1->sin6_port != sin2->sin6_port)
  1681. return 0;
  1682. break;
  1683. }
  1684. default:
  1685. return 0;
  1686. }
  1687. return 1;
  1688. }
  1689. static int nfs_compare_super(struct super_block *sb, void *data)
  1690. {
  1691. struct nfs_sb_mountdata *sb_mntdata = data;
  1692. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  1693. int mntflags = sb_mntdata->mntflags;
  1694. if (!nfs_compare_super_address(old, server))
  1695. return 0;
  1696. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  1697. if (old->flags & NFS_MOUNT_UNSHARED)
  1698. return 0;
  1699. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  1700. return 0;
  1701. return nfs_compare_mount_options(sb, server, mntflags);
  1702. }
  1703. static int nfs_bdi_register(struct nfs_server *server)
  1704. {
  1705. return bdi_register_dev(&server->backing_dev_info, server->s_dev);
  1706. }
  1707. static int nfs_get_sb(struct file_system_type *fs_type,
  1708. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1709. {
  1710. struct nfs_server *server = NULL;
  1711. struct super_block *s;
  1712. struct nfs_parsed_mount_data *data;
  1713. struct nfs_fh *mntfh;
  1714. struct dentry *mntroot;
  1715. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1716. struct nfs_sb_mountdata sb_mntdata = {
  1717. .mntflags = flags,
  1718. };
  1719. int error = -ENOMEM;
  1720. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1721. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  1722. if (data == NULL || mntfh == NULL)
  1723. goto out_free_fh;
  1724. security_init_mnt_opts(&data->lsm_opts);
  1725. /* Validate the mount data */
  1726. error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
  1727. if (error < 0)
  1728. goto out;
  1729. /* Get a volume representation */
  1730. server = nfs_create_server(data, mntfh);
  1731. if (IS_ERR(server)) {
  1732. error = PTR_ERR(server);
  1733. goto out;
  1734. }
  1735. sb_mntdata.server = server;
  1736. if (server->flags & NFS_MOUNT_UNSHARED)
  1737. compare_super = NULL;
  1738. /* Get a superblock - note that we may end up sharing one that already exists */
  1739. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1740. if (IS_ERR(s)) {
  1741. error = PTR_ERR(s);
  1742. goto out_err_nosb;
  1743. }
  1744. if (s->s_fs_info != server) {
  1745. nfs_free_server(server);
  1746. server = NULL;
  1747. } else {
  1748. error = nfs_bdi_register(server);
  1749. if (error)
  1750. goto error_splat_super;
  1751. }
  1752. if (!s->s_root) {
  1753. /* initial superblock/root creation */
  1754. nfs_fill_super(s, data);
  1755. }
  1756. mntroot = nfs_get_root(s, mntfh);
  1757. if (IS_ERR(mntroot)) {
  1758. error = PTR_ERR(mntroot);
  1759. goto error_splat_super;
  1760. }
  1761. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  1762. if (error)
  1763. goto error_splat_root;
  1764. s->s_flags |= MS_ACTIVE;
  1765. mnt->mnt_sb = s;
  1766. mnt->mnt_root = mntroot;
  1767. error = 0;
  1768. out:
  1769. kfree(data->nfs_server.hostname);
  1770. kfree(data->mount_server.hostname);
  1771. security_free_mnt_opts(&data->lsm_opts);
  1772. out_free_fh:
  1773. kfree(mntfh);
  1774. kfree(data);
  1775. return error;
  1776. out_err_nosb:
  1777. nfs_free_server(server);
  1778. goto out;
  1779. error_splat_root:
  1780. dput(mntroot);
  1781. error_splat_super:
  1782. up_write(&s->s_umount);
  1783. deactivate_super(s);
  1784. goto out;
  1785. }
  1786. /*
  1787. * Destroy an NFS2/3 superblock
  1788. */
  1789. static void nfs_kill_super(struct super_block *s)
  1790. {
  1791. struct nfs_server *server = NFS_SB(s);
  1792. bdi_unregister(&server->backing_dev_info);
  1793. kill_anon_super(s);
  1794. nfs_free_server(server);
  1795. }
  1796. /*
  1797. * Clone an NFS2/3 server record on xdev traversal (FSID-change)
  1798. */
  1799. static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1800. const char *dev_name, void *raw_data,
  1801. struct vfsmount *mnt)
  1802. {
  1803. struct nfs_clone_mount *data = raw_data;
  1804. struct super_block *s;
  1805. struct nfs_server *server;
  1806. struct dentry *mntroot;
  1807. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1808. struct nfs_sb_mountdata sb_mntdata = {
  1809. .mntflags = flags,
  1810. };
  1811. int error;
  1812. dprintk("--> nfs_xdev_get_sb()\n");
  1813. /* create a new volume representation */
  1814. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1815. if (IS_ERR(server)) {
  1816. error = PTR_ERR(server);
  1817. goto out_err_noserver;
  1818. }
  1819. sb_mntdata.server = server;
  1820. if (server->flags & NFS_MOUNT_UNSHARED)
  1821. compare_super = NULL;
  1822. /* Get a superblock - note that we may end up sharing one that already exists */
  1823. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1824. if (IS_ERR(s)) {
  1825. error = PTR_ERR(s);
  1826. goto out_err_nosb;
  1827. }
  1828. if (s->s_fs_info != server) {
  1829. nfs_free_server(server);
  1830. server = NULL;
  1831. } else {
  1832. error = nfs_bdi_register(server);
  1833. if (error)
  1834. goto error_splat_super;
  1835. }
  1836. if (!s->s_root) {
  1837. /* initial superblock/root creation */
  1838. nfs_clone_super(s, data->sb);
  1839. }
  1840. mntroot = nfs_get_root(s, data->fh);
  1841. if (IS_ERR(mntroot)) {
  1842. error = PTR_ERR(mntroot);
  1843. goto error_splat_super;
  1844. }
  1845. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  1846. dput(mntroot);
  1847. error = -ESTALE;
  1848. goto error_splat_super;
  1849. }
  1850. s->s_flags |= MS_ACTIVE;
  1851. mnt->mnt_sb = s;
  1852. mnt->mnt_root = mntroot;
  1853. /* clone any lsm security options from the parent to the new sb */
  1854. security_sb_clone_mnt_opts(data->sb, s);
  1855. dprintk("<-- nfs_xdev_get_sb() = 0\n");
  1856. return 0;
  1857. out_err_nosb:
  1858. nfs_free_server(server);
  1859. out_err_noserver:
  1860. dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
  1861. return error;
  1862. error_splat_super:
  1863. up_write(&s->s_umount);
  1864. deactivate_super(s);
  1865. dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
  1866. return error;
  1867. }
  1868. #ifdef CONFIG_NFS_V4
  1869. /*
  1870. * Finish setting up a cloned NFS4 superblock
  1871. */
  1872. static void nfs4_clone_super(struct super_block *sb,
  1873. const struct super_block *old_sb)
  1874. {
  1875. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1876. sb->s_blocksize = old_sb->s_blocksize;
  1877. sb->s_maxbytes = old_sb->s_maxbytes;
  1878. sb->s_time_gran = 1;
  1879. sb->s_op = old_sb->s_op;
  1880. nfs_initialise_sb(sb);
  1881. }
  1882. /*
  1883. * Set up an NFS4 superblock
  1884. */
  1885. static void nfs4_fill_super(struct super_block *sb)
  1886. {
  1887. sb->s_time_gran = 1;
  1888. sb->s_op = &nfs4_sops;
  1889. nfs_initialise_sb(sb);
  1890. }
  1891. /*
  1892. * Validate NFSv4 mount options
  1893. */
  1894. static int nfs4_validate_mount_data(void *options,
  1895. struct nfs_parsed_mount_data *args,
  1896. const char *dev_name)
  1897. {
  1898. struct sockaddr_in *ap;
  1899. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  1900. char *c;
  1901. if (data == NULL)
  1902. goto out_no_data;
  1903. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1904. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1905. args->acregmin = NFS_DEF_ACREGMIN;
  1906. args->acregmax = NFS_DEF_ACREGMAX;
  1907. args->acdirmin = NFS_DEF_ACDIRMIN;
  1908. args->acdirmax = NFS_DEF_ACDIRMAX;
  1909. args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
  1910. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1911. args->auth_flavor_len = 0;
  1912. switch (data->version) {
  1913. case 1:
  1914. ap = (struct sockaddr_in *)&args->nfs_server.address;
  1915. if (data->host_addrlen > sizeof(args->nfs_server.address))
  1916. goto out_no_address;
  1917. if (data->host_addrlen == 0)
  1918. goto out_no_address;
  1919. args->nfs_server.addrlen = data->host_addrlen;
  1920. if (copy_from_user(ap, data->host_addr, data->host_addrlen))
  1921. return -EFAULT;
  1922. if (!nfs_verify_server_address((struct sockaddr *)
  1923. &args->nfs_server.address))
  1924. goto out_no_address;
  1925. if (data->auth_flavourlen) {
  1926. if (data->auth_flavourlen > 1)
  1927. goto out_inval_auth;
  1928. if (copy_from_user(&args->auth_flavors[0],
  1929. data->auth_flavours,
  1930. sizeof(args->auth_flavors[0])))
  1931. return -EFAULT;
  1932. }
  1933. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  1934. if (IS_ERR(c))
  1935. return PTR_ERR(c);
  1936. args->nfs_server.hostname = c;
  1937. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  1938. if (IS_ERR(c))
  1939. return PTR_ERR(c);
  1940. args->nfs_server.export_path = c;
  1941. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  1942. c = strndup_user(data->client_addr.data, 16);
  1943. if (IS_ERR(c))
  1944. return PTR_ERR(c);
  1945. args->client_address = c;
  1946. /*
  1947. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  1948. * can deal with.
  1949. */
  1950. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  1951. args->rsize = data->rsize;
  1952. args->wsize = data->wsize;
  1953. args->timeo = data->timeo;
  1954. args->retrans = data->retrans;
  1955. args->acregmin = data->acregmin;
  1956. args->acregmax = data->acregmax;
  1957. args->acdirmin = data->acdirmin;
  1958. args->acdirmax = data->acdirmax;
  1959. args->nfs_server.protocol = data->proto;
  1960. nfs_validate_transport_protocol(args);
  1961. break;
  1962. default: {
  1963. int status;
  1964. if (nfs_parse_mount_options((char *)options, args) == 0)
  1965. return -EINVAL;
  1966. if (!nfs_verify_server_address((struct sockaddr *)
  1967. &args->nfs_server.address))
  1968. return -EINVAL;
  1969. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1970. args->nfs_server.port);
  1971. nfs_validate_transport_protocol(args);
  1972. if (args->auth_flavor_len > 1)
  1973. goto out_inval_auth;
  1974. if (args->client_address == NULL)
  1975. goto out_no_client_address;
  1976. status = nfs_parse_devname(dev_name,
  1977. &args->nfs_server.hostname,
  1978. NFS4_MAXNAMLEN,
  1979. &args->nfs_server.export_path,
  1980. NFS4_MAXPATHLEN);
  1981. if (status < 0)
  1982. return status;
  1983. break;
  1984. }
  1985. }
  1986. return 0;
  1987. out_no_data:
  1988. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  1989. return -EINVAL;
  1990. out_inval_auth:
  1991. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  1992. data->auth_flavourlen);
  1993. return -EINVAL;
  1994. out_no_address:
  1995. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  1996. return -EINVAL;
  1997. out_no_client_address:
  1998. dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
  1999. return -EINVAL;
  2000. }
  2001. /*
  2002. * Get the superblock for an NFS4 mountpoint
  2003. */
  2004. static int nfs4_get_sb(struct file_system_type *fs_type,
  2005. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  2006. {
  2007. struct nfs_parsed_mount_data *data;
  2008. struct super_block *s;
  2009. struct nfs_server *server;
  2010. struct nfs_fh *mntfh;
  2011. struct dentry *mntroot;
  2012. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2013. struct nfs_sb_mountdata sb_mntdata = {
  2014. .mntflags = flags,
  2015. };
  2016. int error = -ENOMEM;
  2017. data = kzalloc(sizeof(*data), GFP_KERNEL);
  2018. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  2019. if (data == NULL || mntfh == NULL)
  2020. goto out_free_fh;
  2021. security_init_mnt_opts(&data->lsm_opts);
  2022. /* Validate the mount data */
  2023. error = nfs4_validate_mount_data(raw_data, data, dev_name);
  2024. if (error < 0)
  2025. goto out;
  2026. /* Get a volume representation */
  2027. server = nfs4_create_server(data, mntfh);
  2028. if (IS_ERR(server)) {
  2029. error = PTR_ERR(server);
  2030. goto out;
  2031. }
  2032. sb_mntdata.server = server;
  2033. if (server->flags & NFS4_MOUNT_UNSHARED)
  2034. compare_super = NULL;
  2035. /* Get a superblock - note that we may end up sharing one that already exists */
  2036. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2037. if (IS_ERR(s)) {
  2038. error = PTR_ERR(s);
  2039. goto out_free;
  2040. }
  2041. if (s->s_fs_info != server) {
  2042. nfs_free_server(server);
  2043. server = NULL;
  2044. } else {
  2045. error = nfs_bdi_register(server);
  2046. if (error)
  2047. goto error_splat_super;
  2048. }
  2049. if (!s->s_root) {
  2050. /* initial superblock/root creation */
  2051. nfs4_fill_super(s);
  2052. }
  2053. mntroot = nfs4_get_root(s, mntfh);
  2054. if (IS_ERR(mntroot)) {
  2055. error = PTR_ERR(mntroot);
  2056. goto error_splat_super;
  2057. }
  2058. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  2059. if (error)
  2060. goto error_splat_root;
  2061. s->s_flags |= MS_ACTIVE;
  2062. mnt->mnt_sb = s;
  2063. mnt->mnt_root = mntroot;
  2064. error = 0;
  2065. out:
  2066. kfree(data->client_address);
  2067. kfree(data->nfs_server.export_path);
  2068. kfree(data->nfs_server.hostname);
  2069. security_free_mnt_opts(&data->lsm_opts);
  2070. out_free_fh:
  2071. kfree(mntfh);
  2072. kfree(data);
  2073. return error;
  2074. out_free:
  2075. nfs_free_server(server);
  2076. goto out;
  2077. error_splat_root:
  2078. dput(mntroot);
  2079. error_splat_super:
  2080. up_write(&s->s_umount);
  2081. deactivate_super(s);
  2082. goto out;
  2083. }
  2084. static void nfs4_kill_super(struct super_block *sb)
  2085. {
  2086. struct nfs_server *server = NFS_SB(sb);
  2087. nfs_return_all_delegations(sb);
  2088. kill_anon_super(sb);
  2089. nfs4_renewd_prepare_shutdown(server);
  2090. nfs_free_server(server);
  2091. }
  2092. /*
  2093. * Clone an NFS4 server record on xdev traversal (FSID-change)
  2094. */
  2095. static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
  2096. const char *dev_name, void *raw_data,
  2097. struct vfsmount *mnt)
  2098. {
  2099. struct nfs_clone_mount *data = raw_data;
  2100. struct super_block *s;
  2101. struct nfs_server *server;
  2102. struct dentry *mntroot;
  2103. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2104. struct nfs_sb_mountdata sb_mntdata = {
  2105. .mntflags = flags,
  2106. };
  2107. int error;
  2108. dprintk("--> nfs4_xdev_get_sb()\n");
  2109. /* create a new volume representation */
  2110. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  2111. if (IS_ERR(server)) {
  2112. error = PTR_ERR(server);
  2113. goto out_err_noserver;
  2114. }
  2115. sb_mntdata.server = server;
  2116. if (server->flags & NFS4_MOUNT_UNSHARED)
  2117. compare_super = NULL;
  2118. /* Get a superblock - note that we may end up sharing one that already exists */
  2119. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2120. if (IS_ERR(s)) {
  2121. error = PTR_ERR(s);
  2122. goto out_err_nosb;
  2123. }
  2124. if (s->s_fs_info != server) {
  2125. nfs_free_server(server);
  2126. server = NULL;
  2127. } else {
  2128. error = nfs_bdi_register(server);
  2129. if (error)
  2130. goto error_splat_super;
  2131. }
  2132. if (!s->s_root) {
  2133. /* initial superblock/root creation */
  2134. nfs4_clone_super(s, data->sb);
  2135. }
  2136. mntroot = nfs4_get_root(s, data->fh);
  2137. if (IS_ERR(mntroot)) {
  2138. error = PTR_ERR(mntroot);
  2139. goto error_splat_super;
  2140. }
  2141. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2142. dput(mntroot);
  2143. error = -ESTALE;
  2144. goto error_splat_super;
  2145. }
  2146. s->s_flags |= MS_ACTIVE;
  2147. mnt->mnt_sb = s;
  2148. mnt->mnt_root = mntroot;
  2149. security_sb_clone_mnt_opts(data->sb, s);
  2150. dprintk("<-- nfs4_xdev_get_sb() = 0\n");
  2151. return 0;
  2152. out_err_nosb:
  2153. nfs_free_server(server);
  2154. out_err_noserver:
  2155. dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
  2156. return error;
  2157. error_splat_super:
  2158. up_write(&s->s_umount);
  2159. deactivate_super(s);
  2160. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  2161. return error;
  2162. }
  2163. /*
  2164. * Create an NFS4 server record on referral traversal
  2165. */
  2166. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  2167. const char *dev_name, void *raw_data,
  2168. struct vfsmount *mnt)
  2169. {
  2170. struct nfs_clone_mount *data = raw_data;
  2171. struct super_block *s;
  2172. struct nfs_server *server;
  2173. struct dentry *mntroot;
  2174. struct nfs_fh mntfh;
  2175. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2176. struct nfs_sb_mountdata sb_mntdata = {
  2177. .mntflags = flags,
  2178. };
  2179. int error;
  2180. dprintk("--> nfs4_referral_get_sb()\n");
  2181. /* create a new volume representation */
  2182. server = nfs4_create_referral_server(data, &mntfh);
  2183. if (IS_ERR(server)) {
  2184. error = PTR_ERR(server);
  2185. goto out_err_noserver;
  2186. }
  2187. sb_mntdata.server = server;
  2188. if (server->flags & NFS4_MOUNT_UNSHARED)
  2189. compare_super = NULL;
  2190. /* Get a superblock - note that we may end up sharing one that already exists */
  2191. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2192. if (IS_ERR(s)) {
  2193. error = PTR_ERR(s);
  2194. goto out_err_nosb;
  2195. }
  2196. if (s->s_fs_info != server) {
  2197. nfs_free_server(server);
  2198. server = NULL;
  2199. } else {
  2200. error = nfs_bdi_register(server);
  2201. if (error)
  2202. goto error_splat_super;
  2203. }
  2204. if (!s->s_root) {
  2205. /* initial superblock/root creation */
  2206. nfs4_fill_super(s);
  2207. }
  2208. mntroot = nfs4_get_root(s, &mntfh);
  2209. if (IS_ERR(mntroot)) {
  2210. error = PTR_ERR(mntroot);
  2211. goto error_splat_super;
  2212. }
  2213. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2214. dput(mntroot);
  2215. error = -ESTALE;
  2216. goto error_splat_super;
  2217. }
  2218. s->s_flags |= MS_ACTIVE;
  2219. mnt->mnt_sb = s;
  2220. mnt->mnt_root = mntroot;
  2221. security_sb_clone_mnt_opts(data->sb, s);
  2222. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  2223. return 0;
  2224. out_err_nosb:
  2225. nfs_free_server(server);
  2226. out_err_noserver:
  2227. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  2228. return error;
  2229. error_splat_super:
  2230. up_write(&s->s_umount);
  2231. deactivate_super(s);
  2232. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  2233. return error;
  2234. }
  2235. #endif /* CONFIG_NFS_V4 */