super.c 79 KB

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