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;
  597. struct rpc_clnt *rpc;
  598. lock_kernel();
  599. server = NFS_SB(sb);
  600. /* -EIO all pending I/O */
  601. rpc = server->client_acl;
  602. if (!IS_ERR(rpc))
  603. rpc_killall_tasks(rpc);
  604. rpc = server->client;
  605. if (!IS_ERR(rpc))
  606. rpc_killall_tasks(rpc);
  607. unlock_kernel();
  608. }
  609. /*
  610. * Sanity-check a server address provided by the mount command.
  611. *
  612. * Address family must be initialized, and address must not be
  613. * the ANY address for that family.
  614. */
  615. static int nfs_verify_server_address(struct sockaddr *addr)
  616. {
  617. switch (addr->sa_family) {
  618. case AF_INET: {
  619. struct sockaddr_in *sa = (struct sockaddr_in *)addr;
  620. return sa->sin_addr.s_addr != htonl(INADDR_ANY);
  621. }
  622. case AF_INET6: {
  623. struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
  624. return !ipv6_addr_any(sa);
  625. }
  626. }
  627. return 0;
  628. }
  629. static void nfs_parse_ipv4_address(char *string, size_t str_len,
  630. struct sockaddr *sap, size_t *addr_len)
  631. {
  632. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  633. u8 *addr = (u8 *)&sin->sin_addr.s_addr;
  634. if (str_len <= INET_ADDRSTRLEN) {
  635. dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
  636. (int)str_len, string);
  637. sin->sin_family = AF_INET;
  638. *addr_len = sizeof(*sin);
  639. if (in4_pton(string, str_len, addr, '\0', NULL))
  640. return;
  641. }
  642. sap->sa_family = AF_UNSPEC;
  643. *addr_len = 0;
  644. }
  645. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  646. static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
  647. const char *delim,
  648. struct sockaddr_in6 *sin6)
  649. {
  650. char *p;
  651. size_t len;
  652. if ((string + str_len) == delim)
  653. return 1;
  654. if (*delim != IPV6_SCOPE_DELIMITER)
  655. return 0;
  656. if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
  657. return 0;
  658. len = (string + str_len) - delim - 1;
  659. p = kstrndup(delim + 1, len, GFP_KERNEL);
  660. if (p) {
  661. unsigned long scope_id = 0;
  662. struct net_device *dev;
  663. dev = dev_get_by_name(&init_net, p);
  664. if (dev != NULL) {
  665. scope_id = dev->ifindex;
  666. dev_put(dev);
  667. } else {
  668. if (strict_strtoul(p, 10, &scope_id) == 0) {
  669. kfree(p);
  670. return 0;
  671. }
  672. }
  673. kfree(p);
  674. sin6->sin6_scope_id = scope_id;
  675. dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
  676. return 1;
  677. }
  678. return 0;
  679. }
  680. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  681. struct sockaddr *sap, size_t *addr_len)
  682. {
  683. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  684. u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
  685. const char *delim;
  686. if (str_len <= INET6_ADDRSTRLEN) {
  687. dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
  688. (int)str_len, string);
  689. sin6->sin6_family = AF_INET6;
  690. *addr_len = sizeof(*sin6);
  691. if (in6_pton(string, str_len, addr,
  692. IPV6_SCOPE_DELIMITER, &delim) != 0) {
  693. if (nfs_parse_ipv6_scope_id(string, str_len,
  694. delim, sin6) != 0)
  695. return;
  696. }
  697. }
  698. sap->sa_family = AF_UNSPEC;
  699. *addr_len = 0;
  700. }
  701. #else
  702. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  703. struct sockaddr *sap, size_t *addr_len)
  704. {
  705. sap->sa_family = AF_UNSPEC;
  706. *addr_len = 0;
  707. }
  708. #endif
  709. /*
  710. * Construct a sockaddr based on the contents of a string that contains
  711. * an IP address in presentation format.
  712. *
  713. * If there is a problem constructing the new sockaddr, set the address
  714. * family to AF_UNSPEC.
  715. */
  716. void nfs_parse_ip_address(char *string, size_t str_len,
  717. struct sockaddr *sap, size_t *addr_len)
  718. {
  719. unsigned int i, colons;
  720. colons = 0;
  721. for (i = 0; i < str_len; i++)
  722. if (string[i] == ':')
  723. colons++;
  724. if (colons >= 2)
  725. nfs_parse_ipv6_address(string, str_len, sap, addr_len);
  726. else
  727. nfs_parse_ipv4_address(string, str_len, sap, addr_len);
  728. }
  729. /*
  730. * Sanity check the NFS transport protocol.
  731. *
  732. */
  733. static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
  734. {
  735. switch (mnt->nfs_server.protocol) {
  736. case XPRT_TRANSPORT_UDP:
  737. case XPRT_TRANSPORT_TCP:
  738. case XPRT_TRANSPORT_RDMA:
  739. break;
  740. default:
  741. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  742. }
  743. }
  744. /*
  745. * For text based NFSv2/v3 mounts, the mount protocol transport default
  746. * settings should depend upon the specified NFS transport.
  747. */
  748. static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
  749. {
  750. nfs_validate_transport_protocol(mnt);
  751. if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
  752. mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
  753. return;
  754. switch (mnt->nfs_server.protocol) {
  755. case XPRT_TRANSPORT_UDP:
  756. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  757. break;
  758. case XPRT_TRANSPORT_TCP:
  759. case XPRT_TRANSPORT_RDMA:
  760. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  761. }
  762. }
  763. /*
  764. * Parse the value of the 'sec=' option.
  765. *
  766. * The flavor_len setting is for v4 mounts.
  767. */
  768. static int nfs_parse_security_flavors(char *value,
  769. struct nfs_parsed_mount_data *mnt)
  770. {
  771. substring_t args[MAX_OPT_ARGS];
  772. dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
  773. switch (match_token(value, nfs_secflavor_tokens, args)) {
  774. case Opt_sec_none:
  775. mnt->auth_flavor_len = 0;
  776. mnt->auth_flavors[0] = RPC_AUTH_NULL;
  777. break;
  778. case Opt_sec_sys:
  779. mnt->auth_flavor_len = 0;
  780. mnt->auth_flavors[0] = RPC_AUTH_UNIX;
  781. break;
  782. case Opt_sec_krb5:
  783. mnt->auth_flavor_len = 1;
  784. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
  785. break;
  786. case Opt_sec_krb5i:
  787. mnt->auth_flavor_len = 1;
  788. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
  789. break;
  790. case Opt_sec_krb5p:
  791. mnt->auth_flavor_len = 1;
  792. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
  793. break;
  794. case Opt_sec_lkey:
  795. mnt->auth_flavor_len = 1;
  796. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
  797. break;
  798. case Opt_sec_lkeyi:
  799. mnt->auth_flavor_len = 1;
  800. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
  801. break;
  802. case Opt_sec_lkeyp:
  803. mnt->auth_flavor_len = 1;
  804. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
  805. break;
  806. case Opt_sec_spkm:
  807. mnt->auth_flavor_len = 1;
  808. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
  809. break;
  810. case Opt_sec_spkmi:
  811. mnt->auth_flavor_len = 1;
  812. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
  813. break;
  814. case Opt_sec_spkmp:
  815. mnt->auth_flavor_len = 1;
  816. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
  817. break;
  818. default:
  819. return 0;
  820. }
  821. return 1;
  822. }
  823. static void nfs_parse_invalid_value(const char *option)
  824. {
  825. dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
  826. }
  827. /*
  828. * Error-check and convert a string of mount options from user space into
  829. * a data structure. The whole mount string is processed; bad options are
  830. * skipped as they are encountered. If there were no errors, return 1;
  831. * otherwise return 0 (zero).
  832. */
  833. static int nfs_parse_mount_options(char *raw,
  834. struct nfs_parsed_mount_data *mnt)
  835. {
  836. char *p, *string, *secdata;
  837. int rc, sloppy = 0, errors = 0;
  838. if (!raw) {
  839. dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
  840. return 1;
  841. }
  842. dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
  843. secdata = alloc_secdata();
  844. if (!secdata)
  845. goto out_nomem;
  846. rc = security_sb_copy_data(raw, secdata);
  847. if (rc)
  848. goto out_security_failure;
  849. rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
  850. if (rc)
  851. goto out_security_failure;
  852. free_secdata(secdata);
  853. while ((p = strsep(&raw, ",")) != NULL) {
  854. substring_t args[MAX_OPT_ARGS];
  855. int option, token;
  856. if (!*p)
  857. continue;
  858. dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
  859. token = match_token(p, nfs_mount_option_tokens, args);
  860. switch (token) {
  861. /*
  862. * boolean options: foo/nofoo
  863. */
  864. case Opt_soft:
  865. mnt->flags |= NFS_MOUNT_SOFT;
  866. break;
  867. case Opt_hard:
  868. mnt->flags &= ~NFS_MOUNT_SOFT;
  869. break;
  870. case Opt_posix:
  871. mnt->flags |= NFS_MOUNT_POSIX;
  872. break;
  873. case Opt_noposix:
  874. mnt->flags &= ~NFS_MOUNT_POSIX;
  875. break;
  876. case Opt_cto:
  877. mnt->flags &= ~NFS_MOUNT_NOCTO;
  878. break;
  879. case Opt_nocto:
  880. mnt->flags |= NFS_MOUNT_NOCTO;
  881. break;
  882. case Opt_ac:
  883. mnt->flags &= ~NFS_MOUNT_NOAC;
  884. break;
  885. case Opt_noac:
  886. mnt->flags |= NFS_MOUNT_NOAC;
  887. break;
  888. case Opt_lock:
  889. mnt->flags &= ~NFS_MOUNT_NONLM;
  890. break;
  891. case Opt_nolock:
  892. mnt->flags |= NFS_MOUNT_NONLM;
  893. break;
  894. case Opt_v2:
  895. mnt->flags &= ~NFS_MOUNT_VER3;
  896. break;
  897. case Opt_v3:
  898. mnt->flags |= NFS_MOUNT_VER3;
  899. break;
  900. case Opt_udp:
  901. mnt->flags &= ~NFS_MOUNT_TCP;
  902. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  903. break;
  904. case Opt_tcp:
  905. mnt->flags |= NFS_MOUNT_TCP;
  906. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  907. break;
  908. case Opt_rdma:
  909. mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
  910. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  911. xprt_load_transport(p);
  912. break;
  913. case Opt_acl:
  914. mnt->flags &= ~NFS_MOUNT_NOACL;
  915. break;
  916. case Opt_noacl:
  917. mnt->flags |= NFS_MOUNT_NOACL;
  918. break;
  919. case Opt_rdirplus:
  920. mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
  921. break;
  922. case Opt_nordirplus:
  923. mnt->flags |= NFS_MOUNT_NORDIRPLUS;
  924. break;
  925. case Opt_sharecache:
  926. mnt->flags &= ~NFS_MOUNT_UNSHARED;
  927. break;
  928. case Opt_nosharecache:
  929. mnt->flags |= NFS_MOUNT_UNSHARED;
  930. break;
  931. case Opt_resvport:
  932. mnt->flags &= ~NFS_MOUNT_NORESVPORT;
  933. break;
  934. case Opt_noresvport:
  935. mnt->flags |= NFS_MOUNT_NORESVPORT;
  936. break;
  937. case Opt_fscache:
  938. mnt->options |= NFS_OPTION_FSCACHE;
  939. kfree(mnt->fscache_uniq);
  940. mnt->fscache_uniq = NULL;
  941. break;
  942. case Opt_nofscache:
  943. mnt->options &= ~NFS_OPTION_FSCACHE;
  944. kfree(mnt->fscache_uniq);
  945. mnt->fscache_uniq = NULL;
  946. break;
  947. case Opt_fscache_uniq:
  948. string = match_strdup(args);
  949. if (!string)
  950. goto out_nomem;
  951. kfree(mnt->fscache_uniq);
  952. mnt->fscache_uniq = string;
  953. mnt->options |= NFS_OPTION_FSCACHE;
  954. break;
  955. /*
  956. * options that take numeric values
  957. */
  958. case Opt_port:
  959. if (match_int(args, &option) ||
  960. option < 0 || option > USHORT_MAX) {
  961. errors++;
  962. nfs_parse_invalid_value("port");
  963. } else
  964. mnt->nfs_server.port = option;
  965. break;
  966. case Opt_rsize:
  967. if (match_int(args, &option) || option < 0) {
  968. errors++;
  969. nfs_parse_invalid_value("rsize");
  970. } else
  971. mnt->rsize = option;
  972. break;
  973. case Opt_wsize:
  974. if (match_int(args, &option) || option < 0) {
  975. errors++;
  976. nfs_parse_invalid_value("wsize");
  977. } else
  978. mnt->wsize = option;
  979. break;
  980. case Opt_bsize:
  981. if (match_int(args, &option) || option < 0) {
  982. errors++;
  983. nfs_parse_invalid_value("bsize");
  984. } else
  985. mnt->bsize = option;
  986. break;
  987. case Opt_timeo:
  988. if (match_int(args, &option) || option <= 0) {
  989. errors++;
  990. nfs_parse_invalid_value("timeo");
  991. } else
  992. mnt->timeo = option;
  993. break;
  994. case Opt_retrans:
  995. if (match_int(args, &option) || option <= 0) {
  996. errors++;
  997. nfs_parse_invalid_value("retrans");
  998. } else
  999. mnt->retrans = option;
  1000. break;
  1001. case Opt_acregmin:
  1002. if (match_int(args, &option) || option < 0) {
  1003. errors++;
  1004. nfs_parse_invalid_value("acregmin");
  1005. } else
  1006. mnt->acregmin = option;
  1007. break;
  1008. case Opt_acregmax:
  1009. if (match_int(args, &option) || option < 0) {
  1010. errors++;
  1011. nfs_parse_invalid_value("acregmax");
  1012. } else
  1013. mnt->acregmax = option;
  1014. break;
  1015. case Opt_acdirmin:
  1016. if (match_int(args, &option) || option < 0) {
  1017. errors++;
  1018. nfs_parse_invalid_value("acdirmin");
  1019. } else
  1020. mnt->acdirmin = option;
  1021. break;
  1022. case Opt_acdirmax:
  1023. if (match_int(args, &option) || option < 0) {
  1024. errors++;
  1025. nfs_parse_invalid_value("acdirmax");
  1026. } else
  1027. mnt->acdirmax = option;
  1028. break;
  1029. case Opt_actimeo:
  1030. if (match_int(args, &option) || option < 0) {
  1031. errors++;
  1032. nfs_parse_invalid_value("actimeo");
  1033. } else
  1034. mnt->acregmin = mnt->acregmax =
  1035. mnt->acdirmin = mnt->acdirmax = option;
  1036. break;
  1037. case Opt_namelen:
  1038. if (match_int(args, &option) || option < 0) {
  1039. errors++;
  1040. nfs_parse_invalid_value("namlen");
  1041. } else
  1042. mnt->namlen = option;
  1043. break;
  1044. case Opt_mountport:
  1045. if (match_int(args, &option) ||
  1046. option < 0 || option > USHORT_MAX) {
  1047. errors++;
  1048. nfs_parse_invalid_value("mountport");
  1049. } else
  1050. mnt->mount_server.port = option;
  1051. break;
  1052. case Opt_mountvers:
  1053. if (match_int(args, &option) ||
  1054. option < NFS_MNT_VERSION ||
  1055. option > NFS_MNT3_VERSION) {
  1056. errors++;
  1057. nfs_parse_invalid_value("mountvers");
  1058. } else
  1059. mnt->mount_server.version = option;
  1060. break;
  1061. case Opt_nfsvers:
  1062. if (match_int(args, &option)) {
  1063. errors++;
  1064. nfs_parse_invalid_value("nfsvers");
  1065. break;
  1066. }
  1067. switch (option) {
  1068. case NFS2_VERSION:
  1069. mnt->flags &= ~NFS_MOUNT_VER3;
  1070. break;
  1071. case NFS3_VERSION:
  1072. mnt->flags |= NFS_MOUNT_VER3;
  1073. break;
  1074. default:
  1075. errors++;
  1076. nfs_parse_invalid_value("nfsvers");
  1077. }
  1078. break;
  1079. /*
  1080. * options that take text values
  1081. */
  1082. case Opt_sec:
  1083. string = match_strdup(args);
  1084. if (string == NULL)
  1085. goto out_nomem;
  1086. rc = nfs_parse_security_flavors(string, mnt);
  1087. kfree(string);
  1088. if (!rc) {
  1089. errors++;
  1090. dfprintk(MOUNT, "NFS: unrecognized "
  1091. "security flavor\n");
  1092. }
  1093. break;
  1094. case Opt_proto:
  1095. string = match_strdup(args);
  1096. if (string == NULL)
  1097. goto out_nomem;
  1098. token = match_token(string,
  1099. nfs_xprt_protocol_tokens, args);
  1100. switch (token) {
  1101. case Opt_xprt_udp:
  1102. mnt->flags &= ~NFS_MOUNT_TCP;
  1103. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1104. break;
  1105. case Opt_xprt_tcp:
  1106. mnt->flags |= NFS_MOUNT_TCP;
  1107. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1108. break;
  1109. case Opt_xprt_rdma:
  1110. /* vector side protocols to TCP */
  1111. mnt->flags |= NFS_MOUNT_TCP;
  1112. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1113. xprt_load_transport(string);
  1114. break;
  1115. default:
  1116. errors++;
  1117. dfprintk(MOUNT, "NFS: unrecognized "
  1118. "transport protocol\n");
  1119. }
  1120. kfree(string);
  1121. break;
  1122. case Opt_mountproto:
  1123. string = match_strdup(args);
  1124. if (string == NULL)
  1125. goto out_nomem;
  1126. token = match_token(string,
  1127. nfs_xprt_protocol_tokens, args);
  1128. kfree(string);
  1129. switch (token) {
  1130. case Opt_xprt_udp:
  1131. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  1132. break;
  1133. case Opt_xprt_tcp:
  1134. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  1135. break;
  1136. case Opt_xprt_rdma: /* not used for side protocols */
  1137. default:
  1138. errors++;
  1139. dfprintk(MOUNT, "NFS: unrecognized "
  1140. "transport protocol\n");
  1141. }
  1142. break;
  1143. case Opt_addr:
  1144. string = match_strdup(args);
  1145. if (string == NULL)
  1146. goto out_nomem;
  1147. nfs_parse_ip_address(string, strlen(string),
  1148. (struct sockaddr *)
  1149. &mnt->nfs_server.address,
  1150. &mnt->nfs_server.addrlen);
  1151. kfree(string);
  1152. break;
  1153. case Opt_clientaddr:
  1154. string = match_strdup(args);
  1155. if (string == NULL)
  1156. goto out_nomem;
  1157. kfree(mnt->client_address);
  1158. mnt->client_address = string;
  1159. break;
  1160. case Opt_mounthost:
  1161. string = match_strdup(args);
  1162. if (string == NULL)
  1163. goto out_nomem;
  1164. kfree(mnt->mount_server.hostname);
  1165. mnt->mount_server.hostname = string;
  1166. break;
  1167. case Opt_mountaddr:
  1168. string = match_strdup(args);
  1169. if (string == NULL)
  1170. goto out_nomem;
  1171. nfs_parse_ip_address(string, strlen(string),
  1172. (struct sockaddr *)
  1173. &mnt->mount_server.address,
  1174. &mnt->mount_server.addrlen);
  1175. kfree(string);
  1176. break;
  1177. case Opt_lookupcache:
  1178. string = match_strdup(args);
  1179. if (string == NULL)
  1180. goto out_nomem;
  1181. token = match_token(string,
  1182. nfs_lookupcache_tokens, args);
  1183. kfree(string);
  1184. switch (token) {
  1185. case Opt_lookupcache_all:
  1186. mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
  1187. break;
  1188. case Opt_lookupcache_positive:
  1189. mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
  1190. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
  1191. break;
  1192. case Opt_lookupcache_none:
  1193. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
  1194. break;
  1195. default:
  1196. errors++;
  1197. dfprintk(MOUNT, "NFS: invalid "
  1198. "lookupcache argument\n");
  1199. };
  1200. break;
  1201. /*
  1202. * Special options
  1203. */
  1204. case Opt_sloppy:
  1205. sloppy = 1;
  1206. dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
  1207. break;
  1208. case Opt_userspace:
  1209. case Opt_deprecated:
  1210. dfprintk(MOUNT, "NFS: ignoring mount option "
  1211. "'%s'\n", p);
  1212. break;
  1213. default:
  1214. errors++;
  1215. dfprintk(MOUNT, "NFS: unrecognized mount option "
  1216. "'%s'\n", p);
  1217. }
  1218. }
  1219. if (errors > 0) {
  1220. dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
  1221. errors, (errors == 1 ? "" : "s"));
  1222. if (!sloppy)
  1223. return 0;
  1224. }
  1225. return 1;
  1226. out_nomem:
  1227. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  1228. return 0;
  1229. out_security_failure:
  1230. free_secdata(secdata);
  1231. printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
  1232. return 0;
  1233. }
  1234. /*
  1235. * Use the remote server's MOUNT service to request the NFS file handle
  1236. * corresponding to the provided path.
  1237. */
  1238. static int nfs_try_mount(struct nfs_parsed_mount_data *args,
  1239. struct nfs_fh *root_fh)
  1240. {
  1241. struct nfs_mount_request request = {
  1242. .sap = (struct sockaddr *)
  1243. &args->mount_server.address,
  1244. .dirpath = args->nfs_server.export_path,
  1245. .protocol = args->mount_server.protocol,
  1246. .fh = root_fh,
  1247. .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
  1248. };
  1249. int status;
  1250. if (args->mount_server.version == 0) {
  1251. if (args->flags & NFS_MOUNT_VER3)
  1252. args->mount_server.version = NFS_MNT3_VERSION;
  1253. else
  1254. args->mount_server.version = NFS_MNT_VERSION;
  1255. }
  1256. request.version = args->mount_server.version;
  1257. if (args->mount_server.hostname)
  1258. request.hostname = args->mount_server.hostname;
  1259. else
  1260. request.hostname = args->nfs_server.hostname;
  1261. /*
  1262. * Construct the mount server's address.
  1263. */
  1264. if (args->mount_server.address.ss_family == AF_UNSPEC) {
  1265. memcpy(request.sap, &args->nfs_server.address,
  1266. args->nfs_server.addrlen);
  1267. args->mount_server.addrlen = args->nfs_server.addrlen;
  1268. }
  1269. request.salen = args->mount_server.addrlen;
  1270. /*
  1271. * autobind will be used if mount_server.port == 0
  1272. */
  1273. nfs_set_port(request.sap, args->mount_server.port);
  1274. /*
  1275. * Now ask the mount server to map our export path
  1276. * to a file handle.
  1277. */
  1278. status = nfs_mount(&request);
  1279. if (status == 0)
  1280. return 0;
  1281. dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
  1282. request.hostname, status);
  1283. return status;
  1284. }
  1285. static int nfs_parse_simple_hostname(const char *dev_name,
  1286. char **hostname, size_t maxnamlen,
  1287. char **export_path, size_t maxpathlen)
  1288. {
  1289. size_t len;
  1290. char *colon, *comma;
  1291. colon = strchr(dev_name, ':');
  1292. if (colon == NULL)
  1293. goto out_bad_devname;
  1294. len = colon - dev_name;
  1295. if (len > maxnamlen)
  1296. goto out_hostname;
  1297. /* N.B. caller will free nfs_server.hostname in all cases */
  1298. *hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1299. if (!*hostname)
  1300. goto out_nomem;
  1301. /* kill possible hostname list: not supported */
  1302. comma = strchr(*hostname, ',');
  1303. if (comma != NULL) {
  1304. if (comma == *hostname)
  1305. goto out_bad_devname;
  1306. *comma = '\0';
  1307. }
  1308. colon++;
  1309. len = strlen(colon);
  1310. if (len > maxpathlen)
  1311. goto out_path;
  1312. *export_path = kstrndup(colon, len, GFP_KERNEL);
  1313. if (!*export_path)
  1314. goto out_nomem;
  1315. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
  1316. return 0;
  1317. out_bad_devname:
  1318. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1319. return -EINVAL;
  1320. out_nomem:
  1321. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1322. return -ENOMEM;
  1323. out_hostname:
  1324. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1325. return -ENAMETOOLONG;
  1326. out_path:
  1327. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1328. return -ENAMETOOLONG;
  1329. }
  1330. /*
  1331. * Hostname has square brackets around it because it contains one or
  1332. * more colons. We look for the first closing square bracket, and a
  1333. * colon must follow it.
  1334. */
  1335. static int nfs_parse_protected_hostname(const char *dev_name,
  1336. char **hostname, size_t maxnamlen,
  1337. char **export_path, size_t maxpathlen)
  1338. {
  1339. size_t len;
  1340. char *start, *end;
  1341. start = (char *)(dev_name + 1);
  1342. end = strchr(start, ']');
  1343. if (end == NULL)
  1344. goto out_bad_devname;
  1345. if (*(end + 1) != ':')
  1346. goto out_bad_devname;
  1347. len = end - start;
  1348. if (len > maxnamlen)
  1349. goto out_hostname;
  1350. /* N.B. caller will free nfs_server.hostname in all cases */
  1351. *hostname = kstrndup(start, len, GFP_KERNEL);
  1352. if (*hostname == NULL)
  1353. goto out_nomem;
  1354. end += 2;
  1355. len = strlen(end);
  1356. if (len > maxpathlen)
  1357. goto out_path;
  1358. *export_path = kstrndup(end, len, GFP_KERNEL);
  1359. if (!*export_path)
  1360. goto out_nomem;
  1361. return 0;
  1362. out_bad_devname:
  1363. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1364. return -EINVAL;
  1365. out_nomem:
  1366. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1367. return -ENOMEM;
  1368. out_hostname:
  1369. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1370. return -ENAMETOOLONG;
  1371. out_path:
  1372. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1373. return -ENAMETOOLONG;
  1374. }
  1375. /*
  1376. * Split "dev_name" into "hostname:export_path".
  1377. *
  1378. * The leftmost colon demarks the split between the server's hostname
  1379. * and the export path. If the hostname starts with a left square
  1380. * bracket, then it may contain colons.
  1381. *
  1382. * Note: caller frees hostname and export path, even on error.
  1383. */
  1384. static int nfs_parse_devname(const char *dev_name,
  1385. char **hostname, size_t maxnamlen,
  1386. char **export_path, size_t maxpathlen)
  1387. {
  1388. if (*dev_name == '[')
  1389. return nfs_parse_protected_hostname(dev_name,
  1390. hostname, maxnamlen,
  1391. export_path, maxpathlen);
  1392. return nfs_parse_simple_hostname(dev_name,
  1393. hostname, maxnamlen,
  1394. export_path, maxpathlen);
  1395. }
  1396. /*
  1397. * Validate the NFS2/NFS3 mount data
  1398. * - fills in the mount root filehandle
  1399. *
  1400. * For option strings, user space handles the following behaviors:
  1401. *
  1402. * + DNS: mapping server host name to IP address ("addr=" option)
  1403. *
  1404. * + failure mode: how to behave if a mount request can't be handled
  1405. * immediately ("fg/bg" option)
  1406. *
  1407. * + retry: how often to retry a mount request ("retry=" option)
  1408. *
  1409. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  1410. * mountproto=tcp after mountproto=udp, and so on
  1411. */
  1412. static int nfs_validate_mount_data(void *options,
  1413. struct nfs_parsed_mount_data *args,
  1414. struct nfs_fh *mntfh,
  1415. const char *dev_name)
  1416. {
  1417. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  1418. if (data == NULL)
  1419. goto out_no_data;
  1420. args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
  1421. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1422. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1423. args->acregmin = NFS_DEF_ACREGMIN;
  1424. args->acregmax = NFS_DEF_ACREGMAX;
  1425. args->acdirmin = NFS_DEF_ACDIRMIN;
  1426. args->acdirmax = NFS_DEF_ACDIRMAX;
  1427. args->mount_server.port = 0; /* autobind unless user sets port */
  1428. args->nfs_server.port = 0; /* autobind unless user sets port */
  1429. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1430. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1431. switch (data->version) {
  1432. case 1:
  1433. data->namlen = 0;
  1434. case 2:
  1435. data->bsize = 0;
  1436. case 3:
  1437. if (data->flags & NFS_MOUNT_VER3)
  1438. goto out_no_v3;
  1439. data->root.size = NFS2_FHSIZE;
  1440. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  1441. case 4:
  1442. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1443. goto out_no_sec;
  1444. case 5:
  1445. memset(data->context, 0, sizeof(data->context));
  1446. case 6:
  1447. if (data->flags & NFS_MOUNT_VER3) {
  1448. if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
  1449. goto out_invalid_fh;
  1450. mntfh->size = data->root.size;
  1451. } else
  1452. mntfh->size = NFS2_FHSIZE;
  1453. memcpy(mntfh->data, data->root.data, mntfh->size);
  1454. if (mntfh->size < sizeof(mntfh->data))
  1455. memset(mntfh->data + mntfh->size, 0,
  1456. sizeof(mntfh->data) - mntfh->size);
  1457. /*
  1458. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1459. * can deal with.
  1460. */
  1461. args->flags = data->flags & NFS_MOUNT_FLAGMASK;
  1462. args->rsize = data->rsize;
  1463. args->wsize = data->wsize;
  1464. args->timeo = data->timeo;
  1465. args->retrans = data->retrans;
  1466. args->acregmin = data->acregmin;
  1467. args->acregmax = data->acregmax;
  1468. args->acdirmin = data->acdirmin;
  1469. args->acdirmax = data->acdirmax;
  1470. memcpy(&args->nfs_server.address, &data->addr,
  1471. sizeof(data->addr));
  1472. args->nfs_server.addrlen = sizeof(data->addr);
  1473. if (!nfs_verify_server_address((struct sockaddr *)
  1474. &args->nfs_server.address))
  1475. goto out_no_address;
  1476. if (!(data->flags & NFS_MOUNT_TCP))
  1477. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1478. /* N.B. caller will free nfs_server.hostname in all cases */
  1479. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1480. args->namlen = data->namlen;
  1481. args->bsize = data->bsize;
  1482. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1483. args->auth_flavors[0] = data->pseudoflavor;
  1484. if (!args->nfs_server.hostname)
  1485. goto out_nomem;
  1486. /*
  1487. * The legacy version 6 binary mount data from userspace has a
  1488. * field used only to transport selinux information into the
  1489. * the kernel. To continue to support that functionality we
  1490. * have a touch of selinux knowledge here in the NFS code. The
  1491. * userspace code converted context=blah to just blah so we are
  1492. * converting back to the full string selinux understands.
  1493. */
  1494. if (data->context[0]){
  1495. #ifdef CONFIG_SECURITY_SELINUX
  1496. int rc;
  1497. char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
  1498. if (!opts_str)
  1499. return -ENOMEM;
  1500. strcpy(opts_str, "context=");
  1501. data->context[NFS_MAX_CONTEXT_LEN] = '\0';
  1502. strcat(opts_str, &data->context[0]);
  1503. rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
  1504. kfree(opts_str);
  1505. if (rc)
  1506. return rc;
  1507. #else
  1508. return -EINVAL;
  1509. #endif
  1510. }
  1511. break;
  1512. default: {
  1513. int status;
  1514. if (nfs_parse_mount_options((char *)options, args) == 0)
  1515. return -EINVAL;
  1516. if (!nfs_verify_server_address((struct sockaddr *)
  1517. &args->nfs_server.address))
  1518. goto out_no_address;
  1519. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1520. args->nfs_server.port);
  1521. nfs_set_mount_transport_protocol(args);
  1522. status = nfs_parse_devname(dev_name,
  1523. &args->nfs_server.hostname,
  1524. PAGE_SIZE,
  1525. &args->nfs_server.export_path,
  1526. NFS_MAXPATHLEN);
  1527. if (!status)
  1528. status = nfs_try_mount(args, mntfh);
  1529. kfree(args->nfs_server.export_path);
  1530. args->nfs_server.export_path = NULL;
  1531. if (status)
  1532. return status;
  1533. break;
  1534. }
  1535. }
  1536. #ifndef CONFIG_NFS_V3
  1537. if (args->flags & NFS_MOUNT_VER3)
  1538. goto out_v3_not_compiled;
  1539. #endif /* !CONFIG_NFS_V3 */
  1540. return 0;
  1541. out_no_data:
  1542. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1543. return -EINVAL;
  1544. out_no_v3:
  1545. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1546. data->version);
  1547. return -EINVAL;
  1548. out_no_sec:
  1549. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1550. return -EINVAL;
  1551. #ifndef CONFIG_NFS_V3
  1552. out_v3_not_compiled:
  1553. dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
  1554. return -EPROTONOSUPPORT;
  1555. #endif /* !CONFIG_NFS_V3 */
  1556. out_nomem:
  1557. dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
  1558. return -ENOMEM;
  1559. out_no_address:
  1560. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1561. return -EINVAL;
  1562. out_invalid_fh:
  1563. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1564. return -EINVAL;
  1565. }
  1566. static int
  1567. nfs_compare_remount_data(struct nfs_server *nfss,
  1568. struct nfs_parsed_mount_data *data)
  1569. {
  1570. if (data->flags != nfss->flags ||
  1571. data->rsize != nfss->rsize ||
  1572. data->wsize != nfss->wsize ||
  1573. data->retrans != nfss->client->cl_timeout->to_retries ||
  1574. data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
  1575. data->acregmin != nfss->acregmin / HZ ||
  1576. data->acregmax != nfss->acregmax / HZ ||
  1577. data->acdirmin != nfss->acdirmin / HZ ||
  1578. data->acdirmax != nfss->acdirmax / HZ ||
  1579. data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
  1580. data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
  1581. memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1582. data->nfs_server.addrlen) != 0)
  1583. return -EINVAL;
  1584. return 0;
  1585. }
  1586. static int
  1587. nfs_remount(struct super_block *sb, int *flags, char *raw_data)
  1588. {
  1589. int error;
  1590. struct nfs_server *nfss = sb->s_fs_info;
  1591. struct nfs_parsed_mount_data *data;
  1592. struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
  1593. struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
  1594. u32 nfsvers = nfss->nfs_client->rpc_ops->version;
  1595. /*
  1596. * Userspace mount programs that send binary options generally send
  1597. * them populated with default values. We have no way to know which
  1598. * ones were explicitly specified. Fall back to legacy behavior and
  1599. * just return success.
  1600. */
  1601. if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
  1602. (nfsvers <= 3 && (!options || (options->version >= 1 &&
  1603. options->version <= 6))))
  1604. return 0;
  1605. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1606. if (data == NULL)
  1607. return -ENOMEM;
  1608. /* fill out struct with values from existing mount */
  1609. data->flags = nfss->flags;
  1610. data->rsize = nfss->rsize;
  1611. data->wsize = nfss->wsize;
  1612. data->retrans = nfss->client->cl_timeout->to_retries;
  1613. data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
  1614. data->acregmin = nfss->acregmin / HZ;
  1615. data->acregmax = nfss->acregmax / HZ;
  1616. data->acdirmin = nfss->acdirmin / HZ;
  1617. data->acdirmax = nfss->acdirmax / HZ;
  1618. data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
  1619. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  1620. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1621. data->nfs_server.addrlen);
  1622. /* overwrite those values with any that were specified */
  1623. error = nfs_parse_mount_options((char *)options, data);
  1624. if (error < 0)
  1625. goto out;
  1626. /* compare new mount options with old ones */
  1627. error = nfs_compare_remount_data(nfss, data);
  1628. out:
  1629. kfree(data);
  1630. return error;
  1631. }
  1632. /*
  1633. * Initialise the common bits of the superblock
  1634. */
  1635. static inline void nfs_initialise_sb(struct super_block *sb)
  1636. {
  1637. struct nfs_server *server = NFS_SB(sb);
  1638. sb->s_magic = NFS_SUPER_MAGIC;
  1639. /* We probably want something more informative here */
  1640. snprintf(sb->s_id, sizeof(sb->s_id),
  1641. "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  1642. if (sb->s_blocksize == 0)
  1643. sb->s_blocksize = nfs_block_bits(server->wsize,
  1644. &sb->s_blocksize_bits);
  1645. if (server->flags & NFS_MOUNT_NOAC)
  1646. sb->s_flags |= MS_SYNCHRONOUS;
  1647. nfs_super_set_maxbytes(sb, server->maxfilesize);
  1648. }
  1649. /*
  1650. * Finish setting up an NFS2/3 superblock
  1651. */
  1652. static void nfs_fill_super(struct super_block *sb,
  1653. struct nfs_parsed_mount_data *data)
  1654. {
  1655. struct nfs_server *server = NFS_SB(sb);
  1656. sb->s_blocksize_bits = 0;
  1657. sb->s_blocksize = 0;
  1658. if (data->bsize)
  1659. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  1660. if (server->flags & NFS_MOUNT_VER3) {
  1661. /* The VFS shouldn't apply the umask to mode bits. We will do
  1662. * so ourselves when necessary.
  1663. */
  1664. sb->s_flags |= MS_POSIXACL;
  1665. sb->s_time_gran = 1;
  1666. }
  1667. sb->s_op = &nfs_sops;
  1668. nfs_initialise_sb(sb);
  1669. }
  1670. /*
  1671. * Finish setting up a cloned NFS2/3 superblock
  1672. */
  1673. static void nfs_clone_super(struct super_block *sb,
  1674. const struct super_block *old_sb)
  1675. {
  1676. struct nfs_server *server = NFS_SB(sb);
  1677. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1678. sb->s_blocksize = old_sb->s_blocksize;
  1679. sb->s_maxbytes = old_sb->s_maxbytes;
  1680. if (server->flags & NFS_MOUNT_VER3) {
  1681. /* The VFS shouldn't apply the umask to mode bits. We will do
  1682. * so ourselves when necessary.
  1683. */
  1684. sb->s_flags |= MS_POSIXACL;
  1685. sb->s_time_gran = 1;
  1686. }
  1687. sb->s_op = old_sb->s_op;
  1688. nfs_initialise_sb(sb);
  1689. }
  1690. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  1691. {
  1692. const struct nfs_server *a = s->s_fs_info;
  1693. const struct rpc_clnt *clnt_a = a->client;
  1694. const struct rpc_clnt *clnt_b = b->client;
  1695. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  1696. goto Ebusy;
  1697. if (a->nfs_client != b->nfs_client)
  1698. goto Ebusy;
  1699. if (a->flags != b->flags)
  1700. goto Ebusy;
  1701. if (a->wsize != b->wsize)
  1702. goto Ebusy;
  1703. if (a->rsize != b->rsize)
  1704. goto Ebusy;
  1705. if (a->acregmin != b->acregmin)
  1706. goto Ebusy;
  1707. if (a->acregmax != b->acregmax)
  1708. goto Ebusy;
  1709. if (a->acdirmin != b->acdirmin)
  1710. goto Ebusy;
  1711. if (a->acdirmax != b->acdirmax)
  1712. goto Ebusy;
  1713. if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  1714. goto Ebusy;
  1715. return 1;
  1716. Ebusy:
  1717. return 0;
  1718. }
  1719. struct nfs_sb_mountdata {
  1720. struct nfs_server *server;
  1721. int mntflags;
  1722. };
  1723. static int nfs_set_super(struct super_block *s, void *data)
  1724. {
  1725. struct nfs_sb_mountdata *sb_mntdata = data;
  1726. struct nfs_server *server = sb_mntdata->server;
  1727. int ret;
  1728. s->s_flags = sb_mntdata->mntflags;
  1729. s->s_fs_info = server;
  1730. ret = set_anon_super(s, server);
  1731. if (ret == 0)
  1732. server->s_dev = s->s_dev;
  1733. return ret;
  1734. }
  1735. static int nfs_compare_super_address(struct nfs_server *server1,
  1736. struct nfs_server *server2)
  1737. {
  1738. struct sockaddr *sap1, *sap2;
  1739. sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
  1740. sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
  1741. if (sap1->sa_family != sap2->sa_family)
  1742. return 0;
  1743. switch (sap1->sa_family) {
  1744. case AF_INET: {
  1745. struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
  1746. struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
  1747. if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
  1748. return 0;
  1749. if (sin1->sin_port != sin2->sin_port)
  1750. return 0;
  1751. break;
  1752. }
  1753. case AF_INET6: {
  1754. struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
  1755. struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
  1756. if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
  1757. return 0;
  1758. if (sin1->sin6_port != sin2->sin6_port)
  1759. return 0;
  1760. break;
  1761. }
  1762. default:
  1763. return 0;
  1764. }
  1765. return 1;
  1766. }
  1767. static int nfs_compare_super(struct super_block *sb, void *data)
  1768. {
  1769. struct nfs_sb_mountdata *sb_mntdata = data;
  1770. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  1771. int mntflags = sb_mntdata->mntflags;
  1772. if (!nfs_compare_super_address(old, server))
  1773. return 0;
  1774. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  1775. if (old->flags & NFS_MOUNT_UNSHARED)
  1776. return 0;
  1777. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  1778. return 0;
  1779. return nfs_compare_mount_options(sb, server, mntflags);
  1780. }
  1781. static int nfs_bdi_register(struct nfs_server *server)
  1782. {
  1783. return bdi_register_dev(&server->backing_dev_info, server->s_dev);
  1784. }
  1785. static int nfs_get_sb(struct file_system_type *fs_type,
  1786. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1787. {
  1788. struct nfs_server *server = NULL;
  1789. struct super_block *s;
  1790. struct nfs_parsed_mount_data *data;
  1791. struct nfs_fh *mntfh;
  1792. struct dentry *mntroot;
  1793. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1794. struct nfs_sb_mountdata sb_mntdata = {
  1795. .mntflags = flags,
  1796. };
  1797. int error = -ENOMEM;
  1798. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1799. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  1800. if (data == NULL || mntfh == NULL)
  1801. goto out_free_fh;
  1802. security_init_mnt_opts(&data->lsm_opts);
  1803. /* Validate the mount data */
  1804. error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
  1805. if (error < 0)
  1806. goto out;
  1807. /* Get a volume representation */
  1808. server = nfs_create_server(data, mntfh);
  1809. if (IS_ERR(server)) {
  1810. error = PTR_ERR(server);
  1811. goto out;
  1812. }
  1813. sb_mntdata.server = server;
  1814. if (server->flags & NFS_MOUNT_UNSHARED)
  1815. compare_super = NULL;
  1816. /* Get a superblock - note that we may end up sharing one that already exists */
  1817. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1818. if (IS_ERR(s)) {
  1819. error = PTR_ERR(s);
  1820. goto out_err_nosb;
  1821. }
  1822. if (s->s_fs_info != server) {
  1823. nfs_free_server(server);
  1824. server = NULL;
  1825. } else {
  1826. error = nfs_bdi_register(server);
  1827. if (error)
  1828. goto error_splat_super;
  1829. }
  1830. if (!s->s_root) {
  1831. /* initial superblock/root creation */
  1832. nfs_fill_super(s, data);
  1833. nfs_fscache_get_super_cookie(s, data);
  1834. }
  1835. mntroot = nfs_get_root(s, mntfh);
  1836. if (IS_ERR(mntroot)) {
  1837. error = PTR_ERR(mntroot);
  1838. goto error_splat_super;
  1839. }
  1840. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  1841. if (error)
  1842. goto error_splat_root;
  1843. s->s_flags |= MS_ACTIVE;
  1844. mnt->mnt_sb = s;
  1845. mnt->mnt_root = mntroot;
  1846. error = 0;
  1847. out:
  1848. kfree(data->nfs_server.hostname);
  1849. kfree(data->mount_server.hostname);
  1850. kfree(data->fscache_uniq);
  1851. security_free_mnt_opts(&data->lsm_opts);
  1852. out_free_fh:
  1853. kfree(mntfh);
  1854. kfree(data);
  1855. return error;
  1856. out_err_nosb:
  1857. nfs_free_server(server);
  1858. goto out;
  1859. error_splat_root:
  1860. dput(mntroot);
  1861. error_splat_super:
  1862. deactivate_locked_super(s);
  1863. goto out;
  1864. }
  1865. /*
  1866. * Destroy an NFS2/3 superblock
  1867. */
  1868. static void nfs_kill_super(struct super_block *s)
  1869. {
  1870. struct nfs_server *server = NFS_SB(s);
  1871. bdi_unregister(&server->backing_dev_info);
  1872. kill_anon_super(s);
  1873. nfs_fscache_release_super_cookie(s);
  1874. nfs_free_server(server);
  1875. }
  1876. /*
  1877. * Clone an NFS2/3 server record on xdev traversal (FSID-change)
  1878. */
  1879. static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1880. const char *dev_name, void *raw_data,
  1881. struct vfsmount *mnt)
  1882. {
  1883. struct nfs_clone_mount *data = raw_data;
  1884. struct super_block *s;
  1885. struct nfs_server *server;
  1886. struct dentry *mntroot;
  1887. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1888. struct nfs_sb_mountdata sb_mntdata = {
  1889. .mntflags = flags,
  1890. };
  1891. int error;
  1892. dprintk("--> nfs_xdev_get_sb()\n");
  1893. /* create a new volume representation */
  1894. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1895. if (IS_ERR(server)) {
  1896. error = PTR_ERR(server);
  1897. goto out_err_noserver;
  1898. }
  1899. sb_mntdata.server = server;
  1900. if (server->flags & NFS_MOUNT_UNSHARED)
  1901. compare_super = NULL;
  1902. /* Get a superblock - note that we may end up sharing one that already exists */
  1903. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1904. if (IS_ERR(s)) {
  1905. error = PTR_ERR(s);
  1906. goto out_err_nosb;
  1907. }
  1908. if (s->s_fs_info != server) {
  1909. nfs_free_server(server);
  1910. server = NULL;
  1911. } else {
  1912. error = nfs_bdi_register(server);
  1913. if (error)
  1914. goto error_splat_super;
  1915. }
  1916. if (!s->s_root) {
  1917. /* initial superblock/root creation */
  1918. nfs_clone_super(s, data->sb);
  1919. }
  1920. mntroot = nfs_get_root(s, data->fh);
  1921. if (IS_ERR(mntroot)) {
  1922. error = PTR_ERR(mntroot);
  1923. goto error_splat_super;
  1924. }
  1925. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  1926. dput(mntroot);
  1927. error = -ESTALE;
  1928. goto error_splat_super;
  1929. }
  1930. s->s_flags |= MS_ACTIVE;
  1931. mnt->mnt_sb = s;
  1932. mnt->mnt_root = mntroot;
  1933. /* clone any lsm security options from the parent to the new sb */
  1934. security_sb_clone_mnt_opts(data->sb, s);
  1935. dprintk("<-- nfs_xdev_get_sb() = 0\n");
  1936. return 0;
  1937. out_err_nosb:
  1938. nfs_free_server(server);
  1939. out_err_noserver:
  1940. dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
  1941. return error;
  1942. error_splat_super:
  1943. deactivate_locked_super(s);
  1944. dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
  1945. return error;
  1946. }
  1947. #ifdef CONFIG_NFS_V4
  1948. /*
  1949. * Finish setting up a cloned NFS4 superblock
  1950. */
  1951. static void nfs4_clone_super(struct super_block *sb,
  1952. const struct super_block *old_sb)
  1953. {
  1954. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1955. sb->s_blocksize = old_sb->s_blocksize;
  1956. sb->s_maxbytes = old_sb->s_maxbytes;
  1957. sb->s_time_gran = 1;
  1958. sb->s_op = old_sb->s_op;
  1959. nfs_initialise_sb(sb);
  1960. }
  1961. /*
  1962. * Set up an NFS4 superblock
  1963. */
  1964. static void nfs4_fill_super(struct super_block *sb)
  1965. {
  1966. sb->s_time_gran = 1;
  1967. sb->s_op = &nfs4_sops;
  1968. nfs_initialise_sb(sb);
  1969. }
  1970. /*
  1971. * Validate NFSv4 mount options
  1972. */
  1973. static int nfs4_validate_mount_data(void *options,
  1974. struct nfs_parsed_mount_data *args,
  1975. const char *dev_name)
  1976. {
  1977. struct sockaddr_in *ap;
  1978. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  1979. char *c;
  1980. if (data == NULL)
  1981. goto out_no_data;
  1982. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1983. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1984. args->acregmin = NFS_DEF_ACREGMIN;
  1985. args->acregmax = NFS_DEF_ACREGMAX;
  1986. args->acdirmin = NFS_DEF_ACDIRMIN;
  1987. args->acdirmax = NFS_DEF_ACDIRMAX;
  1988. args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
  1989. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1990. args->auth_flavor_len = 0;
  1991. switch (data->version) {
  1992. case 1:
  1993. ap = (struct sockaddr_in *)&args->nfs_server.address;
  1994. if (data->host_addrlen > sizeof(args->nfs_server.address))
  1995. goto out_no_address;
  1996. if (data->host_addrlen == 0)
  1997. goto out_no_address;
  1998. args->nfs_server.addrlen = data->host_addrlen;
  1999. if (copy_from_user(ap, data->host_addr, data->host_addrlen))
  2000. return -EFAULT;
  2001. if (!nfs_verify_server_address((struct sockaddr *)
  2002. &args->nfs_server.address))
  2003. goto out_no_address;
  2004. if (data->auth_flavourlen) {
  2005. if (data->auth_flavourlen > 1)
  2006. goto out_inval_auth;
  2007. if (copy_from_user(&args->auth_flavors[0],
  2008. data->auth_flavours,
  2009. sizeof(args->auth_flavors[0])))
  2010. return -EFAULT;
  2011. }
  2012. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  2013. if (IS_ERR(c))
  2014. return PTR_ERR(c);
  2015. args->nfs_server.hostname = c;
  2016. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  2017. if (IS_ERR(c))
  2018. return PTR_ERR(c);
  2019. args->nfs_server.export_path = c;
  2020. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  2021. c = strndup_user(data->client_addr.data, 16);
  2022. if (IS_ERR(c))
  2023. return PTR_ERR(c);
  2024. args->client_address = c;
  2025. /*
  2026. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  2027. * can deal with.
  2028. */
  2029. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  2030. args->rsize = data->rsize;
  2031. args->wsize = data->wsize;
  2032. args->timeo = data->timeo;
  2033. args->retrans = data->retrans;
  2034. args->acregmin = data->acregmin;
  2035. args->acregmax = data->acregmax;
  2036. args->acdirmin = data->acdirmin;
  2037. args->acdirmax = data->acdirmax;
  2038. args->nfs_server.protocol = data->proto;
  2039. nfs_validate_transport_protocol(args);
  2040. break;
  2041. default: {
  2042. int status;
  2043. if (nfs_parse_mount_options((char *)options, args) == 0)
  2044. return -EINVAL;
  2045. if (!nfs_verify_server_address((struct sockaddr *)
  2046. &args->nfs_server.address))
  2047. return -EINVAL;
  2048. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  2049. args->nfs_server.port);
  2050. nfs_validate_transport_protocol(args);
  2051. if (args->auth_flavor_len > 1)
  2052. goto out_inval_auth;
  2053. if (args->client_address == NULL)
  2054. goto out_no_client_address;
  2055. status = nfs_parse_devname(dev_name,
  2056. &args->nfs_server.hostname,
  2057. NFS4_MAXNAMLEN,
  2058. &args->nfs_server.export_path,
  2059. NFS4_MAXPATHLEN);
  2060. if (status < 0)
  2061. return status;
  2062. break;
  2063. }
  2064. }
  2065. return 0;
  2066. out_no_data:
  2067. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  2068. return -EINVAL;
  2069. out_inval_auth:
  2070. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  2071. data->auth_flavourlen);
  2072. return -EINVAL;
  2073. out_no_address:
  2074. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  2075. return -EINVAL;
  2076. out_no_client_address:
  2077. dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
  2078. return -EINVAL;
  2079. }
  2080. /*
  2081. * Get the superblock for an NFS4 mountpoint
  2082. */
  2083. static int nfs4_get_sb(struct file_system_type *fs_type,
  2084. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  2085. {
  2086. struct nfs_parsed_mount_data *data;
  2087. struct super_block *s;
  2088. struct nfs_server *server;
  2089. struct nfs_fh *mntfh;
  2090. struct dentry *mntroot;
  2091. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2092. struct nfs_sb_mountdata sb_mntdata = {
  2093. .mntflags = flags,
  2094. };
  2095. int error = -ENOMEM;
  2096. data = kzalloc(sizeof(*data), GFP_KERNEL);
  2097. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  2098. if (data == NULL || mntfh == NULL)
  2099. goto out_free_fh;
  2100. security_init_mnt_opts(&data->lsm_opts);
  2101. /* Validate the mount data */
  2102. error = nfs4_validate_mount_data(raw_data, data, dev_name);
  2103. if (error < 0)
  2104. goto out;
  2105. /* Get a volume representation */
  2106. server = nfs4_create_server(data, mntfh);
  2107. if (IS_ERR(server)) {
  2108. error = PTR_ERR(server);
  2109. goto out;
  2110. }
  2111. sb_mntdata.server = server;
  2112. if (server->flags & NFS4_MOUNT_UNSHARED)
  2113. compare_super = NULL;
  2114. /* Get a superblock - note that we may end up sharing one that already exists */
  2115. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2116. if (IS_ERR(s)) {
  2117. error = PTR_ERR(s);
  2118. goto out_free;
  2119. }
  2120. if (s->s_fs_info != server) {
  2121. nfs_free_server(server);
  2122. server = NULL;
  2123. } else {
  2124. error = nfs_bdi_register(server);
  2125. if (error)
  2126. goto error_splat_super;
  2127. }
  2128. if (!s->s_root) {
  2129. /* initial superblock/root creation */
  2130. nfs4_fill_super(s);
  2131. nfs_fscache_get_super_cookie(s, data);
  2132. }
  2133. mntroot = nfs4_get_root(s, mntfh);
  2134. if (IS_ERR(mntroot)) {
  2135. error = PTR_ERR(mntroot);
  2136. goto error_splat_super;
  2137. }
  2138. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  2139. if (error)
  2140. goto error_splat_root;
  2141. s->s_flags |= MS_ACTIVE;
  2142. mnt->mnt_sb = s;
  2143. mnt->mnt_root = mntroot;
  2144. error = 0;
  2145. out:
  2146. kfree(data->client_address);
  2147. kfree(data->nfs_server.export_path);
  2148. kfree(data->nfs_server.hostname);
  2149. kfree(data->fscache_uniq);
  2150. security_free_mnt_opts(&data->lsm_opts);
  2151. out_free_fh:
  2152. kfree(mntfh);
  2153. kfree(data);
  2154. return error;
  2155. out_free:
  2156. nfs_free_server(server);
  2157. goto out;
  2158. error_splat_root:
  2159. dput(mntroot);
  2160. error_splat_super:
  2161. deactivate_locked_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. deactivate_locked_super(s);
  2240. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  2241. return error;
  2242. }
  2243. /*
  2244. * Create an NFS4 server record on referral traversal
  2245. */
  2246. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  2247. const char *dev_name, void *raw_data,
  2248. struct vfsmount *mnt)
  2249. {
  2250. struct nfs_clone_mount *data = raw_data;
  2251. struct super_block *s;
  2252. struct nfs_server *server;
  2253. struct dentry *mntroot;
  2254. struct nfs_fh mntfh;
  2255. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2256. struct nfs_sb_mountdata sb_mntdata = {
  2257. .mntflags = flags,
  2258. };
  2259. int error;
  2260. dprintk("--> nfs4_referral_get_sb()\n");
  2261. /* create a new volume representation */
  2262. server = nfs4_create_referral_server(data, &mntfh);
  2263. if (IS_ERR(server)) {
  2264. error = PTR_ERR(server);
  2265. goto out_err_noserver;
  2266. }
  2267. sb_mntdata.server = server;
  2268. if (server->flags & NFS4_MOUNT_UNSHARED)
  2269. compare_super = NULL;
  2270. /* Get a superblock - note that we may end up sharing one that already exists */
  2271. s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2272. if (IS_ERR(s)) {
  2273. error = PTR_ERR(s);
  2274. goto out_err_nosb;
  2275. }
  2276. if (s->s_fs_info != server) {
  2277. nfs_free_server(server);
  2278. server = NULL;
  2279. } else {
  2280. error = nfs_bdi_register(server);
  2281. if (error)
  2282. goto error_splat_super;
  2283. }
  2284. if (!s->s_root) {
  2285. /* initial superblock/root creation */
  2286. nfs4_fill_super(s);
  2287. }
  2288. mntroot = nfs4_get_root(s, &mntfh);
  2289. if (IS_ERR(mntroot)) {
  2290. error = PTR_ERR(mntroot);
  2291. goto error_splat_super;
  2292. }
  2293. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2294. dput(mntroot);
  2295. error = -ESTALE;
  2296. goto error_splat_super;
  2297. }
  2298. s->s_flags |= MS_ACTIVE;
  2299. mnt->mnt_sb = s;
  2300. mnt->mnt_root = mntroot;
  2301. security_sb_clone_mnt_opts(data->sb, s);
  2302. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  2303. return 0;
  2304. out_err_nosb:
  2305. nfs_free_server(server);
  2306. out_err_noserver:
  2307. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  2308. return error;
  2309. error_splat_super:
  2310. deactivate_locked_super(s);
  2311. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  2312. return error;
  2313. }
  2314. #endif /* CONFIG_NFS_V4 */