super.c 64 KB

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