super.c 77 KB

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