super.c 63 KB

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