super.c 66 KB

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