super.c 64 KB

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