super.c 66 KB

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