super.c 77 KB

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