super.c 65 KB

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