super.c 79 KB

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