super.c 75 KB

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