super.c 71 KB

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