super.c 75 KB

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